@@ -0,0 +1,3083 @@
+/*%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.qos.legacy;%0A%0Aimport org.apache.dubbo.common.URL;%0Aimport org.apache.dubbo.qos.legacy.service.DemoService;%0Aimport org.apache.dubbo.remoting.Channel;%0Aimport org.apache.dubbo.remoting.telnet.TelnetHandler;%0Aimport org.apache.dubbo.rpc.Invoker;%0Aimport org.apache.dubbo.rpc.protocol.dubbo.DubboProtocol;%0Aimport org.apache.dubbo.rpc.protocol.dubbo.filter.TraceFilter;%0Aimport org.junit.jupiter.api.AfterEach;%0Aimport org.junit.jupiter.api.Assertions;%0Aimport org.junit.jupiter.api.BeforeEach;%0Aimport org.junit.jupiter.api.Test;%0A%0Aimport java.lang.reflect.Field;%0Aimport java.util.Set;%0Aimport java.util.concurrent.ConcurrentHashMap;%0A%0Aimport static org.mockito.BDDMockito.given;%0Aimport static org.mockito.Mockito.mock;%0Aimport static org.mockito.Mockito.reset;%0A%0Apublic class TraceTelnetHandlerTest %7B%0A%0A    private TelnetHandler handler;%0A    private Channel mockChannel;%0A    private Invoker%3CDemoService%3E mockInvoker;%0A    private URL url = URL.valueOf(%22dubbo://127.0.0.1:20884/demo%22);%0A%0A    @BeforeEach%0A    public void setUp() %7B%0A        handler = new TraceTelnetHandler();%0A        mockChannel = mock(Channel.class);%0A        mockInvoker = mock(Invoker.class);%0A        given(mockInvoker.getInterface()).willReturn(DemoService.class);%0A        given(mockInvoker.getUrl()).willReturn(url);%0A    %7D%0A%0A    @AfterEach%0A    public void tearDown() %7B%0A        reset(mockChannel, mockInvoker);%0A        ProtocolUtils.closeAll();%0A    %7D%0A%0A    @Test%0A    public void testTraceTelnetAddTracer() throws Exception %7B%0A        String method = %22sayHello%22;%0A        String message = %22org.apache.dubbo.qos.legacy.service.DemoService sayHello 1%22;%0A        Class%3C?%3E type = DemoService.class;%0A%0A        DubboProtocol.getDubboProtocol().export(mockInvoker);%0A        handler.telnet(mockChannel, message);%0A%0A        String key = type.getName() + %22.%22 + method;%0A        Field tracers = TraceFilter.class.getDeclaredField(%22TRACERS%22);%0A        tracers.setAccessible(true);%0A        ConcurrentHashMap%3CString, Set%3CChannel%3E%3E map =%0A                (ConcurrentHashMap%3CString, Set%3CChannel%3E%3E) tracers.get(new ConcurrentHashMap%3CString, Set%3CChannel%3E%3E());%0A%0A        Set%3CChannel%3E channels = map.getOrDefault(key, null);%0A        Assertions.assertNotNull(channels);%0A%0A        Assertions.assertTrue(channels.contains(mockChannel));%0A    %7D%0A%7D%0A

add unit test for TraceTelnetHandler (#7843) (#7861)