Search in sources :

Example 11 with ExecutingQuery

use of org.neo4j.kernel.api.query.ExecutingQuery 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 12 with ExecutingQuery

use of org.neo4j.kernel.api.query.ExecutingQuery 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 13 with ExecutingQuery

use of org.neo4j.kernel.api.query.ExecutingQuery 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 14 with ExecutingQuery

use of org.neo4j.kernel.api.query.ExecutingQuery in project neo4j by neo4j.

the class QueryLoggerTest method shouldLogQueryOnFailureEvenIfFasterThanThreshold.

@Test
public void shouldLogQueryOnFailureEvenIfFasterThanThreshold() 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);
    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) RETURN n - {}"), sameInstance(failure)));
}
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 15 with ExecutingQuery

use of org.neo4j.kernel.api.query.ExecutingQuery in project neo4j by neo4j.

the class QueryLoggerTest method shouldLogMetaData.

@Test
public void shouldLogMetaData() 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, emptyMap(), map("User", "UltiMate"));
    queryLogger.startQueryExecution(query);
    clock.forward(10, TimeUnit.MILLISECONDS);
    queryLogger.endSuccess(query);
    ExecutingQuery anotherQuery = query(10, SESSION_1, "AnotherUser", QUERY_1, emptyMap(), map("Place", "Town"));
    queryLogger.startQueryExecution(anotherQuery);
    clock.forward(10, TimeUnit.MILLISECONDS);
    Throwable error = new Throwable();
    queryLogger.endFailure(anotherQuery, error);
    // then
    logProvider.assertExactly(inLog(getClass()).info(format("%d ms: %s - %s - {User: 'UltiMate'}", 10L, sessionConnectionDetails(SESSION_1, "TestUser"), QUERY_1)), inLog(getClass()).error(equalTo(format("%d ms: %s - %s - {Place: 'Town'}", 10L, sessionConnectionDetails(SESSION_1, "AnotherUser"), QUERY_1)), sameInstance(error)));
}
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

ExecutingQuery (org.neo4j.kernel.api.query.ExecutingQuery)18 Test (org.junit.Test)14 QueryLogger (org.neo4j.kernel.impl.query.QueryLoggerKernelExtension.QueryLogger)9 AssertableLogProvider (org.neo4j.logging.AssertableLogProvider)9 FakeClock (org.neo4j.time.FakeClock)9 Statement (org.neo4j.kernel.api.Statement)4 ThreadToStatementContextBridge (org.neo4j.kernel.impl.core.ThreadToStatementContextBridge)3 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)3 HashMap (java.util.HashMap)2 InOrder (org.mockito.InOrder)2 ReturnsDeepStubs (org.mockito.internal.stubbing.defaultanswers.ReturnsDeepStubs)2 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)2 QueryRegistryOperations (org.neo4j.kernel.api.QueryRegistryOperations)2 SecurityContext (org.neo4j.kernel.api.security.SecurityContext)2 KernelStatement (org.neo4j.kernel.impl.api.KernelStatement)2 PropertyContainerLocker (org.neo4j.kernel.impl.coreapi.PropertyContainerLocker)2 DependencyResolver (org.neo4j.graphdb.DependencyResolver)1 GraphDatabaseQueryService (org.neo4j.kernel.GraphDatabaseQueryService)1 Guard (org.neo4j.kernel.guard.Guard)1 ClientConnectionInfo (org.neo4j.kernel.impl.query.clientconnection.ClientConnectionInfo)1