Skip to content

Commit

Permalink
add unit tests to register and delete model classes
Browse files Browse the repository at this point in the history
Signed-off-by: Bhavana Ramaram <[email protected]>
  • Loading branch information
rbhavna committed Jul 10, 2023
1 parent 7bea913 commit 4f49ec1
Show file tree
Hide file tree
Showing 10 changed files with 233 additions and 285 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
import static org.opensearch.ml.engine.algorithms.metrics_correlation.MetricsCorrelation.MODEL_CONTENT_HASH;

//TODO: fix mockito error: Cannot mock/spy class org.opensearch.common.settings.Settings final class

@Ignore
public class MetricsCorrelationTest {
@Rule
Expand Down Expand Up @@ -195,7 +196,7 @@ public void setUp() throws IOException, URISyntaxException {
extendedInput = MetricsCorrelationInput.builder().inputData(extendedInputData).build();
}

@Ignore
@Test
public void testWhenModelIdNotNullButModelIsNotDeployed() throws ExecuteException {
metricsCorrelation.initModel(model, params);
Expand Down Expand Up @@ -224,7 +225,7 @@ public void testWhenModelIdNotNullButModelIsNotDeployed() throws ExecuteExceptio
assertNull(mlModelOutputs.get(0).getMCorrModelTensors());
}

@Ignore
@Test
public void testExecuteWithModelInIndexAndEmptyOutput() throws ExecuteException, URISyntaxException {
Map<String, Object> params = new HashMap<>();
Expand Down Expand Up @@ -287,7 +288,7 @@ public void testExecuteWithModelInIndexAndOneEvent() throws ExecuteException, UR
assertNotNull(mlModelOutputs.get(0).getMCorrModelTensors().get(0).getSuspected_metrics());
}

@Ignore
@Test
public void testExecuteWithNoModelIndexAndOneEvent() throws ExecuteException, URISyntaxException {
Map<String, Object> params = new HashMap<>();
Expand Down Expand Up @@ -328,7 +329,7 @@ public void testExecuteWithNoModelIndexAndOneEvent() throws ExecuteException, UR
assertNotNull(mlModelOutputs.get(0).getMCorrModelTensors().get(0).getSuspected_metrics());
}

@Ignore
@Test
public void testExecuteWithModelInIndexAndInvokeDeployAndOneEvent() throws ExecuteException, URISyntaxException {
Map<String, Object> params = new HashMap<>();
Expand Down Expand Up @@ -376,7 +377,7 @@ public void testExecuteWithModelInIndexAndInvokeDeployAndOneEvent() throws Execu
}


@Ignore
@Test
public void testExecuteWithNoModelInIndexAndOneEvent() throws ExecuteException, URISyntaxException {
Map<String, Object> params = new HashMap<>();
Expand Down Expand Up @@ -418,7 +419,7 @@ public void testExecuteWithNoModelInIndexAndOneEvent() throws ExecuteException,
assertNotNull(mlModelOutputs.get(0).getMCorrModelTensors().get(0).getSuspected_metrics());
}

@Ignore
@Test
public void testGetModel() {
ActionFuture<MLModelGetResponse> mockedFuture = mock(ActionFuture.class);
Expand Down Expand Up @@ -483,7 +484,7 @@ public void testSearchRequest() {
assertEquals(MLModel.MODEL_VERSION_FIELD, versionQueryBuilder.fieldName());
}

@Ignore
@Test
public void testRegisterModel() throws InterruptedException {
doAnswer(invocation -> {
Expand All @@ -507,7 +508,7 @@ public void testRegisterModel() throws InterruptedException {
verify(mlRegisterModelResponseActionListener).onResponse(mlRegisterModelResponse);
}

@Ignore
@Test
public void testDeployModel() {
doAnswer(invocation -> {
Expand All @@ -522,7 +523,7 @@ public void testDeployModel() {
verify(mlDeployModelResponseActionListener).onResponse(mlDeployModelResponse);
}

@Ignore
@Test
public void testDeployModelFail() {
Exception ex = new ExecuteException("Testing");
Expand All @@ -535,22 +536,22 @@ public void testDeployModelFail() {
verify(mlDeployModelResponseActionListener).onFailure(ex);
}

@Ignore
@Test
public void testWrongInput() throws ExecuteException {
exceptionRule.expect(ExecuteException.class);
metricsCorrelation.execute(mock(LocalSampleCalculatorInput.class));
}

@Ignore
@Test
public void parseModelTensorOutput_NullOutput() {
exceptionRule.expect(MLException.class);
exceptionRule.expectMessage("No output generated");
metricsCorrelation.parseModelTensorOutput(null, null);
}

@Ignore
@Test
public void initModel_NullModelZipFile() {
exceptionRule.expect(IllegalArgumentException.class);
Expand All @@ -560,7 +561,7 @@ public void initModel_NullModelZipFile() {
metricsCorrelation.initModel(model, params);
}

@Ignore
@Test
public void initModel_NullModelHelper() throws URISyntaxException {
exceptionRule.expect(IllegalArgumentException.class);
Expand All @@ -570,7 +571,7 @@ public void initModel_NullModelHelper() throws URISyntaxException {
metricsCorrelation.initModel(model, params);
}

@Ignore
@Test
public void initModel_NullMLEngine() throws URISyntaxException {
exceptionRule.expect(IllegalArgumentException.class);
Expand All @@ -581,7 +582,7 @@ public void initModel_NullMLEngine() throws URISyntaxException {
metricsCorrelation.initModel(model, params);
}

@Ignore
@Test
public void initModel_NullModelId() throws URISyntaxException {
exceptionRule.expect(IllegalArgumentException.class);
Expand All @@ -591,7 +592,7 @@ public void initModel_NullModelId() throws URISyntaxException {
metricsCorrelation.initModel(model, params);
}

@Ignore
@Test
public void initModel_WrongFunctionName() {
exceptionRule.expect(IllegalArgumentException.class);
Expand Down
11 changes: 2 additions & 9 deletions plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -293,17 +293,10 @@ List<String> jacocoExclusions = [
'org.opensearch.ml.action.connector.DeleteConnectorTransportAction.1',
'org.opensearch.ml.action.connector.TransportCreateConnectorAction',
'org.opensearch.ml.action.connector.SearchConnectorTransportAction',
'org.opensearch.ml.rest.RestMLCreateConnectorAction'
'org.opensearch.ml.rest.RestMLCreateConnectorAction',
'org.opensearch.ml.action.connector.SearchConnectorTransportAction',
'org.opensearch.ml.model.MLModelGroupManager',
'org.opensearch.ml.action.upload_chunk.TransportRegisterModelMetaAction',
'org.opensearch.ml.helper.ModelAccessControlHelper',
'org.opensearch.ml.action.models.DeleteModelTransportAction',
'org.opensearch.ml.action.models.DeleteModelTransportAction.1',
'org.opensearch.ml.action.models.DeleteModelTransportAction.2',
'org.opensearch.ml.action.register.TransportRegisterModelAction',
'org.opensearch.ml.action.model_group.TransportRegisterModelGroupAction',
'org.opensearch.ml.action.model_group.TransportUpdateModelGroupAction'
'org.opensearch.ml.helper.ModelAccessControlHelper'
]

jacocoTestCoverageVerification {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public TransportRegisterModelGroupAction(
this.threadPool = threadPool;
this.client = client;
this.clusterService = clusterService;
this.modelAccessControlHelper = modelAccessControlHelper;
this.mlModelGroupManager = mlModelGroupManager;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
package org.opensearch.ml.action.model_group;

import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.rules.ExpectedException;
import org.opensearch.action.search.SearchRequest;
Expand Down Expand Up @@ -41,7 +40,6 @@ private void registerModelGroup() {
this.modelGroupId = response.getModelGroupId();
}

@Ignore
public void test_empty_body_search() {
SearchRequest searchRequest = new SearchRequest();
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
Expand All @@ -51,7 +49,6 @@ public void test_empty_body_search() {
assertEquals(modelGroupId, response.getHits().getHits()[0].getId());
}

@Ignore
public void test_matchAll_search() {
SearchRequest searchRequest = new SearchRequest();
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
Expand All @@ -62,7 +59,6 @@ public void test_matchAll_search() {
assertEquals(modelGroupId, response.getHits().getHits()[0].getId());
}

@Ignore
public void test_bool_search() {
SearchRequest searchRequest = new SearchRequest();
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
Expand All @@ -73,7 +69,6 @@ public void test_bool_search() {
assertEquals(modelGroupId, response.getHits().getHits()[0].getId());
}

@Ignore
public void test_term_search() {
SearchRequest searchRequest = new SearchRequest();
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
Expand All @@ -84,7 +79,6 @@ public void test_term_search() {
assertEquals(modelGroupId, response.getHits().getHits()[0].getId());
}

@Ignore
public void test_terms_search() {
SearchRequest searchRequest = new SearchRequest();
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
Expand All @@ -95,7 +89,6 @@ public void test_terms_search() {
assertEquals(modelGroupId, response.getHits().getHits()[0].getId());
}

@Ignore
public void test_range_search() {
SearchRequest searchRequest = new SearchRequest();
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
Expand All @@ -106,7 +99,6 @@ public void test_range_search() {
assertEquals(modelGroupId, response.getHits().getHits()[0].getId());
}

@Ignore
public void test_matchPhrase_search() {
SearchRequest searchRequest = new SearchRequest();
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
Expand All @@ -117,7 +109,6 @@ public void test_matchPhrase_search() {
assertEquals(modelGroupId, response.getHits().getHits()[0].getId());
}

@Ignore
public void test_queryString_search() {
SearchRequest searchRequest = new SearchRequest();
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
Expand Down
Loading

0 comments on commit 4f49ec1

Please sign in to comment.