@Test
    public void testThenApplyOnSucceededFutureAndFunctionThrowsCompletionException() {
        KafkaFutureImpl<Integer> future = new KafkaFutureImpl<>();
        KafkaFuture<Integer> dependantFuture = future.thenApply(integer -> {
            throw new CompletionException(new RuntimeException("We require more vespene gas"));
        });
        future.complete(21);
        assertIsSuccessful(future);
        assertIsFailed(dependantFuture);
        awaitAndAssertResult(future, 21, null);
        Throwable cause = awaitAndAssertFailure(dependantFuture, CompletionException.class, "java.lang.RuntimeException: We require more vespene gas");
        assertInstanceOf(RuntimeException.class, cause.getCause());
        assertEquals(cause.getCause().getMessage(), "We require more vespene gas");
    }
Asserts that the given future is done, didn't fail and was cancelled.
clients/src/test/java/org/apache/kafka/common/KafkaFutureTest.java