Skip to content

Commit

Permalink
Try and fail to stop the SearchResponse leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
williamrandolph committed Mar 30, 2024
1 parent 86b36fe commit a7134ab
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import org.elasticsearch.action.bulk.BulkResponse;
import org.elasticsearch.action.support.WriteRequest;
import org.elasticsearch.client.internal.Client;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.indices.SystemIndexThreadPoolTests;
import org.elasticsearch.plugins.Plugin;
Expand All @@ -34,17 +35,18 @@ public void testKibanaThreadPool() {
String idToUpdate = client().prepareIndex(".kibana").setSource(Map.of("foo", "update me!")).get().getId();

// bulk index, delete, and update
BulkResponse response = client().prepareBulk(".kibana")
.add(client().prepareIndex(".kibana").setSource(Map.of("foo", "search me!")))
.add(client().prepareDelete(".kibana", idToDelete))
.add(client().prepareUpdate().setId(idToUpdate).setDoc(Map.of("foo", "I'm updated!")))
Client bulkClient = client();
BulkResponse response = bulkClient.prepareBulk(".kibana")
.add(bulkClient.prepareIndex(".kibana").setSource(Map.of("foo", "search me!")))
.add(bulkClient.prepareDelete(".kibana", idToDelete))
.add(bulkClient.prepareUpdate().setId(idToUpdate).setDoc(Map.of("foo", "I'm updated!")))
.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE)
.get();
assertFalse(response.hasFailures());

// match-all search
var results = client().prepareSearch(".kibana").setQuery(QueryBuilders.matchAllQuery()).get();
assertThat(results.getHits().getHits().length, equalTo(2));
var searchResponse = client().prepareSearch(".kibana").setQuery(QueryBuilders.matchAllQuery()).get();
assertThat(searchResponse.getHits().getHits().length, equalTo(2));
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private void assertThreadPoolsBlocked() {
}

protected void runWithBlockedThreadPools(Runnable runnable) {
ThreadPool threadPool = internalCluster().getInstance(ThreadPool.class);
ThreadPool threadPool = internalCluster().getDataNodeInstance(ThreadPool.class);
int numThreadsToBlock = threadPoolsToBlock().stream().map(threadPool::info).mapToInt(ThreadPool.Info::getMax).sum();
CyclicBarrier cb = new CyclicBarrier(numThreadsToBlock + 1);
Runnable waitAction = () -> {
Expand Down

0 comments on commit a7134ab

Please sign in to comment.