From df822cd87bb4d6937fa92ffcdebb8c67cfb15810 Mon Sep 17 00:00:00 2001 From: Bilal Al-Shahwany Date: Tue, 29 Apr 2025 16:31:39 -0700 Subject: [PATCH 1/2] Fixed excluded null issue --- .../utils/RuleBasedSegmentProcessor.java | 12 +++++++++++ .../experiments/RuleBasedSegmentParser.java | 1 - .../ParsedRuleBasedSegmentTest.java | 20 +++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/client/src/main/java/io/split/client/utils/RuleBasedSegmentProcessor.java b/client/src/main/java/io/split/client/utils/RuleBasedSegmentProcessor.java index a92dd790..eebea3b1 100644 --- a/client/src/main/java/io/split/client/utils/RuleBasedSegmentProcessor.java +++ b/client/src/main/java/io/split/client/utils/RuleBasedSegmentProcessor.java @@ -1,5 +1,6 @@ package io.split.client.utils; +import io.split.client.dtos.Excluded; import io.split.client.dtos.RuleBasedSegment; import io.split.client.dtos.Status; import io.split.engine.experiments.ParsedRuleBasedSegment; @@ -21,6 +22,10 @@ public static RuleBasedSegmentsToUpdate processRuleBasedSegmentChanges(RuleBased List toRemove = new ArrayList<>(); Set segments = new HashSet<>(); for (RuleBasedSegment ruleBasedSegment : ruleBasedSegments) { + if (ruleBasedSegment.excluded == null) + { + ruleBasedSegment.excluded = createEmptyExcluded(); + } if (ruleBasedSegment.status != Status.ACTIVE) { // archive. toRemove.add(ruleBasedSegment.name); @@ -37,4 +42,11 @@ public static RuleBasedSegmentsToUpdate processRuleBasedSegmentChanges(RuleBased return new RuleBasedSegmentsToUpdate(toAdd, toRemove, segments); } + private static Excluded createEmptyExcluded() { + Excluded excluded = new Excluded(); + excluded.segments = new ArrayList<>(); + excluded.keys = new ArrayList<>(); + return excluded; + } + } \ No newline at end of file diff --git a/client/src/main/java/io/split/engine/experiments/RuleBasedSegmentParser.java b/client/src/main/java/io/split/engine/experiments/RuleBasedSegmentParser.java index 2036ab80..b67c5e35 100644 --- a/client/src/main/java/io/split/engine/experiments/RuleBasedSegmentParser.java +++ b/client/src/main/java/io/split/engine/experiments/RuleBasedSegmentParser.java @@ -2,7 +2,6 @@ import com.google.common.collect.Lists; import io.split.client.dtos.Condition; -import io.split.client.dtos.Partition; import io.split.client.dtos.RuleBasedSegment; import io.split.engine.matchers.CombiningMatcher; import org.slf4j.Logger; diff --git a/client/src/test/java/io/split/engine/experiments/ParsedRuleBasedSegmentTest.java b/client/src/test/java/io/split/engine/experiments/ParsedRuleBasedSegmentTest.java index d8b3efab..e3a3c920 100644 --- a/client/src/test/java/io/split/engine/experiments/ParsedRuleBasedSegmentTest.java +++ b/client/src/test/java/io/split/engine/experiments/ParsedRuleBasedSegmentTest.java @@ -4,6 +4,9 @@ import com.google.common.collect.Sets; import io.split.client.dtos.ConditionType; import io.split.client.dtos.MatcherCombiner; +import io.split.client.dtos.SplitChange; +import io.split.client.utils.Json; +import io.split.client.utils.RuleBasedSegmentsToUpdate; import io.split.engine.matchers.AttributeMatcher; import io.split.engine.matchers.CombiningMatcher; import io.split.engine.matchers.UserDefinedSegmentMatcher; @@ -11,6 +14,10 @@ import org.junit.Assert; import org.junit.Test; +import java.util.ArrayList; + +import static io.split.client.utils.RuleBasedSegmentProcessor.processRuleBasedSegmentChanges; + public class ParsedRuleBasedSegmentTest { @Test @@ -27,4 +34,17 @@ public void works() { parsedRuleBasedSegment.parsedConditions()); Assert.assertEquals(123, parsedRuleBasedSegment.changeNumber()); } + + @Test + public void worksWithoutExcluded() { + RuleBasedSegmentParser parser = new RuleBasedSegmentParser(); + String load = "{\"ff\":{\"s\":-1,\"t\":-1,\"d\":[]},\"rbs\":{\"s\":-1,\"t\":1457726098069,\"d\":[{ \"changeNumber\": 123, \"trafficTypeName\": \"user\", \"name\": \"some_name\"," + + "\"status\": \"ACTIVE\",\"conditions\": [{\"contitionType\": \"ROLLOUT\"," + + "\"label\": \"some_label\", \"matcherGroup\": { \"matchers\": [{ \"matcherType\": \"ALL_KEYS\", \"negate\": false}]," + + "\"combiner\": \"AND\"}}]}]}}"; + SplitChange change = Json.fromJson(load, SplitChange.class); + RuleBasedSegmentsToUpdate toUpdate = processRuleBasedSegmentChanges(parser, change.ruleBasedSegments.d); + Assert.assertEquals(new ArrayList<>(), toUpdate.getToAdd().get(0).excludedKeys()); + Assert.assertEquals(new ArrayList<>(), toUpdate.getToAdd().get(0).excludedSegments()); + } } \ No newline at end of file From 9c8d44a5a62d68bcdb08fa7a72765e91b981a963 Mon Sep 17 00:00:00 2001 From: Bilal Al-Shahwany <41021307+chillaq@users.noreply.github.com> Date: Wed, 30 Apr 2025 08:33:58 -0700 Subject: [PATCH 2/2] Update client/src/test/java/io/split/engine/experiments/ParsedRuleBasedSegmentTest.java Co-authored-by: gthea --- .../split/engine/experiments/ParsedRuleBasedSegmentTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/src/test/java/io/split/engine/experiments/ParsedRuleBasedSegmentTest.java b/client/src/test/java/io/split/engine/experiments/ParsedRuleBasedSegmentTest.java index e3a3c920..81f3b768 100644 --- a/client/src/test/java/io/split/engine/experiments/ParsedRuleBasedSegmentTest.java +++ b/client/src/test/java/io/split/engine/experiments/ParsedRuleBasedSegmentTest.java @@ -44,7 +44,7 @@ public void worksWithoutExcluded() { + "\"combiner\": \"AND\"}}]}]}}"; SplitChange change = Json.fromJson(load, SplitChange.class); RuleBasedSegmentsToUpdate toUpdate = processRuleBasedSegmentChanges(parser, change.ruleBasedSegments.d); - Assert.assertEquals(new ArrayList<>(), toUpdate.getToAdd().get(0).excludedKeys()); - Assert.assertEquals(new ArrayList<>(), toUpdate.getToAdd().get(0).excludedSegments()); + Assert.assertTrue(toUpdate.getToAdd().get(0).excludedKeys().isEmpty()); + Assert.assertTrue(toUpdate.getToAdd().get(0).excludedSegments().isEmpty()); } } \ No newline at end of file