admin管理员组文章数量:1391995
My setup is as follow.
I have a Kafka Consumer:
@KafkaListener(topics = "${pmp.kafka.import-catalog-processing.topic}", concurrency = "1", groupId = "${pmp.kafka.group-id}",
containerFactory = "kafkaProductListenerContainerFactory", errorHandler = "kafkaErrorHandler")
public void listen(List<String> values, @Header(KafkaHeaders.RECEIVED_KEY) List<String> keys) { ...
Which then uses a FileDownloadService during the processing.
And i use this as a BaseIntegrationTest
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ActiveProfiles({"test"})
public abstract class BaseIntegrationTest {
@MockitoBean
protected FileDownloadService fileDownloadService;
and mock the fileDownloadService class. I need to use @MockitoBean because the urls which will be downloaded are not under my control.
Now if i run a single integration test, the fileDownloadService works as expected. But if i run more than the test case which depends on the @KafkaListener does not work as expected.
What i see is that the instance of the fileDownloadService which is used during the processing of the listen method is another one as the one i have injected in the integration test.
My assumption is that the Bean with @KafkaListener is instantiated in the beginning with the "first" fileDownloadService. But the context changes between the tests.
I tried a lot so far. Unfornately, nothing worked yet. Also using @DirtiesContext does not change the fact that there are multiple fileDownloadService.
Any idea what could help here?
Thanks in advance+
My setup is as follow.
I have a Kafka Consumer:
@KafkaListener(topics = "${pmp.kafka.import-catalog-processing.topic}", concurrency = "1", groupId = "${pmp.kafka.group-id}",
containerFactory = "kafkaProductListenerContainerFactory", errorHandler = "kafkaErrorHandler")
public void listen(List<String> values, @Header(KafkaHeaders.RECEIVED_KEY) List<String> keys) { ...
Which then uses a FileDownloadService during the processing.
And i use this as a BaseIntegrationTest
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ActiveProfiles({"test"})
public abstract class BaseIntegrationTest {
@MockitoBean
protected FileDownloadService fileDownloadService;
and mock the fileDownloadService class. I need to use @MockitoBean because the urls which will be downloaded are not under my control.
Now if i run a single integration test, the fileDownloadService works as expected. But if i run more than the test case which depends on the @KafkaListener does not work as expected.
What i see is that the instance of the fileDownloadService which is used during the processing of the listen method is another one as the one i have injected in the integration test.
My assumption is that the Bean with @KafkaListener is instantiated in the beginning with the "first" fileDownloadService. But the context changes between the tests.
I tried a lot so far. Unfornately, nothing worked yet. Also using @DirtiesContext does not change the fact that there are multiple fileDownloadService.
Any idea what could help here?
Thanks in advance+
Share Improve this question asked Mar 14 at 6:39 user984200user984200 3031 gold badge7 silver badges20 bronze badges 3- Please edit your question to include a minimal reproducible example. – knittl Commented Mar 14 at 9:17
- Without seeing any code, it's impossible to know what could be wrong, but have you already checked everything in stackoverflow/questions/74027324/…? – knittl Commented Mar 14 at 9:17
- Please edit your question with an example test class that is having this issue – zn43 Commented Mar 15 at 18:54
1 Answer
Reset to default 0In the end the issue was that i had more than one @ConfigInitializer within my test class hierarchy. This lead to different contexts.
本文标签: springIssue with SpringBootTest with KafkaListener and MockitoSpyBeanStack Overflow
版权声明:本文标题:spring - Issue with @SpringBootTest with @KafkaListener and @MockitoSpyBean - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744670336a2618784.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论