|
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; |
@@ -104,6 +105,7 @@ public abstract class ESClientYamlSuiteTestCase extends ESRestTestCase { |
104 | 105 | private static List<BlacklistedPathPatternMatcher> blacklistPathMatchers; |
105 | 106 | private static ClientYamlTestExecutionContext restTestExecutionContext; |
106 | 107 | private static ClientYamlTestExecutionContext adminExecutionContext; |
| 108 | + private static ClientYamlTestClient clientYamlTestClient; |
107 | 109 |
|
108 | 110 | private final ClientYamlTestCandidate testCandidate; |
109 | 111 |
|
@@ -142,7 +144,7 @@ public void initAndResetContext() throws Exception { |
142 | 144 | throw ex; |
143 | 145 | } |
144 | 146 | } |
145 | | - ClientYamlTestClient clientYamlTestClient = initClientYamlTestClient(restSpec, restClient, hosts, esVersion); |
| 147 | + clientYamlTestClient = initClientYamlTestClient(restSpec, restClient, hosts, esVersion); |
146 | 148 | restTestExecutionContext = new ClientYamlTestExecutionContext(clientYamlTestClient, randomizeContentType()); |
147 | 149 | adminExecutionContext = new ClientYamlTestExecutionContext(clientYamlTestClient, false); |
148 | 150 | String[] blacklist = resolvePathsProperty(REST_TESTS_BLACKLIST, null); |
@@ -174,6 +176,18 @@ protected ClientYamlTestClient initClientYamlTestClient( |
174 | 176 | restClientBuilder -> configureClient(restClientBuilder, restClientSettings())); |
175 | 177 | } |
176 | 178 |
|
| 179 | + @AfterClass |
| 180 | + public static void closeClient() throws IOException { |
| 181 | + try { |
| 182 | + IOUtils.close(clientYamlTestClient); |
| 183 | + } finally { |
| 184 | + blacklistPathMatchers = null; |
| 185 | + restTestExecutionContext = null; |
| 186 | + adminExecutionContext = null; |
| 187 | + clientYamlTestClient = null; |
| 188 | + } |
| 189 | + } |
| 190 | + |
177 | 191 | /** |
178 | 192 | * Create parameters for this parameterized test. Uses the |
179 | 193 | * {@link ExecutableSection#XCONTENT_REGISTRY list} of executable sections |
@@ -271,13 +285,6 @@ private static void validateSpec(ClientYamlSuiteRestSpec restSpec) { |
271 | 285 | } |
272 | 286 | } |
273 | 287 |
|
274 | | - @AfterClass |
275 | | - public static void clearStatic() { |
276 | | - blacklistPathMatchers = null; |
277 | | - restTestExecutionContext = null; |
278 | | - adminExecutionContext = null; |
279 | | - } |
280 | | - |
281 | 288 | private static Tuple<Version, Version> readVersionsFromCatNodes(RestClient restClient) throws IOException { |
282 | 289 | // we simply go to the _cat/nodes API and parse all versions in the cluster |
283 | 290 | Response response = restClient.performRequest("GET", "/_cat/nodes", Collections.singletonMap("h", "version,master")); |
|
0 commit comments