Skip to content

Commit

Permalink
Fixing the tests for concurrent search (opensearch-project#11076)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
kasundra07 authored and Jay Deng committed Nov 16, 2023
1 parent 1a2a9eb commit bee638c
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 23 deletions.
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
Loading

0 comments on commit bee638c

Please sign in to comment.