From d119204f766260b96906e8fb8c17cef2e1ba7c58 Mon Sep 17 00:00:00 2001 From: rongtongjin <794220751@qq.com> Date: Thu, 5 Mar 2020 16:13:13 +0800 Subject: [PATCH] fix(test):fix the issue that MessageClientIDSetter#getIPFromID return wrong pid when pid greater than short type max value --- .../rocketmq/common/message/MessageClientIDSetter.java | 6 +++--- .../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 9d6ec95a..041bf6ba 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 55aa5058..6d8c2038 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); } -- GitLab