|
17 | 17 | import java.io.IOException;
|
18 | 18 | import java.util.List;
|
19 | 19 | import java.util.Set;
|
| 20 | +import java.util.function.Function; |
20 | 21 | import java.util.stream.IntStream;
|
21 | 22 | import java.util.stream.Stream;
|
22 | 23 |
|
@@ -154,34 +155,55 @@ public void testDeleteEndpointWhileReferencedByPipeline() throws IOException {
|
154 | 155 | }
|
155 | 156 |
|
156 | 157 | public void testDeleteEndpointWhileReferencedBySemanticText() throws IOException {
|
157 |
| - String endpointId = "endpoint_referenced_by_semantic_text"; |
| 158 | + final String endpointId = "endpoint_referenced_by_semantic_text"; |
| 159 | + final String searchEndpointId = "search_endpoint_referenced_by_semantic_text"; |
| 160 | + final String indexName = randomAlphaOfLength(10).toLowerCase(); |
| 161 | + final Function<String, String> buildErrorString = endpointName -> " Inference endpoint " |
| 162 | + + endpointName |
| 163 | + + " is being used in the mapping for indexes: " |
| 164 | + + Set.of(indexName) |
| 165 | + + ". Ensure that no index mappings are using this inference endpoint, or use force to ignore this warning and delete the" |
| 166 | + + " inference endpoint."; |
| 167 | + |
158 | 168 | putModel(endpointId, mockSparseServiceModelConfig(), TaskType.SPARSE_EMBEDDING);
|
159 |
| - String indexName = randomAlphaOfLength(10).toLowerCase(); |
160 | 169 | putSemanticText(endpointId, indexName);
|
161 | 170 | {
|
162 |
| - |
163 |
| - var errorString = new StringBuilder().append(" Inference endpoint ") |
164 |
| - .append(endpointId) |
165 |
| - .append(" is being used in the mapping for indexes: ") |
166 |
| - .append(Set.of(indexName)) |
167 |
| - .append(". ") |
168 |
| - .append("Ensure that no index mappings are using this inference endpoint, ") |
169 |
| - .append("or use force to ignore this warning and delete the inference endpoint."); |
170 | 171 | var e = expectThrows(ResponseException.class, () -> deleteModel(endpointId));
|
171 |
| - assertThat(e.getMessage(), containsString(errorString.toString())); |
| 172 | + assertThat(e.getMessage(), containsString(buildErrorString.apply(endpointId))); |
172 | 173 | }
|
173 | 174 | {
|
174 | 175 | var response = deleteModel(endpointId, "dry_run=true");
|
175 | 176 | var entityString = EntityUtils.toString(response.getEntity());
|
176 | 177 | assertThat(entityString, containsString("\"acknowledged\":false"));
|
177 | 178 | assertThat(entityString, containsString(indexName));
|
| 179 | + assertThat(entityString, containsString(endpointId)); |
178 | 180 | }
|
179 | 181 | {
|
180 | 182 | var response = deleteModel(endpointId, "force=true");
|
181 | 183 | var entityString = EntityUtils.toString(response.getEntity());
|
182 | 184 | assertThat(entityString, containsString("\"acknowledged\":true"));
|
183 | 185 | }
|
184 | 186 | deleteIndex(indexName);
|
| 187 | + |
| 188 | + putModel(searchEndpointId, mockSparseServiceModelConfig(), TaskType.SPARSE_EMBEDDING); |
| 189 | + putSemanticText(endpointId, searchEndpointId, indexName); |
| 190 | + { |
| 191 | + var e = expectThrows(ResponseException.class, () -> deleteModel(searchEndpointId)); |
| 192 | + assertThat(e.getMessage(), containsString(buildErrorString.apply(searchEndpointId))); |
| 193 | + } |
| 194 | + { |
| 195 | + var response = deleteModel(searchEndpointId, "dry_run=true"); |
| 196 | + var entityString = EntityUtils.toString(response.getEntity()); |
| 197 | + assertThat(entityString, containsString("\"acknowledged\":false")); |
| 198 | + assertThat(entityString, containsString(indexName)); |
| 199 | + assertThat(entityString, containsString(searchEndpointId)); |
| 200 | + } |
| 201 | + { |
| 202 | + var response = deleteModel(searchEndpointId, "force=true"); |
| 203 | + var entityString = EntityUtils.toString(response.getEntity()); |
| 204 | + assertThat(entityString, containsString("\"acknowledged\":true")); |
| 205 | + } |
| 206 | + deleteIndex(indexName); |
185 | 207 | }
|
186 | 208 |
|
187 | 209 | public void testDeleteEndpointWhileReferencedBySemanticTextAndPipeline() throws IOException {
|
@@ -217,6 +239,7 @@ public void testDeleteEndpointWhileReferencedBySemanticTextAndPipeline() throws
|
217 | 239 | assertThat(entityString, containsString("\"acknowledged\":false"));
|
218 | 240 | assertThat(entityString, containsString(indexName));
|
219 | 241 | assertThat(entityString, containsString(pipelineId));
|
| 242 | + assertThat(entityString, containsString(endpointId)); |
220 | 243 | }
|
221 | 244 | {
|
222 | 245 | var response = deleteModel(endpointId, "force=true");
|
|
0 commit comments