camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hekon...@apache.org
Subject git commit: [CAMEL-7250] In Threads DSL thread pool options and executorServiceRef should be mutually exclusive
Date Thu, 27 Feb 2014 14:21:51 GMT
Repository: camel
Updated Branches:
  refs/heads/master 50bb54048 -> 87105eee5


[CAMEL-7250] In Threads DSL thread pool options and executorServiceRef should be mutually
exclusive


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/87105eee
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/87105eee
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/87105eee

Branch: refs/heads/master
Commit: 87105eee5c303af4751661af9480d4a76223b01b
Parents: 50bb540
Author: Henryk Konsek <hekonsek@gmail.com>
Authored: Thu Feb 27 15:20:37 2014 +0100
Committer: Henryk Konsek <hekonsek@gmail.com>
Committed: Thu Feb 27 15:21:35 2014 +0100

----------------------------------------------------------------------
 .../apache/camel/model/ThreadsDefinition.java   |  19 +++
 .../processor/ThreadsInvalidConfigTest.java     | 168 +++++++++++++++++++
 2 files changed, 187 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/87105eee/camel-core/src/main/java/org/apache/camel/model/ThreadsDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/ThreadsDefinition.java b/camel-core/src/main/java/org/apache/camel/model/ThreadsDefinition.java
index 6de5417..1404f22 100644
--- a/camel-core/src/main/java/org/apache/camel/model/ThreadsDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/ThreadsDefinition.java
@@ -95,6 +95,25 @@ public class ThreadsDefinition extends OutputDefinition<ThreadsDefinition>
imple
                     .build();
             threadPool = manager.newThreadPool(this, name, profile);
             shutdownThreadPool = true;
+        } else {
+            if (getThreadName() != null && !getThreadName().equals("Threads")) {
+                throw new IllegalArgumentException("ThreadName and executorServiceRef options
cannot be used together.");
+            }
+            if (getPoolSize() != null) {
+                throw new IllegalArgumentException("PoolSize and executorServiceRef options
cannot be used together.");
+            }
+            if (getMaxPoolSize() != null) {
+                throw new IllegalArgumentException("MaxPoolSize and executorServiceRef options
cannot be used together.");
+            }
+            if (getKeepAliveTime() != null) {
+                throw new IllegalArgumentException("KeepAliveTime and executorServiceRef
options cannot be used together.");
+            }
+            if (getMaxQueueSize() != null) {
+                throw new IllegalArgumentException("MaxQueueSize and executorServiceRef options
cannot be used together.");
+            }
+            if (getRejectedPolicy() != null) {
+                throw new IllegalArgumentException("RejectedPolicy and executorServiceRef
options cannot be used together.");
+            }
         }
 
         ThreadsProcessor thread = new ThreadsProcessor(routeContext.getCamelContext(), threadPool,
shutdownThreadPool);

http://git-wip-us.apache.org/repos/asf/camel/blob/87105eee/camel-core/src/test/java/org/apache/camel/processor/ThreadsInvalidConfigTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/processor/ThreadsInvalidConfigTest.java
b/camel-core/src/test/java/org/apache/camel/processor/ThreadsInvalidConfigTest.java
new file mode 100644
index 0000000..cd7ec45
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/processor/ThreadsInvalidConfigTest.java
@@ -0,0 +1,168 @@
+/**
+ * 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.processor;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.FailedToCreateRouteException;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.spi.ThreadPoolProfile;
+
+import static org.apache.camel.ThreadPoolRejectedPolicy.Abort;
+
+public class ThreadsInvalidConfigTest extends ContextTestSupport {
+
+    ThreadPoolProfile threadPoolProfile = new ThreadPoolProfile("poll");
+
+    public void testCreateRouteIfNoInvalidOptions() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                context.getExecutorServiceManager().registerThreadPoolProfile(threadPoolProfile);
+                from("direct:start")
+                        .threads().executorServiceRef(threadPoolProfile.getId())
+                        .to("mock:test");
+            }
+        });
+    }
+
+    public void testFailIfThreadNameAndExecutorServiceRef() throws Exception {
+        try {
+            context.addRoutes(new RouteBuilder() {
+                @Override
+                public void configure() throws Exception {
+                    context.getExecutorServiceManager().registerThreadPoolProfile(threadPoolProfile);
+                    from("direct:start")
+                            .threads().executorServiceRef(threadPoolProfile.getId()).threadName("foo")
+                            .to("mock:test");
+                }
+            });
+        } catch (FailedToCreateRouteException e) {
+            assertTrue(e.getCause() instanceof IllegalArgumentException);
+            assertTrue(e.getCause().getMessage().startsWith("ThreadName"));
+            return;
+        }
+        fail();
+    }
+
+    public void testPassIfThreadNameWithoutExecutorServiceRef() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                context.getExecutorServiceManager().registerThreadPoolProfile(threadPoolProfile);
+                from("direct:start")
+                        .threads().threadName("foo")
+                        .to("mock:test");
+            }
+        });
+    }
+
+    public void testFailIfPoolSizeAndExecutorServiceRef() throws Exception {
+        try {
+            context.addRoutes(new RouteBuilder() {
+                @Override
+                public void configure() throws Exception {
+                    context.getExecutorServiceManager().registerThreadPoolProfile(threadPoolProfile);
+                    from("direct:start")
+                            .threads().executorServiceRef(threadPoolProfile.getId()).poolSize(1)
+                            .to("mock:test");
+                }
+            });
+        } catch (FailedToCreateRouteException e) {
+            assertTrue(e.getCause() instanceof IllegalArgumentException);
+            assertTrue(e.getCause().getMessage().startsWith("PoolSize"));
+            return;
+        }
+        fail();
+    }
+
+    public void testFailIfMaxPoolSizeAndExecutorServiceRef() throws Exception {
+        try {
+            context.addRoutes(new RouteBuilder() {
+                @Override
+                public void configure() throws Exception {
+                    context.getExecutorServiceManager().registerThreadPoolProfile(threadPoolProfile);
+                    from("direct:start")
+                            .threads().executorServiceRef(threadPoolProfile.getId()).maxPoolSize(1)
+                            .to("mock:test");
+                }
+            });
+        } catch (FailedToCreateRouteException e) {
+            assertTrue(e.getCause() instanceof IllegalArgumentException);
+            assertTrue(e.getCause().getMessage().startsWith("MaxPoolSize"));
+            return;
+        }
+        fail();
+    }
+
+    public void testFailIfKeepAliveTimeAndExecutorServiceRef() throws Exception {
+        try {
+            context.addRoutes(new RouteBuilder() {
+                @Override
+                public void configure() throws Exception {
+                    context.getExecutorServiceManager().registerThreadPoolProfile(threadPoolProfile);
+                    from("direct:start")
+                            .threads().executorServiceRef(threadPoolProfile.getId()).keepAliveTime(1)
+                            .to("mock:test");
+                }
+            });
+        } catch (FailedToCreateRouteException e) {
+            assertTrue(e.getCause() instanceof IllegalArgumentException);
+            assertTrue(e.getCause().getMessage().startsWith("KeepAliveTime"));
+            return;
+        }
+        fail();
+    }
+
+    public void testFailIfMaxQueueSizeAndExecutorServiceRef() throws Exception {
+        try {
+            context.addRoutes(new RouteBuilder() {
+                @Override
+                public void configure() throws Exception {
+                    context.getExecutorServiceManager().registerThreadPoolProfile(threadPoolProfile);
+                    from("direct:start")
+                            .threads().executorServiceRef(threadPoolProfile.getId()).maxQueueSize(1)
+                            .to("mock:test");
+                }
+            });
+        } catch (FailedToCreateRouteException e) {
+            assertTrue(e.getCause() instanceof IllegalArgumentException);
+            assertTrue(e.getCause().getMessage().startsWith("MaxQueueSize"));
+            return;
+        }
+        fail();
+    }
+
+    public void testFailIfRejectedPolicyAndExecutorServiceRef() throws Exception {
+        try {
+            context.addRoutes(new RouteBuilder() {
+                @Override
+                public void configure() throws Exception {
+                    context.getExecutorServiceManager().registerThreadPoolProfile(threadPoolProfile);
+                    from("direct:start")
+                            .threads().executorServiceRef(threadPoolProfile.getId()).rejectedPolicy(Abort)
+                            .to("mock:test");
+                }
+            });
+        } catch (FailedToCreateRouteException e) {
+            assertTrue(e.getCause() instanceof IllegalArgumentException);
+            assertTrue(e.getCause().getMessage().startsWith("RejectedPolicy"));
+            return;
+        }
+        fail();
+    }
+
+}
\ No newline at end of file


Mime
View raw message