Comments (2)
You can try annotating @org.testcontainers.junit.jupiter.Testcontainers
on class WithContainers
.
But it will trigger another problem, the @DynamicPropertySource
method is invoked twice from DynamicPropertiesContextCustomizer
and DynamicPropertySourceMethodsImporter
.
Thread [main] (Suspended (breakpoint at line 22 in TestContainerTests))
owns: DefaultContextCache (id=82)
TestContainerTests.populateDynamicPropertyRegistry(DynamicPropertyRegistry) line: 22
NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]
NativeMethodAccessorImpl.invoke(Object, Object[]) line: 77
DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 43
Method.invoke(Object, Object...) line: 568
ReflectionUtils.invokeMethod(Method, Object, Object...) line: 281
DynamicPropertiesContextCustomizer.lambda$buildDynamicPropertiesMap$3(DynamicPropertyRegistry, Method) line: 82
Thread [main] (Suspended (breakpoint at line 22 in TestContainerTests))
owns: DefaultContextCache (id=82)
TestContainerTests.populateDynamicPropertyRegistry(DynamicPropertyRegistry) line: 22
NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]
NativeMethodAccessorImpl.invoke(Object, Object[]) line: 77
DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 43
Method.invoke(Object, Object...) line: 568
ReflectionUtils.invokeMethod(Method, Object, Object...) line: 281
DynamicPropertySourceMethodsImporter.lambda$registerDynamicPropertySources$0(DynamicPropertyRegistry, Method) line: 57
0x000000012f319850.accept(Object) line: not available
Here is the test case:
package com.example.demo;
import org.junit.jupiter.api.Test;
import org.springframework.boot.testcontainers.context.ImportTestcontainers;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
@SpringJUnitConfig
//@Testcontainers
public class TestContainerTests {
@Container
static PostgreSQLContainer<?> container = new PostgreSQLContainer<>("postgres");
@DynamicPropertySource
static void populateDynamicPropertyRegistry(DynamicPropertyRegistry registry) {
System.out.println(container.getMappedPort(5432));
}
@Test
void test() {
}
@Configuration
@ImportTestcontainers(TestContainerTests.class)
static class Config {
}
}
from spring-boot.
The problem is that you're accessing the container directly within your @DynamicPropertySource
method:
println(localStackContainer.getEndpointOverride(SQS))
This requires the container to have been started when the @DynamicPropertySource
method is called, undoing the benefit of the registry's lazy nature where you register a property with a supplier for its value. Using a supplier means that the container does not have to have been started until the property is accessed which happens later in the application lifecycle.
This worked in 3.2.0 as the containers were started very early but that was at the expense of support for parallel startup being broken. This was fixed in #38831.
In summary, this only worked in 3.2.0 accidentally and, unfortunately, you'll have to make some changes to adapt to the way things now work. You can either remove println
calls that access the container or move them into the supplier implementations where the values for the properties are being returned.
from spring-boot.
Related Issues (20)
- Polish gh-40023
- Rework fix for #21992 to avoid polluting Gradle Module Metadata with mavenOptional… variants
- Rework fix for #21992 to avoid polluting Gradle Module Metadata with mavenOptional… variants
- Update Kotlin DSL examples that configure the environment of bootBuildImage to be additive
- Update Kotlin DSL examples that configure the environment of bootBuildImage to be additive
- Make buildSrc's custom tasks consistently abstract
- Make buildSrc's custom tasks consistently abstract
- Make buildSrc's custom tasks consistently abstract
- TransactionalOperator is not configured in Data Neo4j HOT 9
- OtlpMetricsExportAutoConfiguration uses default OTLP metrics url when value comes from Dynamic Properties HOT 2
- Spring Boot 3.X Upgrade: Custom Health Indicator Not Recognized in Actuator Liveness Group HOT 3
- Review auto-configuration that accepts both a URI and separate properties
- @NewSpan/@SpanTag not working on interface methods HOT 3
- PaketoBuilderTests fail due to deprecation warning from the ca-certificates buildpack
- PaketoBuilderTests fail due to deprecation warning from the ca-certificates buildpack
- PaketoBuilderTests fail due to deprecation warning from the ca-certificates buildpack
- Enable eclipse ignoreUnnamedModuleForSplitPackage setting in buildSrc
- Not able to use actuator WriteOperation annotation with parameters HOT 3
- Springboot connection database password acquisition error HOT 3
- Springboot connection database password acquisition error HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spring-boot.