Search in sources :

Example 6 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)

Example 7 with TopLevelTransaction

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

the class GraphDatabaseFacadeTest method executeQueryStartDefaultTransaction.

@Test
public void executeQueryStartDefaultTransaction() {
    KernelTransaction kernelTransaction = mock(KernelTransaction.class);
    InternalTransaction transaction = new TopLevelTransaction(kernelTransaction, null);
    when(queryService.beginTransaction(KernelTransaction.Type.implicit, AUTH_DISABLED)).thenReturn(transaction);
    graphDatabaseFacade.execute("create (n)");
    graphDatabaseFacade.execute("create (n)", new HashMap<>());
    long timeout = Config.embeddedDefaults().get(GraphDatabaseSettings.transaction_timeout);
    verify(spi, times(2)).beginTransaction(KernelTransaction.Type.implicit, AUTH_DISABLED, timeout);
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) TopLevelTransaction(org.neo4j.kernel.impl.coreapi.TopLevelTransaction) 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