Expose master version in REST test context (#30623)

This commit exposes the master version to the REST test context. This
will be needed in a follow-up where the master version will be used to
determine whether or not a certain warning header is expected.
This commit is contained in:
Jason Tedor 2018-05-15 17:26:43 -04:00 committed by GitHub
parent 869b639d14
commit abc06d5b79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 53 additions and 37 deletions

View File

@ -86,9 +86,13 @@ public class DocsClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase {
}
@Override
protected ClientYamlTestClient initClientYamlTestClient(ClientYamlSuiteRestSpec restSpec, RestClient restClient,
List<HttpHost> hosts, Version esVersion) throws IOException {
return new ClientYamlDocsTestClient(restSpec, restClient, hosts, esVersion);
protected ClientYamlTestClient initClientYamlTestClient(
final ClientYamlSuiteRestSpec restSpec,
final RestClient restClient,
final List<HttpHost> hosts,
final Version esVersion,
final Version masterVersion) throws IOException {
return new ClientYamlDocsTestClient(restSpec, restClient, hosts, esVersion, masterVersion);
}
/**

View File

@ -40,9 +40,13 @@ import java.util.Objects;
*/
public final class ClientYamlDocsTestClient extends ClientYamlTestClient {
public ClientYamlDocsTestClient(ClientYamlSuiteRestSpec restSpec, RestClient restClient, List<HttpHost> hosts, Version esVersion)
throws IOException {
super(restSpec, restClient, hosts, esVersion);
public ClientYamlDocsTestClient(
final ClientYamlSuiteRestSpec restSpec,
final RestClient restClient,
final List<HttpHost> hosts,
final Version esVersion,
final Version masterVersion) throws IOException {
super(restSpec, restClient, hosts, esVersion, masterVersion);
}
public ClientYamlTestResponse callApi(String apiName, Map<String, String> params, HttpEntity entity, Map<String, String> headers)

View File

@ -59,19 +59,29 @@ public class ClientYamlTestClient {
private final ClientYamlSuiteRestSpec restSpec;
protected final RestClient restClient;
private final Version esVersion;
private final Version masterVersion;
public ClientYamlTestClient(ClientYamlSuiteRestSpec restSpec, RestClient restClient, List<HttpHost> hosts,
Version esVersion) throws IOException {
public ClientYamlTestClient(
final ClientYamlSuiteRestSpec restSpec,
final RestClient restClient,
final List<HttpHost> hosts,
final Version esVersion,
final Version masterVersion) throws IOException {
assert hosts.size() > 0;
this.restSpec = restSpec;
this.restClient = restClient;
this.esVersion = esVersion;
this.masterVersion = masterVersion;
}
public Version getEsVersion() {
return esVersion;
}
public Version getMasterVersion() {
return masterVersion;
}
/**
* Calls an api with the provided parameters and body
*/

View File

@ -185,4 +185,8 @@ public class ClientYamlTestExecutionContext {
return clientYamlTestClient.getEsVersion();
}
public Version masterVersion() {
return clientYamlTestClient.getMasterVersion();
}
}

View File

@ -111,33 +111,19 @@ public abstract class ESClientYamlSuiteTestCase extends ESRestTestCase {
if (restTestExecutionContext == null) {
assert adminExecutionContext == null;
assert blacklistPathMatchers == null;
ClientYamlSuiteRestSpec restSpec = ClientYamlSuiteRestSpec.load(SPEC_PATH);
final ClientYamlSuiteRestSpec restSpec = ClientYamlSuiteRestSpec.load(SPEC_PATH);
validateSpec(restSpec);
List<HttpHost> hosts = getClusterHosts();
RestClient restClient = client();
Version infoVersion = readVersionsFromInfo(restClient, hosts.size());
Version esVersion;
try {
Tuple<Version, Version> versionVersionTuple = readVersionsFromCatNodes(restClient);
esVersion = versionVersionTuple.v1();
Version masterVersion = versionVersionTuple.v2();
logger.info("initializing yaml client, minimum es version: [{}] master version: [{}] hosts: {}",
esVersion, masterVersion, hosts);
} catch (ResponseException ex) {
if (ex.getResponse().getStatusLine().getStatusCode() == 403) {
logger.warn("Fallback to simple info '/' request, _cat/nodes is not authorized");
esVersion = infoVersion;
logger.info("initializing yaml client, minimum es version: [{}] hosts: {}", esVersion, hosts);
} else {
throw ex;
}
}
ClientYamlTestClient clientYamlTestClient = initClientYamlTestClient(restSpec, restClient, hosts, esVersion);
final List<HttpHost> hosts = getClusterHosts();
Tuple<Version, Version> versionVersionTuple = readVersionsFromCatNodes(adminClient());
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);
restTestExecutionContext = new ClientYamlTestExecutionContext(clientYamlTestClient, randomizeContentType());
adminExecutionContext = new ClientYamlTestExecutionContext(clientYamlTestClient, false);
String[] blacklist = resolvePathsProperty(REST_TESTS_BLACKLIST, null);
final String[] blacklist = resolvePathsProperty(REST_TESTS_BLACKLIST, null);
blacklistPathMatchers = new ArrayList<>();
for (String entry : blacklist) {
for (final String entry : blacklist) {
blacklistPathMatchers.add(new BlacklistedPathPatternMatcher(entry));
}
}
@ -151,9 +137,13 @@ public abstract class ESClientYamlSuiteTestCase extends ESRestTestCase {
restTestExecutionContext.clear();
}
protected ClientYamlTestClient initClientYamlTestClient(ClientYamlSuiteRestSpec restSpec, RestClient restClient,
List<HttpHost> hosts, Version esVersion) throws IOException {
return new ClientYamlTestClient(restSpec, restClient, hosts, esVersion);
protected ClientYamlTestClient initClientYamlTestClient(
final ClientYamlSuiteRestSpec restSpec,
final RestClient restClient,
final List<HttpHost> hosts,
final Version esVersion,
final Version masterVersion) throws IOException {
return new ClientYamlTestClient(restSpec, restClient, hosts, esVersion, masterVersion);
}
/**

View File

@ -53,9 +53,13 @@ public class XDocsClientYamlTestSuiteIT extends XPackRestIT {
}
@Override
protected ClientYamlTestClient initClientYamlTestClient(ClientYamlSuiteRestSpec restSpec, RestClient restClient,
List<HttpHost> hosts, Version esVersion) throws IOException {
return new ClientYamlDocsTestClient(restSpec, restClient, hosts, esVersion);
protected ClientYamlTestClient initClientYamlTestClient(
final ClientYamlSuiteRestSpec restSpec,
final RestClient restClient,
final List<HttpHost> hosts,
final Version esVersion,
final Version masterVersion) throws IOException {
return new ClientYamlDocsTestClient(restSpec, restClient, hosts, esVersion, masterVersion);
}
/**