Skip to content

Commit

Permalink
SearchServiceTests.testParseSourceValidation failure (#117963)
Browse files Browse the repository at this point in the history
Remove test for deprecated code removed for v_9
  • Loading branch information
drempapis authored Dec 5, 2024
1 parent 5d1bca3 commit 949816f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 118 deletions.
5 changes: 5 additions & 0 deletions docs/changelog/117963.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 117963
summary: '`SearchServiceTests.testParseSourceValidation` failure'
area: Search
type: bug
issues: []
3 changes: 0 additions & 3 deletions muted-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,6 @@ tests:
- class: org.elasticsearch.search.StressSearchServiceReaperIT
method: testStressReaper
issue: https://github.com/elastic/elasticsearch/issues/115816
- class: org.elasticsearch.search.SearchServiceTests
method: testParseSourceValidation
issue: https://github.com/elastic/elasticsearch/issues/115936
- class: org.elasticsearch.xpack.application.connector.ConnectorIndexServiceTests
issue: https://github.com/elastic/elasticsearch/issues/116087
- class: org.elasticsearch.backwards.MixedClusterClientYamlTestSuiteIT
Expand Down
115 changes: 0 additions & 115 deletions server/src/test/java/org/elasticsearch/search/SearchServiceTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@
import org.elasticsearch.search.aggregations.support.ValueType;
import org.elasticsearch.search.builder.PointInTimeBuilder;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.search.collapse.CollapseBuilder;
import org.elasticsearch.search.dfs.AggregatedDfs;
import org.elasticsearch.search.fetch.FetchSearchResult;
import org.elasticsearch.search.fetch.ShardFetchRequest;
Expand Down Expand Up @@ -124,7 +123,6 @@
import org.elasticsearch.search.rank.feature.RankFeatureResult;
import org.elasticsearch.search.rank.feature.RankFeatureShardRequest;
import org.elasticsearch.search.rank.feature.RankFeatureShardResult;
import org.elasticsearch.search.slice.SliceBuilder;
import org.elasticsearch.search.suggest.SuggestBuilder;
import org.elasticsearch.tasks.TaskCancelHelper;
import org.elasticsearch.tasks.TaskCancelledException;
Expand Down Expand Up @@ -2930,119 +2928,6 @@ public void testSlicingBehaviourForParallelCollection() throws Exception {
}
}

/**
* This method tests validation that happens on the data nodes, which is now performed on the coordinating node.
* We still need the validation to cover for mixed cluster scenarios where the coordinating node does not perform the check yet.
*/
public void testParseSourceValidation() {
String index = randomAlphaOfLengthBetween(5, 10).toLowerCase(Locale.ROOT);
IndexService indexService = createIndex(index);
final SearchService service = getInstanceFromNode(SearchService.class);
{
// scroll and search_after
SearchRequest searchRequest = new SearchRequest().source(new SearchSourceBuilder());
searchRequest.scroll(new TimeValue(1000));
searchRequest.source().searchAfter(new String[] { "value" });
assertCreateContextValidation(searchRequest, "`search_after` cannot be used in a scroll context.", indexService, service);
}
{
// scroll and collapse
SearchRequest searchRequest = new SearchRequest().source(new SearchSourceBuilder());
searchRequest.scroll(new TimeValue(1000));
searchRequest.source().collapse(new CollapseBuilder("field"));
assertCreateContextValidation(searchRequest, "cannot use `collapse` in a scroll context", indexService, service);
}
{
// search_after and `from` isn't valid
SearchRequest searchRequest = new SearchRequest().source(new SearchSourceBuilder());
searchRequest.source().searchAfter(new String[] { "value" });
searchRequest.source().from(10);
assertCreateContextValidation(
searchRequest,
"`from` parameter must be set to 0 when `search_after` is used",
indexService,
service
);
}
{
// slice without scroll or pit
SearchRequest searchRequest = new SearchRequest().source(new SearchSourceBuilder());
searchRequest.source().slice(new SliceBuilder(1, 10));
assertCreateContextValidation(
searchRequest,
"[slice] can only be used with [scroll] or [point-in-time] requests",
indexService,
service
);
}
{
// stored fields disabled with _source requested
SearchRequest searchRequest = new SearchRequest().source(new SearchSourceBuilder());
searchRequest.source().storedField("_none_");
searchRequest.source().fetchSource(true);
assertCreateContextValidation(
searchRequest,
"[stored_fields] cannot be disabled if [_source] is requested",
indexService,
service
);
}
{
// stored fields disabled with fetch fields requested
SearchRequest searchRequest = new SearchRequest().source(new SearchSourceBuilder());
searchRequest.source().storedField("_none_");
searchRequest.source().fetchSource(false);
searchRequest.source().fetchField("field");
assertCreateContextValidation(
searchRequest,
"[stored_fields] cannot be disabled when using the [fields] option",
indexService,
service
);
}
}

private static void assertCreateContextValidation(
SearchRequest searchRequest,
String errorMessage,
IndexService indexService,
SearchService searchService
) {
ShardId shardId = new ShardId(indexService.index(), 0);
long nowInMillis = System.currentTimeMillis();
String clusterAlias = randomBoolean() ? null : randomAlphaOfLengthBetween(3, 10);
searchRequest.allowPartialSearchResults(randomBoolean());
ShardSearchRequest request = new ShardSearchRequest(
OriginalIndices.NONE,
searchRequest,
shardId,
0,
indexService.numberOfShards(),
AliasFilter.EMPTY,
1f,
nowInMillis,
clusterAlias
);

SearchShardTask task = new SearchShardTask(1, "type", "action", "description", null, emptyMap());

ReaderContext readerContext = null;
try {
ReaderContext createOrGetReaderContext = searchService.createOrGetReaderContext(request);
readerContext = createOrGetReaderContext;
IllegalArgumentException exception = expectThrows(
IllegalArgumentException.class,
() -> searchService.createContext(createOrGetReaderContext, request, task, ResultsType.QUERY, randomBoolean())
);
assertThat(exception.getMessage(), containsString(errorMessage));
} finally {
if (readerContext != null) {
readerContext.close();
searchService.freeReaderContext(readerContext.id());
}
}
}

private static ReaderContext createReaderContext(IndexService indexService, IndexShard indexShard) {
return new ReaderContext(
new ShardSearchContextId(UUIDs.randomBase64UUID(), randomNonNegativeLong()),
Expand Down

0 comments on commit 949816f

Please sign in to comment.