476 |
|
|
477 |
|
Thread t2 = newStartedThread(new CheckedRunnable() { |
478 |
|
public void realRun() throws TimeoutException { |
479 |
+ |
long startTime = System.nanoTime(); |
480 |
+ |
|
481 |
|
Thread.currentThread().interrupt(); |
482 |
|
try { |
483 |
< |
phaser.awaitAdvanceInterruptibly(0, 2*LONG_DELAY_MS, MILLISECONDS); |
483 |
> |
phaser.awaitAdvanceInterruptibly(0, randomTimeout(), randomTimeUnit()); |
484 |
|
shouldThrow(); |
485 |
|
} catch (InterruptedException success) {} |
486 |
|
assertFalse(Thread.interrupted()); |
487 |
|
|
488 |
|
pleaseInterrupt.countDown(); |
489 |
|
try { |
490 |
< |
phaser.awaitAdvanceInterruptibly(0, 2*LONG_DELAY_MS, MILLISECONDS); |
490 |
> |
phaser.awaitAdvanceInterruptibly(0, LONG_DELAY_MS, MILLISECONDS); |
491 |
|
shouldThrow(); |
492 |
|
} catch (InterruptedException success) {} |
493 |
|
assertFalse(Thread.interrupted()); |
494 |
+ |
|
495 |
+ |
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
496 |
|
}}); |
497 |
|
|
498 |
|
await(pleaseInterrupt); |
499 |
|
assertState(phaser, 0, 1, 1); |
500 |
< |
assertThreadsStayAlive(t1, t2); |
500 |
> |
assertThreadBlocks(t1, Thread.State.WAITING); |
501 |
> |
assertThreadBlocks(t2, Thread.State.TIMED_WAITING); |
502 |
|
t1.interrupt(); |
503 |
|
t2.interrupt(); |
504 |
|
awaitTermination(t1); |
528 |
|
}}); |
529 |
|
|
530 |
|
await(pleaseArrive); |
531 |
< |
waitForThreadToEnterWaitState(t, SHORT_DELAY_MS); |
531 |
> |
assertThreadBlocks(t, Thread.State.WAITING); |
532 |
|
assertEquals(0, phaser.arrive()); |
533 |
|
awaitTermination(t); |
534 |
|
|
556 |
|
}}); |
557 |
|
|
558 |
|
await(pleaseArrive); |
559 |
< |
waitForThreadToEnterWaitState(t, SHORT_DELAY_MS); |
559 |
> |
assertThreadBlocks(t, Thread.State.WAITING); |
560 |
|
t.interrupt(); |
561 |
|
assertEquals(0, phaser.arrive()); |
562 |
|
awaitTermination(t); |
572 |
|
public void testArriveAndAwaitAdvanceAfterInterrupt() { |
573 |
|
final Phaser phaser = new Phaser(); |
574 |
|
assertEquals(0, phaser.register()); |
575 |
< |
final CountDownLatch pleaseInterrupt = new CountDownLatch(1); |
575 |
> |
final CountDownLatch pleaseArrive = new CountDownLatch(1); |
576 |
|
|
577 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
578 |
|
public void realRun() { |
579 |
|
Thread.currentThread().interrupt(); |
580 |
|
assertEquals(0, phaser.register()); |
581 |
< |
pleaseInterrupt.countDown(); |
581 |
> |
pleaseArrive.countDown(); |
582 |
|
assertTrue(Thread.currentThread().isInterrupted()); |
583 |
|
assertEquals(1, phaser.arriveAndAwaitAdvance()); |
584 |
< |
assertTrue(Thread.currentThread().isInterrupted()); |
584 |
> |
assertTrue(Thread.interrupted()); |
585 |
|
}}); |
586 |
|
|
587 |
< |
await(pleaseInterrupt); |
588 |
< |
waitForThreadToEnterWaitState(t, SHORT_DELAY_MS); |
587 |
> |
await(pleaseArrive); |
588 |
> |
assertThreadBlocks(t, Thread.State.WAITING); |
589 |
|
Thread.currentThread().interrupt(); |
590 |
|
assertEquals(1, phaser.arriveAndAwaitAdvance()); |
591 |
|
assertTrue(Thread.interrupted()); |
606 |
|
assertFalse(Thread.currentThread().isInterrupted()); |
607 |
|
pleaseInterrupt.countDown(); |
608 |
|
assertEquals(1, phaser.arriveAndAwaitAdvance()); |
609 |
< |
assertTrue(Thread.currentThread().isInterrupted()); |
609 |
> |
assertTrue(Thread.interrupted()); |
610 |
|
}}); |
611 |
|
|
612 |
|
await(pleaseInterrupt); |
613 |
< |
waitForThreadToEnterWaitState(t, SHORT_DELAY_MS); |
613 |
> |
assertThreadBlocks(t, Thread.State.WAITING); |
614 |
|
t.interrupt(); |
615 |
|
Thread.currentThread().interrupt(); |
616 |
|
assertEquals(1, phaser.arriveAndAwaitAdvance()); |
785 |
|
assertEquals(THREADS, phaser.getArrivedParties()); |
786 |
|
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
787 |
|
for (Thread thread : threads) |
788 |
< |
waitForThreadToEnterWaitState(thread, SHORT_DELAY_MS); |
788 |
> |
assertThreadBlocks(thread, Thread.State.WAITING); |
789 |
|
for (Thread thread : threads) |
790 |
|
assertTrue(thread.isAlive()); |
791 |
|
assertState(phaser, 0, THREADS + 1, 1); |