camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r931444 [2/2] - in /camel/trunk: camel-core/src/main/java/org/apache/camel/ camel-core/src/main/java/org/apache/camel/component/bean/ camel-core/src/main/java/org/apache/camel/impl/ camel-core/src/main/java/org/apache/camel/management/mbean...
Date Wed, 07 Apr 2010 06:31:43 GMT
Added: camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultProducerTemplateWithCustomCacheMaxSizeTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultProducerTemplateWithCustomCacheMaxSizeTest.java?rev=931444&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultProducerTemplateWithCustomCacheMaxSizeTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultProducerTemplateWithCustomCacheMaxSizeTest.java Wed Apr  7 06:31:41 2010
@@ -0,0 +1,74 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.impl;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.ProducerTemplate;
+
+/**
+ * @version $Revision$
+ */
+public class DefaultProducerTemplateWithCustomCacheMaxSizeTest extends ContextTestSupport {
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext context = super.createCamelContext();
+        context.getProperties().put(Exchange.MAXIMUM_CACHE_POOL_SIZE, "200");
+        return context;
+    }
+
+    public void testCacheProducers() throws Exception {
+        ProducerTemplate template = context.createProducerTemplate();
+
+        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.sendBody(e, "Hello");
+        }
+
+        assertEquals("Size should be 200", 200, template.getCurrentCacheSize());
+        template.stop();
+
+        // should be 0
+        assertEquals("Size should be 0", 0, template.getCurrentCacheSize());
+    }
+
+    public void testInvalidSizeABC() {
+        context.getProperties().put(Exchange.MAXIMUM_CACHE_POOL_SIZE, "ABC");
+        try {
+            context.createProducerTemplate();
+            fail("Should have thrown an exception");
+        } catch (Exception e) {
+            assertEquals("Property CamelMaximumCachePoolSize must be a positive number, was: ABC", e.getMessage());
+        }
+    }
+
+    public void testInvalidSizeZero() {
+        context.getProperties().put(Exchange.MAXIMUM_CACHE_POOL_SIZE, "0");
+        try {
+            context.createProducerTemplate();
+            fail("Should have thrown an exception");
+        } catch (Exception e) {
+            assertEquals("Property CamelMaximumCachePoolSize must be a positive number, was: 0", e.getMessage());
+        }
+    }
+}

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultProducerTemplateWithCustomCacheMaxSizeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultProducerTemplateWithCustomCacheMaxSizeTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/impl/MainSupportTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/MainSupportTest.java?rev=931444&r1=931443&r2=931444&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/impl/MainSupportTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/impl/MainSupportTest.java Wed Apr  7 06:31:41 2010
@@ -31,7 +31,7 @@ public class MainSupportTest extends Con
 
     private class MyMainSupport extends MainSupport {
 
-        protected ProducerTemplate findOrCreateCamelTemplate() {
+        protected ProducerTemplate findOrCreateCamelTemplate() throws Exception {
             return context.createProducerTemplate();
         }
 

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ServicePoolTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ServicePoolTest.java?rev=931444&r1=931443&r2=931444&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ServicePoolTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ServicePoolTest.java Wed Apr  7 06:31:41 2010
@@ -81,7 +81,7 @@ public class ServicePoolTest extends Con
         assertEquals("Should have stopped the produers", true, cleanup);
     }
 
-    public void testSingleEnry() throws Exception {
+    public void testSingleEntry() throws Exception {
         Endpoint endpoint = context.getEndpoint("mock:foo");
 
         assertNull(pool.acquire(endpoint));
@@ -102,7 +102,7 @@ public class ServicePoolTest extends Con
         assertEquals(1, pool.size());
     }
 
-    public void testTwoEnries() throws Exception {
+    public void testTwoEntries() throws Exception {
         Endpoint endpoint = context.getEndpoint("mock:foo");
 
         Producer producer1 = new MyProducer(endpoint);
@@ -149,7 +149,7 @@ public class ServicePoolTest extends Con
             pool.release(endpoint, producer);
         }
     }
-    
+
     public void testAcquireAdd() throws Exception {
         Endpoint endpoint = context.getEndpoint("mock:foo");
         List<Producer> producers = new ArrayList<Producer>();
@@ -191,11 +191,11 @@ public class ServicePoolTest extends Con
     public void testConcurrent() throws Exception {
         final Endpoint endpoint = context.getEndpoint("mock:foo");
 
-        ExecutorService exectur = Executors.newFixedThreadPool(5);
+        ExecutorService executor = Executors.newFixedThreadPool(5);
         List<Future> response = new ArrayList<Future>();
         for (int i = 0; i < 5; i++) {
             final int index = i;
-            Future out = exectur.submit(new Callable<Object>() {
+            Future out = executor.submit(new Callable<Object>() {
                 public Object call() throws Exception {
                     Producer producer = pool.acquire(endpoint);
                     if (producer == null) {
@@ -218,11 +218,11 @@ public class ServicePoolTest extends Con
     public void testConcurrentStress() throws Exception {
         final Endpoint endpoint = context.getEndpoint("mock:foo");
 
-        ExecutorService exectur = Executors.newFixedThreadPool(5);
+        ExecutorService executor = Executors.newFixedThreadPool(5);
         List<Future> response = new ArrayList<Future>();
         for (int i = 0; i < 5; i++) {
             final int index = i;
-            Future out = exectur.submit(new Callable<Object>() {
+            Future out = executor.submit(new Callable<Object>() {
                 public Object call() throws Exception {
                     for (int j = 0; j < 100; j++) {
                         Producer producer = pool.acquire(endpoint);

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RecipientListParallelFineGrainedErrorHandlingTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RecipientListParallelFineGrainedErrorHandlingTest.java?rev=931444&r1=931443&r2=931444&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RecipientListParallelFineGrainedErrorHandlingTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RecipientListParallelFineGrainedErrorHandlingTest.java Wed Apr  7 06:31:41 2010
@@ -141,7 +141,7 @@ public class RecipientListParallelFineGr
 
     public static class MyRecipientBean {
 
-        @org.apache.camel.RecipientList(stopOnException = true, parallelProcessoing = true)
+        @org.apache.camel.RecipientList(stopOnException = true, parallelProcessing = true)
         public String sendSomewhere(Exchange exchange) {
             return "mock:foo,mock:bar,bean:fail,mock:baz";
         }

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SamplingThrottlerTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SamplingThrottlerTest.java?rev=931444&r1=931443&r2=931444&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SamplingThrottlerTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SamplingThrottlerTest.java Wed Apr  7 06:31:41 2010
@@ -25,6 +25,7 @@ import java.util.concurrent.TimeUnit;
 
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Exchange;
+import org.apache.camel.ProducerTemplate;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.direct.DirectEndpoint;
 import org.apache.camel.component.mock.MockEndpoint;
@@ -76,7 +77,7 @@ public class SamplingThrottlerTest exten
                 public void run() {
                     try {
                         sendExchangesThroughDroppingThrottler(sentExchanges, 35);
-                    } catch (InterruptedException e) {
+                    } catch (Exception e) {
                         // ignore
                     }
                 }
@@ -86,15 +87,21 @@ public class SamplingThrottlerTest exten
         mock.assertIsSatisfied();
     }
 
-    private void sendExchangesThroughDroppingThrottler(List<Exchange> sentExchanges, int messages) throws InterruptedException {
+    private void sendExchangesThroughDroppingThrottler(List<Exchange> sentExchanges, int messages) throws Exception {
+        ProducerTemplate myTemplate = context.createProducerTemplate();
+
         DirectEndpoint targetEndpoint = resolveMandatoryEndpoint("direct:sample", DirectEndpoint.class);
         for (int i = 0; i < messages; i++) {
             Exchange e = targetEndpoint.createExchange();
             e.getIn().setBody("<message>" + i + "</message>");
-            template.send(targetEndpoint, e);
-            sentExchanges.add(e);
-            Thread.sleep(100);
+            // only send if we are still started
+            if (context.getStatus().isStarted()) {
+                myTemplate.send(targetEndpoint, e);
+                sentExchanges.add(e);
+                Thread.sleep(100);
+            }
         }
+        myTemplate.stop();
     }
 
     private void validateDroppedExchanges(List<Exchange> sentExchanges, int expectedNotDroppedCount) {

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregateProcessorTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregateProcessorTest.java?rev=931444&r1=931443&r2=931444&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregateProcessorTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregateProcessorTest.java Wed Apr  7 06:31:41 2010
@@ -467,7 +467,9 @@ public class AggregateProcessorTest exte
                     throw new IllegalArgumentException("Damn");
                 }
                 // else send it further along
-                new SendProcessor(context.getEndpoint("mock:result")).process(exchange);
+                SendProcessor send = new SendProcessor(context.getEndpoint("mock:result"));
+                send.start();
+                send.process(exchange);
             }
         };
                 

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/aggregator/AlbertoAggregatorTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/aggregator/AlbertoAggregatorTest.java?rev=931444&r1=931443&r2=931444&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/aggregator/AlbertoAggregatorTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/aggregator/AlbertoAggregatorTest.java Wed Apr  7 06:31:41 2010
@@ -24,7 +24,6 @@ import java.util.Map;
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
-import org.apache.camel.ProducerTemplate;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.model.AggregateDefinition;
@@ -64,7 +63,6 @@ public class AlbertoAggregatorTest exten
         resultEndpoint.expectedMessageCount(1);
         resultEndpoint.expectedBodiesReceived(allBrothers);
 
-        ProducerTemplate template = context.createProducerTemplate();
         template.sendBody("direct:start", allNames);
 
         assertMockEndpointsSatisfied();

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/aggregator/SplitRouteNumberOfProcessorTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/aggregator/SplitRouteNumberOfProcessorTest.java?rev=931444&r1=931443&r2=931444&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/aggregator/SplitRouteNumberOfProcessorTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/aggregator/SplitRouteNumberOfProcessorTest.java Wed Apr  7 06:31:41 2010
@@ -16,9 +16,12 @@
  */
 package org.apache.camel.processor.aggregator;
 
+import java.util.concurrent.atomic.AtomicBoolean;
+
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
+import org.apache.camel.ProducerTemplate;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.processor.aggregate.AggregationStrategy;
@@ -28,15 +31,15 @@ import org.apache.camel.processor.aggreg
  */
 public class SplitRouteNumberOfProcessorTest extends ContextTestSupport {
 
-    private static volatile boolean failed;
+    private static AtomicBoolean failed = new AtomicBoolean();
 
     @Override
     public boolean isUseRouteBuilder() {
         return false;
     }
 
-    public void testOneProcesssor() throws Exception {
-        failed = false;
+    public void testOneProcessor() throws Exception {
+        failed.set(false);
 
         context.addRoutes(new RouteBuilder() {
             @Override
@@ -55,7 +58,7 @@ public class SplitRouteNumberOfProcessor
                     })
                         .process(new Processor() {
                             public void process(Exchange exchange) throws Exception {
-                                assertFalse("Should not have out", failed);
+                                assertFalse("Should not have out", failed.get());
                                 String s = exchange.getIn().getBody(String.class);
                                 exchange.getIn().setBody("Hi " + s);
                                 context.createProducerTemplate().send("mock:foo", exchange);
@@ -77,8 +80,8 @@ public class SplitRouteNumberOfProcessor
         assertMockEndpointsSatisfied();
     }
 
-    public void testThreeProcesssors() throws Exception {
-        failed = false;
+    public void testThreeProcessors() throws Exception {
+        failed.set(false);
 
         context.addRoutes(new RouteBuilder() {
             @Override
@@ -99,7 +102,7 @@ public class SplitRouteNumberOfProcessor
                         .to("log:foo")
                         .process(new Processor() {
                             public void process(Exchange exchange) throws Exception {
-                                assertFalse("Should not have out", failed);
+                                assertFalse("Should not have out", failed.get());
                                 String s = exchange.getIn().getBody(String.class);
                                 exchange.getIn().setBody("Hi " + s);
                                 context.createProducerTemplate().send("mock:foo", exchange);

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/onexception/OnExceptionProcessorInspectCausedExceptionTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/onexception/OnExceptionProcessorInspectCausedExceptionTest.java?rev=931444&r1=931443&r2=931444&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/onexception/OnExceptionProcessorInspectCausedExceptionTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/onexception/OnExceptionProcessorInspectCausedExceptionTest.java Wed Apr  7 06:31:41 2010
@@ -49,7 +49,7 @@ public class OnExceptionProcessorInspect
 
                 // START SNIPPET: e1
                 // here we register exception cause for MyFunctionException
-                // when this exception occur we want it to be processed by our proceesor
+                // when this exception occur we want it to be processed by our processor
                 onException(MyFunctionalException.class).process(new MyFunctionFailureHandler()).stop();
                 // END SNIPPET: e1
 

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/onexception/OnExceptionProcessorInspectCausedExceptionWithDefaultErrorHandlerTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/onexception/OnExceptionProcessorInspectCausedExceptionWithDefaultErrorHandlerTest.java?rev=931444&r1=931443&r2=931444&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/onexception/OnExceptionProcessorInspectCausedExceptionWithDefaultErrorHandlerTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/onexception/OnExceptionProcessorInspectCausedExceptionWithDefaultErrorHandlerTest.java Wed Apr  7 06:31:41 2010
@@ -48,7 +48,7 @@ public class OnExceptionProcessorInspect
 
                 // START SNIPPET: e1
                 // here we register exception cause for MyFunctionException
-                // when this exception occur we want it to be processed by our proceesor
+                // when this exception occur we want it to be processed by our processor
                 onException(MyFunctionalException.class).process(new MyFunctionFailureHandler());
                 // END SNIPPET: e1
 

Modified: camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/transport/CamelConduit.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/transport/CamelConduit.java?rev=931444&r1=931443&r2=931444&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/transport/CamelConduit.java (original)
+++ camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/transport/CamelConduit.java Wed Apr  7 06:31:41 2010
@@ -144,7 +144,7 @@ public class CamelConduit extends Abstra
     }
 
     @Deprecated
-    public ProducerTemplate getCamelTemplate() {
+    public ProducerTemplate getCamelTemplate() throws Exception {
         if (camelTemplate == null) {            
             camelTemplate = getCamelContext().createProducerTemplate();
         }

Modified: camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/transport/CamelDestination.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/transport/CamelDestination.java?rev=931444&r1=931443&r2=931444&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/transport/CamelDestination.java (original)
+++ camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/transport/CamelDestination.java Wed Apr  7 06:31:41 2010
@@ -60,7 +60,7 @@ public class CamelDestination extends Ab
     String camelDestinationUri;
 
     private ProducerTemplate camelTemplate;
-    private Endpoint distinationEndpoint;
+    private Endpoint destinationEndpoint;
     private HeaderFilterStrategy headerFilterStrategy;
     private boolean checkException;
 
@@ -107,8 +107,8 @@ public class CamelDestination extends Ab
 
         try {
             getLogger().log(Level.FINE, "establishing Camel connection");
-            distinationEndpoint = getCamelContext().getEndpoint(camelDestinationUri);
-            consumer = distinationEndpoint.createConsumer(new ConsumerProcessor());
+            destinationEndpoint = getCamelContext().getEndpoint(camelDestinationUri);
+            consumer = destinationEndpoint.createConsumer(new ConsumerProcessor());
             consumer.start();
 
         } catch (Exception ex) {
@@ -131,7 +131,7 @@ public class CamelDestination extends Ab
         this.deactivate();
     }
 
-    public ProducerTemplate getCamelTemplate() {
+    public ProducerTemplate getCamelTemplate() throws Exception {
         if (camelTemplate == null) {            
             camelTemplate = getCamelContext().createProducerTemplate();
         }

Modified: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfProducerTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfProducerTest.java?rev=931444&r1=931443&r2=931444&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfProducerTest.java (original)
+++ camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfProducerTest.java Wed Apr  7 06:31:41 2010
@@ -19,7 +19,6 @@ package org.apache.camel.component.cxf;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
-
 import javax.xml.ws.Endpoint;
 
 import org.apache.camel.CamelContext;
@@ -35,7 +34,9 @@ import org.apache.cxf.endpoint.Client;
 import org.apache.cxf.frontend.ServerFactoryBean;
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.hello_world_soap_http.GreeterImpl;
+import org.junit.After;
 import org.junit.Assert;
+import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
@@ -52,9 +53,9 @@ public class CxfProducerTest extends Ass
 
     private static final transient Log LOG = LogFactory.getLog(CxfProducerTest.class);
 
-    protected CamelContext camelContext = new DefaultCamelContext();
-    protected ProducerTemplate template = camelContext.createProducerTemplate();
-    
+    protected CamelContext camelContext;
+    protected ProducerTemplate template;
+
     @BeforeClass
     public static void startService() throws Exception {
         // start a simple front service
@@ -69,6 +70,19 @@ public class CxfProducerTest extends Ass
         Endpoint.publish(JAXWS_SERVER_ADDRESS, greeterImpl);
     }
 
+    @Before
+    public void setUp() throws Exception {
+        camelContext = new DefaultCamelContext();
+        camelContext.start();
+        template = camelContext.createProducerTemplate();
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        template.stop();
+        camelContext.stop();
+    }
+
     @Test
     public void testInvokingSimpleServerWithParams() throws Exception {
         Exchange exchange = sendSimpleMessage();

Modified: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/transport/CamelJBIClientProxyTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/transport/CamelJBIClientProxyTest.java?rev=931444&r1=931443&r2=931444&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/transport/CamelJBIClientProxyTest.java (original)
+++ camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/transport/CamelJBIClientProxyTest.java Wed Apr  7 06:31:41 2010
@@ -49,7 +49,7 @@ public class CamelJBIClientProxyTest {
     }
     
     @Test
-    public void testCallFromCamel() {
+    public void testCallFromCamel() throws Exception {
         // get camel context
         CamelContext context = (CamelContext) applicationContext.getBean("conduit_context");
         ProducerTemplate producer = context.createProducerTemplate();

Modified: camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/Main.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/Main.java?rev=931444&r1=931443&r2=931444&view=diff
==============================================================================
--- camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/Main.java (original)
+++ camel/trunk/components/camel-guice/src/main/java/org/apache/camel/guice/Main.java Wed Apr  7 06:31:41 2010
@@ -52,8 +52,6 @@ public class Main extends MainSupport {
     private String jndiProperties;
  
     public Main() {
-
-
         addOption(new ParameterOption("j", "jndiProperties",
                 "Sets the classpath based jndi properties file location", "jndiProperties") {
             @Override
@@ -62,7 +60,6 @@ public class Main extends MainSupport {
                 
             }
         });
-
     }
     
     public void setJndiProperties(String properties) {
@@ -125,15 +122,14 @@ public class Main extends MainSupport {
     }
 
     protected void doStop() throws Exception {
-        LOG.info("Apache Camel terminating");
-
+        LOG.info("Apache Camel stopping");
 
         if (injector != null) {
             Injectors.close(injector);
         }
     }
 
-    protected ProducerTemplate findOrCreateCamelTemplate() {
+    protected ProducerTemplate findOrCreateCamelTemplate() throws Exception {
         if (injector != null) {
             Set<ProducerTemplate> set = Injectors.getInstancesOf(injector, ProducerTemplate.class);
             if (!set.isEmpty()) {

Modified: camel/trunk/components/camel-jdbc/src/test/java/org/apache/camel/component/jdbc/JdbcEndpointTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jdbc/src/test/java/org/apache/camel/component/jdbc/JdbcEndpointTest.java?rev=931444&r1=931443&r2=931444&view=diff
==============================================================================
--- camel/trunk/components/camel-jdbc/src/test/java/org/apache/camel/component/jdbc/JdbcEndpointTest.java (original)
+++ camel/trunk/components/camel-jdbc/src/test/java/org/apache/camel/component/jdbc/JdbcEndpointTest.java Wed Apr  7 06:31:41 2010
@@ -27,6 +27,7 @@ public class JdbcEndpointTest extends Jd
         return new RouteBuilder() {
             public void configure() throws Exception {
                 JdbcEndpoint jdbc = new JdbcEndpoint();
+                jdbc.setCamelContext(context);
                 jdbc.setDataSource(ds);
                 context.addEndpoint("foo", jdbc);
 

Modified: camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsInOutWithSpringRestartIssueTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsInOutWithSpringRestartIssueTest.java?rev=931444&r1=931443&r2=931444&view=diff
==============================================================================
--- camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsInOutWithSpringRestartIssueTest.java (original)
+++ camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsInOutWithSpringRestartIssueTest.java Wed Apr  7 06:31:41 2010
@@ -42,6 +42,7 @@ public class JmsInOutWithSpringRestartIs
         context.start();
 
         ProducerTemplate producer = context.createProducerTemplate();
+        producer.start();
 
         Object out = producer.requestBody("activemq:queue:foo", "Foo");
         assertEquals("Bye Foo", out);
@@ -50,12 +51,12 @@ public class JmsInOutWithSpringRestartIs
         //producer.stop();
         context.stop();
 
-        Thread.sleep(2000);
-
         // TODO: Does not work properly with AMQ 5.3.1
+        // Thread.sleep(2000);
         // context.start();
 
         //producer = context.createProducerTemplate();
+        //producer.start();
 
         // out = producer.requestBody("activemq:queue:foo", "Bar");
         //assertEquals("Bye Bar", out);

Modified: camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsRedeliveryWithInitialRedeliveryDelayTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsRedeliveryWithInitialRedeliveryDelayTest.java?rev=931444&r1=931443&r2=931444&view=diff
==============================================================================
--- camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsRedeliveryWithInitialRedeliveryDelayTest.java (original)
+++ camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsRedeliveryWithInitialRedeliveryDelayTest.java Wed Apr  7 06:31:41 2010
@@ -18,6 +18,7 @@ package org.apache.camel.component.jms.i
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.Exchange;
+import org.apache.camel.ProducerTemplate;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -25,7 +26,7 @@ import org.springframework.test.context.
 import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
 
 /**
- * Unit test to verify DLC and JSM based on user reporting
+ * Unit test to verify DLC and JMS based on user reporting
  */
 @ContextConfiguration
 public class JmsRedeliveryWithInitialRedeliveryDelayTest extends AbstractJUnit4SpringContextTests {
@@ -33,6 +34,9 @@ public class JmsRedeliveryWithInitialRed
     @Autowired
     protected CamelContext context;
 
+    @Autowired
+    protected ProducerTemplate template;
+
     @Test
     public void testDLCSpringConfiguredRedeliveryPolicy() throws Exception {
         MockEndpoint dead = context.getEndpoint("mock:dead", MockEndpoint.class);
@@ -43,7 +47,7 @@ public class JmsRedeliveryWithInitialRed
         dead.message(0).header(Exchange.REDELIVERY_COUNTER).isEqualTo(4);
         result.expectedMessageCount(0);
 
-        context.createProducerTemplate().sendBody("activemq:in", "Hello World");
+        template.sendBody("activemq:in", "Hello World");
 
         result.assertIsSatisfied();
         dead.assertIsSatisfied();

Modified: camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsResequencerTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsResequencerTest.java?rev=931444&r1=931443&r2=931444&view=diff
==============================================================================
--- camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsResequencerTest.java (original)
+++ camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsResequencerTest.java Wed Apr  7 06:31:41 2010
@@ -21,7 +21,6 @@ import org.apache.camel.EndpointInject;
 import org.apache.camel.ProducerTemplate;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.junit.After;
-import org.junit.Before;
 import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.test.context.ContextConfiguration;
@@ -39,13 +38,9 @@ public class JmsResequencerTest extends 
     @EndpointInject(uri = "mock:result")
     protected MockEndpoint result;
 
+    @Autowired
     protected ProducerTemplate template;
     
-    @Before
-    public void setUp() {
-        template = context.createProducerTemplate();
-    }
-    
     @After
     public void tearDown() {
         result.reset();

Modified: camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/TransactionErrorHandlerRedeliveryDelayTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/TransactionErrorHandlerRedeliveryDelayTest.java?rev=931444&r1=931443&r2=931444&view=diff
==============================================================================
--- camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/TransactionErrorHandlerRedeliveryDelayTest.java (original)
+++ camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/TransactionErrorHandlerRedeliveryDelayTest.java Wed Apr  7 06:31:41 2010
@@ -20,6 +20,7 @@ import org.apache.camel.CamelContext;
 import org.apache.camel.EndpointInject;
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
+import org.apache.camel.ProducerTemplate;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -39,6 +40,9 @@ public class TransactionErrorHandlerRede
     @Autowired
     protected CamelContext context;
 
+    @Autowired
+    protected ProducerTemplate producer;
+
     @EndpointInject(uri = "mock:result")
     protected MockEndpoint result;
 
@@ -47,7 +51,7 @@ public class TransactionErrorHandlerRede
         result.expectedMessageCount(1);
         result.expectedBodiesReceived("Bye World");
 
-        context.createProducerTemplate().sendBody("activemq:queue:in", "Hello World");
+        producer.sendBody("activemq:queue:in", "Hello World");
 
         result.assertIsSatisfied();
     }

Modified: camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaTest.java?rev=931444&r1=931443&r2=931444&view=diff
==============================================================================
--- camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaTest.java (original)
+++ camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaTest.java Wed Apr  7 06:31:41 2010
@@ -48,7 +48,7 @@ import static org.apache.camel.util.Serv
 public class JpaTest extends Assert {
     private static final transient Log LOG = LogFactory.getLog(JpaTest.class);
     protected CamelContext camelContext = new DefaultCamelContext();
-    protected ProducerTemplate template = camelContext.createProducerTemplate();
+    protected ProducerTemplate template;
     protected JpaEndpoint endpoint;
     protected TransactionStrategy transactionStrategy;
     protected JpaTemplate jpaTemplate;
@@ -108,7 +108,7 @@ public class JpaTest extends Assert {
 
     @Before
     public void setUp() throws Exception {
-        
+        template = camelContext.createProducerTemplate();
         startServices(template, camelContext);
 
         Endpoint value = camelContext.getEndpoint(getEndpointUri());
@@ -126,8 +126,6 @@ public class JpaTest extends Assert {
 
     @After
     public void tearDown() throws Exception {
-
         stopServices(consumer, template, camelContext);
-        
     }
 }

Modified: camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaWithNamedQueryTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaWithNamedQueryTest.java?rev=931444&r1=931443&r2=931444&view=diff
==============================================================================
--- camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaWithNamedQueryTest.java (original)
+++ camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaWithNamedQueryTest.java Wed Apr  7 06:31:41 2010
@@ -47,7 +47,7 @@ import org.springframework.orm.jpa.JpaTe
 public class JpaWithNamedQueryTest extends Assert {
     private static final transient Log LOG = LogFactory.getLog(JpaWithNamedQueryTest.class);
     protected CamelContext camelContext = new DefaultCamelContext();
-    protected ProducerTemplate template = camelContext.createProducerTemplate();
+    protected ProducerTemplate template;
     protected JpaEndpoint endpoint;
     protected TransactionStrategy transactionStrategy;
     protected JpaTemplate jpaTemplate;
@@ -140,7 +140,7 @@ public class JpaWithNamedQueryTest exten
 
     @Before
     public void setUp() throws Exception {
-        
+        template = camelContext.createProducerTemplate();
         ServiceHelper.startServices(template, camelContext);
 
         Endpoint value = camelContext.getEndpoint(getEndpointUri());
@@ -158,8 +158,6 @@ public class JpaWithNamedQueryTest exten
 
     @After
     public void tearDown() throws Exception {
-
         ServiceHelper.stopServices(consumer, template, camelContext);
-
     }
 }

Modified: camel/trunk/components/camel-spring-integration/src/main/java/org/apache/camel/component/spring/integration/adapter/CamelTargetAdapter.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring-integration/src/main/java/org/apache/camel/component/spring/integration/adapter/CamelTargetAdapter.java?rev=931444&r1=931443&r2=931444&view=diff
==============================================================================
--- camel/trunk/components/camel-spring-integration/src/main/java/org/apache/camel/component/spring/integration/adapter/CamelTargetAdapter.java (original)
+++ camel/trunk/components/camel-spring-integration/src/main/java/org/apache/camel/component/spring/integration/adapter/CamelTargetAdapter.java Wed Apr  7 06:31:41 2010
@@ -30,10 +30,9 @@ import org.springframework.integration.c
 import org.springframework.integration.core.MessageHeaders;
 import org.springframework.integration.message.MessageDeliveryException;
 import org.springframework.integration.message.MessageHandler;
-import org.springframework.integration.message.MessageRejectedException;
 
 /**
- * CamelTargeAdapter will redirect the Spring Integration message to the Camel context.
+ * CamelTargetAdapter will redirect the Spring Integration message to the Camel context.
  * When we inject the camel context into it, we need also specify the Camel endpoint url
  * we will route the Spring Integration message to the Camel context
  *
@@ -54,7 +53,7 @@ public class CamelTargetAdapter extends 
         return replyChannel;
     }
 
-    public ProducerTemplate getCamelTemplate() {
+    public ProducerTemplate getCamelTemplate() throws Exception {
         if (camelTemplate == null) {
             CamelContext ctx = getCamelContext();
             if (ctx == null) {
@@ -65,7 +64,7 @@ public class CamelTargetAdapter extends 
         return camelTemplate;
     }
 
-    public boolean send(Message<?> message) throws MessageRejectedException, MessageDeliveryException {
+    public boolean send(Message<?> message) throws Exception {
         ExchangePattern pattern;
         boolean result = false;
         if (isExpectReply()) {
@@ -73,7 +72,7 @@ public class CamelTargetAdapter extends 
         } else {
             pattern = ExchangePattern.InOnly;
         }
-        Exchange inExchange = new DefaultExchange(getCamelContext(), pattern);        
+        Exchange inExchange = new DefaultExchange(getCamelContext(), pattern);
         SpringIntegrationBinding.storeToCamelMessage(message, inExchange.getIn());
         Exchange outExchange = getCamelTemplate().send(getCamelEndpointUri(), inExchange);
         if (outExchange.getOut() != null && outExchange.getOut().isFault()) {
@@ -97,8 +96,12 @@ public class CamelTargetAdapter extends 
         return result;
     }
 
-    public void handleMessage(Message<?> message) {
-        send(message);        
+    public void handleMessage(Message<?> message) throws MessageDeliveryException {
+        try {
+            send(message);
+        } catch (Exception e) {
+            throw new MessageDeliveryException(message, "Cannot send message", e);
+        }
     }
 
 }

Modified: camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelConsumerTemplateFactoryBean.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelConsumerTemplateFactoryBean.java?rev=931444&r1=931443&r2=931444&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelConsumerTemplateFactoryBean.java (original)
+++ camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelConsumerTemplateFactoryBean.java Wed Apr  7 06:31:41 2010
@@ -24,6 +24,7 @@ import javax.xml.bind.annotation.XmlTran
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.CamelContextAware;
+import org.apache.camel.ConsumerTemplate;
 import org.apache.camel.impl.DefaultConsumerTemplate;
 import org.apache.camel.model.IdentifiedType;
 import org.apache.camel.spring.util.CamelContextResolverHelper;
@@ -45,9 +46,11 @@ public class CamelConsumerTemplateFactor
     @XmlAttribute
     private String camelContextId;
     @XmlTransient
-    private CamelContext camelContext;    
+    private CamelContext camelContext;
     @XmlTransient
     private ApplicationContext applicationContext;
+    @XmlAttribute
+    private Integer maximumCacheSize;
 
     public void afterPropertiesSet() throws Exception {
         if (camelContext == null && camelContextId != null) {
@@ -59,7 +62,16 @@ public class CamelConsumerTemplateFactor
     }
 
     public Object getObject() throws Exception {
-        return new DefaultConsumerTemplate(getCamelContext());
+        ConsumerTemplate answer = new DefaultConsumerTemplate(camelContext);
+
+        // set custom cache size if provided
+        if (maximumCacheSize != null) {
+            answer.setMaximumCacheSize(maximumCacheSize);
+        }
+
+        // must start it so its ready to use
+        answer.start();
+        return answer;
     }
 
     public Class getObjectType() {
@@ -72,6 +84,7 @@ public class CamelConsumerTemplateFactor
 
     // Properties
     // -------------------------------------------------------------------------
+
     public CamelContext getCamelContext() {
         return camelContext;
     }
@@ -88,4 +101,11 @@ public class CamelConsumerTemplateFactor
         this.camelContextId = camelContextId;
     }
 
+    public Integer getMaximumCacheSize() {
+        return maximumCacheSize;
+    }
+
+    public void setMaximumCacheSize(Integer maximumCacheSize) {
+        this.maximumCacheSize = maximumCacheSize;
+    }
 }
\ No newline at end of file

Modified: camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelProducerTemplateFactoryBean.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelProducerTemplateFactoryBean.java?rev=931444&r1=931443&r2=931444&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelProducerTemplateFactoryBean.java (original)
+++ camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelProducerTemplateFactoryBean.java Wed Apr  7 06:31:41 2010
@@ -25,6 +25,7 @@ import javax.xml.bind.annotation.XmlTran
 import org.apache.camel.CamelContext;
 import org.apache.camel.CamelContextAware;
 import org.apache.camel.Endpoint;
+import org.apache.camel.ProducerTemplate;
 import org.apache.camel.impl.DefaultProducerTemplate;
 import org.apache.camel.model.IdentifiedType;
 import org.apache.camel.spring.util.CamelContextResolverHelper;
@@ -51,6 +52,8 @@ public class CamelProducerTemplateFactor
     private CamelContext camelContext;
     @XmlTransient
     private ApplicationContext applicationContext;
+    @XmlAttribute
+    private Integer maximumCacheSize;
 
     public void afterPropertiesSet() throws Exception {
         if (camelContext == null && camelContextId != null) {
@@ -62,16 +65,28 @@ public class CamelProducerTemplateFactor
     }
 
     public Object getObject() throws Exception {
+        ProducerTemplate answer;
+
         CamelContext context = getCamelContext();
         if (defaultEndpoint != null) {
             Endpoint endpoint = context.getEndpoint(defaultEndpoint);
             if (endpoint == null) {
                 throw new IllegalArgumentException("No endpoint found for URI: " + defaultEndpoint);
             } else {
-                return new DefaultProducerTemplate(context, endpoint);
+                answer = new DefaultProducerTemplate(context, endpoint);
             }
+        } else {
+            answer = new DefaultProducerTemplate(context);
         }
-        return new DefaultProducerTemplate(context);
+
+        // set custom cache size if provided
+        if (maximumCacheSize != null) {
+            answer.setMaximumCacheSize(maximumCacheSize);
+        }
+
+        // must start it so its ready to use
+        answer.start();
+        return answer;
     }
 
     public Class getObjectType() {
@@ -106,5 +121,12 @@ public class CamelProducerTemplateFactor
     public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
         this.applicationContext = applicationContext;
     }
-    
+
+    public Integer getMaximumCacheSize() {
+        return maximumCacheSize;
+    }
+
+    public void setMaximumCacheSize(Integer maximumCacheSize) {
+        this.maximumCacheSize = maximumCacheSize;
+    }
 }

Modified: camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/Main.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/Main.java?rev=931444&r1=931443&r2=931444&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/Main.java (original)
+++ camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/Main.java Wed Apr  7 06:31:41 2010
@@ -186,7 +186,7 @@ public class Main extends MainSupport {
         }
     }
 
-    protected ProducerTemplate findOrCreateCamelTemplate() {
+    protected ProducerTemplate findOrCreateCamelTemplate() throws Exception {
         String[] names = getApplicationContext().getBeanNamesForType(ProducerTemplate.class);
         if (names != null && names.length > 0) {
             return (ProducerTemplate) getApplicationContext().getBean(names[0], ProducerTemplate.class);

Modified: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/CustomProcessorWithNamespacesTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/CustomProcessorWithNamespacesTest.java?rev=931444&r1=931443&r2=931444&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/CustomProcessorWithNamespacesTest.java (original)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/CustomProcessorWithNamespacesTest.java Wed Apr  7 06:31:41 2010
@@ -43,6 +43,7 @@ public class CustomProcessorWithNamespac
 
         // now lets send a message
         ProducerTemplate template = context.createProducerTemplate();
+        template.start();
         template.send("direct:start", new Processor() {
             public void process(Exchange exchange) {
                 Message in = exchange.getIn();
@@ -50,6 +51,7 @@ public class CustomProcessorWithNamespac
                 in.setBody(body);
             }
         });
+        template.stop();
 
         List list = MyProcessor.getExchanges();
         assertEquals("Should have received a single exchange: " + list, 1, list.size());

Modified: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/RoutingUsingCamelContextFactoryTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/RoutingUsingCamelContextFactoryTest.java?rev=931444&r1=931443&r2=931444&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/RoutingUsingCamelContextFactoryTest.java (original)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/RoutingUsingCamelContextFactoryTest.java Wed Apr  7 06:31:41 2010
@@ -46,6 +46,7 @@ public class RoutingUsingCamelContextFac
 
         // now lets send a message
         ProducerTemplate template = context.createProducerTemplate();
+        template.start();
         template.send("seda:start", new Processor() {
             public void process(Exchange exchange) {
                 Message in = exchange.getIn();
@@ -53,6 +54,7 @@ public class RoutingUsingCamelContextFac
                 in.setBody(body);
             }
         });
+        template.stop();
 
         resultEndpoint.assertIsSatisfied();
     }

Modified: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/CamelContextAutoStartupTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/CamelContextAutoStartupTest.java?rev=931444&r1=931443&r2=931444&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/CamelContextAutoStartupTest.java (original)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/CamelContextAutoStartupTest.java Wed Apr  7 06:31:41 2010
@@ -17,6 +17,7 @@
 package org.apache.camel.spring.config;
 
 import junit.framework.TestCase;
+import org.apache.camel.ProducerTemplate;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.spring.SpringCamelContext;
 import org.apache.commons.logging.Log;
@@ -55,7 +56,10 @@ public class CamelContextAutoStartupTest
         MockEndpoint mock = camel.getEndpoint("mock:result", MockEndpoint.class);
         mock.expectedMessageCount(1);
 
-        camel.createProducerTemplate().sendBody("direct:start", "Hello World");
+        ProducerTemplate template = camel.createProducerTemplate();
+        template.start();
+        template.sendBody("direct:start", "Hello World");
+        template.stop();
 
         mock.assertIsSatisfied();
     }
@@ -73,7 +77,10 @@ public class CamelContextAutoStartupTest
         MockEndpoint mock = camel.getEndpoint("mock:result", MockEndpoint.class);
         mock.expectedMessageCount(1);
 
-        camel.createProducerTemplate().sendBody("direct:start", "Hello World");
+        ProducerTemplate template = camel.createProducerTemplate();
+        template.start();
+        template.sendBody("direct:start", "Hello World");
+        template.stop();
 
         mock.assertIsSatisfied();
     }

Added: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/ConsumerTemplateMaximumCacheSizeTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/ConsumerTemplateMaximumCacheSizeTest.java?rev=931444&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/ConsumerTemplateMaximumCacheSizeTest.java (added)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/ConsumerTemplateMaximumCacheSizeTest.java Wed Apr  7 06:31:41 2010
@@ -0,0 +1,61 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.spring.config;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ConsumerTemplate;
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests;
+
+/**
+ * @version $Revision$
+ */
+@ContextConfiguration
+public class ConsumerTemplateMaximumCacheSizeTest extends AbstractJUnit38SpringContextTests {
+
+    @Autowired
+    private ConsumerTemplate template;
+
+    @Autowired
+    private CamelContext context;
+
+    public void testTemplateMaximumCache() throws Exception {
+        assertNotNull("Should have injected a consumer template", template);
+
+        ConsumerTemplate lookup = context.getRegistry().lookup("template", ConsumerTemplate.class);
+        assertNotNull("Should lookup consumer template", lookup);
+
+        assertEquals(50, template.getMaximumCacheSize());
+        assertEquals("Size should be 0", 0, template.getCurrentCacheSize());
+
+        // test that we cache at most 50 producers to avoid it eating to much memory
+        for (int i = 0; i < 53; i++) {
+            Endpoint e = context.getEndpoint("direct:queue:" + i);
+            Exchange ex = template.receiveNoWait(e);
+        }
+
+        assertEquals("Size should be 50", 50, template.getCurrentCacheSize());
+        template.stop();
+
+        // should be 0
+        assertEquals("Size should be 0", 0, template.getCurrentCacheSize());
+    }
+
+}
\ No newline at end of file

Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/ConsumerTemplateMaximumCacheSizeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/ConsumerTemplateMaximumCacheSizeTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Copied: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/ProducerTemplateMaximumCacheSizeTest.java (from r931425, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/ProducerTemplateAutoRegisterTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/ProducerTemplateMaximumCacheSizeTest.java?p2=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/ProducerTemplateMaximumCacheSizeTest.java&p1=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/ProducerTemplateAutoRegisterTest.java&r1=931425&r2=931444&rev=931444&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/ProducerTemplateAutoRegisterTest.java (original)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/ProducerTemplateMaximumCacheSizeTest.java Wed Apr  7 06:31:41 2010
@@ -17,6 +17,7 @@
 package org.apache.camel.spring.config;
 
 import org.apache.camel.CamelContext;
+import org.apache.camel.Endpoint;
 import org.apache.camel.ProducerTemplate;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.test.context.ContextConfiguration;
@@ -26,7 +27,7 @@ import org.springframework.test.context.
  * @version $Revision$
  */
 @ContextConfiguration
-public class ProducerTemplateAutoRegisterTest extends AbstractJUnit38SpringContextTests {
+public class ProducerTemplateMaximumCacheSizeTest extends AbstractJUnit38SpringContextTests {
 
     @Autowired
     private ProducerTemplate template;
@@ -34,10 +35,26 @@ public class ProducerTemplateAutoRegiste
     @Autowired
     private CamelContext context;
 
-    public void testHasTemplate() {
+    public void testTemplateMaximumCache() throws Exception {
         assertNotNull("Should have injected a producer template", template);
 
         ProducerTemplate lookup = context.getRegistry().lookup("template", ProducerTemplate.class);
         assertNotNull("Should lookup producer template", lookup);
+
+        assertEquals(50, template.getMaximumCacheSize());
+        assertEquals("Size should be 0", 0, template.getCurrentCacheSize());
+
+        // test that we cache at most 50 producers to avoid it eating to much memory
+        for (int i = 0; i < 53; i++) {
+            Endpoint e = context.getEndpoint("direct:queue:" + i);
+            template.sendBody(e, "Hello");
+        }
+
+        assertEquals("Size should be 50", 50, template.getCurrentCacheSize());
+        template.stop();
+
+        // should be 0
+        assertEquals("Size should be 0", 0, template.getCurrentCacheSize());
     }
-}
+
+}
\ No newline at end of file

Modified: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/scan/SpringComponentScanTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/scan/SpringComponentScanTest.java?rev=931444&r1=931443&r2=931444&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/scan/SpringComponentScanTest.java (original)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/scan/SpringComponentScanTest.java Wed Apr  7 06:31:41 2010
@@ -32,8 +32,15 @@ public class SpringComponentScanTest ext
         ApplicationContext c = new ClassPathXmlApplicationContext("org/apache/camel/spring/config/scan/componentScan.xml");
         context = (CamelContext)c.getBean("camelContext");
         template = context.createProducerTemplate();
+        template.start();
     }
-    
+
+    @Override
+    protected void tearDown() throws Exception {
+        template.stop();
+        super.tearDown();
+    }
+
     public void testExcludedRoute() throws InterruptedException {
         assertEquals(1, context.getRoutes().size());
         MockEndpoint mock = getMockEndpoint("mock:definitelyShouldNeverReceiveExchange");

Modified: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/scan/SpringComponentScanWithDeprecatedPackagesTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/scan/SpringComponentScanWithDeprecatedPackagesTest.java?rev=931444&r1=931443&r2=931444&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/scan/SpringComponentScanWithDeprecatedPackagesTest.java (original)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/scan/SpringComponentScanWithDeprecatedPackagesTest.java Wed Apr  7 06:31:41 2010
@@ -31,7 +31,13 @@ public class SpringComponentScanWithDepr
         ApplicationContext c = new ClassPathXmlApplicationContext("org/apache/camel/spring/config/scan/componentScanWithPackages.xml");
         context = (CamelContext)c.getBean("camelContext");
         template = context.createProducerTemplate();
+        template.start();
+    }
 
+    @Override
+    protected void tearDown() throws Exception {
+        template.stop();
+        super.tearDown();
     }
 
     public void testSpringComponentScanFeature() throws InterruptedException {

Modified: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/example/PojoDualCamelContextConsumerTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/example/PojoDualCamelContextConsumerTest.java?rev=931444&r1=931443&r2=931444&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/example/PojoDualCamelContextConsumerTest.java (original)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/example/PojoDualCamelContextConsumerTest.java Wed Apr  7 06:31:41 2010
@@ -17,6 +17,7 @@
 package org.apache.camel.spring.example;
 
 import org.apache.camel.CamelContext;
+import org.apache.camel.ProducerTemplate;
 import org.apache.camel.TestSupport;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.springframework.context.ApplicationContext;
@@ -36,7 +37,10 @@ public class PojoDualCamelContextConsume
         MockEndpoint result = camel1.getEndpoint("mock:result", MockEndpoint.class);
         result.expectedBodiesReceived(body);
 
-        camel1.createProducerTemplate().sendBody("direct:start", body);
+        ProducerTemplate template = camel1.createProducerTemplate();
+        template.start();
+        template.sendBody("direct:start", body);
+        template.stop();
 
         result.assertIsSatisfied();
     }
@@ -47,7 +51,10 @@ public class PojoDualCamelContextConsume
         MockEndpoint result = camel2.getEndpoint("mock:result", MockEndpoint.class);
         result.expectedBodiesReceived(body);
 
-        camel2.createProducerTemplate().sendBody("direct:start", body);
+        ProducerTemplate template = camel2.createProducerTemplate();
+        template.start();
+        template.sendBody("direct:start", body);
+        template.stop();
 
         result.assertIsSatisfied();
     }
@@ -59,7 +66,10 @@ public class PojoDualCamelContextConsume
         MockEndpoint result = camel1.getEndpoint("mock:result", MockEndpoint.class);
         result.expectedMessageCount(0);
 
-        camel1.createProducerTemplate().sendBody("direct:foo", body);
+        ProducerTemplate template = camel1.createProducerTemplate();
+        template.start();
+        template.sendBody("direct:foo", body);
+        template.stop();
 
         Thread.sleep(200);
         
@@ -75,7 +85,10 @@ public class PojoDualCamelContextConsume
         MockEndpoint foo = camel2.getEndpoint("mock:foo", MockEndpoint.class);
         foo.expectedBodiesReceived(body);
 
-        camel2.createProducerTemplate().sendBody("direct:foo", body);
+        ProducerTemplate template = camel2.createProducerTemplate();
+        template.start();
+        template.sendBody("direct:foo", body);
+        template.stop();
 
         result.assertIsSatisfied();
         foo.assertIsSatisfied();

Modified: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/ContainerWideInterceptorTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/ContainerWideInterceptorTest.java?rev=931444&r1=931443&r2=931444&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/ContainerWideInterceptorTest.java (original)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/ContainerWideInterceptorTest.java Wed Apr  7 06:31:41 2010
@@ -56,7 +56,9 @@ public class ContainerWideInterceptorTes
         result.expectedBodiesReceived("Hello World");
 
         ProducerTemplate template = camel1.createProducerTemplate();
+        template.start();
         template.sendBody("direct:one", "Hello World");
+        template.stop();
 
         result.assertIsSatisfied();
 
@@ -72,7 +74,9 @@ public class ContainerWideInterceptorTes
         result.expectedBodiesReceived("Bye World");
 
         ProducerTemplate template = camel2.createProducerTemplate();
+        template.start();
         template.sendBody("direct:two", "Bye World");
+        template.stop();
 
         result.assertIsSatisfied();
 

Added: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/ConsumerTemplateMaximumCacheSizeTest-context.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/ConsumerTemplateMaximumCacheSizeTest-context.xml?rev=931444&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/ConsumerTemplateMaximumCacheSizeTest-context.xml (added)
+++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/ConsumerTemplateMaximumCacheSizeTest-context.xml Wed Apr  7 06:31:41 2010
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="
+       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
+    ">
+
+    <camelContext xmlns="http://camel.apache.org/schema/spring">
+        <consumerTemplate id="template" maximumCacheSize="50"/>
+    </camelContext>
+
+</beans>

Propchange: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/ConsumerTemplateMaximumCacheSizeTest-context.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/ConsumerTemplateMaximumCacheSizeTest-context.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/ConsumerTemplateMaximumCacheSizeTest-context.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Copied: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/ProducerTemplateMaximumCacheSizeTest-context.xml (from r931425, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/ProducerTemplateAutoRegisterTest-context.xml)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/ProducerTemplateMaximumCacheSizeTest-context.xml?p2=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/ProducerTemplateMaximumCacheSizeTest-context.xml&p1=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/ProducerTemplateAutoRegisterTest-context.xml&r1=931425&r2=931444&rev=931444&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/ProducerTemplateAutoRegisterTest-context.xml (original)
+++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/ProducerTemplateMaximumCacheSizeTest-context.xml Wed Apr  7 06:31:41 2010
@@ -23,6 +23,7 @@
     ">
 
     <camelContext xmlns="http://camel.apache.org/schema/spring">
+        <template id="template" maximumCacheSize="50" defaultEndpoint="mock:cool"/>
     </camelContext>
 
 </beans>

Modified: camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityDynamicTemplateTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityDynamicTemplateTest.java?rev=931444&r1=931443&r2=931444&view=diff
==============================================================================
--- camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityDynamicTemplateTest.java (original)
+++ camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityDynamicTemplateTest.java Wed Apr  7 06:31:41 2010
@@ -69,7 +69,7 @@ public class VelocityDynamicTemplateTest
         ProducerTemplate template;
         boolean useLetter2;
         
-        public void sendToNewTemplate(Exchange exchange) {
+        public void sendToNewTemplate(Exchange exchange) throws Exception {
             if (template == null) {
                 template = exchange.getContext().createProducerTemplate();
             }

Modified: camel/trunk/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppRouteTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppRouteTest.java?rev=931444&r1=931443&r2=931444&view=diff
==============================================================================
--- camel/trunk/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppRouteTest.java (original)
+++ camel/trunk/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppRouteTest.java Wed Apr  7 06:31:41 2010
@@ -30,7 +30,6 @@ import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.converter.ObjectConverter;
 import org.apache.camel.impl.DefaultCamelContext;
-import org.apache.camel.impl.DefaultProducerServicePool;
 import org.apache.camel.impl.ProducerCache;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -52,7 +51,7 @@ public class XmppRouteTest extends TestC
     protected CamelContext container = new DefaultCamelContext();
     protected CountDownLatch latch = new CountDownLatch(1);
     protected Endpoint endpoint;
-    protected ProducerCache client = new ProducerCache(container, new DefaultProducerServicePool(10));
+    protected ProducerCache client;
 
     public static void main(String[] args) {
         enabled = true;
@@ -111,6 +110,8 @@ public class XmppRouteTest extends TestC
 
     @Override
     protected void setUp() throws Exception {
+        client = new ProducerCache(container, 10);
+
         if (isXmppServerPresent()) {
             String uriPrefix = getUriPrefix();
             final String uri1 = uriPrefix + "&resource=camel-test-from&nickname=came-test-from";



Mime
View raw message