Author: ningjiang
Date: Wed Oct 13 12:55:02 2010
New Revision: 1022085

URL: http://svn.apache.org/viewvc?rev=1022085&view=rev
Log:
CAMEL-3220 try to fix the test hang of ThreadsZeroInCoreAndMaxPoolTest

Modified:
    
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExecutorServiceStrategy.java
    
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ThreadsZeroInCoreAndMaxPoolTest.java

Modified: 
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExecutorServiceStrategy.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExecutorServiceStrategy.java?rev=1022085&r1=1022084&r2=1022085&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExecutorServiceStrategy.java
 (original)
+++ 
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExecutorServiceStrategy.java
 Wed Oct 13 12:55:02 2010
@@ -271,9 +271,9 @@ public class DefaultExecutorServiceStrat
         ObjectHelper.notNull(name, "ThreadName");
         
         // If we set the corePoolSize to be 0, the whole camel application 
will hang in JDK5
-        // just add a check here to set the corePoolSize to be 1 
-        if (corePoolSize == 0) {
-            corePoolSize = 1;
+        // just add a check here to throw the IllegalArgumentException 
+        if (corePoolSize < 1) {
+            throw new IllegalArgumentException("The corePoolSize can't be 
lower than 1");
         }
         
         ExecutorService answer = 
ExecutorServiceHelper.newThreadPool(threadNamePattern, name, corePoolSize, 
maxPoolSize, keepAliveTime,

Modified: 
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ThreadsZeroInCoreAndMaxPoolTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ThreadsZeroInCoreAndMaxPoolTest.java?rev=1022085&r1=1022084&r2=1022085&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ThreadsZeroInCoreAndMaxPoolTest.java
 (original)
+++ 
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ThreadsZeroInCoreAndMaxPoolTest.java
 Wed Oct 13 12:55:02 2010
@@ -17,6 +17,7 @@
 package org.apache.camel.processor;
 
 import org.apache.camel.ContextTestSupport;
+import org.apache.camel.FailedToCreateRouteException;
 import org.apache.camel.builder.RouteBuilder;
 
 /**
@@ -24,14 +25,34 @@ import org.apache.camel.builder.RouteBui
  */
 public class ThreadsZeroInCoreAndMaxPoolTest extends ContextTestSupport {
 
-    public void testThreadsCoreAndMaxPool() throws Exception {
+    // ignore the test
+    public void xtestThreadsCoreAndMaxPool() throws Exception {
         getMockEndpoint("mock:result").expectedMessageCount(1);
 
         template.sendBody("direct:start", "Hello World");
 
         assertMockEndpointsSatisfied();
     }
+    
+    public void testThreadsCoreBeZero() throws Exception {
+        try {
+            context.addRoutes(new RouteBuilder() {
+                @Override
+                public void configure() throws Exception {
+                    from("direct:start")
+                    // will use a a custom thread pool with 0 in core and 2 max
+                        .threads(0, 2).to("mock:result");
+                }
+            });
+            // expect to get the IllegalArgumentException
+            fail("Except the exception here");
+        } catch (FailedToCreateRouteException ex) {
+            assertTrue(ex.getCause() instanceof IllegalArgumentException);
+
+        }
+    }
 
+     
     public void testThreadsCoreAndMaxPoolBuilder() throws Exception {
         getMockEndpoint("mock:result").expectedMessageCount(1);
 
@@ -45,11 +66,7 @@ public class ThreadsZeroInCoreAndMaxPool
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                from("direct:start")
-                    // will use a a custom thread pool with 0 in core and 2 max
-                    .threads(0, 2)
-                    .to("mock:result");
-
+                
                 from("direct:foo")
                     // only change thread name and max, but rely on default 
settings
                     .threads().maxPoolSize(20).threadName("myPool")


Reply via email to