[TEST] Rewrite SearchStatsTests to not shut down nodes after indexing.
The test was shutting down nodes even if some of the inidces had only a single shard. This caused that we basically had no shard active that could sever the docs and caused random failures. This commit fixed the test to rather allocate enough shards such that we never need to resize the cluster which also makes the test faster.
This commit is contained in:
parent
30ca937dbb
commit
3bc6e834cd
|
@ -28,6 +28,7 @@ import org.elasticsearch.cluster.ClusterState;
|
||||||
import org.elasticsearch.cluster.routing.GroupShardsIterator;
|
import org.elasticsearch.cluster.routing.GroupShardsIterator;
|
||||||
import org.elasticsearch.cluster.routing.ShardIterator;
|
import org.elasticsearch.cluster.routing.ShardIterator;
|
||||||
import org.elasticsearch.cluster.routing.ShardRouting;
|
import org.elasticsearch.cluster.routing.ShardRouting;
|
||||||
|
import org.elasticsearch.common.settings.ImmutableSettings;
|
||||||
import org.elasticsearch.common.unit.TimeValue;
|
import org.elasticsearch.common.unit.TimeValue;
|
||||||
import org.elasticsearch.index.query.QueryBuilders;
|
import org.elasticsearch.index.query.QueryBuilders;
|
||||||
import org.elasticsearch.index.search.stats.SearchStats.Stats;
|
import org.elasticsearch.index.search.stats.SearchStats.Stats;
|
||||||
|
@ -37,7 +38,10 @@ import org.junit.Test;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_REPLICAS;
|
||||||
|
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_SHARDS;
|
||||||
import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
|
import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
|
||||||
|
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
|
||||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAllSuccessful;
|
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAllSuccessful;
|
||||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
|
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
|
||||||
import static org.hamcrest.Matchers.*;
|
import static org.hamcrest.Matchers.*;
|
||||||
|
@ -55,29 +59,37 @@ public class SearchStatsTests extends ElasticsearchIntegrationTest {
|
||||||
public void testSimpleStats() throws Exception {
|
public void testSimpleStats() throws Exception {
|
||||||
// clear all stats first
|
// clear all stats first
|
||||||
client().admin().indices().prepareStats().clear().execute().actionGet();
|
client().admin().indices().prepareStats().clear().execute().actionGet();
|
||||||
createIndex("test1");
|
final int numNodes = cluster().dataNodes();
|
||||||
int docsTest1 = atLeast(20);
|
assertThat(numNodes, greaterThanOrEqualTo(2));
|
||||||
|
final int shardsIdx1 = randomIntBetween(1, 10); // we make sure each node gets at least a single shard...
|
||||||
|
final int shardsIdx2 = Math.max(numNodes - shardsIdx1, randomIntBetween(1, 10));
|
||||||
|
assertThat(numNodes, lessThanOrEqualTo(shardsIdx1 + shardsIdx2));
|
||||||
|
assertAcked(prepareCreate("test1").setSettings(ImmutableSettings.builder()
|
||||||
|
.put(SETTING_NUMBER_OF_SHARDS, shardsIdx1)
|
||||||
|
.put(SETTING_NUMBER_OF_REPLICAS, 0)));
|
||||||
|
int docsTest1 = scaledRandomIntBetween(3*shardsIdx1, 5*shardsIdx1);
|
||||||
for (int i = 0; i < docsTest1; i++) {
|
for (int i = 0; i < docsTest1; i++) {
|
||||||
client().prepareIndex("test1", "type", Integer.toString(i)).setSource("field", "value").execute().actionGet();
|
client().prepareIndex("test1", "type", Integer.toString(i)).setSource("field", "value").execute().actionGet();
|
||||||
if (rarely()) {
|
if (rarely()) {
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
createIndex("test2");
|
assertAcked(prepareCreate("test2").setSettings(ImmutableSettings.builder()
|
||||||
int docsTest2 = atLeast(20);
|
.put(SETTING_NUMBER_OF_SHARDS, shardsIdx2)
|
||||||
|
.put(SETTING_NUMBER_OF_REPLICAS, 0)));
|
||||||
|
int docsTest2 = scaledRandomIntBetween(3*shardsIdx2, 5*shardsIdx2);
|
||||||
for (int i = 0; i < docsTest2; i++) {
|
for (int i = 0; i < docsTest2; i++) {
|
||||||
client().prepareIndex("test2", "type", Integer.toString(i)).setSource("field", "value").execute().actionGet();
|
client().prepareIndex("test2", "type", Integer.toString(i)).setSource("field", "value").execute().actionGet();
|
||||||
if (rarely()) {
|
if (rarely()) {
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cluster().ensureAtMostNumNodes(numAssignedShards("test1", "test2"));
|
assertThat(shardsIdx1+shardsIdx2, equalTo(numAssignedShards("test1", "test2")));
|
||||||
assertThat(cluster().size(), greaterThanOrEqualTo(2));
|
|
||||||
assertThat(numAssignedShards("test1", "test2"), greaterThanOrEqualTo(2));
|
assertThat(numAssignedShards("test1", "test2"), greaterThanOrEqualTo(2));
|
||||||
// THERE WILL BE AT LEAST 2 NODES HERE SO WE CAN WAIT FOR GREEN
|
// THERE WILL BE AT LEAST 2 NODES HERE SO WE CAN WAIT FOR GREEN
|
||||||
ensureGreen();
|
ensureGreen();
|
||||||
refresh();
|
refresh();
|
||||||
int iters = atLeast(20);
|
int iters = scaledRandomIntBetween(20, 50);
|
||||||
for (int i = 0; i < iters; i++) {
|
for (int i = 0; i < iters; i++) {
|
||||||
SearchResponse searchResponse = client().prepareSearch().setQuery(QueryBuilders.termQuery("field", "value")).setStats("group1", "group2").execute().actionGet();
|
SearchResponse searchResponse = client().prepareSearch().setQuery(QueryBuilders.termQuery("field", "value")).setStats("group1", "group2").execute().actionGet();
|
||||||
assertHitCount(searchResponse, docsTest1 + docsTest2);
|
assertHitCount(searchResponse, docsTest1 + docsTest2);
|
||||||
|
@ -135,7 +147,7 @@ public class SearchStatsTests extends ElasticsearchIntegrationTest {
|
||||||
@Test
|
@Test
|
||||||
public void testOpenContexts() {
|
public void testOpenContexts() {
|
||||||
createIndex("test1");
|
createIndex("test1");
|
||||||
final int docs = atLeast(20);
|
final int docs = scaledRandomIntBetween(20, 50);
|
||||||
for (int i = 0; i < docs; i++) {
|
for (int i = 0; i < docs; i++) {
|
||||||
client().prepareIndex("test1", "type", Integer.toString(i)).setSource("field", "value").execute().actionGet();
|
client().prepareIndex("test1", "type", Integer.toString(i)).setSource("field", "value").execute().actionGet();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue