Skip to content

Commit

Permalink
Fix tests to handle ambiguous mlClient method signature (#995)
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Widdis <widdis@gmail.com>
(cherry picked from commit 4b92fb8)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
github-actions[bot] committed Jan 15, 2025
1 parent 153687e commit f5f86ab
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import static org.opensearch.flowframework.common.WorkflowResources.CONNECTOR_ID;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.verify;

Expand Down Expand Up @@ -58,7 +59,7 @@ public void testDeleteConnector() throws IOException, ExecutionException, Interr
DeleteResponse output = new DeleteResponse(shardId, connectorIdArg, 1, 1, 1, true);
actionListener.onResponse(output);
return null;
}).when(machineLearningNodeClient).deleteConnector(any(String.class), any());
}).when(machineLearningNodeClient).deleteConnector(anyString(), anyActionListener());

PlainActionFuture<WorkflowData> future = deleteConnectorStep.execute(
inputData.getNodeId(),
Expand All @@ -67,7 +68,7 @@ public void testDeleteConnector() throws IOException, ExecutionException, Interr
Map.of("step_1", CONNECTOR_ID),
Collections.emptyMap()
);
verify(machineLearningNodeClient).deleteConnector(any(String.class), any());
verify(machineLearningNodeClient).deleteConnector(anyString(), anyActionListener());

assertTrue(future.isDone());
assertEquals(connectorId, future.get().getContent().get(CONNECTOR_ID));
Expand Down Expand Up @@ -97,7 +98,7 @@ public void testDeleteConnectorFailure() throws IOException {
ActionListener<DeleteResponse> actionListener = invocation.getArgument(1);
actionListener.onFailure(new FlowFrameworkException("Failed to delete connector", RestStatus.INTERNAL_SERVER_ERROR));
return null;
}).when(machineLearningNodeClient).deleteConnector(any(String.class), any());
}).when(machineLearningNodeClient).deleteConnector(anyString(), anyActionListener());

PlainActionFuture<WorkflowData> future = deleteConnectorStep.execute(
inputData.getNodeId(),
Expand All @@ -107,11 +108,16 @@ public void testDeleteConnectorFailure() throws IOException {
Collections.emptyMap()
);

verify(machineLearningNodeClient).deleteConnector(any(String.class), any());
verify(machineLearningNodeClient).deleteConnector(anyString(), anyActionListener());

assertTrue(future.isDone());
ExecutionException ex = assertThrows(ExecutionException.class, () -> future.get().getContent());
assertTrue(ex.getCause() instanceof FlowFrameworkException);
assertEquals("Failed to delete connector test", ex.getCause().getMessage());
}

@SuppressWarnings("unchecked")
private ActionListener<DeleteResponse> anyActionListener() {
return any(ActionListener.class);
}
}

0 comments on commit f5f86ab

Please sign in to comment.