Swallow BeanCurrentlyInCreationException exceptions
Update `TestcontainersLifecycleBeanPostProcessor` to that initialization doesn't fail if a `BeanCurrentlyInCreationException` is thrown. Prior to this commit, if the first bean being post-processed was a configuration class declaring a bean that the `Container` depended on all initialization would fail. See gh-35223
This commit is contained in:
@@ -95,6 +95,15 @@ class TestcontainersLifecycleApplicationContextInitializerTests {
|
||||
assertThat(applicationContext.getBeanFactoryPostProcessors()).hasSize(initialNumberOfPostProcessors + 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void dealsWithBeanCurrentlyInCreationException() {
|
||||
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
|
||||
new TestcontainersLifecycleApplicationContextInitializer().initialize(applicationContext);
|
||||
applicationContext.register(BeanCurrentlyInCreationExceptionConfiguration2.class,
|
||||
BeanCurrentlyInCreationExceptionConfiguration1.class);
|
||||
applicationContext.refresh();
|
||||
}
|
||||
|
||||
private AnnotationConfigApplicationContext createApplicationContext(Startable container) {
|
||||
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
|
||||
new TestcontainersLifecycleApplicationContextInitializer().initialize(applicationContext);
|
||||
@@ -114,4 +123,33 @@ class TestcontainersLifecycleApplicationContextInitializerTests {
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
static class BeanCurrentlyInCreationExceptionConfiguration1 {
|
||||
|
||||
@Bean
|
||||
TestBean testBean() {
|
||||
return new TestBean();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
static class BeanCurrentlyInCreationExceptionConfiguration2 {
|
||||
|
||||
BeanCurrentlyInCreationExceptionConfiguration2(TestBean testBean) {
|
||||
}
|
||||
|
||||
@Bean
|
||||
GenericContainer<?> container(TestBean testBean) {
|
||||
GenericContainer<?> container = mock(GenericContainer.class);
|
||||
given(container.isShouldBeReused()).willReturn(true);
|
||||
return container;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class TestBean {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user