--- jsr166/src/test/tck/AbstractQueuedLongSynchronizerTest.java 2009/11/30 08:31:09 1.14 +++ jsr166/src/test/tck/AbstractQueuedLongSynchronizerTest.java 2011/03/15 19:47:06 1.22 @@ -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. */ @@ -16,7 +16,7 @@ import java.io.*; public class AbstractQueuedLongSynchronizerTest 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(AbstractQueuedLongSynchronizerTest.class); @@ -47,7 +47,9 @@ public class AbstractQueuedLongSynchroni return true; } - public AbstractQueuedLongSynchronizer.ConditionObject newCondition() { return new AbstractQueuedLongSynchronizer.ConditionObject(); } + public AbstractQueuedLongSynchronizer.ConditionObject newCondition() { + return new AbstractQueuedLongSynchronizer.ConditionObject(); + } } @@ -59,7 +61,7 @@ public class AbstractQueuedLongSynchroni public boolean isSignalled() { return getState() != 0; } public long tryAcquireShared(long ignore) { - return isSignalled()? 1 : -1; + return isSignalled() ? 1 : -1; } public boolean tryReleaseShared(long ignore) { @@ -330,7 +332,7 @@ public class AbstractQueuedLongSynchroni sync.acquire(1); Thread t = new Thread(new CheckedInterruptedRunnable() { public void realRun() throws InterruptedException { - sync.tryAcquireNanos(1, MEDIUM_DELAY_MS * 1000L * 1000L); + sync.tryAcquireNanos(1, MILLISECONDS.toNanos(MEDIUM_DELAY_MS)); }}); t.start(); @@ -348,7 +350,7 @@ public class AbstractQueuedLongSynchroni sync.acquire(1); Thread t = new Thread(new CheckedRunnable() { public void realRun() { - threadAssertFalse(sync.tryAcquire(1)); + assertFalse(sync.tryAcquire(1)); }}); t.start(); @@ -364,7 +366,8 @@ public class AbstractQueuedLongSynchroni sync.acquire(1); Thread t = new Thread(new CheckedRunnable() { public void realRun() throws InterruptedException { - threadAssertFalse(sync.tryAcquireNanos(1, SHORT_DELAY_MS * 1000L * 1000L)); + long nanos = MILLISECONDS.toNanos(SHORT_DELAY_MS); + assertFalse(sync.tryAcquireNanos(1, nanos)); }}); t.start(); @@ -474,7 +477,7 @@ public class AbstractQueuedLongSynchroni } /** - * 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(); @@ -643,8 +646,8 @@ public class AbstractQueuedLongSynchroni 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); }}); @@ -674,8 +677,8 @@ public class AbstractQueuedLongSynchroni 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); }}); @@ -683,8 +686,8 @@ public class AbstractQueuedLongSynchroni 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); }}); @@ -718,7 +721,7 @@ public class AbstractQueuedLongSynchroni 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); }}); @@ -726,7 +729,7 @@ public class AbstractQueuedLongSynchroni 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); }}); @@ -808,7 +811,7 @@ public class AbstractQueuedLongSynchroni Thread t = new Thread(new CheckedInterruptedRunnable() { public void realRun() throws InterruptedException { sync.acquire(1); - c.awaitNanos(LONG_DELAY_MS * 1000L * 1000L); + c.awaitNanos(MILLISECONDS.toNanos(LONG_DELAY_MS)); }}); t.start(); @@ -933,9 +936,9 @@ public class AbstractQueuedLongSynchroni 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(); @@ -950,14 +953,15 @@ public class AbstractQueuedLongSynchroni /** * 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() { public void realRun() throws InterruptedException { - threadAssertFalse(l.isSignalled()); - threadAssertTrue(l.tryAcquireSharedNanos(0, MEDIUM_DELAY_MS * 1000L * 1000L)); - threadAssertTrue(l.isSignalled()); + assertFalse(l.isSignalled()); + long nanos = MILLISECONDS.toNanos(MEDIUM_DELAY_MS); + assertTrue(l.tryAcquireSharedNanos(0, nanos)); + assertTrue(l.isSignalled()); }}); t.start(); @@ -971,11 +975,12 @@ public class AbstractQueuedLongSynchroni /** * acquireSharedInterruptibly throws IE if interrupted before released */ - public void testAcquireSharedInterruptibly_InterruptedException() throws InterruptedException { + public void testAcquireSharedInterruptibly_InterruptedException() + throws InterruptedException { 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); }}); @@ -992,8 +997,9 @@ public class AbstractQueuedLongSynchroni 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 * 1000L * 1000L); + assertFalse(l.isSignalled()); + long nanos = MILLISECONDS.toNanos(SMALL_DELAY_MS); + l.tryAcquireSharedNanos(0, nanos); }}); t.start(); @@ -1010,8 +1016,9 @@ public class AbstractQueuedLongSynchroni 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 * 1000L * 1000L)); + assertFalse(l.isSignalled()); + long nanos = MILLISECONDS.toNanos(SMALL_DELAY_MS); + assertFalse(l.tryAcquireSharedNanos(0, nanos)); }}); t.start();