From 5abf95503317eb93e1d9be7d2dbb4b1c65a490ea Mon Sep 17 00:00:00 2001 From: Chenyang Ji Date: Wed, 10 Apr 2024 15:08:49 -0700 Subject: [PATCH] add unit test for complex data structures Signed-off-by: Chenyang Ji --- .../opensearch/action/search/SearchRequestTests.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/server/src/test/java/org/opensearch/action/search/SearchRequestTests.java b/server/src/test/java/org/opensearch/action/search/SearchRequestTests.java index 41d77ed656772..6468f69cc82e8 100644 --- a/server/src/test/java/org/opensearch/action/search/SearchRequestTests.java +++ b/server/src/test/java/org/opensearch/action/search/SearchRequestTests.java @@ -46,6 +46,7 @@ import org.opensearch.search.Scroll; import org.opensearch.search.builder.PointInTimeBuilder; import org.opensearch.search.builder.SearchSourceBuilder; +import org.opensearch.search.fetch.subphase.FetchSourceContext; import org.opensearch.search.rescore.QueryRescorerBuilder; import org.opensearch.test.OpenSearchTestCase; import org.opensearch.test.VersionUtils; @@ -76,11 +77,20 @@ protected SearchRequest createSearchRequest() throws IOException { ); } - public void testClone() { + public void testClone() throws IOException { SearchRequest searchRequest = new SearchRequest(); SearchRequest clonedRequest = searchRequest.clone(); assertEquals(searchRequest.hashCode(), clonedRequest.hashCode()); assertNotSame(searchRequest, clonedRequest); + + SearchSourceBuilder source = new SearchSourceBuilder() + .fetchSource(new FetchSourceContext(true, new String[] { "field1.*" }, new String[] { "field2.*" })); + SearchRequest complexSearchRequest = createSearchRequest().source(source); + complexSearchRequest.requestCache(false); + complexSearchRequest.scroll(new TimeValue(1000)); + SearchRequest clonedComplexRequest = complexSearchRequest.clone(); + assertEquals(complexSearchRequest.hashCode(), clonedComplexRequest.hashCode()); + assertNotSame(complexSearchRequest, clonedComplexRequest); } public void testWithLocalReduction() {