ServerTcpTransportHandler extends TransportHandler { @Override public void closeClientConnection() throws IOException { if (socket != null && !socket.isClosed()) { socket.close(); } } ServerTcpTransportHandler(long timeout, int port);  ServerTcpTransportHandler(long timeout, ServerSocket serverSocket);  ServerTcpTransportHandler(long timeout, Socket socket); void closeServerSocket(); @Override void closeConnection(); @Override void initialize(); @Override boolean isClosed(); ServerSocket getServerSocket(); @Override void closeClientConnection(); int getPort();  }
@Test public void testCloseClientConnection() throws IOException, InterruptedException, ExecutionException { handler.closeClientConnection(); SocketOpenerCallable callable = new SocketOpenerCallable("localhost", handler.getPort()); FutureTask task = new FutureTask(callable); Thread t = new Thread(task); t.start(); handler.initialize(); assertTrue(handler.isInitialized()); Socket socket = (Socket) task.get(); assertNotNull(socket); assertTrue(socket.isConnected()); try { socket.getOutputStream().write(123); socket.getOutputStream().flush(); } catch (IOException E) { fail(); } handler.closeServerSocket(); try { socket.getOutputStream().write(123); socket.getOutputStream().flush(); } catch (IOException E) { fail(); } handler.closeClientConnection(); Thread.sleep(50); try { socket.getOutputStream().write(123); socket.getOutputStream().flush(); fail(); } catch (IOException E) { } }