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.53 by jsr166, Wed Dec 31 20:09:08 2014 UTC vs.
Revision 1.77 by jsr166, Sun May 14 00:56:43 2017 UTC

# Line 37 | Line 37 | public class LinkedBlockingDequeTest ext
37      }
38  
39      public static void main(String[] args) {
40 <        junit.textui.TestRunner.run(suite());
40 >        main(suite(), args);
41      }
42  
43      public static Test suite() {
44 +        class Implementation implements CollectionImplementation {
45 +            public Class<?> klazz() { return LinkedBlockingDeque.class; }
46 +            public Collection emptyCollection() { return new LinkedBlockingDeque(); }
47 +            public Object makeElement(int i) { return i; }
48 +            public boolean isConcurrent() { return true; }
49 +            public boolean permitsNulls() { return false; }
50 +        }
51          return newTestSuite(LinkedBlockingDequeTest.class,
52                              new Unbounded().testSuite(),
53 <                            new Bounded().testSuite());
53 >                            new Bounded().testSuite(),
54 >                            CollectionTest.testSuite(new Implementation()));
55      }
56  
57      /**
58       * Returns a new deque of given size containing consecutive
59 <     * Integers 0 ... n.
59 >     * Integers 0 ... n - 1.
60       */
61 <    private LinkedBlockingDeque<Integer> populatedDeque(int n) {
61 >    private static LinkedBlockingDeque<Integer> populatedDeque(int n) {
62          LinkedBlockingDeque<Integer> q =
63              new LinkedBlockingDeque<Integer>(n);
64          assertTrue(q.isEmpty());
# Line 59 | Line 67 | public class LinkedBlockingDequeTest ext
67          assertFalse(q.isEmpty());
68          assertEquals(0, q.remainingCapacity());
69          assertEquals(n, q.size());
70 +        assertEquals((Integer) 0, q.peekFirst());
71 +        assertEquals((Integer) (n - 1), q.peekLast());
72          return q;
73      }
74  
# Line 82 | Line 92 | public class LinkedBlockingDequeTest ext
92      public void testSize() {
93          LinkedBlockingDeque q = populatedDeque(SIZE);
94          for (int i = 0; i < SIZE; ++i) {
95 <            assertEquals(SIZE-i, q.size());
95 >            assertEquals(SIZE - i, q.size());
96              q.removeFirst();
97          }
98          for (int i = 0; i < SIZE; ++i) {
# Line 147 | Line 157 | public class LinkedBlockingDequeTest ext
157       */
158      public void testPollLast() {
159          LinkedBlockingDeque q = populatedDeque(SIZE);
160 <        for (int i = SIZE-1; i >= 0; --i) {
160 >        for (int i = SIZE - 1; i >= 0; --i) {
161              assertEquals(i, q.pollLast());
162          }
163          assertNull(q.pollLast());
# Line 186 | Line 196 | public class LinkedBlockingDequeTest ext
196       */
197      public void testPeekLast() {
198          LinkedBlockingDeque q = populatedDeque(SIZE);
199 <        for (int i = SIZE-1; i >= 0; --i) {
199 >        for (int i = SIZE - 1; i >= 0; --i) {
200              assertEquals(i, q.peekLast());
201              assertEquals(i, q.pollLast());
202              assertTrue(q.peekLast() == null ||
# Line 216 | Line 226 | public class LinkedBlockingDequeTest ext
226       */
227      public void testLastElement() {
228          LinkedBlockingDeque q = populatedDeque(SIZE);
229 <        for (int i = SIZE-1; i >= 0; --i) {
229 >        for (int i = SIZE - 1; i >= 0; --i) {
230              assertEquals(i, q.getLast());
231              assertEquals(i, q.pollLast());
232          }
# Line 281 | Line 291 | public class LinkedBlockingDequeTest ext
291          }
292          for (int i = 0; i < SIZE; i += 2) {
293              assertTrue(q.removeFirstOccurrence(new Integer(i)));
294 <            assertFalse(q.removeFirstOccurrence(new Integer(i+1)));
294 >            assertFalse(q.removeFirstOccurrence(new Integer(i + 1)));
295          }
296          assertTrue(q.isEmpty());
297      }
# Line 296 | Line 306 | public class LinkedBlockingDequeTest ext
306          }
307          for (int i = 0; i < SIZE; i += 2) {
308              assertTrue(q.removeLastOccurrence(new Integer(i)));
309 <            assertFalse(q.removeLastOccurrence(new Integer(i+1)));
309 >            assertFalse(q.removeLastOccurrence(new Integer(i + 1)));
310          }
311          assertTrue(q.isEmpty());
312      }
# Line 367 | Line 377 | public class LinkedBlockingDequeTest ext
377       */
378      public void testConstructor5() {
379          Integer[] ints = new Integer[SIZE];
380 <        for (int i = 0; i < SIZE-1; ++i)
380 >        for (int i = 0; i < SIZE - 1; ++i)
381              ints[i] = i;
382          Collection<Integer> elements = Arrays.asList(ints);
383          try {
# Line 407 | Line 417 | public class LinkedBlockingDequeTest ext
417       * remainingCapacity decreases on add, increases on remove
418       */
419      public void testRemainingCapacity() {
420 <        LinkedBlockingDeque q = populatedDeque(SIZE);
420 >        BlockingQueue q = populatedDeque(SIZE);
421          for (int i = 0; i < SIZE; ++i) {
422              assertEquals(i, q.remainingCapacity());
423 <            assertEquals(SIZE-i, q.size());
424 <            q.remove();
423 >            assertEquals(SIZE, q.size() + q.remainingCapacity());
424 >            assertEquals(i, q.remove());
425          }
426          for (int i = 0; i < SIZE; ++i) {
427 <            assertEquals(SIZE-i, q.remainingCapacity());
428 <            assertEquals(i, q.size());
429 <            q.add(new Integer(i));
427 >            assertEquals(SIZE - i, q.remainingCapacity());
428 >            assertEquals(SIZE, q.size() + q.remainingCapacity());
429 >            assertTrue(q.add(i));
430          }
431      }
432  
# Line 424 | Line 434 | public class LinkedBlockingDequeTest ext
434       * push(null) throws NPE
435       */
436      public void testPushNull() {
437 +        LinkedBlockingDeque q = new LinkedBlockingDeque(1);
438          try {
428            LinkedBlockingDeque q = new LinkedBlockingDeque(1);
439              q.push(null);
440              shouldThrow();
441          } catch (NullPointerException success) {}
# Line 435 | Line 445 | public class LinkedBlockingDequeTest ext
445       * push succeeds if not full; throws ISE if full
446       */
447      public void testPush() {
448 +        LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
449 +        for (int i = 0; i < SIZE; ++i) {
450 +            Integer x = new Integer(i);
451 +            q.push(x);
452 +            assertEquals(x, q.peek());
453 +        }
454 +        assertEquals(0, q.remainingCapacity());
455          try {
439            LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
440            for (int i = 0; i < SIZE; ++i) {
441                Integer I = new Integer(i);
442                q.push(I);
443                assertEquals(I, q.peek());
444            }
445            assertEquals(0, q.remainingCapacity());
456              q.push(new Integer(SIZE));
457              shouldThrow();
458          } catch (IllegalStateException success) {}
# Line 513 | Line 523 | public class LinkedBlockingDequeTest ext
523      public void testAddAll3() {
524          LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
525          Integer[] ints = new Integer[SIZE];
526 <        for (int i = 0; i < SIZE-1; ++i)
526 >        for (int i = 0; i < SIZE - 1; ++i)
527              ints[i] = new Integer(i);
528          Collection<Integer> elements = Arrays.asList(ints);
529          try {
# Line 558 | Line 568 | public class LinkedBlockingDequeTest ext
568      public void testPut() throws InterruptedException {
569          LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
570          for (int i = 0; i < SIZE; ++i) {
571 <            Integer I = new Integer(i);
572 <            q.put(I);
573 <            assertTrue(q.contains(I));
571 >            Integer x = new Integer(i);
572 >            q.put(x);
573 >            assertTrue(q.contains(x));
574          }
575          assertEquals(0, q.remainingCapacity());
576      }
# Line 594 | Line 604 | public class LinkedBlockingDequeTest ext
604              }});
605  
606          await(pleaseInterrupt);
607 <        assertThreadStaysAlive(t);
607 >        assertThreadBlocks(t, Thread.State.WAITING);
608          t.interrupt();
609          awaitTermination(t);
610          assertEquals(SIZE, q.size());
# Line 629 | Line 639 | public class LinkedBlockingDequeTest ext
639          assertEquals(0, q.take());
640  
641          await(pleaseInterrupt);
642 <        assertThreadStaysAlive(t);
642 >        assertThreadBlocks(t, Thread.State.WAITING);
643          t.interrupt();
644          awaitTermination(t);
645          assertEquals(0, q.remainingCapacity());
# Line 653 | Line 663 | public class LinkedBlockingDequeTest ext
663                      q.offer(new Object(), 2 * LONG_DELAY_MS, MILLISECONDS);
664                      shouldThrow();
665                  } catch (InterruptedException success) {}
666 +                assertFalse(Thread.interrupted());
667              }});
668  
669          await(pleaseInterrupt);
670 <        assertThreadStaysAlive(t);
670 >        assertThreadBlocks(t, Thread.State.TIMED_WAITING);
671          t.interrupt();
672          awaitTermination(t);
673      }
# Line 679 | Line 690 | public class LinkedBlockingDequeTest ext
690          final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
691          Thread t = newStartedThread(new CheckedRunnable() {
692              public void realRun() throws InterruptedException {
693 <                for (int i = 0; i < SIZE; ++i) {
683 <                    assertEquals(i, q.take());
684 <                }
693 >                for (int i = 0; i < SIZE; i++) assertEquals(i, q.take());
694  
695                  Thread.currentThread().interrupt();
696                  try {
# Line 699 | Line 708 | public class LinkedBlockingDequeTest ext
708              }});
709  
710          await(pleaseInterrupt);
711 <        assertThreadStaysAlive(t);
711 >        assertThreadBlocks(t, Thread.State.WAITING);
712          t.interrupt();
713          awaitTermination(t);
714      }
# Line 748 | Line 757 | public class LinkedBlockingDequeTest ext
757       */
758      public void testInterruptedTimedPoll() throws InterruptedException {
759          final BlockingQueue<Integer> q = populatedDeque(SIZE);
760 <        final CountDownLatch aboutToWait = new CountDownLatch(1);
760 >        final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
761          Thread t = newStartedThread(new CheckedRunnable() {
762              public void realRun() throws InterruptedException {
763 +                long startTime = System.nanoTime();
764                  for (int i = 0; i < SIZE; ++i) {
755                    long t0 = System.nanoTime();
765                      assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS));
757                    assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS);
766                  }
767 <                long t0 = System.nanoTime();
768 <                aboutToWait.countDown();
767 >
768 >                pleaseInterrupt.countDown();
769                  try {
770 <                    q.poll(MEDIUM_DELAY_MS, MILLISECONDS);
770 >                    q.poll(LONG_DELAY_MS, MILLISECONDS);
771                      shouldThrow();
772 <                } catch (InterruptedException success) {
773 <                    assertTrue(millisElapsedSince(t0) < MEDIUM_DELAY_MS);
774 <                }
772 >                } catch (InterruptedException success) {}
773 >                assertFalse(Thread.interrupted());
774 >
775 >                assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
776              }});
777  
778 <        aboutToWait.await();
779 <        waitForThreadToEnterWaitState(t, SMALL_DELAY_MS);
778 >        await(pleaseInterrupt);
779 >        assertThreadBlocks(t, Thread.State.TIMED_WAITING);
780          t.interrupt();
781 <        awaitTermination(t, MEDIUM_DELAY_MS);
781 >        awaitTermination(t);
782          checkEmpty(q);
783      }
784  
# Line 790 | Line 799 | public class LinkedBlockingDequeTest ext
799      public void testPutFirst() throws InterruptedException {
800          LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
801          for (int i = 0; i < SIZE; ++i) {
802 <            Integer I = new Integer(i);
803 <            q.putFirst(I);
804 <            assertTrue(q.contains(I));
802 >            Integer x = new Integer(i);
803 >            q.putFirst(x);
804 >            assertTrue(q.contains(x));
805          }
806          assertEquals(0, q.remainingCapacity());
807      }
# Line 826 | Line 835 | public class LinkedBlockingDequeTest ext
835              }});
836  
837          await(pleaseInterrupt);
838 <        assertThreadStaysAlive(t);
838 >        assertThreadBlocks(t, Thread.State.WAITING);
839          t.interrupt();
840          awaitTermination(t);
841          assertEquals(SIZE, q.size());
# Line 861 | Line 870 | public class LinkedBlockingDequeTest ext
870          assertEquals(capacity - 1, q.take());
871  
872          await(pleaseInterrupt);
873 <        assertThreadStaysAlive(t);
873 >        assertThreadBlocks(t, Thread.State.WAITING);
874          t.interrupt();
875          awaitTermination(t);
876          assertEquals(0, q.remainingCapacity());
# Line 885 | Line 894 | public class LinkedBlockingDequeTest ext
894                      q.offerFirst(new Object(), 2 * LONG_DELAY_MS, MILLISECONDS);
895                      shouldThrow();
896                  } catch (InterruptedException success) {}
897 +                assertFalse(Thread.interrupted());
898              }});
899  
900          await(pleaseInterrupt);
901 <        assertThreadStaysAlive(t);
901 >        assertThreadBlocks(t, Thread.State.TIMED_WAITING);
902          t.interrupt();
903          awaitTermination(t);
904      }
# Line 920 | Line 930 | public class LinkedBlockingDequeTest ext
930              }});
931  
932          await(threadStarted);
933 <        assertThreadStaysAlive(t);
933 >        assertThreadBlocks(t, Thread.State.WAITING);
934          t.interrupt();
935          awaitTermination(t);
936      }
# Line 961 | Line 971 | public class LinkedBlockingDequeTest ext
971              }});
972  
973          await(threadStarted);
974 <        assertThreadStaysAlive(t);
974 >        assertThreadBlocks(t, Thread.State.WAITING);
975          t.interrupt();
976          awaitTermination(t);
977      }
# Line 993 | Line 1003 | public class LinkedBlockingDequeTest ext
1003          final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
1004          Thread t = newStartedThread(new CheckedRunnable() {
1005              public void realRun() throws InterruptedException {
1006 <                for (int i = 0; i < SIZE; ++i) {
997 <                    assertEquals(i, q.takeFirst());
998 <                }
1006 >                for (int i = 0; i < SIZE; i++) assertEquals(i, q.takeFirst());
1007  
1008                  Thread.currentThread().interrupt();
1009                  try {
# Line 1013 | Line 1021 | public class LinkedBlockingDequeTest ext
1021              }});
1022  
1023          await(pleaseInterrupt);
1024 <        assertThreadStaysAlive(t);
1024 >        assertThreadBlocks(t, Thread.State.WAITING);
1025          t.interrupt();
1026          awaitTermination(t);
1027      }
# Line 1050 | Line 1058 | public class LinkedBlockingDequeTest ext
1058       * returning timeout status
1059       */
1060      public void testInterruptedTimedPollFirst() throws InterruptedException {
1061 +        final LinkedBlockingDeque q = populatedDeque(SIZE);
1062          final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
1063          Thread t = newStartedThread(new CheckedRunnable() {
1064              public void realRun() throws InterruptedException {
1065 <                LinkedBlockingDeque q = populatedDeque(SIZE);
1065 >                long startTime = System.nanoTime();
1066                  for (int i = 0; i < SIZE; ++i) {
1067                      assertEquals(i, q.pollFirst(LONG_DELAY_MS, MILLISECONDS));
1068                  }
1069  
1070                  Thread.currentThread().interrupt();
1071                  try {
1072 <                    q.pollFirst(SMALL_DELAY_MS, MILLISECONDS);
1072 >                    q.pollFirst(LONG_DELAY_MS, MILLISECONDS);
1073                      shouldThrow();
1074                  } catch (InterruptedException success) {}
1075                  assertFalse(Thread.interrupted());
# Line 1071 | Line 1080 | public class LinkedBlockingDequeTest ext
1080                      shouldThrow();
1081                  } catch (InterruptedException success) {}
1082                  assertFalse(Thread.interrupted());
1083 +
1084 +                assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
1085              }});
1086  
1087          await(pleaseInterrupt);
1088 <        assertThreadStaysAlive(t);
1088 >        assertThreadBlocks(t, Thread.State.TIMED_WAITING);
1089          t.interrupt();
1090          awaitTermination(t);
1091      }
# Line 1107 | Line 1118 | public class LinkedBlockingDequeTest ext
1118                      q.pollFirst(LONG_DELAY_MS, MILLISECONDS);
1119                      shouldThrow();
1120                  } catch (InterruptedException success) {}
1121 +                assertFalse(Thread.interrupted());
1122                  assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
1123              }});
1124  
# Line 1115 | Line 1127 | public class LinkedBlockingDequeTest ext
1127          assertTrue(q.offerFirst(zero, LONG_DELAY_MS, MILLISECONDS));
1128          assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
1129          barrier.await();
1130 <        assertThreadStaysAlive(t);
1130 >        assertThreadBlocks(t, Thread.State.TIMED_WAITING);
1131          t.interrupt();
1132          awaitTermination(t);
1133      }
# Line 1137 | Line 1149 | public class LinkedBlockingDequeTest ext
1149      public void testPutLast() throws InterruptedException {
1150          LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
1151          for (int i = 0; i < SIZE; ++i) {
1152 <            Integer I = new Integer(i);
1153 <            q.putLast(I);
1154 <            assertTrue(q.contains(I));
1152 >            Integer x = new Integer(i);
1153 >            q.putLast(x);
1154 >            assertTrue(q.contains(x));
1155          }
1156          assertEquals(0, q.remainingCapacity());
1157      }
# Line 1173 | Line 1185 | public class LinkedBlockingDequeTest ext
1185              }});
1186  
1187          await(pleaseInterrupt);
1188 <        assertThreadStaysAlive(t);
1188 >        assertThreadBlocks(t, Thread.State.WAITING);
1189          t.interrupt();
1190          awaitTermination(t);
1191          assertEquals(SIZE, q.size());
# Line 1208 | Line 1220 | public class LinkedBlockingDequeTest ext
1220          assertEquals(0, q.take());
1221  
1222          await(pleaseInterrupt);
1223 <        assertThreadStaysAlive(t);
1223 >        assertThreadBlocks(t, Thread.State.WAITING);
1224          t.interrupt();
1225          awaitTermination(t);
1226          assertEquals(0, q.remainingCapacity());
# Line 1235 | Line 1247 | public class LinkedBlockingDequeTest ext
1247              }});
1248  
1249          await(pleaseInterrupt);
1250 <        assertThreadStaysAlive(t);
1250 >        assertThreadBlocks(t, Thread.State.TIMED_WAITING);
1251          t.interrupt();
1252          awaitTermination(t);
1253      }
# Line 1246 | Line 1258 | public class LinkedBlockingDequeTest ext
1258      public void testTakeLast() throws InterruptedException {
1259          LinkedBlockingDeque q = populatedDeque(SIZE);
1260          for (int i = 0; i < SIZE; ++i) {
1261 <            assertEquals(SIZE-i-1, q.takeLast());
1261 >            assertEquals(SIZE - i - 1, q.takeLast());
1262          }
1263      }
1264  
# Line 1258 | Line 1270 | public class LinkedBlockingDequeTest ext
1270          final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
1271          Thread t = newStartedThread(new CheckedRunnable() {
1272              public void realRun() throws InterruptedException {
1273 <                for (int i = 0; i < SIZE; ++i) {
1274 <                    assertEquals(SIZE-i-1, q.takeLast());
1263 <                }
1273 >                for (int i = 0; i < SIZE; i++)
1274 >                    assertEquals(SIZE - i - 1, q.takeLast());
1275  
1276                  Thread.currentThread().interrupt();
1277                  try {
# Line 1278 | Line 1289 | public class LinkedBlockingDequeTest ext
1289              }});
1290  
1291          await(pleaseInterrupt);
1292 <        assertThreadStaysAlive(t);
1292 >        assertThreadBlocks(t, Thread.State.WAITING);
1293          t.interrupt();
1294          awaitTermination(t);
1295      }
# Line 1289 | Line 1300 | public class LinkedBlockingDequeTest ext
1300      public void testTimedPollLast0() throws InterruptedException {
1301          LinkedBlockingDeque q = populatedDeque(SIZE);
1302          for (int i = 0; i < SIZE; ++i) {
1303 <            assertEquals(SIZE-i-1, q.pollLast(0, MILLISECONDS));
1303 >            assertEquals(SIZE - i - 1, q.pollLast(0, MILLISECONDS));
1304          }
1305          assertNull(q.pollLast(0, MILLISECONDS));
1306      }
# Line 1301 | Line 1312 | public class LinkedBlockingDequeTest ext
1312          LinkedBlockingDeque q = populatedDeque(SIZE);
1313          for (int i = 0; i < SIZE; ++i) {
1314              long startTime = System.nanoTime();
1315 <            assertEquals(SIZE-i-1, q.pollLast(LONG_DELAY_MS, MILLISECONDS));
1315 >            assertEquals(SIZE - i - 1, q.pollLast(LONG_DELAY_MS, MILLISECONDS));
1316              assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
1317          }
1318          long startTime = System.nanoTime();
# Line 1315 | Line 1326 | public class LinkedBlockingDequeTest ext
1326       * returning timeout status
1327       */
1328      public void testInterruptedTimedPollLast() throws InterruptedException {
1329 +        final LinkedBlockingDeque q = populatedDeque(SIZE);
1330          final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
1331          Thread t = newStartedThread(new CheckedRunnable() {
1332              public void realRun() throws InterruptedException {
1333 <                LinkedBlockingDeque q = populatedDeque(SIZE);
1333 >                long startTime = System.nanoTime();
1334                  for (int i = 0; i < SIZE; ++i) {
1335 <                    assertEquals(SIZE-i-1, q.pollLast(LONG_DELAY_MS, MILLISECONDS));
1335 >                    assertEquals(SIZE - i - 1,
1336 >                                 q.pollLast(LONG_DELAY_MS, MILLISECONDS));
1337                  }
1338  
1339                  Thread.currentThread().interrupt();
# Line 1336 | Line 1349 | public class LinkedBlockingDequeTest ext
1349                      shouldThrow();
1350                  } catch (InterruptedException success) {}
1351                  assertFalse(Thread.interrupted());
1352 +
1353 +                assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
1354              }});
1355  
1356          await(pleaseInterrupt);
1357 <        assertThreadStaysAlive(t);
1357 >        assertThreadBlocks(t, Thread.State.TIMED_WAITING);
1358          t.interrupt();
1359          awaitTermination(t);
1360 +        checkEmpty(q);
1361      }
1362  
1363      /**
# Line 1374 | Line 1390 | public class LinkedBlockingDequeTest ext
1390                      shouldThrow();
1391                  } catch (InterruptedException success) {}
1392                  assertFalse(Thread.interrupted());
1393 +
1394 +                assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
1395              }});
1396  
1397          barrier.await();
# Line 1382 | Line 1400 | public class LinkedBlockingDequeTest ext
1400          assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
1401  
1402          barrier.await();
1403 <        assertThreadStaysAlive(t);
1403 >        assertThreadBlocks(t, Thread.State.TIMED_WAITING);
1404          t.interrupt();
1405          awaitTermination(t);
1406      }
# Line 1458 | Line 1476 | public class LinkedBlockingDequeTest ext
1476                  assertTrue(changed);
1477  
1478              assertTrue(q.containsAll(p));
1479 <            assertEquals(SIZE-i, q.size());
1479 >            assertEquals(SIZE - i, q.size());
1480              p.remove();
1481          }
1482      }
# Line 1471 | Line 1489 | public class LinkedBlockingDequeTest ext
1489              LinkedBlockingDeque q = populatedDeque(SIZE);
1490              LinkedBlockingDeque p = populatedDeque(i);
1491              assertTrue(q.removeAll(p));
1492 <            assertEquals(SIZE-i, q.size());
1492 >            assertEquals(SIZE - i, q.size());
1493              for (int j = 0; j < i; ++j) {
1494 <                Integer I = (Integer)(p.remove());
1495 <                assertFalse(q.contains(I));
1494 >                Integer x = (Integer)(p.remove());
1495 >                assertFalse(q.contains(x));
1496              }
1497          }
1498      }
# Line 1518 | Line 1536 | public class LinkedBlockingDequeTest ext
1536      public void testIterator() throws InterruptedException {
1537          LinkedBlockingDeque q = populatedDeque(SIZE);
1538          Iterator it = q.iterator();
1539 <        while (it.hasNext()) {
1539 >        int i;
1540 >        for (i = 0; it.hasNext(); i++)
1541 >            assertTrue(q.contains(it.next()));
1542 >        assertEquals(i, SIZE);
1543 >        assertIteratorExhausted(it);
1544 >
1545 >        it = q.iterator();
1546 >        for (i = 0; it.hasNext(); i++)
1547              assertEquals(it.next(), q.take());
1548 <        }
1548 >        assertEquals(i, SIZE);
1549 >        assertIteratorExhausted(it);
1550 >    }
1551 >
1552 >    /**
1553 >     * iterator of empty collection has no elements
1554 >     */
1555 >    public void testEmptyIterator() {
1556 >        Deque c = new LinkedBlockingDeque();
1557 >        assertIteratorExhausted(c.iterator());
1558 >        assertIteratorExhausted(c.descendingIterator());
1559      }
1560  
1561      /**
# Line 1653 | Line 1688 | public class LinkedBlockingDequeTest ext
1688          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
1689          q.add(one);
1690          q.add(two);
1656        ExecutorService executor = Executors.newFixedThreadPool(2);
1691          final CheckedBarrier threadsStarted = new CheckedBarrier(2);
1692 <        executor.execute(new CheckedRunnable() {
1693 <            public void realRun() throws InterruptedException {
1694 <                assertFalse(q.offer(three));
1695 <                threadsStarted.await();
1696 <                assertTrue(q.offer(three, LONG_DELAY_MS, MILLISECONDS));
1697 <                assertEquals(0, q.remainingCapacity());
1698 <            }});
1699 <
1700 <        executor.execute(new CheckedRunnable() {
1701 <            public void realRun() throws InterruptedException {
1702 <                threadsStarted.await();
1703 <                assertSame(one, q.take());
1704 <            }});
1705 <
1706 <        joinPool(executor);
1692 >        final ExecutorService executor = Executors.newFixedThreadPool(2);
1693 >        try (PoolCleaner cleaner = cleaner(executor)) {
1694 >            executor.execute(new CheckedRunnable() {
1695 >                public void realRun() throws InterruptedException {
1696 >                    assertFalse(q.offer(three));
1697 >                    threadsStarted.await();
1698 >                    assertTrue(q.offer(three, LONG_DELAY_MS, MILLISECONDS));
1699 >                    assertEquals(0, q.remainingCapacity());
1700 >                }});
1701 >
1702 >            executor.execute(new CheckedRunnable() {
1703 >                public void realRun() throws InterruptedException {
1704 >                    threadsStarted.await();
1705 >                    assertSame(one, q.take());
1706 >                }});
1707 >        }
1708      }
1709  
1710      /**
# Line 1678 | Line 1713 | public class LinkedBlockingDequeTest ext
1713      public void testPollInExecutor() {
1714          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
1715          final CheckedBarrier threadsStarted = new CheckedBarrier(2);
1716 <        ExecutorService executor = Executors.newFixedThreadPool(2);
1717 <        executor.execute(new CheckedRunnable() {
1718 <            public void realRun() throws InterruptedException {
1719 <                assertNull(q.poll());
1720 <                threadsStarted.await();
1721 <                assertSame(one, q.poll(LONG_DELAY_MS, MILLISECONDS));
1722 <                checkEmpty(q);
1723 <            }});
1724 <
1725 <        executor.execute(new CheckedRunnable() {
1726 <            public void realRun() throws InterruptedException {
1727 <                threadsStarted.await();
1728 <                q.put(one);
1729 <            }});
1730 <
1731 <        joinPool(executor);
1716 >        final ExecutorService executor = Executors.newFixedThreadPool(2);
1717 >        try (PoolCleaner cleaner = cleaner(executor)) {
1718 >            executor.execute(new CheckedRunnable() {
1719 >                public void realRun() throws InterruptedException {
1720 >                    assertNull(q.poll());
1721 >                    threadsStarted.await();
1722 >                    assertSame(one, q.poll(LONG_DELAY_MS, MILLISECONDS));
1723 >                    checkEmpty(q);
1724 >                }});
1725 >
1726 >            executor.execute(new CheckedRunnable() {
1727 >                public void realRun() throws InterruptedException {
1728 >                    threadsStarted.await();
1729 >                    q.put(one);
1730 >                }});
1731 >        }
1732      }
1733  
1734      /**
# Line 1745 | Line 1780 | public class LinkedBlockingDequeTest ext
1780          final LinkedBlockingDeque q = populatedDeque(SIZE);
1781          Thread t = new Thread(new CheckedRunnable() {
1782              public void realRun() throws InterruptedException {
1783 <                q.put(new Integer(SIZE+1));
1783 >                q.put(new Integer(SIZE + 1));
1784              }});
1785  
1786          t.start();
# Line 1770 | Line 1805 | public class LinkedBlockingDequeTest ext
1805              q.drainTo(l, i);
1806              int k = (i < SIZE) ? i : SIZE;
1807              assertEquals(k, l.size());
1808 <            assertEquals(SIZE-k, q.size());
1808 >            assertEquals(SIZE - k, q.size());
1809              for (int j = 0; j < k; ++j)
1810                  assertEquals(l.get(j), new Integer(j));
1811              do {} while (q.poll() != null);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines