rocketmq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From duhengfore...@apache.org
Subject [rocketmq] branch develop updated: fix(test):fix the issue that MessageClientIDSetter#getIPFromID return wrong pid when pid greater than short type max value
Date Thu, 05 Mar 2020 09:38:53 GMT
This is an automated email from the ASF dual-hosted git repository.

duhengforever pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/rocketmq.git


The following commit(s) were added to refs/heads/develop by this push:
     new d119204  fix(test):fix the issue that MessageClientIDSetter#getIPFromID return wrong
pid when pid greater than short type max value
     new d7102c0  Merge pull request #1822 from RongtongJin/fix_1821
d119204 is described below

commit d119204f766260b96906e8fb8c17cef2e1ba7c58
Author: rongtongjin <794220751@qq.com>
AuthorDate: Thu Mar 5 16:13:13 2020 +0800

    fix(test):fix the issue that MessageClientIDSetter#getIPFromID return wrong pid when pid
greater than short type max value
---
 .../org/apache/rocketmq/common/message/MessageClientIDSetter.java   | 6 +++---
 .../apache/rocketmq/common/message/MessageClientIDSetterTest.java   | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/common/src/main/java/org/apache/rocketmq/common/message/MessageClientIDSetter.java
b/common/src/main/java/org/apache/rocketmq/common/message/MessageClientIDSetter.java
index 9d6ec95..041bf6b 100644
--- a/common/src/main/java/org/apache/rocketmq/common/message/MessageClientIDSetter.java
+++ b/common/src/main/java/org/apache/rocketmq/common/message/MessageClientIDSetter.java
@@ -104,11 +104,11 @@ public class MessageClientIDSetter {
         return result;
     }
 
-    public static short getPidFromID(String msgID) {
+    public static int getPidFromID(String msgID) {
         byte[] bytes = UtilAll.string2bytes(msgID);
         ByteBuffer wrap = ByteBuffer.wrap(bytes);
-        wrap.position(bytes.length - 2 - 4 - 4 - 2);
-        return wrap.getShort();
+        int value = wrap.getShort(bytes.length - 2 - 4 - 4 - 2);
+        return value & 0x0000FFFF;
     }
 
     public static String createUniqID() {
diff --git a/common/src/test/java/org/apache/rocketmq/common/message/MessageClientIDSetterTest.java
b/common/src/test/java/org/apache/rocketmq/common/message/MessageClientIDSetterTest.java
index 55aa505..6d8c203 100644
--- a/common/src/test/java/org/apache/rocketmq/common/message/MessageClientIDSetterTest.java
+++ b/common/src/test/java/org/apache/rocketmq/common/message/MessageClientIDSetterTest.java
@@ -40,7 +40,7 @@ public class MessageClientIDSetterTest {
         int pid = UtilAll.getPid();
 
         String uniqID = MessageClientIDSetter.createUniqID();
-        short pidFromID = MessageClientIDSetter.getPidFromID(uniqID);
+        int pidFromID = MessageClientIDSetter.getPidFromID(uniqID);
 
         assertThat(pid).isEqualTo(pidFromID);
     }


Mime
View raw message