Skip to content

Commit daa9e4a

Browse files
committed
added integration tests
1 parent 6aca626 commit daa9e4a

File tree

9 files changed

+500
-29
lines changed

9 files changed

+500
-29
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package io.split.client;
2+
3+
import org.junit.Assert;
4+
import org.junit.Test;
5+
6+
import java.io.IOException;
7+
import java.net.URISyntaxException;
8+
import java.util.HashMap;
9+
import java.util.concurrent.TimeoutException;
10+
11+
public class JsonLocalhostSplitFactoryTest {
12+
13+
@Test
14+
public void works() throws IOException, URISyntaxException, InterruptedException, TimeoutException {
15+
SplitClientConfig config = SplitClientConfig.builder()
16+
.splitFile("src/test/resources/splits_localhost.json")
17+
.segmentDirectory("src/test/resources")
18+
.setBlockUntilReadyTimeout(10000)
19+
.build();
20+
SplitFactory splitFactory = SplitFactoryBuilder.build("localhost", config);
21+
SplitClient client = splitFactory.client();
22+
client.blockUntilReady();
23+
24+
Assert.assertEquals("on", client.getTreatment("bilal@@split.io", "rbs_flag", new HashMap<String, Object>() {{
25+
put("email", "bilal@@split.io");
26+
}}));
27+
Assert.assertEquals("off", client.getTreatment("[email protected]", "rbs_flag", new HashMap<String, Object>() {{
28+
put("email", "[email protected]");
29+
}}));
30+
Assert.assertEquals("off", client.getTreatment("bilal", "test_split"));
31+
Assert.assertEquals("on", client.getTreatment("bilal", "push_test"));
32+
Assert.assertEquals("on_whitelist", client.getTreatment("admin", "push_test"));
33+
client.destroy();
34+
}
35+
}

client/src/test/java/io/split/client/SplitClientIntegrationTest.java

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ public class SplitClientIntegrationTest {
4444

4545
@Test
4646
public void getTreatmentWithStreamingEnabled() throws Exception {
47-
MockResponse response = new MockResponse().setBody("{\"ff\":{\"d\": [], \"s\":1585948850109, \"t\":1585948850109}, \"rbs\":{\"d\":[],\"s\":-1,\"t\":-1}}");
48-
MockResponse response2 = new MockResponse().setBody("{\"ff\":{\"d\": [], \"s\":1585948850110, \"t\":1585948850110}, \"rbs\":{\"d\":[],\"s\":-1,\"t\":-1}}");
49-
MockResponse response3 = new MockResponse().setBody("{\"ff\":{\"d\": [], \"s\":1585948850111, \"t\":1585948850111}, \"rbs\":{\"d\":[],\"s\":-1,\"t\":-1}}");
47+
MockResponse response = new MockResponse().setBody("{\"ff\":{\"d\": [], \"s\":1585948850109, \"t\":1585948850109}, \"rbs\":{\"d\":[],\"s\":1585948850109,\"t\":1585948850109}}");
48+
MockResponse response2 = new MockResponse().setBody("{\"ff\":{\"d\": [], \"s\":1585948850110, \"t\":1585948850110}, \"rbs\":{\"d\":[],\"s\":1585948850110,\"t\":1585948850110}}");
49+
MockResponse response3 = new MockResponse().setBody("{\"ff\":{\"d\": [], \"s\":1585948850111, \"t\":1585948850111}, \"rbs\":{\"d\":[],\"s\":1585948850111,\"t\":1585948850111}}");
5050
Queue responses = new LinkedList<>();
5151
responses.add(response);
5252
Queue responses2 = new LinkedList<>();
@@ -144,7 +144,7 @@ public void getTreatmentWithStreamingEnabled() throws Exception {
144144

145145
@Test
146146
public void getTreatmentWithStreamingEnabledAndAuthDisabled() throws Exception {
147-
MockResponse response = new MockResponse().setBody("{\"ff\":{\"d\": [], \"s\":1585948850109, \"t\":1585948850109}, \"rbs\":{\"s\":-1,\"t\":-1,\"d\":[]}}");
147+
MockResponse response = new MockResponse().setBody("{\"ff\":{\"d\": [], \"s\":1585948850109, \"t\":1585948850109}, \"rbs\":{\"s\":1585948850109,\"t\":1585948850109,\"d\":[]}}");
148148
Queue responses = new LinkedList<>();
149149
responses.add(response);
150150
SplitMockServer splitServer = new SplitMockServer(CustomDispatcher.builder()
@@ -165,14 +165,19 @@ public void getTreatmentWithStreamingEnabledAndAuthDisabled() throws Exception {
165165

166166
String result = client.getTreatment("admin", "push_test");
167167
Assert.assertEquals("on_whitelist", result);
168-
168+
Assert.assertEquals("on", client.getTreatment("bilal@@split.io", "rbs_flag", new HashMap<String, Object>() {{
169+
put("email", "bilal@@split.io");
170+
}}));
171+
Assert.assertEquals("off", client.getTreatment("[email protected]", "rbs_flag", new HashMap<String, Object>() {{
172+
put("email", "[email protected]");
173+
}}));
169174
client.destroy();
170175
splitServer.stop();
171176
}
172177

173178
@Test
174179
public void getTreatmentWithStreamingDisabled() throws Exception {
175-
MockResponse response = new MockResponse().setBody("{\"ff\":{\"d\": [], \"s\":1585948850109, \"t\":1585948850109}, \"rbs\":{\"d\":[],\"s\":-1,\"t\":-1}}");
180+
MockResponse response = new MockResponse().setBody("{\"ff\":{\"d\": [], \"s\":1585948850109, \"t\":1585948850109}, \"rbs\":{\"d\":[],\"s\":1585948850109,\"t\":1585948850109}}");
176181
Queue responses = new LinkedList<>();
177182
responses.add(response);
178183
SplitMockServer splitServer = new SplitMockServer(CustomDispatcher.builder()
@@ -224,8 +229,8 @@ public void managerSplitsWithStreamingEnabled() throws Exception {
224229
manager.blockUntilReady();
225230

226231
List<SplitView> results = manager.splits();
227-
Assert.assertEquals(4, results.size());
228-
Assert.assertEquals(3, results.stream().filter(r -> !r.killed).toArray().length);
232+
Assert.assertEquals(5, results.size());
233+
Assert.assertEquals(4, results.stream().filter(r -> !r.killed).toArray().length);
229234

230235
// SPLIT_KILL should fetch.
231236
OutboundSseEvent sseEventSplitKill = new OutboundEvent
@@ -237,7 +242,7 @@ public void managerSplitsWithStreamingEnabled() throws Exception {
237242

238243
Awaitility.await()
239244
.atMost(2L, TimeUnit.MINUTES)
240-
.until(() -> 2 == manager.splits().stream().filter(r -> !r.killed).toArray().length);
245+
.until(() -> 3 == manager.splits().stream().filter(r -> !r.killed).toArray().length);
241246

242247
splitServer.stop();
243248
sseServer.stop();
@@ -320,9 +325,9 @@ public void splitClientOccupancyNotifications() throws Exception {
320325

321326
@Test
322327
public void splitClientControlNotifications() throws Exception {
323-
MockResponse response = new MockResponse().setBody("{\"ff\":{\"d\": [], \"s\":1585948850109, \"t\":1585948850109}, \"rbs\":{\"d\":[],\"s\":-1,\"t\":-1}}");
324-
MockResponse response2 = new MockResponse().setBody("{\"ff\":{\"d\": [], \"s\":1585948850110, \"t\":1585948850110}, \"rbs\":{\"d\":[],\"s\":-1,\"t\":-1}}");
325-
MockResponse response3 = new MockResponse().setBody("{\"ff\":{\"d\": [], \"s\":1585948850111, \"t\":1585948850111}, \"rbs\":{\"d\":[],\"s\":-1,\"t\":-1}}");
328+
MockResponse response = new MockResponse().setBody("{\"ff\":{\"d\": [], \"s\":1585948850109, \"t\":1585948850109}, \"rbs\":{\"d\":[],\"s\":1585948850109,\"t\":1585948850109}}");
329+
MockResponse response2 = new MockResponse().setBody("{\"ff\":{\"d\": [], \"s\":1585948850110, \"t\":1585948850110}, \"rbs\":{\"d\":[],\"s\":1585948850110,\"t\":1585948850110}}");
330+
MockResponse response3 = new MockResponse().setBody("{\"ff\":{\"d\": [], \"s\":1585948850111, \"t\":1585948850111}, \"rbs\":{\"d\":[],\"s\":1585948850111,\"t\":1585948850111}}");
326331
Queue responses = new LinkedList<>();
327332
responses.add(response);
328333
Queue responses2 = new LinkedList<>();
@@ -564,7 +569,7 @@ public void splitClientMultiFactory() throws Exception {
564569

565570
@Test
566571
public void keepAlive() throws Exception {
567-
MockResponse response = new MockResponse().setBody("{\"ff\":{\"d\": [], \"s\":1585948850109, \"t\":1585948850109}, \"rbs\":{\"d\":[],\"s\":-1,\"t\":-1}}");
572+
MockResponse response = new MockResponse().setBody("{\"ff\":{\"d\": [], \"s\":1585948850109, \"t\":1585948850109}, \"rbs\":{\"d\":[],\"s\":1585948850109,\"t\":1585948850109}}");
568573
Queue responses = new LinkedList<>();
569574
responses.add(response);
570575

@@ -602,7 +607,7 @@ public void keepAlive() throws Exception {
602607

603608
@Test
604609
public void testConnectionClosedByRemoteHostIsProperlyHandled() throws Exception {
605-
MockResponse response = new MockResponse().setBody("{\"ff\":{\"d\": [], \"s\":1585948850109, \"t\":1585948850109}, \"rbs\":{\"d\":[],\"s\":-1,\"t\":-1}}");
610+
MockResponse response = new MockResponse().setBody("{\"ff\":{\"d\": [], \"s\":1585948850109, \"t\":1585948850109}, \"rbs\":{\"d\":[],\"s\":1585948850109,\"t\":1585948850109}}");
606611
Queue responses = new LinkedList<>();
607612
responses.add(response);
608613
SplitMockServer splitServer = new SplitMockServer(CustomDispatcher.builder()
@@ -640,7 +645,7 @@ public void testConnectionClosedByRemoteHostIsProperlyHandled() throws Exception
640645

641646
@Test
642647
public void testConnectionClosedIsProperlyHandled() throws Exception {
643-
MockResponse response = new MockResponse().setBody("{\"ff\":{\"d\": [], \"s\":1585948850109, \"t\":1585948850109}, \"rbs\":{\"d\":[],\"s\":-1,\"t\":-1}}");
648+
MockResponse response = new MockResponse().setBody("{\"ff\":{\"d\": [], \"s\":1585948850109, \"t\":1585948850109}, \"rbs\":{\"d\":[],\"s\":1585948850109,\"t\":1585948850109}}");
644649
Queue responses = new LinkedList<>();
645650
responses.add(response);
646651
SplitMockServer splitServer = new SplitMockServer(CustomDispatcher.builder()
@@ -706,15 +711,21 @@ public void testPluggableMode() throws IOException, URISyntaxException {
706711
Assert.assertTrue(events.stream().anyMatch(e -> "keyValue".equals(e.getEventDto().key) && e.getEventDto().value == 12L));
707712
Assert.assertTrue(events.stream().anyMatch(e -> "keyProperties".equals(e.getEventDto().key) && e.getEventDto().properties != null));
708713

709-
Assert.assertEquals(2, splits.size());
714+
Assert.assertEquals(3, splits.size());
710715
Assert.assertTrue(splits.stream().anyMatch(sw -> "first.name".equals(sw.name)));
711716
Assert.assertTrue(splits.stream().anyMatch(sw -> "second.name".equals(sw.name)));
712717
Assert.assertEquals("on", client.getTreatment("key", "first.name"));
713718
Assert.assertEquals("off", client.getTreatmentWithConfig("FakeKey", "second.name").treatment());
714719
Assert.assertEquals("control", client.getTreatment("FakeKey", "noSplit"));
720+
Assert.assertEquals("on", client.getTreatment("bilal@@split.io", "rbs_flag", new HashMap<String, Object>() {{
721+
put("email", "bilal@@split.io");
722+
}}));
723+
Assert.assertEquals("off", client.getTreatment("[email protected]", "rbs_flag", new HashMap<String, Object>() {{
724+
put("email", "[email protected]");
725+
}}));
715726

716727
List<ImpressionConsumer> impressions = customStorageWrapper.getImps();
717-
Assert.assertEquals(2, impressions.size());
728+
Assert.assertEquals(4, impressions.size());
718729
Assert.assertTrue(impressions.stream().anyMatch(imp -> "first.name".equals(imp.getKeyImpression().feature) && "on".equals(imp.getKeyImpression().treatment)));
719730
Assert.assertTrue(impressions.stream().anyMatch(imp -> "second.name".equals(imp.getKeyImpression().feature) && "off".equals(imp.getKeyImpression().treatment)));
720731

@@ -727,7 +738,7 @@ public void testPluggableMode() throws IOException, URISyntaxException {
727738
String key3 = keys.stream().filter(key -> key.contains("getTreatmentWithConfig/")).collect(Collectors.toList()).get(0);
728739

729740
Assert.assertEquals(Optional.of(3L), Optional.ofNullable(latencies.get(key1)));
730-
Assert.assertEquals(Optional.of(1L), Optional.of(latencies.get(key2)));
741+
Assert.assertEquals(Optional.of(3L), Optional.of(latencies.get(key2)));
731742
Assert.assertEquals(Optional.of(1L), Optional.of(latencies.get(key3)));
732743

733744
Thread.sleep(500);

client/src/test/java/io/split/client/utils/CustomDispatcher.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ public class CustomDispatcher extends Dispatcher {
1414
public static final String SINCE_1602796638344 = "/api/splitChanges?s=1.3&since=1602796638344&rbSince=-1&sets=set1%2Cset2";
1515
public static final String AUTH_ENABLED = "/api/auth/enabled?s=1.3";
1616
public static final String AUTH_DISABLED = "/api/auth/disabled?s=1.3";
17-
public static final String SINCE_1585948850109 = "/api/splitChanges?s=1.3&since=1585948850109&rbSince=-1";
17+
public static final String SINCE_1585948850109 = "/api/splitChanges?s=1.3&since=1585948850109&rbSince=1585948850109";
1818
public static final String SINCE_1585948850109_FLAG_SET = "/api/splitChanges?s=1.3&since=-1&rbSince=-1&sets=set_1%2Cset_2";
19-
public static final String SINCE_1585948850110 = "/api/splitChanges?s=1.3&since=1585948850110&rbSince=-1";
20-
public static final String SINCE_1585948850111 = "/api/splitChanges?s=1.3&since=1585948850111&rbSince=-1";
21-
public static final String SINCE_1585948850112 = "/api/splitChanges?s=1.3&since=1585948850112&rbSince=-1";
19+
public static final String SINCE_1585948850110 = "/api/splitChanges?s=1.3&since=1585948850110&rbSince=1585948850110";
20+
public static final String SINCE_1585948850111 = "/api/splitChanges?s=1.3&since=1585948850111&rbSince=1585948850111";
21+
public static final String SINCE_1585948850112 = "/api/splitChanges?s=1.3&since=1585948850112&rbSince=1585948850112";
2222
public static final String SEGMENT_TEST_INITIAL = "/api/segmentChanges/segment-test?since=-1";
2323
public static final String SEGMENT3_INITIAL = "/api/segmentChanges/segment3?since=-1";
2424
public static final String SEGMENT3_SINCE_1585948850110 = "/api/segmentChanges/segment3?since=1585948850110";
@@ -50,17 +50,17 @@ public MockResponse dispatch(@NotNull RecordedRequest request) {
5050
case CustomDispatcher.AUTH_DISABLED:
5151
return getResponse(CustomDispatcher.AUTH_DISABLED,new MockResponse().setBody(inputStreamToString("streaming-auth-push-disabled.json")));
5252
case CustomDispatcher.SINCE_1585948850109:
53-
return getResponse(CustomDispatcher.SINCE_1585948850109, new MockResponse().setBody("{\"ff\":{\"d\": [], \"s\":1585948850109, \"t\":1585948850110}, \"rbs\":{\"s\":-1,\"t\":-1,\"d\":[]}}"));
53+
return getResponse(CustomDispatcher.SINCE_1585948850109, new MockResponse().setBody("{\"ff\":{\"d\": [], \"s\":1585948850109, \"t\":1585948850110}, \"rbs\":{\"s\":1585948850109,\"t\":1585948850110,\"d\":[]}}"));
5454
case SINCE_1585948850109_FLAG_SET:
55-
return getResponse(SINCE_1585948850109_FLAG_SET, new MockResponse().setBody("{\"ff\":{\"d\": [], \"s\":1585948850109, \"t\":1585948850110}"));
55+
return getResponse(SINCE_1585948850109_FLAG_SET, new MockResponse().setBody("{\"ff\":{\"d\": [], \"s\":1585948850109, \"t\":1585948850110}, \"rbs\":{\"s\":1585948850109,\"t\":1585948850110,\"d\":[]}}"));
5656
case CustomDispatcher.SINCE_1585948850110:
5757
return getResponse(CustomDispatcher.SINCE_1585948850110, new MockResponse().setBody(inputStreamToString("splits2.json")));
5858
case CustomDispatcher.SINCE_1585948850111:
5959
return getResponse(CustomDispatcher.SINCE_1585948850111, new MockResponse().setBody(inputStreamToString("splits_killed.json")));
6060
case CustomDispatcher.SINCE_1585948850112:
61-
return getResponse(CustomDispatcher.SINCE_1585948850112, new MockResponse().setBody("{\"ff\":{\"d\": [], \"s\":1585948850112, \"t\":1585948850112}, \"rbs\":{\"s\":-1,\"t\":-1,\"d\":[]}}"));
61+
return getResponse(CustomDispatcher.SINCE_1585948850112, new MockResponse().setBody("{\"ff\":{\"d\": [], \"s\":1585948850112, \"t\":1585948850112}, \"rbs\":{\"s\":1585948850112,\"t\":1585948850112,\"d\":[]}}"));
6262
case CustomDispatcher.SINCE_1602796638344:
63-
return getResponse(CustomDispatcher.SINCE_1602796638344, new MockResponse().setBody("{\"ff\":{\"d\": [], \"s\":1602796638344, \"t\":1602796638344}, \"rbs\":{\"s\":-1,\"t\":-1,\"d\":[]}}"));
63+
return getResponse(CustomDispatcher.SINCE_1602796638344, new MockResponse().setBody("{\"ff\":{\"d\": [], \"s\":1602796638344, \"t\":1602796638344}, \"rbs\":{\"s\":1602796638344,\"t\":1602796638344,\"d\":[]}}"));
6464
case CustomDispatcher.SEGMENT_TEST_INITIAL:
6565
return getResponse(CustomDispatcher.SEGMENT_TEST_INITIAL, new MockResponse().setBody("{\"name\": \"segment3\",\"added\": [],\"removed\": [],\"since\": -1,\"till\": -1}"));
6666
case CustomDispatcher.SEGMENT3_INITIAL:

0 commit comments

Comments
 (0)