Skip to content

Commit

Permalink
Fix failing test suites (#113)
Browse files Browse the repository at this point in the history
* test fix for failing test suites

Signed-off-by: Poojita Raj <poojiraj@amazon.com>

* addressed review comments

Signed-off-by: Poojita Raj <poojiraj@amazon.com>

---------

Signed-off-by: Poojita Raj <poojiraj@amazon.com>
  • Loading branch information
Poojita-Raj committed Apr 13, 2023
1 parent cb56798 commit ac2a74c
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,13 @@ public void testAddBlockWhileIndexingDocuments() throws Exception {
disableIndexBlock(indexName, block);
}
refresh(indexName);
assertHitCount(client().prepareSearch(indexName).setSize(0).setTrackTotalHitsUpTo(TRACK_TOTAL_HITS_ACCURATE).get(), nbDocs);
int finalNbDocs = nbDocs;
assertBusy(
() -> assertHitCount(
client().prepareSearch(indexName).setSize(0).setTrackTotalHitsUpTo(TRACK_TOTAL_HITS_ACCURATE).get(),
finalNbDocs
)
);
}

public void testAddBlockWhileDeletingIndices() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ public void testTwoNodesSingleDoc() throws Exception {

logger.info("--> verify 1 doc in the index");
for (int i = 0; i < 10; i++) {
assertHitCount(client().prepareSearch().setQuery(matchAllQuery()).get(), 1L);
assertBusy(() -> assertHitCount(client().prepareSearch().setQuery(matchAllQuery()).get(), 1L));
}

logger.info("--> closing test index...");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ public void testCustomDummyQuery() {
assertHitCount(client().prepareSearch("index").setQuery(new DummyQueryBuilder()).get(), 1L);
}

public void testCustomDummyQueryWithinBooleanQuery() {
assertHitCount(client().prepareSearch("index").setQuery(new BoolQueryBuilder().must(new DummyQueryBuilder())).get(), 1L);
public void testCustomDummyQueryWithinBooleanQuery() throws Exception {
assertBusy(
() -> assertHitCount(client().prepareSearch("index").setQuery(new BoolQueryBuilder().must(new DummyQueryBuilder())).get(), 1L)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@

public class DateMathIndexExpressionsIntegrationIT extends OpenSearchIntegTestCase {

public void testIndexNameDateMathExpressions() {
public void testIndexNameDateMathExpressions() throws Exception {
DateTime now = new DateTime(DateTimeZone.UTC);
String index1 = ".marvel-" + DateTimeFormat.forPattern("YYYY.MM.dd").print(now);
String index2 = ".marvel-" + DateTimeFormat.forPattern("YYYY.MM.dd").print(now.minusDays(1));
Expand All @@ -76,9 +76,11 @@ public void testIndexNameDateMathExpressions() {
client().prepareIndex(dateMathExp3).setId("3").setSource("{}", XContentType.JSON).get();
refresh();

SearchResponse searchResponse = client().prepareSearch(dateMathExp1, dateMathExp2, dateMathExp3).get();
assertHitCount(searchResponse, 3);
assertSearchHits(searchResponse, "1", "2", "3");
assertBusy(() -> {
SearchResponse searchResponse = client().prepareSearch(dateMathExp1, dateMathExp2, dateMathExp3).get();
assertHitCount(searchResponse, 3);
assertSearchHits(searchResponse, "1", "2", "3");
});

GetResponse getResponse = client().prepareGet(dateMathExp1, "1").get();
assertThat(getResponse.isExists(), is(true));
Expand Down Expand Up @@ -136,9 +138,11 @@ public void testAutoCreateIndexWithDateMathExpression() throws Exception {
client().prepareIndex(dateMathExp3).setId("3").setSource("{}", XContentType.JSON).get();
refresh();

SearchResponse searchResponse = client().prepareSearch(dateMathExp1, dateMathExp2, dateMathExp3).get();
assertHitCount(searchResponse, 3);
assertSearchHits(searchResponse, "1", "2", "3");
assertBusy(() -> {
SearchResponse searchResponse = client().prepareSearch(dateMathExp1, dateMathExp2, dateMathExp3).get();
assertHitCount(searchResponse, 3);
assertSearchHits(searchResponse, "1", "2", "3");
});

IndicesStatsResponse indicesStatsResponse = client().admin().indices().prepareStats(dateMathExp1, dateMathExp2, dateMathExp3).get();
assertThat(indicesStatsResponse.getIndex(index1), notNullValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertHitCount;
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertSearchResponse;

@OpenSearchIntegTestCase.ClusterScope(scope = OpenSearchIntegTestCase.Scope.TEST, minNumDataNodes = 2)
public class ExistsIT extends OpenSearchIntegTestCase {

// TODO: move this to a unit test somewhere...
Expand Down Expand Up @@ -243,8 +244,10 @@ public void testFieldAliasWithNoDocValues() throws Exception {
indexRequests.add(client().prepareIndex("idx").setSource("foo", 43));
indexRandom(true, false, indexRequests);

SearchResponse response = client().prepareSearch("idx").setQuery(QueryBuilders.existsQuery("foo-alias")).get();
assertSearchResponse(response);
assertHitCount(response, 2);
assertBusy(() -> {
SearchResponse response = client().prepareSearch("idx").setQuery(QueryBuilders.existsQuery("foo-alias")).get();
assertSearchResponse(response);
assertHitCount(response, 2);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -194,23 +194,29 @@ public void testCustomScriptBoost() throws Exception {
refresh();

logger.info("running doc['num1'].value > 1");
SearchResponse response = client().prepareSearch()
.setQuery(scriptQuery(new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "doc['num1'].value > 1", Collections.emptyMap())))
.addSort("num1", SortOrder.ASC)
.addScriptField("sNum1", new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "doc['num1'].value", Collections.emptyMap()))
.get();

assertThat(response.getHits().getTotalHits().value, equalTo(2L));
assertThat(response.getHits().getAt(0).getId(), equalTo("2"));
assertThat(response.getHits().getAt(0).getFields().get("sNum1").getValues().get(0), equalTo(2.0));
assertThat(response.getHits().getAt(1).getId(), equalTo("3"));
assertThat(response.getHits().getAt(1).getFields().get("sNum1").getValues().get(0), equalTo(3.0));

assertBusy(() -> {
SearchResponse response = client().prepareSearch()
.setQuery(
scriptQuery(new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "doc['num1'].value > 1", Collections.emptyMap()))
)
.addSort("num1", SortOrder.ASC)
.addScriptField(
"sNum1",
new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "doc['num1'].value", Collections.emptyMap())
)
.get();

assertThat(response.getHits().getTotalHits().value, equalTo(2L));
assertThat(response.getHits().getAt(0).getId(), equalTo("2"));
assertThat(response.getHits().getAt(0).getFields().get("sNum1").getValues().get(0), equalTo(2.0));
assertThat(response.getHits().getAt(1).getId(), equalTo("3"));
assertThat(response.getHits().getAt(1).getFields().get("sNum1").getValues().get(0), equalTo(3.0));
});
Map<String, Object> params = new HashMap<>();
params.put("param1", 2);

logger.info("running doc['num1'].value > param1");
response = client().prepareSearch()
SearchResponse response = client().prepareSearch()
.setQuery(scriptQuery(new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "doc['num1'].value > param1", params)))
.addSort("num1", SortOrder.ASC)
.addScriptField("sNum1", new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "doc['num1'].value", Collections.emptyMap()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
/**
* Tests for scrolling.
*/
@OpenSearchIntegTestCase.ClusterScope(scope = OpenSearchIntegTestCase.Scope.TEST, minNumDataNodes = 2)
public class SearchScrollIT extends OpenSearchIntegTestCase {
@After
public void cleanup() throws Exception {
Expand Down Expand Up @@ -235,23 +236,25 @@ public void testScrollAndUpdateIndex() throws Exception {

client().admin().indices().prepareRefresh().get();

assertThat(client().prepareSearch().setSize(0).setQuery(matchAllQuery()).get().getHits().getTotalHits().value, equalTo(500L));
assertThat(
client().prepareSearch().setSize(0).setQuery(termQuery("message", "test")).get().getHits().getTotalHits().value,
equalTo(500L)
);
assertThat(
client().prepareSearch().setSize(0).setQuery(termQuery("message", "test")).get().getHits().getTotalHits().value,
equalTo(500L)
);
assertThat(
client().prepareSearch().setSize(0).setQuery(termQuery("message", "update")).get().getHits().getTotalHits().value,
equalTo(0L)
);
assertThat(
client().prepareSearch().setSize(0).setQuery(termQuery("message", "update")).get().getHits().getTotalHits().value,
equalTo(0L)
);
assertBusy(() -> {
assertThat(client().prepareSearch().setSize(0).setQuery(matchAllQuery()).get().getHits().getTotalHits().value, equalTo(500L));
assertThat(
client().prepareSearch().setSize(0).setQuery(termQuery("message", "test")).get().getHits().getTotalHits().value,
equalTo(500L)
);
assertThat(
client().prepareSearch().setSize(0).setQuery(termQuery("message", "test")).get().getHits().getTotalHits().value,
equalTo(500L)
);
assertThat(
client().prepareSearch().setSize(0).setQuery(termQuery("message", "update")).get().getHits().getTotalHits().value,
equalTo(0L)
);
assertThat(
client().prepareSearch().setSize(0).setQuery(termQuery("message", "update")).get().getHits().getTotalHits().value,
equalTo(0L)
);
});

SearchResponse searchResponse = client().prepareSearch()
.setQuery(queryStringQuery("user:foobar"))
Expand Down Expand Up @@ -570,24 +573,26 @@ public void testStringSortMissingAscTerminates() throws Exception {
assertThat(response.getHits().getHits().length, equalTo(0));
}

public void testCloseAndReopenOrDeleteWithActiveScroll() {
public void testCloseAndReopenOrDeleteWithActiveScroll() throws Exception {
createIndex("test");
for (int i = 0; i < 100; i++) {
client().prepareIndex("test").setId(Integer.toString(i)).setSource("field", i).get();
}
refresh();
SearchResponse searchResponse = client().prepareSearch()
.setQuery(matchAllQuery())
.setSize(35)
.setScroll(TimeValue.timeValueMinutes(2))
.addSort("field", SortOrder.ASC)
.get();
long counter = 0;
assertThat(searchResponse.getHits().getTotalHits().value, equalTo(100L));
assertThat(searchResponse.getHits().getHits().length, equalTo(35));
for (SearchHit hit : searchResponse.getHits()) {
assertThat(((Number) hit.getSortValues()[0]).longValue(), equalTo(counter++));
}
assertBusy(() -> {
SearchResponse searchResponse = client().prepareSearch()
.setQuery(matchAllQuery())
.setSize(35)
.setScroll(TimeValue.timeValueMinutes(2))
.addSort("field", SortOrder.ASC)
.get();
long counter = 0;
assertThat(searchResponse.getHits().getTotalHits().value, equalTo(100L));
assertThat(searchResponse.getHits().getHits().length, equalTo(35));
for (SearchHit hit : searchResponse.getHits()) {
assertThat(((Number) hit.getSortValues()[0]).longValue(), equalTo(counter++));
}
});
if (randomBoolean()) {
assertAcked(client().admin().indices().prepareClose("test"));
assertAcked(client().admin().indices().prepareOpen("test"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,11 @@ public void testSimpleSorts() throws Exception {
});

size = 1 + random.nextInt(10);
SearchResponse searchResponse = client().prepareSearch().setQuery(matchAllQuery()).setSize(size).addSort("str_value", SortOrder.DESC).get();
SearchResponse searchResponse = client().prepareSearch()
.setQuery(matchAllQuery())
.setSize(size)
.addSort("str_value", SortOrder.DESC)
.get();

assertHitCount(searchResponse, 10);
assertThat(searchResponse.getHits().getHits().length, equalTo(size));
Expand Down

0 comments on commit ac2a74c

Please sign in to comment.