Skip to content
Open
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 @@ -65,13 +65,13 @@ protected RemotingCommand request(ChannelHandlerContext ctx, RemotingCommand req
ProxyContext context, long timeoutMillis) throws Exception {
String brokerName;
if (request.getCode() == RequestCode.SEND_MESSAGE_V2 || request.getCode() == RequestCode.SEND_BATCH_MESSAGE) {
if (request.getExtFields().get(BROKER_NAME_FIELD_FOR_SEND_MESSAGE_V2) == null) {
if (request.getExtFields() == null || request.getExtFields().get(BROKER_NAME_FIELD_FOR_SEND_MESSAGE_V2) == null) {
return RemotingCommand.buildErrorResponse(ResponseCode.VERSION_NOT_SUPPORTED,
"Request doesn't have field bname");
}
brokerName = request.getExtFields().get(BROKER_NAME_FIELD_FOR_SEND_MESSAGE_V2);
} else {
if (request.getExtFields().get(BROKER_NAME_FIELD) == null) {
if (request.getExtFields() == null || request.getExtFields().get(BROKER_NAME_FIELD) == null) {
return RemotingCommand.buildErrorResponse(ResponseCode.VERSION_NOT_SUPPORTED,
"Request doesn't have field bname");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,28 @@ public void testRequestInvalid() throws Exception {
verify(ctx, never()).writeAndFlush(any());
}

@Test
public void testRequestWithoutExtFieldsIsInvalid() throws Exception {
RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.PULL_MESSAGE, null);
request.setExtFields(null);

RemotingCommand remotingCommand = remotingActivity.request(ctx, request, null, 10000);

assertThat(remotingCommand.getCode()).isEqualTo(ResponseCode.VERSION_NOT_SUPPORTED);
verify(ctx, never()).writeAndFlush(any());
}

@Test
public void testSendMessageV2WithoutExtFieldsIsInvalid() throws Exception {
RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.SEND_MESSAGE_V2, null);
request.setExtFields(null);

RemotingCommand remotingCommand = remotingActivity.request(ctx, request, null, 10000);

assertThat(remotingCommand.getCode()).isEqualTo(ResponseCode.VERSION_NOT_SUPPORTED);
verify(ctx, never()).writeAndFlush(any());
}

@Test
public void testRequestProxyException() throws Exception {
ArgumentCaptor<RemotingCommand> captor = ArgumentCaptor.forClass(RemotingCommand.class);
Expand Down Expand Up @@ -199,4 +221,4 @@ public void testRequestDefaultException() throws Exception {
verify(ctx, times(1)).writeAndFlush(captor.capture());
assertThat(captor.getValue().getCode()).isEqualTo(ResponseCode.SYSTEM_ERROR);
}
}
}
Loading