Skip to content

Commit

Permalink
[TEST] call yaml client close method from test suite (#31591)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
javanna authored Jun 27, 2018
1 parent 13e1cf6 commit a35b534
Showing 1 changed file with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
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;
Expand Down Expand Up @@ -105,6 +106,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;

Expand Down Expand Up @@ -136,7 +138,7 @@ public void initAndResetContext() throws Exception {
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);
Expand Down Expand Up @@ -169,6 +171,18 @@ protected ClientYamlTestClient initClientYamlTestClient(
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
Expand Down Expand Up @@ -266,13 +280,6 @@ private static void validateSpec(ClientYamlSuiteRestSpec restSpec) {
}
}

@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"));
Expand Down

0 comments on commit a35b534

Please sign in to comment.