RpcStreamConnection extends RpcConnection { @Override public void useConnectionCompression() throws ConnectionException { if (!usingCompression) { super.useConnectionCompression(); try { topOutputStream.flush(); putRpcPacket(RpcPacket.constructRpcPacket(RpcFunctionSpec.PROTOCOL_COMPRESS2, "compress2", null, null)); topOutputStream.flush(); topOutputStream = new RpcGZIPOutputStream(outputStream); topInputStream = new RpcGZIPInputStream(inputStream); } catch (IOException exc) { Log.error("I/O exception encountered while setting up GZIP streaming: %s", exc.getLocalizedMessage()); Log.exception(exc); throwConnectionException(exc, "unable to set up client compression streaming to Perforce server: %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 given_usingCompression_isFalse_and_without_exception_when_useConnectionCompression() throws Exception { mockConnection.setUsingCompression(false); mockConnection.useConnectionCompression(); verify(topOutputStream, times(3)).flush(); }
@Test(expected=ConnectionException.class) public void given_usingCompression_isFalse_and_with_exception_when_useConnectionCompression() throws Exception { mockConnection.setUsingCompression(false); doThrow(new IOException()).when(topOutputStream).flush(); mockConnection.useConnectionCompression(); }