Skip to content

Commit

Permalink
Adding test for execption with POST for invokeModel
Browse files Browse the repository at this point in the history
Signed-off-by: TrungBui59 <[email protected]>
  • Loading branch information
TrungBui59 committed Nov 21, 2023
1 parent 09fa0e7 commit 8d9ff2f
Showing 1 changed file with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.opensearch.ml.common.dataset.MLInputDataset;
import org.opensearch.ml.common.dataset.TextDocsInputDataSet;
import org.opensearch.ml.common.dataset.remote.RemoteInferenceInputDataSet;
import org.opensearch.ml.common.exception.MLException;
import org.opensearch.ml.common.input.MLInput;
import org.opensearch.ml.common.output.model.ModelTensorOutput;
import org.opensearch.ml.engine.httpclient.MLHttpClientFactory;
Expand Down Expand Up @@ -59,6 +60,22 @@ public void setUp() {
MockitoAnnotations.openMocks(this);
}

@Test
public void invokeRemoteModel_POSTMethodErrorPath() {
exceptionRule.expect(MLException.class);
exceptionRule.expectMessage("Failed to create http request for remote model");

ConnectorAction predictAction = ConnectorAction.builder()
.actionType(ConnectorAction.ActionType.PREDICT)
.method("post")
.url("wrong url")
.requestBody("{\"input\": \"${parameters.input}\"}")
.build();
Connector connector = HttpConnector.builder().name("test connector").version("1").protocol("http").actions(Arrays.asList(predictAction)).build();
HttpJsonConnectorExecutor executor = new HttpJsonConnectorExecutor(connector);
executor.invokeRemoteModel(null, null, null, null);
}

@Test
public void invokeRemoteModel_WrongHttpMethod() {
exceptionRule.expect(IllegalArgumentException.class);
Expand Down

0 comments on commit 8d9ff2f

Please sign in to comment.