test/java/util/concurrent/CompletableFuture/Basic.java

Print this page

        

@@ -484,44 +484,44 @@
         try {
             CompletableFuture<Integer> cf3;
             CompletableFuture<Integer> cf1 = supplyAsync(() -> 1);
             CompletableFuture<Integer> cf2 = supplyAsync(() -> 2);
             cf3 = cf1.applyToEither(cf2, (x) -> { check(x == 1 || x == 2); return x; });
-            check(cf1.isDone() || cf2.isDone());
             checkCompletedNormally(cf3, new Object[] {1, 2});
+            check(cf1.isDone() || cf2.isDone());
 
             cf1 = supplyAsync(() -> 1);
             cf2 = supplyAsync(() -> 2);
             cf3 = cf1.applyToEitherAsync(cf2, (x) -> { check(x == 1 || x == 2); return x; });
-            check(cf1.isDone() || cf2.isDone());
             checkCompletedNormally(cf3, new Object[] {1, 2});
+            check(cf1.isDone() || cf2.isDone());
 
             cf1 = supplyAsync(() -> 1);
             cf2 = supplyAsync(() -> 2);
             cf3 = cf1.applyToEitherAsync(cf2, (x) -> { check(x == 1 || x == 2); return x; }, executor);
-            check(cf1.isDone() || cf2.isDone());
             checkCompletedNormally(cf3, new Object[] {1, 2});
+            check(cf1.isDone() || cf2.isDone());
 
             cf1 = supplyAsync(() -> { throw new RuntimeException(); });
             cf2 = supplyAsync(() -> 2);
             cf3 = cf1.applyToEither(cf2, (x) -> { check(x == 2); return x; });
-            check(cf1.isDone() || cf2.isDone());
             try { check(cf3.join() == 1); } catch (CompletionException x) { pass(); }
             check(cf3.isDone());
+            check(cf1.isDone() || cf2.isDone());
 
             cf1 = supplyAsync(() -> 1);
             cf2 = supplyAsync(() -> { throw new RuntimeException(); });
             cf3 = cf1.applyToEitherAsync(cf2, (x) -> { check(x == 1); return x; });
-            check(cf1.isDone() || cf2.isDone());
             try { check(cf3.join() == 1); } catch (CompletionException x) { pass(); }
             check(cf3.isDone());
+            check(cf1.isDone() || cf2.isDone());
 
             cf1 = supplyAsync(() -> { throw new RuntimeException(); });
             cf2 = supplyAsync(() -> { throw new RuntimeException(); });
             cf3 = cf1.applyToEitherAsync(cf2, (x) -> { fail(); return x; });
-            check(cf1.isDone() || cf2.isDone());
             checkCompletedExceptionally(cf3);
+            check(cf1.isDone() || cf2.isDone());
         } catch (Throwable t) { unexpected(t); }
 
         //----------------------------------------------------------------
         // acceptEitherXXX tests
         //----------------------------------------------------------------

@@ -529,49 +529,49 @@
             CompletableFuture<Void> cf3;
             int before = atomicInt.get();
             CompletableFuture<Integer> cf1 = supplyAsync(() -> 1);
             CompletableFuture<Integer> cf2 = supplyAsync(() -> 2);
             cf3 = cf1.acceptEither(cf2, (x) -> { check(x == 1 || x == 2); atomicInt.incrementAndGet(); });
-            check(cf1.isDone() || cf2.isDone());
             checkCompletedNormally(cf3, null);
+            check(cf1.isDone() || cf2.isDone());
             check(atomicInt.get() == (before + 1));
 
             before = atomicInt.get();
             cf1 = supplyAsync(() -> 1);
             cf2 = supplyAsync(() -> 2);
             cf3 = cf1.acceptEitherAsync(cf2, (x) -> { check(x == 1 || x == 2); atomicInt.incrementAndGet(); });
-            check(cf1.isDone() || cf2.isDone());
             checkCompletedNormally(cf3, null);
+            check(cf1.isDone() || cf2.isDone());
             check(atomicInt.get() == (before + 1));
 
             before = atomicInt.get();
             cf1 = supplyAsync(() -> 1);
             cf2 = supplyAsync(() -> 2);
             cf3 = cf2.acceptEitherAsync(cf1, (x) -> { check(x == 1 || x == 2); atomicInt.incrementAndGet(); }, executor);
-            check(cf1.isDone() || cf2.isDone());
             checkCompletedNormally(cf3, null);
+            check(cf1.isDone() || cf2.isDone());
             check(atomicInt.get() == (before + 1));
 
             cf1 = supplyAsync(() -> { throw new RuntimeException(); });
             cf2 = supplyAsync(() -> 2);
             cf3 = cf2.acceptEitherAsync(cf1, (x) -> { check(x == 2); }, executor);
-            check(cf1.isDone() || cf2.isDone());
             try { check(cf3.join() == null); } catch (CompletionException x) { pass(); }
             check(cf3.isDone());
+            check(cf1.isDone() || cf2.isDone());
 
             cf1 = supplyAsync(() -> 1);
             cf2 = supplyAsync(() -> { throw new RuntimeException(); });
             cf3 = cf2.acceptEitherAsync(cf1, (x) -> { check(x == 1); });
-            check(cf1.isDone() || cf2.isDone());
             try { check(cf3.join() == null); } catch (CompletionException x) { pass(); }
             check(cf3.isDone());
+            check(cf1.isDone() || cf2.isDone());
 
             cf1 = supplyAsync(() -> { throw new RuntimeException(); });
             cf2 = supplyAsync(() -> { throw new RuntimeException(); });
             cf3 = cf2.acceptEitherAsync(cf1, (x) -> { fail(); });
-            check(cf1.isDone() || cf2.isDone());
             checkCompletedExceptionally(cf3);
+            check(cf1.isDone() || cf2.isDone());
         } catch (Throwable t) { unexpected(t); }
 
         //----------------------------------------------------------------
         // runAfterEitherXXX tests
         //----------------------------------------------------------------

@@ -579,54 +579,54 @@
             CompletableFuture<Void> cf3;
             int before = atomicInt.get();
             CompletableFuture<Void> cf1 = runAsync(() -> { });
             CompletableFuture<Void> cf2 = runAsync(() -> { });
             cf3 = cf1.runAfterEither(cf2, () -> { atomicInt.incrementAndGet(); });
-            check(cf1.isDone() || cf2.isDone());
             checkCompletedNormally(cf3, null);
+            check(cf1.isDone() || cf2.isDone());
             check(atomicInt.get() == (before + 1));
 
             before = atomicInt.get();
             cf1 = runAsync(() -> { });
             cf2 = runAsync(() -> { });
             cf3 = cf1.runAfterEitherAsync(cf2, () -> { atomicInt.incrementAndGet(); });
-            check(cf1.isDone() || cf2.isDone());
             checkCompletedNormally(cf3, null);
+            check(cf1.isDone() || cf2.isDone());
             check(atomicInt.get() == (before + 1));
 
             before = atomicInt.get();
             cf1 = runAsync(() -> { });
             cf2 = runAsync(() -> { });
             cf3 = cf2.runAfterEitherAsync(cf1, () -> { atomicInt.incrementAndGet(); }, executor);
-            check(cf1.isDone() || cf2.isDone());
             checkCompletedNormally(cf3, null);
+            check(cf1.isDone() || cf2.isDone());
             check(atomicInt.get() == (before + 1));
 
             before = atomicInt.get();
             cf1 = runAsync(() -> { throw new RuntimeException(); });
             cf2 = runAsync(() -> { });
             cf3 = cf2.runAfterEither(cf1, () -> { atomicInt.incrementAndGet(); });
-            check(cf1.isDone() || cf2.isDone());
             try { check(cf3.join() == null); } catch (CompletionException x) { pass(); }
             check(cf3.isDone());
+            check(cf1.isDone() || cf2.isDone());
             check(atomicInt.get() == (before + 1));
 
             before = atomicInt.get();
             cf1 = runAsync(() -> { });
             cf2 = runAsync(() -> { throw new RuntimeException(); });
             cf3 = cf1.runAfterEitherAsync(cf2, () -> { atomicInt.incrementAndGet(); });
-            check(cf1.isDone() || cf2.isDone());
             try { check(cf3.join() == null); } catch (CompletionException x) { pass(); }
             check(cf3.isDone());
+            check(cf1.isDone() || cf2.isDone());
             check(atomicInt.get() == (before + 1));
 
             before = atomicInt.get();
             cf1 = runAsync(() -> { throw new RuntimeException(); });
             cf2 = runAsync(() -> { throw new RuntimeException(); });
             cf3 = cf2.runAfterEitherAsync(cf1, () -> { atomicInt.incrementAndGet(); }, executor);
-            check(cf1.isDone() || cf2.isDone());
             checkCompletedExceptionally(cf3);
+            check(cf1.isDone() || cf2.isDone());
             check(atomicInt.get() == before);
         } catch (Throwable t) { unexpected(t); }
 
         //----------------------------------------------------------------
         // thenComposeXXX tests

@@ -668,20 +668,20 @@
         } catch (Throwable t) { unexpected(t); }
 
         //----------------------------------------------------------------
         // anyOf tests
         //----------------------------------------------------------------
-        //try {
-        //    CompletableFuture<Object> cf3;
-        //    for (int k=0; k < 10; k++){
-        //        CompletableFuture<Integer> cf1 = supplyAsync(() -> 1);
-        //        CompletableFuture<Integer> cf2 = supplyAsync(() -> 2);
-        //        cf3 = CompletableFuture.anyOf(cf1, cf2);
-        //        check(cf1.isDone() || cf2.isDone());
-        //        checkCompletedNormally(cf3, new Object[] {1, 2});
-        //    }
-        //} catch (Throwable t) { unexpected(t); }
+        try {
+            CompletableFuture<Object> cf3;
+            for (int k=0; k < 10; k++){
+                CompletableFuture<Integer> cf1 = supplyAsync(() -> 1);
+                CompletableFuture<Integer> cf2 = supplyAsync(() -> 2);
+                cf3 = CompletableFuture.anyOf(cf1, cf2);
+                checkCompletedNormally(cf3, new Object[] {1, 2});
+                check(cf1.isDone() || cf2.isDone());
+            }
+        } catch (Throwable t) { unexpected(t); }
 
         //----------------------------------------------------------------
         // allOf tests
         //----------------------------------------------------------------
         try {