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.66 by jsr166, Fri Jun 6 19:19:04 2014 UTC vs.
Revision 1.67 by jsr166, Fri Jun 6 19:25:41 2014 UTC

# Line 1900 | Line 1900 | public class CompletableFutureTest exten
1900          for (int i = 0; i < 4; i++) rs[i].assertNotInvoked();
1901      }}
1902  
1903 +    public void testApplyToEither_sourceCancelled2() {
1904 +        for (ExecutionMode m : ExecutionMode.values())
1905 +        for (boolean mayInterruptIfRunning : new boolean[] { true, false })
1906 +        for (boolean fFirst : new boolean[] { true, false })
1907 +        for (Integer v1 : new Integer[] { 1, null })
1908 +    {
1909 +        final CompletableFuture<Integer> f = new CompletableFuture<>();
1910 +        final CompletableFuture<Integer> g = new CompletableFuture<>();
1911 +        final IncFunction[] rs = new IncFunction[6];
1912 +        for (int i = 0; i < rs.length; i++) rs[i] = new IncFunction(m);
1913 +
1914 +        final CompletableFuture<Integer> h0 = m.applyToEither(f, g, rs[0]);
1915 +        final CompletableFuture<Integer> h1 = m.applyToEither(g, f, rs[1]);
1916 +        if (fFirst) {
1917 +            f.complete(v1);
1918 +            g.cancel(mayInterruptIfRunning);
1919 +        } else {
1920 +            g.cancel(mayInterruptIfRunning);
1921 +            f.complete(v1);
1922 +        }
1923 +        final CompletableFuture<Integer> h2 = m.applyToEither(f, g, rs[2]);
1924 +        final CompletableFuture<Integer> h3 = m.applyToEither(g, f, rs[3]);
1925 +
1926 +        // unspecified behavior - both source completions available
1927 +        try {
1928 +            assertEquals(inc(v1), h0.join());
1929 +            rs[0].assertValue(inc(v1));
1930 +        } catch (CompletionException ok) {
1931 +            checkCompletedWithWrappedCancellationException(h0);
1932 +            rs[0].assertNotInvoked();
1933 +        }
1934 +        try {
1935 +            assertEquals(inc(v1), h1.join());
1936 +            rs[1].assertValue(inc(v1));
1937 +        } catch (CompletionException ok) {
1938 +            checkCompletedWithWrappedCancellationException(h1);
1939 +            rs[1].assertNotInvoked();
1940 +        }
1941 +        try {
1942 +            assertEquals(inc(v1), h2.join());
1943 +            rs[2].assertValue(inc(v1));
1944 +        } catch (CompletionException ok) {
1945 +            checkCompletedWithWrappedCancellationException(h2);
1946 +            rs[2].assertNotInvoked();
1947 +        }
1948 +        try {
1949 +            assertEquals(inc(v1), h3.join());
1950 +            rs[3].assertValue(inc(v1));
1951 +        } catch (CompletionException ok) {
1952 +            checkCompletedWithWrappedCancellationException(h3);
1953 +            rs[3].assertNotInvoked();
1954 +        }
1955 +
1956 +        checkCompletedNormally(f, v1);
1957 +        checkCancelled(g);
1958 +    }}
1959 +
1960      /**
1961       * applyToEither result completes exceptionally if action does
1962       */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines