ClientSessionFactory sf = locator.createSessionFactory();
ClientSession session = sf.createSession(false, false, false);
Queue q1 = server.createQueue(ADDRESS, ADDRESS, null, true, false);
Queue q2 = server.createQueue(ADDRESS, new SimpleString("inactive"), null, true, false);
ClientProducer producer = session.createProducer(PagingTest.ADDRESS);
byte[] body = new byte[messageSize];
ByteBuffer bb = ByteBuffer.wrap(body);
for (int j = 1; j <= messageSize; j++)
{
bb.put(getSamplebyte(j));
}
final AtomicInteger errors = new AtomicInteger(0);
Thread t1 = new Thread()
{
public void run()
{
try
{
ServerLocator sl = createInVMNonHALocator();
ClientSessionFactory sf = sl.createSessionFactory();
ClientSession sess = sf.createSession(true, true, 0);
sess.start();
ClientConsumer cons = sess.createConsumer(ADDRESS);
for (int i = 0; i < numberOfMessages; i++)
{
ClientMessage msg = cons.receive(5000);
assertNotNull(msg);
assertEquals(i, msg.getIntProperty("id").intValue());
msg.acknowledge();
}
assertNull(cons.receiveImmediate());
sess.close();
sl.close();
}
catch (Throwable e)
{
e.printStackTrace();
errors.incrementAndGet();
}
}
};
t1.start();
for (int i = 0; i < numberOfMessages; i++)
{
ClientMessage message = session.createMessage(persistentMessages);
HornetQBuffer bodyLocal = message.getBodyBuffer();
bodyLocal.writeBytes(body);
message.putIntProperty(new SimpleString("id"), i);
producer.send(message);
if (i % 20 == 0)
{
session.commit();
}
}
session.commit();
t1.join();
assertEquals(0, errors.get());
assertEquals(numberOfMessages, q2.getMessageCount());
assertEquals(numberOfMessages, q2.getMessagesAdded());
assertEquals(0, q1.getMessageCount());
assertEquals(numberOfMessages, q1.getMessagesAdded());
session.close();
sf.close();
locator.close();
server.stop();
server.start();
Bindings bindings = server.getPostOffice().getBindingsForAddress(ADDRESS);
q1 = null;
q2 = null;
for (Binding bind : bindings.getBindings())
{
if (bind instanceof LocalQueueBinding)
{
LocalQueueBinding qb = (LocalQueueBinding)bind;
if (qb.getQueue().getName().equals(ADDRESS))
{
q1 = qb.getQueue();
}
if (qb.getQueue().getName().equals(new SimpleString("inactive")))
{
q2 = qb.getQueue();
}
}
}
assertNotNull(q1);
assertNotNull(q2);
assertEquals(numberOfMessages, q2.getMessageCount());
assertEquals(numberOfMessages, q2.getMessagesAdded());
assertEquals(0, q1.getMessageCount());
// 0, since nothing was sent to the queue after the server was restarted
assertEquals(0, q1.getMessagesAdded());
}