Search in sources :

Example 6 with AssertableLogProvider

use of org.neo4j.logging.AssertableLogProvider in project neo4j by neo4j.

the class ExecutionResultSerializerTest method shouldAbbreviateWellKnownIOErrors.

@Test
public void shouldAbbreviateWellKnownIOErrors() throws Exception {
    // given
    OutputStream output = mock(OutputStream.class, new ThrowsException(new IOException("Broken pipe")));
    AssertableLogProvider logProvider = new AssertableLogProvider();
    ExecutionResultSerializer serializer = getSerializerWith(output, null, logProvider);
    // when
    serializer.finish();
    // then
    logProvider.assertExactly(AssertableLogProvider.inLog(ExecutionResultSerializer.class).error("Unable to reply to request, because the client has closed the connection (Broken pipe)."));
}
Also used : ThrowsException(org.mockito.internal.stubbing.answers.ThrowsException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) IOException(java.io.IOException) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.Test) Neo4jJsonCodecTest(org.neo4j.server.rest.transactional.Neo4jJsonCodecTest)

Example 7 with AssertableLogProvider

use of org.neo4j.logging.AssertableLogProvider in project neo4j by neo4j.

the class ExecutionResultSerializerTest method shouldLogIOErrors.

@Test
public void shouldLogIOErrors() throws Exception {
    // given
    IOException failure = new IOException();
    OutputStream output = mock(OutputStream.class, new ThrowsException(failure));
    AssertableLogProvider logProvider = new AssertableLogProvider();
    ExecutionResultSerializer serializer = getSerializerWith(output, null, logProvider);
    // when
    serializer.finish();
    // then
    logProvider.assertExactly(AssertableLogProvider.inLog(ExecutionResultSerializer.class).error(is("Failed to generate JSON output."), sameInstance(failure)));
}
Also used : ThrowsException(org.mockito.internal.stubbing.answers.ThrowsException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) IOException(java.io.IOException) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.Test) Neo4jJsonCodecTest(org.neo4j.server.rest.transactional.Neo4jJsonCodecTest)

Example 8 with AssertableLogProvider

use of org.neo4j.logging.AssertableLogProvider in project neo4j by neo4j.

the class TransactionHandleRegistryTest method acquiringATransactionThatHasAlreadyBeenAcquiredShouldThrowInvalidConcurrentTransactionAccess.

@Test
public void acquiringATransactionThatHasAlreadyBeenAcquiredShouldThrowInvalidConcurrentTransactionAccess() throws Exception {
    // Given
    AssertableLogProvider logProvider = new AssertableLogProvider();
    TransactionHandleRegistry registry = new TransactionHandleRegistry(Clocks.fakeClock(), 0, logProvider);
    TransactionHandle handle = mock(TransactionHandle.class);
    long id = registry.begin(handle);
    registry.release(id, handle);
    registry.acquire(id);
    // When
    try {
        registry.acquire(id);
        fail("Should have thrown exception");
    } catch (InvalidConcurrentTransactionAccess e) {
    // expected
    }
    // then
    logProvider.assertNoLoggingOccurred();
}
Also used : InvalidConcurrentTransactionAccess(org.neo4j.server.rest.transactional.error.InvalidConcurrentTransactionAccess) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.Test)

Example 9 with AssertableLogProvider

use of org.neo4j.logging.AssertableLogProvider in project neo4j by neo4j.

the class TransactionHandleRegistryTest method acquiringANonExistentTransactionShouldThrowErrorInvalidTransactionId.

@Test
public void acquiringANonExistentTransactionShouldThrowErrorInvalidTransactionId() throws Exception {
    // Given
    AssertableLogProvider logProvider = new AssertableLogProvider();
    TransactionHandleRegistry registry = new TransactionHandleRegistry(Clocks.fakeClock(), 0, logProvider);
    long madeUpTransactionId = 1337;
    // When
    try {
        registry.acquire(madeUpTransactionId);
        fail("Should have thrown exception");
    } catch (InvalidTransactionId e) {
    // expected
    }
    // then
    logProvider.assertNoLoggingOccurred();
}
Also used : InvalidTransactionId(org.neo4j.server.rest.transactional.error.InvalidTransactionId) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.Test)

Example 10 with AssertableLogProvider

use of org.neo4j.logging.AssertableLogProvider in project neo4j by neo4j.

the class TransactionHandleRegistryTest method gettingInterruptHandlerForUnknownIdShouldThrowErrorInvalidTransactionId.

@Test(expected = InvalidTransactionId.class)
public void gettingInterruptHandlerForUnknownIdShouldThrowErrorInvalidTransactionId() throws TransactionLifecycleException {
    // Given
    AssertableLogProvider logProvider = new AssertableLogProvider();
    FakeClock clock = Clocks.fakeClock();
    int timeoutLength = 123;
    TransactionHandleRegistry registry = new TransactionHandleRegistry(clock, timeoutLength, logProvider);
    // When
    registry.terminate(456);
}
Also used : FakeClock(org.neo4j.time.FakeClock) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.Test)

Aggregations

AssertableLogProvider (org.neo4j.logging.AssertableLogProvider)202 Test (org.junit.jupiter.api.Test)98 Test (org.junit.Test)63 Path (java.nio.file.Path)29 Log (org.neo4j.logging.Log)24 FakeClock (org.neo4j.time.FakeClock)20 SslPolicyConfig (org.neo4j.configuration.ssl.SslPolicyConfig)14 IOException (java.io.IOException)13 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)13 DynamicTest (org.junit.jupiter.api.DynamicTest)12 DynamicTest.dynamicTest (org.junit.jupiter.api.DynamicTest.dynamicTest)12 SocketAddress (org.neo4j.configuration.helpers.SocketAddress)11 NullLog (org.neo4j.logging.NullLog)11 TestDatabaseManagementServiceBuilder (org.neo4j.test.TestDatabaseManagementServiceBuilder)10 BeforeEach (org.junit.jupiter.api.BeforeEach)9 ExecutingQuery (org.neo4j.kernel.api.query.ExecutingQuery)9 QueryLogger (org.neo4j.kernel.impl.query.QueryLoggerKernelExtension.QueryLogger)9 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)8 ServerSocket (java.net.ServerSocket)8 Before (org.junit.Before)8