Skip to content

Commit

Permalink
Merge pull request #441 from splitio/SDKS-7523
Browse files Browse the repository at this point in the history
[SDKS-7523] Add sets in SplitView
  • Loading branch information
nmayorsplit authored Sep 22, 2023
2 parents 07d62f1 + c891eb8 commit 56169c2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
2 changes: 2 additions & 0 deletions client/src/main/java/io/split/client/api/SplitView.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ public class SplitView {
public List<String> treatments;
public long changeNumber;
public Map<String, String> configs;
public List<String> sets;

public static SplitView fromParsedSplit(ParsedSplit parsedSplit) {
SplitView splitView = new SplitView();
splitView.name = parsedSplit.feature();
splitView.trafficType = parsedSplit.trafficTypeName();
splitView.killed = parsedSplit.killed();
splitView.changeNumber = parsedSplit.changeNumber();
splitView.sets = parsedSplit.flagSets() != null ? new ArrayList<>(parsedSplit.flagSets()): new ArrayList<>();

Set<String> treatments = new HashSet<String>();
for (ParsedCondition condition : parsedSplit.parsedConditions()) {
Expand Down
31 changes: 31 additions & 0 deletions client/src/test/java/io/split/client/SplitManagerImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)));
}
Expand Down

0 comments on commit 56169c2

Please sign in to comment.