291 |
|
}}); |
292 |
|
|
293 |
|
await(pleaseInterrupt); |
294 |
< |
assertThreadBlocks(t, Thread.State.WAITING); |
294 |
> |
if (randomBoolean()) assertThreadBlocks(t, Thread.State.WAITING); |
295 |
|
t.interrupt(); |
296 |
|
awaitTermination(t); |
297 |
|
assertEquals(SIZE, q.size()); |
333 |
|
assertEquals(0, q.take()); |
334 |
|
|
335 |
|
await(pleaseInterrupt); |
336 |
< |
assertThreadBlocks(t, Thread.State.WAITING); |
336 |
> |
if (randomBoolean()) assertThreadBlocks(t, Thread.State.WAITING); |
337 |
|
t.interrupt(); |
338 |
|
awaitTermination(t); |
339 |
|
assertEquals(0, q.remainingCapacity()); |
349 |
|
public void realRun() throws InterruptedException { |
350 |
|
q.put(new Object()); |
351 |
|
q.put(new Object()); |
352 |
– |
|
352 |
|
long startTime = System.nanoTime(); |
353 |
+ |
|
354 |
|
assertFalse(q.offer(new Object(), timeoutMillis(), MILLISECONDS)); |
355 |
|
assertTrue(millisElapsedSince(startTime) >= timeoutMillis()); |
356 |
|
|
357 |
|
Thread.currentThread().interrupt(); |
358 |
|
try { |
359 |
< |
q.offer(new Object(), 2 * LONG_DELAY_MS, MILLISECONDS); |
359 |
> |
q.offer(new Object(), randomTimeout(), randomTimeUnit()); |
360 |
|
shouldThrow(); |
361 |
|
} catch (InterruptedException success) {} |
362 |
|
assertFalse(Thread.interrupted()); |
363 |
|
|
364 |
|
pleaseInterrupt.countDown(); |
365 |
|
try { |
366 |
< |
q.offer(new Object(), 2 * LONG_DELAY_MS, MILLISECONDS); |
366 |
> |
q.offer(new Object(), LONGER_DELAY_MS, MILLISECONDS); |
367 |
|
shouldThrow(); |
368 |
|
} catch (InterruptedException success) {} |
369 |
|
assertFalse(Thread.interrupted()); |
370 |
|
}}); |
371 |
|
|
372 |
|
await(pleaseInterrupt); |
373 |
< |
assertThreadBlocks(t, Thread.State.TIMED_WAITING); |
373 |
> |
if (randomBoolean()) assertThreadBlocks(t, Thread.State.TIMED_WAITING); |
374 |
|
t.interrupt(); |
375 |
|
awaitTermination(t); |
376 |
|
} |
411 |
|
}}); |
412 |
|
|
413 |
|
await(pleaseInterrupt); |
414 |
< |
assertThreadBlocks(t, Thread.State.WAITING); |
414 |
> |
if (randomBoolean()) assertThreadBlocks(t, Thread.State.WAITING); |
415 |
|
t.interrupt(); |
416 |
|
awaitTermination(t); |
417 |
|
} |
463 |
|
final CountDownLatch pleaseInterrupt = new CountDownLatch(1); |
464 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
465 |
|
public void realRun() throws InterruptedException { |
466 |
– |
long startTime = System.nanoTime(); |
466 |
|
for (int i = 0; i < SIZE; i++) |
467 |
|
assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS)); |
468 |
|
|
469 |
|
Thread.currentThread().interrupt(); |
470 |
|
try { |
471 |
< |
q.poll(LONG_DELAY_MS, MILLISECONDS); |
471 |
> |
q.poll(randomTimeout(), randomTimeUnit()); |
472 |
|
shouldThrow(); |
473 |
|
} catch (InterruptedException success) {} |
474 |
|
assertFalse(Thread.interrupted()); |
475 |
|
|
476 |
|
pleaseInterrupt.countDown(); |
477 |
|
try { |
478 |
< |
q.poll(LONG_DELAY_MS, MILLISECONDS); |
478 |
> |
q.poll(LONGER_DELAY_MS, MILLISECONDS); |
479 |
|
shouldThrow(); |
480 |
|
} catch (InterruptedException success) {} |
481 |
|
assertFalse(Thread.interrupted()); |
483 |
– |
|
484 |
– |
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
482 |
|
}}); |
483 |
|
|
484 |
|
await(pleaseInterrupt); |
485 |
< |
assertThreadBlocks(t, Thread.State.TIMED_WAITING); |
485 |
> |
if (randomBoolean()) assertThreadBlocks(t, Thread.State.TIMED_WAITING); |
486 |
|
t.interrupt(); |
487 |
|
awaitTermination(t); |
488 |
|
checkEmpty(q); |
626 |
|
*/ |
627 |
|
public void testToArray() { |
628 |
|
LinkedBlockingQueue q = populatedQueue(SIZE); |
629 |
< |
Object[] o = q.toArray(); |
630 |
< |
for (int i = 0; i < o.length; i++) |
631 |
< |
assertSame(o[i], q.poll()); |
629 |
> |
Object[] a = q.toArray(); |
630 |
> |
assertSame(Object[].class, a.getClass()); |
631 |
> |
for (Object o : a) |
632 |
> |
assertSame(o, q.poll()); |
633 |
> |
assertTrue(q.isEmpty()); |
634 |
|
} |
635 |
|
|
636 |
|
/** |
641 |
|
Integer[] ints = new Integer[SIZE]; |
642 |
|
Integer[] array = q.toArray(ints); |
643 |
|
assertSame(ints, array); |
644 |
< |
for (int i = 0; i < ints.length; i++) |
645 |
< |
assertSame(ints[i], q.poll()); |
644 |
> |
for (Integer o : ints) |
645 |
> |
assertSame(o, q.poll()); |
646 |
> |
assertTrue(q.isEmpty()); |
647 |
|
} |
648 |
|
|
649 |
|
/** |