Skip to content

Commit

Permalink
Improve test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
nmayorsplit committed Sep 4, 2023
1 parent 16f1e2b commit eade9da
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static ImpressionsManagerImpl instanceForTest(SplitClientConfig config,
ImpressionsStorageProducer impressionsStorageProducer,
ProcessImpressionStrategy processImpressionStrategy,
ImpressionCounter counter,
ImpressionListener listener) throws URISyntaxException {
ImpressionListener listener) {
return new ImpressionsManagerImpl(config, impressionsSender, telemetryRuntimeProducer, impressionsStorageConsumer,
impressionsStorageProducer, processImpressionStrategy, counter, listener);
}
Expand All @@ -73,7 +73,7 @@ private ImpressionsManagerImpl(SplitClientConfig config,
ImpressionsStorageProducer impressionsStorageProducer,
ProcessImpressionStrategy processImpressionStrategy,
ImpressionCounter impressionCounter,
ImpressionListener impressionListener) throws URISyntaxException {
ImpressionListener impressionListener) {


_config = checkNotNull(config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ public void setUp() {
@Captor
private ArgumentCaptor<List<TestImpressions>> impressionsCaptor;

@Captor
private ArgumentCaptor<List<KeyImpression>> impressionKeyList;

@Captor
private ArgumentCaptor<UniqueKeys> uniqueKeysCaptor;

Expand Down Expand Up @@ -91,7 +94,6 @@ public void works() throws URISyntaxException {
treatmentLog.track(Stream.of(new Impression(ki2.keyName, null, ki2.feature, ki2.treatment, ki2.time, null, ki2.changeNumber, null)).collect(Collectors.toList()));
treatmentLog.track(Stream.of(new Impression(ki3.keyName, null, ki3.feature, ki3.treatment, ki3.time, null, ki3.changeNumber, null)).collect(Collectors.toList()));
treatmentLog.track(Stream.of(new Impression(ki4.keyName, null, ki4.feature, ki4.treatment, ki4.time, null, ki4.changeNumber, null)).collect(Collectors.toList()));
verify(impressionListener, times(4)).log(Mockito.anyObject());

// Do what the scheduler would do.
treatmentLog.sendImpressions();
Expand All @@ -104,13 +106,13 @@ public void works() throws URISyntaxException {
}

@Test
public void testImpressionListenerOptimize() throws URISyntaxException {
public void testImpressionListenerOptimize() {
SplitClientConfig config = SplitClientConfig.builder()
.impressionsQueueSize(10)
.endpoint("nowhere.com", "nowhere.com")
.impressionsMode(ImpressionsManager.Mode.OPTIMIZED)
.build();
ImpressionsStorage storage = new InMemoryImpressionsStorage(config.impressionsQueueSize());
ImpressionsStorage storage = Mockito.mock(InMemoryImpressionsStorage.class);

ImpressionsSender senderMock = Mockito.mock(ImpressionsSender.class);
ImpressionCounter impressionCounter = new ImpressionCounter();
Expand All @@ -124,8 +126,8 @@ public void testImpressionListenerOptimize() throws URISyntaxException {
ImpressionsManagerImpl treatmentLog = ImpressionsManagerImpl.instanceForTest(config, senderMock, TELEMETRY_STORAGE, storage, storage, processImpressionStrategy, impressionCounter, impressionListener);
treatmentLog.start();

KeyImpression ki1 = keyImpression("test1", "adil", "on", 1L, null);
KeyImpression ki2 = keyImpression("test1", "adil", "on", 2L, 1L);
KeyImpression ki1 = keyImpression("test1", "adil", "on", 1L, 1L);
KeyImpression ki2 = keyImpression("test1", "adil", "on", 1L, 1L);
KeyImpression ki3 = keyImpression("test1", "pato", "on", 3L, 2L);
KeyImpression ki4 = keyImpression("test2", "pato", "on", 4L, 3L);

Expand All @@ -138,24 +140,21 @@ public void testImpressionListenerOptimize() throws URISyntaxException {
treatmentLog.track(impressionList);
verify(impressionListener, times(4)).log(Mockito.anyObject());

// Do what the scheduler would do.
treatmentLog.sendImpressions();

verify(senderMock).postImpressionsBulk(impressionsCaptor.capture());
verify(storage).put(impressionKeyList.capture());

List<TestImpressions> captured = impressionsCaptor.getValue();
List captured = impressionKeyList.getValue();

Assert.assertEquals(2, captured.size());
Assert.assertEquals(3, captured.size());
}

@Test
public void testImpressionListenerDebug() throws URISyntaxException {
public void testImpressionListenerDebug() {
SplitClientConfig config = SplitClientConfig.builder()
.impressionsQueueSize(4)
.impressionsQueueSize(6)
.endpoint("nowhere.com", "nowhere.com")
.impressionsMode(ImpressionsManager.Mode.DEBUG)
.build();
ImpressionsStorage storage = new InMemoryImpressionsStorage(config.impressionsQueueSize());
ImpressionsStorage storage = Mockito.mock(InMemoryImpressionsStorage.class);

ImpressionsSender senderMock = Mockito.mock(ImpressionsSender.class);
ImpressionCounter impressionCounter = Mockito.mock(ImpressionCounter.class);
Expand All @@ -168,8 +167,8 @@ public void testImpressionListenerDebug() throws URISyntaxException {
ImpressionsManagerImpl treatmentLog = ImpressionsManagerImpl.instanceForTest(config, senderMock, TELEMETRY_STORAGE, storage, storage, processImpressionStrategy, impressionCounter, impressionListener);
treatmentLog.start();

KeyImpression ki1 = keyImpression("test1", "adil", "on", 1L, null);
KeyImpression ki2 = keyImpression("test1", "adil", "on", 2L, 1L);
KeyImpression ki1 = keyImpression("test1", "adil", "on", 1L, 1L);
KeyImpression ki2 = keyImpression("test1", "adil", "on", 1L, 1L);
KeyImpression ki3 = keyImpression("test1", "pato", "on", 3L, 2L);
KeyImpression ki4 = keyImpression("test2", "pato", "on", 4L, 3L);

Expand All @@ -182,24 +181,21 @@ public void testImpressionListenerDebug() throws URISyntaxException {
treatmentLog.track(impressionList);
verify(impressionListener, times(4)).log(Mockito.anyObject());

// Do what the scheduler would do.
treatmentLog.sendImpressions();

verify(senderMock).postImpressionsBulk(impressionsCaptor.capture());
verify(storage).put(impressionKeyList.capture());

List<TestImpressions> captured = impressionsCaptor.getValue();
List captured = impressionKeyList.getValue();

Assert.assertEquals(2, captured.size());
Assert.assertEquals(4, captured.size());
}

@Test
public void testImpressionListenerNone() throws URISyntaxException {
public void testImpressionListenerNone() {
SplitClientConfig config = SplitClientConfig.builder()
.impressionsQueueSize(10)
.endpoint("nowhere.com", "nowhere.com")
.impressionsMode(ImpressionsManager.Mode.NONE)
.build();
ImpressionsStorage storage = new InMemoryImpressionsStorage(config.impressionsQueueSize());
ImpressionsStorage storage = Mockito.mock(InMemoryImpressionsStorage.class);

ImpressionsSender senderMock = Mockito.mock(ImpressionsSender.class);
TelemetrySynchronizer telemetrySynchronizer = Mockito.mock(TelemetryInMemorySubmitter.class);
Expand All @@ -214,8 +210,8 @@ public void testImpressionListenerNone() throws URISyntaxException {
ImpressionsManagerImpl treatmentLog = ImpressionsManagerImpl.instanceForTest(config, senderMock, TELEMETRY_STORAGE, storage, storage, processImpressionStrategy, impressionCounter, impressionListener);
treatmentLog.start();

KeyImpression ki1 = keyImpression("test1", "adil", "on", 1L, null);
KeyImpression ki2 = keyImpression("test1", "adil", "on", 2L, 1L);
KeyImpression ki1 = keyImpression("test1", "adil", "on", 1L, 1L);
KeyImpression ki2 = keyImpression("test1", "adil", "on", 1L, 1L);
KeyImpression ki3 = keyImpression("test1", "pato", "on", 3L, 2L);
KeyImpression ki4 = keyImpression("test2", "pato", "on", 4L, 3L);

Expand All @@ -227,10 +223,16 @@ public void testImpressionListenerNone() throws URISyntaxException {

treatmentLog.track(impressionList);
verify(impressionListener, times(4)).log(Mockito.anyObject());

verify(storage).put(impressionKeyList.capture());

List captured = impressionKeyList.getValue();

Assert.assertEquals(0, captured.size());
}

@Test
public void worksButDropsImpressions() throws URISyntaxException {
public void worksButDropsImpressions() {

SplitClientConfig config = SplitClientConfig.builder()
.impressionsQueueSize(3)
Expand Down Expand Up @@ -271,7 +273,7 @@ public void worksButDropsImpressions() throws URISyntaxException {
}

@Test
public void works4ImpressionsInOneTest() throws URISyntaxException {
public void works4ImpressionsInOneTest() {

SplitClientConfig config = SplitClientConfig.builder()
.impressionsQueueSize(10)
Expand Down Expand Up @@ -314,7 +316,7 @@ public void works4ImpressionsInOneTest() throws URISyntaxException {
}

@Test
public void worksNoImpressions() throws URISyntaxException {
public void worksNoImpressions() {

SplitClientConfig config = SplitClientConfig.builder()
.impressionsQueueSize(10)
Expand All @@ -340,7 +342,7 @@ public void worksNoImpressions() throws URISyntaxException {
}

@Test
public void alreadySeenImpressionsAreMarked() throws URISyntaxException {
public void alreadySeenImpressionsAreMarked() {
SplitClientConfig config = SplitClientConfig.builder()
.impressionsQueueSize(10)
.endpoint("nowhere.com", "nowhere.com")
Expand Down Expand Up @@ -396,7 +398,7 @@ public void alreadySeenImpressionsAreMarked() throws URISyntaxException {
}

@Test
public void testImpressionsStandaloneModeOptimizedMode() throws URISyntaxException {
public void testImpressionsStandaloneModeOptimizedMode() {
SplitClientConfig config = SplitClientConfig.builder()
.impressionsQueueSize(10)
.endpoint("nowhere.com", "nowhere.com")
Expand Down Expand Up @@ -452,7 +454,7 @@ public void testImpressionsStandaloneModeOptimizedMode() throws URISyntaxExcepti
}

@Test
public void testImpressionsStandaloneModeDebugMode() throws URISyntaxException {
public void testImpressionsStandaloneModeDebugMode() {
SplitClientConfig config = SplitClientConfig.builder()
.impressionsQueueSize(10)
.endpoint("nowhere.com", "nowhere.com")
Expand Down Expand Up @@ -500,7 +502,7 @@ public void testImpressionsStandaloneModeDebugMode() throws URISyntaxException {
}

@Test
public void testImpressionsStandaloneModeNoneMode() throws URISyntaxException {
public void testImpressionsStandaloneModeNoneMode() {
SplitClientConfig config = SplitClientConfig.builder()
.impressionsQueueSize(10)
.endpoint("nowhere.com", "nowhere.com")
Expand Down Expand Up @@ -556,7 +558,7 @@ public void testImpressionsStandaloneModeNoneMode() throws URISyntaxException {
}

@Test
public void testImpressionsConsumerModeOptimizedMode() throws URISyntaxException {
public void testImpressionsConsumerModeOptimizedMode() {
SplitClientConfig config = SplitClientConfig.builder()
.impressionsQueueSize(10)
.endpoint("nowhere.com", "nowhere.com")
Expand Down Expand Up @@ -613,7 +615,7 @@ public void testImpressionsConsumerModeOptimizedMode() throws URISyntaxException
}

@Test
public void testImpressionsConsumerModeNoneMode() throws URISyntaxException {
public void testImpressionsConsumerModeNoneMode() {
SplitClientConfig config = SplitClientConfig.builder()
.impressionsQueueSize(10)
.endpoint("nowhere.com", "nowhere.com")
Expand Down Expand Up @@ -670,7 +672,7 @@ public void testImpressionsConsumerModeNoneMode() throws URISyntaxException {
}

@Test
public void testImpressionsConsumerModeDebugMode() throws URISyntaxException {
public void testImpressionsConsumerModeDebugMode() {
SplitClientConfig config = SplitClientConfig.builder()
.impressionsQueueSize(10)
.endpoint("nowhere.com", "nowhere.com")
Expand Down Expand Up @@ -720,7 +722,7 @@ public void testImpressionsConsumerModeDebugMode() throws URISyntaxException {
}

@Test
public void testCounterStandaloneModeOptimizedMode() throws URISyntaxException {
public void testCounterStandaloneModeOptimizedMode() {
SplitClientConfig config = SplitClientConfig.builder()
.impressionsQueueSize(10)
.endpoint("nowhere.com", "nowhere.com")
Expand All @@ -739,7 +741,7 @@ public void testCounterStandaloneModeOptimizedMode() throws URISyntaxException {
Assert.assertNotNull(manager.getCounter());
}
@Test
public void testCounterStandaloneModeDebugMode() throws URISyntaxException {
public void testCounterStandaloneModeDebugMode() {
SplitClientConfig config = SplitClientConfig.builder()
.impressionsQueueSize(10)
.endpoint("nowhere.com", "nowhere.com")
Expand All @@ -757,7 +759,7 @@ public void testCounterStandaloneModeDebugMode() throws URISyntaxException {
}

@Test
public void testCounterStandaloneModeNoneMode() throws URISyntaxException {
public void testCounterStandaloneModeNoneMode() {
SplitClientConfig config = SplitClientConfig.builder()
.impressionsQueueSize(10)
.endpoint("nowhere.com", "nowhere.com")
Expand All @@ -775,7 +777,7 @@ public void testCounterStandaloneModeNoneMode() throws URISyntaxException {
}

@Test
public void testCounterConsumerModeOptimizedMode() throws URISyntaxException {
public void testCounterConsumerModeOptimizedMode() {
SplitClientConfig config = SplitClientConfig.builder()
.impressionsQueueSize(10)
.endpoint("nowhere.com", "nowhere.com")
Expand All @@ -795,7 +797,7 @@ public void testCounterConsumerModeOptimizedMode() throws URISyntaxException {
}

@Test
public void testCounterConsumerModeDebugMode() throws URISyntaxException {
public void testCounterConsumerModeDebugMode() {
SplitClientConfig config = SplitClientConfig.builder()
.impressionsQueueSize(10)
.endpoint("nowhere.com", "nowhere.com")
Expand All @@ -814,7 +816,7 @@ public void testCounterConsumerModeDebugMode() throws URISyntaxException {
}

@Test
public void testCounterConsumerModeNoneMode() throws URISyntaxException {
public void testCounterConsumerModeNoneMode() {
SplitClientConfig config = SplitClientConfig.builder()
.impressionsQueueSize(10)
.endpoint("nowhere.com", "nowhere.com")
Expand Down

0 comments on commit eade9da

Please sign in to comment.