简体   繁体   English

如何在带有Gemfire和多个Spring应用程序配置的Spring Boot中执行集成测试?

[英]How to perform integration testing in Spring Boot with Gemfire and multiple Spring Application Configurations?

I'm trying to run an integration test that has a different SpringApplicationConfiguration from the other integration tests. 我正在尝试运行一个具有与其他集成测试不同的SpringApplicationConfiguration的集成测试。 The issue only manifests when Gemfire is configured. 仅当配置了Gemfire时,该问题才会显现。

A demonstration of the error in available here: https://github.com/kemitix/test-spring-boot-gemfire-testing 该错误的演示可在此处获取: https//github.com/kemitix/test-spring-boot-gemfire-testing

There are two test classes ContextsApplicationTests and ContextsApplicationWithCustomTests . 有两个测试类ContextsApplicationTestsContextsApplicationWithCustomTests

The first uses a standard SpringApplicationConfiguration based on the ContextsApplication class. 第一种使用基于ContextsApplication类的标准SpringApplicationConfiguration The other attempts to also include the CustomConfiguration class to override a Bean. 其他尝试还包括CustomConfiguration类以覆盖Bean。

Test one: 测试一:

@IntegrationTest
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = ContextsApplication.class)
public class ContextsApplicationTests {
...

Test two: 测试二:

@IntegrationTest
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = {
    ContextsApplication.class,
    CustomConfiguration.class
})
public class ContextsApplicationWithCustomTests {

Without having Gemfire enabled the tests run happily. 在没有启用Gemfire的情况下,测试可以愉快地运行。

However, having Gemfire configured causes an issue with the context loader throwing an IllegalArgumentException : 但是,配置Gemfire会导致上下文加载器抛出IllegalArgumentException

Caused by: java.lang.IllegalArgumentException: 
    a beanFactoryReference already exists for key cacheFactoryBean

The full output is included in the file mvn-clean-install.txt in the repo. 完整的输出包含在mvn-clean-install.txt中的文件mvn-clean-install.txt中。

When the two tests are run in isolation they work. 当两个测试单独运行时,它们将起作用。 It is only when they are run together that the issue appears. 仅当它们一起运行时,问题才出现。 I suspect the Gemfire instance that Spring Boot is running is causing some sort of bleed-over between the two tests that is causing the Contexts not to be properly segregated. 我怀疑Spring Boot正在运行的Gemfire实例在两个测试之间导致某种形式的流血,这导致无法正确隔离上下文。 Unfortunately, I've no idea how to influence this. 不幸的是,我不知道如何影响这一点。

您也可以尝试CacheFactoryBean.setUseBeanFactoryLocator(false)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM