@Test
    public void testWhenCompleteOnFailedFuture() {
        KafkaFutureImpl<Integer> future = new KafkaFutureImpl<>();
        Throwable[] err = new Throwable[1];
        boolean[] ran = {false};
        KafkaFuture<Integer> dependantFuture = future.whenComplete((integer, ex) -> {
            ran[0] = true;
            err[0] = ex;
            if (integer != null) {
                err[0] = new AssertionError();
            }
        });
        assertFalse(dependantFuture.isDone());
        RuntimeException ex = new RuntimeException("We require more vespene gas");
        assertTrue(future.completeExceptionally(ex));
        assertTrue(ran[0]);
        assertEquals(err[0], ex);
    }
Asserts that the given future is done, didn't fail and was cancelled.
clients/src/test/java/org/apache/kafka/common/KafkaFutureTest.java