@Test
    public void testWhenCompleteOnSucceededFuture() throws Throwable {
        KafkaFutureImpl<Integer> future = new KafkaFutureImpl<>();
        Throwable[] err = new Throwable[1];
        boolean[] ran = {false};
        KafkaFuture<Integer> dependantFuture = future.whenComplete((integer, ex) -> {
            ran[0] = true;
            try {
                assertEquals(Integer.valueOf(21), integer);
                if (ex != null) {
                    throw ex;
                }
            } catch (Throwable e) {
                err[0] = e;
            }
        });
        assertFalse(dependantFuture.isDone());
        assertTrue(future.complete(21));
        assertTrue(ran[0]);
        if (err[0] != null) {
            throw err[0];
        }
    }
Asserts that the given future is done, didn't fail and was cancelled.
clients/src/test/java/org/apache/kafka/common/KafkaFutureTest.java