|
5 | 5 | import static org.mockito.Mockito.mock;
|
6 | 6 | import static org.mockito.Mockito.times;
|
7 | 7 | import static org.mockito.Mockito.verify;
|
| 8 | +import static org.mockito.Mockito.verifyNoMoreInteractions; |
8 | 9 |
|
9 | 10 | import java.io.IOException;
|
10 | 11 | import java.util.concurrent.TimeUnit;
|
@@ -58,6 +59,32 @@ public void testBatchWriteWithDifferenctRp() throws InterruptedException, IOExce
|
58 | 59 | verify(mockInfluxDB, times(2)).write(any(BatchPoints.class));
|
59 | 60 | }
|
60 | 61 |
|
| 62 | + @Test |
| 63 | + public void testFlushWritesBufferedPointsAndDoesNotShutdownScheduler() throws InterruptedException { |
| 64 | + InfluxDB mockInfluxDB = mock(InfluxDBImpl.class); |
| 65 | + BatchProcessor batchProcessor = BatchProcessor.builder(mockInfluxDB) |
| 66 | + .actions(Integer.MAX_VALUE) |
| 67 | + .interval(1, TimeUnit.NANOSECONDS).build(); |
| 68 | + |
| 69 | + Point point = Point.measurement("test").addField("region", "a").build(); |
| 70 | + BatchProcessor.HttpBatchEntry httpBatchEntry = new BatchProcessor.HttpBatchEntry(point, "http", "http-rp"); |
| 71 | + |
| 72 | + batchProcessor.put(httpBatchEntry); |
| 73 | + Thread.sleep(100); // wait for scheduler |
| 74 | + // Our put should have been written |
| 75 | + verify(mockInfluxDB).write(any(BatchPoints.class)); |
| 76 | + |
| 77 | + // Force a flush which should not stop the scheduler |
| 78 | + batchProcessor.flush(); |
| 79 | + |
| 80 | + batchProcessor.put(httpBatchEntry); |
| 81 | + Thread.sleep(100); // wait for scheduler |
| 82 | + // Our second put should have been written if the scheduler is still running |
| 83 | + verify(mockInfluxDB, times(2)).write(any(BatchPoints.class)); |
| 84 | + |
| 85 | + verifyNoMoreInteractions(mockInfluxDB); |
| 86 | + } |
| 87 | + |
61 | 88 | @Test(expected = IllegalArgumentException.class)
|
62 | 89 | public void testActionsIsZero() throws InterruptedException, IOException {
|
63 | 90 | InfluxDB mockInfluxDB = mock(InfluxDBImpl.class);
|
|
0 commit comments