// make sure that failover timeout is bigger than flow control timeout
setTestSystemProperty("qpid.failover_method_timeout", "60000");
setTestSystemProperty("qpid.flow_control_wait_failure", "10000");
AMQConnection connection = null;
try
{
connection = createConnectionWithFailover();
final Session producerSession = connection.createSession(true, Session.SESSION_TRANSACTED);
final Queue queue = createAndBindQueueWithFlowControlEnabled(producerSession, getTestQueueName(), DEFAULT_MESSAGE_SIZE * 3, DEFAULT_MESSAGE_SIZE * 2);
final AtomicInteger counter = new AtomicInteger();
// try to send 5 messages (should block after 4)
new Thread(new Runnable()
{
@Override
public void run()
{
try
{
MessageProducer producer = producerSession.createProducer(queue);
for (int i=0; i < 5; i++)
{
Message next = createNextMessage(producerSession, i);
producer.send(next);
producerSession.commit();
counter.incrementAndGet();
}
}
catch(Exception e)
{
// ignore
}
}
}).start();
long limit= 30000l;
long start = System.currentTimeMillis();
// wait until session is blocked
while(!((AMQSession<?,?>)producerSession).isFlowBlocked() && System.currentTimeMillis() - start < limit)
{
Thread.sleep(100l);
}
assertTrue("Flow is not blocked", ((AMQSession<?, ?>) producerSession).isFlowBlocked());
// Message counter could be 3 or 4 depending on the progression of producing thread relative
// to the receipt of the ChannelFlow.
final int currentCounter = counter.get();
assertTrue("Unexpected number of sent messages", currentCounter == 3 || currentCounter == 4);
killBroker();
startBroker();
// allows the failover thread to proceed
Thread.yield();
awaitForFailoverCompletion(60000l);
assertFalse("Flow is blocked", ((AMQSession<?, ?>) producerSession).isFlowBlocked());
}
finally
{
if (connection != null)
{
connection.close();
}
}
}