test/jdk/java/util/concurrent/tck/PhaserTest.java
changeset 58138 1e4270f875ee
parent 47216 71c04702a3d5
equal deleted inserted replaced
58137:6a556bcd94fc 58138:1e4270f875ee
   478     }
   478     }
   479 
   479 
   480     /**
   480     /**
   481      * awaitAdvanceInterruptibly blocks interruptibly
   481      * awaitAdvanceInterruptibly blocks interruptibly
   482      */
   482      */
   483     public void testAwaitAdvanceInterruptibly_interruptible() throws InterruptedException {
   483     public void testAwaitAdvanceInterruptibly_Interruptible() throws InterruptedException {
   484         final Phaser phaser = new Phaser(1);
   484         final Phaser phaser = new Phaser(1);
   485         final CountDownLatch pleaseInterrupt = new CountDownLatch(2);
   485         final CountDownLatch pleaseInterrupt = new CountDownLatch(2);
   486 
   486 
   487         Thread t1 = newStartedThread(new CheckedRunnable() {
   487         Thread t1 = newStartedThread(new CheckedRunnable() {
   488             public void realRun() {
   488             public void realRun() {
   503 
   503 
   504         Thread t2 = newStartedThread(new CheckedRunnable() {
   504         Thread t2 = newStartedThread(new CheckedRunnable() {
   505             public void realRun() throws TimeoutException {
   505             public void realRun() throws TimeoutException {
   506                 Thread.currentThread().interrupt();
   506                 Thread.currentThread().interrupt();
   507                 try {
   507                 try {
   508                     phaser.awaitAdvanceInterruptibly(0, 2*LONG_DELAY_MS, MILLISECONDS);
   508                     phaser.awaitAdvanceInterruptibly(0, randomTimeout(), randomTimeUnit());
   509                     shouldThrow();
   509                     shouldThrow();
   510                 } catch (InterruptedException success) {}
   510                 } catch (InterruptedException success) {}
   511                 assertFalse(Thread.interrupted());
   511                 assertFalse(Thread.interrupted());
   512 
   512 
   513                 pleaseInterrupt.countDown();
   513                 pleaseInterrupt.countDown();
   514                 try {
   514                 try {
   515                     phaser.awaitAdvanceInterruptibly(0, 2*LONG_DELAY_MS, MILLISECONDS);
   515                     phaser.awaitAdvanceInterruptibly(0, LONGER_DELAY_MS, MILLISECONDS);
   516                     shouldThrow();
   516                     shouldThrow();
   517                 } catch (InterruptedException success) {}
   517                 } catch (InterruptedException success) {}
   518                 assertFalse(Thread.interrupted());
   518                 assertFalse(Thread.interrupted());
   519             }});
   519             }});
   520 
   520 
   521         await(pleaseInterrupt);
   521         await(pleaseInterrupt);
   522         assertState(phaser, 0, 1, 1);
   522         assertState(phaser, 0, 1, 1);
   523         assertThreadBlocks(t1, Thread.State.WAITING);
   523         if (randomBoolean()) assertThreadBlocks(t1, Thread.State.WAITING);
   524         assertThreadBlocks(t2, Thread.State.TIMED_WAITING);
   524         if (randomBoolean()) assertThreadBlocks(t2, Thread.State.TIMED_WAITING);
   525         t1.interrupt();
   525         t1.interrupt();
   526         t2.interrupt();
   526         t2.interrupt();
   527         awaitTermination(t1);
   527         awaitTermination(t1);
   528         awaitTermination(t2);
   528         awaitTermination(t2);
   529         assertState(phaser, 0, 1, 1);
   529         assertState(phaser, 0, 1, 1);