Search in sources :

Example 26 with AssertableLogProvider

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

the class BatchingMessageHandlerTest method shouldDropMessagesAfterBeingStopped.

@Test
public void shouldDropMessagesAfterBeingStopped() throws Exception {
    // given
    AssertableLogProvider logProvider = new AssertableLogProvider();
    BatchingMessageHandler batchHandler = new BatchingMessageHandler(raftStateMachine, QUEUE_SIZE, MAX_BATCH, logProvider);
    RaftMessages.ClusterIdAwareMessage message = new RaftMessages.ClusterIdAwareMessage(localClusterId, new RaftMessages.NewEntry.Request(null, null));
    batchHandler.stop();
    // when
    batchHandler.handle(message);
    batchHandler.run();
    // then
    verifyZeroInteractions(raftStateMachine);
    logProvider.assertAtLeastOnce(AssertableLogProvider.inLog(BatchingMessageHandler.class).debug("This handler has been stopped, dropping the message: %s", message));
}
Also used : RaftMessages(org.neo4j.causalclustering.core.consensus.RaftMessages) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.Test)

Example 27 with AssertableLogProvider

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

the class QueryLoggerIT method setUp.

@Before
public void setUp() {
    logsDirectory = new File(testDirectory.graphDbDir(), "logs");
    logFilename = new File(logsDirectory, "query.log");
    AssertableLogProvider inMemoryLog = new AssertableLogProvider();
    databaseBuilder = new TestEnterpriseGraphDatabaseFactory().setFileSystem(new UncloseableDelegatingFileSystemAbstraction(fileSystem.get())).setInternalLogProvider(inMemoryLog).newImpermanentDatabaseBuilder(testDirectory.graphDbDir());
}
Also used : TestEnterpriseGraphDatabaseFactory(org.neo4j.test.TestEnterpriseGraphDatabaseFactory) UncloseableDelegatingFileSystemAbstraction(org.neo4j.graphdb.mockfs.UncloseableDelegatingFileSystemAbstraction) File(java.io.File) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Before(org.junit.Before)

Example 28 with AssertableLogProvider

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

the class QueryLoggerTest method shouldLogQueryParametersOnFailure.

@Test
public void shouldLogQueryParametersOnFailure() throws Exception {
    // given
    final AssertableLogProvider logProvider = new AssertableLogProvider();
    Map<String, Object> params = new HashMap<>();
    params.put("ages", Arrays.asList(41, 42, 43));
    ExecutingQuery query = query(0, SESSION_1, "TestUser", QUERY_4, params, emptyMap());
    FakeClock clock = Clocks.fakeClock();
    QueryLogger queryLogger = queryLoggerWithParams(logProvider, clock);
    RuntimeException failure = new RuntimeException();
    // when
    queryLogger.startQueryExecution(query);
    clock.forward(1, TimeUnit.MILLISECONDS);
    queryLogger.endFailure(query, failure);
    // then
    logProvider.assertExactly(inLog(getClass()).error(is("1 ms: " + sessionConnectionDetails(SESSION_1, "TestUser") + " - MATCH (n) WHERE n.age IN {ages} RETURN n - {ages: [41, 42, 43]} - {}"), sameInstance(failure)));
}
Also used : ExecutingQuery(org.neo4j.kernel.api.query.ExecutingQuery) HashMap(java.util.HashMap) FakeClock(org.neo4j.time.FakeClock) QueryLogger(org.neo4j.kernel.impl.query.QueryLoggerKernelExtension.QueryLogger) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.Test)

Example 29 with AssertableLogProvider

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

the class QueryLoggerTest method shouldNotLogQueryFasterThanThreshold.

@Test
public void shouldNotLogQueryFasterThanThreshold() 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(9, TimeUnit.MILLISECONDS);
    queryLogger.endSuccess(query);
    // then
    logProvider.assertNoLoggingOccurred();
}
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 30 with AssertableLogProvider

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

the class QueryLoggerTest method shouldKeepTrackOfDifferentSessions.

@Test
public void shouldKeepTrackOfDifferentSessions() throws Exception {
    // given
    final AssertableLogProvider logProvider = new AssertableLogProvider();
    ExecutingQuery query1 = query(0, SESSION_1, "TestUser1", QUERY_1);
    ExecutingQuery query2 = query(1, SESSION_2, "TestUser2", QUERY_2);
    ExecutingQuery query3 = query(2, SESSION_3, "TestUser3", QUERY_3);
    FakeClock clock = Clocks.fakeClock();
    QueryLogger queryLogger = queryLoggerWithoutParams(logProvider, clock);
    // when
    queryLogger.startQueryExecution(query1);
    clock.forward(1, TimeUnit.MILLISECONDS);
    queryLogger.startQueryExecution(query2);
    clock.forward(1, TimeUnit.MILLISECONDS);
    queryLogger.startQueryExecution(query3);
    clock.forward(7, TimeUnit.MILLISECONDS);
    queryLogger.endSuccess(query3);
    clock.forward(7, TimeUnit.MILLISECONDS);
    queryLogger.endSuccess(query2);
    clock.forward(7, TimeUnit.MILLISECONDS);
    queryLogger.endSuccess(query1);
    // then
    String expectedSession1String = sessionConnectionDetails(SESSION_1, "TestUser1");
    String expectedSession2String = sessionConnectionDetails(SESSION_2, "TestUser2");
    logProvider.assertExactly(inLog(getClass()).info(format("%d ms: %s - %s - {}", 15L, expectedSession2String, QUERY_2)), inLog(getClass()).info(format("%d ms: %s - %s - {}", 23L, expectedSession1String, 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)

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