未验证 提交 7760bb4a 编写于 作者: C carlvine500 提交者: GitHub

[ISSUE #1463] Skip encode the null value property as string "null" (#1899)

* Update MessageDecoder.java
* add test case for MessageDecoder
上级 276536ed
......@@ -414,6 +414,9 @@ public class MessageDecoder {
final String name = entry.getKey();
final String value = entry.getValue();
if (value == null) {
continue;
}
sb.append(name);
sb.append(NAME_VALUE_SEPARATOR);
sb.append(value);
......
......@@ -246,4 +246,23 @@ public class MessageDecoderTest {
assertThat("abc").isEqualTo(decodedMsg.getTopic());
}
}
public void testNullValueProperty() throws Exception {
MessageExt msg = new MessageExt();
msg.setBody("x".getBytes());
msg.setTopic("x");
msg.setBornHost(new InetSocketAddress("127.0.0.1", 9000));
msg.setStoreHost(new InetSocketAddress("127.0.0.1", 9000));
String key = "NullValueKey";
msg.putProperty(key, null);
try {
byte[] encode = MessageDecoder.encode(msg, false);
MessageExt decode = MessageDecoder.decode(ByteBuffer.wrap(encode));
assertThat(decode.getProperty(key)).isNull();
} catch (Exception e) {
e.printStackTrace();
assertThat(Boolean.FALSE).isTrue();
}
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册