### Question:
ProducerManager { public void scanNotActiveChannel() { try { if (this.hashcodeChannelLock.tryLock(LOCK_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)) { try { Iterator<Entry<Integer, List<ClientChannelInfo>>> it = this.hashcodeChannelTable.entrySet().iterator(); while (it.hasNext()) { Entry<Integer, List<ClientChannelInfo>> entry = it.next(); final Integer groupHashCode = entry.getKey(); final List<ClientChannelInfo> clientChannelInfoList = entry.getValue(); Iterator<ClientChannelInfo> itChannelInfo = clientChannelInfoList.iterator(); while (itChannelInfo.hasNext()) { ClientChannelInfo clientChannelInfo = itChannelInfo.next(); long diff = System.currentTimeMillis() - clientChannelInfo.getLastUpdateTimestamp(); if (diff > CHANNEL_EXPIRED_TIMEOUT) { log.warn( "SCAN: remove expired channel[{}] from ProducerManager hashcodeChannelTable, producer group hash code: {}", RemotingHelper.parseChannelRemoteAddr(clientChannelInfo.getChannel()), groupHashCode); RemotingUtil.closeChannel(clientChannelInfo.getChannel()); itChannelInfo.remove(); } } } } finally { this.hashcodeChannelLock.unlock(); } } else { log.warn("ProducerManager scanNotActiveChannel lock timeout"); } } catch (InterruptedException e) { log.error("", e); } try { if (this.groupChannelLock.tryLock(LOCK_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)) { try { for (final Map.Entry<String, HashMap<Channel, ClientChannelInfo>> entry : this.groupChannelTable .entrySet()) { final String group = entry.getKey(); final HashMap<Channel, ClientChannelInfo> chlMap = entry.getValue(); Iterator<Entry<Channel, ClientChannelInfo>> it = chlMap.entrySet().iterator(); while (it.hasNext()) { Entry<Channel, ClientChannelInfo> item = it.next(); final ClientChannelInfo info = item.getValue(); long diff = System.currentTimeMillis() - info.getLastUpdateTimestamp(); if (diff > CHANNEL_EXPIRED_TIMEOUT) { it.remove(); log.warn( "SCAN: remove expired channel[{}] from ProducerManager groupChannelTable, producer group name: {}", RemotingHelper.parseChannelRemoteAddr(info.getChannel()), group); RemotingUtil.closeChannel(info.getChannel()); } } } } finally { this.groupChannelLock.unlock(); } } else { log.warn("ProducerManager scanNotActiveChannel lock timeout"); } } catch (InterruptedException e) { log.error("", e); } } ProducerManager(); HashMap<String, HashMap<Channel, ClientChannelInfo>> getGroupChannelTable(); void scanNotActiveChannel(); void doChannelCloseEvent(final String remoteAddr, final Channel channel); void registerProducer(final String group, final ClientChannelInfo clientChannelInfo); void unregisterProducer(final String group, final ClientChannelInfo clientChannelInfo); ClientChannelInfo pickProducerChannelRandomly(final int producerGroupHashCode);  }### Answer:
@Test public void scanNotActiveChannel() throws Exception { producerManager.registerProducer(group, clientInfo); assertThat(producerManager.getGroupChannelTable().get(group).get(channel)).isNotNull(); Field field = ProducerManager.class.getDeclaredField("CHANNEL_EXPIRED_TIMEOUT"); field.setAccessible(true); long CHANNEL_EXPIRED_TIMEOUT = field.getLong(producerManager); clientInfo.setLastUpdateTimestamp(System.currentTimeMillis() - CHANNEL_EXPIRED_TIMEOUT - 10); when(channel.close()).thenReturn(mock(ChannelFuture.class)); producerManager.scanNotActiveChannel(); assertThat(producerManager.getGroupChannelTable().get(group).get(channel)).isNull(); }