use of io.divolte.server.config.FileStrategyConfiguration 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();
}
use of io.divolte.server.config.FileStrategyConfiguration in project divolte-collector by divolte.
the class FileFlusherTest method shouldAttemptReconnectAfterHeartbeatRollCloseFailure.
@Test
public void shouldAttemptReconnectAfterHeartbeatRollCloseFailure() 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).thenReturn(// Second file creation succeeds
file);
doThrow(new IOException("close")).when(file).closeAndPublish();
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();
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();
}
use of io.divolte.server.config.FileStrategyConfiguration 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();
}
use of io.divolte.server.config.FileStrategyConfiguration in project divolte-collector by divolte.
the class FileFlusherTest method shouldPostponeFailureOnConstruction.
@Test
public void shouldPostponeFailureOnConstruction() 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())).thenThrow(// First file creation fails
new IOException("file create")).thenReturn(// Second file creation fails
file);
// Actual failing invocation of manager.createNewFile(...) happens here
final FileFlusher flusher = new FileFlusher(fileStrategyConfiguration, manager, 50L);
calls.verify(manager).createFile(anyString());
// Exception should be re-thrown at this point
assertEquals(PAUSE, flusher.process(item));
// Important: should not hit file.append(...)
Thread.sleep(100);
assertEquals(CONTINUE, flusher.heartbeat());
calls.verify(manager).createFile(anyString());
calls.verifyNoMoreInteractions();
}
use of io.divolte.server.config.FileStrategyConfiguration 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();
}
Aggregations