Search in sources :

Example 6 with ExecutingQuery

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

the class ExecutingQueryListTest method removingQueryInTheMiddleKeepsOrder.

@Test
public void removingQueryInTheMiddleKeepsOrder() {
    // Given
    ExecutingQuery query1 = createExecutingQuery(1, "query1");
    ExecutingQuery query2 = createExecutingQuery(2, "query2");
    ExecutingQuery query3 = createExecutingQuery(3, "query3");
    ExecutingQuery query4 = createExecutingQuery(4, "query4");
    ExecutingQuery query5 = createExecutingQuery(5, "query5");
    ExecutingQueryList list = ExecutingQueryList.EMPTY.push(query1).push(query2).push(query3).push(query4).push(query5);
    // When
    List<ExecutingQuery> result = list.remove(query3).queries().collect(Collectors.toList());
    // Then
    assertThat(result, equalTo(asList(query5, query4, query2, query1)));
}
Also used : ExecutingQuery(org.neo4j.kernel.api.query.ExecutingQuery) Test(org.junit.Test)

Example 7 with ExecutingQuery

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

the class ExecutingQueryListTest method shouldNotChangeAListWhenRemovingAQueryThatIsNotInTheList.

@Test
public void shouldNotChangeAListWhenRemovingAQueryThatIsNotInTheList() throws Exception {
    // given
    ExecutingQuery query1 = createExecutingQuery(1, "query1");
    ExecutingQuery query2 = createExecutingQuery(2, "query2");
    ExecutingQueryList list = ExecutingQueryList.EMPTY.push(query1);
    // when
    ExecutingQueryList result = list.remove(query2);
    // then
    assertThat(result, equalTo(list));
}
Also used : ExecutingQuery(org.neo4j.kernel.api.query.ExecutingQuery) Test(org.junit.Test)

Example 8 with ExecutingQuery

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

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

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

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