private void acquireLockAfterOtherLockStoppedSameThread( boolean firstLockShared, boolean secondLockShared ) throws Exception { AcquiredLock thisThreadsExclusiveLock = acquireExclusiveLockInThisThread(); CountDownLatch firstLockFailed = new CountDownLatch( 1 ); CountDownLatch startSecondLock = new CountDownLatch( 1 ); LockAcquisition lockAcquisition = acquireTwoLocksInAnotherThread( firstLockShared, secondLockShared, firstLockFailed, startSecondLock ); assertThreadIsWaitingForLock( lockAcquisition ); lockAcquisition.stop(); await( firstLockFailed ); thisThreadsExclusiveLock.release(); startSecondLock.countDown(); assertLockAcquisitionSucceeded( lockAcquisition ); }
@Test public void acquireExclusiveLockWhileHoldingSharedLockCanBeStopped() throws Exception { AcquiredLock thisThreadsSharedLock = acquireSharedLockInThisThread(); CountDownLatch sharedLockAcquired = new CountDownLatch( 1 ); CountDownLatch startExclusiveLock = new CountDownLatch( 1 ); LockAcquisition acquisition = acquireSharedAndExclusiveLocksInAnotherThread( sharedLockAcquired, startExclusiveLock ); await( sharedLockAcquired ); startExclusiveLock.countDown(); assertThreadIsWaitingForLock( acquisition ); acquisition.stop(); assertLockAcquisitionFailed( acquisition ); thisThreadsSharedLock.release(); assertNoLocksHeld(); }
private void closeClientAfterLockStopped( boolean shared ) throws Exception { AcquiredLock thisThreadsExclusiveLock = acquireExclusiveLockInThisThread(); CountDownLatch firstLockAcquired = new CountDownLatch( 1 ); LockAcquisition acquisition = tryAcquireTwoLocksLockInAnotherThread( shared, firstLockAcquired ); await( firstLockAcquired ); assertThreadIsWaitingForLock( acquisition ); assertLocksHeld( FIRST_NODE_ID, SECOND_NODE_ID ); acquisition.stop(); assertLockAcquisitionFailed( acquisition ); assertLocksHeld( FIRST_NODE_ID ); thisThreadsExclusiveLock.release(); assertNoLocksHeld(); }
@Test public void exclusiveLockCanBeStopped() throws Exception { acquireExclusiveLockInThisThread(); LockAcquisition exclusiveLockAcquisition = acquireExclusiveLockInAnotherThread(); assertThreadIsWaitingForLock( exclusiveLockAcquisition ); exclusiveLockAcquisition.stop(); assertLockAcquisitionFailed( exclusiveLockAcquisition ); }
@Test public void sharedLockCanBeStopped() throws Exception { acquireExclusiveLockInThisThread(); LockAcquisition sharedLockAcquisition = acquireSharedLockInAnotherThread(); assertThreadIsWaitingForLock( sharedLockAcquisition ); sharedLockAcquisition.stop(); assertLockAcquisitionFailed( sharedLockAcquisition ); }
@Test public void acquireExclusiveLockAfterExclusiveLockStoppedOtherThread() throws Exception { AcquiredLock thisThreadsExclusiveLock = acquireExclusiveLockInThisThread(); LockAcquisition exclusiveLockAcquisition1 = acquireExclusiveLockInAnotherThread(); assertThreadIsWaitingForLock( exclusiveLockAcquisition1 ); exclusiveLockAcquisition1.stop(); assertLockAcquisitionFailed( exclusiveLockAcquisition1 ); thisThreadsExclusiveLock.release(); LockAcquisition exclusiveLockAcquisition2 = acquireExclusiveLockInAnotherThread(); assertLockAcquisitionSucceeded( exclusiveLockAcquisition2 ); }
@Test public void acquireSharedLockAfterSharedLockStoppedOtherThread() throws Exception { AcquiredLock thisThreadsExclusiveLock = acquireExclusiveLockInThisThread(); LockAcquisition sharedLockAcquisition1 = acquireSharedLockInAnotherThread(); assertThreadIsWaitingForLock( sharedLockAcquisition1 ); sharedLockAcquisition1.stop(); assertLockAcquisitionFailed( sharedLockAcquisition1 ); thisThreadsExclusiveLock.release(); LockAcquisition sharedLockAcquisition2 = acquireSharedLockInAnotherThread(); assertLockAcquisitionSucceeded( sharedLockAcquisition2 ); }
@Test public void acquireSharedLockAfterExclusiveLockStoppedOtherThread() throws Exception { AcquiredLock thisThreadsExclusiveLock = acquireExclusiveLockInThisThread(); LockAcquisition exclusiveLockAcquisition = acquireExclusiveLockInAnotherThread(); assertThreadIsWaitingForLock( exclusiveLockAcquisition ); exclusiveLockAcquisition.stop(); assertLockAcquisitionFailed( exclusiveLockAcquisition ); thisThreadsExclusiveLock.release(); LockAcquisition sharedLockAcquisition = acquireSharedLockInAnotherThread(); assertLockAcquisitionSucceeded( sharedLockAcquisition ); }
@Test public void acquireExclusiveLockAfterSharedLockStoppedOtherThread() throws Exception { AcquiredLock thisThreadsExclusiveLock = acquireExclusiveLockInThisThread(); LockAcquisition sharedLockAcquisition = acquireSharedLockInAnotherThread(); assertThreadIsWaitingForLock( sharedLockAcquisition ); sharedLockAcquisition.stop(); assertLockAcquisitionFailed( sharedLockAcquisition ); thisThreadsExclusiveLock.release(); LockAcquisition exclusiveLockAcquisition = acquireExclusiveLockInAnotherThread(); assertLockAcquisitionSucceeded( exclusiveLockAcquisition ); }