checkInitialState();
final AtomicInteger counter = new AtomicInteger();
// use a notify to know when the message is done
NotifyBuilder notify = new NotifyBuilder(context).whenDone(4).create();
// use mock during testing as well
getMockEndpoint("mock:a").expectedMessageCount(4);
// there should be 1 duplicate
getMockEndpoint("mock:b").expectedMessageCount(4);
getMockEndpoint("mock:b").whenAnyExchangeReceived(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
if (counter.getAndIncrement() == 1) {
throw new ConnectException("Forced cannot send to AMQ queue");
}
}
});
template.sendBodyAndHeader("activemq:queue:inbox", "D", "uid", 111);
template.sendBodyAndHeader("activemq:queue:inbox", "E", "uid", 222);
template.sendBodyAndHeader("activemq:queue:inbox", "F", "uid", 333);
// assert mock and wait for the message to be done
assertMockEndpointsSatisfied();
assertTrue("Should complete 4 messages", notify.matchesMockWaitTime());
// check that there is two messages in the database and JMS queue
assertEquals(3, jdbcTemplate.queryForInt("select count(*) from CAMEL_MESSAGEPROCESSED"));
assertEquals("DONE-D", consumer.receiveBody("activemq:queue:outbox", 3000));
assertEquals("DONE-E", consumer.receiveBody("activemq:queue:outbox", 3000));