Skip to content

Commit

Permalink
apache#1751 remove repeat code
Browse files Browse the repository at this point in the history
  • Loading branch information
rushsky518 committed Feb 12, 2020
1 parent 9385825 commit 5de8764
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
Expand Up @@ -106,11 +106,9 @@ public static byte[] getIPFromID(String msgID) {

public static short getPidFromID(String msgID) {
byte[] bytes = UtilAll.string2bytes(msgID);
int ipLength = bytes.length == 28 ? 16 : 4;
ByteBuffer wrap = ByteBuffer.wrap(bytes);
wrap.position(ipLength);
short pid = wrap.getShort();
return pid;
wrap.position(bytes.length - 2 - 4 - 4 - 2);
return wrap.getShort();
}

public static String createUniqID() {
Expand Down
Expand Up @@ -17,7 +17,6 @@

package org.apache.rocketmq.common.message;

import org.apache.rocketmq.common.MixAll;
import org.apache.rocketmq.common.UtilAll;
import org.junit.Test;

Expand All @@ -38,10 +37,10 @@ public void testGetIPStrFromID() {

@Test
public void testGetPidFromID() {
long pid = MixAll.getPID();
int pid = UtilAll.getPid();

String uniqID = MessageClientIDSetter.createUniqID();
int pidFromID = MessageClientIDSetter.getPidFromID(uniqID);
short pidFromID = MessageClientIDSetter.getPidFromID(uniqID);

assertThat(pid).isEqualTo(pidFromID);
}
Expand Down

0 comments on commit 5de8764

Please sign in to comment.