Search in sources :

Example 21 with ExecutingQuery

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

the class ExecutingQueryListTest method removingTheLastQueryReturnsAnEmptyList.

@Test
public void removingTheLastQueryReturnsAnEmptyList() {
    // Given
    ExecutingQuery aQuery = createExecutingQuery(1, "query");
    ExecutingQueryList list = ExecutingQueryList.EMPTY.push(aQuery);
    // When
    ExecutingQueryList result = list.remove(aQuery);
    // Then
    assertThat(result, equalTo(ExecutingQueryList.EMPTY));
}
Also used : ExecutingQuery(org.neo4j.kernel.api.query.ExecutingQuery) Test(org.junit.Test)

Example 22 with ExecutingQuery

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

the class ExecutingQueryListTest method addingQueriesKeepsInsertOrder.

@Test
public void addingQueriesKeepsInsertOrder() {
    // 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.queries().collect(Collectors.toList());
    // Then
    assertThat(result, equalTo(asList(query5, query4, query3, query2, query1)));
}
Also used : ExecutingQuery(org.neo4j.kernel.api.query.ExecutingQuery) Test(org.junit.Test)

Example 23 with ExecutingQuery

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

the class Neo4jTransactionalContextTest method contextRollbackClosesAndRollbackTransaction.

@Test
void contextRollbackClosesAndRollbackTransaction() {
    ExecutingQuery executingQuery = mock(ExecutingQuery.class);
    InternalTransaction internalTransaction = mock(InternalTransaction.class, new ReturnsDeepStubs());
    KernelTransaction kernelTransaction = mockTransaction(statement);
    when(internalTransaction.kernelTransaction()).thenReturn(kernelTransaction);
    Neo4jTransactionalContext transactionalContext = new Neo4jTransactionalContext(null, internalTransaction, statement, executingQuery, transactionFactory);
    transactionalContext.rollback();
    verify(internalTransaction).rollback();
    assertFalse(transactionalContext.isOpen());
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) ExecutingQuery(org.neo4j.kernel.api.query.ExecutingQuery) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) ReturnsDeepStubs(org.mockito.internal.stubbing.defaultanswers.ReturnsDeepStubs) Test(org.junit.jupiter.api.Test)

Example 24 with ExecutingQuery

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

the class Neo4jTransactionalContextTest method accumulateExecutionStatisticOverCommitAndRestart.

@Test
void accumulateExecutionStatisticOverCommitAndRestart() {
    InternalTransaction userTransaction = mock(InternalTransaction.class, new ReturnsDeepStubs());
    when(userTransaction.terminationReason()).thenReturn(Optional.empty());
    var statementMock = mock(KernelStatement.class, new ReturnsDeepStubs());
    var transaction = mockTransaction(statementMock);
    when(userTransaction.kernelTransaction()).thenReturn(transaction);
    when(transactionFactory.beginKernelTransaction(any(), any(), any())).thenReturn(transaction);
    ExecutingQuery executingQuery = mock(ExecutingQuery.class);
    when(executingQuery.databaseId()).thenReturn(Optional.of(namedDatabaseId));
    Neo4jTransactionalContext transactionalContext = new Neo4jTransactionalContext(queryService, userTransaction, statement, executingQuery, transactionFactory);
    statistics.setFaults(2);
    statistics.setHits(5);
    transactionalContext.commitAndRestartTx();
    statistics.setFaults(2);
    statistics.setHits(5);
    transactionalContext.commitAndRestartTx();
    statistics.setFaults(2);
    statistics.setHits(5);
    StatisticProvider statisticProvider = transactionalContext.kernelStatisticProvider();
    assertEquals(6, statisticProvider.getPageCacheMisses(), "Expect to see accumulated number of page cache misses.");
    assertEquals(15, statisticProvider.getPageCacheHits(), "Expected to see accumulated number of page cache hits.");
}
Also used : ExecutingQuery(org.neo4j.kernel.api.query.ExecutingQuery) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) ReturnsDeepStubs(org.mockito.internal.stubbing.defaultanswers.ReturnsDeepStubs) StatisticProvider(org.neo4j.kernel.impl.query.statistic.StatisticProvider) Test(org.junit.jupiter.api.Test)

Example 25 with ExecutingQuery

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

the class Neo4jTransactionalContextTest method newContext.

private Neo4jTransactionalContext newContext(InternalTransaction initialTx) {
    ExecutingQuery executingQuery = mock(ExecutingQuery.class);
    when(executingQuery.databaseId()).thenReturn(Optional.of(namedDatabaseId));
    return new Neo4jTransactionalContext(queryService, initialTx, statement, executingQuery, transactionFactory);
}
Also used : ExecutingQuery(org.neo4j.kernel.api.query.ExecutingQuery)

Aggregations

ExecutingQuery (org.neo4j.kernel.api.query.ExecutingQuery)30 Test (org.junit.Test)12 QueryLogger (org.neo4j.kernel.impl.query.QueryLoggerKernelExtension.QueryLogger)9 AssertableLogProvider (org.neo4j.logging.AssertableLogProvider)9 FakeClock (org.neo4j.time.FakeClock)9 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)6 Test (org.junit.jupiter.api.Test)5 ReturnsDeepStubs (org.mockito.internal.stubbing.defaultanswers.ReturnsDeepStubs)4 HashMap (java.util.HashMap)3 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)3 ArrayList (java.util.ArrayList)2 MutableObject (org.apache.commons.lang3.mutable.MutableObject)2 InOrder (org.mockito.InOrder)2 DatabaseContext (org.neo4j.dbms.database.DatabaseContext)2 FabricTransaction (org.neo4j.fabric.transaction.FabricTransaction)2 ClientConnectionInfo (org.neo4j.internal.kernel.api.connectioninfo.ClientConnectionInfo)2 AdminActionOnResource (org.neo4j.internal.kernel.api.security.AdminActionOnResource)2 DatabaseScope (org.neo4j.internal.kernel.api.security.AdminActionOnResource.DatabaseScope)2 SecurityContext (org.neo4j.internal.kernel.api.security.SecurityContext)2 UserSegment (org.neo4j.internal.kernel.api.security.UserSegment)2