Repository: apache/rocketmq (Java)
Task: Bug Fix (2022-03-11 03:45:27+00:00)

Issue:
LmqConsumerOffsetManager deserialize can not load offset map
in the branch develop

LmqConsumerOffsetManager deserialize error and the offset map because empty


Discussion:

Patch:
diff --git a/broker/src/main/java/org/apache/rocketmq/broker/offset/LmqConsumerOffsetManager.java b/broker/src/main/java/org/apache/rocketmq/broker/offset/LmqConsumerOffsetManager.java
--- a/broker/src/main/java/org/apache/rocketmq/broker/offset/LmqConsumerOffsetManager.java
+++ b/broker/src/main/java/org/apache/rocketmq/broker/offset/LmqConsumerOffsetManager.java
@@ -28,6 +28,10 @@
 public class LmqConsumerOffsetManager extends ConsumerOffsetManager {
     private ConcurrentHashMap<String, Long> lmqOffsetTable = new ConcurrentHashMap<>(512);
 
+    public LmqConsumerOffsetManager() {
+
+    }
+
     public LmqConsumerOffsetManager(BrokerController brokerController) {
         super(brokerController);
     }


Test patch:
diff --git a/broker/src/test/java/org/apache/rocketmq/broker/offset/LmqConsumerOffsetManagerTest.java b/broker/src/test/java/org/apache/rocketmq/broker/offset/LmqConsumerOffsetManagerTest.java
--- a/broker/src/test/java/org/apache/rocketmq/broker/offset/LmqConsumerOffsetManagerTest.java
+++ b/broker/src/test/java/org/apache/rocketmq/broker/offset/LmqConsumerOffsetManagerTest.java
@@ -73,6 +73,33 @@ public void testOffsetManage() {
         assertThat(offset1).isEqualTo(-1L);
     }
 
+    @Test
+    public void testOffsetManage1() {
+        LmqConsumerOffsetManager lmqConsumerOffsetManager = new LmqConsumerOffsetManager(brokerController);
+
+        String lmqTopicName = "%LMQ%1111";
+
+        String lmqGroupName = "%LMQ%GID_test";
+
+        lmqConsumerOffsetManager.commitOffset("127.0.0.1", lmqGroupName, lmqTopicName, 0, 10L);
+
+        lmqTopicName = "%LMQ%1222";
+
+        lmqGroupName = "%LMQ%GID_test222";
+
+        lmqConsumerOffsetManager.commitOffset("127.0.0.1", lmqGroupName, lmqTopicName, 0, 10L);
+        lmqConsumerOffsetManager.commitOffset("127.0.0.1","GID_test1", "MqttTest",0, 10L);
+
+        String json = lmqConsumerOffsetManager.encode(true);
+
+        LmqConsumerOffsetManager lmqConsumerOffsetManager1 = new LmqConsumerOffsetManager(brokerController);
+
+        lmqConsumerOffsetManager1.decode(json);
+
+        assertThat(lmqConsumerOffsetManager1.getOffsetTable().size()).isEqualTo(1);
+        assertThat(lmqConsumerOffsetManager1.getLmqOffsetTable().size()).isEqualTo(2);
+    }
+
     @After
     public void destroy() {
         UtilAll.deleteFile(new File(new MessageStoreConfig().getStorePathRootDir()));