use of org.neo4j.kernel.impl.query.QueryLoggerKernelExtension.QueryLogger 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)));
}
use of org.neo4j.kernel.impl.query.QueryLoggerKernelExtension.QueryLogger 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();
}
use of org.neo4j.kernel.impl.query.QueryLoggerKernelExtension.QueryLogger 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)));
}
use of org.neo4j.kernel.impl.query.QueryLoggerKernelExtension.QueryLogger 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)));
}
use of org.neo4j.kernel.impl.query.QueryLoggerKernelExtension.QueryLogger 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)));
}
Aggregations