Skip to content

Commit

Permalink
Merge pull request #830 from CRED-CLUB/sb/multi_instance_support
Browse files Browse the repository at this point in the history
feat: Enable data separation for each MixPanel API instance
  • Loading branch information
zihejia committed Mar 14, 2024
2 parents 951b9ea + 4e7b052 commit cf8840b
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public byte[] performRequest(String endpointUrl, Map<String, Object> params, SSL
};

InstrumentationRegistry.getInstrumentation().getContext().deleteDatabase("mixpanel");
mockAdapter = new MPDbAdapter(InstrumentationRegistry.getInstrumentation().getContext(), MPConfig.getInstance(InstrumentationRegistry.getInstrumentation().getContext())) {
mockAdapter = new MPDbAdapter(InstrumentationRegistry.getInstrumentation().getContext(), MPConfig.getInstance(InstrumentationRegistry.getInstrumentation().getContext(), null)) {
@Override
public void cleanupEvents(String last_id, Table table, String token) {
if (token.equalsIgnoreCase(TOKEN)) {
Expand All @@ -102,7 +102,7 @@ public int addJSON(JSONObject j, String token, Table table) {
}
};

final AnalyticsMessages automaticAnalyticsMessages = new AnalyticsMessages(InstrumentationRegistry.getInstrumentation().getContext(), MPConfig.getInstance(InstrumentationRegistry.getInstrumentation().getContext())) {
final AnalyticsMessages automaticAnalyticsMessages = new AnalyticsMessages(InstrumentationRegistry.getInstrumentation().getContext(), MPConfig.getInstance(InstrumentationRegistry.getInstrumentation().getContext(), null)) {

@Override
protected RemoteService getPoster() {
Expand Down Expand Up @@ -228,7 +228,7 @@ public byte[] performRequest(String endpointUrl, Map<String, Object> params, SSL
}
};

final MPDbAdapter mpSecondDbAdapter = new MPDbAdapter(InstrumentationRegistry.getInstrumentation().getContext(), MPConfig.getInstance(InstrumentationRegistry.getInstrumentation().getContext())) {
final MPDbAdapter mpSecondDbAdapter = new MPDbAdapter(InstrumentationRegistry.getInstrumentation().getContext(), MPConfig.getInstance(InstrumentationRegistry.getInstrumentation().getContext(), null)) {
@Override
public void cleanupEvents(String last_id, Table table, String token) {
if (token.equalsIgnoreCase(SECOND_TOKEN)) {
Expand All @@ -247,7 +247,7 @@ public int addJSON(JSONObject j, String token, Table table) {
}
};

final AnalyticsMessages mpSecondAnalyticsMessages = new AnalyticsMessages(InstrumentationRegistry.getInstrumentation().getContext(), MPConfig.getInstance(InstrumentationRegistry.getInstrumentation().getContext())) {
final AnalyticsMessages mpSecondAnalyticsMessages = new AnalyticsMessages(InstrumentationRegistry.getInstrumentation().getContext(), MPConfig.getInstance(InstrumentationRegistry.getInstrumentation().getContext(), null)) {
@Override
protected RemoteService getPoster() {
return mpSecondPoster;
Expand Down Expand Up @@ -281,8 +281,8 @@ AnalyticsMessages getAnalyticsMessages() {
};
assertTrue(mLatch.await(MAX_TIMEOUT_POLL, TimeUnit.MILLISECONDS));
assertEquals(initialCalls, mTrackedEvents);
mLatch = new CountDownLatch(MPConfig.getInstance(InstrumentationRegistry.getInstrumentation().getContext()).getBulkUploadLimit() - initialCalls);
for (int i = 0; i < MPConfig.getInstance(InstrumentationRegistry.getInstrumentation().getContext()).getBulkUploadLimit() - initialCalls; i++) {
mLatch = new CountDownLatch(MPConfig.getInstance(InstrumentationRegistry.getInstrumentation().getContext(), null).getBulkUploadLimit() - initialCalls);
for (int i = 0; i < MPConfig.getInstance(InstrumentationRegistry.getInstrumentation().getContext(), null).getBulkUploadLimit() - initialCalls; i++) {
mCleanMixpanelAPI.track("Track event " + i);
}

Expand All @@ -291,7 +291,7 @@ AnalyticsMessages getAnalyticsMessages() {

assertEquals(AutomaticEvents.FIRST_OPEN, mPerformRequestEvents.poll(MAX_TIMEOUT_POLL, TimeUnit.MILLISECONDS));
assertEquals(AutomaticEvents.APP_UPDATED, mPerformRequestEvents.poll(MAX_TIMEOUT_POLL, TimeUnit.MILLISECONDS));
for (int i = 0; i < MPConfig.getInstance(InstrumentationRegistry.getInstrumentation().getContext()).getBulkUploadLimit() - initialCalls; i++) {
for (int i = 0; i < MPConfig.getInstance(InstrumentationRegistry.getInstrumentation().getContext(), null).getBulkUploadLimit() - initialCalls; i++) {
assertEquals("Track event " + i, mPerformRequestEvents.poll(MAX_TIMEOUT_POLL, TimeUnit.MILLISECONDS));
}

Expand All @@ -310,4 +310,4 @@ AnalyticsMessages getAnalyticsMessages() {

assertNull(mPerformRequestEvents.poll(MAX_TIMEOUT_POLL, TimeUnit.MILLISECONDS));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public byte[] performRequest(String endpointUrl, Map<String, Object> params, SSL
}
};

final MPConfig config = new MPConfig(new Bundle(), InstrumentationRegistry.getInstrumentation().getContext()) {
final MPConfig config = new MPConfig(new Bundle(), InstrumentationRegistry.getInstrumentation().getContext(), null) {

@Override
public String getEventsEndpoint() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public void testSetMaximumDatabaseLimit2() {
}

private MPConfig mpConfig(final Bundle metaData) {
return new MPConfig(metaData, InstrumentationRegistry.getInstrumentation().getContext());
return new MPConfig(metaData, InstrumentationRegistry.getInstrumentation().getContext(), null);
}

private MixpanelAPI mixpanelApi(final MPConfig config) {
Expand Down
Loading

0 comments on commit cf8840b

Please sign in to comment.