24 |
|
@SuppressWarnings({"unchecked", "rawtypes"}) |
25 |
|
public class LinkedTransferQueueTest extends JSR166TestCase { |
26 |
|
|
27 |
+ |
public static class Generic extends BlockingQueueTest { |
28 |
+ |
protected BlockingQueue emptyCollection() { |
29 |
+ |
return new LinkedTransferQueue(); |
30 |
+ |
} |
31 |
+ |
} |
32 |
+ |
|
33 |
|
public static void main(String[] args) { |
34 |
|
junit.textui.TestRunner.run(suite()); |
35 |
|
} |
36 |
|
|
37 |
|
public static Test suite() { |
38 |
< |
return new TestSuite(LinkedTransferQueueTest.class); |
38 |
> |
return newTestSuite(LinkedTransferQueueTest.class, |
39 |
> |
new Generic().testSuite()); |
40 |
|
} |
41 |
|
|
42 |
|
void checkEmpty(LinkedTransferQueue q) throws InterruptedException { |
375 |
|
} |
376 |
|
|
377 |
|
/** |
371 |
– |
* timed poll before a delayed offer fails; after offer succeeds; |
372 |
– |
* on interruption throws |
373 |
– |
*/ |
374 |
– |
public void testTimedPollWithOffer() throws InterruptedException { |
375 |
– |
final LinkedTransferQueue q = new LinkedTransferQueue(); |
376 |
– |
Thread t = new Thread(new CheckedRunnable() { |
377 |
– |
public void realRun() throws InterruptedException { |
378 |
– |
assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS)); |
379 |
– |
assertSame(zero, q.poll(LONG_DELAY_MS, MILLISECONDS)); |
380 |
– |
try { |
381 |
– |
q.poll(LONG_DELAY_MS, MILLISECONDS); |
382 |
– |
shouldThrow(); |
383 |
– |
} catch (InterruptedException success) {} |
384 |
– |
}}); |
385 |
– |
|
386 |
– |
t.start(); |
387 |
– |
Thread.sleep(SMALL_DELAY_MS); |
388 |
– |
assertTrue(q.offer(zero, SHORT_DELAY_MS, MILLISECONDS)); |
389 |
– |
t.interrupt(); |
390 |
– |
t.join(); |
391 |
– |
} |
392 |
– |
|
393 |
– |
/** |
378 |
|
* peek returns next element, or null if empty |
379 |
|
*/ |
380 |
|
public void testPeek() throws InterruptedException { |
598 |
|
it.remove(); |
599 |
|
|
600 |
|
it = q.iterator(); |
601 |
< |
assertEquals(it.next(), one); |
602 |
< |
assertEquals(it.next(), three); |
601 |
> |
assertSame(it.next(), one); |
602 |
> |
assertSame(it.next(), three); |
603 |
|
assertFalse(it.hasNext()); |
604 |
|
} |
605 |
|
|
664 |
|
executor.execute(new CheckedRunnable() { |
665 |
|
public void realRun() throws InterruptedException { |
666 |
|
Thread.sleep(SMALL_DELAY_MS); |
667 |
< |
assertEquals(one, q.take()); |
667 |
> |
assertSame(one, q.take()); |
668 |
|
}}); |
669 |
|
|
670 |
|
joinPool(executor); |
875 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
876 |
|
public void realRun() throws InterruptedException { |
877 |
|
q.transfer(SIZE); |
878 |
< |
threadAssertTrue(q.isEmpty()); |
878 |
> |
assertTrue(q.isEmpty()); |
879 |
|
}}); |
880 |
|
|
881 |
|
Thread.sleep(SHORT_DELAY_MS); |
896 |
|
public void realRun() throws InterruptedException { |
897 |
|
Integer i = SIZE + 1; |
898 |
|
q.transfer(i); |
899 |
< |
threadAssertTrue(!q.contains(i)); |
900 |
< |
threadAssertEquals(1, q.size()); |
899 |
> |
assertTrue(!q.contains(i)); |
900 |
> |
assertEquals(1, q.size()); |
901 |
|
}}); |
902 |
|
|
903 |
|
Thread interruptedThread = newStartedThread( |
930 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
931 |
|
public void realRun() throws InterruptedException { |
932 |
|
q.transfer(four); |
933 |
< |
threadAssertFalse(q.contains(four)); |
934 |
< |
threadAssertEquals(three, q.poll()); |
933 |
> |
assertFalse(q.contains(four)); |
934 |
> |
assertSame(three, q.poll()); |
935 |
|
}}); |
936 |
|
|
937 |
|
Thread.sleep(SHORT_DELAY_MS); |
938 |
|
assertTrue(q.offer(three)); |
939 |
< |
assertEquals(four, q.poll()); |
939 |
> |
assertSame(four, q.poll()); |
940 |
|
t.join(); |
941 |
|
} |
942 |
|
|
994 |
|
public void realRun() { |
995 |
|
while (! q.hasWaitingConsumer()) |
996 |
|
Thread.yield(); |
997 |
< |
threadAssertTrue(q.hasWaitingConsumer()); |
998 |
< |
threadAssertTrue(q.isEmpty()); |
999 |
< |
threadAssertTrue(q.size() == 0); |
1000 |
< |
threadAssertTrue(q.tryTransfer(hotPotato)); |
997 |
> |
assertTrue(q.hasWaitingConsumer()); |
998 |
> |
assertTrue(q.isEmpty()); |
999 |
> |
assertEquals(q.size(), 0); |
1000 |
> |
assertTrue(q.tryTransfer(hotPotato)); |
1001 |
|
}}); |
1002 |
|
|
1003 |
|
assertSame(hotPotato, q.poll(MEDIUM_DELAY_MS, MILLISECONDS)); |
1017 |
|
public void realRun() { |
1018 |
|
while (! q.hasWaitingConsumer()) |
1019 |
|
Thread.yield(); |
1020 |
< |
threadAssertTrue(q.hasWaitingConsumer()); |
1021 |
< |
threadAssertTrue(q.isEmpty()); |
1022 |
< |
threadAssertTrue(q.size() == 0); |
1023 |
< |
threadAssertTrue(q.tryTransfer(hotPotato)); |
1020 |
> |
assertTrue(q.hasWaitingConsumer()); |
1021 |
> |
assertTrue(q.isEmpty()); |
1022 |
> |
assertEquals(q.size(), 0); |
1023 |
> |
assertTrue(q.tryTransfer(hotPotato)); |
1024 |
|
}}); |
1025 |
|
|
1026 |
|
assertSame(q.take(), hotPotato); |
1078 |
|
|
1079 |
|
Thread.sleep(SHORT_DELAY_MS); |
1080 |
|
assertEquals(2, q.size()); |
1081 |
< |
assertEquals(four, q.poll()); |
1082 |
< |
assertEquals(five, q.poll()); |
1081 |
> |
assertSame(four, q.poll()); |
1082 |
> |
assertSame(five, q.poll()); |
1083 |
|
checkEmpty(q); |
1084 |
|
t.join(); |
1085 |
|
} |
1094 |
|
assertEquals(1, q.size()); |
1095 |
|
assertFalse(q.tryTransfer(five, SHORT_DELAY_MS, MILLISECONDS)); |
1096 |
|
assertEquals(1, q.size()); |
1097 |
< |
assertEquals(four, q.poll()); |
1097 |
> |
assertSame(four, q.poll()); |
1098 |
|
assertNull(q.poll()); |
1099 |
|
checkEmpty(q); |
1100 |
|
} |