[issue #670]change the way to create newGroupChannelTable (#1412)

* change the way to create newGroupChannelTable
This commit is contained in:
Eason Chen
2019-11-13 16:07:11 +08:00
committed by Hu Zongtang
parent 34b902fe9d
commit ea09ce093f
2 changed files with 17 additions and 1 deletions
@@ -53,7 +53,15 @@ public class ProducerManager {
try {
if (this.groupChannelLock.tryLock(LOCK_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)) {
try {
newGroupChannelTable.putAll(groupChannelTable);
Iterator<Map.Entry<String, HashMap<Channel, ClientChannelInfo>>> iter = groupChannelTable.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry<String, HashMap<Channel, ClientChannelInfo>> entry = iter.next();
String key = entry.getKey();
HashMap<Channel, ClientChannelInfo> val = entry.getValue();
HashMap<Channel, ClientChannelInfo> tmp = new HashMap<Channel, ClientChannelInfo>();
tmp.putAll(val);
newGroupChannelTable.put(key, tmp);
}
} finally {
groupChannelLock.unlock();
}
@@ -87,4 +87,12 @@ public class ProducerManagerTest {
assertThat(channelMap).isNull();
}
@Test
public void testGetGroupChannelTable() throws Exception {
producerManager.registerProducer(group, clientInfo);
HashMap<Channel, ClientChannelInfo> oldMap = producerManager.getGroupChannelTable().get(group);
producerManager.unregisterProducer(group, clientInfo);
assertThat(oldMap.size()).isNotEqualTo(0);
}
}