--- jsr166/src/test/tck/BlockingQueueTest.java 2017/05/13 22:38:09 1.19 +++ jsr166/src/test/tck/BlockingQueueTest.java 2019/09/05 21:30:59 1.24 @@ -106,7 +106,7 @@ public abstract class BlockingQueueTest } /** - * put(null) throws NullPointerException + * addAll(null) throws NullPointerException */ public void testAddAllNull() throws InterruptedException { final Collection q = emptyCollection(); @@ -134,7 +134,7 @@ public abstract class BlockingQueueTest public void testToArray_NullArray() { final Collection q = emptyCollection(); try { - q.toArray(null); + q.toArray((Object[])null); shouldThrow(); } catch (NullPointerException success) {} } @@ -189,18 +189,20 @@ public abstract class BlockingQueueTest public void testDrainToNonPositiveMaxElements() { final BlockingQueue q = emptyCollection(); final int[] ns = { 0, -1, -42, Integer.MIN_VALUE }; - for (int n : ns) - assertEquals(0, q.drainTo(new ArrayList(), n)); + final ArrayList sink = new ArrayList(); + for (int n : ns) { + assertEquals(0, q.drainTo(sink, n)); + assertTrue(sink.isEmpty()); + } if (q.remainingCapacity() > 0) { // Not SynchronousQueue, that is Object one = makeElement(1); q.add(one); - ArrayList c = new ArrayList(); for (int n : ns) - assertEquals(0, q.drainTo(new ArrayList(), n)); + assertEquals(0, q.drainTo(sink, n)); assertEquals(1, q.size()); assertSame(one, q.poll()); - assertTrue(c.isEmpty()); + assertTrue(sink.isEmpty()); } } @@ -224,7 +226,7 @@ public abstract class BlockingQueueTest Thread.currentThread().interrupt(); try { - q.poll(LONG_DELAY_MS, MILLISECONDS); + q.poll(randomTimeout(), randomTimeUnit()); shouldThrow(); } catch (InterruptedException success) {} assertFalse(Thread.interrupted()); @@ -245,7 +247,7 @@ public abstract class BlockingQueueTest assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); barrier.await(); - assertThreadBlocks(t, Thread.State.TIMED_WAITING); + if (randomBoolean()) assertThreadBlocks(t, Thread.State.TIMED_WAITING); t.interrupt(); awaitTermination(t); } @@ -267,7 +269,7 @@ public abstract class BlockingQueueTest }}); await(threadStarted); - assertThreadBlocks(t, Thread.State.WAITING); + if (randomBoolean()) assertThreadBlocks(t, Thread.State.WAITING); t.interrupt(); awaitTermination(t); } @@ -296,19 +298,19 @@ public abstract class BlockingQueueTest */ public void testTimedPollFromEmptyBlocksInterruptibly() { final BlockingQueue q = emptyCollection(); - final CountDownLatch threadStarted = new CountDownLatch(1); + final CountDownLatch pleaseInterrupt = new CountDownLatch(1); Thread t = newStartedThread(new CheckedRunnable() { public void realRun() { - threadStarted.countDown(); + pleaseInterrupt.countDown(); try { - q.poll(2 * LONG_DELAY_MS, MILLISECONDS); + q.poll(LONGER_DELAY_MS, MILLISECONDS); shouldThrow(); } catch (InterruptedException success) {} assertFalse(Thread.interrupted()); }}); - await(threadStarted); - assertThreadBlocks(t, Thread.State.TIMED_WAITING); + await(pleaseInterrupt); + if (randomBoolean()) assertThreadBlocks(t, Thread.State.TIMED_WAITING); t.interrupt(); awaitTermination(t); } @@ -323,7 +325,7 @@ public abstract class BlockingQueueTest public void realRun() { Thread.currentThread().interrupt(); try { - q.poll(2 * LONG_DELAY_MS, MILLISECONDS); + q.poll(LONGER_DELAY_MS, MILLISECONDS); shouldThrow(); } catch (InterruptedException success) {} assertFalse(Thread.interrupted());