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.37 by jsr166, Sun Jun 1 23:20:19 2014 UTC vs.
Revision 1.39 by jsr166, Mon Jun 2 00:46:52 2014 UTC

# Line 318 | Line 318 | public class CompletableFutureTest exten
318  
319      // Choose non-commutative actions for better coverage
320  
321 <    // A non-commutative function that handles null values as well,
322 <    // and produces null values occasionally.
323 <    public static Integer subtract(Integer x, Integer y) {
321 >    // A non-commutative function that handles and produces null values as well.
322 >    static Integer subtract(Integer x, Integer y) {
323          return (x == null && y == null) ? null :
324              ((x == null) ? 42 : x.intValue())
325              - ((y == null) ? 99 : y.intValue());
326      }
327  
328 +    // A function that handles and produces null values as well.
329 +    static Integer inc(Integer x) {
330 +        return (x == null) ? null : x + 1;
331 +    }
332 +
333      static final Supplier<Integer> supplyOne =
334          () -> Integer.valueOf(1);
335      static final Function<Integer, Integer> inc =
# Line 333 | Line 337 | public class CompletableFutureTest exten
337      static final BiFunction<Integer, Integer, Integer> subtract =
338          (Integer x, Integer y) -> subtract(x, y);
339      static final class IncAction implements Consumer<Integer> {
340 <        int value;
341 <        public void accept(Integer x) { value = x.intValue() + 1; }
340 >        int invocationCount = 0;
341 >        Integer value;
342 >        public boolean ran() { return invocationCount == 1; }
343 >        public void accept(Integer x) {
344 >            invocationCount++;
345 >            value = inc(x);
346 >        }
347 >    }
348 >    static final class IncFunction implements Function<Integer,Integer> {
349 >        int invocationCount = 0;
350 >        Integer value;
351 >        public boolean ran() { return invocationCount == 1; }
352 >        public Integer apply(Integer x) {
353 >            invocationCount++;
354 >            return value = inc(x);
355 >        }
356      }
357      static final class SubtractAction implements BiConsumer<Integer, Integer> {
358          int invocationCount = 0;
# Line 449 | Line 467 | public class CompletableFutureTest exten
467                   BiFunction<? super T,? super U,? extends V> a) {
468                  return f.thenCombine(g, a);
469              }
470 +            public <T,U> CompletableFuture<U> applyToEither
471 +                (CompletableFuture<T> f,
472 +                 CompletionStage<? extends T> g,
473 +                 Function<? super T,U> a) {
474 +                return f.applyToEither(g, a);
475 +            }
476 +            public <T> CompletableFuture<Void> acceptEither
477 +                (CompletableFuture<T> f,
478 +                 CompletionStage<? extends T> g,
479 +                 Consumer<? super T> a) {
480 +                return f.acceptEither(g, a);
481 +            }
482 +            public <T> CompletableFuture<Void> runAfterEither
483 +                (CompletableFuture<T> f,
484 +                 CompletionStage<?> g,
485 +                 java.lang.Runnable a) {
486 +                return f.runAfterEither(g, a);
487 +            }
488 +            public <T,U> CompletableFuture<U> thenCompose
489 +                (CompletableFuture<T> f,
490 +                 Function<? super T,? extends CompletionStage<U>> a) {
491 +                return f.thenCompose(a);
492 +            }
493 +            public <T> CompletableFuture<T> whenComplete
494 +                (CompletableFuture<T> f,
495 +                 BiConsumer<? super T,? super Throwable> a) {
496 +                return f.whenComplete(a);
497 +            }
498          },
499  
500   //             /** Experimental way to do more testing */
# Line 482 | Line 528 | public class CompletableFutureTest exten
528                   BiFunction<? super T,? super U,? extends V> a) {
529                  return f.thenCombineAsync(g, a);
530              }
531 +            public <T,U> CompletableFuture<U> applyToEither
532 +                (CompletableFuture<T> f,
533 +                 CompletionStage<? extends T> g,
534 +                 Function<? super T,U> a) {
535 +                return f.applyToEitherAsync(g, a);
536 +            }
537 +            public <T> CompletableFuture<Void> acceptEither
538 +                (CompletableFuture<T> f,
539 +                 CompletionStage<? extends T> g,
540 +                 Consumer<? super T> a) {
541 +                return f.acceptEitherAsync(g, a);
542 +            }
543 +            public <T> CompletableFuture<Void> runAfterEither
544 +                (CompletableFuture<T> f,
545 +                 CompletionStage<?> g,
546 +                 java.lang.Runnable a) {
547 +                return f.runAfterEitherAsync(g, a);
548 +            }
549 +            public <T,U> CompletableFuture<U> thenCompose
550 +                (CompletableFuture<T> f,
551 +                 Function<? super T,? extends CompletionStage<U>> a) {
552 +                return f.thenComposeAsync(a);
553 +            }
554 +            public <T> CompletableFuture<T> whenComplete
555 +                (CompletableFuture<T> f,
556 +                 BiConsumer<? super T,? super Throwable> a) {
557 +                return f.whenCompleteAsync(a);
558 +            }
559          },
560  
561   //         REVERSE_DEFAULT_ASYNC {
# Line 514 | Line 588 | public class CompletableFutureTest exten
588                   BiFunction<? super T,? super U,? extends V> a) {
589                  return f.thenCombineAsync(g, a, new ThreadExecutor());
590              }
591 +            public <T,U> CompletableFuture<U> applyToEither
592 +                (CompletableFuture<T> f,
593 +                 CompletionStage<? extends T> g,
594 +                 Function<? super T,U> a) {
595 +                return f.applyToEitherAsync(g, a, new ThreadExecutor());
596 +            }
597 +            public <T> CompletableFuture<Void> acceptEither
598 +                (CompletableFuture<T> f,
599 +                 CompletionStage<? extends T> g,
600 +                 Consumer<? super T> a) {
601 +                return f.acceptEitherAsync(g, a, new ThreadExecutor());
602 +            }
603 +            public <T> CompletableFuture<Void> runAfterEither
604 +                (CompletableFuture<T> f,
605 +                 CompletionStage<?> g,
606 +                 java.lang.Runnable a) {
607 +                return f.runAfterEitherAsync(g, a, new ThreadExecutor());
608 +            }
609 +            public <T,U> CompletableFuture<U> thenCompose
610 +                (CompletableFuture<T> f,
611 +                 Function<? super T,? extends CompletionStage<U>> a) {
612 +                return f.thenComposeAsync(a, new ThreadExecutor());
613 +            }
614 +            public <T> CompletableFuture<T> whenComplete
615 +                (CompletableFuture<T> f,
616 +                 BiConsumer<? super T,? super Throwable> a) {
617 +                return f.whenCompleteAsync(a, new ThreadExecutor());
618 +            }
619          };
620  
621          public abstract <T,U> CompletableFuture<Void> runAfterBoth
# Line 526 | Line 628 | public class CompletableFutureTest exten
628              (CompletableFuture<T> f,
629               CompletionStage<? extends U> g,
630               BiFunction<? super T,? super U,? extends V> a);
631 +        public abstract <T,U> CompletableFuture<U> applyToEither
632 +            (CompletableFuture<T> f,
633 +             CompletionStage<? extends T> g,
634 +             Function<? super T,U> a);
635 +        public abstract <T> CompletableFuture<Void> acceptEither
636 +            (CompletableFuture<T> f,
637 +             CompletionStage<? extends T> g,
638 +             Consumer<? super T> a);
639 +        public abstract <T> CompletableFuture<Void> runAfterEither
640 +            (CompletableFuture<T> f,
641 +             CompletionStage<?> g,
642 +             java.lang.Runnable a);
643 +        public abstract <T,U> CompletableFuture<U> thenCompose
644 +            (CompletableFuture<T> f,
645 +             Function<? super T,? extends CompletionStage<U>> a);
646 +        public abstract <T> CompletableFuture<T> whenComplete
647 +            (CompletableFuture<T> f,
648 +             BiConsumer<? super T,? super Throwable> a);
649 +
650 +
651      }
652  
653      /**
# Line 778 | Line 900 | public class CompletableFutureTest exten
900          CompletableFuture<Void> g = f.thenAccept(r);
901          f.complete(one);
902          checkCompletedNormally(g, null);
903 <        assertEquals(r.value, 2);
903 >        assertEquals(r.value, (Integer) 2);
904      }
905  
906      /**
# Line 1722 | Line 1844 | public class CompletableFutureTest exten
1844       * applyToEither result completes normally after normal completion
1845       * of either source
1846       */
1847 <    public void testApplyToEither() {
1848 <        CompletableFuture<Integer> f = new CompletableFuture<>();
1849 <        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1850 <        CompletableFuture<Integer> g = f.applyToEither(f2, inc);
1729 <        f.complete(one);
1730 <        checkCompletedNormally(g, two);
1731 <        f2.complete(one);
1732 <        checkCompletedNormally(g, two);
1847 >    public void testApplyToEither_normalCompletion1() {
1848 >        for (ExecutionMode m : ExecutionMode.values())
1849 >        for (Integer v1 : new Integer[] { 1, null })
1850 >        for (Integer v2 : new Integer[] { 2, null }) {
1851  
1852 <        f = new CompletableFuture<>();
1853 <        f.complete(one);
1854 <        f2 = new CompletableFuture<>();
1855 <        g = f.applyToEither(f2, inc);
1856 <        checkCompletedNormally(g, two);
1852 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1853 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1854 >        final IncFunction r = new IncFunction();
1855 >        final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
1856 >
1857 >        f.complete(v1);
1858 >        checkCompletedNormally(h, inc(v1));
1859 >        g.complete(v2);
1860 >
1861 >        checkCompletedNormally(f, v1);
1862 >        checkCompletedNormally(g, v2);
1863 >        checkCompletedNormally(h, inc(v1));
1864 >        }
1865 >    }
1866 >
1867 >    public void testApplyToEither_normalCompletion2() {
1868 >        for (ExecutionMode m : ExecutionMode.values())
1869 >        for (Integer v1 : new Integer[] { 1, null })
1870 >        for (Integer v2 : new Integer[] { 2, null }) {
1871 >
1872 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1873 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1874 >        final IncFunction r = new IncFunction();
1875 >        final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
1876 >
1877 >        g.complete(v2);
1878 >        checkCompletedNormally(h, inc(v2));
1879 >        f.complete(v1);
1880 >
1881 >        checkCompletedNormally(f, v1);
1882 >        checkCompletedNormally(g, v2);
1883 >        checkCompletedNormally(h, inc(v2));
1884 >        }
1885 >    }
1886 >    public void testApplyToEither_normalCompletion3() {
1887 >        for (ExecutionMode m : ExecutionMode.values())
1888 >        for (Integer v1 : new Integer[] { 1, null })
1889 >        for (Integer v2 : new Integer[] { 2, null }) {
1890 >
1891 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1892 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1893 >        final IncFunction r = new IncFunction();
1894 >
1895 >        f.complete(v1);
1896 >        g.complete(v2);
1897 >        final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
1898 >
1899 >        checkCompletedNormally(f, v1);
1900 >        checkCompletedNormally(g, v2);
1901 >
1902 >        // unspecified behavior
1903 >        assertTrue(Objects.equals(h.join(), inc(v1)) ||
1904 >                   Objects.equals(h.join(), inc(v2)));
1905 >        }
1906      }
1907  
1908      /**
1909       * applyToEither result completes exceptionally after exceptional
1910       * completion of either source
1911       */
1912 <    public void testApplyToEither2() {
1913 <        CompletableFuture<Integer> f = new CompletableFuture<>();
1914 <        CompletableFuture<Integer> f2 = new CompletableFuture<>();
1748 <        CompletableFuture<Integer> g = f.applyToEither(f2, inc);
1749 <        f.completeExceptionally(new CFException());
1750 <        f2.complete(one);
1751 <        checkCompletedWithWrappedCFException(g);
1912 >    public void testApplyToEither_exceptionalCompletion1() {
1913 >        for (ExecutionMode m : ExecutionMode.values())
1914 >        for (Integer v1 : new Integer[] { 1, null }) {
1915  
1916 <        f = new CompletableFuture<>();
1917 <        f2 = new CompletableFuture<>();
1918 <        f2.completeExceptionally(new CFException());
1919 <        g = f.applyToEither(f2, inc);
1920 <        checkCompletedWithWrappedCFException(g);
1916 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1917 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1918 >        final IncFunction r = new IncFunction();
1919 >        final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
1920 >        final CFException ex = new CFException();
1921 >
1922 >        f.completeExceptionally(ex);
1923 >        checkCompletedWithWrappedCFException(h, ex);
1924 >        g.complete(v1);
1925 >
1926 >        assertFalse(r.ran());
1927 >        checkCompletedNormally(g, v1);
1928 >        checkCompletedWithWrappedCFException(f, ex);
1929 >        checkCompletedWithWrappedCFException(h, ex);
1930 >        }
1931 >    }
1932 >
1933 >    public void testApplyToEither_exceptionalCompletion2() {
1934 >        for (ExecutionMode m : ExecutionMode.values())
1935 >        for (Integer v1 : new Integer[] { 1, null }) {
1936 >
1937 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1938 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1939 >        final IncFunction r = new IncFunction();
1940 >        final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
1941 >        final CFException ex = new CFException();
1942 >
1943 >        g.completeExceptionally(ex);
1944 >        checkCompletedWithWrappedCFException(h, ex);
1945 >        f.complete(v1);
1946 >
1947 >        assertFalse(r.ran());
1948 >        checkCompletedNormally(f, v1);
1949 >        checkCompletedWithWrappedCFException(g, ex);
1950 >        checkCompletedWithWrappedCFException(h, ex);
1951 >        }
1952 >    }
1953 >
1954 >    public void testApplyToEither_exceptionalCompletion3() {
1955 >        for (ExecutionMode m : ExecutionMode.values())
1956 >        for (Integer v1 : new Integer[] { 1, null }) {
1957 >
1958 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1959 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1960 >        final IncFunction r = new IncFunction();
1961 >        final CFException ex = new CFException();
1962 >
1963 >        g.completeExceptionally(ex);
1964 >        f.complete(v1);
1965 >        final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
1966 >
1967 >        // unspecified behavior
1968 >        Integer v;
1969 >        try {
1970 >            assertEquals(h.join(), inc(v1));
1971 >            assertTrue(r.ran());
1972 >        } catch (CompletionException ok) {
1973 >            checkCompletedWithWrappedCFException(h, ex);
1974 >            assertFalse(r.ran());
1975 >        }
1976 >
1977 >        checkCompletedWithWrappedCFException(g, ex);
1978 >        checkCompletedNormally(f, v1);
1979 >        }
1980 >    }
1981 >
1982 >    public void testApplyToEither_exceptionalCompletion4() {
1983 >        for (ExecutionMode m : ExecutionMode.values())
1984 >        for (Integer v1 : new Integer[] { 1, null }) {
1985 >
1986 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
1987 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
1988 >        final IncFunction r = new IncFunction();
1989 >        final CFException ex = new CFException();
1990 >
1991 >        f.completeExceptionally(ex);
1992 >        g.complete(v1);
1993 >        final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
1994 >
1995 >        // unspecified behavior
1996 >        Integer v;
1997 >        try {
1998 >            assertEquals(h.join(), inc(v1));
1999 >            assertTrue(r.ran());
2000 >        } catch (CompletionException ok) {
2001 >            checkCompletedWithWrappedCFException(h, ex);
2002 >            assertFalse(r.ran());
2003 >        }
2004 >
2005 >        checkCompletedWithWrappedCFException(f, ex);
2006 >        assertFalse(r.ran());
2007 >        checkCompletedNormally(g, v1);
2008 >        }
2009      }
2010  
2011      /**
2012       * applyToEither result completes exceptionally if action does
2013       */
2014 <    public void testApplyToEither3() {
2015 <        CompletableFuture<Integer> f = new CompletableFuture<>();
2016 <        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2017 <        FailingFunction r = new FailingFunction();
2018 <        CompletableFuture<Integer> g = f.applyToEither(f2, r);
2019 <        f2.complete(two);
2020 <        checkCompletedWithWrappedCFException(g);
2014 >    public void testApplyToEither_actionFailed1() {
2015 >        for (ExecutionMode m : ExecutionMode.values())
2016 >        for (Integer v1 : new Integer[] { 1, null })
2017 >        for (Integer v2 : new Integer[] { 2, null }) {
2018 >
2019 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
2020 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
2021 >        final FailingFunction r = new FailingFunction();
2022 >        final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
2023 >
2024 >        f.complete(v1);
2025 >        checkCompletedWithWrappedCFException(h);
2026 >        g.complete(v2);
2027 >        checkCompletedNormally(f, v1);
2028 >        checkCompletedNormally(g, v2);
2029 >        }
2030 >    }
2031 >
2032 >    public void testApplyToEither_actionFailed2() {
2033 >        for (ExecutionMode m : ExecutionMode.values())
2034 >        for (Integer v1 : new Integer[] { 1, null })
2035 >        for (Integer v2 : new Integer[] { 2, null }) {
2036 >
2037 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
2038 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
2039 >        final FailingFunction r = new FailingFunction();
2040 >        final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
2041 >
2042 >        g.complete(v2);
2043 >        checkCompletedWithWrappedCFException(h);
2044 >        f.complete(v1);
2045 >        checkCompletedNormally(f, v1);
2046 >        checkCompletedNormally(g, v2);
2047 >        }
2048      }
2049  
2050      /**
2051       * applyToEither result completes exceptionally if either source cancelled
2052       */
2053 <    public void testApplyToEither4() {
2054 <        CompletableFuture<Integer> f = new CompletableFuture<>();
2055 <        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2056 <        CompletableFuture<Integer> g = f.applyToEither(f2, inc);
2057 <        assertTrue(f.cancel(true));
2058 <        checkCompletedWithWrappedCancellationException(g);
2059 <        f = new CompletableFuture<>();
2060 <        f2 = new CompletableFuture<>();
2061 <        assertTrue(f2.cancel(true));
2062 <        checkCompletedWithWrappedCancellationException(g);
2053 >    public void testApplyToEither_sourceCancelled1() {
2054 >        for (ExecutionMode m : ExecutionMode.values())
2055 >        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
2056 >        for (Integer v1 : new Integer[] { 1, null }) {
2057 >
2058 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
2059 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
2060 >        final IncFunction r = new IncFunction();
2061 >        final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
2062 >
2063 >        assertTrue(f.cancel(mayInterruptIfRunning));
2064 >        checkCompletedWithWrappedCancellationException(h);
2065 >        g.complete(v1);
2066 >
2067 >        checkCancelled(f);
2068 >        assertFalse(r.ran());
2069 >        checkCompletedNormally(g, v1);
2070 >        checkCompletedWithWrappedCancellationException(h);
2071 >        }
2072 >    }
2073 >
2074 >    public void testApplyToEither_sourceCancelled2() {
2075 >        for (ExecutionMode m : ExecutionMode.values())
2076 >        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
2077 >        for (Integer v1 : new Integer[] { 1, null }) {
2078 >
2079 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
2080 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
2081 >        final IncFunction r = new IncFunction();
2082 >        final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
2083 >
2084 >        assertTrue(g.cancel(mayInterruptIfRunning));
2085 >        checkCompletedWithWrappedCancellationException(h);
2086 >        f.complete(v1);
2087 >
2088 >        checkCancelled(g);
2089 >        assertFalse(r.ran());
2090 >        checkCompletedNormally(f, v1);
2091 >        checkCompletedWithWrappedCancellationException(h);
2092 >        }
2093 >    }
2094 >
2095 >    public void testApplyToEither_sourceCancelled3() {
2096 >        for (ExecutionMode m : ExecutionMode.values())
2097 >        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
2098 >        for (Integer v1 : new Integer[] { 1, null }) {
2099 >
2100 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
2101 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
2102 >        final IncFunction r = new IncFunction();
2103 >
2104 >        assertTrue(g.cancel(mayInterruptIfRunning));
2105 >        f.complete(v1);
2106 >        final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
2107 >
2108 >        // unspecified behavior
2109 >        Integer v;
2110 >        try {
2111 >            assertEquals(h.join(), inc(v1));
2112 >            assertTrue(r.ran());
2113 >        } catch (CompletionException ok) {
2114 >            checkCompletedWithWrappedCancellationException(h);
2115 >            assertFalse(r.ran());
2116 >        }
2117 >
2118 >        checkCancelled(g);
2119 >        checkCompletedNormally(f, v1);
2120 >        }
2121 >    }
2122 >
2123 >    public void testApplyToEither_sourceCancelled4() {
2124 >        for (ExecutionMode m : ExecutionMode.values())
2125 >        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
2126 >        for (Integer v1 : new Integer[] { 1, null }) {
2127 >
2128 >        final CompletableFuture<Integer> f = new CompletableFuture<>();
2129 >        final CompletableFuture<Integer> g = new CompletableFuture<>();
2130 >        final IncFunction r = new IncFunction();
2131 >
2132 >        assertTrue(f.cancel(mayInterruptIfRunning));
2133 >        g.complete(v1);
2134 >        final CompletableFuture<Integer> h = m.applyToEither(f, g, r);
2135 >
2136 >        // unspecified behavior
2137 >        Integer v;
2138 >        try {
2139 >            assertEquals(h.join(), inc(v1));
2140 >            assertTrue(r.ran());
2141 >        } catch (CompletionException ok) {
2142 >            checkCompletedWithWrappedCancellationException(h);
2143 >            assertFalse(r.ran());
2144 >        }
2145 >
2146 >        checkCancelled(f);
2147 >        checkCompletedNormally(g, v1);
2148 >        }
2149      }
2150  
2151      /**
# Line 1797 | Line 2161 | public class CompletableFutureTest exten
2161          checkCompletedNormally(g, null);
2162          f2.complete(one);
2163          checkCompletedNormally(g, null);
2164 <        assertEquals(r.value, 2);
2164 >        assertEquals(r.value, (Integer) 2);
2165  
2166          r = new IncAction();
2167          f = new CompletableFuture<>();
# Line 1805 | Line 2169 | public class CompletableFutureTest exten
2169          f2 = new CompletableFuture<>();
2170          g = f.acceptEither(f2, r);
2171          checkCompletedNormally(g, null);
2172 <        assertEquals(r.value, 2);
2172 >        assertEquals(r.value, (Integer) 2);
2173      }
2174  
2175      /**
# Line 2115 | Line 2479 | public class CompletableFutureTest exten
2479          CompletableFuture<Void> g = f.thenAcceptAsync(r);
2480          f.complete(one);
2481          checkCompletedNormally(g, null);
2482 <        assertEquals(r.value, 2);
2482 >        assertEquals(r.value, (Integer) 2);
2483      }
2484  
2485      /**
# Line 2153 | Line 2517 | public class CompletableFutureTest exten
2517      }
2518  
2519      /**
2156     * applyToEitherAsync result completes normally after normal
2157     * completion of sources
2158     */
2159    public void testApplyToEitherAsync() {
2160        CompletableFuture<Integer> f = new CompletableFuture<>();
2161        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2162        CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc);
2163        f.complete(one);
2164        checkCompletedNormally(g, two);
2165
2166        f = new CompletableFuture<>();
2167        f.complete(one);
2168        f2 = new CompletableFuture<>();
2169        g = f.applyToEitherAsync(f2, inc);
2170        checkCompletedNormally(g, two);
2171    }
2172
2173    /**
2174     * applyToEitherAsync result completes exceptionally after exceptional
2175     * completion of source
2176     */
2177    public void testApplyToEitherAsync2() {
2178        CompletableFuture<Integer> f = new CompletableFuture<>();
2179        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2180        CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc);
2181        f.completeExceptionally(new CFException());
2182        checkCompletedWithWrappedCFException(g);
2183
2184        f = new CompletableFuture<>();
2185        f2 = new CompletableFuture<>();
2186        f2.completeExceptionally(new CFException());
2187        g = f.applyToEitherAsync(f2, inc);
2188        f.complete(one);
2189        checkCompletedWithWrappedCFException(g);
2190    }
2191
2192    /**
2193     * applyToEitherAsync result completes exceptionally if action does
2194     */
2195    public void testApplyToEitherAsync3() {
2196        CompletableFuture<Integer> f = new CompletableFuture<>();
2197        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2198        FailingFunction r = new FailingFunction();
2199        CompletableFuture<Integer> g = f.applyToEitherAsync(f2, r);
2200        f.complete(one);
2201        checkCompletedWithWrappedCFException(g);
2202    }
2203
2204    /**
2205     * applyToEitherAsync result completes exceptionally if either source cancelled
2206     */
2207    public void testApplyToEitherAsync4() {
2208        CompletableFuture<Integer> f = new CompletableFuture<>();
2209        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2210        CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc);
2211        assertTrue(f.cancel(true));
2212        checkCompletedWithWrappedCancellationException(g);
2213
2214        f = new CompletableFuture<>();
2215        f2 = new CompletableFuture<>();
2216        assertTrue(f2.cancel(true));
2217        g = f.applyToEitherAsync(f2, inc);
2218        checkCompletedWithWrappedCancellationException(g);
2219    }
2220
2221    /**
2520       * acceptEitherAsync result completes normally after normal
2521       * completion of sources
2522       */
# Line 2229 | Line 2527 | public class CompletableFutureTest exten
2527          CompletableFuture<Void> g = f.acceptEitherAsync(f2, r);
2528          f.complete(one);
2529          checkCompletedNormally(g, null);
2530 <        assertEquals(r.value, 2);
2530 >        assertEquals(r.value, (Integer) 2);
2531  
2532          r = new IncAction();
2533          f = new CompletableFuture<>();
# Line 2237 | Line 2535 | public class CompletableFutureTest exten
2535          f2 = new CompletableFuture<>();
2536          g = f.acceptEitherAsync(f2, r);
2537          checkCompletedNormally(g, null);
2538 <        assertEquals(r.value, 2);
2538 >        assertEquals(r.value, (Integer) 2);
2539      }
2540  
2541      /**
# Line 2554 | Line 2852 | public class CompletableFutureTest exten
2852          CompletableFuture<Void> g = f.thenAcceptAsync(r, new ThreadExecutor());
2853          f.complete(one);
2854          checkCompletedNormally(g, null);
2855 <        assertEquals(r.value, 2);
2855 >        assertEquals(r.value, (Integer) 2);
2856      }
2857  
2858      /**
# Line 2592 | Line 2890 | public class CompletableFutureTest exten
2890      }
2891  
2892      /**
2595     * applyToEitherAsync result completes normally after normal
2596     * completion of sources
2597     */
2598    public void testApplyToEitherAsyncE() {
2599        CompletableFuture<Integer> f = new CompletableFuture<>();
2600        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2601        CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc, new ThreadExecutor());
2602        f.complete(one);
2603        checkCompletedNormally(g, two);
2604
2605        f = new CompletableFuture<>();
2606        f.complete(one);
2607        f2 = new CompletableFuture<>();
2608        g = f.applyToEitherAsync(f2, inc, new ThreadExecutor());
2609        checkCompletedNormally(g, two);
2610    }
2611
2612    /**
2613     * applyToEitherAsync result completes exceptionally after exceptional
2614     * completion of source
2615     */
2616    public void testApplyToEitherAsync2E() {
2617        CompletableFuture<Integer> f = new CompletableFuture<>();
2618        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2619        CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc, new ThreadExecutor());
2620        f.completeExceptionally(new CFException());
2621        checkCompletedWithWrappedCFException(g);
2622
2623        f = new CompletableFuture<>();
2624        f2 = new CompletableFuture<>();
2625        f2.completeExceptionally(new CFException());
2626        g = f.applyToEitherAsync(f2, inc, new ThreadExecutor());
2627        f.complete(one);
2628        checkCompletedWithWrappedCFException(g);
2629    }
2630
2631    /**
2632     * applyToEitherAsync result completes exceptionally if action does
2633     */
2634    public void testApplyToEitherAsync3E() {
2635        CompletableFuture<Integer> f = new CompletableFuture<>();
2636        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2637        FailingFunction r = new FailingFunction();
2638        CompletableFuture<Integer> g = f.applyToEitherAsync(f2, r, new ThreadExecutor());
2639        f.complete(one);
2640        checkCompletedWithWrappedCFException(g);
2641    }
2642
2643    /**
2644     * applyToEitherAsync result completes exceptionally if either source cancelled
2645     */
2646    public void testApplyToEitherAsync4E() {
2647        CompletableFuture<Integer> f = new CompletableFuture<>();
2648        CompletableFuture<Integer> f2 = new CompletableFuture<>();
2649        CompletableFuture<Integer> g = f.applyToEitherAsync(f2, inc, new ThreadExecutor());
2650        assertTrue(f.cancel(true));
2651        checkCompletedWithWrappedCancellationException(g);
2652
2653        f = new CompletableFuture<>();
2654        f2 = new CompletableFuture<>();
2655        assertTrue(f2.cancel(true));
2656        g = f.applyToEitherAsync(f2, inc, new ThreadExecutor());
2657        checkCompletedWithWrappedCancellationException(g);
2658    }
2659
2660    /**
2893       * acceptEitherAsync result completes normally after normal
2894       * completion of sources
2895       */
# Line 2668 | Line 2900 | public class CompletableFutureTest exten
2900          CompletableFuture<Void> g = f.acceptEitherAsync(f2, r, new ThreadExecutor());
2901          f.complete(one);
2902          checkCompletedNormally(g, null);
2903 <        assertEquals(r.value, 2);
2903 >        assertEquals(r.value, (Integer) 2);
2904  
2905          r = new IncAction();
2906          f = new CompletableFuture<>();
# Line 2676 | Line 2908 | public class CompletableFutureTest exten
2908          f2 = new CompletableFuture<>();
2909          g = f.acceptEitherAsync(f2, r, new ThreadExecutor());
2910          checkCompletedNormally(g, null);
2911 <        assertEquals(r.value, 2);
2911 >        assertEquals(r.value, (Integer) 2);
2912      }
2913  
2914      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines