Search in sources :

Example 26 with KernelTransaction

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

the class KernelTransactionImplementationTest method shouldRollbackOnClosingTerminatedTransaction.

@Test
public void shouldRollbackOnClosingTerminatedTransaction() throws Exception {
    // GIVEN
    KernelTransaction transaction = newTransaction(securityContext());
    transactionInitializer.accept(transaction);
    transaction.success();
    transaction.markForTermination(Status.General.UnknownError);
    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 27 with KernelTransaction

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

the class KernelTransactionImplementationTest method shouldRollbackAndThrowOnFailedAndSuccess.

@Test
public void shouldRollbackAndThrowOnFailedAndSuccess() throws Exception {
    // GIVEN
    boolean exceptionReceived = false;
    try (KernelTransaction transaction = newTransaction(securityContext())) {
        // WHEN
        transactionInitializer.accept(transaction);
        transaction.failure();
        transaction.success();
    } catch (TransactionFailureException e) {
        // Expected.
        exceptionReceived = true;
    }
    // THEN
    assertTrue(exceptionReceived);
    verify(transactionMonitor, times(1)).transactionFinished(false, isWriteTx);
    verifyExtraInteractionWithTheMonitor(transactionMonitor, isWriteTx);
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) TransactionFailureException(org.neo4j.kernel.api.exceptions.TransactionFailureException) Test(org.junit.Test)

Example 28 with KernelTransaction

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

the class KernelTransactionImplementationTest method shouldRollbackOnClosingSuccessfulButTerminatedTransaction.

@Test
public void shouldRollbackOnClosingSuccessfulButTerminatedTransaction() throws Exception {
    try (KernelTransaction transaction = newTransaction(securityContext())) {
        // WHEN
        transactionInitializer.accept(transaction);
        transaction.markForTermination(Status.General.UnknownError);
        assertEquals(Status.General.UnknownError, transaction.getReasonIfTerminated().get());
    }
    // 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) Test(org.junit.Test)

Example 29 with KernelTransaction

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

the class KernelTransactionImplementationTest method shouldRollbackUnsuccessfulTransaction.

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

Example 30 with KernelTransaction

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

the class KernelSchemaStateFlushingTest method dropConstraint.

private void dropConstraint(ConstraintDescriptor descriptor) throws KernelException {
    try (KernelTransaction transaction = kernel.newTransaction(KernelTransaction.Type.implicit, AUTH_DISABLED);
        Statement statement = transaction.acquireStatement()) {
        statement.schemaWriteOperations().constraintDrop(descriptor);
        transaction.success();
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Statement(org.neo4j.kernel.api.Statement)

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