@@ -179,6 +179,13 @@ public static void cleanup() {
179
179
}
180
180
181
181
public void testDeleteModel_Success () throws IOException , InterruptedException {
182
+ // For controller
183
+ doAnswer (invocation -> {
184
+ ActionListener <DeleteResponse > listener = invocation .getArgument (1 );
185
+ listener .onResponse (deleteResponse );
186
+ return null ;
187
+ }).when (client ).delete (any (), any ());
188
+ // For model
182
189
PlainActionFuture <DeleteResponse > future = PlainActionFuture .newFuture ();
183
190
future .onResponse (deleteResponse );
184
191
when (client .delete (any ())).thenReturn (future );
@@ -207,6 +214,13 @@ public void testDeleteModel_Success() throws IOException, InterruptedException {
207
214
}
208
215
209
216
public void testDeleteRemoteModel_Success () throws IOException , InterruptedException {
217
+ // For controller
218
+ doAnswer (invocation -> {
219
+ ActionListener <DeleteResponse > listener = invocation .getArgument (1 );
220
+ listener .onResponse (deleteResponse );
221
+ return null ;
222
+ }).when (client ).delete (any (), any ());
223
+ // For model
210
224
PlainActionFuture <DeleteResponse > future = PlainActionFuture .newFuture ();
211
225
future .onResponse (deleteResponse );
212
226
when (client .delete (any ())).thenReturn (future );
@@ -228,11 +242,16 @@ public void testDeleteRemoteModel_Success() throws IOException, InterruptedExcep
228
242
}
229
243
230
244
public void testDeleteRemoteModel_deleteModelController_failed () throws IOException , InterruptedException {
245
+ // For controller
246
+ doAnswer (invocation -> {
247
+ ActionListener <DeleteResponse > listener = invocation .getArgument (1 );
248
+ listener .onFailure (new RuntimeException ("runtime exception" ));
249
+ return null ;
250
+ }).when (client ).delete (any (), any ());
251
+ // For model
231
252
PlainActionFuture <DeleteResponse > future = PlainActionFuture .newFuture ();
232
253
future .onResponse (deleteResponse );
233
- PlainActionFuture <DeleteResponse > failFuture = PlainActionFuture .newFuture ();
234
- failFuture .onFailure (new RuntimeException ("runtime exception" ));
235
- when (client .delete (any ())).thenReturn (future ).thenReturn (failFuture );
254
+ when (client .delete (any ())).thenReturn (future );
236
255
237
256
doAnswer (invocation -> {
238
257
ActionListener <BulkByScrollResponse > listener = invocation .getArgument (2 );
@@ -257,11 +276,16 @@ public void testDeleteRemoteModel_deleteModelController_failed() throws IOExcept
257
276
}
258
277
259
278
public void testDeleteLocalModel_deleteModelController_failed () throws IOException , InterruptedException {
279
+ // For controller
280
+ doAnswer (invocation -> {
281
+ ActionListener <DeleteResponse > listener = invocation .getArgument (1 );
282
+ listener .onFailure (new RuntimeException ("runtime exception" ));
283
+ return null ;
284
+ }).when (client ).delete (any (), any ());
285
+ // For model
260
286
PlainActionFuture <DeleteResponse > future = PlainActionFuture .newFuture ();
261
287
future .onResponse (deleteResponse );
262
- PlainActionFuture <DeleteResponse > failFuture = PlainActionFuture .newFuture ();
263
- failFuture .onFailure (new RuntimeException ("runtime exception" ));
264
- when (client .delete (any ())).thenReturn (future ).thenReturn (failFuture );
288
+ when (client .delete (any ())).thenReturn (future );
265
289
266
290
doAnswer (invocation -> {
267
291
ActionListener <BulkByScrollResponse > listener = invocation .getArgument (2 );
@@ -286,6 +310,13 @@ public void testDeleteLocalModel_deleteModelController_failed() throws IOExcepti
286
310
}
287
311
288
312
public void testDeleteRemoteModel_deleteModelChunks_failed () throws IOException , InterruptedException {
313
+ // For controller
314
+ doAnswer (invocation -> {
315
+ ActionListener <DeleteResponse > listener = invocation .getArgument (1 );
316
+ listener .onResponse (deleteResponse );
317
+ return null ;
318
+ }).when (client ).delete (any (), any ());
319
+ // For model
289
320
PlainActionFuture <DeleteResponse > future = PlainActionFuture .newFuture ();
290
321
future .onResponse (deleteResponse );
291
322
when (client .delete (any ())).thenReturn (future );
@@ -312,6 +343,13 @@ public void testDeleteRemoteModel_deleteModelChunks_failed() throws IOException,
312
343
}
313
344
314
345
public void testDeleteHiddenModel_Success () throws IOException , InterruptedException {
346
+ // For controller
347
+ doAnswer (invocation -> {
348
+ ActionListener <DeleteResponse > listener = invocation .getArgument (1 );
349
+ listener .onResponse (deleteResponse );
350
+ return null ;
351
+ }).when (client ).delete (any (), any ());
352
+ // For model
315
353
PlainActionFuture <DeleteResponse > future = PlainActionFuture .newFuture ();
316
354
future .onResponse (deleteResponse );
317
355
when (client .delete (any ())).thenReturn (future );
@@ -371,6 +409,13 @@ public void testDeleteHiddenModel_NoSuperAdminPermission() throws IOException, I
371
409
}
372
410
373
411
public void testDeleteModel_Success_AlgorithmNotNull () throws IOException , InterruptedException {
412
+ // For controller
413
+ doAnswer (invocation -> {
414
+ ActionListener <DeleteResponse > listener = invocation .getArgument (1 );
415
+ listener .onResponse (deleteResponse );
416
+ return null ;
417
+ }).when (client ).delete (any (), any ());
418
+ // For model
374
419
PlainActionFuture <DeleteResponse > future = PlainActionFuture .newFuture ();
375
420
future .onResponse (deleteResponse );
376
421
when (client .delete (any ())).thenReturn (future );
@@ -455,6 +500,13 @@ public void testDeleteModel_ModelNotFoundException() throws IOException, Interru
455
500
}
456
501
457
502
public void testDeleteModel_deleteModelController_ResourceNotFoundException () throws IOException , InterruptedException {
503
+ // For controller
504
+ doAnswer (invocation -> {
505
+ ActionListener <DeleteResponse > listener = invocation .getArgument (1 );
506
+ listener .onFailure (new ResourceNotFoundException ("errorMessage" ));
507
+ return null ;
508
+ }).when (client ).delete (any (), any ());
509
+ // For model
458
510
PlainActionFuture <DeleteResponse > future = PlainActionFuture .newFuture ();
459
511
future .onResponse (deleteResponse );
460
512
PlainActionFuture <DeleteResponse > failFuture = PlainActionFuture .newFuture ();
@@ -505,6 +557,13 @@ public void test_ValidationFailedException() throws IOException, InterruptedExce
505
557
}
506
558
507
559
public void testDeleteRemoteModel_modelNotFound_ResourceNotFoundException () throws IOException , InterruptedException {
560
+ // For controller
561
+ doAnswer (invocation -> {
562
+ ActionListener <DeleteResponse > listener = invocation .getArgument (1 );
563
+ listener .onResponse (deleteResponse );
564
+ return null ;
565
+ }).when (client ).delete (any (), any ());
566
+ // For model
508
567
PlainActionFuture <DeleteResponse > failFuture = PlainActionFuture .newFuture ();
509
568
failFuture .onFailure (new ResourceNotFoundException ("resource not found" ));
510
569
PlainActionFuture <DeleteResponse > future = PlainActionFuture .newFuture ();
@@ -567,9 +626,11 @@ public void testModelNotFound_modelChunks_modelController_delete_success() throw
567
626
getFuture .onResponse (null );
568
627
when (client .get (any ())).thenReturn (getFuture );
569
628
570
- PlainActionFuture <DeleteResponse > future = PlainActionFuture .newFuture ();
571
- future .onResponse (deleteResponse );
572
- when (client .delete (any ())).thenReturn (future );
629
+ doAnswer (invocation -> {
630
+ ActionListener <DeleteResponse > listener = invocation .getArgument (1 );
631
+ listener .onResponse (deleteResponse );
632
+ return null ;
633
+ }).when (client ).delete (any (), any ());
573
634
574
635
doAnswer (invocation -> {
575
636
ActionListener <BulkByScrollResponse > listener = invocation .getArgument (2 );
0 commit comments