@Override public boolean isOpen() { return tx.isOpen(); }
@Override public boolean isOpen() { return internal.isOpen(); }
private static KernelTransaction newTransaction() { KernelTransaction transaction = mock( KernelTransaction.class ); when( transaction.isOpen() ).thenReturn( true ); return transaction; }
void closeTransaction( MutableTransactionState ctx, boolean success ) throws TransactionFailureException { KernelTransaction tx = ctx.currentTransaction; ctx.currentTransaction = null; if ( tx != null ) { try { if ( success ) { tx.success(); } else { tx.failure(); } if ( tx.isOpen() ) { tx.close(); } } finally { ctx.currentTransaction = null; } } }
@Test public void shouldThrowTransactionExceptionOnTransientKernelException() throws Exception { // GIVEN KernelTransaction kernelTransaction = mock( KernelTransaction.class ); when( kernelTransaction.isOpen() ).thenReturn( true ); doThrow( new RuntimeException( "Just a random failure" ) ).when( kernelTransaction ).close(); TopLevelTransaction transaction = new TopLevelTransaction( kernelTransaction ); // WHEN transaction.success(); try { transaction.close(); fail( "Should have failed" ); } catch ( org.neo4j.graphdb.TransactionFailureException e ) { // THEN Good } }
@Test public void shouldLetThroughTransientFailureException() throws Exception { // GIVEN KernelTransaction kernelTransaction = mock( KernelTransaction.class ); when( kernelTransaction.isOpen() ).thenReturn( true ); doThrow( new TransientDatabaseFailureException( "Just a random failure" ) ).when( kernelTransaction ).close(); TopLevelTransaction transaction = new TopLevelTransaction( kernelTransaction ); // WHEN transaction.success(); try { transaction.close(); fail( "Should have failed" ); } catch ( TransientFailureException e ) { // THEN Good } }
@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(); TopLevelTransaction transaction = new TopLevelTransaction( kernelTransaction ); transaction.success(); try { transaction.close(); fail( "Should have failed" ); } catch ( Exception e ) { assertThat( e, instanceOf( TransientTransactionFailureException.class ) ); assertSame( error, e.getCause() ); } }
@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(); TopLevelTransaction transaction = new TopLevelTransaction( kernelTransaction ); // WHEN transaction.success(); try { transaction.close(); fail( "Should have failed" ); } catch ( TransientTransactionFailureException e ) { // THEN Good } }
@Test public void testRollbackError() throws Throwable { // Given BoltStateMachine machine = init( newMachine() ); // Given there is a running transaction machine.process( new RunMessage( "BEGIN", EMPTY_PARAMS ), nullResponseHandler() ); machine.process( DiscardAllMessage.INSTANCE, nullResponseHandler() ); // And given that transaction will fail to roll back TransactionStateMachine txMachine = txStateMachine( machine ); when( txMachine.ctx.currentTransaction.isOpen() ).thenReturn( true ); doThrow( new TransactionFailureException( "No Mr. Bond, I expect you to die." ) ). when( txMachine.ctx.currentTransaction ).close(); // When machine.process( new RunMessage( "ROLLBACK", EMPTY_PARAMS ), nullResponseHandler() ); machine.process( DiscardAllMessage.INSTANCE, nullResponseHandler() ); // Then assertThat( machine, inState( FailedState.class ) ); }
if ( transaction.isOpen() )
public boolean transactionIsOpen() { try { Field transactionField = nativeTransaction.getClass().getDeclaredField("transaction"); transactionField.setAccessible(true); KernelTransaction kernelTransaction = (KernelTransaction) transactionField.get(nativeTransaction); return kernelTransaction.isOpen(); } catch (Exception e) { return false; } } }
public boolean transactionIsOpen() { try { Field transactionField = nativeTransaction.getClass().getDeclaredField("transaction"); transactionField.setAccessible(true); KernelTransaction kernelTransaction = (KernelTransaction) transactionField.get(nativeTransaction); return kernelTransaction.isOpen(); } catch (Exception e) { return false; } } }
@Override public boolean running() { final long currentTime = System.currentTimeMillis(); if (currentTime > lastCheck + interval) { if (transaction.getReasonIfTerminated().isPresent() || !transaction.isOpen()) { running = false; } lastCheck = currentTime; } return running; } }
@Override public boolean running() { final long currentTime = System.currentTimeMillis(); if (currentTime > lastCheck + interval) { if (transaction.getReasonIfTerminated().isPresent() || !transaction.isOpen()) { running = false; } lastCheck = currentTime; } return running; } }
void closeTransaction( MutableTransactionState ctx, boolean success ) throws TransactionFailureException { KernelTransaction tx = ctx.currentTransaction; ctx.currentTransaction = null; if ( tx != null ) { try { if ( success ) { tx.success(); } else { tx.failure(); } if ( tx.isOpen() ) { tx.close(); } } finally { ctx.currentTransaction = null; } } }
if ( transaction.isOpen() )