From bb21009772f5bd47ba45f3cf6d62b7ba334f4bde Mon Sep 17 00:00:00 2001 From: javanna Date: Tue, 5 Jul 2016 19:18:01 +0200 Subject: [PATCH] [TEST] add async entities to the randomization for RequestLoggerTests --- .../client/RequestLoggerTests.java | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/client/rest/src/test/java/org/elasticsearch/client/RequestLoggerTests.java b/client/rest/src/test/java/org/elasticsearch/client/RequestLoggerTests.java index 4d3ad75b5e8..f00060a02de 100644 --- a/client/rest/src/test/java/org/elasticsearch/client/RequestLoggerTests.java +++ b/client/rest/src/test/java/org/elasticsearch/client/RequestLoggerTests.java @@ -35,6 +35,8 @@ import org.apache.http.entity.InputStreamEntity; import org.apache.http.entity.StringEntity; import org.apache.http.message.BasicHttpResponse; import org.apache.http.message.BasicStatusLine; +import org.apache.http.nio.entity.NByteArrayEntity; +import org.apache.http.nio.entity.NStringEntity; import org.apache.http.util.EntityUtils; import java.io.ByteArrayInputStream; @@ -97,14 +99,24 @@ public class RequestLoggerTests extends RestClientTestCase { expected += " -d '" + requestBody + "'"; HttpEntityEnclosingRequest enclosingRequest = (HttpEntityEnclosingRequest) request; HttpEntity entity; - if (getRandom().nextBoolean()) { - entity = new StringEntity(requestBody, StandardCharsets.UTF_8); - } else { - entity = new InputStreamEntity(new ByteArrayInputStream(requestBody.getBytes(StandardCharsets.UTF_8))); + switch(RandomInts.randomIntBetween(getRandom(), 0, 3)) { + case 0: + entity = new StringEntity(requestBody, StandardCharsets.UTF_8); + break; + case 1: + entity = new InputStreamEntity(new ByteArrayInputStream(requestBody.getBytes(StandardCharsets.UTF_8))); + break; + case 2: + entity = new NStringEntity(requestBody, StandardCharsets.UTF_8); + break; + case 3: + entity = new NByteArrayEntity(requestBody.getBytes(StandardCharsets.UTF_8)); + break; + default: + throw new UnsupportedOperationException(); } enclosingRequest.setEntity(entity); } - String traceRequest = RequestLogger.buildTraceRequest(request, host); assertThat(traceRequest, equalTo(expected)); if (hasBody) {