From 23a94bb9745aeba8bc8c04c02c874deaf89ae621 Mon Sep 17 00:00:00 2001 From: javanna Date: Fri, 3 Jun 2016 18:00:54 +0200 Subject: [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. --- .../plugins/ResponseHeaderPluginIT.java | 27 ++++++++++------------ 1 file changed, 12 insertions(+), 15 deletions(-) (limited to 'core/src/test/java/org/elasticsearch/plugins') 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")); } } } -- cgit v1.2.3