20 |
|
public class PhaserTest extends JSR166TestCase { |
21 |
|
|
22 |
|
public static void main(String[] args) { |
23 |
< |
junit.textui.TestRunner.run(suite()); |
23 |
> |
main(suite(), args); |
24 |
|
} |
25 |
|
|
26 |
|
public static Test suite() { |
338 |
|
* registered or unarrived parties would become negative |
339 |
|
*/ |
340 |
|
public void testArriveAndDeregister1() { |
341 |
+ |
Phaser phaser = new Phaser(); |
342 |
|
try { |
342 |
– |
Phaser phaser = new Phaser(); |
343 |
|
phaser.arriveAndDeregister(); |
344 |
|
shouldThrow(); |
345 |
|
} catch (IllegalStateException success) {} |
625 |
|
threads.add(newStartedThread(new CheckedRunnable() { |
626 |
|
public void realRun() { |
627 |
|
for (int k = 0; k < 3; k++) { |
628 |
< |
assertEquals(2*k+1, phaser.arriveAndAwaitAdvance()); |
628 |
> |
assertEquals(2 * k + 1, phaser.arriveAndAwaitAdvance()); |
629 |
|
count.incrementAndGet(); |
630 |
< |
assertEquals(2*k+1, phaser.arrive()); |
631 |
< |
assertEquals(2*k+2, phaser.awaitAdvance(2*k+1)); |
632 |
< |
assertEquals(4*(k+1), count.get()); |
630 |
> |
assertEquals(2 * k + 1, phaser.arrive()); |
631 |
> |
assertEquals(2 * k + 2, phaser.awaitAdvance(2 * k + 1)); |
632 |
> |
assertEquals(4 * (k + 1), count.get()); |
633 |
|
}}})); |
634 |
|
|
635 |
|
for (Thread thread : threads) |
685 |
|
for (Phaser phaser : phasers) { |
686 |
|
assertEquals(-42, phaser.awaitAdvance(-42)); |
687 |
|
assertEquals(-42, phaser.awaitAdvanceInterruptibly(-42)); |
688 |
< |
assertEquals(-42, phaser.awaitAdvanceInterruptibly(-42, SMALL_DELAY_MS, MILLISECONDS)); |
688 |
> |
assertEquals(-42, phaser.awaitAdvanceInterruptibly(-42, MEDIUM_DELAY_MS, MILLISECONDS)); |
689 |
|
} |
690 |
|
|
691 |
|
for (Phaser child : onePartyChildren) |
693 |
|
for (Phaser phaser : phasers) { |
694 |
|
assertEquals(-42, phaser.awaitAdvance(-42)); |
695 |
|
assertEquals(-42, phaser.awaitAdvanceInterruptibly(-42)); |
696 |
< |
assertEquals(-42, phaser.awaitAdvanceInterruptibly(-42, SMALL_DELAY_MS, MILLISECONDS)); |
696 |
> |
assertEquals(-42, phaser.awaitAdvanceInterruptibly(-42, MEDIUM_DELAY_MS, MILLISECONDS)); |
697 |
|
assertEquals(1, phaser.awaitAdvance(0)); |
698 |
|
assertEquals(1, phaser.awaitAdvanceInterruptibly(0)); |
699 |
< |
assertEquals(1, phaser.awaitAdvanceInterruptibly(0, SMALL_DELAY_MS, MILLISECONDS)); |
699 |
> |
assertEquals(1, phaser.awaitAdvanceInterruptibly(0, MEDIUM_DELAY_MS, MILLISECONDS)); |
700 |
|
} |
701 |
|
|
702 |
|
for (Phaser child : onePartyChildren) |
704 |
|
for (Phaser phaser : phasers) { |
705 |
|
assertEquals(-42, phaser.awaitAdvance(-42)); |
706 |
|
assertEquals(-42, phaser.awaitAdvanceInterruptibly(-42)); |
707 |
< |
assertEquals(-42, phaser.awaitAdvanceInterruptibly(-42, SMALL_DELAY_MS, MILLISECONDS)); |
707 |
> |
assertEquals(-42, phaser.awaitAdvanceInterruptibly(-42, MEDIUM_DELAY_MS, MILLISECONDS)); |
708 |
|
assertEquals(2, phaser.awaitAdvance(0)); |
709 |
|
assertEquals(2, phaser.awaitAdvanceInterruptibly(0)); |
710 |
< |
assertEquals(2, phaser.awaitAdvanceInterruptibly(0, SMALL_DELAY_MS, MILLISECONDS)); |
710 |
> |
assertEquals(2, phaser.awaitAdvanceInterruptibly(0, MEDIUM_DELAY_MS, MILLISECONDS)); |
711 |
|
assertEquals(2, phaser.awaitAdvance(1)); |
712 |
|
assertEquals(2, phaser.awaitAdvanceInterruptibly(1)); |
713 |
< |
assertEquals(2, phaser.awaitAdvanceInterruptibly(1, SMALL_DELAY_MS, MILLISECONDS)); |
713 |
> |
assertEquals(2, phaser.awaitAdvanceInterruptibly(1, MEDIUM_DELAY_MS, MILLISECONDS)); |
714 |
|
} |
715 |
|
} |
716 |
|
|
748 |
|
* unarrived parties |
749 |
|
*/ |
750 |
|
public void testArriveAndAwaitAdvance1() { |
751 |
+ |
Phaser phaser = new Phaser(); |
752 |
|
try { |
752 |
– |
Phaser phaser = new Phaser(); |
753 |
|
phaser.arriveAndAwaitAdvance(); |
754 |
|
shouldThrow(); |
755 |
|
} catch (IllegalStateException success) {} |