Search in sources :

Example 81 with NotifyBuilder

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

the class FileConsumerNoopTest method testNoop.

public void testNoop() throws Exception {
    NotifyBuilder notify = new NotifyBuilder(context).whenDone(2).create();
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(2);
    assertMockEndpointsSatisfied();
    notify.matchesMockWaitTime();
    File file = new File("target/filenoop");
    assertEquals("There should be 2 files", 2, file.list().length);
}
Also used : NotifyBuilder(org.apache.camel.builder.NotifyBuilder) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) File(java.io.File)

Example 82 with NotifyBuilder

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

the class SplitterParallelBigFileTest method xxxtestSplitParallelBigFile.

// disabled due manual test
public void xxxtestSplitParallelBigFile() throws Exception {
    StopWatch watch = new StopWatch();
    NotifyBuilder builder = new NotifyBuilder(context).whenDone(lines + 1).create();
    boolean done = builder.matches(120, TimeUnit.SECONDS);
    log.info("Took " + TimeUtils.printDuration(watch.stop()));
    if (!done) {
        throw new CamelException("Could not split file in 2 minutes");
    }
// need a little sleep for capturing memory profiling
// Thread.sleep(60 * 1000);
}
Also used : NotifyBuilder(org.apache.camel.builder.NotifyBuilder) CamelException(org.apache.camel.CamelException) StopWatch(org.apache.camel.util.StopWatch)

Example 83 with NotifyBuilder

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

the class ThreadsRejectedExecutionTest method testThreadsRejectedAbortNoRedelivery.

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

        @Override
        public void configure() throws Exception {
            onException(Exception.class).maximumRedeliveries(3).handled(true).to("mock:error");
            from("seda:start").to("log:before").threads(1, 1).maxPoolSize(1).maxQueueSize(2).rejectedPolicy(ThreadPoolRejectedPolicy.Abort).delay(1000).to("log:after").to("mock:result");
        }
    });
    context.start();
    NotifyBuilder notify = new NotifyBuilder(context).whenDone(10).create();
    // there should be error handling for aborted tasks (eg no redeliveries and no error handling)
    getMockEndpoint("mock:error").expectedMessageCount(0);
    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 84 with NotifyBuilder

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

the class ThreadsRejectedExecutionTest method testThreadsRejectedDiscardOldest.

public void testThreadsRejectedDiscardOldest() 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.DiscardOldest).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 85 with NotifyBuilder

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

the class ThreadsRejectedExecutionTest method testThreadsRejectedAbort.

public void testThreadsRejectedAbort() 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.Abort).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)

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