Search in sources :

Example 1 with PrioritizedEsThreadPoolExecutor

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());
}
Also used : PrioritizedEsThreadPoolExecutor(org.elasticsearch.common.util.concurrent.PrioritizedEsThreadPoolExecutor) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) PrioritizedRunnable(org.elasticsearch.common.util.concurrent.PrioritizedRunnable)

Aggregations

AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 PrioritizedEsThreadPoolExecutor (org.elasticsearch.common.util.concurrent.PrioritizedEsThreadPoolExecutor)1 PrioritizedRunnable (org.elasticsearch.common.util.concurrent.PrioritizedRunnable)1