Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public void handle(final HttpExchange exchange) throws IOException {
exchange.getResponseBody().write(blob.toBytesRef().bytes, start, length);

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

Expand Down Expand Up @@ -251,7 +251,7 @@ private static class AzureErroneousHttpHandler extends ErroneousHttpHandler {

@Override
protected void handleAsError(final HttpExchange exchange) throws IOException {
Streams.readFully(exchange.getRequestBody());
drainInputStream(exchange.getRequestBody());
TestUtils.sendError(exchange, randomFrom(RestStatus.INTERNAL_SERVER_ERROR, RestStatus.SERVICE_UNAVAILABLE));
exchange.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public void handle(final HttpExchange exchange) throws IOException {
}

} else if (Regex.simpleMatch("POST /bucket/*?uploadId=*", request)) {
Streams.readFully(exchange.getRequestBody());
drainInputStream(exchange.getRequestBody());
final Map<String, String> params = new HashMap<>();
RestUtils.decodeQueryString(exchange.getRequestURI().getQuery(), 0, params);
final String uploadId = params.get("uploadId");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.SuppressForbidden;
import org.elasticsearch.common.io.Streams;
import org.elasticsearch.common.network.InetAddresses;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.mocksocket.MockHttpServer;
Expand All @@ -37,6 +36,7 @@
import org.junit.BeforeClass;

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

private static final byte[] BUFFER = new byte[1024];

private static HttpServer httpServer;
private Map<String, HttpHandler> handlers;

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

/**
* 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);
}
}

/**
* HTTP handler that injects random service errors
*
Expand Down Expand Up @@ -166,7 +177,7 @@ public void handle(final HttpExchange exchange) throws IOException {
}

protected void handleAsError(final HttpExchange exchange) throws IOException {
Streams.readFully(exchange.getRequestBody());
drainInputStream(exchange.getRequestBody());
exchange.sendResponseHeaders(HttpStatus.SC_INTERNAL_SERVER_ERROR, -1);
exchange.close();
}
Expand Down