From ea09ce093f4aea64ac476ca55e303990a6d43009 Mon Sep 17 00:00:00 2001 From: Eason Chen Date: Wed, 13 Nov 2019 16:07:11 +0800 Subject: [PATCH] [issue #670]change the way to create newGroupChannelTable (#1412) * change the way to create newGroupChannelTable --- .../apache/rocketmq/broker/client/ProducerManager.java | 10 +++++++++- .../rocketmq/broker/client/ProducerManagerTest.java | 8 ++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/broker/src/main/java/org/apache/rocketmq/broker/client/ProducerManager.java b/broker/src/main/java/org/apache/rocketmq/broker/client/ProducerManager.java index 61ceae53..f3eed652 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/client/ProducerManager.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/client/ProducerManager.java @@ -53,7 +53,15 @@ public class ProducerManager { try { if (this.groupChannelLock.tryLock(LOCK_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)) { try { - newGroupChannelTable.putAll(groupChannelTable); + Iterator>> iter = groupChannelTable.entrySet().iterator(); + while (iter.hasNext()) { + Map.Entry> entry = iter.next(); + String key = entry.getKey(); + HashMap val = entry.getValue(); + HashMap tmp = new HashMap(); + tmp.putAll(val); + newGroupChannelTable.put(key, tmp); + } } finally { groupChannelLock.unlock(); } diff --git a/broker/src/test/java/org/apache/rocketmq/broker/client/ProducerManagerTest.java b/broker/src/test/java/org/apache/rocketmq/broker/client/ProducerManagerTest.java index 08dbb9c7..33995ff2 100644 --- a/broker/src/test/java/org/apache/rocketmq/broker/client/ProducerManagerTest.java +++ b/broker/src/test/java/org/apache/rocketmq/broker/client/ProducerManagerTest.java @@ -87,4 +87,12 @@ public class ProducerManagerTest { assertThat(channelMap).isNull(); } + @Test + public void testGetGroupChannelTable() throws Exception { + producerManager.registerProducer(group, clientInfo); + HashMap oldMap = producerManager.getGroupChannelTable().get(group); + + producerManager.unregisterProducer(group, clientInfo); + assertThat(oldMap.size()).isNotEqualTo(0); + } } \ No newline at end of file -- GitLab