From c0163941154583f54636d68685d237e4d008b39f Mon Sep 17 00:00:00 2001 From: Owais Date: Wed, 18 Sep 2024 16:21:31 -0700 Subject: [PATCH] Updated test Signed-off-by: Owais --- .../pipeline/SearchPipelineServiceTests.java | 75 +++++++------------ 1 file changed, 27 insertions(+), 48 deletions(-) diff --git a/server/src/test/java/org/opensearch/search/pipeline/SearchPipelineServiceTests.java b/server/src/test/java/org/opensearch/search/pipeline/SearchPipelineServiceTests.java index c0639607de8d1..b52205996f34b 100644 --- a/server/src/test/java/org/opensearch/search/pipeline/SearchPipelineServiceTests.java +++ b/server/src/test/java/org/opensearch/search/pipeline/SearchPipelineServiceTests.java @@ -18,7 +18,6 @@ import org.opensearch.Version; import org.opensearch.action.search.DeleteSearchPipelineRequest; import org.opensearch.action.search.MockSearchPhaseContext; -import org.opensearch.action.search.MultiSearchRequest; import org.opensearch.action.search.PutSearchPipelineRequest; import org.opensearch.action.search.QueryPhaseResultConsumer; import org.opensearch.action.search.SearchPhaseContext; @@ -76,8 +75,6 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.function.Consumer; -import static org.opensearch.search.RandomSearchRequestGenerator.randomSearchRequest; -import static org.hamcrest.Matchers.containsString; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -972,11 +969,7 @@ public void testInlinePipeline() throws Exception { } } - /** - * Tests a pipeline name defined in the search request source. - */ - public void testInlineDefinedPipelineForMultiSearch() throws Exception { - int numberOfSearchRequests = randomIntBetween(0, 32); + public void testInlineDefinedPipeline() throws Exception { SearchPipelineService searchPipelineService = createWithProcessors(); SearchPipelineMetadata metadata = new SearchPipelineMetadata( @@ -1002,49 +995,35 @@ public void testInlineDefinedPipelineForMultiSearch() throws Exception { .build(); searchPipelineService.applyClusterState(new ClusterChangedEvent("", clusterState, previousState)); - MultiSearchRequest multiSearchRequest = new MultiSearchRequest(); - for (int i = 0; i < numberOfSearchRequests; i++) { - SearchRequest searchRequest = randomSearchRequest(() -> { - // No need to return a very complex SearchSourceBuilder here, that is tested - // elsewhere - SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); - searchSourceBuilder.from(randomInt(10)); - searchSourceBuilder.size(randomIntBetween(20, 100)); - searchSourceBuilder.pipeline("p1"); - return searchSourceBuilder; - }); - multiSearchRequest.add(searchRequest); - - // Verify pipeline - PipelinedRequest pipelinedRequest = syncTransformRequest( - searchPipelineService.resolvePipeline(searchRequest, indexNameExpressionResolver) - ); - Pipeline pipeline = pipelinedRequest.getPipeline(); - assertEquals("p1", pipeline.getId()); - assertEquals(1, pipeline.getSearchRequestProcessors().size()); - assertEquals(1, pipeline.getSearchResponseProcessors().size()); - - // Verify that pipeline transforms request - assertEquals(200, pipelinedRequest.source().size()); - - int size = 10; - SearchHit[] hits = new SearchHit[size]; - for (int j = 0; j < size; j++) { - hits[j] = new SearchHit(j, "doc" + j, Collections.emptyMap(), Collections.emptyMap()); - hits[j].score(j); - } - SearchHits searchHits = new SearchHits(hits, new TotalHits(size * 2, TotalHits.Relation.EQUAL_TO), size); - SearchResponseSections searchResponseSections = new SearchResponseSections(searchHits, null, null, false, false, null, 0); - SearchResponse searchResponse = new SearchResponse(searchResponseSections, null, 1, 1, 0, 10, null, null); + SearchSourceBuilder sourceBuilder = SearchSourceBuilder.searchSource().size(100).pipeline("p1"); + SearchRequest searchRequest = new SearchRequest().source(sourceBuilder); + searchRequest.pipeline(searchRequest.source().pipeline()); - SearchResponse transformedResponse = syncTransformResponse(pipelinedRequest, searchResponse); - for (int j = 0; j < size; j++) { - assertEquals(2.0, transformedResponse.getHits().getHits()[j].getScore(), 0.0001); - } + // Verify pipeline + PipelinedRequest pipelinedRequest = syncTransformRequest( + searchPipelineService.resolvePipeline(searchRequest, indexNameExpressionResolver) + ); + Pipeline pipeline = pipelinedRequest.getPipeline(); + assertEquals("p1", pipeline.getId()); + assertEquals(1, pipeline.getSearchRequestProcessors().size()); + assertEquals(1, pipeline.getSearchResponseProcessors().size()); + + // Verify that pipeline transforms request + assertEquals(200, pipelinedRequest.source().size()); + + int size = 10; + SearchHit[] hits = new SearchHit[size]; + for (int i = 0; i < size; i++) { + hits[i] = new SearchHit(i, "doc" + i, Collections.emptyMap(), Collections.emptyMap()); + hits[i].score(i); } + SearchHits searchHits = new SearchHits(hits, new TotalHits(size * 2, TotalHits.Relation.EQUAL_TO), size); + SearchResponseSections searchResponseSections = new SearchResponseSections(searchHits, null, null, false, false, null, 0); + SearchResponse searchResponse = new SearchResponse(searchResponseSections, null, 1, 1, 0, 10, null, null); - for (SearchRequest subReq : multiSearchRequest.requests()) { - assertThat(multiSearchRequest.toString(), containsString(subReq.toString())); + SearchResponse transformedResponse = syncTransformResponse(pipelinedRequest, searchResponse); + for (int i = 0; i < size; i++) { + assertEquals(2.0, transformedResponse.getHits().getHits()[i].getScore(), 0.0001); } }