@Test public void testSlowResponse() throws Exception { String response = "{\"jsonrpc\":\"2.0\",\"id\":1," + "\"result\":\"Geth/v1.5.4-stable-b70acf3c/darwin/go1.7.3\"}\n"; unixDomainSocket = new UnixDomainSocket(reader, writer, response.length()); final LinkedList<String> segments = new LinkedList<>(); segments.add(response.substring(0, 50)); segments.add(response.substring(50)); doAnswer(invocation -> { String segment = segments.poll(); if (segment == null) { return 0; } else { Object[] args = invocation.getArguments(); ((CharBuffer) args[0]).append(segment); return segment.length(); } }).when(reader).read(any(CharBuffer.class)); IpcService ipcService = new IpcService() { @Override protected IOFacade getIO() { return unixDomainSocket; } }; ipcService.send(new Request(), Web3ClientVersion.class); }
@Override public String read() throws IOException { CharBuffer response = CharBuffer.allocate(bufferSize); String result = ""; do { response.clear(); reader.read(response); result += new String(response.array(), response.arrayOffset(), response.position()); } while (response.get(response.position() - 1) != '\n'); return result; }
UnixDomainSocket implements IOFacade { @Override public String read() throws IOException { CharBuffer response = CharBuffer.allocate(bufferSize); String result = ""; do { response.clear(); reader.read(response); result += new String(response.array(), response.arrayOffset(), response.position()); } while (response.get(response.position() - 1) != '\n'); return result; } }
UnixDomainSocket implements IOFacade { @Override public String read() throws IOException { CharBuffer response = CharBuffer.allocate(bufferSize); String result = ""; do { response.clear(); reader.read(response); result += new String(response.array(), response.arrayOffset(), response.position()); } while (response.get(response.position() - 1) != '\n'); return result; } UnixDomainSocket(String ipcSocketPath);  UnixDomainSocket(String ipcSocketPath, int bufferSize);   UnixDomainSocket(InputStreamReader reader, PrintWriter writer, int bufferSize); }
UnixDomainSocket implements IOFacade { @Override public String read() throws IOException { CharBuffer response = CharBuffer.allocate(bufferSize); String result = ""; do { response.clear(); reader.read(response); result += new String(response.array(), response.arrayOffset(), response.position()); } while (response.get(response.position() - 1) != '\n'); return result; } UnixDomainSocket(String ipcSocketPath);  UnixDomainSocket(String ipcSocketPath, int bufferSize);   UnixDomainSocket(InputStreamReader reader, PrintWriter writer, int bufferSize); @Override void write(String payload); @Override String read(); @Override void close(); }
UnixDomainSocket implements IOFacade { @Override public String read() throws IOException { CharBuffer response = CharBuffer.allocate(bufferSize); String result = ""; do { response.clear(); reader.read(response); result += new String(response.array(), response.arrayOffset(), response.position()); } while (response.get(response.position() - 1) != '\n'); return result; } UnixDomainSocket(String ipcSocketPath);  UnixDomainSocket(String ipcSocketPath, int bufferSize);   UnixDomainSocket(InputStreamReader reader, PrintWriter writer, int bufferSize); @Override void write(String payload); @Override String read(); @Override void close();  }