Search in sources :

Example 6 with RpcThreadPoolMonitor

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);
}
Also used : RpcThreadPoolMonitor(com.alipay.sofa.rpc.boot.common.RpcThreadPoolMonitor) Field(java.lang.reflect.Field) List(java.util.List) Method(java.lang.reflect.Method) UserThreadPool(com.alipay.sofa.rpc.server.UserThreadPool) ActivelyDestroyTest(com.alipay.sofa.rpc.boot.test.ActivelyDestroyTest) Test(org.junit.Test)

Example 7 with RpcThreadPoolMonitor

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());
}
Also used : RpcThreadPoolMonitor(com.alipay.sofa.rpc.boot.common.RpcThreadPoolMonitor) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) Test(org.junit.Test)

Example 8 with RpcThreadPoolMonitor

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);
}
Also used : RpcThreadPoolMonitor(com.alipay.sofa.rpc.boot.common.RpcThreadPoolMonitor) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) Test(org.junit.Test)

Aggregations

RpcThreadPoolMonitor (com.alipay.sofa.rpc.boot.common.RpcThreadPoolMonitor)8 Test (org.junit.Test)6 UserThreadPool (com.alipay.sofa.rpc.server.UserThreadPool)4 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)4 ActivelyDestroyTest (com.alipay.sofa.rpc.boot.test.ActivelyDestroyTest)2 Field (java.lang.reflect.Field)2 Method (java.lang.reflect.Method)2 HashSet (java.util.HashSet)2 List (java.util.List)2