Search in sources :

Example 1 with StatisticProvider

use of org.neo4j.kernel.impl.query.statistic.StatisticProvider 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)

Aggregations

Test (org.junit.jupiter.api.Test)1 ReturnsDeepStubs (org.mockito.internal.stubbing.defaultanswers.ReturnsDeepStubs)1 ExecutingQuery (org.neo4j.kernel.api.query.ExecutingQuery)1 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)1 StatisticProvider (org.neo4j.kernel.impl.query.statistic.StatisticProvider)1