}
}
private void testRecoverMissingQueues(CountDownLatch latch, ConnectionFactory connectionFactory)
throws InterruptedException {
RabbitAdmin admin = new RabbitAdmin(connectionFactory);
// queue doesn't exist during startup - verify we started, create queue and verify recovery
Thread.sleep(5000);
assertEquals(messageCount, latch.getCount());
admin.declareQueue(new Queue("nonexistent"));
RabbitTemplate template = new RabbitTemplate(connectionFactory);
for (int i = 0; i < messageCount; i++) {
template.convertAndSend("nonexistent", "foo" + i);
}
assertTrue(latch.await(10, TimeUnit.SECONDS));
Map<?,?> consumers = TestUtils.getPropertyValue(container, "consumers", Map.class);
assertEquals(1, consumers.size());
Object consumer = consumers.keySet().iterator().next();
// delete the queue and verify we recover again when it is recreated.
admin.deleteQueue("nonexistent");
Thread.sleep(3000);
latch = new CountDownLatch(messageCount);
container.setMessageListener(new MessageListenerAdapter(new VanillaListener(latch)));
assertEquals(messageCount, latch.getCount());
admin.declareQueue(new Queue("nonexistent"));
for (int i = 0; i < messageCount; i++) {
template.convertAndSend("nonexistent", "foo" + i);
}
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertEquals(1, consumers.size());