Search in sources :

Example 1 with RouteBuilder

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

the class AdvisedMockEndpointProducerTest method startCamelContext.

@Test
@InSequence(1)
public void startCamelContext(CamelContext context) throws Exception {
    context.addRoutes(new RouteBuilder() {

        @Override
        public void configure() {
            interceptSendToEndpoint("mock:outbound").skipSendToOriginalEndpoint().log("Intercepting message [${body}] from mock endpoint").to("mock:intercepted");
            from("direct:inbound").to("mock:outbound");
        }
    });
    context.startAllRoutes();
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) Test(org.junit.Test) InSequence(org.jboss.arquillian.junit.InSequence)

Example 2 with RouteBuilder

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

the class ObjectCacheProducerTest method testAddingMultipleDataInCacheAndGettingBack.

/**
     * Test storing 3 elements into object cache then retrieving them back.
     * We allow cache to store maximum of 2 values to check that overflow to disk not happened (it is not
     * allowed in ehcache object cache (not serializable cache)).
     *
     * @throws Exception
     * @see net.sf.ehcache.Element for information about object cache operations in ehcache
     */
@Test
public void testAddingMultipleDataInCacheAndGettingBack() throws Exception {
    context.addRoutes(new RouteBuilder() {

        public void configure() {
            onException(Exception.class).handled(true).to("log:LOGGER").to("mock:ObjectCacheProducerTest.cacheException");
            from("direct:a").setHeader(CacheConstants.CACHE_OPERATION, constant(CacheConstants.CACHE_OPERATION_ADD)).setHeader(CacheConstants.CACHE_KEY, constant("Ralph_Waldo_Emerson")).to("cache://TestCache1?objectCache=true&overflowToDisk=false&diskPersistent=false&maxElementsInMemory=2");
            from("direct:aGet").setHeader(CacheConstants.CACHE_OPERATION, constant(CacheConstants.CACHE_OPERATION_GET)).setHeader(CacheConstants.CACHE_KEY, constant("Ralph_Waldo_Emerson")).to("cache://TestCache1?objectCache=true&overflowToDisk=false&diskPersistent=false&maxElementsInMemory=2").choice().when(header(CacheConstants.CACHE_ELEMENT_WAS_FOUND).isNotNull()).to("mock:ObjectCacheProducerTest.result").end();
            from("direct:b").setHeader(CacheConstants.CACHE_OPERATION, constant(CacheConstants.CACHE_OPERATION_ADD)).setHeader(CacheConstants.CACHE_KEY, constant("Ralph_Waldo_Emerson_2")).to("cache://TestCache1?objectCache=true&overflowToDisk=false&diskPersistent=false&maxElementsInMemory=2");
            from("direct:bGet").setHeader(CacheConstants.CACHE_OPERATION, constant(CacheConstants.CACHE_OPERATION_GET)).setHeader(CacheConstants.CACHE_KEY, constant("Ralph_Waldo_Emerson_2")).to("cache://TestCache1?objectCache=true&overflowToDisk=false&diskPersistent=false&maxElementsInMemory=2").choice().when(header(CacheConstants.CACHE_ELEMENT_WAS_FOUND).isNotNull()).to("mock:ObjectCacheProducerTest.result").end();
            from("direct:c").setHeader(CacheConstants.CACHE_OPERATION, constant(CacheConstants.CACHE_OPERATION_ADD)).setHeader(CacheConstants.CACHE_KEY, constant("Ralph_Waldo_Emerson_3")).to("cache://TestCache1?objectCache=true&overflowToDisk=false&diskPersistent=false&maxElementsInMemory=2");
            from("direct:cGet").setHeader(CacheConstants.CACHE_OPERATION, constant(CacheConstants.CACHE_OPERATION_GET)).setHeader(CacheConstants.CACHE_KEY, constant("Ralph_Waldo_Emerson_3")).to("cache://TestCache1?objectCache=true&overflowToDisk=false&diskPersistent=false&maxElementsInMemory=2").choice().when(header(CacheConstants.CACHE_ELEMENT_WAS_FOUND).isNotNull()).to("mock:ObjectCacheProducerTest.result").end();
        }
    });
    context.setTracing(true);
    context.start();
    resultEndpoint.expectedMessageCount(2);
    cacheExceptionEndpoint.expectedMessageCount(0);
    log.debug("------------Beginning CacheProducer Add and Get Test---------------");
    log.debug("Putting data into cache");
    sendNonSerializedData("direct:a", newPoetry("Ralph Waldo Emerson", "Brahma"));
    sendNonSerializedData("direct:b", newPoetry("Ralph Waldo Emerson", "The Rhodora"));
    sendNonSerializedData("direct:c", newPoetry("Ralph Waldo Emerson", "Concord Hymn"));
    log.debug("Retrieving data from cache");
    sendEmptyBody("direct:aGet");
    sendEmptyBody("direct:bGet");
    sendEmptyBody("direct:cGet");
    cacheExceptionEndpoint.assertIsSatisfied();
    resultEndpoint.assertIsSatisfied();
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) Test(org.junit.Test)

Example 3 with RouteBuilder

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

the class CacheProducerTest method testUpdatingDataInCacheDoesFailOnEmptyBody.

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

        public void configure() {
            onException(CacheException.class).handled(true).to("log:LOGGER").to("mock:CacheProducerTest.cacheException");
            from("direct:a").setHeader(CacheConstants.CACHE_OPERATION, constant(CacheConstants.CACHE_OPERATION_UPDATE)).setHeader(CacheConstants.CACHE_KEY, constant("Ralph_Waldo_Emerson")).to("cache://TestCache1");
        }
    });
    cacheExceptionEndpoint.expectedMessageCount(1);
    context.start();
    log.debug("------------Beginning CacheProducer Update Does Fail On Empty Body Test---------------");
    sendEmptyBody();
    cacheExceptionEndpoint.assertIsSatisfied();
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) Test(org.junit.Test) BaseCacheTest(org.apache.camel.component.BaseCacheTest)

Example 4 with RouteBuilder

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

the class CacheProducerTest method testCheckDataFromCache.

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

        public void configure() {
            onException(CacheException.class).handled(true).to("log:LOGGER").to("mock:CacheProducerTest.cacheException");
            from("direct:a").setHeader(CacheConstants.CACHE_OPERATION, constant(CacheConstants.CACHE_OPERATION_ADD)).setHeader(CacheConstants.CACHE_KEY, constant("Ralph_Waldo_Emerson")).setBody(constant("Test body")).to("cache://TestCache1").setHeader(CacheConstants.CACHE_OPERATION, constant(CacheConstants.CACHE_OPERATION_URL_CHECK)).setHeader(CacheConstants.CACHE_KEY, constant("Ralph_Waldo_Emerson")).to("cache://TestCache1").choice().when(header(CacheConstants.CACHE_ELEMENT_WAS_FOUND).isNotNull()).to("mock:CacheProducerTest.result").end();
        }
    });
    resultEndpoint.expectedMessageCount(1);
    cacheExceptionEndpoint.expectedMessageCount(0);
    resultEndpoint.expectedBodiesReceived("Test body");
    context.start();
    log.debug("------------Beginning CacheProducer Check An Element Exists Test---------------");
    sendOriginalFile();
    resultEndpoint.assertIsSatisfied();
    cacheExceptionEndpoint.assertIsSatisfied();
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) Test(org.junit.Test) BaseCacheTest(org.apache.camel.component.BaseCacheTest)

Example 5 with RouteBuilder

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

the class CacheProducerTest method testCheckDataFromCacheNegativeTest.

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

        public void configure() {
            onException(CacheException.class).handled(true).to("log:LOGGER").to("mock:CacheProducerTest.cacheException");
            from("direct:a").setHeader(CacheConstants.CACHE_OPERATION, constant(CacheConstants.CACHE_OPERATION_ADD)).setHeader(CacheConstants.CACHE_KEY, constant("Ralph_Waldo_Emerson")).setBody(constant("Test body")).to("cache://TestCache1").setHeader(CacheConstants.CACHE_OPERATION, constant(CacheConstants.CACHE_OPERATION_URL_CHECK)).setHeader(CacheConstants.CACHE_KEY, constant("foo")).to("cache://TestCache1").choice().when(header(CacheConstants.CACHE_ELEMENT_WAS_FOUND).isNotNull()).to("mock:CacheProducerTest.result").end();
        }
    });
    resultEndpoint.expectedMessageCount(0);
    cacheExceptionEndpoint.expectedMessageCount(0);
    context.start();
    log.debug("------------Beginning CacheProducer Check An Element Does Not Exist Test---------------");
    sendOriginalFile();
    resultEndpoint.assertIsSatisfied();
    cacheExceptionEndpoint.assertIsSatisfied();
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) Test(org.junit.Test) BaseCacheTest(org.apache.camel.component.BaseCacheTest)

Aggregations

RouteBuilder (org.apache.camel.builder.RouteBuilder)1744 Exchange (org.apache.camel.Exchange)624 Processor (org.apache.camel.Processor)542 Test (org.junit.Test)470 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)338 CamelExecutionException (org.apache.camel.CamelExecutionException)135 FailedToCreateRouteException (org.apache.camel.FailedToCreateRouteException)119 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)100 File (java.io.File)65 IOException (java.io.IOException)61 CamelContext (org.apache.camel.CamelContext)61 ResolveEndpointFailedException (org.apache.camel.ResolveEndpointFailedException)42 HashMap (java.util.HashMap)34 Path (org.apache.hadoop.fs.Path)34 CountDownLatch (java.util.concurrent.CountDownLatch)32 Configuration (org.apache.hadoop.conf.Configuration)32 ArrayFile (org.apache.hadoop.io.ArrayFile)30 SequenceFile (org.apache.hadoop.io.SequenceFile)30 Endpoint (org.apache.camel.Endpoint)27 RuntimeCamelException (org.apache.camel.RuntimeCamelException)26