Search in sources :

Example 76 with NotifyBuilder

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

the class XPathSplitChoicePerformanceTest method testXPathPerformanceRoute.

@Test
@Ignore("Manual test")
public void testXPathPerformanceRoute() 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) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 77 with NotifyBuilder

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

the class NettyConcurrentTest method doSendMessages.

private void doSendMessages(int files, int poolSize) throws Exception {
    StopWatch watch = new StopWatch();
    NotifyBuilder notify = new NotifyBuilder(context).whenDone(files).create();
    ExecutorService executor = Executors.newFixedThreadPool(poolSize);
    // we access the responses Map below only inside the main thread,
    // so no need for a thread-safe Map implementation
    Map<Integer, Future<String>> responses = new HashMap<Integer, Future<String>>();
    for (int i = 0; i < files; i++) {
        final int index = i;
        Future<String> out = executor.submit(new Callable<String>() {

            public String call() throws Exception {
                String reply = template.requestBody("netty4:tcp://localhost:{{port}}", index, String.class);
                log.debug("Sent {} received {}", index, reply);
                assertEquals("Bye " + index, reply);
                return reply;
            }
        });
        responses.put(index, out);
    }
    notify.matches(2, TimeUnit.MINUTES);
    log.info("Took " + watch.taken() + " millis to process " + files + " messages using " + poolSize + " client threads.");
    assertEquals(files, responses.size());
    // get all responses
    Set<String> unique = new HashSet<String>();
    for (Future<String> future : responses.values()) {
        unique.add(future.get());
    }
    // should be 'files' unique responses
    assertEquals("Should be " + files + " unique responses", files, unique.size());
    executor.shutdownNow();
}
Also used : HashMap(java.util.HashMap) StopWatch(org.apache.camel.util.StopWatch) NotifyBuilder(org.apache.camel.builder.NotifyBuilder) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) HashSet(java.util.HashSet)

Example 78 with NotifyBuilder

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

the class RouteConcurrentTest method testSingleInvocationsOfRoute.

@Test
public void testSingleInvocationsOfRoute() throws Exception {
    NotifyBuilder notify = new NotifyBuilder(context).whenDone(2).create();
    template.sendBody("seda:foo", "Hello World");
    assertTrue(notify.matches(30, TimeUnit.SECONDS));
    verify();
}
Also used : NotifyBuilder(org.apache.camel.builder.NotifyBuilder) Test(org.junit.Test)

Example 79 with NotifyBuilder

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

the class RouteConcurrentTest method testConcurrentInvocationsOfRoute.

@Test
public void testConcurrentInvocationsOfRoute() throws Exception {
    NotifyBuilder notify = new NotifyBuilder(context).whenDone(10).create();
    for (int i = 0; i < 5; i++) {
        template.sendBody("seda:foo", "Hello World");
    }
    assertTrue(notify.matches(30, TimeUnit.SECONDS));
    verifyTraceSpanNumbers(5, testdata.length);
}
Also used : NotifyBuilder(org.apache.camel.builder.NotifyBuilder) Test(org.junit.Test)

Example 80 with NotifyBuilder

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

the class SpringOpenTracingSimpleRouteTest method testRoute.

@Test
public void testRoute() throws Exception {
    NotifyBuilder notify = new NotifyBuilder(context).whenDone(5).create();
    for (int i = 0; i < 5; i++) {
        template.sendBody("seda:dude", "Hello World");
    }
    assertTrue(notify.matches(30, TimeUnit.SECONDS));
    MockTracer tracer = (MockTracer) context().getRegistry().lookupByName("mockTracer");
    // Four spans per invocation, one for client, two for dude route (server and client to), one for car route
    assertEquals(20, tracer.finishedSpans().size());
}
Also used : NotifyBuilder(org.apache.camel.builder.NotifyBuilder) MockTracer(io.opentracing.mock.MockTracer) 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