Correctly release threads from starting gate in o.e.c.ClusterServiceIT
This commit is contained in:
parent
35cc749c9a
commit
84c4ab6c18
|
@ -831,30 +831,38 @@ public class ClusterServiceIT extends ESIntegTestCase {
|
||||||
counts.merge(executor, 1, (previous, one) -> previous + one);
|
counts.merge(executor, 1, (previous, one) -> previous + one);
|
||||||
}
|
}
|
||||||
|
|
||||||
CountDownLatch startingGun = new CountDownLatch(1 + numberOfThreads);
|
CountDownLatch startGate = new CountDownLatch(1);
|
||||||
List<Thread> threads = new ArrayList<>();
|
CountDownLatch endGate = new CountDownLatch(numberOfThreads);
|
||||||
|
AtomicBoolean interrupted = new AtomicBoolean();
|
||||||
for (int i = 0; i < numberOfThreads; i++) {
|
for (int i = 0; i < numberOfThreads; i++) {
|
||||||
final int index = i;
|
final int index = i;
|
||||||
Thread thread = new Thread(() -> {
|
Thread thread = new Thread(() -> {
|
||||||
startingGun.countDown();
|
try {
|
||||||
for (int j = 0; j < tasksSubmittedPerThread; j++) {
|
try {
|
||||||
ClusterStateTaskExecutor<Task> executor = assignments.get(index * tasksSubmittedPerThread + j);
|
startGate.await();
|
||||||
clusterService.submitStateUpdateTask(
|
} catch (InterruptedException e) {
|
||||||
Thread.currentThread().getName(),
|
interrupted.set(true);
|
||||||
new Task(),
|
return;
|
||||||
ClusterStateTaskConfig.build(randomFrom(Priority.values())),
|
}
|
||||||
executor,
|
for (int j = 0; j < tasksSubmittedPerThread; j++) {
|
||||||
listener);
|
ClusterStateTaskExecutor<Task> executor = assignments.get(index * tasksSubmittedPerThread + j);
|
||||||
|
clusterService.submitStateUpdateTask(
|
||||||
|
Thread.currentThread().getName(),
|
||||||
|
new Task(),
|
||||||
|
ClusterStateTaskConfig.build(randomFrom(Priority.values())),
|
||||||
|
executor,
|
||||||
|
listener);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
endGate.countDown();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
threads.add(thread);
|
|
||||||
thread.start();
|
thread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
startingGun.countDown();
|
startGate.countDown();
|
||||||
for (Thread thread : threads) {
|
endGate.await();
|
||||||
thread.join();
|
assertFalse(interrupted.get());
|
||||||
}
|
|
||||||
|
|
||||||
// wait until all the cluster state updates have been processed
|
// wait until all the cluster state updates have been processed
|
||||||
updateLatch.await();
|
updateLatch.await();
|
||||||
|
|
Loading…
Reference in New Issue