Search in sources :

Example 1 with PrioritizedRunnable

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

Aggregations

AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 PrioritizedOpenSearchThreadPoolExecutor (org.opensearch.common.util.concurrent.PrioritizedOpenSearchThreadPoolExecutor)1 PrioritizedRunnable (org.opensearch.common.util.concurrent.PrioritizedRunnable)1