274 |
|
} |
275 |
|
|
276 |
|
/** |
277 |
< |
* take blocks interruptibly when empty |
278 |
< |
*/ |
279 |
< |
public void testTakeFromEmpty() throws InterruptedException { |
280 |
< |
final LinkedTransferQueue q = new LinkedTransferQueue(); |
281 |
< |
Thread t = newStartedThread(new CheckedInterruptedRunnable() { |
282 |
< |
public void realRun() throws InterruptedException { |
283 |
< |
q.take(); |
284 |
< |
}}); |
285 |
< |
Thread.sleep(SHORT_DELAY_MS); |
286 |
< |
t.interrupt(); |
287 |
< |
t.join(); |
288 |
< |
} |
289 |
< |
|
290 |
< |
/** |
291 |
< |
* Take removes existing elements until empty, then blocks interruptibly |
277 |
> |
* take removes existing elements until empty, then blocks interruptibly |
278 |
|
*/ |
279 |
|
public void testBlockingTake() throws InterruptedException { |
280 |
|
final LinkedTransferQueue<Integer> q = populatedQueue(SIZE); |
328 |
|
for (int i = 0; i < SIZE; ++i) { |
329 |
|
long t0 = System.nanoTime(); |
330 |
|
assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS)); |
331 |
< |
long millisElapsed = (System.nanoTime() - t0)/(1024 * 1024); |
346 |
< |
assertTrue(millisElapsed < SMALL_DELAY_MS); |
331 |
> |
assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS); |
332 |
|
} |
333 |
|
assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS)); |
334 |
|
checkEmpty(q); |
345 |
|
for (int i = 0; i < SIZE; ++i) { |
346 |
|
long t0 = System.nanoTime(); |
347 |
|
assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS)); |
348 |
< |
long millisElapsed = (System.nanoTime() - t0)/(1024 * 1024); |
364 |
< |
assertTrue(millisElapsed < SMALL_DELAY_MS); |
348 |
> |
assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS); |
349 |
|
} |
350 |
|
try { |
351 |
|
q.poll(LONG_DELAY_MS, MILLISECONDS); |
1041 |
|
long t0 = System.nanoTime(); |
1042 |
|
assertFalse(q.tryTransfer(new Object(), |
1043 |
|
SHORT_DELAY_MS, MILLISECONDS)); |
1044 |
< |
long elapsed = NANOSECONDS.toMillis(System.nanoTime() - t0); |
1061 |
< |
assertTrue(elapsed >= SHORT_DELAY_MS); |
1044 |
> |
assertTrue(millisElapsedSince(t0) >= SHORT_DELAY_MS); |
1045 |
|
}}); |
1046 |
|
|
1047 |
|
checkEmpty(q); |