< prev index next >

test/jdk/java/util/concurrent/tck/LinkedBlockingDequeTest.java

Print this page
8225490: Miscellaneous changes imported from jsr166 CVS 2019-09
Reviewed-by: martin, alanb

*** 629,639 **** } catch (InterruptedException success) {} assertFalse(Thread.interrupted()); }}); await(pleaseInterrupt); ! assertThreadBlocks(t, Thread.State.WAITING); t.interrupt(); awaitTermination(t); assertEquals(SIZE, q.size()); assertEquals(0, q.remainingCapacity()); } --- 629,639 ---- } catch (InterruptedException success) {} assertFalse(Thread.interrupted()); }}); await(pleaseInterrupt); ! if (randomBoolean()) assertThreadBlocks(t, Thread.State.WAITING); t.interrupt(); awaitTermination(t); assertEquals(SIZE, q.size()); assertEquals(0, q.remainingCapacity()); }
*** 671,681 **** await(pleaseTake); assertEquals(0, q.remainingCapacity()); assertEquals(0, q.take()); await(pleaseInterrupt); ! assertThreadBlocks(t, Thread.State.WAITING); t.interrupt(); awaitTermination(t); assertEquals(0, q.remainingCapacity()); } --- 671,681 ---- await(pleaseTake); assertEquals(0, q.remainingCapacity()); assertEquals(0, q.take()); await(pleaseInterrupt); ! if (randomBoolean()) assertThreadBlocks(t, Thread.State.WAITING); t.interrupt(); awaitTermination(t); assertEquals(0, q.remainingCapacity()); }
*** 688,717 **** Thread t = newStartedThread(new CheckedRunnable() { public void realRun() throws InterruptedException { q.put(new Object()); q.put(new Object()); long startTime = System.nanoTime(); assertFalse(q.offer(new Object(), timeoutMillis(), MILLISECONDS)); assertTrue(millisElapsedSince(startTime) >= timeoutMillis()); Thread.currentThread().interrupt(); try { ! q.offer(new Object(), 2 * LONG_DELAY_MS, MILLISECONDS); shouldThrow(); } catch (InterruptedException success) {} assertFalse(Thread.interrupted()); pleaseInterrupt.countDown(); try { ! q.offer(new Object(), 2 * LONG_DELAY_MS, MILLISECONDS); shouldThrow(); } catch (InterruptedException success) {} assertFalse(Thread.interrupted()); }}); await(pleaseInterrupt); ! assertThreadBlocks(t, Thread.State.TIMED_WAITING); t.interrupt(); awaitTermination(t); } /** --- 688,718 ---- Thread t = newStartedThread(new CheckedRunnable() { public void realRun() throws InterruptedException { q.put(new Object()); q.put(new Object()); long startTime = System.nanoTime(); + assertFalse(q.offer(new Object(), timeoutMillis(), MILLISECONDS)); assertTrue(millisElapsedSince(startTime) >= timeoutMillis()); Thread.currentThread().interrupt(); try { ! q.offer(new Object(), randomTimeout(), randomTimeUnit()); shouldThrow(); } catch (InterruptedException success) {} assertFalse(Thread.interrupted()); pleaseInterrupt.countDown(); try { ! q.offer(new Object(), LONGER_DELAY_MS, MILLISECONDS); shouldThrow(); } catch (InterruptedException success) {} assertFalse(Thread.interrupted()); }}); await(pleaseInterrupt); ! if (randomBoolean()) assertThreadBlocks(t, Thread.State.TIMED_WAITING); t.interrupt(); awaitTermination(t); } /**
*** 748,758 **** } catch (InterruptedException success) {} assertFalse(Thread.interrupted()); }}); await(pleaseInterrupt); ! assertThreadBlocks(t, Thread.State.WAITING); t.interrupt(); awaitTermination(t); } /** --- 749,759 ---- } catch (InterruptedException success) {} assertFalse(Thread.interrupted()); }}); await(pleaseInterrupt); ! if (randomBoolean()) assertThreadBlocks(t, Thread.State.WAITING); t.interrupt(); awaitTermination(t); } /**
*** 800,832 **** public void testInterruptedTimedPoll() throws InterruptedException { final BlockingQueue<Integer> q = populatedDeque(SIZE); final CountDownLatch pleaseInterrupt = new CountDownLatch(1); Thread t = newStartedThread(new CheckedRunnable() { public void realRun() throws InterruptedException { - long startTime = System.nanoTime(); for (int i = 0; i < SIZE; i++) assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS)); Thread.currentThread().interrupt(); try { ! q.poll(LONG_DELAY_MS, MILLISECONDS); shouldThrow(); } catch (InterruptedException success) {} assertFalse(Thread.interrupted()); pleaseInterrupt.countDown(); try { ! q.poll(LONG_DELAY_MS, MILLISECONDS); shouldThrow(); } catch (InterruptedException success) {} assertFalse(Thread.interrupted()); - - assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); }}); await(pleaseInterrupt); ! assertThreadBlocks(t, Thread.State.TIMED_WAITING); t.interrupt(); awaitTermination(t); checkEmpty(q); } --- 801,830 ---- public void testInterruptedTimedPoll() throws InterruptedException { final BlockingQueue<Integer> q = populatedDeque(SIZE); final CountDownLatch pleaseInterrupt = new CountDownLatch(1); Thread t = newStartedThread(new CheckedRunnable() { public void realRun() throws InterruptedException { for (int i = 0; i < SIZE; i++) assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS)); Thread.currentThread().interrupt(); try { ! q.poll(randomTimeout(), randomTimeUnit()); shouldThrow(); } catch (InterruptedException success) {} assertFalse(Thread.interrupted()); pleaseInterrupt.countDown(); try { ! q.poll(LONGER_DELAY_MS, MILLISECONDS); shouldThrow(); } catch (InterruptedException success) {} assertFalse(Thread.interrupted()); }}); await(pleaseInterrupt); ! if (randomBoolean()) assertThreadBlocks(t, Thread.State.TIMED_WAITING); t.interrupt(); awaitTermination(t); checkEmpty(q); }
*** 881,891 **** } catch (InterruptedException success) {} assertFalse(Thread.interrupted()); }}); await(pleaseInterrupt); ! assertThreadBlocks(t, Thread.State.WAITING); t.interrupt(); awaitTermination(t); assertEquals(SIZE, q.size()); assertEquals(0, q.remainingCapacity()); } --- 879,889 ---- } catch (InterruptedException success) {} assertFalse(Thread.interrupted()); }}); await(pleaseInterrupt); ! if (randomBoolean()) assertThreadBlocks(t, Thread.State.WAITING); t.interrupt(); awaitTermination(t); assertEquals(SIZE, q.size()); assertEquals(0, q.remainingCapacity()); }
*** 916,926 **** await(pleaseTake); assertEquals(0, q.remainingCapacity()); assertEquals(capacity - 1, q.take()); await(pleaseInterrupt); ! assertThreadBlocks(t, Thread.State.WAITING); t.interrupt(); awaitTermination(t); assertEquals(0, q.remainingCapacity()); } --- 914,924 ---- await(pleaseTake); assertEquals(0, q.remainingCapacity()); assertEquals(capacity - 1, q.take()); await(pleaseInterrupt); ! if (randomBoolean()) assertThreadBlocks(t, Thread.State.WAITING); t.interrupt(); awaitTermination(t); assertEquals(0, q.remainingCapacity()); }
*** 933,962 **** Thread t = newStartedThread(new CheckedRunnable() { public void realRun() throws InterruptedException { q.putFirst(new Object()); q.putFirst(new Object()); long startTime = System.nanoTime(); assertFalse(q.offerFirst(new Object(), timeoutMillis(), MILLISECONDS)); assertTrue(millisElapsedSince(startTime) >= timeoutMillis()); Thread.currentThread().interrupt(); try { ! q.offerFirst(new Object(), 2 * LONG_DELAY_MS, MILLISECONDS); shouldThrow(); } catch (InterruptedException success) {} assertFalse(Thread.interrupted()); pleaseInterrupt.countDown(); try { ! q.offerFirst(new Object(), 2 * LONG_DELAY_MS, MILLISECONDS); shouldThrow(); } catch (InterruptedException success) {} assertFalse(Thread.interrupted()); }}); await(pleaseInterrupt); ! assertThreadBlocks(t, Thread.State.TIMED_WAITING); t.interrupt(); awaitTermination(t); } /** --- 931,961 ---- Thread t = newStartedThread(new CheckedRunnable() { public void realRun() throws InterruptedException { q.putFirst(new Object()); q.putFirst(new Object()); long startTime = System.nanoTime(); + assertFalse(q.offerFirst(new Object(), timeoutMillis(), MILLISECONDS)); assertTrue(millisElapsedSince(startTime) >= timeoutMillis()); Thread.currentThread().interrupt(); try { ! q.offerFirst(new Object(), randomTimeout(), randomTimeUnit()); shouldThrow(); } catch (InterruptedException success) {} assertFalse(Thread.interrupted()); pleaseInterrupt.countDown(); try { ! q.offerFirst(new Object(), LONGER_DELAY_MS, MILLISECONDS); shouldThrow(); } catch (InterruptedException success) {} assertFalse(Thread.interrupted()); }}); await(pleaseInterrupt); ! if (randomBoolean()) assertThreadBlocks(t, Thread.State.TIMED_WAITING); t.interrupt(); awaitTermination(t); } /**
*** 984,994 **** } catch (InterruptedException success) {} assertFalse(Thread.interrupted()); }}); await(threadStarted); ! assertThreadBlocks(t, Thread.State.WAITING); t.interrupt(); awaitTermination(t); } /** --- 983,993 ---- } catch (InterruptedException success) {} assertFalse(Thread.interrupted()); }}); await(threadStarted); ! if (randomBoolean()) assertThreadBlocks(t, Thread.State.WAITING); t.interrupt(); awaitTermination(t); } /**
*** 1025,1035 **** } catch (InterruptedException success) {} assertFalse(Thread.interrupted()); }}); await(threadStarted); ! assertThreadBlocks(t, Thread.State.WAITING); t.interrupt(); awaitTermination(t); } /** --- 1024,1034 ---- } catch (InterruptedException success) {} assertFalse(Thread.interrupted()); }}); await(threadStarted); ! if (randomBoolean()) assertThreadBlocks(t, Thread.State.WAITING); t.interrupt(); awaitTermination(t); } /**
*** 1075,1085 **** } catch (InterruptedException success) {} assertFalse(Thread.interrupted()); }}); await(pleaseInterrupt); ! assertThreadBlocks(t, Thread.State.WAITING); t.interrupt(); awaitTermination(t); } /** --- 1074,1084 ---- } catch (InterruptedException success) {} assertFalse(Thread.interrupted()); }}); await(pleaseInterrupt); ! if (randomBoolean()) assertThreadBlocks(t, Thread.State.WAITING); t.interrupt(); awaitTermination(t); } /**
*** 1116,1148 **** public void testInterruptedTimedPollFirst() throws InterruptedException { final LinkedBlockingDeque q = populatedDeque(SIZE); final CountDownLatch pleaseInterrupt = new CountDownLatch(1); Thread t = newStartedThread(new CheckedRunnable() { public void realRun() throws InterruptedException { - long startTime = System.nanoTime(); for (int i = 0; i < SIZE; i++) assertEquals(i, q.pollFirst(LONG_DELAY_MS, MILLISECONDS)); Thread.currentThread().interrupt(); try { ! q.pollFirst(LONG_DELAY_MS, MILLISECONDS); shouldThrow(); } catch (InterruptedException success) {} assertFalse(Thread.interrupted()); pleaseInterrupt.countDown(); try { ! q.pollFirst(LONG_DELAY_MS, MILLISECONDS); shouldThrow(); } catch (InterruptedException success) {} assertFalse(Thread.interrupted()); - - assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); }}); await(pleaseInterrupt); ! assertThreadBlocks(t, Thread.State.TIMED_WAITING); t.interrupt(); awaitTermination(t); } /** --- 1115,1144 ---- public void testInterruptedTimedPollFirst() throws InterruptedException { final LinkedBlockingDeque q = populatedDeque(SIZE); final CountDownLatch pleaseInterrupt = new CountDownLatch(1); Thread t = newStartedThread(new CheckedRunnable() { public void realRun() throws InterruptedException { for (int i = 0; i < SIZE; i++) assertEquals(i, q.pollFirst(LONG_DELAY_MS, MILLISECONDS)); Thread.currentThread().interrupt(); try { ! q.pollFirst(randomTimeout(), randomTimeUnit()); shouldThrow(); } catch (InterruptedException success) {} assertFalse(Thread.interrupted()); pleaseInterrupt.countDown(); try { ! q.pollFirst(LONGER_DELAY_MS, MILLISECONDS); shouldThrow(); } catch (InterruptedException success) {} assertFalse(Thread.interrupted()); }}); await(pleaseInterrupt); ! if (randomBoolean()) assertThreadBlocks(t, Thread.State.TIMED_WAITING); t.interrupt(); awaitTermination(t); } /**
*** 1162,1190 **** assertSame(zero, q.pollFirst(LONG_DELAY_MS, MILLISECONDS)); Thread.currentThread().interrupt(); try { ! q.pollFirst(LONG_DELAY_MS, MILLISECONDS); shouldThrow(); } catch (InterruptedException success) {} barrier.await(); try { q.pollFirst(LONG_DELAY_MS, MILLISECONDS); shouldThrow(); } catch (InterruptedException success) {} assertFalse(Thread.interrupted()); assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); }}); barrier.await(); long startTime = System.nanoTime(); assertTrue(q.offerFirst(zero, LONG_DELAY_MS, MILLISECONDS)); assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); barrier.await(); ! assertThreadBlocks(t, Thread.State.TIMED_WAITING); t.interrupt(); awaitTermination(t); } /** --- 1158,1187 ---- assertSame(zero, q.pollFirst(LONG_DELAY_MS, MILLISECONDS)); Thread.currentThread().interrupt(); try { ! q.pollFirst(randomTimeout(), randomTimeUnit()); shouldThrow(); } catch (InterruptedException success) {} barrier.await(); try { q.pollFirst(LONG_DELAY_MS, MILLISECONDS); shouldThrow(); } catch (InterruptedException success) {} assertFalse(Thread.interrupted()); + assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); }}); barrier.await(); long startTime = System.nanoTime(); assertTrue(q.offerFirst(zero, LONG_DELAY_MS, MILLISECONDS)); assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); barrier.await(); ! if (randomBoolean()) assertThreadBlocks(t, Thread.State.TIMED_WAITING); t.interrupt(); awaitTermination(t); } /**
*** 1238,1248 **** } catch (InterruptedException success) {} assertFalse(Thread.interrupted()); }}); await(pleaseInterrupt); ! assertThreadBlocks(t, Thread.State.WAITING); t.interrupt(); awaitTermination(t); assertEquals(SIZE, q.size()); assertEquals(0, q.remainingCapacity()); } --- 1235,1245 ---- } catch (InterruptedException success) {} assertFalse(Thread.interrupted()); }}); await(pleaseInterrupt); ! if (randomBoolean()) assertThreadBlocks(t, Thread.State.WAITING); t.interrupt(); awaitTermination(t); assertEquals(SIZE, q.size()); assertEquals(0, q.remainingCapacity()); }
*** 1280,1290 **** await(pleaseTake); assertEquals(0, q.remainingCapacity()); assertEquals(0, q.take()); await(pleaseInterrupt); ! assertThreadBlocks(t, Thread.State.WAITING); t.interrupt(); awaitTermination(t); assertEquals(0, q.remainingCapacity()); } --- 1277,1287 ---- await(pleaseTake); assertEquals(0, q.remainingCapacity()); assertEquals(0, q.take()); await(pleaseInterrupt); ! if (randomBoolean()) assertThreadBlocks(t, Thread.State.WAITING); t.interrupt(); awaitTermination(t); assertEquals(0, q.remainingCapacity()); }
*** 1297,1324 **** Thread t = newStartedThread(new CheckedRunnable() { public void realRun() throws InterruptedException { q.putLast(new Object()); q.putLast(new Object()); long startTime = System.nanoTime(); assertFalse(q.offerLast(new Object(), timeoutMillis(), MILLISECONDS)); assertTrue(millisElapsedSince(startTime) >= timeoutMillis()); Thread.currentThread().interrupt(); try { ! q.offerLast(new Object(), 2 * LONG_DELAY_MS, MILLISECONDS); shouldThrow(); } catch (InterruptedException success) {} pleaseInterrupt.countDown(); try { ! q.offerLast(new Object(), 2 * LONG_DELAY_MS, MILLISECONDS); shouldThrow(); } catch (InterruptedException success) {} }}); await(pleaseInterrupt); ! assertThreadBlocks(t, Thread.State.TIMED_WAITING); t.interrupt(); awaitTermination(t); } /** --- 1294,1322 ---- Thread t = newStartedThread(new CheckedRunnable() { public void realRun() throws InterruptedException { q.putLast(new Object()); q.putLast(new Object()); long startTime = System.nanoTime(); + assertFalse(q.offerLast(new Object(), timeoutMillis(), MILLISECONDS)); assertTrue(millisElapsedSince(startTime) >= timeoutMillis()); Thread.currentThread().interrupt(); try { ! q.offerLast(new Object(), randomTimeout(), randomTimeUnit()); shouldThrow(); } catch (InterruptedException success) {} pleaseInterrupt.countDown(); try { ! q.offerLast(new Object(), LONGER_DELAY_MS, MILLISECONDS); shouldThrow(); } catch (InterruptedException success) {} }}); await(pleaseInterrupt); ! if (randomBoolean()) assertThreadBlocks(t, Thread.State.TIMED_WAITING); t.interrupt(); awaitTermination(t); } /**
*** 1356,1366 **** } catch (InterruptedException success) {} assertFalse(Thread.interrupted()); }}); await(pleaseInterrupt); ! assertThreadBlocks(t, Thread.State.WAITING); t.interrupt(); awaitTermination(t); } /** --- 1354,1364 ---- } catch (InterruptedException success) {} assertFalse(Thread.interrupted()); }}); await(pleaseInterrupt); ! if (randomBoolean()) assertThreadBlocks(t, Thread.State.WAITING); t.interrupt(); awaitTermination(t); } /**
*** 1397,1430 **** public void testInterruptedTimedPollLast() throws InterruptedException { final LinkedBlockingDeque q = populatedDeque(SIZE); final CountDownLatch pleaseInterrupt = new CountDownLatch(1); Thread t = newStartedThread(new CheckedRunnable() { public void realRun() throws InterruptedException { - long startTime = System.nanoTime(); for (int i = 0; i < SIZE; i++) assertEquals(SIZE - i - 1, q.pollLast(LONG_DELAY_MS, MILLISECONDS)); Thread.currentThread().interrupt(); try { ! q.pollLast(LONG_DELAY_MS, MILLISECONDS); shouldThrow(); } catch (InterruptedException success) {} assertFalse(Thread.interrupted()); pleaseInterrupt.countDown(); try { ! q.pollLast(LONG_DELAY_MS, MILLISECONDS); shouldThrow(); } catch (InterruptedException success) {} assertFalse(Thread.interrupted()); - - assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); }}); await(pleaseInterrupt); ! assertThreadBlocks(t, Thread.State.TIMED_WAITING); t.interrupt(); awaitTermination(t); checkEmpty(q); } --- 1395,1425 ---- public void testInterruptedTimedPollLast() throws InterruptedException { final LinkedBlockingDeque q = populatedDeque(SIZE); final CountDownLatch pleaseInterrupt = new CountDownLatch(1); Thread t = newStartedThread(new CheckedRunnable() { public void realRun() throws InterruptedException { for (int i = 0; i < SIZE; i++) assertEquals(SIZE - i - 1, q.pollLast(LONG_DELAY_MS, MILLISECONDS)); Thread.currentThread().interrupt(); try { ! q.pollLast(randomTimeout(), randomTimeUnit()); shouldThrow(); } catch (InterruptedException success) {} assertFalse(Thread.interrupted()); pleaseInterrupt.countDown(); try { ! q.pollLast(LONGER_DELAY_MS, MILLISECONDS); shouldThrow(); } catch (InterruptedException success) {} assertFalse(Thread.interrupted()); }}); await(pleaseInterrupt); ! if (randomBoolean()) assertThreadBlocks(t, Thread.State.TIMED_WAITING); t.interrupt(); awaitTermination(t); checkEmpty(q); }
*** 1445,1455 **** assertSame(zero, q.poll(LONG_DELAY_MS, MILLISECONDS)); Thread.currentThread().interrupt(); try { ! q.poll(LONG_DELAY_MS, MILLISECONDS); shouldThrow(); } catch (InterruptedException success) {} assertFalse(Thread.interrupted()); barrier.await(); --- 1440,1450 ---- assertSame(zero, q.poll(LONG_DELAY_MS, MILLISECONDS)); Thread.currentThread().interrupt(); try { ! q.poll(randomTimeout(), randomTimeUnit()); shouldThrow(); } catch (InterruptedException success) {} assertFalse(Thread.interrupted()); barrier.await();
*** 1466,1476 **** long startTime = System.nanoTime(); assertTrue(q.offerLast(zero, LONG_DELAY_MS, MILLISECONDS)); assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); barrier.await(); ! assertThreadBlocks(t, Thread.State.TIMED_WAITING); t.interrupt(); awaitTermination(t); } /** --- 1461,1471 ---- long startTime = System.nanoTime(); assertTrue(q.offerLast(zero, LONG_DELAY_MS, MILLISECONDS)); assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); barrier.await(); ! if (randomBoolean()) assertThreadBlocks(t, Thread.State.TIMED_WAITING); t.interrupt(); awaitTermination(t); } /**
< prev index next >