Search in sources :

Example 71 with NotifyBuilder

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

Example 72 with NotifyBuilder

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

Example 73 with NotifyBuilder

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));
}
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)

Example 74 with NotifyBuilder

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

Example 75 with NotifyBuilder

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