final int totalrepeats = 3;
final AtomicInteger errors = new AtomicInteger(0);
// We shouldn't have more than 10K messages pending
final Semaphore semop = new Semaphore(10000);
class ConsumerThread extends Thread
{
public void run()
{
try
{
ServerLocator locator = HornetQClient.createServerLocatorWithoutHA(server1tc);
ClientSessionFactory sf = locator.createSessionFactory();
ClientSession session = sf.createSession(false, false);
session.start();
ClientConsumer consumer = session.createConsumer(queueName1);
for (int i = 0; i < numMessages; i++)
{
ClientMessage message = consumer.receive(5000);
Assert.assertNotNull(message);
message.acknowledge();
semop.release();
if (i % 1000 == 0)
{
session.commit();
}
}
session.commit();
session.close();
sf.close();
locator.close();
}
catch (Throwable e)
{
e.printStackTrace();
errors.incrementAndGet();
}
}
};
class ProducerThread extends Thread
{
final int nmsg;
ProducerThread(int nmsg)
{
this.nmsg = nmsg;
}
public void run()
{
ServerLocator locator = HornetQClient.createServerLocatorWithoutHA(server0tc);
locator.setBlockOnDurableSend(false);
locator.setBlockOnNonDurableSend(false);
ClientSessionFactory sf = null;
ClientSession session = null;
ClientProducer producer = null;
try
{
sf = locator.createSessionFactory();
session = sf.createSession(false, true, true);
producer = session.createProducer(new SimpleString(testAddress));
for (int i = 0; i < nmsg; i++)
{
assertEquals(0, errors.get());
ClientMessage message = session.createMessage(true);
message.putIntProperty("seq", i);
if (i % 100 == 0)
{
message.setPriority((byte)(RandomUtil.randomPositiveInt() % 9));
}
else
{
message.setPriority((byte)5);
}
message.getBodyBuffer().writeBytes(new byte[50]);
producer.send(message);
assertTrue(semop.tryAcquire(1, 10, TimeUnit.SECONDS));
}
}
catch (Throwable e)
{
e.printStackTrace(System.out);