--- jsr166/src/test/tck/AbstractQueuedSynchronizerTest.java 2009/11/21 02:33:20 1.30 +++ jsr166/src/test/tck/AbstractQueuedSynchronizerTest.java 2010/09/16 00:52:49 1.35 @@ -16,7 +16,7 @@ import java.io.*; public class AbstractQueuedSynchronizerTest 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(AbstractQueuedSynchronizerTest.class); @@ -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(); + } } @@ -327,10 +329,11 @@ public class AbstractQueuedSynchronizerT sync.acquire(1); Thread t = new Thread(new CheckedInterruptedRunnable() { public void realRun() throws InterruptedException { - sync.tryAcquireNanos(1, MEDIUM_DELAY_MS * 1000 * 1000); + sync.tryAcquireNanos(1, MILLISECONDS.toNanos(MEDIUM_DELAY_MS)); }}); t.start(); + Thread.sleep(SHORT_DELAY_MS); t.interrupt(); t.join(); } @@ -344,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(); @@ -360,7 +363,8 @@ public class AbstractQueuedSynchronizerT sync.acquire(1); Thread t = new Thread(new CheckedRunnable() { public void realRun() throws InterruptedException { - threadAssertFalse(sync.tryAcquireNanos(1, 1000 * 1000)); + long nanos = MILLISECONDS.toNanos(SHORT_DELAY_MS); + assertFalse(sync.tryAcquireNanos(1, nanos)); }}); t.start(); @@ -417,6 +421,7 @@ public class AbstractQueuedSynchronizerT sync.acquireInterruptibly(1); Thread t = new Thread(new InterruptedSyncRunnable(sync)); t.start(); + Thread.sleep(SHORT_DELAY_MS); t.interrupt(); assertTrue(sync.isHeldExclusively()); t.join(); @@ -639,8 +644,8 @@ 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); }}); @@ -670,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); }}); @@ -679,8 +684,8 @@ 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); }}); @@ -714,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); }}); @@ -722,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); }}); @@ -786,7 +791,6 @@ public class AbstractQueuedSynchronizerT public void realRun() throws InterruptedException { sync.acquire(1); c.await(); - sync.release(1); }}); t.start(); @@ -805,8 +809,7 @@ public class AbstractQueuedSynchronizerT Thread t = new Thread(new CheckedInterruptedRunnable() { public void realRun() throws InterruptedException { sync.acquire(1); - c.awaitNanos(1000 * 1000 * 1000); // 1 sec - sync.release(1); + c.awaitNanos(MILLISECONDS.toNanos(LONG_DELAY_MS)); }}); t.start(); @@ -827,7 +830,6 @@ public class AbstractQueuedSynchronizerT sync.acquire(1); java.util.Date d = new java.util.Date(); c.awaitUntil(new java.util.Date(d.getTime() + 10000)); - sync.release(1); }}); t.start(); @@ -932,9 +934,9 @@ 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(); @@ -954,9 +956,10 @@ public class AbstractQueuedSynchronizerT Thread t = new Thread(new CheckedRunnable() { public void realRun() throws InterruptedException { - threadAssertFalse(l.isSignalled()); - threadAssertTrue(l.tryAcquireSharedNanos(0, MEDIUM_DELAY_MS* 1000 * 1000)); - threadAssertTrue(l.isSignalled()); + assertFalse(l.isSignalled()); + long nanos = MILLISECONDS.toNanos(MEDIUM_DELAY_MS); + assertTrue(l.tryAcquireSharedNanos(0, nanos)); + assertTrue(l.isSignalled()); }}); t.start(); @@ -974,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); }}); @@ -991,8 +994,9 @@ public class AbstractQueuedSynchronizerT final BooleanLatch l = new BooleanLatch(); Thread t = new Thread(new CheckedInterruptedRunnable() { public void realRun() throws InterruptedException { - threadAssertFalse(l.isSignalled()); - l.tryAcquireSharedNanos(0, SMALL_DELAY_MS* 1000 * 1000); + assertFalse(l.isSignalled()); + long nanos = MILLISECONDS.toNanos(SMALL_DELAY_MS); + l.tryAcquireSharedNanos(0, nanos); }}); t.start(); @@ -1009,8 +1013,9 @@ public class AbstractQueuedSynchronizerT final BooleanLatch l = new BooleanLatch(); Thread t = new Thread(new CheckedRunnable() { public void realRun() throws InterruptedException { - threadAssertFalse(l.isSignalled()); - threadAssertFalse(l.tryAcquireSharedNanos(0, SMALL_DELAY_MS* 1000 * 1000)); + assertFalse(l.isSignalled()); + long nanos = MILLISECONDS.toNanos(SMALL_DELAY_MS); + assertFalse(l.tryAcquireSharedNanos(0, nanos)); }}); t.start();