@@ -331,76 +331,75 @@ public void testUpdateAnomalyDetector_disableFlattenResultIndex_shouldDeletePipe
331
331
assertEquals ("Expected 404 response but got: " + statusCode , 404 , statusCode );
332
332
}
333
333
334
- public void testUpdateAnomalyDetector_enableFlattenResultIndex_shouldCreatePipeline () throws Exception {
334
+ public void testUpdateAnomalyDetector_enableFlattenResultIndex_badRequest () throws Exception {
335
335
AnomalyDetector detector = createIndexAndGetAnomalyDetector (
336
- INDEX_NAME ,
337
- ImmutableList .of (TestHelpers .randomFeature ("feature_bytes" , "agg" , true )),
338
- false ,
339
- false
336
+ INDEX_NAME ,
337
+ ImmutableList .of (TestHelpers .randomFeature ("feature_bytes" , "agg" , true )),
338
+ false ,
339
+ false
340
340
);
341
341
// test behavior when AD is enabled
342
342
updateClusterSettings (ADEnabledSetting .AD_ENABLED , true );
343
343
// create a detector with flatten result index disabled, shouldn't find related ingest pipeline
344
344
Response response = TestHelpers
345
- .makeRequest (client (), "POST" , TestHelpers .AD_BASE_DETECTORS_URI , ImmutableMap .of (), TestHelpers .toHttpEntity (detector ), null );
345
+ .makeRequest (client (), "POST" , TestHelpers .AD_BASE_DETECTORS_URI , ImmutableMap .of (), TestHelpers .toHttpEntity (detector ), null );
346
346
assertEquals ("Create anomaly detector without flattened result index failed" , RestStatus .CREATED , TestHelpers .restStatus (response ));
347
347
Map <String , Object > responseMap = entityAsMap (response );
348
348
String id = (String ) responseMap .get ("_id" );
349
349
String expectedPipelineId = String .format (Locale .ROOT , "flatten_result_index_ingest_pipeline%s" , id .toLowerCase (Locale .ROOT ));
350
350
String getIngestPipelineEndpoint = String .format (Locale .ROOT , "_ingest/pipeline/%s" , expectedPipelineId );
351
351
ResponseException responseException = expectThrows (
352
- ResponseException .class ,
353
- () -> TestHelpers .makeRequest (client (), "GET" , getIngestPipelineEndpoint , ImmutableMap .of (), "" , null )
352
+ ResponseException .class ,
353
+ () -> TestHelpers .makeRequest (client (), "GET" , getIngestPipelineEndpoint , ImmutableMap .of (), "" , null )
354
354
);
355
355
int statusCode = responseException .getResponse ().getStatusLine ().getStatusCode ();
356
356
assertEquals ("Expected 404 response but got: " + statusCode , 404 , statusCode );
357
357
// update the detector with flatten result index enabled, should be able to find ingest pipeline
358
358
List <Feature > features = detector .getFeatureAttributes ();
359
359
AnomalyDetector newDetector = new AnomalyDetector (
360
- id ,
361
- detector .getVersion (),
362
- detector .getName (),
363
- detector .getDescription (),
364
- detector .getTimeField (),
365
- detector .getIndices (),
366
- features ,
367
- detector .getFilterQuery (),
368
- detector .getInterval (),
369
- detector .getWindowDelay (),
370
- detector .getShingleSize (),
371
- detector .getUiMetadata (),
372
- detector .getSchemaVersion (),
373
- detector .getLastUpdateTime (),
374
- null ,
375
- detector .getUser (),
376
- detector .getCustomResultIndexOrAlias (),
377
- TestHelpers .randomImputationOption (features ),
378
- randomIntBetween (1 , 10000 ),
379
- randomInt (TimeSeriesSettings .MAX_SHINGLE_SIZE / 2 ),
380
- randomIntBetween (1 , 1000 ),
381
- null ,
382
- null ,
383
- null ,
384
- null ,
385
- true ,
386
- detector .getLastBreakingUIChangeTime ()
360
+ id ,
361
+ detector .getVersion (),
362
+ detector .getName (),
363
+ detector .getDescription (),
364
+ detector .getTimeField (),
365
+ detector .getIndices (),
366
+ features ,
367
+ detector .getFilterQuery (),
368
+ detector .getInterval (),
369
+ detector .getWindowDelay (),
370
+ detector .getShingleSize (),
371
+ detector .getUiMetadata (),
372
+ detector .getSchemaVersion (),
373
+ detector .getLastUpdateTime (),
374
+ null ,
375
+ detector .getUser (),
376
+ detector .getCustomResultIndexOrAlias (),
377
+ TestHelpers .randomImputationOption (features ),
378
+ randomIntBetween (1 , 10000 ),
379
+ randomInt (TimeSeriesSettings .MAX_SHINGLE_SIZE / 2 ),
380
+ randomIntBetween (1 , 1000 ),
381
+ null ,
382
+ null ,
383
+ null ,
384
+ null ,
385
+ true ,
386
+ detector .getLastBreakingUIChangeTime ()
387
387
);
388
- Response updateResponse = TestHelpers
388
+
389
+ ResponseException updateException = expectThrows (
390
+ ResponseException .class ,
391
+ () -> TestHelpers
389
392
.makeRequest (
390
- client (),
391
- "PUT" ,
392
- TestHelpers .AD_BASE_DETECTORS_URI + "/" + id + "?refresh=true" ,
393
- ImmutableMap .of (),
394
- TestHelpers .toHttpEntity (newDetector ),
395
- null
396
- );
397
- assertEquals ("Update anomaly detector failed" , RestStatus .OK , TestHelpers .restStatus (updateResponse ));
398
- Response getPipelineResponse = TestHelpers .makeRequest (client (), "GET" , getIngestPipelineEndpoint , ImmutableMap .of (), "" , null );
399
- assertEquals (
400
- "Expected 200 response but got: " + getPipelineResponse .getStatusLine ().getStatusCode (),
401
- 200 ,
402
- getPipelineResponse .getStatusLine ().getStatusCode ()
393
+ client (),
394
+ "PUT" ,
395
+ TestHelpers .AD_BASE_DETECTORS_URI + "/" + id + "?refresh=true" ,
396
+ ImmutableMap .of (),
397
+ TestHelpers .toHttpEntity (newDetector ),
398
+ null
399
+ )
403
400
);
401
+ int updateExceptionStatusCode = updateException .getResponse ().getStatusLine ().getStatusCode ();
402
+ assertEquals ("Expected 400 response but got: " + updateExceptionStatusCode , 400 , updateExceptionStatusCode );
404
403
}
405
404
406
405
public void testCreateAnomalyDetector () throws Exception {
0 commit comments