ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/StampedLockTest.java
(Generate patch)

Comparing jsr166/src/test/tck/StampedLockTest.java (file contents):
Revision 1.32 by jsr166, Sat Feb 18 00:39:20 2017 UTC vs.
Revision 1.33 by jsr166, Sat Feb 18 14:32:09 2017 UTC

# Line 476 | Line 476 | public class StampedLockTest extends JSR
476      }
477  
478      /**
479 <     * A writelock succeeds only after a reading thread unlocks
479 >     * writeLock() succeeds only after a reading thread unlocks
480       */
481      public void testWriteAfterReadLock() throws InterruptedException {
482 <        final CountDownLatch threadStarted = new CountDownLatch(1);
482 >        final CountDownLatch aboutToLock = new CountDownLatch(1);
483          final StampedLock lock = new StampedLock();
484          long rs = lock.readLock();
485          Thread t = newStartedThread(new CheckedRunnable() {
486              public void realRun() {
487 <                threadStarted.countDown();
487 >                aboutToLock.countDown();
488                  long s = lock.writeLock();
489 +                assertTrue(lock.isWriteLocked());
490 +                assertFalse(lock.isReadLocked());
491                  lock.unlockWrite(s);
492              }});
493  
494 <        threadStarted.await();
495 <        waitForThreadToEnterWaitState(t, MEDIUM_DELAY_MS);
494 >        aboutToLock.await();
495 >        waitForThreadToEnterWaitState(t);
496          assertFalse(lock.isWriteLocked());
497 +        assertTrue(lock.isReadLocked());
498          lock.unlockRead(rs);
499          awaitTermination(t);
500 <        assertFalse(lock.isWriteLocked());
500 >        assertUnlocked(lock);
501      }
502  
503      /**
504 <     * A writelock succeeds only after reading threads unlock
504 >     * writeLock() succeeds only after reading threads unlock
505       */
506      public void testWriteAfterMultipleReadLocks() {
507          final StampedLock lock = new StampedLock();
# Line 521 | Line 524 | public class StampedLockTest extends JSR
524          assertFalse(lock.isWriteLocked());
525          lock.unlockRead(s);
526          awaitTermination(t2);
527 <        assertFalse(lock.isWriteLocked());
527 >        assertUnlocked(lock);
528      }
529  
530      /**
531 <     * Readlocks succeed only after a writing thread unlocks
531 >     * readLock() succeed only after a writing thread unlocks
532       */
533      public void testReadAfterWriteLock() {
534          final StampedLock lock = new StampedLock();
535          final CountDownLatch threadsStarted = new CountDownLatch(2);
536          final long s = lock.writeLock();
537 <        Thread t1 = newStartedThread(new CheckedRunnable() {
537 >        final Runnable acquireReleaseReadLock = new CheckedRunnable() {
538              public void realRun() {
539                  threadsStarted.countDown();
540                  long rs = lock.readLock();
541 +                assertTrue(lock.isReadLocked());
542 +                assertFalse(lock.isWriteLocked());
543                  lock.unlockRead(rs);
544 <            }});
545 <        Thread t2 = newStartedThread(new CheckedRunnable() {
546 <            public void realRun() {
542 <                threadsStarted.countDown();
543 <                long rs = lock.readLock();
544 <                lock.unlockRead(rs);
545 <            }});
544 >            }};
545 >        Thread t1 = newStartedThread(acquireReleaseReadLock);
546 >        Thread t2 = newStartedThread(acquireReleaseReadLock);
547  
548          await(threadsStarted);
549 <        waitForThreadToEnterWaitState(t1, MEDIUM_DELAY_MS);
550 <        waitForThreadToEnterWaitState(t2, MEDIUM_DELAY_MS);
549 >        waitForThreadToEnterWaitState(t1);
550 >        waitForThreadToEnterWaitState(t2);
551 >        assertTrue(lock.isWriteLocked());
552 >        assertFalse(lock.isReadLocked());
553          releaseWriteLock(lock, s);
554          awaitTermination(t1);
555          awaitTermination(t2);
556 +        assertUnlocked(lock);
557      }
558  
559      /**
# Line 749 | Line 753 | public class StampedLockTest extends JSR
753          locked.await();
754          assertFalse(lock.validate(p));
755          assertEquals(0L, lock.tryOptimisticRead());
756 +        waitForThreadToEnterWaitState(t);
757          t.interrupt();
758          awaitTermination(t);
759 +        assertTrue(lock.isWriteLocked());
760      }
761  
762      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines