13 |
|
import java.io.ObjectOutputStream; |
14 |
|
import java.util.ArrayList; |
15 |
|
import java.util.Arrays; |
16 |
– |
import java.util.ConcurrentModificationException; |
16 |
|
import java.util.Iterator; |
17 |
|
import java.util.List; |
18 |
|
import java.util.NoSuchElementException; |
544 |
|
} |
545 |
|
|
546 |
|
/** |
547 |
< |
* toArray contains all elements |
547 |
> |
* toArray() contains all elements |
548 |
|
*/ |
549 |
|
public void testToArray() throws InterruptedException { |
550 |
|
LinkedTransferQueue q = populatedQueue(SIZE); |
579 |
|
} |
580 |
|
|
581 |
|
/** |
582 |
< |
* toArray with incompatible array type throws CCE |
582 |
> |
* toArray(incompatible array type) throws CCE |
583 |
|
*/ |
584 |
|
public void testToArray1_BadArg() { |
585 |
|
try { |
691 |
|
} |
692 |
|
|
693 |
|
/** |
694 |
< |
* poll retrieves elements across Executor threads |
694 |
> |
* timed poll retrieves elements across Executor threads |
695 |
|
*/ |
696 |
|
public void testPollInExecutor() { |
697 |
|
final LinkedTransferQueue q = new LinkedTransferQueue(); |
789 |
|
} |
790 |
|
|
791 |
|
/** |
792 |
< |
* drainTo empties full queue, unblocking a waiting put. |
792 |
> |
* drainTo(c) empties full queue, unblocking a waiting put. |
793 |
|
*/ |
794 |
|
public void testDrainToWithActivePut() throws InterruptedException { |
795 |
|
final LinkedTransferQueue q = populatedQueue(SIZE); |
854 |
|
} |
855 |
|
|
856 |
|
/** |
857 |
< |
* poll and take decrement the waiting consumer count |
857 |
> |
* timed poll() or take() increments the waiting consumer count; |
858 |
> |
* offer(e) decrements the waiting consumer count |
859 |
|
*/ |
860 |
|
public void testWaitingConsumer() throws InterruptedException { |
861 |
|
final LinkedTransferQueue q = new LinkedTransferQueue(); |
862 |
< |
final ConsumerObserver waiting = new ConsumerObserver(); |
862 |
> |
assertEquals(q.getWaitingConsumerCount(), 0); |
863 |
> |
assertFalse(q.hasWaitingConsumer()); |
864 |
|
|
865 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
866 |
|
void realRun() throws InterruptedException { |
867 |
|
Thread.sleep(SMALL_DELAY_MS); |
868 |
|
threadAssertTrue(q.hasWaitingConsumer()); |
869 |
< |
waiting.setWaitingConsumer(q.getWaitingConsumerCount()); |
869 |
> |
threadAssertEquals(q.getWaitingConsumerCount(), 1); |
870 |
|
threadAssertTrue(q.offer(new Object())); |
871 |
+ |
threadAssertFalse(q.hasWaitingConsumer()); |
872 |
+ |
threadAssertEquals(q.getWaitingConsumerCount(), 0); |
873 |
|
}}); |
874 |
|
|
875 |
|
assertTrue(q.poll(LONG_DELAY_MS, MILLISECONDS) != null); |
876 |
< |
assertTrue(q.getWaitingConsumerCount() |
877 |
< |
< waiting.getWaitingConsumers()); |
876 |
> |
assertEquals(q.getWaitingConsumerCount(), 0); |
877 |
> |
assertFalse(q.hasWaitingConsumer()); |
878 |
|
t.join(); |
879 |
|
} |
880 |
|
|
886 |
|
LinkedTransferQueue q = new LinkedTransferQueue(); |
887 |
|
q.transfer(null); |
888 |
|
shouldThrow(); |
889 |
< |
} catch (NullPointerException ex) { |
887 |
< |
} |
889 |
> |
} catch (NullPointerException success) {} |
890 |
|
} |
891 |
|
|
892 |
|
/** |
993 |
|
final LinkedTransferQueue q = new LinkedTransferQueue(); |
994 |
|
q.tryTransfer(null); |
995 |
|
shouldThrow(); |
996 |
< |
} catch (NullPointerException ex) { |
995 |
< |
} |
996 |
> |
} catch (NullPointerException success) {} |
997 |
|
} |
998 |
|
|
999 |
|
/** |
1122 |
|
assertFalse(q.tryTransfer(five, SHORT_DELAY_MS, MILLISECONDS)); |
1123 |
|
assertEquals(1, q.size()); |
1124 |
|
assertEquals(four, q.poll()); |
1124 |
– |
checkEmpty(q); |
1125 |
|
assertNull(q.poll()); |
1126 |
+ |
checkEmpty(q); |
1127 |
|
} |
1128 |
|
|
1129 |
|
private LinkedTransferQueue<Integer> populatedQueue(int n) { |
1137 |
|
assertFalse(q.isEmpty()); |
1138 |
|
return q; |
1139 |
|
} |
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 |
– |
} |
1140 |
|
} |