Skip to content

Commit fb715c3

Browse files
committed
update IT
Signed-off-by: Jackie Han <hnyng@amazon.com>
1 parent 3ce0734 commit fb715c3

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/test/java/org/opensearch/ad/rest/AnomalyDetectorRestApiIT.java

+16-3
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ public void testCreateAnomalyDetectorWithDuplicateName() throws Exception {
196196
public void testCreateAnomalyDetectorWithFlattenedResultIndex() throws Exception {
197197
AnomalyDetector detector = createIndexAndGetAnomalyDetector(
198198
INDEX_NAME,
199-
ImmutableList.of(TestHelpers.randomFeature(true)),
199+
ImmutableList.of(TestHelpers.randomFeature("feature_bytes", "agg", true)),
200200
false,
201201
true
202202
);
@@ -230,8 +230,21 @@ public void testCreateAnomalyDetectorWithFlattenedResultIndex() throws Exception
230230
// ensure the flattened result index was created
231231
String expectedFlattenedIndex = String
232232
.format(Locale.ROOT, "opensearch-ad-plugin-result-test_flattened_%s", id.toLowerCase(Locale.ROOT));
233-
boolean indexExists = indexExists(expectedFlattenedIndex);
234-
assertTrue(indexExists);
233+
boolean aliasExists = aliasExists(expectedFlattenedIndex);
234+
assertTrue(aliasExists);
235+
// ensure that the flattened field "feature_data_feature_bytes" exists in the mappings
236+
String startDetectorEndpoint = String.format(Locale.ROOT, TestHelpers.AD_BASE_START_DETECTOR_URL, id);
237+
Response startDetectorResponse = TestHelpers
238+
.makeRequest(client(), "POST", startDetectorEndpoint, ImmutableMap.of(), TestHelpers.toHttpEntity(detector), null);
239+
String getFlattenedResultIndexEndpoint = String
240+
.format(Locale.ROOT, "/opensearch-ad-plugin-result-test_flattened_%s", id.toLowerCase(Locale.ROOT));
241+
Response getIndexResponse = TestHelpers.makeRequest(client(), "GET", getFlattenedResultIndexEndpoint, ImmutableMap.of(), "", null);
242+
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+
235248
}
236249

237250
public void testCreateAnomalyDetector() throws Exception {

src/test/java/org/opensearch/timeseries/TestHelpers.java

+1
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ public class TestHelpers {
171171
public static final String AD_BASE_RESULT_URI = AD_BASE_DETECTORS_URI + "/results";
172172
public static final String AD_BASE_PREVIEW_URI = AD_BASE_DETECTORS_URI + "/%s/_preview";
173173
public static final String AD_BASE_STATS_URI = "/_plugins/_anomaly_detection/stats";
174+
public static final String AD_BASE_START_DETECTOR_URL = AD_BASE_DETECTORS_URI + "/%s/_start";
174175
public static ImmutableSet<String> HISTORICAL_ANALYSIS_RUNNING_STATS = ImmutableSet
175176
.of(TaskState.CREATED.name(), TaskState.INIT.name(), TaskState.RUNNING.name());
176177
// Task may fail if memory circuit breaker triggered.

0 commit comments

Comments
 (0)