Assert.assertEquals(0, sf.numConnections());
}
public void testTransactedMessagesNotConsumedSoNoRollback() throws Exception
{
ClientSessionFactoryInternal sf = getSessionFactory();
sf.setBlockOnNonDurableSend(true);
sf.setBlockOnDurableSend(true);
ClientSession session1 = sf.createSession(false, false);
session1.createQueue(FailoverTestBase.ADDRESS, FailoverTestBase.ADDRESS, null, true);
final CountDownLatch latch = new CountDownLatch(1);
class MyListener extends BaseListener
{
public void connectionFailed(final HornetQException me)
{
latch.countDown();
}
}
session1.addFailureListener(new MyListener());
ClientProducer producer = session1.createProducer(FailoverTestBase.ADDRESS);
final int numMessages = 100;
for (int i = 0; i < numMessages; i++)
{
ClientMessage message = session1.createMessage(true);
setBody(i, message);
message.putIntProperty("counter", i);
producer.send(message);
}
session1.commit();
ClientSession session2 = sf.createSession(false, false);
ClientConsumer consumer = session2.createConsumer(FailoverTestBase.ADDRESS);
session2.start();
for (int i = 0; i < numMessages / 2; i++)
{
ClientMessage message = consumer.receive(1000);
Assert.assertNotNull(message);
assertMessageBody(i, message);
Assert.assertEquals(i, message.getIntProperty("counter").intValue());
message.acknowledge();
}
session2.commit();
consumer.close();
fail(session2, latch);
Assert.assertFalse(session2.isRollbackOnly());
consumer = session2.createConsumer(FailoverTestBase.ADDRESS);
for (int i = numMessages / 2; i < numMessages; i++)
{
ClientMessage message = consumer.receive(1000);
Assert.assertNotNull(message);
assertMessageBody(i, message);
Assert.assertEquals(i, message.getIntProperty("counter").intValue());
message.acknowledge();
}
session2.commit();
Assert.assertNull(consumer.receiveImmediate());
session1.close();
session2.close();
Assert.assertEquals(0, sf.numSessions());
Assert.assertEquals(0, sf.numConnections());
}