227 |
|
}}); |
228 |
|
|
229 |
|
await(pleaseInterrupt); |
230 |
< |
assertThreadBlocks(t, Thread.State.WAITING); |
230 |
> |
if (randomBoolean()) 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) |
284 |
> |
for (int i = 0; i < SIZE; i++) |
285 |
|
assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS)); |
286 |
< |
aboutToWait.countDown(); |
286 |
> |
|
287 |
> |
Thread.currentThread().interrupt(); |
288 |
|
try { |
289 |
< |
q.poll(LONG_DELAY_MS, MILLISECONDS); |
289 |
> |
q.poll(randomTimeout(), randomTimeUnit()); |
290 |
|
shouldThrow(); |
291 |
|
} catch (InterruptedException success) {} |
292 |
< |
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
292 |
> |
assertFalse(Thread.interrupted()); |
293 |
> |
|
294 |
> |
pleaseInterrupt.countDown(); |
295 |
> |
try { |
296 |
> |
q.poll(LONGER_DELAY_MS, MILLISECONDS); |
297 |
> |
shouldThrow(); |
298 |
> |
} catch (InterruptedException success) {} |
299 |
> |
assertFalse(Thread.interrupted()); |
300 |
|
}}); |
301 |
|
|
302 |
< |
await(aboutToWait); |
303 |
< |
assertThreadBlocks(t, Thread.State.TIMED_WAITING); |
302 |
> |
await(pleaseInterrupt); |
303 |
> |
if (randomBoolean()) assertThreadBlocks(t, Thread.State.TIMED_WAITING); |
304 |
|
t.interrupt(); |
305 |
|
awaitTermination(t); |
306 |
|
checkEmpty(q); |
317 |
|
long startTime = System.nanoTime(); |
318 |
|
Thread.currentThread().interrupt(); |
319 |
|
for (int i = 0; i < SIZE; ++i) |
320 |
< |
assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS)); |
320 |
> |
assertEquals(i, (int) q.poll(randomTimeout(), randomTimeUnit())); |
321 |
|
try { |
322 |
< |
q.poll(LONG_DELAY_MS, MILLISECONDS); |
322 |
> |
q.poll(randomTimeout(), randomTimeUnit()); |
323 |
|
shouldThrow(); |
324 |
|
} catch (InterruptedException success) {} |
325 |
+ |
assertFalse(Thread.interrupted()); |
326 |
|
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
327 |
|
}}); |
328 |
|
|
472 |
|
*/ |
473 |
|
public void testToArray() { |
474 |
|
LinkedTransferQueue q = populatedQueue(SIZE); |
475 |
< |
Object[] o = q.toArray(); |
476 |
< |
for (int i = 0; i < o.length; i++) { |
477 |
< |
assertSame(o[i], q.poll()); |
478 |
< |
} |
475 |
> |
Object[] a = q.toArray(); |
476 |
> |
assertSame(Object[].class, a.getClass()); |
477 |
> |
for (Object o : a) |
478 |
> |
assertSame(o, q.poll()); |
479 |
> |
assertTrue(q.isEmpty()); |
480 |
|
} |
481 |
|
|
482 |
|
/** |
487 |
|
Integer[] ints = new Integer[SIZE]; |
488 |
|
Integer[] array = q.toArray(ints); |
489 |
|
assertSame(ints, array); |
490 |
< |
for (int i = 0; i < ints.length; i++) { |
491 |
< |
assertSame(ints[i], q.poll()); |
492 |
< |
} |
490 |
> |
for (Integer o : ints) |
491 |
> |
assertSame(o, q.poll()); |
492 |
> |
assertTrue(q.isEmpty()); |
493 |
|
} |
494 |
|
|
495 |
|
/** |
645 |
|
} |
646 |
|
|
647 |
|
/** |
648 |
< |
* A deserialized serialized queue has same elements in same order |
648 |
> |
* A deserialized/reserialized queue has same elements in same order |
649 |
|
*/ |
650 |
|
public void testSerialization() throws Exception { |
651 |
|
Queue x = populatedQueue(SIZE); |
772 |
|
} |
773 |
|
|
774 |
|
/** |
775 |
< |
* transfer waits until a poll occurs. The transfered element |
775 |
> |
* transfer waits until a poll occurs. The transferred element |
776 |
|
* is returned by the associated poll. |
777 |
|
*/ |
778 |
|
public void testTransfer2() throws InterruptedException { |
853 |
|
} |
854 |
|
|
855 |
|
/** |
856 |
< |
* transfer waits until a take occurs. The transfered element |
856 |
> |
* transfer waits until a take occurs. The transferred element |
857 |
|
* is returned by the associated take. |
858 |
|
*/ |
859 |
|
public void testTransfer5() throws InterruptedException { |
955 |
|
long startTime = System.nanoTime(); |
956 |
|
Thread.currentThread().interrupt(); |
957 |
|
try { |
958 |
< |
q.tryTransfer(new Object(), LONG_DELAY_MS, MILLISECONDS); |
958 |
> |
q.tryTransfer(new Object(), randomTimeout(), randomTimeUnit()); |
959 |
|
shouldThrow(); |
960 |
|
} catch (InterruptedException success) {} |
961 |
|
assertFalse(Thread.interrupted()); |
966 |
|
shouldThrow(); |
967 |
|
} catch (InterruptedException success) {} |
968 |
|
assertFalse(Thread.interrupted()); |
969 |
+ |
|
970 |
|
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
971 |
|
}}); |
972 |
|
|
973 |
|
await(pleaseInterrupt); |
974 |
< |
assertThreadStaysAlive(t); |
974 |
> |
if (randomBoolean()) assertThreadBlocks(t, Thread.State.TIMED_WAITING); |
975 |
|
t.interrupt(); |
976 |
|
awaitTermination(t); |
977 |
|
checkEmpty(q); |