Camel
  1. Camel
  2. CAMEL-4790

Using the CamelContext.stopRoute(routeId) should not remove the route from context

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.8.3
    • Fix Version/s: 2.8.4, 2.9.0
    • Component/s: camel-core
    • Labels:
      None
    • Estimated Complexity:
      Unknown

      Description

      Christian reported a camel route stop issue few months ago[1], I found this bug by running the unit test he submit.

      public class RouteRemoveTest extends ContextTestSupport {
       
      +    public void testStopRouteOnContext() throws Exception {
      +        assertEquals(ServiceStatus.Started, ((DefaultRoute) context.getRoute("foo")).getStatus());
      +        assertEquals(ServiceStatus.Started, context.getRouteStatus("foo"));
      +        
      +        context.stopRoute("foo");
      +        
      +        assertEquals(ServiceStatus.Stopped, ((DefaultRoute) context.getRoute("foo")).getStatus());
      +        assertEquals(ServiceStatus.Stopped, context.getRouteStatus("foo"));
      +    }
      

      The route foo should not be removed from the camelContext.
      [1] http://camel.465427.n5.nabble.com/Stop-a-route-for-unit-testing-tt4724550.html#a5011082

        Activity

        Hide
        Claus Ibsen added a comment -

        Willem is this an issue in Camel 2.8.x as well? If so please backport the fix.

        Show
        Claus Ibsen added a comment - Willem is this an issue in Camel 2.8.x as well? If so please backport the fix.
        Hide
        Willem Jiang added a comment -

        committed the patch into trunk and 2.8.x branch.

        Show
        Willem Jiang added a comment - committed the patch into trunk and 2.8.x branch.
        Hide
        Willem Jiang added a comment -

        @Claus,
        I just committed the backport fix of Camel 2.8.x after resolving some network connect issue.

        Show
        Willem Jiang added a comment - @Claus, I just committed the backport fix of Camel 2.8.x after resolving some network connect issue.
        Hide
        Christian Müller added a comment -

        I added the second unit test I provided and it still fails:

        public void testStopRouteOnRoute() throws Exception {
            assertEquals(ServiceStatus.Started, ((DefaultRoute) context.getRoute("foo")).getStatus());
            assertEquals(ServiceStatus.Started, context.getRouteStatus("foo"));
        
            ((DefaultRoute) context.getRoute("foo")).stop();
        
            assertEquals(ServiceStatus.Stopped, ((DefaultRoute) context.getRoute("foo")).getStatus());
            assertEquals(ServiceStatus.Stopped, context.getRouteStatus("foo"));
        }
        

        Do I something stupid?

        Show
        Christian Müller added a comment - I added the second unit test I provided and it still fails: public void testStopRouteOnRoute() throws Exception { assertEquals(ServiceStatus.Started, ((DefaultRoute) context.getRoute( "foo" )).getStatus()); assertEquals(ServiceStatus.Started, context.getRouteStatus( "foo" )); ((DefaultRoute) context.getRoute( "foo" )).stop(); assertEquals(ServiceStatus.Stopped, ((DefaultRoute) context.getRoute( "foo" )).getStatus()); assertEquals(ServiceStatus.Stopped, context.getRouteStatus( "foo" )); } Do I something stupid?
        Hide
        Willem Jiang added a comment -

        Hi Christian

        I was planing to send a mail for the second unit test but it takes me too much time to merge the patch due to the network issue.

        Here is my explanation for it, because Camel is using the RouteService to delegate the life cycle invocation, it is also in charge of do some clean up work with the CamelContext. If you just stop the route directly without through the CamelContext API, you will face a issue that the RouteService can not has the same status of the Route.
        So my suggestion is you should use the CamelContext API instead of stop the route directly.

        We should consider not expose the Route itself to client to use in Camel 3.0.

        Show
        Willem Jiang added a comment - Hi Christian I was planing to send a mail for the second unit test but it takes me too much time to merge the patch due to the network issue. Here is my explanation for it, because Camel is using the RouteService to delegate the life cycle invocation, it is also in charge of do some clean up work with the CamelContext. If you just stop the route directly without through the CamelContext API, you will face a issue that the RouteService can not has the same status of the Route. So my suggestion is you should use the CamelContext API instead of stop the route directly. We should consider not expose the Route itself to client to use in Camel 3.0.
        Hide
        Claus Ibsen added a comment -

        I have added javadoc notes to the API to document how to properly control the lifecycle of the routes, eg use the API from CamelContext.

        Show
        Claus Ibsen added a comment - I have added javadoc notes to the API to document how to properly control the lifecycle of the routes, eg use the API from CamelContext.
        Hide
        Christian Müller added a comment -

        Should we deprecate the methods (context.getRoute(String), context.getRoutes(), ...)?

        Show
        Christian Müller added a comment - Should we deprecate the methods (context.getRoute(String), context.getRoutes(), ...)?
        Hide
        Claus Ibsen added a comment -

        No we should not deprecate those methods, as end users should be able to get the Route instance if they need.

        Its just the lifecycle of the routes is best handled using the API from CamelContext to ensure graceful shutdown, and whatnot.

        Show
        Claus Ibsen added a comment - No we should not deprecate those methods, as end users should be able to get the Route instance if they need. Its just the lifecycle of the routes is best handled using the API from CamelContext to ensure graceful shutdown, and whatnot.

          People

          • Assignee:
            Willem Jiang
            Reporter:
            Willem Jiang
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development