@@ -187,7 +187,7 @@ public void testNoData() {
187187 equalTo ("Cannot run forecast: Forecast cannot be executed as job requires data to have been processed and modeled" ));
188188 }
189189
190- public void testMemoryStatus () throws Exception {
190+ public void testMemoryStatus () {
191191 Detector .Builder detector = new Detector .Builder ("mean" , "value" );
192192 detector .setByFieldName ("clientIP" );
193193
@@ -287,6 +287,74 @@ public void testOverflowToDisk() throws Exception {
287287
288288 }
289289
290+ public void testDeleteWildCard () throws Exception {
291+ Detector .Builder detector = new Detector .Builder ("mean" , "value" );
292+
293+ TimeValue bucketSpan = TimeValue .timeValueHours (1 );
294+ AnalysisConfig .Builder analysisConfig = new AnalysisConfig .Builder (Collections .singletonList (detector .build ()));
295+ analysisConfig .setBucketSpan (bucketSpan );
296+ DataDescription .Builder dataDescription = new DataDescription .Builder ();
297+ dataDescription .setTimeFormat ("epoch" );
298+
299+ Job .Builder job = new Job .Builder ("forecast-it-test-delete-wildcard" );
300+ job .setAnalysisConfig (analysisConfig );
301+ job .setDataDescription (dataDescription );
302+
303+ registerJob (job );
304+ putJob (job );
305+ openJob (job .getId ());
306+
307+ long now = Instant .now ().getEpochSecond ();
308+ long timestamp = now - 50 * bucketSpan .seconds ();
309+ List <String > data = new ArrayList <>();
310+ while (timestamp < now ) {
311+ data .add (createJsonRecord (createRecord (timestamp , 10.0 )));
312+ data .add (createJsonRecord (createRecord (timestamp , 30.0 )));
313+ timestamp += bucketSpan .seconds ();
314+ }
315+
316+ postData (job .getId (), data .stream ().collect (Collectors .joining ()));
317+ flushJob (job .getId (), false );
318+ String forecastIdDefaultDurationDefaultExpiry = forecast (job .getId (), null , null );
319+ String forecastIdDuration1HourNoExpiry = forecast (job .getId (), TimeValue .timeValueHours (1 ), TimeValue .ZERO );
320+ String forecastId2Duration1HourNoExpiry = forecast (job .getId (), TimeValue .timeValueHours (1 ), TimeValue .ZERO );
321+ String forecastId2Duration1HourNoExpiry2 = forecast (job .getId (), TimeValue .timeValueHours (1 ), TimeValue .ZERO );
322+ waitForecastToFinish (job .getId (), forecastIdDefaultDurationDefaultExpiry );
323+ waitForecastToFinish (job .getId (), forecastIdDuration1HourNoExpiry );
324+ waitForecastToFinish (job .getId (), forecastId2Duration1HourNoExpiry );
325+ waitForecastToFinish (job .getId (), forecastId2Duration1HourNoExpiry2 );
326+ closeJob (job .getId ());
327+
328+ assertNotNull (getForecastStats (job .getId (), forecastIdDefaultDurationDefaultExpiry ));
329+ assertNotNull (getForecastStats (job .getId (), forecastIdDuration1HourNoExpiry ));
330+ assertNotNull (getForecastStats (job .getId (), forecastId2Duration1HourNoExpiry ));
331+ assertNotNull (getForecastStats (job .getId (), forecastId2Duration1HourNoExpiry2 ));
332+
333+ {
334+ DeleteForecastAction .Request request = new DeleteForecastAction .Request (job .getId (),
335+ forecastIdDefaultDurationDefaultExpiry .substring (0 , forecastIdDefaultDurationDefaultExpiry .length () - 2 ) + "*"
336+ + ","
337+ + forecastIdDuration1HourNoExpiry );
338+ AcknowledgedResponse response = client ().execute (DeleteForecastAction .INSTANCE , request ).actionGet ();
339+ assertTrue (response .isAcknowledged ());
340+
341+ assertNull (getForecastStats (job .getId (), forecastIdDefaultDurationDefaultExpiry ));
342+ assertNull (getForecastStats (job .getId (), forecastIdDuration1HourNoExpiry ));
343+ assertNotNull (getForecastStats (job .getId (), forecastId2Duration1HourNoExpiry ));
344+ assertNotNull (getForecastStats (job .getId (), forecastId2Duration1HourNoExpiry2 ));
345+ }
346+
347+ {
348+ DeleteForecastAction .Request request = new DeleteForecastAction .Request (job .getId (), "*" );
349+ AcknowledgedResponse response = client ().execute (DeleteForecastAction .INSTANCE , request ).actionGet ();
350+ assertTrue (response .isAcknowledged ());
351+
352+ assertNull (getForecastStats (job .getId (), forecastId2Duration1HourNoExpiry ));
353+ assertNull (getForecastStats (job .getId (), forecastId2Duration1HourNoExpiry2 ));
354+ }
355+
356+ }
357+
290358 public void testDelete () throws Exception {
291359 Detector .Builder detector = new Detector .Builder ("mean" , "value" );
292360
@@ -317,6 +385,8 @@ public void testDelete() throws Exception {
317385 flushJob (job .getId (), false );
318386 String forecastIdDefaultDurationDefaultExpiry = forecast (job .getId (), null , null );
319387 String forecastIdDuration1HourNoExpiry = forecast (job .getId (), TimeValue .timeValueHours (1 ), TimeValue .ZERO );
388+ String forecastId2Duration1HourNoExpiry = forecast (job .getId (), TimeValue .timeValueHours (1 ), TimeValue .ZERO );
389+ String forecastId2Duration1HourNoExpiry2 = forecast (job .getId (), TimeValue .timeValueHours (1 ), TimeValue .ZERO );
320390 waitForecastToFinish (job .getId (), forecastIdDefaultDurationDefaultExpiry );
321391 waitForecastToFinish (job .getId (), forecastIdDuration1HourNoExpiry );
322392 closeJob (job .getId ());
@@ -333,13 +403,11 @@ public void testDelete() throws Exception {
333403 forecastIdDefaultDurationDefaultExpiry + "," + forecastIdDuration1HourNoExpiry );
334404 AcknowledgedResponse response = client ().execute (DeleteForecastAction .INSTANCE , request ).actionGet ();
335405 assertTrue (response .isAcknowledged ());
336- }
337406
338- {
339- ForecastRequestStats forecastStats = getForecastStats (job .getId (), forecastIdDefaultDurationDefaultExpiry );
340- assertNull (forecastStats );
341- ForecastRequestStats otherStats = getForecastStats (job .getId (), forecastIdDuration1HourNoExpiry );
342- assertNull (otherStats );
407+ assertNull (getForecastStats (job .getId (), forecastIdDefaultDurationDefaultExpiry ));
408+ assertNull (getForecastStats (job .getId (), forecastIdDuration1HourNoExpiry ));
409+ assertNotNull (getForecastStats (job .getId (), forecastId2Duration1HourNoExpiry ));
410+ assertNotNull (getForecastStats (job .getId (), forecastId2Duration1HourNoExpiry2 ));
343411 }
344412
345413 {
@@ -354,6 +422,9 @@ public void testDelete() throws Exception {
354422 DeleteForecastAction .Request request = new DeleteForecastAction .Request (job .getId (), Metadata .ALL );
355423 AcknowledgedResponse response = client ().execute (DeleteForecastAction .INSTANCE , request ).actionGet ();
356424 assertTrue (response .isAcknowledged ());
425+
426+ assertNull (getForecastStats (job .getId (), forecastId2Duration1HourNoExpiry ));
427+ assertNull (getForecastStats (job .getId (), forecastId2Duration1HourNoExpiry2 ));
357428 }
358429
359430 {
0 commit comments