262 |
|
public void testInterruptedException2() throws InterruptedException { |
263 |
|
final ReentrantLock lock = new ReentrantLock(); |
264 |
|
lock.lock(); |
265 |
< |
Thread t = new Thread(new CheckedInterruptedRunnable() { |
265 |
> |
Thread t = newStartedThread(new CheckedInterruptedRunnable() { |
266 |
|
public void realRun() throws InterruptedException { |
267 |
|
lock.tryLock(MEDIUM_DELAY_MS,MILLISECONDS); |
268 |
|
}}); |
269 |
|
|
270 |
– |
t.start(); |
270 |
|
delay(SHORT_DELAY_MS); |
271 |
|
t.interrupt(); |
272 |
|
t.join(); |
279 |
|
public void testTryLockWhenLocked() throws InterruptedException { |
280 |
|
final ReentrantLock lock = new ReentrantLock(); |
281 |
|
lock.lock(); |
282 |
< |
Thread t = new Thread(new CheckedRunnable() { |
282 |
> |
Thread t = newStartedThread(new CheckedRunnable() { |
283 |
|
public void realRun() { |
284 |
|
assertFalse(lock.tryLock()); |
285 |
|
}}); |
286 |
|
|
288 |
– |
t.start(); |
287 |
|
t.join(); |
288 |
|
lock.unlock(); |
289 |
|
} |
294 |
|
public void testTryLock_Timeout() throws InterruptedException { |
295 |
|
final ReentrantLock lock = new ReentrantLock(); |
296 |
|
lock.lock(); |
297 |
< |
Thread t = new Thread(new CheckedRunnable() { |
297 |
> |
Thread t = newStartedThread(new CheckedRunnable() { |
298 |
|
public void realRun() throws InterruptedException { |
299 |
|
assertFalse(lock.tryLock(1, MILLISECONDS)); |
300 |
|
}}); |
301 |
|
|
304 |
– |
t.start(); |
302 |
|
t.join(); |
303 |
|
lock.unlock(); |
304 |
|
} |
328 |
|
assertTrue(lock.isLocked()); |
329 |
|
lock.unlock(); |
330 |
|
assertFalse(lock.isLocked()); |
331 |
< |
Thread t = new Thread(new CheckedRunnable() { |
331 |
> |
Thread t = newStartedThread(new CheckedRunnable() { |
332 |
|
public void realRun() throws InterruptedException { |
333 |
|
lock.lock(); |
334 |
|
delay(SMALL_DELAY_MS); |
335 |
|
lock.unlock(); |
336 |
|
}}); |
337 |
|
|
341 |
– |
t.start(); |
338 |
|
delay(SHORT_DELAY_MS); |
339 |
|
assertTrue(lock.isLocked()); |
340 |
|
t.join(); |
348 |
|
public void testLockInterruptibly1() throws InterruptedException { |
349 |
|
final ReentrantLock lock = new ReentrantLock(); |
350 |
|
lock.lock(); |
351 |
< |
Thread t = new Thread(new InterruptedLockRunnable(lock)); |
356 |
< |
t.start(); |
351 |
> |
Thread t = newStartedThread(new InterruptedLockRunnable(lock)); |
352 |
|
delay(SHORT_DELAY_MS); |
353 |
|
t.interrupt(); |
354 |
|
delay(SHORT_DELAY_MS); |
362 |
|
public void testLockInterruptibly2() throws InterruptedException { |
363 |
|
final ReentrantLock lock = new ReentrantLock(); |
364 |
|
lock.lockInterruptibly(); |
365 |
< |
Thread t = new Thread(new InterruptedLockRunnable(lock)); |
371 |
< |
t.start(); |
365 |
> |
Thread t = newStartedThread(new InterruptedLockRunnable(lock)); |
366 |
|
delay(SHORT_DELAY_MS); |
367 |
|
t.interrupt(); |
368 |
|
assertTrue(lock.isLocked()); |
435 |
|
public void testAwait() throws InterruptedException { |
436 |
|
final ReentrantLock lock = new ReentrantLock(); |
437 |
|
final Condition c = lock.newCondition(); |
438 |
< |
Thread t = new Thread(new CheckedRunnable() { |
438 |
> |
Thread t = newStartedThread(new CheckedRunnable() { |
439 |
|
public void realRun() throws InterruptedException { |
440 |
|
lock.lock(); |
441 |
|
c.await(); |
442 |
|
lock.unlock(); |
443 |
|
}}); |
444 |
|
|
451 |
– |
t.start(); |
445 |
|
delay(SHORT_DELAY_MS); |
446 |
|
lock.lock(); |
447 |
|
c.signal(); |
569 |
|
public void testHasWaiters() throws InterruptedException { |
570 |
|
final ReentrantLock lock = new ReentrantLock(); |
571 |
|
final Condition c = lock.newCondition(); |
572 |
< |
Thread t = new Thread(new CheckedRunnable() { |
572 |
> |
Thread t = newStartedThread(new CheckedRunnable() { |
573 |
|
public void realRun() throws InterruptedException { |
574 |
|
lock.lock(); |
575 |
|
assertFalse(lock.hasWaiters(c)); |
578 |
|
lock.unlock(); |
579 |
|
}}); |
580 |
|
|
588 |
– |
t.start(); |
581 |
|
delay(SHORT_DELAY_MS); |
582 |
|
lock.lock(); |
583 |
|
assertTrue(lock.hasWaiters(c)); |
599 |
|
public void testGetWaitQueueLength() throws InterruptedException { |
600 |
|
final ReentrantLock lock = new ReentrantLock(); |
601 |
|
final Condition c = lock.newCondition(); |
602 |
< |
Thread t1 = new Thread(new CheckedRunnable() { |
602 |
> |
Thread t1 = newStartedThread(new CheckedRunnable() { |
603 |
|
public void realRun() throws InterruptedException { |
604 |
|
lock.lock(); |
605 |
|
assertFalse(lock.hasWaiters(c)); |
608 |
|
lock.unlock(); |
609 |
|
}}); |
610 |
|
|
611 |
< |
Thread t2 = new Thread(new CheckedRunnable() { |
611 |
> |
delay(SHORT_DELAY_MS); |
612 |
> |
|
613 |
> |
Thread t2 = newStartedThread(new CheckedRunnable() { |
614 |
|
public void realRun() throws InterruptedException { |
615 |
|
lock.lock(); |
616 |
|
assertTrue(lock.hasWaiters(c)); |
619 |
|
lock.unlock(); |
620 |
|
}}); |
621 |
|
|
628 |
– |
t1.start(); |
629 |
– |
delay(SHORT_DELAY_MS); |
630 |
– |
t2.start(); |
622 |
|
delay(SHORT_DELAY_MS); |
623 |
|
lock.lock(); |
624 |
|
assertTrue(lock.hasWaiters(c)); |
743 |
|
public void testAwait_Interrupt() throws InterruptedException { |
744 |
|
final ReentrantLock lock = new ReentrantLock(); |
745 |
|
final Condition c = lock.newCondition(); |
746 |
< |
Thread t = new Thread(new CheckedInterruptedRunnable() { |
746 |
> |
Thread t = newStartedThread(new CheckedInterruptedRunnable() { |
747 |
|
public void realRun() throws InterruptedException { |
748 |
|
lock.lock(); |
749 |
|
c.await(); |
750 |
|
}}); |
751 |
|
|
761 |
– |
t.start(); |
752 |
|
delay(SHORT_DELAY_MS); |
753 |
|
t.interrupt(); |
754 |
|
t.join(SHORT_DELAY_MS); |
761 |
|
public void testAwaitNanos_Interrupt() throws InterruptedException { |
762 |
|
final ReentrantLock lock = new ReentrantLock(); |
763 |
|
final Condition c = lock.newCondition(); |
764 |
< |
Thread t = new Thread(new CheckedInterruptedRunnable() { |
764 |
> |
Thread t = newStartedThread(new CheckedInterruptedRunnable() { |
765 |
|
public void realRun() throws InterruptedException { |
766 |
|
lock.lock(); |
767 |
|
c.awaitNanos(MILLISECONDS.toNanos(LONG_DELAY_MS)); |
768 |
|
}}); |
769 |
|
|
780 |
– |
t.start(); |
770 |
|
delay(SHORT_DELAY_MS); |
771 |
|
t.interrupt(); |
772 |
|
t.join(SHORT_DELAY_MS); |
779 |
|
public void testAwaitUntil_Interrupt() throws InterruptedException { |
780 |
|
final ReentrantLock lock = new ReentrantLock(); |
781 |
|
final Condition c = lock.newCondition(); |
782 |
< |
Thread t = new Thread(new CheckedInterruptedRunnable() { |
782 |
> |
Thread t = newStartedThread(new CheckedInterruptedRunnable() { |
783 |
|
public void realRun() throws InterruptedException { |
784 |
|
lock.lock(); |
785 |
|
java.util.Date d = new java.util.Date(); |
786 |
|
c.awaitUntil(new java.util.Date(d.getTime() + 10000)); |
787 |
|
}}); |
788 |
|
|
800 |
– |
t.start(); |
789 |
|
delay(SHORT_DELAY_MS); |
790 |
|
t.interrupt(); |
791 |
|
t.join(SHORT_DELAY_MS); |
798 |
|
public void testSignalAll() throws InterruptedException { |
799 |
|
final ReentrantLock lock = new ReentrantLock(); |
800 |
|
final Condition c = lock.newCondition(); |
801 |
< |
Thread t1 = new Thread(new CheckedRunnable() { |
801 |
> |
Thread t1 = newStartedThread(new CheckedRunnable() { |
802 |
|
public void realRun() throws InterruptedException { |
803 |
|
lock.lock(); |
804 |
|
c.await(); |
805 |
|
lock.unlock(); |
806 |
|
}}); |
807 |
|
|
808 |
< |
Thread t2 = new Thread(new CheckedRunnable() { |
808 |
> |
Thread t2 = newStartedThread(new CheckedRunnable() { |
809 |
|
public void realRun() throws InterruptedException { |
810 |
|
lock.lock(); |
811 |
|
c.await(); |
812 |
|
lock.unlock(); |
813 |
|
}}); |
814 |
|
|
827 |
– |
t1.start(); |
828 |
– |
t2.start(); |
815 |
|
delay(SHORT_DELAY_MS); |
816 |
|
lock.lock(); |
817 |
|
c.signalAll(); |
828 |
|
public void testAwaitLockCount() throws InterruptedException { |
829 |
|
final ReentrantLock lock = new ReentrantLock(); |
830 |
|
final Condition c = lock.newCondition(); |
831 |
< |
Thread t1 = new Thread(new CheckedRunnable() { |
831 |
> |
Thread t1 = newStartedThread(new CheckedRunnable() { |
832 |
|
public void realRun() throws InterruptedException { |
833 |
|
lock.lock(); |
834 |
|
assertEquals(1, lock.getHoldCount()); |
837 |
|
lock.unlock(); |
838 |
|
}}); |
839 |
|
|
840 |
< |
Thread t2 = new Thread(new CheckedRunnable() { |
840 |
> |
Thread t2 = newStartedThread(new CheckedRunnable() { |
841 |
|
public void realRun() throws InterruptedException { |
842 |
|
lock.lock(); |
843 |
|
lock.lock(); |
848 |
|
lock.unlock(); |
849 |
|
}}); |
850 |
|
|
865 |
– |
t1.start(); |
866 |
– |
t2.start(); |
851 |
|
delay(SHORT_DELAY_MS); |
852 |
|
lock.lock(); |
853 |
|
c.signalAll(); |