Search in sources :

Example 11 with BoltTransaction

use of org.neo4j.bolt.dbapi.BoltTransaction in project neo4j by neo4j.

the class TransactionStateMachineTest method shouldCloseResultAndTransactionHandlesWhenExecutionFails.

@Test
void shouldCloseResultAndTransactionHandlesWhenExecutionFails() throws Exception {
    BoltTransaction transaction = newTransaction();
    BoltResultHandle resultHandle = newResultHandle(new RuntimeException("some error"));
    TransactionStateMachineSPI stateMachineSPI = newTransactionStateMachineSPI(transaction, resultHandle);
    TransactionStateMachine stateMachine = newTransactionStateMachine(stateMachineSPI);
    RuntimeException e = assertThrows(RuntimeException.class, () -> stateMachine.run("SOME STATEMENT", null));
    assertEquals("some error", e.getMessage());
    assertThat(stateMachine.ctx.statementOutcomes.entrySet()).hasSize(0);
    assertNull(stateMachine.ctx.currentTransaction);
}
Also used : BoltTransaction(org.neo4j.bolt.dbapi.BoltTransaction) BoltResultHandle(org.neo4j.bolt.runtime.BoltResultHandle) TransactionStateMachineSPI(org.neo4j.bolt.runtime.statemachine.TransactionStateMachineSPI) Test(org.junit.jupiter.api.Test)

Example 12 with BoltTransaction

use of org.neo4j.bolt.dbapi.BoltTransaction in project neo4j by neo4j.

the class TransactionStateMachine method commitTransaction.

@Override
public Bookmark commitTransaction() throws KernelException {
    try {
        BoltTransaction tx = ctx.currentTransaction;
        state = state.commitTransaction(ctx, spi);
        return newestBookmark(spi, tx);
    } catch (TransactionFailureException ex) {
        state = State.AUTO_COMMIT;
        throw ex;
    }
}
Also used : BoltTransaction(org.neo4j.bolt.dbapi.BoltTransaction) TransactionFailureException(org.neo4j.internal.kernel.api.exceptions.TransactionFailureException)

Example 13 with BoltTransaction

use of org.neo4j.bolt.dbapi.BoltTransaction in project neo4j by neo4j.

the class TransactionStateMachine method validateTransaction.

@Override
public Status validateTransaction() throws KernelException {
    BoltTransaction tx = ctx.currentTransaction;
    if (tx != null) {
        Optional<Status> statusOpt = tx.getReasonIfTerminated();
        if (statusOpt.isPresent() && statusOpt.get().code().classification().rollbackTransaction()) {
            Status pendingTerminationNotice = statusOpt.get();
            reset();
            return pendingTerminationNotice;
        }
    }
    return null;
}
Also used : Status(org.neo4j.kernel.api.exceptions.Status) BoltTransaction(org.neo4j.bolt.dbapi.BoltTransaction)

Example 14 with BoltTransaction

use of org.neo4j.bolt.dbapi.BoltTransaction in project neo4j by neo4j.

the class TransactionStateMachineTest method shouldCloseResultHandlesWhenConsumeFailsInExplicitTransaction.

@Test
void shouldCloseResultHandlesWhenConsumeFailsInExplicitTransaction() throws Throwable {
    BoltTransaction transaction = newTransaction();
    TransactionStateMachineSPI stateMachineSPI = newTransactionStateMachineSPI(transaction);
    TransactionStateMachine stateMachine = newTransactionStateMachine(stateMachineSPI);
    beginTx(stateMachine);
    stateMachine.run("SOME STATEMENT", null);
    StatementOutcome outcome = stateMachine.ctx.statementOutcomes.get(StatementMetadata.ABSENT_QUERY_ID);
    assertNotNull(outcome);
    assertNotNull(outcome.resultHandle);
    assertNotNull(outcome.result);
    RuntimeException e = assertThrows(RuntimeException.class, () -> {
        stateMachine.streamResult(StatementMetadata.ABSENT_QUERY_ID, ERROR);
    });
    assertEquals("some error", e.getMessage());
    assertThat(stateMachine.ctx.statementOutcomes.entrySet()).hasSize(0);
    assertNotNull(stateMachine.ctx.currentTransaction);
}
Also used : BoltTransaction(org.neo4j.bolt.dbapi.BoltTransaction) StatementOutcome(org.neo4j.bolt.runtime.statemachine.impl.TransactionStateMachine.StatementOutcome) TransactionStateMachineSPI(org.neo4j.bolt.runtime.statemachine.TransactionStateMachineSPI) Test(org.junit.jupiter.api.Test)

Example 15 with BoltTransaction

use of org.neo4j.bolt.dbapi.BoltTransaction in project neo4j by neo4j.

the class TransactionStateMachineTest method shouldCloseResultAndTransactionHandlesWhenConsumeFails.

@Test
void shouldCloseResultAndTransactionHandlesWhenConsumeFails() throws Exception {
    BoltTransaction transaction = newTransaction();
    TransactionStateMachineSPI stateMachineSPI = newTransactionStateMachineSPI(transaction);
    TransactionStateMachine stateMachine = newTransactionStateMachine(stateMachineSPI);
    stateMachine.run("SOME STATEMENT", null);
    StatementOutcome outcome = stateMachine.ctx.statementOutcomes.get(StatementMetadata.ABSENT_QUERY_ID);
    assertNotNull(outcome);
    assertNotNull(outcome.resultHandle);
    assertNotNull(outcome.result);
    RuntimeException e = assertThrows(RuntimeException.class, () -> {
        stateMachine.streamResult(StatementMetadata.ABSENT_QUERY_ID, ERROR);
    });
    assertEquals("some error", e.getMessage());
    assertThat(stateMachine.ctx.statementOutcomes.entrySet()).hasSize(0);
    assertNull(stateMachine.ctx.currentTransaction);
}
Also used : BoltTransaction(org.neo4j.bolt.dbapi.BoltTransaction) StatementOutcome(org.neo4j.bolt.runtime.statemachine.impl.TransactionStateMachine.StatementOutcome) TransactionStateMachineSPI(org.neo4j.bolt.runtime.statemachine.TransactionStateMachineSPI) Test(org.junit.jupiter.api.Test)

Aggregations

BoltTransaction (org.neo4j.bolt.dbapi.BoltTransaction)16 Test (org.junit.jupiter.api.Test)13 TransactionStateMachineSPI (org.neo4j.bolt.runtime.statemachine.TransactionStateMachineSPI)13 BoltResultHandle (org.neo4j.bolt.runtime.BoltResultHandle)3 StatementOutcome (org.neo4j.bolt.runtime.statemachine.impl.TransactionStateMachine.StatementOutcome)2 InOrder (org.mockito.InOrder)1 BoltQueryExecutor (org.neo4j.bolt.dbapi.BoltQueryExecutor)1 TransactionFailureException (org.neo4j.internal.kernel.api.exceptions.TransactionFailureException)1 LoginContext (org.neo4j.internal.kernel.api.security.LoginContext)1 Status (org.neo4j.kernel.api.exceptions.Status)1