Skip to content
Open
Show file tree
Hide file tree
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 @@ -83,13 +83,14 @@ public void execute(Input input, ActionListener<Output> listener) {
}

try {
Tool tool = toolFactory.create(new HashMap<>(parameters));
if (!tool.validate(parameters)) {
Map<String, String> mutableParams = new HashMap<>(parameters);
Tool tool = toolFactory.create(mutableParams);
if (!tool.validate(mutableParams)) {
listener.onFailure(new IllegalArgumentException("Invalid parameters for tool: " + toolName));
return;
}

tool.run(parameters, ActionListener.wrap(result -> {
tool.run(mutableParams, ActionListener.wrap(result -> {
List<ModelTensor> modelTensors = new ArrayList<>();
processOutput(result, modelTensors);
ModelTensors tensors = ModelTensors.builder().mlModelTensors(modelTensors).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -41,7 +42,6 @@ public class MLToolExecutorTest {
private Client client;
@Mock
private SdkClient sdkClient;
private Settings settings;
@Mock
private ClusterService clusterService;
@Mock
Expand Down Expand Up @@ -176,4 +176,30 @@ public void test_EmptyInputData() {
mlToolExecutor.execute(toolMLInput, actionListener);
});
}

@Test
public void test_ImmutableEmptyParametersMap() {
Map<String, String> immutableEmptyMap = Collections.emptyMap();

when(toolMLInput.getToolName()).thenReturn("TestTool");
when(toolMLInput.getInputDataset()).thenReturn(inputDataSet);
when(inputDataSet.getParameters()).thenReturn(immutableEmptyMap);
when(toolFactory.create(any())).thenReturn(tool);
when(tool.validate(any())).thenReturn(true);

Mockito.doAnswer(invocation -> {
Map<String, String> params = invocation.getArgument(0);
// Tool tries to modify parameters, should not throw exception
params.put("test_key", "test_value");
ActionListener<Object> listener = invocation.getArgument(1);
listener.onResponse("test result");
return null;
}).when(tool).run(any(), any());

mlToolExecutor.execute(toolMLInput, actionListener);

Mockito.verify(actionListener).onResponse(outputCaptor.capture());
Output output = outputCaptor.getValue();
Assert.assertTrue(output instanceof ModelTensorOutput);
}
}
Loading