mirror of https://github.com/longtai-cn/hippo4j
test: add AbstractThreadPoolRuntimeTest (#1243)
parent
f5126e3b68
commit
f993e88a8a
@ -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);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue