* Tests a requeue for a queue with multiple subscriptions. Verifies that a
* subscriber specific requeue resends the message to <i>that</i> subscriber.
*/
public void testSubscriptionSpecificRequeueForQueueWithMultipleSubscriptions() throws Exception
{
MockSubscription subscription1 = new MockSubscription();
MockSubscription subscription2 = new MockSubscription();
_queue.registerSubscription(subscription1, false);
_queue.registerSubscription(subscription2, false);
final ArrayList<QueueEntry> queueEntries = new ArrayList<QueueEntry>();
PostEnqueueAction postEnqueueAction = new PostEnqueueAction()
{
public void onEnqueue(QueueEntry entry)
{
queueEntries.add(entry);
}
};
AMQMessage messageA = createMessage(new Long(24));
AMQMessage messageB = createMessage(new Long(25));
/* Enqueue two messages */
_queue.enqueue(messageA, postEnqueueAction);
_queue.enqueue(messageB, postEnqueueAction);
Thread.sleep(150); // Work done by SubFlushRunner Thread
assertEquals("Unexpected total number of messages sent to subscription1 after enqueue", 1, subscription1.getMessages().size());
assertEquals("Unexpected total number of messages sent to subscription2 after enqueue", 1, subscription2.getMessages().size());
/* Now requeue a message (for first subscription) */
queueEntries.get(0).release();
_queue.requeue((QueueEntryImpl)queueEntries.get(0), subscription1);
Thread.sleep(150); // Work done by SubFlushRunner Thread
assertEquals("Unexpected total number of messages sent to subscription1 after requeue", 2, subscription1.getMessages().size());
assertEquals("Unexpected total number of messages sent to subscription2 after requeue", 1, subscription2.getMessages().size());
assertNull("releasedEntry should be cleared after requeue processed", ((QueueContext)subscription1.getQueueContext())._releasedEntry);
assertNull("releasedEntry should be cleared after requeue processed", ((QueueContext)subscription2.getQueueContext())._releasedEntry);
}