283 |
|
final CountDownLatch aboutToWait = new CountDownLatch(1); |
284 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
285 |
|
public void realRun() throws InterruptedException { |
286 |
+ |
long startTime = System.nanoTime(); |
287 |
|
for (int i = 0; i < SIZE; ++i) { |
287 |
– |
long t0 = System.nanoTime(); |
288 |
|
assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS)); |
289 |
– |
assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS); |
289 |
|
} |
291 |
– |
long t0 = System.nanoTime(); |
290 |
|
aboutToWait.countDown(); |
291 |
|
try { |
292 |
< |
q.poll(MEDIUM_DELAY_MS, MILLISECONDS); |
292 |
> |
q.poll(LONG_DELAY_MS, MILLISECONDS); |
293 |
|
shouldThrow(); |
294 |
|
} catch (InterruptedException success) { |
295 |
< |
assertTrue(millisElapsedSince(t0) < MEDIUM_DELAY_MS); |
295 |
> |
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
296 |
|
} |
297 |
|
}}); |
298 |
|
|
299 |
|
aboutToWait.await(); |
300 |
< |
waitForThreadToEnterWaitState(t, SMALL_DELAY_MS); |
300 |
> |
waitForThreadToEnterWaitState(t, LONG_DELAY_MS); |
301 |
|
t.interrupt(); |
302 |
< |
awaitTermination(t, MEDIUM_DELAY_MS); |
302 |
> |
awaitTermination(t); |
303 |
|
checkEmpty(q); |
304 |
|
} |
305 |
|
|
313 |
|
public void realRun() throws InterruptedException { |
314 |
|
Thread.currentThread().interrupt(); |
315 |
|
for (int i = 0; i < SIZE; ++i) { |
316 |
< |
long t0 = System.nanoTime(); |
316 |
> |
long startTime = System.nanoTime(); |
317 |
|
assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS)); |
318 |
< |
assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS); |
318 |
> |
assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS); |
319 |
|
} |
320 |
|
try { |
321 |
|
q.poll(MEDIUM_DELAY_MS, MILLISECONDS); |
969 |
|
|
970 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
971 |
|
public void realRun() throws InterruptedException { |
972 |
< |
long t0 = System.nanoTime(); |
972 |
> |
long startTime = System.nanoTime(); |
973 |
|
assertFalse(q.tryTransfer(new Object(), |
974 |
|
timeoutMillis(), MILLISECONDS)); |
975 |
< |
assertTrue(millisElapsedSince(t0) >= timeoutMillis()); |
975 |
> |
assertTrue(millisElapsedSince(startTime) >= timeoutMillis()); |
976 |
|
checkEmpty(q); |
977 |
|
}}); |
978 |
|
|
1011 |
|
final LinkedTransferQueue q = new LinkedTransferQueue(); |
1012 |
|
assertTrue(q.offer(four)); |
1013 |
|
assertEquals(1, q.size()); |
1014 |
< |
long t0 = System.nanoTime(); |
1014 |
> |
long startTime = System.nanoTime(); |
1015 |
|
assertFalse(q.tryTransfer(five, timeoutMillis(), MILLISECONDS)); |
1016 |
< |
assertTrue(millisElapsedSince(t0) >= timeoutMillis()); |
1016 |
> |
assertTrue(millisElapsedSince(startTime) >= timeoutMillis()); |
1017 |
|
assertEquals(1, q.size()); |
1018 |
|
assertSame(four, q.poll()); |
1019 |
|
assertNull(q.poll()); |