Marvel: fix test in IndexStatsCollectorTests

Closes  elastic/elasticsearch#357

Original commit: elastic/x-pack-elasticsearch@5e37eb2fcc
This commit is contained in:
Tanguy Leroux 2015-07-29 16:37:34 +02:00
parent 1628ce2061
commit bedab83929
1 changed files with 20 additions and 3 deletions

View File

@ -5,13 +5,15 @@
*/ */
package org.elasticsearch.marvel.agent.collector.indices; package org.elasticsearch.marvel.agent.collector.indices;
import com.google.common.collect.ImmutableSet;
import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.cluster.block.ClusterBlock;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.marvel.agent.exporter.MarvelDoc; import org.elasticsearch.marvel.agent.exporter.MarvelDoc;
import org.elasticsearch.marvel.agent.settings.MarvelSettingsService; import org.elasticsearch.marvel.agent.settings.MarvelSettingsService;
import org.elasticsearch.test.ElasticsearchSingleNodeTest; import org.elasticsearch.test.ElasticsearchSingleNodeTest;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import java.util.Collection; import java.util.Collection;
@ -23,15 +25,17 @@ import static org.hamcrest.Matchers.*;
public class IndexStatsCollectorTests extends ElasticsearchSingleNodeTest { public class IndexStatsCollectorTests extends ElasticsearchSingleNodeTest {
@Test @Test
@AwaitsFix(bugUrl = "https://github.com/elastic/x-plugins/issues/357")
@Ignore
public void testIndexStatsCollectorNoIndices() throws Exception { public void testIndexStatsCollectorNoIndices() throws Exception {
waitForNoBlocksOnNode();
Collection<MarvelDoc> results = newIndexStatsCollector().doCollect(); Collection<MarvelDoc> results = newIndexStatsCollector().doCollect();
assertThat(results, is(empty())); assertThat(results, is(empty()));
} }
@Test @Test
public void testIndexStatsCollectorOneIndex() throws Exception { public void testIndexStatsCollectorOneIndex() throws Exception {
waitForNoBlocksOnNode();
int nbDocs = randomIntBetween(1, 20); int nbDocs = randomIntBetween(1, 20);
for (int i = 0; i < nbDocs; i++) { for (int i = 0; i < nbDocs; i++) {
client().prepareIndex("test", "test").setSource("num", i).get(); client().prepareIndex("test", "test").setSource("num", i).get();
@ -63,6 +67,8 @@ public class IndexStatsCollectorTests extends ElasticsearchSingleNodeTest {
@Test @Test
public void testIndexStatsCollectorMultipleIndices() throws Exception { public void testIndexStatsCollectorMultipleIndices() throws Exception {
waitForNoBlocksOnNode();
int nbIndices = randomIntBetween(1, 5); int nbIndices = randomIntBetween(1, 5);
int[] docsPerIndex = new int[nbIndices]; int[] docsPerIndex = new int[nbIndices];
@ -117,4 +123,15 @@ public class IndexStatsCollectorTests extends ElasticsearchSingleNodeTest {
client(), client(),
getInstanceFromNode(MarvelSettingsService.class)); getInstanceFromNode(MarvelSettingsService.class));
} }
public void waitForNoBlocksOnNode() throws InterruptedException {
final long start = System.currentTimeMillis();
final TimeValue timeout = TimeValue.timeValueSeconds(30);
ImmutableSet<ClusterBlock> blocks;
do {
blocks = client().admin().cluster().prepareState().setLocal(true).execute().actionGet().getState().blocks().global();
}
while (!blocks.isEmpty() && (System.currentTimeMillis() - start) < timeout.millis());
assertTrue(blocks.isEmpty());
}
} }