-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Varun Jain <[email protected]>
- Loading branch information
1 parent
88ba2e9
commit c06d07a
Showing
11 changed files
with
233 additions
and
48 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
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
50 changes: 50 additions & 0 deletions
50
src/test/java/org/opensearch/neuralsearch/processor/NeuralQueryProcessorTests.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,50 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.neuralsearch.processor; | ||
|
||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.opensearch.action.search.SearchRequest; | ||
import org.opensearch.neuralsearch.query.NeuralQueryBuilder; | ||
import org.opensearch.search.builder.SearchSourceBuilder; | ||
import org.opensearch.test.OpenSearchTestCase; | ||
|
||
public class NeuralQueryProcessorTests extends OpenSearchTestCase { | ||
|
||
public void testFactory() throws Exception { | ||
NeuralQueryProcessor.Factory factory = new NeuralQueryProcessor.Factory(); | ||
NeuralQueryProcessor processor = createTestProcessor(factory); | ||
assertEquals("vasdcvkcjkbldbjkd", processor.modelId); | ||
assertEquals("bahbkcdkacb", processor.neuralFieldMap.get("fieldName").toString()); | ||
|
||
// Missing "query" parameter: | ||
expectThrows( | ||
IllegalArgumentException.class, | ||
() -> factory.create(Collections.emptyMap(), null, null, false, Collections.emptyMap(), null) | ||
); | ||
} | ||
|
||
public void testProcessRequest() throws Exception { | ||
NeuralQueryProcessor.Factory factory = new NeuralQueryProcessor.Factory(); | ||
NeuralQueryBuilder neuralQueryBuilder = new NeuralQueryBuilder(); | ||
SearchRequest searchRequest = new SearchRequest(); | ||
searchRequest.source(new SearchSourceBuilder().query(neuralQueryBuilder)); | ||
NeuralQueryProcessor processor = createTestProcessor(factory); | ||
SearchRequest processSearchRequest = processor.processRequest(searchRequest); | ||
assertEquals(processSearchRequest, searchRequest); | ||
} | ||
|
||
public NeuralQueryProcessor createTestProcessor(NeuralQueryProcessor.Factory factory) throws Exception { | ||
Map<String, Object> configMap = new HashMap<>(); | ||
configMap.put("default_model_id", "vasdcvkcjkbldbjkd"); | ||
configMap.put("neural_field_default_id", Map.of("fieldName", "bahbkcdkacb")); | ||
NeuralQueryProcessor processor = factory.create(Collections.emptyMap(), null, null, false, configMap, null); | ||
return processor; | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
src/test/java/org/opensearch/neuralsearch/util/NeuralSearchClusterTestUtils.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,32 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.neuralsearch.util; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
import org.opensearch.Version; | ||
import org.opensearch.cluster.ClusterState; | ||
import org.opensearch.cluster.node.DiscoveryNodes; | ||
import org.opensearch.cluster.service.ClusterService; | ||
|
||
public class NeuralSearchClusterTestUtils { | ||
|
||
/** | ||
* Create new mock for ClusterService | ||
* @param version min version for cluster nodes | ||
* @return | ||
*/ | ||
public static ClusterService mockClusterService(final Version version) { | ||
ClusterService clusterService = mock(ClusterService.class); | ||
ClusterState clusterState = mock(ClusterState.class); | ||
when(clusterService.state()).thenReturn(clusterState); | ||
DiscoveryNodes discoveryNodes = mock(DiscoveryNodes.class); | ||
when(clusterState.getNodes()).thenReturn(discoveryNodes); | ||
when(discoveryNodes.getMinNodeVersion()).thenReturn(version); | ||
return clusterService; | ||
} | ||
} |
Oops, something went wrong.