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

Comparing jsr166/src/test/tck/DelayQueueTest.java (file contents):
Revision 1.74 by jsr166, Sun May 24 01:42:14 2015 UTC vs.
Revision 1.77 by jsr166, Thu Sep 15 17:07:16 2016 UTC

# Line 94 | Line 94 | public class DelayQueueTest extends JSR1
94          }
95  
96          public boolean equals(Object other) {
97 <            return equals((NanoDelay)other);
98 <        }
99 <        public boolean equals(NanoDelay other) {
100 <            return other.trigger == trigger;
97 >            return (other instanceof NanoDelay) &&
98 >                this.trigger == ((NanoDelay)other).trigger;
99          }
100  
101          // suppress [overrides] javac warning
# Line 412 | Line 410 | public class DelayQueueTest extends JSR1
410       */
411      public void testInterruptedTimedPoll() throws InterruptedException {
412          final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
413 +        final DelayQueue q = populatedQueue(SIZE);
414          Thread t = newStartedThread(new CheckedRunnable() {
415              public void realRun() throws InterruptedException {
416 <                DelayQueue q = populatedQueue(SIZE);
416 >                long startTime = System.nanoTime();
417                  for (int i = 0; i < SIZE; ++i) {
418 <                    assertEquals(new PDelay(i), ((PDelay)q.poll(SHORT_DELAY_MS, MILLISECONDS)));
418 >                    assertEquals(new PDelay(i),
419 >                                 ((PDelay)q.poll(LONG_DELAY_MS, MILLISECONDS)));
420                  }
421  
422                  Thread.currentThread().interrupt();
# Line 432 | Line 432 | public class DelayQueueTest extends JSR1
432                      shouldThrow();
433                  } catch (InterruptedException success) {}
434                  assertFalse(Thread.interrupted());
435 +                assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
436              }});
437  
438          await(pleaseInterrupt);
439          assertThreadStaysAlive(t);
440          t.interrupt();
441          awaitTermination(t);
442 +        checkEmpty(q);
443      }
444  
445      /**
# Line 653 | Line 655 | public class DelayQueueTest extends JSR1
655      public void testPollInExecutor() {
656          final DelayQueue q = new DelayQueue();
657          final CheckedBarrier threadsStarted = new CheckedBarrier(2);
658 <        ExecutorService executor = Executors.newFixedThreadPool(2);
659 <        executor.execute(new CheckedRunnable() {
660 <            public void realRun() throws InterruptedException {
661 <                assertNull(q.poll());
662 <                threadsStarted.await();
663 <                assertNotNull(q.poll(LONG_DELAY_MS, MILLISECONDS));
664 <                checkEmpty(q);
665 <            }});
666 <
667 <        executor.execute(new CheckedRunnable() {
668 <            public void realRun() throws InterruptedException {
669 <                threadsStarted.await();
670 <                q.put(new PDelay(1));
671 <            }});
672 <
673 <        joinPool(executor);
658 >        final ExecutorService executor = Executors.newFixedThreadPool(2);
659 >        try (PoolCleaner cleaner = cleaner(executor)) {
660 >            executor.execute(new CheckedRunnable() {
661 >                public void realRun() throws InterruptedException {
662 >                    assertNull(q.poll());
663 >                    threadsStarted.await();
664 >                    assertNotNull(q.poll(LONG_DELAY_MS, MILLISECONDS));
665 >                    checkEmpty(q);
666 >                }});
667 >
668 >            executor.execute(new CheckedRunnable() {
669 >                public void realRun() throws InterruptedException {
670 >                    threadsStarted.await();
671 >                    q.put(new PDelay(1));
672 >                }});
673 >        }
674      }
675  
676      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines