--- jsr166/src/test/tck/ReentrantReadWriteLockTest.java 2003/11/10 13:32:08 1.6 +++ jsr166/src/test/tck/ReentrantReadWriteLockTest.java 2003/12/27 18:27:02 1.11 @@ -56,17 +56,6 @@ public class ReentrantReadWriteLockTest public Collection getQueuedThreads() { return super.getQueuedThreads(); } - public WriterConditionObject newCondition() { - return new PublicCondition(this); - } - - static class PublicCondition extends ReentrantReadWriteLock.WriterConditionObject { - PublicCondition(PublicReentrantReadWriteLock l) { super(l); } - public Collection getWaitingThreads() { - return super.getWaitingThreads(); - } - } - } /** @@ -76,11 +65,11 @@ public class ReentrantReadWriteLockTest ReentrantReadWriteLock rl = new ReentrantReadWriteLock(); assertFalse(rl.isFair()); assertFalse(rl.isWriteLocked()); - assertEquals(0, rl.getReadLocks()); + assertEquals(0, rl.getReadLockCount()); ReentrantReadWriteLock r2 = new ReentrantReadWriteLock(true); assertTrue(r2.isFair()); assertFalse(r2.isWriteLocked()); - assertEquals(0, r2.getReadLocks()); + assertEquals(0, r2.getReadLockCount()); } /** @@ -91,19 +80,19 @@ public class ReentrantReadWriteLockTest rl.writeLock().lock(); assertTrue(rl.isWriteLocked()); assertTrue(rl.isWriteLockedByCurrentThread()); - assertEquals(0, rl.getReadLocks()); + assertEquals(0, rl.getReadLockCount()); rl.writeLock().unlock(); assertFalse(rl.isWriteLocked()); assertFalse(rl.isWriteLockedByCurrentThread()); - assertEquals(0, rl.getReadLocks()); + assertEquals(0, rl.getReadLockCount()); rl.readLock().lock(); assertFalse(rl.isWriteLocked()); assertFalse(rl.isWriteLockedByCurrentThread()); - assertEquals(1, rl.getReadLocks()); + assertEquals(1, rl.getReadLockCount()); rl.readLock().unlock(); assertFalse(rl.isWriteLocked()); assertFalse(rl.isWriteLockedByCurrentThread()); - assertEquals(0, rl.getReadLocks()); + assertEquals(0, rl.getReadLockCount()); } @@ -115,19 +104,19 @@ public class ReentrantReadWriteLockTest rl.writeLock().lock(); assertTrue(rl.isWriteLocked()); assertTrue(rl.isWriteLockedByCurrentThread()); - assertEquals(0, rl.getReadLocks()); + assertEquals(0, rl.getReadLockCount()); rl.writeLock().unlock(); assertFalse(rl.isWriteLocked()); assertFalse(rl.isWriteLockedByCurrentThread()); - assertEquals(0, rl.getReadLocks()); + assertEquals(0, rl.getReadLockCount()); rl.readLock().lock(); assertFalse(rl.isWriteLocked()); assertFalse(rl.isWriteLockedByCurrentThread()); - assertEquals(1, rl.getReadLocks()); + assertEquals(1, rl.getReadLockCount()); rl.readLock().unlock(); assertFalse(rl.isWriteLocked()); assertFalse(rl.isWriteLockedByCurrentThread()); - assertEquals(0, rl.getReadLocks()); + assertEquals(0, rl.getReadLockCount()); } /** @@ -920,7 +909,7 @@ public class ReentrantReadWriteLockTest */ public void testHasWaiters() { final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); - final ReentrantReadWriteLock.WriterConditionObject c = (ReentrantReadWriteLock.WriterConditionObject)(lock.writeLock().newCondition()); + final AbstractQueuedSynchronizer.ConditionObject c = (lock.writeLock().newCondition()); Thread t = new Thread(new Runnable() { public void run() { try { @@ -962,7 +951,7 @@ public class ReentrantReadWriteLockTest */ public void testGetWaitQueueLength() { final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); - final ReentrantReadWriteLock.WriterConditionObject c = (ReentrantReadWriteLock.WriterConditionObject)(lock.writeLock().newCondition()); + final AbstractQueuedSynchronizer.ConditionObject c = (lock.writeLock().newCondition()); Thread t1 = new Thread(new Runnable() { public void run() { try { @@ -1017,68 +1006,4 @@ public class ReentrantReadWriteLockTest unexpectedException(); } } - - /** - * getWaitingThreads returns only and all waiting threads - */ - public void testGetWaitingThreads() { - final PublicReentrantReadWriteLock lock = new PublicReentrantReadWriteLock(); - final PublicReentrantReadWriteLock.PublicCondition c = (PublicReentrantReadWriteLock.PublicCondition)lock.newCondition(); - Thread t1 = new Thread(new Runnable() { - public void run() { - try { - lock.writeLock().lock(); - threadAssertTrue(c.getWaitingThreads().isEmpty()); - c.await(); - lock.writeLock().unlock(); - } - catch(InterruptedException e) { - threadUnexpectedException(); - } - } - }); - - Thread t2 = new Thread(new Runnable() { - public void run() { - try { - lock.writeLock().lock(); - threadAssertFalse(c.getWaitingThreads().isEmpty()); - c.await(); - lock.writeLock().unlock(); - } - catch(InterruptedException e) { - threadUnexpectedException(); - } - } - }); - - try { - lock.writeLock().lock(); - assertTrue(c.getWaitingThreads().isEmpty()); - lock.writeLock().unlock(); - t1.start(); - Thread.sleep(SHORT_DELAY_MS); - t2.start(); - Thread.sleep(SHORT_DELAY_MS); - lock.writeLock().lock(); - assertTrue(c.hasWaiters()); - assertTrue(c.getWaitingThreads().contains(t1)); - assertTrue(c.getWaitingThreads().contains(t2)); - c.signalAll(); - lock.writeLock().unlock(); - Thread.sleep(SHORT_DELAY_MS); - lock.writeLock().lock(); - assertFalse(c.hasWaiters()); - assertTrue(c.getWaitingThreads().isEmpty()); - lock.writeLock().unlock(); - t1.join(SHORT_DELAY_MS); - t2.join(SHORT_DELAY_MS); - assertFalse(t1.isAlive()); - assertFalse(t2.isAlive()); - } - catch (Exception ex) { - unexpectedException(); - } - } - }