从RabbitMQ切换到Spring RabbitMQ后,maven故障安全测试变得更慢,有多个
消息o.a.c.i.engine.DefaultShutdownStrategy :正常关闭期间发生超时。现在强制关闭路由。注意:由于正常关闭未成功完成,某些资源可能仍在运行。
如何让测试再次快速?
此消息由 DefaultShutdownStrategy 创建。您可以实现自己的,如下所示:
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
}
并在每个集成测试中使用它:
@Autowired
private CamelContext camelContext;
// ...
@Before
public void setup() {
camelContext.setShutdownStrategy(new QuickShutdown());
}
(更优雅的解决方案值得赞赏)