Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix RequestCode overflowed issues:8868 #8871

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ public class RequestCode {

public static final int GET_TIMER_METRICS = 61;

public static final int POP_MESSAGE = 200050;
public static final int ACK_MESSAGE = 200051;
public static final int BATCH_ACK_MESSAGE = 200151;
public static final int PEEK_MESSAGE = 200052;
public static final int CHANGE_MESSAGE_INVISIBLETIME = 200053;
public static final int NOTIFICATION = 200054;
public static final int POLLING_INFO = 200055;
public static final short POP_MESSAGE = 3442;
public static final short ACK_MESSAGE = 3443;
public static final short BATCH_ACK_MESSAGE = 3543;
public static final short PEEK_MESSAGE = 3444;
public static final short CHANGE_MESSAGE_INVISIBLETIME = 3445;
public static final short NOTIFICATION = 3446;
public static final short POLLING_INFO = 3447;

public static final int PUT_KV_CONFIG = 100;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,41 @@ public void testFastEncode() throws Exception {
assertThat(h2.getStr()).isEqualTo("s1");
assertThat(h2.getNum()).isEqualTo(100);
}

@Test
public void testRequestCodeEncode() throws Exception {
testRequestCodeEncode(RequestCode.POP_MESSAGE);
testRequestCodeEncode(RequestCode.ACK_MESSAGE);
testRequestCodeEncode(RequestCode.BATCH_ACK_MESSAGE);
testRequestCodeEncode(RequestCode.PEEK_MESSAGE);
testRequestCodeEncode(RequestCode.CHANGE_MESSAGE_INVISIBLETIME);
testRequestCodeEncode(RequestCode.NOTIFICATION);
testRequestCodeEncode(RequestCode.POLLING_INFO);
}

public void testRequestCodeEncode(int code) throws Exception {
ByteBuf buf = ByteBufAllocator.DEFAULT.buffer(16);
MyHeader1 header1 = new MyHeader1();
header1.setStr("s1");
header1.setNum(100);
RemotingCommand cmd = RemotingCommand.createRequestCommand(code, header1);
cmd.setRemark("remark");
cmd.setOpaque(1001);
cmd.setVersion(99);
cmd.setLanguage(LanguageCode.JAVA);
cmd.setFlag(3);
cmd.makeCustomHeaderToNet();
RocketMQSerializable.rocketMQProtocolEncode(cmd, buf);
RemotingCommand cmd2 = RocketMQSerializable.rocketMQProtocolDecode(buf, buf.readableBytes());
assertThat(cmd2.getRemark()).isEqualTo("remark");
assertThat(cmd2.getCode()).isEqualTo(code);
assertThat(cmd2.getOpaque()).isEqualTo(1001);
assertThat(cmd2.getVersion()).isEqualTo(99);
assertThat(cmd2.getLanguage()).isEqualTo(LanguageCode.JAVA);
assertThat(cmd2.getFlag()).isEqualTo(3);

MyHeader1 h2 = (MyHeader1) cmd2.decodeCommandCustomHeader(MyHeader1.class);
assertThat(h2.getStr()).isEqualTo("s1");
assertThat(h2.getNum()).isEqualTo(100);
}
}
Loading