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); |
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, |
375 |
|
public void testTimedPollWithOffer() throws InterruptedException { |
376 |
|
final LinkedTransferQueue q = new LinkedTransferQueue(); |
377 |
|
Thread t = new Thread(new CheckedRunnable() { |
378 |
< |
void realRun() throws InterruptedException { |
378 |
> |
public void realRun() throws InterruptedException { |
379 |
|
assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS)); |
380 |
|
assertSame(zero, q.poll(LONG_DELAY_MS, MILLISECONDS)); |
381 |
|
try { |
570 |
|
* toArray(null) throws NullPointerException |
571 |
|
*/ |
572 |
|
public void testToArray_BadArg() { |
573 |
+ |
LinkedTransferQueue q = populatedQueue(SIZE); |
574 |
|
try { |
574 |
– |
LinkedTransferQueue q = populatedQueue(SIZE); |
575 |
|
Object o[] = q.toArray(null); |
576 |
|
shouldThrow(); |
577 |
|
} catch (NullPointerException success) {} |
581 |
|
* toArray(incompatible array type) throws CCE |
582 |
|
*/ |
583 |
|
public void testToArray1_BadArg() { |
584 |
+ |
LinkedTransferQueue q = populatedQueue(SIZE); |
585 |
|
try { |
585 |
– |
LinkedTransferQueue q = populatedQueue(SIZE); |
586 |
|
Object o[] = q.toArray(new String[10]); |
587 |
|
shouldThrow(); |
588 |
|
} catch (ArrayStoreException success) {} |
674 |
|
ExecutorService executor = Executors.newFixedThreadPool(2); |
675 |
|
|
676 |
|
executor.execute(new CheckedRunnable() { |
677 |
< |
void realRun() { |
677 |
> |
public void realRun() { |
678 |
|
threadAssertTrue(q.offer(three, MEDIUM_DELAY_MS, |
679 |
|
MILLISECONDS)); |
680 |
|
}}); |
681 |
|
|
682 |
|
executor.execute(new CheckedRunnable() { |
683 |
< |
void realRun() throws InterruptedException { |
683 |
> |
public void realRun() throws InterruptedException { |
684 |
|
Thread.sleep(SMALL_DELAY_MS); |
685 |
|
threadAssertEquals(one, q.take()); |
686 |
|
}}); |
696 |
|
ExecutorService executor = Executors.newFixedThreadPool(2); |
697 |
|
|
698 |
|
executor.execute(new CheckedRunnable() { |
699 |
< |
void realRun() throws InterruptedException { |
700 |
< |
threadAssertNull(q.poll()); |
701 |
< |
threadAssertTrue(null != q.poll(MEDIUM_DELAY_MS, |
702 |
< |
MILLISECONDS)); |
703 |
< |
threadAssertTrue(q.isEmpty()); |
699 |
> |
public void realRun() throws InterruptedException { |
700 |
> |
assertNull(q.poll()); |
701 |
> |
assertSame(one, q.poll(MEDIUM_DELAY_MS, MILLISECONDS)); |
702 |
> |
assertTrue(q.isEmpty()); |
703 |
|
}}); |
704 |
|
|
705 |
|
executor.execute(new CheckedRunnable() { |
706 |
< |
void realRun() throws InterruptedException { |
706 |
> |
public void realRun() throws InterruptedException { |
707 |
|
Thread.sleep(SMALL_DELAY_MS); |
708 |
|
q.put(one); |
709 |
|
}}); |
789 |
|
public void testDrainToWithActivePut() throws InterruptedException { |
790 |
|
final LinkedTransferQueue q = populatedQueue(SIZE); |
791 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
792 |
< |
void realRun() { |
792 |
> |
public void realRun() { |
793 |
|
q.put(SIZE + 1); |
794 |
|
}}); |
795 |
|
ArrayList l = new ArrayList(); |
856 |
|
assertFalse(q.hasWaitingConsumer()); |
857 |
|
|
858 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
859 |
< |
void realRun() throws InterruptedException { |
859 |
> |
public void realRun() throws InterruptedException { |
860 |
|
Thread.sleep(SMALL_DELAY_MS); |
861 |
< |
threadAssertTrue(q.hasWaitingConsumer()); |
862 |
< |
threadAssertEquals(q.getWaitingConsumerCount(), 1); |
863 |
< |
threadAssertTrue(q.offer(new Object())); |
864 |
< |
threadAssertFalse(q.hasWaitingConsumer()); |
865 |
< |
threadAssertEquals(q.getWaitingConsumerCount(), 0); |
861 |
> |
assertTrue(q.hasWaitingConsumer()); |
862 |
> |
assertEquals(q.getWaitingConsumerCount(), 1); |
863 |
> |
assertTrue(q.offer(one)); |
864 |
> |
assertFalse(q.hasWaitingConsumer()); |
865 |
> |
assertEquals(q.getWaitingConsumerCount(), 0); |
866 |
|
}}); |
867 |
|
|
868 |
< |
assertTrue(q.poll(LONG_DELAY_MS, MILLISECONDS) != null); |
868 |
> |
assertSame(one, q.poll(LONG_DELAY_MS, MILLISECONDS)); |
869 |
|
assertEquals(q.getWaitingConsumerCount(), 0); |
870 |
|
assertFalse(q.hasWaitingConsumer()); |
871 |
|
t.join(); |
891 |
|
= new LinkedTransferQueue<Integer>(); |
892 |
|
|
893 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
894 |
< |
void realRun() throws InterruptedException { |
894 |
> |
public void realRun() throws InterruptedException { |
895 |
|
q.transfer(SIZE); |
896 |
|
threadAssertTrue(q.isEmpty()); |
897 |
|
}}); |
911 |
|
= new LinkedTransferQueue<Integer>(); |
912 |
|
|
913 |
|
Thread first = newStartedThread(new CheckedRunnable() { |
914 |
< |
void realRun() throws InterruptedException { |
914 |
> |
public void realRun() throws InterruptedException { |
915 |
|
Integer i = SIZE + 1; |
916 |
|
q.transfer(i); |
917 |
|
threadAssertTrue(!q.contains(i)); |
920 |
|
|
921 |
|
Thread interruptedThread = newStartedThread( |
922 |
|
new CheckedInterruptedRunnable() { |
923 |
< |
void realRun() throws InterruptedException { |
923 |
> |
public void realRun() throws InterruptedException { |
924 |
|
while (q.size() == 0) |
925 |
|
Thread.yield(); |
926 |
|
q.transfer(SIZE); |
946 |
|
final LinkedTransferQueue q = new LinkedTransferQueue(); |
947 |
|
|
948 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
949 |
< |
void realRun() throws InterruptedException { |
949 |
> |
public void realRun() throws InterruptedException { |
950 |
|
q.transfer(four); |
951 |
|
threadAssertFalse(q.contains(four)); |
952 |
|
threadAssertEquals(three, q.poll()); |
967 |
|
= new LinkedTransferQueue<Integer>(); |
968 |
|
|
969 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
970 |
< |
void realRun() throws InterruptedException { |
970 |
> |
public void realRun() throws InterruptedException { |
971 |
|
q.transfer(SIZE); |
972 |
|
checkEmpty(q); |
973 |
|
}}); |
1009 |
|
final LinkedTransferQueue q = new LinkedTransferQueue(); |
1010 |
|
|
1011 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
1012 |
< |
void realRun() { |
1012 |
> |
public void realRun() { |
1013 |
|
while (! q.hasWaitingConsumer()) |
1014 |
|
Thread.yield(); |
1015 |
|
threadAssertTrue(q.hasWaitingConsumer()); |
1032 |
|
final LinkedTransferQueue q = new LinkedTransferQueue(); |
1033 |
|
|
1034 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
1035 |
< |
void realRun() { |
1035 |
> |
public void realRun() { |
1036 |
|
while (! q.hasWaitingConsumer()) |
1037 |
|
Thread.yield(); |
1038 |
|
threadAssertTrue(q.hasWaitingConsumer()); |
1054 |
|
final LinkedTransferQueue q = new LinkedTransferQueue(); |
1055 |
|
|
1056 |
|
Thread toInterrupt = newStartedThread(new CheckedInterruptedRunnable() { |
1057 |
< |
void realRun() throws InterruptedException { |
1057 |
> |
public void realRun() throws InterruptedException { |
1058 |
|
q.tryTransfer(new Object(), LONG_DELAY_MS, MILLISECONDS); |
1059 |
|
}}); |
1060 |
|
|
1070 |
|
final LinkedTransferQueue q = new LinkedTransferQueue(); |
1071 |
|
|
1072 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
1073 |
< |
void realRun() throws InterruptedException { |
1073 |
> |
public void realRun() throws InterruptedException { |
1074 |
|
threadAssertFalse |
1075 |
|
(q.tryTransfer(new Object(), |
1076 |
|
SHORT_DELAY_MS, MILLISECONDS)); |
1090 |
|
assertTrue(q.offer(four)); |
1091 |
|
|
1092 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
1093 |
< |
void realRun() throws InterruptedException { |
1093 |
> |
public void realRun() throws InterruptedException { |
1094 |
|
threadAssertTrue(q.tryTransfer(five, |
1095 |
|
MEDIUM_DELAY_MS, MILLISECONDS)); |
1096 |
|
threadAssertTrue(q.isEmpty()); |