diff --git a/client/rest/src/main/java/org/elasticsearch/client/RestClient.java b/client/rest/src/main/java/org/elasticsearch/client/RestClient.java index ab12fcb5816..0ca4a4e94ce 100644 --- a/client/rest/src/main/java/org/elasticsearch/client/RestClient.java +++ b/client/rest/src/main/java/org/elasticsearch/client/RestClient.java @@ -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.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 params, Header... headers) throws Exception { + public Response performRequest(String method, String endpoint, Map 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 params, - HttpEntity entity, Header... headers) throws Exception { + HttpEntity entity, Header... headers) throws IOException { HttpAsyncResponseConsumer 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 params, HttpEntity entity, HttpAsyncResponseConsumer 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); } } diff --git a/client/rest/src/test/java/org/elasticsearch/client/RestClientIntegTests.java b/client/rest/src/test/java/org/elasticsearch/client/RestClientIntegTests.java index b1f9b66557b..ceaccad846d 100644 --- a/client/rest/src/test/java/org/elasticsearch/client/RestClientIntegTests.java +++ b/client/rest/src/test/java/org/elasticsearch/client/RestClientIntegTests.java @@ -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 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()); diff --git a/client/rest/src/test/java/org/elasticsearch/client/RestClientMultipleHostsTests.java b/client/rest/src/test/java/org/elasticsearch/client/RestClientMultipleHostsTests.java index 5fdf331a01e..2a2d279689a 100644 --- a/client/rest/src/test/java/org/elasticsearch/client/RestClientMultipleHostsTests.java +++ b/client/rest/src/test/java/org/elasticsearch/client/RestClientMultipleHostsTests.java @@ -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 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 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); diff --git a/client/rest/src/test/java/org/elasticsearch/client/RestClientSingleHostTests.java b/client/rest/src/test/java/org/elasticsearch/client/RestClientSingleHostTests.java index 62f8eb548f6..e347dfecc12 100644 --- a/client/rest/src/test/java/org/elasticsearch/client/RestClientSingleHostTests.java +++ b/client/rest/src/test/java/org/elasticsearch/client/RestClientSingleHostTests.java @@ -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 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); diff --git a/client/sniffer/src/main/java/org/elasticsearch/client/sniff/HostsSniffer.java b/client/sniffer/src/main/java/org/elasticsearch/client/sniff/HostsSniffer.java index 4aae68caef0..d5b2c67ee02 100644 --- a/client/sniffer/src/main/java/org/elasticsearch/client/sniff/HostsSniffer.java +++ b/client/sniffer/src/main/java/org/elasticsearch/client/sniff/HostsSniffer.java @@ -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 sniffHosts() throws Exception { + public List sniffHosts() throws IOException { Response response = restClient.performRequest("get", "/_nodes/http", sniffRequestParams); return readHosts(response.getEntity()); } diff --git a/client/sniffer/src/test/java/org/elasticsearch/client/sniff/HostsSnifferTests.java b/client/sniffer/src/test/java/org/elasticsearch/client/sniff/HostsSnifferTests.java index 5a9fd4033d1..bb375834097 100644 --- a/client/sniffer/src/test/java/org/elasticsearch/client/sniff/HostsSnifferTests.java +++ b/client/sniffer/src/test/java/org/elasticsearch/client/sniff/HostsSnifferTests.java @@ -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); diff --git a/qa/smoke-test-http/src/test/java/org/elasticsearch/http/ContextAndHeaderTransportIT.java b/qa/smoke-test-http/src/test/java/org/elasticsearch/http/ContextAndHeaderTransportIT.java index f39abb445d8..1249f1deadf 100644 --- a/qa/smoke-test-http/src/test/java/org/elasticsearch/http/ContextAndHeaderTransportIT.java +++ b/qa/smoke-test-http/src/test/java/org/elasticsearch/http/ContextAndHeaderTransportIT.java @@ -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)); diff --git a/qa/smoke-test-http/src/test/java/org/elasticsearch/http/CorsNotSetIT.java b/qa/smoke-test-http/src/test/java/org/elasticsearch/http/CorsNotSetIT.java index 576d5c0db96..bdda44c1b71 100644 --- a/qa/smoke-test-http/src/test/java/org/elasticsearch/http/CorsNotSetIT.java +++ b/qa/smoke-test-http/src/test/java/org/elasticsearch/http/CorsNotSetIT.java @@ -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()); diff --git a/qa/smoke-test-http/src/test/java/org/elasticsearch/http/CorsRegexIT.java b/qa/smoke-test-http/src/test/java/org/elasticsearch/http/CorsRegexIT.java index 5bcef4828c9..ca5cc1d0762 100644 --- a/qa/smoke-test-http/src/test/java/org/elasticsearch/http/CorsRegexIT.java +++ b/qa/smoke-test-http/src/test/java/org/elasticsearch/http/CorsRegexIT.java @@ -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"), diff --git a/qa/smoke-test-http/src/test/java/org/elasticsearch/http/DeprecationHttpIT.java b/qa/smoke-test-http/src/test/java/org/elasticsearch/http/DeprecationHttpIT.java index 40c757a3b1f..778daa7714e 100644 --- a/qa/smoke-test-http/src/test/java/org/elasticsearch/http/DeprecationHttpIT.java +++ b/qa/smoke-test-http/src/test/java/org/elasticsearch/http/DeprecationHttpIT.java @@ -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 { *

* 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(); diff --git a/qa/smoke-test-http/src/test/java/org/elasticsearch/http/DetailedErrorsDisabledIT.java b/qa/smoke-test-http/src/test/java/org/elasticsearch/http/DetailedErrorsDisabledIT.java index 5e53599b934..0fd4d6e6edd 100644 --- a/qa/smoke-test-http/src/test/java/org/elasticsearch/http/DetailedErrorsDisabledIT.java +++ b/qa/smoke-test-http/src/test/java/org/elasticsearch/http/DetailedErrorsDisabledIT.java @@ -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"); diff --git a/qa/smoke-test-http/src/test/java/org/elasticsearch/http/DetailedErrorsEnabledIT.java b/qa/smoke-test-http/src/test/java/org/elasticsearch/http/DetailedErrorsEnabledIT.java index fb26e59a1a5..cd3cf1a38d8 100644 --- a/qa/smoke-test-http/src/test/java/org/elasticsearch/http/DetailedErrorsEnabledIT.java +++ b/qa/smoke-test-http/src/test/java/org/elasticsearch/http/DetailedErrorsEnabledIT.java @@ -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"); diff --git a/qa/smoke-test-http/src/test/java/org/elasticsearch/http/HttpCompressionIT.java b/qa/smoke-test-http/src/test/java/org/elasticsearch/http/HttpCompressionIT.java index a6d9f833d22..e22b2e187ea 100644 --- a/qa/smoke-test-http/src/test/java/org/elasticsearch/http/HttpCompressionIT.java +++ b/qa/smoke-test-http/src/test/java/org/elasticsearch/http/HttpCompressionIT.java @@ -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", "/"); diff --git a/qa/smoke-test-http/src/test/java/org/elasticsearch/http/ResponseHeaderPluginIT.java b/qa/smoke-test-http/src/test/java/org/elasticsearch/http/ResponseHeaderPluginIT.java index 037549ada06..1e8b25b288d 100644 --- a/qa/smoke-test-http/src/test/java/org/elasticsearch/http/ResponseHeaderPluginIT.java +++ b/qa/smoke-test-http/src/test/java/org/elasticsearch/http/ResponseHeaderPluginIT.java @@ -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"); diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java index cbea7edd5af..16606e9fa91 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java @@ -270,7 +270,7 @@ public abstract class ESRestTestCase extends ESTestCase { } @After - public void wipeCluster() throws Exception { + public void wipeCluster() throws IOException { // wipe indices Map 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 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() + "]"); diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/RestTestExecutionContext.java b/test/framework/src/main/java/org/elasticsearch/test/rest/RestTestExecutionContext.java index 3be5a43e151..7ed46be4d8a 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/RestTestExecutionContext.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/RestTestExecutionContext.java @@ -62,7 +62,7 @@ public class RestTestExecutionContext implements Closeable { * Saves the obtained response in the execution context. */ public RestTestResponse callApi(String apiName, Map params, List> bodies, - Map headers) throws Exception { + Map headers) throws IOException { //makes a copy of the parameters before modifying them for this specific request HashMap requestParams = new HashMap<>(params); for (Map.Entry entry : requestParams.entrySet()) { @@ -105,7 +105,7 @@ public class RestTestExecutionContext implements Closeable { } private RestTestResponse callApiInternal(String apiName, Map params, String body, Map headers) - throws Exception { + throws IOException { return restTestClient.callApi(apiName, params, body, headers); } diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/client/RestTestClient.java b/test/framework/src/main/java/org/elasticsearch/test/rest/client/RestTestClient.java index dfa59509790..56bca24532c 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/client/RestTestClient.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/client/RestTestClient.java @@ -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 params, String body, Map headers) - throws Exception { + throws IOException { if ("raw".equals(apiName)) { // Raw requests are bit simpler.... diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/client/RestTestResponseException.java b/test/framework/src/main/java/org/elasticsearch/test/rest/client/RestTestResponseException.java index 0a1a086b4e5..2fc93a91088 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/client/RestTestResponseException.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/client/RestTestResponseException.java @@ -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; diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/section/DoSection.java b/test/framework/src/main/java/org/elasticsearch/test/rest/section/DoSection.java index 1f60db33378..20b4f66f06c 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/section/DoSection.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/section/DoSection.java @@ -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 diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/section/ExecutableSection.java b/test/framework/src/main/java/org/elasticsearch/test/rest/section/ExecutableSection.java index ece972b77f9..669d82cdd78 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/section/ExecutableSection.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/section/ExecutableSection.java @@ -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; }