Search in sources :

Example 1 with DivolteFile

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

the class FileFlusherTest method shouldAttemptReconnectAfterHeartbeatRollCreateFailure.

@Test
public void shouldAttemptReconnectAfterHeartbeatRollCreateFailure() throws IOException, InterruptedException {
    final FileStrategyConfiguration fileStrategyConfiguration = setupConfiguration("50 milliseconds", "1 hour", "2");
    // 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).thenThrow(// Second file creation fails
    new IOException("file create")).thenReturn(// Third file creation succeeds
    file);
    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);
    calls.verify(file).sync();
    Thread.sleep(100);
    // Rolling the file fails at this point (due to closeAndPublish failure)
    assertEquals(PAUSE, flusher.heartbeat());
    calls.verify(file).closeAndPublish();
    // File rolled; expecting creation of a new file, which fails
    calls.verify(manager).createFile(anyString());
    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 2 with DivolteFile

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

the class FileFlusherTest method shouldAttemptReconnectMoreThanOnceAfterProcessFailure.

@Test
public void shouldAttemptReconnectMoreThanOnceAfterProcessFailure() 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);
    final Item<AvroRecordBuffer> item = itemFromAvroRecordBuffer(newAvroRecordBuffer());
    when(manager.createFile(anyString())).thenReturn(// Flusher construction succeeds
    file).thenThrow(// Second file creation fails
    new IOException("create file")).thenReturn(// Third creation succeeds
    file);
    doThrow(new IOException("append")).when(file).append(// first append fails
    item.payload);
    final FileFlusher flusher = new FileFlusher(fileStrategyConfiguration, manager, 50L);
    assertEquals(PAUSE, flusher.process(item));
    calls.verify(file).append(item.payload);
    calls.verify(file).discard();
    Thread.sleep(100);
    // Fail recovery on first attempt
    assertEquals(PAUSE, flusher.heartbeat());
    calls.verify(manager).createFile(anyString());
    Thread.sleep(100);
    // Succeed recovery on second attempt
    assertEquals(CONTINUE, flusher.heartbeat());
    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 3 with DivolteFile

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

the class FileFlusherTest method shouldDiscardEmptyFile.

@Test
public void shouldDiscardEmptyFile() 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);
    Thread.sleep(200);
    assertEquals(CONTINUE, flusher.heartbeat());
    calls.verify(file).discard();
    calls.verify(manager).createFile(anyString());
    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 4 with DivolteFile

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

the class FileFlusherTest method shouldAttemptReconnectAfterProcessFailure.

@Test
public void shouldAttemptReconnectAfterProcessFailure() 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);
    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, 50L);
    // 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();
    Thread.sleep(100);
    // Recover on first attempt, since creating a new file works
    assertEquals(CONTINUE, flusher.heartbeat());
    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 5 with DivolteFile

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

the class FileFlusherTest method shouldSyncAndRollFileTimeBased.

@Test
public void shouldSyncAndRollFileTimeBased() throws IOException, InterruptedException {
    final FileStrategyConfiguration fileStrategyConfiguration = setupConfiguration("300 milliseconds", "50 milliseconds", "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));
    calls.verify(file).append(item.payload);
    Thread.sleep(100);
    assertEquals(CONTINUE, flusher.heartbeat());
    calls.verify(file).sync();
    Thread.sleep(400);
    assertEquals(CONTINUE, flusher.process(item));
    calls.verify(file).append(item.payload);
    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