public void testLargeQueuePersistentMessagesNotLostOnRestart() throws Exception {
ActiveMQDestination destination = new ActiveMQQueue("TEST");
// Setup the producer and send the message.
StubConnection connection = createConnection();
ConnectionInfo connectionInfo = createConnectionInfo();
SessionInfo sessionInfo = createSessionInfo(connectionInfo);
ProducerInfo producerInfo = createProducerInfo(sessionInfo);
connection.send(connectionInfo);
connection.send(sessionInfo);
connection.send(producerInfo);
ArrayList<String> expected = new ArrayList<String>();
int MESSAGE_COUNT = 10000;
for(int i=0; i < MESSAGE_COUNT; i++) {
Message message = createMessage(producerInfo, destination);
message.setPersistent(true);
connection.send(message);
expected.add(message.getMessageId().toString());
}
connection.request(closeConnectionInfo(connectionInfo));
// restart the broker.
restartBroker();
// Setup the consumer and receive the message.
connection = createConnection();
connectionInfo = createConnectionInfo();
sessionInfo = createSessionInfo(connectionInfo);
connection.send(connectionInfo);
connection.send(sessionInfo);
ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo, destination);
connection.send(consumerInfo);
producerInfo = createProducerInfo(sessionInfo);
connection.send(producerInfo);
for(int i=0; i < MESSAGE_COUNT/2; i++) {
Message m = receiveMessage(connection);
assertNotNull("Should have received message "+expected.get(0)+" by now!", m);
assertEquals(expected.remove(0), m.getMessageId().toString());
MessageAck ack = createAck(consumerInfo, m, 1, MessageAck.STANDARD_ACK_TYPE);
connection.send(ack);
}
connection.request(closeConnectionInfo(connectionInfo));
// restart the broker.
restartBroker();
// Setup the consumer and receive the message.
connection = createConnection();
connectionInfo = createConnectionInfo();
sessionInfo = createSessionInfo(connectionInfo);
connection.send(connectionInfo);
connection.send(sessionInfo);
consumerInfo = createConsumerInfo(sessionInfo, destination);
connection.send(consumerInfo);
for(int i=0; i < MESSAGE_COUNT/2; i++) {
Message m = receiveMessage(connection);
assertNotNull("Should have received message "+expected.get(i)+" by now!", m);
assertEquals(expected.get(i), m.getMessageId().toString());
MessageAck ack = createAck(consumerInfo, m, 1, MessageAck.STANDARD_ACK_TYPE);
connection.send(ack);
}
connection.request(closeConnectionInfo(connectionInfo));
}