1 |
|
/* |
2 |
|
* Written by Doug Lea with assistance from members of JCP JSR-166 |
3 |
|
* Expert Group and released to the public domain, as explained at |
4 |
< |
* http://creativecommons.org/licenses/publicdomain |
4 |
> |
* http://creativecommons.org/publicdomain/zero/1.0/ |
5 |
|
* Other contributors include Andrew Wright, Jeffrey Hayes, |
6 |
|
* Pat Fisher, Mike Judd. |
7 |
|
*/ |
294 |
|
q.put(null); |
295 |
|
shouldThrow(); |
296 |
|
} catch (NullPointerException success) {} |
297 |
< |
} |
297 |
> |
} |
298 |
|
|
299 |
|
/** |
300 |
|
* all elements successfully put are contained |
327 |
|
}}); |
328 |
|
|
329 |
|
t.start(); |
330 |
< |
Thread.sleep(SHORT_DELAY_MS); |
330 |
> |
delay(SHORT_DELAY_MS); |
331 |
|
t.interrupt(); |
332 |
|
t.join(); |
333 |
|
assertEquals(SIZE, q.size()); |
351 |
|
}}); |
352 |
|
|
353 |
|
t.start(); |
354 |
< |
Thread.sleep(SHORT_DELAY_MS); |
354 |
> |
delay(SHORT_DELAY_MS); |
355 |
|
assertEquals(q.remainingCapacity(), 0); |
356 |
|
assertEquals(0, q.take()); |
357 |
< |
Thread.sleep(SHORT_DELAY_MS); |
357 |
> |
delay(SHORT_DELAY_MS); |
358 |
|
t.interrupt(); |
359 |
|
t.join(); |
360 |
|
assertEquals(q.remainingCapacity(), 0); |
377 |
|
}}); |
378 |
|
|
379 |
|
t.start(); |
380 |
< |
Thread.sleep(SHORT_DELAY_MS); |
380 |
> |
delay(SHORT_DELAY_MS); |
381 |
|
t.interrupt(); |
382 |
|
t.join(); |
383 |
|
} |
409 |
|
}}); |
410 |
|
|
411 |
|
t.start(); |
412 |
< |
Thread.sleep(SHORT_DELAY_MS); |
412 |
> |
delay(SHORT_DELAY_MS); |
413 |
|
t.interrupt(); |
414 |
|
t.join(); |
415 |
|
} |
453 |
|
* returning timeout status |
454 |
|
*/ |
455 |
|
public void testInterruptedTimedPoll() throws InterruptedException { |
456 |
< |
Thread t = new Thread(new CheckedRunnable() { |
456 |
> |
final BlockingQueue<Integer> q = populatedQueue(SIZE); |
457 |
> |
final CountDownLatch aboutToWait = new CountDownLatch(1); |
458 |
> |
Thread t = newStartedThread(new CheckedRunnable() { |
459 |
|
public void realRun() throws InterruptedException { |
458 |
– |
ArrayBlockingQueue q = populatedQueue(SIZE); |
460 |
|
for (int i = 0; i < SIZE; ++i) { |
461 |
< |
assertEquals(i, q.poll(SHORT_DELAY_MS, MILLISECONDS));; |
461 |
> |
long t0 = System.nanoTime(); |
462 |
> |
assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS)); |
463 |
> |
assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS); |
464 |
|
} |
465 |
+ |
long t0 = System.nanoTime(); |
466 |
+ |
aboutToWait.countDown(); |
467 |
|
try { |
468 |
< |
q.poll(SMALL_DELAY_MS, MILLISECONDS); |
468 |
> |
q.poll(MEDIUM_DELAY_MS, MILLISECONDS); |
469 |
|
shouldThrow(); |
470 |
< |
} catch (InterruptedException success) {} |
470 |
> |
} catch (InterruptedException success) { |
471 |
> |
assertTrue(millisElapsedSince(t0) < MEDIUM_DELAY_MS); |
472 |
> |
} |
473 |
|
}}); |
474 |
|
|
475 |
< |
t.start(); |
476 |
< |
Thread.sleep(SHORT_DELAY_MS); |
475 |
> |
aboutToWait.await(); |
476 |
> |
waitForThreadToEnterWaitState(t, SMALL_DELAY_MS); |
477 |
|
t.interrupt(); |
478 |
< |
t.join(); |
478 |
> |
awaitTermination(t, MEDIUM_DELAY_MS); |
479 |
> |
checkEmpty(q); |
480 |
|
} |
481 |
|
|
482 |
|
/** |
752 |
|
|
753 |
|
executor.execute(new CheckedRunnable() { |
754 |
|
public void realRun() throws InterruptedException { |
755 |
< |
Thread.sleep(SMALL_DELAY_MS); |
755 |
> |
delay(SMALL_DELAY_MS); |
756 |
|
assertSame(one, q.take()); |
757 |
|
}}); |
758 |
|
|
774 |
|
|
775 |
|
executor.execute(new CheckedRunnable() { |
776 |
|
public void realRun() throws InterruptedException { |
777 |
< |
Thread.sleep(SMALL_DELAY_MS); |
777 |
> |
delay(SMALL_DELAY_MS); |
778 |
|
q.put(one); |
779 |
|
}}); |
780 |
|
|