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 @Override
protected ClientYamlTestClient initClientYamlTestClient(ClientYamlSuiteRestSpec restSpec, RestClient restClient, protected ClientYamlTestClient initClientYamlTestClient(
List<HttpHost> hosts, Version esVersion) throws IOException { final ClientYamlSuiteRestSpec restSpec,
return new ClientYamlDocsTestClient(restSpec, restClient, hosts, esVersion); 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 final class ClientYamlDocsTestClient extends ClientYamlTestClient {
public ClientYamlDocsTestClient(ClientYamlSuiteRestSpec restSpec, RestClient restClient, List<HttpHost> hosts, Version esVersion) public ClientYamlDocsTestClient(
throws IOException { final ClientYamlSuiteRestSpec restSpec,
super(restSpec, restClient, hosts, esVersion); 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) 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; private final ClientYamlSuiteRestSpec restSpec;
protected final RestClient restClient; protected final RestClient restClient;
private final Version esVersion; private final Version esVersion;
private final Version masterVersion;
public ClientYamlTestClient(ClientYamlSuiteRestSpec restSpec, RestClient restClient, List<HttpHost> hosts, public ClientYamlTestClient(
Version esVersion) throws IOException { final ClientYamlSuiteRestSpec restSpec,
final RestClient restClient,
final List<HttpHost> hosts,
final Version esVersion,
final Version masterVersion) throws IOException {
assert hosts.size() > 0; assert hosts.size() > 0;
this.restSpec = restSpec; this.restSpec = restSpec;
this.restClient = restClient; this.restClient = restClient;
this.esVersion = esVersion; this.esVersion = esVersion;
this.masterVersion = masterVersion;
} }
public Version getEsVersion() { public Version getEsVersion() {
return esVersion; return esVersion;
} }
public Version getMasterVersion() {
return masterVersion;
}
/** /**
* Calls an api with the provided parameters and body * Calls an api with the provided parameters and body
*/ */

View File

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

View File

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