|
16 | 16 | import org.opensearch.client.Response;
|
17 | 17 | import org.opensearch.client.ResponseException;
|
18 | 18 | import org.opensearch.core.rest.RestStatus;
|
| 19 | +import org.opensearch.ml.utils.TestHelper; |
19 | 20 | import org.opensearch.rest.RestRequest;
|
20 | 21 |
|
21 | 22 | public class RestMLModelTenantAwareIT extends MLCommonsTenantAwareRestTestCase {
|
@@ -277,6 +278,25 @@ public void testModelCRUD() throws Exception {
|
277 | 278 | assertNull(searchResponse.getHits().getHits()[1].getSourceAsMap().get(TENANT_ID_FIELD));
|
278 | 279 | }
|
279 | 280 |
|
| 281 | + // Test search with aggregations to verify no error is thrown |
| 282 | + Response restResponse = makeRequest(tenantAggregationRequest, GET, MODELS_PATH + "_search"); |
| 283 | + assertOK(restResponse); |
| 284 | + // We can't (easily) parse the JSON from this response into a SearchResponse for the same reason as the bug we're testing |
| 285 | + // So we test the string values instead |
| 286 | + String responseJson = TestHelper.httpEntityToString(restResponse.getEntity()); |
| 287 | + assertTrue(responseJson.contains("\"aggregations\":{\"unique_model_names\"")); |
| 288 | + if (multiTenancyEnabled) { |
| 289 | + assertTrue(responseJson.contains("\"value\":1,\"relation\":\"eq\"")); |
| 290 | + assertTrue(responseJson.contains("\"key\":\"remote model for connector_id ")); |
| 291 | + assertTrue(responseJson.contains("\"doc_count\":1")); |
| 292 | + } else { |
| 293 | + assertTrue(responseJson.contains("\"value\":3,\"relation\":\"eq\"")); |
| 294 | + // one connector will have two doc_count, other will have one |
| 295 | + assertTrue(responseJson.contains("\"key\":\"remote model for connector_id ")); |
| 296 | + assertTrue(responseJson.contains("\"doc_count\":2")); |
| 297 | + assertTrue(responseJson.contains("\"doc_count\":1")); |
| 298 | + } |
| 299 | + |
280 | 300 | /*
|
281 | 301 | * Delete
|
282 | 302 | */
|
|
0 commit comments