From 2d2882cdfeb47c20bc6e1435abda268114e913b5 Mon Sep 17 00:00:00 2001 From: Gian Merlino Date: Wed, 18 Sep 2024 16:08:47 -0700 Subject: [PATCH] Add test for exceptions in FutureUtils.transformAsync. (#17106) Adds an additional test case to FutureUtilsTest. --- .../druid/common/guava/FutureUtilsTest.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/processing/src/test/java/org/apache/druid/common/guava/FutureUtilsTest.java b/processing/src/test/java/org/apache/druid/common/guava/FutureUtilsTest.java index 52be34e78f9..9c261c7935f 100644 --- a/processing/src/test/java/org/apache/druid/common/guava/FutureUtilsTest.java +++ b/processing/src/test/java/org/apache/druid/common/guava/FutureUtilsTest.java @@ -243,6 +243,32 @@ public class FutureUtilsTest ); } + @Test + public void test_transformAsync_exceptionInFunction() + { + final ListenableFuture f = FutureUtils.transformAsync( + Futures.immediateFuture("x"), + s -> { + throw new ISE("error!"); + } + ); + + final ExecutionException e = Assert.assertThrows( + ExecutionException.class, + f::get + ); + + MatcherAssert.assertThat( + e, + ThrowableCauseMatcher.hasCause(CoreMatchers.instanceOf(ISE.class)) + ); + + MatcherAssert.assertThat( + e, + ThrowableCauseMatcher.hasCause(ThrowableMessageMatcher.hasMessage(CoreMatchers.containsString("error!"))) + ); + } + @Test public void test_coalesce_allOk() throws Exception {