Search in sources :

Example 61 with KernelTransaction

use of org.neo4j.kernel.api.KernelTransaction in project neo4j by neo4j.

the class KernelTransactionsTest method shouldTellWhenTransactionsFromSnapshotHaveBeenClosed.

@Test
public void shouldTellWhenTransactionsFromSnapshotHaveBeenClosed() throws Throwable {
    // GIVEN
    KernelTransactions transactions = newKernelTransactions();
    KernelTransaction a = getKernelTransaction(transactions);
    KernelTransaction b = getKernelTransaction(transactions);
    KernelTransaction c = getKernelTransaction(transactions);
    KernelTransactionsSnapshot snapshot = transactions.get();
    assertFalse(snapshot.allClosed());
    // WHEN a gets closed
    a.close();
    assertFalse(snapshot.allClosed());
    // WHEN c gets closed and (test knowing too much) that instance getting reused in another transaction "d".
    c.close();
    KernelTransaction d = getKernelTransaction(transactions);
    assertFalse(snapshot.allClosed());
    // WHEN b finally gets closed
    b.close();
    assertTrue(snapshot.allClosed());
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Test(org.junit.Test)

Example 62 with KernelTransaction

use of org.neo4j.kernel.api.KernelTransaction in project neo4j by neo4j.

the class KernelTransactionImplementationTest method shouldRollbackOnClosingTerminatedButSuccessfulTransaction.

@Test
public void shouldRollbackOnClosingTerminatedButSuccessfulTransaction() throws Exception {
    // GIVEN
    KernelTransaction transaction = newTransaction(securityContext());
    transactionInitializer.accept(transaction);
    transaction.markForTermination(Status.General.UnknownError);
    transaction.success();
    assertEquals(Status.General.UnknownError, transaction.getReasonIfTerminated().get());
    try {
        // WHEN
        transaction.close();
        fail("Exception expected");
    } catch (Exception e) {
        assertThat(e, instanceOf(TransactionTerminatedException.class));
    }
    // THEN
    verify(transactionMonitor, times(1)).transactionFinished(false, isWriteTx);
    verify(transactionMonitor, times(1)).transactionTerminated(isWriteTx);
    verifyExtraInteractionWithTheMonitor(transactionMonitor, isWriteTx);
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) TransactionTerminatedException(org.neo4j.graphdb.TransactionTerminatedException) TransactionFailureException(org.neo4j.kernel.api.exceptions.TransactionFailureException) ExpectedException(org.junit.rules.ExpectedException) Test(org.junit.Test)

Example 63 with KernelTransaction

use of org.neo4j.kernel.api.KernelTransaction in project neo4j by neo4j.

the class KernelTransactionsTest method shouldDisposeTransactionsWhenAsked.

@Test
public void shouldDisposeTransactionsWhenAsked() throws Throwable {
    // Given
    KernelTransactions transactions = newKernelTransactions();
    transactions.disposeAll();
    KernelTransaction first = getKernelTransaction(transactions);
    KernelTransaction second = getKernelTransaction(transactions);
    KernelTransaction leftOpen = getKernelTransaction(transactions);
    first.close();
    second.close();
    // When
    transactions.disposeAll();
    // Then
    KernelTransaction postDispose = getKernelTransaction(transactions);
    assertThat(postDispose, not(equalTo(first)));
    assertThat(postDispose, not(equalTo(second)));
    assertTrue(leftOpen.getReasonIfTerminated() != null);
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Test(org.junit.Test)

Example 64 with KernelTransaction

use of org.neo4j.kernel.api.KernelTransaction in project neo4j by neo4j.

the class KernelTransactionImplementationTest method shouldCommitSuccessfulTransaction.

@Test
public void shouldCommitSuccessfulTransaction() throws Exception {
    // GIVEN
    try (KernelTransaction transaction = newTransaction(securityContext())) {
        // WHEN
        transactionInitializer.accept(transaction);
        transaction.success();
    }
    // THEN
    verify(transactionMonitor, times(1)).transactionFinished(true, isWriteTx);
    verifyExtraInteractionWithTheMonitor(transactionMonitor, isWriteTx);
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Test(org.junit.Test)

Example 65 with KernelTransaction

use of org.neo4j.kernel.api.KernelTransaction in project neo4j by neo4j.

the class KernelTransactionImplementationTest method shouldIgnoreTerminateAfterRollback.

@Test
public void shouldIgnoreTerminateAfterRollback() throws Exception {
    KernelTransaction transaction = newTransaction(securityContext());
    transactionInitializer.accept(transaction);
    transaction.close();
    transaction.markForTermination(Status.General.UnknownError);
    // THEN
    verify(transactionMonitor, times(1)).transactionFinished(false, isWriteTx);
    verifyExtraInteractionWithTheMonitor(transactionMonitor, isWriteTx);
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Test(org.junit.Test)

Aggregations

KernelTransaction (org.neo4j.kernel.api.KernelTransaction)77 Test (org.junit.Test)37 Statement (org.neo4j.kernel.api.Statement)30 TransactionFailureException (org.neo4j.kernel.api.exceptions.TransactionFailureException)14 ThreadToStatementContextBridge (org.neo4j.kernel.impl.core.ThreadToStatementContextBridge)14 KernelAPI (org.neo4j.kernel.api.KernelAPI)9 TopLevelTransaction (org.neo4j.kernel.impl.coreapi.TopLevelTransaction)8 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)7 TransactionTerminatedException (org.neo4j.graphdb.TransactionTerminatedException)6 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)6 QueryRegistryOperations (org.neo4j.kernel.api.QueryRegistryOperations)4 SecurityContext (org.neo4j.kernel.api.security.SecurityContext)4 KernelStatement (org.neo4j.kernel.impl.api.KernelStatement)4 RemoteException (java.rmi.RemoteException)3 ExpectedException (org.junit.rules.ExpectedException)3 DependencyResolver (org.neo4j.graphdb.DependencyResolver)3 GraphDatabaseQueryService (org.neo4j.kernel.GraphDatabaseQueryService)3 ShellException (org.neo4j.shell.ShellException)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2