diff --git a/test/fixtures/azure-fixture/src/main/java/fixture/azure/AzureHttpHandler.java b/test/fixtures/azure-fixture/src/main/java/fixture/azure/AzureHttpHandler.java index 902aa4f132eb2..7a94a8c9f2e57 100644 --- a/test/fixtures/azure-fixture/src/main/java/fixture/azure/AzureHttpHandler.java +++ b/test/fixtures/azure-fixture/src/main/java/fixture/azure/AzureHttpHandler.java @@ -31,7 +31,6 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.InputStream; import java.io.InputStreamReader; import java.nio.charset.StandardCharsets; import java.util.Arrays; @@ -63,6 +62,10 @@ public AzureHttpHandler(final String container) { @Override public void handle(final HttpExchange exchange) throws IOException { final String request = exchange.getRequestMethod() + " " + exchange.getRequestURI().toString(); + if (request.startsWith("GET") || request.startsWith("HEAD") || request.startsWith("DELETE")) { + int read = exchange.getRequestBody().read(); + assert read == -1 : "Request body should have been empty but saw [" + read + "]"; + } try { if (Regex.simpleMatch("PUT /" + container + "/*blockid=*", request)) { // Put Block (https://docs.microsoft.com/en-us/rest/api/storageservices/put-block) @@ -140,9 +143,6 @@ public void handle(final HttpExchange exchange) throws IOException { } else if (Regex.simpleMatch("DELETE /" + container + "/*", request)) { // Delete Blob (https://docs.microsoft.com/en-us/rest/api/storageservices/delete-blob) - try (InputStream is = exchange.getRequestBody()) { - while (is.read() >= 0); - } blobs.entrySet().removeIf(blob -> blob.getKey().startsWith(exchange.getRequestURI().getPath())); exchange.sendResponseHeaders(RestStatus.ACCEPTED.getStatus(), -1); diff --git a/test/fixtures/gcs-fixture/src/main/java/fixture/gcs/GoogleCloudStorageHttpHandler.java b/test/fixtures/gcs-fixture/src/main/java/fixture/gcs/GoogleCloudStorageHttpHandler.java index f3bd2ecfe3091..9d8fa756d16f5 100644 --- a/test/fixtures/gcs-fixture/src/main/java/fixture/gcs/GoogleCloudStorageHttpHandler.java +++ b/test/fixtures/gcs-fixture/src/main/java/fixture/gcs/GoogleCloudStorageHttpHandler.java @@ -76,6 +76,10 @@ public GoogleCloudStorageHttpHandler(final String bucket) { @Override public void handle(final HttpExchange exchange) throws IOException { final String request = exchange.getRequestMethod() + " " + exchange.getRequestURI().toString(); + if (request.startsWith("GET") || request.startsWith("HEAD") || request.startsWith("DELETE")) { + int read = exchange.getRequestBody().read(); + assert read == -1 : "Request body should have been empty but saw [" + read + "]"; + } try { if (Regex.simpleMatch("GET /storage/v1/b/" + bucket + "/o*", request)) { // List Objects https://cloud.google.com/storage/docs/json_api/v1/objects/list diff --git a/test/fixtures/s3-fixture/src/main/java/fixture/s3/S3HttpHandler.java b/test/fixtures/s3-fixture/src/main/java/fixture/s3/S3HttpHandler.java index f4a467d314a27..f9bce9f02c85d 100644 --- a/test/fixtures/s3-fixture/src/main/java/fixture/s3/S3HttpHandler.java +++ b/test/fixtures/s3-fixture/src/main/java/fixture/s3/S3HttpHandler.java @@ -79,6 +79,10 @@ public S3HttpHandler(final String bucket, @Nullable final String basePath) { @Override public void handle(final HttpExchange exchange) throws IOException { final String request = exchange.getRequestMethod() + " " + exchange.getRequestURI().toString(); + if (request.startsWith("GET") || request.startsWith("HEAD") || request.startsWith("DELETE")) { + int read = exchange.getRequestBody().read(); + assert read == -1 : "Request body should have been empty but saw [" + read + "]"; + } try { if (Regex.simpleMatch("POST /" + path + "/*?uploads", request)) { final String uploadId = UUIDs.randomBase64UUID(); diff --git a/test/framework/src/main/java/org/elasticsearch/repositories/blobstore/ESMockAPIBasedRepositoryIntegTestCase.java b/test/framework/src/main/java/org/elasticsearch/repositories/blobstore/ESMockAPIBasedRepositoryIntegTestCase.java index 74b126efe574a..040961ed52b1d 100644 --- a/test/framework/src/main/java/org/elasticsearch/repositories/blobstore/ESMockAPIBasedRepositoryIntegTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/repositories/blobstore/ESMockAPIBasedRepositoryIntegTestCase.java @@ -162,9 +162,7 @@ protected static String httpServerUrl() { * Consumes and closes the given {@link InputStream} */ protected static void drainInputStream(final InputStream inputStream) throws IOException { - try (InputStream is = inputStream) { - while (is.read(BUFFER) >= 0); - } + while (inputStream.read(BUFFER) >= 0) ; } /**