Skip to content

Commit 1fae45f

Browse files
authored
Merge pull request #558 from splitio/rbs-fix-exlcuded-arrays
fix empty arrays in excluded
2 parents bca3958 + 0b2813d commit 1fae45f

File tree

2 files changed

+45
-4
lines changed

2 files changed

+45
-4
lines changed

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@ public static RuleBasedSegmentsToUpdate processRuleBasedSegmentChanges(RuleBased
2222
List<String> toRemove = new ArrayList<>();
2323
Set<String> segments = new HashSet<>();
2424
for (RuleBasedSegment ruleBasedSegment : ruleBasedSegments) {
25-
if (ruleBasedSegment.excluded == null)
26-
{
27-
ruleBasedSegment.excluded = createEmptyExcluded();
28-
}
25+
ruleBasedSegment.excluded = checkExcluded(ruleBasedSegment.excluded);
2926
if (ruleBasedSegment.status != Status.ACTIVE) {
3027
// archive.
3128
toRemove.add(ruleBasedSegment.name);
@@ -49,4 +46,16 @@ private static Excluded createEmptyExcluded() {
4946
return excluded;
5047
}
5148

49+
private static Excluded checkExcluded(Excluded excluded) {
50+
if (excluded == null) {
51+
excluded = createEmptyExcluded();
52+
}
53+
if (excluded.segments == null) {
54+
excluded.segments = new ArrayList<>();
55+
}
56+
if (excluded.keys == null) {
57+
excluded.keys = new ArrayList<>();
58+
}
59+
return excluded;
60+
}
5261
}

client/src/test/java/io/split/engine/experiments/ParsedRuleBasedSegmentTest.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,37 @@ public void worksWithoutExcluded() {
4646
RuleBasedSegmentsToUpdate toUpdate = processRuleBasedSegmentChanges(parser, change.ruleBasedSegments.d);
4747
Assert.assertTrue(toUpdate.getToAdd().get(0).excludedKeys().isEmpty());
4848
Assert.assertTrue(toUpdate.getToAdd().get(0).excludedSegments().isEmpty());
49+
50+
load = "{\"ff\":{\"s\":-1,\"t\":-1,\"d\":[]},\"rbs\":{\"s\":-1,\"t\":1457726098069,\"d\":[{ \"changeNumber\": 123, \"trafficTypeName\": \"user\", \"name\": \"some_name\","
51+
+ "\"status\": \"ACTIVE\",\"excluded\":{\"segments\":[\"segment1\"]},\"conditions\": [{\"contitionType\": \"ROLLOUT\","
52+
+ "\"label\": \"some_label\", \"matcherGroup\": { \"matchers\": [{ \"matcherType\": \"ALL_KEYS\", \"negate\": false}],"
53+
+ "\"combiner\": \"AND\"}}]}]}}";
54+
change = Json.fromJson(load, SplitChange.class);
55+
toUpdate = processRuleBasedSegmentChanges(parser, change.ruleBasedSegments.d);
56+
Assert.assertTrue(toUpdate.getToAdd().get(0).excludedKeys().isEmpty());
57+
58+
load = "{\"ff\":{\"s\":-1,\"t\":-1,\"d\":[]},\"rbs\":{\"s\":-1,\"t\":1457726098069,\"d\":[{ \"changeNumber\": 123, \"trafficTypeName\": \"user\", \"name\": \"some_name\","
59+
+ "\"status\": \"ACTIVE\",\"excluded\":{\"segments\":[\"segment1\"], \"keys\":null},\"conditions\": [{\"contitionType\": \"ROLLOUT\","
60+
+ "\"label\": \"some_label\", \"matcherGroup\": { \"matchers\": [{ \"matcherType\": \"ALL_KEYS\", \"negate\": false}],"
61+
+ "\"combiner\": \"AND\"}}]}]}}";
62+
change = Json.fromJson(load, SplitChange.class);
63+
toUpdate = processRuleBasedSegmentChanges(parser, change.ruleBasedSegments.d);
64+
Assert.assertTrue(toUpdate.getToAdd().get(0).excludedKeys().isEmpty());
65+
66+
load = "{\"ff\":{\"s\":-1,\"t\":-1,\"d\":[]},\"rbs\":{\"s\":-1,\"t\":1457726098069,\"d\":[{ \"changeNumber\": 123, \"trafficTypeName\": \"user\", \"name\": \"some_name\","
67+
+ "\"status\": \"ACTIVE\",\"excluded\":{\"keys\":[\"key1\"]},\"conditions\": [{\"contitionType\": \"ROLLOUT\","
68+
+ "\"label\": \"some_label\", \"matcherGroup\": { \"matchers\": [{ \"matcherType\": \"ALL_KEYS\", \"negate\": false}],"
69+
+ "\"combiner\": \"AND\"}}]}]}}";
70+
change = Json.fromJson(load, SplitChange.class);
71+
toUpdate = processRuleBasedSegmentChanges(parser, change.ruleBasedSegments.d);
72+
Assert.assertTrue(toUpdate.getToAdd().get(0).excludedSegments().isEmpty());
73+
74+
load = "{\"ff\":{\"s\":-1,\"t\":-1,\"d\":[]},\"rbs\":{\"s\":-1,\"t\":1457726098069,\"d\":[{ \"changeNumber\": 123, \"trafficTypeName\": \"user\", \"name\": \"some_name\","
75+
+ "\"status\": \"ACTIVE\",\"excluded\":{\"segments\":null, \"keys\":[\"key1\"]},\"conditions\": [{\"contitionType\": \"ROLLOUT\","
76+
+ "\"label\": \"some_label\", \"matcherGroup\": { \"matchers\": [{ \"matcherType\": \"ALL_KEYS\", \"negate\": false}],"
77+
+ "\"combiner\": \"AND\"}}]}]}}";
78+
change = Json.fromJson(load, SplitChange.class);
79+
toUpdate = processRuleBasedSegmentChanges(parser, change.ruleBasedSegments.d);
80+
Assert.assertTrue(toUpdate.getToAdd().get(0).excludedSegments().isEmpty());
4981
}
5082
}

0 commit comments

Comments
 (0)