--- jsr166/src/test/tck/AbstractQueuedLongSynchronizerTest.java 2009/11/18 16:04:34 1.10 +++ jsr166/src/test/tck/AbstractQueuedLongSynchronizerTest.java 2010/09/16 00:52:49 1.17 @@ -10,12 +10,13 @@ import junit.framework.*; import java.util.*; import java.util.concurrent.*; +import static java.util.concurrent.TimeUnit.MILLISECONDS; import java.util.concurrent.locks.*; 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); @@ -46,7 +47,9 @@ public class AbstractQueuedLongSynchroni return true; } - public AbstractQueuedLongSynchronizer.ConditionObject newCondition() { return new AbstractQueuedLongSynchronizer.ConditionObject(); } + public AbstractQueuedLongSynchronizer.ConditionObject newCondition() { + return new AbstractQueuedLongSynchronizer.ConditionObject(); + } } @@ -96,7 +99,7 @@ public class AbstractQueuedLongSynchroni * isHeldExclusively is false upon construction */ public void testIsHeldExclusively() { - Mutex rl = new Mutex(); + Mutex rl = new Mutex(); assertFalse(rl.isHeldExclusively()); } @@ -104,7 +107,7 @@ public class AbstractQueuedLongSynchroni * acquiring released sync succeeds */ public void testAcquire() { - Mutex rl = new Mutex(); + Mutex rl = new Mutex(); rl.acquire(1); assertTrue(rl.isHeldExclusively()); rl.release(1); @@ -115,7 +118,7 @@ public class AbstractQueuedLongSynchroni * tryAcquire on an released sync succeeds */ public void testTryAcquire() { - Mutex rl = new Mutex(); + Mutex rl = new Mutex(); assertTrue(rl.tryAcquire(1)); assertTrue(rl.isHeldExclusively()); rl.release(1); @@ -125,7 +128,7 @@ public class AbstractQueuedLongSynchroni * hasQueuedThreads reports whether there are waiting threads */ public void testhasQueuedThreads() throws InterruptedException { - final Mutex sync = new Mutex(); + final Mutex sync = new Mutex(); Thread t1 = new Thread(new InterruptedSyncRunnable(sync)); Thread t2 = new Thread(new InterruptibleSyncRunnable(sync)); assertFalse(sync.hasQueuedThreads()); @@ -150,7 +153,7 @@ public class AbstractQueuedLongSynchroni * isQueued(null) throws NPE */ public void testIsQueuedNPE() { - final Mutex sync = new Mutex(); + final Mutex sync = new Mutex(); try { sync.isQueued(null); shouldThrow(); @@ -161,7 +164,7 @@ public class AbstractQueuedLongSynchroni * isQueued reports whether a thread is queued. */ public void testIsQueued() throws InterruptedException { - final Mutex sync = new Mutex(); + final Mutex sync = new Mutex(); Thread t1 = new Thread(new InterruptedSyncRunnable(sync)); Thread t2 = new Thread(new InterruptibleSyncRunnable(sync)); assertFalse(sync.isQueued(t1)); @@ -191,7 +194,7 @@ public class AbstractQueuedLongSynchroni * getFirstQueuedThread returns first waiting thread or null if none */ public void testGetFirstQueuedThread() throws InterruptedException { - final Mutex sync = new Mutex(); + final Mutex sync = new Mutex(); Thread t1 = new Thread(new InterruptedSyncRunnable(sync)); Thread t2 = new Thread(new InterruptibleSyncRunnable(sync)); assertNull(sync.getFirstQueuedThread()); @@ -218,7 +221,7 @@ public class AbstractQueuedLongSynchroni * hasContended reports false if no thread has ever blocked, else true */ public void testHasContended() throws InterruptedException { - final Mutex sync = new Mutex(); + final Mutex sync = new Mutex(); Thread t1 = new Thread(new InterruptedSyncRunnable(sync)); Thread t2 = new Thread(new InterruptibleSyncRunnable(sync)); assertFalse(sync.hasContended()); @@ -243,7 +246,7 @@ public class AbstractQueuedLongSynchroni * getQueuedThreads includes waiting threads */ public void testGetQueuedThreads() throws InterruptedException { - final Mutex sync = new Mutex(); + final Mutex sync = new Mutex(); Thread t1 = new Thread(new InterruptedSyncRunnable(sync)); Thread t2 = new Thread(new InterruptibleSyncRunnable(sync)); assertTrue(sync.getQueuedThreads().isEmpty()); @@ -271,7 +274,7 @@ public class AbstractQueuedLongSynchroni * getExclusiveQueuedThreads includes waiting threads */ public void testGetExclusiveQueuedThreads() throws InterruptedException { - final Mutex sync = new Mutex(); + final Mutex sync = new Mutex(); Thread t1 = new Thread(new InterruptedSyncRunnable(sync)); Thread t2 = new Thread(new InterruptibleSyncRunnable(sync)); assertTrue(sync.getExclusiveQueuedThreads().isEmpty()); @@ -299,7 +302,7 @@ public class AbstractQueuedLongSynchroni * getSharedQueuedThreads does not include exclusively waiting threads */ public void testGetSharedQueuedThreads() throws InterruptedException { - final Mutex sync = new Mutex(); + final Mutex sync = new Mutex(); Thread t1 = new Thread(new InterruptedSyncRunnable(sync)); Thread t2 = new Thread(new InterruptibleSyncRunnable(sync)); assertTrue(sync.getSharedQueuedThreads().isEmpty()); @@ -325,14 +328,15 @@ public class AbstractQueuedLongSynchroni * tryAcquireNanos is interruptible. */ public void testInterruptedException2() throws InterruptedException { - final Mutex sync = new Mutex(); - sync.acquire(1); - Thread t = new Thread(new CheckedInterruptedRunnable() { + final Mutex sync = new Mutex(); + 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(); } @@ -342,11 +346,11 @@ public class AbstractQueuedLongSynchroni * TryAcquire on exclusively held sync fails */ public void testTryAcquireWhenSynced() throws InterruptedException { - final Mutex sync = new Mutex(); - sync.acquire(1); - Thread t = new Thread(new CheckedRunnable() { + final Mutex sync = new Mutex(); + sync.acquire(1); + Thread t = new Thread(new CheckedRunnable() { public void realRun() { - threadAssertFalse(sync.tryAcquire(1)); + assertFalse(sync.tryAcquire(1)); }}); t.start(); @@ -358,11 +362,12 @@ public class AbstractQueuedLongSynchroni * tryAcquireNanos on an exclusively held sync times out */ public void testAcquireNanos_Timeout() throws InterruptedException { - final Mutex sync = new Mutex(); - sync.acquire(1); - Thread t = new Thread(new CheckedRunnable() { + final Mutex sync = new Mutex(); + 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(); @@ -375,12 +380,12 @@ public class AbstractQueuedLongSynchroni * getState is true when acquired and false when not */ public void testGetState() throws InterruptedException { - final Mutex sync = new Mutex(); - sync.acquire(1); - assertTrue(sync.isHeldExclusively()); - sync.release(1); - assertFalse(sync.isHeldExclusively()); - Thread t = new Thread(new CheckedRunnable() { + final Mutex sync = new Mutex(); + sync.acquire(1); + assertTrue(sync.isHeldExclusively()); + sync.release(1); + assertFalse(sync.isHeldExclusively()); + Thread t = new Thread(new CheckedRunnable() { public void realRun() throws InterruptedException { sync.acquire(1); Thread.sleep(SMALL_DELAY_MS); @@ -399,9 +404,9 @@ public class AbstractQueuedLongSynchroni * acquireInterruptibly is interruptible. */ public void testAcquireInterruptibly1() throws InterruptedException { - final Mutex sync = new Mutex(); - sync.acquire(1); - Thread t = new Thread(new InterruptedSyncRunnable(sync)); + final Mutex sync = new Mutex(); + sync.acquire(1); + Thread t = new Thread(new InterruptedSyncRunnable(sync)); t.start(); Thread.sleep(SHORT_DELAY_MS); t.interrupt(); @@ -414,10 +419,11 @@ public class AbstractQueuedLongSynchroni * acquireInterruptibly succeeds when released, else is interruptible */ public void testAcquireInterruptibly2() throws InterruptedException { - final Mutex sync = new Mutex(); + final Mutex sync = new Mutex(); sync.acquireInterruptibly(1); - Thread t = new Thread(new InterruptedSyncRunnable(sync)); + Thread t = new Thread(new InterruptedSyncRunnable(sync)); t.start(); + Thread.sleep(SHORT_DELAY_MS); t.interrupt(); assertTrue(sync.isHeldExclusively()); t.join(); @@ -427,7 +433,7 @@ public class AbstractQueuedLongSynchroni * owns is true for a condition created by sync else false */ public void testOwns() { - final Mutex sync = new Mutex(); + final Mutex sync = new Mutex(); final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition(); final Mutex sync2 = new Mutex(); assertTrue(sync.owns(c)); @@ -438,7 +444,7 @@ public class AbstractQueuedLongSynchroni * Calling await without holding sync throws IllegalMonitorStateException */ public void testAwait_IllegalMonitor() throws InterruptedException { - final Mutex sync = new Mutex(); + final Mutex sync = new Mutex(); final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition(); try { c.await(); @@ -450,7 +456,7 @@ public class AbstractQueuedLongSynchroni * Calling signal without holding sync throws IllegalMonitorStateException */ public void testSignal_IllegalMonitor() throws InterruptedException { - final Mutex sync = new Mutex(); + final Mutex sync = new Mutex(); final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition(); try { c.signal(); @@ -462,7 +468,7 @@ public class AbstractQueuedLongSynchroni * awaitNanos without a signal times out */ public void testAwaitNanos_Timeout() throws InterruptedException { - final Mutex sync = new Mutex(); + final Mutex sync = new Mutex(); final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition(); sync.acquire(1); long t = c.awaitNanos(100); @@ -474,10 +480,10 @@ public class AbstractQueuedLongSynchroni * Timed await without a signal times out */ public void testAwait_Timeout() throws InterruptedException { - final Mutex sync = new Mutex(); + final Mutex sync = new Mutex(); final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition(); sync.acquire(1); - assertFalse(c.await(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); + assertFalse(c.await(SHORT_DELAY_MS, MILLISECONDS)); sync.release(1); } @@ -485,7 +491,7 @@ public class AbstractQueuedLongSynchroni * awaitUntil without a signal times out */ public void testAwaitUntil_Timeout() throws InterruptedException { - final Mutex sync = new Mutex(); + final Mutex sync = new Mutex(); final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition(); sync.acquire(1); java.util.Date d = new java.util.Date(); @@ -497,9 +503,9 @@ public class AbstractQueuedLongSynchroni * await returns when signalled */ public void testAwait() throws InterruptedException { - final Mutex sync = new Mutex(); + final Mutex sync = new Mutex(); final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition(); - Thread t = new Thread(new CheckedRunnable() { + Thread t = new Thread(new CheckedRunnable() { public void realRun() throws InterruptedException { sync.acquire(1); c.await(); @@ -521,7 +527,7 @@ public class AbstractQueuedLongSynchroni * hasWaiters throws NPE if null */ public void testHasWaitersNPE() { - final Mutex sync = new Mutex(); + final Mutex sync = new Mutex(); try { sync.hasWaiters(null); shouldThrow(); @@ -532,7 +538,7 @@ public class AbstractQueuedLongSynchroni * getWaitQueueLength throws NPE if null */ public void testGetWaitQueueLengthNPE() { - final Mutex sync = new Mutex(); + final Mutex sync = new Mutex(); try { sync.getWaitQueueLength(null); shouldThrow(); @@ -544,7 +550,7 @@ public class AbstractQueuedLongSynchroni * getWaitingThreads throws NPE if null */ public void testGetWaitingThreadsNPE() { - final Mutex sync = new Mutex(); + final Mutex sync = new Mutex(); try { sync.getWaitingThreads(null); shouldThrow(); @@ -556,9 +562,9 @@ public class AbstractQueuedLongSynchroni * hasWaiters throws IAE if not owned */ public void testHasWaitersIAE() { - final Mutex sync = new Mutex(); + final Mutex sync = new Mutex(); final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition(); - final Mutex sync2 = new Mutex(); + final Mutex sync2 = new Mutex(); try { sync2.hasWaiters(c); shouldThrow(); @@ -569,7 +575,7 @@ public class AbstractQueuedLongSynchroni * hasWaiters throws IMSE if not synced */ public void testHasWaitersIMSE() { - final Mutex sync = new Mutex(); + final Mutex sync = new Mutex(); final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition(); try { sync.hasWaiters(c); @@ -582,9 +588,9 @@ public class AbstractQueuedLongSynchroni * getWaitQueueLength throws IAE if not owned */ public void testGetWaitQueueLengthIAE() { - final Mutex sync = new Mutex(); + final Mutex sync = new Mutex(); final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition(); - final Mutex sync2 = new Mutex(); + final Mutex sync2 = new Mutex(); try { sync2.getWaitQueueLength(c); shouldThrow(); @@ -595,7 +601,7 @@ public class AbstractQueuedLongSynchroni * getWaitQueueLength throws IMSE if not synced */ public void testGetWaitQueueLengthIMSE() { - final Mutex sync = new Mutex(); + final Mutex sync = new Mutex(); final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition(); try { sync.getWaitQueueLength(c); @@ -608,9 +614,9 @@ public class AbstractQueuedLongSynchroni * getWaitingThreads throws IAE if not owned */ public void testGetWaitingThreadsIAE() { - final Mutex sync = new Mutex(); + final Mutex sync = new Mutex(); final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition(); - final Mutex sync2 = new Mutex(); + final Mutex sync2 = new Mutex(); try { sync2.getWaitingThreads(c); shouldThrow(); @@ -621,7 +627,7 @@ public class AbstractQueuedLongSynchroni * getWaitingThreads throws IMSE if not synced */ public void testGetWaitingThreadsIMSE() { - final Mutex sync = new Mutex(); + final Mutex sync = new Mutex(); final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition(); try { sync.getWaitingThreads(c); @@ -635,13 +641,13 @@ public class AbstractQueuedLongSynchroni * hasWaiters returns true when a thread is waiting, else false */ public void testHasWaiters() throws InterruptedException { - final Mutex sync = new Mutex(); + final Mutex sync = new Mutex(); final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition(); - Thread t = new Thread(new CheckedRunnable() { + 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); }}); @@ -666,22 +672,22 @@ public class AbstractQueuedLongSynchroni * getWaitQueueLength returns number of waiting threads */ public void testGetWaitQueueLength() throws InterruptedException { - final Mutex sync = new Mutex(); + final Mutex sync = new Mutex(); final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition(); - Thread t1 = new Thread(new CheckedRunnable() { + 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); }}); - Thread t2 = new Thread(new CheckedRunnable() { + 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); }}); @@ -710,20 +716,20 @@ public class AbstractQueuedLongSynchroni * getWaitingThreads returns only and all waiting threads */ public void testGetWaitingThreads() throws InterruptedException { - final Mutex sync = new Mutex(); + final Mutex sync = new Mutex(); final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition(); - Thread t1 = new Thread(new CheckedRunnable() { + 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); }}); - Thread t2 = new Thread(new CheckedRunnable() { + 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); }}); @@ -758,9 +764,9 @@ public class AbstractQueuedLongSynchroni * awaitUninterruptibly doesn't abort on interrupt */ public void testAwaitUninterruptibly() throws InterruptedException { - final Mutex sync = new Mutex(); + final Mutex sync = new Mutex(); final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition(); - Thread t = new Thread(new CheckedRunnable() { + Thread t = new Thread(new CheckedRunnable() { public void realRun() { sync.acquire(1); c.awaitUninterruptibly(); @@ -781,13 +787,12 @@ public class AbstractQueuedLongSynchroni * await is interruptible */ public void testAwait_Interrupt() throws InterruptedException { - final Mutex sync = new Mutex(); + final Mutex sync = new Mutex(); final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition(); - Thread t = new Thread(new CheckedInterruptedRunnable() { - public void realRun() throws InterruptedException { + Thread t = new Thread(new CheckedInterruptedRunnable() { + public void realRun() throws InterruptedException { sync.acquire(1); c.await(); - sync.release(1); }}); t.start(); @@ -801,13 +806,12 @@ public class AbstractQueuedLongSynchroni * awaitNanos is interruptible */ public void testAwaitNanos_Interrupt() throws InterruptedException { - final Mutex sync = new Mutex(); + final Mutex sync = new Mutex(); final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition(); - Thread t = new Thread(new CheckedInterruptedRunnable() { - public void realRun() throws InterruptedException { + 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(); @@ -821,14 +825,13 @@ public class AbstractQueuedLongSynchroni * awaitUntil is interruptible */ public void testAwaitUntil_Interrupt() throws InterruptedException { - final Mutex sync = new Mutex(); + final Mutex sync = new Mutex(); final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition(); - Thread t = new Thread(new CheckedInterruptedRunnable() { - public void realRun() throws InterruptedException { + Thread t = new Thread(new CheckedInterruptedRunnable() { + public void realRun() throws InterruptedException { 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(); @@ -842,16 +845,16 @@ public class AbstractQueuedLongSynchroni * signalAll wakes up all threads */ public void testSignalAll() throws InterruptedException { - final Mutex sync = new Mutex(); + final Mutex sync = new Mutex(); final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition(); - Thread t1 = new Thread(new CheckedRunnable() { + Thread t1 = new Thread(new CheckedRunnable() { public void realRun() throws InterruptedException { sync.acquire(1); c.await(); sync.release(1); }}); - Thread t2 = new Thread(new CheckedRunnable() { + Thread t2 = new Thread(new CheckedRunnable() { public void realRun() throws InterruptedException { sync.acquire(1); c.await(); @@ -907,35 +910,35 @@ public class AbstractQueuedLongSynchroni * tryReleaseShared setting state changes getState */ public void testGetStateWithReleaseShared() { - final BooleanLatch l = new BooleanLatch(); - assertFalse(l.isSignalled()); - l.releaseShared(0); - assertTrue(l.isSignalled()); + final BooleanLatch l = new BooleanLatch(); + assertFalse(l.isSignalled()); + l.releaseShared(0); + assertTrue(l.isSignalled()); } /** * releaseShared has no effect when already signalled */ public void testReleaseShared() { - final BooleanLatch l = new BooleanLatch(); - assertFalse(l.isSignalled()); - l.releaseShared(0); - assertTrue(l.isSignalled()); - l.releaseShared(0); - assertTrue(l.isSignalled()); + final BooleanLatch l = new BooleanLatch(); + assertFalse(l.isSignalled()); + l.releaseShared(0); + assertTrue(l.isSignalled()); + l.releaseShared(0); + assertTrue(l.isSignalled()); } /** * acquireSharedInterruptibly returns after release, but not before */ public void testAcquireSharedInterruptibly() throws InterruptedException { - final BooleanLatch l = new BooleanLatch(); + final BooleanLatch l = new BooleanLatch(); - Thread t = new Thread(new CheckedRunnable() { + 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(); @@ -951,13 +954,14 @@ public class AbstractQueuedLongSynchroni * acquireSharedTimed returns after release */ public void testAsquireSharedTimed() throws InterruptedException { - final BooleanLatch l = new BooleanLatch(); + final BooleanLatch l = new BooleanLatch(); - Thread t = new Thread(new CheckedRunnable() { + 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(); @@ -971,15 +975,16 @@ 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()); + Thread t = new Thread(new CheckedInterruptedRunnable() { + public void realRun() throws InterruptedException { + assertFalse(l.isSignalled()); l.acquireSharedInterruptibly(0); }}); - t.start(); + t.start(); assertFalse(l.isSignalled()); t.interrupt(); t.join(); @@ -990,10 +995,11 @@ public class AbstractQueuedLongSynchroni */ public void testAcquireSharedNanos_InterruptedException() throws InterruptedException { 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); + Thread t = new Thread(new CheckedInterruptedRunnable() { + public void realRun() throws InterruptedException { + assertFalse(l.isSignalled()); + long nanos = MILLISECONDS.toNanos(SMALL_DELAY_MS); + l.tryAcquireSharedNanos(0, nanos); }}); t.start(); @@ -1008,10 +1014,11 @@ public class AbstractQueuedLongSynchroni */ public void testAcquireSharedNanos_Timeout() throws InterruptedException { final BooleanLatch l = new BooleanLatch(); - Thread t = new Thread(new CheckedRunnable() { + 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();