Skip to content

Commit f93ae28

Browse files
Adding tests
1 parent ecc9ed1 commit f93ae28

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

client/src/test/java/io/split/engine/common/SynchronizerTest.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import io.split.cache.SplitCache;
55
import io.split.engine.experiments.SplitFetcherImp;
66
import io.split.engine.experiments.SplitSynchronizationTask;
7+
import io.split.engine.segments.SegmentFetcher;
78
import io.split.engine.segments.SegmentSynchronizationTask;
89
import org.junit.Before;
910
import org.junit.Test;
@@ -15,14 +16,15 @@ public class SynchronizerTest {
1516
private SplitFetcherImp _splitFetcher;
1617
private SplitCache _splitCache;
1718
private Synchronizer _synchronizer;
19+
private SegmentCache _segmentCache;
1820

1921
@Before
2022
public void beforeMethod() {
2123
_refreshableSplitFetcherTask = Mockito.mock(SplitSynchronizationTask.class);
2224
_segmentFetcher = Mockito.mock(SegmentSynchronizationTask.class);
2325
_splitFetcher = Mockito.mock(SplitFetcherImp.class);
2426
_splitCache = Mockito.mock(SplitCache.class);
25-
SegmentCache _segmentCache = Mockito.mock(SegmentCache.class);
27+
_segmentCache = Mockito.mock(SegmentCache.class);
2628

2729
_synchronizer = new SynchronizerImp(_refreshableSplitFetcherTask, _splitFetcher, _segmentFetcher, _splitCache, _segmentCache);
2830
}
@@ -51,4 +53,23 @@ public void stopPeriodicFetching() {
5153
Mockito.verify(_refreshableSplitFetcherTask, Mockito.times(1)).stop();
5254
Mockito.verify(_segmentFetcher, Mockito.times(1)).stop();
5355
}
56+
57+
@Test
58+
public void streamingRetryOnSplit() {
59+
Mockito.when(_splitCache.getChangeNumber()).thenReturn(0l).thenReturn(0l).thenReturn(1l);
60+
_synchronizer.refreshSplits(1l);
61+
62+
Mockito.verify(_splitCache, Mockito.times(3)).getChangeNumber();
63+
}
64+
65+
@Test
66+
public void streamingRetryOnSegment() {
67+
SegmentFetcher fetcher = Mockito.mock(SegmentFetcher.class);
68+
Mockito.when(_segmentFetcher.getFetcher(Mockito.anyString())).thenReturn(fetcher);
69+
Mockito.when(_segmentCache.getChangeNumber(Mockito.anyString())).thenReturn(0l).thenReturn(0l).thenReturn(1l);
70+
_synchronizer.refreshSegment("Segment",1l);
71+
72+
Mockito.verify(_segmentCache, Mockito.times(3)).getChangeNumber(Mockito.anyString());
73+
}
74+
5475
}

0 commit comments

Comments
 (0)