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 acquireExclusiveLockAfterSharedLockStoppedOtherThread() throws Exception { AcquiredLock thisThreadsExclusiveLock = acquireExclusiveLockInThisThread(); LockAcquisition sharedLockAcquisition = acquireSharedLockInAnotherThread(); assertThreadIsWaitingForLock( sharedLockAcquisition ); sharedLockAcquisition.stop(); assertLockAcquisitionFailed( sharedLockAcquisition ); thisThreadsExclusiveLock.release(); LockAcquisition exclusiveLockAcquisition = acquireExclusiveLockInAnotherThread(); assertLockAcquisitionSucceeded( exclusiveLockAcquisition ); }
@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 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 acquireExclusiveLockAfterExclusiveLockStoppedOtherThread() throws Exception { AcquiredLock thisThreadsExclusiveLock = acquireExclusiveLockInThisThread(); LockAcquisition exclusiveLockAcquisition1 = acquireExclusiveLockInAnotherThread(); assertThreadIsWaitingForLock( exclusiveLockAcquisition1 ); exclusiveLockAcquisition1.stop(); assertLockAcquisitionFailed( exclusiveLockAcquisition1 ); thisThreadsExclusiveLock.release(); LockAcquisition exclusiveLockAcquisition2 = acquireExclusiveLockInAnotherThread(); assertLockAcquisitionSucceeded( exclusiveLockAcquisition2 ); }