use of org.apache.camel.builder.NotifyBuilder in project camel by apache.
the class SampleCamelApplicationTest method shouldProduceMessages.
@Test
public void shouldProduceMessages() throws Exception {
// we expect that one or more messages is automatic done by the Camel
// route as it uses a timer to trigger
NotifyBuilder notify = new NotifyBuilder(camelContext).whenDone(1).create();
assertTrue(notify.matches(10, TimeUnit.SECONDS));
}
use of org.apache.camel.builder.NotifyBuilder in project camel by apache.
the class SimpleNotifyBuilderTest method testNotifyBuilder.
@Test
public void testNotifyBuilder() throws Exception {
NotifyBuilder notify = new NotifyBuilder(context).from("seda:start").wereSentTo("seda:queue").whenDone(10).create();
for (int i = 0; i < 10; i++) {
template.sendBody("seda:start", "Camel" + i);
}
boolean matches = notify.matches(10, TimeUnit.SECONDS);
assertTrue(matches);
}
use of org.apache.camel.builder.NotifyBuilder in project camel by apache.
the class NettyReuseChannelTest method testReuse.
@Test
public void testReuse() throws Exception {
NotifyBuilder notify = new NotifyBuilder(context).whenDone(1).create();
getMockEndpoint("mock:a").expectedBodiesReceived("Hello World");
getMockEndpoint("mock:b").expectedBodiesReceived("Hello Hello World");
getMockEndpoint("mock:result").expectedBodiesReceived("Hello World", "Hello Hello World");
template.sendBody("direct:start", "World\n");
assertMockEndpointsSatisfied();
assertTrue(notify.matchesMockWaitTime());
assertEquals(2, channels.size());
assertSame("Should reuse channel", channels.get(0), channels.get(1));
assertFalse("And closed when routing done", channels.get(0).isOpen());
assertFalse("And closed when routing done", channels.get(1).isOpen());
}
use of org.apache.camel.builder.NotifyBuilder in project camel by apache.
the class FromJmsToJdbcIdempotentConsumerToJmsTest method testJmsToJdbcJmsCommit.
@Test
public void testJmsToJdbcJmsCommit() throws Exception {
checkInitialState();
// use a notify to know when the message is done
NotifyBuilder notify = new NotifyBuilder(context).whenDone(1).create();
// use mock during testing as well
getMockEndpoint("mock:a").expectedMessageCount(1);
getMockEndpoint("mock:b").expectedMessageCount(1);
template.sendBodyAndHeader("activemq2:queue:inbox", "A", "uid", 123);
// assert mock and wait for the message to be done
assertMockEndpointsSatisfied();
assertTrue("Should complete 1 message", notify.matchesMockWaitTime());
// check that there is a message in the database and JMS queue
assertEquals(new Integer(1), jdbcTemplate.queryForObject("select count(*) from CAMEL_MESSAGEPROCESSED", Integer.class));
Object out = consumer.receiveBody("activemq2:queue:outbox", 3000);
assertEquals("DONE-A", out);
}
use of org.apache.camel.builder.NotifyBuilder in project camel by apache.
the class FromJmsToJdbcIdempotentConsumerToJmsTest method testJmsToJdbcJmsRollbackAtA.
@Ignore("see the TODO below")
@Test
public void testJmsToJdbcJmsRollbackAtA() 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);
// force exception to occur at mock a
getMockEndpoint("mock:a").whenAnyExchangeReceived(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
throw new ConnectException("Forced cannot connect to database");
}
});
getMockEndpoint("mock:b").expectedMessageCount(0);
template.sendBodyAndHeader("activemq2:queue:inbox", "A", "uid", 123);
// assert mock and wait for the message to be done
assertMockEndpointsSatisfied();
assertTrue("Should complete 7 message", 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("A", consumer.receiveBody("activemq2:queue:ActiveMQ.DLQ", 3000));
}
Aggregations