From a35b5341c41ef06022d4644be5d601654e16d77b Mon Sep 17 00:00:00 2001 From: Luca Cavanna Date: Wed, 27 Jun 2018 08:23:53 +0200 Subject: [PATCH] [TEST] call yaml client close method from test suite (#31591) We added a way to close the yaml test client with #31575. Such close method also needs to be called from the test suite though for the additional clients to be closed. --- .../rest/yaml/ESClientYamlSuiteTestCase.java | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ESClientYamlSuiteTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ESClientYamlSuiteTestCase.java index 6afc123520b..69f4e0666ea 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ESClientYamlSuiteTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ESClientYamlSuiteTestCase.java @@ -31,6 +31,7 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.collect.Tuple; import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.xcontent.NamedXContentRegistry; +import org.elasticsearch.core.internal.io.IOUtils; import org.elasticsearch.test.rest.ESRestTestCase; import org.elasticsearch.test.rest.yaml.restspec.ClientYamlSuiteRestApi; import org.elasticsearch.test.rest.yaml.restspec.ClientYamlSuiteRestSpec; @@ -105,6 +106,7 @@ public abstract class ESClientYamlSuiteTestCase extends ESRestTestCase { private static List blacklistPathMatchers; private static ClientYamlTestExecutionContext restTestExecutionContext; private static ClientYamlTestExecutionContext adminExecutionContext; + private static ClientYamlTestClient clientYamlTestClient; private final ClientYamlTestCandidate testCandidate; @@ -136,7 +138,7 @@ public abstract class ESClientYamlSuiteTestCase extends ESRestTestCase { final Version esVersion = versionVersionTuple.v1(); final Version masterVersion = versionVersionTuple.v2(); logger.info("initializing client, minimum es version [{}], master version, [{}], hosts {}", esVersion, masterVersion, hosts); - final ClientYamlTestClient clientYamlTestClient = initClientYamlTestClient(restSpec, client(), hosts, esVersion, masterVersion); + clientYamlTestClient = initClientYamlTestClient(restSpec, client(), hosts, esVersion, masterVersion); restTestExecutionContext = new ClientYamlTestExecutionContext(clientYamlTestClient, randomizeContentType()); adminExecutionContext = new ClientYamlTestExecutionContext(clientYamlTestClient, false); final String[] blacklist = resolvePathsProperty(REST_TESTS_BLACKLIST, null); @@ -169,6 +171,18 @@ public abstract class ESClientYamlSuiteTestCase extends ESRestTestCase { restClientBuilder -> configureClient(restClientBuilder, restClientSettings())); } + @AfterClass + public static void closeClient() throws IOException { + try { + IOUtils.close(clientYamlTestClient); + } finally { + blacklistPathMatchers = null; + restTestExecutionContext = null; + adminExecutionContext = null; + clientYamlTestClient = null; + } + } + /** * Create parameters for this parameterized test. Uses the * {@link ExecutableSection#XCONTENT_REGISTRY list} of executable sections @@ -266,13 +280,6 @@ public abstract class ESClientYamlSuiteTestCase extends ESRestTestCase { } } - @AfterClass - public static void clearStatic() { - blacklistPathMatchers = null; - restTestExecutionContext = null; - adminExecutionContext = null; - } - private static Tuple readVersionsFromCatNodes(RestClient restClient) throws IOException { // we simply go to the _cat/nodes API and parse all versions in the cluster Response response = restClient.performRequest("GET", "/_cat/nodes", Collections.singletonMap("h", "version,master"));