System.out.println("++ runUnackedMultipleSession");
drainQueue();
final int iterationCount = getIterationCount();
QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = (Queue)context.lookup(TEST_QUEUE);
QueueSender sender = session.createSender(queue);
Message message = session.createBytesMessage();
((BytesMessage)message).writeBytes(PAYLOAD);
for (int i = 0; i < iterationCount; i++)
sender.send(message, persistence, 4, 0);
session.close();
QueueSession session1 = queueConnection.createQueueSession(false, Session.CLIENT_ACKNOWLEDGE);
QueueSession session2 = queueConnection.createQueueSession(false, Session.CLIENT_ACKNOWLEDGE);
try
{
queue = (Queue)context.lookup(TEST_QUEUE);
QueueReceiver receiver1 = session1.createReceiver(queue);
QueueReceiver receiver2 = session2.createReceiver(queue);
queueConnection.start();
int c1=0, c2=0;
Message messageConsumer1=null, messageConsumer2=null;
Message lastMessageConsumer1 = null, lastMessageConsumer2=null;
do
{
messageConsumer1 = receiver1.receive(1000);
messageConsumer2 = receiver2.receive(1000);
if (messageConsumer1 != null)
{
c1 ++;
lastMessageConsumer1 = messageConsumer1;
}
if (messageConsumer2 != null)
{
c2 ++;
lastMessageConsumer2 = messageConsumer2;
}
System.out.println("messageConsumer1=" + messageConsumer1 + " messageConsumer2=" + messageConsumer2 + " c1=" + c1 + " c2 = " + c2);
}
while (messageConsumer1!=null || messageConsumer2!=null);
assertEquals(iterationCount, c1 + c2);
if(lastMessageConsumer1 != null)
lastMessageConsumer1.acknowledge();
if(lastMessageConsumer2 != null)
lastMessageConsumer2.acknowledge();
queueConnection.stop();
session1.close();
session2.close();
}
finally
{
try
{
session1.close();
}
catch (Throwable ignored)
{
}
try
{
session2.close();
}
catch (Throwable ignored)
{
}
}