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 { |
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 { |
699 |
> |
public void realRun() throws InterruptedException { |
700 |
|
threadAssertNull(q.poll()); |
701 |
|
threadAssertTrue(null != q.poll(MEDIUM_DELAY_MS, |
702 |
|
MILLISECONDS)); |
704 |
|
}}); |
705 |
|
|
706 |
|
executor.execute(new CheckedRunnable() { |
707 |
< |
void realRun() throws InterruptedException { |
707 |
> |
public void realRun() throws InterruptedException { |
708 |
|
Thread.sleep(SMALL_DELAY_MS); |
709 |
|
q.put(one); |
710 |
|
}}); |
790 |
|
public void testDrainToWithActivePut() throws InterruptedException { |
791 |
|
final LinkedTransferQueue q = populatedQueue(SIZE); |
792 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
793 |
< |
void realRun() { |
793 |
> |
public void realRun() { |
794 |
|
q.put(SIZE + 1); |
795 |
|
}}); |
796 |
|
ArrayList l = new ArrayList(); |
857 |
|
assertFalse(q.hasWaitingConsumer()); |
858 |
|
|
859 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
860 |
< |
void realRun() throws InterruptedException { |
860 |
> |
public void realRun() throws InterruptedException { |
861 |
|
Thread.sleep(SMALL_DELAY_MS); |
862 |
|
threadAssertTrue(q.hasWaitingConsumer()); |
863 |
|
threadAssertEquals(q.getWaitingConsumerCount(), 1); |
892 |
|
= new LinkedTransferQueue<Integer>(); |
893 |
|
|
894 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
895 |
< |
void realRun() throws InterruptedException { |
895 |
> |
public void realRun() throws InterruptedException { |
896 |
|
q.transfer(SIZE); |
897 |
|
threadAssertTrue(q.isEmpty()); |
898 |
|
}}); |
912 |
|
= new LinkedTransferQueue<Integer>(); |
913 |
|
|
914 |
|
Thread first = newStartedThread(new CheckedRunnable() { |
915 |
< |
void realRun() throws InterruptedException { |
915 |
> |
public void realRun() throws InterruptedException { |
916 |
|
Integer i = SIZE + 1; |
917 |
|
q.transfer(i); |
918 |
|
threadAssertTrue(!q.contains(i)); |
921 |
|
|
922 |
|
Thread interruptedThread = newStartedThread( |
923 |
|
new CheckedInterruptedRunnable() { |
924 |
< |
void realRun() throws InterruptedException { |
924 |
> |
public void realRun() throws InterruptedException { |
925 |
|
while (q.size() == 0) |
926 |
|
Thread.yield(); |
927 |
|
q.transfer(SIZE); |
947 |
|
final LinkedTransferQueue q = new LinkedTransferQueue(); |
948 |
|
|
949 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
950 |
< |
void realRun() throws InterruptedException { |
950 |
> |
public void realRun() throws InterruptedException { |
951 |
|
q.transfer(four); |
952 |
|
threadAssertFalse(q.contains(four)); |
953 |
|
threadAssertEquals(three, q.poll()); |
968 |
|
= new LinkedTransferQueue<Integer>(); |
969 |
|
|
970 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
971 |
< |
void realRun() throws InterruptedException { |
971 |
> |
public void realRun() throws InterruptedException { |
972 |
|
q.transfer(SIZE); |
973 |
|
checkEmpty(q); |
974 |
|
}}); |
1010 |
|
final LinkedTransferQueue q = new LinkedTransferQueue(); |
1011 |
|
|
1012 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
1013 |
< |
void realRun() { |
1013 |
> |
public void realRun() { |
1014 |
|
while (! q.hasWaitingConsumer()) |
1015 |
|
Thread.yield(); |
1016 |
|
threadAssertTrue(q.hasWaitingConsumer()); |
1033 |
|
final LinkedTransferQueue q = new LinkedTransferQueue(); |
1034 |
|
|
1035 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
1036 |
< |
void realRun() { |
1036 |
> |
public void realRun() { |
1037 |
|
while (! q.hasWaitingConsumer()) |
1038 |
|
Thread.yield(); |
1039 |
|
threadAssertTrue(q.hasWaitingConsumer()); |
1055 |
|
final LinkedTransferQueue q = new LinkedTransferQueue(); |
1056 |
|
|
1057 |
|
Thread toInterrupt = newStartedThread(new CheckedInterruptedRunnable() { |
1058 |
< |
void realRun() throws InterruptedException { |
1058 |
> |
public void realRun() throws InterruptedException { |
1059 |
|
q.tryTransfer(new Object(), LONG_DELAY_MS, MILLISECONDS); |
1060 |
|
}}); |
1061 |
|
|
1071 |
|
final LinkedTransferQueue q = new LinkedTransferQueue(); |
1072 |
|
|
1073 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
1074 |
< |
void realRun() throws InterruptedException { |
1074 |
> |
public void realRun() throws InterruptedException { |
1075 |
|
threadAssertFalse |
1076 |
|
(q.tryTransfer(new Object(), |
1077 |
|
SHORT_DELAY_MS, MILLISECONDS)); |
1091 |
|
assertTrue(q.offer(four)); |
1092 |
|
|
1093 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
1094 |
< |
void realRun() throws InterruptedException { |
1094 |
> |
public void realRun() throws InterruptedException { |
1095 |
|
threadAssertTrue(q.tryTransfer(five, |
1096 |
|
MEDIUM_DELAY_MS, MILLISECONDS)); |
1097 |
|
threadAssertTrue(q.isEmpty()); |