testcontainers-java icon indicating copy to clipboard operation
testcontainers-java copied to clipboard

Container reuse across r2dbc:tc and jdbc:tc URLs

Open yerzhant opened this issue 3 years ago • 6 comments

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

yerzhant avatar Sep 21 '21 15:09 yerzhant

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.

kiview avatar Sep 22 '21 09:09 kiview

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)

brizzbuzz avatar Feb 01 '22 14:02 brizzbuzz

@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.

kiview avatar Feb 01 '22 16:02 kiview

@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

ThomasVitale avatar Feb 13 '22 15:02 ThomasVitale

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 😸

dinilimento avatar Jun 28 '22 14:06 dinilimento

Up!

giuliana-bezerra avatar Oct 14 '22 12:10 giuliana-bezerra

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/

ghaiszaher avatar Sep 25 '23 07:09 ghaiszaher