Skip to content

Commit df822cd

Browse files
committed
Fixed excluded null issue
1 parent ae9c911 commit df822cd

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

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

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

3+
import io.split.client.dtos.Excluded;
34
import io.split.client.dtos.RuleBasedSegment;
45
import io.split.client.dtos.Status;
56
import io.split.engine.experiments.ParsedRuleBasedSegment;
@@ -21,6 +22,10 @@ public static RuleBasedSegmentsToUpdate processRuleBasedSegmentChanges(RuleBased
2122
List<String> toRemove = new ArrayList<>();
2223
Set<String> segments = new HashSet<>();
2324
for (RuleBasedSegment ruleBasedSegment : ruleBasedSegments) {
25+
if (ruleBasedSegment.excluded == null)
26+
{
27+
ruleBasedSegment.excluded = createEmptyExcluded();
28+
}
2429
if (ruleBasedSegment.status != Status.ACTIVE) {
2530
// archive.
2631
toRemove.add(ruleBasedSegment.name);
@@ -37,4 +42,11 @@ public static RuleBasedSegmentsToUpdate processRuleBasedSegmentChanges(RuleBased
3742
return new RuleBasedSegmentsToUpdate(toAdd, toRemove, segments);
3843
}
3944

45+
private static Excluded createEmptyExcluded() {
46+
Excluded excluded = new Excluded();
47+
excluded.segments = new ArrayList<>();
48+
excluded.keys = new ArrayList<>();
49+
return excluded;
50+
}
51+
4052
}

client/src/main/java/io/split/engine/experiments/RuleBasedSegmentParser.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.google.common.collect.Lists;
44
import io.split.client.dtos.Condition;
5-
import io.split.client.dtos.Partition;
65
import io.split.client.dtos.RuleBasedSegment;
76
import io.split.engine.matchers.CombiningMatcher;
87
import org.slf4j.Logger;

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,20 @@
44
import com.google.common.collect.Sets;
55
import io.split.client.dtos.ConditionType;
66
import io.split.client.dtos.MatcherCombiner;
7+
import io.split.client.dtos.SplitChange;
8+
import io.split.client.utils.Json;
9+
import io.split.client.utils.RuleBasedSegmentsToUpdate;
710
import io.split.engine.matchers.AttributeMatcher;
811
import io.split.engine.matchers.CombiningMatcher;
912
import io.split.engine.matchers.UserDefinedSegmentMatcher;
1013

1114
import org.junit.Assert;
1215
import org.junit.Test;
1316

17+
import java.util.ArrayList;
18+
19+
import static io.split.client.utils.RuleBasedSegmentProcessor.processRuleBasedSegmentChanges;
20+
1421
public class ParsedRuleBasedSegmentTest {
1522

1623
@Test
@@ -27,4 +34,17 @@ public void works() {
2734
parsedRuleBasedSegment.parsedConditions());
2835
Assert.assertEquals(123, parsedRuleBasedSegment.changeNumber());
2936
}
37+
38+
@Test
39+
public void worksWithoutExcluded() {
40+
RuleBasedSegmentParser parser = new RuleBasedSegmentParser();
41+
String load = "{\"ff\":{\"s\":-1,\"t\":-1,\"d\":[]},\"rbs\":{\"s\":-1,\"t\":1457726098069,\"d\":[{ \"changeNumber\": 123, \"trafficTypeName\": \"user\", \"name\": \"some_name\","
42+
+ "\"status\": \"ACTIVE\",\"conditions\": [{\"contitionType\": \"ROLLOUT\","
43+
+ "\"label\": \"some_label\", \"matcherGroup\": { \"matchers\": [{ \"matcherType\": \"ALL_KEYS\", \"negate\": false}],"
44+
+ "\"combiner\": \"AND\"}}]}]}}";
45+
SplitChange change = Json.fromJson(load, SplitChange.class);
46+
RuleBasedSegmentsToUpdate toUpdate = processRuleBasedSegmentChanges(parser, change.ruleBasedSegments.d);
47+
Assert.assertEquals(new ArrayList<>(), toUpdate.getToAdd().get(0).excludedKeys());
48+
Assert.assertEquals(new ArrayList<>(), toUpdate.getToAdd().get(0).excludedSegments());
49+
}
3050
}

0 commit comments

Comments
 (0)