@@ -0,0 +1,3274 @@
+/*%0A * Licensed to the Apache Software Foundation (ASF) under one or more%0A * contributor license agreements.  See the NOTICE file distributed with%0A * this work for additional information regarding copyright ownership.%0A * The ASF licenses this file to You under the Apache License, Version 2.0%0A * (the %22License%22); you may not use this file except in compliance with%0A * the License.  You may obtain a copy of the License at%0A *%0A *     http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage org.apache.dubbo.rpc.protocol.dubbo.status;%0A%0Aimport org.apache.dubbo.common.constants.CommonConstants;%0Aimport org.apache.dubbo.common.extension.ExtensionLoader;%0Aimport org.apache.dubbo.common.status.Status;%0Aimport org.apache.dubbo.common.store.DataStore;%0Aimport org.junit.jupiter.api.Assertions;%0Aimport org.junit.jupiter.api.BeforeEach;%0Aimport org.junit.jupiter.api.Test;%0Aimport org.mockito.Mockito;%0A%0Aimport java.util.concurrent.ThreadPoolExecutor;%0A%0A%0Apublic class ThreadPoolStatusCheckerTest %7B%0A%0A    private ThreadPoolStatusChecker threadPoolStatusChecker;%0A    private Status status;%0A%0A    @BeforeEach%0A    public void setUp() %7B%0A        threadPoolStatusChecker = new ThreadPoolStatusChecker();%0A        status = threadPoolStatusChecker.check();%0A    %7D%0A%0A    @Test%0A    public void statusUnknownTest() %7B%0A        Assertions.assertEquals(status.getLevel(), Status.Level.UNKNOWN);%0A    %7D%0A%0A    @Test%0A    public void statusOkTest() %7B%0A        int activeCount = 1;%0A        int maximumPoolSize = 3;%0A        String portKey = %228888%22;%0A        mockThreadPoolExecutor(activeCount, maximumPoolSize, portKey);%0A%0A        Status status = threadPoolStatusChecker.check();%0A%0A        Assertions.assertEquals(status.getLevel(), Status.Level.OK);%0A        Assertions.assertEquals(status.getMessage(), %22Pool status:OK, max:%22 + maximumPoolSize + %22, core:0, largest:0, active:%22 + activeCount + %22, task:0, service port: %22 + portKey);%0A    %7D%0A%0A%0A    @Test%0A    public void statusWarnTest() %7B%0A        int activeCount = 1;%0A        int maximumPoolSize = 2;%0A        String portKey = %228888%22;%0A        mockThreadPoolExecutor(activeCount, maximumPoolSize, portKey);%0A%0A        Status status = threadPoolStatusChecker.check();%0A%0A        Assertions.assertEquals(status.getLevel(), Status.Level.WARN);%0A        Assertions.assertEquals(status.getMessage(), %22Pool status:WARN, max:%22 + maximumPoolSize + %22, core:0, largest:0, active:%22 + activeCount + %22, task:0, service port: 8888%22);%0A    %7D%0A%0A    private void mockThreadPoolExecutor(int activeCount, int maximumPoolSize, String portKey) %7B%0A        DataStore dataStore = ExtensionLoader.getExtensionLoader(DataStore.class).getDefaultExtension();%0A%0A        ThreadPoolExecutor executor = Mockito.mock(ThreadPoolExecutor.class);%0A        Mockito.when(executor.getActiveCount()).thenReturn(activeCount);%0A        Mockito.when(executor.getMaximumPoolSize()).thenReturn(maximumPoolSize);%0A%0A        dataStore.put(CommonConstants.EXECUTOR_SERVICE_COMPONENT_KEY, portKey, executor);%0A    %7D%0A%0A%7D%0A

Add unit test for ThreadPoolStatusChecker (#7899)