@Test
public void testDeadline() {

    AsyncLoadingCache<String, Integer> cachedResult = new AsyncLoadingCache<>(100, 10);
    final Supplier<CompletableFuture<Integer>> tooLateSupplier = () -> MoreAsyncUtil.delayedFuture(1, TimeUnit.SECONDS)
            .thenApply(ignore -> 2);
    final Supplier<CompletableFuture<Integer>> onTimeSupplier = () -> MoreAsyncUtil.delayedFuture(5, TimeUnit.MILLISECONDS)
            .thenApply(ignore -> 3);
    try {
        cachedResult.orElseGet("a-key", tooLateSupplier).join();
        fail("should throw CompletionException");
    } catch (CompletionException ex) {
        assertThat("it is caused by a deadline exception", ex.getCause(),
                is(instanceOf(DeadlineExceededException.class)));
        assertThat(ex.getCause(), hasMessageContaining("deadline exceeded"));
    }
    assertThat("we get the value before the deadline", cachedResult.orElseGet("a-key", onTimeSupplier).join(), is(3));
}