Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 2.x] Fix tests to handle ambiguous mlClient method signature #996

Merged
merged 1 commit into from
Jan 15, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
Loading