[TEST] call yaml client close method from test suite
We added a way to close the yaml test client with
Such close method also needs to be called from the test suite though for
the additional clients to be closed.
@@ -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;
@@ -104,6 +105,7 @@ public abstract class ESClientYamlSuiteTestCase extends ESRestTestCase {
private static List<BlacklistedPathPatternMatcher> blacklistPathMatchers;
private static ClientYamlTestExecutionContext restTestExecutionContext;
private static ClientYamlTestExecutionContext adminExecutionContext;
+ private static ClientYamlTestClient clientYamlTestClient;
private final ClientYamlTestCandidate testCandidate;
@@ -142,7 +144,7 @@ public abstract class ESClientYamlSuiteTestCase extends ESRestTestCase {
throw ex;
}
}
- ClientYamlTestClient clientYamlTestClient = initClientYamlTestClient(restSpec, restClient, hosts, esVersion);
+ clientYamlTestClient = initClientYamlTestClient(restSpec, restClient, hosts, esVersion);
restTestExecutionContext = new ClientYamlTestExecutionContext(clientYamlTestClient, randomizeContentType());
adminExecutionContext = new ClientYamlTestExecutionContext(clientYamlTestClient, false);
String[] blacklist = resolvePathsProperty(REST_TESTS_BLACKLIST, null);
@@ -174,6 +176,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
@@ -271,13 +285,6 @@ public abstract class ESClientYamlSuiteTestCase extends ESRestTestCase {
}
}
- @AfterClass
- public static void clearStatic() {
- blacklistPathMatchers = null;
- restTestExecutionContext = null;
- adminExecutionContext = null;
- }
-
private static Tuple<Version, Version> 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"));
