RpcStreamConnection extends RpcConnection { public void disconnect(final RpcPacketDispatcher dispatcher) throws ConnectionException { try { ShutdownHandler handler = new ShutdownHandler() { @Override public void shutdown(Socket theSocket) { if (nonNull(dispatcher)) { try { dispatcher.shutdown(RpcStreamConnection.this); } catch (ConnectionException e) { Log.exception(e); } } } }; if (isNotBlank(rsh)) { try { dispatcher.shutdown(RpcStreamConnection.this); } catch (ConnectionException e) { Log.exception(e); } topInputStream.close(); topOutputStream.close(); } else { if (nonNull(pool)) { pool.release(socket, handler); } else { handler.shutdown(socket); topInputStream.close(); topOutputStream.close(); if (nonNull(socket)) { socket.close(); } } } } catch (IOException exc) { throwConnectionException(exc, "RPC disconnection error: %s", exc.getLocalizedMessage()); } } RpcStreamConnection(String serverHost, int serverPort, Properties props,
                               ServerStats stats, P4Charset p4Charset, boolean secure); private  RpcStreamConnection(String serverHost, int serverPort, Properties props,
            ServerStats stats, P4Charset p4Charset, Socket socket, boolean secure); private  RpcStreamConnection(String serverHost, int serverPort, Properties props,
            ServerStats stats, P4Charset p4Charset, Socket socket, RpcSocketPool pool, boolean secure);  RpcStreamConnection(String serverHost, int serverPort, Properties props,
            ServerStats stats, P4Charset p4Charset, Socket socket, RpcSocketPool pool, boolean secure,
            String rsh); String getServerIpPort(); String getClientIpPort(); void disconnect(final RpcPacketDispatcher dispatcher); RpcPacket getRpcPacket(); RpcPacket getRpcPacket(final RpcPacketFieldRule fieldRule,
            final IFilterCallback filterCallback); int getSystemRecvBufferSize(); int getSystemSendBufferSize(); long putRpcPackets(@Nonnull RpcPacket[] packets); long putRpcPacket(@Nonnull RpcPacket packet); @Override void useConnectionCompression(); static final String TRACE_PREFIX; }
@Test public void disconnect_non_socketPool_and_null_rsh() throws Exception { RpcPacketDispatcher dispatcher = mock(RpcPacketDispatcher.class); mockConnection.disconnect(dispatcher); verify(rpcSocketPool, times(1)).release(eq(socket), any(RpcSocketPool.ShutdownHandler.class)); }