use of org.neo4j.logging.RotatingFileOutputStreamSupplier.RotationListener in project neo4j by neo4j.
the class RotatingFileOutputStreamSupplierTest method shouldNotRotateLogWhenSizeExceededButNotDelay.
@Test
public void shouldNotRotateLogWhenSizeExceededButNotDelay() throws Exception {
UpdatableLongSupplier clock = new UpdatableLongSupplier(System.currentTimeMillis());
RotatingFileOutputStreamSupplier supplier = new RotatingFileOutputStreamSupplier(clock, fileSystem, logFile, 10, SECONDS.toMillis(60), 10, DIRECT_EXECUTOR, new RotationListener());
write(supplier, "A string longer than 10 bytes");
assertThat(fileSystem.fileExists(logFile), is(true));
assertThat(fileSystem.fileExists(archiveLogFile1), is(false));
write(supplier, "A string longer than 10 bytes");
assertThat(fileSystem.fileExists(logFile), is(true));
assertThat(fileSystem.fileExists(archiveLogFile1), is(true));
assertThat(fileSystem.fileExists(archiveLogFile2), is(false));
write(supplier, "A string longer than 10 bytes");
clock.setValue(clock.getAsLong() + SECONDS.toMillis(59));
write(supplier, "A string longer than 10 bytes");
clock.setValue(clock.getAsLong() + SECONDS.toMillis(1));
write(supplier, "A string longer than 10 bytes");
assertThat(fileSystem.fileExists(logFile), is(true));
assertThat(fileSystem.fileExists(archiveLogFile1), is(true));
assertThat(fileSystem.fileExists(archiveLogFile2), is(true));
assertThat(fileSystem.fileExists(archiveLogFile3), is(false));
}
use of org.neo4j.logging.RotatingFileOutputStreamSupplier.RotationListener in project neo4j by neo4j.
the class RotatingFileOutputStreamSupplierTest method shouldReattemptRotationAfterExceptionDuringJobExecution.
@Test
public void shouldReattemptRotationAfterExceptionDuringJobExecution() throws Exception {
RotationListener rotationListener = mock(RotationListener.class);
Executor executor = mock(Executor.class);
RotatingFileOutputStreamSupplier supplier = new RotatingFileOutputStreamSupplier(fileSystem, logFile, 10, 0, 10, executor, rotationListener);
OutputStream outputStream = supplier.get();
RejectedExecutionException exception = new RejectedExecutionException("text exception");
doThrow(exception).when(executor).execute(any(Runnable.class));
write(supplier, "A string longer than 10 bytes");
assertThat(supplier.get(), is(outputStream));
assertThat(supplier.get(), is(outputStream));
verify(rotationListener, times(2)).rotationError(exception, outputStream);
}
Aggregations