Skip to content

Commit

Permalink
update IT
Browse files Browse the repository at this point in the history
Signed-off-by: Jackie Han <[email protected]>
  • Loading branch information
jackiehanyang committed Jan 27, 2025
1 parent 3ce0734 commit fb715c3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/test/java/org/opensearch/ad/rest/AnomalyDetectorRestApiIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public void testCreateAnomalyDetectorWithDuplicateName() throws Exception {
public void testCreateAnomalyDetectorWithFlattenedResultIndex() throws Exception {
AnomalyDetector detector = createIndexAndGetAnomalyDetector(
INDEX_NAME,
ImmutableList.of(TestHelpers.randomFeature(true)),
ImmutableList.of(TestHelpers.randomFeature("feature_bytes", "agg", true)),
false,
true
);
Expand Down Expand Up @@ -230,8 +230,21 @@ public void testCreateAnomalyDetectorWithFlattenedResultIndex() throws Exception
// ensure the flattened result index was created
String expectedFlattenedIndex = String
.format(Locale.ROOT, "opensearch-ad-plugin-result-test_flattened_%s", id.toLowerCase(Locale.ROOT));
boolean indexExists = indexExists(expectedFlattenedIndex);
assertTrue(indexExists);
boolean aliasExists = aliasExists(expectedFlattenedIndex);
assertTrue(aliasExists);
// ensure that the flattened field "feature_data_feature_bytes" exists in the mappings
String startDetectorEndpoint = String.format(Locale.ROOT, TestHelpers.AD_BASE_START_DETECTOR_URL, id);
Response startDetectorResponse = TestHelpers
.makeRequest(client(), "POST", startDetectorEndpoint, ImmutableMap.of(), TestHelpers.toHttpEntity(detector), null);
String getFlattenedResultIndexEndpoint = String
.format(Locale.ROOT, "/opensearch-ad-plugin-result-test_flattened_%s", id.toLowerCase(Locale.ROOT));
Response getIndexResponse = TestHelpers.makeRequest(client(), "GET", getFlattenedResultIndexEndpoint, ImmutableMap.of(), "", null);
Map<String, Object> flattenedResultIndex = entityAsMap(getIndexResponse);
Map<String, Object> mappings = (Map<String, Object>) flattenedResultIndex
.get("opensearch-ad-plugin-result-test_flattened_" + id.toLowerCase(Locale.ROOT));
Map<String, Object> properties = (Map<String, Object>) ((Map<String, Object>) mappings.get("mappings")).get("properties");
assertTrue("Flattened field 'feature_data_feature_bytes' does not exist", properties.containsKey("feature_data_feature_bytes"));

}

public void testCreateAnomalyDetector() throws Exception {
Expand Down
1 change: 1 addition & 0 deletions src/test/java/org/opensearch/timeseries/TestHelpers.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ public class TestHelpers {
public static final String AD_BASE_RESULT_URI = AD_BASE_DETECTORS_URI + "/results";
public static final String AD_BASE_PREVIEW_URI = AD_BASE_DETECTORS_URI + "/%s/_preview";
public static final String AD_BASE_STATS_URI = "/_plugins/_anomaly_detection/stats";
public static final String AD_BASE_START_DETECTOR_URL = AD_BASE_DETECTORS_URI + "/%s/_start";
public static ImmutableSet<String> HISTORICAL_ANALYSIS_RUNNING_STATS = ImmutableSet
.of(TaskState.CREATED.name(), TaskState.INIT.name(), TaskState.RUNNING.name());
// Task may fail if memory circuit breaker triggered.
Expand Down

0 comments on commit fb715c3

Please sign in to comment.