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 38935179F8 for ; Wed, 22 Apr 2015 09:53:38 +0000 (UTC) Received: (qmail 7985 invoked by uid 500); 22 Apr 2015 09:53:38 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 7853 invoked by uid 500); 22 Apr 2015 09:53:38 -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 7835 invoked by uid 99); 22 Apr 2015 09:53:38 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 22 Apr 2015 09:53:38 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id EE949E01FB; Wed, 22 Apr 2015 09:53:37 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: davsclaus@apache.org To: commits@camel.apache.org Date: Wed, 22 Apr 2015 09:53:38 -0000 Message-Id: In-Reply-To: <8e3735970b624f37a6c81d46a9daaf58@git.apache.org> References: <8e3735970b624f37a6c81d46a9daaf58@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [2/3] camel git commit: CAMEL-8682: Context scoped OnException should not be stopped if a route is stopped CAMEL-8682: Context scoped OnException should not be stopped if a route is stopped Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/0403f066 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/0403f066 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/0403f066 Branch: refs/heads/camel-2.15.x Commit: 0403f06668de5af9f375df35d3a6e22d503d83e9 Parents: f8d759b Author: Claus Ibsen Authored: Wed Apr 22 10:50:16 2015 +0200 Committer: Claus Ibsen Committed: Wed Apr 22 11:56:33 2015 +0200 ---------------------------------------------------------------------- .../processor/interceptor/DefaultChannel.java | 22 +++- ...pedOnExceptionLoadBalancerStopRouteTest.java | 110 +++++++++++++++++++ ...pedOnExceptionLoadBalancerStopRouteTest.java | 49 +++++++++ 3 files changed, 180 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/0403f066/camel-core/src/main/java/org/apache/camel/processor/interceptor/DefaultChannel.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/processor/interceptor/DefaultChannel.java b/camel-core/src/main/java/org/apache/camel/processor/interceptor/DefaultChannel.java index 9338271..c9ae2f3 100644 --- a/camel-core/src/main/java/org/apache/camel/processor/interceptor/DefaultChannel.java +++ b/camel-core/src/main/java/org/apache/camel/processor/interceptor/DefaultChannel.java @@ -28,6 +28,8 @@ import org.apache.camel.Channel; import org.apache.camel.Exchange; import org.apache.camel.Processor; import org.apache.camel.model.ModelChannel; +import org.apache.camel.model.OnCompletionDefinition; +import org.apache.camel.model.OnExceptionDefinition; import org.apache.camel.model.ProcessorDefinition; import org.apache.camel.model.ProcessorDefinitionHelper; import org.apache.camel.model.RouteDefinition; @@ -155,7 +157,25 @@ public class DefaultChannel extends CamelInternalProcessor implements ModelChann @Override protected void doStop() throws Exception { - ServiceHelper.stopServices(output, errorHandler); + if (!isContextScoped()) { + // only stop services if not context scoped (as context scoped is reused by others) + ServiceHelper.stopServices(output, errorHandler); + } + } + + @Override + protected void doShutdown() throws Exception { + ServiceHelper.stopAndShutdownServices(output, errorHandler); + } + + private boolean isContextScoped() { + if (definition instanceof OnExceptionDefinition) { + return !((OnExceptionDefinition) definition).isRouteScoped(); + } else if (definition instanceof OnCompletionDefinition) { + return !((OnCompletionDefinition) definition).isRouteScoped(); + } + + return false; } @SuppressWarnings("deprecation") http://git-wip-us.apache.org/repos/asf/camel/blob/0403f066/camel-core/src/test/java/org/apache/camel/processor/onexception/ContextScopedOnExceptionLoadBalancerStopRouteTest.java ---------------------------------------------------------------------- diff --git a/camel-core/src/test/java/org/apache/camel/processor/onexception/ContextScopedOnExceptionLoadBalancerStopRouteTest.java b/camel-core/src/test/java/org/apache/camel/processor/onexception/ContextScopedOnExceptionLoadBalancerStopRouteTest.java new file mode 100644 index 0000000..6750231 --- /dev/null +++ b/camel-core/src/test/java/org/apache/camel/processor/onexception/ContextScopedOnExceptionLoadBalancerStopRouteTest.java @@ -0,0 +1,110 @@ +/** + * 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.onexception; + +import org.apache.camel.ContextTestSupport; +import org.apache.camel.ServiceStatus; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.seda.SedaEndpoint; + +public class ContextScopedOnExceptionLoadBalancerStopRouteTest extends ContextTestSupport { + + public void testOk() throws Exception { + getMockEndpoint("mock:error").expectedMessageCount(0); + getMockEndpoint("mock:start").expectedBodiesReceived("World"); + getMockEndpoint("mock:result").expectedBodiesReceived("Bye World"); + getMockEndpoint("mock:exception").expectedMessageCount(0); + + template.sendBody("direct:start", "World"); + + assertMockEndpointsSatisfied(); + } + + public void testError() throws Exception { + getMockEndpoint("mock:error").expectedBodiesReceived("Kaboom"); + getMockEndpoint("mock:start").expectedBodiesReceived("Kaboom"); + getMockEndpoint("mock:result").expectedMessageCount(0); + getMockEndpoint("mock:exception").expectedBodiesReceived("Kaboom"); + + template.sendBody("direct:start", "Kaboom"); + + assertMockEndpointsSatisfied(); + } + + public void testErrorOk() throws Exception { + getMockEndpoint("mock:error").expectedBodiesReceived("Kaboom"); + getMockEndpoint("mock:start").expectedBodiesReceived("Kaboom", "World"); + getMockEndpoint("mock:result").expectedBodiesReceived("Bye World"); + getMockEndpoint("mock:exception").expectedBodiesReceived("Kaboom"); + + template.sendBody("direct:start", "Kaboom"); + template.sendBody("direct:start", "World"); + + assertMockEndpointsSatisfied(); + } + + public void testErrorOkError() throws Exception { + getMockEndpoint("mock:error").expectedBodiesReceived("Kaboom"); + getMockEndpoint("mock:start").expectedBodiesReceived("Kaboom", "World", "Kaboom"); + getMockEndpoint("mock:result").expectedBodiesReceived("Bye World"); + getMockEndpoint("mock:exception").expectedBodiesReceived("Kaboom", "Kaboom"); + + template.sendBody("direct:start", "Kaboom"); + template.sendBody("direct:start", "World"); + + // give time for route to stop + Thread.sleep(1000); + assertEquals(ServiceStatus.Stopped, context.getRouteStatus("errorRoute")); + + template.sendBody("direct:start", "Kaboom"); + + assertMockEndpointsSatisfied(); + + // should be 1 on the seda queue + SedaEndpoint seda = getMandatoryEndpoint("seda:error", SedaEndpoint.class); + SedaEndpoint seda2 = getMandatoryEndpoint("seda:error2", SedaEndpoint.class); + int size = seda.getQueue().size(); + int size2 = seda2.getQueue().size(); + assertTrue("There should be 1 exchange on the seda or seda2 queue", size == 1 || size2 == 1); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + onException(Exception.class) + .handled(true) + .loadBalance().roundRobin().to("seda:error", "seda:error2").end() + .to("mock:exception"); + + from("direct:start") + .to("mock:start") + .choice() + .when(body().contains("Kaboom")) + .throwException(new IllegalArgumentException("Forced")) + .otherwise() + .transform(body().prepend("Bye ")) + .to("mock:result"); + + from("seda:error").routeId("errorRoute") + .to("controlbus:route?action=stop&routeId=errorRoute&async=true") + .to("mock:error"); + } + }; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/0403f066/camel-core/src/test/java/org/apache/camel/processor/onexception/RouteScopedOnExceptionLoadBalancerStopRouteTest.java ---------------------------------------------------------------------- diff --git a/camel-core/src/test/java/org/apache/camel/processor/onexception/RouteScopedOnExceptionLoadBalancerStopRouteTest.java b/camel-core/src/test/java/org/apache/camel/processor/onexception/RouteScopedOnExceptionLoadBalancerStopRouteTest.java new file mode 100644 index 0000000..3aa06c3 --- /dev/null +++ b/camel-core/src/test/java/org/apache/camel/processor/onexception/RouteScopedOnExceptionLoadBalancerStopRouteTest.java @@ -0,0 +1,49 @@ +/** + * 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.onexception; + +import org.apache.camel.builder.RouteBuilder; + +public class RouteScopedOnExceptionLoadBalancerStopRouteTest extends ContextScopedOnExceptionLoadBalancerStopRouteTest { + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("direct:start") + .onException(Exception.class) + .handled(true) + .loadBalance().roundRobin().to("seda:error", "seda:error2").end() + .to("mock:exception") + .end() + // route starts here + .to("mock:start") + .choice() + .when(body().contains("Kaboom")) + .throwException(new IllegalArgumentException("Forced")) + .otherwise() + .transform(body().prepend("Bye ")) + .to("mock:result"); + + from("seda:error").routeId("errorRoute") + .to("controlbus:route?action=stop&routeId=errorRoute&async=true") + .to("mock:error"); + } + }; + } +}