209 |
|
final CountDownLatch pleaseInterrupt = new CountDownLatch(1); |
210 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
211 |
|
public void realRun() throws InterruptedException { |
212 |
< |
for (int i = 0; i < SIZE; ++i) { |
213 |
< |
assertEquals(i, q.take()); |
214 |
< |
} |
212 |
> |
for (int i = 0; i < SIZE; i++) assertEquals(i, q.take()); |
213 |
|
|
214 |
|
Thread.currentThread().interrupt(); |
215 |
|
try { |
227 |
|
}}); |
228 |
|
|
229 |
|
await(pleaseInterrupt); |
230 |
< |
assertThreadStaysAlive(t); |
230 |
> |
assertThreadBlocks(t, Thread.State.WAITING); |
231 |
|
t.interrupt(); |
232 |
|
awaitTermination(t); |
233 |
|
} |
278 |
|
*/ |
279 |
|
public void testInterruptedTimedPoll() throws InterruptedException { |
280 |
|
final BlockingQueue<Integer> q = populatedQueue(SIZE); |
281 |
< |
final CountDownLatch aboutToWait = new CountDownLatch(1); |
281 |
> |
final CountDownLatch pleaseInterrupt = new CountDownLatch(1); |
282 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
283 |
|
public void realRun() throws InterruptedException { |
284 |
|
long startTime = System.nanoTime(); |
285 |
< |
for (int i = 0; i < SIZE; ++i) |
285 |
> |
for (int i = 0; i < SIZE; i++) |
286 |
|
assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS)); |
287 |
< |
aboutToWait.countDown(); |
287 |
> |
|
288 |
> |
Thread.currentThread().interrupt(); |
289 |
> |
try { |
290 |
> |
q.poll(LONG_DELAY_MS, MILLISECONDS); |
291 |
> |
shouldThrow(); |
292 |
> |
} catch (InterruptedException success) {} |
293 |
> |
assertFalse(Thread.interrupted()); |
294 |
> |
|
295 |
> |
pleaseInterrupt.countDown(); |
296 |
|
try { |
297 |
|
q.poll(LONG_DELAY_MS, MILLISECONDS); |
298 |
|
shouldThrow(); |
299 |
|
} catch (InterruptedException success) {} |
300 |
+ |
assertFalse(Thread.interrupted()); |
301 |
+ |
|
302 |
|
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
303 |
|
}}); |
304 |
|
|
305 |
< |
aboutToWait.await(); |
306 |
< |
waitForThreadToEnterWaitState(t); |
305 |
> |
await(pleaseInterrupt); |
306 |
> |
assertThreadBlocks(t, Thread.State.TIMED_WAITING); |
307 |
|
t.interrupt(); |
308 |
|
awaitTermination(t); |
309 |
|
checkEmpty(q); |
325 |
|
q.poll(LONG_DELAY_MS, MILLISECONDS); |
326 |
|
shouldThrow(); |
327 |
|
} catch (InterruptedException success) {} |
328 |
+ |
assertFalse(Thread.interrupted()); |
329 |
|
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
330 |
|
}}); |
331 |
|
|
647 |
|
} |
648 |
|
|
649 |
|
/** |
650 |
< |
* A deserialized serialized queue has same elements in same order |
650 |
> |
* A deserialized/reserialized queue has same elements in same order |
651 |
|
*/ |
652 |
|
public void testSerialization() throws Exception { |
653 |
|
Queue x = populatedQueue(SIZE); |
774 |
|
} |
775 |
|
|
776 |
|
/** |
777 |
< |
* transfer waits until a poll occurs. The transfered element |
777 |
> |
* transfer waits until a poll occurs. The transferred element |
778 |
|
* is returned by the associated poll. |
779 |
|
*/ |
780 |
|
public void testTransfer2() throws InterruptedException { |
808 |
|
Thread first = newStartedThread(new CheckedRunnable() { |
809 |
|
public void realRun() throws InterruptedException { |
810 |
|
q.transfer(four); |
811 |
< |
assertTrue(!q.contains(four)); |
811 |
> |
assertFalse(q.contains(four)); |
812 |
|
assertEquals(1, q.size()); |
813 |
|
}}); |
814 |
|
|
855 |
|
} |
856 |
|
|
857 |
|
/** |
858 |
< |
* transfer waits until a take occurs. The transfered element |
858 |
> |
* transfer waits until a take occurs. The transferred element |
859 |
|
* is returned by the associated take. |
860 |
|
*/ |
861 |
|
public void testTransfer5() throws InterruptedException { |
972 |
|
}}); |
973 |
|
|
974 |
|
await(pleaseInterrupt); |
975 |
< |
assertThreadStaysAlive(t); |
975 |
> |
assertThreadBlocks(t, Thread.State.TIMED_WAITING); |
976 |
|
t.interrupt(); |
977 |
|
awaitTermination(t); |
978 |
|
checkEmpty(q); |