Search in sources :

Example 31 with AssertableLogProvider

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

the class QueryLoggerTest method shouldLogUserName.

@Test
public void shouldLogUserName() throws Exception {
    // given
    final AssertableLogProvider logProvider = new AssertableLogProvider();
    FakeClock clock = Clocks.fakeClock();
    QueryLogger queryLogger = queryLoggerWithoutParams(logProvider, clock);
    // when
    ExecutingQuery query = query(0, SESSION_1, "TestUser", QUERY_1);
    queryLogger.startQueryExecution(query);
    clock.forward(10, TimeUnit.MILLISECONDS);
    queryLogger.endSuccess(query);
    ExecutingQuery anotherQuery = query(10, SESSION_1, "AnotherUser", QUERY_1);
    queryLogger.startQueryExecution(anotherQuery);
    clock.forward(10, TimeUnit.MILLISECONDS);
    queryLogger.endSuccess(anotherQuery);
    // then
    logProvider.assertExactly(inLog(getClass()).info(format("%d ms: %s - %s - {}", 10L, sessionConnectionDetails(SESSION_1, "TestUser"), QUERY_1)), inLog(getClass()).info(format("%d ms: %s - %s - {}", 10L, sessionConnectionDetails(SESSION_1, "AnotherUser"), QUERY_1)));
}
Also used : ExecutingQuery(org.neo4j.kernel.api.query.ExecutingQuery) FakeClock(org.neo4j.time.FakeClock) QueryLogger(org.neo4j.kernel.impl.query.QueryLoggerKernelExtension.QueryLogger) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.Test)

Example 32 with AssertableLogProvider

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

the class QueryLoggerTest method shouldLogQuerySlowerThanThreshold.

@Test
public void shouldLogQuerySlowerThanThreshold() throws Exception {
    // given
    final AssertableLogProvider logProvider = new AssertableLogProvider();
    ExecutingQuery query = query(0, SESSION_1, "TestUser", QUERY_1);
    FakeClock clock = Clocks.fakeClock();
    QueryLogger queryLogger = queryLoggerWithoutParams(logProvider, clock);
    // when
    queryLogger.startQueryExecution(query);
    clock.forward(11, TimeUnit.MILLISECONDS);
    queryLogger.endSuccess(query);
    // then
    String expectedSessionString = sessionConnectionDetails(SESSION_1, "TestUser");
    logProvider.assertExactly(inLog(getClass()).info(format("%d ms: %s - %s - {}", 11L, expectedSessionString, QUERY_1)));
}
Also used : ExecutingQuery(org.neo4j.kernel.api.query.ExecutingQuery) FakeClock(org.neo4j.time.FakeClock) QueryLogger(org.neo4j.kernel.impl.query.QueryLoggerKernelExtension.QueryLogger) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.Test)

Example 33 with AssertableLogProvider

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

the class QueryLoggerTest method runAndCheck.

private void runAndCheck(String inputQuery, String outputQuery, Map<String, Object> params, String paramsString) {
    final AssertableLogProvider logProvider = new AssertableLogProvider();
    FakeClock clock = Clocks.fakeClock();
    QueryLogger queryLogger = queryLoggerWithParams(logProvider, clock);
    // when
    ExecutingQuery query = query(0, SESSION_1, "neo", inputQuery, params, emptyMap());
    queryLogger.startQueryExecution(query);
    clock.forward(10, TimeUnit.MILLISECONDS);
    queryLogger.endSuccess(query);
    // then
    logProvider.assertExactly(inLog(getClass()).info(format("%d ms: %s - %s - {%s} - {}", 10L, sessionConnectionDetails(SESSION_1, "neo"), outputQuery, paramsString)));
}
Also used : ExecutingQuery(org.neo4j.kernel.api.query.ExecutingQuery) FakeClock(org.neo4j.time.FakeClock) QueryLogger(org.neo4j.kernel.impl.query.QueryLoggerKernelExtension.QueryLogger) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider)

Example 34 with AssertableLogProvider

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

the class AsyncLoggingTest method shouldLogWhenLoggingThreadStarts.

@Test
public void shouldLogWhenLoggingThreadStarts() throws Exception {
    // given
    AssertableLogProvider logs = new AssertableLogProvider();
    AsyncLogging logging = new AsyncLogging(logs.getLog("meta"));
    // when
    new AsyncLogProvider(logging.eventSender(), logs).getLog("test").info("hello");
    // then
    logs.assertNoLoggingOccurred();
    // when
    logging.start();
    logging.stop();
    // then
    logs.assertExactly(inLog("test").info(endsWith("hello")));
}
Also used : AsyncLogProvider(org.neo4j.logging.async.AsyncLogProvider) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.Test)

Example 35 with AssertableLogProvider

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

the class LearnerContextImplTest method shouldOnlyLogLearnMissOnce.

@Test
public void shouldOnlyLogLearnMissOnce() throws Exception {
    // Given
    final AssertableLogProvider logProvider = new AssertableLogProvider();
    LearnerContextImpl ctx = new LearnerContextImpl(new InstanceId(1), mock(CommonContextState.class), logProvider, mock(Timeouts.class), mock(PaxosInstanceStore.class), mock(AcceptorInstanceStore.class), mock(ObjectInputStreamFactory.class), mock(ObjectOutputStreamFactory.class), mock(HeartbeatContextImpl.class));
    // When
    ctx.notifyLearnMiss(new org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId(1L));
    ctx.notifyLearnMiss(new org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId(1L));
    ctx.notifyLearnMiss(new org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId(2L));
    ctx.notifyLearnMiss(new org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId(2L));
    ctx.notifyLearnMiss(new org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId(1L));
    // Then
    logProvider.assertExactly(inLog(LearnerState.class).warn(containsString("Did not have learned value for Paxos instance 1.")), inLog(LearnerState.class).warn(containsString("Did not have learned value for Paxos instance 2.")), inLog(LearnerState.class).warn(containsString("Did not have learned value for Paxos instance 1.")));
}
Also used : InstanceId(org.neo4j.cluster.InstanceId) Timeouts(org.neo4j.cluster.timeout.Timeouts) PaxosInstanceStore(org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.PaxosInstanceStore) ObjectInputStreamFactory(org.neo4j.cluster.protocol.atomicbroadcast.ObjectInputStreamFactory) AcceptorInstanceStore(org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.AcceptorInstanceStore) ObjectOutputStreamFactory(org.neo4j.cluster.protocol.atomicbroadcast.ObjectOutputStreamFactory) 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