277 |
|
/** |
278 |
|
* put(null) throws NPE |
279 |
|
*/ |
280 |
< |
public void testPutNull() throws InterruptedException { |
280 |
> |
public void testPutNull() throws InterruptedException { |
281 |
|
try { |
282 |
|
LinkedBlockingQueue q = new LinkedBlockingQueue(SIZE); |
283 |
|
q.put(null); |
284 |
|
shouldThrow(); |
285 |
|
} catch (NullPointerException success) {} |
286 |
< |
} |
286 |
> |
} |
287 |
|
|
288 |
|
/** |
289 |
|
* all elements successfully put are contained |
316 |
|
}}); |
317 |
|
|
318 |
|
t.start(); |
319 |
< |
Thread.sleep(SHORT_DELAY_MS); |
319 |
> |
delay(SHORT_DELAY_MS); |
320 |
|
t.interrupt(); |
321 |
|
t.join(); |
322 |
|
assertEquals(SIZE, q.size()); |
340 |
|
}}); |
341 |
|
|
342 |
|
t.start(); |
343 |
< |
Thread.sleep(SHORT_DELAY_MS); |
343 |
> |
delay(SHORT_DELAY_MS); |
344 |
|
assertEquals(q.remainingCapacity(), 0); |
345 |
|
assertEquals(0, q.take()); |
346 |
< |
Thread.sleep(SHORT_DELAY_MS); |
346 |
> |
delay(SHORT_DELAY_MS); |
347 |
|
t.interrupt(); |
348 |
|
t.join(); |
349 |
|
assertEquals(q.remainingCapacity(), 0); |
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 |
< |
Thread.sleep(SMALL_DELAY_MS); |
372 |
> |
await(pleaseInterrupt); |
373 |
|
t.interrupt(); |
374 |
< |
t.join(); |
374 |
> |
awaitTermination(t); |
375 |
|
} |
376 |
|
|
377 |
|
/** |
401 |
|
}}); |
402 |
|
|
403 |
|
t.start(); |
404 |
< |
Thread.sleep(SHORT_DELAY_MS); |
404 |
> |
delay(SHORT_DELAY_MS); |
405 |
|
t.interrupt(); |
406 |
|
t.join(); |
407 |
|
} |
761 |
|
|
762 |
|
executor.execute(new CheckedRunnable() { |
763 |
|
public void realRun() throws InterruptedException { |
764 |
< |
Thread.sleep(SMALL_DELAY_MS); |
764 |
> |
delay(SMALL_DELAY_MS); |
765 |
|
assertSame(one, q.take()); |
766 |
|
}}); |
767 |
|
|
783 |
|
|
784 |
|
executor.execute(new CheckedRunnable() { |
785 |
|
public void realRun() throws InterruptedException { |
786 |
< |
Thread.sleep(SMALL_DELAY_MS); |
786 |
> |
delay(SMALL_DELAY_MS); |
787 |
|
q.put(one); |
788 |
|
}}); |
789 |
|
|