Search in sources :

Example 76 with Producer

use of org.apache.camel.Producer in project camel by apache.

the class EmptyProducerCacheTest method testEmptyCache.

public void testEmptyCache() throws Exception {
    ProducerCache cache = new EmptyProducerCache(this, context);
    cache.start();
    assertEquals("Size should be 0", 0, cache.size());
    // we never cache any producers
    Endpoint e = context.getEndpoint("direct:queue:1");
    Producer p = cache.acquireProducer(e);
    assertEquals("Size should be 0", 0, cache.size());
    cache.releaseProducer(e, p);
    assertEquals("Size should be 0", 0, cache.size());
    cache.stop();
}
Also used : Endpoint(org.apache.camel.Endpoint) Producer(org.apache.camel.Producer)

Example 77 with Producer

use of org.apache.camel.Producer in project camel by apache.

the class EmptyProducerCacheTest method testCacheProducerAcquireAndRelease.

public void testCacheProducerAcquireAndRelease() throws Exception {
    ProducerCache cache = new EmptyProducerCache(this, context);
    cache.start();
    assertEquals("Size should be 0", 0, cache.size());
    // we never cache any producers
    for (int i = 0; i < 1003; i++) {
        Endpoint e = context.getEndpoint("direct:queue:" + i);
        Producer p = cache.acquireProducer(e);
        cache.releaseProducer(e, p);
    }
    assertEquals("Size should be 1000", 0, cache.size());
    cache.stop();
}
Also used : Endpoint(org.apache.camel.Endpoint) Producer(org.apache.camel.Producer) Endpoint(org.apache.camel.Endpoint)

Example 78 with Producer

use of org.apache.camel.Producer in project camel by apache.

the class DefaultProducerCacheTest method testExtendedStatistics.

public void testExtendedStatistics() throws Exception {
    ProducerCache cache = new ProducerCache(this, context, 5);
    cache.setExtendedStatistics(true);
    cache.start();
    assertEquals("Size should be 0", 0, cache.size());
    // use 1 = 2 times
    // use 2 = 3 times
    // use 3..4 = 1 times
    // use 5 = 0 times
    Endpoint e = new MyEndpoint(true, 1);
    Producer p = cache.acquireProducer(e);
    cache.releaseProducer(e, p);
    e = new MyEndpoint(true, 1);
    p = cache.acquireProducer(e);
    cache.releaseProducer(e, p);
    e = new MyEndpoint(true, 2);
    p = cache.acquireProducer(e);
    cache.releaseProducer(e, p);
    e = new MyEndpoint(true, 2);
    p = cache.acquireProducer(e);
    cache.releaseProducer(e, p);
    e = new MyEndpoint(true, 2);
    p = cache.acquireProducer(e);
    cache.releaseProducer(e, p);
    e = new MyEndpoint(true, 3);
    p = cache.acquireProducer(e);
    cache.releaseProducer(e, p);
    e = new MyEndpoint(true, 4);
    p = cache.acquireProducer(e);
    cache.releaseProducer(e, p);
    assertEquals("Size should be 4", 4, cache.size());
    EndpointUtilizationStatistics stats = cache.getEndpointUtilizationStatistics();
    assertEquals(4, stats.size());
    Map<String, Long> recent = stats.getStatistics();
    assertEquals(2, recent.get("my://1").longValue());
    assertEquals(3, recent.get("my://2").longValue());
    assertEquals(1, recent.get("my://3").longValue());
    assertEquals(1, recent.get("my://4").longValue());
    assertNull(recent.get("my://5"));
    cache.stop();
}
Also used : Endpoint(org.apache.camel.Endpoint) Producer(org.apache.camel.Producer) EndpointUtilizationStatistics(org.apache.camel.spi.EndpointUtilizationStatistics)

Example 79 with Producer

use of org.apache.camel.Producer in project camel by apache.

the class DefaultProducerCacheTest method testReleaseProducerInvokesStopAndShutdownByNonSingletonProducers.

public void testReleaseProducerInvokesStopAndShutdownByNonSingletonProducers() throws Exception {
    ProducerCache cache = new ProducerCache(this, context, 1);
    cache.start();
    assertEquals("Size should be 0", 0, cache.size());
    for (int i = 0; i < 3; i++) {
        Endpoint e = new MyEndpoint(false, i);
        Producer p = cache.acquireProducer(e);
        cache.releaseProducer(e, p);
    }
    assertEquals("Size should be 0", 0, cache.size());
    // should have stopped all 3
    assertEquals(3, stopCounter.get());
    // should have shutdown all 3
    assertEquals(3, shutdownCounter.get());
    cache.stop();
    // no more stop after stopping the cache
    assertEquals(3, stopCounter.get());
    // no more shutdown after stopping the cache
    assertEquals(3, shutdownCounter.get());
}
Also used : Endpoint(org.apache.camel.Endpoint) Producer(org.apache.camel.Producer) Endpoint(org.apache.camel.Endpoint)

Example 80 with Producer

use of org.apache.camel.Producer in project camel by apache.

the class DefaultProducerCacheTest method testCacheProducerAcquireAndRelease.

public void testCacheProducerAcquireAndRelease() throws Exception {
    ProducerCache cache = new ProducerCache(this, context);
    cache.start();
    assertEquals("Size should be 0", 0, cache.size());
    // test that we cache at most 1000 producers to avoid it eating to much memory
    for (int i = 0; i < 1003; i++) {
        Endpoint e = context.getEndpoint("direct:queue:" + i);
        Producer p = cache.acquireProducer(e);
        cache.releaseProducer(e, p);
    }
    // the eviction is async so force cleanup
    cache.cleanUp();
    assertEquals("Size should be 1000", 1000, cache.size());
    cache.stop();
}
Also used : Endpoint(org.apache.camel.Endpoint) Producer(org.apache.camel.Producer) Endpoint(org.apache.camel.Endpoint)

Aggregations

Producer (org.apache.camel.Producer)198 Endpoint (org.apache.camel.Endpoint)140 Exchange (org.apache.camel.Exchange)138 Test (org.junit.Test)72 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)69 Processor (org.apache.camel.Processor)34 RouteBuilder (org.apache.camel.builder.RouteBuilder)23 Message (org.apache.camel.Message)21 CountDownLatch (java.util.concurrent.CountDownLatch)16 File (java.io.File)12 CamelContext (org.apache.camel.CamelContext)12 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)10 DefaultExchange (org.apache.camel.impl.DefaultExchange)9 Mockito.anyLong (org.mockito.Mockito.anyLong)9 Consumer (org.apache.camel.Consumer)8 FileDataSource (javax.activation.FileDataSource)7 AsyncProcessor (org.apache.camel.AsyncProcessor)7 DataHandler (javax.activation.DataHandler)6 Field (java.lang.reflect.Field)5 ExchangePattern (org.apache.camel.ExchangePattern)5