15 |
|
|
16 |
|
public class ReentrantReadWriteLockTest extends JSR166TestCase { |
17 |
|
public static void main(String[] args) { |
18 |
< |
junit.textui.TestRunner.run (suite()); |
18 |
> |
junit.textui.TestRunner.run(suite()); |
19 |
|
} |
20 |
|
public static Test suite() { |
21 |
|
return new TestSuite(ReentrantReadWriteLockTest.class); |
215 |
|
lock.writeLock().lock(); |
216 |
|
Thread t = new Thread(new CheckedInterruptedRunnable() { |
217 |
|
public void realRun() throws InterruptedException { |
218 |
< |
lock.writeLock().tryLock(1000,MILLISECONDS); |
218 |
> |
lock.writeLock().tryLock(SMALL_DELAY_MS, MILLISECONDS); |
219 |
|
}}); |
220 |
|
|
221 |
|
t.start(); |
222 |
+ |
Thread.sleep(SHORT_DELAY_MS); |
223 |
|
t.interrupt(); |
224 |
|
lock.writeLock().unlock(); |
225 |
|
t.join(); |
252 |
|
lock.writeLock().lock(); |
253 |
|
Thread t = new Thread(new CheckedInterruptedRunnable() { |
254 |
|
public void realRun() throws InterruptedException { |
255 |
< |
lock.readLock().tryLock(1000,MILLISECONDS); |
255 |
> |
lock.readLock().tryLock(LONG_DELAY_MS, MILLISECONDS); |
256 |
|
}}); |
257 |
|
|
258 |
|
t.start(); |
259 |
+ |
Thread.sleep(SHORT_DELAY_MS); |
260 |
|
t.interrupt(); |
261 |
|
t.join(); |
262 |
|
} |
270 |
|
lock.writeLock().lock(); |
271 |
|
Thread t = new Thread(new CheckedRunnable() { |
272 |
|
public void realRun() { |
273 |
< |
threadAssertFalse(lock.writeLock().tryLock()); |
273 |
> |
assertFalse(lock.writeLock().tryLock()); |
274 |
|
}}); |
275 |
|
|
276 |
|
t.start(); |
286 |
|
lock.writeLock().lock(); |
287 |
|
Thread t = new Thread(new CheckedRunnable() { |
288 |
|
public void realRun() { |
289 |
< |
threadAssertFalse(lock.readLock().tryLock()); |
289 |
> |
assertFalse(lock.readLock().tryLock()); |
290 |
|
}}); |
291 |
|
|
292 |
|
t.start(); |
302 |
|
lock.readLock().lock(); |
303 |
|
Thread t = new Thread(new CheckedRunnable() { |
304 |
|
public void realRun() { |
305 |
< |
threadAssertTrue(lock.readLock().tryLock()); |
305 |
> |
assertTrue(lock.readLock().tryLock()); |
306 |
|
lock.readLock().unlock(); |
307 |
|
}}); |
308 |
|
|
409 |
|
} |
410 |
|
|
411 |
|
/** |
412 |
< |
* Read lock succeeds if write locked by current thread even if |
412 |
> |
* Read lock succeeds if write locked by current thread even if |
413 |
|
* other threads are waiting for writelock |
414 |
|
*/ |
415 |
|
public void testReadHoldingWriteLock3() throws InterruptedException { |
442 |
|
|
443 |
|
|
444 |
|
/** |
445 |
< |
* Write lock succeeds if write locked by current thread even if |
445 |
> |
* Write lock succeeds if write locked by current thread even if |
446 |
|
* other threads are waiting for writelock |
447 |
|
*/ |
448 |
|
public void testWriteHoldingWriteLock4() throws InterruptedException { |
573 |
|
t2.start(); |
574 |
|
Thread.sleep(SHORT_DELAY_MS); |
575 |
|
assertTrue(lock.isWriteLockedByCurrentThread()); |
576 |
< |
assertTrue(lock.getWriteHoldCount() == 1); |
576 |
> |
assertEquals(1, lock.getWriteHoldCount()); |
577 |
|
lock.writeLock().lock(); |
578 |
< |
assertTrue(lock.getWriteHoldCount() == 2); |
578 |
> |
assertEquals(2, lock.getWriteHoldCount()); |
579 |
|
lock.writeLock().unlock(); |
580 |
|
lock.writeLock().lock(); |
581 |
|
lock.writeLock().unlock(); |
595 |
|
lock.readLock().lock(); |
596 |
|
Thread t = new Thread(new CheckedRunnable() { |
597 |
|
public void realRun() { |
598 |
< |
threadAssertTrue(lock.readLock().tryLock()); |
598 |
> |
assertTrue(lock.readLock().tryLock()); |
599 |
|
lock.readLock().unlock(); |
600 |
|
}}); |
601 |
|
|
614 |
|
lock.readLock().lock(); |
615 |
|
Thread t = new Thread(new CheckedRunnable() { |
616 |
|
public void realRun() { |
617 |
< |
threadAssertFalse(lock.writeLock().tryLock()); |
617 |
> |
assertFalse(lock.writeLock().tryLock()); |
618 |
|
}}); |
619 |
|
|
620 |
|
t.start(); |
631 |
|
lock.readLock().lock(); |
632 |
|
Thread t = new Thread(new CheckedRunnable() { |
633 |
|
public void realRun() { |
634 |
< |
threadAssertTrue(lock.readLock().tryLock()); |
634 |
> |
assertTrue(lock.readLock().tryLock()); |
635 |
|
lock.readLock().unlock(); |
636 |
|
}}); |
637 |
|
|
650 |
|
lock.readLock().lock(); |
651 |
|
Thread t = new Thread(new CheckedRunnable() { |
652 |
|
public void realRun() { |
653 |
< |
threadAssertFalse(lock.writeLock().tryLock()); |
653 |
> |
assertFalse(lock.writeLock().tryLock()); |
654 |
|
}}); |
655 |
|
|
656 |
|
t.start(); |
668 |
|
lock.writeLock().lock(); |
669 |
|
Thread t = new Thread(new CheckedRunnable() { |
670 |
|
public void realRun() throws InterruptedException { |
671 |
< |
threadAssertFalse(lock.writeLock().tryLock(1, MILLISECONDS)); |
671 |
> |
assertFalse(lock.writeLock().tryLock(1, MILLISECONDS)); |
672 |
|
}}); |
673 |
|
|
674 |
|
t.start(); |
685 |
|
lock.writeLock().lock(); |
686 |
|
Thread t = new Thread(new CheckedRunnable() { |
687 |
|
public void realRun() throws InterruptedException { |
688 |
< |
threadAssertFalse(lock.readLock().tryLock(1, MILLISECONDS)); |
688 |
> |
assertFalse(lock.readLock().tryLock(1, MILLISECONDS)); |
689 |
|
}}); |
690 |
|
|
691 |
|
t.start(); |
715 |
|
} |
716 |
|
|
717 |
|
/** |
718 |
< |
* read lockInterruptibly succeeds if lock free else is interruptible |
718 |
> |
* read lockInterruptibly succeeds if lock free else is interruptible |
719 |
|
*/ |
720 |
|
public void testReadLockInterruptibly() throws InterruptedException { |
721 |
|
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
771 |
|
|
772 |
|
|
773 |
|
/** |
774 |
< |
* timed await without a signal times out |
774 |
> |
* timed await without a signal times out |
775 |
|
*/ |
776 |
|
public void testAwait_Timeout() throws InterruptedException { |
777 |
|
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); |
899 |
|
Thread t = new Thread(new CheckedInterruptedRunnable() { |
900 |
|
public void realRun() throws InterruptedException { |
901 |
|
lock.writeLock().lock(); |
902 |
< |
c.awaitNanos(SHORT_DELAY_MS * 2 * 1000000); |
902 |
> |
c.awaitNanos(MILLISECONDS.toNanos(LONG_DELAY_MS)); |
903 |
|
lock.writeLock().unlock(); |
904 |
|
}}); |
905 |
|
|
1224 |
|
Thread t = new Thread(new CheckedRunnable() { |
1225 |
|
public void realRun() throws InterruptedException { |
1226 |
|
lock.writeLock().lock(); |
1227 |
< |
threadAssertFalse(lock.hasWaiters(c)); |
1228 |
< |
threadAssertEquals(0, lock.getWaitQueueLength(c)); |
1227 |
> |
assertFalse(lock.hasWaiters(c)); |
1228 |
> |
assertEquals(0, lock.getWaitQueueLength(c)); |
1229 |
|
c.await(); |
1230 |
|
lock.writeLock().unlock(); |
1231 |
|
}}); |
1255 |
|
Thread t = new Thread(new CheckedRunnable() { |
1256 |
|
public void realRun() throws InterruptedException { |
1257 |
|
lock.writeLock().lock(); |
1258 |
< |
threadAssertFalse(lock.hasWaiters(c)); |
1259 |
< |
threadAssertEquals(0, lock.getWaitQueueLength(c)); |
1258 |
> |
assertFalse(lock.hasWaiters(c)); |
1259 |
> |
assertEquals(0, lock.getWaitQueueLength(c)); |
1260 |
|
c.await(); |
1261 |
|
lock.writeLock().unlock(); |
1262 |
|
}}); |
1287 |
|
Thread t1 = new Thread(new CheckedRunnable() { |
1288 |
|
public void realRun() throws InterruptedException { |
1289 |
|
lock.writeLock().lock(); |
1290 |
< |
threadAssertTrue(lock.getWaitingThreads(c).isEmpty()); |
1290 |
> |
assertTrue(lock.getWaitingThreads(c).isEmpty()); |
1291 |
|
c.await(); |
1292 |
|
lock.writeLock().unlock(); |
1293 |
|
}}); |
1295 |
|
Thread t2 = new Thread(new CheckedRunnable() { |
1296 |
|
public void realRun() throws InterruptedException { |
1297 |
|
lock.writeLock().lock(); |
1298 |
< |
threadAssertFalse(lock.getWaitingThreads(c).isEmpty()); |
1298 |
> |
assertFalse(lock.getWaitingThreads(c).isEmpty()); |
1299 |
|
c.await(); |
1300 |
|
lock.writeLock().unlock(); |
1301 |
|
}}); |