|
30 | 30 | import org.opensearch.action.search.ShardSearchFailure; |
31 | 31 | import org.opensearch.action.support.ActionFilters; |
32 | 32 | import org.opensearch.client.Client; |
33 | | -import org.opensearch.cluster.service.ClusterService; |
34 | 33 | import org.opensearch.common.bytes.BytesReference; |
35 | 34 | import org.opensearch.common.settings.Settings; |
36 | 35 | import org.opensearch.common.util.concurrent.ThreadContext; |
37 | 36 | import org.opensearch.common.xcontent.XContentFactory; |
38 | 37 | import org.opensearch.core.xcontent.NamedXContentRegistry; |
39 | 38 | import org.opensearch.core.xcontent.ToXContent; |
40 | 39 | import org.opensearch.core.xcontent.XContentBuilder; |
| 40 | +import org.opensearch.index.IndexNotFoundException; |
41 | 41 | import org.opensearch.index.get.GetResult; |
42 | 42 | import org.opensearch.ml.common.MLModel; |
43 | 43 | import org.opensearch.ml.common.connector.HttpConnector; |
44 | 44 | import org.opensearch.ml.common.exception.MLValidationException; |
45 | 45 | import org.opensearch.ml.common.transport.connector.MLConnectorDeleteRequest; |
46 | 46 | import org.opensearch.ml.helper.ConnectorAccessControlHelper; |
47 | | -import org.opensearch.ml.model.MLModelManager; |
48 | 47 | import org.opensearch.search.SearchHit; |
49 | 48 | import org.opensearch.search.SearchHits; |
50 | 49 | import org.opensearch.search.aggregations.InternalAggregations; |
@@ -74,15 +73,9 @@ public class DeleteConnectorTransportActionTests extends OpenSearchTestCase { |
74 | 73 | @Mock |
75 | 74 | NamedXContentRegistry xContentRegistry; |
76 | 75 |
|
77 | | - @Mock |
78 | | - private MLModelManager mlModelManager; |
79 | | - |
80 | 76 | @Rule |
81 | 77 | public ExpectedException exceptionRule = ExpectedException.none(); |
82 | 78 |
|
83 | | - @Mock |
84 | | - ClusterService clusterService; |
85 | | - |
86 | 79 | DeleteConnectorTransportAction deleteConnectorTransportAction; |
87 | 80 | MLConnectorDeleteRequest mlConnectorDeleteRequest; |
88 | 81 | ThreadContext threadContext; |
@@ -131,6 +124,24 @@ public void testDeleteConnector_Success() throws IOException { |
131 | 124 | verify(actionListener).onResponse(deleteResponse); |
132 | 125 | } |
133 | 126 |
|
| 127 | + public void testDeleteConnector_ModelIndexNotFoundSuccess() throws IOException { |
| 128 | + doAnswer(invocation -> { |
| 129 | + ActionListener<DeleteResponse> listener = invocation.getArgument(1); |
| 130 | + listener.onResponse(deleteResponse); |
| 131 | + return null; |
| 132 | + }).when(client).delete(any(), any()); |
| 133 | + |
| 134 | + SearchResponse searchResponse = getEmptySearchResponse(); |
| 135 | + doAnswer(invocation -> { |
| 136 | + ActionListener<Exception> actionListener = invocation.getArgument(1); |
| 137 | + actionListener.onFailure(new IndexNotFoundException("ml_model index not found!")); |
| 138 | + return null; |
| 139 | + }).when(client).search(any(), any()); |
| 140 | + |
| 141 | + deleteConnectorTransportAction.doExecute(null, mlConnectorDeleteRequest, actionListener); |
| 142 | + verify(actionListener).onResponse(deleteResponse); |
| 143 | + } |
| 144 | + |
134 | 145 | public void testDeleteConnector_ConnectorNotFound() throws IOException { |
135 | 146 | when(deleteResponse.getResult()).thenReturn(DocWriteResponse.Result.NOT_FOUND); |
136 | 147 |
|
|
0 commit comments