Skip to content

Commit

Permalink
fix bug - not found agent index (opensearch-project#1866)
Browse files Browse the repository at this point in the history
Signed-off-by: Jing Zhang <[email protected]>
  • Loading branch information
jngz-es authored Jan 12, 2024
1 parent e3a8a59 commit 433d81b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,9 @@ public void execute(Input input, ActionListener<Output> listener) {
listener.onFailure(e);
}), context::restore));
}
} else {
listener.onFailure(new ResourceNotFoundException("Agent index not found"));
}

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,25 @@ public void setup() {

}

@Test
public void test_NoAgentIndex() {
ModelTensor modelTensor = ModelTensor.builder().name("response").dataAsMap(ImmutableMap.of("test_key", "test_value")).build();
Mockito.doAnswer(invocation -> {
ActionListener<ModelTensor> listener = invocation.getArgument(2);
listener.onResponse(modelTensor);
return null;
}).when(mlAgentRunner).run(Mockito.any(), Mockito.any(), Mockito.any());
Mockito.doReturn(mlAgentRunner).when(mlAgentExecutor).getAgentRunner(Mockito.any());
Mockito.when(metadata.hasIndex(Mockito.anyString())).thenReturn(false);

mlAgentExecutor.execute(getAgentMLInput(), agentActionListener);

Mockito.verify(agentActionListener).onFailure(exceptionCaptor.capture());
Exception exception = exceptionCaptor.getValue();
Assert.assertTrue(exception instanceof ResourceNotFoundException);
Assert.assertEquals(exception.getMessage(), "Agent index not found");
}

@Test(expected = IllegalArgumentException.class)
public void test_NullInput_ThrowsException() {
mlAgentExecutor.execute(null, agentActionListener);
Expand Down

0 comments on commit 433d81b

Please sign in to comment.