diff --git a/test/java/util/concurrent/CompletableFuture/Basic.java b/test/java/util/concurrent/CompletableFuture/Basic.java index e8ed70658d97c6958d4ca289897da865206d42e3..a35c5f4ec558afc3149fb47a1c75bf4e5a374e8b 100644 --- a/test/java/util/concurrent/CompletableFuture/Basic.java +++ b/test/java/util/concurrent/CompletableFuture/Basic.java @@ -486,40 +486,40 @@ public class Basic { CompletableFuture cf1 = supplyAsync(() -> 1); CompletableFuture 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); } //---------------------------------------------------------------- @@ -531,45 +531,45 @@ public class Basic { CompletableFuture cf1 = supplyAsync(() -> 1); CompletableFuture 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); } //---------------------------------------------------------------- @@ -581,50 +581,50 @@ public class Basic { CompletableFuture cf1 = runAsync(() -> { }); CompletableFuture 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); } @@ -670,16 +670,16 @@ public class Basic { //---------------------------------------------------------------- // anyOf tests //---------------------------------------------------------------- - //try { - // CompletableFuture cf3; - // for (int k=0; k < 10; k++){ - // CompletableFuture cf1 = supplyAsync(() -> 1); - // CompletableFuture 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 cf3; + for (int k=0; k < 10; k++){ + CompletableFuture cf1 = supplyAsync(() -> 1); + CompletableFuture 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