314 |
|
pleaseTake.countDown(); |
315 |
|
q.put(86); |
316 |
|
|
317 |
+ |
Thread.currentThread().interrupt(); |
318 |
+ |
try { |
319 |
+ |
q.put(99); |
320 |
+ |
shouldThrow(); |
321 |
+ |
} catch (InterruptedException success) {} |
322 |
+ |
assertFalse(Thread.interrupted()); |
323 |
+ |
|
324 |
|
pleaseInterrupt.countDown(); |
325 |
|
try { |
326 |
|
q.put(99); |
358 |
|
q.offer(new Object(), 2 * LONG_DELAY_MS, MILLISECONDS); |
359 |
|
shouldThrow(); |
360 |
|
} catch (InterruptedException success) {} |
361 |
+ |
assertFalse(Thread.interrupted()); |
362 |
|
}}); |
363 |
|
|
364 |
|
await(pleaseInterrupt); |
452 |
|
*/ |
453 |
|
public void testInterruptedTimedPoll() throws InterruptedException { |
454 |
|
final BlockingQueue<Integer> q = populatedQueue(SIZE); |
455 |
< |
final CountDownLatch aboutToWait = new CountDownLatch(1); |
455 |
> |
final CountDownLatch pleaseInterrupt = new CountDownLatch(1); |
456 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
457 |
|
public void realRun() throws InterruptedException { |
458 |
|
long startTime = System.nanoTime(); |
459 |
< |
for (int i = 0; i < SIZE; ++i) { |
459 |
> |
for (int i = 0; i < SIZE; i++) |
460 |
|
assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS)); |
461 |
< |
} |
462 |
< |
aboutToWait.countDown(); |
461 |
> |
|
462 |
> |
Thread.currentThread().interrupt(); |
463 |
|
try { |
464 |
|
q.poll(LONG_DELAY_MS, MILLISECONDS); |
465 |
|
shouldThrow(); |
466 |
< |
} catch (InterruptedException success) { |
467 |
< |
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
468 |
< |
} |
466 |
> |
} catch (InterruptedException success) {} |
467 |
> |
assertFalse(Thread.interrupted()); |
468 |
> |
|
469 |
> |
pleaseInterrupt.countDown(); |
470 |
> |
try { |
471 |
> |
q.poll(LONG_DELAY_MS, MILLISECONDS); |
472 |
> |
shouldThrow(); |
473 |
> |
} catch (InterruptedException success) {} |
474 |
> |
assertFalse(Thread.interrupted()); |
475 |
> |
|
476 |
> |
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
477 |
|
}}); |
478 |
|
|
479 |
< |
await(aboutToWait); |
480 |
< |
waitForThreadToEnterWaitState(t); |
479 |
> |
await(pleaseInterrupt); |
480 |
> |
assertThreadBlocks(t, Thread.State.TIMED_WAITING); |
481 |
|
t.interrupt(); |
482 |
|
awaitTermination(t); |
483 |
|
checkEmpty(q); |