Search in sources :

Example 6 with RotationListener

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));
}
Also used : RotationListener(org.neo4j.logging.RotatingFileOutputStreamSupplier.RotationListener) Test(org.junit.Test)

Example 7 with RotationListener

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);
}
Also used : Executor(java.util.concurrent.Executor) RotationListener(org.neo4j.logging.RotatingFileOutputStreamSupplier.RotationListener) AdversarialOutputStream(org.neo4j.adversaries.fs.AdversarialOutputStream) OutputStream(java.io.OutputStream) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)7 RotationListener (org.neo4j.logging.RotatingFileOutputStreamSupplier.RotationListener)7 OutputStream (java.io.OutputStream)6 AdversarialOutputStream (org.neo4j.adversaries.fs.AdversarialOutputStream)6 IOException (java.io.IOException)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)3 DefaultFileSystemAbstraction (org.neo4j.io.fs.DefaultFileSystemAbstraction)3 File (java.io.File)2 Executor (java.util.concurrent.Executor)2 AdversarialFileSystemAbstraction (org.neo4j.adversaries.fs.AdversarialFileSystemAbstraction)2 DelegatingFileSystemAbstraction (org.neo4j.graphdb.mockfs.DelegatingFileSystemAbstraction)2 EphemeralFileSystemAbstraction (org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction)2 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)2 FileNotFoundException (java.io.FileNotFoundException)1 ClosedChannelException (java.nio.channels.ClosedChannelException)1 ArrayList (java.util.ArrayList)1 ExecutorService (java.util.concurrent.ExecutorService)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1