Search in sources :

Example 11 with CountDownLatch

use of java.util.concurrent.CountDownLatch in project camel by apache.

the class SedaConsumer method doStart.

protected void doStart() throws Exception {
    latch = new CountDownLatch(endpoint.getConcurrentConsumers());
    shutdownPending = false;
    forceShutdown = false;
    setupTasks();
    endpoint.onStarted(this);
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch)

Example 12 with CountDownLatch

use of java.util.concurrent.CountDownLatch in project camel by apache.

the class DefaultProducerTemplateAsyncTest method testAsyncCallbackInOnlyProcessor.

public void testAsyncCallbackInOnlyProcessor() throws Exception {
    ORDER.set(0);
    getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
    final CountDownLatch latch = new CountDownLatch(1);
    template.asyncCallback("direct:start", new Processor() {

        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setBody("Hello");
        }
    }, new SynchronizationAdapter() {

        @Override
        public void onDone(Exchange exchange) {
            assertEquals("Hello World", exchange.getIn().getBody());
            ORDER.addAndGet(2);
            latch.countDown();
        }
    });
    ORDER.addAndGet(1);
    assertTrue(latch.await(10, TimeUnit.SECONDS));
    ORDER.addAndGet(4);
    assertMockEndpointsSatisfied();
    assertEquals(7, ORDER.get());
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) CountDownLatch(java.util.concurrent.CountDownLatch) RuntimeCamelException(org.apache.camel.RuntimeCamelException) SynchronizationAdapter(org.apache.camel.support.SynchronizationAdapter)

Example 13 with CountDownLatch

use of java.util.concurrent.CountDownLatch in project camel by apache.

the class DefaultProducerTemplateAsyncTest method testAsyncCallbackBodyInOnly.

public void testAsyncCallbackBodyInOnly() throws Exception {
    ORDER.set(0);
    getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
    final CountDownLatch latch = new CountDownLatch(1);
    template.asyncCallbackSendBody("direct:start", "Hello", new SynchronizationAdapter() {

        @Override
        public void onDone(Exchange exchange) {
            assertEquals("Hello World", exchange.getIn().getBody());
            ORDER.addAndGet(2);
            latch.countDown();
        }
    });
    ORDER.addAndGet(1);
    assertTrue(latch.await(10, TimeUnit.SECONDS));
    ORDER.addAndGet(4);
    assertMockEndpointsSatisfied();
    assertEquals(7, ORDER.get());
}
Also used : Exchange(org.apache.camel.Exchange) CountDownLatch(java.util.concurrent.CountDownLatch) SynchronizationAdapter(org.apache.camel.support.SynchronizationAdapter)

Example 14 with CountDownLatch

use of java.util.concurrent.CountDownLatch in project camel by apache.

the class DefaultProducerTemplateAsyncTest method testAsyncCallbackExchangeInOut.

public void testAsyncCallbackExchangeInOut() throws Exception {
    ORDER.set(0);
    final CountDownLatch latch = new CountDownLatch(1);
    Exchange exchange = context.getEndpoint("direct:start").createExchange();
    exchange.getIn().setBody("Hello");
    exchange.setPattern(ExchangePattern.InOut);
    template.asyncCallback("direct:echo", exchange, new SynchronizationAdapter() {

        @Override
        public void onDone(Exchange exchange) {
            assertEquals("HelloHello", exchange.getOut().getBody());
            ORDER.addAndGet(2);
            latch.countDown();
        }
    });
    ORDER.addAndGet(1);
    assertTrue(latch.await(10, TimeUnit.SECONDS));
    ORDER.addAndGet(4);
    assertEquals(7, ORDER.get());
}
Also used : Exchange(org.apache.camel.Exchange) CountDownLatch(java.util.concurrent.CountDownLatch) SynchronizationAdapter(org.apache.camel.support.SynchronizationAdapter)

Example 15 with CountDownLatch

use of java.util.concurrent.CountDownLatch in project camel by apache.

the class DefaultProducerTemplateAsyncTest method testAsyncCallbackExchangeInOnly.

public void testAsyncCallbackExchangeInOnly() throws Exception {
    ORDER.set(0);
    getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
    final CountDownLatch latch = new CountDownLatch(1);
    Exchange exchange = context.getEndpoint("direct:start").createExchange();
    exchange.getIn().setBody("Hello");
    template.asyncCallback("direct:start", exchange, new SynchronizationAdapter() {

        @Override
        public void onDone(Exchange exchange) {
            assertEquals("Hello World", exchange.getIn().getBody());
            ORDER.addAndGet(2);
            latch.countDown();
        }
    });
    ORDER.addAndGet(1);
    assertTrue(latch.await(10, TimeUnit.SECONDS));
    ORDER.addAndGet(4);
    assertMockEndpointsSatisfied();
    assertEquals(7, ORDER.get());
}
Also used : Exchange(org.apache.camel.Exchange) CountDownLatch(java.util.concurrent.CountDownLatch) SynchronizationAdapter(org.apache.camel.support.SynchronizationAdapter)

Aggregations

CountDownLatch (java.util.concurrent.CountDownLatch)5355 Test (org.junit.Test)2594 IOException (java.io.IOException)631 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)550 AtomicReference (java.util.concurrent.atomic.AtomicReference)501 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)475 ArrayList (java.util.ArrayList)471 QuickTest (com.hazelcast.test.annotation.QuickTest)375 ParallelTest (com.hazelcast.test.annotation.ParallelTest)355 ExecutorService (java.util.concurrent.ExecutorService)322 Test (org.testng.annotations.Test)310 HazelcastInstance (com.hazelcast.core.HazelcastInstance)251 List (java.util.List)212 HashMap (java.util.HashMap)207 HttpServletResponse (javax.servlet.http.HttpServletResponse)207 ExecutionException (java.util.concurrent.ExecutionException)203 HttpServletRequest (javax.servlet.http.HttpServletRequest)189 Ignite (org.apache.ignite.Ignite)188 ServletException (javax.servlet.ServletException)183 TimeoutException (java.util.concurrent.TimeoutException)168