Skip to content

Commit 8d67468

Browse files
committed
polishing
1 parent affc36a commit 8d67468

20 files changed

+102
-84
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ private Spec() {
66
// restrict instantiation
77
}
88

9-
// TODO: Change the schema to 1.3 when updating splitclient
109
public static final String SPEC_1_3 = "1.3";
1110
public static final String SPEC_1_1 = "1.1";
1211
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
public final class HttpSplitChangeFetcher implements SplitChangeFetcher {
3434
private static final Logger _log = LoggerFactory.getLogger(HttpSplitChangeFetcher.class);
3535

36-
private final Object _lock = new Object();
3736
private static final String SINCE = "since";
3837
private static final String RB_SINCE = "rbSince";
3938
private static final String TILL = "till";

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ private SplitChange processSplitChange(SplitChange splitChange, long changeNumbe
8080
return splitChangeToProcess;
8181
}
8282

83-
private byte[] getStringDigest(String Json) throws NoSuchAlgorithmException {
83+
private byte[] getStringDigest(String json) throws NoSuchAlgorithmException {
8484
MessageDigest digest = MessageDigest.getInstance("SHA-1");
8585
digest.reset();
86-
digest.update(Json.getBytes());
86+
digest.update(json.getBytes());
8787
// calculate the json sha
8888
return digest.digest();
8989
}

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.io.FileReader;
2020
import java.util.ArrayList;
2121
import java.util.HashMap;
22+
import java.util.List;
2223
import java.util.Optional;
2324

2425
public class LegacyLocalhostSplitChangeFetcher implements SplitChangeFetcher {
@@ -70,12 +71,7 @@ public SplitChange fetch(long since, long sinceRBS, FetchOptions options) {
7071
split.trafficAllocation = LocalhostConstants.SIZE_100;
7172
split.trafficAllocationSeed = LocalhostConstants.SIZE_1;
7273

73-
Condition condition;
74-
if (featureTreatment.length == 2) {
75-
condition = LocalhostSanitizer.createCondition(null, featureTreatment[1]);
76-
} else {
77-
condition = LocalhostSanitizer.createCondition(featureTreatment[2], featureTreatment[1]);
78-
}
74+
Condition condition = checkCondition(featureTreatment);
7975
if(condition.conditionType != ConditionType.ROLLOUT){
8076
split.conditions.add(0, condition);
8177
} else {
@@ -103,4 +99,14 @@ public SplitChange fetch(long since, long sinceRBS, FetchOptions options) {
10399
throw new IllegalStateException("Problem fetching splitChanges: " + e.getMessage(), e);
104100
}
105101
}
102+
103+
private Condition checkCondition(String[] featureTreatment) {
104+
Condition condition;
105+
if (featureTreatment.length == 2) {
106+
condition = LocalhostSanitizer.createCondition(null, featureTreatment[1]);
107+
} else {
108+
condition = LocalhostSanitizer.createCondition(featureTreatment[2], featureTreatment[1]);
109+
}
110+
return condition;
111+
}
106112
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ protected SplitFactoryImpl(SplitClientConfig config) {
403403
SegmentCache segmentCache = new SegmentCacheInMemoryImpl();
404404
FlagSetsFilter flagSetsFilter = new FlagSetsFilterImpl(config.getSetsFilter());
405405
SplitCache splitCache = new InMemoryCacheImp(flagSetsFilter);
406-
RuleBasedSegmentCache _ruleBasedSegmentCache = new RuleBasedSegmentCacheInMemoryImp();
406+
RuleBasedSegmentCache ruleBasedSegmentCache = new RuleBasedSegmentCacheInMemoryImp();
407407
_splitCache = splitCache;
408408
_gates = new SDKReadinessGates();
409409
_segmentCache = segmentCache;
@@ -422,15 +422,15 @@ protected SplitFactoryImpl(SplitClientConfig config) {
422422
_telemetryStorageProducer,
423423
_splitCache,
424424
config.getThreadFactory(),
425-
_ruleBasedSegmentCache);
425+
ruleBasedSegmentCache);
426426

427427
// SplitFetcher
428428
SplitChangeFetcher splitChangeFetcher = createSplitChangeFetcher(config);
429429
SplitParser splitParser = new SplitParser();
430430
RuleBasedSegmentParser ruleBasedSegmentParser = new RuleBasedSegmentParser();
431431

432432
_splitFetcher = new SplitFetcherImp(splitChangeFetcher, splitParser, splitCache, _telemetryStorageProducer,
433-
flagSetsFilter, ruleBasedSegmentParser, _ruleBasedSegmentCache);
433+
flagSetsFilter, ruleBasedSegmentParser, ruleBasedSegmentCache);
434434

435435
// SplitSynchronizationTask
436436
_splitSynchronizationTask = new SplitSynchronizationTask(_splitFetcher, splitCache,
@@ -442,7 +442,7 @@ protected SplitFactoryImpl(SplitClientConfig config) {
442442
_impressionsManager, null, null, null);
443443

444444
// Evaluator
445-
_evaluator = new EvaluatorImp(splitCache, segmentCache, _ruleBasedSegmentCache);
445+
_evaluator = new EvaluatorImp(splitCache, segmentCache, ruleBasedSegmentCache);
446446

447447
EventsStorage eventsStorage = new NoopEventsStorageImp();
448448

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package io.split.client.dtos;
22

3-
import java.util.ArrayList;
43
import java.util.List;
54

65
public class ChangeDto<T> {

client/src/main/java/io/split/client/utils/LocalhostSanitizer.java

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,41 @@ private LocalhostSanitizer() {
3030
}
3131

3232
public static SplitChange sanitization(SplitChange splitChange) {
33-
SecureRandom random = new SecureRandom();
34-
List<Split> splitsToRemove = new ArrayList<>();
35-
List<RuleBasedSegment> ruleBasedSegmentsToRemove = new ArrayList<>();
3633
splitChange = sanitizeTillAndSince(splitChange);
34+
splitChange.featureFlags.d = sanitizeFeatureFlags(splitChange.featureFlags.d);
35+
splitChange.ruleBasedSegments.d = sanitizeRuleBasedSegments(splitChange.ruleBasedSegments.d);
36+
37+
return splitChange;
38+
}
39+
40+
private static List<RuleBasedSegment> sanitizeRuleBasedSegments(List<RuleBasedSegment> ruleBasedSegments) {
41+
List<RuleBasedSegment> ruleBasedSegmentsToRemove = new ArrayList<>();
42+
if (ruleBasedSegments != null) {
43+
for (RuleBasedSegment ruleBasedSegment : ruleBasedSegments) {
44+
if (ruleBasedSegment.name == null) {
45+
ruleBasedSegmentsToRemove.add(ruleBasedSegment);
46+
continue;
47+
}
48+
ruleBasedSegment.trafficTypeName = sanitizeIfNullOrEmpty(ruleBasedSegment.trafficTypeName, LocalhostConstants.USER);
49+
ruleBasedSegment.status = sanitizeStatus(ruleBasedSegment.status);
50+
ruleBasedSegment.changeNumber = sanitizeChangeNumber(ruleBasedSegment.changeNumber, 0);
51+
ruleBasedSegment.conditions = sanitizeConditions((ArrayList<Condition>) ruleBasedSegment.conditions, false,
52+
ruleBasedSegment.trafficTypeName);
53+
ruleBasedSegment.excluded.segments = sanitizeExcluded((ArrayList) ruleBasedSegment.excluded.segments);
54+
ruleBasedSegment.excluded.keys = sanitizeExcluded((ArrayList) ruleBasedSegment.excluded.keys);
55+
}
56+
ruleBasedSegments.removeAll(ruleBasedSegmentsToRemove);
57+
} else {
58+
ruleBasedSegments = new ArrayList<>();
59+
}
60+
return ruleBasedSegments;
61+
}
3762

38-
if (splitChange.featureFlags.d != null) {
39-
for (Split split : splitChange.featureFlags.d) {
63+
private static List<Split> sanitizeFeatureFlags(List<Split> featureFlags) {
64+
List<Split> splitsToRemove = new ArrayList<>();
65+
SecureRandom random = new SecureRandom();
66+
if (featureFlags != null) {
67+
for (Split split : featureFlags) {
4068
if (split.name == null) {
4169
splitsToRemove.add(split);
4270
continue;
@@ -60,31 +88,11 @@ public static SplitChange sanitization(SplitChange splitChange) {
6088
}
6189
split.conditions = sanitizeConditions((ArrayList<Condition>) split.conditions, false, split.trafficTypeName);
6290
}
63-
splitChange.featureFlags.d.removeAll(splitsToRemove);
91+
featureFlags.removeAll(splitsToRemove);
6492
} else {
65-
splitChange.featureFlags.d = new ArrayList<>();
93+
featureFlags = new ArrayList<>();
6694
}
67-
68-
if (splitChange.ruleBasedSegments.d != null) {
69-
for (RuleBasedSegment ruleBasedSegment : splitChange.ruleBasedSegments.d) {
70-
if (ruleBasedSegment.name == null) {
71-
ruleBasedSegmentsToRemove.add(ruleBasedSegment);
72-
continue;
73-
}
74-
ruleBasedSegment.trafficTypeName = sanitizeIfNullOrEmpty(ruleBasedSegment.trafficTypeName, LocalhostConstants.USER);
75-
ruleBasedSegment.status = sanitizeStatus(ruleBasedSegment.status);
76-
ruleBasedSegment.changeNumber = sanitizeChangeNumber(ruleBasedSegment.changeNumber, 0);
77-
ruleBasedSegment.conditions = sanitizeConditions((ArrayList<Condition>) ruleBasedSegment.conditions, false,
78-
ruleBasedSegment.trafficTypeName);
79-
ruleBasedSegment.excluded.segments = sanitizeExcluded((ArrayList) ruleBasedSegment.excluded.segments);
80-
ruleBasedSegment.excluded.keys = sanitizeExcluded((ArrayList) ruleBasedSegment.excluded.keys);
81-
}
82-
splitChange.ruleBasedSegments.d.removeAll(ruleBasedSegmentsToRemove);
83-
} else {
84-
splitChange.ruleBasedSegments.d = new ArrayList<>();
85-
}
86-
87-
return splitChange;
95+
return featureFlags;
8896
}
8997

9098
private static ArrayList<Condition> sanitizeConditions(ArrayList<Condition> conditions, boolean createPartition, String trafficTypeName) {

client/src/main/java/io/split/client/utils/RuleBasedSegmentProcessor.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
public class RuleBasedSegmentProcessor {
1717
private static final Logger _log = LoggerFactory.getLogger(RuleBasedSegmentProcessor.class);
1818

19+
private RuleBasedSegmentProcessor() {
20+
throw new IllegalStateException("Utility class");
21+
}
22+
1923
public static RuleBasedSegmentsToUpdate processRuleBasedSegmentChanges(RuleBasedSegmentParser ruleBasedSegmentParser,
2024
List<RuleBasedSegment> ruleBasedSegments) {
2125
List<ParsedRuleBasedSegment> toAdd = new ArrayList<>();
@@ -31,10 +35,10 @@ public static RuleBasedSegmentsToUpdate processRuleBasedSegmentChanges(RuleBased
3135
ParsedRuleBasedSegment parsedRuleBasedSegment = ruleBasedSegmentParser.parse(ruleBasedSegment);
3236
if (parsedRuleBasedSegment == null) {
3337
_log.debug(String.format("We could not parse the rule based segment definition for: %s", ruleBasedSegment.name));
34-
continue;
38+
} else {
39+
segments.addAll(parsedRuleBasedSegment.getSegmentsNames());
40+
toAdd.add(parsedRuleBasedSegment);
3541
}
36-
segments.addAll(parsedRuleBasedSegment.getSegmentsNames());
37-
toAdd.add(parsedRuleBasedSegment);
3842
}
3943
return new RuleBasedSegmentsToUpdate(toAdd, toRemove, segments);
4044
}

client/src/main/java/io/split/client/utils/RuleBasedSegmentsToUpdate.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package io.split.client.utils;
22

33
import io.split.engine.experiments.ParsedRuleBasedSegment;
4-
import io.split.engine.experiments.ParsedSplit;
54

65
import java.util.List;
76
import java.util.Set;

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,13 @@ public class EvaluatorImp implements Evaluator {
2424
private static final Logger _log = LoggerFactory.getLogger(EvaluatorImp.class);
2525

2626
private final SegmentCacheConsumer _segmentCacheConsumer;
27-
private final RuleBasedSegmentCacheConsumer _ruleBasedSegmentCacheConsumer;
2827
private final EvaluationContext _evaluationContext;
2928
private final SplitCacheConsumer _splitCacheConsumer;
3029

3130
public EvaluatorImp(SplitCacheConsumer splitCacheConsumer, SegmentCacheConsumer segmentCache,
3231
RuleBasedSegmentCacheConsumer ruleBasedSegmentCacheConsumer) {
3332
_splitCacheConsumer = checkNotNull(splitCacheConsumer);
3433
_segmentCacheConsumer = checkNotNull(segmentCache);
35-
_ruleBasedSegmentCacheConsumer = checkNotNull(ruleBasedSegmentCacheConsumer);
3634
_evaluationContext = new EvaluationContext(this, _segmentCacheConsumer, ruleBasedSegmentCacheConsumer);
3735
}
3836

0 commit comments

Comments
 (0)