@Test
    public void testCompleteFuturesViaCancellation() {
        KafkaFutureImpl<Integer> viaCancel = new KafkaFutureImpl<>();
        assertTrue(viaCancel.cancel(true));
        assertIsCancelled(viaCancel);
        awaitAndAssertCancelled(viaCancel, null);

        KafkaFutureImpl<Integer> viaCancellationException = new KafkaFutureImpl<>();
        assertTrue(viaCancellationException.completeExceptionally(new CancellationException("We require more vespene gas")));
        assertIsCancelled(viaCancellationException);
        awaitAndAssertCancelled(viaCancellationException, "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