Skip to content

Commit 11a5676

Browse files
authored
SearchableSnapshotsIT.testCacheStats should wait for cache writes to complete before checking stats (#76011)
* Wait for cache writes to terminate before checking stats * remove empty method
1 parent f339282 commit 11a5676

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

client/rest-high-level/src/test/java/org/elasticsearch/client/SearchableSnapshotsIT.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
package org.elasticsearch.client;
1010

11+
import org.apache.http.client.methods.HttpGet;
1112
import org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryRequest;
1213
import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest;
1314
import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse;
@@ -35,7 +36,10 @@
3536

3637
import java.io.IOException;
3738
import java.util.List;
39+
import java.util.Map;
40+
import java.util.concurrent.TimeUnit;
3841

42+
import static org.elasticsearch.common.xcontent.support.XContentMapValues.extractValue;
3943
import static org.hamcrest.Matchers.aMapWithSize;
4044
import static org.hamcrest.Matchers.emptyOrNullString;
4145
import static org.hamcrest.Matchers.equalTo;
@@ -125,6 +129,35 @@ public void testCacheStats() throws Exception {
125129
assertThat(response.getHits().getHits()[0].getSourceAsMap(), aMapWithSize(2));
126130
}
127131

132+
{
133+
assertBusy(() -> {
134+
final Response response = client().performRequest(new Request(HttpGet.METHOD_NAME, "/_nodes/stats/thread_pool"));
135+
assertThat(response.getStatusLine().getStatusCode(), equalTo(RestStatus.OK.getStatus()));
136+
137+
@SuppressWarnings("unchecked")
138+
final Map<String, Object> nodes = (Map<String, Object>) extractValue(responseAsMap(response), "nodes");
139+
assertThat(nodes, notNullValue());
140+
141+
for (String node : nodes.keySet()) {
142+
@SuppressWarnings("unchecked")
143+
final Map<String, Object> threadPools =
144+
(Map<String, Object>) extractValue((Map<String, Object>) nodes.get(node), "thread_pool");
145+
assertNotNull("No thread pools on node " + node, threadPools);
146+
147+
@SuppressWarnings("unchecked")
148+
final Map<String, Object> threadPoolStats =
149+
(Map<String, Object>) threadPools.get("searchable_snapshots_cache_fetch_async");
150+
assertNotNull("No thread pools stats on node " + node, threadPoolStats);
151+
152+
final Number active = (Number) extractValue(threadPoolStats, "active");
153+
assertThat(node + " has still active tasks", active, equalTo(0));
154+
155+
final Number queue = (Number) extractValue(threadPoolStats, "queue");
156+
assertThat(node + " has still enqueued tasks", queue, equalTo(0));
157+
}
158+
}, 30L, TimeUnit.SECONDS);
159+
}
160+
128161
{
129162
final CachesStatsRequest request = new CachesStatsRequest();
130163
final CachesStatsResponse response = execute(request, client::cacheStats, client::cacheStatsAsync);

0 commit comments

Comments
 (0)