Thread.sleep(2000);
   public void testRemoveAllMessages() throws Exception   {      InitialContext ic = new InitialContext(ServerManagement.getJNDIEnvironment());      TopicConnectionFactory cf = (JBossConnectionFactory)ic.lookup("/ConnectionFactory");       ServerManagement.deployTopic("TopicRemoveAllMessages");            try      {         Topic topic = (Topic)ic.lookup("/topic/TopicRemoveAllMessages");            TopicConnection conn = cf.createTopicConnection();            conn.setClientID("Client1");            TopicSession s = conn.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);         MessageProducer prod = s.createProducer(topic);         prod.setDeliveryMode(DeliveryMode.PERSISTENT);            // Create 1 durable subscription and 1 non-durable subscription         TopicSubscriber tsDurable = s.createDurableSubscriber(topic, "Durable1");         TopicSubscriber tsNonDurable = s.createSubscriber(topic);                  // Send 1 message         prod.send(s.createTextMessage("First one"));                  ObjectName destObjectName =             new ObjectName("jboss.messaging.destination:service=Topic,name=TopicRemoveAllMessages");         List listMsg = (List)ServerManagement.invoke(destObjectName,                   "listMessagesDurableSub",                  new Object[] {"Durable1", "Client1", null},                  new String[] {"java.lang.String", "java.lang.String", "java.lang.String"});                  assertEquals(1, listMsg.size());                  //TODO - Why the heck isn't there a messageCount method on the subscription         //like there is on queue??????????                  // Start the connection for delivery         conn.start();                  // Remove all messages from the topic                  ServerManagement.invoke(destObjectName, "removeAllMessages", null, null);            // Try to receive messages from the two subscriptions, should be null                  //This is not valid - the messages will already be in the consumer endpoints and         //possibly the client consumers//         assertNull(tsDurable.receiveNoWait());//         assertNull(tsNonDurable.receiveNoWait());                  listMsg = (List)ServerManagement.invoke(destObjectName,                   "listMessagesDurableSub",                  new Object[] {"Durable1", "Client1", null},                  new String[] {"java.lang.String", "java.lang.String", "java.lang.String"});                  assertEquals(0, listMsg.size());                           // Now close the connection         conn.close();                  // Connect again to the same topic         conn = cf.createTopicConnection();         conn.setClientID("Client1");         s = conn.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);         prod = s.createProducer(topic);         prod.setDeliveryMode(DeliveryMode.PERSISTENT);            // Send another message         prod.send(s.createTextMessage("Second one"));                  listMsg = (List)ServerManagement.invoke(destObjectName,                   "listMessagesDurableSub",                  new Object[] {"Durable1", "Client1", null},                  new String[] {"java.lang.String", "java.lang.String", "java.lang.String"});                  assertEquals(1, listMsg.size());                  // Start the connection for delivery         conn.start();                  // Remove all messages from the topic         ServerManagement.invoke(destObjectName, "removeAllMessages", null, null);            // Restore the durable subscription now, the message should be already gone         tsDurable = s.createDurableSubscriber(topic, "Durable1");         //assertNull(tsDurable.receiveNoWait());                  listMsg = (List)ServerManagement.invoke(destObjectName,                   "listMessagesDurableSub",                  new Object[] {"Durable1", "Client1", null},                  new String[] {"java.lang.String", "java.lang.String", "java.lang.String"});                  assertEquals(0, listMsg.size());                  // Clean-up         conn.close();      }      finally      {                  ServerManagement.undeployTopic("TopicRemoveAllMessages");      }   }