|
20 | 20 | package org.elasticsearch.search;
|
21 | 21 |
|
22 | 22 | import org.apache.logging.log4j.LogManager;
|
| 23 | +import org.elasticsearch.ExceptionsHelper; |
23 | 24 | import org.elasticsearch.action.ActionFuture;
|
24 | 25 | import org.elasticsearch.action.admin.cluster.node.tasks.cancel.CancelTasksResponse;
|
25 | 26 | import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse;
|
26 | 27 | import org.elasticsearch.action.bulk.BulkRequestBuilder;
|
| 28 | +import org.elasticsearch.action.search.MultiSearchAction; |
| 29 | +import org.elasticsearch.action.search.MultiSearchResponse; |
27 | 30 | import org.elasticsearch.action.search.SearchAction;
|
28 | 31 | import org.elasticsearch.action.search.SearchPhaseExecutionException;
|
29 | 32 | import org.elasticsearch.action.search.SearchResponse;
|
30 | 33 | import org.elasticsearch.action.search.SearchScrollAction;
|
| 34 | +import org.elasticsearch.action.search.ShardSearchFailure; |
31 | 35 | import org.elasticsearch.action.support.WriteRequest;
|
32 | 36 | import org.elasticsearch.common.Strings;
|
33 | 37 | import org.elasticsearch.common.settings.Settings;
|
|
38 | 42 | import org.elasticsearch.script.Script;
|
39 | 43 | import org.elasticsearch.script.ScriptType;
|
40 | 44 | import org.elasticsearch.search.lookup.LeafFieldsLookup;
|
| 45 | +import org.elasticsearch.tasks.TaskCancelledException; |
41 | 46 | import org.elasticsearch.tasks.TaskInfo;
|
42 | 47 | import org.elasticsearch.test.ESIntegTestCase;
|
43 | 48 |
|
|
52 | 57 |
|
53 | 58 | import static org.elasticsearch.index.query.QueryBuilders.scriptQuery;
|
54 | 59 | import static org.elasticsearch.search.SearchCancellationIT.ScriptedBlockPlugin.SCRIPT_NAME;
|
| 60 | +import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertFailures; |
55 | 61 | import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
|
56 | 62 | import static org.hamcrest.Matchers.equalTo;
|
57 | 63 | import static org.hamcrest.Matchers.greaterThan;
|
58 | 64 | import static org.hamcrest.Matchers.hasSize;
|
| 65 | +import static org.hamcrest.Matchers.notNullValue; |
59 | 66 |
|
60 | 67 | @ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.SUITE)
|
61 | 68 | public class SearchCancellationIT extends ESIntegTestCase {
|
@@ -245,6 +252,26 @@ public void testCancellationOfScrollSearchesOnFollowupRequests() throws Exceptio
|
245 | 252 | client().prepareClearScroll().addScrollId(scrollId).get();
|
246 | 253 | }
|
247 | 254 |
|
| 255 | + public void testCancelMultiSearch() throws Exception { |
| 256 | + List<ScriptedBlockPlugin> plugins = initBlockFactory(); |
| 257 | + indexTestData(); |
| 258 | + ActionFuture<MultiSearchResponse> msearchResponse = client().prepareMultiSearch().add(client().prepareSearch("test") |
| 259 | + .addScriptField("test_field", new Script(ScriptType.INLINE, "mockscript", SCRIPT_NAME, Collections.emptyMap()))) |
| 260 | + .execute(); |
| 261 | + awaitForBlock(plugins); |
| 262 | + cancelSearch(MultiSearchAction.NAME); |
| 263 | + disableBlocks(plugins); |
| 264 | + for (MultiSearchResponse.Item item : msearchResponse.actionGet()) { |
| 265 | + if (item.getFailure() != null) { |
| 266 | + assertThat(ExceptionsHelper.unwrap(item.getFailure(), TaskCancelledException.class), notNullValue()); |
| 267 | + } else { |
| 268 | + assertFailures(item.getResponse()); |
| 269 | + for (ShardSearchFailure shardFailure : item.getResponse().getShardFailures()) { |
| 270 | + assertThat(ExceptionsHelper.unwrap(shardFailure.getCause(), TaskCancelledException.class), notNullValue()); |
| 271 | + } |
| 272 | + } |
| 273 | + } |
| 274 | + } |
248 | 275 |
|
249 | 276 | public static class ScriptedBlockPlugin extends MockScriptPlugin {
|
250 | 277 | static final String SCRIPT_NAME = "search_block";
|
|
0 commit comments