@@ -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,40 +194,41 @@ 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" );
219227 int version = (int ) responseMap .get ("_version" );
220228 assertNotEquals ("response is missing Id" , AnomalyDetector .NO_ID , id );
221229 assertTrue ("incorrect version" , version > 0 );
222230 // ensure the flattened result index was created
223- String expectedFlattenedIndex = String .format (
224- "opensearch-ad-plugin-result-test_flattened_%s" ,
225- id .toLowerCase (Locale .ROOT )
226- );
231+ String expectedFlattenedIndex = String .format ("opensearch-ad-plugin-result-test_flattened_%s" , id .toLowerCase (Locale .ROOT ));
227232 boolean indexExists = indexExists (expectedFlattenedIndex );
228233 assertTrue (indexExists );
229234 }
0 commit comments