ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/PhaserTest.java
(Generate patch)

Comparing jsr166/src/test/tck/PhaserTest.java (file contents):
Revision 1.43 by jsr166, Mon Oct 5 22:38:38 2015 UTC vs.
Revision 1.49 by jsr166, Thu Sep 5 21:44:15 2019 UTC

# Line 302 | Line 302 | public class PhaserTest extends JSR166Te
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() {
# Line 478 | Line 478 | public class PhaserTest extends JSR166Te
478              public void realRun() throws TimeoutException {
479                  Thread.currentThread().interrupt();
480                  try {
481 <                    phaser.awaitAdvanceInterruptibly(0, 2*LONG_DELAY_MS, MILLISECONDS);
481 >                    phaser.awaitAdvanceInterruptibly(0, randomTimeout(), randomTimeUnit());
482                      shouldThrow();
483                  } catch (InterruptedException success) {}
484                  assertFalse(Thread.interrupted());
485  
486                  pleaseInterrupt.countDown();
487                  try {
488 <                    phaser.awaitAdvanceInterruptibly(0, 2*LONG_DELAY_MS, MILLISECONDS);
488 >                    phaser.awaitAdvanceInterruptibly(0, LONGER_DELAY_MS, MILLISECONDS);
489                      shouldThrow();
490                  } catch (InterruptedException success) {}
491                  assertFalse(Thread.interrupted());
# Line 493 | Line 493 | public class PhaserTest extends JSR166Te
493  
494          await(pleaseInterrupt);
495          assertState(phaser, 0, 1, 1);
496 <        assertThreadsStayAlive(t1, t2);
496 >        if (randomBoolean()) assertThreadBlocks(t1, Thread.State.WAITING);
497 >        if (randomBoolean()) assertThreadBlocks(t2, Thread.State.TIMED_WAITING);
498          t1.interrupt();
499          t2.interrupt();
500          awaitTermination(t1);
# Line 523 | Line 524 | public class PhaserTest extends JSR166Te
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  
# Line 551 | Line 552 | public class PhaserTest extends JSR166Te
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);
# Line 567 | Line 568 | public class PhaserTest extends JSR166Te
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());
# Line 601 | Line 602 | public class PhaserTest extends JSR166Te
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());
# Line 620 | Line 621 | public class PhaserTest extends JSR166Te
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() {
# Line 644 | Line 645 | public class PhaserTest extends JSR166Te
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);
# Line 672 | Line 673 | public class PhaserTest extends JSR166Te
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);
# Line 720 | Line 721 | public class PhaserTest extends JSR166Te
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() {
# Line 764 | Line 765 | public class PhaserTest extends JSR166Te
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() {
# Line 780 | Line 781 | public class PhaserTest extends JSR166Te
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);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines