Skip to content

Commit

Permalink
Added Visitor test cases and addressed comments
Browse files Browse the repository at this point in the history
Signed-off-by: Varun Jain <[email protected]>
  • Loading branch information
vibrantvarun committed Sep 27, 2023
1 parent d0b70c7 commit c9ada83
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@

public class NeuralQueryProcessorIT extends BaseNeuralSearchIT {

public static final String index = "my-nlp-index";
public static final String search_pipeline = "search-pipeline";
public static final String ingest_pipeline = "nlp-pipeline";
private static final String index = "my-nlp-index";
private static final String search_pipeline = "search-pipeline";
private static final String ingest_pipeline = "nlp-pipeline";
private static final String TEST_KNN_VECTOR_FIELD_NAME_1 = "test-knn-vector-1";
private static final int TEST_DIMENSION = 768;
private static final SpaceType TEST_SPACE_TYPE = SpaceType.L2;
Expand All @@ -47,6 +47,7 @@ public void tearDown() {
findDeployedModels().forEach(this::deleteModel);
}

@SneakyThrows
public void testNeuralQueryProcessor() throws Exception {
initializeIndexIfNotExist();
String modelId = getDeployedModelId();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

package org.opensearch.neuralsearch.query.visitor;

import java.util.HashMap;
import java.util.Map;

import org.apache.lucene.search.BooleanClause;
import org.opensearch.neuralsearch.query.NeuralQueryBuilder;
import org.opensearch.test.OpenSearchTestCase;

public class NeuralSearchQueryVisitorTests extends OpenSearchTestCase {

public void testAccept_whenNeuralQueryBuilderWithoutModelId_thenSetModelId() {
String modelId = "bdcvjkcdjvkddcjxdjsc";
NeuralQueryBuilder neuralQueryBuilder = new NeuralQueryBuilder();
neuralQueryBuilder.fieldName("passage_text");
neuralQueryBuilder.k(768);

NeuralSearchQueryVisitor neuralSearchQueryVisitor = new NeuralSearchQueryVisitor(modelId, null);
neuralSearchQueryVisitor.accept(neuralQueryBuilder);

assertEquals(modelId, neuralQueryBuilder.modelId());
}

public void testAccept_whenNeuralQueryBuilderWithoutFieldModelId_thenSetFieldModelId() {
Map<String, Object> neuralInfoMap = new HashMap<>();
neuralInfoMap.put("passage_text", "bdcvjkcdjvkddcjxdjsc");
NeuralQueryBuilder neuralQueryBuilder = new NeuralQueryBuilder();
neuralQueryBuilder.fieldName("passage_text");
neuralQueryBuilder.k(768);

NeuralSearchQueryVisitor neuralSearchQueryVisitor = new NeuralSearchQueryVisitor(null, neuralInfoMap);
neuralSearchQueryVisitor.accept(neuralQueryBuilder);

assertEquals("bdcvjkcdjvkddcjxdjsc", neuralQueryBuilder.modelId());
}

public void testAccept_whenNullValuesInVisitor_thenFail() {
NeuralQueryBuilder neuralQueryBuilder = new NeuralQueryBuilder();
NeuralSearchQueryVisitor neuralSearchQueryVisitor = new NeuralSearchQueryVisitor(null, null);

expectThrows(IllegalArgumentException.class, () -> neuralSearchQueryVisitor.accept(neuralQueryBuilder));
}

public void testGetChildVisitor() {
NeuralSearchQueryVisitor neuralSearchQueryVisitor = new NeuralSearchQueryVisitor(null, null);

NeuralSearchQueryVisitor subVisitor = (NeuralSearchQueryVisitor) neuralSearchQueryVisitor.getChildVisitor(BooleanClause.Occur.MUST);

assertEquals(subVisitor, neuralSearchQueryVisitor);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

public class NeuralSearchClusterUtilTests extends OpenSearchTestCase {

public void testSingleNodeCluster() {
public void testMinNodeVersion_whenSingleNodeCluster_thenSuccess() {
ClusterService clusterService = mockClusterService(Version.V_2_4_0);

final NeuralSearchClusterUtil neuralSearchClusterUtil = NeuralSearchClusterUtil.instance();
Expand All @@ -26,7 +26,7 @@ public void testSingleNodeCluster() {
assertTrue(Version.V_2_4_0.equals(minVersion));
}

public void testMultipleNodesCluster() {
public void testMinNodeVersion_whenMultipleNodesCluster_thenSuccess() {
ClusterService clusterService = mockClusterService(Version.V_2_3_0);

final NeuralSearchClusterUtil neuralSearchClusterUtil = NeuralSearchClusterUtil.instance();
Expand All @@ -37,7 +37,7 @@ public void testMultipleNodesCluster() {
assertTrue(Version.V_2_3_0.equals(minVersion));
}

public void testWhenErrorOnClusterStateDiscover() {
public void testMinNodeVersion_WhenErrorOnClusterState_thenMatchCurrentVersion() {
ClusterService clusterService = mock(ClusterService.class);
when(clusterService.state()).thenThrow(new RuntimeException("Cluster state is not ready"));

Expand Down

0 comments on commit c9ada83

Please sign in to comment.