use of com.alipay.sofa.rpc.boot.common.RpcThreadPoolMonitor in project sofa-boot by alipay.
the class ServerConfigContainerTest method testStartCustomThreadPoolMonitor.
@Test
public void testStartCustomThreadPoolMonitor() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, NoSuchFieldException {
UserThreadPoolManager.registerUserThread("service1", new UserThreadPool());
UserThreadPoolManager.registerUserThread("service2", new UserThreadPool());
UserThreadPoolManager.registerUserThread("service3", new UserThreadPool("same-name"));
UserThreadPoolManager.registerUserThread("service4", new UserThreadPool("same-name"));
Method privateStartMethod = serverConfigContainer.getClass().getDeclaredMethod("startCustomThreadPoolMonitor");
privateStartMethod.setAccessible(true);
privateStartMethod.invoke(serverConfigContainer);
Field privateField = serverConfigContainer.getClass().getDeclaredField("customThreadPoolMonitorList");
privateField.setAccessible(true);
Object value = privateField.get(serverConfigContainer);
List<RpcThreadPoolMonitor> customThreadPoolMonitorList = (List<RpcThreadPoolMonitor>) value;
Assert.assertEquals(customThreadPoolMonitorList.size(), 4);
boolean hasHashCode = false;
for (RpcThreadPoolMonitor monitor : customThreadPoolMonitorList) {
if (monitor.getPoolName().contains("same-name-")) {
hasHashCode = true;
}
}
Assert.assertTrue(hasHashCode);
Method privateStopMethod = serverConfigContainer.getClass().getDeclaredMethod("stopCustomThreadPoolMonitor");
privateStopMethod.setAccessible(true);
privateStopMethod.invoke(serverConfigContainer);
Assert.assertEquals(customThreadPoolMonitorList.size(), 0);
}
use of com.alipay.sofa.rpc.boot.common.RpcThreadPoolMonitor in project sofa-boot by alipay.
the class ThreadPoolMonitorTest method testTestStop.
@Test
public void testTestStop() throws InterruptedException {
ThreadPoolExecutor executorService = new ThreadPoolExecutor(10, 11, 1, TimeUnit.DAYS, new LinkedBlockingQueue<>(10));
RpcThreadPoolMonitor rpcThreadPoolMonitor = new RpcThreadPoolMonitor(executorService, LoggerConstant.TRIPLE_THREAD_LOGGER_NAME);
rpcThreadPoolMonitor.start();
Thread monitor = rpcThreadPoolMonitor.getMonitor();
Assert.assertFalse(Thread.State.TERMINATED == monitor.getState());
rpcThreadPoolMonitor.stop();
Thread.sleep(100);
System.out.println(monitor.getState());
Assert.assertTrue(Thread.State.TERMINATED == monitor.getState());
}
use of com.alipay.sofa.rpc.boot.common.RpcThreadPoolMonitor in project sofa-boot by alipay.
the class ThreadPoolMonitorTest method test.
@Test
public void test() throws InterruptedException {
ThreadPoolExecutor executorService = new ThreadPoolExecutor(10, 11, 1, TimeUnit.DAYS, new LinkedBlockingQueue<>(10));
new RpcThreadPoolMonitor(executorService, LoggerConstant.TRIPLE_THREAD_LOGGER_NAME).start();
Thread.sleep(10000);
}
Aggregations