|
42 | 42 | import org.hamcrest.Matchers;
|
43 | 43 |
|
44 | 44 | import java.io.IOException;
|
| 45 | +import java.util.Arrays; |
45 | 46 | import java.util.Collections;
|
| 47 | +import java.util.List; |
46 | 48 |
|
47 | 49 | import static org.hamcrest.Matchers.containsString;
|
48 | 50 | import static org.hamcrest.Matchers.endsWith;
|
|
55 | 57 | public class SearchSlowLogTests extends ESSingleNodeTestCase {
|
56 | 58 | @Override
|
57 | 59 | protected SearchContext createSearchContext(IndexService indexService) {
|
| 60 | + return createSearchContext(indexService, new String[]{}); |
| 61 | + } |
| 62 | + protected SearchContext createSearchContext(IndexService indexService, String ... groupStats) { |
58 | 63 | BigArrays bigArrays = indexService.getBigArrays();
|
59 | 64 | ThreadPool threadPool = indexService.getThreadPool();
|
60 | 65 | return new TestSearchContext(bigArrays, indexService) {
|
@@ -150,6 +155,12 @@ public String getClusterAlias() {
|
150 | 155 | return null;
|
151 | 156 | }
|
152 | 157 | };
|
| 158 | + |
| 159 | + @Override |
| 160 | + public List<String> groupStats() { |
| 161 | + return Arrays.asList(groupStats); |
| 162 | + } |
| 163 | + |
153 | 164 | @Override
|
154 | 165 | public ShardSearchRequest request() {
|
155 | 166 | return request;
|
@@ -177,6 +188,26 @@ public void testSlowLogHasJsonFields() throws IOException {
|
177 | 188 | assertThat(p.getValueFor("source"), equalTo("{\\\"query\\\":{\\\"match_all\\\":{\\\"boost\\\":1.0}}}"));
|
178 | 189 | }
|
179 | 190 |
|
| 191 | + public void testSlowLogsWithStats() throws IOException { |
| 192 | + IndexService index = createIndex("foo"); |
| 193 | + SearchContext searchContext = createSearchContext(index,"group1"); |
| 194 | + SearchSourceBuilder source = SearchSourceBuilder.searchSource().query(QueryBuilders.matchAllQuery()); |
| 195 | + searchContext.request().source(source); |
| 196 | + searchContext.setTask(new SearchTask(0, "n/a", "n/a", "test", null, |
| 197 | + Collections.singletonMap(Task.X_OPAQUE_ID, "my_id"))); |
| 198 | + |
| 199 | + SearchSlowLog.SearchSlowLogMessage p = new SearchSlowLog.SearchSlowLogMessage(searchContext, 10); |
| 200 | + assertThat(p.getValueFor("stats"), equalTo("[\\\"group1\\\"]")); |
| 201 | + |
| 202 | + searchContext = createSearchContext(index, "group1", "group2"); |
| 203 | + source = SearchSourceBuilder.searchSource().query(QueryBuilders.matchAllQuery()); |
| 204 | + searchContext.request().source(source); |
| 205 | + searchContext.setTask(new SearchTask(0, "n/a", "n/a", "test", null, |
| 206 | + Collections.singletonMap(Task.X_OPAQUE_ID, "my_id"))); |
| 207 | + p = new SearchSlowLog.SearchSlowLogMessage(searchContext, 10); |
| 208 | + assertThat(p.getValueFor("stats"), equalTo("[\\\"group1\\\", \\\"group2\\\"]")); |
| 209 | + } |
| 210 | + |
180 | 211 | public void testSlowLogSearchContextPrinterToLog() throws IOException {
|
181 | 212 | IndexService index = createIndex("foo");
|
182 | 213 | SearchContext searchContext = createSearchContext(index);
|
|
0 commit comments