Search in sources :

Example 1 with PrioritizedOpenSearchThreadPoolExecutor

use of org.opensearch.common.util.concurrent.PrioritizedOpenSearchThreadPoolExecutor in project OpenSearch by opensearch-project.

the class EvilThreadPoolTests method testExecutionExceptionOnSinglePrioritizingThreadPoolExecutor.

public void testExecutionExceptionOnSinglePrioritizingThreadPoolExecutor() throws InterruptedException {
    final PrioritizedOpenSearchThreadPoolExecutor prioritizedExecutor = OpenSearchExecutors.newSinglePrioritizing("test", OpenSearchExecutors.daemonThreadFactory("test"), threadPool.getThreadContext(), threadPool.scheduler());
    try {
        checkExecutionException(getExecuteRunner(prioritizedExecutor), true);
        checkExecutionException(getSubmitRunner(prioritizedExecutor), false);
        // bias towards timeout
        checkExecutionException(r -> prioritizedExecutor.execute(delayMillis(r, 10), TimeValue.ZERO, r), true);
        // race whether timeout or success (but typically biased towards success)
        checkExecutionException(r -> prioritizedExecutor.execute(r, TimeValue.ZERO, r), true);
        // bias towards no timeout.
        checkExecutionException(r -> prioritizedExecutor.execute(r, TimeValue.timeValueMillis(10), r), true);
    } finally {
        ThreadPool.terminate(prioritizedExecutor, 10, TimeUnit.SECONDS);
    }
}
Also used : PrioritizedOpenSearchThreadPoolExecutor(org.opensearch.common.util.concurrent.PrioritizedOpenSearchThreadPoolExecutor)

Example 2 with PrioritizedOpenSearchThreadPoolExecutor

use of org.opensearch.common.util.concurrent.PrioritizedOpenSearchThreadPoolExecutor 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)

Example 3 with PrioritizedOpenSearchThreadPoolExecutor

use of org.opensearch.common.util.concurrent.PrioritizedOpenSearchThreadPoolExecutor in project OpenSearch by opensearch-project.

the class EvilThreadPoolTests method testExecutionErrorOnSinglePrioritizingThreadPoolExecutor.

public void testExecutionErrorOnSinglePrioritizingThreadPoolExecutor() throws InterruptedException {
    final PrioritizedOpenSearchThreadPoolExecutor prioritizedExecutor = OpenSearchExecutors.newSinglePrioritizing("test", OpenSearchExecutors.daemonThreadFactory("test"), threadPool.getThreadContext(), threadPool.scheduler());
    try {
        checkExecutionError(getExecuteRunner(prioritizedExecutor));
        checkExecutionError(getSubmitRunner(prioritizedExecutor));
        // bias towards timeout
        checkExecutionError(r -> prioritizedExecutor.execute(delayMillis(r, 10), TimeValue.ZERO, r));
        // race whether timeout or success (but typically biased towards success)
        checkExecutionError(r -> prioritizedExecutor.execute(r, TimeValue.ZERO, r));
        // bias towards no timeout.
        checkExecutionError(r -> prioritizedExecutor.execute(r, TimeValue.timeValueMillis(10), r));
    } finally {
        ThreadPool.terminate(prioritizedExecutor, 10, TimeUnit.SECONDS);
    }
}
Also used : PrioritizedOpenSearchThreadPoolExecutor(org.opensearch.common.util.concurrent.PrioritizedOpenSearchThreadPoolExecutor)

Aggregations

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