Return-Path: X-Original-To: apmail-camel-commits-archive@www.apache.org Delivered-To: apmail-camel-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 4B2AA1022D for ; Thu, 27 Feb 2014 14:22:02 +0000 (UTC) Received: (qmail 78011 invoked by uid 500); 27 Feb 2014 14:21:57 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 77944 invoked by uid 500); 27 Feb 2014 14:21:54 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 77875 invoked by uid 99); 27 Feb 2014 14:21:52 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 27 Feb 2014 14:21:52 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id DB17592EAF8; Thu, 27 Feb 2014 14:21:51 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: hekonsek@apache.org To: commits@camel.apache.org Message-Id: <8daca87bd6ad44779af30782eec57c8a@git.apache.org> X-Mailer: ASF-Git Admin Mailer 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 +0000 (UTC) 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 Authored: Thu Feb 27 15:20:37 2014 +0100 Committer: Henryk Konsek 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 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