Search in sources :

Example 61 with NotifyBuilder

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

the class TokenPairIteratorSplitChoicePerformanceTest method xxxtestTokenPairPerformanceRoute.

public void xxxtestTokenPairPerformanceRoute() throws Exception {
    NotifyBuilder notify = new NotifyBuilder(context).whenDone(size).create();
    boolean matches = notify.matches(5, TimeUnit.MINUTES);
    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 62 with NotifyBuilder

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

the class ManagedThrottlerTest method testThrottleAsyncExceptionVisableViaJmx.

public void testThrottleAsyncExceptionVisableViaJmx() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }
    if (isPlatform("windows")) {
        // windows needs more sleep to read updated jmx values so we skip as we dont want further delays in core tests
        return;
    }
    // get the stats for the route
    MBeanServer mbeanServer = getMBeanServer();
    // get the object name for the delayer
    ObjectName throttlerName = ObjectName.getInstance("org.apache.camel:context=camel-1,type=processors,name=\"mythrottler4\"");
    // use route to get the total time
    ObjectName routeName = ObjectName.getInstance("org.apache.camel:context=camel-1,type=routes,name=\"route4\"");
    // reset the counters
    mbeanServer.invoke(routeName, "reset", null, null);
    getMockEndpoint("mock:endAsyncException").expectedMessageCount(10);
    NotifyBuilder notifier = new NotifyBuilder(context).from("seda:throttleCountAsyncException").whenReceived(5).create();
    for (int i = 0; i < 10; i++) {
        template.sendBody("seda:throttleCountAsyncException", "Message " + i);
    }
    assertTrue(notifier.matches(2, TimeUnit.SECONDS));
    assertMockEndpointsSatisfied();
    // give a sec for exception handling to finish..
    Thread.sleep(500);
    // since all exchanges ended w/ exception, they are not completed
    Long completed = (Long) mbeanServer.getAttribute(routeName, "ExchangesCompleted");
    assertEquals(0, completed.longValue());
}
Also used : NotifyBuilder(org.apache.camel.builder.NotifyBuilder) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 63 with NotifyBuilder

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

the class ManagedThrottlerTest method testThrottleVisableViaJmx.

public void testThrottleVisableViaJmx() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }
    if (isPlatform("windows")) {
        // windows needs more sleep to read updated jmx values so we skip as we dont want further delays in core tests
        return;
    }
    // get the stats for the route
    MBeanServer mbeanServer = getMBeanServer();
    // get the object name for the delayer
    ObjectName throttlerName = ObjectName.getInstance("org.apache.camel:context=camel-1,type=processors,name=\"mythrottler2\"");
    // use route to get the total time
    ObjectName routeName = ObjectName.getInstance("org.apache.camel:context=camel-1,type=routes,name=\"route2\"");
    // reset the counters
    mbeanServer.invoke(routeName, "reset", null, null);
    getMockEndpoint("mock:end").expectedMessageCount(10);
    NotifyBuilder notifier = new NotifyBuilder(context).from("seda:throttleCount").whenReceived(5).create();
    for (int i = 0; i < 10; i++) {
        template.sendBody("seda:throttleCount", "Message " + i);
    }
    assertTrue(notifier.matches(2, TimeUnit.SECONDS));
    assertMockEndpointsSatisfied();
    Long completed = (Long) mbeanServer.getAttribute(routeName, "ExchangesCompleted");
    assertEquals(10, completed.longValue());
}
Also used : NotifyBuilder(org.apache.camel.builder.NotifyBuilder) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 64 with NotifyBuilder

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

the class ApplicationTest method newOrderTest.

@Test
public void newOrderTest() {
    // Wait for maximum 5s until the first order gets inserted and processed
    NotifyBuilder notify = new NotifyBuilder(camelContext).fromRoute("generate-order").whenDone(1).and().fromRoute("process-order").whenDone(1).create();
    assertThat(notify.matches(5, TimeUnit.SECONDS)).isTrue();
    // Then call the REST API
    ResponseEntity<Order> response = restTemplate.getForEntity("/camel-rest-jpa/books/order/1", Order.class);
    assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
    Order order = response.getBody();
    assertThat(order.getId()).isEqualTo(1);
    assertThat(order.getAmount()).isBetween(1, 10);
    assertThat(order.getBook().getItem()).isIn("Camel", "ActiveMQ");
    assertThat(order.getBook().getDescription()).isIn("Camel in Action", "ActiveMQ in Action");
    assertThat(order.isProcessed()).isTrue();
}
Also used : NotifyBuilder(org.apache.camel.builder.NotifyBuilder) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 65 with NotifyBuilder

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

the class ZipFileDataFormatTest method testZipToFileWithFileName.

@Test
public void testZipToFileWithFileName() throws Exception {
    NotifyBuilder notify = new NotifyBuilder(context).whenDone(1).create();
    MockEndpoint mock = getMockEndpoint("mock:zipToFile");
    mock.expectedMessageCount(1);
    File file = new File(TEST_DIR, "poem.txt.zip");
    assertFalse("The zip should not exit.", file.exists());
    template.sendBodyAndHeader("direct:zipToFile", TEXT, FILE_NAME, "poem.txt");
    // just make sure the file is created
    mock.assertIsSatisfied();
    // use builder to ensure the exchange is fully done before we check for file exists
    assertTrue("The exchange is not done in time.", notify.matches(5, TimeUnit.SECONDS));
    assertTrue("The file should exist.", file.exists());
    assertArrayEquals("Get a wrong message content.", getZippedText("poem.txt"), getBytes(file));
}
Also used : NotifyBuilder(org.apache.camel.builder.NotifyBuilder) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) ZipFile(java.util.zip.ZipFile) 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