[TEST] make sure all shards have docs

we need that in order for refresh to be effective and actually refresh in the second round of indexing, otherwise, it caches a 0 docs shard and a refresh won't expire anything there
This commit is contained in:
Shay Banon 2014-08-05 20:28:47 +02:00
parent e6e2781ee7
commit f216dc4ab8
1 changed files with 34 additions and 15 deletions

View File

@ -194,16 +194,35 @@ public class IndexStatsTests extends ElasticsearchIntegrationTest {
assertAcked(client().admin().indices().prepareCreate("idx").setSettings(IndicesQueryCache.INDEX_CACHE_QUERY_ENABLED, true).get());
ensureGreen();
int numDocs = randomIntBetween(2, 100);
IndexRequestBuilder[] builders = new IndexRequestBuilder[numDocs];
for (int i = 0; i < numDocs; ++i) {
builders[i] = client().prepareIndex("idx", "type", Integer.toString(i)).setSource(jsonBuilder()
// index docs until we have at least one doc on each shard, otherwise, our tests will not work
// since refresh will not refresh anything on a shard that has 0 docs and its search response get cached
int pageDocs = randomIntBetween(2, 100);
int numDocs = 0;
int counter = 0;
while (true) {
IndexRequestBuilder[] builders = new IndexRequestBuilder[pageDocs];
for (int i = 0; i < pageDocs; ++i) {
builders[i] = client().prepareIndex("idx", "type", Integer.toString(counter++)).setSource(jsonBuilder()
.startObject()
.field("common", "field")
.field("str_value", "s" + i)
.endObject());
}
indexRandom(true, builders);
numDocs += pageDocs;
boolean allHaveDocs = true;
for (ShardStats stats : client().admin().indices().prepareStats("idx").setDocs(true).get().getShards()) {
if (stats.getStats().getDocs().getCount() == 0) {
allHaveDocs = false;
break;
}
}
if (allHaveDocs) {
break;
}
}
assertThat(client().admin().indices().prepareStats("idx").setQueryCache(true).get().getTotal().getQueryCache().getMemorySizeInBytes(), equalTo(0l));
for (int i = 0; i < 10; i++) {
@ -212,7 +231,7 @@ public class IndexStatsTests extends ElasticsearchIntegrationTest {
}
// index the data again...
builders = new IndexRequestBuilder[numDocs];
IndexRequestBuilder[] builders = new IndexRequestBuilder[numDocs];
for (int i = 0; i < numDocs; ++i) {
builders[i] = client().prepareIndex("idx", "type", Integer.toString(i)).setSource(jsonBuilder()
.startObject()
@ -417,7 +436,7 @@ public class IndexStatsTests extends ElasticsearchIntegrationTest {
stats = client().admin().indices().prepareStats().setSegments(true).get();
assertThat(stats.getTotal().getSegments(), notNullValue());
assertThat(stats.getTotal().getSegments().getCount(), equalTo((long)test1.totalNumShards));
assertThat(stats.getTotal().getSegments().getCount(), equalTo((long) test1.totalNumShards));
assumeTrue(org.elasticsearch.Version.CURRENT.luceneVersion != Version.LUCENE_46);
assertThat(stats.getTotal().getSegments().getMemoryInBytes(), greaterThan(0l));
}
@ -681,7 +700,7 @@ public class IndexStatsTests extends ElasticsearchIntegrationTest {
ensureGreen();
client().prepareIndex("test1", "bar", Integer.toString(1)).setSource("foo","bar").execute().actionGet();
client().prepareIndex("test1", "bar", Integer.toString(1)).setSource("foo", "bar").execute().actionGet();
refresh();
client().prepareSearch("_all").setStats("bar", "baz").execute().actionGet();
@ -718,8 +737,8 @@ public class IndexStatsTests extends ElasticsearchIntegrationTest {
ensureGreen();
client().prepareIndex("test1", "bar", Integer.toString(1)).setSource("foo","bar").execute().actionGet();
client().prepareIndex("test2", "baz", Integer.toString(1)).setSource("foo","bar").execute().actionGet();
client().prepareIndex("test1", "bar", Integer.toString(1)).setSource("foo", "bar").execute().actionGet();
client().prepareIndex("test2", "baz", Integer.toString(1)).setSource("foo", "bar").execute().actionGet();
refresh();
IndicesStatsRequestBuilder builder = client().admin().indices().prepareStats();