ok2c commented on code in PR #648: URL: https://github.com/apache/httpcomponents-client/pull/648#discussion_r2137130664
########## httpclient5-testing/src/main/java/org/apache/hc/client5/testing/async/AsyncRandomHandler.java: ########## @@ -93,6 +93,20 @@ public void handleRequest( } catch (final URISyntaxException ex) { throw new ProtocolException(ex.getMessage(), ex); } + final String query = uri.getQuery(); Review Comment: @rschmitt `WWWFormCodec#parse` may make parsing easier here. ########## httpclient5-testing/src/main/java/org/apache/hc/client5/testing/async/AsyncRandomHandler.java: ########## @@ -192,6 +216,10 @@ public int availableData() { @Override protected void produceData(final StreamChannel<ByteBuffer> channel) throws IOException { + if (System.currentTimeMillis() < deadline) { + return; + } Review Comment: @rschmitt With the current approach the data producer will make the i/o reactor spin. This is probably permissible for integration tests but ideally the data producer should signal it has no data to produce by returning 0 from `#availableData` and write data from a worker thread once it becomes available. This is of course requires quite a bit of work. ########## httpclient5-testing/src/main/java/org/apache/hc/client5/testing/classic/RandomHandler.java: ########## @@ -84,6 +84,20 @@ public void handle(final ClassicHttpRequest request, } catch (final URISyntaxException ex) { throw new ProtocolException(ex.getMessage(), ex); } + final String query = uri.getQuery(); Review Comment: @rschmitt Same. ########## httpclient5-testing/src/main/java/org/apache/hc/client5/testing/classic/RandomHandler.java: ########## @@ -185,31 +219,48 @@ public InputStream getContent() { @Override public void writeTo(final OutputStream out) throws IOException { - final int blocksize = 2048; - int remaining = (int) length; // range checked in constructor - final byte[] data = new byte[Math.min(remaining, blocksize)]; + try { + final int blocksize = 2048; + int remaining = (int) length; // range checked in constructor + final byte[] data = new byte[Math.min(remaining, blocksize)]; - while (remaining > 0) { - final int end = Math.min(remaining, data.length); + out.flush(); + if (!drip) { + delay(); + } + while (remaining > 0) { + final int end = Math.min(remaining, data.length); - double value = 0.0; - for (int i = 0; i < end; i++) { - // we get 5 random characters out of one random value - if (i % 5 == 0) { - value = Math.random(); + double value = 0.0; + for (int i = 0; i < end; i++) { + // we get 5 random characters out of one random value + if (i % 5 == 0) { + value = Math.random(); + } + value = value * RANGE.length; + final int d = (int) value; + value = value - d; + data[i] = RANGE[d]; } - value = value * RANGE.length; - final int d = (int) value; - value = value - d; - data[i] = RANGE[d]; - } - out.write(data, 0, end); - out.flush(); + out.write(data, 0, end); + out.flush(); - remaining = remaining - end; + remaining = remaining - end; + if (drip) { + delay(); + } + } + } finally { + out.close(); } - out.close(); + } + private void delay() throws IOException { + try { + Thread.sleep(delayMs); + } catch (final InterruptedException ex) { + throw new IOException(ex); Review Comment: @rschmitt `InterruptedIOException` instead? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org For additional commands, e-mail: dev-h...@hc.apache.org