public void disconnect(String node, boolean allowLateResponses) {
        long now = time.milliseconds();
        Iterator<ClientRequest> iter = requests.iterator();
        while (iter.hasNext()) {
            ClientRequest request = iter.next();
            if (request.destination().equals(node)) {
                short version = request.requestBuilder().latestAllowedVersion();
                responses.add(new ClientResponse(request.makeHeader(version), request.callback(), request.destination(),
                        request.createdTimeMs(), now, true, null, null, null));
                if (!allowLateResponses)
                    iter.remove();
            }
        }
        CompletableFuture<String> curDisconnectFuture = disconnectFuture;
        if (curDisconnectFuture != null) {
            curDisconnectFuture.complete(node);
        }
        connectionState(node).disconnect();
    }
A mock network client for use testing code
clients/src/test/java/org/apache/kafka/clients/MockClient.java