AMQQueue queue = new org.apache.qpid.server.queue.AMQQueue(new AMQShortString("testQueue_" + System.currentTimeMillis()),
false,
new AMQShortString("test"),
true,
_protocolSession.getVirtualHost());
AMQChannel channel = new AMQChannel(_protocolSession,2, _messageStore, null);
channel.setDefaultQueue(queue);
_protocolSession.addChannel(channel);
channelCount = _mbean.channels().size();
assertTrue(channelCount == 2);
// general properties test
_mbean.setMaximumNumberOfChannels(1000L);
assertTrue(_mbean.getMaximumNumberOfChannels() == 1000L);
// check APIs
AMQChannel channel3 = new AMQChannel(_protocolSession,3, _messageStore, null);
channel3.setLocalTransactional();
_protocolSession.addChannel(channel3);
_mbean.rollbackTransactions(2);
_mbean.rollbackTransactions(3);
_mbean.commitTransactions(2);
_mbean.commitTransactions(3);
// This should throw exception, because the channel does't exist
try
{
_mbean.commitTransactions(4);
fail();
}
catch (JMException ex)
{
System.out.println("expected exception is thrown :" + ex.getMessage());
}
// check if closing of session works
_protocolSession.addChannel(new AMQChannel(_protocolSession,5, _messageStore, null));
_mbean.closeConnection();
try
{
channelCount = _mbean.channels().size();
assertTrue(channelCount == 0);
// session is now closed so adding another channel should throw an exception
_protocolSession.addChannel(new AMQChannel(_protocolSession,6, _messageStore, null));
fail();
}
catch(AMQException ex)
{
System.out.println("expected exception is thrown :" + ex.getMessage());