Skip to content

Commit bf552b5

Browse files
committed
cleanup
Signed-off-by: Jackie Han <hnyng@amazon.com>
1 parent b131f9a commit bf552b5

File tree

2 files changed

+58
-48
lines changed

2 files changed

+58
-48
lines changed

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

+27-18
Original file line numberDiff line numberDiff line change
@@ -122,19 +122,23 @@ private AnomalyDetector createIndexAndGetAnomalyDetector(String indexName, List<
122122
}
123123

124124
private AnomalyDetector createIndexAndGetAnomalyDetector(String indexName, List<Feature> features, boolean useDateNanos)
125-
throws IOException {
125+
throws IOException {
126126
return createIndexAndGetAnomalyDetector(indexName, features, useDateNanos, false);
127127
}
128128

129-
private AnomalyDetector createIndexAndGetAnomalyDetector(String indexName, List<Feature> features, boolean useDateNanos,
130-
boolean useFlattenResultIndex) throws IOException {
129+
private AnomalyDetector createIndexAndGetAnomalyDetector(
130+
String indexName,
131+
List<Feature> features,
132+
boolean useDateNanos,
133+
boolean useFlattenResultIndex
134+
) throws IOException {
131135
TestHelpers.createIndexWithTimeField(client(), indexName, TIME_FIELD, useDateNanos);
132136
String testIndexData = "{\"keyword-field\": \"field-1\", \"ip-field\": \"1.2.3.4\", \"timestamp\": 1}";
133137
TestHelpers.ingestDataToIndex(client(), indexName, TestHelpers.toHttpEntity(testIndexData));
134138

135139
AnomalyDetector detector = useFlattenResultIndex
136-
? TestHelpers.randomAnomalyDetectorWithFlattenResultIndex(TIME_FIELD, indexName, features)
137-
: TestHelpers.randomAnomalyDetector(TIME_FIELD, indexName, features);
140+
? TestHelpers.randomAnomalyDetectorWithFlattenResultIndex(TIME_FIELD, indexName, features)
141+
: TestHelpers.randomAnomalyDetector(TIME_FIELD, indexName, features);
138142

139143
return detector;
140144
}
@@ -190,29 +194,33 @@ public void testCreateAnomalyDetectorWithDuplicateName() throws Exception {
190194
}
191195

192196
public void testCreateAnomalyDetectorWithFlattenedResultIndex() throws Exception {
193-
AnomalyDetector detector = createIndexAndGetAnomalyDetector(INDEX_NAME,
194-
ImmutableList.of(TestHelpers.randomFeature(true)), false, true);
197+
AnomalyDetector detector = createIndexAndGetAnomalyDetector(
198+
INDEX_NAME,
199+
ImmutableList.of(TestHelpers.randomFeature(true)),
200+
false,
201+
true
202+
);
195203

196204
// test behavior when AD is disabled
197205
updateClusterSettings(ADEnabledSetting.AD_ENABLED, false);
198206
Exception ex = expectThrows(
199-
ResponseException.class,
200-
() -> TestHelpers
201-
.makeRequest(
202-
client(),
203-
"POST",
204-
TestHelpers.AD_BASE_DETECTORS_URI,
205-
ImmutableMap.of(),
206-
TestHelpers.toHttpEntity(detector),
207-
null
208-
)
207+
ResponseException.class,
208+
() -> TestHelpers
209+
.makeRequest(
210+
client(),
211+
"POST",
212+
TestHelpers.AD_BASE_DETECTORS_URI,
213+
ImmutableMap.of(),
214+
TestHelpers.toHttpEntity(detector),
215+
null
216+
)
209217
);
210218
assertThat(ex.getMessage(), containsString(ADCommonMessages.DISABLED_ERR_MSG));
211219

212220
// test behavior when AD is enabled
213221
updateClusterSettings(ADEnabledSetting.AD_ENABLED, true);
214222
Response response = TestHelpers
215-
.makeRequest(client(), "POST", TestHelpers.AD_BASE_DETECTORS_URI, ImmutableMap.of(), TestHelpers.toHttpEntity(detector), null);
223+
.makeRequest(client(), "POST", TestHelpers.AD_BASE_DETECTORS_URI, ImmutableMap.of(), TestHelpers.toHttpEntity(detector), null);
216224
assertEquals("Create anomaly detector with flattened result index failed", RestStatus.CREATED, TestHelpers.restStatus(response));
217225
Map<String, Object> responseMap = entityAsMap(response);
218226
String id = (String) responseMap.get("_id");
@@ -221,6 +229,7 @@ public void testCreateAnomalyDetectorWithFlattenedResultIndex() throws Exception
221229
assertTrue("incorrect version", version > 0);
222230
// ensure the flattened result index was created
223231
String expectedFlattenedIndex = String.format(
232+
Locale.ROOT,
224233
"opensearch-ad-plugin-result-test_flattened_%s",
225234
id.toLowerCase(Locale.ROOT)
226235
);

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

+31-30
Original file line numberDiff line numberDiff line change
@@ -511,37 +511,38 @@ public static AnomalyDetector randomAnomalyDetector(String timefield, String ind
511511
);
512512
}
513513

514-
public static AnomalyDetector randomAnomalyDetectorWithFlattenResultIndex(String timefield, String indexName, List<Feature> features) throws IOException {
514+
public static AnomalyDetector randomAnomalyDetectorWithFlattenResultIndex(String timefield, String indexName, List<Feature> features)
515+
throws IOException {
515516
return new AnomalyDetector(
516-
randomAlphaOfLength(10),
517-
randomLong(),
518-
randomAlphaOfLength(20),
519-
randomAlphaOfLength(30),
520-
timefield,
521-
ImmutableList.of(indexName.toLowerCase(Locale.ROOT)),
522-
features,
523-
randomQuery(),
524-
randomIntervalTimeConfiguration(),
525-
randomIntervalTimeConfiguration(),
526-
randomIntBetween(1, TimeSeriesSettings.MAX_SHINGLE_SIZE),
527-
null,
528-
randomInt(),
529-
Instant.now(),
530-
null,
531-
randomUser(),
532-
ADCommonName.CUSTOM_RESULT_INDEX_PREFIX + "test",
533-
TestHelpers.randomImputationOption(features),
534-
// timeDecay (reverse of recencyEmphasis) should be less than 1.
535-
// so we start with 2.
536-
randomIntBetween(2, 10000),
537-
randomInt(TimeSeriesSettings.MAX_SHINGLE_SIZE / 2),
538-
randomIntBetween(1, 1000),
539-
null,
540-
null,
541-
null,
542-
null,
543-
true,
544-
Instant.now()
517+
randomAlphaOfLength(10),
518+
randomLong(),
519+
randomAlphaOfLength(20),
520+
randomAlphaOfLength(30),
521+
timefield,
522+
ImmutableList.of(indexName.toLowerCase(Locale.ROOT)),
523+
features,
524+
randomQuery(),
525+
randomIntervalTimeConfiguration(),
526+
randomIntervalTimeConfiguration(),
527+
randomIntBetween(1, TimeSeriesSettings.MAX_SHINGLE_SIZE),
528+
null,
529+
randomInt(),
530+
Instant.now(),
531+
null,
532+
randomUser(),
533+
ADCommonName.CUSTOM_RESULT_INDEX_PREFIX + "test",
534+
TestHelpers.randomImputationOption(features),
535+
// timeDecay (reverse of recencyEmphasis) should be less than 1.
536+
// so we start with 2.
537+
randomIntBetween(2, 10000),
538+
randomInt(TimeSeriesSettings.MAX_SHINGLE_SIZE / 2),
539+
randomIntBetween(1, 1000),
540+
null,
541+
null,
542+
null,
543+
null,
544+
true,
545+
Instant.now()
545546
);
546547
}
547548

0 commit comments

Comments
 (0)