462 |
|
public void testTimedPoll() throws InterruptedException { |
463 |
|
DelayQueue q = populatedQueue(SIZE); |
464 |
|
for (int i = 0; i < SIZE; ++i) { |
465 |
< |
assertEquals(new PDelay(i), ((PDelay)q.poll(SHORT_DELAY_MS, MILLISECONDS))); |
465 |
> |
long startTime = System.nanoTime(); |
466 |
> |
assertEquals(new PDelay(i), ((PDelay)q.poll(LONG_DELAY_MS, MILLISECONDS))); |
467 |
> |
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
468 |
|
} |
469 |
< |
assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS)); |
469 |
> |
long startTime = System.nanoTime(); |
470 |
> |
assertNull(q.poll(timeoutMillis(), MILLISECONDS)); |
471 |
> |
assertTrue(millisElapsedSince(startTime) >= timeoutMillis()); |
472 |
> |
checkEmpty(q); |
473 |
|
} |
474 |
|
|
475 |
|
/** |
516 |
|
final CheckedBarrier barrier = new CheckedBarrier(2); |
517 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
518 |
|
public void realRun() throws InterruptedException { |
519 |
< |
assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS)); |
519 |
> |
assertNull(q.poll(timeoutMillis(), MILLISECONDS)); |
520 |
|
|
521 |
|
barrier.await(); |
522 |
|
assertSame(pdelay, q.poll(LONG_DELAY_MS, MILLISECONDS)); |
841 |
|
public void testTimedPollDelayed() throws InterruptedException { |
842 |
|
DelayQueue q = new DelayQueue(); |
843 |
|
q.add(new NanoDelay(LONG_DELAY_MS * 1000000L)); |
844 |
< |
assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS)); |
844 |
> |
assertNull(q.poll(timeoutMillis(), MILLISECONDS)); |
845 |
|
} |
846 |
|
|
847 |
|
/** |