Skip to content

Commit

Permalink
Adding missing boolean type support in Message properties. (Azure#251)
Browse files Browse the repository at this point in the history
  • Loading branch information
yvgopal authored Jul 21, 2018
1 parent dce22da commit 13b05b7
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public final class AmqpErrorCode
public static final Symbol InternalError = Symbol.getSymbol("amqp:internal-error");
public static final Symbol IllegalState = Symbol.getSymbol("amqp:illegal-state");
public static final Symbol NotImplemented = Symbol.getSymbol("amqp:not-implemented");
public static final Symbol DecodeError = Symbol.getSymbol("amqp:decode-error");

// link errors
public static final Symbol Stolen = Symbol.getSymbol("amqp:link:stolen");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ else if (errorCondition.getCondition() == ClientConstants.ENTITY_ALREADY_EXISTS_
{
return new MessagingEntityAlreadyExistsException(errorCondition.getDescription());
}
else if (errorCondition.getCondition() == AmqpErrorCode.DecodeError)
{
return new ServiceBusException(false, new AmqpException(errorCondition));
}

return new ServiceBusException(ClientConstants.DEFAULT_IS_TRANSIENT, errorCondition.toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ static int sizeof(Object obj)
return Short.BYTES;
}

if (obj instanceof Boolean)
{
return 1;
}

if (obj instanceof Character)
{
return 4;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,13 @@ public void testReceiveBySequenceNumberAndDeadletter() throws InterruptedExcepti
TestCommons.testReceiveBySequenceNumberAndDeadletter(this.sender, this.sessionId, this.receiver);
}

@Test
public void testSendReceiveMessageWithVariousPropertyTypes() throws InterruptedException, ServiceBusException
{
this.receiver = ClientFactory.createMessageReceiverFromEntityPath(factory, this.receiveEntityPath, ReceiveMode.RECEIVEANDDELETE);
TestCommons.testSendReceiveMessageWithVariousPropertyTypes(this.sender, this.sessionId, this.receiver);
}

private void drainAllMessages() throws InterruptedException, ServiceBusException
{
if(this.receiver != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,14 @@ public void testReceiveBySequenceNumberAndDeadletter() throws InterruptedExcepti
TestCommons.testReceiveBySequenceNumberAndDeadletter(this.sender, sessionId, this.session);
}

@Test
public void testSendReceiveMessageWithVariousPropertyTypes() throws InterruptedException, ServiceBusException
{
String sessionId = TestUtils.getRandomString();
this.session = ClientFactory.acceptSessionFromEntityPath(this.factory, this.receiveEntityPath, sessionId, ReceiveMode.RECEIVEANDDELETE);
TestCommons.testSendReceiveMessageWithVariousPropertyTypes(this.sender, sessionId, this.session);
}

@Test
public void testAcceptAnySession() throws InterruptedException, ServiceBusException
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
Expand Down Expand Up @@ -507,6 +508,59 @@ public static void testReceiveBySequenceNumberAndDeadletter(IMessageSender sende
// Expected
}
}

public static void testSendReceiveMessageWithVariousPropertyTypes(IMessageSender sender, String sessionId, IMessageReceiver receiver) throws InterruptedException, ServiceBusException
{
Map<String, Object> sentProperties = new HashMap<>();
sentProperties.put("NullProperty", null);
sentProperties.put("BooleanProperty", true);
sentProperties.put("ByteProperty", (byte)1);
sentProperties.put("ShortProperty", (short)2);
sentProperties.put("IntProperty", 3);
sentProperties.put("LongProperty", 4l);
sentProperties.put("FloatProperty", 5.5f);
sentProperties.put("DoubleProperty", 6.6f);
sentProperties.put("CharProperty", 'z');
sentProperties.put("UUIDProperty", UUID.randomUUID());
sentProperties.put("StringProperty", "string");

// These additional types are not supported in message properties by Azure Service Bus
// sentProperties.put("ArrayProperty", new Object[]{1, 2, 3, 4, 5});
// List<Integer> list = new ArrayList<>();
// list.add(10);
// list.add(11);
// sentProperties.put("ListProperty", list);
// Map<String, Object> map = new HashMap<>();
// map.put("key1", 20);
// map.put("key2", "thirty");
// sentProperties.put("MapProperty", map);

String messageId = UUID.randomUUID().toString();
Message message = new Message("AMQP message");
message.setMessageId(messageId);
if(sessionId != null)
{
message.setSessionId(sessionId);
}
message.getProperties().putAll(sentProperties);
sender.send(message);

IMessage receivedMessage = receiver.receive();
Assert.assertNotNull("Message not received", receivedMessage);
Assert.assertEquals("Message Id did not match", messageId, receivedMessage.getMessageId());
Map<String, Object> receivedProperties = receivedMessage.getProperties();
for(Map.Entry<String, Object> sentEntry : sentProperties.entrySet())
{
if(sentEntry.getValue() != null && sentEntry.getValue().getClass().isArray())
{
Assert.assertArrayEquals("Sent property didn't match with received property", (Object[])sentEntry.getValue(), (Object[])receivedProperties.get(sentEntry.getKey()));
}
else
{
Assert.assertEquals("Sent property didn't match with received property", sentEntry.getValue(), receivedProperties.get(sentEntry.getKey()));
}
}
}

public static void testGetMessageSessions(IMessageSender sender, Object sessionsClient) throws InterruptedException, ServiceBusException
{
Expand Down

0 comments on commit 13b05b7

Please sign in to comment.