java - 在 Cucumber 测试中无法关闭 CamelContext
问题描述
问题
问题有点小,但如下:在 Cucumber 测试中有多个场景时,日志被以下消息污染:
14:54:54.021 [Camel (camel-1) thread #7 - TemporaryQueueReplyManager[queueName]] ERROR o.a.c.c.j.DefaultJmsMessageListenerContainer - Could not refresh JMS Connection for destination 'temporary' - retrying using FixedBackOff{interval=5000, currentAttempts=26, maxAttempts=unlimited}. Cause: null
我在做什么
所以我有一个生成胖罐的应用程序。在我的 Cucumber 测试中,我从它自己的工作目录为每个场景运行这个 jar。jar 使用 JMS,所以我在测试中创建了一个 ActiveMQ 代理来进行通信。虽然 jar 没有使用 Apache-Camel,但 Cucumber 测试确实使用了 Camel。
在每个场景开始时,安装 jar,构建 Camel 上下文,启动 AMQ 代理,最后启动 jar。
然后发生测试步骤,在 jar 具有主动权的情况下使用 Routes 并在我正在存根的应用程序具有主动权的情况下使用生产者。
在测试结束时,我首先停止应用程序,在 CamelContext 上调用 stop 并停止代理。
模式似乎是对于同一功能文件中的每个场景,在相同的 JUnit 运行定义下,上述错误的出现次数似乎增加了。
我的假设是 CamelContext 中的某些东西挥之不去,从而导致了该消息。
我试过的
在项目开始时,选择了 Camel 版本 2.19.5。我试过用 2.24.3 版本运行它,它没有改变任何东西。
我的其余尝试都在这个块中,我停止了 CamelContext 和代理:
camelContext.getShutdownStrategy().setSuppressLoggingOnTimeout(true);
camelContext.getShutdownStrategy().setLogInflightExchangesOnTimeout(false);
camelContext.getShutdownStrategy().setTimeout(TimeUnit.SECONDS.toMillis(5));
camelContext.stop();
long startTime = System.currentTimeMillis();
try {
Awaitility.await().atMost(1, TimeUnit.MINUTES).until(() -> camelContext.getRoutes().isEmpty());
} finally {
LOG.info("Waited time for Camel was {}", System.currentTimeMillis() - startTime);
startTime = System.currentTimeMillis();
if (broker != null) {
broker.getBrokerService().stop();
broker.getBrokerService().waitUntilStopped();
LOG.info("Waited time for ActiveMQ was {}", System.currentTimeMillis() - startTime);
}
}
生成的日志记录对于 Camel 大约为 100 毫秒,对于 ActiveMQ 则低于 10 毫秒。
解决方案
推荐阅读
- python - Pillow - 改变每个像素的 RGB 值
- reactjs - 我有一个关于在单击时将 id 传递到我的详细信息路线的问题
- kubernetes - Tiller 每 30 秒超时,无法继续安装
- angular7 - 订阅许多承诺?
- javascript - 具有反应形式值的节点 js 过滤器数组
- c# - .NET 4.0 图形库 - 如何捕获“整个”屏幕?
- libra - 将助记词恢复种子写入文件时出错:LibraWalletGeneric: Permission denied (os error 13)
- python - 我的年份列表不适用于 BeautifulSoup。为什么?
- python - 用户输入一个字母后,我需要打印上一个字母、输入的字母和下一个字母
- python - 如何过滤 groupby 对象以使列值位于范围内?