Search in sources :

Example 11 with NotifyBuilder

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));
}
Also used : NotifyBuilder(org.apache.camel.builder.NotifyBuilder) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 12 with NotifyBuilder

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);
}
Also used : NotifyBuilder(org.apache.camel.builder.NotifyBuilder) Test(org.junit.Test)

Example 13 with NotifyBuilder

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());
}
Also used : NotifyBuilder(org.apache.camel.builder.NotifyBuilder) Test(org.junit.Test)

Example 14 with NotifyBuilder

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);
}
Also used : NotifyBuilder(org.apache.camel.builder.NotifyBuilder) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Example 15 with NotifyBuilder

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));
}
Also used : NotifyBuilder(org.apache.camel.builder.NotifyBuilder) Exchange(org.apache.camel.Exchange) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Processor(org.apache.camel.Processor) ConnectException(java.net.ConnectException) ConnectException(java.net.ConnectException) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

NotifyBuilder (org.apache.camel.builder.NotifyBuilder)109 Test (org.junit.Test)72 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)30 File (java.io.File)24 Exchange (org.apache.camel.Exchange)10 RouteBuilder (org.apache.camel.builder.RouteBuilder)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 HashSet (java.util.HashSet)4 MBeanServer (javax.management.MBeanServer)4 ObjectName (javax.management.ObjectName)4 Processor (org.apache.camel.Processor)4 StopWatch (org.apache.camel.util.StopWatch)4 ConnectException (java.net.ConnectException)3 ExecutorService (java.util.concurrent.ExecutorService)3 Ignore (org.junit.Ignore)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Future (java.util.concurrent.Future)2 ZipFile (java.util.zip.ZipFile)2