提交 d61a0a4b 编写于 作者: C chegar

8011799: CompletableFuture/Basic.java fails intermittently

Reviewed-by: martin, alanb
上级 72e038be
......@@ -486,40 +486,40 @@ public class Basic {
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); }
//----------------------------------------------------------------
......@@ -531,45 +531,45 @@ public class Basic {
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); }
//----------------------------------------------------------------
......@@ -581,50 +581,50 @@ public class Basic {
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); }
......@@ -670,16 +670,16 @@ public class Basic {
//----------------------------------------------------------------
// 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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册