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.27 by jsr166, Wed Aug 25 01:44:48 2010 UTC

# Line 14 | Line 14 | import java.io.*;
14  
15   public class PriorityBlockingQueueTest extends JSR166TestCase {
16      public static void main(String[] args) {
17 <        junit.textui.TestRunner.run (suite());
17 >        junit.textui.TestRunner.run(suite());
18      }
19      public static Test suite() {
20          return new TestSuite(PriorityBlockingQueueTest.class);
# 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 249 | Line 245 | public class PriorityBlockingQueueTest e
245              shouldThrow();
246          } catch (NullPointerException success) {}
247      }
248 +
249      /**
250       * addAll of a collection with any null elements throws NPE after
251       * possibly adding some elements
# Line 332 | Line 329 | public class PriorityBlockingQueueTest e
329              public void realRun() {
330                  q.put(new Integer(0));
331                  q.put(new Integer(0));
332 <                threadAssertTrue(q.offer(new Integer(0), SHORT_DELAY_MS, MILLISECONDS));
333 <                threadAssertTrue(q.offer(new Integer(0), LONG_DELAY_MS, MILLISECONDS));
332 >                assertTrue(q.offer(new Integer(0), SHORT_DELAY_MS, MILLISECONDS));
333 >                assertTrue(q.offer(new Integer(0), LONG_DELAY_MS, MILLISECONDS));
334              }});
335  
336          t.start();
# Line 348 | Line 345 | public class PriorityBlockingQueueTest e
345      public void testTake() throws InterruptedException {
346          PriorityBlockingQueue q = populatedQueue(SIZE);
347          for (int i = 0; i < SIZE; ++i) {
348 <            assertEquals(i, ((Integer)q.take()).intValue());
348 >            assertEquals(i, q.take());
349          }
350      }
351  
# Line 372 | Line 369 | public class PriorityBlockingQueueTest e
369       * Take removes existing elements until empty, then blocks interruptibly
370       */
371      public void testBlockingTake() throws InterruptedException {
372 <        Thread t = new Thread(new CheckedInterruptedRunnable() {
372 >        final PriorityBlockingQueue q = populatedQueue(SIZE);
373 >        Thread t = new Thread(new CheckedRunnable() {
374              public void realRun() throws InterruptedException {
377                PriorityBlockingQueue q = populatedQueue(SIZE);
375                  for (int i = 0; i < SIZE; ++i) {
376 <                    threadAssertEquals(i, ((Integer)q.take()).intValue());
376 >                    assertEquals(i, q.take());
377                  }
378 <                q.take();
378 >                try {
379 >                    q.take();
380 >                    shouldThrow();
381 >                } catch (InterruptedException success) {}
382              }});
383  
384          t.start();
# Line 394 | Line 394 | public class PriorityBlockingQueueTest e
394      public void testPoll() {
395          PriorityBlockingQueue q = populatedQueue(SIZE);
396          for (int i = 0; i < SIZE; ++i) {
397 <            assertEquals(i, ((Integer)q.poll()).intValue());
397 >            assertEquals(i, q.poll());
398          }
399          assertNull(q.poll());
400      }
# Line 405 | Line 405 | public class PriorityBlockingQueueTest e
405      public void testTimedPoll0() throws InterruptedException {
406          PriorityBlockingQueue q = populatedQueue(SIZE);
407          for (int i = 0; i < SIZE; ++i) {
408 <            assertEquals(i, ((Integer)q.poll(0, MILLISECONDS)).intValue());
408 >            assertEquals(i, q.poll(0, MILLISECONDS));
409          }
410          assertNull(q.poll(0, MILLISECONDS));
411      }
# Line 416 | Line 416 | public class PriorityBlockingQueueTest e
416      public void testTimedPoll() throws InterruptedException {
417          PriorityBlockingQueue q = populatedQueue(SIZE);
418          for (int i = 0; i < SIZE; ++i) {
419 <            assertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, MILLISECONDS)).intValue());
419 >            assertEquals(i, q.poll(SHORT_DELAY_MS, MILLISECONDS));
420          }
421          assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
422      }
# Line 430 | Line 430 | public class PriorityBlockingQueueTest e
430              public void realRun() throws InterruptedException {
431                  PriorityBlockingQueue q = populatedQueue(SIZE);
432                  for (int i = 0; i < SIZE; ++i) {
433 <                    assertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, MILLISECONDS)).intValue());
433 >                    assertEquals(i, q.poll(SHORT_DELAY_MS, MILLISECONDS));
434                  }
435                  try {
436                      q.poll(SMALL_DELAY_MS, MILLISECONDS);
# Line 453 | Line 453 | public class PriorityBlockingQueueTest e
453          Thread t = new Thread(new CheckedRunnable() {
454              public void realRun() throws InterruptedException {
455                  assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
456 <                assertEquals(0, q.poll(MEDIUM_DELAY_MS, MILLISECONDS));
456 >                assertSame(zero, q.poll(MEDIUM_DELAY_MS, MILLISECONDS));
457                  try {
458                      q.poll(LONG_DELAY_MS, MILLISECONDS);
459 <                    threadShouldThrow();
459 >                    shouldThrow();
460                  } catch (InterruptedException success) {}
461              }});
462  
463          t.start();
464          Thread.sleep(SMALL_DELAY_MS);
465 <        assertTrue(q.offer(new Integer(0), SHORT_DELAY_MS, MILLISECONDS));
465 >        assertTrue(q.offer(zero, SHORT_DELAY_MS, MILLISECONDS));
466          t.interrupt();
467          t.join();
468      }
# Line 474 | Line 474 | public class PriorityBlockingQueueTest e
474      public void testPeek() {
475          PriorityBlockingQueue q = populatedQueue(SIZE);
476          for (int i = 0; i < SIZE; ++i) {
477 <            assertEquals(i, ((Integer)q.peek()).intValue());
478 <            q.poll();
477 >            assertEquals(i, q.peek());
478 >            assertEquals(i, q.poll());
479              assertTrue(q.peek() == null ||
480 <                       i != ((Integer)q.peek()).intValue());
480 >                       !q.peek().equals(i));
481          }
482          assertNull(q.peek());
483      }
# Line 488 | Line 488 | public class PriorityBlockingQueueTest e
488      public void testElement() {
489          PriorityBlockingQueue q = populatedQueue(SIZE);
490          for (int i = 0; i < SIZE; ++i) {
491 <            assertEquals(i, ((Integer)q.element()).intValue());
492 <            q.poll();
491 >            assertEquals(i, q.element());
492 >            assertEquals(i, q.poll());
493          }
494          try {
495              q.element();
# Line 503 | Line 503 | public class PriorityBlockingQueueTest e
503      public void testRemove() {
504          PriorityBlockingQueue q = populatedQueue(SIZE);
505          for (int i = 0; i < SIZE; ++i) {
506 <            assertEquals(i, ((Integer)q.remove()).intValue());
506 >            assertEquals(i, q.remove());
507          }
508          try {
509              q.remove();
# Line 629 | Line 629 | public class PriorityBlockingQueueTest e
629       * toArray(null) throws NPE
630       */
631      public void testToArray_BadArg() {
632 +        PriorityBlockingQueue q = populatedQueue(SIZE);
633          try {
633            PriorityBlockingQueue q = populatedQueue(SIZE);
634              Object o[] = q.toArray(null);
635              shouldThrow();
636          } catch (NullPointerException success) {}
# Line 640 | Line 640 | public class PriorityBlockingQueueTest e
640       * toArray with incompatible array type throws CCE
641       */
642      public void testToArray1_BadArg() {
643 +        PriorityBlockingQueue q = populatedQueue(SIZE);
644          try {
645 <            PriorityBlockingQueue q = populatedQueue(SIZE);
645 <            Object o[] = q.toArray(new String[10] );
645 >            Object o[] = q.toArray(new String[10]);
646              shouldThrow();
647          } catch (ArrayStoreException success) {}
648      }
# Line 664 | Line 664 | public class PriorityBlockingQueueTest e
664      /**
665       * iterator.remove removes current element
666       */
667 <    public void testIteratorRemove () {
667 >    public void testIteratorRemove() {
668          final PriorityBlockingQueue q = new PriorityBlockingQueue(3);
669          q.add(new Integer(2));
670          q.add(new Integer(1));
# Line 700 | Line 700 | public class PriorityBlockingQueueTest e
700          ExecutorService executor = Executors.newFixedThreadPool(2);
701          executor.execute(new CheckedRunnable() {
702              public void realRun() throws InterruptedException {
703 <                threadAssertNull(q.poll());
704 <                threadAssertTrue(null != q.poll(MEDIUM_DELAY_MS, MILLISECONDS));
705 <                threadAssertTrue(q.isEmpty());
703 >                assertNull(q.poll());
704 >                assertSame(one, q.poll(MEDIUM_DELAY_MS, MILLISECONDS));
705 >                assertTrue(q.isEmpty());
706              }});
707  
708          executor.execute(new CheckedRunnable() {
709              public void realRun() throws InterruptedException {
710                  Thread.sleep(SMALL_DELAY_MS);
711 <                q.put(new Integer(1));
711 >                q.put(one);
712              }});
713  
714          joinPool(executor);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines