@Test
    public void testWhenCompleteOnFailedFutureAndConsumerThrows() {
        KafkaFutureImpl<Integer> future = new KafkaFutureImpl<>();
        boolean[] ran = {false};
        KafkaFuture<Integer> dependantFuture = future.whenComplete((integer, ex) -> {
            ran[0] = true;
            throw new RuntimeException("We require more minerals");
        });
        assertFalse(dependantFuture.isDone());
        assertTrue(future.completeExceptionally(new RuntimeException("We require more vespene gas")));
        assertIsFailed(future);
        assertTrue(ran[0]);
        assertIsFailed(dependantFuture);
        awaitAndAssertFailure(dependantFuture, RuntimeException.class, "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