Skip to content

Commit

Permalink
Merge pull request #34 from gcheng/emptyQueue
Browse files Browse the repository at this point in the history
fix empty queue scenario.
  • Loading branch information
Albert Cheng committed Apr 22, 2013
2 parents bdc1c7d + 4975d23 commit 2fe266a
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ else if (options.isPeekLock()) {
throw new RuntimeException("Unknown ReceiveMode");
}

if (clientResult.getStatus() == 204) {
return null;
}

BrokerProperties brokerProperties;
if (clientResult.getHeaders().containsKey("BrokerProperties")) {
brokerProperties = mapper.fromString(clientResult.getHeaders().getFirst("BrokerProperties"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -172,6 +173,21 @@ 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 receiveQueueMessageResult = service.receiveQueueMessage(queueName,
RECEIVE_AND_DELETE_5_SECONDS);

// Assert
assertNotNull(receiveQueueMessageResult);
assertNull(receiveQueueMessageResult.getValue());
}

@Test
public void peekLockMessageWorks() throws Exception {
// Arrange
Expand All @@ -189,6 +205,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
Expand Down Expand Up @@ -252,8 +282,20 @@ public void peekLockedMessageCanBeDeleted() throws Exception {
// Assert
assertNotNull(lockToken);
assertNotNull(lockedUntil);
assertNull(receivedMessage.getLockToken());
assertNull(receivedMessage.getLockedUntilUtc());
assertNull(receivedMessage);
}

@Test
public void emptyQueueReturnsNullMessage() throws Exception {
// Arrange
String queueName = "testEmptyQueueReturnsNullMessage";
service.createQueue(new QueueInfo(queueName));

// Act
BrokeredMessage brokeredMessage = service.receiveQueueMessage(queueName, PEEK_LOCK_5_SECONDS).getValue();

// Assert
assertNull(brokeredMessage);
}

@Test
Expand Down

0 comments on commit 2fe266a

Please sign in to comment.