Add test for exceptions in FutureUtils.transformAsync. (#17106)

Adds an additional test case to FutureUtilsTest.
This commit is contained in:
Gian Merlino 2024-09-18 16:08:47 -07:00 committed by GitHub
parent ca0cb64ee8
commit 2d2882cdfe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 26 additions and 0 deletions

View File

@ -243,6 +243,32 @@ public class FutureUtilsTest
);
}
@Test
public void test_transformAsync_exceptionInFunction()
{
final ListenableFuture<Object> 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
{