--- jsr166/src/test/tck/ReentrantLockTest.java 2003/09/25 11:02:41 1.7 +++ jsr166/src/test/tck/ReentrantLockTest.java 2003/12/27 18:27:02 1.11 @@ -56,20 +56,20 @@ public class ReentrantLockTest extends J public Collection getQueuedThreads() { return super.getQueuedThreads(); } - public ConditionObject newCondition() { - return new PublicCondition(this); - } - static class PublicCondition extends ReentrantLock.ConditionObject { - PublicCondition(PublicReentrantLock l) { super(l); } - public Collection getWaitingThreads() { - return super.getWaitingThreads(); - } - } + } + /** + * Constructor sets given fairness + */ + public void testConstructor() { + ReentrantLock rl = new ReentrantLock(); + assertFalse(rl.isFair()); + ReentrantLock r2 = new ReentrantLock(true); + assertTrue(r2.isFair()); } - /* + /** * locking an unlocked lock succeeds */ public void testLock() { @@ -79,7 +79,7 @@ public class ReentrantLockTest extends J rl.unlock(); } - /* + /** * locking an unlocked fair lock succeeds */ public void testFairLock() { @@ -89,7 +89,7 @@ public class ReentrantLockTest extends J rl.unlock(); } - /* + /** * Unlocking an unlocked lock throws IllegalMonitorStateException */ public void testUnlock_IllegalMonitorStateException() { @@ -101,7 +101,7 @@ public class ReentrantLockTest extends J } catch(IllegalMonitorStateException success){} } - /* + /** * trylock on an unlocked lock succeeds */ public void testTryLock() { @@ -112,7 +112,7 @@ public class ReentrantLockTest extends J } - /* + /** * getQueueLength reports number of waiting threads */ public void testGetQueueLength() { @@ -141,7 +141,7 @@ public class ReentrantLockTest extends J } } - /* + /** * getQueuedThreads includes waiting threads */ public void testGetQueuedThreads() { @@ -174,7 +174,7 @@ public class ReentrantLockTest extends J } - /* + /** * timed trylock is interruptible. */ public void testInterruptedException2() { @@ -290,7 +290,7 @@ public class ReentrantLockTest extends J } - /* + /** * lockInterruptibly is interruptible. */ public void testLockInterruptibly1() { @@ -418,7 +418,7 @@ public class ReentrantLockTest extends J */ public void testAwait() { final ReentrantLock lock = new ReentrantLock(); - final ReentrantLock.ConditionObject c = lock.newCondition(); + final AbstractQueuedSynchronizer.ConditionObject c = lock.newCondition(); Thread t = new Thread(new Runnable() { public void run() { try { @@ -451,7 +451,7 @@ public class ReentrantLockTest extends J */ public void testHasWaiters() { final ReentrantLock lock = new ReentrantLock(); - final ReentrantLock.ConditionObject c = lock.newCondition(); + final AbstractQueuedSynchronizer.ConditionObject c = lock.newCondition(); Thread t = new Thread(new Runnable() { public void run() { try { @@ -493,7 +493,7 @@ public class ReentrantLockTest extends J */ public void testGetWaitQueueLength() { final ReentrantLock lock = new ReentrantLock(); - final ReentrantLock.ConditionObject c = lock.newCondition(); + final AbstractQueuedSynchronizer.ConditionObject c = lock.newCondition(); Thread t1 = new Thread(new Runnable() { public void run() { try { @@ -541,69 +541,6 @@ public class ReentrantLockTest extends J lock.unlock(); t1.join(SHORT_DELAY_MS); t2.join(SHORT_DELAY_MS); - assertFalse(t1.isAlive()); - assertFalse(t2.isAlive()); - } - catch (Exception ex) { - unexpectedException(); - } - } - - /** - * getWaitingThreads returns only and all waiting threads - */ - public void testGetWaitingThreads() { - final PublicReentrantLock lock = new PublicReentrantLock(); - final PublicReentrantLock.PublicCondition c = (PublicReentrantLock.PublicCondition)lock.newCondition(); - Thread t1 = new Thread(new Runnable() { - public void run() { - try { - lock.lock(); - threadAssertTrue(c.getWaitingThreads().isEmpty()); - c.await(); - lock.unlock(); - } - catch(InterruptedException e) { - threadUnexpectedException(); - } - } - }); - - Thread t2 = new Thread(new Runnable() { - public void run() { - try { - lock.lock(); - threadAssertFalse(c.getWaitingThreads().isEmpty()); - c.await(); - lock.unlock(); - } - catch(InterruptedException e) { - threadUnexpectedException(); - } - } - }); - - try { - lock.lock(); - assertTrue(c.getWaitingThreads().isEmpty()); - lock.unlock(); - t1.start(); - Thread.sleep(SHORT_DELAY_MS); - t2.start(); - Thread.sleep(SHORT_DELAY_MS); - lock.lock(); - assertTrue(c.hasWaiters()); - assertTrue(c.getWaitingThreads().contains(t1)); - assertTrue(c.getWaitingThreads().contains(t2)); - c.signalAll(); - lock.unlock(); - Thread.sleep(SHORT_DELAY_MS); - lock.lock(); - assertFalse(c.hasWaiters()); - assertTrue(c.getWaitingThreads().isEmpty()); - lock.unlock(); - t1.join(SHORT_DELAY_MS); - t2.join(SHORT_DELAY_MS); assertFalse(t1.isAlive()); assertFalse(t2.isAlive()); }