Skip to content

Commit

Permalink
Allow null sender when using DatagramPacketEncoder (#9204)
Browse files Browse the repository at this point in the history
Motivation:

It is valid to use null as sender so we should support it when DatagramPacketEncoder checks if it supports the message.

Modifications:

- Add null check
- Add unit test

Result:

Fixes #9199.
  • Loading branch information
normanmaurer committed Jun 3, 2019
1 parent a635847 commit 4b8db65
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public boolean acceptOutboundMessage(Object msg) throws Exception {
@SuppressWarnings("rawtypes")
AddressedEnvelope envelope = (AddressedEnvelope) msg;
return encoder.acceptOutboundMessage(envelope.content())
&& envelope.sender() instanceof InetSocketAddress
&& (envelope.sender() instanceof InetSocketAddress || envelope.sender() == null)
&& envelope.recipient() instanceof InetSocketAddress;
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,17 @@ public void tearDown() {

@Test
public void testEncode() {
testEncode(false);
}

@Test
public void testEncodeWithSenderIsNull() {
testEncode(true);
}

private void testEncode(boolean senderIsNull) {
InetSocketAddress recipient = SocketUtils.socketAddress("127.0.0.1", 10000);
InetSocketAddress sender = SocketUtils.socketAddress("127.0.0.1", 20000);
InetSocketAddress sender = senderIsNull ? null : SocketUtils.socketAddress("127.0.0.1", 20000);
assertTrue(channel.writeOutbound(
new DefaultAddressedEnvelope<>("netty", recipient, sender)));
DatagramPacket packet = channel.readOutbound();
Expand Down

0 comments on commit 4b8db65

Please sign in to comment.