use of org.apache.camel.ConsumerTemplate in project camel by apache.
the class DefaultConsumerTemplateWithCustomCacheMaxSizeTest method testCacheConsumers.
public void testCacheConsumers() throws Exception {
ConsumerTemplate template = context.createConsumerTemplate();
assertEquals("Size should be 0", 0, template.getCurrentCacheSize());
// test that we cache at most 500 producers to avoid it eating to much memory
for (int i = 0; i < 203; i++) {
Endpoint e = context.getEndpoint("direct:queue:" + i);
template.receiveNoWait(e);
}
// the eviction is async so force cleanup
template.cleanUp();
assertEquals("Size should be 200", 200, template.getCurrentCacheSize());
template.stop();
// should be 0
assertEquals("Size should be 0", 0, template.getCurrentCacheSize());
}
use of org.apache.camel.ConsumerTemplate in project camel by apache.
the class RedeliveryErrorHandlerAsyncDelayedTwoCamelContextIssueTest method shouldNotBreakRedeliveriesOfSecondContextAfterFirstBeingStopped.
@Test
public void shouldNotBreakRedeliveriesOfSecondContextAfterFirstBeingStopped() throws Exception {
DefaultCamelContext context1 = createContext();
ProducerTemplate producer1 = context1.createProducerTemplate();
ConsumerTemplate consumer1 = context1.createConsumerTemplate();
context1.start();
producer1.sendBody("seda://input", "Hey1");
Exchange ex1 = consumer1.receive("seda://output", 5000);
DefaultCamelContext context2 = createContext();
ProducerTemplate producer2 = context2.createProducerTemplate();
ConsumerTemplate consumer2 = context2.createConsumerTemplate();
context2.start();
// now stop 1, and see that 2 is still working
consumer1.stop();
producer1.stop();
context1.stop();
producer2.sendBody("seda://input", "Hey2");
Exchange ex2 = consumer2.receive("seda://output", 5000);
Assert.assertNotNull(ex1);
Assert.assertEquals("Hey1", ex1.getIn().getBody());
Assert.assertNotNull(ex2);
Assert.assertEquals("Hey2", ex2.getIn().getBody());
consumer2.stop();
producer2.stop();
context2.stop();
}
Aggregations