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.57 by jsr166, Sat Apr 25 04:55:31 2015 UTC vs.
Revision 1.79 by jsr166, Sun May 14 04:02:06 2017 UTC

# Line 41 | Line 41 | public class LinkedBlockingDequeTest ext
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 414 | Line 424 | public class LinkedBlockingDequeTest ext
424              assertEquals(i, q.remove());
425          }
426          for (int i = 0; i < SIZE; ++i) {
427 <            assertEquals(SIZE-i, q.remainingCapacity());
427 >            assertEquals(SIZE - i, q.remainingCapacity());
428              assertEquals(SIZE, q.size() + q.remainingCapacity());
429              assertTrue(q.add(i));
430          }
# 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 x = new Integer(i);
442                q.push(x);
443                assertEquals(x, 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 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 616 | Line 626 | public class LinkedBlockingDequeTest ext
626                  pleaseTake.countDown();
627                  q.put(86);
628  
629 +                Thread.currentThread().interrupt();
630 +                try {
631 +                    q.put(99);
632 +                    shouldThrow();
633 +                } catch (InterruptedException success) {}
634 +                assertFalse(Thread.interrupted());
635 +
636                  pleaseInterrupt.countDown();
637                  try {
638                      q.put(99);
# Line 629 | Line 646 | public class LinkedBlockingDequeTest ext
646          assertEquals(0, q.take());
647  
648          await(pleaseInterrupt);
649 <        assertThreadStaysAlive(t);
649 >        assertThreadBlocks(t, Thread.State.WAITING);
650          t.interrupt();
651          awaitTermination(t);
652          assertEquals(0, q.remainingCapacity());
# Line 653 | Line 670 | public class LinkedBlockingDequeTest ext
670                      q.offer(new Object(), 2 * LONG_DELAY_MS, MILLISECONDS);
671                      shouldThrow();
672                  } catch (InterruptedException success) {}
673 +                assertFalse(Thread.interrupted());
674              }});
675  
676          await(pleaseInterrupt);
677 <        assertThreadStaysAlive(t);
677 >        assertThreadBlocks(t, Thread.State.TIMED_WAITING);
678          t.interrupt();
679          awaitTermination(t);
680      }
# Line 679 | Line 697 | public class LinkedBlockingDequeTest ext
697          final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
698          Thread t = newStartedThread(new CheckedRunnable() {
699              public void realRun() throws InterruptedException {
700 <                for (int i = 0; i < SIZE; ++i) {
683 <                    assertEquals(i, q.take());
684 <                }
700 >                for (int i = 0; i < SIZE; i++) assertEquals(i, q.take());
701  
702                  Thread.currentThread().interrupt();
703                  try {
# Line 699 | Line 715 | public class LinkedBlockingDequeTest ext
715              }});
716  
717          await(pleaseInterrupt);
718 <        assertThreadStaysAlive(t);
718 >        assertThreadBlocks(t, Thread.State.WAITING);
719          t.interrupt();
720          awaitTermination(t);
721      }
# Line 748 | Line 764 | public class LinkedBlockingDequeTest ext
764       */
765      public void testInterruptedTimedPoll() throws InterruptedException {
766          final BlockingQueue<Integer> q = populatedDeque(SIZE);
767 <        final CountDownLatch aboutToWait = new CountDownLatch(1);
767 >        final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
768          Thread t = newStartedThread(new CheckedRunnable() {
769              public void realRun() throws InterruptedException {
770 <                for (int i = 0; i < SIZE; ++i) {
771 <                    long t0 = System.nanoTime();
770 >                long startTime = System.nanoTime();
771 >                for (int i = 0; i < SIZE; i++)
772                      assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS));
773 <                    assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS);
774 <                }
775 <                long t0 = System.nanoTime();
776 <                aboutToWait.countDown();
773 >
774 >                Thread.currentThread().interrupt();
775 >                try {
776 >                    q.poll(LONG_DELAY_MS, MILLISECONDS);
777 >                    shouldThrow();
778 >                } catch (InterruptedException success) {}
779 >                assertFalse(Thread.interrupted());
780 >
781 >                pleaseInterrupt.countDown();
782                  try {
783 <                    q.poll(MEDIUM_DELAY_MS, MILLISECONDS);
783 >                    q.poll(LONG_DELAY_MS, MILLISECONDS);
784                      shouldThrow();
785 <                } catch (InterruptedException success) {
786 <                    assertTrue(millisElapsedSince(t0) < MEDIUM_DELAY_MS);
787 <                }
785 >                } catch (InterruptedException success) {}
786 >                assertFalse(Thread.interrupted());
787 >
788 >                assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
789              }});
790  
791 <        aboutToWait.await();
792 <        waitForThreadToEnterWaitState(t, SMALL_DELAY_MS);
791 >        await(pleaseInterrupt);
792 >        assertThreadBlocks(t, Thread.State.TIMED_WAITING);
793          t.interrupt();
794 <        awaitTermination(t, MEDIUM_DELAY_MS);
794 >        awaitTermination(t);
795          checkEmpty(q);
796      }
797  
# Line 826 | Line 848 | public class LinkedBlockingDequeTest ext
848              }});
849  
850          await(pleaseInterrupt);
851 <        assertThreadStaysAlive(t);
851 >        assertThreadBlocks(t, Thread.State.WAITING);
852          t.interrupt();
853          awaitTermination(t);
854          assertEquals(SIZE, q.size());
# Line 861 | Line 883 | public class LinkedBlockingDequeTest ext
883          assertEquals(capacity - 1, q.take());
884  
885          await(pleaseInterrupt);
886 <        assertThreadStaysAlive(t);
886 >        assertThreadBlocks(t, Thread.State.WAITING);
887          t.interrupt();
888          awaitTermination(t);
889          assertEquals(0, q.remainingCapacity());
# Line 885 | Line 907 | public class LinkedBlockingDequeTest ext
907                      q.offerFirst(new Object(), 2 * LONG_DELAY_MS, MILLISECONDS);
908                      shouldThrow();
909                  } catch (InterruptedException success) {}
910 +                assertFalse(Thread.interrupted());
911              }});
912  
913          await(pleaseInterrupt);
914 <        assertThreadStaysAlive(t);
914 >        assertThreadBlocks(t, Thread.State.TIMED_WAITING);
915          t.interrupt();
916          awaitTermination(t);
917      }
# Line 920 | Line 943 | public class LinkedBlockingDequeTest ext
943              }});
944  
945          await(threadStarted);
946 <        assertThreadStaysAlive(t);
946 >        assertThreadBlocks(t, Thread.State.WAITING);
947          t.interrupt();
948          awaitTermination(t);
949      }
# Line 961 | Line 984 | public class LinkedBlockingDequeTest ext
984              }});
985  
986          await(threadStarted);
987 <        assertThreadStaysAlive(t);
987 >        assertThreadBlocks(t, Thread.State.WAITING);
988          t.interrupt();
989          awaitTermination(t);
990      }
# Line 993 | Line 1016 | public class LinkedBlockingDequeTest ext
1016          final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
1017          Thread t = newStartedThread(new CheckedRunnable() {
1018              public void realRun() throws InterruptedException {
1019 <                for (int i = 0; i < SIZE; ++i) {
997 <                    assertEquals(i, q.takeFirst());
998 <                }
1019 >                for (int i = 0; i < SIZE; i++) assertEquals(i, q.takeFirst());
1020  
1021                  Thread.currentThread().interrupt();
1022                  try {
# Line 1013 | Line 1034 | public class LinkedBlockingDequeTest ext
1034              }});
1035  
1036          await(pleaseInterrupt);
1037 <        assertThreadStaysAlive(t);
1037 >        assertThreadBlocks(t, Thread.State.WAITING);
1038          t.interrupt();
1039          awaitTermination(t);
1040      }
# Line 1050 | Line 1071 | public class LinkedBlockingDequeTest ext
1071       * returning timeout status
1072       */
1073      public void testInterruptedTimedPollFirst() throws InterruptedException {
1074 +        final LinkedBlockingDeque q = populatedDeque(SIZE);
1075          final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
1076          Thread t = newStartedThread(new CheckedRunnable() {
1077              public void realRun() throws InterruptedException {
1078 <                LinkedBlockingDeque q = populatedDeque(SIZE);
1079 <                for (int i = 0; i < SIZE; ++i) {
1078 >                long startTime = System.nanoTime();
1079 >                for (int i = 0; i < SIZE; i++)
1080                      assertEquals(i, q.pollFirst(LONG_DELAY_MS, MILLISECONDS));
1059                }
1081  
1082                  Thread.currentThread().interrupt();
1083                  try {
1084 <                    q.pollFirst(SMALL_DELAY_MS, MILLISECONDS);
1084 >                    q.pollFirst(LONG_DELAY_MS, MILLISECONDS);
1085                      shouldThrow();
1086                  } catch (InterruptedException success) {}
1087                  assertFalse(Thread.interrupted());
# Line 1071 | Line 1092 | public class LinkedBlockingDequeTest ext
1092                      shouldThrow();
1093                  } catch (InterruptedException success) {}
1094                  assertFalse(Thread.interrupted());
1095 +
1096 +                assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
1097              }});
1098  
1099          await(pleaseInterrupt);
1100 <        assertThreadStaysAlive(t);
1100 >        assertThreadBlocks(t, Thread.State.TIMED_WAITING);
1101          t.interrupt();
1102          awaitTermination(t);
1103      }
# Line 1107 | Line 1130 | public class LinkedBlockingDequeTest ext
1130                      q.pollFirst(LONG_DELAY_MS, MILLISECONDS);
1131                      shouldThrow();
1132                  } catch (InterruptedException success) {}
1133 +                assertFalse(Thread.interrupted());
1134                  assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
1135              }});
1136  
# Line 1115 | Line 1139 | public class LinkedBlockingDequeTest ext
1139          assertTrue(q.offerFirst(zero, LONG_DELAY_MS, MILLISECONDS));
1140          assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
1141          barrier.await();
1142 <        assertThreadStaysAlive(t);
1142 >        assertThreadBlocks(t, Thread.State.TIMED_WAITING);
1143          t.interrupt();
1144          awaitTermination(t);
1145      }
# Line 1173 | Line 1197 | public class LinkedBlockingDequeTest ext
1197              }});
1198  
1199          await(pleaseInterrupt);
1200 <        assertThreadStaysAlive(t);
1200 >        assertThreadBlocks(t, Thread.State.WAITING);
1201          t.interrupt();
1202          awaitTermination(t);
1203          assertEquals(SIZE, q.size());
# Line 1208 | Line 1232 | public class LinkedBlockingDequeTest ext
1232          assertEquals(0, q.take());
1233  
1234          await(pleaseInterrupt);
1235 <        assertThreadStaysAlive(t);
1235 >        assertThreadBlocks(t, Thread.State.WAITING);
1236          t.interrupt();
1237          awaitTermination(t);
1238          assertEquals(0, q.remainingCapacity());
# Line 1235 | Line 1259 | public class LinkedBlockingDequeTest ext
1259              }});
1260  
1261          await(pleaseInterrupt);
1262 <        assertThreadStaysAlive(t);
1262 >        assertThreadBlocks(t, Thread.State.TIMED_WAITING);
1263          t.interrupt();
1264          awaitTermination(t);
1265      }
# Line 1246 | Line 1270 | public class LinkedBlockingDequeTest ext
1270      public void testTakeLast() throws InterruptedException {
1271          LinkedBlockingDeque q = populatedDeque(SIZE);
1272          for (int i = 0; i < SIZE; ++i) {
1273 <            assertEquals(SIZE-i-1, q.takeLast());
1273 >            assertEquals(SIZE - i - 1, q.takeLast());
1274          }
1275      }
1276  
# Line 1258 | Line 1282 | public class LinkedBlockingDequeTest ext
1282          final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
1283          Thread t = newStartedThread(new CheckedRunnable() {
1284              public void realRun() throws InterruptedException {
1285 <                for (int i = 0; i < SIZE; ++i) {
1286 <                    assertEquals(SIZE-i-1, q.takeLast());
1263 <                }
1285 >                for (int i = 0; i < SIZE; i++)
1286 >                    assertEquals(SIZE - i - 1, q.takeLast());
1287  
1288                  Thread.currentThread().interrupt();
1289                  try {
# Line 1278 | Line 1301 | public class LinkedBlockingDequeTest ext
1301              }});
1302  
1303          await(pleaseInterrupt);
1304 <        assertThreadStaysAlive(t);
1304 >        assertThreadBlocks(t, Thread.State.WAITING);
1305          t.interrupt();
1306          awaitTermination(t);
1307      }
# Line 1289 | Line 1312 | public class LinkedBlockingDequeTest ext
1312      public void testTimedPollLast0() throws InterruptedException {
1313          LinkedBlockingDeque q = populatedDeque(SIZE);
1314          for (int i = 0; i < SIZE; ++i) {
1315 <            assertEquals(SIZE-i-1, q.pollLast(0, MILLISECONDS));
1315 >            assertEquals(SIZE - i - 1, q.pollLast(0, MILLISECONDS));
1316          }
1317          assertNull(q.pollLast(0, MILLISECONDS));
1318      }
# Line 1301 | Line 1324 | public class LinkedBlockingDequeTest ext
1324          LinkedBlockingDeque q = populatedDeque(SIZE);
1325          for (int i = 0; i < SIZE; ++i) {
1326              long startTime = System.nanoTime();
1327 <            assertEquals(SIZE-i-1, q.pollLast(LONG_DELAY_MS, MILLISECONDS));
1327 >            assertEquals(SIZE - i - 1, q.pollLast(LONG_DELAY_MS, MILLISECONDS));
1328              assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
1329          }
1330          long startTime = System.nanoTime();
# Line 1315 | Line 1338 | public class LinkedBlockingDequeTest ext
1338       * returning timeout status
1339       */
1340      public void testInterruptedTimedPollLast() throws InterruptedException {
1341 +        final LinkedBlockingDeque q = populatedDeque(SIZE);
1342          final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
1343          Thread t = newStartedThread(new CheckedRunnable() {
1344              public void realRun() throws InterruptedException {
1345 <                LinkedBlockingDeque q = populatedDeque(SIZE);
1346 <                for (int i = 0; i < SIZE; ++i) {
1347 <                    assertEquals(SIZE-i-1, q.pollLast(LONG_DELAY_MS, MILLISECONDS));
1348 <                }
1345 >                long startTime = System.nanoTime();
1346 >                for (int i = 0; i < SIZE; i++)
1347 >                    assertEquals(SIZE - i - 1,
1348 >                                 q.pollLast(LONG_DELAY_MS, MILLISECONDS));
1349  
1350                  Thread.currentThread().interrupt();
1351                  try {
# Line 1336 | Line 1360 | public class LinkedBlockingDequeTest ext
1360                      shouldThrow();
1361                  } catch (InterruptedException success) {}
1362                  assertFalse(Thread.interrupted());
1363 +
1364 +                assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
1365              }});
1366  
1367          await(pleaseInterrupt);
1368 <        assertThreadStaysAlive(t);
1368 >        assertThreadBlocks(t, Thread.State.TIMED_WAITING);
1369          t.interrupt();
1370          awaitTermination(t);
1371 +        checkEmpty(q);
1372      }
1373  
1374      /**
# Line 1374 | Line 1401 | public class LinkedBlockingDequeTest ext
1401                      shouldThrow();
1402                  } catch (InterruptedException success) {}
1403                  assertFalse(Thread.interrupted());
1404 +
1405 +                assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
1406              }});
1407  
1408          barrier.await();
# Line 1382 | Line 1411 | public class LinkedBlockingDequeTest ext
1411          assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
1412  
1413          barrier.await();
1414 <        assertThreadStaysAlive(t);
1414 >        assertThreadBlocks(t, Thread.State.TIMED_WAITING);
1415          t.interrupt();
1416          awaitTermination(t);
1417      }
# Line 1458 | Line 1487 | public class LinkedBlockingDequeTest ext
1487                  assertTrue(changed);
1488  
1489              assertTrue(q.containsAll(p));
1490 <            assertEquals(SIZE-i, q.size());
1490 >            assertEquals(SIZE - i, q.size());
1491              p.remove();
1492          }
1493      }
# Line 1471 | Line 1500 | public class LinkedBlockingDequeTest ext
1500              LinkedBlockingDeque q = populatedDeque(SIZE);
1501              LinkedBlockingDeque p = populatedDeque(i);
1502              assertTrue(q.removeAll(p));
1503 <            assertEquals(SIZE-i, q.size());
1503 >            assertEquals(SIZE - i, q.size());
1504              for (int j = 0; j < i; ++j) {
1505                  Integer x = (Integer)(p.remove());
1506                  assertFalse(q.contains(x));
# Line 1670 | Line 1699 | public class LinkedBlockingDequeTest ext
1699          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
1700          q.add(one);
1701          q.add(two);
1673        ExecutorService executor = Executors.newFixedThreadPool(2);
1702          final CheckedBarrier threadsStarted = new CheckedBarrier(2);
1703 <        executor.execute(new CheckedRunnable() {
1704 <            public void realRun() throws InterruptedException {
1705 <                assertFalse(q.offer(three));
1706 <                threadsStarted.await();
1707 <                assertTrue(q.offer(three, LONG_DELAY_MS, MILLISECONDS));
1708 <                assertEquals(0, q.remainingCapacity());
1709 <            }});
1710 <
1711 <        executor.execute(new CheckedRunnable() {
1712 <            public void realRun() throws InterruptedException {
1713 <                threadsStarted.await();
1714 <                assertSame(one, q.take());
1715 <            }});
1716 <
1717 <        joinPool(executor);
1703 >        final ExecutorService executor = Executors.newFixedThreadPool(2);
1704 >        try (PoolCleaner cleaner = cleaner(executor)) {
1705 >            executor.execute(new CheckedRunnable() {
1706 >                public void realRun() throws InterruptedException {
1707 >                    assertFalse(q.offer(three));
1708 >                    threadsStarted.await();
1709 >                    assertTrue(q.offer(three, LONG_DELAY_MS, MILLISECONDS));
1710 >                    assertEquals(0, q.remainingCapacity());
1711 >                }});
1712 >
1713 >            executor.execute(new CheckedRunnable() {
1714 >                public void realRun() throws InterruptedException {
1715 >                    threadsStarted.await();
1716 >                    assertSame(one, q.take());
1717 >                }});
1718 >        }
1719      }
1720  
1721      /**
# Line 1695 | Line 1724 | public class LinkedBlockingDequeTest ext
1724      public void testPollInExecutor() {
1725          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
1726          final CheckedBarrier threadsStarted = new CheckedBarrier(2);
1727 <        ExecutorService executor = Executors.newFixedThreadPool(2);
1728 <        executor.execute(new CheckedRunnable() {
1729 <            public void realRun() throws InterruptedException {
1730 <                assertNull(q.poll());
1731 <                threadsStarted.await();
1732 <                assertSame(one, q.poll(LONG_DELAY_MS, MILLISECONDS));
1733 <                checkEmpty(q);
1734 <            }});
1735 <
1736 <        executor.execute(new CheckedRunnable() {
1737 <            public void realRun() throws InterruptedException {
1738 <                threadsStarted.await();
1739 <                q.put(one);
1740 <            }});
1741 <
1742 <        joinPool(executor);
1727 >        final ExecutorService executor = Executors.newFixedThreadPool(2);
1728 >        try (PoolCleaner cleaner = cleaner(executor)) {
1729 >            executor.execute(new CheckedRunnable() {
1730 >                public void realRun() throws InterruptedException {
1731 >                    assertNull(q.poll());
1732 >                    threadsStarted.await();
1733 >                    assertSame(one, q.poll(LONG_DELAY_MS, MILLISECONDS));
1734 >                    checkEmpty(q);
1735 >                }});
1736 >
1737 >            executor.execute(new CheckedRunnable() {
1738 >                public void realRun() throws InterruptedException {
1739 >                    threadsStarted.await();
1740 >                    q.put(one);
1741 >                }});
1742 >        }
1743      }
1744  
1745      /**
# Line 1762 | Line 1791 | public class LinkedBlockingDequeTest ext
1791          final LinkedBlockingDeque q = populatedDeque(SIZE);
1792          Thread t = new Thread(new CheckedRunnable() {
1793              public void realRun() throws InterruptedException {
1794 <                q.put(new Integer(SIZE+1));
1794 >                q.put(new Integer(SIZE + 1));
1795              }});
1796  
1797          t.start();
# Line 1787 | Line 1816 | public class LinkedBlockingDequeTest ext
1816              q.drainTo(l, i);
1817              int k = (i < SIZE) ? i : SIZE;
1818              assertEquals(k, l.size());
1819 <            assertEquals(SIZE-k, q.size());
1819 >            assertEquals(SIZE - k, q.size());
1820              for (int j = 0; j < k; ++j)
1821                  assertEquals(l.get(j), new Integer(j));
1822              do {} while (q.poll() != null);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines