352 |
|
/** |
353 |
|
* timed offer times out if full and elements not taken |
354 |
|
*/ |
355 |
< |
public void testTimedOffer() throws InterruptedException { |
355 |
> |
public void testTimedOffer() { |
356 |
|
final LinkedBlockingQueue q = new LinkedBlockingQueue(2); |
357 |
< |
Thread t = new Thread(new CheckedRunnable() { |
357 |
> |
final CountDownLatch pleaseInterrupt = new CountDownLatch(1); |
358 |
> |
Thread t = newStartedThread(new CheckedRunnable() { |
359 |
|
public void realRun() throws InterruptedException { |
360 |
|
q.put(new Object()); |
361 |
|
q.put(new Object()); |
362 |
< |
assertFalse(q.offer(new Object(), SHORT_DELAY_MS, MILLISECONDS)); |
362 |
> |
long startTime = System.nanoTime(); |
363 |
> |
assertFalse(q.offer(new Object(), timeoutMillis(), MILLISECONDS)); |
364 |
> |
assertTrue(millisElapsedSince(startTime) >= timeoutMillis()); |
365 |
> |
pleaseInterrupt.countDown(); |
366 |
|
try { |
367 |
< |
q.offer(new Object(), LONG_DELAY_MS, MILLISECONDS); |
367 |
> |
q.offer(new Object(), 2 * LONG_DELAY_MS, MILLISECONDS); |
368 |
|
shouldThrow(); |
369 |
|
} catch (InterruptedException success) {} |
370 |
|
}}); |
371 |
|
|
372 |
< |
t.start(); |
369 |
< |
delay(SMALL_DELAY_MS); |
372 |
> |
await(pleaseInterrupt); |
373 |
|
t.interrupt(); |
374 |
< |
t.join(); |
374 |
> |
awaitTermination(t); |
375 |
|
} |
376 |
|
|
377 |
|
/** |