test/jdk/java/util/concurrent/tck/LinkedBlockingDequeTest.java
changeset 58138 1e4270f875ee
parent 50764 5637aca18f1d
equal deleted inserted replaced
58137:6a556bcd94fc 58138:1e4270f875ee
   629                 } catch (InterruptedException success) {}
   629                 } catch (InterruptedException success) {}
   630                 assertFalse(Thread.interrupted());
   630                 assertFalse(Thread.interrupted());
   631             }});
   631             }});
   632 
   632 
   633         await(pleaseInterrupt);
   633         await(pleaseInterrupt);
   634         assertThreadBlocks(t, Thread.State.WAITING);
   634         if (randomBoolean()) assertThreadBlocks(t, Thread.State.WAITING);
   635         t.interrupt();
   635         t.interrupt();
   636         awaitTermination(t);
   636         awaitTermination(t);
   637         assertEquals(SIZE, q.size());
   637         assertEquals(SIZE, q.size());
   638         assertEquals(0, q.remainingCapacity());
   638         assertEquals(0, q.remainingCapacity());
   639     }
   639     }
   671         await(pleaseTake);
   671         await(pleaseTake);
   672         assertEquals(0, q.remainingCapacity());
   672         assertEquals(0, q.remainingCapacity());
   673         assertEquals(0, q.take());
   673         assertEquals(0, q.take());
   674 
   674 
   675         await(pleaseInterrupt);
   675         await(pleaseInterrupt);
   676         assertThreadBlocks(t, Thread.State.WAITING);
   676         if (randomBoolean()) assertThreadBlocks(t, Thread.State.WAITING);
   677         t.interrupt();
   677         t.interrupt();
   678         awaitTermination(t);
   678         awaitTermination(t);
   679         assertEquals(0, q.remainingCapacity());
   679         assertEquals(0, q.remainingCapacity());
   680     }
   680     }
   681 
   681 
   688         Thread t = newStartedThread(new CheckedRunnable() {
   688         Thread t = newStartedThread(new CheckedRunnable() {
   689             public void realRun() throws InterruptedException {
   689             public void realRun() throws InterruptedException {
   690                 q.put(new Object());
   690                 q.put(new Object());
   691                 q.put(new Object());
   691                 q.put(new Object());
   692                 long startTime = System.nanoTime();
   692                 long startTime = System.nanoTime();
       
   693 
   693                 assertFalse(q.offer(new Object(), timeoutMillis(), MILLISECONDS));
   694                 assertFalse(q.offer(new Object(), timeoutMillis(), MILLISECONDS));
   694                 assertTrue(millisElapsedSince(startTime) >= timeoutMillis());
   695                 assertTrue(millisElapsedSince(startTime) >= timeoutMillis());
   695 
   696 
   696                 Thread.currentThread().interrupt();
   697                 Thread.currentThread().interrupt();
   697                 try {
   698                 try {
   698                     q.offer(new Object(), 2 * LONG_DELAY_MS, MILLISECONDS);
   699                     q.offer(new Object(), randomTimeout(), randomTimeUnit());
   699                     shouldThrow();
   700                     shouldThrow();
   700                 } catch (InterruptedException success) {}
   701                 } catch (InterruptedException success) {}
   701                 assertFalse(Thread.interrupted());
   702                 assertFalse(Thread.interrupted());
   702 
   703 
   703                 pleaseInterrupt.countDown();
   704                 pleaseInterrupt.countDown();
   704                 try {
   705                 try {
   705                     q.offer(new Object(), 2 * LONG_DELAY_MS, MILLISECONDS);
   706                     q.offer(new Object(), LONGER_DELAY_MS, MILLISECONDS);
   706                     shouldThrow();
   707                     shouldThrow();
   707                 } catch (InterruptedException success) {}
   708                 } catch (InterruptedException success) {}
   708                 assertFalse(Thread.interrupted());
   709                 assertFalse(Thread.interrupted());
   709             }});
   710             }});
   710 
   711 
   711         await(pleaseInterrupt);
   712         await(pleaseInterrupt);
   712         assertThreadBlocks(t, Thread.State.TIMED_WAITING);
   713         if (randomBoolean()) assertThreadBlocks(t, Thread.State.TIMED_WAITING);
   713         t.interrupt();
   714         t.interrupt();
   714         awaitTermination(t);
   715         awaitTermination(t);
   715     }
   716     }
   716 
   717 
   717     /**
   718     /**
   748                 } catch (InterruptedException success) {}
   749                 } catch (InterruptedException success) {}
   749                 assertFalse(Thread.interrupted());
   750                 assertFalse(Thread.interrupted());
   750             }});
   751             }});
   751 
   752 
   752         await(pleaseInterrupt);
   753         await(pleaseInterrupt);
   753         assertThreadBlocks(t, Thread.State.WAITING);
   754         if (randomBoolean()) assertThreadBlocks(t, Thread.State.WAITING);
   754         t.interrupt();
   755         t.interrupt();
   755         awaitTermination(t);
   756         awaitTermination(t);
   756     }
   757     }
   757 
   758 
   758     /**
   759     /**
   800     public void testInterruptedTimedPoll() throws InterruptedException {
   801     public void testInterruptedTimedPoll() throws InterruptedException {
   801         final BlockingQueue<Integer> q = populatedDeque(SIZE);
   802         final BlockingQueue<Integer> q = populatedDeque(SIZE);
   802         final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
   803         final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
   803         Thread t = newStartedThread(new CheckedRunnable() {
   804         Thread t = newStartedThread(new CheckedRunnable() {
   804             public void realRun() throws InterruptedException {
   805             public void realRun() throws InterruptedException {
   805                 long startTime = System.nanoTime();
       
   806                 for (int i = 0; i < SIZE; i++)
   806                 for (int i = 0; i < SIZE; i++)
   807                     assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS));
   807                     assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS));
   808 
   808 
   809                 Thread.currentThread().interrupt();
   809                 Thread.currentThread().interrupt();
   810                 try {
   810                 try {
   811                     q.poll(LONG_DELAY_MS, MILLISECONDS);
   811                     q.poll(randomTimeout(), randomTimeUnit());
   812                     shouldThrow();
   812                     shouldThrow();
   813                 } catch (InterruptedException success) {}
   813                 } catch (InterruptedException success) {}
   814                 assertFalse(Thread.interrupted());
   814                 assertFalse(Thread.interrupted());
   815 
   815 
   816                 pleaseInterrupt.countDown();
   816                 pleaseInterrupt.countDown();
   817                 try {
   817                 try {
   818                     q.poll(LONG_DELAY_MS, MILLISECONDS);
   818                     q.poll(LONGER_DELAY_MS, MILLISECONDS);
   819                     shouldThrow();
   819                     shouldThrow();
   820                 } catch (InterruptedException success) {}
   820                 } catch (InterruptedException success) {}
   821                 assertFalse(Thread.interrupted());
   821                 assertFalse(Thread.interrupted());
   822 
       
   823                 assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
       
   824             }});
   822             }});
   825 
   823 
   826         await(pleaseInterrupt);
   824         await(pleaseInterrupt);
   827         assertThreadBlocks(t, Thread.State.TIMED_WAITING);
   825         if (randomBoolean()) assertThreadBlocks(t, Thread.State.TIMED_WAITING);
   828         t.interrupt();
   826         t.interrupt();
   829         awaitTermination(t);
   827         awaitTermination(t);
   830         checkEmpty(q);
   828         checkEmpty(q);
   831     }
   829     }
   832 
   830 
   881                 } catch (InterruptedException success) {}
   879                 } catch (InterruptedException success) {}
   882                 assertFalse(Thread.interrupted());
   880                 assertFalse(Thread.interrupted());
   883             }});
   881             }});
   884 
   882 
   885         await(pleaseInterrupt);
   883         await(pleaseInterrupt);
   886         assertThreadBlocks(t, Thread.State.WAITING);
   884         if (randomBoolean()) assertThreadBlocks(t, Thread.State.WAITING);
   887         t.interrupt();
   885         t.interrupt();
   888         awaitTermination(t);
   886         awaitTermination(t);
   889         assertEquals(SIZE, q.size());
   887         assertEquals(SIZE, q.size());
   890         assertEquals(0, q.remainingCapacity());
   888         assertEquals(0, q.remainingCapacity());
   891     }
   889     }
   916         await(pleaseTake);
   914         await(pleaseTake);
   917         assertEquals(0, q.remainingCapacity());
   915         assertEquals(0, q.remainingCapacity());
   918         assertEquals(capacity - 1, q.take());
   916         assertEquals(capacity - 1, q.take());
   919 
   917 
   920         await(pleaseInterrupt);
   918         await(pleaseInterrupt);
   921         assertThreadBlocks(t, Thread.State.WAITING);
   919         if (randomBoolean()) assertThreadBlocks(t, Thread.State.WAITING);
   922         t.interrupt();
   920         t.interrupt();
   923         awaitTermination(t);
   921         awaitTermination(t);
   924         assertEquals(0, q.remainingCapacity());
   922         assertEquals(0, q.remainingCapacity());
   925     }
   923     }
   926 
   924 
   933         Thread t = newStartedThread(new CheckedRunnable() {
   931         Thread t = newStartedThread(new CheckedRunnable() {
   934             public void realRun() throws InterruptedException {
   932             public void realRun() throws InterruptedException {
   935                 q.putFirst(new Object());
   933                 q.putFirst(new Object());
   936                 q.putFirst(new Object());
   934                 q.putFirst(new Object());
   937                 long startTime = System.nanoTime();
   935                 long startTime = System.nanoTime();
       
   936 
   938                 assertFalse(q.offerFirst(new Object(), timeoutMillis(), MILLISECONDS));
   937                 assertFalse(q.offerFirst(new Object(), timeoutMillis(), MILLISECONDS));
   939                 assertTrue(millisElapsedSince(startTime) >= timeoutMillis());
   938                 assertTrue(millisElapsedSince(startTime) >= timeoutMillis());
   940 
   939 
   941                 Thread.currentThread().interrupt();
   940                 Thread.currentThread().interrupt();
   942                 try {
   941                 try {
   943                     q.offerFirst(new Object(), 2 * LONG_DELAY_MS, MILLISECONDS);
   942                     q.offerFirst(new Object(), randomTimeout(), randomTimeUnit());
   944                     shouldThrow();
   943                     shouldThrow();
   945                 } catch (InterruptedException success) {}
   944                 } catch (InterruptedException success) {}
   946                 assertFalse(Thread.interrupted());
   945                 assertFalse(Thread.interrupted());
   947 
   946 
   948                 pleaseInterrupt.countDown();
   947                 pleaseInterrupt.countDown();
   949                 try {
   948                 try {
   950                     q.offerFirst(new Object(), 2 * LONG_DELAY_MS, MILLISECONDS);
   949                     q.offerFirst(new Object(), LONGER_DELAY_MS, MILLISECONDS);
   951                     shouldThrow();
   950                     shouldThrow();
   952                 } catch (InterruptedException success) {}
   951                 } catch (InterruptedException success) {}
   953                 assertFalse(Thread.interrupted());
   952                 assertFalse(Thread.interrupted());
   954             }});
   953             }});
   955 
   954 
   956         await(pleaseInterrupt);
   955         await(pleaseInterrupt);
   957         assertThreadBlocks(t, Thread.State.TIMED_WAITING);
   956         if (randomBoolean()) assertThreadBlocks(t, Thread.State.TIMED_WAITING);
   958         t.interrupt();
   957         t.interrupt();
   959         awaitTermination(t);
   958         awaitTermination(t);
   960     }
   959     }
   961 
   960 
   962     /**
   961     /**
   984                 } catch (InterruptedException success) {}
   983                 } catch (InterruptedException success) {}
   985                 assertFalse(Thread.interrupted());
   984                 assertFalse(Thread.interrupted());
   986             }});
   985             }});
   987 
   986 
   988         await(threadStarted);
   987         await(threadStarted);
   989         assertThreadBlocks(t, Thread.State.WAITING);
   988         if (randomBoolean()) assertThreadBlocks(t, Thread.State.WAITING);
   990         t.interrupt();
   989         t.interrupt();
   991         awaitTermination(t);
   990         awaitTermination(t);
   992     }
   991     }
   993 
   992 
   994     /**
   993     /**
  1025                 } catch (InterruptedException success) {}
  1024                 } catch (InterruptedException success) {}
  1026                 assertFalse(Thread.interrupted());
  1025                 assertFalse(Thread.interrupted());
  1027             }});
  1026             }});
  1028 
  1027 
  1029         await(threadStarted);
  1028         await(threadStarted);
  1030         assertThreadBlocks(t, Thread.State.WAITING);
  1029         if (randomBoolean()) assertThreadBlocks(t, Thread.State.WAITING);
  1031         t.interrupt();
  1030         t.interrupt();
  1032         awaitTermination(t);
  1031         awaitTermination(t);
  1033     }
  1032     }
  1034 
  1033 
  1035     /**
  1034     /**
  1075                 } catch (InterruptedException success) {}
  1074                 } catch (InterruptedException success) {}
  1076                 assertFalse(Thread.interrupted());
  1075                 assertFalse(Thread.interrupted());
  1077             }});
  1076             }});
  1078 
  1077 
  1079         await(pleaseInterrupt);
  1078         await(pleaseInterrupt);
  1080         assertThreadBlocks(t, Thread.State.WAITING);
  1079         if (randomBoolean()) assertThreadBlocks(t, Thread.State.WAITING);
  1081         t.interrupt();
  1080         t.interrupt();
  1082         awaitTermination(t);
  1081         awaitTermination(t);
  1083     }
  1082     }
  1084 
  1083 
  1085     /**
  1084     /**
  1116     public void testInterruptedTimedPollFirst() throws InterruptedException {
  1115     public void testInterruptedTimedPollFirst() throws InterruptedException {
  1117         final LinkedBlockingDeque q = populatedDeque(SIZE);
  1116         final LinkedBlockingDeque q = populatedDeque(SIZE);
  1118         final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
  1117         final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
  1119         Thread t = newStartedThread(new CheckedRunnable() {
  1118         Thread t = newStartedThread(new CheckedRunnable() {
  1120             public void realRun() throws InterruptedException {
  1119             public void realRun() throws InterruptedException {
  1121                 long startTime = System.nanoTime();
       
  1122                 for (int i = 0; i < SIZE; i++)
  1120                 for (int i = 0; i < SIZE; i++)
  1123                     assertEquals(i, q.pollFirst(LONG_DELAY_MS, MILLISECONDS));
  1121                     assertEquals(i, q.pollFirst(LONG_DELAY_MS, MILLISECONDS));
  1124 
  1122 
  1125                 Thread.currentThread().interrupt();
  1123                 Thread.currentThread().interrupt();
  1126                 try {
  1124                 try {
  1127                     q.pollFirst(LONG_DELAY_MS, MILLISECONDS);
  1125                     q.pollFirst(randomTimeout(), randomTimeUnit());
  1128                     shouldThrow();
  1126                     shouldThrow();
  1129                 } catch (InterruptedException success) {}
  1127                 } catch (InterruptedException success) {}
  1130                 assertFalse(Thread.interrupted());
  1128                 assertFalse(Thread.interrupted());
  1131 
  1129 
  1132                 pleaseInterrupt.countDown();
  1130                 pleaseInterrupt.countDown();
  1133                 try {
  1131                 try {
  1134                     q.pollFirst(LONG_DELAY_MS, MILLISECONDS);
  1132                     q.pollFirst(LONGER_DELAY_MS, MILLISECONDS);
  1135                     shouldThrow();
  1133                     shouldThrow();
  1136                 } catch (InterruptedException success) {}
  1134                 } catch (InterruptedException success) {}
  1137                 assertFalse(Thread.interrupted());
  1135                 assertFalse(Thread.interrupted());
  1138 
       
  1139                 assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
       
  1140             }});
  1136             }});
  1141 
  1137 
  1142         await(pleaseInterrupt);
  1138         await(pleaseInterrupt);
  1143         assertThreadBlocks(t, Thread.State.TIMED_WAITING);
  1139         if (randomBoolean()) assertThreadBlocks(t, Thread.State.TIMED_WAITING);
  1144         t.interrupt();
  1140         t.interrupt();
  1145         awaitTermination(t);
  1141         awaitTermination(t);
  1146     }
  1142     }
  1147 
  1143 
  1148     /**
  1144     /**
  1162 
  1158 
  1163                 assertSame(zero, q.pollFirst(LONG_DELAY_MS, MILLISECONDS));
  1159                 assertSame(zero, q.pollFirst(LONG_DELAY_MS, MILLISECONDS));
  1164 
  1160 
  1165                 Thread.currentThread().interrupt();
  1161                 Thread.currentThread().interrupt();
  1166                 try {
  1162                 try {
       
  1163                     q.pollFirst(randomTimeout(), randomTimeUnit());
       
  1164                     shouldThrow();
       
  1165                 } catch (InterruptedException success) {}
       
  1166 
       
  1167                 barrier.await();
       
  1168                 try {
  1167                     q.pollFirst(LONG_DELAY_MS, MILLISECONDS);
  1169                     q.pollFirst(LONG_DELAY_MS, MILLISECONDS);
  1168                     shouldThrow();
  1170                     shouldThrow();
  1169                 } catch (InterruptedException success) {}
  1171                 } catch (InterruptedException success) {}
  1170 
  1172                 assertFalse(Thread.interrupted());
  1171                 barrier.await();
  1173 
  1172                 try {
       
  1173                     q.pollFirst(LONG_DELAY_MS, MILLISECONDS);
       
  1174                     shouldThrow();
       
  1175                 } catch (InterruptedException success) {}
       
  1176                 assertFalse(Thread.interrupted());
       
  1177                 assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
  1174                 assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
  1178             }});
  1175             }});
  1179 
  1176 
  1180         barrier.await();
  1177         barrier.await();
  1181         long startTime = System.nanoTime();
  1178         long startTime = System.nanoTime();
  1182         assertTrue(q.offerFirst(zero, LONG_DELAY_MS, MILLISECONDS));
  1179         assertTrue(q.offerFirst(zero, LONG_DELAY_MS, MILLISECONDS));
  1183         assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
  1180         assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
  1184         barrier.await();
  1181         barrier.await();
  1185         assertThreadBlocks(t, Thread.State.TIMED_WAITING);
  1182         if (randomBoolean()) assertThreadBlocks(t, Thread.State.TIMED_WAITING);
  1186         t.interrupt();
  1183         t.interrupt();
  1187         awaitTermination(t);
  1184         awaitTermination(t);
  1188     }
  1185     }
  1189 
  1186 
  1190     /**
  1187     /**
  1238                 } catch (InterruptedException success) {}
  1235                 } catch (InterruptedException success) {}
  1239                 assertFalse(Thread.interrupted());
  1236                 assertFalse(Thread.interrupted());
  1240             }});
  1237             }});
  1241 
  1238 
  1242         await(pleaseInterrupt);
  1239         await(pleaseInterrupt);
  1243         assertThreadBlocks(t, Thread.State.WAITING);
  1240         if (randomBoolean()) assertThreadBlocks(t, Thread.State.WAITING);
  1244         t.interrupt();
  1241         t.interrupt();
  1245         awaitTermination(t);
  1242         awaitTermination(t);
  1246         assertEquals(SIZE, q.size());
  1243         assertEquals(SIZE, q.size());
  1247         assertEquals(0, q.remainingCapacity());
  1244         assertEquals(0, q.remainingCapacity());
  1248     }
  1245     }
  1280         await(pleaseTake);
  1277         await(pleaseTake);
  1281         assertEquals(0, q.remainingCapacity());
  1278         assertEquals(0, q.remainingCapacity());
  1282         assertEquals(0, q.take());
  1279         assertEquals(0, q.take());
  1283 
  1280 
  1284         await(pleaseInterrupt);
  1281         await(pleaseInterrupt);
  1285         assertThreadBlocks(t, Thread.State.WAITING);
  1282         if (randomBoolean()) assertThreadBlocks(t, Thread.State.WAITING);
  1286         t.interrupt();
  1283         t.interrupt();
  1287         awaitTermination(t);
  1284         awaitTermination(t);
  1288         assertEquals(0, q.remainingCapacity());
  1285         assertEquals(0, q.remainingCapacity());
  1289     }
  1286     }
  1290 
  1287 
  1297         Thread t = newStartedThread(new CheckedRunnable() {
  1294         Thread t = newStartedThread(new CheckedRunnable() {
  1298             public void realRun() throws InterruptedException {
  1295             public void realRun() throws InterruptedException {
  1299                 q.putLast(new Object());
  1296                 q.putLast(new Object());
  1300                 q.putLast(new Object());
  1297                 q.putLast(new Object());
  1301                 long startTime = System.nanoTime();
  1298                 long startTime = System.nanoTime();
       
  1299 
  1302                 assertFalse(q.offerLast(new Object(), timeoutMillis(), MILLISECONDS));
  1300                 assertFalse(q.offerLast(new Object(), timeoutMillis(), MILLISECONDS));
  1303                 assertTrue(millisElapsedSince(startTime) >= timeoutMillis());
  1301                 assertTrue(millisElapsedSince(startTime) >= timeoutMillis());
  1304 
  1302 
  1305                 Thread.currentThread().interrupt();
  1303                 Thread.currentThread().interrupt();
  1306                 try {
  1304                 try {
  1307                     q.offerLast(new Object(), 2 * LONG_DELAY_MS, MILLISECONDS);
  1305                     q.offerLast(new Object(), randomTimeout(), randomTimeUnit());
  1308                     shouldThrow();
  1306                     shouldThrow();
  1309                 } catch (InterruptedException success) {}
  1307                 } catch (InterruptedException success) {}
  1310 
  1308 
  1311                 pleaseInterrupt.countDown();
  1309                 pleaseInterrupt.countDown();
  1312                 try {
  1310                 try {
  1313                     q.offerLast(new Object(), 2 * LONG_DELAY_MS, MILLISECONDS);
  1311                     q.offerLast(new Object(), LONGER_DELAY_MS, MILLISECONDS);
  1314                     shouldThrow();
  1312                     shouldThrow();
  1315                 } catch (InterruptedException success) {}
  1313                 } catch (InterruptedException success) {}
  1316             }});
  1314             }});
  1317 
  1315 
  1318         await(pleaseInterrupt);
  1316         await(pleaseInterrupt);
  1319         assertThreadBlocks(t, Thread.State.TIMED_WAITING);
  1317         if (randomBoolean()) assertThreadBlocks(t, Thread.State.TIMED_WAITING);
  1320         t.interrupt();
  1318         t.interrupt();
  1321         awaitTermination(t);
  1319         awaitTermination(t);
  1322     }
  1320     }
  1323 
  1321 
  1324     /**
  1322     /**
  1356                 } catch (InterruptedException success) {}
  1354                 } catch (InterruptedException success) {}
  1357                 assertFalse(Thread.interrupted());
  1355                 assertFalse(Thread.interrupted());
  1358             }});
  1356             }});
  1359 
  1357 
  1360         await(pleaseInterrupt);
  1358         await(pleaseInterrupt);
  1361         assertThreadBlocks(t, Thread.State.WAITING);
  1359         if (randomBoolean()) assertThreadBlocks(t, Thread.State.WAITING);
  1362         t.interrupt();
  1360         t.interrupt();
  1363         awaitTermination(t);
  1361         awaitTermination(t);
  1364     }
  1362     }
  1365 
  1363 
  1366     /**
  1364     /**
  1397     public void testInterruptedTimedPollLast() throws InterruptedException {
  1395     public void testInterruptedTimedPollLast() throws InterruptedException {
  1398         final LinkedBlockingDeque q = populatedDeque(SIZE);
  1396         final LinkedBlockingDeque q = populatedDeque(SIZE);
  1399         final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
  1397         final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
  1400         Thread t = newStartedThread(new CheckedRunnable() {
  1398         Thread t = newStartedThread(new CheckedRunnable() {
  1401             public void realRun() throws InterruptedException {
  1399             public void realRun() throws InterruptedException {
  1402                 long startTime = System.nanoTime();
       
  1403                 for (int i = 0; i < SIZE; i++)
  1400                 for (int i = 0; i < SIZE; i++)
  1404                     assertEquals(SIZE - i - 1,
  1401                     assertEquals(SIZE - i - 1,
  1405                                  q.pollLast(LONG_DELAY_MS, MILLISECONDS));
  1402                                  q.pollLast(LONG_DELAY_MS, MILLISECONDS));
  1406 
  1403 
  1407                 Thread.currentThread().interrupt();
  1404                 Thread.currentThread().interrupt();
  1408                 try {
  1405                 try {
  1409                     q.pollLast(LONG_DELAY_MS, MILLISECONDS);
  1406                     q.pollLast(randomTimeout(), randomTimeUnit());
  1410                     shouldThrow();
  1407                     shouldThrow();
  1411                 } catch (InterruptedException success) {}
  1408                 } catch (InterruptedException success) {}
  1412                 assertFalse(Thread.interrupted());
  1409                 assertFalse(Thread.interrupted());
  1413 
  1410 
  1414                 pleaseInterrupt.countDown();
  1411                 pleaseInterrupt.countDown();
  1415                 try {
  1412                 try {
  1416                     q.pollLast(LONG_DELAY_MS, MILLISECONDS);
  1413                     q.pollLast(LONGER_DELAY_MS, MILLISECONDS);
  1417                     shouldThrow();
  1414                     shouldThrow();
  1418                 } catch (InterruptedException success) {}
  1415                 } catch (InterruptedException success) {}
  1419                 assertFalse(Thread.interrupted());
  1416                 assertFalse(Thread.interrupted());
  1420 
       
  1421                 assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
       
  1422             }});
  1417             }});
  1423 
  1418 
  1424         await(pleaseInterrupt);
  1419         await(pleaseInterrupt);
  1425         assertThreadBlocks(t, Thread.State.TIMED_WAITING);
  1420         if (randomBoolean()) assertThreadBlocks(t, Thread.State.TIMED_WAITING);
  1426         t.interrupt();
  1421         t.interrupt();
  1427         awaitTermination(t);
  1422         awaitTermination(t);
  1428         checkEmpty(q);
  1423         checkEmpty(q);
  1429     }
  1424     }
  1430 
  1425 
  1445 
  1440 
  1446                 assertSame(zero, q.poll(LONG_DELAY_MS, MILLISECONDS));
  1441                 assertSame(zero, q.poll(LONG_DELAY_MS, MILLISECONDS));
  1447 
  1442 
  1448                 Thread.currentThread().interrupt();
  1443                 Thread.currentThread().interrupt();
  1449                 try {
  1444                 try {
  1450                     q.poll(LONG_DELAY_MS, MILLISECONDS);
  1445                     q.poll(randomTimeout(), randomTimeUnit());
  1451                     shouldThrow();
  1446                     shouldThrow();
  1452                 } catch (InterruptedException success) {}
  1447                 } catch (InterruptedException success) {}
  1453                 assertFalse(Thread.interrupted());
  1448                 assertFalse(Thread.interrupted());
  1454 
  1449 
  1455                 barrier.await();
  1450                 barrier.await();
  1466         long startTime = System.nanoTime();
  1461         long startTime = System.nanoTime();
  1467         assertTrue(q.offerLast(zero, LONG_DELAY_MS, MILLISECONDS));
  1462         assertTrue(q.offerLast(zero, LONG_DELAY_MS, MILLISECONDS));
  1468         assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
  1463         assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
  1469 
  1464 
  1470         barrier.await();
  1465         barrier.await();
  1471         assertThreadBlocks(t, Thread.State.TIMED_WAITING);
  1466         if (randomBoolean()) assertThreadBlocks(t, Thread.State.TIMED_WAITING);
  1472         t.interrupt();
  1467         t.interrupt();
  1473         awaitTermination(t);
  1468         awaitTermination(t);
  1474     }
  1469     }
  1475 
  1470 
  1476     /**
  1471     /**