You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by al...@apache.org on 2019/06/21 12:46:06 UTC

[camel] branch master updated: CAMEL-13666: Fixed the autoStartup cancellation from route policy issue

This is an automated email from the ASF dual-hosted git repository.

aldettinger pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/master by this push:
     new 3b1cb18  CAMEL-13666: Fixed the autoStartup cancellation from route policy issue
3b1cb18 is described below

commit 3b1cb18bd8d55996620983a66051c4b029004210
Author: aldettinger <al...@gmail.com>
AuthorDate: Fri Jun 21 09:08:01 2019 +0200

    CAMEL-13666: Fixed the autoStartup cancellation from route policy issue
---
 .../JGroupsRaftClusteredRoutePolicyTest.java       |  1 -
 .../java/org/apache/camel/impl/RouteService.java   |  3 ++
 .../RoutePolicyAutoStartupCancelledOnInitTest.java | 51 ++++++++++++++++++++++
 3 files changed, 54 insertions(+), 1 deletion(-)

diff --git a/components/camel-jgroups-raft/src/test/java/org/apache/camel/component/jgroups/raft/cluster/JGroupsRaftClusteredRoutePolicyTest.java b/components/camel-jgroups-raft/src/test/java/org/apache/camel/component/jgroups/raft/cluster/JGroupsRaftClusteredRoutePolicyTest.java
index 2cbcf3d..f676644 100644
--- a/components/camel-jgroups-raft/src/test/java/org/apache/camel/component/jgroups/raft/cluster/JGroupsRaftClusteredRoutePolicyTest.java
+++ b/components/camel-jgroups-raft/src/test/java/org/apache/camel/component/jgroups/raft/cluster/JGroupsRaftClusteredRoutePolicyTest.java
@@ -94,7 +94,6 @@ public class JGroupsRaftClusteredRoutePolicyTest extends JGroupsRaftClusterAbstr
             public void configure() throws Exception {
                 from("timer:master?delay=1s&period=1s")
                         .routeId("route-" + id)
-                        .autoStartup(false)
                         .routePolicy(ClusteredRoutePolicy.forNamespace("jgr"))
                         .log("From ${routeId}");
             }
diff --git a/core/camel-core/src/main/java/org/apache/camel/impl/RouteService.java b/core/camel-core/src/main/java/org/apache/camel/impl/RouteService.java
index 1551af6..8d0d18d 100644
--- a/core/camel-core/src/main/java/org/apache/camel/impl/RouteService.java
+++ b/core/camel-core/src/main/java/org/apache/camel/impl/RouteService.java
@@ -61,6 +61,9 @@ public class RouteService extends BaseRouteService {
         if (!getCamelContext().isAutoStartup()) {
             return false;
         }
+        if (!getRouteContext().isAutoStartup()) {
+            return false;
+        }
         if (routeDefinition.getAutoStartup() == null) {
             // should auto startup by default
             return true;
diff --git a/core/camel-core/src/test/java/org/apache/camel/impl/RoutePolicyAutoStartupCancelledOnInitTest.java b/core/camel-core/src/test/java/org/apache/camel/impl/RoutePolicyAutoStartupCancelledOnInitTest.java
new file mode 100644
index 0000000..bacd9e2
--- /dev/null
+++ b/core/camel-core/src/test/java/org/apache/camel/impl/RoutePolicyAutoStartupCancelledOnInitTest.java
@@ -0,0 +1,51 @@
+/*
+ * 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.impl;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Route;
+import org.apache.camel.ServiceStatus;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.spi.RoutePolicy;
+import org.apache.camel.support.RoutePolicySupport;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class RoutePolicyAutoStartupCancelledOnInitTest extends ContextTestSupport {
+
+    private RoutePolicy policy = new RoutePolicySupport() {
+        @Override
+        public void onInit(Route route) {
+            route.getRouteContext().setAutoStartup(false);
+        }
+    };
+
+    @Test
+    public void test() {
+        ServiceStatus status = context.getRouteController().getRouteStatus("foo");
+        Assert.assertEquals(ServiceStatus.Stopped, status);
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            public void configure() {
+                from("direct:start").routeId("foo").routePolicy(policy).to("mock:result");
+            }
+        };
+    }
+}