Ensure to release async search iterator in tests

We need to close an async search response iterator to release
the related point in time if the test uses pit.
This commit is contained in:
Nhat Nguyen 2020-09-12 12:00:17 -04:00
parent 5ea5cc5b54
commit 7779c1f703
1 changed files with 25 additions and 22 deletions

View File

@ -196,23 +196,25 @@ public class AsyncSearchActionIT extends AsyncSearchIntegTestCase {
public void testDeleteCancelRunningTask() throws Exception {
final AsyncSearchResponse initial;
SearchResponseIterator it =
assertBlockingIterator(indexName, numShards, new SearchSourceBuilder(), randomBoolean() ? 1 : 0, 2);
initial = it.next();
deleteAsyncSearch(initial.getId());
it.close();
ensureTaskCompletion(initial.getId());
ensureTaskRemoval(initial.getId());
try (SearchResponseIterator it =
assertBlockingIterator(indexName, numShards, new SearchSourceBuilder(), randomBoolean() ? 1 : 0, 2)) {
initial = it.next();
deleteAsyncSearch(initial.getId());
it.close();
ensureTaskCompletion(initial.getId());
ensureTaskRemoval(initial.getId());
}
}
public void testDeleteCleanupIndex() throws Exception {
SearchResponseIterator it =
assertBlockingIterator(indexName, numShards, new SearchSourceBuilder(), randomBoolean() ? 1 : 0, 2);
AsyncSearchResponse response = it.next();
deleteAsyncSearch(response.getId());
it.close();
ensureTaskCompletion(response.getId());
ensureTaskRemoval(response.getId());
try (SearchResponseIterator it =
assertBlockingIterator(indexName, numShards, new SearchSourceBuilder(), randomBoolean() ? 1 : 0, 2)) {
AsyncSearchResponse response = it.next();
deleteAsyncSearch(response.getId());
it.close();
ensureTaskCompletion(response.getId());
ensureTaskRemoval(response.getId());
}
}
public void testCleanupOnFailure() throws Exception {
@ -233,15 +235,16 @@ public class AsyncSearchActionIT extends AsyncSearchIntegTestCase {
}
public void testInvalidId() throws Exception {
SearchResponseIterator it =
assertBlockingIterator(indexName, numShards, new SearchSourceBuilder(), randomBoolean() ? 1 : 0, 2);
AsyncSearchResponse response = it.next();
ExecutionException exc = expectThrows(ExecutionException.class, () -> getAsyncSearch("invalid"));
assertThat(exc.getMessage(), containsString("invalid id"));
while (it.hasNext()) {
response = it.next();
try (SearchResponseIterator it =
assertBlockingIterator(indexName, numShards, new SearchSourceBuilder(), randomBoolean() ? 1 : 0, 2)) {
AsyncSearchResponse response = it.next();
ExecutionException exc = expectThrows(ExecutionException.class, () -> getAsyncSearch("invalid"));
assertThat(exc.getMessage(), containsString("invalid id"));
while (it.hasNext()) {
response = it.next();
}
assertFalse(response.isRunning());
}
assertFalse(response.isRunning());
}
public void testNoIndex() throws Exception {