Tests: Fix upgrade tests by not running stats against arbitrary hosts
Original commit: elastic/x-pack-elasticsearch@91d05bc99a0613a36b294f3025a87e0d175bb3cd
@@ -137,9 +137,8 @@ public class WatchBackwardsCompatibilityIT extends ESRestTestCase {
}
public void testWatcherRestart() throws Exception {
- executeAgainstRandomNode(client -> {
- assertOK(client.performRequest("POST", "/_xpack/watcher/_stop"));
- assertBusy(() -> {
+ executeAgainstRandomNode(client -> assertOK(client.performRequest("POST", "/_xpack/watcher/_stop")));
+ executeAgainstMasterNode(client -> assertBusy(() -> {
try (InputStream is = client.performRequest("GET", "_xpack/watcher/stats").getEntity().getContent()) {
// TODO once the serialization fix is in here, we can check for concrete fields if the run against a 5.x or a 6.x node
// using a checkedbiconsumer, that provides info against which node the request runs
@@ -148,8 +147,7 @@ public class WatchBackwardsCompatibilityIT extends ESRestTestCase {
assertThat(responseBody, not(containsString("\"watcher_state\":\"started\"")));
assertThat(responseBody, not(containsString("\"watcher_state\":\"stopping\"")));
}
- });
- });
+ }));
// currently the triggered watches index is not checked by the upgrade API, resulting in an existing index
// that has not configured the `index.format: 6`, resulting in watcher not starting
@@ -160,9 +158,8 @@ public class WatchBackwardsCompatibilityIT extends ESRestTestCase {
executeUpgradeIfNeeded();
- executeAgainstRandomNode(client -> {
- assertOK(client.performRequest("POST", "/_xpack/watcher/_start"));
- assertBusy(() -> {
+ executeAgainstRandomNode(client -> assertOK(client.performRequest("POST", "/_xpack/watcher/_start")));
+ executeAgainstMasterNode(client -> assertBusy(() -> {
try (InputStream is = client.performRequest("GET", "_xpack/watcher/stats").getEntity().getContent()) {
// TODO once the serialization fix is in here, we can check for concrete fields if the run against a 5.x or a 6.x node
// using a checkedbiconsumer, that provides info against which node the request runs
@@ -171,8 +168,7 @@ public class WatchBackwardsCompatibilityIT extends ESRestTestCase {
assertThat(responseBody, not(containsString("\"watcher_state\":\"stopping\"")));
assertThat(responseBody, not(containsString("\"watcher_state\":\"stopped\"")));
}
- });
- });
+ }));
}
public void testWatchCrudApis() throws IOException {
@@ -232,6 +228,12 @@ public class WatchBackwardsCompatibilityIT extends ESRestTestCase {
}
}
+ private void executeAgainstMasterNode(CheckedConsumer<RestClient, Exception> consumer) throws Exception {
+ try (RestClient client = buildClient(restClientSettings(), new HttpHost[]{this.nodes.getMaster().publishAddress})) {
+ consumer.accept(client);
+ }
+ }
+
private void executeAgainstAllNodes(CheckedConsumer<RestClient, IOException> consumer)
throws IOException {
HttpHost[] newHosts = nodes.getNewNodes().stream().map(Node::getPublishAddress).toArray(HttpHost[]::new);
