ObjectName destObjectName =
new ObjectName("jboss.messaging.destination:service=Queue,name=QueueMessageCounter");
//Most of this is tested in ServerPeerTest
MessageCounter counter = (MessageCounter)ServerManagement.getAttribute(destObjectName, "MessageCounter");
assertNotNull(counter);
assertEquals(0, counter.getCount());
assertEquals(0, counter.getCountDelta());
assertEquals(-1, counter.getHistoryLimit());
Connection conn = cf.createConnection();
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer prod = sess.createProducer(queue);
TextMessage tm1 = sess.createTextMessage("message1");
prod.send(tm1);
TextMessage tm2 = sess.createTextMessage("message2");
prod.send(tm2);
TextMessage tm3 = sess.createTextMessage("message3");
prod.send(tm3);
Thread.sleep(1500);
assertEquals(3, counter.getCount());
assertEquals(3, counter.getCountDelta());
assertEquals(3, counter.getCount());
assertEquals(0, counter.getCountDelta());
MessageStatistics stats = (MessageStatistics)ServerManagement.getAttribute(destObjectName, "MessageStatistics");
assertNotNull(stats);
assertEquals(3, stats.getCount());
assertEquals(0, stats.getCountDelta());
assertEquals(3, stats.getDepth());
ServerManagement.invoke(destObjectName, "resetMessageCounter", null, null);
assertEquals(0, counter.getCount());
ServerManagement.invoke(destObjectName, "resetMessageCounterHistory", null, null);
String html = (String)ServerManagement.invoke(destObjectName, "listMessageCounterHistoryAsHTML", null, null);