399 |
|
q.offer(new Object(), 2 * LONG_DELAY_MS, MILLISECONDS); |
400 |
|
shouldThrow(); |
401 |
|
} catch (InterruptedException success) {} |
402 |
+ |
assertFalse(Thread.interrupted()); |
403 |
|
}}); |
404 |
|
|
405 |
|
await(pleaseInterrupt); |
494 |
|
*/ |
495 |
|
public void testInterruptedTimedPoll() throws InterruptedException { |
496 |
|
final BlockingQueue<Integer> q = populatedQueue(SIZE); |
497 |
< |
final CountDownLatch aboutToWait = new CountDownLatch(1); |
497 |
> |
final CountDownLatch pleaseInterrupt = new CountDownLatch(1); |
498 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
499 |
|
public void realRun() throws InterruptedException { |
500 |
|
long startTime = System.nanoTime(); |
501 |
< |
for (int i = 0; i < SIZE; ++i) { |
501 |
> |
for (int i = 0; i < SIZE; i++) |
502 |
|
assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS)); |
503 |
< |
} |
504 |
< |
aboutToWait.countDown(); |
503 |
> |
|
504 |
> |
Thread.currentThread().interrupt(); |
505 |
> |
try { |
506 |
> |
q.poll(LONG_DELAY_MS, MILLISECONDS); |
507 |
> |
shouldThrow(); |
508 |
> |
} catch (InterruptedException success) {} |
509 |
> |
assertFalse(Thread.interrupted()); |
510 |
> |
|
511 |
> |
pleaseInterrupt.countDown(); |
512 |
|
try { |
513 |
|
q.poll(LONG_DELAY_MS, MILLISECONDS); |
514 |
|
shouldThrow(); |
515 |
< |
} catch (InterruptedException success) { |
516 |
< |
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
517 |
< |
} |
515 |
> |
} catch (InterruptedException success) {} |
516 |
> |
assertFalse(Thread.interrupted()); |
517 |
> |
|
518 |
> |
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
519 |
|
}}); |
520 |
|
|
521 |
< |
await(aboutToWait); |
522 |
< |
waitForThreadToEnterWaitState(t); |
521 |
> |
await(pleaseInterrupt); |
522 |
> |
assertThreadBlocks(t, Thread.State.TIMED_WAITING); |
523 |
|
t.interrupt(); |
524 |
|
awaitTermination(t); |
525 |
|
checkEmpty(q); |