restore throws IOException clause on all performRequest sync methods

We throw IOException, which is the exception that is going to be thrown in 99% of the cases. A more generic exception can happen, and if it is a runtime one we just let it bubble up as is, otherwise we wrap it into runtime one so that we don't require to catch Exception everywhere, which seems odd.

Also adjusted javadocs for all performRequest methods
This commit is contained in:
javanna 2016-07-19 15:09:52 +02:00 committed by Luca Cavanna
parent 8eccdff9ad
commit a9b5c5adbe
20 changed files with 94 additions and 72 deletions

View File

@ -121,8 +121,9 @@ public final class RestClient implements Closeable {
}
/**
* Sends a request to the elasticsearch cluster that the current client points to.
* Shortcut to {@link #performRequest(String, String, Map, HttpEntity, Header...)} but without parameters and request body.
* Sends a request to the elasticsearch cluster that the current client points to and waits for the corresponding response
* to be returned. Shortcut to {@link #performRequest(String, String, Map, HttpEntity, Header...)} but without parameters
* and request body.
*
* @param method the http method
* @param endpoint the path of the request (without host and port)
@ -132,13 +133,13 @@ public final class RestClient implements Closeable {
* @throws ClientProtocolException in case of an http protocol error
* @throws ResponseException in case elasticsearch responded with a status code that indicated an error
*/
public Response performRequest(String method, String endpoint, Header... headers) throws Exception {
public Response performRequest(String method, String endpoint, Header... headers) throws IOException {
return performRequest(method, endpoint, Collections.<String, String>emptyMap(), (HttpEntity)null, headers);
}
/**
* Sends a request to the elasticsearch cluster that the current client points to.
* Shortcut to {@link #performRequest(String, String, Map, HttpEntity, Header...)} but without request body.
* Sends a request to the elasticsearch cluster that the current client points to and waits for the corresponding response
* to be returned. Shortcut to {@link #performRequest(String, String, Map, HttpEntity, Header...)} but without request body.
*
* @param method the http method
* @param endpoint the path of the request (without host and port)
@ -149,16 +150,15 @@ public final class RestClient implements Closeable {
* @throws ClientProtocolException in case of an http protocol error
* @throws ResponseException in case elasticsearch responded with a status code that indicated an error
*/
public Response performRequest(String method, String endpoint, Map<String, String> params, Header... headers) throws Exception {
public Response performRequest(String method, String endpoint, Map<String, String> params, Header... headers) throws IOException {
return performRequest(method, endpoint, params, (HttpEntity)null, headers);
}
/**
* Sends a request to the elasticsearch cluster that the current client points to. Blocks until the request is completed and returns
* its response of fails by throwing an exception. Selects a host out of the provided ones in a round-robin fashion. Failing hosts
* are marked dead and retried after a certain amount of time (minimum 1 minute, maximum 30 minutes), depending on how many times
* they previously failed (the more failures, the later they will be retried). In case of failures all of the alive nodes (or dead
* nodes that deserve a retry) are retried until one responds or none of them does, in which case an {@link IOException} will be thrown.
* Sends a request to the elasticsearch cluster that the current client points to and waits for the corresponding response
* to be returned. Shortcut to {@link #performRequest(String, String, Map, HttpEntity, HttpAsyncResponseConsumer, Header...)}
* which doesn't require specifying an {@link HttpAsyncResponseConsumer} instance, {@link HeapBufferedAsyncResponseConsumer}
* will be used to consume the response body.
*
* @param method the http method
* @param endpoint the path of the request (without host and port)
@ -171,7 +171,7 @@ public final class RestClient implements Closeable {
* @throws ResponseException in case elasticsearch responded with a status code that indicated an error
*/
public Response performRequest(String method, String endpoint, Map<String, String> params,
HttpEntity entity, Header... headers) throws Exception {
HttpEntity entity, Header... headers) throws IOException {
HttpAsyncResponseConsumer<HttpResponse> responseConsumer = new HeapBufferedAsyncResponseConsumer();
return performRequest(method, endpoint, params, entity, responseConsumer, headers);
}
@ -197,17 +197,16 @@ public final class RestClient implements Closeable {
*/
public Response performRequest(String method, String endpoint, Map<String, String> params,
HttpEntity entity, HttpAsyncResponseConsumer<HttpResponse> responseConsumer,
Header... headers) throws Exception {
Header... headers) throws IOException {
SyncResponseListener listener = new SyncResponseListener();
performRequest(method, endpoint, params, entity, responseConsumer, listener, headers);
return listener.get();
}
/**
* Sends a request to the elasticsearch cluster that the current client points to.
* Shortcut to {@link #performRequest(String, String, Map, HttpEntity, HttpAsyncResponseConsumer, ResponseListener, Header...)}
* but without parameters, request body and async response consumer. A default response consumer, specifically an instance of
* ({@link org.apache.http.nio.protocol.BasicAsyncResponseConsumer} will be created and used.
* Sends a request to the elasticsearch cluster that the current client points to. Doesn't wait for the response, instead
* the provided {@link ResponseListener} will be notified upon completion or failure. Shortcut to
* {@link #performRequest(String, String, Map, HttpEntity, ResponseListener, Header...)} but without parameters and request body.
*
* @param method the http method
* @param endpoint the path of the request (without host and port)
@ -219,10 +218,9 @@ public final class RestClient implements Closeable {
}
/**
* Sends a request to the elasticsearch cluster that the current client points to.
* Shortcut to {@link #performRequest(String, String, Map, HttpEntity, HttpAsyncResponseConsumer, ResponseListener, Header...)}
* but without request body and async response consumer. A default response consumer, specifically an instance of
* ({@link org.apache.http.nio.protocol.BasicAsyncResponseConsumer} will be created and used.
* Sends a request to the elasticsearch cluster that the current client points to. Doesn't wait for the response, instead
* the provided {@link ResponseListener} will be notified upon completion or failure. Shortcut to
* {@link #performRequest(String, String, Map, HttpEntity, ResponseListener, Header...)} but without request body.
*
* @param method the http method
* @param endpoint the path of the request (without host and port)
@ -236,10 +234,11 @@ public final class RestClient implements Closeable {
}
/**
* Sends a request to the elasticsearch cluster that the current client points to.
* Sends a request to the elasticsearch cluster that the current client points to. Doesn't wait for the response, instead
* the provided {@link ResponseListener} will be notified upon completion or failure.
* Shortcut to {@link #performRequest(String, String, Map, HttpEntity, HttpAsyncResponseConsumer, ResponseListener, Header...)}
* but without an async response consumer, meaning that a {@link org.apache.http.nio.protocol.BasicAsyncResponseConsumer}
* will be created and used.
* which doesn't require specifying an {@link HttpAsyncResponseConsumer} instance, {@link HeapBufferedAsyncResponseConsumer}
* will be used to consume the response body.
*
* @param method the http method
* @param endpoint the path of the request (without host and port)
@ -256,7 +255,7 @@ public final class RestClient implements Closeable {
/**
* Sends a request to the elasticsearch cluster that the current client points to. The request is executed asynchronously
* and the provided {@link ResponseListener} gets notified whenever it is completed or it fails.
* and the provided {@link ResponseListener} gets notified upon request completion or failure.
* Selects a host out of the provided ones in a round-robin fashion. Failing hosts are marked dead and retried after a certain
* amount of time (minimum 1 minute, maximum 30 minutes), depending on how many times they previously failed (the more failures,
* the later they will be retried). In case of failures all of the alive nodes (or dead nodes that deserve a retry) are retried
@ -541,14 +540,25 @@ public final class RestClient implements Closeable {
latch.countDown();
}
Response get() throws Exception {
latch.await();
Response get() throws IOException {
try {
latch.await();
} catch (InterruptedException e) {
throw new RuntimeException("thread waiting for the response was interrupted", e);
}
if (response != null) {
assert exception == null;
return response;
}
assert exception != null;
throw exception;
//try and leave the exception untouched as much as possible but we don't want to just add throws Exception clause everywhere
if (exception instanceof IOException) {
throw (IOException) exception;
}
if (exception instanceof RuntimeException){
throw (RuntimeException) exception;
}
throw new IOException("error while performing request", exception);
}
}

View File

@ -141,7 +141,7 @@ public class RestClientIntegTests extends RestClientTestCase {
* to set/add headers to the {@link org.apache.http.client.HttpClient}.
* Exercises the test http server ability to send back whatever headers it received.
*/
public void testHeaders() throws Exception {
public void testHeaders() throws IOException {
for (String method : getHttpMethods()) {
Set<String> standardHeaders = new HashSet<>(
Arrays.asList("Connection", "Host", "User-agent", "Date"));
@ -189,7 +189,7 @@ public class RestClientIntegTests extends RestClientTestCase {
* out of the box by {@link org.apache.http.client.HttpClient}.
* Exercises the test http server ability to send back whatever body it received.
*/
public void testDeleteWithBody() throws Exception {
public void testDeleteWithBody() throws IOException {
bodyTest("DELETE");
}
@ -198,11 +198,11 @@ public class RestClientIntegTests extends RestClientTestCase {
* out of the box by {@link org.apache.http.client.HttpClient}.
* Exercises the test http server ability to send back whatever body it received.
*/
public void testGetWithBody() throws Exception {
public void testGetWithBody() throws IOException {
bodyTest("GET");
}
private void bodyTest(String method) throws Exception {
private void bodyTest(String method) throws IOException {
String requestBody = "{ \"field\": \"value\" }";
StringEntity entity = new StringEntity(requestBody);
int statusCode = randomStatusCode(getRandom());

View File

@ -104,7 +104,7 @@ public class RestClientMultipleHostsTests extends RestClientTestCase {
restClient = new RestClient(httpClient, 10000, new Header[0], httpHosts, failureListener);
}
public void testRoundRobinOkStatusCodes() throws Exception {
public void testRoundRobinOkStatusCodes() throws IOException {
int numIters = RandomInts.randomIntBetween(getRandom(), 1, 5);
for (int i = 0; i < numIters; i++) {
Set<HttpHost> hostsSet = new HashSet<>();
@ -120,7 +120,7 @@ public class RestClientMultipleHostsTests extends RestClientTestCase {
failureListener.assertNotCalled();
}
public void testRoundRobinNoRetryErrors() throws Exception {
public void testRoundRobinNoRetryErrors() throws IOException {
int numIters = RandomInts.randomIntBetween(getRandom(), 1, 5);
for (int i = 0; i < numIters; i++) {
Set<HttpHost> hostsSet = new HashSet<>();
@ -153,7 +153,7 @@ public class RestClientMultipleHostsTests extends RestClientTestCase {
failureListener.assertNotCalled();
}
public void testRoundRobinRetryErrors() throws Exception {
public void testRoundRobinRetryErrors() throws IOException {
String retryEndpoint = randomErrorRetryEndpoint();
try {
restClient.performRequest(randomHttpMethod(getRandom()), retryEndpoint);

View File

@ -199,7 +199,7 @@ public class RestClientSingleHostTests extends RestClientTestCase {
/**
* End to end test for ok status codes
*/
public void testOkStatusCodes() throws Exception {
public void testOkStatusCodes() throws IOException {
for (String method : getHttpMethods()) {
for (int okStatusCode : getOkStatusCodes()) {
Response response = performRequest(method, "/" + okStatusCode);
@ -212,7 +212,7 @@ public class RestClientSingleHostTests extends RestClientTestCase {
/**
* End to end test for error status codes: they should cause an exception to be thrown, apart from 404 with HEAD requests
*/
public void testErrorStatusCodes() throws Exception {
public void testErrorStatusCodes() throws IOException {
for (String method : getHttpMethods()) {
//error status codes should cause an exception to be thrown
for (int errorStatusCode : getAllErrorStatusCodes()) {
@ -239,7 +239,7 @@ public class RestClientSingleHostTests extends RestClientTestCase {
}
}
public void testIOExceptions() throws Exception {
public void testIOExceptions() throws IOException {
for (String method : getHttpMethods()) {
//IOExceptions should be let bubble up
try {
@ -263,7 +263,7 @@ public class RestClientSingleHostTests extends RestClientTestCase {
* End to end test for request and response body. Exercises the mock http client ability to send back
* whatever body it has received.
*/
public void testBody() throws Exception {
public void testBody() throws IOException {
String body = "{ \"field\": \"value\" }";
StringEntity entity = new StringEntity(body);
for (String method : Arrays.asList("DELETE", "GET", "PATCH", "POST", "PUT")) {
@ -293,7 +293,7 @@ public class RestClientSingleHostTests extends RestClientTestCase {
}
}
public void testNullHeaders() throws Exception {
public void testNullHeaders() throws IOException {
String method = randomHttpMethod(getRandom());
int statusCode = randomStatusCode(getRandom());
try {
@ -310,7 +310,7 @@ public class RestClientSingleHostTests extends RestClientTestCase {
}
}
public void testNullParams() throws Exception {
public void testNullParams() throws IOException {
String method = randomHttpMethod(getRandom());
int statusCode = randomStatusCode(getRandom());
try {
@ -331,7 +331,7 @@ public class RestClientSingleHostTests extends RestClientTestCase {
* End to end test for request and response headers. Exercises the mock http client ability to send back
* whatever headers it has received.
*/
public void testHeaders() throws Exception {
public void testHeaders() throws IOException {
for (String method : getHttpMethods()) {
Map<String, String> expectedHeaders = new HashMap<>();
for (Header defaultHeader : defaultHeaders) {
@ -447,7 +447,7 @@ public class RestClientSingleHostTests extends RestClientTestCase {
return request;
}
private Response performRequest(String method, String endpoint, Header... headers) throws Exception {
private Response performRequest(String method, String endpoint, Header... headers) throws IOException {
switch(randomIntBetween(0, 2)) {
case 0:
return restClient.performRequest(method, endpoint, headers);

View File

@ -61,7 +61,7 @@ public class HostsSniffer {
/**
* Calls the elasticsearch nodes info api, parses the response and returns all the found http hosts
*/
public List<HttpHost> sniffHosts() throws Exception {
public List<HttpHost> sniffHosts() throws IOException {
Response response = restClient.performRequest("get", "/_nodes/http", sniffRequestParams);
return readHosts(response.getEntity());
}

View File

@ -85,7 +85,7 @@ public class HostsSnifferTests extends RestClientTestCase {
httpServer.stop(0);
}
public void testSniffNodes() throws Exception {
public void testSniffNodes() throws IOException {
HttpHost httpHost = new HttpHost(httpServer.getAddress().getHostString(), httpServer.getAddress().getPort());
try (RestClient restClient = RestClient.builder(httpHost).build()) {
HostsSniffer.Builder builder = HostsSniffer.builder(restClient).setSniffRequestTimeoutMillis(sniffRequestTimeout);

View File

@ -51,6 +51,7 @@ import org.elasticsearch.threadpool.ThreadPool;
import org.junit.After;
import org.junit.Before;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@ -218,7 +219,7 @@ public class ContextAndHeaderTransportIT extends HttpSmokeTestCase {
assertRequestsContainHeader(MultiTermVectorsRequest.class);
}
public void testThatRelevantHttpHeadersBecomeRequestHeaders() throws Exception {
public void testThatRelevantHttpHeadersBecomeRequestHeaders() throws IOException {
final String IRRELEVANT_HEADER = "SomeIrrelevantHeader";
Response response = getRestClient().performRequest("GET", "/" + queryIndex + "/_search",
new BasicHeader(CUSTOM_HEADER, randomHeaderValue), new BasicHeader(IRRELEVANT_HEADER, randomHeaderValue));

View File

@ -23,12 +23,14 @@ import org.apache.http.message.BasicHeader;
import org.elasticsearch.client.Response;
import org.elasticsearch.test.ESIntegTestCase;
import java.io.IOException;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
public class CorsNotSetIT extends HttpSmokeTestCase {
public void testCorsSettingDefaultBehaviourDoesNotReturnAnything() throws Exception {
public void testCorsSettingDefaultBehaviourDoesNotReturnAnything() throws IOException {
String corsValue = "http://localhost:9200";
Response response = getRestClient().performRequest("GET", "/",
new BasicHeader("User-Agent", "Mozilla Bar"), new BasicHeader("Origin", corsValue));
@ -37,7 +39,7 @@ public class CorsNotSetIT extends HttpSmokeTestCase {
assertThat(response.getHeader("Access-Control-Allow-Credentials"), nullValue());
}
public void testThatOmittingCorsHeaderDoesNotReturnAnything() throws Exception {
public void testThatOmittingCorsHeaderDoesNotReturnAnything() throws IOException {
Response response = getRestClient().performRequest("GET", "/");
assertThat(response.getStatusLine().getStatusCode(), is(200));
assertThat(response.getHeader("Access-Control-Allow-Origin"), nullValue());

View File

@ -28,6 +28,8 @@ import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
import org.elasticsearch.test.ESIntegTestCase.Scope;
import org.jboss.netty.handler.codec.http.HttpHeaders;
import java.io.IOException;
import static org.elasticsearch.http.HttpTransportSettings.SETTING_CORS_ALLOW_CREDENTIALS;
import static org.elasticsearch.http.HttpTransportSettings.SETTING_CORS_ALLOW_METHODS;
import static org.elasticsearch.http.HttpTransportSettings.SETTING_CORS_ALLOW_ORIGIN;
@ -58,7 +60,7 @@ public class CorsRegexIT extends HttpSmokeTestCase {
return true;
}
public void testThatRegularExpressionWorksOnMatch() throws Exception {
public void testThatRegularExpressionWorksOnMatch() throws IOException {
String corsValue = "http://localhost:9200";
Response response = getRestClient().performRequest("GET", "/",
new BasicHeader("User-Agent", "Mozilla Bar"), new BasicHeader("Origin", corsValue));
@ -71,7 +73,7 @@ public class CorsRegexIT extends HttpSmokeTestCase {
assertThat(response.getHeader("Access-Control-Allow-Credentials"), is("true"));
}
public void testThatRegularExpressionReturnsForbiddenOnNonMatch() throws Exception {
public void testThatRegularExpressionReturnsForbiddenOnNonMatch() throws IOException {
try {
getRestClient().performRequest("GET", "/", new BasicHeader("User-Agent", "Mozilla Bar"),
new BasicHeader("Origin", "http://evil-host:9200"));
@ -84,19 +86,19 @@ public class CorsRegexIT extends HttpSmokeTestCase {
}
}
public void testThatSendingNoOriginHeaderReturnsNoAccessControlHeader() throws Exception {
public void testThatSendingNoOriginHeaderReturnsNoAccessControlHeader() throws IOException {
Response response = getRestClient().performRequest("GET", "/", new BasicHeader("User-Agent", "Mozilla Bar"));
assertThat(response.getStatusLine().getStatusCode(), is(200));
assertThat(response.getHeader("Access-Control-Allow-Origin"), nullValue());
}
public void testThatRegularExpressionIsNotAppliedWithoutCorrectBrowserOnMatch() throws Exception {
public void testThatRegularExpressionIsNotAppliedWithoutCorrectBrowserOnMatch() throws IOException {
Response response = getRestClient().performRequest("GET", "/");
assertThat(response.getStatusLine().getStatusCode(), is(200));
assertThat(response.getHeader("Access-Control-Allow-Origin"), nullValue());
}
public void testThatPreFlightRequestWorksOnMatch() throws Exception {
public void testThatPreFlightRequestWorksOnMatch() throws IOException {
String corsValue = "http://localhost:9200";
Response response = getRestClient().performRequest("OPTIONS", "/",
new BasicHeader("User-Agent", "Mozilla Bar"), new BasicHeader("Origin", corsValue),
@ -105,7 +107,7 @@ public class CorsRegexIT extends HttpSmokeTestCase {
assertNotNull(response.getHeader("Access-Control-Allow-Methods"));
}
public void testThatPreFlightRequestReturnsNullOnNonMatch() throws Exception {
public void testThatPreFlightRequestReturnsNullOnNonMatch() throws IOException {
try {
getRestClient().performRequest("OPTIONS", "/", new BasicHeader("User-Agent", "Mozilla Bar"),
new BasicHeader("Origin", "http://evil-host:9200"),

View File

@ -77,7 +77,7 @@ public class DeprecationHttpIT extends HttpSmokeTestCase {
* Attempts to do a scatter/gather request that expects unique responses per sub-request.
*/
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/19222")
public void testUniqueDeprecationResponsesMergedTogether() throws Exception {
public void testUniqueDeprecationResponsesMergedTogether() throws IOException {
final String[] indices = new String[randomIntBetween(2, 5)];
// add at least one document for each index
@ -135,7 +135,7 @@ public class DeprecationHttpIT extends HttpSmokeTestCase {
* <p>
* Re-running this back-to-back helps to ensure that warnings are not being maintained across requests.
*/
private void doTestDeprecationWarningsAppearInHeaders() throws Exception {
private void doTestDeprecationWarningsAppearInHeaders() throws IOException {
final boolean useDeprecatedField = randomBoolean();
final boolean useNonDeprecatedSetting = randomBoolean();

View File

@ -28,6 +28,7 @@ import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
import org.elasticsearch.test.ESIntegTestCase.Scope;
import java.io.IOException;
import java.util.Collections;
import static org.hamcrest.Matchers.is;
@ -52,7 +53,7 @@ public class DetailedErrorsDisabledIT extends HttpSmokeTestCase {
return true;
}
public void testThatErrorTraceParamReturns400() throws Exception {
public void testThatErrorTraceParamReturns400() throws IOException {
try {
getRestClient().performRequest("DELETE", "/", Collections.singletonMap("error_trace", "true"));
fail("request should have failed");

View File

@ -24,6 +24,7 @@ import org.elasticsearch.client.Response;
import org.elasticsearch.client.ResponseException;
import org.elasticsearch.test.ESIntegTestCase;
import java.io.IOException;
import java.util.Collections;
import static org.hamcrest.Matchers.containsString;
@ -34,7 +35,7 @@ import static org.hamcrest.Matchers.not;
*/
public class DetailedErrorsEnabledIT extends HttpSmokeTestCase {
public void testThatErrorTraceWorksByDefault() throws Exception {
public void testThatErrorTraceWorksByDefault() throws IOException {
try {
getRestClient().performRequest("DELETE", "/", Collections.singletonMap("error_trace", "true"));
fail("request should have failed");

View File

@ -26,6 +26,7 @@ import org.elasticsearch.client.Response;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.test.ESIntegTestCase;
import java.io.IOException;
import java.util.Collections;
public class HttpCompressionIT extends ESIntegTestCase {
@ -43,7 +44,7 @@ public class HttpCompressionIT extends ESIntegTestCase {
return false;
}
public void testCompressesResponseIfRequested() throws Exception {
public void testCompressesResponseIfRequested() throws IOException {
ensureGreen();
try (RestClient client = getRestClient()) {
Response response = client.performRequest("GET", "/", new BasicHeader(HttpHeaders.ACCEPT_ENCODING, GZIP_ENCODING));
@ -52,7 +53,7 @@ public class HttpCompressionIT extends ESIntegTestCase {
}
}
public void testUncompressedResponseByDefault() throws Exception {
public void testUncompressedResponseByDefault() throws IOException {
ensureGreen();
try (RestClient client = getRestClient()) {
Response response = client.performRequest("GET", "/");

View File

@ -27,6 +27,7 @@ import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
import org.elasticsearch.test.ESIntegTestCase.Scope;
import java.util.ArrayList;
import java.io.IOException;
import java.util.Collection;
import static org.hamcrest.Matchers.equalTo;
@ -56,7 +57,7 @@ public class ResponseHeaderPluginIT extends HttpSmokeTestCase {
return plugins;
}
public void testThatSettingHeadersWorks() throws Exception {
public void testThatSettingHeadersWorks() throws IOException {
ensureGreen();
try {
getRestClient().performRequest("GET", "/_protected");

View File

@ -270,7 +270,7 @@ public abstract class ESRestTestCase extends ESTestCase {
}
@After
public void wipeCluster() throws Exception {
public void wipeCluster() throws IOException {
// wipe indices
Map<String, String> deleteIndicesArgs = new HashMap<>();
deleteIndicesArgs.put("index", "*");
@ -299,7 +299,7 @@ public abstract class ESRestTestCase extends ESTestCase {
* other tests.
*/
@After
public void logIfThereAreRunningTasks() throws Exception {
public void logIfThereAreRunningTasks() throws IOException {
RestTestResponse tasks = adminExecutionContext.callApi("tasks.list", emptyMap(), emptyList(), emptyMap());
Set<String> runningTasks = runningTasks(tasks);
// Ignore the task list API - it doens't count against us
@ -378,7 +378,7 @@ public abstract class ESRestTestCase extends ESTestCase {
return messageBuilder.toString();
}
public void test() throws Exception {
public void test() throws IOException {
//let's check that there is something to run, otherwise there might be a problem with the test section
if (testCandidate.getTestSection().getExecutableSections().size() == 0) {
throw new IllegalArgumentException("No executable sections loaded for [" + testCandidate.getTestPath() + "]");

View File

@ -62,7 +62,7 @@ public class RestTestExecutionContext implements Closeable {
* Saves the obtained response in the execution context.
*/
public RestTestResponse callApi(String apiName, Map<String, String> params, List<Map<String, Object>> bodies,
Map<String, String> headers) throws Exception {
Map<String, String> headers) throws IOException {
//makes a copy of the parameters before modifying them for this specific request
HashMap<String, String> requestParams = new HashMap<>(params);
for (Map.Entry<String, String> entry : requestParams.entrySet()) {
@ -105,7 +105,7 @@ public class RestTestExecutionContext implements Closeable {
}
private RestTestResponse callApiInternal(String apiName, Map<String, String> params, String body, Map<String, String> headers)
throws Exception {
throws IOException {
return restTestClient.callApi(apiName, params, body, headers);
}

View File

@ -84,7 +84,7 @@ public class RestTestClient implements Closeable {
private final RestClient restClient;
private final Version esVersion;
public RestTestClient(RestSpec restSpec, Settings settings, URL[] urls) throws Exception {
public RestTestClient(RestSpec restSpec, Settings settings, URL[] urls) throws IOException {
assert urls.length > 0;
this.restSpec = restSpec;
this.restClient = createRestClient(urls, settings);
@ -92,7 +92,7 @@ public class RestTestClient implements Closeable {
logger.info("REST client initialized {}, elasticsearch version: [{}]", urls, esVersion);
}
private Version readAndCheckVersion(URL[] urls) throws Exception {
private Version readAndCheckVersion(URL[] urls) throws IOException {
RestApi restApi = restApi("info");
assert restApi.getPaths().size() == 1;
assert restApi.getMethods().size() == 1;
@ -127,7 +127,7 @@ public class RestTestClient implements Closeable {
* Calls an api with the provided parameters and body
*/
public RestTestResponse callApi(String apiName, Map<String, String> params, String body, Map<String, String> headers)
throws Exception {
throws IOException {
if ("raw".equals(apiName)) {
// Raw requests are bit simpler....

View File

@ -27,7 +27,7 @@ import java.io.IOException;
* Exception obtained from a REST call in case the response code indicated an error. Eagerly reads the response body into a string
* for later optional parsing. Supports parsing the response body when needed and returning specific values extracted from it.
*/
public class RestTestResponseException extends Exception {
public class RestTestResponseException extends IOException {
private final RestTestResponse restTestResponse;
private final ResponseException responseException;

View File

@ -26,6 +26,7 @@ import org.elasticsearch.test.rest.RestTestExecutionContext;
import org.elasticsearch.test.rest.client.RestTestResponse;
import org.elasticsearch.test.rest.client.RestTestResponseException;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
@ -78,7 +79,7 @@ public class DoSection implements ExecutableSection {
}
@Override
public void execute(RestTestExecutionContext executionContext) throws Exception {
public void execute(RestTestExecutionContext executionContext) throws IOException {
if ("param".equals(catchParam)) {
//client should throw validation error before sending request

View File

@ -20,6 +20,8 @@ package org.elasticsearch.test.rest.section;
import org.elasticsearch.test.rest.RestTestExecutionContext;
import java.io.IOException;
/**
* Represents a test fragment that can be executed (e.g. api call, assertion)
*/
@ -28,5 +30,5 @@ public interface ExecutableSection {
/**
* Executes the section passing in the execution context
*/
void execute(RestTestExecutionContext executionContext) throws Exception;
void execute(RestTestExecutionContext executionContext) throws IOException;
}