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.37 by dl, Fri May 6 11:22:07 2011 UTC

# Line 1 | Line 1
1   /*
2   * Written by Doug Lea with assistance from members of JCP JSR-166
3   * Expert Group and released to the public domain, as explained at
4 < * http://creativecommons.org/licenses/publicdomain
4 > * http://creativecommons.org/publicdomain/zero/1.0/
5   */
6  
7   import junit.framework.*;
# 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      /**
38       * Create a deque of given size containing consecutive
39       * Integers 0 ... n.
40       */
41 <    private LinkedBlockingDeque populatedDeque(int n) {
42 <        LinkedBlockingDeque q = new LinkedBlockingDeque(n);
41 >    private LinkedBlockingDeque<Integer> populatedDeque(int n) {
42 >        LinkedBlockingDeque<Integer> q =
43 >            new LinkedBlockingDeque<Integer>(n);
44          assertTrue(q.isEmpty());
45          for (int i = 0; i < n; i++)
46              assertTrue(q.offer(new Integer(i)));
# Line 93 | Line 109 | public class LinkedBlockingDequeTest ext
109      }
110  
111      /**
112 <     *  pollFirst succeeds unless empty
112 >     * pollFirst succeeds unless empty
113       */
114      public void testPollFirst() {
115          LinkedBlockingDeque q = populatedDeque(SIZE);
# Line 104 | Line 120 | public class LinkedBlockingDequeTest ext
120      }
121  
122      /**
123 <     *  pollLast succeeds unless empty
123 >     * pollLast succeeds unless empty
124       */
125      public void testPollLast() {
126          LinkedBlockingDeque q = populatedDeque(SIZE);
# Line 115 | Line 131 | public class LinkedBlockingDequeTest ext
131      }
132  
133      /**
134 <     *  peekFirst returns next element, or null if empty
134 >     * peekFirst returns next element, or null if empty
135       */
136      public void testPeekFirst() {
137          LinkedBlockingDeque q = populatedDeque(SIZE);
# Line 129 | Line 145 | public class LinkedBlockingDequeTest ext
145      }
146  
147      /**
148 <     *  peek returns next element, or null if empty
148 >     * peek returns next element, or null if empty
149       */
150      public void testPeek() {
151          LinkedBlockingDeque q = populatedDeque(SIZE);
# Line 143 | Line 159 | public class LinkedBlockingDequeTest ext
159      }
160  
161      /**
162 <     *  peekLast returns next element, or null if empty
162 >     * peekLast returns next element, or null if empty
163       */
164      public void testPeekLast() {
165          LinkedBlockingDeque q = populatedDeque(SIZE);
# Line 157 | Line 173 | public class LinkedBlockingDequeTest ext
173      }
174  
175      /**
176 <     * getFirst returns next getFirst, or throws NSEE if empty
176 >     * getFirst() returns first element, or throws NSEE if empty
177       */
178      public void testFirstElement() {
179          LinkedBlockingDeque q = populatedDeque(SIZE);
# Line 173 | Line 189 | public class LinkedBlockingDequeTest ext
189      }
190  
191      /**
192 <     *  getLast returns next element, or throws NSEE if empty
192 >     * getLast() returns last element, or throws NSEE if empty
193       */
194      public void testLastElement() {
195          LinkedBlockingDeque q = populatedDeque(SIZE);
# Line 189 | Line 205 | public class LinkedBlockingDequeTest ext
205      }
206  
207      /**
208 <     *  removeFirst removes next element, or throws NSEE if empty
208 >     * removeFirst() removes first element, or throws NSEE if empty
209       */
210      public void testRemoveFirst() {
211          LinkedBlockingDeque q = populatedDeque(SIZE);
# Line 204 | Line 220 | public class LinkedBlockingDequeTest ext
220      }
221  
222      /**
223 <     *  removeLast removes last element, or throws NSEE if empty
223 >     * removeLast() removes last element, or throws NSEE if empty
224       */
225      public void testRemoveLast() {
226          LinkedBlockingDeque q = populatedDeque(SIZE);
# Line 219 | Line 235 | public class LinkedBlockingDequeTest ext
235      }
236  
237      /**
238 <     *  remove removes next element, or throws NSEE if empty
238 >     * remove removes next element, or throws NSEE if empty
239       */
240      public void testRemove() {
241          LinkedBlockingDeque q = populatedDeque(SIZE);
# Line 442 | Line 458 | public class LinkedBlockingDequeTest ext
458  
459  
460      /**
461 <     *  pop removes next element, or throws NSEE if empty
461 >     * pop removes next element, or throws NSEE if empty
462       */
463      public void testPop() {
464          LinkedBlockingDeque q = populatedDeque(SIZE);
# Line 513 | Line 529 | public class LinkedBlockingDequeTest ext
529              shouldThrow();
530          } catch (NullPointerException success) {}
531      }
532 +
533      /**
534       * addAll of a collection with any null elements throws NPE after
535       * possibly adding some elements
# Line 527 | Line 544 | public class LinkedBlockingDequeTest ext
544              shouldThrow();
545          } catch (NullPointerException success) {}
546      }
547 +
548      /**
549       * addAll throws ISE if not enough room
550       */
# Line 599 | Line 617 | public class LinkedBlockingDequeTest ext
617              }});
618  
619          t.start();
620 <        Thread.sleep(SHORT_DELAY_MS);
620 >        delay(SHORT_DELAY_MS);
621          t.interrupt();
622          t.join();
623          assertEquals(SIZE, q.size());
# Line 623 | Line 641 | public class LinkedBlockingDequeTest ext
641              }});
642  
643          t.start();
644 <        Thread.sleep(SHORT_DELAY_MS);
644 >        delay(SHORT_DELAY_MS);
645          assertEquals(q.remainingCapacity(), 0);
646          assertEquals(0, q.take());
647 <        Thread.sleep(SHORT_DELAY_MS);
647 >        delay(SHORT_DELAY_MS);
648          t.interrupt();
649          t.join();
650          assertEquals(q.remainingCapacity(), 0);
# Line 649 | Line 667 | public class LinkedBlockingDequeTest ext
667              }});
668  
669          t.start();
670 <        Thread.sleep(SMALL_DELAY_MS);
670 >        delay(SMALL_DELAY_MS);
671          t.interrupt();
672          t.join();
673      }
# Line 665 | Line 683 | public class LinkedBlockingDequeTest ext
683      }
684  
685      /**
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    /**
686       * Take removes existing elements until empty, then blocks interruptibly
687       */
688      public void testBlockingTake() throws InterruptedException {
# Line 697 | Line 699 | public class LinkedBlockingDequeTest ext
699              }});
700  
701          t.start();
702 <        Thread.sleep(SHORT_DELAY_MS);
702 >        delay(SHORT_DELAY_MS);
703          t.interrupt();
704          t.join();
705      }
# Line 741 | Line 743 | public class LinkedBlockingDequeTest ext
743       * returning timeout status
744       */
745      public void testInterruptedTimedPoll() throws InterruptedException {
746 <        Thread t = new Thread(new CheckedRunnable() {
746 >        final BlockingQueue<Integer> q = populatedDeque(SIZE);
747 >        final CountDownLatch aboutToWait = new CountDownLatch(1);
748 >        Thread t = newStartedThread(new CheckedRunnable() {
749              public void realRun() throws InterruptedException {
746                LinkedBlockingDeque q = populatedDeque(SIZE);
750                  for (int i = 0; i < SIZE; ++i) {
751 <                    assertEquals(i, q.poll(SHORT_DELAY_MS, MILLISECONDS));
751 >                    long t0 = System.nanoTime();
752 >                    assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS));
753 >                    assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS);
754                  }
755 +                long t0 = System.nanoTime();
756 +                aboutToWait.countDown();
757                  try {
758 <                    q.poll(SMALL_DELAY_MS, MILLISECONDS);
758 >                    q.poll(MEDIUM_DELAY_MS, MILLISECONDS);
759                      shouldThrow();
760 <                } catch (InterruptedException success) {}
761 <            }});
762 <
756 <        t.start();
757 <        Thread.sleep(SHORT_DELAY_MS);
758 <        t.interrupt();
759 <        t.join();
760 <    }
761 <
762 <    /**
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) {}
760 >                } catch (InterruptedException success) {
761 >                    assertTrue(millisElapsedSince(t0) < MEDIUM_DELAY_MS);
762 >                }
763              }});
764  
765 <        t.start();
766 <        Thread.sleep(SMALL_DELAY_MS);
780 <        assertTrue(q.offer(zero, SHORT_DELAY_MS, MILLISECONDS));
765 >        aboutToWait.await();
766 >        waitForThreadToEnterWaitState(t, SMALL_DELAY_MS);
767          t.interrupt();
768 <        t.join();
768 >        awaitTermination(t, MEDIUM_DELAY_MS);
769 >        checkEmpty(q);
770      }
771  
785
772      /**
773       * putFirst(null) throws NPE
774       */
775 <     public void testPutFirstNull() throws InterruptedException {
775 >    public void testPutFirstNull() throws InterruptedException {
776          try {
777              LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
778              q.putFirst(null);
779              shouldThrow();
780          } catch (NullPointerException success) {}
781 <     }
781 >    }
782  
783      /**
784       * all elements successfully putFirst are contained
785       */
786 <     public void testPutFirst() throws InterruptedException {
787 <         LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
788 <         for (int i = 0; i < SIZE; ++i) {
789 <             Integer I = new Integer(i);
790 <             q.putFirst(I);
791 <             assertTrue(q.contains(I));
792 <         }
793 <         assertEquals(0, q.remainingCapacity());
786 >    public void testPutFirst() throws InterruptedException {
787 >        LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
788 >        for (int i = 0; i < SIZE; ++i) {
789 >            Integer I = new Integer(i);
790 >            q.putFirst(I);
791 >            assertTrue(q.contains(I));
792 >        }
793 >        assertEquals(0, q.remainingCapacity());
794      }
795  
796      /**
# Line 825 | Line 811 | public class LinkedBlockingDequeTest ext
811              }});
812  
813          t.start();
814 <        Thread.sleep(SHORT_DELAY_MS);
814 >        delay(SHORT_DELAY_MS);
815          t.interrupt();
816          t.join();
817          assertEquals(SIZE, q.size());
# Line 849 | Line 835 | public class LinkedBlockingDequeTest ext
835              }});
836  
837          t.start();
838 <        Thread.sleep(SHORT_DELAY_MS);
838 >        delay(SHORT_DELAY_MS);
839          assertEquals(q.remainingCapacity(), 0);
840          assertEquals(capacity - 1, q.take());
841 <        Thread.sleep(SHORT_DELAY_MS);
841 >        delay(SHORT_DELAY_MS);
842          t.interrupt();
843          t.join();
844          assertEquals(q.remainingCapacity(), 0);
# Line 875 | Line 861 | public class LinkedBlockingDequeTest ext
861              }});
862  
863          t.start();
864 <        Thread.sleep(SMALL_DELAY_MS);
864 >        delay(SMALL_DELAY_MS);
865          t.interrupt();
866          t.join();
867      }
# Line 901 | Line 887 | public class LinkedBlockingDequeTest ext
887              }};
888  
889          t.start();
890 <        Thread.sleep(SHORT_DELAY_MS);
890 >        delay(SHORT_DELAY_MS);
891          t.interrupt();
892          t.join();
893      }
# Line 922 | Line 908 | public class LinkedBlockingDequeTest ext
908              }});
909  
910          t.start();
911 <        Thread.sleep(SHORT_DELAY_MS);
911 >        delay(SHORT_DELAY_MS);
912          t.interrupt();
913          t.join();
914      }
# Line 968 | Line 954 | public class LinkedBlockingDequeTest ext
954              }});
955  
956          t.start();
957 <        Thread.sleep(SHORT_DELAY_MS);
957 >        delay(SHORT_DELAY_MS);
958          t.interrupt();
959          t.join();
960      }
961  
962      /**
963 <     *  timed pollFirst before a delayed offerFirst fails; after offerFirst succeeds;
964 <     *  on interruption throws
963 >     * timed pollFirst before a delayed offerFirst fails; after offerFirst succeeds;
964 >     * on interruption throws
965       */
966      public void testTimedPollFirstWithOfferFirst() throws InterruptedException {
967          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
# Line 990 | Line 976 | public class LinkedBlockingDequeTest ext
976              }});
977  
978          t.start();
979 <        Thread.sleep(SMALL_DELAY_MS);
979 >        delay(SMALL_DELAY_MS);
980          assertTrue(q.offerFirst(zero, SHORT_DELAY_MS, MILLISECONDS));
981          t.interrupt();
982          t.join();
# Line 999 | Line 985 | public class LinkedBlockingDequeTest ext
985      /**
986       * putLast(null) throws NPE
987       */
988 <     public void testPutLastNull() throws InterruptedException {
988 >    public void testPutLastNull() throws InterruptedException {
989          try {
990              LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
991              q.putLast(null);
992              shouldThrow();
993          } catch (NullPointerException success) {}
994 <     }
994 >    }
995  
996      /**
997       * all elements successfully putLast are contained
998       */
999 <     public void testPutLast() throws InterruptedException {
1000 <         LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
1001 <         for (int i = 0; i < SIZE; ++i) {
1002 <             Integer I = new Integer(i);
1003 <             q.putLast(I);
1004 <             assertTrue(q.contains(I));
1005 <         }
1006 <         assertEquals(0, q.remainingCapacity());
999 >    public void testPutLast() throws InterruptedException {
1000 >        LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
1001 >        for (int i = 0; i < SIZE; ++i) {
1002 >            Integer I = new Integer(i);
1003 >            q.putLast(I);
1004 >            assertTrue(q.contains(I));
1005 >        }
1006 >        assertEquals(0, q.remainingCapacity());
1007      }
1008  
1009      /**
# Line 1038 | Line 1024 | public class LinkedBlockingDequeTest ext
1024              }});
1025  
1026          t.start();
1027 <        Thread.sleep(SHORT_DELAY_MS);
1027 >        delay(SHORT_DELAY_MS);
1028          t.interrupt();
1029          t.join();
1030          assertEquals(SIZE, q.size());
# Line 1062 | Line 1048 | public class LinkedBlockingDequeTest ext
1048              }});
1049  
1050          t.start();
1051 <        Thread.sleep(SHORT_DELAY_MS);
1051 >        delay(SHORT_DELAY_MS);
1052          assertEquals(q.remainingCapacity(), 0);
1053          assertEquals(0, q.take());
1054 <        Thread.sleep(SHORT_DELAY_MS);
1054 >        delay(SHORT_DELAY_MS);
1055          t.interrupt();
1056          t.join();
1057          assertEquals(q.remainingCapacity(), 0);
# Line 1088 | Line 1074 | public class LinkedBlockingDequeTest ext
1074              }});
1075  
1076          t.start();
1077 <        Thread.sleep(SMALL_DELAY_MS);
1077 >        delay(SMALL_DELAY_MS);
1078          t.interrupt();
1079          t.join();
1080      }
# Line 1114 | Line 1100 | public class LinkedBlockingDequeTest ext
1100              }};
1101  
1102          t.start();
1103 <        Thread.sleep(SHORT_DELAY_MS);
1103 >        delay(SHORT_DELAY_MS);
1104          t.interrupt();
1105          t.join();
1106      }
# Line 1135 | Line 1121 | public class LinkedBlockingDequeTest ext
1121              }});
1122  
1123          t.start();
1124 <        Thread.sleep(SHORT_DELAY_MS);
1124 >        delay(SHORT_DELAY_MS);
1125          t.interrupt();
1126          t.join();
1127      }
# Line 1180 | Line 1166 | public class LinkedBlockingDequeTest ext
1166              }});
1167  
1168          t.start();
1169 <        Thread.sleep(SHORT_DELAY_MS);
1169 >        delay(SHORT_DELAY_MS);
1170          t.interrupt();
1171          t.join();
1172      }
1173  
1174      /**
1175 <     *  timed poll before a delayed offerLast fails; after offerLast succeeds;
1176 <     *  on interruption throws
1175 >     * timed poll before a delayed offerLast fails; after offerLast succeeds;
1176 >     * on interruption throws
1177       */
1178      public void testTimedPollWithOfferLast() throws InterruptedException {
1179          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
# Line 1202 | Line 1188 | public class LinkedBlockingDequeTest ext
1188              }});
1189  
1190          t.start();
1191 <        Thread.sleep(SMALL_DELAY_MS);
1191 >        delay(SMALL_DELAY_MS);
1192          assertTrue(q.offerLast(zero, SHORT_DELAY_MS, MILLISECONDS));
1193          t.interrupt();
1194          t.join();
# Line 1230 | Line 1216 | public class LinkedBlockingDequeTest ext
1216      public void testRemoveElement() {
1217          LinkedBlockingDeque q = populatedDeque(SIZE);
1218          for (int i = 1; i < SIZE; i+=2) {
1219 <            assertTrue(q.remove(new Integer(i)));
1219 >            assertTrue(q.contains(i));
1220 >            assertTrue(q.remove(i));
1221 >            assertFalse(q.contains(i));
1222 >            assertTrue(q.contains(i-1));
1223          }
1224          for (int i = 0; i < SIZE; i+=2) {
1225 <            assertTrue(q.remove(new Integer(i)));
1226 <            assertFalse(q.remove(new Integer(i+1)));
1225 >            assertTrue(q.contains(i));
1226 >            assertTrue(q.remove(i));
1227 >            assertFalse(q.contains(i));
1228 >            assertFalse(q.remove(i+1));
1229 >            assertFalse(q.contains(i+1));
1230          }
1231          assertTrue(q.isEmpty());
1232      }
# Line 1317 | Line 1309 | public class LinkedBlockingDequeTest ext
1309      }
1310  
1311      /**
1312 <     * toArray contains all elements
1312 >     * toArray contains all elements in FIFO order
1313       */
1314      public void testToArray() throws InterruptedException{
1315          LinkedBlockingDeque q = populatedDeque(SIZE);
1316          Object[] o = q.toArray();
1317          for (int i = 0; i < o.length; i++)
1318 <            assertEquals(o[i], q.take());
1318 >            assertSame(o[i], q.poll());
1319      }
1320  
1321      /**
1322 <     * toArray(a) contains all elements
1322 >     * toArray(a) contains all elements in FIFO order
1323       */
1324 <    public void testToArray2() throws InterruptedException {
1325 <        LinkedBlockingDeque q = populatedDeque(SIZE);
1324 >    public void testToArray2() {
1325 >        LinkedBlockingDeque<Integer> q = populatedDeque(SIZE);
1326          Integer[] ints = new Integer[SIZE];
1327 <        ints = (Integer[])q.toArray(ints);
1327 >        Integer[] array = q.toArray(ints);
1328 >        assertSame(ints, array);
1329          for (int i = 0; i < ints.length; i++)
1330 <            assertEquals(ints[i], q.take());
1330 >            assertSame(ints[i], q.remove());
1331      }
1332  
1333      /**
1334 <     * toArray(null) throws NPE
1334 >     * toArray(null) throws NullPointerException
1335       */
1336 <    public void testToArray_BadArg() {
1336 >    public void testToArray_NullArg() {
1337          LinkedBlockingDeque q = populatedDeque(SIZE);
1338          try {
1339 <            Object o[] = q.toArray(null);
1339 >            q.toArray(null);
1340              shouldThrow();
1341          } catch (NullPointerException success) {}
1342      }
1343  
1344      /**
1345 <     * toArray with incompatible array type throws CCE
1345 >     * toArray(incompatible array type) throws ArrayStoreException
1346       */
1347      public void testToArray1_BadArg() {
1348          LinkedBlockingDeque q = populatedDeque(SIZE);
1349          try {
1350 <            Object o[] = q.toArray(new String[10]);
1350 >            q.toArray(new String[10]);
1351              shouldThrow();
1352          } catch (ArrayStoreException success) {}
1353      }
# Line 1374 | Line 1367 | public class LinkedBlockingDequeTest ext
1367      /**
1368       * iterator.remove removes current element
1369       */
1370 <    public void testIteratorRemove () {
1370 >    public void testIteratorRemove() {
1371          final LinkedBlockingDeque q = new LinkedBlockingDeque(3);
1372          q.add(two);
1373          q.add(one);
# Line 1410 | Line 1403 | public class LinkedBlockingDequeTest ext
1403      /**
1404       * Modifications do not cause iterators to fail
1405       */
1406 <    public void testWeaklyConsistentIteration () {
1406 >    public void testWeaklyConsistentIteration() {
1407          final LinkedBlockingDeque q = new LinkedBlockingDeque(3);
1408          q.add(one);
1409          q.add(two);
# Line 1424 | Line 1417 | public class LinkedBlockingDequeTest ext
1417  
1418  
1419      /**
1420 <     *  Descending iterator iterates through all elements
1420 >     * Descending iterator iterates through all elements
1421       */
1422      public void testDescendingIterator() {
1423          LinkedBlockingDeque q = populatedDeque(SIZE);
# Line 1443 | Line 1436 | public class LinkedBlockingDequeTest ext
1436      }
1437  
1438      /**
1439 <     *  Descending iterator ordering is reverse FIFO
1439 >     * Descending iterator ordering is reverse FIFO
1440       */
1441      public void testDescendingIteratorOrdering() {
1442          final LinkedBlockingDeque q = new LinkedBlockingDeque();
# Line 1466 | Line 1459 | public class LinkedBlockingDequeTest ext
1459      /**
1460       * descendingIterator.remove removes current element
1461       */
1462 <    public void testDescendingIteratorRemove () {
1462 >    public void testDescendingIteratorRemove() {
1463          final LinkedBlockingDeque q = new LinkedBlockingDeque();
1464          for (int iters = 0; iters < 100; ++iters) {
1465              q.add(new Integer(3));
# Line 1515 | Line 1508 | public class LinkedBlockingDequeTest ext
1508  
1509          executor.execute(new CheckedRunnable() {
1510              public void realRun() throws InterruptedException {
1511 <                Thread.sleep(SMALL_DELAY_MS);
1511 >                delay(SMALL_DELAY_MS);
1512                  assertSame(one, q.take());
1513              }});
1514  
# Line 1537 | Line 1530 | public class LinkedBlockingDequeTest ext
1530  
1531          executor.execute(new CheckedRunnable() {
1532              public void realRun() throws InterruptedException {
1533 <                Thread.sleep(SMALL_DELAY_MS);
1533 >                delay(SMALL_DELAY_MS);
1534                  q.put(one);
1535              }});
1536  
# Line 1652 | Line 1645 | public class LinkedBlockingDequeTest ext
1645      }
1646  
1647      /**
1648 <     * drainTo(c, n) empties first max {n, size} elements of deque into c
1648 >     * drainTo(c, n) empties first min(n, size) elements of queue into c
1649       */
1650      public void testDrainToN() {
1651          LinkedBlockingDeque q = new LinkedBlockingDeque();
# Line 1661 | Line 1654 | public class LinkedBlockingDequeTest ext
1654                  assertTrue(q.offer(new Integer(j)));
1655              ArrayList l = new ArrayList();
1656              q.drainTo(l, i);
1657 <            int k = (i < SIZE)? i : SIZE;
1657 >            int k = (i < SIZE) ? i : SIZE;
1658              assertEquals(l.size(), k);
1659              assertEquals(q.size(), SIZE-k);
1660              for (int j = 0; j < k; ++j)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines