RpcStreamConnection extends RpcConnection { RpcStreamConnection socket(Socket socket) { this.socket = socket; return this; } 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 initSocketBasedServer_orignal_socket_isNull() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, IOException { Method initSocketBasedServer = getPrivateMethod(RpcStreamConnection.class, "initSocketBasedServer"); mockConnection.socket(null); initSocketBasedServer.invoke(mockConnection); verify(rpcSocketPool).acquire(); }
@Test public void initSocketBasedServer_with_exceptions() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, IOException { Method initSocketBasedServer = getPrivateMethod(RpcStreamConnection.class, "initSocketBasedServer"); mockConnection.socket(null); reset(rpcSocketPool); doThrow(UnknownHostException.class).when(rpcSocketPool).acquire(); assertExceptionFromMethod(mockConnection, initSocketBasedServer, UnknownHostException.class); reset(rpcSocketPool); doThrow(IOException.class).when(rpcSocketPool).acquire(); assertExceptionFromMethod(mockConnection, initSocketBasedServer, IOException.class); reset(rpcSocketPool); doThrow(Throwable.class).when(rpcSocketPool).acquire(); assertExceptionFromMethod(mockConnection, initSocketBasedServer, Throwable.class); }
@Test(expected=InvocationTargetException.class) public void initRpcSocketInputAndOutputStreamIfSocketBasedServer_with_exception() throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { Method initRpcSocketInputAndOutputStreamIfSocketBasedServer = getPrivateMethod(RpcStreamConnection.class, "initRpcSocketInputAndOutputStreamIfSocketBasedServer"); mockConnection.socket(null); initRpcSocketInputAndOutputStreamIfSocketBasedServer.invoke(mockConnection); }
@Test public void initSSL_with_exceptions() throws IllegalAccessException, IllegalArgumentException { Method initSSL = getPrivateMethod(RpcStreamConnection.class, "initSSL"); SSLSocket sslSocket = mock(SSLSocket.class); doThrow(CertificateExpiredException.class).when(sslSocket).getSession(); mockConnection.socket(sslSocket); assertExceptionFromMethod(mockConnection, initSSL, CertificateExpiredException.class); reset(sslSocket); doThrow(CertificateNotYetValidException.class).when(sslSocket).getSession(); assertExceptionFromMethod(mockConnection, initSSL, CertificateNotYetValidException.class); reset(sslSocket); doThrow(NoSuchAlgorithmException.class).when(sslSocket).getSession(); assertExceptionFromMethod(mockConnection, initSSL, NoSuchAlgorithmException.class); reset(sslSocket); doThrow(IOException.class).when(sslSocket).getSession(); assertExceptionFromMethod(mockConnection, initSSL, IOException.class); }