108 |
|
*/ |
109 |
|
public void testConstructor5() { |
110 |
|
Integer[] ints = new Integer[SIZE]; |
111 |
< |
for (int i = 0; i < SIZE-1; ++i) |
111 |
> |
for (int i = 0; i < SIZE - 1; ++i) |
112 |
|
ints[i] = new Integer(i); |
113 |
|
Collection<Integer> elements = Arrays.asList(ints); |
114 |
|
try { |
155 |
|
assertEquals(i, q.remove()); |
156 |
|
} |
157 |
|
for (int i = 0; i < SIZE; ++i) { |
158 |
< |
assertEquals(SIZE-i, q.remainingCapacity()); |
158 |
> |
assertEquals(SIZE - i, q.remainingCapacity()); |
159 |
|
assertEquals(SIZE, q.size() + q.remainingCapacity()); |
160 |
|
assertTrue(q.add(i)); |
161 |
|
} |
202 |
|
public void testAddAll3() { |
203 |
|
LinkedBlockingQueue q = new LinkedBlockingQueue(SIZE); |
204 |
|
Integer[] ints = new Integer[SIZE]; |
205 |
< |
for (int i = 0; i < SIZE-1; ++i) |
205 |
> |
for (int i = 0; i < SIZE - 1; ++i) |
206 |
|
ints[i] = new Integer(i); |
207 |
|
Collection<Integer> elements = Arrays.asList(ints); |
208 |
|
try { |
574 |
|
assertTrue(changed); |
575 |
|
|
576 |
|
assertTrue(q.containsAll(p)); |
577 |
< |
assertEquals(SIZE-i, q.size()); |
577 |
> |
assertEquals(SIZE - i, q.size()); |
578 |
|
p.remove(); |
579 |
|
} |
580 |
|
} |
587 |
|
LinkedBlockingQueue q = populatedQueue(SIZE); |
588 |
|
LinkedBlockingQueue p = populatedQueue(i); |
589 |
|
assertTrue(q.removeAll(p)); |
590 |
< |
assertEquals(SIZE-i, q.size()); |
590 |
> |
assertEquals(SIZE - i, q.size()); |
591 |
|
for (int j = 0; j < i; ++j) { |
592 |
|
Integer x = (Integer)(p.remove()); |
593 |
|
assertFalse(q.contains(x)); |
722 |
|
final LinkedBlockingQueue q = new LinkedBlockingQueue(2); |
723 |
|
q.add(one); |
724 |
|
q.add(two); |
725 |
– |
ExecutorService executor = Executors.newFixedThreadPool(2); |
725 |
|
final CheckedBarrier threadsStarted = new CheckedBarrier(2); |
726 |
< |
executor.execute(new CheckedRunnable() { |
727 |
< |
public void realRun() throws InterruptedException { |
728 |
< |
assertFalse(q.offer(three)); |
729 |
< |
threadsStarted.await(); |
730 |
< |
assertTrue(q.offer(three, LONG_DELAY_MS, MILLISECONDS)); |
731 |
< |
assertEquals(0, q.remainingCapacity()); |
732 |
< |
}}); |
733 |
< |
|
734 |
< |
executor.execute(new CheckedRunnable() { |
735 |
< |
public void realRun() throws InterruptedException { |
736 |
< |
threadsStarted.await(); |
737 |
< |
assertSame(one, q.take()); |
738 |
< |
}}); |
739 |
< |
|
740 |
< |
joinPool(executor); |
726 |
> |
final ExecutorService executor = Executors.newFixedThreadPool(2); |
727 |
> |
try (PoolCleaner cleaner = cleaner(executor)) { |
728 |
> |
executor.execute(new CheckedRunnable() { |
729 |
> |
public void realRun() throws InterruptedException { |
730 |
> |
assertFalse(q.offer(three)); |
731 |
> |
threadsStarted.await(); |
732 |
> |
assertTrue(q.offer(three, LONG_DELAY_MS, MILLISECONDS)); |
733 |
> |
assertEquals(0, q.remainingCapacity()); |
734 |
> |
}}); |
735 |
> |
|
736 |
> |
executor.execute(new CheckedRunnable() { |
737 |
> |
public void realRun() throws InterruptedException { |
738 |
> |
threadsStarted.await(); |
739 |
> |
assertSame(one, q.take()); |
740 |
> |
}}); |
741 |
> |
} |
742 |
|
} |
743 |
|
|
744 |
|
/** |
747 |
|
public void testPollInExecutor() { |
748 |
|
final LinkedBlockingQueue q = new LinkedBlockingQueue(2); |
749 |
|
final CheckedBarrier threadsStarted = new CheckedBarrier(2); |
750 |
< |
ExecutorService executor = Executors.newFixedThreadPool(2); |
751 |
< |
executor.execute(new CheckedRunnable() { |
752 |
< |
public void realRun() throws InterruptedException { |
753 |
< |
assertNull(q.poll()); |
754 |
< |
threadsStarted.await(); |
755 |
< |
assertSame(one, q.poll(LONG_DELAY_MS, MILLISECONDS)); |
756 |
< |
checkEmpty(q); |
757 |
< |
}}); |
758 |
< |
|
759 |
< |
executor.execute(new CheckedRunnable() { |
760 |
< |
public void realRun() throws InterruptedException { |
761 |
< |
threadsStarted.await(); |
762 |
< |
q.put(one); |
763 |
< |
}}); |
764 |
< |
|
765 |
< |
joinPool(executor); |
750 |
> |
final ExecutorService executor = Executors.newFixedThreadPool(2); |
751 |
> |
try (PoolCleaner cleaner = cleaner(executor)) { |
752 |
> |
executor.execute(new CheckedRunnable() { |
753 |
> |
public void realRun() throws InterruptedException { |
754 |
> |
assertNull(q.poll()); |
755 |
> |
threadsStarted.await(); |
756 |
> |
assertSame(one, q.poll(LONG_DELAY_MS, MILLISECONDS)); |
757 |
> |
checkEmpty(q); |
758 |
> |
}}); |
759 |
> |
|
760 |
> |
executor.execute(new CheckedRunnable() { |
761 |
> |
public void realRun() throws InterruptedException { |
762 |
> |
threadsStarted.await(); |
763 |
> |
q.put(one); |
764 |
> |
}}); |
765 |
> |
} |
766 |
|
} |
767 |
|
|
768 |
|
/** |
814 |
|
final LinkedBlockingQueue q = populatedQueue(SIZE); |
815 |
|
Thread t = new Thread(new CheckedRunnable() { |
816 |
|
public void realRun() throws InterruptedException { |
817 |
< |
q.put(new Integer(SIZE+1)); |
817 |
> |
q.put(new Integer(SIZE + 1)); |
818 |
|
}}); |
819 |
|
|
820 |
|
t.start(); |
839 |
|
q.drainTo(l, i); |
840 |
|
int k = (i < SIZE) ? i : SIZE; |
841 |
|
assertEquals(k, l.size()); |
842 |
< |
assertEquals(SIZE-k, q.size()); |
842 |
> |
assertEquals(SIZE - k, q.size()); |
843 |
|
for (int j = 0; j < k; ++j) |
844 |
|
assertEquals(l.get(j), new Integer(j)); |
845 |
|
do {} while (q.poll() != null); |