15 |
|
|
16 |
|
public class ReentrantLockTest 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(ReentrantLockTest.class); |
56 |
|
public Collection<Thread> getWaitingThreads(Condition c) { |
57 |
|
return super.getWaitingThreads(c); |
58 |
|
} |
59 |
– |
|
60 |
– |
|
59 |
|
} |
60 |
|
|
61 |
|
/** |
268 |
|
}}); |
269 |
|
|
270 |
|
t.start(); |
271 |
+ |
Thread.sleep(SHORT_DELAY_MS); |
272 |
|
t.interrupt(); |
273 |
|
t.join(); |
274 |
|
} |
282 |
|
lock.lock(); |
283 |
|
Thread t = new Thread(new CheckedRunnable() { |
284 |
|
public void realRun() { |
285 |
< |
threadAssertFalse(lock.tryLock()); |
285 |
> |
assertFalse(lock.tryLock()); |
286 |
|
}}); |
287 |
|
|
288 |
|
t.start(); |
298 |
|
lock.lock(); |
299 |
|
Thread t = new Thread(new CheckedRunnable() { |
300 |
|
public void realRun() throws InterruptedException { |
301 |
< |
threadAssertFalse(lock.tryLock(1, MILLISECONDS)); |
301 |
> |
assertFalse(lock.tryLock(1, MILLISECONDS)); |
302 |
|
}}); |
303 |
|
|
304 |
|
t.start(); |
369 |
|
lock.lockInterruptibly(); |
370 |
|
Thread t = new Thread(new InterruptedLockRunnable(lock)); |
371 |
|
t.start(); |
372 |
+ |
Thread.sleep(SHORT_DELAY_MS); |
373 |
|
t.interrupt(); |
374 |
|
assertTrue(lock.isLocked()); |
375 |
|
assertTrue(lock.isHeldByCurrentThread()); |
413 |
|
} |
414 |
|
|
415 |
|
/** |
416 |
< |
* timed await without a signal times out |
416 |
> |
* timed await without a signal times out |
417 |
|
*/ |
418 |
|
public void testAwait_Timeout() throws InterruptedException { |
419 |
|
final ReentrantLock lock = new ReentrantLock(); |
579 |
|
Thread t = new Thread(new CheckedRunnable() { |
580 |
|
public void realRun() throws InterruptedException { |
581 |
|
lock.lock(); |
582 |
< |
threadAssertFalse(lock.hasWaiters(c)); |
583 |
< |
threadAssertEquals(0, lock.getWaitQueueLength(c)); |
582 |
> |
assertFalse(lock.hasWaiters(c)); |
583 |
> |
assertEquals(0, lock.getWaitQueueLength(c)); |
584 |
|
c.await(); |
585 |
|
lock.unlock(); |
586 |
|
}}); |
610 |
|
Thread t1 = new Thread(new CheckedRunnable() { |
611 |
|
public void realRun() throws InterruptedException { |
612 |
|
lock.lock(); |
613 |
< |
threadAssertFalse(lock.hasWaiters(c)); |
614 |
< |
threadAssertEquals(0, lock.getWaitQueueLength(c)); |
613 |
> |
assertFalse(lock.hasWaiters(c)); |
614 |
> |
assertEquals(0, lock.getWaitQueueLength(c)); |
615 |
|
c.await(); |
616 |
|
lock.unlock(); |
617 |
|
}}); |
619 |
|
Thread t2 = new Thread(new CheckedRunnable() { |
620 |
|
public void realRun() throws InterruptedException { |
621 |
|
lock.lock(); |
622 |
< |
threadAssertTrue(lock.hasWaiters(c)); |
623 |
< |
threadAssertEquals(1, lock.getWaitQueueLength(c)); |
622 |
> |
assertTrue(lock.hasWaiters(c)); |
623 |
> |
assertEquals(1, lock.getWaitQueueLength(c)); |
624 |
|
c.await(); |
625 |
|
lock.unlock(); |
626 |
|
}}); |
654 |
|
Thread t1 = new Thread(new CheckedRunnable() { |
655 |
|
public void realRun() throws InterruptedException { |
656 |
|
lock.lock(); |
657 |
< |
threadAssertTrue(lock.getWaitingThreads(c).isEmpty()); |
657 |
> |
assertTrue(lock.getWaitingThreads(c).isEmpty()); |
658 |
|
c.await(); |
659 |
|
lock.unlock(); |
660 |
|
}}); |
662 |
|
Thread t2 = new Thread(new CheckedRunnable() { |
663 |
|
public void realRun() throws InterruptedException { |
664 |
|
lock.lock(); |
665 |
< |
threadAssertFalse(lock.getWaitingThreads(c).isEmpty()); |
665 |
> |
assertFalse(lock.getWaitingThreads(c).isEmpty()); |
666 |
|
c.await(); |
667 |
|
lock.unlock(); |
668 |
|
}}); |
774 |
|
Thread t = new Thread(new CheckedInterruptedRunnable() { |
775 |
|
public void realRun() throws InterruptedException { |
776 |
|
lock.lock(); |
777 |
< |
c.awaitNanos(1000 * 1000 * 1000); // 1 sec |
777 |
> |
c.awaitNanos(MILLISECONDS.toNanos(LONG_DELAY_MS)); |
778 |
|
}}); |
779 |
|
|
780 |
|
t.start(); |
845 |
|
Thread t1 = new Thread(new CheckedRunnable() { |
846 |
|
public void realRun() throws InterruptedException { |
847 |
|
lock.lock(); |
848 |
< |
threadAssertEquals(1, lock.getHoldCount()); |
848 |
> |
assertEquals(1, lock.getHoldCount()); |
849 |
|
c.await(); |
850 |
< |
threadAssertEquals(1, lock.getHoldCount()); |
850 |
> |
assertEquals(1, lock.getHoldCount()); |
851 |
|
lock.unlock(); |
852 |
|
}}); |
853 |
|
|
855 |
|
public void realRun() throws InterruptedException { |
856 |
|
lock.lock(); |
857 |
|
lock.lock(); |
858 |
< |
threadAssertEquals(2, lock.getHoldCount()); |
858 |
> |
assertEquals(2, lock.getHoldCount()); |
859 |
|
c.await(); |
860 |
< |
threadAssertEquals(2, lock.getHoldCount()); |
860 |
> |
assertEquals(2, lock.getHoldCount()); |
861 |
|
lock.unlock(); |
862 |
|
lock.unlock(); |
863 |
|
}}); |
887 |
|
new ObjectOutputStream(new BufferedOutputStream(bout)); |
888 |
|
out.writeObject(l); |
889 |
|
out.close(); |
890 |
< |
|
890 |
> |
|
891 |
|
ByteArrayInputStream bin = |
892 |
|
new ByteArrayInputStream(bout.toByteArray()); |
893 |
|
ObjectInputStream in = |