Search in sources :

Example 56 with KernelTransaction

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

the class TransitionalTxManagementKernelTransaction method commit.

public void commit() {
    try {
        KernelTransaction kernelTransactionBoundToThisThread = bridge.getKernelTransactionBoundToThisThread(true);
        kernelTransactionBoundToThisThread.success();
        kernelTransactionBoundToThisThread.close();
    } catch (TransactionFailureException e) {
        throw new RuntimeException(e);
    } finally {
        bridge.unbindTransactionFromCurrentThread();
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) TransactionFailureException(org.neo4j.kernel.api.exceptions.TransactionFailureException)

Example 57 with KernelTransaction

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

the class CypherExecutorTest method setUpMocks.

private void setUpMocks() {
    database = mock(Database.class);
    databaseFacade = mock(GraphDatabaseFacade.class);
    resolver = mock(DependencyResolver.class);
    executionEngine = mock(ExecutionEngine.class);
    statementBridge = mock(ThreadToStatementContextBridge.class);
    databaseQueryService = mock(GraphDatabaseQueryService.class);
    kernelTransaction = mock(KernelTransaction.class);
    statement = mock(Statement.class);
    request = mock(HttpServletRequest.class);
    InternalTransaction transaction = new TopLevelTransaction(kernelTransaction, () -> statement);
    SecurityContext securityContext = AUTH_DISABLED;
    KernelTransaction.Type type = KernelTransaction.Type.implicit;
    QueryRegistryOperations registryOperations = mock(QueryRegistryOperations.class);
    when(statement.queryRegistration()).thenReturn(registryOperations);
    when(statementBridge.get()).thenReturn(statement);
    when(kernelTransaction.securityContext()).thenReturn(securityContext);
    when(kernelTransaction.transactionType()).thenReturn(type);
    when(database.getGraph()).thenReturn(databaseFacade);
    when(databaseFacade.getDependencyResolver()).thenReturn(resolver);
    when(resolver.resolveDependency(QueryExecutionEngine.class)).thenReturn(executionEngine);
    when(resolver.resolveDependency(ThreadToStatementContextBridge.class)).thenReturn(statementBridge);
    when(resolver.resolveDependency(GraphDatabaseQueryService.class)).thenReturn(databaseQueryService);
    when(databaseQueryService.beginTransaction(type, securityContext)).thenReturn(transaction);
    when(databaseQueryService.beginTransaction(type, securityContext, CUSTOM_TRANSACTION_TIMEOUT, TimeUnit.MILLISECONDS)).thenReturn(transaction);
    when(databaseQueryService.getDependencyResolver()).thenReturn(resolver);
    when(request.getScheme()).thenReturn("http");
    when(request.getRemoteAddr()).thenReturn("127.0.0.1");
    when(request.getRemotePort()).thenReturn(5678);
    when(request.getServerName()).thenReturn("127.0.0.1");
    when(request.getServerPort()).thenReturn(7474);
    when(request.getRequestURI()).thenReturn("/");
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) GraphDatabaseQueryService(org.neo4j.kernel.GraphDatabaseQueryService) Statement(org.neo4j.kernel.api.Statement) QueryRegistryOperations(org.neo4j.kernel.api.QueryRegistryOperations) ThreadToStatementContextBridge(org.neo4j.kernel.impl.core.ThreadToStatementContextBridge) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) TopLevelTransaction(org.neo4j.kernel.impl.coreapi.TopLevelTransaction) DependencyResolver(org.neo4j.graphdb.DependencyResolver) HttpServletRequest(javax.servlet.http.HttpServletRequest) QueryExecutionEngine(org.neo4j.kernel.impl.query.QueryExecutionEngine) ExecutionEngine(org.neo4j.cypher.internal.javacompat.ExecutionEngine) SecurityContext(org.neo4j.kernel.api.security.SecurityContext) GraphDatabaseFacade(org.neo4j.kernel.impl.factory.GraphDatabaseFacade)

Example 58 with KernelTransaction

use of org.neo4j.kernel.api.KernelTransaction 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 59 with KernelTransaction

use of org.neo4j.kernel.api.KernelTransaction 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 60 with KernelTransaction

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

the class KernelTransactionsTest method shouldListActiveTransactions.

@Test
public void shouldListActiveTransactions() throws Throwable {
    // Given
    KernelTransactions transactions = newTestKernelTransactions();
    // When
    KernelTransaction first = getKernelTransaction(transactions);
    KernelTransaction second = getKernelTransaction(transactions);
    KernelTransaction third = getKernelTransaction(transactions);
    first.close();
    // Then
    assertThat(transactions.activeTransactions(), equalTo(asSet(newHandle(second), newHandle(third))));
}
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