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

Comparing jsr166/src/test/tck/PriorityBlockingQueueTest.java (file contents):
Revision 1.64 by jsr166, Sun May 24 01:42:14 2015 UTC vs.
Revision 1.67 by jsr166, Wed Jun 1 16:08:04 2016 UTC

# Line 200 | Line 200 | public class PriorityBlockingQueueTest e
200          PriorityBlockingQueue q = new PriorityBlockingQueue(1);
201          try {
202              q.offer(new Object());
203            q.offer(new Object());
203              shouldThrow();
204 <        } catch (ClassCastException success) {}
204 >        } catch (ClassCastException success) {
205 >            assertTrue(q.isEmpty());
206 >            assertEquals(0, q.size());
207 >            assertNull(q.poll());
208 >        }
209      }
210  
211      /**
# Line 393 | Line 396 | public class PriorityBlockingQueueTest e
396          final CountDownLatch aboutToWait = new CountDownLatch(1);
397          Thread t = newStartedThread(new CheckedRunnable() {
398              public void realRun() throws InterruptedException {
399 +                long startTime = System.nanoTime();
400                  for (int i = 0; i < SIZE; ++i) {
397                    long t0 = System.nanoTime();
401                      assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS));
399                    assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS);
402                  }
401                long t0 = System.nanoTime();
403                  aboutToWait.countDown();
404                  try {
405                      q.poll(LONG_DELAY_MS, MILLISECONDS);
406                      shouldThrow();
407                  } catch (InterruptedException success) {
408 <                    assertTrue(millisElapsedSince(t0) < MEDIUM_DELAY_MS);
408 >                    assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
409                  }
410              }});
411  
412          aboutToWait.await();
413 <        waitForThreadToEnterWaitState(t, SMALL_DELAY_MS);
413 >        waitForThreadToEnterWaitState(t, LONG_DELAY_MS);
414          t.interrupt();
415 <        awaitTermination(t, MEDIUM_DELAY_MS);
415 >        awaitTermination(t);
416      }
417  
418      /**
# Line 624 | Line 625 | public class PriorityBlockingQueueTest e
625      public void testPollInExecutor() {
626          final PriorityBlockingQueue q = new PriorityBlockingQueue(2);
627          final CheckedBarrier threadsStarted = new CheckedBarrier(2);
628 <        ExecutorService executor = Executors.newFixedThreadPool(2);
629 <        executor.execute(new CheckedRunnable() {
630 <            public void realRun() throws InterruptedException {
631 <                assertNull(q.poll());
632 <                threadsStarted.await();
633 <                assertSame(one, q.poll(LONG_DELAY_MS, MILLISECONDS));
634 <                checkEmpty(q);
635 <            }});
636 <
637 <        executor.execute(new CheckedRunnable() {
638 <            public void realRun() throws InterruptedException {
639 <                threadsStarted.await();
640 <                q.put(one);
641 <            }});
642 <
643 <        joinPool(executor);
628 >        final ExecutorService executor = Executors.newFixedThreadPool(2);
629 >        try (PoolCleaner cleaner = cleaner(executor)) {
630 >            executor.execute(new CheckedRunnable() {
631 >                public void realRun() throws InterruptedException {
632 >                    assertNull(q.poll());
633 >                    threadsStarted.await();
634 >                    assertSame(one, q.poll(LONG_DELAY_MS, MILLISECONDS));
635 >                    checkEmpty(q);
636 >                }});
637 >
638 >            executor.execute(new CheckedRunnable() {
639 >                public void realRun() throws InterruptedException {
640 >                    threadsStarted.await();
641 >                    q.put(one);
642 >                }});
643 >        }
644      }
645  
646      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines