public void DoTestRedelivery(int queuePrefetch, bool interleaveProducer)
{
(connection as Connection).PrefetchPolicy.QueuePrefetch = queuePrefetch;
connection.Start();
if(interleaveProducer)
{
PopulateDestinationWithInterleavedProducer(nbMessages, destinationName);
}
else
{
PopulateDestination(nbMessages, destinationName);
}
// Consume messages and Rollback transactions
{
int received = 0;
IDictionary rolledback = Hashtable.Synchronized(new Hashtable());
while(received < nbMessages)
{
ISession session = connection.CreateSession(AcknowledgementMode.Transactional);
IDestination destination = session.GetQueue(destinationName);
IMessageConsumer consumer = session.CreateConsumer(destination);
ITextMessage msg = (ITextMessage) consumer.Receive(TimeSpan.FromMilliseconds(6000000));
if(msg != null)
{
if(msg != null && rolledback.Contains(msg.Text))
{
Interlocked.Increment(ref received);
Assert.IsTrue(msg.NMSRedelivered);
Assert.AreEqual(2, msg.Properties.GetLong("NMSXDeliveryCount"));
session.Commit();
}
else
{
Assert.IsFalse(msg.NMSRedelivered);
rolledback.Add(msg.Text, (Boolean) true);
session.Rollback();
}
}
consumer.Close();
session.Close();
}
}
}