Watcher: Fix BWC tests, disable test requiring upgrade API

Original commit: elastic/x-pack-elasticsearch@e8de71cdf7
This commit is contained in:
Alexander Reelsen 2017-06-07 11:09:14 +02:00
parent ae299f633e
commit 887538d6bc
1 changed files with 23 additions and 17 deletions

View File

@ -27,6 +27,7 @@ import org.junit.Before;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Base64; import java.util.Base64;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
@ -47,6 +48,8 @@ import static org.hamcrest.Matchers.greaterThanOrEqualTo;
public class WatchBackwardsCompatibilityIT extends ESRestTestCase { public class WatchBackwardsCompatibilityIT extends ESRestTestCase {
private Nodes nodes;
@Before @Before
public void waitForSecuritySetup() throws Exception { public void waitForSecuritySetup() throws Exception {
String masterNode = null; String masterNode = null;
@ -97,15 +100,8 @@ public class WatchBackwardsCompatibilityIT extends ESRestTestCase {
throw new AssertionError("failed to get cluster state", e); throw new AssertionError("failed to get cluster state", e);
} }
}); });
}
private Nodes nodes;
@Before
public void ensureNewNodesAreInCluster() throws IOException {
nodes = buildNodeAndVersions(); nodes = buildNodeAndVersions();
assumeFalse("new nodes is empty", nodes.getNewNodes().isEmpty());
} }
@Override @Override
@ -135,7 +131,12 @@ public class WatchBackwardsCompatibilityIT extends ESRestTestCase {
}); });
} }
// we have to have finish the upgrade API first to make this test work, so we can call it instead of
// https://github.com/elastic/x-pack-elasticsearch/issues/1303
@AwaitsFix(bugUrl = "https://github.com/elastic/x-pack-elasticsearch/pull/1603")
public void testWatchCrudApis() throws IOException { public void testWatchCrudApis() throws IOException {
assumeFalse("new nodes is empty", nodes.getNewNodes().isEmpty());
BytesReference bytesReference = watchBuilder() BytesReference bytesReference = watchBuilder()
.trigger(schedule(interval("5m"))) .trigger(schedule(interval("5m")))
.input(simpleInput()) .input(simpleInput())
@ -158,18 +159,24 @@ public class WatchBackwardsCompatibilityIT extends ESRestTestCase {
public void executeAgainstAllNodes(CheckedConsumer<RestClient, IOException> consumer) public void executeAgainstAllNodes(CheckedConsumer<RestClient, IOException> consumer)
throws IOException { throws IOException {
try (RestClient newClient = buildClient(restClientSettings(), HttpHost[] newHosts = nodes.getNewNodes().stream().map(Node::getPublishAddress).toArray(HttpHost[]::new);
nodes.getNewNodes().stream().map(Node::getPublishAddress) HttpHost[] bwcHosts = nodes.getBWCNodes().stream().map(Node::getPublishAddress).toArray(HttpHost[]::new);
.toArray(HttpHost[]::new))) {
logger.info("# of bwc nodes [{}], number of new nodes [{}]", Arrays.asList(bwcHosts), Arrays.asList(newHosts));
assertTrue("No nodes in cluster, cannot run any tests", newHosts.length > 0 || bwcHosts.length > 0);
if (newHosts.length > 0) {
try (RestClient newClient = buildClient(restClientSettings(), newHosts)) {
consumer.accept(newClient); consumer.accept(newClient);
} }
}
try (RestClient bwcClient = buildClient(restClientSettings(), if (bwcHosts.length > 0) {
nodes.getBWCNodes().stream().map(Node::getPublishAddress) try (RestClient bwcClient = buildClient(restClientSettings(), bwcHosts)) {
.toArray(HttpHost[]::new))) {
consumer.accept(bwcClient); consumer.accept(bwcClient);
} }
} }
}
private void assertOK(Response response) { private void assertOK(Response response) {
assertThat(response.getStatusLine().getStatusCode(), anyOf(equalTo(200), equalTo(201))); assertThat(response.getStatusLine().getStatusCode(), anyOf(equalTo(200), equalTo(201)));
@ -244,8 +251,7 @@ public class WatchBackwardsCompatibilityIT extends ESRestTestCase {
if (isEmpty()) { if (isEmpty()) {
throw new IllegalStateException("no nodes available"); throw new IllegalStateException("no nodes available");
} }
return Version.fromId(values().stream().map(node -> node.getVersion().id) return Version.fromId(values().stream().map(node -> node.getVersion().id).min(Integer::compareTo).get());
.min(Integer::compareTo).get());
} }
public Node getSafe(String id) { public Node getSafe(String id) {