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.27 by jsr166, Tue Dec 1 06:03:49 2009 UTC vs.
Revision 1.36 by jsr166, Thu Oct 28 17:57:26 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());
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 224 | Line 240 | public class ArrayBlockingQueueTest exte
240              shouldThrow();
241          } catch (NullPointerException success) {}
242      }
243 +
244      /**
245       * addAll of a collection with any null elements throws NPE after
246       * possibly adding some elements
# Line 238 | Line 255 | public class ArrayBlockingQueueTest exte
255              shouldThrow();
256          } catch (NullPointerException success) {}
257      }
258 +
259      /**
260       * addAll throws ISE if not enough room
261       */
# Line 251 | Line 269 | public class ArrayBlockingQueueTest exte
269              shouldThrow();
270          } catch (IllegalStateException success) {}
271      }
272 +
273      /**
274       * Queue contains all elements, in traversal order, of successful addAll
275       */
# Line 267 | 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 374 | Line 393 | public class ArrayBlockingQueueTest exte
393      }
394  
395      /**
377     * take blocks interruptibly when empty
378     */
379    public void testTakeFromEmpty() throws InterruptedException {
380        final ArrayBlockingQueue q = new ArrayBlockingQueue(2);
381        Thread t = new ThreadShouldThrow(InterruptedException.class) {
382            public void realRun() throws InterruptedException {
383                q.take();
384            }};
385
386        t.start();
387        Thread.sleep(SHORT_DELAY_MS);
388        t.interrupt();
389        t.join();
390    }
391
392    /**
396       * Take removes existing elements until empty, then blocks interruptibly
397       */
398      public void testBlockingTake() throws InterruptedException {
# Line 469 | Line 472 | public class ArrayBlockingQueueTest exte
472      }
473  
474      /**
472     *  timed poll before a delayed offer fails; after offer succeeds;
473     *  on interruption throws
474     */
475    public void testTimedPollWithOffer() throws InterruptedException {
476        final ArrayBlockingQueue q = new ArrayBlockingQueue(2);
477        Thread t = new Thread(new CheckedRunnable() {
478            public void realRun() throws InterruptedException {
479                assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
480                assertSame(zero, q.poll(LONG_DELAY_MS, MILLISECONDS));
481                try {
482                    q.poll(LONG_DELAY_MS, MILLISECONDS);
483                    shouldThrow();
484                } catch (InterruptedException success) {}
485            }});
486
487        t.start();
488        Thread.sleep(SMALL_DELAY_MS);
489        assertTrue(q.offer(zero, SHORT_DELAY_MS, MILLISECONDS));
490        t.interrupt();
491        t.join();
492    }
493
494
495    /**
475       * peek returns next element, or null if empty
476       */
477      public void testPeek() {
# Line 628 | Line 607 | public class ArrayBlockingQueueTest exte
607      }
608  
609      /**
610 <     *  toArray contains all elements
610 >     * toArray contains all elements
611       */
612      public void testToArray() throws InterruptedException {
613          ArrayBlockingQueue q = populatedQueue(SIZE);
# Line 685 | Line 664 | public class ArrayBlockingQueueTest exte
664      /**
665       * iterator.remove removes current element
666       */
667 <    public void testIteratorRemove () {
667 >    public void testIteratorRemove() {
668          final ArrayBlockingQueue q = new ArrayBlockingQueue(3);
669          q.add(two);
670          q.add(one);
# Line 696 | Line 675 | public class ArrayBlockingQueueTest exte
675          it.remove();
676  
677          it = q.iterator();
678 <        assertEquals(it.next(), one);
679 <        assertEquals(it.next(), three);
678 >        assertSame(it.next(), one);
679 >        assertSame(it.next(), three);
680          assertFalse(it.hasNext());
681      }
682  
# Line 722 | Line 701 | public class ArrayBlockingQueueTest exte
701      /**
702       * Modifications do not cause iterators to fail
703       */
704 <    public void testWeaklyConsistentIteration () {
704 >    public void testWeaklyConsistentIteration() {
705          final ArrayBlockingQueue q = new ArrayBlockingQueue(3);
706          q.add(one);
707          q.add(two);
# Line 769 | Line 748 | public class ArrayBlockingQueueTest exte
748              }});
749  
750          joinPool(executor);
772
751      }
752  
753      /**
# Line 902 | 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 911 | 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