use of org.apache.camel.builder.NotifyBuilder in project camel by apache.
the class StAXXPathSplitChoicePerformanceTest method testXPathSTaXPerformanceRoute.
@Test
public void testXPathSTaXPerformanceRoute() throws Exception {
NotifyBuilder notify = new NotifyBuilder(context).whenDone(size).create();
boolean matches = notify.matches(60, TimeUnit.SECONDS);
log.info("Processed file with " + size + " elements in: " + TimeUtils.printDuration(watch.stop()));
log.info("Processed " + tiny.get() + " tiny messages");
log.info("Processed " + small.get() + " small messages");
log.info("Processed " + med.get() + " medium messages");
log.info("Processed " + large.get() + " large messages");
assertEquals((size / 10) * 4, tiny.get());
assertEquals((size / 10) * 2, small.get());
assertEquals((size / 10) * 3, med.get());
assertEquals((size / 10) * 1, large.get());
assertTrue("Should complete route", matches);
}
use of org.apache.camel.builder.NotifyBuilder in project camel by apache.
the class FromJmsToJdbcIdempotentConsumerToJmsTest method testFilterIdempotent.
@Test
public void testFilterIdempotent() throws Exception {
checkInitialState();
// use a notify to know when the message is done
NotifyBuilder notify = new NotifyBuilder(context).whenDone(3).create();
// use mock during testing as well
getMockEndpoint("mock:a").expectedMessageCount(3);
// there should be 1 duplicate
getMockEndpoint("mock:b").expectedMessageCount(2);
template.sendBodyAndHeader("activemq2:queue:inbox", "D", "uid", 111);
template.sendBodyAndHeader("activemq2:queue:inbox", "E", "uid", 222);
template.sendBodyAndHeader("activemq2:queue:inbox", "D", "uid", 111);
// assert mock and wait for the message to be done
assertMockEndpointsSatisfied();
assertTrue("Should complete 3 messages", notify.matchesMockWaitTime());
// check that there is two messages in the database and JMS queue
assertEquals(new Integer(2), jdbcTemplate.queryForObject("select count(*) from CAMEL_MESSAGEPROCESSED", Integer.class));
assertEquals("DONE-D", consumer.receiveBody("activemq2:queue:outbox", 3000));
assertEquals("DONE-E", consumer.receiveBody("activemq2:queue:outbox", 3000));
}
use of org.apache.camel.builder.NotifyBuilder in project camel by apache.
the class FromJmsToJdbcIdempotentConsumerToJmsTest method testJmsToJdbcJmsRollbackAtB.
@Ignore("see the TODO below")
@Test
public void testJmsToJdbcJmsRollbackAtB() throws Exception {
checkInitialState();
// use a notify to know that after 1+6 (1 original + 6 redelivery) attempts from AcitveMQ
NotifyBuilder notify = new NotifyBuilder(context).whenDone(7).create();
// TODO: occasionally we get only 6 instead of 7 expected exchanges which's most probably an issue in ActiveMQ itself
getMockEndpoint("mock:a").expectedMessageCount(7);
getMockEndpoint("mock:b").expectedMessageCount(7);
// force exception to occur at mock b
getMockEndpoint("mock:b").whenAnyExchangeReceived(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
throw new ConnectException("Forced cannot send to AMQ queue");
}
});
template.sendBodyAndHeader("activemq2:queue:inbox", "B", "uid", 456);
// assert mock and wait for the message to be done
assertMockEndpointsSatisfied();
assertTrue("Should complete 7 messages", notify.matchesMockWaitTime());
// check that there is a message in the database and JMS queue
assertEquals(new Integer(0), jdbcTemplate.queryForObject("select count(*) from CAMEL_MESSAGEPROCESSED", Integer.class));
assertNull(consumer.receiveBody("activemq2:queue:outbox", 3000));
// the message should have been moved to the AMQ DLQ queue
assertEquals("B", consumer.receiveBody("activemq2:queue:ActiveMQ.DLQ", 3000));
}
use of org.apache.camel.builder.NotifyBuilder in project camel by apache.
the class FromJmsToJdbcIdempotentConsumerToJmsTest method testRetryAfterException.
@Test
public void testRetryAfterException() throws Exception {
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("activemq2:queue:inbox", "D", "uid", 111);
template.sendBodyAndHeader("activemq2:queue:inbox", "E", "uid", 222);
template.sendBodyAndHeader("activemq2: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(new Integer(3), jdbcTemplate.queryForObject("select count(*) from CAMEL_MESSAGEPROCESSED", Integer.class));
assertEquals("DONE-D", consumer.receiveBody("activemq2:queue:outbox", 3000));
assertEquals("DONE-E", consumer.receiveBody("activemq2:queue:outbox", 3000));
assertEquals("DONE-F", consumer.receiveBody("activemq2:queue:outbox", 3000));
}
use of org.apache.camel.builder.NotifyBuilder in project camel by apache.
the class FromFileToHdfsTest method testFileToHdfs.
@Test
public void testFileToHdfs() throws Exception {
if (!canTest()) {
return;
}
NotifyBuilder notify = new NotifyBuilder(context).whenDone(1).create();
template.sendBodyAndHeader("file:target/inbox", "Hello World", Exchange.FILE_NAME, "hello.txt");
notify.matchesMockWaitTime();
File delete = new File("target/inbox/hello.txt");
assertTrue("File should be deleted " + delete, !delete.exists());
File create = new File(TEMP_DIR + "/output.txt");
assertTrue("File should be created " + create, create.exists());
}
Aggregations