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.135 by jsr166, Sun Nov 15 20:03:08 2015 UTC vs.
Revision 1.139 by jsr166, Sat Jan 23 20:02:48 2016 UTC

# Line 876 | Line 876 | public class CompletableFutureTest exten
876          assertEquals(1, a.get());
877      }}
878  
879 +    /**
880 +     * If an "exceptionally action" throws an exception, it completes
881 +     * exceptionally with that exception
882 +     */
883      public void testExceptionally_exceptionalCompletionActionFailed() {
884          for (boolean createIncomplete : new boolean[] { true, false })
885      {
# Line 894 | Line 898 | public class CompletableFutureTest exten
898          if (createIncomplete) f.completeExceptionally(ex1);
899  
900          checkCompletedWithWrappedException(g, ex2);
901 +        checkCompletedExceptionally(f, ex1);
902          assertEquals(1, a.get());
903      }}
904  
# Line 1035 | Line 1040 | public class CompletableFutureTest exten
1040  
1041          checkCompletedWithWrappedException(g, ex1);
1042          checkCompletedExceptionally(f, ex1);
1043 +        if (testImplementationDetails) {
1044 +            assertEquals(1, ex1.getSuppressed().length);
1045 +            assertSame(ex2, ex1.getSuppressed()[0]);
1046 +        }
1047          assertEquals(1, a.get());
1048      }}
1049  
# Line 3821 | Line 3830 | public class CompletableFutureTest exten
3830              AtomicReference<Throwable> firstFailure = new AtomicReference<>(null);
3831          }
3832  
3833 <        // Monadic "plus"
3833 >        /** Implements "monadic plus". */
3834          static <T> CompletableFuture<T> plus(CompletableFuture<? extends T> f,
3835                                               CompletableFuture<? extends T> g) {
3836              PlusFuture<T> plus = new PlusFuture<T>();
3837              BiConsumer<T, Throwable> action = (T result, Throwable ex) -> {
3838 <                if (ex == null) {
3839 <                    if (plus.complete(result))
3840 <                        if (plus.firstFailure.get() != null)
3838 >                try {
3839 >                    if (ex == null) {
3840 >                        if (plus.complete(result))
3841 >                            if (plus.firstFailure.get() != null)
3842 >                                plus.firstFailure.set(null);
3843 >                    }
3844 >                    else if (plus.firstFailure.compareAndSet(null, ex)) {
3845 >                        if (plus.isDone())
3846                              plus.firstFailure.set(null);
3847 <                }
3848 <                else if (plus.firstFailure.compareAndSet(null, ex)) {
3849 <                    if (plus.isDone())
3850 <                        plus.firstFailure.set(null);
3851 <                }
3852 <                else {
3853 <                    // first failure has precedence
3854 <                    Throwable first = plus.firstFailure.getAndSet(null);
3855 <
3856 <                    // may fail with "Self-suppression not permitted"
3857 <                    try { first.addSuppressed(ex); }
3858 <                    catch (Exception ignored) {}
3859 <
3846 <                    plus.completeExceptionally(first);
3847 >                    }
3848 >                    else {
3849 >                        // first failure has precedence
3850 >                        Throwable first = plus.firstFailure.getAndSet(null);
3851 >
3852 >                        // may fail with "Self-suppression not permitted"
3853 >                        try { first.addSuppressed(ex); }
3854 >                        catch (Exception ignored) {}
3855 >
3856 >                        plus.completeExceptionally(first);
3857 >                    }
3858 >                } catch (Throwable unexpected) {
3859 >                    plus.completeExceptionally(unexpected);
3860                  }
3861              };
3862              f.whenComplete(action);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines