Skip to content

Commit b739b97

Browse files
committed
fixing segment names
1 parent 147393c commit b739b97

File tree

5 files changed

+16
-5
lines changed

5 files changed

+16
-5
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: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package io.split.client.dtos;
22

3-
import java.util.Arrays;
43
import java.util.List;
54

65
public class RuleBasedSegment {

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)