Skip to content

Commit de5f09d

Browse files
committed
Add a test for PauseLock
1 parent 47130ac commit de5f09d

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

server/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@
162162
import java.util.concurrent.BrokenBarrierException;
163163
import java.util.concurrent.CountDownLatch;
164164
import java.util.concurrent.CyclicBarrier;
165+
import java.util.concurrent.Executors;
165166
import java.util.concurrent.Phaser;
166167
import java.util.concurrent.Semaphore;
167168
import java.util.concurrent.TimeUnit;
@@ -7686,6 +7687,23 @@ public void testDisableRecoverySource() throws Exception {
76867687
}
76877688
}
76887689

7690+
public void testPauseLockCanBeThrottledConcurrently() throws Exception {
7691+
int allowThreads = randomIntBetween(2, 8);
7692+
var pauseLock = new Engine.PauseLock(allowThreads);
7693+
var executor = Executors.newFixedThreadPool(allowThreads);
7694+
var barrier = new CyclicBarrier(allowThreads);
7695+
for (int i = 0; i < allowThreads; i++) {
7696+
executor.submit(() -> {
7697+
safeAwait(barrier);
7698+
pauseLock.throttle();
7699+
pauseLock.unthrottle();
7700+
});
7701+
}
7702+
7703+
executor.shutdown();
7704+
assertTrue(executor.awaitTermination(10, TimeUnit.SECONDS));
7705+
}
7706+
76897707
private static void assertCommitGenerations(Map<IndexCommit, Engine.IndexCommitRef> commits, List<Long> expectedGenerations) {
76907708
assertCommitGenerations(commits.values().stream().map(Engine.IndexCommitRef::getIndexCommit).toList(), expectedGenerations);
76917709
}

0 commit comments

Comments
 (0)