484 |
|
} |
485 |
|
|
486 |
|
/** |
487 |
< |
* timed poll before a delayed offer fails; after offer succeeds; |
488 |
< |
* on interruption throws |
487 |
> |
* timed poll before a delayed offer fails; after offer succeeds; |
488 |
> |
* on interruption throws |
489 |
|
*/ |
490 |
|
public void testTimedPollWithOffer() throws InterruptedException { |
491 |
|
final DelayQueue q = new DelayQueue(); |
492 |
|
final PDelay pdelay = new PDelay(0); |
493 |
+ |
final CheckedBarrier barrier = new CheckedBarrier(2); |
494 |
|
Thread t = new Thread(new CheckedRunnable() { |
495 |
|
public void realRun() throws InterruptedException { |
496 |
|
assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS)); |
497 |
< |
assertSame(pdelay, q.poll(LONG_DELAY_MS, MILLISECONDS)); |
497 |
> |
|
498 |
> |
barrier.await(); |
499 |
> |
assertSame(pdelay, q.poll(MEDIUM_DELAY_MS, MILLISECONDS)); |
500 |
> |
|
501 |
> |
Thread.currentThread().interrupt(); |
502 |
> |
try { |
503 |
> |
q.poll(SHORT_DELAY_MS, MILLISECONDS); |
504 |
> |
shouldThrow(); |
505 |
> |
} catch (InterruptedException success) {} |
506 |
> |
|
507 |
> |
barrier.await(); |
508 |
|
try { |
509 |
< |
q.poll(LONG_DELAY_MS, MILLISECONDS); |
509 |
> |
q.poll(MEDIUM_DELAY_MS, MILLISECONDS); |
510 |
|
shouldThrow(); |
511 |
|
} catch (InterruptedException success) {} |
512 |
|
}}); |
513 |
|
|
514 |
|
t.start(); |
515 |
< |
Thread.sleep(SMALL_DELAY_MS); |
515 |
> |
barrier.await(); |
516 |
|
assertTrue(q.offer(pdelay, SHORT_DELAY_MS, MILLISECONDS)); |
517 |
+ |
barrier.await(); |
518 |
+ |
sleep(SHORT_DELAY_MS); |
519 |
|
t.interrupt(); |
520 |
|
t.join(); |
521 |
|
} |