CAMEL-8964: CamelContext API for routeStatus is wrong for suspended routes.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/ea8ee025 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/ea8ee025 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/ea8ee025 Branch: refs/heads/master Commit: ea8ee025e7c59345a48849440629ef1295d4d25c Parents: 48d187e Author: Claus Ibsen <davscl...@apache.org> Authored: Tue Jul 14 09:34:48 2015 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Tue Jul 14 09:34:48 2015 +0200 ---------------------------------------------------------------------- .../apache/camel/impl/DefaultCamelContext.java | 13 +++- .../org/apache/camel/util/ServiceHelper.java | 8 +- .../camel/impl/RouteSedaStopStartTest.java | 78 ++++++++++++++++++++ .../camel/impl/RouteSedaSuspendResumeTest.java | 10 +++ 4 files changed, 103 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/ea8ee025/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 c24674e..0ed913a 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 @@ -984,6 +984,9 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon RouteService routeService = routeServices.get(routeId); if (routeService != null) { resumeRouteService(routeService); + // must resume the route as well + Route route = getRoute(routeId); + ServiceHelper.resumeService(route); } } @@ -1125,12 +1128,15 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon RouteService routeService = routeServices.get(routeId); if (routeService != null) { List<RouteStartupOrder> routes = new ArrayList<RouteStartupOrder>(1); - RouteStartupOrder order = new DefaultRouteStartupOrder(1, routeService.getRoutes().iterator().next(), routeService); + Route route = routeService.getRoutes().iterator().next(); + RouteStartupOrder order = new DefaultRouteStartupOrder(1, route, routeService); routes.add(order); getShutdownStrategy().suspend(this, routes); // must suspend route service as well suspendRouteService(routeService); + // must suspend the route as well + ServiceHelper.suspendService(route); } } @@ -1143,12 +1149,15 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon RouteService routeService = routeServices.get(routeId); if (routeService != null) { List<RouteStartupOrder> routes = new ArrayList<RouteStartupOrder>(1); - RouteStartupOrder order = new DefaultRouteStartupOrder(1, routeService.getRoutes().iterator().next(), routeService); + Route route = routeService.getRoutes().iterator().next(); + RouteStartupOrder order = new DefaultRouteStartupOrder(1, route, routeService); routes.add(order); getShutdownStrategy().suspend(this, routes, timeout, timeUnit); // must suspend route service as well suspendRouteService(routeService); + // must suspend the route as well + ServiceHelper.suspendService(route); } } http://git-wip-us.apache.org/repos/asf/camel/blob/ea8ee025/camel-core/src/main/java/org/apache/camel/util/ServiceHelper.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/util/ServiceHelper.java b/camel-core/src/main/java/org/apache/camel/util/ServiceHelper.java index 0a7df51..90b5ce9 100644 --- a/camel-core/src/main/java/org/apache/camel/util/ServiceHelper.java +++ b/camel-core/src/main/java/org/apache/camel/util/ServiceHelper.java @@ -260,7 +260,7 @@ public final class ServiceHelper { * If there's any exception being thrown while resuming the elements one after the * other this method would rethrow the <b>first</b> such exception being thrown. * - * @see #resumeService(Service) + * @see #resumeService(Object) */ public static void resumeServices(Collection<?> services) throws Exception { if (services == null) { @@ -308,7 +308,7 @@ public final class ServiceHelper { * @throws Exception is thrown if error occurred * @see #startService(Service) */ - public static boolean resumeService(Service service) throws Exception { + public static boolean resumeService(Object service) throws Exception { if (service instanceof SuspendableService) { SuspendableService ss = (SuspendableService) service; if (ss.isSuspended()) { @@ -331,7 +331,7 @@ public final class ServiceHelper { * If there's any exception being thrown while suspending the elements one after the * other this method would rethrow the <b>first</b> such exception being thrown. * - * @see #suspendService(Service) + * @see #suspendService(Object) */ public static void suspendServices(Collection<?> services) throws Exception { if (services == null) { @@ -379,7 +379,7 @@ public final class ServiceHelper { * @throws Exception is thrown if error occurred * @see #stopService(Object) */ - public static boolean suspendService(Service service) throws Exception { + public static boolean suspendService(Object service) throws Exception { if (service instanceof SuspendableService) { SuspendableService ss = (SuspendableService) service; if (!ss.isSuspended()) { http://git-wip-us.apache.org/repos/asf/camel/blob/ea8ee025/camel-core/src/test/java/org/apache/camel/impl/RouteSedaStopStartTest.java ---------------------------------------------------------------------- diff --git a/camel-core/src/test/java/org/apache/camel/impl/RouteSedaStopStartTest.java b/camel-core/src/test/java/org/apache/camel/impl/RouteSedaStopStartTest.java new file mode 100644 index 0000000..aadd797 --- /dev/null +++ b/camel-core/src/test/java/org/apache/camel/impl/RouteSedaStopStartTest.java @@ -0,0 +1,78 @@ +/** + * 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.StatefulService; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; + +/** + * @version + */ +public class RouteSedaStopStartTest extends ContextTestSupport { + + public void testStopStart() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:result"); + mock.expectedBodiesReceived("A"); + + template.sendBody("seda:foo", "A"); + + assertMockEndpointsSatisfied(); + + log.info("Stopping"); + + // now suspend and dont expect a message to be routed + resetMocks(); + mock.expectedMessageCount(0); + context.stopRoute("foo"); + + assertEquals("Stopped", context.getRouteStatus("foo").name()); + Route route = context.getRoute("foo"); + if (route instanceof StatefulService) { + assertEquals("Stopped", ((StatefulService) route).getStatus().name()); + } + + template.sendBody("seda:foo", "B"); + mock.assertIsSatisfied(1000); + + log.info("Starting"); + + // now resume and expect the previous message to be routed + resetMocks(); + mock.expectedBodiesReceived("B"); + context.startRoute("foo"); + assertMockEndpointsSatisfied(); + + assertEquals("Started", context.getRouteStatus("foo").name()); + route = context.getRoute("foo"); + if (route instanceof StatefulService) { + assertEquals("Started", ((StatefulService) route).getStatus().name()); + } + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("seda:foo").routeId("foo").to("log:foo").to("mock:result"); + } + }; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/ea8ee025/camel-core/src/test/java/org/apache/camel/impl/RouteSedaSuspendResumeTest.java ---------------------------------------------------------------------- diff --git a/camel-core/src/test/java/org/apache/camel/impl/RouteSedaSuspendResumeTest.java b/camel-core/src/test/java/org/apache/camel/impl/RouteSedaSuspendResumeTest.java index ff74dc1..cc103ee 100644 --- a/camel-core/src/test/java/org/apache/camel/impl/RouteSedaSuspendResumeTest.java +++ b/camel-core/src/test/java/org/apache/camel/impl/RouteSedaSuspendResumeTest.java @@ -17,6 +17,8 @@ package org.apache.camel.impl; import org.apache.camel.ContextTestSupport; +import org.apache.camel.Route; +import org.apache.camel.StatefulService; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.mock.MockEndpoint; @@ -41,6 +43,10 @@ public class RouteSedaSuspendResumeTest extends ContextTestSupport { context.suspendRoute("foo"); assertEquals("Suspended", context.getRouteStatus("foo").name()); + Route route = context.getRoute("foo"); + if (route instanceof StatefulService) { + assertEquals("Suspended", ((StatefulService) route).getStatus().name()); + } template.sendBody("seda:foo", "B"); mock.assertIsSatisfied(1000); @@ -54,6 +60,10 @@ public class RouteSedaSuspendResumeTest extends ContextTestSupport { assertMockEndpointsSatisfied(); assertEquals("Started", context.getRouteStatus("foo").name()); + route = context.getRoute("foo"); + if (route instanceof StatefulService) { + assertEquals("Started", ((StatefulService) route).getStatus().name()); + } } @Override