Marvel: Fix MultiNodesStatsTests
Closes elastic/elasticsearch#960 Original commit: elastic/x-pack-elasticsearch@969f22fcf7
This commit is contained in:
parent
d4afcf4e4e
commit
e6832e5881
|
@ -5,23 +5,27 @@
|
||||||
*/
|
*/
|
||||||
package org.elasticsearch.marvel.agent.renderer.node;
|
package org.elasticsearch.marvel.agent.renderer.node;
|
||||||
|
|
||||||
import org.apache.lucene.util.LuceneTestCase;
|
|
||||||
import org.elasticsearch.action.search.SearchResponse;
|
import org.elasticsearch.action.search.SearchResponse;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.index.query.QueryBuilders;
|
|
||||||
import org.elasticsearch.marvel.agent.collector.node.NodeStatsCollector;
|
import org.elasticsearch.marvel.agent.collector.node.NodeStatsCollector;
|
||||||
import org.elasticsearch.marvel.agent.settings.MarvelSettings;
|
import org.elasticsearch.marvel.agent.settings.MarvelSettings;
|
||||||
import org.elasticsearch.marvel.test.MarvelIntegTestCase;
|
import org.elasticsearch.marvel.test.MarvelIntegTestCase;
|
||||||
|
import org.elasticsearch.search.aggregations.Aggregation;
|
||||||
|
import org.elasticsearch.search.aggregations.AggregationBuilders;
|
||||||
|
import org.elasticsearch.search.aggregations.bucket.terms.StringTerms;
|
||||||
import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
|
import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
|
||||||
import org.elasticsearch.test.ESIntegTestCase.Scope;
|
import org.elasticsearch.test.ESIntegTestCase.Scope;
|
||||||
|
import org.elasticsearch.test.InternalTestCluster;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
|
||||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoTimeout;
|
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoTimeout;
|
||||||
import static org.hamcrest.Matchers.greaterThan;
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
|
import static org.hamcrest.Matchers.instanceOf;
|
||||||
|
|
||||||
@LuceneTestCase.AwaitsFix(bugUrl = "https://github.com/elastic/x-plugins/issues/960")
|
|
||||||
@ClusterScope(scope = Scope.TEST, numDataNodes = 0, numClientNodes = 0, transportClientRatio = 0.0)
|
@ClusterScope(scope = Scope.TEST, numDataNodes = 0, numClientNodes = 0, transportClientRatio = 0.0)
|
||||||
public class MultiNodesStatsTests extends MarvelIntegTestCase {
|
public class MultiNodesStatsTests extends MarvelIntegTestCase {
|
||||||
|
|
||||||
|
@ -41,30 +45,38 @@ public class MultiNodesStatsTests extends MarvelIntegTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMultipleNodes() throws Exception {
|
public void testMultipleNodes() throws Exception {
|
||||||
logger.debug("--> starting a master only node");
|
int nodes = 0;
|
||||||
internalCluster().startMasterOnlyNodeAsync();
|
|
||||||
|
|
||||||
logger.debug("--> starting a data only node");
|
int n = randomIntBetween(1, 2);
|
||||||
internalCluster().startDataOnlyNodeAsync();
|
logger.debug("--> starting {} master only nodes", n);
|
||||||
|
InternalTestCluster.Async<List<String>> masterNodes = internalCluster().startMasterOnlyNodesAsync(n);
|
||||||
|
masterNodes.get();
|
||||||
|
nodes += n;
|
||||||
|
|
||||||
logger.debug("--> starting a client node");
|
n = randomIntBetween(2, 3);
|
||||||
internalCluster().startNodeClient(Settings.EMPTY);
|
logger.debug("--> starting {} data only nodes", n);
|
||||||
|
InternalTestCluster.Async<List<String>> dataNodes = internalCluster().startDataOnlyNodesAsync(n);
|
||||||
|
dataNodes.get();
|
||||||
|
nodes += n;
|
||||||
|
|
||||||
logger.debug("--> starting few other nodes");
|
n = randomIntBetween(1, 2);
|
||||||
int extraNodes = randomIntBetween(2, 5);
|
logger.debug("--> starting {} client only nodes", n);
|
||||||
for (int i = 0; i < extraNodes; i++) {
|
InternalTestCluster.Async<List<String>> clientNodes = internalCluster().startNodesAsync(n, settingsBuilder().put("node.client", true).build());
|
||||||
if (randomBoolean()) {
|
clientNodes.get();
|
||||||
internalCluster().startNodeAsync();
|
nodes += n;
|
||||||
} else {
|
|
||||||
internalCluster().startNodeClient(Settings.EMPTY);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final int nbNodes = 3 + extraNodes;
|
n = randomIntBetween(1, 2);
|
||||||
|
logger.debug("--> starting {} extra nodes", n);
|
||||||
|
InternalTestCluster.Async<List<String>> extraNodes = internalCluster().startNodesAsync(n);
|
||||||
|
extraNodes.get();
|
||||||
|
nodes += n;
|
||||||
|
|
||||||
|
final int nbNodes = nodes;
|
||||||
logger.debug("--> waiting for {} nodes to be available", nbNodes);
|
logger.debug("--> waiting for {} nodes to be available", nbNodes);
|
||||||
assertBusy(new Runnable() {
|
assertBusy(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
assertThat(cluster().size(), equalTo(nbNodes));
|
||||||
assertNoTimeout(client().admin().cluster().prepareHealth().setWaitForNodes(Integer.toString(nbNodes)).get());
|
assertNoTimeout(client().admin().cluster().prepareHealth().setWaitForNodes(Integer.toString(nbNodes)).get());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -77,15 +89,22 @@ public class MultiNodesStatsTests extends MarvelIntegTestCase {
|
||||||
public void run() {
|
public void run() {
|
||||||
securedFlush();
|
securedFlush();
|
||||||
|
|
||||||
for (String nodeName : internalCluster().getNodeNames()) {
|
SearchResponse response = client().prepareSearch()
|
||||||
SearchResponse response = client(nodeName).prepareSearch()
|
.setTypes(NodeStatsCollector.TYPE)
|
||||||
.setTypes(NodeStatsCollector.TYPE)
|
.setSize(0)
|
||||||
.setQuery(QueryBuilders.termQuery("node_stats.node_id", internalCluster().clusterService(nodeName).localNode().getId()))
|
.addAggregation(AggregationBuilders.terms("nodes_ids").field("node_stats.node_id"))
|
||||||
.get();
|
.get();
|
||||||
assertThat(response.getHits().getTotalHits(), greaterThan(0L));
|
|
||||||
|
for (Aggregation aggregation : response.getAggregations()) {
|
||||||
|
assertThat(aggregation, instanceOf(StringTerms.class));
|
||||||
|
assertThat(((StringTerms) aggregation).getBuckets().size(), equalTo(nbNodes));
|
||||||
|
|
||||||
|
for (String nodeName : internalCluster().getNodeNames()) {
|
||||||
|
StringTerms.Bucket bucket = (StringTerms.Bucket) ((StringTerms) aggregation).getBucketByKey(internalCluster().clusterService(nodeName).localNode().getId());
|
||||||
|
assertThat(bucket.getDocCount(), equalTo(1L));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue