From 278b9a2eb394fe91a31bc30374aa173e55677512 Mon Sep 17 00:00:00 2001 From: sakuragi27 <745958546@qq.com> Date: Thu, 11 May 2023 12:47:03 +0800 Subject: [PATCH] test: add AbstractThreadPoolRuntimeTest --- .../state/AbstractThreadPoolRuntimeTest.java | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 hippo4j-core/src/test/java/cn/hippo4j/core/executor/state/AbstractThreadPoolRuntimeTest.java diff --git a/hippo4j-core/src/test/java/cn/hippo4j/core/executor/state/AbstractThreadPoolRuntimeTest.java b/hippo4j-core/src/test/java/cn/hippo4j/core/executor/state/AbstractThreadPoolRuntimeTest.java new file mode 100644 index 00000000..250dfdb4 --- /dev/null +++ b/hippo4j-core/src/test/java/cn/hippo4j/core/executor/state/AbstractThreadPoolRuntimeTest.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package cn.hippo4j.core.executor.state; + +import cn.hippo4j.common.model.ThreadPoolRunStateInfo; +import cn.hippo4j.core.executor.DynamicThreadPoolExecutor; +import cn.hippo4j.core.executor.DynamicThreadPoolWrapper; +import cn.hippo4j.core.executor.manage.GlobalThreadPoolManage; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; + +import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + +@ExtendWith(MockitoExtension.class) +public class AbstractThreadPoolRuntimeTest { + + @Test + void testPoolRunState() { + AbstractThreadPoolRuntime threadPoolRuntime = new AbstractThreadPoolRuntime() { + @Override + public ThreadPoolRunStateInfo supplement(ThreadPoolRunStateInfo threadPoolRunStateInfo) { + return threadPoolRunStateInfo; + } + }; + + final String threadPoolId = "test"; + DynamicThreadPoolExecutor executor = new DynamicThreadPoolExecutor( + 1, 1, 1000L, TimeUnit.MILLISECONDS, + 1000L, true, 1000L, + new ArrayBlockingQueue<>(1), threadPoolId, Thread::new, new ThreadPoolExecutor.DiscardOldestPolicy()); + + DynamicThreadPoolWrapper dynamicThreadPoolWrapper = DynamicThreadPoolWrapper.builder() + .threadPoolId(threadPoolId) + .executor(executor) + .build(); + GlobalThreadPoolManage.registerPool(threadPoolId, dynamicThreadPoolWrapper); + + ThreadPoolRunStateInfo threadPoolRunStateInfo = threadPoolRuntime.getPoolRunState(threadPoolId); + Assertions.assertNotNull(threadPoolRunStateInfo); + + threadPoolRunStateInfo = threadPoolRuntime.getPoolRunState(threadPoolId, executor); + Assertions.assertNotNull(threadPoolRunStateInfo); + } + +} \ No newline at end of file