375 |
|
public void realRun() throws InterruptedException { |
376 |
|
q.put(new PDelay(0)); |
377 |
|
q.put(new PDelay(0)); |
378 |
< |
threadAssertTrue(q.offer(new PDelay(0), SHORT_DELAY_MS, MILLISECONDS)); |
379 |
< |
threadAssertTrue(q.offer(new PDelay(0), LONG_DELAY_MS, MILLISECONDS)); |
378 |
> |
assertTrue(q.offer(new PDelay(0), SHORT_DELAY_MS, MILLISECONDS)); |
379 |
> |
assertTrue(q.offer(new PDelay(0), LONG_DELAY_MS, MILLISECONDS)); |
380 |
|
}}); |
381 |
|
|
382 |
|
t.start(); |
415 |
|
* Take removes existing elements until empty, then blocks interruptibly |
416 |
|
*/ |
417 |
|
public void testBlockingTake() throws InterruptedException { |
418 |
< |
Thread t = new ThreadShouldThrow(InterruptedException.class) { |
418 |
> |
final DelayQueue q = populatedQueue(SIZE); |
419 |
> |
Thread t = new Thread(new CheckedRunnable() { |
420 |
|
public void realRun() throws InterruptedException { |
420 |
– |
DelayQueue q = populatedQueue(SIZE); |
421 |
|
for (int i = 0; i < SIZE; ++i) { |
422 |
< |
threadAssertEquals(new PDelay(i), ((PDelay)q.take())); |
422 |
> |
assertEquals(new PDelay(i), ((PDelay)q.take())); |
423 |
|
} |
424 |
< |
q.take(); |
425 |
< |
}}; |
424 |
> |
try { |
425 |
> |
q.take(); |
426 |
> |
shouldThrow(); |
427 |
> |
} catch (InterruptedException success) {} |
428 |
> |
}}); |
429 |
|
|
430 |
|
t.start(); |
431 |
|
Thread.sleep(SHORT_DELAY_MS); |
479 |
|
assertEquals(new PDelay(i), ((PDelay)q.poll(SHORT_DELAY_MS, MILLISECONDS))); |
480 |
|
} |
481 |
|
try { |
482 |
< |
q.poll(LONG_DELAY_MS, MILLISECONDS); |
482 |
> |
q.poll(SMALL_DELAY_MS, MILLISECONDS); |
483 |
|
shouldThrow(); |
484 |
|
} catch (InterruptedException success) {} |
485 |
|
}}); |
496 |
|
*/ |
497 |
|
public void testTimedPollWithOffer() throws InterruptedException { |
498 |
|
final DelayQueue q = new DelayQueue(); |
499 |
+ |
final PDelay pdelay = new PDelay(0); |
500 |
|
Thread t = new Thread(new CheckedRunnable() { |
501 |
|
public void realRun() throws InterruptedException { |
502 |
|
assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS)); |
503 |
< |
q.poll(LONG_DELAY_MS, MILLISECONDS); |
503 |
> |
assertSame(pdelay, q.poll(LONG_DELAY_MS, MILLISECONDS)); |
504 |
|
try { |
505 |
|
q.poll(LONG_DELAY_MS, MILLISECONDS); |
506 |
|
shouldThrow(); |
509 |
|
|
510 |
|
t.start(); |
511 |
|
Thread.sleep(SMALL_DELAY_MS); |
512 |
< |
assertTrue(q.offer(new PDelay(0), SHORT_DELAY_MS, MILLISECONDS)); |
512 |
> |
assertTrue(q.offer(pdelay, SHORT_DELAY_MS, MILLISECONDS)); |
513 |
|
t.interrupt(); |
514 |
|
t.join(); |
515 |
|
} |