Search in sources :

Example 1 with TopLevelTransaction

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

the class ExecutionResultTest method activeTransaction.

private TopLevelTransaction activeTransaction() {
    ThreadToStatementContextBridge bridge = db.getDependencyResolver().resolveDependency(ThreadToStatementContextBridge.class);
    KernelTransaction kernelTransaction = bridge.getTopLevelTransactionBoundToThisThread(false);
    return kernelTransaction == null ? null : new TopLevelTransaction(kernelTransaction, null);
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) ThreadToStatementContextBridge(org.neo4j.kernel.impl.core.ThreadToStatementContextBridge) TopLevelTransaction(org.neo4j.kernel.impl.coreapi.TopLevelTransaction)

Example 2 with TopLevelTransaction

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

the class TopLevelTransactionTest method shouldThrowTransactionExceptionOnTransientKernelException.

@Test
public void shouldThrowTransactionExceptionOnTransientKernelException() throws Exception {
    // GIVEN
    KernelTransaction kernelTransaction = mock(KernelTransaction.class);
    when(kernelTransaction.isOpen()).thenReturn(true);
    doThrow(new RuntimeException("Just a random failure")).when(kernelTransaction).close();
    ThreadToStatementContextBridge bridge = new ThreadToStatementContextBridge();
    TopLevelTransaction transaction = new TopLevelTransaction(kernelTransaction, bridge);
    // WHEN
    transaction.success();
    try {
        transaction.close();
        fail("Should have failed");
    } catch (org.neo4j.graphdb.TransactionFailureException e) {
    // THEN Good
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) ThreadToStatementContextBridge(org.neo4j.kernel.impl.core.ThreadToStatementContextBridge) TopLevelTransaction(org.neo4j.kernel.impl.coreapi.TopLevelTransaction) Test(org.junit.Test)

Example 3 with TopLevelTransaction

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

the class TopLevelTransactionTest method shouldLetThroughTransientFailureException.

@Test
public void shouldLetThroughTransientFailureException() throws Exception {
    // GIVEN
    KernelTransaction kernelTransaction = mock(KernelTransaction.class);
    when(kernelTransaction.isOpen()).thenReturn(true);
    doThrow(new TransientDatabaseFailureException("Just a random failure")).when(kernelTransaction).close();
    ThreadToStatementContextBridge bridge = new ThreadToStatementContextBridge();
    TopLevelTransaction transaction = new TopLevelTransaction(kernelTransaction, bridge);
    // WHEN
    transaction.success();
    try {
        transaction.close();
        fail("Should have failed");
    } catch (TransientFailureException e) {
    // THEN Good
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) TransientFailureException(org.neo4j.graphdb.TransientFailureException) ThreadToStatementContextBridge(org.neo4j.kernel.impl.core.ThreadToStatementContextBridge) TransientDatabaseFailureException(org.neo4j.graphdb.TransientDatabaseFailureException) TopLevelTransaction(org.neo4j.kernel.impl.coreapi.TopLevelTransaction) Test(org.junit.Test)

Example 4 with TopLevelTransaction

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

the class TopLevelTransactionTest method shouldThrowTransientExceptionOnTransientKernelException.

@Test
public void shouldThrowTransientExceptionOnTransientKernelException() throws Exception {
    // GIVEN
    KernelTransaction kernelTransaction = mock(KernelTransaction.class);
    when(kernelTransaction.isOpen()).thenReturn(true);
    doThrow(new TransactionFailureException(Status.Transaction.ConstraintsChanged, "Proving that TopLevelTransaction does the right thing")).when(kernelTransaction).close();
    ThreadToStatementContextBridge bridge = new ThreadToStatementContextBridge();
    TopLevelTransaction transaction = new TopLevelTransaction(kernelTransaction, bridge);
    // WHEN
    transaction.success();
    try {
        transaction.close();
        fail("Should have failed");
    } catch (TransientTransactionFailureException e) {
    // THEN Good
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) TransientTransactionFailureException(org.neo4j.graphdb.TransientTransactionFailureException) TransactionFailureException(org.neo4j.kernel.api.exceptions.TransactionFailureException) ThreadToStatementContextBridge(org.neo4j.kernel.impl.core.ThreadToStatementContextBridge) TransientTransactionFailureException(org.neo4j.graphdb.TransientTransactionFailureException) TopLevelTransaction(org.neo4j.kernel.impl.coreapi.TopLevelTransaction) Test(org.junit.Test)

Example 5 with TopLevelTransaction

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

the class TopLevelTransactionTest method shouldShowTransactionTerminatedExceptionAsTransient.

@Test
public void shouldShowTransactionTerminatedExceptionAsTransient() throws Exception {
    KernelTransaction kernelTransaction = mock(KernelTransaction.class);
    doReturn(true).when(kernelTransaction).isOpen();
    RuntimeException error = new TransactionTerminatedException(Status.Transaction.Terminated);
    doThrow(error).when(kernelTransaction).close();
    ThreadToStatementContextBridge bridge = new ThreadToStatementContextBridge();
    TopLevelTransaction transaction = new TopLevelTransaction(kernelTransaction, bridge);
    transaction.success();
    try {
        transaction.close();
        fail("Should have failed");
    } catch (Exception e) {
        assertThat(e, instanceOf(TransientTransactionFailureException.class));
        assertSame(error, e.getCause());
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) TransactionTerminatedException(org.neo4j.graphdb.TransactionTerminatedException) ThreadToStatementContextBridge(org.neo4j.kernel.impl.core.ThreadToStatementContextBridge) TopLevelTransaction(org.neo4j.kernel.impl.coreapi.TopLevelTransaction) TransactionTerminatedException(org.neo4j.graphdb.TransactionTerminatedException) TransientTransactionFailureException(org.neo4j.graphdb.TransientTransactionFailureException) TransientDatabaseFailureException(org.neo4j.graphdb.TransientDatabaseFailureException) TransactionFailureException(org.neo4j.kernel.api.exceptions.TransactionFailureException) TransientFailureException(org.neo4j.graphdb.TransientFailureException) Test(org.junit.Test)

Aggregations

KernelTransaction (org.neo4j.kernel.api.KernelTransaction)7 TopLevelTransaction (org.neo4j.kernel.impl.coreapi.TopLevelTransaction)7 ThreadToStatementContextBridge (org.neo4j.kernel.impl.core.ThreadToStatementContextBridge)6 Test (org.junit.Test)5 TransientDatabaseFailureException (org.neo4j.graphdb.TransientDatabaseFailureException)2 TransientFailureException (org.neo4j.graphdb.TransientFailureException)2 TransientTransactionFailureException (org.neo4j.graphdb.TransientTransactionFailureException)2 TransactionFailureException (org.neo4j.kernel.api.exceptions.TransactionFailureException)2 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 ExecutionEngine (org.neo4j.cypher.internal.javacompat.ExecutionEngine)1 DependencyResolver (org.neo4j.graphdb.DependencyResolver)1 TransactionTerminatedException (org.neo4j.graphdb.TransactionTerminatedException)1 GraphDatabaseQueryService (org.neo4j.kernel.GraphDatabaseQueryService)1 QueryRegistryOperations (org.neo4j.kernel.api.QueryRegistryOperations)1 Statement (org.neo4j.kernel.api.Statement)1 SecurityContext (org.neo4j.kernel.api.security.SecurityContext)1 GraphDatabaseFacade (org.neo4j.kernel.impl.factory.GraphDatabaseFacade)1 QueryExecutionEngine (org.neo4j.kernel.impl.query.QueryExecutionEngine)1