@Test
    public void testCompleteFuturesExceptionally() {
        KafkaFutureImpl<Integer> futureFail = new KafkaFutureImpl<>();
        assertTrue(futureFail.completeExceptionally(new RuntimeException("We require more vespene gas")));
        assertIsFailed(futureFail);
        assertFalse(futureFail.completeExceptionally(new RuntimeException("We require more minerals")));
        assertFalse(futureFail.cancel(true));

        ExecutionException executionException = assertThrows(ExecutionException.class, futureFail::get);
        assertEquals(RuntimeException.class, executionException.getCause().getClass());
        assertEquals("We require more vespene gas", executionException.getCause().getMessage());

        KafkaFutureImpl<Integer> tricky1 = new KafkaFutureImpl<>();
        assertTrue(tricky1.completeExceptionally(new CompletionException(new CancellationException())));
        assertIsFailed(tricky1);
        awaitAndAssertFailure(tricky1, CompletionException.class, "java.util.concurrent.CancellationException");
    }
Asserts that the given future is done, didn't fail and was cancelled.
clients/src/test/java/org/apache/kafka/common/KafkaFutureTest.java