Search in sources :

Example 6 with DivolteFile

use of io.divolte.server.filesinks.FileManager.DivolteFile in project divolte-collector by divolte.

the class FileFlusherTest method shouldDiscardEmptyFileOnExit.

@Test
public void shouldDiscardEmptyFileOnExit() throws IOException {
    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);
    assertEquals(CONTINUE, flusher.heartbeat());
    flusher.cleanup();
    calls.verify(file).discard();
    calls.verifyNoMoreInteractions();
}
Also used : InOrder(org.mockito.InOrder) FileStrategyConfiguration(io.divolte.server.config.FileStrategyConfiguration) DivolteFile(io.divolte.server.filesinks.FileManager.DivolteFile) Test(org.junit.Test)

Example 7 with DivolteFile

use of io.divolte.server.filesinks.FileManager.DivolteFile 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();
}
Also used : InOrder(org.mockito.InOrder) FileStrategyConfiguration(io.divolte.server.config.FileStrategyConfiguration) AvroRecordBuffer(io.divolte.server.AvroRecordBuffer) DivolteFile(io.divolte.server.filesinks.FileManager.DivolteFile) Test(org.junit.Test)

Example 8 with DivolteFile

use of io.divolte.server.filesinks.FileManager.DivolteFile in project divolte-collector by divolte.

the class FileFlusherTest method shouldPauseAndAttemptDiscardOnAnyFailure.

@Test
public void shouldPauseAndAttemptDiscardOnAnyFailure() throws IOException {
    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);
    final Item<AvroRecordBuffer> item = itemFromAvroRecordBuffer(newAvroRecordBuffer());
    // Expect new file creation on file flusher construction
    when(manager.createFile(anyString())).thenReturn(file);
    final FileFlusher flusher = new FileFlusher(fileStrategyConfiguration, manager, 1L);
    // throw exception on first record
    doThrow(new IOException("append")).when(file).append(item.payload);
    assertEquals(PAUSE, flusher.process(item));
    calls.verify(file).append(item.payload);
    calls.verify(file).discard();
    calls.verifyNoMoreInteractions();
}
Also used : InOrder(org.mockito.InOrder) FileStrategyConfiguration(io.divolte.server.config.FileStrategyConfiguration) AvroRecordBuffer(io.divolte.server.AvroRecordBuffer) DivolteFile(io.divolte.server.filesinks.FileManager.DivolteFile) IOException(java.io.IOException) Test(org.junit.Test)

Example 9 with DivolteFile

use of io.divolte.server.filesinks.FileManager.DivolteFile in project divolte-collector by divolte.

the class FileFlusherTest method shouldAttemptReconnectAfterHeartbeatSyncFailure.

@Test
public void shouldAttemptReconnectAfterHeartbeatSyncFailure() throws IOException, InterruptedException {
    final FileStrategyConfiguration fileStrategyConfiguration = setupConfiguration("1 hour", "50 milliseconds", "200");
    // Mocks
    final FileManager manager = mock(FileManager.class);
    final DivolteFile file = mock(DivolteFile.class);
    final InOrder calls = inOrder(manager, file);
    final Item<AvroRecordBuffer> item = itemFromAvroRecordBuffer(newAvroRecordBuffer());
    when(manager.createFile(anyString())).thenReturn(// Flusher construction succeeds
    file).thenReturn(// Second file creation succeeds
    file);
    doThrow(new IOException("sync")).when(file).sync();
    final FileFlusher flusher = new FileFlusher(fileStrategyConfiguration, manager, 50L);
    assertEquals(CONTINUE, flusher.process(item));
    assertEquals(CONTINUE, flusher.process(item));
    calls.verify(file, times(2)).append(item.payload);
    Thread.sleep(100);
    // Sync fails at this point
    assertEquals(PAUSE, flusher.heartbeat());
    calls.verify(file).sync();
    calls.verify(file).discard();
    // No attempt at rolling / creating a new file should be made at this point
    Thread.sleep(100);
    assertEquals(CONTINUE, flusher.heartbeat());
    // Reconnect attempt
    calls.verify(manager).createFile(anyString());
    calls.verifyNoMoreInteractions();
}
Also used : InOrder(org.mockito.InOrder) FileStrategyConfiguration(io.divolte.server.config.FileStrategyConfiguration) AvroRecordBuffer(io.divolte.server.AvroRecordBuffer) DivolteFile(io.divolte.server.filesinks.FileManager.DivolteFile) IOException(java.io.IOException) Test(org.junit.Test)

Example 10 with DivolteFile

use of io.divolte.server.filesinks.FileManager.DivolteFile 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();
}
Also used : InOrder(org.mockito.InOrder) FileStrategyConfiguration(io.divolte.server.config.FileStrategyConfiguration) AvroRecordBuffer(io.divolte.server.AvroRecordBuffer) DivolteFile(io.divolte.server.filesinks.FileManager.DivolteFile) Test(org.junit.Test)

Aggregations

FileStrategyConfiguration (io.divolte.server.config.FileStrategyConfiguration)13 DivolteFile (io.divolte.server.filesinks.FileManager.DivolteFile)13 Test (org.junit.Test)13 InOrder (org.mockito.InOrder)13 AvroRecordBuffer (io.divolte.server.AvroRecordBuffer)11 IOException (java.io.IOException)7