|
8 | 8 | package org.elasticsearch.multiterms; |
9 | 9 |
|
10 | 10 | import org.apache.http.client.config.RequestConfig; |
| 11 | +import org.apache.http.util.EntityUtils; |
11 | 12 | import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; |
12 | 13 | import org.elasticsearch.client.Request; |
13 | 14 | import org.elasticsearch.common.Strings; |
|
30 | 31 | import java.net.SocketTimeoutException; |
31 | 32 | import java.util.Locale; |
32 | 33 | import java.util.Map; |
| 34 | +import java.util.concurrent.TimeUnit; |
33 | 35 |
|
34 | 36 | import static org.elasticsearch.test.ListMatcher.matchesList; |
35 | 37 | import static org.elasticsearch.test.MapMatcher.assertMap; |
@@ -287,14 +289,33 @@ private void setTimeout(Request request) { |
287 | 289 | request.setOptions(request.getOptions().toBuilder().setRequestConfig(config.build())); |
288 | 290 | } |
289 | 291 |
|
| 292 | + /** |
| 293 | + * Asserts that within a minute the _search has left the _tasks api. |
| 294 | + * <p> |
| 295 | + * It'd sure be more convenient if, whenever the _search has returned |
| 296 | + * back to us the _tasks API doesn't contain the _search. But sometimes |
| 297 | + * it still does. So long as it stops <strong>eventually</strong> that's |
| 298 | + * still indicative of the interrupt code working. |
| 299 | + * </p> |
| 300 | + */ |
290 | 301 | private void assertNoSearchesRunning() throws Exception { |
291 | | - Request tasks = new Request("GET", "/_tasks"); |
292 | | - tasks.addParameter("actions", "*search"); |
293 | | - tasks.addParameter("detailed", ""); |
294 | 302 | assertBusy(() -> { |
295 | | - Map<?, ?> response = responseAsMap(client().performRequest(tasks)); |
296 | | - // If there are running searches the map in `nodes` is non-empty. |
297 | | - assertMap(response, matchesMap().entry("nodes", matchesMap())); |
298 | | - }); |
| 303 | + Request tasks = new Request("GET", "/_tasks"); |
| 304 | + tasks.addParameter("actions", "*search"); |
| 305 | + tasks.addParameter("detailed", ""); |
| 306 | + assertBusy(() -> { |
| 307 | + Map<?, ?> response = responseAsMap(client().performRequest(tasks)); |
| 308 | + // If there are running searches the map in `nodes` is non-empty. |
| 309 | + if (response.isEmpty() == false) { |
| 310 | + logger.warn("search still running, hot threads:\n{}", hotThreads()); |
| 311 | + } |
| 312 | + assertMap(response, matchesMap().entry("nodes", matchesMap())); |
| 313 | + }); |
| 314 | + }, 1, TimeUnit.MINUTES); |
| 315 | + } |
| 316 | + |
| 317 | + private String hotThreads() throws IOException { |
| 318 | + Request tasks = new Request("GET", "/_nodes/hot_threads"); |
| 319 | + return EntityUtils.toString(client().performRequest(tasks).getEntity()); |
299 | 320 | } |
300 | 321 | } |
0 commit comments