From 64bbc110ff791bb0c46e6ce95b4a0dc9b0810768 Mon Sep 17 00:00:00 2001 From: Tanguy Leroux Date: Thu, 27 Aug 2015 14:14:07 +0200 Subject: [PATCH] Marvel: Fixes for Index Stats Collector tests Original commit: elastic/x-pack-elasticsearch@4fdc11946ed2bb14a6e7a2a7a4223955897c77c3 --- .../indices/IndexStatsCollectorTests.java | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/marvel/src/test/java/org/elasticsearch/marvel/agent/collector/indices/IndexStatsCollectorTests.java b/marvel/src/test/java/org/elasticsearch/marvel/agent/collector/indices/IndexStatsCollectorTests.java index b13ca2ecffb..25de0a2824f 100644 --- a/marvel/src/test/java/org/elasticsearch/marvel/agent/collector/indices/IndexStatsCollectorTests.java +++ b/marvel/src/test/java/org/elasticsearch/marvel/agent/collector/indices/IndexStatsCollectorTests.java @@ -16,6 +16,8 @@ import org.junit.Test; import java.util.Collection; import java.util.Iterator; +import java.util.concurrent.Callable; +import java.util.concurrent.TimeUnit; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount; import static org.hamcrest.Matchers.*; @@ -34,7 +36,7 @@ public class IndexStatsCollectorTests extends AbstractCollectorTestCase { public void testIndexStatsCollectorOneIndex() throws Exception { waitForNoBlocksOnNodes(); - final String indexName = "test_" + randomInt(); + final String indexName = "one-index"; final int nbDocs = randomIntBetween(1, 20); for (int i = 0; i < nbDocs; i++) { @@ -45,8 +47,14 @@ public class IndexStatsCollectorTests extends AbstractCollectorTestCase { waitForRelocation(); - Collection results = newIndexStatsCollector().doCollect(); - assertThat(results, hasSize(1)); + Collection results = assertBusy(new Callable>() { + @Override + public Collection call() throws Exception { + Collection results = newIndexStatsCollector().doCollect(); + assertThat(results, hasSize(1)); + return results; + } + }, 30L, TimeUnit.SECONDS); MarvelDoc marvelDoc = results.iterator().next(); assertNotNull(marvelDoc); @@ -73,8 +81,8 @@ public class IndexStatsCollectorTests extends AbstractCollectorTestCase { public void testIndexStatsCollectorMultipleIndices() throws Exception { waitForNoBlocksOnNodes(); - final String indexPrefix = "test_" + randomInt() + "_"; - int nbIndices = randomIntBetween(1, 5); + final String indexPrefix = "multi-indices-"; + final int nbIndices = randomIntBetween(1, 5); int[] docsPerIndex = new int[nbIndices]; for (int i = 0; i < nbIndices; i++) { @@ -92,8 +100,14 @@ public class IndexStatsCollectorTests extends AbstractCollectorTestCase { waitForRelocation(); - Collection results = newIndexStatsCollector().doCollect(); - assertThat(results, hasSize(nbIndices)); + Collection results = assertBusy(new Callable>() { + @Override + public Collection call() throws Exception { + Collection results = newIndexStatsCollector().doCollect(); + assertThat(results, hasSize(nbIndices)); + return results; + } + }, 30L, TimeUnit.SECONDS); for (int i = 0; i < nbIndices; i++) { String indexName = indexPrefix + i;