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.78 by jsr166, Sun May 14 01:30:34 2017 UTC vs.
Revision 1.84 by jsr166, Sun Aug 11 22:29:27 2019 UTC

# Line 442 | Line 442 | public class LinkedBlockingDequeTest ext
442      }
443  
444      /**
445 <     * push succeeds if not full; throws ISE if full
445 >     * push succeeds if not full; throws IllegalStateException if full
446       */
447      public void testPush() {
448          LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
# Line 492 | Line 492 | public class LinkedBlockingDequeTest ext
492      }
493  
494      /**
495 <     * add succeeds if not full; throws ISE if full
495 >     * add succeeds if not full; throws IllegalStateException if full
496       */
497      public void testAdd() {
498          LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
# Line 506 | Line 506 | public class LinkedBlockingDequeTest ext
506      }
507  
508      /**
509 <     * addAll(this) throws IAE
509 >     * addAll(this) throws IllegalArgumentException
510       */
511      public void testAddAllSelf() {
512          LinkedBlockingDeque q = populatedDeque(SIZE);
# Line 604 | Line 604 | public class LinkedBlockingDequeTest ext
604              }});
605  
606          await(pleaseInterrupt);
607 <        assertThreadBlocks(t, Thread.State.WAITING);
607 >        if (randomBoolean()) assertThreadBlocks(t, Thread.State.WAITING);
608          t.interrupt();
609          awaitTermination(t);
610          assertEquals(SIZE, q.size());
# Line 626 | 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 639 | Line 646 | public class LinkedBlockingDequeTest ext
646          assertEquals(0, q.take());
647  
648          await(pleaseInterrupt);
649 <        assertThreadBlocks(t, Thread.State.WAITING);
649 >        if (randomBoolean()) assertThreadBlocks(t, Thread.State.WAITING);
650          t.interrupt();
651          awaitTermination(t);
652          assertEquals(0, q.remainingCapacity());
# Line 648 | Line 655 | public class LinkedBlockingDequeTest ext
655      /**
656       * timed offer times out if full and elements not taken
657       */
658 <    public void testTimedOffer() throws InterruptedException {
658 >    public void testTimedOffer() {
659          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
660          final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
661          Thread t = newStartedThread(new CheckedRunnable() {
# Line 656 | Line 663 | public class LinkedBlockingDequeTest ext
663                  q.put(new Object());
664                  q.put(new Object());
665                  long startTime = System.nanoTime();
666 +
667                  assertFalse(q.offer(new Object(), timeoutMillis(), MILLISECONDS));
668                  assertTrue(millisElapsedSince(startTime) >= timeoutMillis());
669 +
670 +                Thread.currentThread().interrupt();
671 +                try {
672 +                    q.offer(new Object(), randomTimeout(), randomTimeUnit());
673 +                    shouldThrow();
674 +                } catch (InterruptedException success) {}
675 +                assertFalse(Thread.interrupted());
676 +
677                  pleaseInterrupt.countDown();
678                  try {
679 <                    q.offer(new Object(), 2 * LONG_DELAY_MS, MILLISECONDS);
679 >                    q.offer(new Object(), LONG_DELAY_MS, MILLISECONDS);
680                      shouldThrow();
681                  } catch (InterruptedException success) {}
682                  assertFalse(Thread.interrupted());
683 +
684 +                assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
685              }});
686  
687          await(pleaseInterrupt);
688 <        assertThreadBlocks(t, Thread.State.TIMED_WAITING);
688 >        if (randomBoolean()) assertThreadBlocks(t, Thread.State.TIMED_WAITING);
689          t.interrupt();
690          awaitTermination(t);
691      }
# Line 708 | Line 726 | public class LinkedBlockingDequeTest ext
726              }});
727  
728          await(pleaseInterrupt);
729 <        assertThreadBlocks(t, Thread.State.WAITING);
729 >        if (randomBoolean()) assertThreadBlocks(t, Thread.State.WAITING);
730          t.interrupt();
731          awaitTermination(t);
732      }
# Line 766 | Line 784 | public class LinkedBlockingDequeTest ext
784  
785                  Thread.currentThread().interrupt();
786                  try {
787 <                    q.poll(LONG_DELAY_MS, MILLISECONDS);
787 >                    q.poll(randomTimeout(), randomTimeUnit());
788                      shouldThrow();
789                  } catch (InterruptedException success) {}
790                  assertFalse(Thread.interrupted());
# Line 782 | Line 800 | public class LinkedBlockingDequeTest ext
800              }});
801  
802          await(pleaseInterrupt);
803 <        assertThreadBlocks(t, Thread.State.TIMED_WAITING);
803 >        if (randomBoolean()) assertThreadBlocks(t, Thread.State.TIMED_WAITING);
804          t.interrupt();
805          awaitTermination(t);
806          checkEmpty(q);
# Line 841 | Line 859 | public class LinkedBlockingDequeTest ext
859              }});
860  
861          await(pleaseInterrupt);
862 <        assertThreadBlocks(t, Thread.State.WAITING);
862 >        if (randomBoolean()) assertThreadBlocks(t, Thread.State.WAITING);
863          t.interrupt();
864          awaitTermination(t);
865          assertEquals(SIZE, q.size());
# Line 876 | Line 894 | public class LinkedBlockingDequeTest ext
894          assertEquals(capacity - 1, q.take());
895  
896          await(pleaseInterrupt);
897 <        assertThreadBlocks(t, Thread.State.WAITING);
897 >        if (randomBoolean()) assertThreadBlocks(t, Thread.State.WAITING);
898          t.interrupt();
899          awaitTermination(t);
900          assertEquals(0, q.remainingCapacity());
# Line 885 | Line 903 | public class LinkedBlockingDequeTest ext
903      /**
904       * timed offerFirst times out if full and elements not taken
905       */
906 <    public void testTimedOfferFirst() throws InterruptedException {
906 >    public void testTimedOfferFirst() {
907          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
908          final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
909          Thread t = newStartedThread(new CheckedRunnable() {
# Line 893 | Line 911 | public class LinkedBlockingDequeTest ext
911                  q.putFirst(new Object());
912                  q.putFirst(new Object());
913                  long startTime = System.nanoTime();
914 +
915                  assertFalse(q.offerFirst(new Object(), timeoutMillis(), MILLISECONDS));
916                  assertTrue(millisElapsedSince(startTime) >= timeoutMillis());
917 +
918 +                Thread.currentThread().interrupt();
919 +                try {
920 +                    q.offerFirst(new Object(), randomTimeout(), randomTimeUnit());
921 +                    shouldThrow();
922 +                } catch (InterruptedException success) {}
923 +                assertFalse(Thread.interrupted());
924 +
925                  pleaseInterrupt.countDown();
926                  try {
927 <                    q.offerFirst(new Object(), 2 * LONG_DELAY_MS, MILLISECONDS);
927 >                    q.offerFirst(new Object(), LONG_DELAY_MS, MILLISECONDS);
928                      shouldThrow();
929                  } catch (InterruptedException success) {}
930                  assertFalse(Thread.interrupted());
931 +
932 +                assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
933              }});
934  
935          await(pleaseInterrupt);
936 <        assertThreadBlocks(t, Thread.State.TIMED_WAITING);
936 >        if (randomBoolean()) assertThreadBlocks(t, Thread.State.TIMED_WAITING);
937          t.interrupt();
938          awaitTermination(t);
939      }
# Line 936 | Line 965 | public class LinkedBlockingDequeTest ext
965              }});
966  
967          await(threadStarted);
968 <        assertThreadBlocks(t, Thread.State.WAITING);
968 >        if (randomBoolean()) assertThreadBlocks(t, Thread.State.WAITING);
969          t.interrupt();
970          awaitTermination(t);
971      }
# Line 977 | Line 1006 | public class LinkedBlockingDequeTest ext
1006              }});
1007  
1008          await(threadStarted);
1009 <        assertThreadBlocks(t, Thread.State.WAITING);
1009 >        if (randomBoolean()) assertThreadBlocks(t, Thread.State.WAITING);
1010          t.interrupt();
1011          awaitTermination(t);
1012      }
# Line 1027 | Line 1056 | public class LinkedBlockingDequeTest ext
1056              }});
1057  
1058          await(pleaseInterrupt);
1059 <        assertThreadBlocks(t, Thread.State.WAITING);
1059 >        if (randomBoolean()) assertThreadBlocks(t, Thread.State.WAITING);
1060          t.interrupt();
1061          awaitTermination(t);
1062      }
# Line 1074 | Line 1103 | public class LinkedBlockingDequeTest ext
1103  
1104                  Thread.currentThread().interrupt();
1105                  try {
1106 <                    q.pollFirst(LONG_DELAY_MS, MILLISECONDS);
1106 >                    q.pollFirst(randomTimeout(), randomTimeUnit());
1107                      shouldThrow();
1108                  } catch (InterruptedException success) {}
1109                  assertFalse(Thread.interrupted());
# Line 1090 | Line 1119 | public class LinkedBlockingDequeTest ext
1119              }});
1120  
1121          await(pleaseInterrupt);
1122 <        assertThreadBlocks(t, Thread.State.TIMED_WAITING);
1122 >        if (randomBoolean()) assertThreadBlocks(t, Thread.State.TIMED_WAITING);
1123          t.interrupt();
1124          awaitTermination(t);
1125      }
# Line 1114 | Line 1143 | public class LinkedBlockingDequeTest ext
1143  
1144                  Thread.currentThread().interrupt();
1145                  try {
1146 <                    q.pollFirst(LONG_DELAY_MS, MILLISECONDS);
1146 >                    q.pollFirst(randomTimeout(), randomTimeUnit());
1147                      shouldThrow();
1148                  } catch (InterruptedException success) {}
1149  
# Line 1124 | Line 1153 | public class LinkedBlockingDequeTest ext
1153                      shouldThrow();
1154                  } catch (InterruptedException success) {}
1155                  assertFalse(Thread.interrupted());
1156 +
1157                  assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
1158              }});
1159  
# Line 1132 | Line 1162 | public class LinkedBlockingDequeTest ext
1162          assertTrue(q.offerFirst(zero, LONG_DELAY_MS, MILLISECONDS));
1163          assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
1164          barrier.await();
1165 <        assertThreadBlocks(t, Thread.State.TIMED_WAITING);
1165 >        if (randomBoolean()) assertThreadBlocks(t, Thread.State.TIMED_WAITING);
1166          t.interrupt();
1167          awaitTermination(t);
1168      }
# Line 1190 | Line 1220 | public class LinkedBlockingDequeTest ext
1220              }});
1221  
1222          await(pleaseInterrupt);
1223 <        assertThreadBlocks(t, Thread.State.WAITING);
1223 >        if (randomBoolean()) assertThreadBlocks(t, Thread.State.WAITING);
1224          t.interrupt();
1225          awaitTermination(t);
1226          assertEquals(SIZE, q.size());
# Line 1212 | Line 1242 | public class LinkedBlockingDequeTest ext
1242                  pleaseTake.countDown();
1243                  q.putLast(86);
1244  
1245 +                Thread.currentThread().interrupt();
1246 +                try {
1247 +                    q.putLast(99);
1248 +                    shouldThrow();
1249 +                } catch (InterruptedException success) {}
1250 +                assertFalse(Thread.interrupted());
1251 +
1252                  pleaseInterrupt.countDown();
1253                  try {
1254                      q.putLast(99);
# Line 1225 | Line 1262 | public class LinkedBlockingDequeTest ext
1262          assertEquals(0, q.take());
1263  
1264          await(pleaseInterrupt);
1265 <        assertThreadBlocks(t, Thread.State.WAITING);
1265 >        if (randomBoolean()) assertThreadBlocks(t, Thread.State.WAITING);
1266          t.interrupt();
1267          awaitTermination(t);
1268          assertEquals(0, q.remainingCapacity());
# Line 1234 | Line 1271 | public class LinkedBlockingDequeTest ext
1271      /**
1272       * timed offerLast times out if full and elements not taken
1273       */
1274 <    public void testTimedOfferLast() throws InterruptedException {
1274 >    public void testTimedOfferLast() {
1275          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
1276          final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
1277          Thread t = newStartedThread(new CheckedRunnable() {
# Line 1242 | Line 1279 | public class LinkedBlockingDequeTest ext
1279                  q.putLast(new Object());
1280                  q.putLast(new Object());
1281                  long startTime = System.nanoTime();
1282 +
1283                  assertFalse(q.offerLast(new Object(), timeoutMillis(), MILLISECONDS));
1284                  assertTrue(millisElapsedSince(startTime) >= timeoutMillis());
1285 +
1286 +                Thread.currentThread().interrupt();
1287 +                try {
1288 +                    q.offerLast(new Object(), randomTimeout(), randomTimeUnit());
1289 +                    shouldThrow();
1290 +                } catch (InterruptedException success) {}
1291 +
1292                  pleaseInterrupt.countDown();
1293                  try {
1294 <                    q.offerLast(new Object(), 2 * LONG_DELAY_MS, MILLISECONDS);
1294 >                    q.offerLast(new Object(), LONG_DELAY_MS, MILLISECONDS);
1295                      shouldThrow();
1296                  } catch (InterruptedException success) {}
1297 +
1298 +                assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
1299              }});
1300  
1301          await(pleaseInterrupt);
1302 <        assertThreadBlocks(t, Thread.State.TIMED_WAITING);
1302 >        if (randomBoolean()) assertThreadBlocks(t, Thread.State.TIMED_WAITING);
1303          t.interrupt();
1304          awaitTermination(t);
1305      }
# Line 1294 | Line 1341 | public class LinkedBlockingDequeTest ext
1341              }});
1342  
1343          await(pleaseInterrupt);
1344 <        assertThreadBlocks(t, Thread.State.WAITING);
1344 >        if (randomBoolean()) assertThreadBlocks(t, Thread.State.WAITING);
1345          t.interrupt();
1346          awaitTermination(t);
1347      }
# Line 1342 | Line 1389 | public class LinkedBlockingDequeTest ext
1389  
1390                  Thread.currentThread().interrupt();
1391                  try {
1392 <                    q.pollLast(LONG_DELAY_MS, MILLISECONDS);
1392 >                    q.pollLast(randomTimeout(), randomTimeUnit());
1393                      shouldThrow();
1394                  } catch (InterruptedException success) {}
1395                  assertFalse(Thread.interrupted());
# Line 1358 | Line 1405 | public class LinkedBlockingDequeTest ext
1405              }});
1406  
1407          await(pleaseInterrupt);
1408 <        assertThreadBlocks(t, Thread.State.TIMED_WAITING);
1408 >        if (randomBoolean()) assertThreadBlocks(t, Thread.State.TIMED_WAITING);
1409          t.interrupt();
1410          awaitTermination(t);
1411          checkEmpty(q);
# Line 1383 | Line 1430 | public class LinkedBlockingDequeTest ext
1430  
1431                  Thread.currentThread().interrupt();
1432                  try {
1433 <                    q.poll(LONG_DELAY_MS, MILLISECONDS);
1433 >                    q.poll(randomTimeout(), randomTimeUnit());
1434                      shouldThrow();
1435                  } catch (InterruptedException success) {}
1436                  assertFalse(Thread.interrupted());
# Line 1404 | Line 1451 | public class LinkedBlockingDequeTest ext
1451          assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
1452  
1453          barrier.await();
1454 <        assertThreadBlocks(t, Thread.State.TIMED_WAITING);
1454 >        if (randomBoolean()) assertThreadBlocks(t, Thread.State.TIMED_WAITING);
1455          t.interrupt();
1456          awaitTermination(t);
1457      }
# Line 1506 | Line 1553 | public class LinkedBlockingDequeTest ext
1553       */
1554      public void testToArray() throws InterruptedException {
1555          LinkedBlockingDeque q = populatedDeque(SIZE);
1556 <        Object[] o = q.toArray();
1557 <        for (int i = 0; i < o.length; i++)
1558 <            assertSame(o[i], q.poll());
1556 >        Object[] a = q.toArray();
1557 >        assertSame(Object[].class, a.getClass());
1558 >        for (Object o : a)
1559 >            assertSame(o, q.poll());
1560 >        assertTrue(q.isEmpty());
1561      }
1562  
1563      /**
# Line 1519 | Line 1568 | public class LinkedBlockingDequeTest ext
1568          Integer[] ints = new Integer[SIZE];
1569          Integer[] array = q.toArray(ints);
1570          assertSame(ints, array);
1571 <        for (int i = 0; i < ints.length; i++)
1572 <            assertSame(ints[i], q.remove());
1571 >        for (Integer o : ints)
1572 >            assertSame(o, q.remove());
1573 >        assertTrue(q.isEmpty());
1574      }
1575  
1576      /**
# Line 1736 | Line 1786 | public class LinkedBlockingDequeTest ext
1786      }
1787  
1788      /**
1789 <     * A deserialized serialized deque has same elements in same order
1789 >     * A deserialized/reserialized deque has same elements in same order
1790       */
1791      public void testSerialization() throws Exception {
1792          Queue x = populatedDeque(SIZE);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines