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);
}
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;
}
}
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;
}
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);
}
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);
}
Aggregations