private void waitForBytesBuffered(Selector selector, String node) throws Exception {
        TestUtils.waitForCondition(() -> {
            try {
                selector.poll(0L);
                return selector.channel(node).hasBytesBuffered();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }, 2000L, "Failed to reach socket state with bytes buffered");
    }
A set of tests for the selector. These use a test harness that runs a simple socket server that echos back responses.
clients/src/test/java/org/apache/kafka/common/network/SslSelectorTest.java