testcontainers-java
testcontainers-java copied to clipboard
Container reuse across r2dbc:tc and jdbc:tc URLs
Could you please enable container reusage across r2dbc and jdbc urls?
Use case (in Spring Boot):
spring:
r2dbc:
url: r2dbc:tc:postgresql:///test?TC_IMAGE_TAG=12-alpine
flyway:
url: jdbc:tc:postgresql:12-alpine:///test
https://github.com/testcontainers/testcontainers-java/issues/4282
https://github.com/spring-projects/spring-boot/issues/28076
https://github.com/flyway/flyway/issues/3282
HI @yerzhant,
thanks for raising this issue and brining it to our attention, this is indeed a very interesting feature. However, implementation might be a bit more involved, so I can't promise when we will have time to work on this.
Contributions by the community exploring possible implementations are welcome.
Does anyone have any current workarounds for this? This seems to block any kind of integration tests that leverage Flyway (since they don't have r2dbc support, see here)
@unredundant
You can always use the regular Java object-based Testcontainers integration and use @DynamicPropertySource
to construct your specific URLs from the same container object.
@unredundant you can find an example of the workaround here: https://github.com/ThomasVitale/cloud-native-spring-in-action/blob/main/Chapter08/08-end/order-service/src/test/java/com/polarbookshop/orderservice/OrderServiceApplicationTests.java#L38
I think for JDBC this works by appending ?&TC_REUSABLE=true. I'm using the following:
spring:
datasource:
flyway:
url: jdbc:tc:sqlserver:2019-latest://testcontainers/testdb?TC_REUSABLE=true
Would be good to adjust the documentation accordingly if this is indeed intentional 😸
Up!
I think for JDBC this works by appending ?&TC_REUSABLE=true. I'm using the following:
spring: datasource: flyway: url: jdbc:tc:sqlserver:2019-latest://testcontainers/testdb?TC_REUSABLE=true
Would be good to adjust the documentation accordingly if this is indeed intentional 😸
I think this was done with https://github.com/testcontainers/testcontainers-java/pull/6216: https://java.testcontainers.org/features/reuse/