--- jsr166/src/test/tck/CompletableFutureTest.java 2013/03/21 16:26:43 1.5 +++ jsr166/src/test/tck/CompletableFutureTest.java 2013/03/22 22:27:04 1.8 @@ -75,31 +75,27 @@ public class CompletableFutureTest exten try { f.join(); shouldThrow(); - } catch (Throwable ex) { - assertTrue(ex instanceof CompletionException && - ((CompletionException)ex).getCause() instanceof CFException); + } catch (CompletionException success) { + assertTrue(success.getCause() instanceof CFException); } try { f.getNow(null); shouldThrow(); - } catch (Throwable ex) { - assertTrue(ex instanceof CompletionException && - ((CompletionException)ex).getCause() instanceof CFException); + } catch (CompletionException success) { + assertTrue(success.getCause() instanceof CFException); } try { f.get(); shouldThrow(); - } catch (Throwable ex) { - assertTrue(ex instanceof ExecutionException && - ((ExecutionException)ex).getCause() instanceof CFException); - } + } catch (ExecutionException success) { + assertTrue(success.getCause() instanceof CFException); + } catch (Throwable fail) { threadUnexpectedException(fail); } try { f.get(0L, SECONDS); shouldThrow(); - } catch (Throwable ex) { - assertTrue(ex instanceof ExecutionException && - ((ExecutionException)ex).getCause() instanceof CFException); - } + } catch (ExecutionException success) { + assertTrue(success.getCause() instanceof CFException); + } catch (Throwable fail) { threadUnexpectedException(fail); } assertTrue(f.isDone()); assertFalse(f.isCancelled()); } @@ -108,27 +104,21 @@ public class CompletableFutureTest exten try { f.join(); shouldThrow(); - } catch (Throwable ex) { - assertTrue(ex instanceof CancellationException); - } + } catch (CancellationException success) {} try { f.getNow(null); shouldThrow(); - } catch (Throwable ex) { - assertTrue(ex instanceof CancellationException); - } + } catch (CancellationException success) {} try { f.get(); shouldThrow(); - } catch (Throwable ex) { - assertTrue(ex instanceof CancellationException); - } + } catch (CancellationException success) { + } catch (Throwable fail) { threadUnexpectedException(fail); } try { f.get(0L, SECONDS); shouldThrow(); - } catch (Throwable ex) { - assertTrue(ex instanceof CancellationException); - } + } catch (CancellationException success) { + } catch (Throwable fail) { threadUnexpectedException(fail); } assertTrue(f.isDone()); assertTrue(f.isCancelled()); } @@ -137,31 +127,27 @@ public class CompletableFutureTest exten try { f.join(); shouldThrow(); - } catch (Throwable ex) { - assertTrue(ex instanceof CompletionException && - ((CompletionException)ex).getCause() instanceof CancellationException); + } catch (CompletionException success) { + assertTrue(success.getCause() instanceof CancellationException); } try { f.getNow(null); shouldThrow(); - } catch (Throwable ex) { - assertTrue(ex instanceof CompletionException && - ((CompletionException)ex).getCause() instanceof CancellationException); + } catch (CompletionException success) { + assertTrue(success.getCause() instanceof CancellationException); } try { f.get(); shouldThrow(); - } catch (Throwable ex) { - assertTrue(ex instanceof ExecutionException && - ((ExecutionException)ex).getCause() instanceof CancellationException); - } + } catch (ExecutionException success) { + assertTrue(success.getCause() instanceof CancellationException); + } catch (Throwable fail) { threadUnexpectedException(fail); } try { f.get(0L, SECONDS); shouldThrow(); - } catch (Throwable ex) { - assertTrue(ex instanceof ExecutionException && - ((ExecutionException)ex).getCause() instanceof CancellationException); - } + } catch (ExecutionException success) { + assertTrue(success.getCause() instanceof CancellationException); + } catch (Throwable fail) { threadUnexpectedException(fail); } assertTrue(f.isDone()); assertFalse(f.isCancelled()); } @@ -249,7 +235,7 @@ public class CompletableFutureTest exten f.obtrudeException(new CFException()); checkCompletedWithWrappedCFException(f); } - + /** * getNumberOfDependents returns number of dependent tasks */ @@ -285,11 +271,11 @@ public class CompletableFutureTest exten assertTrue(f.toString().contains("[Completed exceptionally]")); } - static final Supplier supplyOne = + static final Supplier supplyOne = () -> Integer.valueOf(1); - static final Function inc = + static final Function inc = (Integer x) -> Integer.valueOf(x.intValue() + 1); - static final BiFunction add = + static final BiFunction add = (Integer x, Integer y) -> Integer.valueOf(x.intValue() + y.intValue()); static final class IncAction implements Consumer { int value; @@ -297,8 +283,8 @@ public class CompletableFutureTest exten } static final class AddAction implements BiConsumer { int value; - public void accept(Integer x, Integer y) { - value = x.intValue() + y.intValue(); + public void accept(Integer x, Integer y) { + value = x.intValue() + y.intValue(); } } static final class Noop implements Runnable { @@ -345,7 +331,7 @@ public class CompletableFutureTest exten ran = true; throw new CFException(); } } - + // Used for explicit executor tests static final class ThreadExecutor implements Executor { public void execute(Runnable r) { @@ -358,7 +344,7 @@ public class CompletableFutureTest exten } static final class IntegerHandler implements BiFunction { - public Integer apply(Integer x, Throwable t) { + public Integer apply(Integer x, Throwable t) { return (t == null) ? two : three; } } @@ -456,8 +442,8 @@ public class CompletableFutureTest exten assertTrue(r.ran); } - // seq conmpletion methods - + // seq completion methods + /** * thenRun result completes normally after normal completion of source */ @@ -1126,7 +1112,7 @@ public class CompletableFutureTest exten try { g.join(); shouldThrow(); - } catch(Exception ok) { + } catch (Exception ok) { } checkCompletedWithWrappedCFException(g); } @@ -1141,7 +1127,7 @@ public class CompletableFutureTest exten f.complete(null); checkCompletedWithWrappedCFException(g); } - + /** * thenRunAsync result completes exceptionally if source cancelled */ @@ -1184,7 +1170,7 @@ public class CompletableFutureTest exten f.complete(null); checkCompletedWithWrappedCFException(g); } - + /** * thenApplyAsync result completes exceptionally if source cancelled */ @@ -1230,7 +1216,7 @@ public class CompletableFutureTest exten f.complete(null); checkCompletedWithWrappedCFException(g); } - + /** * thenAcceptAsync result completes exceptionally if source cancelled */ @@ -1288,7 +1274,7 @@ public class CompletableFutureTest exten f2.complete(two); checkCompletedWithWrappedCFException(g); } - + /** * thenCombineAsync result completes exceptionally if either source cancelled */ @@ -1299,7 +1285,7 @@ public class CompletableFutureTest exten assertTrue(f.cancel(true)); f2.complete(two); checkCompletedWithWrappedCancellationException(g); - + f = new CompletableFuture(); f2 = new CompletableFuture(); g = f.thenCombineAsync(f2, add); @@ -1353,13 +1339,13 @@ public class CompletableFutureTest exten CompletableFuture f = new CompletableFuture(); CompletableFuture f2 = new CompletableFuture(); FailingBiConsumer r = new FailingBiConsumer(); - CompletableFuture g = f.thenAcceptBothAsync(f2, r); + CompletableFuture g = f.thenAcceptBothAsync(f2, r); f.complete(one); checkIncomplete(g); f2.complete(two); checkCompletedWithWrappedCFException(g); } - + /** * thenAcceptBothAsync result completes exceptionally if either source cancelled */ @@ -1371,7 +1357,7 @@ public class CompletableFutureTest exten assertTrue(f.cancel(true)); f2.complete(two); checkCompletedWithWrappedCancellationException(g); - + r = new AddAction(); f = new CompletableFuture(); f2 = new CompletableFuture(); @@ -1426,13 +1412,13 @@ public class CompletableFutureTest exten CompletableFuture f = new CompletableFuture(); CompletableFuture f2 = new CompletableFuture(); FailingNoop r = new FailingNoop(); - CompletableFuture g = f.runAfterBothAsync(f2, r); + CompletableFuture g = f.runAfterBothAsync(f2, r); f.complete(one); checkIncomplete(g); f2.complete(two); checkCompletedWithWrappedCFException(g); } - + /** * runAfterBothAsync result completes exceptionally if either source cancelled */ @@ -1444,7 +1430,7 @@ public class CompletableFutureTest exten assertTrue(f.cancel(true)); f2.complete(two); checkCompletedWithWrappedCancellationException(g); - + r = new Noop(); f = new CompletableFuture(); f2 = new CompletableFuture(); @@ -1498,11 +1484,11 @@ public class CompletableFutureTest exten CompletableFuture f = new CompletableFuture(); CompletableFuture f2 = new CompletableFuture(); FailingFunction r = new FailingFunction(); - CompletableFuture g = f.applyToEitherAsync(f2, r); + CompletableFuture g = f.applyToEitherAsync(f2, r); f.complete(one); checkCompletedWithWrappedCFException(g); } - + /** * applyToEitherAsync result completes exceptionally if either source cancelled */ @@ -1512,7 +1498,7 @@ public class CompletableFutureTest exten CompletableFuture g = f.applyToEitherAsync(f2, inc); assertTrue(f.cancel(true)); checkCompletedWithWrappedCancellationException(g); - + f = new CompletableFuture(); f2 = new CompletableFuture(); assertTrue(f2.cancel(true)); @@ -1570,11 +1556,11 @@ public class CompletableFutureTest exten CompletableFuture f = new CompletableFuture(); CompletableFuture f2 = new CompletableFuture(); FailingConsumer r = new FailingConsumer(); - CompletableFuture g = f.acceptEitherAsync(f2, r); + CompletableFuture g = f.acceptEitherAsync(f2, r); f.complete(one); checkCompletedWithWrappedCFException(g); } - + /** * acceptEitherAsync result completes exceptionally if either * source cancelled @@ -1586,7 +1572,7 @@ public class CompletableFutureTest exten CompletableFuture g = f.acceptEitherAsync(f2, r); assertTrue(f.cancel(true)); checkCompletedWithWrappedCancellationException(g); - + r = new IncAction(); f = new CompletableFuture(); f2 = new CompletableFuture(); @@ -1645,11 +1631,11 @@ public class CompletableFutureTest exten CompletableFuture f = new CompletableFuture(); CompletableFuture f2 = new CompletableFuture(); FailingNoop r = new FailingNoop(); - CompletableFuture g = f.runAfterEitherAsync(f2, r); + CompletableFuture g = f.runAfterEitherAsync(f2, r); f.complete(one); checkCompletedWithWrappedCFException(g); } - + /** * runAfterEitherAsync result completes exceptionally if either * source cancelled @@ -1661,7 +1647,7 @@ public class CompletableFutureTest exten CompletableFuture g = f.runAfterEitherAsync(f2, r); assertTrue(f.cancel(true)); checkCompletedWithWrappedCancellationException(g); - + r = new Noop(); f = new CompletableFuture(); f2 = new CompletableFuture(); @@ -1671,7 +1657,8 @@ public class CompletableFutureTest exten } /** - * thenCompse result completes normally after normal completion of source + * thenComposeAsync result completes normally after normal + * completion of source */ public void testThenComposeAsync() { CompletableFuture f = new CompletableFuture(); @@ -1682,8 +1669,8 @@ public class CompletableFutureTest exten } /** - * thenComposeAsync result completes exceptionally after exceptional - * completion of source + * thenComposeAsync result completes exceptionally after + * exceptional completion of source */ public void testThenComposeAsync2() { CompletableFuture f = new CompletableFuture(); @@ -1716,7 +1703,7 @@ public class CompletableFutureTest exten } - // aaync with explicit executors + // async with explicit executors /** * thenRunAsync result completes normally after normal completion of source @@ -1748,7 +1735,7 @@ public class CompletableFutureTest exten try { g.join(); shouldThrow(); - } catch(Exception ok) { + } catch (Exception ok) { } checkCompletedWithWrappedCFException(g); } @@ -1763,7 +1750,7 @@ public class CompletableFutureTest exten f.complete(null); checkCompletedWithWrappedCFException(g); } - + /** * thenRunAsync result completes exceptionally if source cancelled */ @@ -1806,7 +1793,7 @@ public class CompletableFutureTest exten f.complete(null); checkCompletedWithWrappedCFException(g); } - + /** * thenApplyAsync result completes exceptionally if source cancelled */ @@ -1852,7 +1839,7 @@ public class CompletableFutureTest exten f.complete(null); checkCompletedWithWrappedCFException(g); } - + /** * thenAcceptAsync result completes exceptionally if source cancelled */ @@ -1910,7 +1897,7 @@ public class CompletableFutureTest exten f2.complete(two); checkCompletedWithWrappedCFException(g); } - + /** * thenCombineAsync result completes exceptionally if either source cancelled */ @@ -1921,7 +1908,7 @@ public class CompletableFutureTest exten assertTrue(f.cancel(true)); f2.complete(two); checkCompletedWithWrappedCancellationException(g); - + f = new CompletableFuture(); f2 = new CompletableFuture(); g = f.thenCombineAsync(f2, add, new ThreadExecutor()); @@ -1975,13 +1962,13 @@ public class CompletableFutureTest exten CompletableFuture f = new CompletableFuture(); CompletableFuture f2 = new CompletableFuture(); FailingBiConsumer r = new FailingBiConsumer(); - CompletableFuture g = f.thenAcceptBothAsync(f2, r, new ThreadExecutor()); + CompletableFuture g = f.thenAcceptBothAsync(f2, r, new ThreadExecutor()); f.complete(one); checkIncomplete(g); f2.complete(two); checkCompletedWithWrappedCFException(g); } - + /** * thenAcceptBothAsync result completes exceptionally if either source cancelled */ @@ -1993,7 +1980,7 @@ public class CompletableFutureTest exten assertTrue(f.cancel(true)); f2.complete(two); checkCompletedWithWrappedCancellationException(g); - + r = new AddAction(); f = new CompletableFuture(); f2 = new CompletableFuture(); @@ -2048,13 +2035,13 @@ public class CompletableFutureTest exten CompletableFuture f = new CompletableFuture(); CompletableFuture f2 = new CompletableFuture(); FailingNoop r = new FailingNoop(); - CompletableFuture g = f.runAfterBothAsync(f2, r, new ThreadExecutor()); + CompletableFuture g = f.runAfterBothAsync(f2, r, new ThreadExecutor()); f.complete(one); checkIncomplete(g); f2.complete(two); checkCompletedWithWrappedCFException(g); } - + /** * runAfterBothAsync result completes exceptionally if either source cancelled */ @@ -2066,7 +2053,7 @@ public class CompletableFutureTest exten assertTrue(f.cancel(true)); f2.complete(two); checkCompletedWithWrappedCancellationException(g); - + r = new Noop(); f = new CompletableFuture(); f2 = new CompletableFuture(); @@ -2120,11 +2107,11 @@ public class CompletableFutureTest exten CompletableFuture f = new CompletableFuture(); CompletableFuture f2 = new CompletableFuture(); FailingFunction r = new FailingFunction(); - CompletableFuture g = f.applyToEitherAsync(f2, r, new ThreadExecutor()); + CompletableFuture g = f.applyToEitherAsync(f2, r, new ThreadExecutor()); f.complete(one); checkCompletedWithWrappedCFException(g); } - + /** * applyToEitherAsync result completes exceptionally if either source cancelled */ @@ -2134,7 +2121,7 @@ public class CompletableFutureTest exten CompletableFuture g = f.applyToEitherAsync(f2, inc, new ThreadExecutor()); assertTrue(f.cancel(true)); checkCompletedWithWrappedCancellationException(g); - + f = new CompletableFuture(); f2 = new CompletableFuture(); assertTrue(f2.cancel(true)); @@ -2192,11 +2179,11 @@ public class CompletableFutureTest exten CompletableFuture f = new CompletableFuture(); CompletableFuture f2 = new CompletableFuture(); FailingConsumer r = new FailingConsumer(); - CompletableFuture g = f.acceptEitherAsync(f2, r, new ThreadExecutor()); + CompletableFuture g = f.acceptEitherAsync(f2, r, new ThreadExecutor()); f.complete(one); checkCompletedWithWrappedCFException(g); } - + /** * acceptEitherAsync result completes exceptionally if either * source cancelled @@ -2208,7 +2195,7 @@ public class CompletableFutureTest exten CompletableFuture g = f.acceptEitherAsync(f2, r, new ThreadExecutor()); assertTrue(f.cancel(true)); checkCompletedWithWrappedCancellationException(g); - + r = new IncAction(); f = new CompletableFuture(); f2 = new CompletableFuture(); @@ -2267,11 +2254,11 @@ public class CompletableFutureTest exten CompletableFuture f = new CompletableFuture(); CompletableFuture f2 = new CompletableFuture(); FailingNoop r = new FailingNoop(); - CompletableFuture g = f.runAfterEitherAsync(f2, r, new ThreadExecutor()); + CompletableFuture g = f.runAfterEitherAsync(f2, r, new ThreadExecutor()); f.complete(one); checkCompletedWithWrappedCFException(g); } - + /** * runAfterEitherAsync result completes exceptionally if either * source cancelled @@ -2283,7 +2270,7 @@ public class CompletableFutureTest exten CompletableFuture g = f.runAfterEitherAsync(f2, r, new ThreadExecutor()); assertTrue(f.cancel(true)); checkCompletedWithWrappedCancellationException(g); - + r = new Noop(); f = new CompletableFuture(); f2 = new CompletableFuture(); @@ -2293,7 +2280,8 @@ public class CompletableFutureTest exten } /** - * thenCompse result completes normally after normal completion of source + * thenComposeAsync result completes normally after normal + * completion of source */ public void testThenComposeAsyncE() { CompletableFuture f = new CompletableFuture(); @@ -2304,8 +2292,8 @@ public class CompletableFutureTest exten } /** - * thenComposeAsync result completes exceptionally after exceptional - * completion of source + * thenComposeAsync result completes exceptionally after + * exceptional completion of source */ public void testThenComposeAsync2E() { CompletableFuture f = new CompletableFuture(); @@ -2337,7 +2325,7 @@ public class CompletableFutureTest exten checkCompletedWithWrappedCancellationException(g); } - // other static methods + // other static methods /** * allOf(no component futures) returns a future completed normally @@ -2354,7 +2342,7 @@ public class CompletableFutureTest exten public void testAllOf() throws Exception { for (int k = 1; k < 20; ++k) { CompletableFuture[] fs = new CompletableFuture[k]; - for (int i = 0; i < k; ++i) + for (int i = 0; i < k; ++i) fs[i] = new CompletableFuture(); CompletableFuture f = CompletableFuture.allOf(fs); for (int i = 0; i < k; ++i) { @@ -2380,7 +2368,7 @@ public class CompletableFutureTest exten public void testAnyOf() throws Exception { for (int k = 1; k < 20; ++k) { CompletableFuture[] fs = new CompletableFuture[k]; - for (int i = 0; i < k; ++i) + for (int i = 0; i < k; ++i) fs[i] = new CompletableFuture(); CompletableFuture f = CompletableFuture.anyOf(fs); checkIncomplete(f);