public static CompletableFuture<Channel> toCompletableFuture(ChannelFuture channelFuture) {
        Objects.requireNonNull(channelFuture, "channelFuture cannot be null");

        CompletableFuture<Channel> adapter = new CompletableFuture<>();
        if (channelFuture.isDone()) {
            if (channelFuture.isSuccess()) {
                adapter.complete(channelFuture.channel());
            } else {
                adapter.completeExceptionally(channelFuture.cause());
            }
        } else {
            channelFuture.addListener((ChannelFuture cf) -> {
                if (cf.isSuccess()) {
                    adapter.complete(cf.channel());
                } else {
                    adapter.completeExceptionally(cf.cause());
                }
            });
        }
        return adapter;
    }
@Test
    public void toCompletableFuture_shouldCompleteExceptionally_channelFutureCompletedAfter() throws Exception {
        CompletableFuture<Channel> future = ChannelFutures.toCompletableFuture(channelFuture);
        Assert.assertFalse(future.isDone());

        Exception failure = new Exception();
        channelFuture.setFailure(failure);
        try {
            future.get(1, TimeUnit.SECONDS);
            Assert.fail("Should complete exceptionally");
        } catch (ExecutionException e) {
            Assert.assertSame(e.getCause(), failure);
        }
    }