@Test
    public void testServerDisconnect() throws Exception {
        final String node = "0";

        // connect and do a simple request
        blockingConnect(node);
        assertEquals("hello", blockingRequest(node, "hello"));

        KafkaChannel channel = selector.channel(node);

        // disconnect
        this.server.closeConnections();
        waitForCondition(() -> {
            try {
                selector.poll(1000L);
                return selector.disconnected().containsKey(node);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }, 5000, "Failed to observe disconnected node in disconnected set");

        assertNull(channel.selectionKey().attachment());

        // reconnect and do another request
        blockingConnect(node);
        assertEquals("hello", blockingRequest(node, "hello"));
    }
Validate that when the server disconnects, a client send ends up with that node in the disconnected list.
clients/src/test/java/org/apache/kafka/common/network/SelectorTest.java