-
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…
… phase execution Signed-off-by: Ankit Jain <akjain@amazon.com>
- Loading branch information
1 parent
3125b94
commit a742967
Showing
6 changed files
with
168 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
77 changes: 77 additions & 0 deletions
77
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,77 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
/* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
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))); | ||
} | ||
|
||
} |
77 changes: 77 additions & 0 deletions
77
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,77 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
/* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
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))); | ||
} | ||
|
||
} |