ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/BlockingQueueTest.java
(Generate patch)

Comparing jsr166/src/test/tck/BlockingQueueTest.java (file contents):
Revision 1.15 by jsr166, Sun May 24 01:23:17 2015 UTC vs.
Revision 1.24 by jsr166, Thu Sep 5 21:30:59 2019 UTC

# Line 106 | Line 106 | public abstract class BlockingQueueTest
106      }
107  
108      /**
109 <     * put(null) throws NullPointerException
109 >     * addAll(null) throws NullPointerException
110       */
111      public void testAddAllNull() throws InterruptedException {
112          final Collection q = emptyCollection();
# Line 134 | Line 134 | public abstract class BlockingQueueTest
134      public void testToArray_NullArray() {
135          final Collection q = emptyCollection();
136          try {
137 <            q.toArray(null);
137 >            q.toArray((Object[])null);
138              shouldThrow();
139          } catch (NullPointerException success) {}
140      }
# Line 189 | Line 189 | public abstract class BlockingQueueTest
189      public void testDrainToNonPositiveMaxElements() {
190          final BlockingQueue q = emptyCollection();
191          final int[] ns = { 0, -1, -42, Integer.MIN_VALUE };
192 <        for (int n : ns)
193 <            assertEquals(0, q.drainTo(new ArrayList(), n));
192 >        final ArrayList sink = new ArrayList();
193 >        for (int n : ns) {
194 >            assertEquals(0, q.drainTo(sink, n));
195 >            assertTrue(sink.isEmpty());
196 >        }
197          if (q.remainingCapacity() > 0) {
198              // Not SynchronousQueue, that is
199              Object one = makeElement(1);
200              q.add(one);
198            ArrayList c = new ArrayList();
201              for (int n : ns)
202 <                assertEquals(0, q.drainTo(new ArrayList(), n));
202 >                assertEquals(0, q.drainTo(sink, n));
203              assertEquals(1, q.size());
204              assertSame(one, q.poll());
205 <            assertTrue(c.isEmpty());
205 >            assertTrue(sink.isEmpty());
206          }
207      }
208  
# Line 224 | Line 226 | public abstract class BlockingQueueTest
226  
227                  Thread.currentThread().interrupt();
228                  try {
229 <                    q.poll(LONG_DELAY_MS, MILLISECONDS);
229 >                    q.poll(randomTimeout(), randomTimeUnit());
230                      shouldThrow();
231                  } catch (InterruptedException success) {}
232                  assertFalse(Thread.interrupted());
# Line 235 | Line 237 | public abstract class BlockingQueueTest
237                      shouldThrow();
238                  } catch (InterruptedException success) {}
239                  assertFalse(Thread.interrupted());
240 +
241 +                assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
242              }});
243  
244          barrier.await();
# Line 243 | Line 247 | public abstract class BlockingQueueTest
247          assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
248  
249          barrier.await();
250 <        assertThreadStaysAlive(t);
250 >        if (randomBoolean()) assertThreadBlocks(t, Thread.State.TIMED_WAITING);
251          t.interrupt();
252          awaitTermination(t);
253      }
# Line 265 | Line 269 | public abstract class BlockingQueueTest
269              }});
270  
271          await(threadStarted);
272 <        assertThreadStaysAlive(t);
272 >        if (randomBoolean()) assertThreadBlocks(t, Thread.State.WAITING);
273          t.interrupt();
274          awaitTermination(t);
275      }
# Line 294 | Line 298 | public abstract class BlockingQueueTest
298       */
299      public void testTimedPollFromEmptyBlocksInterruptibly() {
300          final BlockingQueue q = emptyCollection();
301 <        final CountDownLatch threadStarted = new CountDownLatch(1);
301 >        final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
302          Thread t = newStartedThread(new CheckedRunnable() {
303              public void realRun() {
304 <                threadStarted.countDown();
304 >                pleaseInterrupt.countDown();
305                  try {
306 <                    q.poll(2 * LONG_DELAY_MS, MILLISECONDS);
306 >                    q.poll(LONGER_DELAY_MS, MILLISECONDS);
307                      shouldThrow();
308                  } catch (InterruptedException success) {}
309                  assertFalse(Thread.interrupted());
310              }});
311  
312 <        await(threadStarted);
313 <        assertThreadStaysAlive(t);
312 >        await(pleaseInterrupt);
313 >        if (randomBoolean()) assertThreadBlocks(t, Thread.State.TIMED_WAITING);
314          t.interrupt();
315          awaitTermination(t);
316      }
# Line 321 | Line 325 | public abstract class BlockingQueueTest
325              public void realRun() {
326                  Thread.currentThread().interrupt();
327                  try {
328 <                    q.poll(2 * LONG_DELAY_MS, MILLISECONDS);
328 >                    q.poll(LONGER_DELAY_MS, MILLISECONDS);
329                      shouldThrow();
330                  } catch (InterruptedException success) {}
331                  assertFalse(Thread.interrupted());
# Line 348 | Line 352 | public abstract class BlockingQueueTest
352                  assertEquals((pass == 0), q.contains(elts[i]));
353                  assertEquals((pass == 0), q.remove(elts[i]));
354                  assertFalse(q.contains(elts[i]));
355 <                assertTrue(q.contains(elts[i-1]));
355 >                assertTrue(q.contains(elts[i - 1]));
356                  if (i < size - 1)
357 <                    assertTrue(q.contains(elts[i+1]));
357 >                    assertTrue(q.contains(elts[i + 1]));
358              }
359          }
360          if (size > 0)
361              assertTrue(q.contains(elts[0]));
362          for (int i = size - 2; i >= 0; i -= 2) {
363              assertTrue(q.contains(elts[i]));
364 <            assertFalse(q.contains(elts[i+1]));
364 >            assertFalse(q.contains(elts[i + 1]));
365              assertTrue(q.remove(elts[i]));
366              assertFalse(q.contains(elts[i]));
367 <            assertFalse(q.remove(elts[i+1]));
368 <            assertFalse(q.contains(elts[i+1]));
367 >            assertFalse(q.remove(elts[i + 1]));
368 >            assertFalse(q.contains(elts[i + 1]));
369          }
370          checkEmpty(q);
371      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines