Skip to content

Commit dde3f65

Browse files
committed
Fixed race condition in periodic sink test.
1 parent c1bc0cc commit dde3f65

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/test/java/com/arpnetworking/tsdcore/sinks/PeriodicStatisticsSinkTest.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import org.mockito.Mockito;
2626

2727
import java.util.concurrent.ScheduledExecutorService;
28-
import java.util.concurrent.TimeUnit;
2928

3029
/**
3130
* Tests for the <code>PeriodicStatisticsSink</code> class.
@@ -57,15 +56,15 @@ public void testFlushOnClose() {
5756
}
5857

5958
@Test
60-
public void testPeriodicFlush() throws InterruptedException {
59+
public void testPeriodicFlush() {
6160
final ScheduledExecutorService executor = Mockito.mock(ScheduledExecutorService.class);
6261
final ArgumentCaptor<Runnable> runnableCaptor = ArgumentCaptor.forClass(Runnable.class);
6362
final Sink statisticsSink = new PeriodicStatisticsSink(_statisticsSinkBuilder, executor);
6463
Mockito.verify(executor).scheduleAtFixedRate(
6564
runnableCaptor.capture(),
6665
Mockito.anyLong(),
6766
Mockito.anyLong(),
68-
Mockito.<TimeUnit>any());
67+
Mockito.any());
6968

7069
final Runnable periodicRunnable = runnableCaptor.getValue();
7170

@@ -91,7 +90,15 @@ public void testPeriodicFlush() throws InterruptedException {
9190

9291
@Test
9392
public void testRecordProcessedAggregateData() {
94-
final Sink statisticsSink = _statisticsSinkBuilder.build();
93+
final ScheduledExecutorService executor = Mockito.mock(ScheduledExecutorService.class);
94+
final ArgumentCaptor<Runnable> runnableCaptor = ArgumentCaptor.forClass(Runnable.class);
95+
final Sink statisticsSink = new PeriodicStatisticsSink(_statisticsSinkBuilder, executor);
96+
Mockito.verify(executor).scheduleAtFixedRate(
97+
runnableCaptor.capture(),
98+
Mockito.anyLong(),
99+
Mockito.anyLong(),
100+
Mockito.any());
101+
95102
Mockito.verify(_mockMetricsFactory).create();
96103
Mockito.verify(_mockMetrics).resetCounter(COUNTER_NAME);
97104

0 commit comments

Comments
 (0)