@Test public void testReadResponse() throws Exception { System.out.println("readResponse"); SocketChannelEmul sock = new SocketChannelEmul(); sock.setBytesToRead(ByteBuffer.wrap("test".getBytes())); SampleResult res = new SampleResult(); res.sampleStart(); byte[] expResult = "test".getBytes(); byte[] result = instance.readResponse(sock, res); assertEquals(expResult.length, result.length); }
protected byte[] readResponse(SocketChannel channel, SampleResult res) throws IOException { ByteArrayOutputStream response = new ByteArrayOutputStream(); ByteBuffer recvBuf = getRecvBuf(); recvBuf.clear(); boolean firstPack = true; int cnt; int responseSize = 0; if (log.isDebugEnabled()) { log.debug("Start reading response"); } try { while ((cnt = channel.read(recvBuf)) != -1) { responseSize += cnt; if (firstPack) { res.latencyEnd(); firstPack = false; } recvBuf.flip(); if (response.size() <= recvDataLimit) { byte[] bytes = new byte[cnt]; recvBuf.get(bytes); response.write(bytes); } recvBuf.clear(); } if (response.size() < 1) { log.warn("Read no bytes from socket, seems it was closed. Let it be so."); channel.close(); } } catch (IOException ex) { channel.close(); throw ex; } if (log.isDebugEnabled()) { log.debug("Done reading response"); } res.sampleEnd(); if (!isUseKeepAlive()) { channel.close(); } res.setBytes(responseSize); return response.toByteArray(); }
HTTPRawSampler extends AbstractIPSampler { protected byte[] readResponse(SocketChannel channel, SampleResult res) throws IOException { ByteArrayOutputStream response = new ByteArrayOutputStream(); ByteBuffer recvBuf = getRecvBuf(); recvBuf.clear(); boolean firstPack = true; int cnt; int responseSize = 0; if (log.isDebugEnabled()) { log.debug("Start reading response"); } try { while ((cnt = channel.read(recvBuf)) != -1) { responseSize += cnt; if (firstPack) { res.latencyEnd(); firstPack = false; } recvBuf.flip(); if (response.size() <= recvDataLimit) { byte[] bytes = new byte[cnt]; recvBuf.get(bytes); response.write(bytes); } recvBuf.clear(); } if (response.size() < 1) { log.warn("Read no bytes from socket, seems it was closed. Let it be so."); channel.close(); } } catch (IOException ex) { channel.close(); throw ex; } if (log.isDebugEnabled()) { log.debug("Done reading response"); } res.sampleEnd(); if (!isUseKeepAlive()) { channel.close(); } res.setBytes(responseSize); return response.toByteArray(); } }
HTTPRawSampler extends AbstractIPSampler { protected byte[] readResponse(SocketChannel channel, SampleResult res) throws IOException { ByteArrayOutputStream response = new ByteArrayOutputStream(); ByteBuffer recvBuf = getRecvBuf(); recvBuf.clear(); boolean firstPack = true; int cnt; int responseSize = 0; if (log.isDebugEnabled()) { log.debug("Start reading response"); } try { while ((cnt = channel.read(recvBuf)) != -1) { responseSize += cnt; if (firstPack) { res.latencyEnd(); firstPack = false; } recvBuf.flip(); if (response.size() <= recvDataLimit) { byte[] bytes = new byte[cnt]; recvBuf.get(bytes); response.write(bytes); } recvBuf.clear(); } if (response.size() < 1) { log.warn("Read no bytes from socket, seems it was closed. Let it be so."); channel.close(); } } catch (IOException ex) { channel.close(); throw ex; } if (log.isDebugEnabled()) { log.debug("Done reading response"); } res.sampleEnd(); if (!isUseKeepAlive()) { channel.close(); } res.setBytes(responseSize); return response.toByteArray(); } HTTPRawSampler(); }
HTTPRawSampler extends AbstractIPSampler { protected byte[] readResponse(SocketChannel channel, SampleResult res) throws IOException { ByteArrayOutputStream response = new ByteArrayOutputStream(); ByteBuffer recvBuf = getRecvBuf(); recvBuf.clear(); boolean firstPack = true; int cnt; int responseSize = 0; if (log.isDebugEnabled()) { log.debug("Start reading response"); } try { while ((cnt = channel.read(recvBuf)) != -1) { responseSize += cnt; if (firstPack) { res.latencyEnd(); firstPack = false; } recvBuf.flip(); if (response.size() <= recvDataLimit) { byte[] bytes = new byte[cnt]; recvBuf.get(bytes); response.write(bytes); } recvBuf.clear(); } if (response.size() < 1) { log.warn("Read no bytes from socket, seems it was closed. Let it be so."); channel.close(); } } catch (IOException ex) { channel.close(); throw ex; } if (log.isDebugEnabled()) { log.debug("Done reading response"); } res.sampleEnd(); if (!isUseKeepAlive()) { channel.close(); } res.setBytes(responseSize); return response.toByteArray(); } HTTPRawSampler(); @Override SampleResult sample(Entry entry); boolean isUseKeepAlive(); void setUseKeepAlive(boolean selected); boolean isParseResult(); void setParseResult(boolean selected); String getFileToSend(); void setFileToSend(String text); @Override boolean interrupt(); }
HTTPRawSampler extends AbstractIPSampler { protected byte[] readResponse(SocketChannel channel, SampleResult res) throws IOException { ByteArrayOutputStream response = new ByteArrayOutputStream(); ByteBuffer recvBuf = getRecvBuf(); recvBuf.clear(); boolean firstPack = true; int cnt; int responseSize = 0; if (log.isDebugEnabled()) { log.debug("Start reading response"); } try { while ((cnt = channel.read(recvBuf)) != -1) { responseSize += cnt; if (firstPack) { res.latencyEnd(); firstPack = false; } recvBuf.flip(); if (response.size() <= recvDataLimit) { byte[] bytes = new byte[cnt]; recvBuf.get(bytes); response.write(bytes); } recvBuf.clear(); } if (response.size() < 1) { log.warn("Read no bytes from socket, seems it was closed. Let it be so."); channel.close(); } } catch (IOException ex) { channel.close(); throw ex; } if (log.isDebugEnabled()) { log.debug("Done reading response"); } res.sampleEnd(); if (!isUseKeepAlive()) { channel.close(); } res.setBytes(responseSize); return response.toByteArray(); } HTTPRawSampler(); @Override SampleResult sample(Entry entry); boolean isUseKeepAlive(); void setUseKeepAlive(boolean selected); boolean isParseResult(); void setParseResult(boolean selected); String getFileToSend(); void setFileToSend(String text); @Override boolean interrupt();  }