15 |
|
import java.util.NoSuchElementException; |
16 |
|
import java.util.Queue; |
17 |
|
import java.util.concurrent.BlockingQueue; |
18 |
+ |
import java.util.concurrent.Callable; |
19 |
|
import java.util.concurrent.CountDownLatch; |
20 |
|
import java.util.concurrent.Executors; |
21 |
|
import java.util.concurrent.ExecutorService; |
25 |
|
|
26 |
|
@SuppressWarnings({"unchecked", "rawtypes"}) |
27 |
|
public class LinkedTransferQueueTest extends JSR166TestCase { |
27 |
– |
|
28 |
|
public static class Generic extends BlockingQueueTest { |
29 |
|
protected BlockingQueue emptyCollection() { |
30 |
|
return new LinkedTransferQueue(); |
36 |
|
} |
37 |
|
|
38 |
|
public static Test suite() { |
39 |
+ |
class Implementation implements CollectionImplementation { |
40 |
+ |
public Class<?> klazz() { return LinkedTransferQueue.class; } |
41 |
+ |
public Collection emptyCollection() { return new LinkedTransferQueue(); } |
42 |
+ |
public Object makeElement(int i) { return i; } |
43 |
+ |
public boolean isConcurrent() { return true; } |
44 |
+ |
public boolean permitsNulls() { return false; } |
45 |
+ |
} |
46 |
|
return newTestSuite(LinkedTransferQueueTest.class, |
47 |
< |
new Generic().testSuite()); |
47 |
> |
new Generic().testSuite(), |
48 |
> |
CollectionTest.testSuite(new Implementation())); |
49 |
|
} |
50 |
|
|
51 |
|
/** |
86 |
|
*/ |
87 |
|
public void testConstructor4() { |
88 |
|
Integer[] ints = new Integer[SIZE]; |
89 |
< |
for (int i = 0; i < SIZE-1; ++i) |
89 |
> |
for (int i = 0; i < SIZE - 1; ++i) |
90 |
|
ints[i] = i; |
91 |
|
Collection<Integer> elements = Arrays.asList(ints); |
92 |
|
try { |
140 |
|
* addAll(this) throws IllegalArgumentException |
141 |
|
*/ |
142 |
|
public void testAddAllSelf() { |
143 |
+ |
LinkedTransferQueue q = populatedQueue(SIZE); |
144 |
|
try { |
136 |
– |
LinkedTransferQueue q = populatedQueue(SIZE); |
145 |
|
q.addAll(q); |
146 |
|
shouldThrow(); |
147 |
|
} catch (IllegalArgumentException success) {} |
152 |
|
* NullPointerException after possibly adding some elements |
153 |
|
*/ |
154 |
|
public void testAddAll3() { |
155 |
+ |
LinkedTransferQueue q = new LinkedTransferQueue(); |
156 |
+ |
Integer[] ints = new Integer[SIZE]; |
157 |
+ |
for (int i = 0; i < SIZE - 1; ++i) |
158 |
+ |
ints[i] = i; |
159 |
|
try { |
148 |
– |
LinkedTransferQueue q = new LinkedTransferQueue(); |
149 |
– |
Integer[] ints = new Integer[SIZE]; |
150 |
– |
for (int i = 0; i < SIZE - 1; ++i) { |
151 |
– |
ints[i] = i; |
152 |
– |
} |
160 |
|
q.addAll(Arrays.asList(ints)); |
161 |
|
shouldThrow(); |
162 |
|
} catch (NullPointerException success) {} |
183 |
|
* all elements successfully put are contained |
184 |
|
*/ |
185 |
|
public void testPut() { |
186 |
< |
LinkedTransferQueue<Integer> q = new LinkedTransferQueue<Integer>(); |
186 |
> |
LinkedTransferQueue<Integer> q = new LinkedTransferQueue<>(); |
187 |
|
for (int i = 0; i < SIZE; ++i) { |
188 |
|
assertEquals(i, q.size()); |
189 |
|
q.put(i); |
209 |
|
final CountDownLatch pleaseInterrupt = new CountDownLatch(1); |
210 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
211 |
|
public void realRun() throws InterruptedException { |
212 |
< |
for (int i = 0; i < SIZE; ++i) { |
206 |
< |
assertEquals(i, q.take()); |
207 |
< |
} |
212 |
> |
for (int i = 0; i < SIZE; i++) assertEquals(i, q.take()); |
213 |
|
|
214 |
|
Thread.currentThread().interrupt(); |
215 |
|
try { |
227 |
|
}}); |
228 |
|
|
229 |
|
await(pleaseInterrupt); |
230 |
< |
assertThreadStaysAlive(t); |
230 |
> |
assertThreadBlocks(t, Thread.State.WAITING); |
231 |
|
t.interrupt(); |
232 |
|
awaitTermination(t); |
233 |
|
} |
261 |
|
*/ |
262 |
|
public void testTimedPoll() throws InterruptedException { |
263 |
|
LinkedTransferQueue<Integer> q = populatedQueue(SIZE); |
259 |
– |
for (int i = 0; i < SIZE; ++i) { |
260 |
– |
long startTime = System.nanoTime(); |
261 |
– |
assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS)); |
262 |
– |
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
263 |
– |
} |
264 |
|
long startTime = System.nanoTime(); |
265 |
+ |
for (int i = 0; i < SIZE; ++i) |
266 |
+ |
assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS)); |
267 |
+ |
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
268 |
+ |
|
269 |
+ |
startTime = System.nanoTime(); |
270 |
|
assertNull(q.poll(timeoutMillis(), MILLISECONDS)); |
271 |
|
assertTrue(millisElapsedSince(startTime) >= timeoutMillis()); |
272 |
|
checkEmpty(q); |
278 |
|
*/ |
279 |
|
public void testInterruptedTimedPoll() throws InterruptedException { |
280 |
|
final BlockingQueue<Integer> q = populatedQueue(SIZE); |
281 |
< |
final CountDownLatch aboutToWait = new CountDownLatch(1); |
281 |
> |
final CountDownLatch pleaseInterrupt = new CountDownLatch(1); |
282 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
283 |
|
public void realRun() throws InterruptedException { |
284 |
< |
for (int i = 0; i < SIZE; ++i) { |
285 |
< |
long t0 = System.nanoTime(); |
284 |
> |
long startTime = System.nanoTime(); |
285 |
> |
for (int i = 0; i < SIZE; ++i) |
286 |
|
assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS)); |
287 |
< |
assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS); |
288 |
< |
} |
284 |
< |
long t0 = System.nanoTime(); |
285 |
< |
aboutToWait.countDown(); |
287 |
> |
|
288 |
> |
pleaseInterrupt.countDown(); |
289 |
|
try { |
290 |
< |
q.poll(MEDIUM_DELAY_MS, MILLISECONDS); |
290 |
> |
q.poll(LONG_DELAY_MS, MILLISECONDS); |
291 |
|
shouldThrow(); |
292 |
< |
} catch (InterruptedException success) { |
293 |
< |
assertTrue(millisElapsedSince(t0) < MEDIUM_DELAY_MS); |
294 |
< |
} |
292 |
> |
} catch (InterruptedException success) {} |
293 |
> |
assertFalse(Thread.interrupted()); |
294 |
> |
|
295 |
> |
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
296 |
|
}}); |
297 |
|
|
298 |
< |
aboutToWait.await(); |
299 |
< |
waitForThreadToEnterWaitState(t, SMALL_DELAY_MS); |
298 |
> |
await(pleaseInterrupt); |
299 |
> |
assertThreadBlocks(t, Thread.State.TIMED_WAITING); |
300 |
|
t.interrupt(); |
301 |
< |
awaitTermination(t, MEDIUM_DELAY_MS); |
301 |
> |
awaitTermination(t); |
302 |
|
checkEmpty(q); |
303 |
|
} |
304 |
|
|
310 |
|
final BlockingQueue<Integer> q = populatedQueue(SIZE); |
311 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
312 |
|
public void realRun() throws InterruptedException { |
313 |
+ |
long startTime = System.nanoTime(); |
314 |
|
Thread.currentThread().interrupt(); |
315 |
< |
for (int i = 0; i < SIZE; ++i) { |
311 |
< |
long t0 = System.nanoTime(); |
315 |
> |
for (int i = 0; i < SIZE; ++i) |
316 |
|
assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS)); |
313 |
– |
assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS); |
314 |
– |
} |
317 |
|
try { |
318 |
< |
q.poll(MEDIUM_DELAY_MS, MILLISECONDS); |
318 |
> |
q.poll(LONG_DELAY_MS, MILLISECONDS); |
319 |
|
shouldThrow(); |
320 |
|
} catch (InterruptedException success) {} |
321 |
+ |
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
322 |
|
}}); |
323 |
|
|
324 |
< |
awaitTermination(t, MEDIUM_DELAY_MS); |
324 |
> |
awaitTermination(t); |
325 |
|
checkEmpty(q); |
326 |
|
} |
327 |
|
|
417 |
|
*/ |
418 |
|
public void testContainsAll() { |
419 |
|
LinkedTransferQueue<Integer> q = populatedQueue(SIZE); |
420 |
< |
LinkedTransferQueue<Integer> p = new LinkedTransferQueue<Integer>(); |
420 |
> |
LinkedTransferQueue<Integer> p = new LinkedTransferQueue<>(); |
421 |
|
for (int i = 0; i < SIZE; ++i) { |
422 |
|
assertTrue(q.containsAll(p)); |
423 |
|
assertFalse(p.containsAll(q)); |
546 |
|
* iterator ordering is FIFO |
547 |
|
*/ |
548 |
|
public void testIteratorOrdering() { |
549 |
< |
final LinkedTransferQueue<Integer> q |
547 |
< |
= new LinkedTransferQueue<Integer>(); |
549 |
> |
final LinkedTransferQueue<Integer> q = new LinkedTransferQueue<>(); |
550 |
|
assertEquals(Integer.MAX_VALUE, q.remainingCapacity()); |
551 |
|
q.add(one); |
552 |
|
q.add(two); |
591 |
|
public void testOfferInExecutor() { |
592 |
|
final LinkedTransferQueue q = new LinkedTransferQueue(); |
593 |
|
final CheckedBarrier threadsStarted = new CheckedBarrier(2); |
594 |
< |
ExecutorService executor = Executors.newFixedThreadPool(2); |
594 |
> |
final ExecutorService executor = Executors.newFixedThreadPool(2); |
595 |
> |
try (PoolCleaner cleaner = cleaner(executor)) { |
596 |
|
|
597 |
< |
executor.execute(new CheckedRunnable() { |
598 |
< |
public void realRun() throws InterruptedException { |
599 |
< |
threadsStarted.await(); |
600 |
< |
assertTrue(q.offer(one, LONG_DELAY_MS, MILLISECONDS)); |
601 |
< |
}}); |
602 |
< |
|
603 |
< |
executor.execute(new CheckedRunnable() { |
601 |
< |
public void realRun() throws InterruptedException { |
602 |
< |
threadsStarted.await(); |
603 |
< |
assertSame(one, q.take()); |
604 |
< |
checkEmpty(q); |
605 |
< |
}}); |
597 |
> |
executor.execute(new CheckedRunnable() { |
598 |
> |
public void realRun() throws InterruptedException { |
599 |
> |
threadsStarted.await(); |
600 |
> |
long startTime = System.nanoTime(); |
601 |
> |
assertTrue(q.offer(one, LONG_DELAY_MS, MILLISECONDS)); |
602 |
> |
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
603 |
> |
}}); |
604 |
|
|
605 |
< |
joinPool(executor); |
605 |
> |
executor.execute(new CheckedRunnable() { |
606 |
> |
public void realRun() throws InterruptedException { |
607 |
> |
threadsStarted.await(); |
608 |
> |
assertSame(one, q.take()); |
609 |
> |
checkEmpty(q); |
610 |
> |
}}); |
611 |
> |
} |
612 |
|
} |
613 |
|
|
614 |
|
/** |
617 |
|
public void testPollInExecutor() { |
618 |
|
final LinkedTransferQueue q = new LinkedTransferQueue(); |
619 |
|
final CheckedBarrier threadsStarted = new CheckedBarrier(2); |
620 |
< |
ExecutorService executor = Executors.newFixedThreadPool(2); |
621 |
< |
|
618 |
< |
executor.execute(new CheckedRunnable() { |
619 |
< |
public void realRun() throws InterruptedException { |
620 |
< |
assertNull(q.poll()); |
621 |
< |
threadsStarted.await(); |
622 |
< |
assertSame(one, q.poll(LONG_DELAY_MS, MILLISECONDS)); |
623 |
< |
checkEmpty(q); |
624 |
< |
}}); |
620 |
> |
final ExecutorService executor = Executors.newFixedThreadPool(2); |
621 |
> |
try (PoolCleaner cleaner = cleaner(executor)) { |
622 |
|
|
623 |
< |
executor.execute(new CheckedRunnable() { |
624 |
< |
public void realRun() throws InterruptedException { |
625 |
< |
threadsStarted.await(); |
626 |
< |
q.put(one); |
627 |
< |
}}); |
623 |
> |
executor.execute(new CheckedRunnable() { |
624 |
> |
public void realRun() throws InterruptedException { |
625 |
> |
assertNull(q.poll()); |
626 |
> |
threadsStarted.await(); |
627 |
> |
long startTime = System.nanoTime(); |
628 |
> |
assertSame(one, q.poll(LONG_DELAY_MS, MILLISECONDS)); |
629 |
> |
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
630 |
> |
checkEmpty(q); |
631 |
> |
}}); |
632 |
|
|
633 |
< |
joinPool(executor); |
633 |
> |
executor.execute(new CheckedRunnable() { |
634 |
> |
public void realRun() throws InterruptedException { |
635 |
> |
threadsStarted.await(); |
636 |
> |
q.put(one); |
637 |
> |
}}); |
638 |
> |
} |
639 |
|
} |
640 |
|
|
641 |
|
/** |
696 |
|
assertTrue(l.size() >= SIZE); |
697 |
|
for (int i = 0; i < SIZE; ++i) |
698 |
|
assertEquals(i, l.get(i)); |
699 |
< |
awaitTermination(t, MEDIUM_DELAY_MS); |
699 |
> |
awaitTermination(t); |
700 |
|
assertTrue(q.size() + l.size() >= SIZE); |
701 |
|
} |
702 |
|
|
733 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
734 |
|
public void realRun() throws InterruptedException { |
735 |
|
threadStarted.countDown(); |
736 |
+ |
long startTime = System.nanoTime(); |
737 |
|
assertSame(one, q.poll(LONG_DELAY_MS, MILLISECONDS)); |
738 |
|
assertEquals(0, q.getWaitingConsumerCount()); |
739 |
|
assertFalse(q.hasWaitingConsumer()); |
740 |
+ |
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
741 |
|
}}); |
742 |
|
|
743 |
|
threadStarted.await(); |
744 |
< |
waitForThreadToEnterWaitState(t, SMALL_DELAY_MS); |
745 |
< |
assertEquals(1, q.getWaitingConsumerCount()); |
746 |
< |
assertTrue(q.hasWaitingConsumer()); |
744 |
> |
Callable<Boolean> oneConsumer |
745 |
> |
= new Callable<Boolean>() { public Boolean call() { |
746 |
> |
return q.hasWaitingConsumer() |
747 |
> |
&& q.getWaitingConsumerCount() == 1; }}; |
748 |
> |
waitForThreadToEnterWaitState(t, oneConsumer); |
749 |
|
|
750 |
|
assertTrue(q.offer(one)); |
751 |
|
assertEquals(0, q.getWaitingConsumerCount()); |
752 |
|
assertFalse(q.hasWaitingConsumer()); |
753 |
|
|
754 |
< |
awaitTermination(t, MEDIUM_DELAY_MS); |
754 |
> |
awaitTermination(t); |
755 |
|
} |
756 |
|
|
757 |
|
/** |
767 |
|
|
768 |
|
/** |
769 |
|
* transfer waits until a poll occurs. The transfered element |
770 |
< |
* is returned by this associated poll. |
770 |
> |
* is returned by the associated poll. |
771 |
|
*/ |
772 |
|
public void testTransfer2() throws InterruptedException { |
773 |
< |
final LinkedTransferQueue<Integer> q |
764 |
< |
= new LinkedTransferQueue<Integer>(); |
773 |
> |
final LinkedTransferQueue<Integer> q = new LinkedTransferQueue<>(); |
774 |
|
final CountDownLatch threadStarted = new CountDownLatch(1); |
775 |
|
|
776 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
781 |
|
}}); |
782 |
|
|
783 |
|
threadStarted.await(); |
784 |
< |
waitForThreadToEnterWaitState(t, SMALL_DELAY_MS); |
785 |
< |
assertEquals(1, q.size()); |
784 |
> |
Callable<Boolean> oneElement |
785 |
> |
= new Callable<Boolean>() { public Boolean call() { |
786 |
> |
return !q.isEmpty() && q.size() == 1; }}; |
787 |
> |
waitForThreadToEnterWaitState(t, oneElement); |
788 |
> |
|
789 |
|
assertSame(five, q.poll()); |
790 |
|
checkEmpty(q); |
791 |
< |
awaitTermination(t, MEDIUM_DELAY_MS); |
791 |
> |
awaitTermination(t); |
792 |
|
} |
793 |
|
|
794 |
|
/** |
795 |
|
* transfer waits until a poll occurs, and then transfers in fifo order |
796 |
|
*/ |
797 |
|
public void testTransfer3() throws InterruptedException { |
798 |
< |
final LinkedTransferQueue<Integer> q |
787 |
< |
= new LinkedTransferQueue<Integer>(); |
798 |
> |
final LinkedTransferQueue<Integer> q = new LinkedTransferQueue<>(); |
799 |
|
|
800 |
|
Thread first = newStartedThread(new CheckedRunnable() { |
801 |
|
public void realRun() throws InterruptedException { |
802 |
|
q.transfer(four); |
803 |
< |
assertTrue(!q.contains(four)); |
803 |
> |
assertFalse(q.contains(four)); |
804 |
|
assertEquals(1, q.size()); |
805 |
|
}}); |
806 |
|
|
843 |
|
assertEquals(1, q.size()); |
844 |
|
assertTrue(q.offer(three)); |
845 |
|
assertSame(four, q.poll()); |
846 |
< |
awaitTermination(t, MEDIUM_DELAY_MS); |
846 |
> |
awaitTermination(t); |
847 |
|
} |
848 |
|
|
849 |
|
/** |
850 |
|
* transfer waits until a take occurs. The transfered element |
851 |
< |
* is returned by this associated take. |
851 |
> |
* is returned by the associated take. |
852 |
|
*/ |
853 |
|
public void testTransfer5() throws InterruptedException { |
854 |
< |
final LinkedTransferQueue<Integer> q |
844 |
< |
= new LinkedTransferQueue<Integer>(); |
854 |
> |
final LinkedTransferQueue<Integer> q = new LinkedTransferQueue<>(); |
855 |
|
|
856 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
857 |
|
public void realRun() throws InterruptedException { |
865 |
|
assertEquals(1, q.size()); |
866 |
|
assertSame(four, q.take()); |
867 |
|
checkEmpty(q); |
868 |
< |
awaitTermination(t, MEDIUM_DELAY_MS); |
868 |
> |
awaitTermination(t); |
869 |
|
} |
870 |
|
|
871 |
|
/** |
872 |
|
* tryTransfer(null) throws NullPointerException |
873 |
|
*/ |
874 |
|
public void testTryTransfer1() { |
875 |
+ |
final LinkedTransferQueue q = new LinkedTransferQueue(); |
876 |
|
try { |
866 |
– |
final LinkedTransferQueue q = new LinkedTransferQueue(); |
877 |
|
q.tryTransfer(null); |
878 |
|
shouldThrow(); |
879 |
|
} catch (NullPointerException success) {} |
907 |
|
assertTrue(q.tryTransfer(hotPotato)); |
908 |
|
}}); |
909 |
|
|
910 |
< |
assertSame(hotPotato, q.poll(MEDIUM_DELAY_MS, MILLISECONDS)); |
910 |
> |
long startTime = System.nanoTime(); |
911 |
> |
assertSame(hotPotato, q.poll(LONG_DELAY_MS, MILLISECONDS)); |
912 |
> |
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
913 |
|
checkEmpty(q); |
914 |
< |
awaitTermination(t, MEDIUM_DELAY_MS); |
914 |
> |
awaitTermination(t); |
915 |
|
} |
916 |
|
|
917 |
|
/** |
933 |
|
|
934 |
|
assertSame(q.take(), hotPotato); |
935 |
|
checkEmpty(q); |
936 |
< |
awaitTermination(t, MEDIUM_DELAY_MS); |
936 |
> |
awaitTermination(t); |
937 |
|
} |
938 |
|
|
939 |
|
/** |
946 |
|
|
947 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
948 |
|
public void realRun() throws InterruptedException { |
949 |
+ |
long startTime = System.nanoTime(); |
950 |
|
Thread.currentThread().interrupt(); |
951 |
|
try { |
952 |
|
q.tryTransfer(new Object(), LONG_DELAY_MS, MILLISECONDS); |
960 |
|
shouldThrow(); |
961 |
|
} catch (InterruptedException success) {} |
962 |
|
assertFalse(Thread.interrupted()); |
963 |
+ |
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
964 |
|
}}); |
965 |
|
|
966 |
|
await(pleaseInterrupt); |
967 |
< |
assertThreadStaysAlive(t); |
967 |
> |
assertThreadBlocks(t, Thread.State.TIMED_WAITING); |
968 |
|
t.interrupt(); |
969 |
|
awaitTermination(t); |
970 |
|
checkEmpty(q); |
978 |
|
|
979 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
980 |
|
public void realRun() throws InterruptedException { |
981 |
< |
long t0 = System.nanoTime(); |
981 |
> |
long startTime = System.nanoTime(); |
982 |
|
assertFalse(q.tryTransfer(new Object(), |
983 |
|
timeoutMillis(), MILLISECONDS)); |
984 |
< |
assertTrue(millisElapsedSince(t0) >= timeoutMillis()); |
984 |
> |
assertTrue(millisElapsedSince(startTime) >= timeoutMillis()); |
985 |
|
checkEmpty(q); |
986 |
|
}}); |
987 |
|
|
999 |
|
|
1000 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
1001 |
|
public void realRun() throws InterruptedException { |
1002 |
< |
assertTrue(q.tryTransfer(five, MEDIUM_DELAY_MS, MILLISECONDS)); |
1002 |
> |
long startTime = System.nanoTime(); |
1003 |
> |
assertTrue(q.tryTransfer(five, LONG_DELAY_MS, MILLISECONDS)); |
1004 |
> |
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
1005 |
|
checkEmpty(q); |
1006 |
|
}}); |
1007 |
|
|
1011 |
|
assertSame(four, q.poll()); |
1012 |
|
assertSame(five, q.poll()); |
1013 |
|
checkEmpty(q); |
1014 |
< |
awaitTermination(t, MEDIUM_DELAY_MS); |
1014 |
> |
awaitTermination(t); |
1015 |
|
} |
1016 |
|
|
1017 |
|
/** |
1022 |
|
final LinkedTransferQueue q = new LinkedTransferQueue(); |
1023 |
|
assertTrue(q.offer(four)); |
1024 |
|
assertEquals(1, q.size()); |
1025 |
< |
long t0 = System.nanoTime(); |
1025 |
> |
long startTime = System.nanoTime(); |
1026 |
|
assertFalse(q.tryTransfer(five, timeoutMillis(), MILLISECONDS)); |
1027 |
< |
assertTrue(millisElapsedSince(t0) >= timeoutMillis()); |
1027 |
> |
assertTrue(millisElapsedSince(startTime) >= timeoutMillis()); |
1028 |
|
assertEquals(1, q.size()); |
1029 |
|
assertSame(four, q.poll()); |
1030 |
|
assertNull(q.poll()); |
1032 |
|
} |
1033 |
|
|
1034 |
|
private LinkedTransferQueue<Integer> populatedQueue(int n) { |
1035 |
< |
LinkedTransferQueue<Integer> q = new LinkedTransferQueue<Integer>(); |
1035 |
> |
LinkedTransferQueue<Integer> q = new LinkedTransferQueue<>(); |
1036 |
|
checkEmpty(q); |
1037 |
|
for (int i = 0; i < n; i++) { |
1038 |
|
assertEquals(i, q.size()); |