Skip to content

Commit

Permalink
[Backport 2.x] Add indexRandomForConcurrentSearch for tests (#11204)
Browse files Browse the repository at this point in the history
* Add indexRandomForConcurrentSearch method to tests: (#11118)

* IndexStatsIT.java
* SearchTimeoutIT.java
* NaNSortingIT.java
* NestedIT.java
* RangeIT.java

Signed-off-by: Jay Deng <[email protected]>

* Add indexRandomForConcurrentSearch for tests: (#11181)

* MultiSearchIT.java
* SimpleNestedIT.java
* SearchPreferenceIT.java
* SimpleQueryStringIT.java
* ScriptQuerySearchIT.java

Signed-off-by: Jay Deng <[email protected]>

* Fix tests for concurrent search with IndexRandomForConcurrentSearch follow-up [#11130] (#11212)

Signed-off-by: Ganesh Ramadurai <[email protected]>
Co-authored-by: Ganesh Ramadurai <[email protected]>

* Fix tests for concurrent search (#11130)

Signed-off-by: Ganesh Ramadurai <[email protected]>
Signed-off-by: Ganesh Ramadurai <[email protected]>
Co-authored-by: Ganesh Ramadurai <[email protected]>

* Fixing the tests for concurrent search (#11076)

* Fixing the tests for concurrent search

Signed-off-by: Bansi Kasundra <[email protected]>

* Remove changes for non-flaky tests

Signed-off-by: Bansi Kasundra <[email protected]>

---------

Signed-off-by: Bansi Kasundra <[email protected]>

* Fixed test cases for concurrent search (#11184)

Updated flaky and failing test cases after changes to indexRandomForConcurrentSearch
	    Remove unnecessary call to indexRandomForConcurrentSearch in testSearchAndRelocateConcurrently

Signed-off-by: Ethan Emoto <[email protected]>

---------

Signed-off-by: Jay Deng <[email protected]>
Signed-off-by: Ganesh Ramadurai <[email protected]>
Signed-off-by: Ganesh Ramadurai <[email protected]>
Signed-off-by: Bansi Kasundra <[email protected]>
Signed-off-by: Ethan Emoto <[email protected]>
Co-authored-by: Ganesh Krishna Ramadurai <[email protected]>
Co-authored-by: Ganesh Ramadurai <[email protected]>
Co-authored-by: Bansi Kasundra <[email protected]>
Co-authored-by: Ethan Emoto <[email protected]>
  • Loading branch information
5 people authored Nov 17, 2023
1 parent 78cfce4 commit b33981e
Show file tree
Hide file tree
Showing 22 changed files with 196 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ private Settings.Builder settingsBuilder() {
return Settings.builder().put(indexSettings());
}

public void testFieldDataStats() {
public void testFieldDataStats() throws InterruptedException {
assertAcked(
client().admin()
.indices()
Expand All @@ -182,6 +182,7 @@ public void testFieldDataStats() {
client().prepareIndex("test").setId("1").setSource("field", "value1", "field2", "value1").execute().actionGet();
client().prepareIndex("test").setId("2").setSource("field", "value2", "field2", "value2").execute().actionGet();
client().admin().indices().prepareRefresh().execute().actionGet();
indexRandomForConcurrentSearch("test");

NodesStatsResponse nodesStats = client().admin().cluster().prepareNodesStats("data:true").setIndices(true).execute().actionGet();
assertThat(
Expand Down Expand Up @@ -305,6 +306,7 @@ public void testClearAllCaches() throws Exception {
client().prepareIndex("test").setId("1").setSource("field", "value1").execute().actionGet();
client().prepareIndex("test").setId("2").setSource("field", "value2").execute().actionGet();
client().admin().indices().prepareRefresh().execute().actionGet();
indexRandomForConcurrentSearch("test");

NodesStatsResponse nodesStats = client().admin().cluster().prepareNodesStats("data:true").setIndices(true).execute().actionGet();
assertThat(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public void testSimpleTimeout() throws Exception {
client().prepareIndex("test").setId(Integer.toString(i)).setSource("field", "value").get();
}
refresh("test");
indexRandomForConcurrentSearch("test");

SearchResponse searchResponse = client().prepareSearch("test")
.setTimeout(new TimeValue(5, TimeUnit.MILLISECONDS))
Expand All @@ -104,12 +105,11 @@ public void testSimpleTimeout() throws Exception {
}

public void testSimpleDoesNotTimeout() throws Exception {
final int numDocs = 10;
final int numDocs = 9;
for (int i = 0; i < numDocs; i++) {
client().prepareIndex("test").setId(Integer.toString(i)).setSource("field", "value").get();
client().prepareIndex("test").setId(Integer.toString(i)).setSource("field", "value").setRefreshPolicy(IMMEDIATE).get();
}
refresh("test");

indexRandomForConcurrentSearch("test");
SearchResponse searchResponse = client().prepareSearch("test")
.setTimeout(new TimeValue(10000, TimeUnit.SECONDS))
.setQuery(scriptQuery(new Script(ScriptType.INLINE, "mockscript", SCRIPT_NAME, Collections.emptyMap())))
Expand All @@ -122,7 +122,7 @@ public void testSimpleDoesNotTimeout() throws Exception {

public void testPartialResultsIntolerantTimeout() throws Exception {
client().prepareIndex("test").setId("1").setSource("field", "value").setRefreshPolicy(IMMEDIATE).get();

indexRandomForConcurrentSearch("test");
OpenSearchException ex = expectThrows(
OpenSearchException.class,
() -> client().prepareSearch("test")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ public void setupSuiteScopeCluster() throws Exception {
client().prepareIndex("idx").setSource(source.endObject()).get();
}
refresh();
indexRandomForMultipleSlices("idx");
ensureSearchable();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ public void setupSuiteScopeCluster() throws Exception {
)
);
indexRandom(true, builders);
indexRandomForMultipleSlices("idx");
ensureSearchable();
}

Expand Down Expand Up @@ -354,6 +355,7 @@ public void testNestedAsSubAggregation() throws Exception {
}

public void testNestNestedAggs() throws Exception {
indexRandomForConcurrentSearch("idx_nested_nested_aggs");
SearchResponse response = client().prepareSearch("idx_nested_nested_aggs")
.addAggregation(
nested("level1", "nested1").subAggregation(
Expand Down Expand Up @@ -607,6 +609,7 @@ public void testNestedSameDocIdProcessedMultipleTime() throws Exception {
)
.get();
refresh();
indexRandomForConcurrentSearch("idx4");

SearchResponse response = client().prepareSearch("idx4")
.addAggregation(
Expand Down Expand Up @@ -782,6 +785,7 @@ public void testFilterAggInsideNestedAgg() throws Exception {
)
.get();
refresh();
indexRandomForConcurrentSearch("classes");

SearchResponse response = client().prepareSearch("classes")
.addAggregation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ public void setupSuiteScopeCluster() throws Exception {
builders.add(client().prepareIndex("new_index").setSource(Collections.emptyMap()));

indexRandom(true, builders);
indexRandomForMultipleSlices("idx", "old_index", "new_index");
ensureSearchable();
}

Expand Down Expand Up @@ -917,6 +918,7 @@ public void testOverlappingRanges() throws Exception {
}

public void testEmptyAggregation() throws Exception {
indexRandomForConcurrentSearch("empty_bucket_idx");
SearchResponse searchResponse = client().prepareSearch("empty_bucket_idx")
.setQuery(matchAllQuery())
.addAggregation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,6 @@ protected Collection<Class<? extends Plugin>> nodePlugins() {

@SuppressWarnings("unchecked")
public void testPlugin() throws Exception {
assumeFalse(
"Concurrent search case muted pending fix: https://github.com/opensearch-project/OpenSearch/issues/11112",
internalCluster().clusterService().getClusterSettings().get(CLUSTER_CONCURRENT_SEGMENT_SEARCH_SETTING)
);
client().admin()
.indices()
.prepareCreate("test")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,7 @@ public void testNestedSource() throws Exception {
)
.get();
refresh();
indexRandomForConcurrentSearch("index1");

// the field name (comments.message) used for source filtering should be the same as when using that field for
// other features (like in the query dsl or aggs) in order for consistency:
Expand Down Expand Up @@ -973,6 +974,7 @@ public void testInnerHitsWithIgnoreUnmapped() throws Exception {
client().prepareIndex("index1").setId("1").setSource("nested_type", Collections.singletonMap("key", "value")).get();
client().prepareIndex("index2").setId("3").setSource("key", "value").get();
refresh();
indexRandomForConcurrentSearch("index1", "index2");

SearchResponse response = client().prepareSearch("index1", "index2")
.setQuery(
Expand Down Expand Up @@ -1002,6 +1004,7 @@ public void testUseMaxDocInsteadOfSize() throws Exception {
.setRefreshPolicy(IMMEDIATE)
.get();

indexRandomForConcurrentSearch("index2");
QueryBuilder query = nestedQuery("nested", matchQuery("nested.field", "value1"), ScoreMode.Avg).innerHit(
new InnerHitBuilder().setSize(ArrayUtil.MAX_ARRAY_LENGTH - 1)
);
Expand All @@ -1019,6 +1022,7 @@ public void testTooHighResultWindow() throws Exception {
)
.setRefreshPolicy(IMMEDIATE)
.get();
indexRandomForConcurrentSearch("index2");
SearchResponse response = client().prepareSearch("index2")
.setQuery(
nestedQuery("nested", matchQuery("nested.field", "value1"), ScoreMode.Avg).innerHit(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public void testSimpleMatchedQueryFromFilteredQuery() throws Exception {
client().prepareIndex("test").setId("2").setSource("name", "test2", "number", 2).get();
client().prepareIndex("test").setId("3").setSource("name", "test3", "number", 3).get();
refresh();
indexRandomForConcurrentSearch("test");

SearchResponse searchResponse = client().prepareSearch()
.setQuery(
Expand Down Expand Up @@ -141,6 +142,7 @@ public void testSimpleMatchedQueryFromTopLevelFilter() throws Exception {
client().prepareIndex("test").setId("2").setSource("name", "test").get();
client().prepareIndex("test").setId("3").setSource("name", "test").get();
refresh();
indexRandomForConcurrentSearch("test");

SearchResponse searchResponse = client().prepareSearch()
.setQuery(matchAllQuery())
Expand Down Expand Up @@ -192,6 +194,7 @@ public void testSimpleMatchedQueryFromTopLevelFilterAndFilteredQuery() throws Ex
client().prepareIndex("test").setId("2").setSource("name", "test", "title", "title2").get();
client().prepareIndex("test").setId("3").setSource("name", "test", "title", "title3").get();
refresh();
indexRandomForConcurrentSearch("test");

SearchResponse searchResponse = client().prepareSearch()
.setQuery(boolQuery().must(matchAllQuery()).filter(termsQuery("title", "title1", "title2", "title3").queryName("title")))
Expand Down Expand Up @@ -224,12 +227,13 @@ public void testSimpleMatchedQueryFromTopLevelFilterAndFilteredQuery() throws Ex
}
}

public void testRegExpQuerySupportsName() {
public void testRegExpQuerySupportsName() throws InterruptedException {
createIndex("test1");
ensureGreen();

client().prepareIndex("test1").setId("1").setSource("title", "title1").get();
refresh();
indexRandomForConcurrentSearch("test1");

SearchResponse searchResponse = client().prepareSearch()
.setQuery(QueryBuilders.regexpQuery("title", "title1").queryName("regex"))
Expand All @@ -246,12 +250,13 @@ public void testRegExpQuerySupportsName() {
}
}

public void testPrefixQuerySupportsName() {
public void testPrefixQuerySupportsName() throws InterruptedException {
createIndex("test1");
ensureGreen();

client().prepareIndex("test1").setId("1").setSource("title", "title1").get();
refresh();
indexRandomForConcurrentSearch("test1");

SearchResponse searchResponse = client().prepareSearch()
.setQuery(QueryBuilders.prefixQuery("title", "title").queryName("prefix"))
Expand All @@ -268,12 +273,13 @@ public void testPrefixQuerySupportsName() {
}
}

public void testFuzzyQuerySupportsName() {
public void testFuzzyQuerySupportsName() throws InterruptedException {
createIndex("test1");
ensureGreen();

client().prepareIndex("test1").setId("1").setSource("title", "title1").get();
refresh();
indexRandomForConcurrentSearch("test1");

SearchResponse searchResponse = client().prepareSearch()
.setQuery(QueryBuilders.fuzzyQuery("title", "titel1").queryName("fuzzy"))
Expand All @@ -290,12 +296,13 @@ public void testFuzzyQuerySupportsName() {
}
}

public void testWildcardQuerySupportsName() {
public void testWildcardQuerySupportsName() throws InterruptedException {
createIndex("test1");
ensureGreen();

client().prepareIndex("test1").setId("1").setSource("title", "title1").get();
refresh();
indexRandomForConcurrentSearch("test1");

SearchResponse searchResponse = client().prepareSearch()
.setQuery(QueryBuilders.wildcardQuery("title", "titl*").queryName("wildcard"))
Expand All @@ -312,12 +319,13 @@ public void testWildcardQuerySupportsName() {
}
}

public void testSpanFirstQuerySupportsName() {
public void testSpanFirstQuerySupportsName() throws InterruptedException {
createIndex("test1");
ensureGreen();

client().prepareIndex("test1").setId("1").setSource("title", "title1 title2").get();
refresh();
indexRandomForConcurrentSearch("test1");

SearchResponse searchResponse = client().prepareSearch()
.setQuery(QueryBuilders.spanFirstQuery(QueryBuilders.spanTermQuery("title", "title1"), 10).queryName("span"))
Expand All @@ -344,6 +352,7 @@ public void testMatchedWithShould() throws Exception {
client().prepareIndex("test").setId("1").setSource("content", "Lorem ipsum dolor sit amet").get();
client().prepareIndex("test").setId("2").setSource("content", "consectetur adipisicing elit").get();
refresh();
indexRandomForConcurrentSearch("test");

// Execute search at least two times to load it in cache
int iter = scaledRandomIntBetween(2, 10);
Expand Down Expand Up @@ -378,6 +387,7 @@ public void testMatchedWithWrapperQuery() throws Exception {

client().prepareIndex("test").setId("1").setSource("content", "Lorem ipsum dolor sit amet").get();
refresh();
indexRandomForConcurrentSearch("test");

MatchQueryBuilder matchQueryBuilder = matchQuery("content", "amet").queryName("abc");
BytesReference matchBytes = XContentHelper.toXContent(matchQueryBuilder, MediaTypeRegistry.JSON, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ public void testConsistentHitsWithSameSeed() throws Exception {
}
flush();
refresh();
indexRandomForConcurrentSearch("test");
int outerIters = scaledRandomIntBetween(10, 20);
for (int o = 0; o < outerIters; o++) {
final int seed = randomInt();
Expand Down Expand Up @@ -299,6 +300,7 @@ public void testSeedReportedInExplain() throws Exception {
index("test", "type", "1", jsonBuilder().startObject().endObject());
flush();
refresh();
indexRandomForConcurrentSearch("test");

int seed = 12345678;

Expand All @@ -318,6 +320,7 @@ public void testSeedAndNameReportedInExplain() throws Exception {
index("test", "type", "1", jsonBuilder().startObject().endObject());
flush();
refresh();
indexRandomForConcurrentSearch("test");

int seed = 12345678;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,13 @@ protected Settings featureFlagSettings() {
return Settings.builder().put(super.featureFlagSettings()).put(FeatureFlags.CONCURRENT_SEGMENT_SEARCH, "true").build();
}

public void testSimpleMultiSearch() {
public void testSimpleMultiSearch() throws InterruptedException {
createIndex("test");
ensureGreen();
client().prepareIndex("test").setId("1").setSource("field", "xxx").get();
client().prepareIndex("test").setId("2").setSource("field", "yyy").get();
refresh();
indexRandomForConcurrentSearch("test");
MultiSearchResponse response = client().prepareMultiSearch()
.add(client().prepareSearch("test").setQuery(QueryBuilders.termQuery("field", "xxx")))
.add(client().prepareSearch("test").setQuery(QueryBuilders.termQuery("field", "yyy")))
Expand All @@ -94,13 +95,14 @@ public void testSimpleMultiSearch() {
assertFirstHit(response.getResponses()[1].getResponse(), hasId("2"));
}

public void testSimpleMultiSearchMoreRequests() {
public void testSimpleMultiSearchMoreRequests() throws InterruptedException {
createIndex("test");
int numDocs = randomIntBetween(0, 16);
for (int i = 0; i < numDocs; i++) {
client().prepareIndex("test").setId(Integer.toString(i)).setSource("{}", MediaTypeRegistry.JSON).get();
}
refresh();
indexRandomForConcurrentSearch("test");

int numSearchRequests = randomIntBetween(1, 64);
MultiSearchRequest request = new MultiSearchRequest();
Expand Down
Loading

0 comments on commit b33981e

Please sign in to comment.