Fix issues due to missing refresh after indexing test documents in SearchStatsTests.testOpenContexts
This commit is contained in:
parent
901421bc14
commit
0820cb66c3
core/src/test/java/org/elasticsearch/search/stats
|
@ -21,6 +21,8 @@ package org.elasticsearch.search.stats;
|
||||||
|
|
||||||
import org.elasticsearch.action.admin.cluster.node.stats.NodeStats;
|
import org.elasticsearch.action.admin.cluster.node.stats.NodeStats;
|
||||||
import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse;
|
import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse;
|
||||||
|
import org.elasticsearch.action.admin.cluster.stats.ClusterStatsRequest;
|
||||||
|
import org.elasticsearch.action.admin.cluster.stats.ClusterStatsRequestBuilder;
|
||||||
import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse;
|
import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse;
|
||||||
import org.elasticsearch.action.search.SearchResponse;
|
import org.elasticsearch.action.search.SearchResponse;
|
||||||
import org.elasticsearch.action.search.SearchType;
|
import org.elasticsearch.action.search.SearchType;
|
||||||
|
@ -38,6 +40,7 @@ import org.elasticsearch.test.ElasticsearchIntegrationTest;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
@ -162,33 +165,47 @@ public class SearchStatsTests extends ElasticsearchIntegrationTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOpenContexts() {
|
public void testOpenContexts() {
|
||||||
createIndex("test1");
|
String index = "test1";
|
||||||
ensureGreen("test1");
|
createIndex(index);
|
||||||
|
ensureGreen(index);
|
||||||
|
|
||||||
|
// create shards * docs number of docs and attempt to distribute them equally
|
||||||
|
// this distribution will not be perfect; each shard will have an integer multiple of docs (possibly zero)
|
||||||
|
// we do this so we have a lot of pages to scroll through
|
||||||
final int docs = scaledRandomIntBetween(20, 50);
|
final int docs = scaledRandomIntBetween(20, 50);
|
||||||
for (int i = 0; i < docs; i++) {
|
for (int s = 0; s < numAssignedShards(index); s++) {
|
||||||
client().prepareIndex("test1", "type", Integer.toString(i)).setSource("field", "value").execute().actionGet();
|
for (int i = 0; i < docs; i++) {
|
||||||
|
client()
|
||||||
|
.prepareIndex(index, "type", Integer.toString(s * docs + i))
|
||||||
|
.setSource("field", "value")
|
||||||
|
.setRouting(Integer.toString(s))
|
||||||
|
.execute()
|
||||||
|
.actionGet();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
IndicesStatsResponse indicesStats = client().admin().indices().prepareStats().execute().actionGet();
|
client().admin().indices().prepareRefresh(index).execute().actionGet();
|
||||||
|
|
||||||
|
IndicesStatsResponse indicesStats = client().admin().indices().prepareStats(index).execute().actionGet();
|
||||||
assertThat(indicesStats.getTotal().getSearch().getOpenContexts(), equalTo(0l));
|
assertThat(indicesStats.getTotal().getSearch().getOpenContexts(), equalTo(0l));
|
||||||
|
|
||||||
|
int size = scaledRandomIntBetween(1, docs);
|
||||||
SearchResponse searchResponse = client().prepareSearch()
|
SearchResponse searchResponse = client().prepareSearch()
|
||||||
.setSearchType(SearchType.SCAN)
|
.setSearchType(SearchType.SCAN)
|
||||||
.setQuery(matchAllQuery())
|
.setQuery(matchAllQuery())
|
||||||
.setSize(5)
|
.setSize(size)
|
||||||
.setScroll(TimeValue.timeValueMinutes(2))
|
.setScroll(TimeValue.timeValueMinutes(2))
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
assertSearchResponse(searchResponse);
|
assertSearchResponse(searchResponse);
|
||||||
|
|
||||||
indicesStats = client().admin().indices().prepareStats().execute().actionGet();
|
// refresh the stats now that scroll contexts are opened
|
||||||
assertThat(indicesStats.getTotal().getSearch().getOpenContexts(), equalTo((long) numAssignedShards("test1")));
|
indicesStats = client().admin().indices().prepareStats(index).execute().actionGet();
|
||||||
assertThat(indicesStats.getTotal().getSearch().getTotal().getScrollCurrent(), equalTo((long) numAssignedShards("test1")));
|
|
||||||
|
|
||||||
// force the scan to complete measuring the time taken
|
assertThat(indicesStats.getTotal().getSearch().getOpenContexts(), equalTo((long) numAssignedShards(index)));
|
||||||
// the total time the scroll is open should be greater than this
|
assertThat(indicesStats.getTotal().getSearch().getTotal().getScrollCurrent(), equalTo((long) numAssignedShards(index)));
|
||||||
// the number of queries should equal the number of pages in the scan times the number of shards
|
|
||||||
int count = 0;
|
int hits = 0;
|
||||||
while (true) {
|
while (true) {
|
||||||
count++;
|
hits += searchResponse.getHits().getHits().length;
|
||||||
searchResponse = client().prepareSearchScroll(searchResponse.getScrollId())
|
searchResponse = client().prepareSearchScroll(searchResponse.getScrollId())
|
||||||
.setScroll(TimeValue.timeValueMinutes(2))
|
.setScroll(TimeValue.timeValueMinutes(2))
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
|
@ -196,10 +213,18 @@ public class SearchStatsTests extends ElasticsearchIntegrationTest {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
long expected = 0;
|
||||||
|
|
||||||
|
// the number of queries executed is equal to the sum of 1 + number of pages in shard over all shards
|
||||||
|
IndicesStatsResponse r = client().admin().indices().prepareStats(index).execute().actionGet();
|
||||||
|
for (int s = 0; s < numAssignedShards(index); s++) {
|
||||||
|
expected += 1 + (long)Math.ceil(r.getShards()[s].getStats().getDocs().getCount() / size);
|
||||||
|
}
|
||||||
indicesStats = client().admin().indices().prepareStats().execute().actionGet();
|
indicesStats = client().admin().indices().prepareStats().execute().actionGet();
|
||||||
Stats stats = indicesStats.getTotal().getSearch().getTotal();
|
Stats stats = indicesStats.getTotal().getSearch().getTotal();
|
||||||
assertThat(stats.getQueryCount(), equalTo(count * (long)numAssignedShards("test1")));
|
assertEquals(hits, docs * numAssignedShards(index));
|
||||||
assertThat(stats.getScrollCount(), equalTo((long)numAssignedShards("test1")));
|
assertThat(stats.getQueryCount(), equalTo(expected));
|
||||||
|
assertThat(stats.getScrollCount(), equalTo((long)numAssignedShards(index)));
|
||||||
assertThat(stats.getScrollTimeInMillis(), greaterThan(0l));
|
assertThat(stats.getScrollTimeInMillis(), greaterThan(0l));
|
||||||
|
|
||||||
// scroll, but with no timeout (so no context)
|
// scroll, but with no timeout (so no context)
|
||||||
|
|
Loading…
Reference in New Issue