21
21
import org .elasticsearch .test .ESIntegTestCase .SuiteScopeTestCase ;
22
22
import org .elasticsearch .xpack .core .XPackPlugin ;
23
23
import org .elasticsearch .xpack .core .search .action .AsyncSearchResponse ;
24
+ import org .elasticsearch .xpack .core .search .action .AsyncStatusResponse ;
24
25
import org .elasticsearch .xpack .core .search .action .SubmitAsyncSearchRequest ;
25
26
26
27
import java .util .ArrayList ;
41
42
import static org .hamcrest .Matchers .lessThan ;
42
43
import static org .hamcrest .Matchers .lessThanOrEqualTo ;
43
44
45
+
44
46
@ SuiteScopeTestCase
45
47
public class AsyncSearchActionIT extends AsyncSearchIntegTestCase {
46
48
private static String indexName ;
@@ -187,10 +189,19 @@ public void testRestartAfterCompletion() throws Exception {
187
189
}
188
190
ensureTaskCompletion (initial .getId ());
189
191
restartTaskNode (initial .getId (), indexName );
192
+
190
193
AsyncSearchResponse response = getAsyncSearch (initial .getId ());
191
194
assertNotNull (response .getSearchResponse ());
192
195
assertFalse (response .isRunning ());
193
196
assertFalse (response .isPartial ());
197
+
198
+ AsyncStatusResponse statusResponse = getAsyncStatus (initial .getId ());
199
+ assertFalse (statusResponse .isRunning ());
200
+ assertFalse (statusResponse .isPartial ());
201
+ assertEquals (numShards , statusResponse .getTotalShards ());
202
+ assertEquals (numShards , statusResponse .getSuccessfulShards ());
203
+ assertEquals (RestStatus .OK , statusResponse .getCompletionStatus ());
204
+
194
205
deleteAsyncSearch (response .getId ());
195
206
ensureTaskRemoval (response .getId ());
196
207
}
@@ -231,6 +242,15 @@ public void testCleanupOnFailure() throws Exception {
231
242
assertTrue (response .isPartial ());
232
243
assertThat (response .getSearchResponse ().getTotalShards (), equalTo (numShards ));
233
244
assertThat (response .getSearchResponse ().getShardFailures ().length , equalTo (numShards ));
245
+
246
+ AsyncStatusResponse statusResponse = getAsyncStatus (initial .getId ());
247
+ assertFalse (statusResponse .isRunning ());
248
+ assertTrue (statusResponse .isPartial ());
249
+ assertEquals (numShards , statusResponse .getTotalShards ());
250
+ assertEquals (0 , statusResponse .getSuccessfulShards ());
251
+ assertEquals (numShards , statusResponse .getFailedShards ());
252
+ assertThat (statusResponse .getCompletionStatus ().getStatus (), greaterThanOrEqualTo (400 ));
253
+
234
254
deleteAsyncSearch (initial .getId ());
235
255
ensureTaskRemoval (initial .getId ());
236
256
}
@@ -246,6 +266,9 @@ public void testInvalidId() throws Exception {
246
266
}
247
267
assertFalse (response .isRunning ());
248
268
}
269
+
270
+ ExecutionException exc = expectThrows (ExecutionException .class , () -> getAsyncStatus ("invalid" ));
271
+ assertThat (exc .getMessage (), containsString ("invalid id" ));
249
272
}
250
273
251
274
public void testNoIndex () throws Exception {
@@ -287,6 +310,13 @@ public void testCancellation() throws Exception {
287
310
assertThat (response .getSearchResponse ().getSuccessfulShards (), equalTo (0 ));
288
311
assertThat (response .getSearchResponse ().getFailedShards (), equalTo (0 ));
289
312
313
+ AsyncStatusResponse statusResponse = getAsyncStatus (response .getId ());
314
+ assertTrue (statusResponse .isRunning ());
315
+ assertEquals (numShards , statusResponse .getTotalShards ());
316
+ assertEquals (0 , statusResponse .getSuccessfulShards ());
317
+ assertEquals (0 , statusResponse .getSkippedShards ());
318
+ assertEquals (0 , statusResponse .getFailedShards ());
319
+
290
320
deleteAsyncSearch (response .getId ());
291
321
ensureTaskRemoval (response .getId ());
292
322
}
@@ -321,6 +351,17 @@ public void testUpdateRunningKeepAlive() throws Exception {
321
351
assertThat (response .getSearchResponse ().getSuccessfulShards (), equalTo (0 ));
322
352
assertThat (response .getSearchResponse ().getFailedShards (), equalTo (0 ));
323
353
354
+ AsyncStatusResponse statusResponse = getAsyncStatus (response .getId ());
355
+ assertTrue (statusResponse .isRunning ());
356
+ assertTrue (statusResponse .isPartial ());
357
+ assertThat (statusResponse .getExpirationTime (), greaterThan (expirationTime ));
358
+ assertThat (statusResponse .getStartTime (), lessThan (statusResponse .getExpirationTime ()));
359
+ assertEquals (numShards , statusResponse .getTotalShards ());
360
+ assertEquals (0 , statusResponse .getSuccessfulShards ());
361
+ assertEquals (0 , statusResponse .getFailedShards ());
362
+ assertEquals (0 , statusResponse .getSkippedShards ());
363
+ assertEquals (null , statusResponse .getCompletionStatus ());
364
+
324
365
response = getAsyncSearch (response .getId (), TimeValue .timeValueMillis (1 ));
325
366
assertThat (response .getExpirationTime (), lessThan (expirationTime ));
326
367
ensureTaskNotRunning (response .getId ());
0 commit comments