--- jsr166/src/test/tck/CompletableFutureTest.java 2015/09/03 16:30:05 1.105 +++ jsr166/src/test/tck/CompletableFutureTest.java 2015/09/05 15:35:47 1.117 @@ -3333,6 +3333,7 @@ public class CompletableFutureTest exten () -> f.exceptionally(null), () -> f.handle(null), + () -> CompletableFuture.allOf((CompletableFuture)null), () -> CompletableFuture.allOf((CompletableFuture[])null), () -> CompletableFuture.allOf(f, null), @@ -3344,6 +3345,13 @@ public class CompletableFutureTest exten () -> CompletableFuture.anyOf(null, f), () -> f.obtrudeException(null), + + () -> CompletableFuture.delayedExecutor(1L, SECONDS, null), + () -> CompletableFuture.delayedExecutor(1L, null, new ThreadExecutor()), + () -> CompletableFuture.delayedExecutor(1L, null), + + () -> f.orTimeout(1L, null), + () -> f.completeOnTimeout(42, 1L, null), }; assertThrows(NullPointerException.class, throwingActions); @@ -3364,11 +3372,19 @@ public class CompletableFutureTest exten * newIncompleteFuture returns an incomplete CompletableFuture */ public void testNewIncompleteFuture() { + for (Integer v1 : new Integer[] { 1, null }) + { CompletableFuture f = new CompletableFuture<>(); CompletableFuture g = f.newIncompleteFuture(); checkIncomplete(f); checkIncomplete(g); - } + f.complete(v1); + checkCompletedNormally(f, v1); + checkIncomplete(g); + g.complete(v1); + checkCompletedNormally(g, v1); + assertSame(g.getClass(), CompletableFuture.class); + }} /** * completedStage returns a completed CompletionStage @@ -3384,14 +3400,16 @@ public class CompletableFutureTest exten /** * defaultExecutor by default returns the commonPool if - * it supports at least one thread. + * it supports more than one thread. */ public void testDefaultExecutor() { CompletableFuture f = new CompletableFuture<>(); Executor e = f.defaultExecutor(); - Executor c = ForkJoinPool.commonPool(); + Executor c = ForkJoinPool.commonPool(); if (ForkJoinPool.getCommonPoolParallelism() > 1) assertSame(e, c); + else + assertNotSame(e, c); } /** @@ -3479,7 +3497,7 @@ public class CompletableFutureTest exten } /** - * failedStage returns a Completionstage completed + * failedStage returns a CompletionStage completed * exceptionally with the given Exception */ public void testFailedStage() { @@ -3542,57 +3560,55 @@ public class CompletableFutureTest exten } /** - * orTimeout completes with TimeoutException if not complete + * orTimeout completes with TimeoutException if not complete */ public void testOrTimeout() { CompletableFuture f = new CompletableFuture<>(); - f.orTimeout(SHORT_DELAY_MS, TimeUnit.MILLISECONDS); + f.orTimeout(SHORT_DELAY_MS, MILLISECONDS); checkCompletedExceptionallyWithTimeout(f); } /** - * orTimeout completes normally if completed before timeout + * orTimeout completes normally if completed before timeout */ public void testOrTimeout2() { CompletableFuture f = new CompletableFuture<>(); f.complete(1); - f.orTimeout(SHORT_DELAY_MS, TimeUnit.MILLISECONDS); + f.orTimeout(SHORT_DELAY_MS, MILLISECONDS); checkCompletedNormally(f, 1); } /** - * completeOnTimeout completes with given value if not complete + * completeOnTimeout completes with given value if not complete */ public void testCompleteOnTimeout() { CompletableFuture f = new CompletableFuture<>(); - f.completeOnTimeout(-1, SHORT_DELAY_MS, TimeUnit.MILLISECONDS); + f.completeOnTimeout(-1, SHORT_DELAY_MS, MILLISECONDS); f.join(); checkCompletedNormally(f, -1); } /** - * completeOnTimeout has no effect if completed within timeout + * completeOnTimeout has no effect if completed within timeout */ public void testCompleteOnTimeout2() { CompletableFuture f = new CompletableFuture<>(); f.complete(1); - f.completeOnTimeout(-1, SHORT_DELAY_MS, TimeUnit.MILLISECONDS); + f.completeOnTimeout(-1, SHORT_DELAY_MS, MILLISECONDS); checkCompletedNormally(f, 1); } /** * delayedExecutor returns an executor that delays submission */ - public void testDelayedExecutor() { + public void testDelayedExecutor() throws Exception { long timeoutMillis = SMALL_DELAY_MS; Executor d = CompletableFuture.delayedExecutor(timeoutMillis, MILLISECONDS); long startTime = System.nanoTime(); CompletableFuture f = CompletableFuture.supplyAsync(() -> 1, d); assertNull(f.getNow(null)); - try { - f.get(LONG_DELAY_MS, MILLISECONDS); - } catch (Throwable fail) { threadUnexpectedException(fail); } + assertEquals(1, (int) f.get(LONG_DELAY_MS, MILLISECONDS)); assertTrue(millisElapsedSince(startTime) > timeoutMillis/2); checkCompletedNormally(f, 1); } @@ -3601,7 +3617,7 @@ public class CompletableFutureTest exten * delayedExecutor for a given executor returns an executor that * delays submission */ - public void testDelayedExecutor2() { + public void testDelayedExecutor2() throws Exception { long timeoutMillis = SMALL_DELAY_MS; Executor d = CompletableFuture.delayedExecutor(timeoutMillis, MILLISECONDS, @@ -3609,9 +3625,7 @@ public class CompletableFutureTest exten long startTime = System.nanoTime(); CompletableFuture f = CompletableFuture.supplyAsync(() -> 1, d); assertNull(f.getNow(null)); - try { - f.get(LONG_DELAY_MS, MILLISECONDS); - } catch (Throwable fail) { threadUnexpectedException(fail); } + assertEquals(1, (int) f.get(LONG_DELAY_MS, MILLISECONDS)); assertTrue(millisElapsedSince(startTime) > timeoutMillis/2); checkCompletedNormally(f, 1); }