441 |
|
* returning timeout status |
442 |
|
*/ |
443 |
|
public void testInterruptedTimedPoll() throws InterruptedException { |
444 |
< |
Thread t = new Thread(new CheckedRunnable() { |
444 |
> |
final BlockingQueue<Integer> q = populatedQueue(SIZE); |
445 |
> |
final CountDownLatch aboutToWait = new CountDownLatch(1); |
446 |
> |
Thread t = newStartedThread(new CheckedRunnable() { |
447 |
|
public void realRun() throws InterruptedException { |
446 |
– |
LinkedBlockingQueue q = populatedQueue(SIZE); |
448 |
|
for (int i = 0; i < SIZE; ++i) { |
449 |
< |
assertEquals(i, q.poll(SHORT_DELAY_MS, MILLISECONDS)); |
449 |
> |
long t0 = System.nanoTime(); |
450 |
> |
assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS)); |
451 |
> |
assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS); |
452 |
|
} |
453 |
+ |
long t0 = System.nanoTime(); |
454 |
+ |
aboutToWait.countDown(); |
455 |
|
try { |
456 |
< |
q.poll(SMALL_DELAY_MS, MILLISECONDS); |
456 |
> |
q.poll(MEDIUM_DELAY_MS, MILLISECONDS); |
457 |
|
shouldThrow(); |
458 |
< |
} catch (InterruptedException success) {} |
458 |
> |
} catch (InterruptedException success) { |
459 |
> |
assertTrue(millisElapsedSince(t0) < MEDIUM_DELAY_MS); |
460 |
> |
} |
461 |
|
}}); |
462 |
|
|
463 |
< |
t.start(); |
464 |
< |
Thread.sleep(SHORT_DELAY_MS); |
463 |
> |
aboutToWait.await(); |
464 |
> |
waitForThreadToEnterWaitState(t, SMALL_DELAY_MS); |
465 |
|
t.interrupt(); |
466 |
< |
t.join(); |
466 |
> |
awaitTermination(t, MEDIUM_DELAY_MS); |
467 |
> |
checkEmpty(q); |
468 |
|
} |
469 |
|
|
470 |
|
/** |