|
|
|
@ -17,5 +17,59 @@
|
|
|
|
|
|
|
|
|
|
package cn.hippo4j.common.executor;
|
|
|
|
|
|
|
|
|
|
public final class ThreadPoolManagerTest {
|
|
|
|
|
|
|
|
|
|
import cn.hippo4j.common.toolkit.ReflectUtil;
|
|
|
|
|
import org.junit.Assert;
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
|
|
import java.util.concurrent.Executors;
|
|
|
|
|
import java.util.concurrent.ScheduledExecutorService;
|
|
|
|
|
|
|
|
|
|
public class ThreadPoolManagerTest {
|
|
|
|
|
|
|
|
|
|
// tenantId = schedule,group = schedule
|
|
|
|
|
ScheduledExecutorService executorService1 = Executors.newScheduledThreadPool(1);
|
|
|
|
|
|
|
|
|
|
// tenantId = schedule,group = schedule
|
|
|
|
|
ScheduledExecutorService executorService2 = Executors.newScheduledThreadPool(10);
|
|
|
|
|
|
|
|
|
|
// tenantId = executor,group = executor
|
|
|
|
|
ExecutorService executorService3 = Executors.newFixedThreadPool(8);
|
|
|
|
|
|
|
|
|
|
// tenantId = executor,group = executor
|
|
|
|
|
ExecutorService executorService4 = Executors.newFixedThreadPool(16);
|
|
|
|
|
|
|
|
|
|
static final String schedule = "schedule";
|
|
|
|
|
|
|
|
|
|
static final String executor = "executor";
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void getInstance() {
|
|
|
|
|
ThreadPoolManager poolManager = ThreadPoolManager.getInstance();
|
|
|
|
|
Assert.assertNotNull(poolManager);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void register() {
|
|
|
|
|
ThreadPoolManager poolManager = ThreadPoolManager.getInstance();
|
|
|
|
|
poolManager.register(schedule, schedule, executorService1);
|
|
|
|
|
poolManager.register(schedule, schedule, executorService2);
|
|
|
|
|
poolManager.register(executor, executor, executorService3);
|
|
|
|
|
poolManager.register(executor, executor, executorService4);
|
|
|
|
|
|
|
|
|
|
Map<String, Map<String, Set<ExecutorService>>> manager = (Map<String, Map<String, Set<ExecutorService>>>) ReflectUtil.getFieldValue(poolManager, "resourcesManager");
|
|
|
|
|
|
|
|
|
|
Map<String, Set<ExecutorService>> scheduleMap = manager.get(schedule);
|
|
|
|
|
Assert.assertEquals(1, scheduleMap.size());
|
|
|
|
|
Set<ExecutorService> scheduleSet = scheduleMap.get(schedule);
|
|
|
|
|
Assert.assertEquals(2, scheduleSet.size());
|
|
|
|
|
|
|
|
|
|
Map<String, Set<ExecutorService>> executorMap = manager.get(executor);
|
|
|
|
|
Assert.assertEquals(1, executorMap.size());
|
|
|
|
|
Set<ExecutorService> executorSet = executorMap.get(executor);
|
|
|
|
|
Assert.assertEquals(2, executorSet.size());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|