11package io .split .client ;
22
33import io .split .SSEMockServer ;
4+ import io .split .Spec ;
45import io .split .SplitMockServer ;
56import io .split .client .api .SplitView ;
67import io .split .client .dtos .EvaluationOptions ;
78import io .split .client .impressions .ImpressionsManager ;
89import io .split .client .utils .CustomDispatcher ;
10+ import io .split .engine .experiments .SplitFetcherImp ;
911import io .split .storages .enums .OperationMode ;
1012import io .split .storages .enums .StorageMode ;
1113import io .split .storages .pluggable .CustomStorageWrapperImp ;
2426
2527import javax .ws .rs .sse .OutboundSseEvent ;
2628import java .io .IOException ;
29+ import java .lang .reflect .Field ;
2730import java .net .URISyntaxException ;
2831import java .nio .charset .StandardCharsets ;
2932import java .nio .file .Files ;
@@ -246,13 +249,14 @@ public void managerSplitsWithStreamingEnabled() throws Exception {
246249
247250 splitServer .stop ();
248251 sseServer .stop ();
252+ factory .destroy ();
249253 }
250254
251255 @ Test
252256 public void splitClientOccupancyNotifications () throws Exception {
253- MockResponse response = new MockResponse ().setBody ("{\" ff\" :{\" d\" : [], \" s\" :1585948850109, \" t\" :1585948850109}, \" rbs\" :{\" d\" :[],\" s\" :-1 ,\" t\" :-1 }}" );
254- MockResponse response2 = new MockResponse ().setBody ("{\" ff\" :{\" d\" : [], \" s\" :1585948850110, \" t\" :1585948850110}, \" rbs\" :{\" d\" :[],\" s\" :-1 ,\" t\" :-1 }}" );
255- MockResponse response3 = new MockResponse ().setBody ("{\" ff\" :{\" d\" : [], \" s\" :1585948850111, \" t\" :1585948850111}, \" rbs\" :{\" d\" :[],\" s\" :-1 ,\" t\" :-1 }}" );
257+ MockResponse response = new MockResponse ().setBody ("{\" ff\" :{\" d\" : [], \" s\" :1585948850109, \" t\" :1585948850109}, \" rbs\" :{\" d\" :[],\" s\" :1585948850109 ,\" t\" :1585948850109 }}" );
258+ MockResponse response2 = new MockResponse ().setBody ("{\" ff\" :{\" d\" : [], \" s\" :1585948850110, \" t\" :1585948850110}, \" rbs\" :{\" d\" :[],\" s\" :1585948850110 ,\" t\" :1585948850110 }}" );
259+ MockResponse response3 = new MockResponse ().setBody ("{\" ff\" :{\" d\" : [], \" s\" :1585948850111, \" t\" :1585948850111}, \" rbs\" :{\" d\" :[],\" s\" :1585948850111 ,\" t\" :1585948850111 }}" );
256260 Queue responses = new LinkedList <>();
257261 responses .add (response );
258262 Queue responses2 = new LinkedList <>();
@@ -420,7 +424,7 @@ public void splitClientControlNotifications() throws Exception {
420424
421425 @ Test
422426 public void splitClientMultiFactory () throws Exception {
423- MockResponse response = new MockResponse ().setBody ("{\" ff\" :{\" d\" : [], \" s\" :1585948850109, \" t\" :1585948850109}, \" rbs\" :{\" d\" :[],\" s\" :-1 ,\" t\" :-1 }}" );
427+ MockResponse response = new MockResponse ().setBody ("{\" ff\" :{\" d\" :[],\" s\" :1585948850109, \" t\" :1585948850109},\" rbs\" :{\" d\" :[],\" s\" :1585948850109 ,\" t\" :1585948850109 }}" );
424428 Queue responses = new LinkedList <>();
425429 responses .add (response );
426430 responses .add (response );
@@ -573,9 +577,10 @@ public void keepAlive() throws Exception {
573577 Queue responses = new LinkedList <>();
574578 responses .add (response );
575579
576- SplitMockServer splitServer = new SplitMockServer ( CustomDispatcher .builder ()
580+ CustomDispatcher dispatcher = CustomDispatcher .builder ()
577581 .path (CustomDispatcher .SINCE_1585948850109 , responses )
578- .build ());
582+ .build ();
583+ SplitMockServer splitServer = new SplitMockServer (dispatcher );
579584
580585 //plitMockServer splitServer = new SplitMockServer(CustomDispatcher.builder().build());
581586 SSEMockServer .SseEventQueue eventQueue = new SSEMockServer .SseEventQueue ();
@@ -594,7 +599,6 @@ public void keepAlive() throws Exception {
594599
595600 // wait to check keep alive notification.
596601 Thread .sleep (50000 );
597-
598602 // must reconnect and after the second syncAll the result must be different
599603 Awaitility .await ()
600604 .atMost (1L , TimeUnit .MINUTES )
@@ -641,6 +645,7 @@ public void testConnectionClosedByRemoteHostIsProperlyHandled() throws Exception
641645 Thread .sleep (1000 );
642646 result = client .getTreatment ("admin" , "push_test" );
643647 Assert .assertNotEquals ("on_whitelist" , result );
648+ client .destroy ();
644649 }
645650
646651 @ Test
@@ -677,6 +682,7 @@ public void testConnectionClosedIsProperlyHandled() throws Exception {
677682 Thread .sleep (1000 );
678683 result = client .getTreatment ("admin" , "push_test" );
679684 Assert .assertNotEquals ("on_whitelist" , result );
685+ client .destroy ();
680686 }
681687
682688 @ Test
@@ -745,15 +751,15 @@ public void testPluggableMode() throws IOException, URISyntaxException {
745751 Assert .assertNotNull (customStorageWrapper .getConfig ());
746752 String key = customStorageWrapper .getConfig ().keySet ().stream ().collect (Collectors .toList ()).get (0 );
747753 Assert .assertTrue (customStorageWrapper .getConfig ().get (key ).contains (StorageMode .PLUGGABLE .name ()));
748-
754+ client . destroy ();
749755 } catch (TimeoutException | InterruptedException e ) {
750756 }
751757 }
752758
753759 @ Test
754760 public void getTreatmentFlagSetWithPolling () throws Exception {
755- MockResponse response = new MockResponse ().setBody ("{\" splits\" :[{\" trafficTypeName\" :\" client\" ,\" name\" :\" workm\" ,\" trafficAllocation\" :100,\" trafficAllocationSeed\" :147392224,\" seed\" :524417105,\" status\" :\" ACTIVE\" ,\" killed\" :false,\" defaultTreatment\" :\" on\" ,\" changeNumber\" :1602796638344,\" algo\" :2,\" configurations\" :{},\" sets\" :[\" set1\" ,\" set2\" ],\" conditions\" :[{\" conditionType\" :\" ROLLOUT\" ,\" matcherGroup\" :{\" combiner\" :\" AND\" ,\" matchers\" :[{\" keySelector\" :{\" trafficType\" :\" client\" ,\" attribute\" :null},\" matcherType\" :\" IN_SEGMENT\" ,\" negate\" :false,\" userDefinedSegmentMatcherData\" :{\" segmentName\" :\" new_segment\" },\" whitelistMatcherData\" :null,\" unaryNumericMatcherData\" :null,\" betweenMatcherData\" :null,\" booleanMatcherData\" :null,\" dependencyMatcherData\" :null,\" stringMatcherData\" :null}]},\" partitions\" :[{\" treatment\" :\" on\" ,\" size\" :0},{\" treatment\" :\" off\" ,\" size\" :0},{\" treatment\" :\" free\" ,\" size\" :100},{\" treatment\" :\" conta\" ,\" size\" :0}],\" label\" :\" in segment new_segment\" },{\" conditionType\" :\" ROLLOUT\" ,\" matcherGroup\" :{\" combiner\" :\" AND\" ,\" matchers\" :[{\" keySelector\" :{\" trafficType\" :\" client\" ,\" attribute\" :null},\" matcherType\" :\" ALL_KEYS\" ,\" negate\" :false,\" userDefinedSegmentMatcherData\" :null,\" whitelistMatcherData\" :null,\" unaryNumericMatcherData\" :null,\" betweenMatcherData\" :null,\" booleanMatcherData\" :null,\" dependencyMatcherData\" :null,\" stringMatcherData\" :null}]},\" partitions\" :[{\" treatment\" :\" on\" ,\" size\" :100},{\" treatment\" :\" off\" ,\" size\" :0},{\" treatment\" :\" free\" ,\" size\" :0},{\" treatment\" :\" conta\" ,\" size\" :0}],\" label\" :\" default rule\" }]},{\" trafficTypeName\" :\" client\" ,\" name\" :\" workm_set_3\" ,\" trafficAllocation\" :100,\" trafficAllocationSeed\" :147392224,\" seed\" :524417105,\" status\" :\" ACTIVE\" ,\" killed\" :false,\" defaultTreatment\" :\" on\" ,\" changeNumber\" :1602796638344,\" algo\" :2,\" configurations\" :{},\" sets\" :[\" set3\" ],\" conditions\" :[{\" conditionType\" :\" ROLLOUT\" ,\" matcherGroup\" :{\" combiner\" :\" AND\" ,\" matchers\" :[{\" keySelector\" :{\" trafficType\" :\" client\" ,\" attribute\" :null},\" matcherType\" :\" IN_SEGMENT\" ,\" negate\" :false,\" userDefinedSegmentMatcherData\" :{\" segmentName\" :\" new_segment\" },\" whitelistMatcherData\" :null,\" unaryNumericMatcherData\" :null,\" betweenMatcherData\" :null,\" booleanMatcherData\" :null,\" dependencyMatcherData\" :null,\" stringMatcherData\" :null}]},\" partitions\" :[{\" treatment\" :\" on\" ,\" size\" :0},{\" treatment\" :\" off\" ,\" size\" :0},{\" treatment\" :\" free\" ,\" size\" :100},{\" treatment\" :\" conta\" ,\" size\" :0}],\" label\" :\" in segment new_segment\" },{\" conditionType\" :\" ROLLOUT\" ,\" matcherGroup\" :{\" combiner\" :\" AND\" ,\" matchers\" :[{\" keySelector\" :{\" trafficType\" :\" client\" ,\" attribute\" :null},\" matcherType\" :\" ALL_KEYS\" ,\" negate\" :false,\" userDefinedSegmentMatcherData\" :null,\" whitelistMatcherData\" :null,\" unaryNumericMatcherData\" :null,\" betweenMatcherData\" :null,\" booleanMatcherData\" :null,\" dependencyMatcherData\" :null,\" stringMatcherData\" :null}]},\" partitions\" :[{\" treatment\" :\" on\" ,\" size\" :100},{\" treatment\" :\" off\" ,\" size\" :0},{\" treatment\" :\" free\" ,\" size\" :0},{\" treatment\" :\" conta\" ,\" size\" :0}],\" label\" :\" default rule\" }]}],\" since\" :-1,\" till\" :1602796638344}" );
756- MockResponse responseFlag = new MockResponse ().setBody ("{\" splits \" : [], \" since \" :1602796638344, \" till \" :1602796638344}" );
761+ MockResponse response = new MockResponse ().setBody ("{\" ff\" :{\" d\" :[{\" trafficTypeName\" :\" client\" ,\" name\" :\" workm\" ,\" trafficAllocation\" :100,\" trafficAllocationSeed\" :147392224,\" seed\" :524417105,\" status\" :\" ACTIVE\" ,\" killed\" :false,\" defaultTreatment\" :\" on\" ,\" changeNumber\" :1602796638344,\" algo\" :2,\" configurations\" :{},\" sets\" :[\" set1\" ,\" set2\" ],\" conditions\" :[{\" conditionType\" :\" ROLLOUT\" ,\" matcherGroup\" :{\" combiner\" :\" AND\" ,\" matchers\" :[{\" keySelector\" :{\" trafficType\" :\" client\" ,\" attribute\" :null},\" matcherType\" :\" IN_SEGMENT\" ,\" negate\" :false,\" userDefinedSegmentMatcherData\" :{\" segmentName\" :\" new_segment\" },\" whitelistMatcherData\" :null,\" unaryNumericMatcherData\" :null,\" betweenMatcherData\" :null,\" booleanMatcherData\" :null,\" dependencyMatcherData\" :null,\" stringMatcherData\" :null}]},\" partitions\" :[{\" treatment\" :\" on\" ,\" size\" :0},{\" treatment\" :\" off\" ,\" size\" :0},{\" treatment\" :\" free\" ,\" size\" :100},{\" treatment\" :\" conta\" ,\" size\" :0}],\" label\" :\" in segment new_segment\" },{\" conditionType\" :\" ROLLOUT\" ,\" matcherGroup\" :{\" combiner\" :\" AND\" ,\" matchers\" :[{\" keySelector\" :{\" trafficType\" :\" client\" ,\" attribute\" :null},\" matcherType\" :\" ALL_KEYS\" ,\" negate\" :false,\" userDefinedSegmentMatcherData\" :null,\" whitelistMatcherData\" :null,\" unaryNumericMatcherData\" :null,\" betweenMatcherData\" :null,\" booleanMatcherData\" :null,\" dependencyMatcherData\" :null,\" stringMatcherData\" :null}]},\" partitions\" :[{\" treatment\" :\" on\" ,\" size\" :100},{\" treatment\" :\" off\" ,\" size\" :0},{\" treatment\" :\" free\" ,\" size\" :0},{\" treatment\" :\" conta\" ,\" size\" :0}],\" label\" :\" default rule\" }]},{\" trafficTypeName\" :\" client\" ,\" name\" :\" workm_set_3\" ,\" trafficAllocation\" :100,\" trafficAllocationSeed\" :147392224,\" seed\" :524417105,\" status\" :\" ACTIVE\" ,\" killed\" :false,\" defaultTreatment\" :\" on\" ,\" changeNumber\" :1602796638344,\" algo\" :2,\" configurations\" :{},\" sets\" :[\" set3\" ],\" conditions\" :[{\" conditionType\" :\" ROLLOUT\" ,\" matcherGroup\" :{\" combiner\" :\" AND\" ,\" matchers\" :[{\" keySelector\" :{\" trafficType\" :\" client\" ,\" attribute\" :null},\" matcherType\" :\" IN_SEGMENT\" ,\" negate\" :false,\" userDefinedSegmentMatcherData\" :{\" segmentName\" :\" new_segment\" },\" whitelistMatcherData\" :null,\" unaryNumericMatcherData\" :null,\" betweenMatcherData\" :null,\" booleanMatcherData\" :null,\" dependencyMatcherData\" :null,\" stringMatcherData\" :null}]},\" partitions\" :[{\" treatment\" :\" on\" ,\" size\" :0},{\" treatment\" :\" off\" ,\" size\" :0},{\" treatment\" :\" free\" ,\" size\" :100},{\" treatment\" :\" conta\" ,\" size\" :0}],\" label\" :\" in segment new_segment\" },{\" conditionType\" :\" ROLLOUT\" ,\" matcherGroup\" :{\" combiner\" :\" AND\" ,\" matchers\" :[{\" keySelector\" :{\" trafficType\" :\" client\" ,\" attribute\" :null},\" matcherType\" :\" ALL_KEYS\" ,\" negate\" :false,\" userDefinedSegmentMatcherData\" :null,\" whitelistMatcherData\" :null,\" unaryNumericMatcherData\" :null,\" betweenMatcherData\" :null,\" booleanMatcherData\" :null,\" dependencyMatcherData\" :null,\" stringMatcherData\" :null}]},\" partitions\" :[{\" treatment\" :\" on\" ,\" size\" :100},{\" treatment\" :\" off\" ,\" size\" :0},{\" treatment\" :\" free\" ,\" size\" :0},{\" treatment\" :\" conta\" ,\" size\" :0}],\" label\" :\" default rule\" }]}],\" s\" :-1,\" t\" :1602796638344},\" rbs\" :{\" d\" :[],\" t\" :-1,\" s\" :-1}}" );
762+ MockResponse responseFlag = new MockResponse ().setBody ("{\" ff \" :{ \" d \" : [],\" s \" :1602796638344,\" t \" :1602796638344}, \" rbs \" :{ \" d \" :[], \" t \" :-1, \" s \" :-1} }" );
757763 MockResponse segmentResponse = new MockResponse ().setBody ("{\" name\" :\" new_segment\" ,\" added\" :[\" user-1\" ],\" removed\" :[\" user-2\" ,\" user-3\" ],\" since\" :-1,\" till\" :-1}" );
758764 Queue responses = new LinkedList <>();
759765 responses .add (response );
0 commit comments