|
38 | 38 | import org.elasticsearch.action.get.GetResponse; |
39 | 39 | import org.elasticsearch.action.index.IndexAction; |
40 | 40 | import org.elasticsearch.action.index.IndexResponse; |
| 41 | +import org.elasticsearch.action.search.SearchAction; |
41 | 42 | import org.elasticsearch.action.search.SearchResponse; |
| 43 | +import org.elasticsearch.action.search.SearchTransportService; |
| 44 | +import org.elasticsearch.action.support.WriteRequest; |
42 | 45 | import org.elasticsearch.action.support.replication.ReplicationResponse; |
43 | 46 | import org.elasticsearch.action.support.replication.TransportReplicationActionTests; |
44 | 47 | import org.elasticsearch.cluster.node.DiscoveryNode; |
45 | 48 | import org.elasticsearch.cluster.service.ClusterService; |
46 | 49 | import org.elasticsearch.common.Strings; |
47 | 50 | import org.elasticsearch.common.collect.Tuple; |
| 51 | +import org.elasticsearch.common.regex.Regex; |
48 | 52 | import org.elasticsearch.common.settings.Settings; |
49 | 53 | import org.elasticsearch.index.query.QueryBuilders; |
50 | 54 | import org.elasticsearch.plugins.Plugin; |
|
82 | 86 | import static org.elasticsearch.common.unit.TimeValue.timeValueSeconds; |
83 | 87 | import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; |
84 | 88 | import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures; |
| 89 | +import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse; |
85 | 90 | import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertThrows; |
86 | 91 | import static org.hamcrest.Matchers.allOf; |
| 92 | +import static org.hamcrest.Matchers.contains; |
| 93 | +import static org.hamcrest.Matchers.containsString; |
87 | 94 | import static org.hamcrest.Matchers.empty; |
88 | 95 | import static org.hamcrest.Matchers.emptyCollectionOf; |
| 96 | +import static org.hamcrest.Matchers.endsWith; |
| 97 | +import static org.hamcrest.Matchers.equalTo; |
| 98 | +import static org.hamcrest.Matchers.greaterThan; |
89 | 99 | import static org.hamcrest.Matchers.greaterThanOrEqualTo; |
90 | 100 | import static org.hamcrest.Matchers.hasSize; |
91 | 101 | import static org.hamcrest.Matchers.lessThanOrEqualTo; |
92 | 102 | import static org.hamcrest.Matchers.not; |
| 103 | +import static org.hamcrest.Matchers.notNullValue; |
| 104 | +import static org.hamcrest.Matchers.startsWith; |
93 | 105 |
|
94 | 106 | /** |
95 | 107 | * Integration tests for task management API |
@@ -329,6 +341,50 @@ public void testTransportBulkTasks() { |
329 | 341 | assertParentTask(findEvents(BulkAction.NAME + "[s][r]", Tuple::v1), shardTask); |
330 | 342 | } |
331 | 343 |
|
| 344 | + |
| 345 | + public void testSearchTaskDescriptions() { |
| 346 | + registerTaskManageListeners(SearchAction.NAME); // main task |
| 347 | + registerTaskManageListeners(SearchAction.NAME + "[*]"); // shard task |
| 348 | + createIndex("test"); |
| 349 | + ensureGreen("test"); // Make sure all shards are allocated to catch replication tasks |
| 350 | + client().prepareIndex("test", "doc", "test_id").setSource("{\"foo\": \"bar\"}") |
| 351 | + .setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get(); |
| 352 | + |
| 353 | + assertSearchResponse(client().prepareSearch("test").setTypes("doc").setQuery(QueryBuilders.matchAllQuery()).get()); |
| 354 | + |
| 355 | + // the search operation should produce one main task |
| 356 | + List<TaskInfo> mainTask = findEvents(SearchAction.NAME, Tuple::v1); |
| 357 | + assertEquals(1, mainTask.size()); |
| 358 | + assertThat(mainTask.get(0).getDescription(), startsWith("indices[test], types[doc], search_type[")); |
| 359 | + assertThat(mainTask.get(0).getDescription(), containsString("\"query\":{\"match_all\"")); |
| 360 | + |
| 361 | + // check that if we have any shard-level requests they all have non-zero length description |
| 362 | + List<TaskInfo> shardTasks = findEvents(SearchAction.NAME + "[*]", Tuple::v1); |
| 363 | + for (TaskInfo taskInfo : shardTasks) { |
| 364 | + assertThat(taskInfo.getParentTaskId(), notNullValue()); |
| 365 | + assertEquals(mainTask.get(0).getTaskId(), taskInfo.getParentTaskId()); |
| 366 | + switch (taskInfo.getAction()) { |
| 367 | + case SearchTransportService.QUERY_ACTION_NAME: |
| 368 | + case SearchTransportService.QUERY_FETCH_ACTION_NAME: |
| 369 | + case SearchTransportService.DFS_ACTION_NAME: |
| 370 | + assertTrue(taskInfo.getDescription(), Regex.simpleMatch("shardId[[test][*]]", taskInfo.getDescription())); |
| 371 | + break; |
| 372 | + case SearchTransportService.QUERY_ID_ACTION_NAME: |
| 373 | + assertTrue(taskInfo.getDescription(), Regex.simpleMatch("id[*], indices[test]", taskInfo.getDescription())); |
| 374 | + break; |
| 375 | + case SearchTransportService.FETCH_ID_ACTION_NAME: |
| 376 | + assertTrue(taskInfo.getDescription(), Regex.simpleMatch("id[*], size[1], lastEmittedDoc[null]", |
| 377 | + taskInfo.getDescription())); |
| 378 | + break; |
| 379 | + default: |
| 380 | + fail("Unexpected action [" + taskInfo.getAction() + "] with description [" + taskInfo.getDescription() + "]"); |
| 381 | + } |
| 382 | + // assert that all task descriptions have non-zero length |
| 383 | + assertThat(taskInfo.getDescription().length(), greaterThan(0)); |
| 384 | + } |
| 385 | + |
| 386 | + } |
| 387 | + |
332 | 388 | /** |
333 | 389 | * Very basic "is it plugged in" style test that indexes a document and makes sure that you can fetch the status of the process. The |
334 | 390 | * goal here is to verify that the large moving parts that make fetching task status work fit together rather than to verify any |
|
0 commit comments