//Send some messages to durable sub
InitialContext ic = new InitialContext(ServerManagement.getJNDIEnvironment());
ConnectionFactory cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");
Topic topic = (Topic)ic.lookup("/topic/ReloadTopic");
Connection conn = cf.createConnection();
conn.start();
conn.setClientID("wibble765");
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer cons = sess.createDurableSubscriber(topic, "subxyz");
MessageProducer prod = sess.createProducer(topic);
prod.setDeliveryMode(DeliveryMode.PERSISTENT);
for (int i = 0; i < 10; i++)
{
TextMessage tm = sess.createTextMessage();
tm.setText("message:" + i);
prod.send(tm);
}
conn.close();
//Receive half of them
conn = cf.createConnection();
conn.setClientID("wibble765");
sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
cons = sess.createDurableSubscriber(topic, "subxyz");
conn.start();
for (int i = 0; i < 5; i++)
{
TextMessage tm = (TextMessage)cons.receive(1000);
assertNotNull(tm);
assertEquals("message:" + i, tm.getText());
}
conn.close();
//Undeploy and redeploy the queue
//The last 5 persistent messages should still be there
undeployDestination("ReloadTopic");
deploy(config);
topic = (Topic)ic.lookup("/topic/ReloadTopic");
conn = cf.createConnection();
conn.setClientID("wibble765");
sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);