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.20 by jsr166, Sat Nov 21 09:28:16 2009 UTC vs.
Revision 1.26 by jsr166, Sun Nov 22 18:57:17 2009 UTC

# Line 175 | Line 175 | public class DelayQueueTest extends JSR1
175       * Queue contains all elements of collection used to initialize
176       */
177      public void testConstructor6() {
178 <        try {
179 <            PDelay[] ints = new PDelay[SIZE];
180 <            for (int i = 0; i < SIZE; ++i)
181 <                ints[i] = new PDelay(i);
182 <            DelayQueue q = new DelayQueue(Arrays.asList(ints));
183 <            for (int i = 0; i < SIZE; ++i)
184 <                assertEquals(ints[i], q.poll());
185 <        }
186 <        finally {}
178 >        PDelay[] ints = new PDelay[SIZE];
179 >        for (int i = 0; i < SIZE; ++i)
180 >            ints[i] = new PDelay(i);
181 >        DelayQueue q = new DelayQueue(Arrays.asList(ints));
182 >        for (int i = 0; i < SIZE; ++i)
183 >            assertEquals(ints[i], q.poll());
184      }
185  
186      /**
# Line 314 | Line 311 | public class DelayQueueTest extends JSR1
311       * Queue contains all elements of successful addAll
312       */
313      public void testAddAll5() {
314 <        try {
315 <            PDelay[] empty = new PDelay[0];
316 <            PDelay[] ints = new PDelay[SIZE];
317 <            for (int i = SIZE-1; i >= 0; --i)
318 <                ints[i] = new PDelay(i);
319 <            DelayQueue q = new DelayQueue();
320 <            assertFalse(q.addAll(Arrays.asList(empty)));
321 <            assertTrue(q.addAll(Arrays.asList(ints)));
322 <            for (int i = 0; i < SIZE; ++i)
326 <                assertEquals(ints[i], q.poll());
327 <        }
328 <        finally {}
314 >        PDelay[] empty = new PDelay[0];
315 >        PDelay[] ints = new PDelay[SIZE];
316 >        for (int i = SIZE-1; i >= 0; --i)
317 >            ints[i] = new PDelay(i);
318 >        DelayQueue q = new DelayQueue();
319 >        assertFalse(q.addAll(Arrays.asList(empty)));
320 >        assertTrue(q.addAll(Arrays.asList(ints)));
321 >        for (int i = 0; i < SIZE; ++i)
322 >            assertEquals(ints[i], q.poll());
323      }
324  
325      /**
# Line 381 | Line 375 | public class DelayQueueTest extends JSR1
375              public void realRun() throws InterruptedException {
376                  q.put(new PDelay(0));
377                  q.put(new PDelay(0));
378 <                threadAssertTrue(q.offer(new PDelay(0), SHORT_DELAY_MS, MILLISECONDS));
379 <                threadAssertTrue(q.offer(new PDelay(0), LONG_DELAY_MS, MILLISECONDS));
378 >                assertTrue(q.offer(new PDelay(0), SHORT_DELAY_MS, MILLISECONDS));
379 >                assertTrue(q.offer(new PDelay(0), LONG_DELAY_MS, MILLISECONDS));
380              }});
381  
382          t.start();
# Line 421 | Line 415 | public class DelayQueueTest extends JSR1
415       * Take removes existing elements until empty, then blocks interruptibly
416       */
417      public void testBlockingTake() throws InterruptedException {
418 <        Thread t = new ThreadShouldThrow(InterruptedException.class) {
418 >        final DelayQueue q = populatedQueue(SIZE);
419 >        Thread t = new Thread(new CheckedRunnable() {
420              public void realRun() throws InterruptedException {
426                DelayQueue q = populatedQueue(SIZE);
421                  for (int i = 0; i < SIZE; ++i) {
422 <                    threadAssertEquals(new PDelay(i), ((PDelay)q.take()));
422 >                    assertEquals(new PDelay(i), ((PDelay)q.take()));
423                  }
424 <                q.take();
425 <            }};
424 >                try {
425 >                    q.take();
426 >                    shouldThrow();
427 >                } catch (InterruptedException success) {}
428 >            }});
429  
430          t.start();
431          Thread.sleep(SHORT_DELAY_MS);
# Line 482 | Line 479 | public class DelayQueueTest extends JSR1
479                      assertEquals(new PDelay(i), ((PDelay)q.poll(SHORT_DELAY_MS, MILLISECONDS)));
480                  }
481                  try {
482 <                    q.poll(LONG_DELAY_MS, MILLISECONDS);
482 >                    q.poll(SMALL_DELAY_MS, MILLISECONDS);
483                      shouldThrow();
484                  } catch (InterruptedException success) {}
485              }});
# Line 499 | Line 496 | public class DelayQueueTest extends JSR1
496       */
497      public void testTimedPollWithOffer() throws InterruptedException {
498          final DelayQueue q = new DelayQueue();
499 +        final PDelay pdelay = new PDelay(0);
500          Thread t = new Thread(new CheckedRunnable() {
501              public void realRun() throws InterruptedException {
502                  assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
503 <                q.poll(LONG_DELAY_MS, MILLISECONDS);
503 >                assertSame(pdelay, q.poll(LONG_DELAY_MS, MILLISECONDS));
504                  try {
505                      q.poll(LONG_DELAY_MS, MILLISECONDS);
506                      shouldThrow();
# Line 511 | Line 509 | public class DelayQueueTest extends JSR1
509  
510          t.start();
511          Thread.sleep(SMALL_DELAY_MS);
512 <        assertTrue(q.offer(new PDelay(0), SHORT_DELAY_MS, MILLISECONDS));
512 >        assertTrue(q.offer(pdelay, SHORT_DELAY_MS, MILLISECONDS));
513          t.interrupt();
514          t.join();
515      }
# Line 524 | Line 522 | public class DelayQueueTest extends JSR1
522          DelayQueue q = populatedQueue(SIZE);
523          for (int i = 0; i < SIZE; ++i) {
524              assertEquals(new PDelay(i), ((PDelay)q.peek()));
525 <            q.poll();
525 >            assertEquals(new PDelay(i), ((PDelay)q.poll()));
526              if (q.isEmpty())
527                  assertNull(q.peek());
528              else
529 <                assertTrue(i != ((PDelay)q.peek()).intValue());
529 >                assertFalse(new PDelay(i).equals(q.peek()));
530          }
531          assertNull(q.peek());
532      }
# Line 683 | Line 681 | public class DelayQueueTest extends JSR1
681       * toArray(null) throws NPE
682       */
683      public void testToArray_BadArg() {
684 +        DelayQueue q = populatedQueue(SIZE);
685          try {
687            DelayQueue q = populatedQueue(SIZE);
686              Object o[] = q.toArray(null);
687              shouldThrow();
688          } catch (NullPointerException success) {}
# Line 694 | Line 692 | public class DelayQueueTest extends JSR1
692       * toArray with incompatible array type throws CCE
693       */
694      public void testToArray1_BadArg() {
695 +        DelayQueue q = populatedQueue(SIZE);
696          try {
697 <            DelayQueue q = populatedQueue(SIZE);
699 <            Object o[] = q.toArray(new String[10] );
697 >            Object o[] = q.toArray(new String[10]);
698              shouldThrow();
699          } catch (ArrayStoreException success) {}
700      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines