Search in sources :

Example 1 with ExchangeBuilder

use of org.apache.camel.builder.ExchangeBuilder in project opennms by OpenNMS.

the class JaxbUtilsUnmarshalProcessorTest method testSpeed.

@Test
public void testSpeed() throws Exception {
    TestMe test = new TestMe();
    test.lets = "lets";
    test.make = "make";
    test.an = "an";
    test.object = "object";
    String marshalled = JaxbUtils.marshal(test);
    final int numberOfMessages = 10000;
    final int warmUp = 4000;
    CamelContext m_camel = new DefaultCamelContext(new SimpleRegistry());
    JaxbUtilsUnmarshalProcessor processor = new JaxbUtilsUnmarshalProcessor(TestMe.class);
    List<Exchange> exchanges = IntStream.range(0, numberOfMessages).mapToObj(i -> {
        return new ExchangeBuilder(m_camel).withBody(marshalled).build();
    }).collect(Collectors.toList());
    int counter = 0;
    long begin = 0;
    long end = 0;
    for (Exchange exchange : exchanges) {
        processor.process(exchange);
        if (counter++ < warmUp) {
            // Warm up
            continue;
        }
        if (begin == 0) {
            begin = System.currentTimeMillis();
        }
        // System.out.println(end = System.currentTimeMillis());
        end = System.currentTimeMillis();
    }
    System.out.println("BEGIN: " + begin);
    System.out.println("END: " + end);
    System.out.println("TOTAL TIME: " + (end - begin));
    System.out.println("RATE: " + ((double) (numberOfMessages - warmUp) / (double) (end - begin)) + "/ms");
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Exchange(org.apache.camel.Exchange) IntStream(java.util.stream.IntStream) XmlAccessorType(javax.xml.bind.annotation.XmlAccessorType) CamelContext(org.apache.camel.CamelContext) Exchange(org.apache.camel.Exchange) Test(org.junit.Test) XmlRootElement(javax.xml.bind.annotation.XmlRootElement) Collectors(java.util.stream.Collectors) XmlAccessType(javax.xml.bind.annotation.XmlAccessType) List(java.util.List) ExchangeBuilder(org.apache.camel.builder.ExchangeBuilder) JaxbUtils(org.opennms.core.xml.JaxbUtils) SimpleRegistry(org.apache.camel.impl.SimpleRegistry) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) SimpleRegistry(org.apache.camel.impl.SimpleRegistry) ExchangeBuilder(org.apache.camel.builder.ExchangeBuilder) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Aggregations

List (java.util.List)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1 XmlAccessType (javax.xml.bind.annotation.XmlAccessType)1 XmlAccessorType (javax.xml.bind.annotation.XmlAccessorType)1 XmlRootElement (javax.xml.bind.annotation.XmlRootElement)1 CamelContext (org.apache.camel.CamelContext)1 Exchange (org.apache.camel.Exchange)1 ExchangeBuilder (org.apache.camel.builder.ExchangeBuilder)1 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)1 SimpleRegistry (org.apache.camel.impl.SimpleRegistry)1 Test (org.junit.Test)1 JaxbUtils (org.opennms.core.xml.JaxbUtils)1