--- jsr166/src/test/tck/ReentrantReadWriteLockTest.java 2009/11/21 02:07:27 1.35 +++ jsr166/src/test/tck/ReentrantReadWriteLockTest.java 2011/05/02 00:03:34 1.46 @@ -1,7 +1,7 @@ /* * Written by Doug Lea with assistance from members of JCP JSR-166 * Expert Group and released to the public domain, as explained at - * http://creativecommons.org/licenses/publicdomain + * http://creativecommons.org/publicdomain/zero/1.0/ * Other contributors include Andrew Wright, Jeffrey Hayes, * Pat Fisher, Mike Judd. */ @@ -9,12 +9,13 @@ import junit.framework.*; import java.util.concurrent.locks.*; import java.util.concurrent.*; +import static java.util.concurrent.TimeUnit.MILLISECONDS; import java.io.*; import java.util.*; public class ReentrantReadWriteLockTest extends JSR166TestCase { public static void main(String[] args) { - junit.textui.TestRunner.run (suite()); + junit.textui.TestRunner.run(suite()); } public static Test suite() { return new TestSuite(ReentrantReadWriteLockTest.class); @@ -58,6 +59,15 @@ public class ReentrantReadWriteLockTest } /** + * Releases lock, checking that it had a hold count of 1. + */ + void releaseLock(ReentrantReadWriteLock.WriteLock lock) { + assertTrue(lock.isHeldByCurrentThread()); + lock.unlock(); + assertFalse(lock.isHeldByCurrentThread()); + } + + /** * Constructor sets given fairness, and is in unlocked state */ public void testConstructor() { @@ -189,21 +199,16 @@ public class ReentrantReadWriteLockTest */ public void testWriteLockInterruptibly_Interrupted() throws Exception { final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); - Thread t = new Thread(new CheckedInterruptedRunnable() { + lock.writeLock().lock(); + Thread t = newStartedThread(new CheckedInterruptedRunnable() { public void realRun() throws InterruptedException { lock.writeLock().lockInterruptibly(); - lock.writeLock().unlock(); - lock.writeLock().lockInterruptibly(); - lock.writeLock().unlock(); }}); - lock.writeLock().lock(); - t.start(); Thread.sleep(SHORT_DELAY_MS); t.interrupt(); - Thread.sleep(SHORT_DELAY_MS); - lock.writeLock().unlock(); t.join(); + releaseLock(lock.writeLock()); } /** @@ -212,12 +217,12 @@ public class ReentrantReadWriteLockTest public void testWriteTryLock_Interrupted() throws InterruptedException { final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); lock.writeLock().lock(); - Thread t = new Thread(new CheckedInterruptedRunnable() { + Thread t = newStartedThread(new CheckedInterruptedRunnable() { public void realRun() throws InterruptedException { - lock.writeLock().tryLock(1000,TimeUnit.MILLISECONDS); + lock.writeLock().tryLock(SMALL_DELAY_MS, MILLISECONDS); }}); - t.start(); + Thread.sleep(SHORT_DELAY_MS); t.interrupt(); lock.writeLock().unlock(); t.join(); @@ -229,12 +234,11 @@ public class ReentrantReadWriteLockTest public void testReadLockInterruptibly_Interrupted() throws InterruptedException { final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); lock.writeLock().lock(); - Thread t = new Thread(new CheckedInterruptedRunnable() { + Thread t = newStartedThread(new CheckedInterruptedRunnable() { public void realRun() throws InterruptedException { lock.readLock().lockInterruptibly(); }}); - t.start(); Thread.sleep(SHORT_DELAY_MS); t.interrupt(); Thread.sleep(SHORT_DELAY_MS); @@ -248,12 +252,12 @@ public class ReentrantReadWriteLockTest public void testReadTryLock_Interrupted() throws InterruptedException { final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); lock.writeLock().lock(); - Thread t = new Thread(new CheckedInterruptedRunnable() { + Thread t = newStartedThread(new CheckedInterruptedRunnable() { public void realRun() throws InterruptedException { - lock.readLock().tryLock(1000,TimeUnit.MILLISECONDS); + lock.readLock().tryLock(LONG_DELAY_MS, MILLISECONDS); }}); - t.start(); + Thread.sleep(SHORT_DELAY_MS); t.interrupt(); t.join(); } @@ -265,13 +269,11 @@ public class ReentrantReadWriteLockTest public void testWriteTryLockWhenLocked() throws InterruptedException { final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); lock.writeLock().lock(); - Thread t = new Thread(new Runnable() { - public void run() { - threadAssertFalse(lock.writeLock().tryLock()); - } - }); + Thread t = newStartedThread(new CheckedRunnable() { + public void realRun() { + assertFalse(lock.writeLock().tryLock()); + }}); - t.start(); t.join(); lock.writeLock().unlock(); } @@ -282,13 +284,11 @@ public class ReentrantReadWriteLockTest public void testReadTryLockWhenLocked() throws InterruptedException { final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); lock.writeLock().lock(); - Thread t = new Thread(new Runnable() { - public void run() { - threadAssertFalse(lock.readLock().tryLock()); - } - }); + Thread t = newStartedThread(new CheckedRunnable() { + public void realRun() { + assertFalse(lock.readLock().tryLock()); + }}); - t.start(); t.join(); lock.writeLock().unlock(); } @@ -299,14 +299,12 @@ public class ReentrantReadWriteLockTest public void testMultipleReadLocks() throws InterruptedException { final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); lock.readLock().lock(); - Thread t = new Thread(new Runnable() { - public void run() { - threadAssertTrue(lock.readLock().tryLock()); - lock.readLock().unlock(); - } - }); + Thread t = newStartedThread(new CheckedRunnable() { + public void realRun() { + assertTrue(lock.readLock().tryLock()); + lock.readLock().unlock(); + }}); - t.start(); t.join(); lock.readLock().unlock(); } @@ -317,21 +315,17 @@ public class ReentrantReadWriteLockTest public void testWriteAfterMultipleReadLocks() throws InterruptedException { final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); lock.readLock().lock(); - Thread t1 = new Thread(new Runnable() { - public void run() { - lock.readLock().lock(); - lock.readLock().unlock(); - } - }); - Thread t2 = new Thread(new Runnable() { - public void run() { - lock.writeLock().lock(); - lock.writeLock().unlock(); - } - }); + Thread t1 = newStartedThread(new CheckedRunnable() { + public void realRun() { + lock.readLock().lock(); + lock.readLock().unlock(); + }}); + Thread t2 = newStartedThread(new CheckedRunnable() { + public void realRun() { + lock.writeLock().lock(); + lock.writeLock().unlock(); + }}); - t1.start(); - t2.start(); Thread.sleep(SHORT_DELAY_MS); lock.readLock().unlock(); t1.join(MEDIUM_DELAY_MS); @@ -346,21 +340,17 @@ public class ReentrantReadWriteLockTest public void testReadAfterWriteLock() throws InterruptedException { final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); lock.writeLock().lock(); - Thread t1 = new Thread(new Runnable() { - public void run() { - lock.readLock().lock(); - lock.readLock().unlock(); - } - }); - Thread t2 = new Thread(new Runnable() { - public void run() { - lock.readLock().lock(); - lock.readLock().unlock(); - } - }); + Thread t1 = newStartedThread(new CheckedRunnable() { + public void realRun() { + lock.readLock().lock(); + lock.readLock().unlock(); + }}); + Thread t2 = newStartedThread(new CheckedRunnable() { + public void realRun() { + lock.readLock().lock(); + lock.readLock().unlock(); + }}); - t1.start(); - t2.start(); Thread.sleep(SHORT_DELAY_MS); lock.writeLock().unlock(); t1.join(MEDIUM_DELAY_MS); @@ -387,21 +377,17 @@ public class ReentrantReadWriteLockTest public void testReadHoldingWriteLock2() throws InterruptedException { final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); lock.writeLock().lock(); - Thread t1 = new Thread(new Runnable() { - public void run() { - lock.readLock().lock(); - lock.readLock().unlock(); - } - }); - Thread t2 = new Thread(new Runnable() { - public void run() { - lock.readLock().lock(); - lock.readLock().unlock(); - } - }); + Thread t1 = newStartedThread(new CheckedRunnable() { + public void realRun() { + lock.readLock().lock(); + lock.readLock().unlock(); + }}); + Thread t2 = newStartedThread(new CheckedRunnable() { + public void realRun() { + lock.readLock().lock(); + lock.readLock().unlock(); + }}); - t1.start(); - t2.start(); lock.readLock().lock(); lock.readLock().unlock(); Thread.sleep(SHORT_DELAY_MS); @@ -415,27 +401,23 @@ public class ReentrantReadWriteLockTest } /** - * Read lock succeeds if write locked by current thread even if + * Read lock succeeds if write locked by current thread even if * other threads are waiting for writelock */ public void testReadHoldingWriteLock3() throws InterruptedException { final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); lock.writeLock().lock(); - Thread t1 = new Thread(new Runnable() { - public void run() { - lock.writeLock().lock(); - lock.writeLock().unlock(); - } - }); - Thread t2 = new Thread(new Runnable() { - public void run() { - lock.writeLock().lock(); - lock.writeLock().unlock(); - } - }); + Thread t1 = newStartedThread(new CheckedRunnable() { + public void realRun() { + lock.writeLock().lock(); + lock.writeLock().unlock(); + }}); + Thread t2 = newStartedThread(new CheckedRunnable() { + public void realRun() { + lock.writeLock().lock(); + lock.writeLock().unlock(); + }}); - t1.start(); - t2.start(); lock.readLock().lock(); lock.readLock().unlock(); Thread.sleep(SHORT_DELAY_MS); @@ -450,27 +432,23 @@ public class ReentrantReadWriteLockTest /** - * Write lock succeeds if write locked by current thread even if + * Write lock succeeds if write locked by current thread even if * other threads are waiting for writelock */ public void testWriteHoldingWriteLock4() throws InterruptedException { final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); lock.writeLock().lock(); - Thread t1 = new Thread(new Runnable() { - public void run() { - lock.writeLock().lock(); - lock.writeLock().unlock(); - } - }); - Thread t2 = new Thread(new Runnable() { - public void run() { - lock.writeLock().lock(); - lock.writeLock().unlock(); - } - }); + Thread t1 = newStartedThread(new CheckedRunnable() { + public void realRun() { + lock.writeLock().lock(); + lock.writeLock().unlock(); + }}); + Thread t2 = newStartedThread(new CheckedRunnable() { + public void realRun() { + lock.writeLock().lock(); + lock.writeLock().unlock(); + }}); - t1.start(); - t2.start(); lock.writeLock().lock(); lock.writeLock().unlock(); Thread.sleep(SHORT_DELAY_MS); @@ -502,21 +480,17 @@ public class ReentrantReadWriteLockTest public void testReadHoldingWriteLockFair2() throws InterruptedException { final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(true); lock.writeLock().lock(); - Thread t1 = new Thread(new Runnable() { - public void run() { - lock.readLock().lock(); - lock.readLock().unlock(); - } - }); - Thread t2 = new Thread(new Runnable() { - public void run() { - lock.readLock().lock(); - lock.readLock().unlock(); - } - }); + Thread t1 = newStartedThread(new CheckedRunnable() { + public void realRun() { + lock.readLock().lock(); + lock.readLock().unlock(); + }}); + Thread t2 = newStartedThread(new CheckedRunnable() { + public void realRun() { + lock.readLock().lock(); + lock.readLock().unlock(); + }}); - t1.start(); - t2.start(); lock.readLock().lock(); lock.readLock().unlock(); Thread.sleep(SHORT_DELAY_MS); @@ -537,21 +511,17 @@ public class ReentrantReadWriteLockTest public void testReadHoldingWriteLockFair3() throws InterruptedException { final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(true); lock.writeLock().lock(); - Thread t1 = new Thread(new Runnable() { - public void run() { - lock.writeLock().lock(); - lock.writeLock().unlock(); - } - }); - Thread t2 = new Thread(new Runnable() { - public void run() { - lock.writeLock().lock(); - lock.writeLock().unlock(); - } - }); + Thread t1 = newStartedThread(new CheckedRunnable() { + public void realRun() { + lock.writeLock().lock(); + lock.writeLock().unlock(); + }}); + Thread t2 = newStartedThread(new CheckedRunnable() { + public void realRun() { + lock.writeLock().lock(); + lock.writeLock().unlock(); + }}); - t1.start(); - t2.start(); lock.readLock().lock(); lock.readLock().unlock(); Thread.sleep(SHORT_DELAY_MS); @@ -572,26 +542,22 @@ public class ReentrantReadWriteLockTest public void testWriteHoldingWriteLockFair4() throws InterruptedException { final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(true); lock.writeLock().lock(); - Thread t1 = new Thread(new Runnable() { - public void run() { - lock.writeLock().lock(); - lock.writeLock().unlock(); - } - }); - Thread t2 = new Thread(new Runnable() { - public void run() { - lock.writeLock().lock(); - lock.writeLock().unlock(); - } - }); + Thread t1 = newStartedThread(new CheckedRunnable() { + public void realRun() { + lock.writeLock().lock(); + lock.writeLock().unlock(); + }}); + Thread t2 = newStartedThread(new CheckedRunnable() { + public void realRun() { + lock.writeLock().lock(); + lock.writeLock().unlock(); + }}); - t1.start(); - t2.start(); Thread.sleep(SHORT_DELAY_MS); assertTrue(lock.isWriteLockedByCurrentThread()); - assertTrue(lock.getWriteHoldCount() == 1); + assertEquals(1, lock.getWriteHoldCount()); lock.writeLock().lock(); - assertTrue(lock.getWriteHoldCount() == 2); + assertEquals(2, lock.getWriteHoldCount()); lock.writeLock().unlock(); lock.writeLock().lock(); lock.writeLock().unlock(); @@ -609,33 +575,27 @@ public class ReentrantReadWriteLockTest public void testTryLockWhenReadLocked() throws InterruptedException { final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); lock.readLock().lock(); - Thread t = new Thread(new Runnable() { - public void run() { - threadAssertTrue(lock.readLock().tryLock()); - lock.readLock().unlock(); - } - }); + Thread t = newStartedThread(new CheckedRunnable() { + public void realRun() { + assertTrue(lock.readLock().tryLock()); + lock.readLock().unlock(); + }}); - t.start(); t.join(); lock.readLock().unlock(); } - - /** * write tryLock fails when readlocked */ public void testWriteTryLockWhenReadLocked() throws InterruptedException { final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); lock.readLock().lock(); - Thread t = new Thread(new Runnable() { - public void run() { - threadAssertFalse(lock.writeLock().tryLock()); - } - }); + Thread t = newStartedThread(new CheckedRunnable() { + public void realRun() { + assertFalse(lock.writeLock().tryLock()); + }}); - t.start(); t.join(); lock.readLock().unlock(); } @@ -647,14 +607,12 @@ public class ReentrantReadWriteLockTest public void testTryLockWhenReadLockedFair() throws InterruptedException { final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(true); lock.readLock().lock(); - Thread t = new Thread(new Runnable() { - public void run() { - threadAssertTrue(lock.readLock().tryLock()); - lock.readLock().unlock(); - } - }); + Thread t = newStartedThread(new CheckedRunnable() { + public void realRun() { + assertTrue(lock.readLock().tryLock()); + lock.readLock().unlock(); + }}); - t.start(); t.join(); lock.readLock().unlock(); } @@ -667,13 +625,11 @@ public class ReentrantReadWriteLockTest public void testWriteTryLockWhenReadLockedFair() throws InterruptedException { final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(true); lock.readLock().lock(); - Thread t = new Thread(new Runnable() { - public void run() { - threadAssertFalse(lock.writeLock().tryLock()); - } - }); + Thread t = newStartedThread(new CheckedRunnable() { + public void realRun() { + assertFalse(lock.writeLock().tryLock()); + }}); - t.start(); t.join(); lock.readLock().unlock(); } @@ -686,12 +642,11 @@ public class ReentrantReadWriteLockTest public void testWriteTryLock_Timeout() throws InterruptedException { final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); lock.writeLock().lock(); - Thread t = new Thread(new CheckedRunnable() { + Thread t = newStartedThread(new CheckedRunnable() { public void realRun() throws InterruptedException { - threadAssertFalse(lock.writeLock().tryLock(1, TimeUnit.MILLISECONDS)); + assertFalse(lock.writeLock().tryLock(1, MILLISECONDS)); }}); - t.start(); t.join(); assertTrue(lock.writeLock().isHeldByCurrentThread()); lock.writeLock().unlock(); @@ -703,12 +658,11 @@ public class ReentrantReadWriteLockTest public void testReadTryLock_Timeout() throws InterruptedException { final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); lock.writeLock().lock(); - Thread t = new Thread(new CheckedRunnable() { + Thread t = newStartedThread(new CheckedRunnable() { public void realRun() throws InterruptedException { - threadAssertFalse(lock.readLock().tryLock(1, TimeUnit.MILLISECONDS)); + assertFalse(lock.readLock().tryLock(1, MILLISECONDS)); }}); - t.start(); t.join(); assertTrue(lock.writeLock().isHeldByCurrentThread()); lock.writeLock().unlock(); @@ -721,12 +675,11 @@ public class ReentrantReadWriteLockTest public void testWriteLockInterruptibly() throws InterruptedException { final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); lock.writeLock().lockInterruptibly(); - Thread t = new Thread(new CheckedInterruptedRunnable() { + Thread t = newStartedThread(new CheckedInterruptedRunnable() { public void realRun() throws InterruptedException { lock.writeLock().lockInterruptibly(); }}); - t.start(); Thread.sleep(SHORT_DELAY_MS); t.interrupt(); Thread.sleep(SHORT_DELAY_MS); @@ -735,17 +688,16 @@ public class ReentrantReadWriteLockTest } /** - * read lockInterruptibly succeeds if lock free else is interruptible + * read lockInterruptibly succeeds if lock free else is interruptible */ public void testReadLockInterruptibly() throws InterruptedException { final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); lock.writeLock().lockInterruptibly(); - Thread t = new Thread(new CheckedInterruptedRunnable() { + Thread t = newStartedThread(new CheckedInterruptedRunnable() { public void realRun() throws InterruptedException { lock.readLock().lockInterruptibly(); }}); - t.start(); Thread.sleep(SHORT_DELAY_MS); t.interrupt(); t.join(); @@ -791,13 +743,13 @@ public class ReentrantReadWriteLockTest /** - * timed await without a signal times out + * timed await without a signal times out */ public void testAwait_Timeout() throws InterruptedException { final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); final Condition c = lock.writeLock().newCondition(); lock.writeLock().lock(); - assertFalse(c.await(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); + assertFalse(c.await(SHORT_DELAY_MS, MILLISECONDS)); lock.writeLock().unlock(); } @@ -819,14 +771,13 @@ public class ReentrantReadWriteLockTest public void testAwait() throws InterruptedException { final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); final Condition c = lock.writeLock().newCondition(); - Thread t = new Thread(new CheckedRunnable() { + Thread t = newStartedThread(new CheckedRunnable() { public void realRun() throws InterruptedException { lock.writeLock().lock(); c.await(); lock.writeLock().unlock(); }}); - t.start(); Thread.sleep(SHORT_DELAY_MS); lock.writeLock().lock(); c.signal(); @@ -896,14 +847,13 @@ public class ReentrantReadWriteLockTest public void testAwait_Interrupt() throws InterruptedException { final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); final Condition c = lock.writeLock().newCondition(); - Thread t = new Thread(new CheckedInterruptedRunnable() { + Thread t = newStartedThread(new CheckedInterruptedRunnable() { public void realRun() throws InterruptedException { lock.writeLock().lock(); c.await(); lock.writeLock().unlock(); }}); - t.start(); Thread.sleep(SHORT_DELAY_MS); t.interrupt(); t.join(SHORT_DELAY_MS); @@ -916,14 +866,13 @@ public class ReentrantReadWriteLockTest public void testAwaitNanos_Interrupt() throws InterruptedException { final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); final Condition c = lock.writeLock().newCondition(); - Thread t = new Thread(new CheckedInterruptedRunnable() { + Thread t = newStartedThread(new CheckedInterruptedRunnable() { public void realRun() throws InterruptedException { lock.writeLock().lock(); - c.awaitNanos(SHORT_DELAY_MS * 2 * 1000000); + c.awaitNanos(MILLISECONDS.toNanos(LONG_DELAY_MS)); lock.writeLock().unlock(); }}); - t.start(); Thread.sleep(SHORT_DELAY_MS); t.interrupt(); t.join(SHORT_DELAY_MS); @@ -936,7 +885,7 @@ public class ReentrantReadWriteLockTest public void testAwaitUntil_Interrupt() throws InterruptedException { final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); final Condition c = lock.writeLock().newCondition(); - Thread t = new Thread(new CheckedInterruptedRunnable() { + Thread t = newStartedThread(new CheckedInterruptedRunnable() { public void realRun() throws InterruptedException { lock.writeLock().lock(); java.util.Date d = new java.util.Date(); @@ -944,7 +893,6 @@ public class ReentrantReadWriteLockTest lock.writeLock().unlock(); }}); - t.start(); Thread.sleep(SHORT_DELAY_MS); t.interrupt(); t.join(SHORT_DELAY_MS); @@ -957,22 +905,20 @@ public class ReentrantReadWriteLockTest public void testSignalAll() throws InterruptedException { final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); final Condition c = lock.writeLock().newCondition(); - Thread t1 = new Thread(new CheckedRunnable() { + Thread t1 = newStartedThread(new CheckedRunnable() { public void realRun() throws InterruptedException { lock.writeLock().lock(); c.await(); lock.writeLock().unlock(); }}); - Thread t2 = new Thread(new CheckedRunnable() { + Thread t2 = newStartedThread(new CheckedRunnable() { public void realRun() throws InterruptedException { lock.writeLock().lock(); c.await(); lock.writeLock().unlock(); }}); - t1.start(); - t2.start(); Thread.sleep(SHORT_DELAY_MS); lock.writeLock().lock(); c.signalAll(); @@ -1241,16 +1187,15 @@ public class ReentrantReadWriteLockTest public void testHasWaiters() throws InterruptedException { final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); final Condition c = lock.writeLock().newCondition(); - Thread t = new Thread(new CheckedRunnable() { + Thread t = newStartedThread(new CheckedRunnable() { public void realRun() throws InterruptedException { lock.writeLock().lock(); - threadAssertFalse(lock.hasWaiters(c)); - threadAssertEquals(0, lock.getWaitQueueLength(c)); + assertFalse(lock.hasWaiters(c)); + assertEquals(0, lock.getWaitQueueLength(c)); c.await(); lock.writeLock().unlock(); }}); - t.start(); Thread.sleep(SHORT_DELAY_MS); lock.writeLock().lock(); assertTrue(lock.hasWaiters(c)); @@ -1272,16 +1217,15 @@ public class ReentrantReadWriteLockTest public void testGetWaitQueueLength() throws InterruptedException { final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); final Condition c = lock.writeLock().newCondition(); - Thread t = new Thread(new CheckedRunnable() { + Thread t = newStartedThread(new CheckedRunnable() { public void realRun() throws InterruptedException { lock.writeLock().lock(); - threadAssertFalse(lock.hasWaiters(c)); - threadAssertEquals(0, lock.getWaitQueueLength(c)); + assertFalse(lock.hasWaiters(c)); + assertEquals(0, lock.getWaitQueueLength(c)); c.await(); lock.writeLock().unlock(); }}); - t.start(); Thread.sleep(SHORT_DELAY_MS); lock.writeLock().lock(); assertTrue(lock.hasWaiters(c)); @@ -1307,7 +1251,7 @@ public class ReentrantReadWriteLockTest Thread t1 = new Thread(new CheckedRunnable() { public void realRun() throws InterruptedException { lock.writeLock().lock(); - threadAssertTrue(lock.getWaitingThreads(c).isEmpty()); + assertTrue(lock.getWaitingThreads(c).isEmpty()); c.await(); lock.writeLock().unlock(); }}); @@ -1315,7 +1259,7 @@ public class ReentrantReadWriteLockTest Thread t2 = new Thread(new CheckedRunnable() { public void realRun() throws InterruptedException { lock.writeLock().lock(); - threadAssertFalse(lock.getWaitingThreads(c).isEmpty()); + assertFalse(lock.getWaitingThreads(c).isEmpty()); c.await(); lock.writeLock().unlock(); }});