Skip to content

Commit af36e1a

Browse files
committed
Test IndexNotFound branch
Signed-off-by: Daniel Widdis <[email protected]>
1 parent 3a14d1c commit af36e1a

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

plugin/src/test/java/org/opensearch/ml/action/tasks/DeleteTaskTransportActionTests.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.opensearch.core.xcontent.NamedXContentRegistry;
3737
import org.opensearch.core.xcontent.ToXContent;
3838
import org.opensearch.core.xcontent.XContentBuilder;
39+
import org.opensearch.index.IndexNotFoundException;
3940
import org.opensearch.index.get.GetResult;
4041
import org.opensearch.ml.common.MLTask;
4142
import org.opensearch.ml.common.MLTaskState;
@@ -146,6 +147,20 @@ public void testDeleteTask_ResourceNotFoundException() throws IOException {
146147
assertEquals("Failed to get data object from index .plugins-ml-task", argumentCaptor.getValue().getMessage());
147148
}
148149

150+
public void testDeleteTask_IndexNotFoundException() {
151+
doAnswer(invocation -> {
152+
ActionListener<GetResponse> actionListener = invocation.getArgument(1);
153+
actionListener.onFailure(new IndexNotFoundException(ML_TASK_INDEX));
154+
return null;
155+
}).when(client).get(any(), any());
156+
157+
deleteTaskTransportAction.doExecute(null, mlTaskDeleteRequest, actionListener);
158+
159+
ArgumentCaptor<Exception> argumentCaptor = ArgumentCaptor.forClass(Exception.class);
160+
verify(actionListener).onFailure(argumentCaptor.capture());
161+
assertEquals("Failed to find task", argumentCaptor.getValue().getMessage());
162+
}
163+
149164
public void testDeleteTask_GetResponseNotExistsException() {
150165
GetResult getResult = new GetResult(
151166
ML_TASK_INDEX,

0 commit comments

Comments
 (0)