100 |
|
public void testConstructor5() { |
101 |
|
Item[] items = defaultItems; |
102 |
|
List<Item> intList = Arrays.asList(items); |
103 |
< |
LinkedTransferQueue<Item> q |
104 |
< |
= new LinkedTransferQueue<Item>(intList); |
103 |
> |
LinkedTransferQueue<Item> q = new LinkedTransferQueue<>(intList); |
104 |
|
mustEqual(q.size(), intList.size()); |
105 |
|
mustEqual(q.toString(), intList.toString()); |
106 |
|
assertTrue(Arrays.equals(q.toArray(), |
147 |
|
* NullPointerException after possibly adding some elements |
148 |
|
*/ |
149 |
|
public void testAddAll3() { |
150 |
< |
LinkedTransferQueue<Item> q = new LinkedTransferQueue<Item>(); |
150 |
> |
LinkedTransferQueue<Item> q = new LinkedTransferQueue<>(); |
151 |
|
Item[] items = new Item[2]; items[0] = zero; |
152 |
|
try { |
153 |
|
q.addAll(Arrays.asList(items)); |
369 |
|
* An add following remove(x) succeeds |
370 |
|
*/ |
371 |
|
public void testRemoveElementAndAdd() throws InterruptedException { |
372 |
< |
LinkedTransferQueue<Item> q = new LinkedTransferQueue<Item>(); |
372 |
> |
LinkedTransferQueue<Item> q = new LinkedTransferQueue<>(); |
373 |
|
mustAdd(q, one); |
374 |
|
mustAdd(q, two); |
375 |
|
mustRemove(q, one); |
484 |
|
/** |
485 |
|
* toArray(incompatible array type) throws ArrayStoreException |
486 |
|
*/ |
487 |
< |
public void testToArray1_BadArg() { |
487 |
> |
@SuppressWarnings("CollectionToArraySafeParameter") |
488 |
> |
public void testToArray_incompatibleArrayType() { |
489 |
|
LinkedTransferQueue<Item> q = populatedQueue(SIZE); |
490 |
|
try { |
491 |
|
q.toArray(new String[10]); |
523 |
|
* iterator.remove() removes current element |
524 |
|
*/ |
525 |
|
public void testIteratorRemove() { |
526 |
< |
final LinkedTransferQueue<Item> q = new LinkedTransferQueue<Item>(); |
526 |
> |
final LinkedTransferQueue<Item> q = new LinkedTransferQueue<>(); |
527 |
|
q.add(two); |
528 |
|
q.add(one); |
529 |
|
q.add(three); |
559 |
|
* Modifications do not cause iterators to fail |
560 |
|
*/ |
561 |
|
public void testWeaklyConsistentIteration() { |
562 |
< |
final LinkedTransferQueue<Item> q = new LinkedTransferQueue<Item>(); |
562 |
> |
final LinkedTransferQueue<Item> q = new LinkedTransferQueue<>(); |
563 |
|
q.add(one); |
564 |
|
q.add(two); |
565 |
|
q.add(three); |
585 |
|
* offer transfers elements across Executor tasks |
586 |
|
*/ |
587 |
|
public void testOfferInExecutor() { |
588 |
< |
final LinkedTransferQueue<Item> q = new LinkedTransferQueue<Item>(); |
588 |
> |
final LinkedTransferQueue<Item> q = new LinkedTransferQueue<>(); |
589 |
|
final CheckedBarrier threadsStarted = new CheckedBarrier(2); |
590 |
|
final ExecutorService executor = Executors.newFixedThreadPool(2); |
591 |
|
try (PoolCleaner cleaner = cleaner(executor)) { |
611 |
|
* timed poll retrieves elements across Executor threads |
612 |
|
*/ |
613 |
|
public void testPollInExecutor() { |
614 |
< |
final LinkedTransferQueue<Item> q = new LinkedTransferQueue<Item>(); |
614 |
> |
final LinkedTransferQueue<Item> q = new LinkedTransferQueue<>(); |
615 |
|
final CheckedBarrier threadsStarted = new CheckedBarrier(2); |
616 |
|
final ExecutorService executor = Executors.newFixedThreadPool(2); |
617 |
|
try (PoolCleaner cleaner = cleaner(executor)) { |
700 |
|
* drainTo(c, n) empties first min(n, size) elements of queue into c |
701 |
|
*/ |
702 |
|
public void testDrainToN() { |
703 |
< |
LinkedTransferQueue<Item> q = new LinkedTransferQueue<Item>(); |
703 |
> |
LinkedTransferQueue<Item> q = new LinkedTransferQueue<>(); |
704 |
|
for (int i = 0; i < SIZE + 2; ++i) { |
705 |
|
for (int j = 0; j < SIZE; j++) { |
706 |
|
mustOffer(q, j); |
721 |
|
* offer(e) decrements the waiting consumer count |
722 |
|
*/ |
723 |
|
public void testWaitingConsumer() throws InterruptedException { |
724 |
< |
final LinkedTransferQueue<Item> q = new LinkedTransferQueue<Item>(); |
724 |
> |
final LinkedTransferQueue<Item> q = new LinkedTransferQueue<>(); |
725 |
|
mustEqual(0, q.getWaitingConsumerCount()); |
726 |
|
assertFalse(q.hasWaitingConsumer()); |
727 |
|
final CountDownLatch threadStarted = new CountDownLatch(1); |
737 |
|
}}); |
738 |
|
|
739 |
|
threadStarted.await(); |
740 |
< |
Callable<Boolean> oneConsumer |
741 |
< |
= new Callable<Boolean>() { public Boolean call() { |
740 |
> |
Callable<Boolean> oneConsumer = new Callable<>() { |
741 |
> |
public Boolean call() { |
742 |
|
return q.hasWaitingConsumer() |
743 |
|
&& q.getWaitingConsumerCount() == 1; }}; |
744 |
|
waitForThreadToEnterWaitState(t, oneConsumer); |
755 |
|
*/ |
756 |
|
public void testTransfer1() throws InterruptedException { |
757 |
|
try { |
758 |
< |
LinkedTransferQueue<Item> q = new LinkedTransferQueue<Item>(); |
758 |
> |
LinkedTransferQueue<Item> q = new LinkedTransferQueue<>(); |
759 |
|
q.transfer(null); |
760 |
|
shouldThrow(); |
761 |
|
} catch (NullPointerException success) {} |
777 |
|
}}); |
778 |
|
|
779 |
|
threadStarted.await(); |
780 |
< |
Callable<Boolean> oneElement |
781 |
< |
= new Callable<Boolean>() { public Boolean call() { |
780 |
> |
Callable<Boolean> oneElement = new Callable<>() { |
781 |
> |
public Boolean call() { |
782 |
|
return !q.isEmpty() && q.size() == 1; }}; |
783 |
|
waitForThreadToEnterWaitState(t, oneElement); |
784 |
|
|
824 |
|
* thread returns the element |
825 |
|
*/ |
826 |
|
public void testTransfer4() throws InterruptedException { |
827 |
< |
final LinkedTransferQueue<Item> q = new LinkedTransferQueue<Item>(); |
827 |
> |
final LinkedTransferQueue<Item> q = new LinkedTransferQueue<>(); |
828 |
|
|
829 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
830 |
|
public void realRun() throws InterruptedException { |
868 |
|
* tryTransfer(null) throws NullPointerException |
869 |
|
*/ |
870 |
|
public void testTryTransfer1() { |
871 |
< |
final LinkedTransferQueue<Item> q = new LinkedTransferQueue<Item>(); |
871 |
> |
final LinkedTransferQueue<Item> q = new LinkedTransferQueue<>(); |
872 |
|
try { |
873 |
|
q.tryTransfer(null); |
874 |
|
shouldThrow(); |
880 |
|
* consumers waiting to poll or take. |
881 |
|
*/ |
882 |
|
public void testTryTransfer2() throws InterruptedException { |
883 |
< |
final LinkedTransferQueue<Object> q = new LinkedTransferQueue<Object>(); |
883 |
> |
final LinkedTransferQueue<Object> q = new LinkedTransferQueue<>(); |
884 |
|
assertFalse(q.tryTransfer(new Object())); |
885 |
|
assertFalse(q.hasWaitingConsumer()); |
886 |
|
checkEmpty(q); |
892 |
|
*/ |
893 |
|
public void testTryTransfer3() throws InterruptedException { |
894 |
|
final Object hotPotato = new Object(); |
895 |
< |
final LinkedTransferQueue<Object> q = new LinkedTransferQueue<Object>(); |
895 |
> |
final LinkedTransferQueue<Object> q = new LinkedTransferQueue<>(); |
896 |
|
|
897 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
898 |
|
public void realRun() { |
916 |
|
*/ |
917 |
|
public void testTryTransfer4() throws InterruptedException { |
918 |
|
final Object hotPotato = new Object(); |
919 |
< |
final LinkedTransferQueue<Object> q = new LinkedTransferQueue<Object>(); |
919 |
> |
final LinkedTransferQueue<Object> q = new LinkedTransferQueue<>(); |
920 |
|
|
921 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
922 |
|
public void realRun() { |
936 |
|
* tryTransfer blocks interruptibly if no takers |
937 |
|
*/ |
938 |
|
public void testTryTransfer5() throws InterruptedException { |
939 |
< |
final LinkedTransferQueue<Object> q = new LinkedTransferQueue<Object>(); |
939 |
> |
final LinkedTransferQueue<Object> q = new LinkedTransferQueue<>(); |
940 |
|
final CountDownLatch pleaseInterrupt = new CountDownLatch(1); |
941 |
|
assertTrue(q.isEmpty()); |
942 |
|
|
968 |
|
* tryTransfer gives up after the timeout and returns false |
969 |
|
*/ |
970 |
|
public void testTryTransfer6() throws InterruptedException { |
971 |
< |
final LinkedTransferQueue<Object> q = new LinkedTransferQueue<Object>(); |
971 |
> |
final LinkedTransferQueue<Object> q = new LinkedTransferQueue<>(); |
972 |
|
|
973 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
974 |
|
public void realRun() throws InterruptedException { |
988 |
|
* before transfering to a poll or take |
989 |
|
*/ |
990 |
|
public void testTryTransfer7() throws InterruptedException { |
991 |
< |
final LinkedTransferQueue<Item> q = new LinkedTransferQueue<Item>(); |
991 |
> |
final LinkedTransferQueue<Item> q = new LinkedTransferQueue<>(); |
992 |
|
assertTrue(q.offer(four)); |
993 |
|
|
994 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
1013 |
|
* returning false not enqueueing and the successive poll is null |
1014 |
|
*/ |
1015 |
|
public void testTryTransfer8() throws InterruptedException { |
1016 |
< |
final LinkedTransferQueue<Item> q = new LinkedTransferQueue<Item>(); |
1016 |
> |
final LinkedTransferQueue<Item> q = new LinkedTransferQueue<>(); |
1017 |
|
assertTrue(q.offer(four)); |
1018 |
|
mustEqual(1, q.size()); |
1019 |
|
long startTime = System.nanoTime(); |
1042 |
|
*/ |
1043 |
|
public void testNeverContainsNull() { |
1044 |
|
Collection<?>[] qs = { |
1045 |
< |
new LinkedTransferQueue<Object>(), |
1045 |
> |
new LinkedTransferQueue<>(), |
1046 |
|
populatedQueue(2), |
1047 |
|
}; |
1048 |
|
|