Skip to content

Commit

Permalink
New test that verifies correct unwrapping of exceptions.
Browse files Browse the repository at this point in the history
Signed-off-by: Santiago Pericas-Geertsen <[email protected]>
  • Loading branch information
spericas committed Dec 3, 2024
1 parent 0fa93ea commit 9c53b52
Showing 1 changed file with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@

import static io.helidon.microprofile.cdi.ExecuteOn.ThreadType;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.fail;

class ExecuteOnAsyncTest {

Expand Down Expand Up @@ -109,6 +111,11 @@ CompletableFuture<Thread> eternallyBlocked() throws BrokenBarrierException, Inte
return CompletableFuture.completedFuture(Thread.currentThread());
}

@ExecuteOn(ThreadType.VIRTUAL)
CompletableFuture<Thread> alwaysFails() {
return CompletableFuture.failedFuture(new UnsupportedOperationException("Not supported"));
}

@Produces
@Named("my-executor")
ExecutorService myExecutor() {
Expand Down Expand Up @@ -173,6 +180,18 @@ void testEternallyBlocked() throws Exception {
() -> completableFuture.get(SHORT_TIMEOUT, TimeUnit.MILLISECONDS));
completableFuture.cancel(true);
assertThrows(CancellationException.class,
() -> completableFuture.get(SHORT_TIMEOUT, TimeUnit.MILLISECONDS));
() -> completableFuture.get(LONG_TIMEOUT, TimeUnit.MILLISECONDS));
}

@Test
void testAlwaysFails() {
CompletableFuture<Thread> completableFuture = bean.alwaysFails();
try {
completableFuture.get(LONG_TIMEOUT, TimeUnit.MILLISECONDS);
} catch (ExecutionException e) {
assertThat(e.getCause(), is(instanceOf(UnsupportedOperationException.class)));
} catch (Exception e) {
fail();
}
}
}

0 comments on commit 9c53b52

Please sign in to comment.