[TEST] Wait for nodes to join before asserting on cluster stats
This commit is contained in:
parent
940954bfd1
commit
4d6eb369a3
|
@ -20,7 +20,9 @@
|
||||||
package org.elasticsearch.action.admin.cluster.stats;
|
package org.elasticsearch.action.admin.cluster.stats;
|
||||||
|
|
||||||
import org.elasticsearch.Version;
|
import org.elasticsearch.Version;
|
||||||
|
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
|
||||||
import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
|
import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
|
||||||
|
import org.elasticsearch.client.Requests;
|
||||||
import org.elasticsearch.common.settings.ImmutableSettings;
|
import org.elasticsearch.common.settings.ImmutableSettings;
|
||||||
import org.elasticsearch.monitor.sigar.SigarService;
|
import org.elasticsearch.monitor.sigar.SigarService;
|
||||||
import org.elasticsearch.test.ElasticsearchIntegrationTest;
|
import org.elasticsearch.test.ElasticsearchIntegrationTest;
|
||||||
|
@ -28,7 +30,9 @@ import org.elasticsearch.test.ElasticsearchIntegrationTest.ClusterScope;
|
||||||
import org.hamcrest.Matchers;
|
import org.hamcrest.Matchers;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
@ClusterScope(scope = ElasticsearchIntegrationTest.Scope.TEST, numNodes = 0)
|
import static org.hamcrest.Matchers.is;
|
||||||
|
|
||||||
|
@ClusterScope(scope = ElasticsearchIntegrationTest.Scope.SUITE, numNodes = 1)
|
||||||
public class ClusterStatsTests extends ElasticsearchIntegrationTest {
|
public class ClusterStatsTests extends ElasticsearchIntegrationTest {
|
||||||
|
|
||||||
private void assertCounts(ClusterStatsNodes.Counts counts, int total, int masterOnly, int dataOnly, int masterData, int client) {
|
private void assertCounts(ClusterStatsNodes.Counts counts, int total, int masterOnly, int dataOnly, int masterData, int client) {
|
||||||
|
@ -39,22 +43,30 @@ public class ClusterStatsTests extends ElasticsearchIntegrationTest {
|
||||||
assertThat(counts.getClient(), Matchers.equalTo(client));
|
assertThat(counts.getClient(), Matchers.equalTo(client));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void waitForNodes(int numNodes) {
|
||||||
|
ClusterHealthResponse actionGet = client().admin().cluster()
|
||||||
|
.health(Requests.clusterHealthRequest().waitForNodes(Integer.toString(numNodes))).actionGet();
|
||||||
|
assertThat(actionGet.isTimedOut(), is(false));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNodeCounts() {
|
public void testNodeCounts() {
|
||||||
cluster().startNode();
|
|
||||||
ClusterStatsResponse response = client().admin().cluster().prepareClusterStats().get();
|
ClusterStatsResponse response = client().admin().cluster().prepareClusterStats().get();
|
||||||
assertCounts(response.getNodesStats().getCounts(), 1, 0, 0, 1, 0);
|
assertCounts(response.getNodesStats().getCounts(), 1, 0, 0, 1, 0);
|
||||||
|
|
||||||
cluster().startNode(ImmutableSettings.builder().put("node.data", false));
|
cluster().startNode(ImmutableSettings.builder().put("node.data", false));
|
||||||
|
waitForNodes(2);
|
||||||
response = client().admin().cluster().prepareClusterStats().get();
|
response = client().admin().cluster().prepareClusterStats().get();
|
||||||
assertCounts(response.getNodesStats().getCounts(), 2, 1, 0, 1, 0);
|
assertCounts(response.getNodesStats().getCounts(), 2, 1, 0, 1, 0);
|
||||||
|
|
||||||
cluster().startNode(ImmutableSettings.builder().put("node.master", false));
|
cluster().startNode(ImmutableSettings.builder().put("node.master", false));
|
||||||
response = client().admin().cluster().prepareClusterStats().get();
|
response = client().admin().cluster().prepareClusterStats().get();
|
||||||
|
waitForNodes(3);
|
||||||
assertCounts(response.getNodesStats().getCounts(), 3, 1, 1, 1, 0);
|
assertCounts(response.getNodesStats().getCounts(), 3, 1, 1, 1, 0);
|
||||||
|
|
||||||
cluster().startNode(ImmutableSettings.builder().put("node.client", true));
|
cluster().startNode(ImmutableSettings.builder().put("node.client", true));
|
||||||
response = client().admin().cluster().prepareClusterStats().get();
|
response = client().admin().cluster().prepareClusterStats().get();
|
||||||
|
waitForNodes(4);
|
||||||
assertCounts(response.getNodesStats().getCounts(), 4, 1, 1, 1, 1);
|
assertCounts(response.getNodesStats().getCounts(), 4, 1, 1, 1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,8 +80,6 @@ public class ClusterStatsTests extends ElasticsearchIntegrationTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIndicesShardStats() {
|
public void testIndicesShardStats() {
|
||||||
cluster().startNode();
|
|
||||||
|
|
||||||
ClusterStatsResponse response = client().admin().cluster().prepareClusterStats().get();
|
ClusterStatsResponse response = client().admin().cluster().prepareClusterStats().get();
|
||||||
assertThat(response.getStatus(), Matchers.equalTo(ClusterHealthStatus.GREEN));
|
assertThat(response.getStatus(), Matchers.equalTo(ClusterHealthStatus.GREEN));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue