--- jsr166/src/test/tck/CompletableFutureTest.java 2014/06/06 17:41:02 1.65 +++ jsr166/src/test/tck/CompletableFutureTest.java 2014/06/06 19:19:04 1.66 @@ -1765,14 +1765,14 @@ public class CompletableFutureTest exten final CompletableFuture h5 = m.applyToEither(g, f, rs[5]); try { assertEquals(inc(v1), h4.join()); - rs[4].assertInvoked(); + rs[4].assertValue(inc(v1)); } catch (CompletionException ok) { checkCompletedWithWrappedCFException(h4, ex); rs[4].assertNotInvoked(); } try { assertEquals(inc(v1), h5.join()); - rs[5].assertInvoked(); + rs[5].assertValue(inc(v1)); } catch (CompletionException ok) { checkCompletedWithWrappedCFException(h5, ex); rs[5].assertNotInvoked(); @@ -1788,6 +1788,63 @@ public class CompletableFutureTest exten for (int i = 0; i < 4; i++) rs[i].assertNotInvoked(); }} + public void testApplyToEither_exceptionalCompletion2() { + for (ExecutionMode m : ExecutionMode.values()) + for (boolean fFirst : new boolean[] { true, false }) + for (Integer v1 : new Integer[] { 1, null }) + { + final CompletableFuture f = new CompletableFuture<>(); + final CompletableFuture g = new CompletableFuture<>(); + final CFException ex = new CFException(); + final IncFunction[] rs = new IncFunction[6]; + for (int i = 0; i < rs.length; i++) rs[i] = new IncFunction(m); + + final CompletableFuture h0 = m.applyToEither(f, g, rs[0]); + final CompletableFuture h1 = m.applyToEither(g, f, rs[1]); + if (fFirst) { + f.complete(v1); + g.completeExceptionally(ex); + } else { + g.completeExceptionally(ex); + f.complete(v1); + } + final CompletableFuture h2 = m.applyToEither(f, g, rs[2]); + final CompletableFuture h3 = m.applyToEither(g, f, rs[3]); + + // unspecified behavior - both source completions available + try { + assertEquals(inc(v1), h0.join()); + rs[0].assertValue(inc(v1)); + } catch (CompletionException ok) { + checkCompletedWithWrappedCFException(h0, ex); + rs[0].assertNotInvoked(); + } + try { + assertEquals(inc(v1), h1.join()); + rs[1].assertValue(inc(v1)); + } catch (CompletionException ok) { + checkCompletedWithWrappedCFException(h1, ex); + rs[1].assertNotInvoked(); + } + try { + assertEquals(inc(v1), h2.join()); + rs[2].assertValue(inc(v1)); + } catch (CompletionException ok) { + checkCompletedWithWrappedCFException(h2, ex); + rs[2].assertNotInvoked(); + } + try { + assertEquals(inc(v1), h3.join()); + rs[3].assertValue(inc(v1)); + } catch (CompletionException ok) { + checkCompletedWithWrappedCFException(h3, ex); + rs[3].assertNotInvoked(); + } + + checkCompletedNormally(f, v1); + checkCompletedWithWrappedCFException(g, ex); + }} + /** * applyToEither result completes exceptionally if either source cancelled */ @@ -1821,14 +1878,14 @@ public class CompletableFutureTest exten final CompletableFuture h5 = m.applyToEither(g, f, rs[5]); try { assertEquals(inc(v1), h4.join()); - rs[4].assertInvoked(); + rs[4].assertValue(inc(v1)); } catch (CompletionException ok) { checkCompletedWithWrappedCancellationException(h4); rs[4].assertNotInvoked(); } try { assertEquals(inc(v1), h5.join()); - rs[5].assertInvoked(); + rs[5].assertValue(inc(v1)); } catch (CompletionException ok) { checkCompletedWithWrappedCancellationException(h5); rs[5].assertNotInvoked();