-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removing unused fetch sub phase processor initialization during fetch… (
#12503) * Removing unused fetch sub phase processor initialization during fetch phase execution Signed-off-by: Ankit Jain <akjain@amazon.com> * Updating CHANGELOG.md with the bug fix Signed-off-by: Ankit Jain <akjain@amazon.com> * Fixing smoke test failures Signed-off-by: Ankit Jain <akjain@amazon.com> * Addressing review comments Signed-off-by: Ankit Jain <akjain@amazon.com> * Addressing review comments around boolean check convention Signed-off-by: Ankit Jain <akjain@amazon.com> --------- Signed-off-by: Ankit Jain <akjain@amazon.com>
- Loading branch information
1 parent
abe270f
commit da5b205
Showing
8 changed files
with
126 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
server/src/test/java/org/opensearch/search/fetch/subphase/InnerHitsPhaseTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.search.fetch.subphase; | ||
|
||
import org.opensearch.index.query.QueryShardContext; | ||
import org.opensearch.search.fetch.FetchContext; | ||
import org.opensearch.search.internal.SearchContext; | ||
import org.opensearch.search.lookup.SearchLookup; | ||
import org.opensearch.test.OpenSearchTestCase; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class InnerHitsPhaseTests extends OpenSearchTestCase { | ||
|
||
/* | ||
Returns mock search context reused across test methods | ||
*/ | ||
private SearchContext getMockSearchContext(final boolean hasInnerHits) { | ||
final QueryShardContext queryShardContext = mock(QueryShardContext.class); | ||
when(queryShardContext.newFetchLookup()).thenReturn(mock(SearchLookup.class)); | ||
|
||
final SearchContext searchContext = mock(SearchContext.class); | ||
when(searchContext.hasInnerHits()).thenReturn(hasInnerHits); | ||
when(searchContext.getQueryShardContext()).thenReturn(queryShardContext); | ||
|
||
return searchContext; | ||
} | ||
|
||
/* | ||
Validates that InnerHitsPhase processor is not initialized when no inner hits | ||
*/ | ||
public void testInnerHitsNull() { | ||
assertNull(new InnerHitsPhase(null).getProcessor(new FetchContext(getMockSearchContext(false)))); | ||
} | ||
|
||
/* | ||
Validates that InnerHitsPhase processor is initialized when inner hits are present | ||
*/ | ||
public void testInnerHitsNonNull() { | ||
final SearchContext searchContext = getMockSearchContext(true); | ||
when(searchContext.innerHits()).thenReturn(new InnerHitsContext()); | ||
|
||
assertNotNull(new InnerHitsPhase(null).getProcessor(new FetchContext(searchContext))); | ||
} | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
server/src/test/java/org/opensearch/search/fetch/subphase/ScriptFieldsPhaseTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.search.fetch.subphase; | ||
|
||
import org.opensearch.index.query.QueryShardContext; | ||
import org.opensearch.search.fetch.FetchContext; | ||
import org.opensearch.search.internal.SearchContext; | ||
import org.opensearch.search.lookup.SearchLookup; | ||
import org.opensearch.test.OpenSearchTestCase; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class ScriptFieldsPhaseTests extends OpenSearchTestCase { | ||
|
||
/* | ||
Returns mock search context reused across test methods | ||
*/ | ||
private SearchContext getMockSearchContext(final boolean hasScriptFields) { | ||
final QueryShardContext queryShardContext = mock(QueryShardContext.class); | ||
when(queryShardContext.newFetchLookup()).thenReturn(mock(SearchLookup.class)); | ||
|
||
final SearchContext searchContext = mock(SearchContext.class); | ||
when(searchContext.hasScriptFields()).thenReturn(hasScriptFields); | ||
when(searchContext.getQueryShardContext()).thenReturn(queryShardContext); | ||
|
||
return searchContext; | ||
} | ||
|
||
/* | ||
Validates that ScriptFieldsPhase processor is not initialized when no script fields | ||
*/ | ||
public void testScriptFieldsNull() { | ||
assertNull(new ScriptFieldsPhase().getProcessor(new FetchContext(getMockSearchContext(false)))); | ||
} | ||
|
||
/* | ||
Validates that ScriptFieldsPhase processor is initialized when script fields are present | ||
*/ | ||
public void testScriptFieldsNonNull() { | ||
final SearchContext searchContext = getMockSearchContext(true); | ||
when(searchContext.scriptFields()).thenReturn(new ScriptFieldsContext()); | ||
|
||
assertNotNull(new ScriptFieldsPhase().getProcessor(new FetchContext(searchContext))); | ||
} | ||
|
||
} |