ServerTCPNonBlockingTransportHandler extends TransportHandler { @Override public void closeClientConnection() throws IOException { if (clientSocket != null && !clientSocket.isClosed()) { clientSocket.close(); } } ServerTCPNonBlockingTransportHandler(long timeout, int port); @Override void closeConnection(); @Override void initialize(); void recheck(); void recheck(long timeout); @Override boolean isClosed(); @Override void closeClientConnection(); int getPort();  }
@Test public void testCloseClientConnection() throws IOException { handler.initialize(); Socket socket = new Socket(); socket.setTcpNoDelay(true); socket.connect(new InetSocketAddress("localhost", handler.getPort())); handler.recheck(1000); Exception ex = null; assertNotNull(socket); assertTrue(socket.isConnected()); handler.closeClientConnection(); try { assertTrue(socket.getInputStream().read() == -1); } catch (IOException E) { ex = E; fail(); } assertFalse(handler.isClosed()); handler.closeConnection(); }