|
| 1 | +/* |
| 2 | + * ELASTICSEARCH CONFIDENTIAL |
| 3 | + * __________________ |
| 4 | + * |
| 5 | + * Copyright Elasticsearch B.V. All rights reserved. |
| 6 | + * |
| 7 | + * NOTICE: All information contained herein is, and remains |
| 8 | + * the property of Elasticsearch B.V. and its suppliers, if any. |
| 9 | + * The intellectual and technical concepts contained herein |
| 10 | + * are proprietary to Elasticsearch B.V. and its suppliers and |
| 11 | + * may be covered by U.S. and Foreign Patents, patents in |
| 12 | + * process, and are protected by trade secret or copyright |
| 13 | + * law. Dissemination of this information or reproduction of |
| 14 | + * this material is strictly forbidden unless prior written |
| 15 | + * permission is obtained from Elasticsearch B.V. |
| 16 | + */ |
| 17 | + |
| 18 | +package org.elasticsearch.common.util.concurrent; |
| 19 | + |
| 20 | +import org.elasticsearch.common.settings.Settings; |
| 21 | + |
| 22 | +import java.util.concurrent.TimeUnit; |
| 23 | +import java.util.function.LongSupplier; |
| 24 | + |
| 25 | +import static org.elasticsearch.test.ESTestCase.randomIdentifier; |
| 26 | + |
| 27 | +public class EsThreadPoolExecutorTestHelper { |
| 28 | + |
| 29 | + public static EsExecutors.HotThreadsOnLargeQueueConfig getHotThreadsOnLargeQueueConfig(EsThreadPoolExecutor executor) { |
| 30 | + return executor.getHotThreadsOnLargeQueueConfig(); |
| 31 | + } |
| 32 | + |
| 33 | + public static long getStartTimeOfLargeQueue(EsThreadPoolExecutor executor) { |
| 34 | + return executor.getStartTimeOfLargeQueue(); |
| 35 | + } |
| 36 | + |
| 37 | + public static EsThreadPoolExecutor newEsThreadPoolExecutor( |
| 38 | + String name, |
| 39 | + int corePoolSize, |
| 40 | + int maximumPoolSize, |
| 41 | + EsExecutors.HotThreadsOnLargeQueueConfig hotThreadsOnLargeQueueConfig, |
| 42 | + LongSupplier currentTimeMillisSupplier |
| 43 | + ) { |
| 44 | + return new EsThreadPoolExecutor( |
| 45 | + name, |
| 46 | + corePoolSize, |
| 47 | + maximumPoolSize, |
| 48 | + 5, |
| 49 | + TimeUnit.MINUTES, |
| 50 | + new EsExecutors.ExecutorScalingQueue<>(), |
| 51 | + EsExecutors.daemonThreadFactory(randomIdentifier(), name), |
| 52 | + new EsExecutors.ForceQueuePolicy(false, false), |
| 53 | + new ThreadContext(Settings.EMPTY), |
| 54 | + hotThreadsOnLargeQueueConfig, |
| 55 | + currentTimeMillisSupplier |
| 56 | + ); |
| 57 | + } |
| 58 | +} |
0 commit comments