@Override public void close() { try { if (transaction.isOpen()) { transaction.close(); } } catch (TransientFailureException e) { // We let deadlock exceptions pass through unchanged since they aren't really transaction // failures // in the same sense as unexpected failures are. A deadlock exception signals that the // transaction // can be retried and might be successful the next time. throw e; } catch (Exception e) { String userMessage = successCalled ? "Transaction was marked as successful, but unable to commit transaction so rolled back." : "Unable to rollback transaction"; if (e instanceof KernelException && ((KernelException) e).status().code().classification() == Classification.TransientError) { throw new TransientTransactionFailureException(userMessage, e); } throw new TransactionFailureException(userMessage, e); } }
@Test public void shouldKillTransactionsOnShutdown() throws Throwable { // Given assumeThat(kernel, instanceOf(Kernel.class)); KernelTransaction tx = kernel.newTransaction(); // When ((Kernel) kernel).stop(); // Then try { tx.acquireStatement().readOperations().nodeExists(0l); fail("Should have been terminated."); } catch (TransactionTerminatedException e) { // Success } finally { tx.close(); } }
@Override public void success() { successCalled = true; transaction.success(); }
@Override public void failure() { failureCalled = true; transaction.failure(); }