453 |
|
* returning timeout status |
454 |
|
*/ |
455 |
|
public void testInterruptedTimedPoll() throws InterruptedException { |
456 |
< |
Thread t = new Thread(new CheckedRunnable() { |
456 |
> |
final BlockingQueue<Integer> q = populatedQueue(SIZE); |
457 |
> |
final CountDownLatch aboutToWait = new CountDownLatch(1); |
458 |
> |
Thread t = newStartedThread(new CheckedRunnable() { |
459 |
|
public void realRun() throws InterruptedException { |
458 |
– |
ArrayBlockingQueue q = populatedQueue(SIZE); |
460 |
|
for (int i = 0; i < SIZE; ++i) { |
461 |
< |
assertEquals(i, q.poll(SHORT_DELAY_MS, MILLISECONDS));; |
461 |
> |
long t0 = System.nanoTime(); |
462 |
> |
assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS)); |
463 |
> |
assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS); |
464 |
|
} |
465 |
+ |
long t0 = System.nanoTime(); |
466 |
+ |
aboutToWait.countDown(); |
467 |
|
try { |
468 |
< |
q.poll(SMALL_DELAY_MS, MILLISECONDS); |
468 |
> |
q.poll(MEDIUM_DELAY_MS, MILLISECONDS); |
469 |
|
shouldThrow(); |
470 |
< |
} catch (InterruptedException success) {} |
470 |
> |
} catch (InterruptedException success) { |
471 |
> |
assertTrue(millisElapsedSince(t0) < MEDIUM_DELAY_MS); |
472 |
> |
} |
473 |
|
}}); |
474 |
|
|
475 |
< |
t.start(); |
476 |
< |
Thread.sleep(SHORT_DELAY_MS); |
475 |
> |
aboutToWait.await(); |
476 |
> |
waitForThreadToEnterWaitState(t, SMALL_DELAY_MS); |
477 |
|
t.interrupt(); |
478 |
< |
t.join(); |
478 |
> |
awaitTermination(t, MEDIUM_DELAY_MS); |
479 |
> |
checkEmpty(q); |
480 |
|
} |
481 |
|
|
482 |
|
/** |