55import io .split .cache .SegmentCache ;
66import io .split .cache .SegmentCacheInMemoryImpl ;
77import io .split .cache .SplitCache ;
8- import io .split .client .dtos .Matcher ;
9- import io .split .client .dtos .MatcherGroup ;
10- import io .split .client .dtos .Split ;
11- import io .split .client .dtos .Status ;
12- import io .split .client .dtos .Condition ;
13- import io .split .client .dtos .SplitChange ;
8+ import io .split .client .dtos .*;
149import io .split .engine .ConditionsTestUtil ;
1510import io .split .engine .SDKReadinessGates ;
1611import io .split .engine .matchers .AllKeysMatcher ;
1712import io .split .engine .matchers .CombiningMatcher ;
18- import io .split .engine .segments .NoChangeSegmentChangeFetcher ;
1913import io .split .engine .segments .SegmentChangeFetcher ;
2014import io .split .engine .segments .SegmentSynchronizationTask ;
2115import io .split .engine .segments .SegmentSynchronizationTaskImp ;
2216import io .split .grammar .Treatments ;
2317import org .junit .Test ;
18+ import org .mockito .Mockito ;
2419import org .slf4j .Logger ;
2520import org .slf4j .LoggerFactory ;
2621
22+ import java .util .ArrayList ;
2723import java .util .List ;
2824import java .util .concurrent .Executors ;
2925import java .util .concurrent .ScheduledExecutorService ;
3531import static org .hamcrest .Matchers .greaterThan ;
3632import static org .hamcrest .Matchers .nullValue ;
3733import static org .junit .Assert .assertThat ;
34+ import static org .mockito .Matchers .anyLong ;
35+ import static org .mockito .Matchers .anyString ;
3836import static org .mockito .Mockito .mock ;
3937import static org .mockito .Mockito .when ;
4038
@@ -58,7 +56,7 @@ private void works(long startingChangeNumber) throws InterruptedException {
5856 AChangePerCallSplitChangeFetcher splitChangeFetcher = new AChangePerCallSplitChangeFetcher ();
5957 SDKReadinessGates gates = new SDKReadinessGates ();
6058 SegmentCache segmentCache = new SegmentCacheInMemoryImpl ();
61- SegmentChangeFetcher segmentChangeFetcher = new NoChangeSegmentChangeFetcher ( );
59+ SegmentChangeFetcher segmentChangeFetcher = Mockito . mock ( SegmentChangeFetcher . class );
6260 SegmentSynchronizationTask segmentSynchronizationTask = new SegmentSynchronizationTaskImp (segmentChangeFetcher ,1 ,10 , gates , segmentCache );
6361 SplitCache cache = new InMemoryCacheImp (startingChangeNumber );
6462 SplitFetcherImp fetcher = new SplitFetcherImp (splitChangeFetcher , new SplitParser (segmentSynchronizationTask , segmentCache ), gates , cache );
@@ -131,7 +129,7 @@ public void when_parser_fails_we_remove_the_experiment() throws InterruptedExcep
131129
132130 SegmentCache segmentCache = new SegmentCacheInMemoryImpl ();
133131
134- SegmentChangeFetcher segmentChangeFetcher = new NoChangeSegmentChangeFetcher ( );
132+ SegmentChangeFetcher segmentChangeFetcher = mock ( SegmentChangeFetcher . class );
135133 SegmentSynchronizationTask segmentSynchronizationTask = new SegmentSynchronizationTaskImp (segmentChangeFetcher , 1 ,10 , gates , segmentCache );
136134 segmentSynchronizationTask .startPeriodicFetching ();
137135 SplitCache cache = new InMemoryCacheImp (-1 );
@@ -154,7 +152,7 @@ public void if_there_is_a_problem_talking_to_split_change_count_down_latch_is_no
154152 when (splitChangeFetcher .fetch (-1L )).thenThrow (new RuntimeException ());
155153 SegmentCache segmentCache = new SegmentCacheInMemoryImpl ();
156154
157- SegmentChangeFetcher segmentChangeFetcher = new NoChangeSegmentChangeFetcher ( );
155+ SegmentChangeFetcher segmentChangeFetcher = mock ( SegmentChangeFetcher . class );
158156 SegmentSynchronizationTask segmentSynchronizationTask = new SegmentSynchronizationTaskImp (segmentChangeFetcher , 1 ,10 , gates , segmentCache );
159157 segmentSynchronizationTask .startPeriodicFetching ();
160158 SplitFetcherImp fetcher = new SplitFetcherImp (splitChangeFetcher , new SplitParser (segmentSynchronizationTask , segmentCache ), gates , cache );
@@ -194,7 +192,9 @@ public void works_with_user_defined_segments() throws Exception {
194192 SplitCache cache = new InMemoryCacheImp (startingChangeNumber );
195193 SegmentCache segmentCache = new SegmentCacheInMemoryImpl ();
196194
197- SegmentChangeFetcher segmentChangeFetcher = new NoChangeSegmentChangeFetcher ();
195+ SegmentChangeFetcher segmentChangeFetcher = mock (SegmentChangeFetcher .class );
196+ SegmentChange segmentChange = getSegmentChange (0L , 0L , segmentName );
197+ when (segmentChangeFetcher .fetch (anyString (), anyLong ())).thenReturn (segmentChange );
198198 SegmentSynchronizationTask segmentSynchronizationTask = new SegmentSynchronizationTaskImp (segmentChangeFetcher , 1 ,10 , gates , segmentCache );
199199 segmentSynchronizationTask .startPeriodicFetching ();
200200 SplitFetcherImp fetcher = new SplitFetcherImp (experimentChangeFetcher , new SplitParser (segmentSynchronizationTask , segmentCache ), gates , cache );
@@ -216,4 +216,14 @@ public void works_with_user_defined_segments() throws Exception {
216216 assertThat (gates .areSegmentsReady (100 ), is (equalTo (true )));
217217 assertThat (gates .isSDKReady (0 ), is (equalTo (true )));
218218 }
219+
220+ private SegmentChange getSegmentChange (long since , long till , String segmentName ){
221+ SegmentChange segmentChange = new SegmentChange ();
222+ segmentChange .name = segmentName ;
223+ segmentChange .since = since ;
224+ segmentChange .till = till ;
225+ segmentChange .added = new ArrayList <>();
226+ segmentChange .removed = new ArrayList <>();
227+ return segmentChange ;
228+ }
219229}
0 commit comments