Search in sources :

Example 26 with Cache

use of com.optimizely.ab.android.shared.Cache in project android-sdk by optimizely.

the class DefaultUserProfileServiceTest method setup.

@Before
public void setup() {
    logger = mock(Logger.class);
    cache = new Cache(InstrumentationRegistry.getInstrumentation().getTargetContext(), logger);
    executor = Executors.newSingleThreadExecutor();
    legacyDiskCache = new UserProfileCache.LegacyDiskCache(cache, executor, logger, projectId);
    memoryCache = new ConcurrentHashMap<>();
    projectId = "123";
    diskCache = new UserProfileCache.DiskCache(cache, executor, logger, projectId);
    userProfileCache = new UserProfileCache(diskCache, logger, memoryCache, legacyDiskCache);
    userProfileService = new DefaultUserProfileService(userProfileCache, logger);
    // Test data.
    userId1 = "user_1";
    Map<String, Map<String, String>> experimentBucketMap1 = new ConcurrentHashMap<>();
    Map<String, String> decisionMap1 = new ConcurrentHashMap<>();
    decisionMap1.put("variation_id", "var_1");
    experimentBucketMap1.put("exp_1", decisionMap1);
    Map<String, String> decisionMap2 = new ConcurrentHashMap<>();
    decisionMap2.put("variation_id", "var_2");
    experimentBucketMap1.put("exp_2", decisionMap2);
    userProfileMap1 = new ConcurrentHashMap<>();
    userProfileMap1.put("user_id", userId1);
    userProfileMap1.put("experiment_bucket_map", experimentBucketMap1);
    userId2 = "user_2";
    Map<String, Map<String, String>> experimentBucketMap2 = new ConcurrentHashMap<>();
    Map<String, String> decisionMap3 = new ConcurrentHashMap<>();
    decisionMap3.put("variation_id", "var_3");
    experimentBucketMap2.put("exp_1", decisionMap3);
    Map<String, String> decisionMap4 = new ConcurrentHashMap<>();
    decisionMap4.put("variation_id", "var_4");
    experimentBucketMap2.put("exp_2", decisionMap4);
    userProfileMap2 = new ConcurrentHashMap<>();
    userProfileMap2.put("user_id", userId2);
    userProfileMap2.put("experiment_bucket_map", experimentBucketMap2);
}
Also used : Logger(org.slf4j.Logger) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map) Cache(com.optimizely.ab.android.shared.Cache) Before(org.junit.Before)

Example 27 with Cache

use of com.optimizely.ab.android.shared.Cache in project android-sdk by optimizely.

the class DiskCacheTest method setup.

@Before
public void setup() {
    logger = mock(Logger.class);
    cache = new Cache(InstrumentationRegistry.getInstrumentation().getTargetContext(), logger);
    memoryCache = new ConcurrentHashMap<>();
    projectId = "123";
    diskCache = new UserProfileCache.DiskCache(cache, executor, logger, projectId);
    userId = "user_1";
    // Populate in-memory cache.
    Map<String, Map<String, String>> experimentBucketMap = new ConcurrentHashMap<>();
    Map<String, String> decisionMap1 = new ConcurrentHashMap<>();
    decisionMap1.put("variation_id", "var_1");
    experimentBucketMap.put("exp_1", decisionMap1);
    Map<String, String> decisionMap2 = new ConcurrentHashMap<>();
    decisionMap2.put("variation_id", "var_2");
    experimentBucketMap.put("exp_2", decisionMap2);
    Map<String, Object> userProfileMap = new ConcurrentHashMap<>();
    userProfileMap.put("user_id", userId);
    userProfileMap.put("experiment_bucket_map", experimentBucketMap);
    memoryCache.put(userId, userProfileMap);
}
Also used : JSONObject(org.json.JSONObject) Logger(org.slf4j.Logger) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map) Cache(com.optimizely.ab.android.shared.Cache) Before(org.junit.Before)

Example 28 with Cache

use of com.optimizely.ab.android.shared.Cache in project android-sdk by optimizely.

the class LegacyDiskCacheTest method setup.

@Before
public void setup() {
    logger = mock(Logger.class);
    cache = new Cache(InstrumentationRegistry.getInstrumentation().getTargetContext(), logger);
    projectId = "123";
    legacyDiskCache = new UserProfileCache.LegacyDiskCache(cache, executor, logger, projectId);
}
Also used : Logger(org.slf4j.Logger) Cache(com.optimizely.ab.android.shared.Cache) Before(org.junit.Before)

Aggregations

Cache (com.optimizely.ab.android.shared.Cache)28 Test (org.junit.Test)10 Logger (org.slf4j.Logger)9 Before (org.junit.Before)8 DatafileConfig (com.optimizely.ab.android.shared.DatafileConfig)6 Client (com.optimizely.ab.android.shared.Client)5 ExecutorService (java.util.concurrent.ExecutorService)5 Context (android.content.Context)3 OptlyStorage (com.optimizely.ab.android.shared.OptlyStorage)3 Map (java.util.Map)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 JSONObject (org.json.JSONObject)3 SdkSuppress (androidx.test.filters.SdkSuppress)2 JSONException (org.json.JSONException)2 Intent (android.content.Intent)1 FileObserver (android.os.FileObserver)1 IBinder (android.os.IBinder)1 NonNull (androidx.annotation.NonNull)1 ListenableWorker (androidx.work.ListenableWorker)1 File (java.io.File)1