44 |
|
try { |
45 |
|
q.element(); |
46 |
|
shouldThrow(); |
47 |
< |
} catch (NoSuchElementException success) { |
48 |
< |
} |
47 |
> |
} catch (NoSuchElementException success) {} |
48 |
|
try { |
49 |
|
q.iterator().next(); |
50 |
|
shouldThrow(); |
51 |
< |
} catch (NoSuchElementException success) { |
53 |
< |
} |
51 |
> |
} catch (NoSuchElementException success) {} |
52 |
|
try { |
53 |
|
q.remove(); |
54 |
|
shouldThrow(); |
55 |
< |
} catch (NoSuchElementException success) { |
58 |
< |
} |
55 |
> |
} catch (NoSuchElementException success) {} |
56 |
|
} |
57 |
|
|
58 |
|
/** |
72 |
|
try { |
73 |
|
new LinkedTransferQueue(null); |
74 |
|
shouldThrow(); |
75 |
< |
} catch (NullPointerException success) { |
79 |
< |
} |
75 |
> |
} catch (NullPointerException success) {} |
76 |
|
} |
77 |
|
|
78 |
|
/** |
84 |
|
Integer[] ints = new Integer[SIZE]; |
85 |
|
new LinkedTransferQueue(Arrays.asList(ints)); |
86 |
|
shouldThrow(); |
87 |
< |
} catch (NullPointerException success) { |
92 |
< |
} |
87 |
> |
} catch (NullPointerException success) {} |
88 |
|
} |
89 |
|
|
90 |
|
/** |
99 |
|
} |
100 |
|
new LinkedTransferQueue(Arrays.asList(ints)); |
101 |
|
shouldThrow(); |
102 |
< |
} catch (NullPointerException success) { |
108 |
< |
} |
102 |
> |
} catch (NullPointerException success) {} |
103 |
|
} |
104 |
|
|
105 |
|
/** |
151 |
|
LinkedTransferQueue q = new LinkedTransferQueue(); |
152 |
|
q.offer(null); |
153 |
|
shouldThrow(); |
154 |
< |
} catch (NullPointerException success) { |
161 |
< |
} |
154 |
> |
} catch (NullPointerException success) {} |
155 |
|
} |
156 |
|
|
157 |
|
/** |
162 |
|
LinkedTransferQueue q = new LinkedTransferQueue(); |
163 |
|
q.add(null); |
164 |
|
shouldThrow(); |
165 |
< |
} catch (NullPointerException success) { |
173 |
< |
} |
165 |
> |
} catch (NullPointerException success) {} |
166 |
|
} |
167 |
|
|
168 |
|
/** |
173 |
|
LinkedTransferQueue q = new LinkedTransferQueue(); |
174 |
|
q.addAll(null); |
175 |
|
shouldThrow(); |
176 |
< |
} catch (NullPointerException success) { |
185 |
< |
} |
176 |
> |
} catch (NullPointerException success) {} |
177 |
|
} |
178 |
|
|
179 |
|
/** |
184 |
|
LinkedTransferQueue q = populatedQueue(SIZE); |
185 |
|
q.addAll(q); |
186 |
|
shouldThrow(); |
187 |
< |
} catch (IllegalArgumentException success) { |
197 |
< |
} |
187 |
> |
} catch (IllegalArgumentException success) {} |
188 |
|
} |
189 |
|
|
190 |
|
/** |
196 |
|
Integer[] ints = new Integer[SIZE]; |
197 |
|
q.addAll(Arrays.asList(ints)); |
198 |
|
shouldThrow(); |
199 |
< |
} catch (NullPointerException success) { |
210 |
< |
} |
199 |
> |
} catch (NullPointerException success) {} |
200 |
|
} |
201 |
|
|
202 |
|
/** |
212 |
|
} |
213 |
|
q.addAll(Arrays.asList(ints)); |
214 |
|
shouldThrow(); |
215 |
< |
} catch (NullPointerException success) { |
227 |
< |
} |
215 |
> |
} catch (NullPointerException success) {} |
216 |
|
} |
217 |
|
|
218 |
|
/** |
271 |
|
public void testTakeFromEmpty() throws InterruptedException { |
272 |
|
final LinkedTransferQueue q = new LinkedTransferQueue(); |
273 |
|
Thread t = newStartedThread(new CheckedInterruptedRunnable() { |
274 |
< |
void realRun() throws InterruptedException { |
274 |
> |
public void realRun() throws InterruptedException { |
275 |
|
q.take(); |
276 |
|
}}); |
277 |
|
Thread.sleep(SHORT_DELAY_MS); |
284 |
|
*/ |
285 |
|
public void testBlockingTake() throws InterruptedException { |
286 |
|
final LinkedTransferQueue<Integer> q = populatedQueue(SIZE); |
287 |
< |
Thread t = newStartedThread(new CheckedInterruptedRunnable() { |
288 |
< |
void realRun() throws InterruptedException { |
287 |
> |
Thread t = new Thread(new CheckedRunnable() { |
288 |
> |
public void realRun() throws InterruptedException { |
289 |
|
for (int i = 0; i < SIZE; ++i) { |
290 |
< |
threadAssertEquals(i, (int) q.take()); |
290 |
> |
assertEquals(i, (int) q.take()); |
291 |
|
} |
292 |
< |
q.take(); |
292 |
> |
try { |
293 |
> |
q.take(); |
294 |
> |
shouldThrow(); |
295 |
> |
} catch (InterruptedException success) {} |
296 |
|
}}); |
297 |
< |
Thread.sleep(SMALL_DELAY_MS); |
297 |
> |
|
298 |
> |
t.start(); |
299 |
> |
Thread.sleep(SHORT_DELAY_MS); |
300 |
|
t.interrupt(); |
301 |
|
t.join(); |
302 |
|
checkEmpty(q); |
348 |
|
public void testInterruptedTimedPoll() throws InterruptedException { |
349 |
|
final LinkedTransferQueue<Integer> q = populatedQueue(SIZE); |
350 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
351 |
< |
void realRun() throws InterruptedException { |
351 |
> |
public void realRun() throws InterruptedException { |
352 |
|
for (int i = 0; i < SIZE; ++i) { |
353 |
|
long t0 = System.nanoTime(); |
354 |
< |
threadAssertEquals(i, (int) q.poll(LONG_DELAY_MS, |
362 |
< |
MILLISECONDS)); |
354 |
> |
assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS)); |
355 |
|
long millisElapsed = (System.nanoTime() - t0)/(1024 * 1024); |
356 |
|
assertTrue(millisElapsed < SMALL_DELAY_MS); |
357 |
|
} |
358 |
|
try { |
359 |
|
q.poll(LONG_DELAY_MS, MILLISECONDS); |
360 |
+ |
shouldThrow(); |
361 |
|
} catch (InterruptedException success) {} |
362 |
|
}}); |
363 |
+ |
|
364 |
|
Thread.sleep(SMALL_DELAY_MS); |
365 |
|
t.interrupt(); |
366 |
|
t.join(); |
373 |
|
*/ |
374 |
|
public void testTimedPollWithOffer() throws InterruptedException { |
375 |
|
final LinkedTransferQueue q = new LinkedTransferQueue(); |
376 |
< |
Thread t = newStartedThread(new CheckedInterruptedRunnable() { |
377 |
< |
void realRun() throws InterruptedException { |
378 |
< |
threadAssertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS)); |
379 |
< |
q.poll(LONG_DELAY_MS, MILLISECONDS); |
380 |
< |
q.poll(LONG_DELAY_MS, MILLISECONDS); |
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(); |
417 |
|
try { |
418 |
|
q.element(); |
419 |
|
shouldThrow(); |
420 |
< |
} catch (NoSuchElementException success) { |
422 |
< |
} |
420 |
> |
} catch (NoSuchElementException success) {} |
421 |
|
checkEmpty(q); |
422 |
|
} |
423 |
|
|
432 |
|
try { |
433 |
|
q.remove(); |
434 |
|
shouldThrow(); |
435 |
< |
} catch (NoSuchElementException success) { |
438 |
< |
} |
435 |
> |
} catch (NoSuchElementException success) {} |
436 |
|
checkEmpty(q); |
437 |
|
} |
438 |
|
|
461 |
|
assertTrue(q.remove(one)); |
462 |
|
assertTrue(q.remove(two)); |
463 |
|
assertTrue(q.add(three)); |
464 |
< |
assertTrue(q.take() == three); |
464 |
> |
assertSame(q.take(), three); |
465 |
|
} |
466 |
|
|
467 |
|
/** |
569 |
|
* toArray(null) throws NullPointerException |
570 |
|
*/ |
571 |
|
public void testToArray_BadArg() { |
572 |
+ |
LinkedTransferQueue q = populatedQueue(SIZE); |
573 |
|
try { |
576 |
– |
LinkedTransferQueue q = populatedQueue(SIZE); |
574 |
|
Object o[] = q.toArray(null); |
575 |
|
shouldThrow(); |
576 |
< |
} catch (NullPointerException success) { |
580 |
< |
} |
576 |
> |
} catch (NullPointerException success) {} |
577 |
|
} |
578 |
|
|
579 |
|
/** |
580 |
|
* toArray(incompatible array type) throws CCE |
581 |
|
*/ |
582 |
|
public void testToArray1_BadArg() { |
583 |
+ |
LinkedTransferQueue q = populatedQueue(SIZE); |
584 |
|
try { |
588 |
– |
LinkedTransferQueue q = populatedQueue(SIZE); |
585 |
|
Object o[] = q.toArray(new String[10]); |
586 |
|
shouldThrow(); |
587 |
< |
} catch (ArrayStoreException success) { |
592 |
< |
} |
587 |
> |
} catch (ArrayStoreException success) {} |
588 |
|
} |
589 |
|
|
590 |
|
/** |
673 |
|
ExecutorService executor = Executors.newFixedThreadPool(2); |
674 |
|
|
675 |
|
executor.execute(new CheckedRunnable() { |
676 |
< |
void realRun() { |
677 |
< |
threadAssertTrue(q.offer(three, MEDIUM_DELAY_MS, |
683 |
< |
MILLISECONDS)); |
676 |
> |
public void realRun() { |
677 |
> |
assertTrue(q.offer(three, MEDIUM_DELAY_MS, MILLISECONDS)); |
678 |
|
}}); |
679 |
|
|
680 |
|
executor.execute(new CheckedRunnable() { |
681 |
< |
void realRun() throws InterruptedException { |
681 |
> |
public void realRun() throws InterruptedException { |
682 |
|
Thread.sleep(SMALL_DELAY_MS); |
683 |
< |
threadAssertEquals(one, q.take()); |
683 |
> |
assertEquals(one, q.take()); |
684 |
|
}}); |
685 |
|
|
686 |
|
joinPool(executor); |
694 |
|
ExecutorService executor = Executors.newFixedThreadPool(2); |
695 |
|
|
696 |
|
executor.execute(new CheckedRunnable() { |
697 |
< |
void realRun() throws InterruptedException { |
698 |
< |
threadAssertNull(q.poll()); |
699 |
< |
threadAssertTrue(null != q.poll(MEDIUM_DELAY_MS, |
700 |
< |
MILLISECONDS)); |
707 |
< |
threadAssertTrue(q.isEmpty()); |
697 |
> |
public void realRun() throws InterruptedException { |
698 |
> |
assertNull(q.poll()); |
699 |
> |
assertSame(one, q.poll(MEDIUM_DELAY_MS, MILLISECONDS)); |
700 |
> |
assertTrue(q.isEmpty()); |
701 |
|
}}); |
702 |
|
|
703 |
|
executor.execute(new CheckedRunnable() { |
704 |
< |
void realRun() throws InterruptedException { |
704 |
> |
public void realRun() throws InterruptedException { |
705 |
|
Thread.sleep(SMALL_DELAY_MS); |
706 |
|
q.put(one); |
707 |
|
}}); |
741 |
|
try { |
742 |
|
q.drainTo(null); |
743 |
|
shouldThrow(); |
744 |
< |
} catch (NullPointerException success) { |
752 |
< |
} |
744 |
> |
} catch (NullPointerException success) {} |
745 |
|
} |
746 |
|
|
747 |
|
/** |
752 |
|
try { |
753 |
|
q.drainTo(q); |
754 |
|
shouldThrow(); |
755 |
< |
} catch (IllegalArgumentException success) { |
764 |
< |
} |
755 |
> |
} catch (IllegalArgumentException success) {} |
756 |
|
} |
757 |
|
|
758 |
|
/** |
787 |
|
public void testDrainToWithActivePut() throws InterruptedException { |
788 |
|
final LinkedTransferQueue q = populatedQueue(SIZE); |
789 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
790 |
< |
void realRun() { |
790 |
> |
public void realRun() { |
791 |
|
q.put(SIZE + 1); |
792 |
|
}}); |
793 |
|
ArrayList l = new ArrayList(); |
808 |
|
try { |
809 |
|
q.drainTo(null, SIZE); |
810 |
|
shouldThrow(); |
811 |
< |
} catch (NullPointerException success) { |
821 |
< |
} |
811 |
> |
} catch (NullPointerException success) {} |
812 |
|
} |
813 |
|
|
814 |
|
/** |
819 |
|
try { |
820 |
|
q.drainTo(q, SIZE); |
821 |
|
shouldThrow(); |
822 |
< |
} catch (IllegalArgumentException success) { |
833 |
< |
} |
822 |
> |
} catch (IllegalArgumentException success) {} |
823 |
|
} |
824 |
|
|
825 |
|
/** |
854 |
|
assertFalse(q.hasWaitingConsumer()); |
855 |
|
|
856 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
857 |
< |
void realRun() throws InterruptedException { |
857 |
> |
public void realRun() throws InterruptedException { |
858 |
|
Thread.sleep(SMALL_DELAY_MS); |
859 |
< |
threadAssertTrue(q.hasWaitingConsumer()); |
860 |
< |
threadAssertEquals(q.getWaitingConsumerCount(), 1); |
861 |
< |
threadAssertTrue(q.offer(new Object())); |
862 |
< |
threadAssertFalse(q.hasWaitingConsumer()); |
863 |
< |
threadAssertEquals(q.getWaitingConsumerCount(), 0); |
859 |
> |
assertTrue(q.hasWaitingConsumer()); |
860 |
> |
assertEquals(q.getWaitingConsumerCount(), 1); |
861 |
> |
assertTrue(q.offer(one)); |
862 |
> |
assertFalse(q.hasWaitingConsumer()); |
863 |
> |
assertEquals(q.getWaitingConsumerCount(), 0); |
864 |
|
}}); |
865 |
|
|
866 |
< |
assertTrue(q.poll(LONG_DELAY_MS, MILLISECONDS) != null); |
866 |
> |
assertSame(one, q.poll(LONG_DELAY_MS, MILLISECONDS)); |
867 |
|
assertEquals(q.getWaitingConsumerCount(), 0); |
868 |
|
assertFalse(q.hasWaitingConsumer()); |
869 |
|
t.join(); |
889 |
|
= new LinkedTransferQueue<Integer>(); |
890 |
|
|
891 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
892 |
< |
void realRun() throws InterruptedException { |
892 |
> |
public void realRun() throws InterruptedException { |
893 |
|
q.transfer(SIZE); |
894 |
|
threadAssertTrue(q.isEmpty()); |
895 |
|
}}); |
909 |
|
= new LinkedTransferQueue<Integer>(); |
910 |
|
|
911 |
|
Thread first = newStartedThread(new CheckedRunnable() { |
912 |
< |
void realRun() throws InterruptedException { |
912 |
> |
public void realRun() throws InterruptedException { |
913 |
|
Integer i = SIZE + 1; |
914 |
|
q.transfer(i); |
915 |
|
threadAssertTrue(!q.contains(i)); |
918 |
|
|
919 |
|
Thread interruptedThread = newStartedThread( |
920 |
|
new CheckedInterruptedRunnable() { |
921 |
< |
void realRun() throws InterruptedException { |
921 |
> |
public void realRun() throws InterruptedException { |
922 |
|
while (q.size() == 0) |
923 |
|
Thread.yield(); |
924 |
|
q.transfer(SIZE); |
944 |
|
final LinkedTransferQueue q = new LinkedTransferQueue(); |
945 |
|
|
946 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
947 |
< |
void realRun() throws InterruptedException { |
947 |
> |
public void realRun() throws InterruptedException { |
948 |
|
q.transfer(four); |
949 |
|
threadAssertFalse(q.contains(four)); |
950 |
|
threadAssertEquals(three, q.poll()); |
965 |
|
= new LinkedTransferQueue<Integer>(); |
966 |
|
|
967 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
968 |
< |
void realRun() throws InterruptedException { |
968 |
> |
public void realRun() throws InterruptedException { |
969 |
|
q.transfer(SIZE); |
970 |
|
checkEmpty(q); |
971 |
|
}}); |
1007 |
|
final LinkedTransferQueue q = new LinkedTransferQueue(); |
1008 |
|
|
1009 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
1010 |
< |
void realRun() { |
1010 |
> |
public void realRun() { |
1011 |
|
while (! q.hasWaitingConsumer()) |
1012 |
|
Thread.yield(); |
1013 |
|
threadAssertTrue(q.hasWaitingConsumer()); |
1016 |
|
threadAssertTrue(q.tryTransfer(hotPotato)); |
1017 |
|
}}); |
1018 |
|
|
1019 |
< |
assertTrue(q.poll(MEDIUM_DELAY_MS, MILLISECONDS) == hotPotato); |
1019 |
> |
assertSame(hotPotato, q.poll(MEDIUM_DELAY_MS, MILLISECONDS)); |
1020 |
|
checkEmpty(q); |
1021 |
|
t.join(); |
1022 |
|
} |
1030 |
|
final LinkedTransferQueue q = new LinkedTransferQueue(); |
1031 |
|
|
1032 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
1033 |
< |
void realRun() { |
1033 |
> |
public void realRun() { |
1034 |
|
while (! q.hasWaitingConsumer()) |
1035 |
|
Thread.yield(); |
1036 |
|
threadAssertTrue(q.hasWaitingConsumer()); |
1039 |
|
threadAssertTrue(q.tryTransfer(hotPotato)); |
1040 |
|
}}); |
1041 |
|
|
1042 |
< |
assertTrue(q.take() == hotPotato); |
1042 |
> |
assertSame(q.take(), hotPotato); |
1043 |
|
checkEmpty(q); |
1044 |
|
t.join(); |
1045 |
|
} |
1052 |
|
final LinkedTransferQueue q = new LinkedTransferQueue(); |
1053 |
|
|
1054 |
|
Thread toInterrupt = newStartedThread(new CheckedInterruptedRunnable() { |
1055 |
< |
void realRun() throws InterruptedException { |
1055 |
> |
public void realRun() throws InterruptedException { |
1056 |
|
q.tryTransfer(new Object(), LONG_DELAY_MS, MILLISECONDS); |
1057 |
|
}}); |
1058 |
|
|
1068 |
|
final LinkedTransferQueue q = new LinkedTransferQueue(); |
1069 |
|
|
1070 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
1071 |
< |
void realRun() throws InterruptedException { |
1072 |
< |
threadAssertFalse |
1073 |
< |
(q.tryTransfer(new Object(), |
1085 |
< |
SHORT_DELAY_MS, MILLISECONDS)); |
1071 |
> |
public void realRun() throws InterruptedException { |
1072 |
> |
assertFalse(q.tryTransfer(new Object(), |
1073 |
> |
SHORT_DELAY_MS, MILLISECONDS)); |
1074 |
|
}}); |
1075 |
|
|
1076 |
|
Thread.sleep(SMALL_DELAY_MS); |
1087 |
|
assertTrue(q.offer(four)); |
1088 |
|
|
1089 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
1090 |
< |
void realRun() throws InterruptedException { |
1091 |
< |
threadAssertTrue(q.tryTransfer(five, |
1092 |
< |
MEDIUM_DELAY_MS, MILLISECONDS)); |
1105 |
< |
threadAssertTrue(q.isEmpty()); |
1090 |
> |
public void realRun() throws InterruptedException { |
1091 |
> |
assertTrue(q.tryTransfer(five, MEDIUM_DELAY_MS, MILLISECONDS)); |
1092 |
> |
assertTrue(q.isEmpty()); |
1093 |
|
}}); |
1094 |
|
|
1095 |
|
Thread.sleep(SHORT_DELAY_MS); |