You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2014/08/18 09:50:51 UTC

[6/6] git commit: CAMEL-7714: AdviceWith - Does not honor autoStartup option

CAMEL-7714: AdviceWith - Does not honor autoStartup option


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

Branch: refs/heads/camel-2.12.x
Commit: ff702629f16f18b0cacff85c02a09e1f2bd49428
Parents: d84408e
Author: Claus Ibsen <da...@apache.org>
Authored: Mon Aug 18 09:20:28 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Mon Aug 18 09:50:31 2014 +0200

----------------------------------------------------------------------
 .../java/org/apache/camel/CamelContext.java     |  7 ++
 .../org/apache/camel/RuntimeConfiguration.java  |  3 +-
 .../mbean/ManagedCamelContextMBean.java         |  3 +
 .../apache/camel/impl/DefaultCamelContext.java  |  8 ++-
 .../management/mbean/ManagedCamelContext.java   |  4 ++
 .../DefaultCamelContextAutoStartupTest.java     |  8 +--
 .../interceptor/AdviceWithAutoStartupTest.java  | 68 ++++++++++++++++++++
 7 files changed, 94 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/ff702629/camel-core/src/main/java/org/apache/camel/CamelContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/CamelContext.java b/camel-core/src/main/java/org/apache/camel/CamelContext.java
index a9005bc..319e3a0 100644
--- a/camel-core/src/main/java/org/apache/camel/CamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/CamelContext.java
@@ -491,6 +491,13 @@ public interface CamelContext extends SuspendableService, RuntimeConfiguration {
     void startRoute(RouteDefinition route) throws Exception;
 
     /**
+     * Starts all the routes which currently is not started.
+     *
+     * @throws Exception is thrown if a route could not be started for whatever reason
+     */
+    void startAllRoutes() throws Exception;
+
+    /**
      * Starts the given route if it has been previously stopped
      *
      * @param routeId the route id

http://git-wip-us.apache.org/repos/asf/camel/blob/ff702629/camel-core/src/main/java/org/apache/camel/RuntimeConfiguration.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/RuntimeConfiguration.java b/camel-core/src/main/java/org/apache/camel/RuntimeConfiguration.java
index 0bcaff1..e1e0e2e 100644
--- a/camel-core/src/main/java/org/apache/camel/RuntimeConfiguration.java
+++ b/camel-core/src/main/java/org/apache/camel/RuntimeConfiguration.java
@@ -104,7 +104,8 @@ public interface RuntimeConfiguration {
      * <br/>
      * <b>Note:</b> When setting auto startup <tt>false</tt> on {@link CamelContext} then that takes precedence
      * and <i>no</i> routes is started. You would need to start {@link CamelContext} explicit using
-     * the {@link org.apache.camel.CamelContext#start()} method, to start the context and the routes.
+     * the {@link org.apache.camel.CamelContext#start()} method, to start the context, and then
+     * you would need to start the routes manually using {@link CamelContext#startRoute(String)}.
      * <p/>
      * Default is <tt>true</tt> to always start up.
      *

http://git-wip-us.apache.org/repos/asf/camel/blob/ff702629/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCamelContextMBean.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCamelContextMBean.java b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCamelContextMBean.java
index 590b431..865e52e 100644
--- a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCamelContextMBean.java
+++ b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCamelContextMBean.java
@@ -143,6 +143,9 @@ public interface ManagedCamelContextMBean extends ManagedPerformanceCounterMBean
     @ManagedOperation(description = "Resume Camel")
     void resume() throws Exception;
 
+    @ManagedOperation(description = "Starts all the routes which currently is not started")
+    void startAllRoutes() throws Exception;
+
     @ManagedOperation(description = "Send body (in only)")
     void sendBody(String endpointUri, Object body) throws Exception;
 

http://git-wip-us.apache.org/repos/asf/camel/blob/ff702629/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
index 4e41234..bbb8bde 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
@@ -794,6 +794,10 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
         stopRoute(route.idOrCreate(nodeIdFactory));
     }
 
+    public void startAllRoutes() throws Exception {
+        doStartOrResumeRoutes(routeServices, true, true, false, false);
+    }
+
     public synchronized void startRoute(String routeId) throws Exception {
         RouteService routeService = routeServices.get(routeId);
         if (routeService != null) {
@@ -1979,7 +1983,7 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
                     // this method will log the routes being started
                     safelyStartRouteServices(true, true, true, false, addingRoutes, routeService);
                     // start route services if it was configured to auto startup and we are not adding routes
-                    boolean autoStartup = routeService.getRouteDefinition().isAutoStartup(this);
+                    boolean autoStartup = routeService.getRouteDefinition().isAutoStartup(this) && this.isAutoStartup();
                     if (!addingRoutes || autoStartup) {
                         // start the route since auto start is enabled or we are starting a route (not adding new routes)
                         routeService.start();
@@ -2169,7 +2173,7 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
             RouteService routeService = entry.getValue().getRouteService();
 
             // if we are starting camel, then skip routes which are configured to not be auto started
-            boolean autoStartup = routeService.getRouteDefinition().isAutoStartup(this);
+            boolean autoStartup = routeService.getRouteDefinition().isAutoStartup(this) && this.isAutoStartup();
             if (addingRoute && !autoStartup) {
                 log.info("Skipping starting of route " + routeService.getId() + " as its configured with autoStartup=false");
                 continue;

http://git-wip-us.apache.org/repos/asf/camel/blob/ff702629/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
index 2aeffe8..3285c47 100644
--- a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
@@ -228,6 +228,10 @@ public class ManagedCamelContext extends ManagedPerformanceCounter implements Ti
         }
     }
 
+    public void startAllRoutes() throws Exception {
+        context.startAllRoutes();
+    }
+
     public void sendBody(String endpointUri, Object body) throws Exception {
         ProducerTemplate template = context.createProducerTemplate();
         try {

http://git-wip-us.apache.org/repos/asf/camel/blob/ff702629/camel-core/src/test/java/org/apache/camel/impl/DefaultCamelContextAutoStartupTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/impl/DefaultCamelContextAutoStartupTest.java b/camel-core/src/test/java/org/apache/camel/impl/DefaultCamelContextAutoStartupTest.java
index a1a4893..b4f5b6d 100644
--- a/camel-core/src/test/java/org/apache/camel/impl/DefaultCamelContextAutoStartupTest.java
+++ b/camel-core/src/test/java/org/apache/camel/impl/DefaultCamelContextAutoStartupTest.java
@@ -44,8 +44,8 @@ public class DefaultCamelContextAutoStartupTest extends TestSupport {
         assertEquals(1, camel.getRoutes().size());
         assertEquals(true, camel.getRouteStatus("foo").isStopped());
 
-        // now start camel again, to get it to start the routes
-        camel.start();
+        // now start all routes
+        camel.startAllRoutes();
 
         assertEquals(true, camel.getRouteStatus("foo").isStarted());
 
@@ -140,8 +140,8 @@ public class DefaultCamelContextAutoStartupTest extends TestSupport {
         assertEquals(true, camel.getRouteStatus("foo").isStopped());
         assertEquals(false, camel.getRouteStatus("foo").isStarted());
 
-        // now start camel again, to get it to start the routes
-        camel.start();
+        // now start all the routes
+        camel.startAllRoutes();
 
         assertEquals(true, camel.getRouteStatus("foo").isStarted());
 

http://git-wip-us.apache.org/repos/asf/camel/blob/ff702629/camel-core/src/test/java/org/apache/camel/processor/interceptor/AdviceWithAutoStartupTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/processor/interceptor/AdviceWithAutoStartupTest.java b/camel-core/src/test/java/org/apache/camel/processor/interceptor/AdviceWithAutoStartupTest.java
new file mode 100644
index 0000000..0cfb242
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/processor/interceptor/AdviceWithAutoStartupTest.java
@@ -0,0 +1,68 @@
+/**
+ * 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.interceptor;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.AdviceWithRouteBuilder;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * @version 
+ */
+public class AdviceWithAutoStartupTest extends ContextTestSupport {
+
+    public void testAdvised() throws Exception {
+        assertFalse(context.getRouteStatus("foo").isStarted());
+        assertFalse(context.getRouteStatus("bar").isStarted());
+
+        context.getRouteDefinition("bar").adviceWith(context, new AdviceWithRouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                replaceFromWith("seda:newBar");
+            }
+        });
+
+        assertFalse(context.getRouteStatus("foo").isStarted());
+        assertFalse(context.getRouteStatus("bar").isStarted());
+
+        context.startRoute("foo");
+        context.startRoute("bar");
+
+        assertTrue(context.getRouteStatus("foo").isStarted());
+        assertTrue(context.getRouteStatus("bar").isStarted());
+
+        getMockEndpoint("mock:newBar").expectedMessageCount(1);
+
+        template.sendBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                context.setAutoStartup(false);
+
+                from("direct:start").routeId("foo").to("seda:newBar");
+
+                from("seda:bar").routeId("bar").to("mock:newBar");
+            }
+        };
+    }
+}
\ No newline at end of file