Search in sources :

Example 11 with AssertableLogProvider

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

the class TransactionHandleRegistryTest method shouldProvideInterruptHandlerForSuspendedTransaction.

@Test
public void shouldProvideInterruptHandlerForSuspendedTransaction() throws TransactionLifecycleException {
    // Given
    AssertableLogProvider logProvider = new AssertableLogProvider();
    FakeClock clock = Clocks.fakeClock();
    int timeoutLength = 123;
    TransactionHandleRegistry registry = new TransactionHandleRegistry(clock, timeoutLength, logProvider);
    TransactionHandle handle = mock(TransactionHandle.class);
    // Suspended Tx in Registry
    long id = registry.begin(handle);
    registry.release(id, handle);
    // When
    registry.terminate(id);
    // Then
    verify(handle, times(1)).terminate();
    verifyNoMoreInteractions(handle);
}
Also used : FakeClock(org.neo4j.time.FakeClock) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.Test)

Example 12 with AssertableLogProvider

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

the class TransactionHandleRegistryTest method transactionsShouldBeEvictedWhenUnusedLongerThanTimeout.

@Test
public void transactionsShouldBeEvictedWhenUnusedLongerThanTimeout() throws Exception {
    // Given
    FakeClock clock = Clocks.fakeClock();
    AssertableLogProvider logProvider = new AssertableLogProvider();
    TransactionHandleRegistry registry = new TransactionHandleRegistry(clock, 0, logProvider);
    TransactionHandle oldTx = mock(TransactionHandle.class);
    TransactionHandle newTx = mock(TransactionHandle.class);
    TransactionHandle handle = mock(TransactionHandle.class);
    long txId1 = registry.begin(handle);
    long txId2 = registry.begin(handle);
    // And given one transaction was stored one minute ago, and another was stored just now
    registry.release(txId1, oldTx);
    clock.forward(1, TimeUnit.MINUTES);
    registry.release(txId2, newTx);
    // When
    registry.rollbackSuspendedTransactionsIdleSince(clock.millis() - 1000);
    // Then
    assertThat(registry.acquire(txId2), equalTo(newTx));
    // And then the other should have been evicted
    try {
        registry.acquire(txId1);
        fail("Should have thrown exception");
    } catch (InvalidTransactionId e) {
    // ok
    }
    logProvider.assertExactly(inLog(TransactionHandleRegistry.class).info("Transaction with id 1 has been automatically rolled " + "back due to transaction timeout."));
}
Also used : FakeClock(org.neo4j.time.FakeClock) InvalidTransactionId(org.neo4j.server.rest.transactional.error.InvalidTransactionId) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.Test)

Example 13 with AssertableLogProvider

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

the class TransactionHandleRegistryTest method shouldProvideInterruptHandlerForActiveTransaction.

@Test
public void shouldProvideInterruptHandlerForActiveTransaction() throws TransactionLifecycleException {
    // Given
    AssertableLogProvider logProvider = new AssertableLogProvider();
    FakeClock clock = Clocks.fakeClock();
    int timeoutLength = 123;
    TransactionHandleRegistry registry = new TransactionHandleRegistry(clock, timeoutLength, logProvider);
    TransactionHandle handle = mock(TransactionHandle.class);
    // Active Tx in Registry
    long id = registry.begin(handle);
    // When
    registry.terminate(id);
    // Then
    verify(handle, times(1)).terminate();
    verifyNoMoreInteractions(handle);
}
Also used : FakeClock(org.neo4j.time.FakeClock) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.Test)

Example 14 with AssertableLogProvider

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

the class LoggingListenerTest method shouldBeAbleToOutputAMethodArgument.

@Test
public void shouldBeAbleToOutputAMethodArgument() {
    // Given
    Monitors monitors = new Monitors();
    AssertableLogProvider logProvider = new AssertableLogProvider();
    InterestingMonitor1 aMonitor = monitors.newMonitor(InterestingMonitor1.class);
    LoggingListener listener = new LoggingListener(Collections.<Class<?>, Logger>singletonMap(InterestingMonitor1.class, logProvider.getLog(InterestingMonitor1.class).errorLogger()));
    monitors.addMonitorListener(listener, listener.predicate);
    // When
    aMonitor.touch("APA");
    // Then
    logProvider.assertExactly(inLog(InterestingMonitor1.class).error("touch(String:APA)"));
}
Also used : Monitors(org.neo4j.kernel.monitoring.Monitors) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.Test)

Example 15 with AssertableLogProvider

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

the class LoggingListenerTest method shouldLogWhenThingsAreMonitored.

@Test
public void shouldLogWhenThingsAreMonitored() {
    // Given
    Monitors monitors = new Monitors();
    AssertableLogProvider logProvider = new AssertableLogProvider();
    InterestingMonitor1 aMonitor = monitors.newMonitor(InterestingMonitor1.class);
    LoggingListener listener = new LoggingListener(Collections.<Class<?>, Logger>singletonMap(InterestingMonitor1.class, logProvider.getLog(InterestingMonitor1.class).infoLogger()));
    monitors.addMonitorListener(listener, listener.predicate);
    // When
    aMonitor.touch();
    // Then
    logProvider.assertExactly(inLog(InterestingMonitor1.class).info("touch()"));
}
Also used : Monitors(org.neo4j.kernel.monitoring.Monitors) 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