Skip to content

Commit

Permalink
dubbo: fix dubbo heart beat response (#18001)
Browse files Browse the repository at this point in the history
Risk Level: low
Testing: Added.
Fixes Issue: #17996
Docs Changes: N/A.
Release Notes: N/A.
Platform Specific Features: N/A.

Signed-off-by: wbpcode <wbphub@live.com>
  • Loading branch information
wbpcode authored Sep 7, 2021
1 parent ff9704e commit 94153b4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,11 @@ bool DubboProtocolImpl::encode(Buffer::Instance& buffer, const MessageMetadata&
buffer.writeByte(flag);
buffer.writeByte(static_cast<uint8_t>(metadata.responseStatus()));
buffer.writeBEInt<uint64_t>(metadata.requestId());
buffer.writeBEInt<uint32_t>(0);
// Body of heart beat response is null.
// TODO(wbpcode): Currently we only support the Hessian2 serialization scheme, so here we
// directly use the 'N' for null object in Hessian2. This coupling should be unnecessary.
buffer.writeBEInt<uint32_t>(1u);
buffer.writeByte('N');
return true;
}
case MessageType::Response: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,21 @@ TEST(DubboProtocolImplTest, encode) {
EXPECT_TRUE(dubbo_protocol.decodeData(buffer, context, output_metadata));
}

TEST(DubboProtocolImplTest, HeartBeatResponseTest) {
MessageMetadata metadata;
metadata.setMessageType(MessageType::HeartbeatResponse);
metadata.setResponseStatus(ResponseStatus::Ok);
metadata.setSerializationType(SerializationType::Hessian2);
metadata.setRequestId(100);

Buffer::OwnedImpl buffer;
DubboProtocolImpl dubbo_protocol;
dubbo_protocol.initSerializer(SerializationType::Hessian2);
EXPECT_TRUE(dubbo_protocol.encode(buffer, metadata, "", RpcResponseType::ResponseWithValue));
// 16 bytes header and one byte null object body.
EXPECT_EQ(17, buffer.length());
}

TEST(DubboProtocolImplTest, decode) {
Buffer::OwnedImpl buffer;
MessageMetadataSharedPtr metadata;
Expand Down

0 comments on commit 94153b4

Please sign in to comment.