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.20 by jsr166, Sat Nov 21 19:11:53 2009 UTC vs.
Revision 1.24 by jsr166, Sun Nov 22 18:57:17 2009 UTC

# Line 25 | Line 25 | public class PriorityBlockingQueueTest e
25      /** Sample Comparator */
26      static class MyReverseComparator implements Comparator {
27          public int compare(Object x, Object y) {
28 <            int i = ((Integer)x).intValue();
29 <            int j = ((Integer)y).intValue();
30 <            if (i < j) return 1;
31 <            if (i > j) return -1;
32 <            return 0;
28 >            return ((Comparable)y).compareTo(x);
29          }
30      }
31  
# Line 332 | Line 328 | public class PriorityBlockingQueueTest e
328              public void realRun() {
329                  q.put(new Integer(0));
330                  q.put(new Integer(0));
331 <                threadAssertTrue(q.offer(new Integer(0), SHORT_DELAY_MS, MILLISECONDS));
332 <                threadAssertTrue(q.offer(new Integer(0), LONG_DELAY_MS, MILLISECONDS));
331 >                assertTrue(q.offer(new Integer(0), SHORT_DELAY_MS, MILLISECONDS));
332 >                assertTrue(q.offer(new Integer(0), LONG_DELAY_MS, MILLISECONDS));
333              }});
334  
335          t.start();
# Line 348 | Line 344 | public class PriorityBlockingQueueTest e
344      public void testTake() throws InterruptedException {
345          PriorityBlockingQueue q = populatedQueue(SIZE);
346          for (int i = 0; i < SIZE; ++i) {
347 <            assertEquals(i, ((Integer)q.take()).intValue());
347 >            assertEquals(i, q.take());
348          }
349      }
350  
# Line 372 | Line 368 | public class PriorityBlockingQueueTest e
368       * Take removes existing elements until empty, then blocks interruptibly
369       */
370      public void testBlockingTake() throws InterruptedException {
371 <        Thread t = new Thread(new CheckedInterruptedRunnable() {
371 >        final PriorityBlockingQueue q = populatedQueue(SIZE);
372 >        Thread t = new Thread(new CheckedRunnable() {
373              public void realRun() throws InterruptedException {
377                PriorityBlockingQueue q = populatedQueue(SIZE);
374                  for (int i = 0; i < SIZE; ++i) {
375 <                    threadAssertEquals(i, ((Integer)q.take()).intValue());
375 >                    assertEquals(i, q.take());
376                  }
377 <                q.take();
377 >                try {
378 >                    q.take();
379 >                    shouldThrow();
380 >                } catch (InterruptedException success) {}
381              }});
382  
383          t.start();
# Line 394 | Line 393 | public class PriorityBlockingQueueTest e
393      public void testPoll() {
394          PriorityBlockingQueue q = populatedQueue(SIZE);
395          for (int i = 0; i < SIZE; ++i) {
396 <            assertEquals(i, ((Integer)q.poll()).intValue());
396 >            assertEquals(i, q.poll());
397          }
398          assertNull(q.poll());
399      }
# Line 405 | Line 404 | public class PriorityBlockingQueueTest e
404      public void testTimedPoll0() throws InterruptedException {
405          PriorityBlockingQueue q = populatedQueue(SIZE);
406          for (int i = 0; i < SIZE; ++i) {
407 <            assertEquals(i, ((Integer)q.poll(0, MILLISECONDS)).intValue());
407 >            assertEquals(i, q.poll(0, MILLISECONDS));
408          }
409          assertNull(q.poll(0, MILLISECONDS));
410      }
# Line 416 | Line 415 | public class PriorityBlockingQueueTest e
415      public void testTimedPoll() throws InterruptedException {
416          PriorityBlockingQueue q = populatedQueue(SIZE);
417          for (int i = 0; i < SIZE; ++i) {
418 <            assertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, MILLISECONDS)).intValue());
418 >            assertEquals(i, q.poll(SHORT_DELAY_MS, MILLISECONDS));
419          }
420          assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
421      }
# Line 430 | Line 429 | public class PriorityBlockingQueueTest e
429              public void realRun() throws InterruptedException {
430                  PriorityBlockingQueue q = populatedQueue(SIZE);
431                  for (int i = 0; i < SIZE; ++i) {
432 <                    assertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, MILLISECONDS)).intValue());
432 >                    assertEquals(i, q.poll(SHORT_DELAY_MS, MILLISECONDS));
433                  }
434                  try {
435                      q.poll(SMALL_DELAY_MS, MILLISECONDS);
# Line 453 | Line 452 | public class PriorityBlockingQueueTest e
452          Thread t = new Thread(new CheckedRunnable() {
453              public void realRun() throws InterruptedException {
454                  assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
455 <                assertEquals(0, q.poll(MEDIUM_DELAY_MS, MILLISECONDS));
455 >                assertSame(zero, q.poll(MEDIUM_DELAY_MS, MILLISECONDS));
456                  try {
457                      q.poll(LONG_DELAY_MS, MILLISECONDS);
458 <                    threadShouldThrow();
458 >                    shouldThrow();
459                  } catch (InterruptedException success) {}
460              }});
461  
462          t.start();
463          Thread.sleep(SMALL_DELAY_MS);
464 <        assertTrue(q.offer(new Integer(0), SHORT_DELAY_MS, MILLISECONDS));
464 >        assertTrue(q.offer(zero, SHORT_DELAY_MS, MILLISECONDS));
465          t.interrupt();
466          t.join();
467      }
# Line 474 | Line 473 | public class PriorityBlockingQueueTest e
473      public void testPeek() {
474          PriorityBlockingQueue q = populatedQueue(SIZE);
475          for (int i = 0; i < SIZE; ++i) {
476 <            assertEquals(i, ((Integer)q.peek()).intValue());
477 <            q.poll();
476 >            assertEquals(i, q.peek());
477 >            assertEquals(i, q.poll());
478              assertTrue(q.peek() == null ||
479 <                       i != ((Integer)q.peek()).intValue());
479 >                       !q.peek().equals(i));
480          }
481          assertNull(q.peek());
482      }
# Line 488 | Line 487 | public class PriorityBlockingQueueTest e
487      public void testElement() {
488          PriorityBlockingQueue q = populatedQueue(SIZE);
489          for (int i = 0; i < SIZE; ++i) {
490 <            assertEquals(i, ((Integer)q.element()).intValue());
491 <            q.poll();
490 >            assertEquals(i, q.element());
491 >            assertEquals(i, q.poll());
492          }
493          try {
494              q.element();
# Line 503 | Line 502 | public class PriorityBlockingQueueTest e
502      public void testRemove() {
503          PriorityBlockingQueue q = populatedQueue(SIZE);
504          for (int i = 0; i < SIZE; ++i) {
505 <            assertEquals(i, ((Integer)q.remove()).intValue());
505 >            assertEquals(i, q.remove());
506          }
507          try {
508              q.remove();
# Line 629 | Line 628 | public class PriorityBlockingQueueTest e
628       * toArray(null) throws NPE
629       */
630      public void testToArray_BadArg() {
631 +        PriorityBlockingQueue q = populatedQueue(SIZE);
632          try {
633            PriorityBlockingQueue q = populatedQueue(SIZE);
633              Object o[] = q.toArray(null);
634              shouldThrow();
635          } catch (NullPointerException success) {}
# Line 640 | Line 639 | public class PriorityBlockingQueueTest e
639       * toArray with incompatible array type throws CCE
640       */
641      public void testToArray1_BadArg() {
642 +        PriorityBlockingQueue q = populatedQueue(SIZE);
643          try {
644 <            PriorityBlockingQueue q = populatedQueue(SIZE);
645 <            Object o[] = q.toArray(new String[10] );
644 >            Object o[] = q.toArray(new String[10]);
645              shouldThrow();
646          } catch (ArrayStoreException success) {}
647      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines