11 |
|
import static java.util.concurrent.TimeUnit.SECONDS; |
12 |
|
|
13 |
|
import java.util.ArrayList; |
14 |
+ |
import java.util.Collection; |
15 |
+ |
import java.util.Collections; |
16 |
|
import java.util.List; |
17 |
|
import java.util.concurrent.ArrayBlockingQueue; |
18 |
|
import java.util.concurrent.BlockingQueue; |
1497 |
|
} |
1498 |
|
|
1499 |
|
/** |
1500 |
< |
* invokeAny(empty collection) throws IAE |
1500 |
> |
* invokeAny(empty collection) throws IllegalArgumentException |
1501 |
|
*/ |
1502 |
|
public void testInvokeAny2() throws Exception { |
1503 |
|
final ExecutorService e = |
1587 |
|
} |
1588 |
|
|
1589 |
|
/** |
1590 |
< |
* invokeAll(empty collection) returns empty collection |
1590 |
> |
* invokeAll(empty collection) returns empty list |
1591 |
|
*/ |
1592 |
|
public void testInvokeAll2() throws InterruptedException { |
1593 |
|
final ExecutorService e = |
1594 |
|
new ThreadPoolExecutor(2, 2, |
1595 |
|
LONG_DELAY_MS, MILLISECONDS, |
1596 |
|
new ArrayBlockingQueue<Runnable>(10)); |
1597 |
+ |
final Collection<Callable<String>> emptyCollection |
1598 |
+ |
= Collections.emptyList(); |
1599 |
|
try (PoolCleaner cleaner = cleaner(e)) { |
1600 |
< |
List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>()); |
1600 |
> |
List<Future<String>> r = e.invokeAll(emptyCollection); |
1601 |
|
assertTrue(r.isEmpty()); |
1602 |
|
} |
1603 |
|
} |
1672 |
|
new ArrayBlockingQueue<Runnable>(10)); |
1673 |
|
try (PoolCleaner cleaner = cleaner(e)) { |
1674 |
|
try { |
1675 |
< |
e.invokeAny(null, MEDIUM_DELAY_MS, MILLISECONDS); |
1675 |
> |
e.invokeAny(null, randomTimeout(), randomTimeUnit()); |
1676 |
|
shouldThrow(); |
1677 |
|
} catch (NullPointerException success) {} |
1678 |
|
} |
1690 |
|
List<Callable<String>> l = new ArrayList<>(); |
1691 |
|
l.add(new StringTask()); |
1692 |
|
try { |
1693 |
< |
e.invokeAny(l, MEDIUM_DELAY_MS, null); |
1693 |
> |
e.invokeAny(l, randomTimeout(), null); |
1694 |
|
shouldThrow(); |
1695 |
|
} catch (NullPointerException success) {} |
1696 |
|
} |
1697 |
|
} |
1698 |
|
|
1699 |
|
/** |
1700 |
< |
* timed invokeAny(empty collection) throws IAE |
1700 |
> |
* timed invokeAny(empty collection) throws IllegalArgumentException |
1701 |
|
*/ |
1702 |
|
public void testTimedInvokeAny2() throws Exception { |
1703 |
|
final ExecutorService e = |
1707 |
|
try (PoolCleaner cleaner = cleaner(e)) { |
1708 |
|
try { |
1709 |
|
e.invokeAny(new ArrayList<Callable<String>>(), |
1710 |
< |
MEDIUM_DELAY_MS, MILLISECONDS); |
1710 |
> |
randomTimeout(), randomTimeUnit()); |
1711 |
|
shouldThrow(); |
1712 |
|
} catch (IllegalArgumentException success) {} |
1713 |
|
} |
1714 |
|
} |
1715 |
|
|
1716 |
|
/** |
1717 |
< |
* timed invokeAny(c) throws NPE if c has null elements |
1717 |
> |
* timed invokeAny(c) throws NullPointerException if c has null elements |
1718 |
|
*/ |
1719 |
|
public void testTimedInvokeAny3() throws Exception { |
1720 |
|
final CountDownLatch latch = new CountDownLatch(1); |
1727 |
|
l.add(latchAwaitingStringTask(latch)); |
1728 |
|
l.add(null); |
1729 |
|
try { |
1730 |
< |
e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); |
1730 |
> |
e.invokeAny(l, randomTimeout(), randomTimeUnit()); |
1731 |
|
shouldThrow(); |
1732 |
|
} catch (NullPointerException success) {} |
1733 |
|
latch.countDown(); |
1785 |
|
new ArrayBlockingQueue<Runnable>(10)); |
1786 |
|
try (PoolCleaner cleaner = cleaner(e)) { |
1787 |
|
try { |
1788 |
< |
e.invokeAll(null, MEDIUM_DELAY_MS, MILLISECONDS); |
1788 |
> |
e.invokeAll(null, randomTimeout(), randomTimeUnit()); |
1789 |
|
shouldThrow(); |
1790 |
|
} catch (NullPointerException success) {} |
1791 |
|
} |
1803 |
|
List<Callable<String>> l = new ArrayList<>(); |
1804 |
|
l.add(new StringTask()); |
1805 |
|
try { |
1806 |
< |
e.invokeAll(l, MEDIUM_DELAY_MS, null); |
1806 |
> |
e.invokeAll(l, randomTimeout(), null); |
1807 |
|
shouldThrow(); |
1808 |
|
} catch (NullPointerException success) {} |
1809 |
|
} |
1810 |
|
} |
1811 |
|
|
1812 |
|
/** |
1813 |
< |
* timed invokeAll(empty collection) returns empty collection |
1813 |
> |
* timed invokeAll(empty collection) returns empty list |
1814 |
|
*/ |
1815 |
|
public void testTimedInvokeAll2() throws InterruptedException { |
1816 |
|
final ExecutorService e = |
1817 |
|
new ThreadPoolExecutor(2, 2, |
1818 |
|
LONG_DELAY_MS, MILLISECONDS, |
1819 |
|
new ArrayBlockingQueue<Runnable>(10)); |
1820 |
+ |
final Collection<Callable<String>> emptyCollection |
1821 |
+ |
= Collections.emptyList(); |
1822 |
|
try (PoolCleaner cleaner = cleaner(e)) { |
1823 |
< |
List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>(), |
1824 |
< |
MEDIUM_DELAY_MS, MILLISECONDS); |
1823 |
> |
List<Future<String>> r = |
1824 |
> |
e.invokeAll(emptyCollection, randomTimeout(), randomTimeUnit()); |
1825 |
|
assertTrue(r.isEmpty()); |
1826 |
|
} |
1827 |
|
} |
1839 |
|
l.add(new StringTask()); |
1840 |
|
l.add(null); |
1841 |
|
try { |
1842 |
< |
e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); |
1842 |
> |
e.invokeAll(l, randomTimeout(), randomTimeUnit()); |
1843 |
|
shouldThrow(); |
1844 |
|
} catch (NullPointerException success) {} |
1845 |
|
} |
2081 |
|
} |
2082 |
|
} |
2083 |
|
|
2084 |
+ |
public void testAbortPolicy() { |
2085 |
+ |
final RejectedExecutionHandler handler = |
2086 |
+ |
new ThreadPoolExecutor.AbortPolicy(); |
2087 |
+ |
final ThreadPoolExecutor p = |
2088 |
+ |
new ThreadPoolExecutor(1, 1, |
2089 |
+ |
LONG_DELAY_MS, MILLISECONDS, |
2090 |
+ |
new ArrayBlockingQueue<Runnable>(10)); |
2091 |
+ |
final TrackedNoOpRunnable r = new TrackedNoOpRunnable(); |
2092 |
+ |
try { |
2093 |
+ |
handler.rejectedExecution(r, p); |
2094 |
+ |
shouldThrow(); |
2095 |
+ |
} catch (RejectedExecutionException success) {} |
2096 |
+ |
assertFalse(r.done); |
2097 |
+ |
assertEquals(0, p.getTaskCount()); |
2098 |
+ |
assertTrue(p.getQueue().isEmpty()); |
2099 |
+ |
} |
2100 |
+ |
|
2101 |
|
} |