From 7146a36f878235c2e6625b341f69d86aa487e094 Mon Sep 17 00:00:00 2001 From: Oleg Kalnichevski Date: Thu, 7 Mar 2019 11:32:16 +0100 Subject: [PATCH] Bug fix: Fixed broken data generation logic in AsyncRandomHandler (affects test code only) --- .../hc/client5/testing/async/AsyncRandomHandler.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/httpclient5-testing/src/main/java/org/apache/hc/client5/testing/async/AsyncRandomHandler.java b/httpclient5-testing/src/main/java/org/apache/hc/client5/testing/async/AsyncRandomHandler.java index 07a5cf544..844ea4331 100644 --- a/httpclient5-testing/src/main/java/org/apache/hc/client5/testing/async/AsyncRandomHandler.java +++ b/httpclient5-testing/src/main/java/org/apache/hc/client5/testing/async/AsyncRandomHandler.java @@ -197,13 +197,13 @@ public class AsyncRandomHandler implements AsyncServerExchangeHandler { final byte b = RANGE[(int) (Math.random() * RANGE.length)]; buffer.put(b); } + remaining -= chunk; + buffer.flip(); - final int bytesWritten = channel.write(buffer); - if (bytesWritten > 0) { - remaining -= bytesWritten; - } + channel.write(buffer); buffer.compact(); - if (remaining <= 0) { + + if (remaining <= 0 && buffer.position() == 0) { channel.endStream(); } }