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.60 by jsr166, Sun May 24 01:42:14 2015 UTC vs.
Revision 1.63 by jsr166, Thu Oct 8 00:41:57 2015 UTC

# Line 751 | Line 751 | public class LinkedBlockingDequeTest ext
751          final CountDownLatch aboutToWait = new CountDownLatch(1);
752          Thread t = newStartedThread(new CheckedRunnable() {
753              public void realRun() throws InterruptedException {
754 +                long startTime = System.nanoTime();
755                  for (int i = 0; i < SIZE; ++i) {
755                    long t0 = System.nanoTime();
756                      assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS));
757                    assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS);
757                  }
759                long t0 = System.nanoTime();
758                  aboutToWait.countDown();
759                  try {
760 <                    q.poll(MEDIUM_DELAY_MS, MILLISECONDS);
760 >                    q.poll(LONG_DELAY_MS, MILLISECONDS);
761                      shouldThrow();
762                  } catch (InterruptedException success) {
763 <                    assertTrue(millisElapsedSince(t0) < MEDIUM_DELAY_MS);
763 >                    assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
764                  }
765              }});
766  
767          aboutToWait.await();
768 <        waitForThreadToEnterWaitState(t, SMALL_DELAY_MS);
768 >        waitForThreadToEnterWaitState(t, LONG_DELAY_MS);
769          t.interrupt();
770 <        awaitTermination(t, MEDIUM_DELAY_MS);
770 >        awaitTermination(t);
771          checkEmpty(q);
772      }
773  
# Line 1050 | Line 1048 | public class LinkedBlockingDequeTest ext
1048       * returning timeout status
1049       */
1050      public void testInterruptedTimedPollFirst() throws InterruptedException {
1051 +        final LinkedBlockingDeque q = populatedDeque(SIZE);
1052          final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
1053          Thread t = newStartedThread(new CheckedRunnable() {
1054              public void realRun() throws InterruptedException {
1055 <                LinkedBlockingDeque q = populatedDeque(SIZE);
1055 >                long startTime = System.nanoTime();
1056                  for (int i = 0; i < SIZE; ++i) {
1057                      assertEquals(i, q.pollFirst(LONG_DELAY_MS, MILLISECONDS));
1058                  }
1059  
1060                  Thread.currentThread().interrupt();
1061                  try {
1062 <                    q.pollFirst(SMALL_DELAY_MS, MILLISECONDS);
1062 >                    q.pollFirst(LONG_DELAY_MS, MILLISECONDS);
1063                      shouldThrow();
1064                  } catch (InterruptedException success) {}
1065                  assertFalse(Thread.interrupted());
# Line 1071 | Line 1070 | public class LinkedBlockingDequeTest ext
1070                      shouldThrow();
1071                  } catch (InterruptedException success) {}
1072                  assertFalse(Thread.interrupted());
1073 +                assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
1074              }});
1075  
1076          await(pleaseInterrupt);
# Line 1315 | Line 1315 | public class LinkedBlockingDequeTest ext
1315       * returning timeout status
1316       */
1317      public void testInterruptedTimedPollLast() throws InterruptedException {
1318 +        final LinkedBlockingDeque q = populatedDeque(SIZE);
1319          final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
1320          Thread t = newStartedThread(new CheckedRunnable() {
1321              public void realRun() throws InterruptedException {
1322 <                LinkedBlockingDeque q = populatedDeque(SIZE);
1322 >                long startTime = System.nanoTime();
1323                  for (int i = 0; i < SIZE; ++i) {
1324                      assertEquals(SIZE - i - 1,
1325                                   q.pollLast(LONG_DELAY_MS, MILLISECONDS));
# Line 1337 | Line 1338 | public class LinkedBlockingDequeTest ext
1338                      shouldThrow();
1339                  } catch (InterruptedException success) {}
1340                  assertFalse(Thread.interrupted());
1341 +
1342 +                assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
1343              }});
1344  
1345          await(pleaseInterrupt);
1346          assertThreadStaysAlive(t);
1347          t.interrupt();
1348          awaitTermination(t);
1349 +        checkEmpty(q);
1350      }
1351  
1352      /**
# Line 1375 | Line 1379 | public class LinkedBlockingDequeTest ext
1379                      shouldThrow();
1380                  } catch (InterruptedException success) {}
1381                  assertFalse(Thread.interrupted());
1382 +
1383 +                assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
1384              }});
1385  
1386          barrier.await();
# Line 1671 | Line 1677 | public class LinkedBlockingDequeTest ext
1677          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
1678          q.add(one);
1679          q.add(two);
1674        ExecutorService executor = Executors.newFixedThreadPool(2);
1680          final CheckedBarrier threadsStarted = new CheckedBarrier(2);
1681 <        executor.execute(new CheckedRunnable() {
1682 <            public void realRun() throws InterruptedException {
1683 <                assertFalse(q.offer(three));
1684 <                threadsStarted.await();
1685 <                assertTrue(q.offer(three, LONG_DELAY_MS, MILLISECONDS));
1686 <                assertEquals(0, q.remainingCapacity());
1687 <            }});
1688 <
1689 <        executor.execute(new CheckedRunnable() {
1690 <            public void realRun() throws InterruptedException {
1691 <                threadsStarted.await();
1692 <                assertSame(one, q.take());
1693 <            }});
1694 <
1695 <        joinPool(executor);
1681 >        final ExecutorService executor = Executors.newFixedThreadPool(2);
1682 >        try (PoolCleaner cleaner = cleaner(executor)) {
1683 >            executor.execute(new CheckedRunnable() {
1684 >                public void realRun() throws InterruptedException {
1685 >                    assertFalse(q.offer(three));
1686 >                    threadsStarted.await();
1687 >                    assertTrue(q.offer(three, LONG_DELAY_MS, MILLISECONDS));
1688 >                    assertEquals(0, q.remainingCapacity());
1689 >                }});
1690 >
1691 >            executor.execute(new CheckedRunnable() {
1692 >                public void realRun() throws InterruptedException {
1693 >                    threadsStarted.await();
1694 >                    assertSame(one, q.take());
1695 >                }});
1696 >        }
1697      }
1698  
1699      /**
# Line 1696 | Line 1702 | public class LinkedBlockingDequeTest ext
1702      public void testPollInExecutor() {
1703          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
1704          final CheckedBarrier threadsStarted = new CheckedBarrier(2);
1705 <        ExecutorService executor = Executors.newFixedThreadPool(2);
1706 <        executor.execute(new CheckedRunnable() {
1707 <            public void realRun() throws InterruptedException {
1708 <                assertNull(q.poll());
1709 <                threadsStarted.await();
1710 <                assertSame(one, q.poll(LONG_DELAY_MS, MILLISECONDS));
1711 <                checkEmpty(q);
1712 <            }});
1713 <
1714 <        executor.execute(new CheckedRunnable() {
1715 <            public void realRun() throws InterruptedException {
1716 <                threadsStarted.await();
1717 <                q.put(one);
1718 <            }});
1719 <
1720 <        joinPool(executor);
1705 >        final ExecutorService executor = Executors.newFixedThreadPool(2);
1706 >        try (PoolCleaner cleaner = cleaner(executor)) {
1707 >            executor.execute(new CheckedRunnable() {
1708 >                public void realRun() throws InterruptedException {
1709 >                    assertNull(q.poll());
1710 >                    threadsStarted.await();
1711 >                    assertSame(one, q.poll(LONG_DELAY_MS, MILLISECONDS));
1712 >                    checkEmpty(q);
1713 >                }});
1714 >
1715 >            executor.execute(new CheckedRunnable() {
1716 >                public void realRun() throws InterruptedException {
1717 >                    threadsStarted.await();
1718 >                    q.put(one);
1719 >                }});
1720 >        }
1721      }
1722  
1723      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines