Skip to content

Commit 71fd095

Browse files
committed
Drain input stream with smaller buffer
1 parent e10a00f commit 71fd095

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

plugins/repository-azure/src/test/java/org/elasticsearch/repositories/azure/AzureBlobStoreRepositoryTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ public void handle(final HttpExchange exchange) throws IOException {
199199
exchange.getResponseBody().write(blob.toBytesRef().bytes, start, length);
200200

201201
} else if (Regex.simpleMatch("DELETE /container/*", request)) {
202-
Streams.readFully(exchange.getRequestBody());
202+
drainInputStream(exchange.getRequestBody());
203203
blobs.entrySet().removeIf(blob -> blob.getKey().startsWith(exchange.getRequestURI().getPath()));
204204
exchange.sendResponseHeaders(RestStatus.ACCEPTED.getStatus(), -1);
205205

@@ -251,7 +251,7 @@ private static class AzureErroneousHttpHandler extends ErroneousHttpHandler {
251251

252252
@Override
253253
protected void handleAsError(final HttpExchange exchange) throws IOException {
254-
Streams.readFully(exchange.getRequestBody());
254+
drainInputStream(exchange.getRequestBody());
255255
TestUtils.sendError(exchange, randomFrom(RestStatus.INTERNAL_SERVER_ERROR, RestStatus.SERVICE_UNAVAILABLE));
256256
exchange.close();
257257
}

plugins/repository-s3/src/test/java/org/elasticsearch/repositories/s3/S3BlobStoreRepositoryTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ public void handle(final HttpExchange exchange) throws IOException {
194194
}
195195

196196
} else if (Regex.simpleMatch("POST /bucket/*?uploadId=*", request)) {
197-
Streams.readFully(exchange.getRequestBody());
197+
drainInputStream(exchange.getRequestBody());
198198
final Map<String, String> params = new HashMap<>();
199199
RestUtils.decodeQueryString(exchange.getRequestURI().getQuery(), 0, params);
200200
final String uploadId = params.get("uploadId");

test/framework/src/main/java/org/elasticsearch/repositories/blobstore/ESMockAPIBasedRepositoryIntegTestCase.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import org.elasticsearch.cluster.metadata.IndexMetaData;
2727
import org.elasticsearch.common.Strings;
2828
import org.elasticsearch.common.SuppressForbidden;
29-
import org.elasticsearch.common.io.Streams;
3029
import org.elasticsearch.common.network.InetAddresses;
3130
import org.elasticsearch.common.settings.Settings;
3231
import org.elasticsearch.mocksocket.MockHttpServer;
@@ -37,6 +36,7 @@
3736
import org.junit.BeforeClass;
3837

3938
import java.io.IOException;
39+
import java.io.InputStream;
4040
import java.net.InetAddress;
4141
import java.net.InetSocketAddress;
4242
import java.util.Map;
@@ -53,6 +53,8 @@
5353
@SuppressForbidden(reason = "this test uses a HttpServer to emulate a cloud-based storage service")
5454
public abstract class ESMockAPIBasedRepositoryIntegTestCase extends ESBlobStoreRepositoryIntegTestCase {
5555

56+
private static final byte[] BUFFER = new byte[1024];
57+
5658
private static HttpServer httpServer;
5759
private Map<String, HttpHandler> handlers;
5860

@@ -127,6 +129,15 @@ protected static String httpServerUrl() {
127129
return "http://" + InetAddresses.toUriString(address.getAddress()) + ":" + address.getPort();
128130
}
129131

132+
/**
133+
* Consumes and closes the given {@link InputStream}
134+
*/
135+
protected static void drainInputStream(final InputStream inputStream) throws IOException {
136+
try (InputStream is = inputStream) {
137+
while (is.read(BUFFER) >= 0);
138+
}
139+
}
140+
130141
/**
131142
* HTTP handler that injects random service errors
132143
*
@@ -166,7 +177,7 @@ public void handle(final HttpExchange exchange) throws IOException {
166177
}
167178

168179
protected void handleAsError(final HttpExchange exchange) throws IOException {
169-
Streams.readFully(exchange.getRequestBody());
180+
drainInputStream(exchange.getRequestBody());
170181
exchange.sendResponseHeaders(HttpStatus.SC_INTERNAL_SERVER_ERROR, -1);
171182
exchange.close();
172183
}

0 commit comments

Comments
 (0)