private Locks.Client stoppedClient() { try { client.stop(); return client; } catch ( Throwable t ) { throw new AssertionError( "Unable to stop client", t ); } }
@Test public void terminatedTxMarkedNeitherSuccessNorFailureClosesWithoutThrowing() throws TransactionFailureException { Locks.Client locksClient = mock( Locks.Client.class ); KernelTransactionImplementation tx = newTransaction( loginContext(), locksClient ); transactionInitializer.accept( tx ); tx.markForTermination( Status.General.UnknownError ); tx.close(); verify( locksClient ).stop(); verify( transactionMonitor ).transactionTerminated( isWriteTx ); }
@Test public void markForTerminationTerminatedTransaction() { Locks.Client locksClient = mock( Locks.Client.class ); KernelTransactionImplementation tx = newTransaction( loginContext(), locksClient ); transactionInitializer.accept( tx ); tx.markForTermination( Status.Transaction.Terminated ); tx.markForTermination( Status.Transaction.Outdated ); tx.markForTermination( Status.Transaction.LockClientStopped ); assertEquals( Status.Transaction.Terminated, tx.getReasonIfTerminated().get() ); verify( locksClient ).stop(); verify( transactionMonitor ).transactionTerminated( isWriteTx ); }
@Override public void stop() { localClient.stop(); }
@Override public void stop() { localClient.stop(); }
@Override public void stop() { client.stop(); }
@Test public void mustReleaseWriteLockWaitersOnStop() { // Given clientA.acquireShared( TRACER, NODE, 1L ); clientB.acquireShared( TRACER, NODE, 2L ); clientC.acquireShared( TRACER, NODE, 3L ); acquireExclusive( clientB, TRACER, NODE, 1L ).callAndAssertWaiting(); acquireExclusive( clientC, TRACER, NODE, 1L ).callAndAssertWaiting(); // When clientC.stop(); clientB.stop(); clientA.stop(); // All locks clients should be stopped at this point, and all all locks should be released because none of the // clients entered the prepare phase LockCountVisitor lockCountVisitor = new LockCountVisitor(); locks.accept( lockCountVisitor ); assertEquals( 0, lockCountVisitor.getLockCount() ); }
@Test public void markForTerminationWithIncorrectReuseCount() throws Exception { int reuseCount = 13; int nextReuseCount = reuseCount + 2; Status.Transaction terminationReason = Status.Transaction.Terminated; KernelTransactionImplementation tx = newNotInitializedTransaction( ); initializeAndClose( tx, reuseCount ); Locks.Client locksClient = mock( Locks.Client.class ); SimpleStatementLocks statementLocks = new SimpleStatementLocks( locksClient ); tx.initialize( 42, 42, statementLocks, KernelTransaction.Type.implicit, loginContext().authorize( s -> -1, GraphDatabaseSettings.DEFAULT_DATABASE_NAME ), 0L, 0L ); assertFalse( tx.markForTermination( nextReuseCount, terminationReason ) ); assertFalse( tx.getReasonIfTerminated().isPresent() ); verify( locksClient, never() ).stop(); }
@Test public void mustReleaseReadLockWaitersOnStop() { // Given clientA.acquireExclusive( TRACER, NODE, 1L ); clientB.acquireExclusive( TRACER, NODE, 2L ); acquireShared( clientB, TRACER, NODE, 1L ).callAndAssertWaiting(); // When clientB.stop(); clientA.stop(); // All locks clients should be stopped at this point, and all all locks should be released because none of the // clients entered the prepare phase LockCountVisitor lockCountVisitor = new LockCountVisitor(); locks.accept( lockCountVisitor ); assertEquals( 0, lockCountVisitor.getLockCount() ); }
@Test public void markForTerminationWithCorrectReuseCount() throws Exception { int reuseCount = 10; Status.Transaction terminationReason = Status.Transaction.Terminated; KernelTransactionImplementation tx = newNotInitializedTransaction( ); initializeAndClose( tx, reuseCount ); Locks.Client locksClient = mock( Locks.Client.class ); SimpleStatementLocks statementLocks = new SimpleStatementLocks( locksClient ); tx.initialize( 42, 42, statementLocks, KernelTransaction.Type.implicit, loginContext().authorize( s -> -1, GraphDatabaseSettings.DEFAULT_DATABASE_NAME ), 0L, 0L ); assertTrue( tx.markForTermination( reuseCount, terminationReason ) ); assertEquals( terminationReason, tx.getReasonIfTerminated().get() ); verify( locksClient ).stop(); }
@Test public void mustNotReleaseLocksAfterPrepareOnStop() { // Given clientA.acquireShared( TRACER, NODE, 1L ); clientA.acquireExclusive( TRACER, NODE, 2L ); clientA.prepare(); // When clientA.stop(); // The client entered the prepare phase, so it gets to keep its locks LockCountVisitor lockCountVisitor = new LockCountVisitor(); locks.accept( lockCountVisitor ); assertEquals( 2, lockCountVisitor.getLockCount() ); }
@Test public void prepareMustAllowAcquiringNewLocksAfterStop() { // Given clientA.prepare(); clientA.stop(); // When clientA.acquireShared( TRACER, NODE, 1 ); clientA.acquireExclusive( TRACER, NODE, 2 ); // Stopped essentially has no effect when it comes after the client has entered the prepare phase LockCountVisitor lockCountVisitor = new LockCountVisitor(); locks.accept( lockCountVisitor ); assertEquals( 2, lockCountVisitor.getLockCount() ); }
@Test public void mustReleaseUnpreparedLocksOnStop() { // Given clientA.acquireShared( TRACER, NODE, 1L ); clientA.acquireExclusive( TRACER, NODE, 2L ); // When clientA.stop(); // The client was stopped before it could enter the prepare phase, so all of its locks are released LockCountVisitor lockCountVisitor = new LockCountVisitor(); locks.accept( lockCountVisitor ); assertEquals( 0, lockCountVisitor.getLockCount() ); }
void stop() { getClient().stop(); } }
@Test public void terminatedTxMarkedForFailureClosesWithoutThrowing() throws TransactionFailureException { Locks.Client locksClient = mock( Locks.Client.class ); KernelTransactionImplementation tx = newTransaction( loginContext(), locksClient ); transactionInitializer.accept( tx ); tx.failure(); tx.markForTermination( Status.General.UnknownError ); tx.close(); verify( locksClient ).stop(); verify( transactionMonitor ).transactionTerminated( isWriteTx ); }
@Test public void markForTerminationInitializedTransaction() { Locks.Client locksClient = mock( Locks.Client.class ); KernelTransactionImplementation tx = newTransaction( loginContext(), locksClient ); tx.markForTermination( Status.General.UnknownError ); assertEquals( Status.General.UnknownError, tx.getReasonIfTerminated().get() ); verify( locksClient ).stop(); }
@Override public void stop() { client.stop(); }