Skip to content

Commit c28de52

Browse files
committed
Simplify thread-pool blocking
1 parent e1b9dfc commit c28de52

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

server/src/internalClusterTest/java/org/elasticsearch/cluster/routing/allocation/decider/WriteLoadConstraintDeciderIT.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import java.util.Map;
5454
import java.util.concurrent.CountDownLatch;
5555

56+
import static java.util.stream.IntStream.range;
5657
import static org.elasticsearch.cluster.metadata.IndexMetadata.SETTING_NUMBER_OF_REPLICAS;
5758
import static org.elasticsearch.cluster.metadata.IndexMetadata.SETTING_NUMBER_OF_SHARDS;
5859
import static org.hamcrest.Matchers.everyItem;
@@ -284,17 +285,11 @@ public void testMaxQueueLatencyMetricIsPublished() {
284285
final String dataNodeToDelay = randomFrom(dataNodes);
285286
final ThreadPool threadPoolToDelay = internalCluster().getInstance(ThreadPool.class, dataNodeToDelay);
286287

287-
// Fill the write thread pool
288+
// Fill the write thread pool and block a task for some time
288289
final int writeThreadPoolSize = threadPoolToDelay.info(ThreadPool.Names.WRITE).getMax();
289290
final var latch = new CountDownLatch(1);
290291
final var writeThreadPool = threadPoolToDelay.executor(ThreadPool.Names.WRITE);
291-
for (int i = 0; i < writeThreadPoolSize; i++) {
292-
writeThreadPool.execute(() -> safeAwait(latch));
293-
}
294-
// Submit a task that will be delayed
295-
writeThreadPool.execute(() -> {
296-
// Doesn't need to do anything
297-
});
292+
range(0, writeThreadPoolSize + 1).forEach(i -> writeThreadPool.execute(() -> safeAwait(latch)));
298293
final long delayMillis = randomIntBetween(100, 200);
299294
safeSleep(delayMillis);
300295
// Unblock the pool

0 commit comments

Comments
 (0)