springrabbitmqapache-camelmaven-failsafe-plugin

Spring Camel integration tests slow with Timeout message


After switching from RabbitMQ to Spring RabbitMQ, the maven failsafe tests have become slower, with multiple messages of

o.a.c.i.engine.DefaultShutdownStrategy : Timeout occurred during graceful shutdown. Forcing the routes to be shutdown now. Notice: some resources may still be running as graceful shutdown did not complete successfully.

How to make the tests fast again?


Solution

  • This message is created by the DefaultShutdownStrategy. You can implement your own, like so:

    public class QuickShutdown implements ShutdownStrategy
    {
       @Override
       public void shutdownForced(final CamelContext context, final List<RouteStartupOrder> routes) throws Exception
       {
          routes.forEach(this::stopRoute);
       }
    
       private void stopRoute(RouteStartupOrder route) {
          route.getServices().forEach(Service::stop);
       }
    
       @Override
       public void shutdown(final CamelContext context, final List<RouteStartupOrder> routes) throws Exception
       {
          shutdownForced(context, routes);
       }
    
       @Override
       public void shutdown(final CamelContext context, final List<RouteStartupOrder> routes, final long timeout,
             final TimeUnit timeUnit)
             throws Exception
       {
          shutdownForced(context, routes);
       }
    
       @Override
       public boolean shutdown(final CamelContext context, final RouteStartupOrder route, final long timeout,
             final TimeUnit timeUnit,
             final boolean abortAfterTimeout) throws Exception
       {
          stopRoute(route);
          return false;
       }
    // leave remainder of auto-generated methods empty
    }
    

    And use it in each integration test:

    @Autowired
    private CamelContext camelContext;
    // ...
    @Before
    public void setup() {
        camelContext.setShutdownStrategy(new QuickShutdown());
    }
    

    or set this in a test configuration like so:

       @Bean
       CamelContextConfiguration contextConfiguration()
       {
          return new CamelContextConfiguration()
          {
             @Override
             public void beforeApplicationStart(@NonNull final CamelContext context)
             {
                context.setShutdownStrategy(new QuickShutdown());
             }
           // remaining method
        }}
    

    (a more elegant solution is appreciated)