--- jsr166/src/test/tck/AbstractQueuedSynchronizerTest.java 2010/08/25 00:07:02 1.34 +++ jsr166/src/test/tck/AbstractQueuedSynchronizerTest.java 2011/05/06 16:43:45 1.40 @@ -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. */ @@ -34,7 +34,7 @@ public class AbstractQueuedSynchronizerT public boolean isHeldExclusively() { return getState() == 1; } public boolean tryAcquire(int acquires) { - assertTrue(acquires == 1); + assertEquals(1, acquires); return compareAndSetState(0, 1); } @@ -44,7 +44,9 @@ public class AbstractQueuedSynchronizerT return true; } - public AbstractQueuedSynchronizer.ConditionObject newCondition() { return new AbstractQueuedSynchronizer.ConditionObject(); } + public AbstractQueuedSynchronizer.ConditionObject newCondition() { + return new AbstractQueuedSynchronizer.ConditionObject(); + } } @@ -56,7 +58,7 @@ public class AbstractQueuedSynchronizerT public boolean isSignalled() { return getState() != 0; } public int tryAcquireShared(int ignore) { - return isSignalled()? 1 : -1; + return isSignalled() ? 1 : -1; } public boolean tryReleaseShared(int ignore) { @@ -129,16 +131,16 @@ public class AbstractQueuedSynchronizerT assertFalse(sync.hasQueuedThreads()); sync.acquire(1); t1.start(); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); assertTrue(sync.hasQueuedThreads()); t2.start(); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); assertTrue(sync.hasQueuedThreads()); t1.interrupt(); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); assertTrue(sync.hasQueuedThreads()); sync.release(1); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); assertFalse(sync.hasQueuedThreads()); t1.join(); t2.join(); @@ -166,20 +168,20 @@ public class AbstractQueuedSynchronizerT assertFalse(sync.isQueued(t2)); sync.acquire(1); t1.start(); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); assertTrue(sync.isQueued(t1)); t2.start(); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); assertTrue(sync.isQueued(t1)); assertTrue(sync.isQueued(t2)); t1.interrupt(); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); assertFalse(sync.isQueued(t1)); assertTrue(sync.isQueued(t2)); sync.release(1); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); assertFalse(sync.isQueued(t1)); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); assertFalse(sync.isQueued(t2)); t1.join(); t2.join(); @@ -195,17 +197,17 @@ public class AbstractQueuedSynchronizerT assertNull(sync.getFirstQueuedThread()); sync.acquire(1); t1.start(); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); assertEquals(t1, sync.getFirstQueuedThread()); t2.start(); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); assertEquals(t1, sync.getFirstQueuedThread()); t1.interrupt(); - Thread.sleep(SHORT_DELAY_MS); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); assertEquals(t2, sync.getFirstQueuedThread()); sync.release(1); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); assertNull(sync.getFirstQueuedThread()); t1.join(); t2.join(); @@ -222,16 +224,16 @@ public class AbstractQueuedSynchronizerT assertFalse(sync.hasContended()); sync.acquire(1); t1.start(); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); assertTrue(sync.hasContended()); t2.start(); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); assertTrue(sync.hasContended()); t1.interrupt(); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); assertTrue(sync.hasContended()); sync.release(1); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); assertTrue(sync.hasContended()); t1.join(); t2.join(); @@ -248,18 +250,18 @@ public class AbstractQueuedSynchronizerT sync.acquire(1); assertTrue(sync.getQueuedThreads().isEmpty()); t1.start(); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); assertTrue(sync.getQueuedThreads().contains(t1)); t2.start(); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); assertTrue(sync.getQueuedThreads().contains(t1)); assertTrue(sync.getQueuedThreads().contains(t2)); t1.interrupt(); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); assertFalse(sync.getQueuedThreads().contains(t1)); assertTrue(sync.getQueuedThreads().contains(t2)); sync.release(1); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); assertTrue(sync.getQueuedThreads().isEmpty()); t1.join(); t2.join(); @@ -276,18 +278,18 @@ public class AbstractQueuedSynchronizerT sync.acquire(1); assertTrue(sync.getExclusiveQueuedThreads().isEmpty()); t1.start(); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); assertTrue(sync.getExclusiveQueuedThreads().contains(t1)); t2.start(); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); assertTrue(sync.getExclusiveQueuedThreads().contains(t1)); assertTrue(sync.getExclusiveQueuedThreads().contains(t2)); t1.interrupt(); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); assertFalse(sync.getExclusiveQueuedThreads().contains(t1)); assertTrue(sync.getExclusiveQueuedThreads().contains(t2)); sync.release(1); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); assertTrue(sync.getExclusiveQueuedThreads().isEmpty()); t1.join(); t2.join(); @@ -304,16 +306,16 @@ public class AbstractQueuedSynchronizerT sync.acquire(1); assertTrue(sync.getSharedQueuedThreads().isEmpty()); t1.start(); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); assertTrue(sync.getSharedQueuedThreads().isEmpty()); t2.start(); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); assertTrue(sync.getSharedQueuedThreads().isEmpty()); t1.interrupt(); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); assertTrue(sync.getSharedQueuedThreads().isEmpty()); sync.release(1); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); assertTrue(sync.getSharedQueuedThreads().isEmpty()); t1.join(); t2.join(); @@ -331,7 +333,7 @@ public class AbstractQueuedSynchronizerT }}); t.start(); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); t.interrupt(); t.join(); } @@ -345,7 +347,7 @@ public class AbstractQueuedSynchronizerT sync.acquire(1); Thread t = new Thread(new CheckedRunnable() { public void realRun() { - threadAssertFalse(sync.tryAcquire(1)); + assertFalse(sync.tryAcquire(1)); }}); t.start(); @@ -383,12 +385,12 @@ public class AbstractQueuedSynchronizerT Thread t = new Thread(new CheckedRunnable() { public void realRun() throws InterruptedException { sync.acquire(1); - Thread.sleep(SMALL_DELAY_MS); + delay(SMALL_DELAY_MS); sync.release(1); }}); t.start(); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); assertTrue(sync.isHeldExclusively()); t.join(); assertFalse(sync.isHeldExclusively()); @@ -404,9 +406,9 @@ public class AbstractQueuedSynchronizerT Thread t = new Thread(new InterruptedSyncRunnable(sync)); t.start(); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); t.interrupt(); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); sync.release(1); t.join(); } @@ -419,7 +421,7 @@ public class AbstractQueuedSynchronizerT sync.acquireInterruptibly(1); Thread t = new Thread(new InterruptedSyncRunnable(sync)); t.start(); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); t.interrupt(); assertTrue(sync.isHeldExclusively()); t.join(); @@ -473,7 +475,7 @@ public class AbstractQueuedSynchronizerT } /** - * Timed await without a signal times out + * Timed await without a signal times out */ public void testAwait_Timeout() throws InterruptedException { final Mutex sync = new Mutex(); @@ -509,7 +511,7 @@ public class AbstractQueuedSynchronizerT }}); t.start(); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); sync.acquire(1); c.signal(); sync.release(1); @@ -642,20 +644,20 @@ public class AbstractQueuedSynchronizerT Thread t = new Thread(new CheckedRunnable() { public void realRun() throws InterruptedException { sync.acquire(1); - threadAssertFalse(sync.hasWaiters(c)); - threadAssertEquals(0, sync.getWaitQueueLength(c)); + assertFalse(sync.hasWaiters(c)); + assertEquals(0, sync.getWaitQueueLength(c)); c.await(); sync.release(1); }}); t.start(); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); sync.acquire(1); assertTrue(sync.hasWaiters(c)); assertEquals(1, sync.getWaitQueueLength(c)); c.signal(); sync.release(1); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); sync.acquire(1); assertFalse(sync.hasWaiters(c)); assertEquals(0, sync.getWaitQueueLength(c)); @@ -673,8 +675,8 @@ public class AbstractQueuedSynchronizerT Thread t1 = new Thread(new CheckedRunnable() { public void realRun() throws InterruptedException { sync.acquire(1); - threadAssertFalse(sync.hasWaiters(c)); - threadAssertEquals(0, sync.getWaitQueueLength(c)); + assertFalse(sync.hasWaiters(c)); + assertEquals(0, sync.getWaitQueueLength(c)); c.await(); sync.release(1); }}); @@ -682,22 +684,22 @@ public class AbstractQueuedSynchronizerT Thread t2 = new Thread(new CheckedRunnable() { public void realRun() throws InterruptedException { sync.acquire(1); - threadAssertTrue(sync.hasWaiters(c)); - threadAssertEquals(1, sync.getWaitQueueLength(c)); + assertTrue(sync.hasWaiters(c)); + assertEquals(1, sync.getWaitQueueLength(c)); c.await(); sync.release(1); }}); t1.start(); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); t2.start(); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); sync.acquire(1); assertTrue(sync.hasWaiters(c)); assertEquals(2, sync.getWaitQueueLength(c)); c.signalAll(); sync.release(1); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); sync.acquire(1); assertFalse(sync.hasWaiters(c)); assertEquals(0, sync.getWaitQueueLength(c)); @@ -717,7 +719,7 @@ public class AbstractQueuedSynchronizerT Thread t1 = new Thread(new CheckedRunnable() { public void realRun() throws InterruptedException { sync.acquire(1); - threadAssertTrue(sync.getWaitingThreads(c).isEmpty()); + assertTrue(sync.getWaitingThreads(c).isEmpty()); c.await(); sync.release(1); }}); @@ -725,7 +727,7 @@ public class AbstractQueuedSynchronizerT Thread t2 = new Thread(new CheckedRunnable() { public void realRun() throws InterruptedException { sync.acquire(1); - threadAssertFalse(sync.getWaitingThreads(c).isEmpty()); + assertFalse(sync.getWaitingThreads(c).isEmpty()); c.await(); sync.release(1); }}); @@ -734,16 +736,16 @@ public class AbstractQueuedSynchronizerT assertTrue(sync.getWaitingThreads(c).isEmpty()); sync.release(1); t1.start(); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); t2.start(); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); sync.acquire(1); assertTrue(sync.hasWaiters(c)); assertTrue(sync.getWaitingThreads(c).contains(t1)); assertTrue(sync.getWaitingThreads(c).contains(t2)); c.signalAll(); sync.release(1); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); sync.acquire(1); assertFalse(sync.hasWaiters(c)); assertTrue(sync.getWaitingThreads(c).isEmpty()); @@ -770,7 +772,7 @@ public class AbstractQueuedSynchronizerT }}); t.start(); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); t.interrupt(); sync.acquire(1); c.signal(); @@ -792,7 +794,7 @@ public class AbstractQueuedSynchronizerT }}); t.start(); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); t.interrupt(); t.join(SHORT_DELAY_MS); assertFalse(t.isAlive()); @@ -811,7 +813,7 @@ public class AbstractQueuedSynchronizerT }}); t.start(); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); t.interrupt(); t.join(SHORT_DELAY_MS); assertFalse(t.isAlive()); @@ -831,7 +833,7 @@ public class AbstractQueuedSynchronizerT }}); t.start(); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); t.interrupt(); t.join(SHORT_DELAY_MS); assertFalse(t.isAlive()); @@ -859,7 +861,7 @@ public class AbstractQueuedSynchronizerT t1.start(); t2.start(); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); sync.acquire(1); c.signalAll(); sync.release(1); @@ -932,14 +934,14 @@ public class AbstractQueuedSynchronizerT Thread t = new Thread(new CheckedRunnable() { public void realRun() throws InterruptedException { - threadAssertFalse(l.isSignalled()); + assertFalse(l.isSignalled()); l.acquireSharedInterruptibly(0); - threadAssertTrue(l.isSignalled()); + assertTrue(l.isSignalled()); }}); t.start(); assertFalse(l.isSignalled()); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); l.releaseShared(0); assertTrue(l.isSignalled()); t.join(); @@ -949,7 +951,7 @@ public class AbstractQueuedSynchronizerT /** * acquireSharedTimed returns after release */ - public void testAsquireSharedTimed() throws InterruptedException { + public void testAcquireSharedTimed() throws InterruptedException { final BooleanLatch l = new BooleanLatch(); Thread t = new Thread(new CheckedRunnable() { @@ -962,7 +964,7 @@ public class AbstractQueuedSynchronizerT t.start(); assertFalse(l.isSignalled()); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); l.releaseShared(0); assertTrue(l.isSignalled()); t.join(); @@ -975,7 +977,7 @@ public class AbstractQueuedSynchronizerT final BooleanLatch l = new BooleanLatch(); Thread t = new Thread(new CheckedInterruptedRunnable() { public void realRun() throws InterruptedException { - threadAssertFalse(l.isSignalled()); + assertFalse(l.isSignalled()); l.acquireSharedInterruptibly(0); }}); @@ -998,7 +1000,7 @@ public class AbstractQueuedSynchronizerT }}); t.start(); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); assertFalse(l.isSignalled()); t.interrupt(); t.join(); @@ -1017,7 +1019,7 @@ public class AbstractQueuedSynchronizerT }}); t.start(); - Thread.sleep(SHORT_DELAY_MS); + delay(SHORT_DELAY_MS); assertFalse(l.isSignalled()); t.join(); }