@@ -0,0 +1,3665 @@
+/*%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.rocketmq.broker.client;%0A%0Aimport io.netty.channel.Channel;%0Aimport io.netty.channel.ChannelFuture;%0Aimport java.lang.reflect.Field;%0Aimport java.util.HashMap;%0Aimport org.junit.Before;%0Aimport org.junit.Test;%0Aimport org.junit.runner.RunWith;%0Aimport org.mockito.Mock;%0Aimport org.mockito.junit.MockitoJUnitRunner;%0A%0Aimport static org.assertj.core.api.Assertions.assertThat;%0Aimport static org.mockito.Mockito.mock;%0Aimport static org.mockito.Mockito.when;%0A%0A@RunWith(MockitoJUnitRunner.class)%0Apublic class ProducerManagerTest %7B%0A    private ProducerManager producerManager;%0A    private String group = %22FooBar%22;%0A    private ClientChannelInfo clientInfo;%0A%0A    @Mock%0A    private Channel channel;%0A%0A    @Before%0A    public void init() %7B%0A        producerManager = new ProducerManager();%0A        clientInfo = new ClientChannelInfo(channel);%0A    %7D%0A%0A    @Test%0A    public void scanNotActiveChannel() throws Exception %7B%0A        producerManager.registerProducer(group, clientInfo);%0A        assertThat(producerManager.getGroupChannelTable().get(group).get(channel)).isNotNull();%0A%0A        Field field = ProducerManager.class.getDeclaredField(%22CHANNEL_EXPIRED_TIMEOUT%22);%0A        field.setAccessible(true);%0A        long CHANNEL_EXPIRED_TIMEOUT = field.getLong(producerManager);%0A        clientInfo.setLastUpdateTimestamp(System.currentTimeMillis() - CHANNEL_EXPIRED_TIMEOUT - 10);%0A        when(channel.close()).thenReturn(mock(ChannelFuture.class));%0A        producerManager.scanNotActiveChannel();%0A        assertThat(producerManager.getGroupChannelTable().get(group).get(channel)).isNull();%0A    %7D%0A%0A    @Test%0A    public void doChannelCloseEvent() throws Exception %7B%0A        producerManager.registerProducer(group, clientInfo);%0A        assertThat(producerManager.getGroupChannelTable().get(group).get(channel)).isNotNull();%0A        producerManager.doChannelCloseEvent(%22127.0.0.1%22, channel);%0A        assertThat(producerManager.getGroupChannelTable().get(group).get(channel)).isNull();%0A    %7D%0A%0A    @Test%0A    public void testRegisterProducer() throws Exception %7B%0A        producerManager.registerProducer(group, clientInfo);%0A        HashMap%3CChannel, ClientChannelInfo%3E channelMap = producerManager.getGroupChannelTable().get(group);%0A        assertThat(channelMap).isNotNull();%0A        assertThat(channelMap.get(channel)).isEqualTo(clientInfo);%0A    %7D%0A%0A    @Test%0A    public void unregisterProducer() throws Exception %7B%0A        producerManager.registerProducer(group, clientInfo);%0A        HashMap%3CChannel, ClientChannelInfo%3E channelMap = producerManager.getGroupChannelTable().get(group);%0A        assertThat(channelMap).isNotNull();%0A        assertThat(channelMap.get(channel)).isEqualTo(clientInfo);%0A%0A        producerManager.unregisterProducer(group, clientInfo);%0A        channelMap = producerManager.getGroupChannelTable().get(group);%0A        assertThat(channelMap).isNull();%0A    %7D%0A%0A%7D

Add unit tests for ProducerManager