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

Comparing jsr166/src/test/tck/LinkedBlockingDequeTest.java (file contents):
Revision 1.20 by jsr166, Tue Dec 1 09:56:28 2009 UTC vs.
Revision 1.31 by jsr166, Thu Nov 4 01:04:54 2010 UTC

# Line 11 | Line 11 | import static java.util.concurrent.TimeU
11   import java.io.*;
12  
13   public class LinkedBlockingDequeTest extends JSR166TestCase {
14 +
15 +    public static class Unbounded extends BlockingQueueTest {
16 +        protected BlockingQueue emptyCollection() {
17 +            return new LinkedBlockingDeque();
18 +        }
19 +    }
20 +
21 +    public static class Bounded extends BlockingQueueTest {
22 +        protected BlockingQueue emptyCollection() {
23 +            return new LinkedBlockingDeque(20);
24 +        }
25 +    }
26 +
27      public static void main(String[] args) {
28 <        junit.textui.TestRunner.run (suite());
28 >        junit.textui.TestRunner.run(suite());
29      }
30  
31      public static Test suite() {
32 <        return new TestSuite(LinkedBlockingDequeTest.class);
32 >        return newTestSuite(LinkedBlockingDequeTest.class,
33 >                            new Unbounded().testSuite(),
34 >                            new Bounded().testSuite());
35      }
36  
37      /**
# Line 93 | Line 108 | public class LinkedBlockingDequeTest ext
108      }
109  
110      /**
111 <     *  pollFirst succeeds unless empty
111 >     * pollFirst succeeds unless empty
112       */
113      public void testPollFirst() {
114          LinkedBlockingDeque q = populatedDeque(SIZE);
# Line 104 | Line 119 | public class LinkedBlockingDequeTest ext
119      }
120  
121      /**
122 <     *  pollLast succeeds unless empty
122 >     * pollLast succeeds unless empty
123       */
124      public void testPollLast() {
125          LinkedBlockingDeque q = populatedDeque(SIZE);
# Line 115 | Line 130 | public class LinkedBlockingDequeTest ext
130      }
131  
132      /**
133 <     *  peekFirst returns next element, or null if empty
133 >     * peekFirst returns next element, or null if empty
134       */
135      public void testPeekFirst() {
136          LinkedBlockingDeque q = populatedDeque(SIZE);
# Line 129 | Line 144 | public class LinkedBlockingDequeTest ext
144      }
145  
146      /**
147 <     *  peek returns next element, or null if empty
147 >     * peek returns next element, or null if empty
148       */
149      public void testPeek() {
150          LinkedBlockingDeque q = populatedDeque(SIZE);
# Line 143 | Line 158 | public class LinkedBlockingDequeTest ext
158      }
159  
160      /**
161 <     *  peekLast returns next element, or null if empty
161 >     * peekLast returns next element, or null if empty
162       */
163      public void testPeekLast() {
164          LinkedBlockingDeque q = populatedDeque(SIZE);
# Line 157 | Line 172 | public class LinkedBlockingDequeTest ext
172      }
173  
174      /**
175 <     * getFirst returns next getFirst, or throws NSEE if empty
175 >     * getFirst() returns first element, or throws NSEE if empty
176       */
177      public void testFirstElement() {
178          LinkedBlockingDeque q = populatedDeque(SIZE);
# Line 173 | Line 188 | public class LinkedBlockingDequeTest ext
188      }
189  
190      /**
191 <     *  getLast returns next element, or throws NSEE if empty
191 >     * getLast() returns last element, or throws NSEE if empty
192       */
193      public void testLastElement() {
194          LinkedBlockingDeque q = populatedDeque(SIZE);
# Line 189 | Line 204 | public class LinkedBlockingDequeTest ext
204      }
205  
206      /**
207 <     *  removeFirst removes next element, or throws NSEE if empty
207 >     * removeFirst() removes first element, or throws NSEE if empty
208       */
209      public void testRemoveFirst() {
210          LinkedBlockingDeque q = populatedDeque(SIZE);
# Line 204 | Line 219 | public class LinkedBlockingDequeTest ext
219      }
220  
221      /**
222 <     *  removeLast removes last element, or throws NSEE if empty
222 >     * removeLast() removes last element, or throws NSEE if empty
223       */
224      public void testRemoveLast() {
225          LinkedBlockingDeque q = populatedDeque(SIZE);
# Line 219 | Line 234 | public class LinkedBlockingDequeTest ext
234      }
235  
236      /**
237 <     *  remove removes next element, or throws NSEE if empty
237 >     * remove removes next element, or throws NSEE if empty
238       */
239      public void testRemove() {
240          LinkedBlockingDeque q = populatedDeque(SIZE);
# Line 442 | Line 457 | public class LinkedBlockingDequeTest ext
457  
458  
459      /**
460 <     *  pop removes next element, or throws NSEE if empty
460 >     * pop removes next element, or throws NSEE if empty
461       */
462      public void testPop() {
463          LinkedBlockingDeque q = populatedDeque(SIZE);
# Line 513 | Line 528 | public class LinkedBlockingDequeTest ext
528              shouldThrow();
529          } catch (NullPointerException success) {}
530      }
531 +
532      /**
533       * addAll of a collection with any null elements throws NPE after
534       * possibly adding some elements
# Line 527 | Line 543 | public class LinkedBlockingDequeTest ext
543              shouldThrow();
544          } catch (NullPointerException success) {}
545      }
546 +
547      /**
548       * addAll throws ISE if not enough room
549       */
# Line 665 | Line 682 | public class LinkedBlockingDequeTest ext
682      }
683  
684      /**
668     * take blocks interruptibly when empty
669     */
670    public void testTakeFromEmpty() throws InterruptedException {
671        final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
672        Thread t = new ThreadShouldThrow(InterruptedException.class) {
673            public void realRun() throws InterruptedException {
674                q.take();
675            }};
676
677        t.start();
678        Thread.sleep(SHORT_DELAY_MS);
679        t.interrupt();
680        t.join();
681    }
682
683    /**
685       * Take removes existing elements until empty, then blocks interruptibly
686       */
687      public void testBlockingTake() throws InterruptedException {
# Line 760 | Line 761 | public class LinkedBlockingDequeTest ext
761      }
762  
763      /**
763     *  timed poll before a delayed offer fails; after offer succeeds;
764     *  on interruption throws
765     */
766    public void testTimedPollWithOffer() throws InterruptedException {
767        final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
768        Thread t = new Thread(new CheckedRunnable() {
769            public void realRun() throws InterruptedException {
770                assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
771                assertSame(zero, q.poll(LONG_DELAY_MS, MILLISECONDS));
772                try {
773                    q.poll(LONG_DELAY_MS, MILLISECONDS);
774                    shouldThrow();
775                } catch (InterruptedException success) {}
776            }});
777
778        t.start();
779        Thread.sleep(SMALL_DELAY_MS);
780        assertTrue(q.offer(zero, SHORT_DELAY_MS, MILLISECONDS));
781        t.interrupt();
782        t.join();
783    }
784
785
786    /**
764       * putFirst(null) throws NPE
765       */
766       public void testPutFirstNull() throws InterruptedException {
# Line 974 | Line 951 | public class LinkedBlockingDequeTest ext
951      }
952  
953      /**
954 <     *  timed pollFirst before a delayed offerFirst fails; after offerFirst succeeds;
955 <     *  on interruption throws
954 >     * timed pollFirst before a delayed offerFirst fails; after offerFirst succeeds;
955 >     * on interruption throws
956       */
957      public void testTimedPollFirstWithOfferFirst() throws InterruptedException {
958          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
# Line 1186 | Line 1163 | public class LinkedBlockingDequeTest ext
1163      }
1164  
1165      /**
1166 <     *  timed poll before a delayed offerLast fails; after offerLast succeeds;
1167 <     *  on interruption throws
1166 >     * timed poll before a delayed offerLast fails; after offerLast succeeds;
1167 >     * on interruption throws
1168       */
1169      public void testTimedPollWithOfferLast() throws InterruptedException {
1170          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
# Line 1317 | Line 1294 | public class LinkedBlockingDequeTest ext
1294      }
1295  
1296      /**
1297 <     * toArray contains all elements
1297 >     * toArray contains all elements in FIFO order
1298       */
1299      public void testToArray() throws InterruptedException{
1300          LinkedBlockingDeque q = populatedDeque(SIZE);
1301          Object[] o = q.toArray();
1302          for (int i = 0; i < o.length; i++)
1303 <            assertEquals(o[i], q.take());
1303 >            assertSame(o[i], q.poll());
1304      }
1305  
1306      /**
1307 <     * toArray(a) contains all elements
1307 >     * toArray(a) contains all elements in FIFO order
1308       */
1309 <    public void testToArray2() throws InterruptedException {
1309 >    public void testToArray2() {
1310          LinkedBlockingDeque q = populatedDeque(SIZE);
1311          Integer[] ints = new Integer[SIZE];
1312 <        ints = (Integer[])q.toArray(ints);
1312 >        assertSame(ints, q.toArray(ints));
1313          for (int i = 0; i < ints.length; i++)
1314 <            assertEquals(ints[i], q.take());
1314 >            assertSame(ints[i], q.remove());
1315      }
1316  
1317      /**
1318 <     * toArray(null) throws NPE
1318 >     * toArray(null) throws NullPointerException
1319       */
1320 <    public void testToArray_BadArg() {
1320 >    public void testToArray_NullArg() {
1321          LinkedBlockingDeque q = populatedDeque(SIZE);
1322          try {
1323 <            Object o[] = q.toArray(null);
1323 >            q.toArray(null);
1324              shouldThrow();
1325          } catch (NullPointerException success) {}
1326      }
1327  
1328      /**
1329 <     * toArray with incompatible array type throws CCE
1329 >     * toArray(incompatible array type) throws ArrayStoreException
1330       */
1331      public void testToArray1_BadArg() {
1332          LinkedBlockingDeque q = populatedDeque(SIZE);
1333          try {
1334 <            Object o[] = q.toArray(new String[10]);
1334 >            q.toArray(new String[10]);
1335              shouldThrow();
1336          } catch (ArrayStoreException success) {}
1337      }
# Line 1374 | Line 1351 | public class LinkedBlockingDequeTest ext
1351      /**
1352       * iterator.remove removes current element
1353       */
1354 <    public void testIteratorRemove () {
1354 >    public void testIteratorRemove() {
1355          final LinkedBlockingDeque q = new LinkedBlockingDeque(3);
1356          q.add(two);
1357          q.add(one);
# Line 1410 | Line 1387 | public class LinkedBlockingDequeTest ext
1387      /**
1388       * Modifications do not cause iterators to fail
1389       */
1390 <    public void testWeaklyConsistentIteration () {
1390 >    public void testWeaklyConsistentIteration() {
1391          final LinkedBlockingDeque q = new LinkedBlockingDeque(3);
1392          q.add(one);
1393          q.add(two);
# Line 1424 | Line 1401 | public class LinkedBlockingDequeTest ext
1401  
1402  
1403      /**
1404 <     *  Descending iterator iterates through all elements
1404 >     * Descending iterator iterates through all elements
1405       */
1406      public void testDescendingIterator() {
1407          LinkedBlockingDeque q = populatedDeque(SIZE);
# Line 1443 | Line 1420 | public class LinkedBlockingDequeTest ext
1420      }
1421  
1422      /**
1423 <     *  Descending iterator ordering is reverse FIFO
1423 >     * Descending iterator ordering is reverse FIFO
1424       */
1425      public void testDescendingIteratorOrdering() {
1426          final LinkedBlockingDeque q = new LinkedBlockingDeque();
# Line 1466 | Line 1443 | public class LinkedBlockingDequeTest ext
1443      /**
1444       * descendingIterator.remove removes current element
1445       */
1446 <    public void testDescendingIteratorRemove () {
1446 >    public void testDescendingIteratorRemove() {
1447          final LinkedBlockingDeque q = new LinkedBlockingDeque();
1448          for (int iters = 0; iters < 100; ++iters) {
1449              q.add(new Integer(3));
# Line 1652 | Line 1629 | public class LinkedBlockingDequeTest ext
1629      }
1630  
1631      /**
1632 <     * drainTo(c, n) empties first max {n, size} elements of deque into c
1632 >     * drainTo(c, n) empties first min(n, size) elements of queue into c
1633       */
1634      public void testDrainToN() {
1635          LinkedBlockingDeque q = new LinkedBlockingDeque();
# Line 1661 | Line 1638 | public class LinkedBlockingDequeTest ext
1638                  assertTrue(q.offer(new Integer(j)));
1639              ArrayList l = new ArrayList();
1640              q.drainTo(l, i);
1641 <            int k = (i < SIZE)? i : SIZE;
1641 >            int k = (i < SIZE) ? i : SIZE;
1642              assertEquals(l.size(), k);
1643              assertEquals(q.size(), SIZE-k);
1644              for (int j = 0; j < k; ++j)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines