Skip to content

Commit 1acf543

Browse files
authored
Merge pull request #562 from splitio/fix-rbs-segment-names
Fixing segment names
2 parents 147393c + c22003e commit 1acf543

File tree

5 files changed

+32
-6
lines changed

5 files changed

+32
-6
lines changed

client/src/main/java/io/split/client/dtos/ExcludedSegments.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,8 @@ public boolean isStandard() {
2020
public boolean isRuleBased() {
2121
return RULE_BASED_TYPE.equals(type);
2222
}
23+
24+
public String getSegmentName(){
25+
return name;
26+
}
2327
}

client/src/main/java/io/split/client/dtos/RuleBasedSegment.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package io.split.client.dtos;
22

3-
import java.util.Arrays;
3+
import java.util.ArrayList;
44
import java.util.List;
55

66
public class RuleBasedSegment {
@@ -17,7 +17,21 @@ public String toString() {
1717
"name='" + name + '\'' +
1818
", status=" + status +
1919
", trafficTypeName='" + trafficTypeName + '\'' +
20-
", changeNumber=" + changeNumber +
20+
", changeNumber=" + changeNumber + '\'' +
21+
excludedToString() + '\'' +
2122
'}';
2223
}
24+
25+
public String excludedToString() {
26+
Excluded ts = excluded != null ? excluded : new Excluded();
27+
if (ts.keys == null) {
28+
ts.keys = new ArrayList<>();
29+
}
30+
31+
if (ts.segments == null) {
32+
ts.segments = new ArrayList<>();
33+
}
34+
35+
return ", excludedKeys=" + ts.keys + '\'' + ", excludedSegments=" + ts.segments;
36+
}
2337
}

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,20 @@ public String toString() {
107107
}
108108

109109
public Set<String> getSegmentsNames() {
110-
return parsedConditions().stream()
110+
Set<String> segmentNames = excludedSegments()
111+
.stream()
112+
.filter(ExcludedSegments::isStandard)
113+
.map(ExcludedSegments::getSegmentName)
114+
.collect(Collectors.toSet());
115+
116+
segmentNames.addAll(parsedConditions().stream()
111117
.flatMap(parsedCondition -> parsedCondition.matcher().attributeMatchers().stream())
112118
.filter(ParsedRuleBasedSegment::isSegmentMatcher)
113119
.map(ParsedRuleBasedSegment::asSegmentMatcherForEach)
114120
.map(UserDefinedSegmentMatcher::getSegmentName)
115-
.collect(Collectors.toSet());
121+
.collect(Collectors.toSet()));
122+
123+
return segmentNames;
116124
}
117125

118126
private static boolean isSegmentMatcher(AttributeMatcher attributeMatcher) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public void works() {
3434
Lists.newArrayList(new ParsedCondition(ConditionType.WHITELIST, segmentCombiningMatcher, null, "label")), "user",
3535
123, Lists.newArrayList("mauro@test.io", "gaston@test.io"), excludedSegments);
3636

37-
Assert.assertEquals(Sets.newHashSet("employees"), parsedRuleBasedSegment.getSegmentsNames());
37+
Assert.assertEquals(Sets.newHashSet("segment2", "segment1", "employees"), parsedRuleBasedSegment.getSegmentsNames());
3838
Assert.assertEquals("another_rule_based_segment", parsedRuleBasedSegment.ruleBasedSegment());
3939
Assert.assertEquals(Lists.newArrayList(new ParsedCondition(ConditionType.WHITELIST, segmentCombiningMatcher, null, "label")),
4040
parsedRuleBasedSegment.parsedConditions());

client/src/test/java/io/split/storages/memory/RuleBasedSegmentCacheInMemoryImplTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,6 @@ public void testMultipleSegment(){
6161

6262
ruleBasedSegmentCache.update(Lists.newArrayList(parsedRuleBasedSegment1, parsedRuleBasedSegment2), null, 123);
6363
assertEquals(Lists.newArrayList("another_rule_based_segment", "sample_rule_based_segment"), ruleBasedSegmentCache.ruleBasedSegmentNames());
64-
assertEquals(Sets.newHashSet("employees"), ruleBasedSegmentCache.getSegments());
64+
assertEquals(Sets.newHashSet("segment2", "segment1", "employees"), ruleBasedSegmentCache.getSegments());
6565
}
6666
}

0 commit comments

Comments
 (0)