Fix off-by one error in TransportSearchActionTests

Closes #54156
This commit is contained in:
jimczi 2020-03-25 11:40:11 +01:00
parent b6e482295b
commit e380a5a8c3
1 changed files with 10 additions and 12 deletions

View File

@ -844,9 +844,8 @@ public class TransportSearchActionTests extends ESTestCase {
}
}
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/54156")
public void testShouldPreFilterSearchShards() {
int numIndices = randomIntBetween(1, 10);
int numIndices = randomIntBetween(2, 10);
Index[] indices = new Index[numIndices];
for (int i = 0; i < numIndices; i++) {
String indexName = randomAlphaOfLengthBetween(5, 10);
@ -856,7 +855,7 @@ public class TransportSearchActionTests extends ESTestCase {
{
SearchRequest searchRequest = new SearchRequest();
assertFalse(TransportSearchAction.shouldPreFilterSearchShards(clusterState, searchRequest,
indices, randomIntBetween(1, 127)));
indices, randomIntBetween(2, 127)));
assertFalse(TransportSearchAction.shouldPreFilterSearchShards(clusterState, searchRequest,
indices, randomIntBetween(127, 10000)));
}
@ -864,7 +863,7 @@ public class TransportSearchActionTests extends ESTestCase {
SearchRequest searchRequest = new SearchRequest()
.source(new SearchSourceBuilder().query(QueryBuilders.rangeQuery("timestamp")));
assertFalse(TransportSearchAction.shouldPreFilterSearchShards(clusterState, searchRequest,
indices, randomIntBetween(1, 127)));
indices, randomIntBetween(2, 127)));
assertTrue(TransportSearchAction.shouldPreFilterSearchShards(clusterState, searchRequest,
indices, randomIntBetween(127, 10000)));
}
@ -872,7 +871,7 @@ public class TransportSearchActionTests extends ESTestCase {
SearchRequest searchRequest = new SearchRequest()
.source(new SearchSourceBuilder().sort(SortBuilders.fieldSort("timestamp")));
assertTrue(TransportSearchAction.shouldPreFilterSearchShards(clusterState, searchRequest,
indices, randomIntBetween(1, 127)));
indices, randomIntBetween(2, 127)));
assertTrue(TransportSearchAction.shouldPreFilterSearchShards(clusterState, searchRequest,
indices, randomIntBetween(127, 10000)));
}
@ -881,15 +880,14 @@ public class TransportSearchActionTests extends ESTestCase {
.source(new SearchSourceBuilder().sort(SortBuilders.fieldSort("timestamp")))
.scroll("5m");
assertTrue(TransportSearchAction.shouldPreFilterSearchShards(clusterState, searchRequest,
indices, randomIntBetween(1, 127)));
indices, randomIntBetween(2, 127)));
assertTrue(TransportSearchAction.shouldPreFilterSearchShards(clusterState, searchRequest,
indices, randomIntBetween(127, 10000)));
}
}
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/54156")
public void testShouldPreFilterSearchShardsWithReadOnly() {
int numIndices = randomIntBetween(1, 10);
int numIndices = randomIntBetween(2, 10);
int numReadOnly = randomIntBetween(1, numIndices);
Index[] indices = new Index[numIndices];
ClusterBlocks.Builder blocksBuilder = ClusterBlocks.builder();
@ -908,7 +906,7 @@ public class TransportSearchActionTests extends ESTestCase {
{
SearchRequest searchRequest = new SearchRequest();
assertFalse(TransportSearchAction.shouldPreFilterSearchShards(clusterState, searchRequest,
indices, randomIntBetween(1, 127)));
indices, randomIntBetween(2, 127)));
assertFalse(TransportSearchAction.shouldPreFilterSearchShards(clusterState, searchRequest,
indices, randomIntBetween(127, 10000)));
}
@ -916,7 +914,7 @@ public class TransportSearchActionTests extends ESTestCase {
SearchRequest searchRequest = new SearchRequest()
.source(new SearchSourceBuilder().query(QueryBuilders.rangeQuery("timestamp")));
assertTrue(TransportSearchAction.shouldPreFilterSearchShards(clusterState, searchRequest,
indices, randomIntBetween(1, 127)));
indices, randomIntBetween(2, 127)));
assertTrue(TransportSearchAction.shouldPreFilterSearchShards(clusterState, searchRequest,
indices, randomIntBetween(127, 10000)));
}
@ -925,7 +923,7 @@ public class TransportSearchActionTests extends ESTestCase {
.source(new SearchSourceBuilder().query(QueryBuilders.rangeQuery("timestamp")));
searchRequest.scroll("5s");
assertTrue(TransportSearchAction.shouldPreFilterSearchShards(clusterState, searchRequest,
indices, randomIntBetween(127, 10000)));
indices, randomIntBetween(2, 127)));
assertTrue(TransportSearchAction.shouldPreFilterSearchShards(clusterState, searchRequest,
indices, randomIntBetween(127, 10000)));
}
@ -934,7 +932,7 @@ public class TransportSearchActionTests extends ESTestCase {
.source(new SearchSourceBuilder().query(QueryBuilders.rangeQuery("timestamp")));
searchRequest.searchType(SearchType.DFS_QUERY_THEN_FETCH);
assertFalse(TransportSearchAction.shouldPreFilterSearchShards(clusterState, searchRequest,
indices, randomIntBetween(127, 10000)));
indices, randomIntBetween(2, 127)));
assertFalse(TransportSearchAction.shouldPreFilterSearchShards(clusterState, searchRequest,
indices, randomIntBetween(127, 10000)));
}