Search in sources :

Example 86 with NotifyBuilder

use of org.apache.camel.builder.NotifyBuilder in project camel by apache.

the class ThreadsRejectedExecutionTest method testThreadsRejectedDiscard.

public void testThreadsRejectedDiscard() throws Exception {
    context.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("seda:start").to("log:before").threads(1, 1).maxPoolSize(1).maxQueueSize(2).rejectedPolicy(ThreadPoolRejectedPolicy.Discard).delay(1000).to("log:after").to("mock:result");
        }
    });
    context.start();
    NotifyBuilder notify = new NotifyBuilder(context).whenDone(10).create();
    getMockEndpoint("mock:result").expectedMinimumMessageCount(2);
    for (int i = 0; i < 10; i++) {
        template.sendBody("seda:start", "Message " + i);
    }
    assertMockEndpointsSatisfied();
    assertTrue(notify.matchesMockWaitTime());
    int inflight = context.getInflightRepository().size();
    assertEquals(0, inflight);
}
Also used : NotifyBuilder(org.apache.camel.builder.NotifyBuilder) RouteBuilder(org.apache.camel.builder.RouteBuilder) MockEndpoint(org.apache.camel.component.mock.MockEndpoint)

Example 87 with NotifyBuilder

use of org.apache.camel.builder.NotifyBuilder in project camel by apache.

the class XPathSplitChoicePerformanceTest method xxTestXPatPerformanceRoute.

public void xxTestXPatPerformanceRoute() 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)

Example 88 with NotifyBuilder

use of org.apache.camel.builder.NotifyBuilder in project camel by apache.

the class AggregateSimpleExpressionIssueTest method xxxtestAggregateSimpleExpression.

// Enable me for manual unit testing
public void xxxtestAggregateSimpleExpression() throws Exception {
    // 10 files + 10 files * 100 batches
    int files = 10;
    int rows = 100000;
    int batches = rows / 1000;
    int total = files + (files * rows) + (files * batches);
    LOG.info("There are " + total + " exchanges");
    NotifyBuilder notify = new NotifyBuilder(context).whenDone(total).create();
    LOG.info("Writing 10 files with 100000 rows in each file");
    // write 10 files of 100k rows
    for (int i = 0; i < files; i++) {
        Writer out = IOHelper.buffered(new FileWriter(new File("target/files", "data" + i)));
        for (int j = 0; j < rows; j++) {
            out.write(DATA);
        }
        out.close();
    }
    // start the route
    StopWatch watch = new StopWatch();
    context.startRoute("foo");
    LOG.info("Waiting to process all the files");
    boolean matches = notify.matches(3, TimeUnit.MINUTES);
    LOG.info("Should process all files " + matches);
    LOG.info("Time taken " + watch.taken() + " ms");
}
Also used : NotifyBuilder(org.apache.camel.builder.NotifyBuilder) FileWriter(java.io.FileWriter) File(java.io.File) FileWriter(java.io.FileWriter) Writer(java.io.Writer) StopWatch(org.apache.camel.util.StopWatch)

Example 89 with NotifyBuilder

use of org.apache.camel.builder.NotifyBuilder in project camel by apache.

the class BeanBeforeAggregateIssueTest method testBeanBeforeAggregation.

public void testBeanBeforeAggregation() throws Exception {
    NotifyBuilder notify = new NotifyBuilder(context).whenDone(3).create();
    getMockEndpoint("mock:result").expectedBodiesReceived("A+B");
    template.sendBody("seda:start", "A");
    template.sendBody("seda:start", "B");
    assertMockEndpointsSatisfied();
    // wait for all exchanges to be done (2 input + 1 aggregated)
    notify.matches(5, TimeUnit.SECONDS);
    // should have confirmed
    assertTrue("Should have confirmed", myRepo.isConfirm());
}
Also used : NotifyBuilder(org.apache.camel.builder.NotifyBuilder)

Example 90 with NotifyBuilder

use of org.apache.camel.builder.NotifyBuilder in project camel by apache.

the class FileConsumeDoneFileIssueTest method testFileConsumeDynamicDoneFileName.

public void testFileConsumeDynamicDoneFileName() throws Exception {
    NotifyBuilder notify = new NotifyBuilder(context).whenDone(3).create();
    template.sendBodyAndHeader("file:target/done2", "A", Exchange.FILE_NAME, "a.txt");
    template.sendBodyAndHeader("file:target/done2", "B", Exchange.FILE_NAME, "b.txt");
    template.sendBodyAndHeader("file:target/done2", "C", Exchange.FILE_NAME, "c.txt");
    template.sendBodyAndHeader("file:target/done2", "a", Exchange.FILE_NAME, "a.txt.done");
    template.sendBodyAndHeader("file:target/done2", "b", Exchange.FILE_NAME, "b.txt.done");
    template.sendBodyAndHeader("file:target/done2", "c", Exchange.FILE_NAME, "c.txt.done");
    assertTrue("Done file should exists", new File("target/done2/a.txt.done").exists());
    assertTrue("Done file should exists", new File("target/done2/b.txt.done").exists());
    assertTrue("Done file should exists", new File("target/done2/c.txt.done").exists());
    getMockEndpoint("mock:result").expectedBodiesReceivedInAnyOrder("A", "B", "C");
    context.startRoute("bar");
    assertMockEndpointsSatisfied();
    assertTrue(notify.matchesMockWaitTime());
    Thread.sleep(250);
    // the done file should be deleted
    assertFalse("Done file should be deleted", new File("target/done2/a.txt.done").exists());
    assertFalse("Done file should be deleted", new File("target/done2/b.txt.done").exists());
    assertFalse("Done file should be deleted", new File("target/done2/c.txt.done").exists());
}
Also used : NotifyBuilder(org.apache.camel.builder.NotifyBuilder) File(java.io.File)

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