{
Connection conn = cf.createConnection();
Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer prod = sessSend.createProducer(queue);
TextMessage m0 = sessSend.createTextMessage("a");
TextMessage m1 = sessSend.createTextMessage("b");
TextMessage m2 = sessSend.createTextMessage("c");
TextMessage m3 = sessSend.createTextMessage("d");
TextMessage m4 = sessSend.createTextMessage("e");
TextMessage m5 = sessSend.createTextMessage("f");
TextMessage m6 = sessSend.createTextMessage("g");
TextMessage m7 = sessSend.createTextMessage("h");
TextMessage m8 = sessSend.createTextMessage("i");
TextMessage m9 = sessSend.createTextMessage("j");
prod.send(m0, DeliveryMode.PERSISTENT, 0, 0);
prod.send(m1, DeliveryMode.PERSISTENT, 0, 0);
prod.send(m2, DeliveryMode.PERSISTENT, 0, 0);
prod.send(m3, DeliveryMode.PERSISTENT, 3, 0);
prod.send(m4, DeliveryMode.PERSISTENT, 3, 0);
prod.send(m5, DeliveryMode.PERSISTENT, 4, 0);
prod.send(m6, DeliveryMode.PERSISTENT, 4, 0);
prod.send(m7, DeliveryMode.PERSISTENT, 5, 0);
prod.send(m8, DeliveryMode.PERSISTENT, 5, 0);
prod.send(m9, DeliveryMode.PERSISTENT, 6, 0);
conn.close();
ServerManagement.stopServerPeer();
ServerManagement.startServerPeer();
// Messaging server restart implies new ConnectionFactory lookup
cf = (ConnectionFactory)initialContext.lookup("/ConnectionFactory");
ServerManagement.deployQueue("Queue");
conn = cf.createConnection();
Session sessReceive = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
conn.start();
MessageConsumer cons = sessReceive.createConsumer(queue);
{
TextMessage t = (TextMessage)cons.receive(1000);
assertNotNull(t);
assertEquals("j", t.getText());
}
{
TextMessage t = (TextMessage)cons.receive(1000);
assertNotNull(t);
assertEquals("h", t.getText());
}
{
TextMessage t = (TextMessage)cons.receive(1000);
assertNotNull(t);
assertEquals("i", t.getText());
}
{
TextMessage t = (TextMessage)cons.receive(1000);
assertNotNull(t);
assertEquals("f", t.getText());
}
{
TextMessage t = (TextMessage)cons.receive(1000);
assertNotNull(t);
assertEquals("g", t.getText());
}
{
TextMessage t = (TextMessage)cons.receive(1000);
assertNotNull(t);
assertEquals("d", t.getText());
}
{
TextMessage t = (TextMessage)cons.receive(1000);
assertNotNull(t);
assertEquals("e", t.getText());
}
{
TextMessage t = (TextMessage)cons.receive(1000);
assertNotNull(t);
assertEquals("a", t.getText());
}
{
TextMessage t = (TextMessage)cons.receive(1000);
assertNotNull(t);
assertEquals("b", t.getText());
}
{
TextMessage t = (TextMessage)cons.receive(1000);
assertNotNull(t);
assertEquals("c", t.getText());
}
{
TextMessage t = (TextMessage)cons.receiveNoWait();
assertNull(t);
}
conn.close();
}