Spring集成测试启动缓慢。原因?无法禁用 RabbitMQ

2023-12-26

我在启动集成测试时遇到性能问题。

我正在尝试模拟系统的消息传递。为此,我基本上使用@MockBean在我的网关上并使用@EnableAutoConfiguration(exclude = {RabbitAutoConfiguration.class})。例子:

@RunWith(SpringRunner.class)
@SpringBootTest(classes = MyApplication.class)
@WebAppConfiguration
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
@ActiveProfiles("test")
@EnableAutoConfiguration(exclude = {RabbitAutoConfiguration.class})
public class MyTestIT {

这两个配置很好地完成了工作,我的测试运行没有问题,并且不依赖于某些外部 RabbitMQ。

但是spring boot的启动时间非常非常慢。仅此部分配置大约两分钟SimpleMessageListenerContainer, AmqpInboundChannelAdapter, EventDrivenConsumer, RabbitExchangeQueueProvisioner, etc.

日志有一些关于问题所在的提示(我删掉了很多消息,这是一个示例):

2018-02-09 14:26:37.784  INFO [ms-project-name-service,,,] 13804 --- [           main] o.s.integration.channel.DirectChannel    : Channel 'ms-project-name-service:test:-1.channel2-output' has 1 subscriber(s).

2018-02-09 14:26:54.110  INFO [ms-project-name-service,,,] 13804 --- [           main] c.s.b.r.p.RabbitExchangeQueueProvisioner : declaring queue for inbound: channel1-input.anonymous.417FtxKTTce7-_IR0tGuNA, bound to: channel1-input

2018-02-09 14:27:00.147  INFO [ms-project-name-service,,,] 13804 --- [           main] o.s.c.stream.binder.BinderErrorChannel   : Channel 'ms-project-name-service:test:-1.channel1-input.anonymous.417FtxKTTce7-_IR0tGuNA.errors' has 2 subscriber(s).

2018-02-09 14:27:09.186  INFO [ms-project-name-service,,,] 13804 --- [ce7-_IR0tGuNA-1] o.s.a.r.l.SimpleMessageListenerContainer : Restarting Consumer@4f0ea6f8: tags=[{}], channel=null, acknowledgeMode=AUTO local queue size=0

最奇怪的是这个:

2018-02-09 14:58:42.783  WARN [ms-project-name-service,,,] 208 --- [geGeQP_9Li3Jg-1] o.s.a.r.l.SimpleMessageListenerContainer : Consumer raised exception, processing can restart if the connection factory supports it. Exception summary: org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused: connect

最后一个似乎他仍在尝试连接本地 RabbitMQ。

日志上有很多这样的消息。我不明白为什么即使禁用 RabbitMQAutoConfiguration 仍然会发生这种情况。如果没有 RabbitMQ 连接,Spring 如何在通道中订阅也是一个谜。


我们在这里遇到了类似的问题,通过更改跑步者解决了这个问题:

@RunWith(SpringRunner.class)

to

@RunWith(SpringJUnit4ClassRunner.class)

它们在文档中看起来是相同的,但真正启动了我们的测试性能。 让我知道它是否有效,我仍在查看文档以获取更多详细信息。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Spring集成测试启动缓慢。原因?无法禁用 RabbitMQ 的相关文章

随机推荐