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 |
< |
await(aboutToWait); |
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 |
|
|
475 |
|
*/ |
476 |
|
public void testToArray() { |
477 |
|
LinkedTransferQueue q = populatedQueue(SIZE); |
478 |
< |
Object[] o = q.toArray(); |
479 |
< |
for (int i = 0; i < o.length; i++) { |
480 |
< |
assertSame(o[i], q.poll()); |
481 |
< |
} |
478 |
> |
Object[] a = q.toArray(); |
479 |
> |
assertSame(Object[].class, a.getClass()); |
480 |
> |
for (Object o : a) |
481 |
> |
assertSame(o, q.poll()); |
482 |
> |
assertTrue(q.isEmpty()); |
483 |
|
} |
484 |
|
|
485 |
|
/** |
490 |
|
Integer[] ints = new Integer[SIZE]; |
491 |
|
Integer[] array = q.toArray(ints); |
492 |
|
assertSame(ints, array); |
493 |
< |
for (int i = 0; i < ints.length; i++) { |
494 |
< |
assertSame(ints[i], q.poll()); |
495 |
< |
} |
493 |
> |
for (Integer o : ints) |
494 |
> |
assertSame(o, q.poll()); |
495 |
> |
assertTrue(q.isEmpty()); |
496 |
|
} |
497 |
|
|
498 |
|
/** |
648 |
|
} |
649 |
|
|
650 |
|
/** |
651 |
< |
* A deserialized serialized queue has same elements in same order |
651 |
> |
* A deserialized/reserialized queue has same elements in same order |
652 |
|
*/ |
653 |
|
public void testSerialization() throws Exception { |
654 |
|
Queue x = populatedQueue(SIZE); |
775 |
|
} |
776 |
|
|
777 |
|
/** |
778 |
< |
* transfer waits until a poll occurs. The transfered element |
778 |
> |
* transfer waits until a poll occurs. The transferred element |
779 |
|
* is returned by the associated poll. |
780 |
|
*/ |
781 |
|
public void testTransfer2() throws InterruptedException { |
856 |
|
} |
857 |
|
|
858 |
|
/** |
859 |
< |
* transfer waits until a take occurs. The transfered element |
859 |
> |
* transfer waits until a take occurs. The transferred element |
860 |
|
* is returned by the associated take. |
861 |
|
*/ |
862 |
|
public void testTransfer5() throws InterruptedException { |
973 |
|
}}); |
974 |
|
|
975 |
|
await(pleaseInterrupt); |
976 |
< |
assertThreadStaysAlive(t); |
976 |
> |
assertThreadBlocks(t, Thread.State.TIMED_WAITING); |
977 |
|
t.interrupt(); |
978 |
|
awaitTermination(t); |
979 |
|
checkEmpty(q); |