341 |
|
*/ |
342 |
|
public void testTimedOffer() throws InterruptedException { |
343 |
|
final LinkedBlockingQueue q = new LinkedBlockingQueue(2); |
344 |
< |
Thread t = new ThreadShouldThrow(InterruptedException.class) { |
344 |
> |
Thread t = new Thread(new CheckedRunnable() { |
345 |
|
public void realRun() throws InterruptedException { |
346 |
|
q.put(new Object()); |
347 |
|
q.put(new Object()); |
348 |
< |
threadAssertFalse(q.offer(new Object(), SHORT_DELAY_MS, MILLISECONDS)); |
349 |
< |
q.offer(new Object(), LONG_DELAY_MS, MILLISECONDS); |
350 |
< |
}}; |
348 |
> |
assertFalse(q.offer(new Object(), SHORT_DELAY_MS, MILLISECONDS)); |
349 |
> |
try { |
350 |
> |
q.offer(new Object(), LONG_DELAY_MS, MILLISECONDS); |
351 |
> |
shouldThrow(); |
352 |
> |
} catch (InterruptedException success) {} |
353 |
> |
}}); |
354 |
|
|
355 |
|
t.start(); |
356 |
|
Thread.sleep(SMALL_DELAY_MS); |
442 |
|
* returning timeout status |
443 |
|
*/ |
444 |
|
public void testInterruptedTimedPoll() throws InterruptedException { |
445 |
< |
Thread t = new ThreadShouldThrow(InterruptedException.class) { |
445 |
> |
Thread t = new Thread(new CheckedRunnable() { |
446 |
|
public void realRun() throws InterruptedException { |
447 |
|
LinkedBlockingQueue q = populatedQueue(SIZE); |
448 |
|
for (int i = 0; i < SIZE; ++i) { |
449 |
< |
threadAssertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, MILLISECONDS)).intValue()); |
449 |
> |
assertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, MILLISECONDS)).intValue()); |
450 |
|
} |
451 |
< |
q.poll(SMALL_DELAY_MS, MILLISECONDS); |
452 |
< |
}}; |
451 |
> |
try { |
452 |
> |
q.poll(SMALL_DELAY_MS, MILLISECONDS); |
453 |
> |
shouldThrow(); |
454 |
> |
} catch (InterruptedException success) {} |
455 |
> |
}}); |
456 |
|
|
457 |
|
t.start(); |
458 |
|
Thread.sleep(SHORT_DELAY_MS); |
466 |
|
*/ |
467 |
|
public void testTimedPollWithOffer() throws InterruptedException { |
468 |
|
final LinkedBlockingQueue q = new LinkedBlockingQueue(2); |
469 |
< |
Thread t = new ThreadShouldThrow(InterruptedException.class) { |
469 |
> |
Thread t = new Thread(new CheckedRunnable() { |
470 |
|
public void realRun() throws InterruptedException { |
471 |
< |
threadAssertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS)); |
472 |
< |
q.poll(LONG_DELAY_MS, MILLISECONDS); |
473 |
< |
q.poll(LONG_DELAY_MS, MILLISECONDS); |
474 |
< |
}}; |
471 |
> |
assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS)); |
472 |
> |
assertSame(zero, q.poll(LONG_DELAY_MS, MILLISECONDS)); |
473 |
> |
try { |
474 |
> |
q.poll(LONG_DELAY_MS, MILLISECONDS); |
475 |
> |
shouldThrow(); |
476 |
> |
} catch (InterruptedException success) {} |
477 |
> |
}}); |
478 |
|
|
479 |
|
t.start(); |
480 |
|
Thread.sleep(SMALL_DELAY_MS); |