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.29 by jsr166, Tue Dec 1 09:48:12 2009 UTC vs.
Revision 1.36 by jsr166, Mon Oct 11 04:19:16 2010 UTC

# Line 13 | Line 13 | import java.util.concurrent.*;
13  
14   public class DelayQueueTest extends JSR166TestCase {
15      public static void main(String[] args) {
16 <        junit.textui.TestRunner.run (suite());
16 >        junit.textui.TestRunner.run(suite());
17      }
18  
19      public static Test suite() {
# Line 191 | Line 191 | public class DelayQueueTest extends JSR1
191      }
192  
193      /**
194 <     * remainingCapacity does not change when elementa added or removed,
194 >     * remainingCapacity does not change when elements added or removed,
195       * but size does
196       */
197      public void testRemainingCapacity() {
# Line 284 | Line 284 | public class DelayQueueTest extends JSR1
284              shouldThrow();
285          } catch (NullPointerException success) {}
286      }
287 +
288      /**
289       * addAll of a collection with any null elements throws NPE after
290       * possibly adding some elements
# Line 483 | Line 484 | public class DelayQueueTest extends JSR1
484      }
485  
486      /**
487 <     *  timed poll before a delayed offer fails; after offer succeeds;
488 <     *  on interruption throws
487 >     * timed poll before a delayed offer fails; after offer succeeds;
488 >     * on interruption throws
489       */
490      public void testTimedPollWithOffer() throws InterruptedException {
491          final DelayQueue q = new DelayQueue();
492          final PDelay pdelay = new PDelay(0);
493 +        final CheckedBarrier barrier = new CheckedBarrier(2);
494          Thread t = new Thread(new CheckedRunnable() {
495              public void realRun() throws InterruptedException {
496                  assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
497 <                assertSame(pdelay, q.poll(LONG_DELAY_MS, MILLISECONDS));
497 >
498 >                barrier.await();
499 >                assertSame(pdelay, q.poll(MEDIUM_DELAY_MS, MILLISECONDS));
500 >
501 >                Thread.currentThread().interrupt();
502 >                try {
503 >                    q.poll(SHORT_DELAY_MS, MILLISECONDS);
504 >                    shouldThrow();
505 >                } catch (InterruptedException success) {}
506 >
507 >                barrier.await();
508                  try {
509 <                    q.poll(LONG_DELAY_MS, MILLISECONDS);
509 >                    q.poll(MEDIUM_DELAY_MS, MILLISECONDS);
510                      shouldThrow();
511                  } catch (InterruptedException success) {}
512              }});
513  
514          t.start();
515 <        Thread.sleep(SMALL_DELAY_MS);
515 >        barrier.await();
516          assertTrue(q.offer(pdelay, SHORT_DELAY_MS, MILLISECONDS));
517 +        barrier.await();
518 +        sleep(SHORT_DELAY_MS);
519          t.interrupt();
520          t.join();
521      }
# Line 708 | Line 722 | public class DelayQueueTest extends JSR1
722      /**
723       * iterator.remove removes current element
724       */
725 <    public void testIteratorRemove () {
725 >    public void testIteratorRemove() {
726          final DelayQueue q = new DelayQueue();
727          q.add(new PDelay(2));
728          q.add(new PDelay(1));
# Line 774 | Line 788 | public class DelayQueueTest extends JSR1
788          for (int i = 0; i < SIZE; ++i) {
789              NanoDelay e = (NanoDelay)(q.take());
790              long tt = e.getTriggerTime();
791 <            assertTrue(tt <= System.nanoTime());
791 >            assertTrue(tt - System.nanoTime() <= 0);
792              if (i != 0)
793                  assertTrue(tt >= last);
794              last = tt;
# Line 787 | Line 801 | public class DelayQueueTest extends JSR1
801      public void testPeekDelayed() {
802          DelayQueue q = new DelayQueue();
803          q.add(new NanoDelay(Long.MAX_VALUE));
804 <        assert(q.peek() != null);
804 >        assertNotNull(q.peek());
805      }
806  
807  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines