ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/CompletableFutureTest.java
(Generate patch)

Comparing jsr166/src/test/tck/CompletableFutureTest.java (file contents):
Revision 1.205 by jsr166, Sun Sep 23 00:55:03 2018 UTC vs.
Revision 1.209 by jsr166, Sun Sep 23 17:02:24 2018 UTC

# Line 926 | Line 926 | public class CompletableFutureTest exten
926          for (boolean createIncomplete : new boolean[] { true, false })
927          for (Integer v1 : new Integer[] { 1, null })
928      {
929        final AtomicInteger a = new AtomicInteger(0);
929          final CompletableFuture<Integer> f = new CompletableFuture<>();
930          if (!createIncomplete) assertTrue(f.complete(v1));
931          final CompletableFuture<Integer> g = m.exceptionally
932              (f, (Throwable t) -> {
934                a.getAndIncrement();
933                  threadFail("should not be called");
934                  return null;            // unreached
935              });
# Line 939 | Line 937 | public class CompletableFutureTest exten
937  
938          checkCompletedNormally(g, v1);
939          checkCompletedNormally(f, v1);
942        assertEquals(0, a.get());
940      }}
941  
942      /**
# Line 3170 | Line 3167 | public class CompletableFutureTest exten
3167          final CompletableFuture<Integer> g = m.exceptionallyCompose(f, r);
3168          if (createIncomplete) assertTrue(f.complete(v1));
3169  
3170 +        if (!createIncomplete && testImplementationDetails)
3171 +            assertSame(f, g);   // an optimization
3172 +
3173          checkCompletedNormally(f, v1);
3174          checkCompletedNormally(g, v1);
3175          r.assertNotInvoked();
# Line 3217 | Line 3217 | public class CompletableFutureTest exten
3217          r.assertInvoked();
3218      }}
3219  
3220 +    /**
3221 +     * thenComposeExceptionally result completes exceptionally if the
3222 +     * result of the action does
3223 +     */
3224 +    public void testExceptionallyCompose_actionReturnsFailingFuture() {
3225 +        for (ExecutionMode m : ExecutionMode.values())
3226 +        for (int order = 0; order < 6; order++)
3227 +        for (Integer v1 : new Integer[] { 1, null })
3228 +    {
3229 +        final CFException ex0 = new CFException();
3230 +        final CFException ex = new CFException();
3231 +        final CompletableFuture<Integer> f = new CompletableFuture<>();
3232 +        final CompletableFuture<Integer> g = new CompletableFuture<>();
3233 +        final CompletableFuture<Integer> h;
3234 +        // Test all permutations of orders
3235 +        switch (order) {
3236 +        case 0:
3237 +            assertTrue(f.completeExceptionally(ex0));
3238 +            assertTrue(g.completeExceptionally(ex));
3239 +            h = m.exceptionallyCompose(f, (x -> g));
3240 +            break;
3241 +        case 1:
3242 +            assertTrue(f.completeExceptionally(ex0));
3243 +            h = m.exceptionallyCompose(f, (x -> g));
3244 +            assertTrue(g.completeExceptionally(ex));
3245 +            break;
3246 +        case 2:
3247 +            assertTrue(g.completeExceptionally(ex));
3248 +            assertTrue(f.completeExceptionally(ex0));
3249 +            h = m.exceptionallyCompose(f, (x -> g));
3250 +            break;
3251 +        case 3:
3252 +            assertTrue(g.completeExceptionally(ex));
3253 +            h = m.exceptionallyCompose(f, (x -> g));
3254 +            assertTrue(f.completeExceptionally(ex0));
3255 +            break;
3256 +        case 4:
3257 +            h = m.exceptionallyCompose(f, (x -> g));
3258 +            assertTrue(f.completeExceptionally(ex0));
3259 +            assertTrue(g.completeExceptionally(ex));
3260 +            break;
3261 +        case 5:
3262 +            h = m.exceptionallyCompose(f, (x -> g));
3263 +            assertTrue(f.completeExceptionally(ex0));
3264 +            assertTrue(g.completeExceptionally(ex));
3265 +            break;
3266 +        default: throw new AssertionError();
3267 +        }
3268 +
3269 +        checkCompletedExceptionally(g, ex);
3270 +
3271 +        // TODO: should this be: checkCompletedWithWrappedException(h, ex);
3272 +        try {
3273 +            h.join();
3274 +            shouldThrow();
3275 +        } catch (Throwable t) {
3276 +            assertSame(ex, (t instanceof CompletionException) ? t.getCause() : t);
3277 +        }
3278 +
3279 +        checkCompletedExceptionally(f, ex0);
3280 +    }}
3281  
3282      // other static methods
3283  
# Line 4780 | Line 4841 | public class CompletableFutureTest exten
4841      }
4842  
4843      /**
4844 +     * default-implemented exceptionallyAsync action is not invoked when
4845 +     * source completes normally, and source result is propagated
4846 +     */
4847 +    public void testDefaultExceptionallyAsync_normalCompletion() {
4848 +        for (boolean createIncomplete : new boolean[] { true, false })
4849 +        for (Integer v1 : new Integer[] { 1, null })
4850 +    {
4851 +        final CompletableFuture<Integer> f = new CompletableFuture<>();
4852 +        final DelegatedCompletionStage<Integer> d =
4853 +            new DelegatedCompletionStage<Integer>(f);
4854 +        if (!createIncomplete) assertTrue(f.complete(v1));
4855 +        final CompletionStage<Integer> g = d.exceptionallyAsync
4856 +            ((Throwable t) -> {
4857 +                threadFail("should not be called");
4858 +                return null;            // unreached
4859 +            });
4860 +        if (createIncomplete) assertTrue(f.complete(v1));
4861 +
4862 +        checkCompletedNormally(g.toCompletableFuture(), v1);
4863 +    }}
4864 +
4865 +    /**
4866       * default-implemented exceptionallyAsync action completes with
4867       * function value on source exception
4868       */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines