|
27 | 27 | import java.util.stream.Collectors;
|
28 | 28 |
|
29 | 29 | import org.apache.hc.core5.http.ContentType;
|
| 30 | +import org.apache.hc.core5.http.HttpEntity; |
30 | 31 | import org.apache.hc.core5.http.io.entity.StringEntity;
|
31 | 32 | import org.hamcrest.CoreMatchers;
|
32 | 33 | import org.junit.Assert;
|
@@ -235,16 +236,26 @@ public void testCreateAnomalyDetectorWithFlattenedResultIndex() throws Exception
|
235 | 236 | // ensure that the flattened field "feature_data_feature_bytes" exists in the mappings
|
236 | 237 | String startDetectorEndpoint = String.format(Locale.ROOT, TestHelpers.AD_BASE_START_DETECTOR_URL, id);
|
237 | 238 | Response startDetectorResponse = TestHelpers
|
238 |
| - .makeRequest(client(), "POST", startDetectorEndpoint, ImmutableMap.of(), TestHelpers.toHttpEntity(detector), null); |
| 239 | + .makeRequest(client(), "POST", startDetectorEndpoint, ImmutableMap.of(), (HttpEntity) null, null); |
239 | 240 | String getFlattenedResultIndexEndpoint = String
|
240 | 241 | .format(Locale.ROOT, "/opensearch-ad-plugin-result-test_flattened_%s", id.toLowerCase(Locale.ROOT));
|
| 242 | + // wait for the detector starts writing result |
| 243 | + try { |
| 244 | + Thread.sleep(60 * 1000); |
| 245 | + } catch (InterruptedException e) { |
| 246 | + Thread.currentThread().interrupt(); |
| 247 | + throw new RuntimeException("Thread was interrupted while waiting", e); |
| 248 | + } |
241 | 249 | Response getIndexResponse = TestHelpers.makeRequest(client(), "GET", getFlattenedResultIndexEndpoint, ImmutableMap.of(), "", null);
|
242 | 250 | Map<String, Object> flattenedResultIndex = entityAsMap(getIndexResponse);
|
243 |
| - Map<String, Object> mappings = (Map<String, Object>) flattenedResultIndex |
244 |
| - .get("opensearch-ad-plugin-result-test_flattened_" + id.toLowerCase(Locale.ROOT)); |
245 |
| - Map<String, Object> properties = (Map<String, Object>) ((Map<String, Object>) mappings.get("mappings")).get("properties"); |
246 |
| - assertTrue("Flattened field 'feature_data_feature_bytes' does not exist", properties.containsKey("feature_data_feature_bytes")); |
247 | 251 |
|
| 252 | + String indexKey = flattenedResultIndex.keySet().stream().findFirst().orElse(null); |
| 253 | + Map<String, Object> indexDetails = (Map<String, Object>) flattenedResultIndex.get(indexKey); |
| 254 | + Map<String, Object> mappings = (Map<String, Object>) indexDetails.get("mappings"); |
| 255 | + Object dynamicValue = mappings.get("dynamic"); |
| 256 | + assertEquals("Dynamic field is not set to true", "true", dynamicValue.toString()); |
| 257 | + Map<String, Object> properties = (Map<String, Object>) mappings.get("properties"); |
| 258 | + assertTrue("Flattened field 'feature_data_feature_bytes' does not exist", properties.containsKey("feature_data_feature_bytes")); |
248 | 259 | }
|
249 | 260 |
|
250 | 261 | public void testCreateAnomalyDetector() throws Exception {
|
|
0 commit comments