Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
Signed-off-by: Jackie Han <[email protected]>
  • Loading branch information
jackiehanyang committed Jun 1, 2024
1 parent 21c595d commit e315f0f
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 38 deletions.
30 changes: 30 additions & 0 deletions src/test/java/org/opensearch/ad/model/AnomalyDetectorTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -871,4 +871,34 @@ public void testParseAnomalyDetector_withCustomIndex_withNullCustomResultIndexMi
AnomalyDetector parsedDetector = AnomalyDetector.parse(TestHelpers.parser(detectorString), "id", 1L, null, null);
assertEquals(null, parsedDetector.getCustomResultIndexMinSize());
}

public void testParseAnomalyDetector_withCustomIndex_withCustomResultIndexMinAge() throws IOException {
String detectorString = "{\"name\":\"AhtYYGWTgqkzairTchcs\",\"description\":\"iIiAVPMyFgnFlEniLbMyfJxyoGvJAl\","
+ "\"time_field\":\"HmdFH\",\"indices\":[\"ffsBF\"],\"filter_query\":{\"bool\":{\"filter\":[{\"exists\":"
+ "{\"field\":\"value\",\"boost\":1}}],\"adjust_pure_negative\":true,\"boost\":1}},\"window_delay\":"
+ "{\"period\":{\"interval\":2,\"unit\":\"Minutes\"}},\"shingle_size\":8,\"schema_version\":-512063255,"
+ "\"feature_attributes\":[{\"feature_id\":\"OTYJs\",\"feature_name\":\"eYYCM\",\"feature_enabled\":false,"
+ "\"aggregation_query\":{\"XzewX\":{\"value_count\":{\"field\":\"ok\"}}}}],\"recency_emphasis\":3342,"
+ "\"history\":62,\"last_update_time\":1717192049845,\"category_field\":[\"Tcqcb\"],\"result_index\":"
+ "\"opensearch-ad-plugin-result-test\",\"imputation_option\":{\"method\":\"FIXED_VALUES\",\"defaultFill\""
+ ":[],\"integerSensitive\":false},\"suggested_seasonality\":64,\"detection_interval\":{\"period\":"
+ "{\"interval\":5,\"unit\":\"Minutes\"}},\"detector_type\":\"MULTI_ENTITY\",\"rules\":[],\"result_index_min_age\":7}";
AnomalyDetector parsedDetector = AnomalyDetector.parse(TestHelpers.parser(detectorString), "id", 1L, null, null);
assertEquals(7, (int) parsedDetector.getCustomResultIndexMinAge());
}

public void testParseAnomalyDetector_withCustomIndex_withCustomResultIndexTTL() throws IOException {
String detectorString = "{\"name\":\"AhtYYGWTgqkzairTchcs\",\"description\":\"iIiAVPMyFgnFlEniLbMyfJxyoGvJAl\","
+ "\"time_field\":\"HmdFH\",\"indices\":[\"ffsBF\"],\"filter_query\":{\"bool\":{\"filter\":[{\"exists\":"
+ "{\"field\":\"value\",\"boost\":1}}],\"adjust_pure_negative\":true,\"boost\":1}},\"window_delay\":"
+ "{\"period\":{\"interval\":2,\"unit\":\"Minutes\"}},\"shingle_size\":8,\"schema_version\":-512063255,"
+ "\"feature_attributes\":[{\"feature_id\":\"OTYJs\",\"feature_name\":\"eYYCM\",\"feature_enabled\":false,"
+ "\"aggregation_query\":{\"XzewX\":{\"value_count\":{\"field\":\"ok\"}}}}],\"recency_emphasis\":3342,"
+ "\"history\":62,\"last_update_time\":1717192049845,\"category_field\":[\"Tcqcb\"],\"result_index\":"
+ "\"opensearch-ad-plugin-result-test\",\"imputation_option\":{\"method\":\"FIXED_VALUES\",\"defaultFill\""
+ ":[],\"integerSensitive\":false},\"suggested_seasonality\":64,\"detection_interval\":{\"period\":"
+ "{\"interval\":5,\"unit\":\"Minutes\"}},\"detector_type\":\"MULTI_ENTITY\",\"rules\":[],\"result_index_ttl\":30}";
AnomalyDetector parsedDetector = AnomalyDetector.parse(TestHelpers.parser(detectorString), "id", 1L, null, null);
assertEquals(30, (int) parsedDetector.getCustomResultIndexTTL());
}
}
49 changes: 14 additions & 35 deletions src/test/java/org/opensearch/forecast/model/ForecasterTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -449,42 +449,21 @@ public void testParseNullCustomResultIndex_nullCustomResultIndexConditions() thr
.xContentBuilderToString(forecaster.toXContent(TestHelpers.builder(), ToXContent.EMPTY_PARAMS));
LOG.info(forecasterString);
Forecaster parsedForecaster = Forecaster.parse(TestHelpers.parser(forecasterString));
assertEquals("Parsing forecaster doesn't work", forecaster, parsedForecaster);
assertEquals(forecaster, parsedForecaster);
}

public void testValidCustomResultIndex_withIndexConditions() {
String resultIndex = ForecastCommonName.CUSTOM_RESULT_INDEX_PREFIX + "test";

var forecaster = new Forecaster(
forecasterId,
version,
name,
description,
timeField,
indices,
features,
filterQuery,
forecastInterval,
windowDelay,
shingleSize,
uiMetadata,
schemaVersion,
lastUpdateTime,
categoryFields,
user,
resultIndex,
horizon,
TestHelpers.randomImputationOption(0),
recencyEmphasis,
seasonality,
randomIntBetween(1, 1000),
20000,
7,
null
);

assertEquals(20000, (int) forecaster.getCustomResultIndexMinSize());
assertEquals(7, (int) forecaster.getCustomResultIndexMinAge());
assertEquals(null, forecaster.getCustomResultIndexTTL());
public void testValidCustomResultIndex_withIndexConditions() throws IOException {
Forecaster forecaster = TestHelpers.ForecasterBuilder
.newInstance()
.setCustomResultIndex(ForecastCommonName.CUSTOM_RESULT_INDEX_PREFIX + "test")
.setCustomResultIndexMinSize(2000)
.setCustomResultIndexMinAge(7)
.setCustomResultIndexTTL(30)
.build();
String forecasterString = TestHelpers
.xContentBuilderToString(forecaster.toXContent(TestHelpers.builder(), ToXContent.EMPTY_PARAMS));
LOG.info(forecasterString);
Forecaster parsedForecaster = Forecaster.parse(TestHelpers.parser(forecasterString));
assertEquals(forecaster, parsedForecaster);
}
}
6 changes: 3 additions & 3 deletions src/test/java/org/opensearch/timeseries/TestHelpers.java
Original file line number Diff line number Diff line change
Expand Up @@ -1867,9 +1867,9 @@ public Forecaster build() {
randomIntBetween(1, 1000),
randomIntBetween(1, 128),
randomIntBetween(1, 1000),
null,
null,
null
customResultIndexMinSize,
customResultIndexMinAge,
customResultIndexTTL
);
}
}
Expand Down

0 comments on commit e315f0f

Please sign in to comment.