Skip to content

Commit e1b9dfc

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

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
import java.util.HashMap;
5252
import java.util.List;
5353
import java.util.Map;
54-
import java.util.concurrent.CyclicBarrier;
54+
import java.util.concurrent.CountDownLatch;
5555

5656
import static org.elasticsearch.cluster.metadata.IndexMetadata.SETTING_NUMBER_OF_REPLICAS;
5757
import static org.elasticsearch.cluster.metadata.IndexMetadata.SETTING_NUMBER_OF_SHARDS;
@@ -286,22 +286,19 @@ public void testMaxQueueLatencyMetricIsPublished() {
286286

287287
// Fill the write thread pool
288288
final int writeThreadPoolSize = threadPoolToDelay.info(ThreadPool.Names.WRITE).getMax();
289-
final CyclicBarrier delayLatch = new CyclicBarrier(writeThreadPoolSize + 1);
289+
final var latch = new CountDownLatch(1);
290+
final var writeThreadPool = threadPoolToDelay.executor(ThreadPool.Names.WRITE);
290291
for (int i = 0; i < writeThreadPoolSize; i++) {
291-
threadPoolToDelay.executor(ThreadPool.Names.WRITE).execute(() -> {
292-
safeAwait(delayLatch);
293-
safeAwait(delayLatch);
294-
});
292+
writeThreadPool.execute(() -> safeAwait(latch));
295293
}
296-
safeAwait(delayLatch);
297294
// Submit a task that will be delayed
298-
threadPoolToDelay.executor(ThreadPool.Names.WRITE).execute(() -> {
295+
writeThreadPool.execute(() -> {
299296
// Doesn't need to do anything
300297
});
301298
final long delayMillis = randomIntBetween(100, 200);
302299
safeSleep(delayMillis);
303300
// Unblock the pool
304-
safeAwait(delayLatch);
301+
latch.countDown();
305302

306303
refreshClusterInfo(masterName);
307304
mostRecentQueueLatencyMetrics = getMostRecentQueueLatencyMetrics(dataNodes);

0 commit comments

Comments
 (0)