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.64 by jsr166, Sat Aug 6 17:02:49 2016 UTC vs.
Revision 1.77 by jsr166, Sun May 14 00:56:43 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 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) {
765                      assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS));
766                  }
767 <                aboutToWait.countDown();
767 >
768 >                pleaseInterrupt.countDown();
769                  try {
770                      q.poll(LONG_DELAY_MS, MILLISECONDS);
771                      shouldThrow();
772 <                } catch (InterruptedException success) {
773 <                    assertTrue(millisElapsedSince(startTime) < LONG_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);
778 >        await(pleaseInterrupt);
779 >        assertThreadBlocks(t, Thread.State.TIMED_WAITING);
780          t.interrupt();
781          awaitTermination(t);
782          checkEmpty(q);
# Line 824 | 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 859 | 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 883 | 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 918 | 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 959 | 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 991 | 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) {
995 <                    assertEquals(i, q.takeFirst());
996 <                }
1006 >                for (int i = 0; i < SIZE; i++) assertEquals(i, q.takeFirst());
1007  
1008                  Thread.currentThread().interrupt();
1009                  try {
# Line 1011 | 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 1070 | 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 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 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) {
1273 >                for (int i = 0; i < SIZE; i++)
1274                      assertEquals(SIZE - i - 1, q.takeLast());
1263                }
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 1343 | Line 1354 | public class LinkedBlockingDequeTest ext
1354              }});
1355  
1356          await(pleaseInterrupt);
1357 <        assertThreadStaysAlive(t);
1357 >        assertThreadBlocks(t, Thread.State.TIMED_WAITING);
1358          t.interrupt();
1359          awaitTermination(t);
1360          checkEmpty(q);
# Line 1389 | 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      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines