--- jsr166/src/test/tck/CompletableFutureTest.java 2014/06/01 22:22:49 1.35 +++ jsr166/src/test/tck/CompletableFutureTest.java 2014/06/01 23:51:44 1.38 @@ -318,28 +318,62 @@ public class CompletableFutureTest exten // Choose non-commutative actions for better coverage + // A non-commutative function that handles and produces null values as well. + static Integer subtract(Integer x, Integer y) { + return (x == null && y == null) ? null : + ((x == null) ? 42 : x.intValue()) + - ((y == null) ? 99 : y.intValue()); + } + + // A function that handles and produces null values as well. + static Integer inc(Integer x) { + return (x == null) ? null : x + 1; + } + static final Supplier supplyOne = () -> Integer.valueOf(1); static final Function inc = (Integer x) -> Integer.valueOf(x.intValue() + 1); static final BiFunction subtract = - (Integer x, Integer y) -> Integer.valueOf(x.intValue() - y.intValue()); + (Integer x, Integer y) -> subtract(x, y); static final class IncAction implements Consumer { - int value; - public void accept(Integer x) { value = x.intValue() + 1; } + int invocationCount = 0; + Integer value; + public boolean ran() { return invocationCount == 1; } + public void accept(Integer x) { + invocationCount++; + value = inc(x); + } } - static final class SubtractAction implements BiConsumer { - // Handle null values as well - public int subtract(Integer x, Integer y) { - return ((x == null) ? 42 : x.intValue()) - - ((y == null) ? 99 : y.intValue()); + static final class IncFunction implements Function { + int invocationCount = 0; + Integer value; + public boolean ran() { return invocationCount == 1; } + public Integer apply(Integer x) { + invocationCount++; + return value = inc(x); } - int value; - public boolean ran() { return value != 0; } + } + static final class SubtractAction implements BiConsumer { + int invocationCount = 0; + Integer value; + // Check this action was invoked exactly once when result is computed. + public boolean ran() { return invocationCount == 1; } public void accept(Integer x, Integer y) { + invocationCount++; value = subtract(x, y); } } + static final class SubtractFunction implements BiFunction { + int invocationCount = 0; + Integer value; + // Check this action was invoked exactly once when result is computed. + public boolean ran() { return invocationCount == 1; } + public Integer apply(Integer x, Integer y) { + invocationCount++; + return value = subtract(x, y); + } + } static final class Noop implements Runnable { boolean ran; public void run() { ran = true; } @@ -427,6 +461,40 @@ public class CompletableFutureTest exten BiConsumer a) { return f.thenAcceptBoth(g, a); } + public CompletableFuture thenCombine + (CompletableFuture f, + CompletionStage g, + BiFunction a) { + return f.thenCombine(g, a); + } + public CompletableFuture applyToEither + (CompletableFuture f, + CompletionStage g, + Function a) { + return f.applyToEither(g, a); + } + public CompletableFuture acceptEither + (CompletableFuture f, + CompletionStage g, + Consumer a) { + return f.acceptEither(g, a); + } + public CompletableFuture runAfterEither + (CompletableFuture f, + CompletionStage g, + java.lang.Runnable a) { + return f.runAfterEither(g, a); + } + public CompletableFuture thenCompose + (CompletableFuture f, + Function> a) { + return f.thenCompose(a); + } + public CompletableFuture whenComplete + (CompletableFuture f, + BiConsumer a) { + return f.whenComplete(a); + } }, // /** Experimental way to do more testing */ @@ -454,6 +522,40 @@ public class CompletableFutureTest exten BiConsumer a) { return f.thenAcceptBothAsync(g, a); } + public CompletableFuture thenCombine + (CompletableFuture f, + CompletionStage g, + BiFunction a) { + return f.thenCombineAsync(g, a); + } + public CompletableFuture applyToEither + (CompletableFuture f, + CompletionStage g, + Function a) { + return f.applyToEitherAsync(g, a); + } + public CompletableFuture acceptEither + (CompletableFuture f, + CompletionStage g, + Consumer a) { + return f.acceptEitherAsync(g, a); + } + public CompletableFuture runAfterEither + (CompletableFuture f, + CompletionStage g, + java.lang.Runnable a) { + return f.runAfterEitherAsync(g, a); + } + public CompletableFuture thenCompose + (CompletableFuture f, + Function> a) { + return f.thenComposeAsync(a); + } + public CompletableFuture whenComplete + (CompletableFuture f, + BiConsumer a) { + return f.whenCompleteAsync(a); + } }, // REVERSE_DEFAULT_ASYNC { @@ -480,6 +582,40 @@ public class CompletableFutureTest exten BiConsumer a) { return f.thenAcceptBothAsync(g, a, new ThreadExecutor()); } + public CompletableFuture thenCombine + (CompletableFuture f, + CompletionStage g, + BiFunction a) { + return f.thenCombineAsync(g, a, new ThreadExecutor()); + } + public CompletableFuture applyToEither + (CompletableFuture f, + CompletionStage g, + Function a) { + return f.applyToEitherAsync(g, a, new ThreadExecutor()); + } + public CompletableFuture acceptEither + (CompletableFuture f, + CompletionStage g, + Consumer a) { + return f.acceptEitherAsync(g, a, new ThreadExecutor()); + } + public CompletableFuture runAfterEither + (CompletableFuture f, + CompletionStage g, + java.lang.Runnable a) { + return f.runAfterEitherAsync(g, a, new ThreadExecutor()); + } + public CompletableFuture thenCompose + (CompletableFuture f, + Function> a) { + return f.thenComposeAsync(a, new ThreadExecutor()); + } + public CompletableFuture whenComplete + (CompletableFuture f, + BiConsumer a) { + return f.whenCompleteAsync(a, new ThreadExecutor()); + } }; public abstract CompletableFuture runAfterBoth @@ -488,6 +624,30 @@ public class CompletableFutureTest exten (CompletableFuture f, CompletionStage g, BiConsumer a); + public abstract CompletableFuture thenCombine + (CompletableFuture f, + CompletionStage g, + BiFunction a); + public abstract CompletableFuture applyToEither + (CompletableFuture f, + CompletionStage g, + Function a); + public abstract CompletableFuture acceptEither + (CompletableFuture f, + CompletionStage g, + Consumer a); + public abstract CompletableFuture runAfterEither + (CompletableFuture f, + CompletionStage g, + java.lang.Runnable a); + public abstract CompletableFuture thenCompose + (CompletableFuture f, + Function> a); + public abstract CompletableFuture whenComplete + (CompletableFuture f, + BiConsumer a); + + } /** @@ -740,7 +900,7 @@ public class CompletableFutureTest exten CompletableFuture g = f.thenAccept(r); f.complete(one); checkCompletedNormally(g, null); - assertEquals(r.value, 2); + assertEquals(r.value, (Integer) 2); } /** @@ -782,115 +942,298 @@ public class CompletableFutureTest exten * thenCombine result completes normally after normal completion * of sources */ - public void testThenCombine() { - CompletableFuture f, g, h; + public void testThenCombine_normalCompletion1() { + for (ExecutionMode m : ExecutionMode.values()) + for (Integer v1 : new Integer[] { 1, null }) + for (Integer v2 : new Integer[] { 2, null }) { - f = new CompletableFuture<>(); - g = new CompletableFuture<>(); - h = f.thenCombine(g, subtract); - f.complete(3); + final CompletableFuture f = new CompletableFuture<>(); + final CompletableFuture g = new CompletableFuture<>(); + final SubtractFunction r = new SubtractFunction(); + final CompletableFuture h = m.thenCombine(f, g, r); + + f.complete(v1); checkIncomplete(h); - g.complete(1); - checkCompletedNormally(h, 2); + assertFalse(r.ran()); + g.complete(v2); - f = new CompletableFuture<>(); - g = new CompletableFuture<>(); - h = f.thenCombine(g, subtract); - g.complete(1); + checkCompletedNormally(h, subtract(v1, v2)); + checkCompletedNormally(f, v1); + checkCompletedNormally(g, v2); + } + } + + public void testThenCombine_normalCompletion2() { + for (ExecutionMode m : ExecutionMode.values()) + for (Integer v1 : new Integer[] { 1, null }) + for (Integer v2 : new Integer[] { 2, null }) { + + final CompletableFuture f = new CompletableFuture<>(); + final CompletableFuture g = new CompletableFuture<>(); + final SubtractFunction r = new SubtractFunction(); + final CompletableFuture h = m.thenCombine(f, g, r); + + g.complete(v2); checkIncomplete(h); - f.complete(3); - checkCompletedNormally(h, 2); + assertFalse(r.ran()); + f.complete(v1); - f = new CompletableFuture<>(); - g = new CompletableFuture<>(); - g.complete(1); - f.complete(3); - h = f.thenCombine(g, subtract); - checkCompletedNormally(h, 2); + checkCompletedNormally(h, subtract(v1, v2)); + checkCompletedNormally(f, v1); + checkCompletedNormally(g, v2); + } + } + + public void testThenCombine_normalCompletion3() { + for (ExecutionMode m : ExecutionMode.values()) + for (Integer v1 : new Integer[] { 1, null }) + for (Integer v2 : new Integer[] { 2, null }) { + + final CompletableFuture f = new CompletableFuture<>(); + final CompletableFuture g = new CompletableFuture<>(); + final SubtractFunction r = new SubtractFunction(); + + g.complete(v2); + f.complete(v1); + final CompletableFuture h = m.thenCombine(f, g, r); + + checkCompletedNormally(h, subtract(v1, v2)); + checkCompletedNormally(f, v1); + checkCompletedNormally(g, v2); + } + } + + public void testThenCombine_normalCompletion4() { + for (ExecutionMode m : ExecutionMode.values()) + for (Integer v1 : new Integer[] { 1, null }) + for (Integer v2 : new Integer[] { 2, null }) { + + final CompletableFuture f = new CompletableFuture<>(); + final CompletableFuture g = new CompletableFuture<>(); + final SubtractFunction r = new SubtractFunction(); + + f.complete(v1); + g.complete(v2); + final CompletableFuture h = m.thenCombine(f, g, r); + + checkCompletedNormally(h, subtract(v1, v2)); + checkCompletedNormally(f, v1); + checkCompletedNormally(g, v2); + } } /** * thenCombine result completes exceptionally after exceptional * completion of either source */ - public void testThenCombine2() { - CompletableFuture f, g, h; + public void testThenCombine_exceptionalCompletion1() { + for (ExecutionMode m : ExecutionMode.values()) + for (Integer v1 : new Integer[] { 1, null }) { - f = new CompletableFuture<>(); - g = new CompletableFuture<>(); - h = f.thenCombine(g, subtract); - f.completeExceptionally(new CFException()); + final CompletableFuture f = new CompletableFuture<>(); + final CompletableFuture g = new CompletableFuture<>(); + final SubtractFunction r = new SubtractFunction(); + final CompletableFuture h = m.thenCombine(f, g, r); + final CFException ex = new CFException(); + + f.completeExceptionally(ex); checkIncomplete(h); - g.complete(1); - checkCompletedWithWrappedCFException(h); + g.complete(v1); - f = new CompletableFuture<>(); - g = new CompletableFuture<>(); - h = f.thenCombine(g, subtract); - g.completeExceptionally(new CFException()); + checkCompletedWithWrappedCFException(h, ex); + checkCompletedWithWrappedCFException(f, ex); + assertFalse(r.ran()); + checkCompletedNormally(g, v1); + } + } + + public void testThenCombine_exceptionalCompletion2() { + for (ExecutionMode m : ExecutionMode.values()) + for (Integer v1 : new Integer[] { 1, null }) { + + final CompletableFuture f = new CompletableFuture<>(); + final CompletableFuture g = new CompletableFuture<>(); + final SubtractFunction r = new SubtractFunction(); + final CompletableFuture h = m.thenCombine(f, g, r); + final CFException ex = new CFException(); + + g.completeExceptionally(ex); checkIncomplete(h); - f.complete(3); - checkCompletedWithWrappedCFException(h); + f.complete(v1); - f = new CompletableFuture<>(); - g = new CompletableFuture<>(); - f.complete(3); - g.completeExceptionally(new CFException()); - h = f.thenCombine(g, subtract); - checkCompletedWithWrappedCFException(h); + checkCompletedWithWrappedCFException(h, ex); + checkCompletedWithWrappedCFException(g, ex); + assertFalse(r.ran()); + checkCompletedNormally(f, v1); + } + } - f = new CompletableFuture<>(); - g = new CompletableFuture<>(); - f.completeExceptionally(new CFException()); - g.complete(3); - h = f.thenCombine(g, subtract); - checkCompletedWithWrappedCFException(h); + public void testThenCombine_exceptionalCompletion3() { + for (ExecutionMode m : ExecutionMode.values()) + for (Integer v1 : new Integer[] { 1, null }) { + + final CompletableFuture f = new CompletableFuture<>(); + final CompletableFuture g = new CompletableFuture<>(); + final SubtractFunction r = new SubtractFunction(); + final CFException ex = new CFException(); + + g.completeExceptionally(ex); + f.complete(v1); + final CompletableFuture h = m.thenCombine(f, g, r); + + checkCompletedWithWrappedCFException(h, ex); + checkCompletedWithWrappedCFException(g, ex); + assertFalse(r.ran()); + checkCompletedNormally(f, v1); + } + } + + public void testThenCombine_exceptionalCompletion4() { + for (ExecutionMode m : ExecutionMode.values()) + for (Integer v1 : new Integer[] { 1, null }) { + + final CompletableFuture f = new CompletableFuture<>(); + final CompletableFuture g = new CompletableFuture<>(); + final SubtractFunction r = new SubtractFunction(); + final CFException ex = new CFException(); + + f.completeExceptionally(ex); + g.complete(v1); + final CompletableFuture h = m.thenCombine(f, g, r); + + checkCompletedWithWrappedCFException(h, ex); + checkCompletedWithWrappedCFException(f, ex); + assertFalse(r.ran()); + checkCompletedNormally(g, v1); + } } /** * thenCombine result completes exceptionally if action does */ - public void testThenCombine3() { - CompletableFuture f = new CompletableFuture<>(); - CompletableFuture f2 = new CompletableFuture<>(); - FailingBiFunction r = new FailingBiFunction(); - CompletableFuture g = f.thenCombine(f2, r); - f.complete(one); - checkIncomplete(g); - assertFalse(r.ran); - f2.complete(two); - checkCompletedWithWrappedCFException(g); - assertTrue(r.ran); + public void testThenCombine_actionFailed1() { + for (ExecutionMode m : ExecutionMode.values()) + for (Integer v1 : new Integer[] { 1, null }) + for (Integer v2 : new Integer[] { 2, null }) { + + final CompletableFuture f = new CompletableFuture<>(); + final CompletableFuture g = new CompletableFuture<>(); + final FailingBiFunction r = new FailingBiFunction(); + final CompletableFuture h = m.thenCombine(f, g, r); + + f.complete(v1); + checkIncomplete(h); + g.complete(v2); + + checkCompletedWithWrappedCFException(h); + checkCompletedNormally(f, v1); + checkCompletedNormally(g, v2); + } + } + + public void testThenCombine_actionFailed2() { + for (ExecutionMode m : ExecutionMode.values()) + for (Integer v1 : new Integer[] { 1, null }) + for (Integer v2 : new Integer[] { 2, null }) { + + final CompletableFuture f = new CompletableFuture<>(); + final CompletableFuture g = new CompletableFuture<>(); + final FailingBiFunction r = new FailingBiFunction(); + final CompletableFuture h = m.thenCombine(f, g, r); + + g.complete(v2); + checkIncomplete(h); + f.complete(v1); + + checkCompletedWithWrappedCFException(h); + checkCompletedNormally(f, v1); + checkCompletedNormally(g, v2); + } } /** * thenCombine result completes exceptionally if either source cancelled */ - public void testThenCombine4() { - CompletableFuture f, g, h; + public void testThenCombine_sourceCancelled1() { + for (ExecutionMode m : ExecutionMode.values()) + for (boolean mayInterruptIfRunning : new boolean[] { true, false }) + for (Integer v1 : new Integer[] { 1, null }) { - f = new CompletableFuture<>(); - g = new CompletableFuture<>(); - h = f.thenCombine(g, subtract); - assertTrue(f.cancel(true)); + final CompletableFuture f = new CompletableFuture<>(); + final CompletableFuture g = new CompletableFuture<>(); + final SubtractFunction r = new SubtractFunction(); + final CompletableFuture h = m.thenCombine(f, g, r); + + assertTrue(f.cancel(mayInterruptIfRunning)); checkIncomplete(h); - g.complete(1); + g.complete(v1); + checkCompletedWithWrappedCancellationException(h); + checkCancelled(f); + assertFalse(r.ran()); + checkCompletedNormally(g, v1); + } + } - f = new CompletableFuture<>(); - g = new CompletableFuture<>(); - h = f.thenCombine(g, subtract); - assertTrue(g.cancel(true)); + public void testThenCombine_sourceCancelled2() { + for (ExecutionMode m : ExecutionMode.values()) + for (boolean mayInterruptIfRunning : new boolean[] { true, false }) + for (Integer v1 : new Integer[] { 1, null }) { + + final CompletableFuture f = new CompletableFuture<>(); + final CompletableFuture g = new CompletableFuture<>(); + final SubtractFunction r = new SubtractFunction(); + final CompletableFuture h = m.thenCombine(f, g, r); + + assertTrue(g.cancel(mayInterruptIfRunning)); checkIncomplete(h); - f.complete(3); + f.complete(v1); + checkCompletedWithWrappedCancellationException(h); + checkCancelled(g); + assertFalse(r.ran()); + checkCompletedNormally(f, v1); + } + } + + public void testThenCombine_sourceCancelled3() { + for (ExecutionMode m : ExecutionMode.values()) + for (boolean mayInterruptIfRunning : new boolean[] { true, false }) + for (Integer v1 : new Integer[] { 1, null }) { + + final CompletableFuture f = new CompletableFuture<>(); + final CompletableFuture g = new CompletableFuture<>(); + final SubtractFunction r = new SubtractFunction(); + + assertTrue(g.cancel(mayInterruptIfRunning)); + f.complete(v1); + final CompletableFuture h = m.thenCombine(f, g, r); - f = new CompletableFuture<>(); - g = new CompletableFuture<>(); - assertTrue(f.cancel(true)); - assertTrue(g.cancel(true)); - h = f.thenCombine(g, subtract); checkCompletedWithWrappedCancellationException(h); + checkCancelled(g); + assertFalse(r.ran()); + checkCompletedNormally(f, v1); + } + } + + public void testThenCombine_sourceCancelled4() { + for (ExecutionMode m : ExecutionMode.values()) + for (boolean mayInterruptIfRunning : new boolean[] { true, false }) + for (Integer v1 : new Integer[] { 1, null }) { + + final CompletableFuture f = new CompletableFuture<>(); + final CompletableFuture g = new CompletableFuture<>(); + final SubtractFunction r = new SubtractFunction(); + + assertTrue(f.cancel(mayInterruptIfRunning)); + g.complete(v1); + final CompletableFuture h = m.thenCombine(f, g, r); + + checkCompletedWithWrappedCancellationException(h); + checkCancelled(f); + assertFalse(r.ran()); + checkCompletedNormally(g, v1); + } } /** @@ -909,11 +1252,11 @@ public class CompletableFutureTest exten f.complete(v1); checkIncomplete(h); - assertEquals(r.value, 0); + assertFalse(r.ran()); g.complete(v2); checkCompletedNormally(h, null); - assertEquals(r.value, r.subtract(v1, v2)); + assertEquals(r.value, subtract(v1, v2)); checkCompletedNormally(f, v1); checkCompletedNormally(g, v2); } @@ -931,11 +1274,11 @@ public class CompletableFutureTest exten g.complete(v2); checkIncomplete(h); - assertEquals(r.value, 0); + assertFalse(r.ran()); f.complete(v1); checkCompletedNormally(h, null); - assertEquals(r.value, r.subtract(v1, v2)); + assertEquals(r.value, subtract(v1, v2)); checkCompletedNormally(f, v1); checkCompletedNormally(g, v2); } @@ -955,7 +1298,7 @@ public class CompletableFutureTest exten final CompletableFuture h = m.thenAcceptBoth(f, g, r); checkCompletedNormally(h, null); - assertEquals(r.value, r.subtract(v1, v2)); + assertEquals(r.value, subtract(v1, v2)); checkCompletedNormally(f, v1); checkCompletedNormally(g, v2); } @@ -975,7 +1318,7 @@ public class CompletableFutureTest exten final CompletableFuture h = m.thenAcceptBoth(f, g, r); checkCompletedNormally(h, null); - assertEquals(r.value, r.subtract(v1, v2)); + assertEquals(r.value, subtract(v1, v2)); checkCompletedNormally(f, v1); checkCompletedNormally(g, v2); } @@ -1576,7 +1919,7 @@ public class CompletableFutureTest exten checkCompletedNormally(g, null); f2.complete(one); checkCompletedNormally(g, null); - assertEquals(r.value, 2); + assertEquals(r.value, (Integer) 2); r = new IncAction(); f = new CompletableFuture<>(); @@ -1584,7 +1927,7 @@ public class CompletableFutureTest exten f2 = new CompletableFuture<>(); g = f.acceptEither(f2, r); checkCompletedNormally(g, null); - assertEquals(r.value, 2); + assertEquals(r.value, (Integer) 2); } /** @@ -1894,7 +2237,7 @@ public class CompletableFutureTest exten CompletableFuture g = f.thenAcceptAsync(r); f.complete(one); checkCompletedNormally(g, null); - assertEquals(r.value, 2); + assertEquals(r.value, (Integer) 2); } /** @@ -1932,121 +2275,6 @@ public class CompletableFutureTest exten } /** - * thenCombineAsync result completes normally after normal - * completion of sources - */ - public void testThenCombineAsync() { - CompletableFuture f, g, h; - - f = new CompletableFuture<>(); - g = new CompletableFuture<>(); - h = f.thenCombineAsync(g, subtract); - f.complete(3); - checkIncomplete(h); - g.complete(1); - checkCompletedNormally(h, 2); - - f = new CompletableFuture<>(); - g = new CompletableFuture<>(); - h = f.thenCombineAsync(g, subtract); - g.complete(1); - checkIncomplete(h); - f.complete(3); - checkCompletedNormally(h, 2); - - f = new CompletableFuture<>(); - g = new CompletableFuture<>(); - g.complete(1); - f.complete(3); - h = f.thenCombineAsync(g, subtract); - checkCompletedNormally(h, 2); - } - - /** - * thenCombineAsync result completes exceptionally after exceptional - * completion of either source - */ - public void testThenCombineAsync2() { - CompletableFuture f, g, h; - - f = new CompletableFuture<>(); - g = new CompletableFuture<>(); - h = f.thenCombineAsync(g, subtract); - f.completeExceptionally(new CFException()); - checkIncomplete(h); - g.complete(1); - checkCompletedWithWrappedCFException(h); - - f = new CompletableFuture<>(); - g = new CompletableFuture<>(); - h = f.thenCombineAsync(g, subtract); - g.completeExceptionally(new CFException()); - checkIncomplete(h); - f.complete(3); - checkCompletedWithWrappedCFException(h); - - f = new CompletableFuture<>(); - g = new CompletableFuture<>(); - g.completeExceptionally(new CFException()); - f.complete(3); - h = f.thenCombineAsync(g, subtract); - checkCompletedWithWrappedCFException(h); - } - - /** - * thenCombineAsync result completes exceptionally if action does - */ - public void testThenCombineAsync3() { - CompletableFuture f = new CompletableFuture<>(); - CompletableFuture f2 = new CompletableFuture<>(); - FailingBiFunction r = new FailingBiFunction(); - CompletableFuture g = f.thenCombineAsync(f2, r); - f.complete(one); - checkIncomplete(g); - assertFalse(r.ran); - f2.complete(two); - checkCompletedWithWrappedCFException(g); - assertTrue(r.ran); - } - - /** - * thenCombineAsync result completes exceptionally if either source cancelled - */ - public void testThenCombineAsync4() { - CompletableFuture f, g, h; - - f = new CompletableFuture<>(); - g = new CompletableFuture<>(); - h = f.thenCombineAsync(g, subtract); - assertTrue(f.cancel(true)); - checkIncomplete(h); - g.complete(1); - checkCompletedWithWrappedCancellationException(h); - - f = new CompletableFuture<>(); - g = new CompletableFuture<>(); - h = f.thenCombineAsync(g, subtract); - assertTrue(g.cancel(true)); - checkIncomplete(h); - f.complete(3); - checkCompletedWithWrappedCancellationException(h); - - f = new CompletableFuture<>(); - g = new CompletableFuture<>(); - g.complete(3); - assertTrue(f.cancel(true)); - h = f.thenCombineAsync(g, subtract); - checkCompletedWithWrappedCancellationException(h); - - f = new CompletableFuture<>(); - g = new CompletableFuture<>(); - f.complete(3); - assertTrue(g.cancel(true)); - h = f.thenCombineAsync(g, subtract); - checkCompletedWithWrappedCancellationException(h); - } - - /** * applyToEitherAsync result completes normally after normal * completion of sources */ @@ -2123,7 +2351,7 @@ public class CompletableFutureTest exten CompletableFuture g = f.acceptEitherAsync(f2, r); f.complete(one); checkCompletedNormally(g, null); - assertEquals(r.value, 2); + assertEquals(r.value, (Integer) 2); r = new IncAction(); f = new CompletableFuture<>(); @@ -2131,7 +2359,7 @@ public class CompletableFutureTest exten f2 = new CompletableFuture<>(); g = f.acceptEitherAsync(f2, r); checkCompletedNormally(g, null); - assertEquals(r.value, 2); + assertEquals(r.value, (Integer) 2); } /** @@ -2448,7 +2676,7 @@ public class CompletableFutureTest exten CompletableFuture g = f.thenAcceptAsync(r, new ThreadExecutor()); f.complete(one); checkCompletedNormally(g, null); - assertEquals(r.value, 2); + assertEquals(r.value, (Integer) 2); } /** @@ -2486,135 +2714,6 @@ public class CompletableFutureTest exten } /** - * thenCombineAsync result completes normally after normal - * completion of sources - */ - public void testThenCombineAsyncE() { - CompletableFuture f, g, h; - ThreadExecutor e = new ThreadExecutor(); - int count = 0; - - f = new CompletableFuture<>(); - g = new CompletableFuture<>(); - h = f.thenCombineAsync(g, subtract, e); - f.complete(3); - checkIncomplete(h); - g.complete(1); - checkCompletedNormally(h, 2); - assertEquals(++count, e.count.get()); - - f = new CompletableFuture<>(); - g = new CompletableFuture<>(); - h = f.thenCombineAsync(g, subtract, e); - g.complete(1); - checkIncomplete(h); - f.complete(3); - checkCompletedNormally(h, 2); - assertEquals(++count, e.count.get()); - - f = new CompletableFuture<>(); - g = new CompletableFuture<>(); - g.complete(1); - f.complete(3); - h = f.thenCombineAsync(g, subtract, e); - checkCompletedNormally(h, 2); - assertEquals(++count, e.count.get()); - } - - /** - * thenCombineAsync result completes exceptionally after exceptional - * completion of either source - */ - public void testThenCombineAsync2E() { - CompletableFuture f, g, h; - ThreadExecutor e = new ThreadExecutor(); - int count = 0; - - f = new CompletableFuture<>(); - g = new CompletableFuture<>(); - h = f.thenCombineAsync(g, subtract, e); - f.completeExceptionally(new CFException()); - checkIncomplete(h); - g.complete(1); - checkCompletedWithWrappedCFException(h); - - f = new CompletableFuture<>(); - g = new CompletableFuture<>(); - h = f.thenCombineAsync(g, subtract, e); - g.completeExceptionally(new CFException()); - checkIncomplete(h); - f.complete(3); - checkCompletedWithWrappedCFException(h); - - f = new CompletableFuture<>(); - g = new CompletableFuture<>(); - g.completeExceptionally(new CFException()); - h = f.thenCombineAsync(g, subtract, e); - checkIncomplete(h); - f.complete(3); - checkCompletedWithWrappedCFException(h); - - assertEquals(0, e.count.get()); - } - - /** - * thenCombineAsync result completes exceptionally if action does - */ - public void testThenCombineAsync3E() { - CompletableFuture f = new CompletableFuture<>(); - CompletableFuture f2 = new CompletableFuture<>(); - FailingBiFunction r = new FailingBiFunction(); - CompletableFuture g = f.thenCombineAsync(f2, r, new ThreadExecutor()); - f.complete(one); - checkIncomplete(g); - assertFalse(r.ran); - f2.complete(two); - checkCompletedWithWrappedCFException(g); - assertTrue(r.ran); - } - - /** - * thenCombineAsync result completes exceptionally if either source cancelled - */ - public void testThenCombineAsync4E() { - CompletableFuture f, g, h; - ThreadExecutor e = new ThreadExecutor(); - - f = new CompletableFuture<>(); - g = new CompletableFuture<>(); - h = f.thenCombineAsync(g, subtract, e); - assertTrue(f.cancel(true)); - checkIncomplete(h); - g.complete(1); - checkCompletedWithWrappedCancellationException(h); - - f = new CompletableFuture<>(); - g = new CompletableFuture<>(); - h = f.thenCombineAsync(g, subtract, e); - assertTrue(g.cancel(true)); - checkIncomplete(h); - f.complete(3); - checkCompletedWithWrappedCancellationException(h); - - f = new CompletableFuture<>(); - g = new CompletableFuture<>(); - assertTrue(g.cancel(true)); - h = f.thenCombineAsync(g, subtract, e); - checkIncomplete(h); - f.complete(3); - checkCompletedWithWrappedCancellationException(h); - - f = new CompletableFuture<>(); - g = new CompletableFuture<>(); - assertTrue(f.cancel(true)); - assertTrue(g.cancel(true)); - h = f.thenCombineAsync(g, subtract, e); - checkCompletedWithWrappedCancellationException(h); - - assertEquals(0, e.count.get()); - } - - /** * applyToEitherAsync result completes normally after normal * completion of sources */ @@ -2691,7 +2790,7 @@ public class CompletableFutureTest exten CompletableFuture g = f.acceptEitherAsync(f2, r, new ThreadExecutor()); f.complete(one); checkCompletedNormally(g, null); - assertEquals(r.value, 2); + assertEquals(r.value, (Integer) 2); r = new IncAction(); f = new CompletableFuture<>(); @@ -2699,7 +2798,7 @@ public class CompletableFutureTest exten f2 = new CompletableFuture<>(); g = f.acceptEitherAsync(f2, r, new ThreadExecutor()); checkCompletedNormally(g, null); - assertEquals(r.value, 2); + assertEquals(r.value, (Integer) 2); } /**