提交 347aa69d 编写于 作者: P psandoz

8072030: Race condition in ThenComposeExceptionTest.java

Reviewed-by: chegar
上级 979f8b54
...@@ -36,7 +36,7 @@ import java.util.function.Consumer; ...@@ -36,7 +36,7 @@ import java.util.function.Consumer;
/** /**
* @test * @test
* @bug 8068432 * @bug 8068432 8072030
* @run testng ThenComposeExceptionTest * @run testng ThenComposeExceptionTest
* @summary Test that CompletableFuture.thenCompose works correctly if the * @summary Test that CompletableFuture.thenCompose works correctly if the
* composing future completes exceptionally * composing future completes exceptionally
...@@ -92,7 +92,8 @@ public class ThenComposeExceptionTest { ...@@ -92,7 +92,8 @@ public class ThenComposeExceptionTest {
Assert.assertNotSame(f_thenCompose, fe, "Composed CompletableFuture returned directly"); Assert.assertNotSame(f_thenCompose, fe, "Composed CompletableFuture returned directly");
AtomicReference<Throwable> eOnWhenComplete = new AtomicReference<>(); AtomicReference<Throwable> eOnWhenComplete = new AtomicReference<>();
f_thenCompose.whenComplete((r, e) -> eOnWhenComplete.set(e)); CompletableFuture<String> f_whenComplete = f_thenCompose.
whenComplete((r, e) -> eOnWhenComplete.set(e));
afterAction.accept(fe); afterAction.accept(fe);
...@@ -103,10 +104,20 @@ public class ThenComposeExceptionTest { ...@@ -103,10 +104,20 @@ public class ThenComposeExceptionTest {
catch (Throwable t) { catch (Throwable t) {
eOnJoined = t; eOnJoined = t;
} }
Assert.assertTrue(eOnJoined instanceof CompletionException,
"Incorrect exception reported when joined on thenCompose: " + eOnJoined);
Assert.assertTrue(eOnWhenComplete.get() instanceof CompletionException, // Need to wait for f_whenComplete to complete to avoid
"Incorrect exception reported on whenComplete"); // race condition when updating eOnWhenComplete
eOnJoined = null;
try {
f_whenComplete.join();
} catch (Throwable t) {
eOnJoined = t;
}
Assert.assertTrue(eOnJoined instanceof CompletionException, Assert.assertTrue(eOnJoined instanceof CompletionException,
"Incorrect exception reported when joined"); "Incorrect exception reported when joined on whenComplete: " + eOnJoined);
Assert.assertTrue(eOnWhenComplete.get() instanceof CompletionException,
"Incorrect exception passed to whenComplete: " + eOnWhenComplete.get());
} }
} }
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册