From 03780e4a1bbbe62696b3656cdb6bc0ef639d0072 Mon Sep 17 00:00:00 2001 From: Nadia Mayor Date: Fri, 22 Sep 2023 15:41:03 -0300 Subject: [PATCH] [SDKS-7523] Add sets in SplitView --- .../java/io/split/client/api/SplitView.java | 4 +++ .../io/split/client/SplitManagerImplTest.java | 31 +++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/client/src/main/java/io/split/client/api/SplitView.java b/client/src/main/java/io/split/client/api/SplitView.java index c053c8950..e7c0c8afc 100644 --- a/client/src/main/java/io/split/client/api/SplitView.java +++ b/client/src/main/java/io/split/client/api/SplitView.java @@ -24,6 +24,7 @@ public class SplitView { public List treatments; public long changeNumber; public Map configs; + public List sets = new ArrayList<>(); public static SplitView fromParsedSplit(ParsedSplit parsedSplit) { SplitView splitView = new SplitView(); @@ -31,6 +32,9 @@ public static SplitView fromParsedSplit(ParsedSplit parsedSplit) { splitView.trafficType = parsedSplit.trafficTypeName(); splitView.killed = parsedSplit.killed(); splitView.changeNumber = parsedSplit.changeNumber(); + if (parsedSplit.flagSets() != null) { + splitView.sets = new ArrayList<>(parsedSplit.flagSets()); + } Set treatments = new HashSet(); for (ParsedCondition condition : parsedSplit.parsedConditions()) { diff --git a/client/src/test/java/io/split/client/SplitManagerImplTest.java b/client/src/test/java/io/split/client/SplitManagerImplTest.java index e393ceb27..90cdb868f 100644 --- a/client/src/test/java/io/split/client/SplitManagerImplTest.java +++ b/client/src/test/java/io/split/client/SplitManagerImplTest.java @@ -17,6 +17,7 @@ import org.junit.Test; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -185,6 +186,36 @@ public void block_until_ready_times_when_sdk_is_not_ready() throws TimeoutExcept verify(TELEMETRY_STORAGE, times(1)).recordBURTimeout(); } + @Test + public void splitCallWithExistentSets() { + String existent = "existent"; + SplitCacheConsumer splitCacheConsumer = mock(SplitCacheConsumer.class); + ParsedSplit response = ParsedSplit.createParsedSplitForTests("FeatureName", 123, true, "off", + Lists.newArrayList(getTestCondition("off")), "traffic", 456L, 1, new HashSet<>(Arrays.asList("set1", "set2", "set3"))); + when(splitCacheConsumer.get(existent)).thenReturn(response); + + SplitManagerImpl splitManager = new SplitManagerImpl(splitCacheConsumer, + mock(SplitClientConfig.class), + mock(SDKReadinessGates.class), TELEMETRY_STORAGE); + SplitView theOne = splitManager.split(existent); + Assert.assertEquals(response.flagSets().size(), theOne.sets.size()); + } + + @Test + public void splitCallWithEmptySets() { + String existent = "existent"; + SplitCacheConsumer splitCacheConsumer = mock(SplitCacheConsumer.class); + ParsedSplit response = ParsedSplit.createParsedSplitForTests("FeatureName", 123, true, "off", + Lists.newArrayList(getTestCondition("off")), "traffic", 456L, 1, null); + when(splitCacheConsumer.get(existent)).thenReturn(response); + + SplitManagerImpl splitManager = new SplitManagerImpl(splitCacheConsumer, + mock(SplitClientConfig.class), + mock(SDKReadinessGates.class), TELEMETRY_STORAGE); + SplitView theOne = splitManager.split(existent); + Assert.assertEquals(0, theOne.sets.size()); + } + private ParsedCondition getTestCondition(String treatment) { return ParsedCondition.createParsedConditionForTests(CombiningMatcher.of(new AllKeysMatcher()), Lists.newArrayList(ConditionsTestUtil.partition(treatment, 10))); }