@@ -122,19 +122,23 @@ private AnomalyDetector createIndexAndGetAnomalyDetector(String indexName, List<
122
122
}
123
123
124
124
private AnomalyDetector createIndexAndGetAnomalyDetector (String indexName , List <Feature > features , boolean useDateNanos )
125
- throws IOException {
125
+ throws IOException {
126
126
return createIndexAndGetAnomalyDetector (indexName , features , useDateNanos , false );
127
127
}
128
128
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 {
131
135
TestHelpers .createIndexWithTimeField (client (), indexName , TIME_FIELD , useDateNanos );
132
136
String testIndexData = "{\" keyword-field\" : \" field-1\" , \" ip-field\" : \" 1.2.3.4\" , \" timestamp\" : 1}" ;
133
137
TestHelpers .ingestDataToIndex (client (), indexName , TestHelpers .toHttpEntity (testIndexData ));
134
138
135
139
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 );
138
142
139
143
return detector ;
140
144
}
@@ -190,29 +194,33 @@ public void testCreateAnomalyDetectorWithDuplicateName() throws Exception {
190
194
}
191
195
192
196
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
+ );
195
203
196
204
// test behavior when AD is disabled
197
205
updateClusterSettings (ADEnabledSetting .AD_ENABLED , false );
198
206
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
+ )
209
217
);
210
218
assertThat (ex .getMessage (), containsString (ADCommonMessages .DISABLED_ERR_MSG ));
211
219
212
220
// test behavior when AD is enabled
213
221
updateClusterSettings (ADEnabledSetting .AD_ENABLED , true );
214
222
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 );
216
224
assertEquals ("Create anomaly detector with flattened result index failed" , RestStatus .CREATED , TestHelpers .restStatus (response ));
217
225
Map <String , Object > responseMap = entityAsMap (response );
218
226
String id = (String ) responseMap .get ("_id" );
@@ -221,6 +229,7 @@ public void testCreateAnomalyDetectorWithFlattenedResultIndex() throws Exception
221
229
assertTrue ("incorrect version" , version > 0 );
222
230
// ensure the flattened result index was created
223
231
String expectedFlattenedIndex = String .format (
232
+ Locale .ROOT ,
224
233
"opensearch-ad-plugin-result-test_flattened_%s" ,
225
234
id .toLowerCase (Locale .ROOT )
226
235
);
0 commit comments