Skip to content

Commit 7a199f0

Browse files
committed
Added RBS tests
1 parent 11978f6 commit 7a199f0

File tree

3 files changed

+154
-1
lines changed

3 files changed

+154
-1
lines changed

client/src/test/java/io/split/engine/matchers/RuleBasedSegmentMatcherTest.java

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import java.nio.charset.StandardCharsets;
2727
import java.nio.file.Files;
2828
import java.nio.file.Paths;
29+
import java.util.ArrayList;
30+
import java.util.Arrays;
2931
import java.util.HashMap;
3032
import java.util.Set;
3133

@@ -61,7 +63,7 @@ public void works() {
6163
}
6264

6365
@Test
64-
public void usingRbsWithinExcludedTest() throws IOException {
66+
public void usingRbsInConditionTest() throws IOException {
6567
String load = new String(Files.readAllBytes(Paths.get("src/test/resources/rule_base_segments.json")), StandardCharsets.UTF_8);
6668
Evaluator evaluator = Mockito.mock(Evaluator.class);
6769
SegmentCache segmentCache = new SegmentCacheInMemoryImpl();
@@ -83,4 +85,57 @@ public void usingRbsWithinExcludedTest() throws IOException {
8385
assertThat(matcher.match("mauro@split.io", null, attrib1, evaluationContext), is(false));
8486
assertThat(matcher.match("bilal@split.io", null, attrib2, evaluationContext), is(true));
8587
}
88+
89+
@Test
90+
public void usingSegmentInExcludedTest() throws IOException {
91+
String load = new String(Files.readAllBytes(Paths.get("src/test/resources/rule_base_segments3.json")), StandardCharsets.UTF_8);
92+
Evaluator evaluator = Mockito.mock(Evaluator.class);
93+
SegmentCache segmentCache = new SegmentCacheInMemoryImpl();
94+
segmentCache.updateSegment("segment1", Arrays.asList("bilal@split.io"), new ArrayList<>(), 123);
95+
RuleBasedSegmentCache ruleBasedSegmentCache = new RuleBasedSegmentCacheInMemoryImp();
96+
EvaluationContext evaluationContext = new EvaluationContext(evaluator, segmentCache, ruleBasedSegmentCache);
97+
98+
SplitChange change = Json.fromJson(load, SplitChange.class);
99+
RuleBasedSegmentParser ruleBasedSegmentParser = new RuleBasedSegmentParser();
100+
RuleBasedSegmentsToUpdate ruleBasedSegmentsToUpdate = processRuleBasedSegmentChanges(ruleBasedSegmentParser,
101+
change.ruleBasedSegments.d);
102+
ruleBasedSegmentCache.update(ruleBasedSegmentsToUpdate.getToAdd(), null, 123);
103+
RuleBasedSegmentMatcher matcher = new RuleBasedSegmentMatcher("sample_rule_based_segment");
104+
HashMap<String, Object> attrib1 = new HashMap<String, Object>() {{
105+
put("email", "mauro@split.io");
106+
}};
107+
HashMap<String, Object> attrib2 = new HashMap<String, Object>() {{
108+
put("email", "bilal@split.io");
109+
}};
110+
HashMap<String, Object> attrib3 = new HashMap<String, Object>() {{
111+
put("email", "pato@split.io");
112+
}};
113+
assertThat(matcher.match("mauro@split.io", null, attrib1, evaluationContext), is(false));
114+
assertThat(matcher.match("bilal@split.io", null, attrib2, evaluationContext), is(false));
115+
assertThat(matcher.match("pato@split.io", null, attrib3, evaluationContext), is(true));
116+
}
117+
118+
@Test
119+
public void usingRbsInExcludedTest() throws IOException {
120+
String load = new String(Files.readAllBytes(Paths.get("src/test/resources/rule_base_segments2.json")), StandardCharsets.UTF_8);
121+
Evaluator evaluator = Mockito.mock(Evaluator.class);
122+
SegmentCache segmentCache = new SegmentCacheInMemoryImpl();
123+
RuleBasedSegmentCache ruleBasedSegmentCache = new RuleBasedSegmentCacheInMemoryImp();
124+
EvaluationContext evaluationContext = new EvaluationContext(evaluator, segmentCache, ruleBasedSegmentCache);
125+
126+
SplitChange change = Json.fromJson(load, SplitChange.class);
127+
RuleBasedSegmentParser ruleBasedSegmentParser = new RuleBasedSegmentParser();
128+
RuleBasedSegmentsToUpdate ruleBasedSegmentsToUpdate = processRuleBasedSegmentChanges(ruleBasedSegmentParser,
129+
change.ruleBasedSegments.d);
130+
ruleBasedSegmentCache.update(ruleBasedSegmentsToUpdate.getToAdd(), null, 123);
131+
RuleBasedSegmentMatcher matcher = new RuleBasedSegmentMatcher("no_excludes");
132+
HashMap<String, Object> attrib1 = new HashMap<String, Object>() {{
133+
put("email", "mauro@split.io");
134+
}};
135+
HashMap<String, Object> attrib2 = new HashMap<String, Object>() {{
136+
put("email", "bilal@split.io");
137+
}};
138+
assertThat(matcher.match("mauro@split.io", null, attrib1, evaluationContext), is(true));
139+
assertThat(matcher.match("bilal@split.io", null, attrib2, evaluationContext), is(true));
140+
}
86141
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{"ff": {"d": [], "t": -1, "s": -1},
2+
"rbs": {"t": -1, "s": -1, "d": [
3+
{
4+
"changeNumber": 5,
5+
"name": "sample_rule_based_segment",
6+
"status": "ACTIVE",
7+
"trafficTypeName": "user",
8+
"excluded":{
9+
"keys":["mauro@split.io","gaston@split.io"],
10+
"segments":[{"type":"rule-based", "name":"no_excludes"}]
11+
},
12+
"conditions": [
13+
{
14+
"matcherGroup": {
15+
"combiner": "AND",
16+
"matchers": [
17+
{
18+
"keySelector": {
19+
"trafficType": "user",
20+
"attribute": "email"
21+
},
22+
"matcherType": "ENDS_WITH",
23+
"negate": false,
24+
"whitelistMatcherData": {
25+
"whitelist": [
26+
"@split.io"
27+
]
28+
}
29+
}
30+
]
31+
}
32+
}
33+
]
34+
},
35+
{
36+
"changeNumber": 5,
37+
"name": "no_excludes",
38+
"status": "ACTIVE",
39+
"trafficTypeName": "user",
40+
"conditions": [
41+
{
42+
"matcherGroup": {
43+
"combiner": "AND",
44+
"matchers": [
45+
{
46+
"keySelector": {
47+
"trafficType": "user",
48+
"attribute": "email"
49+
},
50+
"matcherType": "ENDS_WITH",
51+
"negate": false,
52+
"whitelistMatcherData": {
53+
"whitelist": [
54+
"@split.io"
55+
]
56+
}
57+
}
58+
]
59+
}
60+
}
61+
]
62+
}
63+
]}}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{"ff": {"d": [], "t": -1, "s": -1},
2+
"rbs": {"t": -1, "s": -1, "d": [
3+
{
4+
"changeNumber": 5,
5+
"name": "sample_rule_based_segment",
6+
"status": "ACTIVE",
7+
"trafficTypeName": "user",
8+
"excluded":{
9+
"keys":["mauro@split.io","gaston@split.io"],
10+
"segments":[{"type":"standard", "name":"segment1"}]
11+
},
12+
"conditions": [
13+
{
14+
"matcherGroup": {
15+
"combiner": "AND",
16+
"matchers": [
17+
{
18+
"keySelector": {
19+
"trafficType": "user",
20+
"attribute": "email"
21+
},
22+
"matcherType": "ENDS_WITH",
23+
"negate": false,
24+
"whitelistMatcherData": {
25+
"whitelist": [
26+
"@split.io"
27+
]
28+
}
29+
}
30+
]
31+
}
32+
}
33+
]
34+
}
35+
]}}

0 commit comments

Comments
 (0)