Skip to content

Commit 2d634d1

Browse files
authored
Fixing a regression caused by upgrading to proton-j version 1.31. Fix addresses the case where a property value is null. (#321)
1 parent 0387311 commit 2d634d1

File tree

4 files changed

+50
-1
lines changed

4 files changed

+50
-1
lines changed

azure-servicebus/src/main/java/com/microsoft/azure/servicebus/MessageConverter.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,14 @@ else if (body instanceof AmqpSequence)
145145
}
146146
else
147147
{
148-
convertedProperties.put(entry.getKey(), entry.getValue().toString());
148+
if(entry.getValue() == null)
149+
{
150+
convertedProperties.put(entry.getKey(), null);
151+
}
152+
else
153+
{
154+
convertedProperties.put(entry.getKey(), entry.getValue().toString());
155+
}
149156
}
150157
}
151158

azure-servicebus/src/test/java/com/microsoft/azure/servicebus/SendReceiveTests.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,13 @@ public void testBasicReceiveAndComplete() throws InterruptedException, ServiceBu
152152
TestCommons.testBasicReceiveAndComplete(this.sender, this.sessionId, this.receiver);
153153
}
154154

155+
@Test
156+
public void testBasicReceiveAndCompleteMessageWithProperties() throws InterruptedException, ServiceBusException, ExecutionException
157+
{
158+
this.receiver = ClientFactory.createMessageReceiverFromEntityPath(factory, this.receiveEntityPath, ReceiveMode.PEEKLOCK);
159+
TestCommons.testBasicReceiveAndCompleteMessageWithProperties(this.sender, this.sessionId, this.receiver);
160+
}
161+
155162
@Test
156163
public void testBasicReceiveAndAbandon() throws InterruptedException, ServiceBusException, ExecutionException
157164
{

azure-servicebus/src/test/java/com/microsoft/azure/servicebus/SessionTests.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,14 @@ public void testBasicReceiveAndComplete() throws InterruptedException, ServiceBu
163163
TestCommons.testBasicReceiveAndComplete(this.sender, sessionId, this.session);
164164
}
165165

166+
@Test
167+
public void testBasicReceiveAndCompleteMessageWithProperties() throws InterruptedException, ServiceBusException, ExecutionException
168+
{
169+
String sessionId = TestUtils.getRandomString();
170+
this.session = ClientFactory.acceptSessionFromEntityPath(this.factory, this.receiveEntityPath, sessionId, ReceiveMode.PEEKLOCK);
171+
TestCommons.testBasicReceiveAndCompleteMessageWithProperties(this.sender, sessionId, this.session);
172+
}
173+
166174
@Test
167175
public void testBasicReceiveAndAbandon() throws InterruptedException, ServiceBusException, ExecutionException
168176
{

azure-servicebus/src/test/java/com/microsoft/azure/servicebus/TestCommons.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.util.Iterator;
1010
import java.util.LinkedList;
1111
import java.util.List;
12+
import java.util.Map;
1213
import java.util.UUID;
1314
import java.util.concurrent.CompletableFuture;
1415
import java.util.concurrent.ExecutionException;
@@ -186,6 +187,32 @@ public static void testBasicReceiveAndComplete(IMessageSender sender, String ses
186187
Assert.assertNull("Message was not properly completed", receivedMessage);
187188
}
188189

190+
public static void testBasicReceiveAndCompleteMessageWithProperties(IMessageSender sender, String sessionId, IMessageReceiver receiver) throws InterruptedException, ServiceBusException, ExecutionException
191+
{
192+
String messageId = UUID.randomUUID().toString();
193+
Message message = new Message("AMQP message");
194+
message.setMessageId(messageId);
195+
if(sessionId != null)
196+
{
197+
message.setSessionId(sessionId);
198+
}
199+
HashMap<String, String> messageProps = new HashMap<>();
200+
messageProps.put("key1", "value1");
201+
messageProps.put("key2", null); // Some customers are using it this way
202+
message.setProperties(messageProps);
203+
sender.send(message);
204+
205+
IMessage receivedMessage = receiver.receive();
206+
Assert.assertNotNull("Message not received", receivedMessage);
207+
Assert.assertEquals("Message Id did not match", messageId, receivedMessage.getMessageId());
208+
Map<String, String> receivedProps = receivedMessage.getProperties();
209+
Assert.assertEquals("All sent properties not recieved", "value1", receivedProps.get("key1"));
210+
Assert.assertNull("Property with null value not received", receivedProps.get("key2"));
211+
receiver.complete(receivedMessage.getLockToken());
212+
receivedMessage = receiver.receive(SHORT_WAIT_TIME);
213+
Assert.assertNull("Message was not properly completed", receivedMessage);
214+
}
215+
189216
public static void testBasicReceiveAndAbandon(IMessageSender sender, String sessionId, IMessageReceiver receiver) throws InterruptedException, ServiceBusException, ExecutionException
190217
{
191218
String messageId = UUID.randomUUID().toString();

0 commit comments

Comments
 (0)