camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
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 GMT
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<Endpoint> existingEndpoints = new ArrayList<Endpoint>();
+                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);



Mime
View raw message