319 |
|
} |
320 |
|
|
321 |
|
/** |
322 |
< |
* timed offer does not time out |
322 |
> |
* Queue is unbounded, so timed offer never times out |
323 |
|
*/ |
324 |
|
public void testTimedOffer() { |
325 |
|
final PriorityBlockingQueue q = new PriorityBlockingQueue(2); |
370 |
|
}}); |
371 |
|
|
372 |
|
await(pleaseInterrupt); |
373 |
< |
assertThreadBlocks(t, Thread.State.WAITING); |
373 |
> |
if (randomBoolean()) assertThreadBlocks(t, Thread.State.WAITING); |
374 |
|
t.interrupt(); |
375 |
|
awaitTermination(t); |
376 |
|
} |
422 |
|
final CountDownLatch pleaseInterrupt = new CountDownLatch(1); |
423 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
424 |
|
public void realRun() throws InterruptedException { |
425 |
– |
long startTime = System.nanoTime(); |
425 |
|
for (int i = 0; i < SIZE; i++) |
426 |
|
assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS)); |
427 |
|
|
428 |
|
Thread.currentThread().interrupt(); |
429 |
|
try { |
430 |
< |
q.poll(LONG_DELAY_MS, MILLISECONDS); |
430 |
> |
q.poll(randomTimeout(), randomTimeUnit()); |
431 |
|
shouldThrow(); |
432 |
|
} catch (InterruptedException success) {} |
433 |
|
assertFalse(Thread.interrupted()); |
434 |
|
|
435 |
|
pleaseInterrupt.countDown(); |
436 |
|
try { |
437 |
< |
q.poll(LONG_DELAY_MS, MILLISECONDS); |
437 |
> |
q.poll(LONGER_DELAY_MS, MILLISECONDS); |
438 |
|
shouldThrow(); |
439 |
|
} catch (InterruptedException success) {} |
440 |
|
assertFalse(Thread.interrupted()); |
442 |
– |
|
443 |
– |
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
441 |
|
}}); |
442 |
|
|
443 |
|
await(pleaseInterrupt); |
444 |
< |
assertThreadBlocks(t, Thread.State.TIMED_WAITING); |
444 |
> |
if (randomBoolean()) assertThreadBlocks(t, Thread.State.TIMED_WAITING); |
445 |
|
t.interrupt(); |
446 |
|
awaitTermination(t); |
447 |
|
} |
570 |
|
*/ |
571 |
|
public void testToArray() throws InterruptedException { |
572 |
|
PriorityBlockingQueue q = populatedQueue(SIZE); |
573 |
< |
Object[] o = q.toArray(); |
574 |
< |
Arrays.sort(o); |
575 |
< |
for (int i = 0; i < o.length; i++) |
576 |
< |
assertSame(o[i], q.take()); |
573 |
> |
Object[] a = q.toArray(); |
574 |
> |
assertSame(Object[].class, a.getClass()); |
575 |
> |
Arrays.sort(a); |
576 |
> |
for (Object o : a) |
577 |
> |
assertSame(o, q.take()); |
578 |
> |
assertTrue(q.isEmpty()); |
579 |
|
} |
580 |
|
|
581 |
|
/** |
587 |
|
Integer[] array = q.toArray(ints); |
588 |
|
assertSame(ints, array); |
589 |
|
Arrays.sort(ints); |
590 |
< |
for (int i = 0; i < ints.length; i++) |
591 |
< |
assertSame(ints[i], q.take()); |
590 |
> |
for (Integer o : ints) |
591 |
> |
assertSame(o, q.take()); |
592 |
> |
assertTrue(q.isEmpty()); |
593 |
|
} |
594 |
|
|
595 |
|
/** |