Skip to content

Commit

Permalink
Avoid size=0 for terminate_after tests (opensearch-project#10436)
Browse files Browse the repository at this point in the history
Signed-off-by: Jay Deng <[email protected]>
  • Loading branch information
jed326 authored Oct 10, 2023
1 parent 8bb11a6 commit 74ffdb6
Showing 1 changed file with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,9 @@ public void testSimpleDateRange() throws Exception {
assertHitCount(searchResponse, 2L);
}

public void testSimpleTerminateAfterCount() throws Exception {
public void dotestSimpleTerminateAfterCountWithSize(int size, int max) throws Exception {
prepareCreate("test").setSettings(Settings.builder().put(SETTING_NUMBER_OF_SHARDS, 1).put(SETTING_NUMBER_OF_REPLICAS, 0)).get();
ensureGreen();
int max = randomIntBetween(3, 29);
List<IndexRequestBuilder> docbuilders = new ArrayList<>(max);

for (int i = 1; i <= max; i++) {
Expand All @@ -299,9 +298,7 @@ public void testSimpleTerminateAfterCount() throws Exception {
refresh();

SearchResponse searchResponse;
int size;
for (int i = 1; i < max; i++) {
size = randomIntBetween(0, max);
searchResponse = client().prepareSearch("test")
.setQuery(QueryBuilders.rangeQuery("field").gte(1).lte(max))
.setTerminateAfter(i)
Expand All @@ -322,7 +319,18 @@ public void testSimpleTerminateAfterCount() throws Exception {
assertFalse(searchResponse.isTerminatedEarly());
}

public void testSimpleTerminateAfterTrackTotalHitsUpTo() throws Exception {
@AwaitsFix(bugUrl = "https://github.com/opensearch-project/OpenSearch/issues/10435")
public void testSimpleTerminateAfterCountSize0() throws Exception {
int max = randomIntBetween(3, 29);
dotestSimpleTerminateAfterCountWithSize(0, max);
}

public void testSimpleTerminateAfterCountRandomSize() throws Exception {
int max = randomIntBetween(3, 29);
dotestSimpleTerminateAfterCountWithSize(randomIntBetween(1, max), max);
}

public void doTestSimpleTerminateAfterTrackTotalHitsUpTo(int size) throws Exception {
prepareCreate("test").setSettings(Settings.builder().put(SETTING_NUMBER_OF_SHARDS, 1).put(SETTING_NUMBER_OF_REPLICAS, 0)).get();
ensureGreen();
int numDocs = 29;
Expand All @@ -337,8 +345,6 @@ public void testSimpleTerminateAfterTrackTotalHitsUpTo() throws Exception {
ensureGreen();
refresh();

// size=0 is a special case where topDocsCollector is not added
int size = randomIntBetween(0, 1);
SearchResponse searchResponse;
searchResponse = client().prepareSearch("test")
.setQuery(QueryBuilders.rangeQuery("field").gte(1).lte(numDocs))
Expand Down Expand Up @@ -399,6 +405,15 @@ public void testSimpleTerminateAfterTrackTotalHitsUpTo() throws Exception {
assertEquals(GREATER_THAN_OR_EQUAL_TO, searchResponse.getHits().getTotalHits().relation);
}

@AwaitsFix(bugUrl = "https://github.com/opensearch-project/OpenSearch/issues/10435")
public void testSimpleTerminateAfterTrackTotalHitsUpToRandomSize() throws Exception {
doTestSimpleTerminateAfterTrackTotalHitsUpTo(0);
}

public void testSimpleTerminateAfterTrackTotalHitsUpToSize0() throws Exception {
doTestSimpleTerminateAfterTrackTotalHitsUpTo(randomIntBetween(1, 29));
}

public void testSimpleIndexSortEarlyTerminate() throws Exception {
prepareCreate("test").setSettings(
Settings.builder().put(SETTING_NUMBER_OF_SHARDS, 1).put(SETTING_NUMBER_OF_REPLICAS, 0).put("index.sort.field", "rank")
Expand Down

0 comments on commit 74ffdb6

Please sign in to comment.