summaryrefslogtreecommitdiff
path: root/core/src/test/java
diff options
context:
space:
mode:
authorjavanna <cavannaluca@gmail.com>2016-06-03 18:00:54 +0200
committerLuca Cavanna <cavannaluca@gmail.com>2016-06-03 18:00:54 +0200
commit23a94bb9745aeba8bc8c04c02c874deaf89ae621 (patch)
treeb726da5b56656e2f3df9cb112fcd088461eb5e02 /core/src/test/java
parentf5825b86e631905f1108f72ae9466f2bc42119b9 (diff)
[TEST] create standard RestClient at first request and reuse it
A RestClient instance is now created whenever EsIntegTestCase#getRestClient is invoked for the first time. It is then kept until the cluster is cleared (depending on the cluster scope of the test). Renamed other two restClient methods to createRestClient, as that instance needs to be closed and managed in the tests.
Diffstat (limited to 'core/src/test/java')
-rw-r--r--core/src/test/java/org/elasticsearch/http/netty/NettyHttpCompressionIT.java8
-rw-r--r--core/src/test/java/org/elasticsearch/options/detailederrors/DetailedErrorsDisabledIT.java5
-rw-r--r--core/src/test/java/org/elasticsearch/options/detailederrors/DetailedErrorsEnabledIT.java37
-rw-r--r--core/src/test/java/org/elasticsearch/plugins/ResponseHeaderPluginIT.java27
-rw-r--r--core/src/test/java/org/elasticsearch/rest/CorsNotSetIT.java23
-rw-r--r--core/src/test/java/org/elasticsearch/rest/CorsRegexIT.java59
-rw-r--r--core/src/test/java/org/elasticsearch/rest/action/main/RestMainActionIT.java19
-rw-r--r--core/src/test/java/org/elasticsearch/transport/ContextAndHeaderTransportIT.java21
8 files changed, 85 insertions, 114 deletions
diff --git a/core/src/test/java/org/elasticsearch/http/netty/NettyHttpCompressionIT.java b/core/src/test/java/org/elasticsearch/http/netty/NettyHttpCompressionIT.java
index 32a331d61f..fb616a8781 100644
--- a/core/src/test/java/org/elasticsearch/http/netty/NettyHttpCompressionIT.java
+++ b/core/src/test/java/org/elasticsearch/http/netty/NettyHttpCompressionIT.java
@@ -61,7 +61,7 @@ public class NettyHttpCompressionIT extends ESIntegTestCase {
ensureGreen();
// we need to intercept early, otherwise internal logic in HttpClient will just remove the header and we cannot verify it
ContentEncodingHeaderExtractor headerExtractor = new ContentEncodingHeaderExtractor();
- try (RestClient client = restClient(HttpClients.custom().addInterceptorFirst(headerExtractor).build())) {
+ try (RestClient client = createRestClient(HttpClients.custom().addInterceptorFirst(headerExtractor).build())) {
try (ElasticsearchResponse response = client.performRequest("GET", "/", Collections.emptyMap(), null,
new BasicHeader(HttpHeaders.ACCEPT_ENCODING, GZIP_ENCODING))) {
assertEquals(200, response.getStatusLine().getStatusCode());
@@ -75,7 +75,7 @@ public class NettyHttpCompressionIT extends ESIntegTestCase {
ensureGreen();
ContentEncodingHeaderExtractor headerExtractor = new ContentEncodingHeaderExtractor();
CloseableHttpClient httpClient = HttpClients.custom().disableContentCompression().addInterceptorFirst(headerExtractor).build();
- try (RestClient client = restClient(httpClient)) {
+ try (RestClient client = createRestClient(httpClient)) {
try (ElasticsearchResponse response = client.performRequest("GET", "/", Collections.emptyMap(), null)) {
assertEquals(200, response.getStatusLine().getStatusCode());
assertFalse(headerExtractor.hasContentEncodingHeader());
@@ -88,7 +88,7 @@ public class NettyHttpCompressionIT extends ESIntegTestCase {
ContentEncodingHeaderExtractor headerExtractor = new ContentEncodingHeaderExtractor();
// this disable content compression in both directions (request and response)
CloseableHttpClient httpClient = HttpClients.custom().disableContentCompression().addInterceptorFirst(headerExtractor).build();
- try (RestClient client = restClient(httpClient)) {
+ try (RestClient client = createRestClient(httpClient)) {
try (ElasticsearchResponse response = client.performRequest("POST", "/company/employees/1",
Collections.emptyMap(), SAMPLE_DOCUMENT)) {
assertEquals(201, response.getStatusLine().getStatusCode());
@@ -101,7 +101,7 @@ public class NettyHttpCompressionIT extends ESIntegTestCase {
ensureGreen();
ContentEncodingHeaderExtractor headerExtractor = new ContentEncodingHeaderExtractor();
// we don't call #disableContentCompression() hence the client will send the content compressed
- try (RestClient client = restClient(HttpClients.custom().addInterceptorFirst(headerExtractor).build())) {
+ try (RestClient client = createRestClient(HttpClients.custom().addInterceptorFirst(headerExtractor).build())) {
try (ElasticsearchResponse response = client.performRequest("POST", "/company/employees/2",
Collections.emptyMap(), SAMPLE_DOCUMENT)) {
assertEquals(201, response.getStatusLine().getStatusCode());
diff --git a/core/src/test/java/org/elasticsearch/options/detailederrors/DetailedErrorsDisabledIT.java b/core/src/test/java/org/elasticsearch/options/detailederrors/DetailedErrorsDisabledIT.java
index ba8840bbc2..c23b6fc123 100644
--- a/core/src/test/java/org/elasticsearch/options/detailederrors/DetailedErrorsDisabledIT.java
+++ b/core/src/test/java/org/elasticsearch/options/detailederrors/DetailedErrorsDisabledIT.java
@@ -21,7 +21,6 @@ package org.elasticsearch.options.detailederrors;
import org.elasticsearch.client.ElasticsearchResponse;
import org.elasticsearch.client.ElasticsearchResponseException;
-import org.elasticsearch.client.RestClient;
import org.elasticsearch.common.network.NetworkModule;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.http.HttpTransportSettings;
@@ -49,8 +48,8 @@ public class DetailedErrorsDisabledIT extends ESIntegTestCase {
}
public void testThatErrorTraceParamReturns400() throws Exception {
- try (RestClient restClient = restClient()) {
- restClient.performRequest("DELETE", "/", Collections.singletonMap("error_trace", "true"), null);
+ try {
+ getRestClient().performRequest("DELETE", "/", Collections.singletonMap("error_trace", "true"), null);
fail("request should have failed");
} catch(ElasticsearchResponseException e) {
ElasticsearchResponse response = e.getElasticsearchResponse();
diff --git a/core/src/test/java/org/elasticsearch/options/detailederrors/DetailedErrorsEnabledIT.java b/core/src/test/java/org/elasticsearch/options/detailederrors/DetailedErrorsEnabledIT.java
index a040c31299..df1cb5a630 100644
--- a/core/src/test/java/org/elasticsearch/options/detailederrors/DetailedErrorsEnabledIT.java
+++ b/core/src/test/java/org/elasticsearch/options/detailederrors/DetailedErrorsEnabledIT.java
@@ -21,7 +21,6 @@ package org.elasticsearch.options.detailederrors;
import org.elasticsearch.client.ElasticsearchResponse;
import org.elasticsearch.client.ElasticsearchResponseException;
-import org.elasticsearch.client.RestClient;
import org.elasticsearch.common.network.NetworkModule;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.test.ESIntegTestCase;
@@ -47,26 +46,24 @@ public class DetailedErrorsEnabledIT extends ESIntegTestCase {
}
public void testThatErrorTraceWorksByDefault() throws Exception {
- try (RestClient restClient = restClient()) {
- try {
- restClient.performRequest("DELETE", "/", Collections.singletonMap("error_trace", "true"), null);
- fail("request should have failed");
- } catch(ElasticsearchResponseException e) {
- ElasticsearchResponse response = e.getElasticsearchResponse();
- assertThat(response.getFirstHeader("Content-Type"), containsString("application/json"));
- assertThat(e.getResponseBody(), containsString("\"stack_trace\":\"[Validation Failed: 1: index / indices is missing;]; " +
- "nested: ActionRequestValidationException[Validation Failed: 1:"));
- }
+ try {
+ getRestClient().performRequest("DELETE", "/", Collections.singletonMap("error_trace", "true"), null);
+ fail("request should have failed");
+ } catch(ElasticsearchResponseException e) {
+ ElasticsearchResponse response = e.getElasticsearchResponse();
+ assertThat(response.getFirstHeader("Content-Type"), containsString("application/json"));
+ assertThat(e.getResponseBody(), containsString("\"stack_trace\":\"[Validation Failed: 1: index / indices is missing;]; " +
+ "nested: ActionRequestValidationException[Validation Failed: 1:"));
+ }
- try {
- restClient.performRequest("DELETE", "/", Collections.emptyMap(), null);
- fail("request should have failed");
- } catch(ElasticsearchResponseException e) {
- ElasticsearchResponse response = e.getElasticsearchResponse();
- assertThat(response.getFirstHeader("Content-Type"), containsString("application/json"));
- assertThat(e.getResponseBody(), not(containsString("\"stack_trace\":\"[Validation Failed: 1: index / indices is missing;]; "
- + "nested: ActionRequestValidationException[Validation Failed: 1:")));
- }
+ try {
+ getRestClient().performRequest("DELETE", "/", Collections.emptyMap(), null);
+ fail("request should have failed");
+ } catch(ElasticsearchResponseException e) {
+ ElasticsearchResponse response = e.getElasticsearchResponse();
+ assertThat(response.getFirstHeader("Content-Type"), containsString("application/json"));
+ assertThat(e.getResponseBody(), not(containsString("\"stack_trace\":\"[Validation Failed: 1: index / indices is missing;]; "
+ + "nested: ActionRequestValidationException[Validation Failed: 1:")));
}
}
}
diff --git a/core/src/test/java/org/elasticsearch/plugins/ResponseHeaderPluginIT.java b/core/src/test/java/org/elasticsearch/plugins/ResponseHeaderPluginIT.java
index 4b905d7b1a..0fd21651ac 100644
--- a/core/src/test/java/org/elasticsearch/plugins/ResponseHeaderPluginIT.java
+++ b/core/src/test/java/org/elasticsearch/plugins/ResponseHeaderPluginIT.java
@@ -21,7 +21,6 @@ package org.elasticsearch.plugins;
import org.apache.http.message.BasicHeader;
import org.elasticsearch.client.ElasticsearchResponse;
import org.elasticsearch.client.ElasticsearchResponseException;
-import org.elasticsearch.client.RestClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.plugins.responseheader.TestResponseHeaderPlugin;
import org.elasticsearch.test.ESIntegTestCase;
@@ -56,21 +55,19 @@ public class ResponseHeaderPluginIT extends ESIntegTestCase {
public void testThatSettingHeadersWorks() throws Exception {
ensureGreen();
- try (RestClient client = restClient()) {
- try {
- client.performRequest("GET", "/_protected", Collections.emptyMap(), null);
- fail("request should have failed");
- } catch(ElasticsearchResponseException e) {
- ElasticsearchResponse response = e.getElasticsearchResponse();
- assertThat(response, hasStatus(UNAUTHORIZED));
- assertThat(response.getFirstHeader("Secret"), equalTo("required"));
- }
+ try {
+ getRestClient().performRequest("GET", "/_protected", Collections.emptyMap(), null);
+ fail("request should have failed");
+ } catch(ElasticsearchResponseException e) {
+ ElasticsearchResponse response = e.getElasticsearchResponse();
+ assertThat(response, hasStatus(UNAUTHORIZED));
+ assertThat(response.getFirstHeader("Secret"), equalTo("required"));
+ }
- try (ElasticsearchResponse authResponse = client.performRequest("GET", "/_protected", Collections.emptyMap(), null,
- new BasicHeader("Secret", "password"))) {
- assertThat(authResponse, hasStatus(OK));
- assertThat(authResponse.getFirstHeader("Secret"), equalTo("granted"));
- }
+ try (ElasticsearchResponse authResponse = getRestClient().performRequest("GET", "/_protected", Collections.emptyMap(), null,
+ new BasicHeader("Secret", "password"))) {
+ assertThat(authResponse, hasStatus(OK));
+ assertThat(authResponse.getFirstHeader("Secret"), equalTo("granted"));
}
}
}
diff --git a/core/src/test/java/org/elasticsearch/rest/CorsNotSetIT.java b/core/src/test/java/org/elasticsearch/rest/CorsNotSetIT.java
index c6c23da102..0f4ccd1a6c 100644
--- a/core/src/test/java/org/elasticsearch/rest/CorsNotSetIT.java
+++ b/core/src/test/java/org/elasticsearch/rest/CorsNotSetIT.java
@@ -21,7 +21,6 @@ package org.elasticsearch.rest;
import org.apache.http.message.BasicHeader;
import org.elasticsearch.client.ElasticsearchResponse;
-import org.elasticsearch.client.RestClient;
import org.elasticsearch.common.network.NetworkModule;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.test.ESIntegTestCase;
@@ -47,23 +46,19 @@ public class CorsNotSetIT extends ESIntegTestCase {
public void testCorsSettingDefaultBehaviourDoesNotReturnAnything() throws Exception {
String corsValue = "http://localhost:9200";
- try (RestClient restClient = restClient()) {
- try (ElasticsearchResponse response = restClient.performRequest("GET", "/", Collections.emptyMap(), null,
- new BasicHeader("User-Agent", "Mozilla Bar"), new BasicHeader("Origin", corsValue))) {
- assertThat(response.getStatusLine().getStatusCode(), is(200));
- assertThat(response.getFirstHeader("Access-Control-Allow-Origin"), nullValue());
- assertThat(response.getFirstHeader("Access-Control-Allow-Credentials"), nullValue());
- }
+ try (ElasticsearchResponse response = getRestClient().performRequest("GET", "/", Collections.emptyMap(), null,
+ new BasicHeader("User-Agent", "Mozilla Bar"), new BasicHeader("Origin", corsValue))) {
+ assertThat(response.getStatusLine().getStatusCode(), is(200));
+ assertThat(response.getFirstHeader("Access-Control-Allow-Origin"), nullValue());
+ assertThat(response.getFirstHeader("Access-Control-Allow-Credentials"), nullValue());
}
}
public void testThatOmittingCorsHeaderDoesNotReturnAnything() throws Exception {
- try (RestClient restClient = restClient()) {
- try (ElasticsearchResponse response = restClient.performRequest("GET", "/", Collections.emptyMap(), null)) {
- assertThat(response.getStatusLine().getStatusCode(), is(200));
- assertThat(response.getFirstHeader("Access-Control-Allow-Origin"), nullValue());
- assertThat(response.getFirstHeader("Access-Control-Allow-Credentials"), nullValue());
- }
+ try (ElasticsearchResponse response = getRestClient().performRequest("GET", "/", Collections.emptyMap(), null)) {
+ assertThat(response.getStatusLine().getStatusCode(), is(200));
+ assertThat(response.getFirstHeader("Access-Control-Allow-Origin"), nullValue());
+ assertThat(response.getFirstHeader("Access-Control-Allow-Credentials"), nullValue());
}
}
}
diff --git a/core/src/test/java/org/elasticsearch/rest/CorsRegexIT.java b/core/src/test/java/org/elasticsearch/rest/CorsRegexIT.java
index 49bfd82e61..f6012702ce 100644
--- a/core/src/test/java/org/elasticsearch/rest/CorsRegexIT.java
+++ b/core/src/test/java/org/elasticsearch/rest/CorsRegexIT.java
@@ -21,7 +21,6 @@ package org.elasticsearch.rest;
import org.apache.http.message.BasicHeader;
import org.elasticsearch.client.ElasticsearchResponse;
import org.elasticsearch.client.ElasticsearchResponseException;
-import org.elasticsearch.client.RestClient;
import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.network.NetworkModule;
@@ -62,23 +61,21 @@ public class CorsRegexIT extends ESIntegTestCase {
public void testThatRegularExpressionWorksOnMatch() throws Exception {
String corsValue = "http://localhost:9200";
- try (RestClient client = restClient()) {
- try (ElasticsearchResponse response = client.performRequest("GET", "/", Collections.emptyMap(), null,
- new BasicHeader("User-Agent", "Mozilla Bar"), new BasicHeader("Origin", corsValue))) {
- assertResponseWithOriginheader(response, corsValue);
- }
- corsValue = "https://localhost:9200";
- try (ElasticsearchResponse response = client.performRequest("GET", "/", Collections.emptyMap(), null,
- new BasicHeader("User-Agent", "Mozilla Bar"), new BasicHeader("Origin", corsValue));) {
- assertResponseWithOriginheader(response, corsValue);
- assertThat(response.getFirstHeader("Access-Control-Allow-Credentials"), is("true"));
- }
+ try (ElasticsearchResponse response = getRestClient().performRequest("GET", "/", Collections.emptyMap(), null,
+ new BasicHeader("User-Agent", "Mozilla Bar"), new BasicHeader("Origin", corsValue))) {
+ assertResponseWithOriginheader(response, corsValue);
+ }
+ corsValue = "https://localhost:9200";
+ try (ElasticsearchResponse response = getRestClient().performRequest("GET", "/", Collections.emptyMap(), null,
+ new BasicHeader("User-Agent", "Mozilla Bar"), new BasicHeader("Origin", corsValue));) {
+ assertResponseWithOriginheader(response, corsValue);
+ assertThat(response.getFirstHeader("Access-Control-Allow-Credentials"), is("true"));
}
}
public void testThatRegularExpressionReturnsForbiddenOnNonMatch() throws Exception {
- try (RestClient client = restClient()) {
- client.performRequest("GET", "/", Collections.emptyMap(), null, new BasicHeader("User-Agent", "Mozilla Bar"),
+ try {
+ getRestClient().performRequest("GET", "/", Collections.emptyMap(), null, new BasicHeader("User-Agent", "Mozilla Bar"),
new BasicHeader("Origin", "http://evil-host:9200"));
fail("request should have failed");
} catch(ElasticsearchResponseException e) {
@@ -90,39 +87,33 @@ public class CorsRegexIT extends ESIntegTestCase {
}
public void testThatSendingNoOriginHeaderReturnsNoAccessControlHeader() throws Exception {
- try (RestClient client = restClient()) {
- try (ElasticsearchResponse response = client.performRequest("GET", "/", Collections.emptyMap(), null,
- new BasicHeader("User-Agent", "Mozilla Bar"))) {
- assertThat(response.getStatusLine().getStatusCode(), is(200));
- assertThat(response.getFirstHeader("Access-Control-Allow-Origin"), nullValue());
- }
+ try (ElasticsearchResponse response = getRestClient().performRequest("GET", "/", Collections.emptyMap(), null,
+ new BasicHeader("User-Agent", "Mozilla Bar"))) {
+ assertThat(response.getStatusLine().getStatusCode(), is(200));
+ assertThat(response.getFirstHeader("Access-Control-Allow-Origin"), nullValue());
}
}
public void testThatRegularExpressionIsNotAppliedWithoutCorrectBrowserOnMatch() throws Exception {
- try (RestClient client = restClient()) {
- try (ElasticsearchResponse response = client.performRequest("GET", "/", Collections.emptyMap(), null)) {
- assertThat(response.getStatusLine().getStatusCode(), is(200));
- assertThat(response.getFirstHeader("Access-Control-Allow-Origin"), nullValue());
- }
+ try (ElasticsearchResponse response = getRestClient().performRequest("GET", "/", Collections.emptyMap(), null)) {
+ assertThat(response.getStatusLine().getStatusCode(), is(200));
+ assertThat(response.getFirstHeader("Access-Control-Allow-Origin"), nullValue());
}
}
public void testThatPreFlightRequestWorksOnMatch() throws Exception {
String corsValue = "http://localhost:9200";
- try (RestClient client = restClient()) {
- try (ElasticsearchResponse response = client.performRequest("OPTIONS", "/", Collections.emptyMap(), null,
- new BasicHeader("User-Agent", "Mozilla Bar"), new BasicHeader("Origin", corsValue),
- new BasicHeader(HttpHeaders.Names.ACCESS_CONTROL_REQUEST_METHOD, "GET"));) {
- assertResponseWithOriginheader(response, corsValue);
- assertNotNull(response.getFirstHeader("Access-Control-Allow-Methods"));
- }
+ try (ElasticsearchResponse response = getRestClient().performRequest("OPTIONS", "/", Collections.emptyMap(), null,
+ new BasicHeader("User-Agent", "Mozilla Bar"), new BasicHeader("Origin", corsValue),
+ new BasicHeader(HttpHeaders.Names.ACCESS_CONTROL_REQUEST_METHOD, "GET"));) {
+ assertResponseWithOriginheader(response, corsValue);
+ assertNotNull(response.getFirstHeader("Access-Control-Allow-Methods"));
}
}
public void testThatPreFlightRequestReturnsNullOnNonMatch() throws Exception {
- try (RestClient client = restClient()) {
- client.performRequest("OPTIONS", "/", Collections.emptyMap(), null, new BasicHeader("User-Agent", "Mozilla Bar"),
+ try {
+ getRestClient().performRequest("OPTIONS", "/", Collections.emptyMap(), null, new BasicHeader("User-Agent", "Mozilla Bar"),
new BasicHeader("Origin", "http://evil-host:9200"),
new BasicHeader(HttpHeaders.Names.ACCESS_CONTROL_REQUEST_METHOD, "GET"));
fail("request should have failed");
diff --git a/core/src/test/java/org/elasticsearch/rest/action/main/RestMainActionIT.java b/core/src/test/java/org/elasticsearch/rest/action/main/RestMainActionIT.java
index 0723a9573b..edf9b5b2c0 100644
--- a/core/src/test/java/org/elasticsearch/rest/action/main/RestMainActionIT.java
+++ b/core/src/test/java/org/elasticsearch/rest/action/main/RestMainActionIT.java
@@ -20,7 +20,6 @@ package org.elasticsearch.rest.action.main;
import org.apache.http.util.EntityUtils;
import org.elasticsearch.client.ElasticsearchResponse;
-import org.elasticsearch.client.RestClient;
import org.elasticsearch.common.network.NetworkModule;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.test.ESIntegTestCase;
@@ -41,21 +40,17 @@ public class RestMainActionIT extends ESIntegTestCase {
}
public void testHeadRequest() throws IOException {
- try (RestClient client = restClient()) {
- try (ElasticsearchResponse response = client.performRequest("HEAD", "/", Collections.emptyMap(), null)) {
- assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
- assertNull(response.getEntity());
- }
+ try (ElasticsearchResponse response = getRestClient().performRequest("HEAD", "/", Collections.emptyMap(), null)) {
+ assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
+ assertNull(response.getEntity());
}
}
public void testGetRequest() throws IOException {
- try (RestClient client = restClient()) {
- try (ElasticsearchResponse response = client.performRequest("GET", "/", Collections.emptyMap(), null)) {
- assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
- assertNotNull(response.getEntity());
- assertThat(EntityUtils.toString(response.getEntity()), containsString("cluster_name"));
- }
+ try (ElasticsearchResponse response = getRestClient().performRequest("GET", "/", Collections.emptyMap(), null)) {
+ assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
+ assertNotNull(response.getEntity());
+ assertThat(EntityUtils.toString(response.getEntity()), containsString("cluster_name"));
}
}
}
diff --git a/core/src/test/java/org/elasticsearch/transport/ContextAndHeaderTransportIT.java b/core/src/test/java/org/elasticsearch/transport/ContextAndHeaderTransportIT.java
index e2139d7321..ecee90f313 100644
--- a/core/src/test/java/org/elasticsearch/transport/ContextAndHeaderTransportIT.java
+++ b/core/src/test/java/org/elasticsearch/transport/ContextAndHeaderTransportIT.java
@@ -33,7 +33,6 @@ import org.elasticsearch.action.support.ActionFilter;
import org.elasticsearch.action.termvectors.MultiTermVectorsRequest;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.ElasticsearchResponse;
-import org.elasticsearch.client.RestClient;
import org.elasticsearch.common.inject.AbstractModule;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.inject.Module;
@@ -220,17 +219,15 @@ public class ContextAndHeaderTransportIT extends ESIntegTestCase {
restController.registerRelevantHeaders(relevantHeaderName);
}
- try (RestClient client = restClient()) {
- try (ElasticsearchResponse response = client.performRequest("GET", "/" + queryIndex + "/_search", Collections.emptyMap(), null,
- new BasicHeader(randomHeaderKey, randomHeaderValue), new BasicHeader(relevantHeaderName, randomHeaderValue))) {
- assertThat(response, hasStatus(OK));
- List<RequestAndHeaders> searchRequests = getRequests(SearchRequest.class);
- assertThat(searchRequests, hasSize(greaterThan(0)));
- for (RequestAndHeaders requestAndHeaders : searchRequests) {
- assertThat(requestAndHeaders.headers.containsKey(relevantHeaderName), is(true));
- // was not specified, thus is not included
- assertThat(requestAndHeaders.headers.containsKey(randomHeaderKey), is(false));
- }
+ try (ElasticsearchResponse response = getRestClient().performRequest("GET", "/" + queryIndex + "/_search", Collections.emptyMap(), null,
+ new BasicHeader(randomHeaderKey, randomHeaderValue), new BasicHeader(relevantHeaderName, randomHeaderValue))) {
+ assertThat(response, hasStatus(OK));
+ List<RequestAndHeaders> searchRequests = getRequests(SearchRequest.class);
+ assertThat(searchRequests, hasSize(greaterThan(0)));
+ for (RequestAndHeaders requestAndHeaders : searchRequests) {
+ assertThat(requestAndHeaders.headers.containsKey(relevantHeaderName), is(true));
+ // was not specified, thus is not included
+ assertThat(requestAndHeaders.headers.containsKey(randomHeaderKey), is(false));
}
}
}