{
locator.setBlockOnNonDurableSend(true);
locator.setBlockOnDurableSend(true);
locator.setReconnectAttempts(-1);
ClientSessionFactoryInternal sf = createSessionFactoryAndWaitForTopology(locator, 2);
ClientSession session = createSession(sf, false, false);
session.createQueue(FailoverTestBase.ADDRESS, FailoverTestBase.ADDRESS, null, true);
ClientProducer producer = session.createProducer(FailoverTestBase.ADDRESS);
final int numMessages = 100;
for (int i = 0; i < numMessages; i++)
{
ClientMessage message = session.createMessage(i % 2 == 0);
setBody(i, message);
message.putIntProperty("counter", i);
producer.send(message);
}
crash(session);
Assert.assertTrue(session.isRollbackOnly());
try
{
session.commit();
Assert.fail("Should throw exception");
}
catch (HornetQException e)
{
Assert.assertEquals(HornetQException.TRANSACTION_ROLLED_BACK, e.getCode());
}
ClientMessage message = session.createMessage(false);
int counter = RandomUtil.randomInt();
message.putIntProperty("counter", counter);
producer.send(message);
// session is working again
session.commit();
session.start();
ClientConsumer consumer = session.createConsumer(FailoverTestBase.ADDRESS);
session.start();
message = consumer.receiveImmediate();
Assert.assertNotNull(message);
Assert.assertEquals(counter, message.getIntProperty("counter").intValue());
session.close();
sf.close();
Assert.assertEquals(0, sf.numSessions());
Assert.assertEquals(0, sf.numConnections());
}