use of org.opensearch.common.util.concurrent.OpenSearchThreadPoolExecutor in project OpenSearch by opensearch-project.
the class EvilThreadPoolTests method testExecutionErrorOnFixedESThreadPoolExecutor.
public void testExecutionErrorOnFixedESThreadPoolExecutor() throws InterruptedException {
final OpenSearchThreadPoolExecutor fixedExecutor = OpenSearchExecutors.newFixed("test", 1, 1, OpenSearchExecutors.daemonThreadFactory("test"), threadPool.getThreadContext());
try {
checkExecutionError(getExecuteRunner(fixedExecutor));
checkExecutionError(getSubmitRunner(fixedExecutor));
} finally {
ThreadPool.terminate(fixedExecutor, 10, TimeUnit.SECONDS);
}
}
use of org.opensearch.common.util.concurrent.OpenSearchThreadPoolExecutor in project OpenSearch by opensearch-project.
the class EvilThreadPoolTests method testExecutionExceptionOnScalingESThreadPoolExecutor.
public void testExecutionExceptionOnScalingESThreadPoolExecutor() throws InterruptedException {
final OpenSearchThreadPoolExecutor scalingExecutor = OpenSearchExecutors.newScaling("test", 1, 1, 10, TimeUnit.SECONDS, OpenSearchExecutors.daemonThreadFactory("test"), threadPool.getThreadContext());
try {
checkExecutionException(getExecuteRunner(scalingExecutor), true);
checkExecutionException(getSubmitRunner(scalingExecutor), false);
} finally {
ThreadPool.terminate(scalingExecutor, 10, TimeUnit.SECONDS);
}
}
use of org.opensearch.common.util.concurrent.OpenSearchThreadPoolExecutor in project OpenSearch by opensearch-project.
the class ScalingThreadPoolTests method testScalingThreadPoolConfiguration.
public void testScalingThreadPoolConfiguration() throws InterruptedException {
final String threadPoolName = randomThreadPool(ThreadPool.ThreadPoolType.SCALING);
final Settings.Builder builder = Settings.builder();
final int core;
if (randomBoolean()) {
core = randomIntBetween(0, 8);
builder.put("thread_pool." + threadPoolName + ".core", core);
} else {
// the defaults
core = "generic".equals(threadPoolName) ? 4 : 1;
}
final int availableProcessors = Runtime.getRuntime().availableProcessors();
final int maxBasedOnNumberOfProcessors;
final int processorsUsed;
if (randomBoolean()) {
final int processors = randomIntBetween(1, 64);
maxBasedOnNumberOfProcessors = expectedSize(threadPoolName, processors);
builder.put("node.processors", processors);
processorsUsed = processors;
} else {
maxBasedOnNumberOfProcessors = expectedSize(threadPoolName, availableProcessors);
processorsUsed = availableProcessors;
}
final int expectedMax;
if (maxBasedOnNumberOfProcessors < core || randomBoolean()) {
expectedMax = randomIntBetween(Math.max(1, core), 16);
builder.put("thread_pool." + threadPoolName + ".max", expectedMax);
} else {
expectedMax = maxBasedOnNumberOfProcessors;
}
final long keepAlive;
if (randomBoolean()) {
keepAlive = randomIntBetween(1, 300);
builder.put("thread_pool." + threadPoolName + ".keep_alive", keepAlive + "s");
} else {
// the defaults
keepAlive = "generic".equals(threadPoolName) ? 30 : 300;
}
runScalingThreadPoolTest(builder.build(), (clusterSettings, threadPool) -> {
final Executor executor = threadPool.executor(threadPoolName);
assertThat(executor, instanceOf(OpenSearchThreadPoolExecutor.class));
final OpenSearchThreadPoolExecutor openSearchThreadPoolExecutor = (OpenSearchThreadPoolExecutor) executor;
final ThreadPool.Info info = info(threadPool, threadPoolName);
assertThat(info.getName(), equalTo(threadPoolName));
assertThat(info.getThreadPoolType(), equalTo(ThreadPool.ThreadPoolType.SCALING));
assertThat(info.getKeepAlive().seconds(), equalTo(keepAlive));
assertThat(openSearchThreadPoolExecutor.getKeepAliveTime(TimeUnit.SECONDS), equalTo(keepAlive));
assertNull(info.getQueueSize());
assertThat(openSearchThreadPoolExecutor.getQueue().remainingCapacity(), equalTo(Integer.MAX_VALUE));
assertThat(info.getMin(), equalTo(core));
assertThat(openSearchThreadPoolExecutor.getCorePoolSize(), equalTo(core));
assertThat(info.getMax(), equalTo(expectedMax));
assertThat(openSearchThreadPoolExecutor.getMaximumPoolSize(), equalTo(expectedMax));
});
if (processorsUsed > availableProcessors) {
assertWarnings("setting [node.processors] to value [" + processorsUsed + "] which is more than available processors [" + availableProcessors + "] is deprecated");
}
}
use of org.opensearch.common.util.concurrent.OpenSearchThreadPoolExecutor in project OpenSearch by opensearch-project.
the class EvilThreadPoolTests method testExecutionErrorOnScalingESThreadPoolExecutor.
public void testExecutionErrorOnScalingESThreadPoolExecutor() throws InterruptedException {
final OpenSearchThreadPoolExecutor scalingExecutor = OpenSearchExecutors.newScaling("test", 1, 1, 10, TimeUnit.SECONDS, OpenSearchExecutors.daemonThreadFactory("test"), threadPool.getThreadContext());
try {
checkExecutionError(getExecuteRunner(scalingExecutor));
checkExecutionError(getSubmitRunner(scalingExecutor));
} finally {
ThreadPool.terminate(scalingExecutor, 10, TimeUnit.SECONDS);
}
}
use of org.opensearch.common.util.concurrent.OpenSearchThreadPoolExecutor in project OpenSearch by opensearch-project.
the class EvilThreadPoolTests method testExecutionExceptionOnFixedESThreadPoolExecutor.
public void testExecutionExceptionOnFixedESThreadPoolExecutor() throws InterruptedException {
final OpenSearchThreadPoolExecutor fixedExecutor = OpenSearchExecutors.newFixed("test", 1, 1, OpenSearchExecutors.daemonThreadFactory("test"), threadPool.getThreadContext());
try {
checkExecutionException(getExecuteRunner(fixedExecutor), true);
checkExecutionException(getSubmitRunner(fixedExecutor), false);
} finally {
ThreadPool.terminate(fixedExecutor, 10, TimeUnit.SECONDS);
}
}
Aggregations