use of org.elasticsearch.common.util.concurrent.PrioritizedEsThreadPoolExecutor in project crate by crate.
the class MockSinglePrioritizingExecutorTests method testPrioritizedEsThreadPoolExecutor.
public void testPrioritizedEsThreadPoolExecutor() {
final DeterministicTaskQueue taskQueue = DeterministicTaskQueueTests.newTaskQueue();
final PrioritizedEsThreadPoolExecutor executor = new MockSinglePrioritizingExecutor("test", taskQueue);
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