1765 |
|
final CompletableFuture<Integer> h5 = m.applyToEither(g, f, rs[5]); |
1766 |
|
try { |
1767 |
|
assertEquals(inc(v1), h4.join()); |
1768 |
< |
rs[4].assertInvoked(); |
1768 |
> |
rs[4].assertValue(inc(v1)); |
1769 |
|
} catch (CompletionException ok) { |
1770 |
|
checkCompletedWithWrappedCFException(h4, ex); |
1771 |
|
rs[4].assertNotInvoked(); |
1772 |
|
} |
1773 |
|
try { |
1774 |
|
assertEquals(inc(v1), h5.join()); |
1775 |
< |
rs[5].assertInvoked(); |
1775 |
> |
rs[5].assertValue(inc(v1)); |
1776 |
|
} catch (CompletionException ok) { |
1777 |
|
checkCompletedWithWrappedCFException(h5, ex); |
1778 |
|
rs[5].assertNotInvoked(); |
1788 |
|
for (int i = 0; i < 4; i++) rs[i].assertNotInvoked(); |
1789 |
|
}} |
1790 |
|
|
1791 |
+ |
public void testApplyToEither_exceptionalCompletion2() { |
1792 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
1793 |
+ |
for (boolean fFirst : new boolean[] { true, false }) |
1794 |
+ |
for (Integer v1 : new Integer[] { 1, null }) |
1795 |
+ |
{ |
1796 |
+ |
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
1797 |
+ |
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
1798 |
+ |
final CFException ex = new CFException(); |
1799 |
+ |
final IncFunction[] rs = new IncFunction[6]; |
1800 |
+ |
for (int i = 0; i < rs.length; i++) rs[i] = new IncFunction(m); |
1801 |
+ |
|
1802 |
+ |
final CompletableFuture<Integer> h0 = m.applyToEither(f, g, rs[0]); |
1803 |
+ |
final CompletableFuture<Integer> h1 = m.applyToEither(g, f, rs[1]); |
1804 |
+ |
if (fFirst) { |
1805 |
+ |
f.complete(v1); |
1806 |
+ |
g.completeExceptionally(ex); |
1807 |
+ |
} else { |
1808 |
+ |
g.completeExceptionally(ex); |
1809 |
+ |
f.complete(v1); |
1810 |
+ |
} |
1811 |
+ |
final CompletableFuture<Integer> h2 = m.applyToEither(f, g, rs[2]); |
1812 |
+ |
final CompletableFuture<Integer> h3 = m.applyToEither(g, f, rs[3]); |
1813 |
+ |
|
1814 |
+ |
// unspecified behavior - both source completions available |
1815 |
+ |
try { |
1816 |
+ |
assertEquals(inc(v1), h0.join()); |
1817 |
+ |
rs[0].assertValue(inc(v1)); |
1818 |
+ |
} catch (CompletionException ok) { |
1819 |
+ |
checkCompletedWithWrappedCFException(h0, ex); |
1820 |
+ |
rs[0].assertNotInvoked(); |
1821 |
+ |
} |
1822 |
+ |
try { |
1823 |
+ |
assertEquals(inc(v1), h1.join()); |
1824 |
+ |
rs[1].assertValue(inc(v1)); |
1825 |
+ |
} catch (CompletionException ok) { |
1826 |
+ |
checkCompletedWithWrappedCFException(h1, ex); |
1827 |
+ |
rs[1].assertNotInvoked(); |
1828 |
+ |
} |
1829 |
+ |
try { |
1830 |
+ |
assertEquals(inc(v1), h2.join()); |
1831 |
+ |
rs[2].assertValue(inc(v1)); |
1832 |
+ |
} catch (CompletionException ok) { |
1833 |
+ |
checkCompletedWithWrappedCFException(h2, ex); |
1834 |
+ |
rs[2].assertNotInvoked(); |
1835 |
+ |
} |
1836 |
+ |
try { |
1837 |
+ |
assertEquals(inc(v1), h3.join()); |
1838 |
+ |
rs[3].assertValue(inc(v1)); |
1839 |
+ |
} catch (CompletionException ok) { |
1840 |
+ |
checkCompletedWithWrappedCFException(h3, ex); |
1841 |
+ |
rs[3].assertNotInvoked(); |
1842 |
+ |
} |
1843 |
+ |
|
1844 |
+ |
checkCompletedNormally(f, v1); |
1845 |
+ |
checkCompletedWithWrappedCFException(g, ex); |
1846 |
+ |
}} |
1847 |
+ |
|
1848 |
|
/** |
1849 |
|
* applyToEither result completes exceptionally if either source cancelled |
1850 |
|
*/ |
1878 |
|
final CompletableFuture<Integer> h5 = m.applyToEither(g, f, rs[5]); |
1879 |
|
try { |
1880 |
|
assertEquals(inc(v1), h4.join()); |
1881 |
< |
rs[4].assertInvoked(); |
1881 |
> |
rs[4].assertValue(inc(v1)); |
1882 |
|
} catch (CompletionException ok) { |
1883 |
|
checkCompletedWithWrappedCancellationException(h4); |
1884 |
|
rs[4].assertNotInvoked(); |
1885 |
|
} |
1886 |
|
try { |
1887 |
|
assertEquals(inc(v1), h5.join()); |
1888 |
< |
rs[5].assertInvoked(); |
1888 |
> |
rs[5].assertValue(inc(v1)); |
1889 |
|
} catch (CompletionException ok) { |
1890 |
|
checkCompletedWithWrappedCancellationException(h5); |
1891 |
|
rs[5].assertNotInvoked(); |