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.23 by jsr166, Sat Nov 21 21:00:34 2009 UTC vs.
Revision 1.28 by jsr166, Tue Dec 1 06:39:23 2009 UTC

# Line 24 | Line 24 | public class DelayQueueTest extends JSR1
24  
25      /**
26       * A delayed implementation for testing.
27 <     * Most  tests use Pseudodelays, where delays are all elapsed
27 >     * Most tests use Pseudodelays, where delays are all elapsed
28       * (so, no blocking solely for delays) but are still ordered
29       */
30      static class PDelay implements Delayed {
# Line 32 | Line 32 | public class DelayQueueTest extends JSR1
32          PDelay(int i) { pseudodelay = Integer.MIN_VALUE + i; }
33          public int compareTo(PDelay y) {
34              int i = pseudodelay;
35 <            int j = ((PDelay)y).pseudodelay;
35 >            int j = y.pseudodelay;
36              if (i < j) return -1;
37              if (i > j) return 1;
38              return 0;
39          }
40  
41          public int compareTo(Delayed y) {
42 <            int i = pseudodelay;
43 <            int j = ((PDelay)y).pseudodelay;
44 <            if (i < j) return -1;
45 <            if (i > j) return 1;
46 <            return 0;
42 >            return compareTo((PDelay)y);
43          }
44  
45          public boolean equals(Object other) {
46 <            return ((PDelay)other).pseudodelay == pseudodelay;
46 >            return equals((PDelay)other);
47          }
48          public boolean equals(PDelay other) {
49 <            return ((PDelay)other).pseudodelay == pseudodelay;
49 >            return other.pseudodelay == pseudodelay;
50          }
51  
52  
# Line 77 | Line 73 | public class DelayQueueTest extends JSR1
73          }
74          public int compareTo(NanoDelay y) {
75              long i = trigger;
76 <            long j = ((NanoDelay)y).trigger;
76 >            long j = y.trigger;
77              if (i < j) return -1;
78              if (i > j) return 1;
79              return 0;
80          }
81  
82          public int compareTo(Delayed y) {
83 <            long i = trigger;
88 <            long j = ((NanoDelay)y).trigger;
89 <            if (i < j) return -1;
90 <            if (i > j) return 1;
91 <            return 0;
83 >            return compareTo((NanoDelay)y);
84          }
85  
86          public boolean equals(Object other) {
87 <            return ((NanoDelay)other).trigger == trigger;
87 >            return equals((NanoDelay)other);
88          }
89          public boolean equals(NanoDelay other) {
90 <            return ((NanoDelay)other).trigger == trigger;
90 >            return other.trigger == trigger;
91          }
92  
93          public long getDelay(TimeUnit unit) {
# Line 375 | Line 367 | public class DelayQueueTest extends JSR1
367              public void realRun() throws InterruptedException {
368                  q.put(new PDelay(0));
369                  q.put(new PDelay(0));
370 <                threadAssertTrue(q.offer(new PDelay(0), SHORT_DELAY_MS, MILLISECONDS));
371 <                threadAssertTrue(q.offer(new PDelay(0), LONG_DELAY_MS, MILLISECONDS));
370 >                assertTrue(q.offer(new PDelay(0), SHORT_DELAY_MS, MILLISECONDS));
371 >                assertTrue(q.offer(new PDelay(0), LONG_DELAY_MS, MILLISECONDS));
372              }});
373  
374          t.start();
# Line 415 | Line 407 | public class DelayQueueTest extends JSR1
407       * Take removes existing elements until empty, then blocks interruptibly
408       */
409      public void testBlockingTake() throws InterruptedException {
410 <        Thread t = new ThreadShouldThrow(InterruptedException.class) {
410 >        final DelayQueue q = populatedQueue(SIZE);
411 >        Thread t = new Thread(new CheckedRunnable() {
412              public void realRun() throws InterruptedException {
420                DelayQueue q = populatedQueue(SIZE);
413                  for (int i = 0; i < SIZE; ++i) {
414 <                    threadAssertEquals(new PDelay(i), ((PDelay)q.take()));
414 >                    assertEquals(new PDelay(i), ((PDelay)q.take()));
415                  }
416 <                q.take();
417 <            }};
416 >                try {
417 >                    q.take();
418 >                    shouldThrow();
419 >                } catch (InterruptedException success) {}
420 >            }});
421  
422          t.start();
423          Thread.sleep(SHORT_DELAY_MS);
# Line 519 | Line 514 | public class DelayQueueTest extends JSR1
514          DelayQueue q = populatedQueue(SIZE);
515          for (int i = 0; i < SIZE; ++i) {
516              assertEquals(new PDelay(i), ((PDelay)q.peek()));
517 <            q.poll();
517 >            assertEquals(new PDelay(i), ((PDelay)q.poll()));
518              if (q.isEmpty())
519                  assertNull(q.peek());
520              else
521 <                assertTrue(i != ((PDelay)q.peek()).intValue());
521 >                assertFalse(new PDelay(i).equals(q.peek()));
522          }
523          assertNull(q.peek());
524      }
# Line 678 | Line 673 | public class DelayQueueTest extends JSR1
673       * toArray(null) throws NPE
674       */
675      public void testToArray_BadArg() {
676 +        DelayQueue q = populatedQueue(SIZE);
677          try {
682            DelayQueue q = populatedQueue(SIZE);
678              Object o[] = q.toArray(null);
679              shouldThrow();
680          } catch (NullPointerException success) {}
# Line 689 | Line 684 | public class DelayQueueTest extends JSR1
684       * toArray with incompatible array type throws CCE
685       */
686      public void testToArray1_BadArg() {
687 +        DelayQueue q = populatedQueue(SIZE);
688          try {
689 <            DelayQueue q = populatedQueue(SIZE);
694 <            Object o[] = q.toArray(new String[10] );
689 >            Object o[] = q.toArray(new String[10]);
690              shouldThrow();
691          } catch (ArrayStoreException success) {}
692      }
# Line 747 | Line 742 | public class DelayQueueTest extends JSR1
742          ExecutorService executor = Executors.newFixedThreadPool(2);
743          executor.execute(new CheckedRunnable() {
744              public void realRun() throws InterruptedException {
745 <                threadAssertNull(q.poll());
746 <                threadAssertTrue(null != q.poll(MEDIUM_DELAY_MS, MILLISECONDS));
747 <                threadAssertTrue(q.isEmpty());
745 >                assertNull(q.poll());
746 >                assertTrue(null != q.poll(MEDIUM_DELAY_MS, MILLISECONDS));
747 >                assertTrue(q.isEmpty());
748              }});
749  
750          executor.execute(new CheckedRunnable() {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines