Skip to content

Commit 166146b

Browse files
committed
pr feedback
1 parent e10331c commit 166146b

File tree

5 files changed

+39
-41
lines changed

5 files changed

+39
-41
lines changed

client/src/main/java/io/split/client/SplitClientImpl.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
import io.split.client.api.Key;
55
import io.split.client.api.SplitResult;
66
import io.split.client.dtos.Event;
7-
import io.split.client.dtos.TreatmentLabelAndChangeNumber;
87
import io.split.client.exceptions.ChangeNumberExceptionWrapper;
98
import io.split.client.impressions.Impression;
109
import io.split.client.impressions.ImpressionsManager;
1110
import io.split.engine.evaluator.Evaluator;
1211
import io.split.engine.SDKReadinessGates;
12+
import io.split.engine.evaluator.EvaluatorImp;
1313
import io.split.engine.experiments.SplitFetcher;
1414
import io.split.engine.metrics.Metrics;
1515
import io.split.grammar.Treatments;
@@ -315,7 +315,7 @@ private SplitResult getTreatmentWithConfigInternal(String label, String matching
315315

316316
long start = System.currentTimeMillis();
317317

318-
TreatmentLabelAndChangeNumber result = getTreatmentResultWithoutImpressions(matchingKey, bucketingKey, split, attributes);
318+
EvaluatorImp.TreatmentLabelAndChangeNumber result = getTreatmentResultWithoutImpressions(matchingKey, bucketingKey, split, attributes);
319319

320320
recordStats(
321321
matchingKey,
@@ -350,15 +350,15 @@ private void recordStats(String matchingKey, String bucketingKey, String split,
350350
}
351351
}
352352

353-
private TreatmentLabelAndChangeNumber getTreatmentResultWithoutImpressions(String matchingKey, String bucketingKey, String split, Map<String, Object> attributes) {
354-
TreatmentLabelAndChangeNumber result;
353+
private EvaluatorImp.TreatmentLabelAndChangeNumber getTreatmentResultWithoutImpressions(String matchingKey, String bucketingKey, String split, Map<String, Object> attributes) {
354+
EvaluatorImp.TreatmentLabelAndChangeNumber result;
355355
try {
356356
result = _evaluator.evaluateFeature(matchingKey, bucketingKey, split, attributes, this);
357357
} catch (ChangeNumberExceptionWrapper e) {
358-
result = new TreatmentLabelAndChangeNumber(Treatments.CONTROL, EXCEPTION, e.changeNumber());
358+
result = new EvaluatorImp.TreatmentLabelAndChangeNumber(Treatments.CONTROL, EXCEPTION, e.changeNumber());
359359
_log.error("Exception", e.wrappedException());
360360
} catch (Exception e) {
361-
result = new TreatmentLabelAndChangeNumber(Treatments.CONTROL, EXCEPTION);
361+
result = new EvaluatorImp.TreatmentLabelAndChangeNumber(Treatments.CONTROL, EXCEPTION);
362362
_log.error("Exception", e);
363363
}
364364

client/src/main/java/io/split/client/dtos/TreatmentLabelAndChangeNumber.java

Lines changed: 0 additions & 23 deletions
This file was deleted.
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
package io.split.engine.evaluator;
22

33
import io.split.client.SplitClientImpl;
4-
import io.split.client.dtos.TreatmentLabelAndChangeNumber;
54
import io.split.client.exceptions.ChangeNumberExceptionWrapper;
65

76
import java.util.Map;
87

98
public interface Evaluator {
10-
TreatmentLabelAndChangeNumber evaluateFeature(String matchingKey, String bucketingKey, String split, Map<String, Object> attributes, SplitClientImpl splitClient) throws ChangeNumberExceptionWrapper;
9+
EvaluatorImp.TreatmentLabelAndChangeNumber evaluateFeature(String matchingKey, String bucketingKey, String split, Map<String, Object> attributes, SplitClientImpl splitClient) throws ChangeNumberExceptionWrapper;
1110
}

client/src/main/java/io/split/engine/evaluator/EvaluatorImp.java

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import io.split.client.SplitClientImpl;
44
import io.split.client.dtos.ConditionType;
5-
import io.split.client.dtos.TreatmentLabelAndChangeNumber;
65
import io.split.client.exceptions.ChangeNumberExceptionWrapper;
76
import io.split.engine.SDKReadinessGates;
87
import io.split.engine.experiments.ParsedCondition;
@@ -15,6 +14,8 @@
1514

1615
import java.util.Map;
1716

17+
import static com.google.common.base.Preconditions.checkNotNull;
18+
1819
public class EvaluatorImp implements Evaluator {
1920
private static final String NOT_IN_SPLIT = "not in split";
2021
private static final String DEFAULT_RULE = "default rule";
@@ -28,8 +29,8 @@ public class EvaluatorImp implements Evaluator {
2829

2930
public EvaluatorImp(SDKReadinessGates gates,
3031
SplitFetcher splitFetcher) {
31-
_gates = gates;
32-
_splitFetcher = splitFetcher;
32+
_gates = checkNotNull(gates);
33+
_splitFetcher = checkNotNull(splitFetcher);
3334
}
3435

3536
@Override
@@ -104,4 +105,26 @@ private TreatmentLabelAndChangeNumber getTreatment(String matchingKey, String bu
104105
throw new ChangeNumberExceptionWrapper(e, parsedSplit.changeNumber());
105106
}
106107
}
108+
109+
public static final class TreatmentLabelAndChangeNumber {
110+
public final String treatment;
111+
public final String label;
112+
public final Long changeNumber;
113+
public final String configurations;
114+
115+
public TreatmentLabelAndChangeNumber(String treatment, String label) {
116+
this(treatment, label, null, null);
117+
}
118+
119+
public TreatmentLabelAndChangeNumber(String treatment, String label, Long changeNumber) {
120+
this(treatment, label, changeNumber, null);
121+
}
122+
123+
public TreatmentLabelAndChangeNumber(String treatment, String label, Long changeNumber, String configurations) {
124+
this.treatment = treatment;
125+
this.label = label;
126+
this.changeNumber = changeNumber;
127+
this.configurations = configurations;
128+
}
129+
}
107130
}

client/src/test/java/io/split/engine/evaluator/EvaluatorTest.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import io.split.client.SplitFactory;
77
import io.split.client.dtos.ConditionType;
88
import io.split.client.dtos.Partition;
9-
import io.split.client.dtos.TreatmentLabelAndChangeNumber;
109
import io.split.client.exceptions.ChangeNumberExceptionWrapper;
1110
import io.split.client.impressions.ImpressionsManager;
1211
import io.split.engine.SDKReadinessGates;
@@ -61,7 +60,7 @@ public void before() {
6160
public void evaluateWhenSplitNameDoesNotExistReturnControl() throws ChangeNumberExceptionWrapper {
6261
Mockito.when(_splitFetcher.fetch(SplitName)).thenReturn(null);
6362

64-
TreatmentLabelAndChangeNumber result = _evaluator.evaluateFeature(MatchingKey, BucketingKey, SplitName, null, _splitClient);
63+
EvaluatorImp.TreatmentLabelAndChangeNumber result = _evaluator.evaluateFeature(MatchingKey, BucketingKey, SplitName, null, _splitClient);
6564

6665
assertEquals("control", result.treatment);
6766
assertEquals("definition not found", result.label);
@@ -72,7 +71,7 @@ public void evaluateWhenSplitIsKilledReturnDefaultTreatment() throws ChangeNumbe
7271
ParsedSplit split = ParsedSplit.createParsedSplitForTests(SplitName, 0, true, DefaultTreatmentValue, _conditions, TrafficTypeValue, ChangeNumber, 2);
7372
Mockito.when(_splitFetcher.fetch(SplitName)).thenReturn(split);
7473

75-
TreatmentLabelAndChangeNumber result = _evaluator.evaluateFeature(MatchingKey, BucketingKey, SplitName, null, _splitClient);
74+
EvaluatorImp.TreatmentLabelAndChangeNumber result = _evaluator.evaluateFeature(MatchingKey, BucketingKey, SplitName, null, _splitClient);
7675

7776
assertEquals(DefaultTreatmentValue, result.treatment);
7877
assertEquals("killed", result.label);
@@ -84,7 +83,7 @@ public void evaluateWithoutConditionsReturnDefaultTreatment() throws ChangeNumbe
8483
ParsedSplit split = ParsedSplit.createParsedSplitForTests(SplitName, 0, false, DefaultTreatmentValue, _conditions, TrafficTypeValue, ChangeNumber, 2);
8584
Mockito.when(_splitFetcher.fetch(SplitName)).thenReturn(split);
8685

87-
TreatmentLabelAndChangeNumber result = _evaluator.evaluateFeature(MatchingKey, BucketingKey, SplitName, null, _splitClient);
86+
EvaluatorImp.TreatmentLabelAndChangeNumber result = _evaluator.evaluateFeature(MatchingKey, BucketingKey, SplitName, null, _splitClient);
8887

8988
assertEquals(DefaultTreatmentValue, result.treatment);
9089
assertEquals("default rule", result.label);
@@ -105,7 +104,7 @@ public void evaluateWithRollOutConditionBucketIsBiggerTrafficAllocationReturnDef
105104
Mockito.when(_splitFetcher.fetch(SplitName)).thenReturn(split);
106105
Mockito.when(condition.matcher().match(MatchingKey, BucketingKey, null, _splitClient)).thenReturn(true);
107106

108-
TreatmentLabelAndChangeNumber result = _evaluator.evaluateFeature(MatchingKey, BucketingKey, SplitName, null, _splitClient);
107+
EvaluatorImp.TreatmentLabelAndChangeNumber result = _evaluator.evaluateFeature(MatchingKey, BucketingKey, SplitName, null, _splitClient);
109108

110109
assertEquals(DefaultTreatmentValue, result.treatment);
111110
assertEquals("not in split", result.label);
@@ -126,7 +125,7 @@ public void evaluateWithRollOutConditionTrafficAllocationIsBiggerBucketReturnTre
126125
Mockito.when(_splitFetcher.fetch(SplitName)).thenReturn(split);
127126
Mockito.when(condition.matcher().match(MatchingKey, BucketingKey, null, _splitClient)).thenReturn(true);
128127

129-
TreatmentLabelAndChangeNumber result = _evaluator.evaluateFeature(MatchingKey, BucketingKey, SplitName, null, _splitClient);
128+
EvaluatorImp.TreatmentLabelAndChangeNumber result = _evaluator.evaluateFeature(MatchingKey, BucketingKey, SplitName, null, _splitClient);
130129

131130
assertEquals(TreatmentValue, result.treatment);
132131
assertEquals(TestLabelValue, result.label);
@@ -147,7 +146,7 @@ public void evaluateWithWhitelistConditionReturnTreatment() throws ChangeNumberE
147146
Mockito.when(_splitFetcher.fetch(SplitName)).thenReturn(split);
148147
Mockito.when(condition.matcher().match(MatchingKey, BucketingKey, null, _splitClient)).thenReturn(true);
149148

150-
TreatmentLabelAndChangeNumber result = _evaluator.evaluateFeature(MatchingKey, BucketingKey, SplitName, null, _splitClient);
149+
EvaluatorImp.TreatmentLabelAndChangeNumber result = _evaluator.evaluateFeature(MatchingKey, BucketingKey, SplitName, null, _splitClient);
151150

152151
assertEquals(TreatmentValue, result.treatment);
153152
assertEquals("test whitelist label", result.label);

0 commit comments

Comments
 (0)