{
startHornetQServer(NettyAcceptorFactory.class.getName());
serverManager.createQueue(false, queueName, null, true, queueName);
Queue queue = HornetQJMSClient.createQueue(queueName);
JMSServerControl control = createManagementControl();
long startTime = System.currentTimeMillis();
String jsonStr = control.listConnectionsAsJSON();
assertNotNull(jsonStr);
JMSConnectionInfo[] infos = JMSConnectionInfo.from(jsonStr);
assertEquals(0, infos.length);
ConnectionFactory cf1 = JMSUtil.createFactory(NettyConnectorFactory.class.getName(),
JMSServerControl2Test.CONNECTION_TTL,
JMSServerControl2Test.PING_PERIOD);
Connection connection = cf1.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
TemporaryTopic temporaryTopic = session.createTemporaryTopic();
// create a regular message consumer
MessageConsumer consumer = session.createConsumer(queue);
jsonStr = control.listConnectionsAsJSON();
assertNotNull(jsonStr);
infos = JMSConnectionInfo.from(jsonStr);
assertEquals(1, infos.length);
String connectionID = infos[0].getConnectionID();
String consJsonStr = control.listConsumersAsJSON(connectionID);
assertNotNull(consJsonStr);
JMSConsumerInfo[] consumerInfos = JMSConsumerInfo.from(consJsonStr);
assertEquals(1, consumerInfos.length);
JMSConsumerInfo consumerInfo = consumerInfos[0];
assertNotNull(consumerInfo.getConsumerID());
assertEquals(connectionID, consumerInfo.getConnectionID());
assertEquals(queue.getQueueName(), consumerInfo.getDestinationName());
assertEquals("queue", consumerInfo.getDestinationType());
assertNull(consumerInfo.getFilter());
assertEquals(false, consumerInfo.isBrowseOnly());
assertEquals(false, consumerInfo.isDurable());
assertTrue(startTime <= consumerInfo.getCreationTime() && consumerInfo.getCreationTime() <= System.currentTimeMillis());
consumer.close();
consJsonStr = control.listConsumersAsJSON(connectionID);
assertNotNull(consJsonStr);
consumerInfos = JMSConsumerInfo.from(consJsonStr);
assertEquals(0, consumerInfos.length);
// create a queue browser
QueueBrowser browser = session.createBrowser(queue);
// the server resources are created when the browser starts enumerating
browser.getEnumeration();
consJsonStr = control.listConsumersAsJSON(connectionID);
assertNotNull(consJsonStr);
System.out.println(consJsonStr);
consumerInfos = JMSConsumerInfo.from(consJsonStr);
assertEquals(1, consumerInfos.length);
consumerInfo = consumerInfos[0];
assertNotNull(consumerInfo.getConsumerID());
assertEquals(connectionID, consumerInfo.getConnectionID());
assertEquals(queue.getQueueName(), consumerInfo.getDestinationName());
assertEquals("queue", consumerInfo.getDestinationType());
assertNull(consumerInfo.getFilter());
assertEquals(true, consumerInfo.isBrowseOnly());
assertEquals(false, consumerInfo.isDurable());
assertTrue(startTime <= consumerInfo.getCreationTime() && consumerInfo.getCreationTime() <= System.currentTimeMillis());
browser.close();
// create a regular consumer w/ filter on a temp topic
String filter = "color = 'red'";
consumer = session.createConsumer(temporaryTopic, filter);
consJsonStr = control.listConsumersAsJSON(connectionID);
assertNotNull(consJsonStr);
System.out.println(consJsonStr);
consumerInfos = JMSConsumerInfo.from(consJsonStr);
assertEquals(1, consumerInfos.length);
consumerInfo = consumerInfos[0];