diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/implementation/ServiceBusRestProxy.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/implementation/ServiceBusRestProxy.java index 86a104fcaeadd..53c52808dd580 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/implementation/ServiceBusRestProxy.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/implementation/ServiceBusRestProxy.java @@ -183,6 +183,12 @@ else if (options.isPeekLock()) { throw new RuntimeException("Unknown ReceiveMode"); } + //No Messages Available scenario + //Q is empty or contains only LOCKED Messages during period specified by timeout + if (clientResult.getStatus() == 204) { + return null; + } + BrokerProperties brokerProperties; if (clientResult.getHeaders().containsKey("BrokerProperties")) { brokerProperties = mapper.fromString(clientResult.getHeaders().getFirst("BrokerProperties")); diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/serviceBus/ServiceBusIntegrationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/serviceBus/ServiceBusIntegrationTest.java index c09af13305b8b..d03fb0ce0097a 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/serviceBus/ServiceBusIntegrationTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/serviceBus/ServiceBusIntegrationTest.java @@ -47,6 +47,7 @@ import com.microsoft.windowsazure.services.serviceBus.models.ListTopicsResult; import com.microsoft.windowsazure.services.serviceBus.models.QueueInfo; import com.microsoft.windowsazure.services.serviceBus.models.ReceiveMessageOptions; +import com.microsoft.windowsazure.services.serviceBus.models.ReceiveQueueMessageResult; import com.microsoft.windowsazure.services.serviceBus.models.RuleInfo; import com.microsoft.windowsazure.services.serviceBus.models.SubscriptionInfo; import com.microsoft.windowsazure.services.serviceBus.models.TopicInfo; @@ -172,6 +173,20 @@ public void receiveMessageWorks() throws Exception { assertArrayEquals("Hello World".getBytes(), Arrays.copyOf(data, size)); } + @Test + public void receiveMessageEmptyQueueWorks() throws Exception { + // Arrange + String queueName = "TestReceiveMessageEmptyQueueWorks"; + service.createQueue(new QueueInfo(queueName)); + + // Act + ReceiveQueueMessageResult result = service.receiveQueueMessage(queueName, RECEIVE_AND_DELETE_5_SECONDS); + + //Assert + assertNotNull(result); + assertNull(result.getValue()); + } + @Test public void peekLockMessageWorks() throws Exception { // Arrange @@ -189,6 +204,20 @@ public void peekLockMessageWorks() throws Exception { assertEquals("Hello Again", new String(data, 0, size)); } + @Test + public void peekLockMessageEmptyQueueWorks() throws Exception { + // Arrange + String queueName = "TestPeekLockMessageEmptyQueueWorks"; + service.createQueue(new QueueInfo(queueName)); + + // Act + ReceiveQueueMessageResult result = service.receiveQueueMessage(queueName, PEEK_LOCK_5_SECONDS); + + // Assert + assertNotNull(result); + assertNull(result.getValue()); + } + @Test public void peekLockedMessageCanBeCompleted() throws Exception { // Arrange @@ -245,15 +274,16 @@ public void peekLockedMessageCanBeDeleted() throws Exception { String lockToken = peekedMessage.getLockToken(); Date lockedUntil = peekedMessage.getLockedUntilUtc(); - service.deleteMessage(peekedMessage); - BrokeredMessage receivedMessage = service.receiveQueueMessage(queueName, RECEIVE_AND_DELETE_5_SECONDS) - .getValue(); - // Assert assertNotNull(lockToken); assertNotNull(lockedUntil); - assertNull(receivedMessage.getLockToken()); - assertNull(receivedMessage.getLockedUntilUtc()); + + // Act + service.deleteMessage(peekedMessage); + ReceiveQueueMessageResult result = service.receiveQueueMessage(queueName, RECEIVE_AND_DELETE_5_SECONDS); + + //Assert + assertNull(result.getValue()); } @Test