admin管理员组文章数量:1336659
I am trying to setup testcontainers with ActiveMQ broker.
Here's my setup, this is the base test class, that other tests inherit from:
@SpringBootTest
@ActiveProfiles("test")
abstract class BaseIntegrationTest {
companion object {
@JvmStatic
val activeMQContainer: GenericContainer<*> = GenericContainer("rmohr/activemq:5.15.9")
.withExposedPorts(61616)
.waitingFor(Wait.forListeningPort())
@JvmStatic
@BeforeAll
fun setup() {
activeMQContainer.start()
System.setProperty(
"jms.activemq.brokerUrl",
"tcp://${activeMQContainer.host}:${activeMQContainer.getMappedPort(61616)}"
)
}
@JvmStatic
@AfterAll
fun tearDown() {
activeMQContainer.stop()
}
}
}
And here is the test jmsTemplate config:
@Configuration
@Profile("test")
class TestJmsConfig(
@Value("\${jms.activemq.brokerUrl}") private val brokerUrl: String
) {
@Bean
fun connectionFactory(): ConnectionFactory {
return ActiveMQConnectionFactory().apply {
brokerURL = brokerUrl
}
}
@Bean
fun jmsTemplate(connectionFactory: ConnectionFactory): JmsTemplate {
return JmsTemplate(connectionFactory)
}
}
Here you can see the full setup:
I get the following error on the failing test:
jakarta.servlet.ServletException: Request processing failed: .springframework.jms.UncategorizedJmsException: Uncategorized exception occurred during JMS processing
...
Caused by: jakarta.jms.JMSException: Could not connect to broker URL: tcp://localhost:32769. Reason: java.ConnectException: Connection refused
...
Having one test class seems to be working, but the tests break when I have 2 test classes.
If I removed one of the test classes, the other one would pass.
I have set up simple tests like this:
@SpringBootTest
@AutoConfigureMockMvc
class NiceControllerIntegrationTest : BaseIntegrationTest() {
@Autowired
lateinit var mockMvc: MockMvc
@Test
fun `send nice message`() {
mockMvc.perform(MockMvcRequestBuilders.post("/v1/nice/send"))
}
}
where calling this endpoint triggers a message to be send to an ActiveMQ queue
And I expect them to pass. But when there is more than one test class, I get an error as described above
In my pom I am using
- Spring Boot version 3.2.5
- java version 21
- kotlin version 2.0.0
本文标签: spring bootHow to setup ActiveMQ broker for multiple TestcontainersStack Overflow
版权声明:本文标题:spring boot - How to setup ActiveMQ broker for multiple Testcontainers - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742419832a2471433.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论