Search in sources :

Example 81 with InternalTransaction

use of org.neo4j.kernel.impl.coreapi.InternalTransaction in project neo4j by neo4j.

the class Neo4jTransactionalContextTest method shouldBePossibleToTerminateWithoutActiveTransaction.

@Test
void shouldBePossibleToTerminateWithoutActiveTransaction() {
    InternalTransaction tx = mock(InternalTransaction.class);
    Neo4jTransactionalContext context = newContext(tx);
    context.close();
    context.terminate();
    verify(tx, never()).terminate();
}
Also used : InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Test(org.junit.jupiter.api.Test)

Example 82 with InternalTransaction

use of org.neo4j.kernel.impl.coreapi.InternalTransaction 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 83 with InternalTransaction

use of org.neo4j.kernel.impl.coreapi.InternalTransaction 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 84 with InternalTransaction

use of org.neo4j.kernel.impl.coreapi.InternalTransaction in project neo4j by neo4j.

the class Neo4jTransactionalContextTest method shouldBeOpenAfterCreation.

@Test
void shouldBeOpenAfterCreation() {
    InternalTransaction tx = mock(InternalTransaction.class);
    Neo4jTransactionalContext context = newContext(tx);
    assertTrue(context.isOpen());
}
Also used : InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Test(org.junit.jupiter.api.Test)

Example 85 with InternalTransaction

use of org.neo4j.kernel.impl.coreapi.InternalTransaction in project neo4j by neo4j.

the class Neo4jTransactionalContextTest method shouldThrowWhenRestartedAfterTermination.

@Test
void shouldThrowWhenRestartedAfterTermination() {
    MutableObject<Status> terminationReason = new MutableObject<>();
    InternalTransaction tx = mock(InternalTransaction.class);
    doAnswer(invocation -> {
        terminationReason.setValue(Status.Transaction.Terminated);
        return null;
    }).when(tx).terminate();
    when(tx.terminationReason()).then(invocation -> Optional.ofNullable(terminationReason.getValue()));
    Neo4jTransactionalContext context = newContext(tx);
    context.terminate();
    assertThrows(TransactionTerminatedException.class, context::commitAndRestartTx);
}
Also used : Status(org.neo4j.kernel.api.exceptions.Status) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) MutableObject(org.apache.commons.lang3.mutable.MutableObject) Test(org.junit.jupiter.api.Test)

Aggregations

InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)126 Transaction (org.neo4j.graphdb.Transaction)58 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)53 Test (org.junit.jupiter.api.Test)46 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)20 MethodSource (org.junit.jupiter.params.provider.MethodSource)18 Node (org.neo4j.graphdb.Node)16 NodeValueIndexCursor (org.neo4j.internal.kernel.api.NodeValueIndexCursor)15 ArrayList (java.util.ArrayList)13 Test (org.junit.Test)12 Result (org.neo4j.graphdb.Result)12 TokenRead (org.neo4j.internal.kernel.api.TokenRead)11 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)10 IndexReadSession (org.neo4j.internal.kernel.api.IndexReadSession)8 ExecutingQuery (org.neo4j.kernel.api.query.ExecutingQuery)7 Relationship (org.neo4j.graphdb.Relationship)6 GraphDatabaseQueryService (org.neo4j.kernel.GraphDatabaseQueryService)6 GraphDatabaseFacade (org.neo4j.kernel.impl.factory.GraphDatabaseFacade)6 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)6 ReturnsDeepStubs (org.mockito.internal.stubbing.defaultanswers.ReturnsDeepStubs)5