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.61 by jsr166, Sun Oct 4 18:49:02 2015 UTC vs.
Revision 1.65 by jsr166, Sun Oct 16 20:44:18 2016 UTC

# Line 48 | Line 48 | public class LinkedBlockingDequeTest ext
48  
49      /**
50       * Returns a new deque of given size containing consecutive
51 <     * Integers 0 ... n.
51 >     * Integers 0 ... n - 1.
52       */
53      private LinkedBlockingDeque<Integer> populatedDeque(int n) {
54          LinkedBlockingDeque<Integer> q =
# Line 59 | Line 59 | public class LinkedBlockingDequeTest ext
59          assertFalse(q.isEmpty());
60          assertEquals(0, q.remainingCapacity());
61          assertEquals(n, q.size());
62 +        assertEquals((Integer) 0, q.peekFirst());
63 +        assertEquals((Integer) (n - 1), q.peekLast());
64          return q;
65      }
66  
# Line 751 | Line 753 | public class LinkedBlockingDequeTest ext
753          final CountDownLatch aboutToWait = new CountDownLatch(1);
754          Thread t = newStartedThread(new CheckedRunnable() {
755              public void realRun() throws InterruptedException {
756 +                long startTime = System.nanoTime();
757                  for (int i = 0; i < SIZE; ++i) {
755                    long t0 = System.nanoTime();
758                      assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS));
757                    assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS);
759                  }
759                long t0 = System.nanoTime();
760                  aboutToWait.countDown();
761                  try {
762 <                    q.poll(MEDIUM_DELAY_MS, MILLISECONDS);
762 >                    q.poll(LONG_DELAY_MS, MILLISECONDS);
763                      shouldThrow();
764                  } catch (InterruptedException success) {
765 <                    assertTrue(millisElapsedSince(t0) < MEDIUM_DELAY_MS);
765 >                    assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
766                  }
767              }});
768  
769          aboutToWait.await();
770 <        waitForThreadToEnterWaitState(t, SMALL_DELAY_MS);
770 >        waitForThreadToEnterWaitState(t);
771          t.interrupt();
772 <        awaitTermination(t, MEDIUM_DELAY_MS);
772 >        awaitTermination(t);
773          checkEmpty(q);
774      }
775  
# Line 1050 | Line 1050 | public class LinkedBlockingDequeTest ext
1050       * returning timeout status
1051       */
1052      public void testInterruptedTimedPollFirst() throws InterruptedException {
1053 +        final LinkedBlockingDeque q = populatedDeque(SIZE);
1054          final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
1055          Thread t = newStartedThread(new CheckedRunnable() {
1056              public void realRun() throws InterruptedException {
1057 <                LinkedBlockingDeque q = populatedDeque(SIZE);
1057 >                long startTime = System.nanoTime();
1058                  for (int i = 0; i < SIZE; ++i) {
1059                      assertEquals(i, q.pollFirst(LONG_DELAY_MS, MILLISECONDS));
1060                  }
1061  
1062                  Thread.currentThread().interrupt();
1063                  try {
1064 <                    q.pollFirst(SMALL_DELAY_MS, MILLISECONDS);
1064 >                    q.pollFirst(LONG_DELAY_MS, MILLISECONDS);
1065                      shouldThrow();
1066                  } catch (InterruptedException success) {}
1067                  assertFalse(Thread.interrupted());
# Line 1071 | Line 1072 | public class LinkedBlockingDequeTest ext
1072                      shouldThrow();
1073                  } catch (InterruptedException success) {}
1074                  assertFalse(Thread.interrupted());
1075 +                assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
1076              }});
1077  
1078          await(pleaseInterrupt);
# Line 1315 | Line 1317 | public class LinkedBlockingDequeTest ext
1317       * returning timeout status
1318       */
1319      public void testInterruptedTimedPollLast() throws InterruptedException {
1320 +        final LinkedBlockingDeque q = populatedDeque(SIZE);
1321          final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
1322          Thread t = newStartedThread(new CheckedRunnable() {
1323              public void realRun() throws InterruptedException {
1324 <                LinkedBlockingDeque q = populatedDeque(SIZE);
1324 >                long startTime = System.nanoTime();
1325                  for (int i = 0; i < SIZE; ++i) {
1326                      assertEquals(SIZE - i - 1,
1327                                   q.pollLast(LONG_DELAY_MS, MILLISECONDS));
# Line 1337 | Line 1340 | public class LinkedBlockingDequeTest ext
1340                      shouldThrow();
1341                  } catch (InterruptedException success) {}
1342                  assertFalse(Thread.interrupted());
1343 +
1344 +                assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
1345              }});
1346  
1347          await(pleaseInterrupt);
1348          assertThreadStaysAlive(t);
1349          t.interrupt();
1350          awaitTermination(t);
1351 +        checkEmpty(q);
1352      }
1353  
1354      /**
# Line 1375 | Line 1381 | public class LinkedBlockingDequeTest ext
1381                      shouldThrow();
1382                  } catch (InterruptedException success) {}
1383                  assertFalse(Thread.interrupted());
1384 +
1385 +                assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
1386              }});
1387  
1388          barrier.await();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines