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.30 by jsr166, Wed Aug 25 01:44:48 2010 UTC vs.
Revision 1.40 by jsr166, Thu Nov 4 01:04:54 2010 UTC

# Line 14 | Line 14 | import static java.util.concurrent.TimeU
14   import java.io.*;
15  
16   public class ArrayBlockingQueueTest extends JSR166TestCase {
17 +
18 +    public static class Fair extends BlockingQueueTest {
19 +        protected BlockingQueue emptyCollection() {
20 +            return new ArrayBlockingQueue(20, true);
21 +        }
22 +    }
23 +
24 +    public static class NonFair extends BlockingQueueTest {
25 +        protected BlockingQueue emptyCollection() {
26 +            return new ArrayBlockingQueue(20, false);
27 +        }
28 +    }
29 +
30      public static void main(String[] args) {
31          junit.textui.TestRunner.run(suite());
32      }
33 +
34      public static Test suite() {
35 <        return new TestSuite(ArrayBlockingQueueTest.class);
35 >        return newTestSuite(ArrayBlockingQueueTest.class,
36 >                            new Fair().testSuite(),
37 >                            new NonFair().testSuite());
38      }
39  
40      /**
# Line 145 | Line 161 | public class ArrayBlockingQueueTest exte
161      }
162  
163      /**
164 <     *  offer(null) throws NPE
164 >     * offer(null) throws NPE
165       */
166      public void testOfferNull() {
167          try {
# Line 156 | Line 172 | public class ArrayBlockingQueueTest exte
172      }
173  
174      /**
175 <     *  add(null) throws NPE
175 >     * add(null) throws NPE
176       */
177      public void testAddNull() {
178          try {
# Line 191 | Line 207 | public class ArrayBlockingQueueTest exte
207      }
208  
209      /**
210 <     *  addAll(null) throws NPE
210 >     * addAll(null) throws NPE
211       */
212      public void testAddAll1() {
213          try {
# Line 214 | Line 230 | public class ArrayBlockingQueueTest exte
230  
231  
232      /**
233 <     *  addAll of a collection with null elements throws NPE
233 >     * addAll of a collection with null elements throws NPE
234       */
235      public void testAddAll2() {
236          try {
# Line 270 | Line 286 | public class ArrayBlockingQueueTest exte
286      }
287  
288      /**
289 <     *  put(null) throws NPE
289 >     * put(null) throws NPE
290       */
291      public void testPutNull() throws InterruptedException {
292          try {
# Line 377 | Line 393 | public class ArrayBlockingQueueTest exte
393      }
394  
395      /**
380     * take blocks interruptibly when empty
381     */
382    public void testTakeFromEmpty() throws InterruptedException {
383        final ArrayBlockingQueue q = new ArrayBlockingQueue(2);
384        Thread t = new ThreadShouldThrow(InterruptedException.class) {
385            public void realRun() throws InterruptedException {
386                q.take();
387            }};
388
389        t.start();
390        Thread.sleep(SHORT_DELAY_MS);
391        t.interrupt();
392        t.join();
393    }
394
395    /**
396       * Take removes existing elements until empty, then blocks interruptibly
397       */
398      public void testBlockingTake() throws InterruptedException {
# Line 427 | 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 438 | 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 472 | Line 472 | public class ArrayBlockingQueueTest exte
472      }
473  
474      /**
475     *  timed poll before a delayed offer fails; after offer succeeds;
476     *  on interruption throws
477     */
478    public void testTimedPollWithOffer() throws InterruptedException {
479        final ArrayBlockingQueue q = new ArrayBlockingQueue(2);
480        Thread t = new Thread(new CheckedRunnable() {
481            public void realRun() throws InterruptedException {
482                assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
483                assertSame(zero, q.poll(LONG_DELAY_MS, MILLISECONDS));
484                try {
485                    q.poll(LONG_DELAY_MS, MILLISECONDS);
486                    shouldThrow();
487                } catch (InterruptedException success) {}
488            }});
489
490        t.start();
491        Thread.sleep(SMALL_DELAY_MS);
492        assertTrue(q.offer(zero, SHORT_DELAY_MS, MILLISECONDS));
493        t.interrupt();
494        t.join();
495    }
496
497
498    /**
475       * peek returns next element, or null if empty
476       */
477      public void testPeek() {
# Line 631 | 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 {
622 >    public void testToArray2() {
623          ArrayBlockingQueue q = populatedQueue(SIZE);
624          Integer[] ints = new Integer[SIZE];
625 <        ints = (Integer[])q.toArray(ints);
625 >        assertSame(ints, q.toArray(ints));
626          for (int i = 0; i < ints.length; i++)
627 <            assertEquals(ints[i], q.take());
627 >            assertSame(ints[i], q.poll());
628      }
629  
630      /**
631 <     * toArray(null) throws NPE
631 >     * toArray(null) throws NullPointerException
632       */
633 <    public void testToArray_BadArg() {
633 >    public void testToArray_NullArg() {
634          ArrayBlockingQueue q = populatedQueue(SIZE);
635          try {
636 <            Object o[] = q.toArray(null);
636 >            q.toArray(null);
637              shouldThrow();
638          } catch (NullPointerException success) {}
639      }
640  
641      /**
642 <     * toArray with incompatible array type throws CCE
642 >     * toArray(incompatible array type) throws ArrayStoreException
643       */
644      public void testToArray1_BadArg() {
645          ArrayBlockingQueue q = populatedQueue(SIZE);
646          try {
647 <            Object o[] = q.toArray(new String[10]);
647 >            q.toArray(new String[10]);
648              shouldThrow();
649          } catch (ArrayStoreException success) {}
650      }
# Line 904 | Line 880 | public class ArrayBlockingQueueTest exte
880      }
881  
882      /**
883 <     * drainTo(c, n) empties first max {n, size} elements of queue into c
883 >     * drainTo(c, n) empties first min(n, size) elements of queue into c
884       */
885      public void testDrainToN() {
886          ArrayBlockingQueue q = new ArrayBlockingQueue(SIZE*2);
# Line 913 | Line 889 | public class ArrayBlockingQueueTest exte
889                  assertTrue(q.offer(new Integer(j)));
890              ArrayList l = new ArrayList();
891              q.drainTo(l, i);
892 <            int k = (i < SIZE)? i : SIZE;
892 >            int k = (i < SIZE) ? i : SIZE;
893              assertEquals(l.size(), k);
894              assertEquals(q.size(), SIZE-k);
895              for (int j = 0; j < k; ++j)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines