48 |
|
|
49 |
|
/** |
50 |
|
* Returns a new queue of given size containing consecutive |
51 |
< |
* Integers 0 ... n. |
51 |
> |
* Integers 0 ... n - 1. |
52 |
|
*/ |
53 |
|
private LinkedBlockingQueue<Integer> populatedQueue(int n) { |
54 |
|
LinkedBlockingQueue<Integer> q = |
59 |
|
assertFalse(q.isEmpty()); |
60 |
|
assertEquals(0, q.remainingCapacity()); |
61 |
|
assertEquals(n, q.size()); |
62 |
+ |
assertEquals((Integer) 0, q.peek()); |
63 |
|
return q; |
64 |
|
} |
65 |
|
|
441 |
|
final CountDownLatch aboutToWait = new CountDownLatch(1); |
442 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
443 |
|
public void realRun() throws InterruptedException { |
444 |
+ |
long startTime = System.nanoTime(); |
445 |
|
for (int i = 0; i < SIZE; ++i) { |
444 |
– |
long t0 = System.nanoTime(); |
446 |
|
assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS)); |
446 |
– |
assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS); |
447 |
|
} |
448 |
– |
long t0 = System.nanoTime(); |
448 |
|
aboutToWait.countDown(); |
449 |
|
try { |
450 |
< |
q.poll(MEDIUM_DELAY_MS, MILLISECONDS); |
450 |
> |
q.poll(LONG_DELAY_MS, MILLISECONDS); |
451 |
|
shouldThrow(); |
452 |
|
} catch (InterruptedException success) { |
453 |
< |
assertTrue(millisElapsedSince(t0) < MEDIUM_DELAY_MS); |
453 |
> |
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
454 |
|
} |
455 |
|
}}); |
456 |
|
|
457 |
< |
aboutToWait.await(); |
458 |
< |
waitForThreadToEnterWaitState(t, SMALL_DELAY_MS); |
457 |
> |
await(aboutToWait); |
458 |
> |
waitForThreadToEnterWaitState(t); |
459 |
|
t.interrupt(); |
460 |
< |
awaitTermination(t, MEDIUM_DELAY_MS); |
460 |
> |
awaitTermination(t); |
461 |
|
checkEmpty(q); |
462 |
|
} |
463 |
|
|