use of org.opensearch.common.util.concurrent.PrioritizedRunnable in project OpenSearch by opensearch-project.
the class MockSinglePrioritizingExecutorTests method testPrioritizedEsThreadPoolExecutor.
public void testPrioritizedEsThreadPoolExecutor() {
final DeterministicTaskQueue taskQueue = DeterministicTaskQueueTests.newTaskQueue();
final PrioritizedOpenSearchThreadPoolExecutor executor = new MockSinglePrioritizingExecutor("test", taskQueue, taskQueue.getThreadPool());
final AtomicBoolean called1 = new AtomicBoolean();
final AtomicBoolean called2 = new AtomicBoolean();
executor.execute(new PrioritizedRunnable(Priority.NORMAL) {
@Override
public void run() {
// check that this is only called once
assertTrue(called1.compareAndSet(false, true));
}
});
executor.execute(new PrioritizedRunnable(Priority.HIGH) {
@Override
public void run() {
// check that this is only called once
assertTrue(called2.compareAndSet(false, true));
}
});
assertFalse(called1.get());
assertFalse(called2.get());
taskQueue.runRandomTask();
assertFalse(called1.get());
assertTrue(called2.get());
taskQueue.runRandomTask();
assertTrue(called1.get());
assertTrue(called2.get());
taskQueue.runRandomTask();
assertFalse(taskQueue.hasRunnableTasks());
}
Aggregations