locator.setBlockOnNonDurableSend(true);
locator.setBlockOnDurableSend(true);
locator.setBlockOnAcknowledge(true);
ClientSessionFactory sf = locator.createSessionFactory();
ClientSession session = sf.createSession(false, false, false);
if (divert)
{
session.createQueue(PagingTest.ADDRESS + "-1", PagingTest.ADDRESS + "-1", null, true);
session.createQueue(PagingTest.ADDRESS + "-2", PagingTest.ADDRESS + "-2", null, true);
}
else
{
session.createQueue(PagingTest.ADDRESS.toString(), PagingTest.ADDRESS + "-1", null, true);
session.createQueue(PagingTest.ADDRESS.toString(), PagingTest.ADDRESS + "-2", null, true);
}
ClientProducer producer = session.createProducer(PagingTest.ADDRESS);
ClientMessage message = null;
for (int i = 0; i < numberOfMessages; i++)
{
if (i % 500 == 0)
{
log.info("Sent " + i + " messages");
session.commit();
}
message = session.createMessage(true);
HornetQBuffer bodyLocal = message.getBodyBuffer();
bodyLocal.writeBytes(body);
message.putIntProperty(new SimpleString("id"), i);
producer.send(message);
}
session.commit();
session.close();
server.stop();
sf.close();
locator.close();
}
server = createServer(true,
config,
PagingTest.PAGE_SIZE,
PagingTest.PAGE_MAX,
new HashMap<String, AddressSettings>());
server.start();
Queue queue1 = server.locateQueue(PagingTest.ADDRESS.concat("-1"));
Queue queue2 = server.locateQueue(PagingTest.ADDRESS.concat("-2"));
assertNotNull(queue1);
assertNotNull(queue2);
assertNotSame(queue1, queue2);
tcount1 = new TCount(queue1);
tcount2 = new TCount(queue2);
tcount1.start();
tcount2.start();
ServerLocator locator = createInVMNonHALocator();
final ClientSessionFactory sf2 = locator.createSessionFactory();
final AtomicInteger errors = new AtomicInteger(0);
Thread threads[] = new Thread[2];
for (int start = 1; start <= 2; start++)
{
final String addressToSubscribe = PagingTest.ADDRESS + "-" + start;
threads[start - 1] = new Thread()
{
public void run()
{
try
{
ClientSession session = sf2.createSession(null, null, false, true, true, false, 0);
ClientConsumer consumer = session.createConsumer(addressToSubscribe);
session.start();
for (int i = 0; i < numberOfMessages; i++)
{
ClientMessage message2 = consumer.receive(PagingTest.RECEIVE_TIMEOUT);
Assert.assertNotNull(message2);
Assert.assertEquals(i, message2.getIntProperty("id").intValue());
message2.acknowledge();
Assert.assertNotNull(message2);
if (i % 100 == 0)
{
if (i % 5000 == 0)
{
log.info(addressToSubscribe + " consumed " + i + " messages");
}
session.commit();
}
try
{
assertBodiesEqual(body, message2.getBodyBuffer());
}
catch (AssertionFailedError e)
{
PagingTest.log.info("Expected buffer:" + UnitTestCase.dumbBytesHex(body, 40));
PagingTest.log.info("Arriving buffer:" + UnitTestCase.dumbBytesHex(message2.getBodyBuffer()
.toByteBuffer()
.array(), 40));
throw e;
}
}
session.commit();
consumer.close();
session.close();
}
catch (Throwable e)
{
e.printStackTrace();
errors.incrementAndGet();
}
}
};
}
for (int i = 0; i < 2; i++)
{
threads[i].start();
}
for (int i = 0; i < 2; i++)
{
threads[i].join();
}
sf2.close();
locator.close();
assertEquals(0, errors.get());
for (int i = 0; i < 20 && server.getPostOffice().getPagingManager().getTransactions().size() != 0; i++)