use of io.divolte.server.config.FileStrategyConfiguration in project divolte-collector by divolte.
the class FileFlusherTest method shouldRollFileOnHeartbeatWithNoPendingRecords.
@Test
public void shouldRollFileOnHeartbeatWithNoPendingRecords() throws IOException, InterruptedException {
final FileStrategyConfiguration fileStrategyConfiguration = setupConfiguration("100 milliseconds", "1 hour", "1");
// Mocks
final FileManager manager = mock(FileManager.class);
final DivolteFile file = mock(DivolteFile.class);
final InOrder calls = inOrder(manager, file);
// Expect new file creation on file flusher construction
when(manager.createFile(anyString())).thenReturn(file);
final FileFlusher flusher = new FileFlusher(fileStrategyConfiguration, manager, 1L);
final Item<AvroRecordBuffer> item = itemFromAvroRecordBuffer(newAvroRecordBuffer());
assertEquals(CONTINUE, flusher.process(item));
calls.verify(file).append(item.payload);
Thread.sleep(200);
assertEquals(CONTINUE, flusher.heartbeat());
calls.verify(file).closeAndPublish();
calls.verify(manager).createFile(anyString());
calls.verifyNoMoreInteractions();
}
use of io.divolte.server.config.FileStrategyConfiguration in project divolte-collector by divolte.
the class FileFlusherTest method shouldCloseAndPublishOnExitBeforeSync.
@Test
public void shouldCloseAndPublishOnExitBeforeSync() throws IOException, InterruptedException {
final FileStrategyConfiguration fileStrategyConfiguration = setupConfiguration("1 hour", "1 hour", "200");
// Mocks
final FileManager manager = mock(FileManager.class);
final DivolteFile file = mock(DivolteFile.class);
final InOrder calls = inOrder(manager, file);
// Expect new file creation on file flusher construction
when(manager.createFile(anyString())).thenReturn(file);
final FileFlusher flusher = new FileFlusher(fileStrategyConfiguration, manager, 1L);
final Item<AvroRecordBuffer> item = itemFromAvroRecordBuffer(newAvroRecordBuffer());
assertEquals(CONTINUE, flusher.process(item));
assertEquals(CONTINUE, flusher.process(item));
calls.verify(file, times(2)).append(item.payload);
assertEquals(CONTINUE, flusher.heartbeat());
flusher.cleanup();
calls.verify(file).closeAndPublish();
calls.verifyNoMoreInteractions();
}
use of io.divolte.server.config.FileStrategyConfiguration in project divolte-collector by divolte.
the class FileFlusherTest method shouldSyncAndRollFile.
@Test
public void shouldSyncAndRollFile() throws IOException, InterruptedException {
final FileStrategyConfiguration fileStrategyConfiguration = setupConfiguration("200 milliseconds", "1 hour", "2");
// Mocks
final FileManager manager = mock(FileManager.class);
final DivolteFile file = mock(DivolteFile.class);
final InOrder calls = inOrder(manager, file);
// Expect new file creation on file flusher construction
when(manager.createFile(anyString())).thenReturn(file);
final FileFlusher flusher = new FileFlusher(fileStrategyConfiguration, manager, 1L);
final Item<AvroRecordBuffer> item = itemFromAvroRecordBuffer(newAvroRecordBuffer());
assertEquals(CONTINUE, flusher.process(item));
assertEquals(CONTINUE, flusher.process(item));
calls.verify(file, times(2)).append(item.payload);
calls.verify(file).sync();
assertEquals(CONTINUE, flusher.process(item));
calls.verify(file).append(item.payload);
Thread.sleep(300);
assertEquals(CONTINUE, flusher.heartbeat());
calls.verify(file).closeAndPublish();
calls.verify(manager).createFile(anyString());
calls.verifyNoMoreInteractions();
}
Aggregations