Skip to content

Commit

Permalink
add more 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 f079baf commit ac8f122
Showing 1 changed file with 75 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public void testCreateAnomalyDetectorWithDuplicateName() throws Exception {
);
}

public void testCreateAnomalyDetectorWithFlattenedResultIndex() throws Exception {
public void testCreateAnomalyDetector_withFlattenedResultIndex() throws Exception {
AnomalyDetector detector = createIndexAndGetAnomalyDetector(
INDEX_NAME,
ImmutableList.of(TestHelpers.randomFeature("feature_bytes", "agg", true)),
Expand Down Expand Up @@ -258,6 +258,80 @@ public void testCreateAnomalyDetectorWithFlattenedResultIndex() throws Exception
assertTrue("Flattened field 'feature_data_feature_bytes' does not exist", properties.containsKey("feature_data_feature_bytes"));
}

public void testUpdateAnomalyDetector_disableFlattenResultIndex_shouldDeletePipeline() throws Exception {
AnomalyDetector detector = createIndexAndGetAnomalyDetector(
INDEX_NAME,
ImmutableList.of(TestHelpers.randomFeature("feature_bytes", "agg", true)),
false,
true
);

// test behavior when AD is enabled
updateClusterSettings(ADEnabledSetting.AD_ENABLED, true);
Response response = TestHelpers
.makeRequest(client(), "POST", TestHelpers.AD_BASE_DETECTORS_URI, ImmutableMap.of(), TestHelpers.toHttpEntity(detector), null);
assertEquals("Create anomaly detector with flattened result index failed", RestStatus.CREATED, TestHelpers.restStatus(response));
Map<String, Object> responseMap = entityAsMap(response);
String id = (String) responseMap.get("_id");
String expectedFlattenedIndex = String
.format(Locale.ROOT, "opensearch-ad-plugin-result-test_flattened_%s", id.toLowerCase(Locale.ROOT));
String expectedPipelineId = String.format(Locale.ROOT, "flatten_result_index_ingest_pipeline%s", id.toLowerCase(Locale.ROOT));
String getIngestPipelineEndpoint = String.format(Locale.ROOT, "_ingest/pipeline/%s", expectedPipelineId);
Response getPipelineResponse = TestHelpers.makeRequest(client(), "GET", getIngestPipelineEndpoint, ImmutableMap.of(), "", null);
assertEquals(
"Expected 200 response but got: " + getPipelineResponse.getStatusLine().getStatusCode(),
200,
getPipelineResponse.getStatusLine().getStatusCode()
);
List<Feature> features = detector.getFeatureAttributes();
AnomalyDetector newDetector = new AnomalyDetector(
id,
detector.getVersion(),
detector.getName(),
detector.getDescription(),
detector.getTimeField(),
detector.getIndices(),
features,
detector.getFilterQuery(),
detector.getInterval(),
detector.getWindowDelay(),
detector.getShingleSize(),
detector.getUiMetadata(),
detector.getSchemaVersion(),
detector.getLastUpdateTime(),
null,
detector.getUser(),
detector.getCustomResultIndexOrAlias(),
TestHelpers.randomImputationOption(features),
randomIntBetween(1, 10000),
randomInt(TimeSeriesSettings.MAX_SHINGLE_SIZE / 2),
randomIntBetween(1, 1000),
null,
null,
null,
null,
false,
detector.getLastBreakingUIChangeTime()
);
Response updateResponse = TestHelpers
.makeRequest(
client(),
"PUT",
TestHelpers.AD_BASE_DETECTORS_URI + "/" + id + "?refresh=true",
ImmutableMap.of(),
TestHelpers.toHttpEntity(newDetector),
null
);
assertEquals("Update anomaly detector failed", RestStatus.OK, TestHelpers.restStatus(updateResponse));
Response getPipelineResponseAfterUpdatingDetector = TestHelpers
.makeRequest(client(), "GET", expectedPipelineId, ImmutableMap.of(), "", null);
assertEquals(
"Expected 404 response but got: " + getPipelineResponseAfterUpdatingDetector.getStatusLine().getStatusCode(),
404,
getPipelineResponseAfterUpdatingDetector.getStatusLine().getStatusCode()
);
}

public void testCreateAnomalyDetector() throws Exception {
AnomalyDetector detector = createIndexAndGetAnomalyDetector(INDEX_NAME);
updateClusterSettings(ADEnabledSetting.AD_ENABLED, false);
Expand Down

0 comments on commit ac8f122

Please sign in to comment.