}
//Create a temp queue
TemporaryQueue tempQueue = sess.createTemporaryQueue();
counters = (List)
ServerManagement.getAttribute(ServerManagement.getServerPeerObjectName(), "MessageCounters");
assertNotNull(counters);
//Should now be 7
assertEquals(7, counters.size());
//Send some messages
MessageProducer prod = sess.createProducer(null);
TextMessage tm1 = sess.createTextMessage("message1");
TextMessage tm2 = sess.createTextMessage("message2");
TextMessage tm3 = sess.createTextMessage("message3");
prod.send(queue1, tm1);
prod.send(queue1, tm2);
prod.send(queue1, tm3);
prod.send(queue2, tm1);
prod.send(queue2, tm2);
prod.send(queue2, tm3);
prod.send(queue3, tm1);
prod.send(queue3, tm2);
prod.send(queue3, tm3);
prod.send(tempQueue, tm1);
prod.send(tempQueue, tm2);
prod.send(tempQueue, tm3);
prod.send(topic1, tm1);
prod.send(topic1, tm2);
prod.send(topic1, tm3);
prod.send(topic2, tm1);
prod.send(topic2, tm2);
prod.send(topic2, tm3);
iter = counters.iterator();
//Wait until the stats are updated
Thread.sleep(1500);
while (iter.hasNext())
{
MessageCounter counter = (MessageCounter)iter.next();
assertEquals(3, counter.getCount());
assertEquals(3, counter.getCountDelta());
assertEquals(-1, counter.getHistoryLimit());
}
while (iter.hasNext())
{
MessageCounter counter = (MessageCounter)iter.next();
assertEquals(3, counter.getCount());
assertEquals(0, counter.getCountDelta());
assertEquals(-1, counter.getHistoryLimit());
}
ServerManagement.invoke(ServerManagement.getServerPeerObjectName(), "resetAllMessageCounters", null, null);
ServerManagement.invoke(ServerManagement.getServerPeerObjectName(), "resetAllMessageCounterHistories", null, null);
while (iter.hasNext())
{
MessageCounter counter = (MessageCounter)iter.next();
assertEquals(0, counter.getCount());
assertEquals(0, counter.getCountDelta());
assertEquals(-1, counter.getHistoryLimit());
}
String html = (String)ServerManagement.invoke(ServerManagement.getServerPeerObjectName(), "listMessageCountersAsHTML", null, null);
assertNotNull(html);
while (iter.hasNext())
{
MessageCounter counter = (MessageCounter)iter.next();
assertTrue(html.indexOf(counter.getDestinationName()) != -1);
}
List stats = (List)ServerManagement.getAttribute(ServerManagement.getServerPeerObjectName(), "MessageStatistics");
assertNotNull(stats);
assertEquals(7, stats.size());
iter = stats.iterator();
while (iter.hasNext())
{
MessageStatistics stat = (MessageStatistics)iter.next();
assertEquals(0, stat.getCount());
assertEquals(0, stat.getCountDelta());
assertEquals(3, stat.getDepth());
assertEquals(0, stat.getDepthDelta());
}
cons1.close();
cons2.close();
cons3.close();
sess.unsubscribe("sub1");
counters = (List)
ServerManagement.getAttribute(ServerManagement.getServerPeerObjectName(), "MessageCounters");
assertNotNull(counters);
assertEquals(4, counters.size());
tempQueue.delete();
counters = (List)
ServerManagement.getAttribute(ServerManagement.getServerPeerObjectName(), "MessageCounters");