545 |
|
} |
546 |
|
|
547 |
|
/** |
548 |
< |
* toArray contains all elements |
548 |
> |
* toArray() contains all elements |
549 |
|
*/ |
550 |
|
public void testToArray() throws InterruptedException { |
551 |
|
LinkedTransferQueue q = populatedQueue(SIZE); |
580 |
|
} |
581 |
|
|
582 |
|
/** |
583 |
< |
* toArray with incompatible array type throws CCE |
583 |
> |
* toArray(incompatible array type) throws CCE |
584 |
|
*/ |
585 |
|
public void testToArray1_BadArg() { |
586 |
|
try { |
692 |
|
} |
693 |
|
|
694 |
|
/** |
695 |
< |
* poll retrieves elements across Executor threads |
695 |
> |
* timed poll retrieves elements across Executor threads |
696 |
|
*/ |
697 |
|
public void testPollInExecutor() { |
698 |
|
final LinkedTransferQueue q = new LinkedTransferQueue(); |
790 |
|
} |
791 |
|
|
792 |
|
/** |
793 |
< |
* drainTo empties full queue, unblocking a waiting put. |
793 |
> |
* drainTo(c) empties full queue, unblocking a waiting put. |
794 |
|
*/ |
795 |
|
public void testDrainToWithActivePut() throws InterruptedException { |
796 |
|
final LinkedTransferQueue q = populatedQueue(SIZE); |
855 |
|
} |
856 |
|
|
857 |
|
/** |
858 |
< |
* poll and take decrement the waiting consumer count |
858 |
> |
* timed poll() or take() increments the waiting consumer count; |
859 |
> |
* offer(e) decrements the waiting consumer count |
860 |
|
*/ |
861 |
|
public void testWaitingConsumer() throws InterruptedException { |
862 |
|
final LinkedTransferQueue q = new LinkedTransferQueue(); |
863 |
< |
final ConsumerObserver waiting = new ConsumerObserver(); |
863 |
> |
assertEquals(q.getWaitingConsumerCount(), 0); |
864 |
> |
assertFalse(q.hasWaitingConsumer()); |
865 |
|
|
866 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
867 |
|
void realRun() throws InterruptedException { |
868 |
|
Thread.sleep(SMALL_DELAY_MS); |
869 |
|
threadAssertTrue(q.hasWaitingConsumer()); |
870 |
< |
waiting.setWaitingConsumer(q.getWaitingConsumerCount()); |
870 |
> |
threadAssertEquals(q.getWaitingConsumerCount(), 1); |
871 |
|
threadAssertTrue(q.offer(new Object())); |
872 |
+ |
threadAssertFalse(q.hasWaitingConsumer()); |
873 |
+ |
threadAssertEquals(q.getWaitingConsumerCount(), 0); |
874 |
|
}}); |
875 |
|
|
876 |
|
assertTrue(q.poll(LONG_DELAY_MS, MILLISECONDS) != null); |
877 |
< |
assertTrue(q.getWaitingConsumerCount() |
878 |
< |
< waiting.getWaitingConsumers()); |
877 |
> |
assertEquals(q.getWaitingConsumerCount(), 0); |
878 |
> |
assertFalse(q.hasWaitingConsumer()); |
879 |
|
t.join(); |
880 |
|
} |
881 |
|
|
1125 |
|
assertFalse(q.tryTransfer(five, SHORT_DELAY_MS, MILLISECONDS)); |
1126 |
|
assertEquals(1, q.size()); |
1127 |
|
assertEquals(four, q.poll()); |
1124 |
– |
checkEmpty(q); |
1128 |
|
assertNull(q.poll()); |
1129 |
+ |
checkEmpty(q); |
1130 |
|
} |
1131 |
|
|
1132 |
|
private LinkedTransferQueue<Integer> populatedQueue(int n) { |
1140 |
|
assertFalse(q.isEmpty()); |
1141 |
|
return q; |
1142 |
|
} |
1139 |
– |
|
1140 |
– |
private static class ConsumerObserver { |
1141 |
– |
|
1142 |
– |
private int waitingConsumers; |
1143 |
– |
|
1144 |
– |
private ConsumerObserver() { |
1145 |
– |
} |
1146 |
– |
|
1147 |
– |
private void setWaitingConsumer(int i) { |
1148 |
– |
this.waitingConsumers = i; |
1149 |
– |
} |
1150 |
– |
|
1151 |
– |
private int getWaitingConsumers() { |
1152 |
– |
return waitingConsumers; |
1153 |
– |
} |
1154 |
– |
} |
1143 |
|
} |