--- jsr166/src/test/tck/AbstractQueuedSynchronizerTest.java 2004/01/04 00:57:21 1.8 +++ jsr166/src/test/tck/AbstractQueuedSynchronizerTest.java 2004/01/08 01:29:46 1.11 @@ -32,7 +32,7 @@ public class AbstractQueuedSynchronizerT private static class Sync extends AbstractQueuedSynchronizer { boolean isLocked() { return getState() == 1; } - public boolean tryAcquireExclusive(boolean isQueued, int acquires) { + public boolean tryAcquireExclusive(int acquires) { assert acquires == 1; // Does not use multiple acquires return compareAndSetState(0, 1); } @@ -57,7 +57,7 @@ public class AbstractQueuedSynchronizerT private final Sync sync = new Sync(); public boolean tryLock() { - return sync.tryAcquireExclusive(false, 1); + return sync.tryAcquireExclusive(1); } public void lock() { sync.acquireExclusiveUninterruptibly(1); @@ -73,6 +73,7 @@ public class AbstractQueuedSynchronizerT public boolean isLocked() { return sync.isLocked(); } public boolean hasQueuedThreads() { return sync.hasQueuedThreads(); } public boolean hasContended() { return sync.hasContended(); } + public boolean isQueued(Thread t) { return sync.isQueued(t); } } /** @@ -149,6 +150,51 @@ public class AbstractQueuedSynchronizerT t1.join(); t2.join(); } catch(Exception e){ + unexpectedException(); + } + } + + /** + * isQueued(null) throws NPE + */ + public void testIsQueuedNPE() { + final Mutex lock = new Mutex(); + try { + lock.isQueued(null); + shouldThrow(); + } catch (NullPointerException success) { + } + } + + /** + * isQueued reports whether a thread is queued. + */ + public void testIsQueued() { + final Mutex lock = new Mutex(); + Thread t1 = new Thread(new InterruptedLockRunnable(lock)); + Thread t2 = new Thread(new InterruptibleLockRunnable(lock)); + try { + assertFalse(lock.isQueued(t1)); + assertFalse(lock.isQueued(t2)); + lock.lock(); + t1.start(); + Thread.sleep(SHORT_DELAY_MS); + assertTrue(lock.isQueued(t1)); + t2.start(); + Thread.sleep(SHORT_DELAY_MS); + assertTrue(lock.isQueued(t1)); + assertTrue(lock.isQueued(t2)); + t1.interrupt(); + Thread.sleep(SHORT_DELAY_MS); + assertFalse(lock.isQueued(t1)); + assertTrue(lock.isQueued(t2)); + lock.unlock(); + Thread.sleep(SHORT_DELAY_MS); + assertFalse(lock.isQueued(t1)); + assertFalse(lock.isQueued(t2)); + t1.join(); + t2.join(); + } catch(Exception e){ unexpectedException(); } }