@Test
    @SuppressWarnings("unchecked")
    public void testLeakCompletableFuture() throws Throwable {
        final KafkaFutureImpl<String> kfut = new KafkaFutureImpl<>();
        CompletableFuture<String> comfut = kfut.toCompletionStage().toCompletableFuture();
        assertThrows(UnsupportedOperationException.class, () -> comfut.complete(""));
        assertThrows(UnsupportedOperationException.class, () -> comfut.completeExceptionally(new RuntimeException()));
        // Annoyingly CompletableFuture added some more methods in Java 9, but the tests need to run on Java 8
        // so test reflectively
        if (Java.IS_JAVA9_COMPATIBLE) {
            Method completeOnTimeout = CompletableFuture.class.getDeclaredMethod("completeOnTimeout", Object.class, Long.TYPE, TimeUnit.class);
            assertThrows(UnsupportedOperationException.class, () -> invokeOrThrow(completeOnTimeout, comfut, "", 1L, TimeUnit.MILLISECONDS));

            Method completeAsync = CompletableFuture.class.getDeclaredMethod("completeAsync", Supplier.class);
            assertThrows(UnsupportedOperationException.class, () -> invokeOrThrow(completeAsync, comfut, (Supplier<String>) () -> ""));

            Method obtrudeValue = CompletableFuture.class.getDeclaredMethod("obtrudeValue", Object.class);
            assertThrows(UnsupportedOperationException.class, () -> invokeOrThrow(obtrudeValue, comfut, ""));

            Method obtrudeException = CompletableFuture.class.getDeclaredMethod("obtrudeException", Throwable.class);
            assertThrows(UnsupportedOperationException.class, () -> invokeOrThrow(obtrudeException, comfut, new RuntimeException()));

            // Check the CF from a minimal CompletionStage doesn't cause completion of the original KafkaFuture
            Method minimal = CompletableFuture.class.getDeclaredMethod("minimalCompletionStage");
            CompletionStage<String> cs = (CompletionStage<String>) invokeOrThrow(minimal, comfut);
            cs.toCompletableFuture().complete("");

            assertFalse(kfut.isDone());
            assertFalse(comfut.isDone());
        }
    }
Asserts that the given future is done, didn't fail and was cancelled.
clients/src/test/java/org/apache/kafka/common/KafkaFutureTest.java