Skip to content

Commit

Permalink
Log merged attributes in Impression Logger (#407)
Browse files Browse the repository at this point in the history
  • Loading branch information
gthea authored Aug 11, 2022
1 parent 5817c76 commit 7c409bf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ private SplitResult getTreatmentWithConfigWithoutMetrics(String split, Map<Strin
mValidationLogger.e(errorInfo, validationTag);
return new SplitResult(Treatments.CONTROL);
}

String splitName = split;
errorInfo = mSplitValidator.validateName(split);
if (errorInfo != null) {
Expand All @@ -181,7 +180,8 @@ private SplitResult getTreatmentWithConfigWithoutMetrics(String split, Map<Strin
splitName = split.trim();
}

EvaluationResult evaluationResult = evaluateIfReady(splitName, mAttributesMerger.merge(mAttributesManager.getAllAttributes(), attributes), validationTag);
final Map<String, Object> mergedAttributes = mAttributesMerger.merge(mAttributesManager.getAllAttributes(), attributes);
EvaluationResult evaluationResult = evaluateIfReady(splitName, mergedAttributes, validationTag);
SplitResult splitResult = new SplitResult(evaluationResult.getTreatment(), evaluationResult.getConfigurations());

if (evaluationResult.getLabel().equals(TreatmentLabels.DEFINITION_NOT_FOUND)) {
Expand All @@ -196,7 +196,7 @@ private SplitResult getTreatmentWithConfigWithoutMetrics(String split, Map<Strin
evaluationResult.getTreatment(),
(mLabelsEnabled ? evaluationResult.getLabel() : null),
evaluationResult.getChangeNumber(),
attributes
mergedAttributes
);

return splitResult;
Expand All @@ -217,7 +217,7 @@ private Map<String, SplitResult> getTreatmentsWithConfigWithoutMetrics(List<Stri
return results;
}

Map<String, Object> mergedAttributes = mAttributesMerger.merge(mAttributesManager.getAllAttributes(), attributes);
final Map<String, Object> mergedAttributes = mAttributesMerger.merge(mAttributesManager.getAllAttributes(), attributes);
for (String split : splits) {
errorInfo = mSplitValidator.validateName(split);
if (errorInfo != null) {
Expand All @@ -243,7 +243,7 @@ private Map<String, SplitResult> getTreatmentsWithConfigWithoutMetrics(List<Stri
result.getTreatment(),
(mLabelsEnabled ? result.getLabel() : null),
result.getChangeNumber(),
attributes);
mergedAttributes);
}

return results;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,35 +83,6 @@ public void EventIsPassedDownToChildrenIfRegisteredAfterEmission() {
verify(newMockChildEventsManager).notifyInternalEvent(SplitInternalEvent.SPLITS_FETCHED);
}

@Test
public void EventIsNotDuplicated() {
ISplitEventsManager firstEventsManager = mock(ISplitEventsManager.class);
ISplitEventsManager secondEventsManager = mock(ISplitEventsManager.class);

Thread thread0 = new Thread(() -> mEventsManager.registerEventsManager(new Key("first", "bucketing"), firstEventsManager));
Thread thread1 = new Thread(() -> mEventsManager.registerEventsManager(new Key("second", "bucketing"), secondEventsManager));

Thread thread4 = new Thread(() -> mEventsManager.notifyInternalEvent(SplitInternalEvent.SPLITS_FETCHED));
Thread thread5 = new Thread(this::delay);

thread0.start();
thread1.start();
thread4.start();
thread5.start();

try {
thread0.join();
thread1.join();
thread4.join();
thread5.join();
} catch (InterruptedException e) {
e.printStackTrace();
}

verify(firstEventsManager, times(1)).notifyInternalEvent(SplitInternalEvent.SPLITS_FETCHED);
verify(secondEventsManager, times(1)).notifyInternalEvent(SplitInternalEvent.SPLITS_FETCHED);
}

private void delay() {
boolean shouldStop = false;
long maxExecutionTime = System.currentTimeMillis() + 1000;
Expand Down

0 comments on commit 7c409bf

Please sign in to comment.