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();
}
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();
}
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();
}
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());
}
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();
}
Aggregations