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.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 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                  long startTime = System.nanoTime();
771 <                for (int i = 0; i < SIZE; ++i) {
771 >                for (int i = 0; i < SIZE; i++)
772                      assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS));
773 <                }
774 <                aboutToWait.countDown();
773 >
774 >                Thread.currentThread().interrupt();
775                  try {
776                      q.poll(LONG_DELAY_MS, MILLISECONDS);
777                      shouldThrow();
778 <                } catch (InterruptedException success) {
779 <                    assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
780 <                }
778 >                } catch (InterruptedException success) {}
779 >                assertFalse(Thread.interrupted());
780 >
781 >                pleaseInterrupt.countDown();
782 >                try {
783 >                    q.poll(LONG_DELAY_MS, MILLISECONDS);
784 >                    shouldThrow();
785 >                } catch (InterruptedException success) {}
786 >                assertFalse(Thread.interrupted());
787 >
788 >                assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
789              }});
790  
791 <        aboutToWait.await();
792 <        waitForThreadToEnterWaitState(t);
791 >        await(pleaseInterrupt);
792 >        assertThreadBlocks(t, Thread.State.TIMED_WAITING);
793          t.interrupt();
794          awaitTermination(t);
795          checkEmpty(q);
# Line 824 | 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 859 | 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 883 | 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 918 | 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 959 | 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 991 | 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) {
995 <                    assertEquals(i, q.takeFirst());
996 <                }
1019 >                for (int i = 0; i < SIZE; i++) assertEquals(i, q.takeFirst());
1020  
1021                  Thread.currentThread().interrupt();
1022                  try {
# Line 1011 | 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 1053 | Line 1076 | public class LinkedBlockingDequeTest ext
1076          Thread t = newStartedThread(new CheckedRunnable() {
1077              public void realRun() throws InterruptedException {
1078                  long startTime = System.nanoTime();
1079 <                for (int i = 0; i < SIZE; ++i) {
1079 >                for (int i = 0; i < SIZE; i++)
1080                      assertEquals(i, q.pollFirst(LONG_DELAY_MS, MILLISECONDS));
1058                }
1081  
1082                  Thread.currentThread().interrupt();
1083                  try {
# Line 1070 | 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 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) {
1285 >                for (int i = 0; i < SIZE; i++)
1286                      assertEquals(SIZE - i - 1, q.takeLast());
1263                }
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 1320 | Line 1343 | public class LinkedBlockingDequeTest ext
1343          Thread t = newStartedThread(new CheckedRunnable() {
1344              public void realRun() throws InterruptedException {
1345                  long startTime = System.nanoTime();
1346 <                for (int i = 0; i < SIZE; ++i) {
1346 >                for (int i = 0; i < SIZE; i++)
1347                      assertEquals(SIZE - i - 1,
1348                                   q.pollLast(LONG_DELAY_MS, MILLISECONDS));
1326                }
1349  
1350                  Thread.currentThread().interrupt();
1351                  try {
# Line 1343 | Line 1365 | public class LinkedBlockingDequeTest ext
1365              }});
1366  
1367          await(pleaseInterrupt);
1368 <        assertThreadStaysAlive(t);
1368 >        assertThreadBlocks(t, Thread.State.TIMED_WAITING);
1369          t.interrupt();
1370          awaitTermination(t);
1371          checkEmpty(q);
# Line 1389 | 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      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines