This is an automated email from the ASF dual-hosted git repository. klund pushed a commit to branch support/1.13 in repository https://gitbox.apache.org/repos/asf/geode.git
commit 7285e44aee247af09e64929f383c1007d0a693c3 Author: Kirk Lund <[email protected]> AuthorDate: Thu May 14 14:25:31 2020 -0700 GEODE-8126: Add ExecutionException tests to ExecutorServiceRuleTest (#5113) (cherry picked from commit 2842ce027f78a04386ffbfae6c9a6a0d73d47e05) --- .../test/junit/rules/ExecutorServiceRuleTest.java | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/geode-junit/src/test/java/org/apache/geode/test/junit/rules/ExecutorServiceRuleTest.java b/geode-junit/src/test/java/org/apache/geode/test/junit/rules/ExecutorServiceRuleTest.java index 4c6f146..e522cdd 100644 --- a/geode-junit/src/test/java/org/apache/geode/test/junit/rules/ExecutorServiceRuleTest.java +++ b/geode-junit/src/test/java/org/apache/geode/test/junit/rules/ExecutorServiceRuleTest.java @@ -17,8 +17,10 @@ package org.apache.geode.test.junit.rules; import static java.util.concurrent.TimeUnit.MILLISECONDS; import static org.apache.geode.test.awaitility.GeodeAwaitility.await; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Future; import java.util.concurrent.TimeoutException; @@ -110,6 +112,17 @@ public class ExecutorServiceRuleTest { assertThat(failure.getException()).isInstanceOf(TimeoutException.class); } + @Test + public void futureRethrowsFailureWrappedInExecutionException() { + Result result = TestRunner.runTest(FutureRethrows.class); + assertThat(result.wasSuccessful()).isFalse(); + assertThat(result.getFailures()).hasSize(1); + Failure failure = result.getFailures().get(0); + assertThat(failure.getException()) + .isInstanceOf(ExecutionException.class) + .hasRootCauseInstanceOf(AssertionError.class); + } + private static void awaitLatch(CountDownLatch latch) { await().untilAsserted(() -> assertThat(latch.getCount()) .as("Latch failed to countDown within timeout").isZero()); @@ -172,4 +185,17 @@ public class ExecutorServiceRuleTest { future.get(1, MILLISECONDS); } } + + public static class FutureRethrows extends HasExecutorServiceRule { + + @Test + public void doTest() throws Exception { + Future<Void> future = executorServiceRule.runAsync(() -> { + fail("Fails"); + }); + + // this is expected to throw + future.get(); + } + } }
