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 294E29E37 for ; Mon, 5 Mar 2012 09:23:38 +0000 (UTC) Received: (qmail 72354 invoked by uid 500); 5 Mar 2012 09:23:38 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 72285 invoked by uid 500); 5 Mar 2012 09:23: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 72268 invoked by uid 99); 5 Mar 2012 09:23:37 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 05 Mar 2012 09:23:37 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 05 Mar 2012 09:23:33 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 6910623888E7; Mon, 5 Mar 2012 09:23:12 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1296974 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/impl/ test/java/org/apache/camel/component/direct/ test/java/org/apache/camel/component/seda/ test/java/org/apache/camel/view/ Date: Mon, 05 Mar 2012 09:23:12 -0000 To: commits@camel.apache.org From: davsclaus@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120305092312.6910623888E7@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: davsclaus Date: Mon Mar 5 09:23:11 2012 New Revision: 1296974 URL: http://svn.apache.org/viewvc?rev=1296974&view=rev Log: CAMEL-4680: Check for clash with multiple consumers when starting a new route manually using startRoute Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java camel/trunk/camel-core/src/test/java/org/apache/camel/component/direct/DirectEndpointRouteInlinedTest.java camel/trunk/camel-core/src/test/java/org/apache/camel/component/seda/SedaConcurrentConsumersNPEIssueTest.java camel/trunk/camel-core/src/test/java/org/apache/camel/view/DotViewTest.java camel/trunk/camel-core/src/test/java/org/apache/camel/view/XmlGraphTest.java Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java?rev=1296974&r1=1296973&r2=1296974&view=diff ============================================================================== --- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java (original) +++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java Mon Mar 5 09:23:11 2012 @@ -1963,11 +1963,30 @@ public class DefaultCamelContext extends for (Consumer consumer : routeService.getInputs().values()) { Endpoint endpoint = consumer.getEndpoint(); - // check multiple consumer violation + // check multiple consumer violation, with the other routes to be started if (!doCheckMultipleConsumerSupportClash(endpoint, routeInputs)) { throw new FailedToStartRouteException(routeService.getId(), "Multiple consumers for the same endpoint is not allowed: " + endpoint); } + + // check for multiple consumer violations with existing routes which + // have already been started, or is currently starting + List existingEndpoints = new ArrayList(); + for (Route existingRoute : getRoutes()) { + if (route.getId().equals(existingRoute.getId())) { + // skip ourselves + continue; + } + Endpoint existing = existingRoute.getEndpoint(); + ServiceStatus status = getRouteStatus(existingRoute.getId()); + if (status != null && status.isStarted() || status.isStarting()) { + existingEndpoints.add(existing); + } + } + if (!doCheckMultipleConsumerSupportClash(endpoint, existingEndpoints)) { + throw new FailedToStartRouteException(routeService.getId(), + "Multiple consumers for the same endpoint is not allowed: " + endpoint); + } // start the consumer on the route log.debug("Route: {} >>> {}", route.getId(), route); Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/direct/DirectEndpointRouteInlinedTest.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/direct/DirectEndpointRouteInlinedTest.java?rev=1296974&r1=1296973&r2=1296974&view=diff ============================================================================== --- camel/trunk/camel-core/src/test/java/org/apache/camel/component/direct/DirectEndpointRouteInlinedTest.java (original) +++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/direct/DirectEndpointRouteInlinedTest.java Mon Mar 5 09:23:11 2012 @@ -17,6 +17,7 @@ package org.apache.camel.component.direct; import org.apache.camel.ContextTestSupport; +import org.apache.camel.FailedToStartRouteException; import org.apache.camel.builder.RouteBuilder; /** @@ -54,8 +55,8 @@ public class DirectEndpointRouteInlinedT } }); fail("Should have thrown exception"); - } catch (IllegalArgumentException e) { - assertEquals("Cannot add a 2nd consumer to the same endpoint. Endpoint Endpoint[direct://start] only allows one consumer.", e.getMessage()); + } catch (FailedToStartRouteException e) { + assertEquals("Failed to start route route2 because of Multiple consumers for the same endpoint is not allowed: Endpoint[direct://start]", e.getMessage()); } } Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/seda/SedaConcurrentConsumersNPEIssueTest.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/seda/SedaConcurrentConsumersNPEIssueTest.java?rev=1296974&r1=1296973&r2=1296974&view=diff ============================================================================== --- camel/trunk/camel-core/src/test/java/org/apache/camel/component/seda/SedaConcurrentConsumersNPEIssueTest.java (original) +++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/seda/SedaConcurrentConsumersNPEIssueTest.java Mon Mar 5 09:23:11 2012 @@ -17,6 +17,7 @@ package org.apache.camel.component.seda; import org.apache.camel.ContextTestSupport; +import org.apache.camel.FailedToStartRouteException; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.mock.MockEndpoint; @@ -33,14 +34,33 @@ public class SedaConcurrentConsumersNPEI assertMockEndpointsSatisfied(); - // now start the first route, which should cause a failure due multiple consumers is not allowed - mock.reset(); - mock.expectedMessageCount(0); + try { + context.startRoute("first"); + fail("Should have thrown exception"); + } catch (FailedToStartRouteException e) { + assertEquals("Failed to start route first because of Multiple consumers for the same endpoint is not allowed:" + + " Endpoint[seda://foo?concurrentConsumers=5]", e.getMessage()); + } + } - context.startRoute("first"); - template.sendBody("seda:foo", "Bye World"); + public void testStartThird() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:result"); + mock.expectedBodiesReceived("Hello World"); + + template.sendBody("seda:foo", "Hello World"); assertMockEndpointsSatisfied(); + + // this should be okay + context.startRoute("third"); + + try { + context.startRoute("first"); + fail("Should have thrown exception"); + } catch (FailedToStartRouteException e) { + assertEquals("Failed to start route first because of Multiple consumers for the same endpoint is not allowed:" + + " Endpoint[seda://foo?concurrentConsumers=5]", e.getMessage()); + } } @Override @@ -51,6 +71,8 @@ public class SedaConcurrentConsumersNPEI from("seda:foo?concurrentConsumers=5").routeId("first").noAutoStartup().to("mock:result"); from("seda:foo?concurrentConsumers=5").routeId("second").to("mock:result"); + + from("direct:foo").routeId("third").noAutoStartup().to("mock:result"); } }; } Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/view/DotViewTest.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/view/DotViewTest.java?rev=1296974&r1=1296973&r2=1296974&view=diff ============================================================================== --- camel/trunk/camel-core/src/test/java/org/apache/camel/view/DotViewTest.java (original) +++ camel/trunk/camel-core/src/test/java/org/apache/camel/view/DotViewTest.java Mon Mar 5 09:23:11 2012 @@ -23,7 +23,6 @@ import org.apache.camel.component.bean.M import org.apache.camel.impl.JndiRegistry; import org.apache.camel.processor.aggregate.UseLatestAggregationStrategy; - /** * @version */ @@ -74,7 +73,7 @@ public class DotViewTest extends Context static class AnotherPipelineRoute extends RouteBuilder { public void configure() throws Exception { - from("seda:pipeline.in").pipeline("seda:pipeline.out1", "seda:pipeline.out2", "seda:pipeline.out3"); + from("seda:pipeline.in2").pipeline("seda:pipeline.out1", "seda:pipeline.out2", "seda:pipeline.out3"); } } @@ -86,19 +85,19 @@ public class DotViewTest extends Context static class FromToBeanRoute extends RouteBuilder { public void configure() throws Exception { - from("seda:foo").beanRef("myBean", "hello"); + from("seda:foo2").beanRef("myBean", "hello"); } } static class RoutingSlipRoute extends RouteBuilder { public void configure() throws Exception { - from("seda:foo").routingSlip(header("splipHeader")); + from("seda:foo3").routingSlip(header("splipHeader")); } } static class AggreagateRoute extends RouteBuilder { public void configure() throws Exception { - from("seda:foo") + from("seda:foo4") .aggregate(constant("messageId"), new UseLatestAggregationStrategy()).completionTimeout(1000L). to("seda:aggregated"); } @@ -106,7 +105,7 @@ public class DotViewTest extends Context static class ResequenceRoute extends RouteBuilder { public void configure() throws Exception { - from("seda:foo").resequence(constant("seqNum")).to("seda:bar"); + from("seda:foo5").resequence(constant("seqNum")).to("seda:bar"); } } Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/view/XmlGraphTest.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/view/XmlGraphTest.java?rev=1296974&r1=1296973&r2=1296974&view=diff ============================================================================== --- camel/trunk/camel-core/src/test/java/org/apache/camel/view/XmlGraphTest.java (original) +++ camel/trunk/camel-core/src/test/java/org/apache/camel/view/XmlGraphTest.java Mon Mar 5 09:23:11 2012 @@ -20,6 +20,7 @@ package org.apache.camel.view; * @version */ public class XmlGraphTest extends DotViewTest { + @Override public void testGenerateFiles() throws Exception { XmlGraphGenerator generator = new XmlGraphGenerator(outputDirectory);