Search in sources :

Example 46 with NotifyBuilder

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

the class SqsConcurrentConsumerTest method consumeMessagesFromQueue.

@Test
public void consumeMessagesFromQueue() throws Exception {
    // simple test to make sure that concurrent consumers were used in the test
    NotifyBuilder notifier = new NotifyBuilder(context).whenCompleted(NUM_MESSAGES).create();
    assertTrue("We didn't process " + NUM_MESSAGES + " messages as we expected!", notifier.matches(5, TimeUnit.SECONDS));
    if (isPlatform("windows")) {
    // threading is different on windows
    } else {
        // usually we use all threads evenly but sometimes threads are reused so just test that 50%+ was used
        if (threadNumbers.size() < (NUM_CONCURRENT / 2)) {
            fail(String.format("We were expecting to have about half of %d numbers of concurrent consumers, but only found %d", NUM_CONCURRENT, threadNumbers.size()));
        }
    }
}
Also used : NotifyBuilder(org.apache.camel.builder.NotifyBuilder) Test(org.junit.Test)

Example 47 with NotifyBuilder

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

the class ThreadsRejectedExecutionTest method testThreadsRejectedCallerRuns.

public void testThreadsRejectedCallerRuns() 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.CallerRuns).delay(200).to("log:after").to("mock:result");
        }
    });
    context.start();
    NotifyBuilder notify = new NotifyBuilder(context).whenDone(10).create();
    getMockEndpoint("mock:result").expectedMessageCount(10);
    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 48 with NotifyBuilder

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

the class FlexibleAggregationStrategiesTest method testLinkedList.

@Test
public void testLinkedList() throws Exception {
    NotifyBuilder notify = new NotifyBuilder(context).whenDone(1).and().whenExactlyFailed(0).create();
    template.sendBody("direct:linkedlist", Arrays.asList("FIRST", "SECOND"));
    assertTrue(notify.matches(10, TimeUnit.SECONDS));
}
Also used : NotifyBuilder(org.apache.camel.builder.NotifyBuilder) Test(org.junit.Test)

Example 49 with NotifyBuilder

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

the class FlexibleAggregationStrategiesTest method testHashSet.

@Test
public void testHashSet() throws Exception {
    HashSet<String> r = new HashSet<>();
    r.add("FIRST");
    r.add("SECOND");
    NotifyBuilder notify = new NotifyBuilder(context).whenDone(1).and().whenExactlyFailed(0).create();
    Set result = template.requestBody("direct:hashset", Arrays.asList("FIRST", "SECOND"), Set.class);
    assertTrue(notify.matches(10, TimeUnit.SECONDS));
    assertEquals(r, result);
}
Also used : NotifyBuilder(org.apache.camel.builder.NotifyBuilder) Set(java.util.Set) HashSet(java.util.HashSet) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 50 with NotifyBuilder

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

the class CacheProducerTest method testAddingDataToCacheWithNonStringCacheKey.

@Test
public void testAddingDataToCacheWithNonStringCacheKey() throws Exception {
    context.addRoutes(new RouteBuilder() {

        public void configure() {
            from("direct:a").setHeader(CacheConstants.CACHE_OPERATION, constant(CacheConstants.CACHE_OPERATION_ADD)).setHeader(CacheConstants.CACHE_KEY, constant(10L)).to("cache://TestCache1");
        }
    });
    context.start();
    NotifyBuilder notify = new NotifyBuilder(context).whenExactlyDone(1).create();
    log.debug("------------Beginning CacheProducer Add Test---------------");
    sendOriginalFile();
    notify.matches(10, TimeUnit.SECONDS);
    assertNotNull(fetchElement("10"));
}
Also used : NotifyBuilder(org.apache.camel.builder.NotifyBuilder) RouteBuilder(org.apache.camel.builder.RouteBuilder) Test(org.junit.Test) BaseCacheTest(org.apache.camel.component.BaseCacheTest)

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