test/jdk/java/util/concurrent/tck/BlockingQueueTest.java
changeset 58138 1e4270f875ee
parent 50697 3ef0862bbb3d
equal deleted inserted replaced
58137:6a556bcd94fc 58138:1e4270f875ee
   251 
   251 
   252                 assertSame(zero, q.poll(LONG_DELAY_MS, MILLISECONDS));
   252                 assertSame(zero, q.poll(LONG_DELAY_MS, MILLISECONDS));
   253 
   253 
   254                 Thread.currentThread().interrupt();
   254                 Thread.currentThread().interrupt();
   255                 try {
   255                 try {
   256                     q.poll(LONG_DELAY_MS, MILLISECONDS);
   256                     q.poll(randomTimeout(), randomTimeUnit());
   257                     shouldThrow();
   257                     shouldThrow();
   258                 } catch (InterruptedException success) {}
   258                 } catch (InterruptedException success) {}
   259                 assertFalse(Thread.interrupted());
   259                 assertFalse(Thread.interrupted());
   260 
   260 
   261                 barrier.await();
   261                 barrier.await();
   272         long startTime = System.nanoTime();
   272         long startTime = System.nanoTime();
   273         assertTrue(q.offer(zero, LONG_DELAY_MS, MILLISECONDS));
   273         assertTrue(q.offer(zero, LONG_DELAY_MS, MILLISECONDS));
   274         assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
   274         assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
   275 
   275 
   276         barrier.await();
   276         barrier.await();
   277         assertThreadBlocks(t, Thread.State.TIMED_WAITING);
   277         if (randomBoolean()) assertThreadBlocks(t, Thread.State.TIMED_WAITING);
   278         t.interrupt();
   278         t.interrupt();
   279         awaitTermination(t);
   279         awaitTermination(t);
   280     }
   280     }
   281 
   281 
   282     /**
   282     /**
   294                 } catch (InterruptedException success) {}
   294                 } catch (InterruptedException success) {}
   295                 assertFalse(Thread.interrupted());
   295                 assertFalse(Thread.interrupted());
   296             }});
   296             }});
   297 
   297 
   298         await(threadStarted);
   298         await(threadStarted);
   299         assertThreadBlocks(t, Thread.State.WAITING);
   299         if (randomBoolean()) assertThreadBlocks(t, Thread.State.WAITING);
   300         t.interrupt();
   300         t.interrupt();
   301         awaitTermination(t);
   301         awaitTermination(t);
   302     }
   302     }
   303 
   303 
   304     /**
   304     /**
   323     /**
   323     /**
   324      * timed poll() blocks interruptibly when empty
   324      * timed poll() blocks interruptibly when empty
   325      */
   325      */
   326     public void testTimedPollFromEmptyBlocksInterruptibly() {
   326     public void testTimedPollFromEmptyBlocksInterruptibly() {
   327         final BlockingQueue q = emptyCollection();
   327         final BlockingQueue q = emptyCollection();
   328         final CountDownLatch threadStarted = new CountDownLatch(1);
   328         final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
   329         Thread t = newStartedThread(new CheckedRunnable() {
   329         Thread t = newStartedThread(new CheckedRunnable() {
   330             public void realRun() {
   330             public void realRun() {
   331                 threadStarted.countDown();
   331                 pleaseInterrupt.countDown();
   332                 try {
   332                 try {
   333                     q.poll(2 * LONG_DELAY_MS, MILLISECONDS);
   333                     q.poll(LONGER_DELAY_MS, MILLISECONDS);
   334                     shouldThrow();
   334                     shouldThrow();
   335                 } catch (InterruptedException success) {}
   335                 } catch (InterruptedException success) {}
   336                 assertFalse(Thread.interrupted());
   336                 assertFalse(Thread.interrupted());
   337             }});
   337             }});
   338 
   338 
   339         await(threadStarted);
   339         await(pleaseInterrupt);
   340         assertThreadBlocks(t, Thread.State.TIMED_WAITING);
   340         if (randomBoolean()) assertThreadBlocks(t, Thread.State.TIMED_WAITING);
   341         t.interrupt();
   341         t.interrupt();
   342         awaitTermination(t);
   342         awaitTermination(t);
   343     }
   343     }
   344 
   344 
   345     /**
   345     /**
   350         final BlockingQueue q = emptyCollection();
   350         final BlockingQueue q = emptyCollection();
   351         Thread t = newStartedThread(new CheckedRunnable() {
   351         Thread t = newStartedThread(new CheckedRunnable() {
   352             public void realRun() {
   352             public void realRun() {
   353                 Thread.currentThread().interrupt();
   353                 Thread.currentThread().interrupt();
   354                 try {
   354                 try {
   355                     q.poll(2 * LONG_DELAY_MS, MILLISECONDS);
   355                     q.poll(LONGER_DELAY_MS, MILLISECONDS);
   356                     shouldThrow();
   356                     shouldThrow();
   357                 } catch (InterruptedException success) {}
   357                 } catch (InterruptedException success) {}
   358                 assertFalse(Thread.interrupted());
   358                 assertFalse(Thread.interrupted());
   359             }});
   359             }});
   360 
   360