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 { |
51 |
|
try { |
52 |
|
q.element(); |
53 |
|
shouldThrow(); |
54 |
< |
} catch (NoSuchElementException success) { |
48 |
< |
} |
54 |
> |
} catch (NoSuchElementException success) {} |
55 |
|
try { |
56 |
|
q.iterator().next(); |
57 |
|
shouldThrow(); |
58 |
< |
} catch (NoSuchElementException success) { |
53 |
< |
} |
58 |
> |
} catch (NoSuchElementException success) {} |
59 |
|
try { |
60 |
|
q.remove(); |
61 |
|
shouldThrow(); |
62 |
< |
} catch (NoSuchElementException success) { |
58 |
< |
} |
62 |
> |
} catch (NoSuchElementException success) {} |
63 |
|
} |
64 |
|
|
65 |
|
/** |
79 |
|
try { |
80 |
|
new LinkedTransferQueue(null); |
81 |
|
shouldThrow(); |
82 |
< |
} catch (NullPointerException success) { |
79 |
< |
} |
82 |
> |
} catch (NullPointerException success) {} |
83 |
|
} |
84 |
|
|
85 |
|
/** |
91 |
|
Integer[] ints = new Integer[SIZE]; |
92 |
|
new LinkedTransferQueue(Arrays.asList(ints)); |
93 |
|
shouldThrow(); |
94 |
< |
} catch (NullPointerException success) { |
92 |
< |
} |
94 |
> |
} catch (NullPointerException success) {} |
95 |
|
} |
96 |
|
|
97 |
|
/** |
106 |
|
} |
107 |
|
new LinkedTransferQueue(Arrays.asList(ints)); |
108 |
|
shouldThrow(); |
109 |
< |
} catch (NullPointerException success) { |
108 |
< |
} |
109 |
> |
} catch (NullPointerException success) {} |
110 |
|
} |
111 |
|
|
112 |
|
/** |
158 |
|
LinkedTransferQueue q = new LinkedTransferQueue(); |
159 |
|
q.offer(null); |
160 |
|
shouldThrow(); |
161 |
< |
} catch (NullPointerException success) { |
161 |
< |
} |
161 |
> |
} catch (NullPointerException success) {} |
162 |
|
} |
163 |
|
|
164 |
|
/** |
169 |
|
LinkedTransferQueue q = new LinkedTransferQueue(); |
170 |
|
q.add(null); |
171 |
|
shouldThrow(); |
172 |
< |
} catch (NullPointerException success) { |
173 |
< |
} |
172 |
> |
} catch (NullPointerException success) {} |
173 |
|
} |
174 |
|
|
175 |
|
/** |
180 |
|
LinkedTransferQueue q = new LinkedTransferQueue(); |
181 |
|
q.addAll(null); |
182 |
|
shouldThrow(); |
183 |
< |
} catch (NullPointerException success) { |
185 |
< |
} |
183 |
> |
} catch (NullPointerException success) {} |
184 |
|
} |
185 |
|
|
186 |
|
/** |
191 |
|
LinkedTransferQueue q = populatedQueue(SIZE); |
192 |
|
q.addAll(q); |
193 |
|
shouldThrow(); |
194 |
< |
} catch (IllegalArgumentException success) { |
197 |
< |
} |
194 |
> |
} catch (IllegalArgumentException success) {} |
195 |
|
} |
196 |
|
|
197 |
|
/** |
203 |
|
Integer[] ints = new Integer[SIZE]; |
204 |
|
q.addAll(Arrays.asList(ints)); |
205 |
|
shouldThrow(); |
206 |
< |
} catch (NullPointerException success) { |
210 |
< |
} |
206 |
> |
} catch (NullPointerException success) {} |
207 |
|
} |
208 |
|
|
209 |
|
/** |
219 |
|
} |
220 |
|
q.addAll(Arrays.asList(ints)); |
221 |
|
shouldThrow(); |
222 |
< |
} catch (NullPointerException success) { |
227 |
< |
} |
222 |
> |
} catch (NullPointerException success) {} |
223 |
|
} |
224 |
|
|
225 |
|
/** |
278 |
|
public void testTakeFromEmpty() throws InterruptedException { |
279 |
|
final LinkedTransferQueue q = new LinkedTransferQueue(); |
280 |
|
Thread t = newStartedThread(new CheckedInterruptedRunnable() { |
281 |
< |
void realRun() throws InterruptedException { |
281 |
> |
public void realRun() throws InterruptedException { |
282 |
|
q.take(); |
283 |
|
}}); |
284 |
|
Thread.sleep(SHORT_DELAY_MS); |
291 |
|
*/ |
292 |
|
public void testBlockingTake() throws InterruptedException { |
293 |
|
final LinkedTransferQueue<Integer> q = populatedQueue(SIZE); |
294 |
< |
Thread t = newStartedThread(new CheckedInterruptedRunnable() { |
295 |
< |
void realRun() throws InterruptedException { |
294 |
> |
Thread t = new Thread(new CheckedRunnable() { |
295 |
> |
public void realRun() throws InterruptedException { |
296 |
|
for (int i = 0; i < SIZE; ++i) { |
297 |
< |
threadAssertEquals(i, (int) q.take()); |
297 |
> |
assertEquals(i, (int) q.take()); |
298 |
|
} |
299 |
< |
q.take(); |
299 |
> |
try { |
300 |
> |
q.take(); |
301 |
> |
shouldThrow(); |
302 |
> |
} catch (InterruptedException success) {} |
303 |
|
}}); |
304 |
< |
Thread.sleep(SMALL_DELAY_MS); |
304 |
> |
|
305 |
> |
t.start(); |
306 |
> |
Thread.sleep(SHORT_DELAY_MS); |
307 |
|
t.interrupt(); |
308 |
|
t.join(); |
309 |
|
checkEmpty(q); |
354 |
|
*/ |
355 |
|
public void testInterruptedTimedPoll() throws InterruptedException { |
356 |
|
final LinkedTransferQueue<Integer> q = populatedQueue(SIZE); |
357 |
< |
Thread t = newStartedThread(new CheckedInterruptedRunnable() { |
358 |
< |
void realRun() throws InterruptedException { |
357 |
> |
Thread t = newStartedThread(new CheckedRunnable() { |
358 |
> |
public void realRun() throws InterruptedException { |
359 |
|
for (int i = 0; i < SIZE; ++i) { |
360 |
|
long t0 = System.nanoTime(); |
361 |
< |
threadAssertEquals(i, (int) q.poll(LONG_DELAY_MS, |
362 |
< |
MILLISECONDS)); |
361 |
> |
assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS)); |
362 |
|
long millisElapsed = (System.nanoTime() - t0)/(1024 * 1024); |
363 |
|
assertTrue(millisElapsed < SMALL_DELAY_MS); |
364 |
|
} |
365 |
< |
q.poll(LONG_DELAY_MS, MILLISECONDS); |
365 |
> |
try { |
366 |
> |
q.poll(LONG_DELAY_MS, MILLISECONDS); |
367 |
> |
shouldThrow(); |
368 |
> |
} catch (InterruptedException success) {} |
369 |
|
}}); |
368 |
– |
Thread.sleep(SMALL_DELAY_MS); |
369 |
– |
t.interrupt(); |
370 |
– |
t.join(); |
371 |
– |
checkEmpty(q); |
372 |
– |
} |
370 |
|
|
374 |
– |
/** |
375 |
– |
* timed poll before a delayed offer fails; after offer succeeds; |
376 |
– |
* on interruption throws |
377 |
– |
*/ |
378 |
– |
public void testTimedPollWithOffer() throws InterruptedException { |
379 |
– |
final LinkedTransferQueue q = new LinkedTransferQueue(); |
380 |
– |
Thread t = newStartedThread(new CheckedInterruptedRunnable() { |
381 |
– |
void realRun() throws InterruptedException { |
382 |
– |
threadAssertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS)); |
383 |
– |
q.poll(LONG_DELAY_MS, MILLISECONDS); |
384 |
– |
q.poll(LONG_DELAY_MS, MILLISECONDS); |
385 |
– |
}}); |
371 |
|
Thread.sleep(SMALL_DELAY_MS); |
387 |
– |
assertTrue(q.offer(zero, SHORT_DELAY_MS, MILLISECONDS)); |
372 |
|
t.interrupt(); |
373 |
|
t.join(); |
374 |
+ |
checkEmpty(q); |
375 |
|
} |
376 |
|
|
377 |
|
/** |
401 |
|
try { |
402 |
|
q.element(); |
403 |
|
shouldThrow(); |
404 |
< |
} catch (NoSuchElementException success) { |
420 |
< |
} |
404 |
> |
} catch (NoSuchElementException success) {} |
405 |
|
checkEmpty(q); |
406 |
|
} |
407 |
|
|
416 |
|
try { |
417 |
|
q.remove(); |
418 |
|
shouldThrow(); |
419 |
< |
} catch (NoSuchElementException success) { |
436 |
< |
} |
419 |
> |
} catch (NoSuchElementException success) {} |
420 |
|
checkEmpty(q); |
421 |
|
} |
422 |
|
|
445 |
|
assertTrue(q.remove(one)); |
446 |
|
assertTrue(q.remove(two)); |
447 |
|
assertTrue(q.add(three)); |
448 |
< |
assertTrue(q.take() == three); |
448 |
> |
assertSame(q.take(), three); |
449 |
|
} |
450 |
|
|
451 |
|
/** |
553 |
|
* toArray(null) throws NullPointerException |
554 |
|
*/ |
555 |
|
public void testToArray_BadArg() { |
556 |
+ |
LinkedTransferQueue q = populatedQueue(SIZE); |
557 |
|
try { |
574 |
– |
LinkedTransferQueue q = populatedQueue(SIZE); |
558 |
|
Object o[] = q.toArray(null); |
559 |
|
shouldThrow(); |
560 |
< |
} catch (NullPointerException success) { |
578 |
< |
} |
560 |
> |
} catch (NullPointerException success) {} |
561 |
|
} |
562 |
|
|
563 |
|
/** |
564 |
|
* toArray(incompatible array type) throws CCE |
565 |
|
*/ |
566 |
|
public void testToArray1_BadArg() { |
567 |
+ |
LinkedTransferQueue q = populatedQueue(SIZE); |
568 |
|
try { |
586 |
– |
LinkedTransferQueue q = populatedQueue(SIZE); |
569 |
|
Object o[] = q.toArray(new String[10]); |
570 |
|
shouldThrow(); |
571 |
< |
} catch (ArrayStoreException success) { |
590 |
< |
} |
571 |
> |
} catch (ArrayStoreException success) {} |
572 |
|
} |
573 |
|
|
574 |
|
/** |
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 |
|
|
657 |
|
ExecutorService executor = Executors.newFixedThreadPool(2); |
658 |
|
|
659 |
|
executor.execute(new CheckedRunnable() { |
660 |
< |
void realRun() { |
661 |
< |
threadAssertTrue(q.offer(three, MEDIUM_DELAY_MS, |
681 |
< |
MILLISECONDS)); |
660 |
> |
public void realRun() { |
661 |
> |
assertTrue(q.offer(three, MEDIUM_DELAY_MS, MILLISECONDS)); |
662 |
|
}}); |
663 |
|
|
664 |
|
executor.execute(new CheckedRunnable() { |
665 |
< |
void realRun() throws InterruptedException { |
665 |
> |
public void realRun() throws InterruptedException { |
666 |
|
Thread.sleep(SMALL_DELAY_MS); |
667 |
< |
threadAssertEquals(one, q.take()); |
667 |
> |
assertSame(one, q.take()); |
668 |
|
}}); |
669 |
|
|
670 |
|
joinPool(executor); |
678 |
|
ExecutorService executor = Executors.newFixedThreadPool(2); |
679 |
|
|
680 |
|
executor.execute(new CheckedRunnable() { |
681 |
< |
void realRun() throws InterruptedException { |
682 |
< |
threadAssertNull(q.poll()); |
683 |
< |
threadAssertTrue(null != q.poll(MEDIUM_DELAY_MS, |
684 |
< |
MILLISECONDS)); |
705 |
< |
threadAssertTrue(q.isEmpty()); |
681 |
> |
public void realRun() throws InterruptedException { |
682 |
> |
assertNull(q.poll()); |
683 |
> |
assertSame(one, q.poll(MEDIUM_DELAY_MS, MILLISECONDS)); |
684 |
> |
assertTrue(q.isEmpty()); |
685 |
|
}}); |
686 |
|
|
687 |
|
executor.execute(new CheckedRunnable() { |
688 |
< |
void realRun() throws InterruptedException { |
688 |
> |
public void realRun() throws InterruptedException { |
689 |
|
Thread.sleep(SMALL_DELAY_MS); |
690 |
|
q.put(one); |
691 |
|
}}); |
725 |
|
try { |
726 |
|
q.drainTo(null); |
727 |
|
shouldThrow(); |
728 |
< |
} catch (NullPointerException success) { |
750 |
< |
} |
728 |
> |
} catch (NullPointerException success) {} |
729 |
|
} |
730 |
|
|
731 |
|
/** |
736 |
|
try { |
737 |
|
q.drainTo(q); |
738 |
|
shouldThrow(); |
739 |
< |
} catch (IllegalArgumentException success) { |
762 |
< |
} |
739 |
> |
} catch (IllegalArgumentException success) {} |
740 |
|
} |
741 |
|
|
742 |
|
/** |
771 |
|
public void testDrainToWithActivePut() throws InterruptedException { |
772 |
|
final LinkedTransferQueue q = populatedQueue(SIZE); |
773 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
774 |
< |
void realRun() { |
774 |
> |
public void realRun() { |
775 |
|
q.put(SIZE + 1); |
776 |
|
}}); |
777 |
|
ArrayList l = new ArrayList(); |
792 |
|
try { |
793 |
|
q.drainTo(null, SIZE); |
794 |
|
shouldThrow(); |
795 |
< |
} catch (NullPointerException success) { |
819 |
< |
} |
795 |
> |
} catch (NullPointerException success) {} |
796 |
|
} |
797 |
|
|
798 |
|
/** |
803 |
|
try { |
804 |
|
q.drainTo(q, SIZE); |
805 |
|
shouldThrow(); |
806 |
< |
} catch (IllegalArgumentException success) { |
831 |
< |
} |
806 |
> |
} catch (IllegalArgumentException success) {} |
807 |
|
} |
808 |
|
|
809 |
|
/** |
810 |
< |
* drainTo(c, n) empties first max {n, size} elements of queue into c |
810 |
> |
* drainTo(c, n) empties first min(n, size) elements of queue into c |
811 |
|
*/ |
812 |
|
public void testDrainToN() { |
813 |
|
LinkedTransferQueue q = new LinkedTransferQueue(); |
838 |
|
assertFalse(q.hasWaitingConsumer()); |
839 |
|
|
840 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
841 |
< |
void realRun() throws InterruptedException { |
841 |
> |
public void realRun() throws InterruptedException { |
842 |
|
Thread.sleep(SMALL_DELAY_MS); |
843 |
< |
threadAssertTrue(q.hasWaitingConsumer()); |
844 |
< |
threadAssertEquals(q.getWaitingConsumerCount(), 1); |
845 |
< |
threadAssertTrue(q.offer(new Object())); |
846 |
< |
threadAssertFalse(q.hasWaitingConsumer()); |
847 |
< |
threadAssertEquals(q.getWaitingConsumerCount(), 0); |
843 |
> |
assertTrue(q.hasWaitingConsumer()); |
844 |
> |
assertEquals(q.getWaitingConsumerCount(), 1); |
845 |
> |
assertTrue(q.offer(one)); |
846 |
> |
assertFalse(q.hasWaitingConsumer()); |
847 |
> |
assertEquals(q.getWaitingConsumerCount(), 0); |
848 |
|
}}); |
849 |
|
|
850 |
< |
assertTrue(q.poll(LONG_DELAY_MS, MILLISECONDS) != null); |
850 |
> |
assertSame(one, q.poll(LONG_DELAY_MS, MILLISECONDS)); |
851 |
|
assertEquals(q.getWaitingConsumerCount(), 0); |
852 |
|
assertFalse(q.hasWaitingConsumer()); |
853 |
|
t.join(); |
861 |
|
LinkedTransferQueue q = new LinkedTransferQueue(); |
862 |
|
q.transfer(null); |
863 |
|
shouldThrow(); |
864 |
< |
} catch (NullPointerException ex) { |
890 |
< |
} |
864 |
> |
} catch (NullPointerException success) {} |
865 |
|
} |
866 |
|
|
867 |
|
/** |
873 |
|
= new LinkedTransferQueue<Integer>(); |
874 |
|
|
875 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
876 |
< |
void realRun() throws InterruptedException { |
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); |
893 |
|
= new LinkedTransferQueue<Integer>(); |
894 |
|
|
895 |
|
Thread first = newStartedThread(new CheckedRunnable() { |
896 |
< |
void realRun() throws InterruptedException { |
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( |
904 |
|
new CheckedInterruptedRunnable() { |
905 |
< |
void realRun() throws InterruptedException { |
905 |
> |
public void realRun() throws InterruptedException { |
906 |
|
while (q.size() == 0) |
907 |
|
Thread.yield(); |
908 |
|
q.transfer(SIZE); |
928 |
|
final LinkedTransferQueue q = new LinkedTransferQueue(); |
929 |
|
|
930 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
931 |
< |
void realRun() throws InterruptedException { |
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 |
|
|
949 |
|
= new LinkedTransferQueue<Integer>(); |
950 |
|
|
951 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
952 |
< |
void realRun() throws InterruptedException { |
952 |
> |
public void realRun() throws InterruptedException { |
953 |
|
q.transfer(SIZE); |
954 |
|
checkEmpty(q); |
955 |
|
}}); |
968 |
|
final LinkedTransferQueue q = new LinkedTransferQueue(); |
969 |
|
q.tryTransfer(null); |
970 |
|
shouldThrow(); |
971 |
< |
} catch (NullPointerException ex) { |
998 |
< |
} |
971 |
> |
} catch (NullPointerException success) {} |
972 |
|
} |
973 |
|
|
974 |
|
/** |
991 |
|
final LinkedTransferQueue q = new LinkedTransferQueue(); |
992 |
|
|
993 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
994 |
< |
void realRun() { |
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 |
< |
assertTrue(q.poll(MEDIUM_DELAY_MS, MILLISECONDS) == hotPotato); |
1003 |
> |
assertSame(hotPotato, q.poll(MEDIUM_DELAY_MS, MILLISECONDS)); |
1004 |
|
checkEmpty(q); |
1005 |
|
t.join(); |
1006 |
|
} |
1014 |
|
final LinkedTransferQueue q = new LinkedTransferQueue(); |
1015 |
|
|
1016 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
1017 |
< |
void realRun() { |
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 |
< |
assertTrue(q.take() == hotPotato); |
1026 |
> |
assertSame(q.take(), hotPotato); |
1027 |
|
checkEmpty(q); |
1028 |
|
t.join(); |
1029 |
|
} |
1036 |
|
final LinkedTransferQueue q = new LinkedTransferQueue(); |
1037 |
|
|
1038 |
|
Thread toInterrupt = newStartedThread(new CheckedInterruptedRunnable() { |
1039 |
< |
void realRun() throws InterruptedException { |
1039 |
> |
public void realRun() throws InterruptedException { |
1040 |
|
q.tryTransfer(new Object(), LONG_DELAY_MS, MILLISECONDS); |
1041 |
|
}}); |
1042 |
|
|
1052 |
|
final LinkedTransferQueue q = new LinkedTransferQueue(); |
1053 |
|
|
1054 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
1055 |
< |
void realRun() throws InterruptedException { |
1056 |
< |
threadAssertFalse |
1057 |
< |
(q.tryTransfer(new Object(), |
1085 |
< |
SHORT_DELAY_MS, MILLISECONDS)); |
1055 |
> |
public void realRun() throws InterruptedException { |
1056 |
> |
assertFalse(q.tryTransfer(new Object(), |
1057 |
> |
SHORT_DELAY_MS, MILLISECONDS)); |
1058 |
|
}}); |
1059 |
|
|
1060 |
|
Thread.sleep(SMALL_DELAY_MS); |
1071 |
|
assertTrue(q.offer(four)); |
1072 |
|
|
1073 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
1074 |
< |
void realRun() throws InterruptedException { |
1075 |
< |
threadAssertTrue(q.tryTransfer(five, |
1076 |
< |
MEDIUM_DELAY_MS, MILLISECONDS)); |
1105 |
< |
threadAssertTrue(q.isEmpty()); |
1074 |
> |
public void realRun() throws InterruptedException { |
1075 |
> |
assertTrue(q.tryTransfer(five, MEDIUM_DELAY_MS, MILLISECONDS)); |
1076 |
> |
assertTrue(q.isEmpty()); |
1077 |
|
}}); |
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 |
|
} |