Search in sources :

Example 6 with RouteBuilder

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

the class CacheProducerTest method testAddingDataToCache.

@Test
public void testAddingDataToCache() 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("Ralph_Waldo_Emerson")).to("cache://TestCache1");
        }
    });
    context.start();
    log.debug("------------Beginning CacheProducer Add Test---------------");
    sendOriginalFile();
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) Test(org.junit.Test) BaseCacheTest(org.apache.camel.component.BaseCacheTest)

Example 7 with RouteBuilder

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

the class CacheProducerTest method testAddingDataToCacheDoesFailOnEmptyBody.

@Test
public void testAddingDataToCacheDoesFailOnEmptyBody() 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")).to("cache://TestCache1");
        }
    });
    resultEndpoint.expectedMessageCount(0);
    cacheExceptionEndpoint.expectedMessageCount(1);
    context.start();
    log.debug("------------Beginning CacheProducer Add Does Fail On Empty Body Test---------------");
    sendEmptyBody();
    resultEndpoint.assertIsSatisfied();
    cacheExceptionEndpoint.assertIsSatisfied();
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) Test(org.junit.Test) BaseCacheTest(org.apache.camel.component.BaseCacheTest)

Example 8 with RouteBuilder

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

the class CacheProducerTest method testAddingDataElementIdle.

@Test
public void testAddingDataElementIdle() 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("Ralph_Waldo_Emerson")).setHeader(CacheConstants.CACHE_ELEMENT_EXPIRY_IDLE, constant(24)).to("cache://TestCache1");
        }
    });
    context.start();
    log.debug("------------Beginning CacheProducer Add Test---------------");
    sendOriginalFile();
    Element element = fetchElement("Ralph_Waldo_Emerson");
    assertEquals(24, element.getTimeToIdle());
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) Element(net.sf.ehcache.Element) Test(org.junit.Test) BaseCacheTest(org.apache.camel.component.BaseCacheTest)

Example 9 with RouteBuilder

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

the class CacheProducerTest method testQueringDataFromCacheUsingUrlParameters.

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

        public void configure() {
            onException(CacheException.class).handled(true).to("log:LOGGER").to("mock:CacheProducerTest.cacheException");
            from("direct:a").to("cache://TestCache1?operation=add&key=foo").setBody(constant("Don't care. This body will be overridden.")).to("cache://TestCache1?operation=get&key=foo").choice().when(header(CacheConstants.CACHE_ELEMENT_WAS_FOUND).isNotNull()).to("mock:CacheProducerTest.result").end();
        }
    });
    resultEndpoint.expectedMessageCount(1);
    cacheExceptionEndpoint.expectedMessageCount(0);
    resultEndpoint.expectedBodiesReceived(POETRY);
    context.start();
    log.debug("------------Beginning CacheProducer Query An Elements Test---------------");
    sendSerializedData();
    resultEndpoint.assertIsSatisfied();
    cacheExceptionEndpoint.assertIsSatisfied();
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) Test(org.junit.Test) BaseCacheTest(org.apache.camel.component.BaseCacheTest)

Example 10 with RouteBuilder

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

the class CacheProducerTest method testAddingDataElementEternal.

@Test
public void testAddingDataElementEternal() 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("Ralph_Waldo_Emerson")).setHeader(CacheConstants.CACHE_ELEMENT_EXPIRY_ETERNAL, constant(Boolean.TRUE)).to("cache://TestCache1");
        }
    });
    context.start();
    log.debug("------------Beginning CacheProducer Add Test---------------");
    sendOriginalFile();
    Element element = fetchElement("Ralph_Waldo_Emerson");
    assertTrue(element.isEternal());
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) Element(net.sf.ehcache.Element) 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