-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit tests for MachineLearningPlugin
Signed-off-by: Austin Lee <[email protected]>
- Loading branch information
1 parent
8cbac4c
commit 739d96a
Showing
2 changed files
with
118 additions
and
13 deletions.
There are no files selected for viewing
105 changes: 105 additions & 0 deletions
105
plugin/src/test/java/org/opensearch/ml/plugin/MachineLearningPluginTests.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,105 @@ | ||
/* | ||
* Copyright 2023 Aryn | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Licensed 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. | ||
*/ | ||
package org.opensearch.ml.plugin; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.mockito.Mockito.mock; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.junit.Test; | ||
import org.opensearch.common.settings.Settings; | ||
import org.opensearch.plugins.SearchPipelinePlugin; | ||
import org.opensearch.plugins.SearchPlugin; | ||
import org.opensearch.searchpipelines.questionanswering.generative.GenerativeQAProcessorConstants; | ||
import org.opensearch.searchpipelines.questionanswering.generative.GenerativeQARequestProcessor; | ||
import org.opensearch.searchpipelines.questionanswering.generative.GenerativeQAResponseProcessor; | ||
import org.opensearch.searchpipelines.questionanswering.generative.ext.GenerativeQAParamExtBuilder; | ||
|
||
public class MachineLearningPluginTests { | ||
|
||
@Test | ||
public void testGetSearchExtsFeatureDisabled() { | ||
Settings settings = Settings.builder().build(); | ||
MachineLearningPlugin plugin = new MachineLearningPlugin(settings); | ||
List<SearchPlugin.SearchExtSpec<?>> searchExts = plugin.getSearchExts(); | ||
assertEquals(0, searchExts.size()); | ||
} | ||
|
||
@Test | ||
public void testGetSearchExtsFeatureDisabledExplicit() { | ||
Settings settings = Settings.builder().put("plugins.ml_commons.rag_pipeline_feature_enabled", "false").build(); | ||
MachineLearningPlugin plugin = new MachineLearningPlugin(settings); | ||
List<SearchPlugin.SearchExtSpec<?>> searchExts = plugin.getSearchExts(); | ||
assertEquals(0, searchExts.size()); | ||
} | ||
|
||
@Test | ||
public void testGetRequestProcessorsFeatureDisabled() { | ||
Settings settings = Settings.builder().build(); | ||
MachineLearningPlugin plugin = new MachineLearningPlugin(settings); | ||
SearchPipelinePlugin.Parameters parameters = mock(SearchPipelinePlugin.Parameters.class); | ||
Map<String, ?> requestProcessors = plugin.getRequestProcessors(parameters); | ||
assertEquals(0, requestProcessors.size()); | ||
} | ||
|
||
@Test | ||
public void testGetResponseProcessorsFeatureDisabled() { | ||
Settings settings = Settings.builder().build(); | ||
MachineLearningPlugin plugin = new MachineLearningPlugin(settings); | ||
SearchPipelinePlugin.Parameters parameters = mock(SearchPipelinePlugin.Parameters.class); | ||
Map<String, ?> responseProcessors = plugin.getResponseProcessors(parameters); | ||
assertEquals(0, responseProcessors.size()); | ||
} | ||
|
||
@Test | ||
public void testGetSearchExts() { | ||
Settings settings = Settings.builder().put("plugins.ml_commons.rag_pipeline_feature_enabled", "true").build(); | ||
MachineLearningPlugin plugin = new MachineLearningPlugin(settings); | ||
List<SearchPlugin.SearchExtSpec<?>> searchExts = plugin.getSearchExts(); | ||
assertEquals(1, searchExts.size()); | ||
SearchPlugin.SearchExtSpec<?> spec = searchExts.get(0); | ||
assertEquals(GenerativeQAParamExtBuilder.PARAMETER_NAME, spec.getName().getPreferredName()); | ||
} | ||
|
||
@Test | ||
public void testGetRequestProcessors() { | ||
Settings settings = Settings.builder().put("plugins.ml_commons.rag_pipeline_feature_enabled", "true").build(); | ||
MachineLearningPlugin plugin = new MachineLearningPlugin(settings); | ||
SearchPipelinePlugin.Parameters parameters = mock(SearchPipelinePlugin.Parameters.class); | ||
Map<String, ?> requestProcessors = plugin.getRequestProcessors(parameters); | ||
assertEquals(1, requestProcessors.size()); | ||
assertTrue( | ||
requestProcessors.get(GenerativeQAProcessorConstants.REQUEST_PROCESSOR_TYPE) instanceof GenerativeQARequestProcessor.Factory | ||
); | ||
} | ||
|
||
@Test | ||
public void testGetResponseProcessors() { | ||
Settings settings = Settings.builder().put("plugins.ml_commons.rag_pipeline_feature_enabled", "true").build(); | ||
MachineLearningPlugin plugin = new MachineLearningPlugin(settings); | ||
SearchPipelinePlugin.Parameters parameters = mock(SearchPipelinePlugin.Parameters.class); | ||
Map<String, ?> responseProcessors = plugin.getResponseProcessors(parameters); | ||
assertEquals(1, responseProcessors.size()); | ||
assertTrue( | ||
responseProcessors.get(GenerativeQAProcessorConstants.RESPONSE_PROCESSOR_TYPE) instanceof GenerativeQAResponseProcessor.Factory | ||
); | ||
} | ||
} |
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