[Test] Let SuggestStatsTests.testSimpleStats do more work
The test verifies that stats are measure by checking timeInMillis>0. On fast machines the suggestions are done in < 1 millis time. The tests now index documents (to power suggestions) and does multiple suggestions per iterations to slow things down.
This commit is contained in:
parent
a6764e24a4
commit
2580099cf2
|
@ -22,12 +22,15 @@ package org.elasticsearch.index.suggest.stats;
|
|||
import org.elasticsearch.action.admin.cluster.node.stats.NodeStats;
|
||||
import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse;
|
||||
import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse;
|
||||
import org.elasticsearch.action.suggest.SuggestRequestBuilder;
|
||||
import org.elasticsearch.action.suggest.SuggestResponse;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.cluster.routing.GroupShardsIterator;
|
||||
import org.elasticsearch.cluster.routing.ShardIterator;
|
||||
import org.elasticsearch.cluster.routing.ShardRouting;
|
||||
import org.elasticsearch.common.settings.ImmutableSettings;
|
||||
import org.elasticsearch.search.suggest.phrase.PhraseSuggestionBuilder;
|
||||
import org.elasticsearch.search.suggest.term.TermSuggestionBuilder;
|
||||
import org.elasticsearch.test.ElasticsearchIntegrationTest;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -61,28 +64,36 @@ public class SuggestStatsTests extends ElasticsearchIntegrationTest {
|
|||
assertThat(numNodes, lessThanOrEqualTo(totalShards));
|
||||
assertAcked(prepareCreate("test1").setSettings(ImmutableSettings.builder()
|
||||
.put(SETTING_NUMBER_OF_SHARDS, shardsIdx1)
|
||||
.put(SETTING_NUMBER_OF_REPLICAS, 0)));
|
||||
.put(SETTING_NUMBER_OF_REPLICAS, 0))
|
||||
.addMapping("type", "f", "type=string"));
|
||||
assertAcked(prepareCreate("test2").setSettings(ImmutableSettings.builder()
|
||||
.put(SETTING_NUMBER_OF_SHARDS, shardsIdx2)
|
||||
.put(SETTING_NUMBER_OF_REPLICAS, 0)));
|
||||
assertThat(shardsIdx1+shardsIdx2, equalTo(numAssignedShards("test1", "test2")));
|
||||
.put(SETTING_NUMBER_OF_REPLICAS, 0))
|
||||
.addMapping("type", "f", "type=string"));
|
||||
assertThat(shardsIdx1 + shardsIdx2, equalTo(numAssignedShards("test1", "test2")));
|
||||
assertThat(numAssignedShards("test1", "test2"), greaterThanOrEqualTo(2));
|
||||
ensureGreen();
|
||||
|
||||
for (int i = 0; i < randomIntBetween(20, 100); i++) {
|
||||
index("test" + ((i % 2) + 1), "type", "" + i, "f", "test" + i);
|
||||
}
|
||||
refresh();
|
||||
|
||||
int suggestAllIdx = scaledRandomIntBetween(20, 50);
|
||||
int suggestIdx1 = scaledRandomIntBetween(20, 50);
|
||||
int suggestIdx2 = scaledRandomIntBetween(20, 50);
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
for (int i = 0; i < suggestAllIdx; i++) {
|
||||
SuggestResponse suggestResponse = cluster().clientNodeClient().prepareSuggest().setSuggestText("test").get();
|
||||
SuggestResponse suggestResponse = addSuggestions(cluster().clientNodeClient().prepareSuggest(), i).get();
|
||||
assertAllSuccessful(suggestResponse);
|
||||
}
|
||||
for (int i = 0; i < suggestIdx1; i++) {
|
||||
SuggestResponse suggestResponse = cluster().clientNodeClient().prepareSuggest("test1").setSuggestText("test").get();
|
||||
SuggestResponse suggestResponse = addSuggestions(cluster().clientNodeClient().prepareSuggest("test1"), i).get();
|
||||
assertAllSuccessful(suggestResponse);
|
||||
}
|
||||
for (int i = 0; i < suggestIdx2; i++) {
|
||||
SuggestResponse suggestResponse = cluster().clientNodeClient().prepareSuggest("test2").setSuggestText("test").get();
|
||||
SuggestResponse suggestResponse = addSuggestions(cluster().clientNodeClient().prepareSuggest("test2"), i).get();
|
||||
assertAllSuccessful(suggestResponse);
|
||||
}
|
||||
long endTime = System.currentTimeMillis();
|
||||
|
@ -93,10 +104,11 @@ public class SuggestStatsTests extends ElasticsearchIntegrationTest {
|
|||
assertThat(indicesStats.getTotal().getSuggest().getCurrent(), equalTo(0l));
|
||||
|
||||
// check suggest count
|
||||
assertThat(indicesStats.getTotal().getSuggest().getCount(), equalTo((long)(suggestAllIdx * totalShards + suggestIdx1 * shardsIdx1 + suggestIdx2 * shardsIdx2)));
|
||||
assertThat(indicesStats.getIndices().get("test1").getTotal().getSuggest().getCount(), equalTo((long)((suggestAllIdx + suggestIdx1) * shardsIdx1)));
|
||||
assertThat(indicesStats.getIndices().get("test2").getTotal().getSuggest().getCount(), equalTo((long)((suggestAllIdx + suggestIdx2) * shardsIdx2)));
|
||||
assertThat(indicesStats.getTotal().getSuggest().getCount(), equalTo((long) (suggestAllIdx * totalShards + suggestIdx1 * shardsIdx1 + suggestIdx2 * shardsIdx2)));
|
||||
assertThat(indicesStats.getIndices().get("test1").getTotal().getSuggest().getCount(), equalTo((long) ((suggestAllIdx + suggestIdx1) * shardsIdx1)));
|
||||
assertThat(indicesStats.getIndices().get("test2").getTotal().getSuggest().getCount(), equalTo((long) ((suggestAllIdx + suggestIdx2) * shardsIdx2)));
|
||||
|
||||
logger.info("iter {}, iter1 {}, iter2 {}, {}", suggestAllIdx, suggestIdx1, suggestIdx2, endTime - startTime);
|
||||
// check suggest time
|
||||
assertThat(indicesStats.getTotal().getSuggest().getTimeInMillis(), greaterThan(0l));
|
||||
// the upperbound is num shards * total time since we do searches in parallel
|
||||
|
@ -108,6 +120,7 @@ public class SuggestStatsTests extends ElasticsearchIntegrationTest {
|
|||
int num = 0;
|
||||
for (NodeStats stat : nodes) {
|
||||
SuggestStats suggestStats = stat.getIndices().getSuggest();
|
||||
logger.info("evaluating {}", stat.getNode());
|
||||
if (nodeIdsWithIndex.contains(stat.getNode().getId())) {
|
||||
assertThat(suggestStats.getCount(), greaterThan(0l));
|
||||
assertThat(suggestStats.getTimeInMillis(), greaterThan(0l));
|
||||
|
@ -119,7 +132,18 @@ public class SuggestStatsTests extends ElasticsearchIntegrationTest {
|
|||
}
|
||||
|
||||
assertThat(num, greaterThan(0));
|
||||
|
||||
|
||||
}
|
||||
|
||||
private SuggestRequestBuilder addSuggestions(SuggestRequestBuilder request, int i) {
|
||||
for (int s = 0; s < randomIntBetween(2, 10); s++) {
|
||||
if (randomBoolean()) {
|
||||
request.addSuggestion(new PhraseSuggestionBuilder("s" + s).field("f").text("test" + i + " test" + (i - 1)));
|
||||
} else {
|
||||
request.addSuggestion(new TermSuggestionBuilder("s" + s).field("f").text("test" + i));
|
||||
}
|
||||
}
|
||||
return request;
|
||||
}
|
||||
|
||||
private Set<String> nodeIdsWithIndex(String... indices) {
|
||||
|
|
Loading…
Reference in New Issue