Skip to content

Commit

Permalink
Adding feature flag for identity caching feature
Browse files Browse the repository at this point in the history
Pending read from it, as of know is disabled.
  • Loading branch information
markvdouw authored and Mansi-mParticle committed Sep 12, 2024
1 parent 1617f8b commit 405d853
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,18 @@ class IdentityApiStartTest : BaseCleanInstallEachTest() {
@Test
@Throws(Exception::class)
fun testNoInitialIdentity() {
val currentMpid = ran.nextLong()
val identities = mRandomUtils.randomUserIdentities
startMParticle()
TestCase.assertEquals(mServer.Requests().identify.size, 1)
MParticle.getInstance()?.Internal()?.configManager?.setMpid(currentMpid, ran.nextBoolean())
for ((key, value) in identities) {
AccessUtils.setUserIdentity(value, key, currentMpid)
}
com.mparticle.internal.AccessUtils.awaitMessageHandler()
mServer = MockServer.getNewInstance(mContext)
startMParticle()
// Due to caching
TestCase.assertEquals(mServer.Requests().identify.size, 0)
TestCase.assertEquals(mServer.Requests().identify.size, 1)
assertIdentitiesMatch(mServer.Requests().identify[0], identities, false)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ private void reset() {
}

private boolean shouldMakeRequest(IdentityApiRequest identityRequest, boolean acceptCachedResponse, long lastIdentityCall) {
if (!acceptCachedResponse) {
if (!acceptCachedResponse || !mConfigManager.isIdentityCachingEnabled()) {
return true;
}
boolean hasTimedOut = lastIdentityCall == -1L || (lastIdentityCall + (timeoutSeconds * 1000) > System.currentTimeMillis());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public class ConfigManager {
static final String DATAPLAN_BLOCK_USER_IDENTITIES = "id";
public static final String KIT_CONFIG_KEY = "kit_config";
static final String MIGRATED_TO_KIT_SHARED_PREFS = "is_mig_kit_sp";
private static final String IDENTITY_CACHING_ENABLED = "identityCachingEnabled";

private static final int DEVMODE_UPLOAD_INTERVAL_MILLISECONDS = 10 * 1000;
private static final int DEFAULT_MAX_ALIAS_WINDOW_DAYS = 90;
Expand All @@ -92,6 +93,7 @@ public class ConfigManager {
private JSONObject mProviderPersistence;
private int mRampValue = -1;
private int mUserBucket = -1;
private boolean identityCachingEnabled = false;

private int mSessionTimeoutInterval = -1;
private int mUploadInterval = -1;
Expand Down Expand Up @@ -421,6 +423,9 @@ private synchronized void updateCoreConfig(JSONObject responseJSON, boolean newC
mSendOoEvents = false;
}

//TODO Read from identityCachingEnabled feature flag
editor.putBoolean(IDENTITY_CACHING_ENABLED, identityCachingEnabled);

if (responseJSON.has(ProviderPersistence.KEY_PERSISTENCE)) {
setProviderPersistence(new ProviderPersistence(responseJSON, mContext));
} else {
Expand Down Expand Up @@ -527,6 +532,10 @@ public long getInfluenceOpenTimeoutMillis() {
return mInfluenceOpenTimeout;
}

public boolean isIdentityCachingEnabled() {
return identityCachingEnabled;
}

private void applyConfig() {
if (getLogUnhandledExceptions()) {
enableUncaughtExceptionLogging(false);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mparticle.testutils;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import android.app.Activity;
Expand Down Expand Up @@ -103,6 +104,7 @@ protected void startMParticle(MParticleOptions.Builder optionsBuilder) throws In
MParticle.start(optionsBuilder.build());
mServer.setupHappyIdentify(mStartingMpid);
latch.await();
assertTrue(called.value);
}

protected void goToBackground() {
Expand Down

0 comments on commit 405d853

Please sign in to comment.