|
31 | 31 | import org.elasticsearch.common.collect.Tuple;
|
32 | 32 | import org.elasticsearch.common.io.PathUtils;
|
33 | 33 | import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
| 34 | +import org.elasticsearch.core.internal.io.IOUtils; |
34 | 35 | import org.elasticsearch.test.rest.ESRestTestCase;
|
35 | 36 | import org.elasticsearch.test.rest.yaml.restspec.ClientYamlSuiteRestApi;
|
36 | 37 | import org.elasticsearch.test.rest.yaml.restspec.ClientYamlSuiteRestSpec;
|
@@ -105,6 +106,7 @@ public abstract class ESClientYamlSuiteTestCase extends ESRestTestCase {
|
105 | 106 | private static List<BlacklistedPathPatternMatcher> blacklistPathMatchers;
|
106 | 107 | private static ClientYamlTestExecutionContext restTestExecutionContext;
|
107 | 108 | private static ClientYamlTestExecutionContext adminExecutionContext;
|
| 109 | + private static ClientYamlTestClient clientYamlTestClient; |
108 | 110 |
|
109 | 111 | private final ClientYamlTestCandidate testCandidate;
|
110 | 112 |
|
@@ -136,7 +138,7 @@ public void initAndResetContext() throws Exception {
|
136 | 138 | final Version esVersion = versionVersionTuple.v1();
|
137 | 139 | final Version masterVersion = versionVersionTuple.v2();
|
138 | 140 | logger.info("initializing client, minimum es version [{}], master version, [{}], hosts {}", esVersion, masterVersion, hosts);
|
139 |
| - final ClientYamlTestClient clientYamlTestClient = initClientYamlTestClient(restSpec, client(), hosts, esVersion, masterVersion); |
| 141 | + clientYamlTestClient = initClientYamlTestClient(restSpec, client(), hosts, esVersion, masterVersion); |
140 | 142 | restTestExecutionContext = new ClientYamlTestExecutionContext(clientYamlTestClient, randomizeContentType());
|
141 | 143 | adminExecutionContext = new ClientYamlTestExecutionContext(clientYamlTestClient, false);
|
142 | 144 | final String[] blacklist = resolvePathsProperty(REST_TESTS_BLACKLIST, null);
|
@@ -169,6 +171,18 @@ protected ClientYamlTestClient initClientYamlTestClient(
|
169 | 171 | restClientBuilder -> configureClient(restClientBuilder, restClientSettings()));
|
170 | 172 | }
|
171 | 173 |
|
| 174 | + @AfterClass |
| 175 | + public static void closeClient() throws IOException { |
| 176 | + try { |
| 177 | + IOUtils.close(clientYamlTestClient); |
| 178 | + } finally { |
| 179 | + blacklistPathMatchers = null; |
| 180 | + restTestExecutionContext = null; |
| 181 | + adminExecutionContext = null; |
| 182 | + clientYamlTestClient = null; |
| 183 | + } |
| 184 | + } |
| 185 | + |
172 | 186 | /**
|
173 | 187 | * Create parameters for this parameterized test. Uses the
|
174 | 188 | * {@link ExecutableSection#XCONTENT_REGISTRY list} of executable sections
|
@@ -266,13 +280,6 @@ private static void validateSpec(ClientYamlSuiteRestSpec restSpec) {
|
266 | 280 | }
|
267 | 281 | }
|
268 | 282 |
|
269 |
| - @AfterClass |
270 |
| - public static void clearStatic() { |
271 |
| - blacklistPathMatchers = null; |
272 |
| - restTestExecutionContext = null; |
273 |
| - adminExecutionContext = null; |
274 |
| - } |
275 |
| - |
276 | 283 | private static Tuple<Version, Version> readVersionsFromCatNodes(RestClient restClient) throws IOException {
|
277 | 284 | // we simply go to the _cat/nodes API and parse all versions in the cluster
|
278 | 285 | Response response = restClient.performRequest("GET", "/_cat/nodes", Collections.singletonMap("h", "version,master"));
|
|
0 commit comments