302 |
|
public void testArrive2() { |
303 |
|
final Phaser phaser = new Phaser(); |
304 |
|
assertEquals(0, phaser.register()); |
305 |
< |
List<Thread> threads = new ArrayList<Thread>(); |
305 |
> |
List<Thread> threads = new ArrayList<>(); |
306 |
|
for (int i = 0; i < 10; i++) { |
307 |
|
assertEquals(0, phaser.register()); |
308 |
|
threads.add(newStartedThread(new CheckedRunnable() { |
493 |
|
|
494 |
|
await(pleaseInterrupt); |
495 |
|
assertState(phaser, 0, 1, 1); |
496 |
< |
assertThreadsStayAlive(t1, t2); |
496 |
> |
assertThreadBlocks(t1, Thread.State.WAITING); |
497 |
> |
assertThreadBlocks(t2, Thread.State.TIMED_WAITING); |
498 |
|
t1.interrupt(); |
499 |
|
t2.interrupt(); |
500 |
|
awaitTermination(t1); |
524 |
|
}}); |
525 |
|
|
526 |
|
await(pleaseArrive); |
527 |
< |
waitForThreadToEnterWaitState(t, SHORT_DELAY_MS); |
527 |
> |
assertThreadBlocks(t, Thread.State.WAITING); |
528 |
|
assertEquals(0, phaser.arrive()); |
529 |
|
awaitTermination(t); |
530 |
|
|
552 |
|
}}); |
553 |
|
|
554 |
|
await(pleaseArrive); |
555 |
< |
waitForThreadToEnterWaitState(t, SHORT_DELAY_MS); |
555 |
> |
assertThreadBlocks(t, Thread.State.WAITING); |
556 |
|
t.interrupt(); |
557 |
|
assertEquals(0, phaser.arrive()); |
558 |
|
awaitTermination(t); |
568 |
|
public void testArriveAndAwaitAdvanceAfterInterrupt() { |
569 |
|
final Phaser phaser = new Phaser(); |
570 |
|
assertEquals(0, phaser.register()); |
571 |
< |
final CountDownLatch pleaseInterrupt = new CountDownLatch(1); |
571 |
> |
final CountDownLatch pleaseArrive = new CountDownLatch(1); |
572 |
|
|
573 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
574 |
|
public void realRun() { |
575 |
|
Thread.currentThread().interrupt(); |
576 |
|
assertEquals(0, phaser.register()); |
577 |
< |
pleaseInterrupt.countDown(); |
577 |
> |
pleaseArrive.countDown(); |
578 |
|
assertTrue(Thread.currentThread().isInterrupted()); |
579 |
|
assertEquals(1, phaser.arriveAndAwaitAdvance()); |
580 |
< |
assertTrue(Thread.currentThread().isInterrupted()); |
580 |
> |
assertTrue(Thread.interrupted()); |
581 |
|
}}); |
582 |
|
|
583 |
< |
await(pleaseInterrupt); |
584 |
< |
waitForThreadToEnterWaitState(t, SHORT_DELAY_MS); |
583 |
> |
await(pleaseArrive); |
584 |
> |
assertThreadBlocks(t, Thread.State.WAITING); |
585 |
|
Thread.currentThread().interrupt(); |
586 |
|
assertEquals(1, phaser.arriveAndAwaitAdvance()); |
587 |
|
assertTrue(Thread.interrupted()); |
602 |
|
assertFalse(Thread.currentThread().isInterrupted()); |
603 |
|
pleaseInterrupt.countDown(); |
604 |
|
assertEquals(1, phaser.arriveAndAwaitAdvance()); |
605 |
< |
assertTrue(Thread.currentThread().isInterrupted()); |
605 |
> |
assertTrue(Thread.interrupted()); |
606 |
|
}}); |
607 |
|
|
608 |
|
await(pleaseInterrupt); |
609 |
< |
waitForThreadToEnterWaitState(t, SHORT_DELAY_MS); |
609 |
> |
assertThreadBlocks(t, Thread.State.WAITING); |
610 |
|
t.interrupt(); |
611 |
|
Thread.currentThread().interrupt(); |
612 |
|
assertEquals(1, phaser.arriveAndAwaitAdvance()); |
621 |
|
public void testAwaitAdvance4() { |
622 |
|
final Phaser phaser = new Phaser(4); |
623 |
|
final AtomicInteger count = new AtomicInteger(0); |
624 |
< |
List<Thread> threads = new ArrayList<Thread>(); |
624 |
> |
List<Thread> threads = new ArrayList<>(); |
625 |
|
for (int i = 0; i < 4; i++) |
626 |
|
threads.add(newStartedThread(new CheckedRunnable() { |
627 |
|
public void realRun() { |
645 |
|
assertEquals(1, phaser.awaitAdvance(phaser.arrive())); |
646 |
|
assertEquals(1, phaser.getPhase()); |
647 |
|
assertEquals(1, phaser.register()); |
648 |
< |
List<Thread> threads = new ArrayList<Thread>(); |
648 |
> |
List<Thread> threads = new ArrayList<>(); |
649 |
|
for (int i = 0; i < 8; i++) { |
650 |
|
final CountDownLatch latch = new CountDownLatch(1); |
651 |
|
final boolean goesFirst = ((i & 1) == 0); |
673 |
|
*/ |
674 |
|
public void testAwaitAdvanceTieredPhaser() throws Exception { |
675 |
|
final Phaser parent = new Phaser(); |
676 |
< |
final List<Phaser> zeroPartyChildren = new ArrayList<Phaser>(3); |
677 |
< |
final List<Phaser> onePartyChildren = new ArrayList<Phaser>(3); |
676 |
> |
final List<Phaser> zeroPartyChildren = new ArrayList<>(3); |
677 |
> |
final List<Phaser> onePartyChildren = new ArrayList<>(3); |
678 |
|
for (int i = 0; i < 3; i++) { |
679 |
|
zeroPartyChildren.add(new Phaser(parent, 0)); |
680 |
|
onePartyChildren.add(new Phaser(parent, 1)); |
681 |
|
} |
682 |
< |
final List<Phaser> phasers = new ArrayList<Phaser>(); |
682 |
> |
final List<Phaser> phasers = new ArrayList<>(); |
683 |
|
phasers.addAll(zeroPartyChildren); |
684 |
|
phasers.addAll(onePartyChildren); |
685 |
|
phasers.add(parent); |
721 |
|
public void testAwaitAdvance6() { |
722 |
|
final Phaser phaser = new Phaser(3); |
723 |
|
final CountDownLatch pleaseForceTermination = new CountDownLatch(2); |
724 |
< |
final List<Thread> threads = new ArrayList<Thread>(); |
724 |
> |
final List<Thread> threads = new ArrayList<>(); |
725 |
|
for (int i = 0; i < 2; i++) { |
726 |
|
Runnable r = new CheckedRunnable() { |
727 |
|
public void realRun() { |
765 |
|
final Phaser phaser = new Phaser(1); |
766 |
|
final int THREADS = 3; |
767 |
|
final CountDownLatch pleaseArrive = new CountDownLatch(THREADS); |
768 |
< |
final List<Thread> threads = new ArrayList<Thread>(); |
768 |
> |
final List<Thread> threads = new ArrayList<>(); |
769 |
|
for (int i = 0; i < THREADS; i++) |
770 |
|
threads.add(newStartedThread(new CheckedRunnable() { |
771 |
|
public void realRun() { |
781 |
|
assertEquals(THREADS, phaser.getArrivedParties()); |
782 |
|
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
783 |
|
for (Thread thread : threads) |
784 |
< |
waitForThreadToEnterWaitState(thread, SHORT_DELAY_MS); |
784 |
> |
assertThreadBlocks(thread, Thread.State.WAITING); |
785 |
|
for (Thread thread : threads) |
786 |
|
assertTrue(thread.isAlive()); |
787 |
|
assertState(phaser, 0, THREADS + 1, 1); |