mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-17 10:25:15 +00:00
Give SearchContext a toString
and move the string capturing to capture time.
This commit is contained in:
parent
ac94e5f287
commit
525ce40d1c
@ -403,4 +403,16 @@ public abstract class SearchContext implements Releasable {
|
||||
|
||||
public abstract QueryShardContext getQueryShardContext();
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder result = new StringBuilder().append(shardTarget());
|
||||
if (searchType() != SearchType.DEFAULT) {
|
||||
result.append("searchType=[").append(searchType()).append("]");
|
||||
}
|
||||
if (scrollContext() != null) {
|
||||
result.append("scroll=[").append(scrollContext().scroll.keepAlive()).append("]");
|
||||
}
|
||||
result.append(" query=[").append(query()).append("]");
|
||||
return result.toString();
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,6 @@
|
||||
|
||||
package org.elasticsearch.search;
|
||||
|
||||
import org.elasticsearch.action.search.SearchType;
|
||||
import org.elasticsearch.cache.recycler.PageCacheRecycler;
|
||||
import org.elasticsearch.cluster.service.ClusterService;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
@ -62,22 +61,10 @@ public class MockSearchService extends SearchService {
|
||||
public static void assertNoInFlightContext() {
|
||||
final Map<SearchContext, Throwable> copy = new HashMap<>(ACTIVE_SEARCH_CONTEXTS);
|
||||
if (copy.isEmpty() == false) {
|
||||
Map.Entry<SearchContext, Throwable> firstOpen = copy.entrySet().iterator().next();
|
||||
SearchContext context = firstOpen.getKey();
|
||||
StringBuilder message = new StringBuilder().append(context.shardTarget());
|
||||
if (context.searchType() != SearchType.DEFAULT) {
|
||||
message.append("searchType=[").append(context.searchType()).append("]");
|
||||
}
|
||||
if (context.scrollContext() != null) {
|
||||
message.append("scroll=[").append(context.scrollContext().scroll.keepAlive()).append("]");
|
||||
}
|
||||
message.append(" query=[").append(context.query()).append("]");
|
||||
RuntimeException cause = new RuntimeException(message.toString());
|
||||
cause.setStackTrace(firstOpen.getValue().getStackTrace());
|
||||
throw new AssertionError(
|
||||
"There are still " + copy.size()
|
||||
+ " in-flight contexts. The first one's creation site is listed as the cause of this exception.",
|
||||
cause);
|
||||
"There are still [" + copy.size()
|
||||
+ "] in-flight contexts. The first one's creation site is listed as the cause of this exception.",
|
||||
copy.values().iterator().next());
|
||||
}
|
||||
}
|
||||
|
||||
@ -85,7 +72,7 @@ public class MockSearchService extends SearchService {
|
||||
* Add an active search context to the list of tracked contexts. Package private for testing.
|
||||
*/
|
||||
static void addActiveContext(SearchContext context) {
|
||||
ACTIVE_SEARCH_CONTEXTS.put(context, new RuntimeException());
|
||||
ACTIVE_SEARCH_CONTEXTS.put(context, new RuntimeException(context.toString()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -53,7 +53,7 @@ public class MockSearchServiceTests extends ESTestCase {
|
||||
MockSearchService.addActiveContext(s);
|
||||
try {
|
||||
Throwable e = expectThrows(AssertionError.class, () -> MockSearchService.assertNoInFlightContext());
|
||||
assertEquals("There are still 1 in-flight contexts. The first one's creation site is listed as the cause of this exception.",
|
||||
assertEquals("There are still [1] in-flight contexts. The first one's creation site is listed as the cause of this exception.",
|
||||
e.getMessage());
|
||||
e = e.getCause();
|
||||
// The next line with throw an exception if the date looks wrong
|
||||
|
Loading…
x
Reference in New Issue
Block a user