|
@@ -26,6 +26,7 @@ import org.elasticsearch.client.Node;
|
|
|
import org.elasticsearch.client.Request;
|
|
|
import org.elasticsearch.client.Response;
|
|
|
import org.elasticsearch.client.RestClient;
|
|
|
+import org.elasticsearch.client.RestClientBuilder;
|
|
|
import org.elasticsearch.client.sniff.ElasticsearchNodesSniffer;
|
|
|
import org.elasticsearch.common.Strings;
|
|
|
import org.elasticsearch.common.collect.Tuple;
|
|
@@ -58,13 +59,6 @@ import java.util.Set;
|
|
|
/**
|
|
|
* Runs a suite of yaml tests shared with all the official Elasticsearch
|
|
|
* clients against against an elasticsearch cluster.
|
|
|
- * <p>
|
|
|
- * <strong>IMPORTANT</strong>: These tests sniff the cluster for metadata
|
|
|
- * and hosts on startup and replace the list of hosts that they are
|
|
|
- * configured to use with the list sniffed from the cluster. So you can't
|
|
|
- * control which nodes receive the request by providing the right list of
|
|
|
- * nodes in the <code>tests.rest.cluster</code> system property. Instead
|
|
|
- * the tests must explictly use `node_selector`s.
|
|
|
*/
|
|
|
public abstract class ESClientYamlSuiteTestCase extends ESRestTestCase {
|
|
|
|
|
@@ -123,11 +117,6 @@ public abstract class ESClientYamlSuiteTestCase extends ESRestTestCase {
|
|
|
@Before
|
|
|
public void initAndResetContext() throws Exception {
|
|
|
if (restTestExecutionContext == null) {
|
|
|
- // Sniff host metadata in case we need it in the yaml tests
|
|
|
- List<Node> nodesWithMetadata = sniffHostMetadata();
|
|
|
- client().setNodes(nodesWithMetadata);
|
|
|
- adminClient().setNodes(nodesWithMetadata);
|
|
|
-
|
|
|
assert adminExecutionContext == null;
|
|
|
assert blacklistPathMatchers == null;
|
|
|
final ClientYamlSuiteRestSpec restSpec = ClientYamlSuiteRestSpec.load(SPEC_PATH);
|
|
@@ -166,8 +155,7 @@ public abstract class ESClientYamlSuiteTestCase extends ESRestTestCase {
|
|
|
final List<HttpHost> hosts,
|
|
|
final Version esVersion,
|
|
|
final Version masterVersion) {
|
|
|
- return new ClientYamlTestClient(restSpec, restClient, hosts, esVersion, masterVersion,
|
|
|
- restClientBuilder -> configureClient(restClientBuilder, restClientSettings()));
|
|
|
+ return new ClientYamlTestClient(restSpec, restClient, hosts, esVersion, masterVersion, this::getClientBuilderWithSniffedHosts);
|
|
|
}
|
|
|
|
|
|
@AfterClass
|
|
@@ -408,13 +396,16 @@ public abstract class ESClientYamlSuiteTestCase extends ESRestTestCase {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Sniff the cluster for host metadata.
|
|
|
+ * Sniff the cluster for host metadata and return a
|
|
|
+ * {@link RestClientBuilder} for a client with that metadata.
|
|
|
*/
|
|
|
- private List<Node> sniffHostMetadata() throws IOException {
|
|
|
+ protected final RestClientBuilder getClientBuilderWithSniffedHosts() throws IOException {
|
|
|
ElasticsearchNodesSniffer.Scheme scheme =
|
|
|
ElasticsearchNodesSniffer.Scheme.valueOf(getProtocol().toUpperCase(Locale.ROOT));
|
|
|
ElasticsearchNodesSniffer sniffer = new ElasticsearchNodesSniffer(
|
|
|
adminClient(), ElasticsearchNodesSniffer.DEFAULT_SNIFF_REQUEST_TIMEOUT, scheme);
|
|
|
- return sniffer.sniff();
|
|
|
+ RestClientBuilder builder = RestClient.builder(sniffer.sniff().toArray(new Node[0]));
|
|
|
+ configureClient(builder, restClientSettings());
|
|
|
+ return builder;
|
|
|
}
|
|
|
}
|