private void sendServerHello(final SSLEngine sslEngine) throws IOException {
        final SSLSession session = sslEngine.getSession();
        final ByteBuffer serverAppData = ByteBuffer.allocate(session.getApplicationBufferSize());
        final ByteBuffer serverNetData = ByteBuffer.allocate(session.getPacketBufferSize());
        while (sslEngine.getHandshakeStatus() == HandshakeStatus.NEED_WRAP) {
            serverAppData.flip();
            final Status status = sslEngine.wrap(serverAppData, serverNetData).getStatus();
            if (status != Status.OK) {
                throw new RuntimeException("Bad status while wrapping data: " + status);
            }
            serverNetData.flip();
            socket.write(serverNetData);
            serverNetData.compact();
            if (sslEngine.getHandshakeStatus() == HandshakeStatus.NEED_TASK) {
                sslEngine.getDelegatedTask().run();
            }
        }
    }
This test server accepts a single TLS connection request, which will then time out. The server can run in two modes.
If {@code sendServerHello} is false, the Client Hello message will be swallowed, and the client will time out while
waiting for the Server Hello record. Else, the server will respond to the Client Hello with a Server Hello, and the
client's connection attempt will subsequently time out while waiting for the Change Cipher Spec record from the
server.
httpclient5-testing/src/test/java/org/apache/hc/client5/testing/tls/TlsHandshakeTimeoutServer.java