Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,11 @@ public void startHandlesJSONException() throws IOException {
public void start() throws JSONException {
androidUserExperimentRecord.start();
androidUserExperimentRecord.save("user1", "exp1", "var1");
androidUserExperimentRecord.save("user1", "exp2", "var2");

Map<String, String> expKeyToVarKeyMap = new HashMap<>();
expKeyToVarKeyMap.put("exp1", "var1");
expKeyToVarKeyMap.put("exp2", "var2");
Map<String, Map<String, String>> recordMap = new HashMap<>();
recordMap.put("user1", expKeyToVarKeyMap);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,11 @@ public void loadWhenNoFile() throws JSONException {
@Test
public void testSaveAndLoad() throws JSONException {
assertTrue(userExperimentRecordCache.save("foo", "exp1", "var1"));
assertTrue(userExperimentRecordCache.save("foo", "exp2", "var2"));
JSONObject expectedActivation = new JSONObject();
JSONObject expectedExpIdToVarId = new JSONObject();
expectedExpIdToVarId.put("exp1", "var1");
expectedExpIdToVarId.put("exp2", "var2");
expectedActivation.put("foo", expectedExpIdToVarId);
assertEquals(expectedActivation.toString(), userExperimentRecordCache.load().toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ public void start() {
while (iterator2.hasNext()) {
String expId = iterator2.next();
String varId = expIdToVarIdJson.getString(expId);
Map<String, String> expIdToVarIdMap = new HashMap<>();
Map<String, String> expIdToVarIdMap = writeThroughCacheTaskFactory.getMemoryUserExperimentRecordCache().get(userId);
if (expIdToVarIdMap == null) {
expIdToVarIdMap = new HashMap<>();
}
expIdToVarIdMap.put(expId, varId);
writeThroughCacheTaskFactory.getMemoryUserExperimentRecordCache().put(userId, expIdToVarIdMap);
}
Expand Down Expand Up @@ -160,10 +163,6 @@ public String lookup(String userId, String experimentKey) {
variationKey = expIdToVarIdMap.get(experimentKey);
}

if (variationKey == null) {
logger.error("Project config did not contain matching experiment and variation ids");
}

return variationKey;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@ boolean remove(@NonNull String userId, @NonNull String experimentId) {
boolean save(@NonNull String userId, @NonNull String experimentId, @NonNull String variationId) {
try {
JSONObject userExperimentRecord = load();
userExperimentRecord.put(userId, null);
JSONObject expIdToVarId = new JSONObject();
JSONObject expIdToVarId = userExperimentRecord.optJSONObject(userId);
if (expIdToVarId == null) {
expIdToVarId = new JSONObject();
}
expIdToVarId.put(experimentId, variationId);
userExperimentRecord.put(userId, expIdToVarId);
return cache.save(getFileName(), userExperimentRecord.toString());
Expand Down