producer = producerSession.createProducer(queue);
Thread.sleep(1000);
//Create a JMX MBean proxy for the queue
ManagedQueue queueMBean = _jmxUtils.getManagedObject(ManagedQueue.class, _jmxUtils.getQueueObjectName("test", queueName));
assertNotNull(queueMBean);
//check current attribute values are 0 as expected
assertTrue("Capacity was not the expected value", queueMBean.getCapacity() == 0L);
assertTrue("FlowResumeCapacity was not the expected value", queueMBean.getFlowResumeCapacity() == 0L);
//set new values that will cause flow control to be active, and the queue to become overfull after 1 message is sent
queueMBean.setCapacity(250L);
queueMBean.setFlowResumeCapacity(250L);
assertTrue("Capacity was not the expected value", queueMBean.getCapacity() == 250L);
assertTrue("FlowResumeCapacity was not the expected value", queueMBean.getFlowResumeCapacity() == 250L);
assertFalse("Queue should not be overfull", queueMBean.isFlowOverfull());
// try to send 2 messages (should block after 1)
sendMessagesAsync(producer, producerSession, 2, 50L);
Thread.sleep(2000);
//check only 1 message was sent, and queue is overfull
assertEquals("Incorrect number of message sent before blocking", 1, _sentMessages.get());
assertTrue("Queue should be overfull", queueMBean.isFlowOverfull());
//raise the attribute values, causing the queue to become underfull and allow the second message to be sent.
queueMBean.setCapacity(300L);
queueMBean.setFlowResumeCapacity(300L);
Thread.sleep(2000);
//check second message was sent, and caused the queue to become overfull again
assertEquals("Second message was not sent after lifting FlowResumeCapacity", 2, _sentMessages.get());
assertTrue("Queue should be overfull", queueMBean.isFlowOverfull());
//raise capacity above queue depth, check queue remains overfull as FlowResumeCapacity still exceeded
queueMBean.setCapacity(700L);
assertTrue("Queue should be overfull", queueMBean.isFlowOverfull());
//receive a message, check queue becomes underfull
consumer = consumerSession.createConsumer(queue);
consumerConnection.start();
consumer.receive();
//perform a synchronous op on the connection
((AMQSession<?,?>) consumerSession).sync();
assertFalse("Queue should not be overfull", queueMBean.isFlowOverfull());
consumer.receive();
}