RpcStreamConnection extends RpcConnection { private void reallocateSendBufferInPutPacketIfRunOut(@Nonnull final RpcPacketSupplier supplier, @Nonnull final byte[] fieldBytes, final int reallocateIncrement) { byte[] sendBytes = supplier.sendBytes(); int sendPos = supplier.sendPos(); byte[] newSendBytes = sendBytes; if ((sendBytes.length - sendPos) <= fieldBytes.length) { stats.bufferCompacts.getAndIncrement(); int newBytesLength = sendBytes.length + fieldBytes.length + reallocateIncrement; newSendBytes = new byte[newBytesLength]; System.arraycopy(sendBytes, 0, newSendBytes, 0, sendPos); } System.arraycopy(fieldBytes, 0, newSendBytes, sendPos, fieldBytes.length); supplier.sendBytes(newSendBytes).sendPos(sendPos + fieldBytes.length); } RpcStreamConnection(String serverHost, int serverPort, Properties props,
            ServerStats stats, Charset charset);  RpcStreamConnection(String serverHost, int serverPort, Properties props,
            ServerStats stats, Charset charset, boolean secure);  RpcStreamConnection(String serverHost, int serverPort, Properties props,
            ServerStats stats, Charset charset, Socket socket);  RpcStreamConnection(String serverHost, int serverPort, Properties props,
            ServerStats stats, Charset charset, RpcSocketPool pool);  RpcStreamConnection(String serverHost, int serverPort, Properties props,
            ServerStats stats, Charset charset, Socket socket, boolean secure);  RpcStreamConnection(String serverHost, int serverPort, Properties props,
            ServerStats stats, Charset charset, RpcSocketPool pool, boolean secure);  RpcStreamConnection(String serverHost, int serverPort, Properties props,
            ServerStats stats, Charset charset, Socket socket, RpcSocketPool pool, boolean secure);  RpcStreamConnection(String serverHost, int serverPort, Properties props,
            ServerStats stats, Charset charset, 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 reallocateSendBufferInPutPacketIfRunOut() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { RpcStreamConnection.RpcPacketSupplier supplier = createMockRpcPacketSupplier(); byte[] fieldBytes = new byte[] { 'a', 'b', 'c' }; Method reallocateSendBufferInPutPacketIfRunOut = getPrivateMethod(RpcStreamConnection.class, "reallocateSendBufferInPutPacketIfRunOut", RpcStreamConnection.RpcPacketSupplier.class, byte[].class, int.class); reallocateSendBufferInPutPacketIfRunOut.invoke(mockConnection, supplier, fieldBytes, 1); verifyMockRpcPacketSupplier(supplier, 1); }