Marvel: Fix various tests inconsistencies

Original commit: elastic/x-pack-elasticsearch@1b122ecd40
This commit is contained in:
Tanguy Leroux 2015-09-02 15:09:40 +02:00
parent 892eeaf845
commit 93f6b705e4
9 changed files with 101 additions and 28 deletions

View File

@ -54,7 +54,7 @@ public class AbstractCollectorTestCase extends ESIntegTestCase {
assertNotNull(collector);
assertTrue("collector [" + collector.name() + "] should be able to collect data", collector.canCollect());
Collection results = collector.collect();
assertTrue(results != null && !results.isEmpty());
assertNotNull(results);
}
protected void assertCannotCollect(AbstractCollector collector) {

View File

@ -5,10 +5,8 @@
*/
package org.elasticsearch.marvel.agent.collector.cluster;
import org.apache.lucene.util.LuceneTestCase;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.marvel.agent.collector.AbstractCollectorTestCase;
import org.elasticsearch.marvel.agent.exporter.MarvelDoc;
@ -20,7 +18,6 @@ import java.util.Collection;
import static org.hamcrest.Matchers.*;
@LuceneTestCase.AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/13017")
public class ClusterInfoCollectorTests extends AbstractCollectorTestCase {
@Test
@ -48,7 +45,7 @@ public class ClusterInfoCollectorTests extends AbstractCollectorTestCase {
}
@Test
public void tesClusterInfoCollectorWithLicensing() {
public void testClusterInfoCollectorWithLicensing() {
String[] nodes = internalCluster().getNodeNames();
for (String node : nodes) {
logger.debug("--> creating a new instance of the collector");
@ -90,13 +87,12 @@ public class ClusterInfoCollectorTests extends AbstractCollectorTestCase {
}
private ClusterInfoCollector newClusterInfoCollector() {
return newClusterInfoCollector(null);
// This collector runs on master node only
return newClusterInfoCollector(internalCluster().getMasterName());
}
private ClusterInfoCollector newClusterInfoCollector(String nodeId) {
if (!Strings.hasText(nodeId)) {
nodeId = randomFrom(internalCluster().getNodeNames());
}
assertNotNull(nodeId);
return new ClusterInfoCollector(internalCluster().getInstance(Settings.class, nodeId),
internalCluster().getInstance(ClusterService.class, nodeId),
internalCluster().getInstance(MarvelSettings.class, nodeId),

View File

@ -8,7 +8,6 @@ package org.elasticsearch.marvel.agent.collector.cluster;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.marvel.agent.collector.AbstractCollectorTestCase;
import org.elasticsearch.marvel.agent.exporter.MarvelDoc;
@ -118,7 +117,7 @@ public class ClusterStateCollectorTests extends AbstractCollectorTestCase {
}
@Test
public void tesClusterStateCollectorWithLicensing() {
public void testClusterStateCollectorWithLicensing() {
String[] nodes = internalCluster().getNodeNames();
for (String node : nodes) {
logger.debug("--> creating a new instance of the collector");
@ -152,13 +151,12 @@ public class ClusterStateCollectorTests extends AbstractCollectorTestCase {
}
private ClusterStateCollector newClusterStateCollector() {
return newClusterStateCollector(null);
// This collector runs on master node only
return newClusterStateCollector(internalCluster().getMasterName());
}
private ClusterStateCollector newClusterStateCollector(String nodeId) {
if (!Strings.hasText(nodeId)) {
nodeId = randomFrom(internalCluster().getNodeNames());
}
assertNotNull(nodeId);
return new ClusterStateCollector(internalCluster().getInstance(Settings.class, nodeId),
internalCluster().getInstance(ClusterService.class, nodeId),
internalCluster().getInstance(MarvelSettings.class, nodeId),

View File

@ -6,7 +6,6 @@
package org.elasticsearch.marvel.agent.collector.cluster;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.marvel.agent.collector.AbstractCollectorTestCase;
import org.elasticsearch.marvel.agent.exporter.MarvelDoc;
@ -39,7 +38,7 @@ public class ClusterStatsCollectorTests extends AbstractCollectorTestCase {
}
@Test
public void tesClusterStatsCollectorWithLicensing() {
public void testClusterStatsCollectorWithLicensing() {
String[] nodes = internalCluster().getNodeNames();
for (String node : nodes) {
logger.debug("--> creating a new instance of the collector");
@ -73,13 +72,12 @@ public class ClusterStatsCollectorTests extends AbstractCollectorTestCase {
}
private ClusterStatsCollector newClusterStatsCollector() {
return newClusterStatsCollector(null);
// This collector runs on master node only
return newClusterStatsCollector(internalCluster().getMasterName());
}
private ClusterStatsCollector newClusterStatsCollector(String nodeId) {
if (!Strings.hasText(nodeId)) {
nodeId = randomFrom(internalCluster().getNodeNames());
}
assertNotNull(nodeId);
return new ClusterStatsCollector(internalCluster().getInstance(Settings.class, nodeId),
internalCluster().getInstance(ClusterService.class, nodeId),
internalCluster().getInstance(MarvelSettings.class, nodeId),

View File

@ -117,7 +117,7 @@ public class IndexRecoveryCollectorTests extends AbstractCollectorTestCase {
}
@Test
public void tesIndexRecoveryCollectorWithLicensing() {
public void testIndexRecoveryCollectorWithLicensing() {
String[] nodes = internalCluster().getNodeNames();
for (String node : nodes) {
logger.debug("--> creating a new instance of the collector");

View File

@ -6,9 +6,11 @@
package org.elasticsearch.marvel.agent.collector.indices;
import org.elasticsearch.action.admin.indices.stats.IndexStats;
import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.marvel.agent.collector.AbstractCollectorTestCase;
import org.elasticsearch.marvel.agent.collector.cluster.ClusterStatsCollector;
import org.elasticsearch.marvel.agent.exporter.MarvelDoc;
import org.elasticsearch.marvel.agent.settings.MarvelSettings;
import org.elasticsearch.marvel.license.LicenseService;
@ -43,10 +45,21 @@ public class IndexStatsCollectorTests extends AbstractCollectorTestCase {
for (int i = 0; i < nbDocs; i++) {
client().prepareIndex(indexName, "test").setSource("num", i).get();
}
client().admin().indices().prepareRefresh().get();
refresh();
waitForRelocation();
assertHitCount(client().prepareCount().get(), nbDocs);
waitForRelocation();
logger.debug("--> wait for index stats to report data about indices");
assertBusy(new Runnable() {
@Override
public void run() {
IndicesStatsResponse response = client(internalCluster().getMasterName()).admin().indices().prepareStats().setRefresh(true).get();
assertNotNull(response.getIndices());
assertThat(response.getIndices().size(), greaterThan(0));
}
}, 30L, TimeUnit.SECONDS);
Collection<MarvelDoc> results = assertBusy(new Callable<Collection<MarvelDoc>>() {
@Override
@ -100,8 +113,19 @@ public class IndexStatsCollectorTests extends AbstractCollectorTestCase {
assertHitCount(client().prepareCount(indexPrefix + i).get(), docsPerIndex[i]);
}
refresh();
waitForRelocation();
logger.debug("--> wait for index stats to report data about indices");
assertBusy(new Runnable() {
@Override
public void run() {
IndicesStatsResponse response = client().admin().indices().prepareStats().setRefresh(true).get();
assertNotNull(response.getIndices());
assertThat(response.getIndices().size(), greaterThan(0));
}
}, 30L, TimeUnit.SECONDS);
Collection<MarvelDoc> results = assertBusy(new Callable<Collection<MarvelDoc>>() {
@Override
public Collection<MarvelDoc> call() throws Exception {
@ -133,7 +157,7 @@ public class IndexStatsCollectorTests extends AbstractCollectorTestCase {
assertNotNull(indexStats.getTotal().getDocs());
assertThat(indexStats.getPrimaries().getDocs().getCount(), equalTo((long) docsPerIndex[i]));
assertNotNull(indexStats.getTotal().getStore());
assertThat(indexStats.getTotal().getStore().getSizeInBytes(), greaterThan(0L));
assertThat(indexStats.getTotal().getStore().getSizeInBytes(), greaterThanOrEqualTo(0L));
assertThat(indexStats.getTotal().getStore().getThrottleTime().millis(), equalTo(0L));
assertNotNull(indexStats.getTotal().getIndexing());
assertThat(indexStats.getTotal().getIndexing().getTotal().getThrottleTimeInMillis(), equalTo(0L));
@ -144,8 +168,47 @@ public class IndexStatsCollectorTests extends AbstractCollectorTestCase {
}
}
@Test
public void testIndexStatsCollectorWithLicensing() {
String[] nodes = internalCluster().getNodeNames();
for (String node : nodes) {
logger.debug("--> creating a new instance of the collector");
IndexStatsCollector collector = newIndexStatsCollector(node);
assertNotNull(collector);
logger.debug("--> enabling license and checks that the collector can collect data if node is master");
enableLicense();
if (node.equals(internalCluster().getMasterName())) {
assertCanCollect(collector);
} else {
assertCannotCollect(collector);
}
logger.debug("--> starting graceful period and checks that the collector can still collect data if node is master");
beginGracefulPeriod();
if (node.equals(internalCluster().getMasterName())) {
assertCanCollect(collector);
} else {
assertCannotCollect(collector);
}
logger.debug("--> ending graceful period and checks that the collector cannot collect data");
endGracefulPeriod();
assertCannotCollect(collector);
logger.debug("--> disabling license and checks that the collector cannot collect data");
disableLicense();
assertCannotCollect(collector);
}
}
private IndexStatsCollector newIndexStatsCollector() {
String nodeId = randomFrom(internalCluster().getNodeNames());
// This collector runs on master node only
return newIndexStatsCollector(internalCluster().getMasterName());
}
private IndexStatsCollector newIndexStatsCollector(String nodeId) {
assertNotNull(nodeId);
return new IndexStatsCollector(internalCluster().getInstance(Settings.class, nodeId),
internalCluster().getInstance(ClusterService.class, nodeId),
internalCluster().getInstance(MarvelSettings.class, nodeId),

View File

@ -20,6 +20,7 @@ import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
import java.util.Arrays;
import java.util.Collection;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import static org.hamcrest.Matchers.*;
@ -66,7 +67,7 @@ public abstract class AbstractRendererTestCase extends ESIntegTestCase {
fail("exception when waiting for marvel docs: " + t.getMessage());
}
}
});
}, 30L, TimeUnit.SECONDS);
}
/**

View File

@ -5,16 +5,20 @@
*/
package org.elasticsearch.marvel.agent.renderer.cluster;
import org.elasticsearch.action.admin.cluster.stats.ClusterStatsResponse;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.marvel.agent.collector.cluster.ClusterStatsCollector;
import org.elasticsearch.marvel.agent.renderer.AbstractRendererTestCase;
import org.elasticsearch.marvel.agent.settings.MarvelSettings;
import org.elasticsearch.search.SearchHit;
import org.junit.Test;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.hamcrest.Matchers.greaterThan;
public class ClusterStatsIT extends AbstractRendererTestCase {
@ -31,6 +35,19 @@ public class ClusterStatsIT extends AbstractRendererTestCase {
createIndex("test-" + i);
}
logger.debug("--> wait for cluster stats to report data about shards");
assertBusy(new Runnable() {
@Override
public void run() {
ClusterStatsResponse response = client().admin().cluster().prepareClusterStats().get();
assertNotNull(response.getIndicesStats().getShards());
assertThat(response.getIndicesStats().getShards().getTotal(), greaterThan(0));
}
}, 30L, TimeUnit.SECONDS);
logger.debug("--> delete all indices in case of cluster stats documents have been indexed with no shards data");
assertAcked(client().admin().indices().prepareDelete(MarvelSettings.MARVEL_INDICES_PREFIX + "*"));
waitForMarvelDocs(ClusterStatsCollector.TYPE);
logger.debug("--> searching for marvel documents of type [{}]", ClusterStatsCollector.TYPE);

View File

@ -28,7 +28,7 @@ public class IndexRecoveryIT extends AbstractRendererTestCase {
public void testIndexRecovery() throws Exception {
logger.debug("--> creating some indices so that index recovery collector reports data");
for (int i = 0; i < randomIntBetween(1, 5); i++) {
createIndex("test-" + i);
client().prepareIndex("test-" + i, "foo").setRefresh(true).setSource("field1", "value1").get();
}
waitForMarvelDocs(IndexRecoveryCollector.TYPE);