test/jdk/java/util/concurrent/tck/LinkedTransferQueueTest.java
changeset 58138 1e4270f875ee
parent 50764 5637aca18f1d
equal deleted inserted replaced
58137:6a556bcd94fc 58138:1e4270f875ee
   252                 } catch (InterruptedException success) {}
   252                 } catch (InterruptedException success) {}
   253                 assertFalse(Thread.interrupted());
   253                 assertFalse(Thread.interrupted());
   254             }});
   254             }});
   255 
   255 
   256         await(pleaseInterrupt);
   256         await(pleaseInterrupt);
   257         assertThreadBlocks(t, Thread.State.WAITING);
   257         if (randomBoolean()) assertThreadBlocks(t, Thread.State.WAITING);
   258         t.interrupt();
   258         t.interrupt();
   259         awaitTermination(t);
   259         awaitTermination(t);
   260     }
   260     }
   261 
   261 
   262     /**
   262     /**
   306     public void testInterruptedTimedPoll() throws InterruptedException {
   306     public void testInterruptedTimedPoll() throws InterruptedException {
   307         final BlockingQueue<Integer> q = populatedQueue(SIZE);
   307         final BlockingQueue<Integer> q = populatedQueue(SIZE);
   308         final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
   308         final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
   309         Thread t = newStartedThread(new CheckedRunnable() {
   309         Thread t = newStartedThread(new CheckedRunnable() {
   310             public void realRun() throws InterruptedException {
   310             public void realRun() throws InterruptedException {
   311                 long startTime = System.nanoTime();
       
   312                 for (int i = 0; i < SIZE; i++)
   311                 for (int i = 0; i < SIZE; i++)
   313                     assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS));
   312                     assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS));
   314 
   313 
   315                 Thread.currentThread().interrupt();
   314                 Thread.currentThread().interrupt();
   316                 try {
   315                 try {
   317                     q.poll(LONG_DELAY_MS, MILLISECONDS);
   316                     q.poll(randomTimeout(), randomTimeUnit());
   318                     shouldThrow();
   317                     shouldThrow();
   319                 } catch (InterruptedException success) {}
   318                 } catch (InterruptedException success) {}
   320                 assertFalse(Thread.interrupted());
   319                 assertFalse(Thread.interrupted());
   321 
   320 
   322                 pleaseInterrupt.countDown();
   321                 pleaseInterrupt.countDown();
   323                 try {
   322                 try {
   324                     q.poll(LONG_DELAY_MS, MILLISECONDS);
   323                     q.poll(LONGER_DELAY_MS, MILLISECONDS);
   325                     shouldThrow();
   324                     shouldThrow();
   326                 } catch (InterruptedException success) {}
   325                 } catch (InterruptedException success) {}
   327                 assertFalse(Thread.interrupted());
   326                 assertFalse(Thread.interrupted());
   328 
       
   329                 assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
       
   330             }});
   327             }});
   331 
   328 
   332         await(pleaseInterrupt);
   329         await(pleaseInterrupt);
   333         assertThreadBlocks(t, Thread.State.TIMED_WAITING);
   330         if (randomBoolean()) assertThreadBlocks(t, Thread.State.TIMED_WAITING);
   334         t.interrupt();
   331         t.interrupt();
   335         awaitTermination(t);
   332         awaitTermination(t);
   336         checkEmpty(q);
   333         checkEmpty(q);
   337     }
   334     }
   338 
   335 
   342      */
   339      */
   343     public void testTimedPollAfterInterrupt() throws InterruptedException {
   340     public void testTimedPollAfterInterrupt() throws InterruptedException {
   344         final BlockingQueue<Integer> q = populatedQueue(SIZE);
   341         final BlockingQueue<Integer> q = populatedQueue(SIZE);
   345         Thread t = newStartedThread(new CheckedRunnable() {
   342         Thread t = newStartedThread(new CheckedRunnable() {
   346             public void realRun() throws InterruptedException {
   343             public void realRun() throws InterruptedException {
   347                 long startTime = System.nanoTime();
       
   348                 Thread.currentThread().interrupt();
   344                 Thread.currentThread().interrupt();
   349                 for (int i = 0; i < SIZE; ++i)
   345                 for (int i = 0; i < SIZE; ++i)
   350                     assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS));
   346                     assertEquals(i, (int) q.poll(randomTimeout(), randomTimeUnit()));
   351                 try {
   347                 try {
   352                     q.poll(LONG_DELAY_MS, MILLISECONDS);
   348                     q.poll(randomTimeout(), randomTimeUnit());
   353                     shouldThrow();
   349                     shouldThrow();
   354                 } catch (InterruptedException success) {}
   350                 } catch (InterruptedException success) {}
   355                 assertFalse(Thread.interrupted());
   351                 assertFalse(Thread.interrupted());
   356                 assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
       
   357             }});
   352             }});
   358 
   353 
   359         awaitTermination(t);
   354         awaitTermination(t);
   360         checkEmpty(q);
   355         checkEmpty(q);
   361     }
   356     }
   980         final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
   975         final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
   981         assertTrue(q.isEmpty());
   976         assertTrue(q.isEmpty());
   982 
   977 
   983         Thread t = newStartedThread(new CheckedRunnable() {
   978         Thread t = newStartedThread(new CheckedRunnable() {
   984             public void realRun() throws InterruptedException {
   979             public void realRun() throws InterruptedException {
   985                 long startTime = System.nanoTime();
       
   986                 Thread.currentThread().interrupt();
   980                 Thread.currentThread().interrupt();
   987                 try {
   981                 try {
   988                     q.tryTransfer(new Object(), LONG_DELAY_MS, MILLISECONDS);
   982                     q.tryTransfer(new Object(), randomTimeout(), randomTimeUnit());
   989                     shouldThrow();
   983                     shouldThrow();
   990                 } catch (InterruptedException success) {}
   984                 } catch (InterruptedException success) {}
   991                 assertFalse(Thread.interrupted());
   985                 assertFalse(Thread.interrupted());
   992 
   986 
   993                 pleaseInterrupt.countDown();
   987                 pleaseInterrupt.countDown();
   994                 try {
   988                 try {
   995                     q.tryTransfer(new Object(), LONG_DELAY_MS, MILLISECONDS);
   989                     q.tryTransfer(new Object(), LONGER_DELAY_MS, MILLISECONDS);
   996                     shouldThrow();
   990                     shouldThrow();
   997                 } catch (InterruptedException success) {}
   991                 } catch (InterruptedException success) {}
   998                 assertFalse(Thread.interrupted());
   992                 assertFalse(Thread.interrupted());
   999                 assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
       
  1000             }});
   993             }});
  1001 
   994 
  1002         await(pleaseInterrupt);
   995         await(pleaseInterrupt);
  1003         assertThreadBlocks(t, Thread.State.TIMED_WAITING);
   996         if (randomBoolean()) assertThreadBlocks(t, Thread.State.TIMED_WAITING);
  1004         t.interrupt();
   997         t.interrupt();
  1005         awaitTermination(t);
   998         awaitTermination(t);
  1006         checkEmpty(q);
   999         checkEmpty(q);
  1007     }
  1000     }
  1008 
  1001