Skip to content

Commit

Permalink
[issue alibaba#670]change the way to create newGroupChannelTable (ali…
Browse files Browse the repository at this point in the history
…baba#1412)

* change the way to create newGroupChannelTable
  • Loading branch information
qqeasonchen authored and zongtanghu committed Nov 13, 2019
1 parent 34b902f commit ea09ce0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,15 @@ public HashMap<String, HashMap<Channel, ClientChannelInfo>> getGroupChannelTable
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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,12 @@ public void unregisterProducer() throws Exception {
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);
}
}

0 comments on commit ea09ce0

Please sign in to comment.