ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/ArrayBlockingQueueTest.java
(Generate patch)

Comparing jsr166/src/test/tck/ArrayBlockingQueueTest.java (file contents):
Revision 1.33 by jsr166, Sat Oct 9 19:30:34 2010 UTC vs.
Revision 1.41 by jsr166, Fri Nov 5 00:17:22 2010 UTC

# Line 41 | Line 41 | public class ArrayBlockingQueueTest exte
41       * Create a queue of given size containing consecutive
42       * Integers 0 ... n.
43       */
44 <    private ArrayBlockingQueue populatedQueue(int n) {
45 <        ArrayBlockingQueue q = new ArrayBlockingQueue(n);
44 >    private ArrayBlockingQueue<Integer> populatedQueue(int n) {
45 >        ArrayBlockingQueue<Integer> q = new ArrayBlockingQueue<Integer>(n);
46          assertTrue(q.isEmpty());
47          for (int i = 0; i < n; i++)
48              assertTrue(q.offer(new Integer(i)));
# Line 393 | Line 393 | public class ArrayBlockingQueueTest exte
393      }
394  
395      /**
396     * take blocks interruptibly when empty
397     */
398    public void testTakeFromEmpty() throws InterruptedException {
399        final ArrayBlockingQueue q = new ArrayBlockingQueue(2);
400        Thread t = new ThreadShouldThrow(InterruptedException.class) {
401            public void realRun() throws InterruptedException {
402                q.take();
403            }};
404
405        t.start();
406        Thread.sleep(SHORT_DELAY_MS);
407        t.interrupt();
408        t.join();
409    }
410
411    /**
396       * Take removes existing elements until empty, then blocks interruptibly
397       */
398      public void testBlockingTake() throws InterruptedException {
# Line 443 | Line 427 | public class ArrayBlockingQueueTest exte
427      }
428  
429      /**
430 <     * timed pool with zero timeout succeeds when non-empty, else times out
430 >     * timed poll with zero timeout succeeds when non-empty, else times out
431       */
432      public void testTimedPoll0() throws InterruptedException {
433          ArrayBlockingQueue q = populatedQueue(SIZE);
# Line 454 | Line 438 | public class ArrayBlockingQueueTest exte
438      }
439  
440      /**
441 <     * timed pool with nonzero timeout succeeds when non-empty, else times out
441 >     * timed poll with nonzero timeout succeeds when non-empty, else times out
442       */
443      public void testTimedPoll() throws InterruptedException {
444          ArrayBlockingQueue q = populatedQueue(SIZE);
# Line 623 | Line 607 | public class ArrayBlockingQueueTest exte
607      }
608  
609      /**
610 <     * toArray contains all elements
610 >     * toArray contains all elements in FIFO order
611       */
612 <    public void testToArray() throws InterruptedException {
612 >    public void testToArray() {
613          ArrayBlockingQueue q = populatedQueue(SIZE);
614          Object[] o = q.toArray();
615          for (int i = 0; i < o.length; i++)
616 <            assertEquals(o[i], q.take());
616 >            assertSame(o[i], q.poll());
617      }
618  
619      /**
620 <     * toArray(a) contains all elements
620 >     * toArray(a) contains all elements in FIFO order
621       */
622 <    public void testToArray2() throws InterruptedException {
623 <        ArrayBlockingQueue q = populatedQueue(SIZE);
622 >    public void testToArray2() {
623 >        ArrayBlockingQueue<Integer> q = populatedQueue(SIZE);
624          Integer[] ints = new Integer[SIZE];
625 <        ints = (Integer[])q.toArray(ints);
625 >        Integer[] array = q.toArray(ints);
626 >        assertSame(ints, array);
627          for (int i = 0; i < ints.length; i++)
628 <            assertEquals(ints[i], q.take());
628 >            assertSame(ints[i], q.poll());
629      }
630  
631      /**
632 <     * toArray(null) throws NPE
632 >     * toArray(null) throws NullPointerException
633       */
634 <    public void testToArray_BadArg() {
634 >    public void testToArray_NullArg() {
635          ArrayBlockingQueue q = populatedQueue(SIZE);
636          try {
637 <            Object o[] = q.toArray(null);
637 >            q.toArray(null);
638              shouldThrow();
639          } catch (NullPointerException success) {}
640      }
641  
642      /**
643 <     * toArray with incompatible array type throws CCE
643 >     * toArray(incompatible array type) throws ArrayStoreException
644       */
645      public void testToArray1_BadArg() {
646          ArrayBlockingQueue q = populatedQueue(SIZE);
647          try {
648 <            Object o[] = q.toArray(new String[10]);
648 >            q.toArray(new String[10]);
649              shouldThrow();
650          } catch (ArrayStoreException success) {}
651      }
# Line 896 | Line 881 | public class ArrayBlockingQueueTest exte
881      }
882  
883      /**
884 <     * drainTo(c, n) empties first max {n, size} elements of queue into c
884 >     * drainTo(c, n) empties first min(n, size) elements of queue into c
885       */
886      public void testDrainToN() {
887          ArrayBlockingQueue q = new ArrayBlockingQueue(SIZE*2);
# Line 905 | Line 890 | public class ArrayBlockingQueueTest exte
890                  assertTrue(q.offer(new Integer(j)));
891              ArrayList l = new ArrayList();
892              q.drainTo(l, i);
893 <            int k = (i < SIZE)? i : SIZE;
893 >            int k = (i < SIZE) ? i : SIZE;
894              assertEquals(l.size(), k);
895              assertEquals(q.size(), SIZE-k);
896              for (int j = 0; j < k; ++j)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines