New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
R2dbc support #1141
R2dbc support #1141
Conversation
|
Awesome news. You might want to wait until the configuration/discoverability PR (r2dbc/r2dbc-spi#30) is merged. This will be an improvement to generic client bootstrap. |
|
Thanks, definitely will. |
|
Hi @Humblehound I have no experience with R2DBC yet, so I'd need to look into it first, but the feature itself is probably very desirable. Right now I'm wondering, if we couldn't support JDBC and R2DBC in the same classes, just a different getter? |
|
Thanks :) So that would totally be possible - I thought initially that it wouldn't work for the containers to use both JDBC and R2DBC at the same time and we would have to make the existing methods for getting |
|
This proved to be much simpler than I expected - I've reverted previous commits and just exposed a
If you are ok with both I'd add missing documentation |
|
Connection Factory Discovery has now landed in R2DBC. This way, using code is not required to touch driver classes but rather can declare options that are used to determine an appropriate driver: ConnectionFactoryOptions options = builder()
.option(DRIVER, "mssql") // alternative: postgresql
.option(HOST, "…")
.option(PORT, …)
.option(USER, "…")
.option(PASSWORD, "…")
.option(DATABASE, "…")
.build();
ConnectionFactory connectionFactory = ConnectionFactories.get(options);
Mono<Connection> connectionMono = factory.create(); |
|
While this syntax is easier to use for the end user, here I think that using specific implementations would be better. The ConnectionFactory needs to be returned for each driver: If we were to use |
|
@Humblehound I’m not sure you lose any type safety with |
|
@nebhale Indeed, but here I just don't see a benefit in passing a string containing a driver name to the |
|
But of course, it's your project so I'm happy to refactor to |
|
No, no I didn't want to be strongly one way or the other 😄 I just wanted to clarify the lack of type safety. What I think @mp911de was getting at is that using |
|
@Humblehound @nebhale I think the best end goal we could achieve is supporting R2DBC URI (like we do with JDBC) and implementing a fake, proxying R2DBC driver inside Testcontainers. I don't think it makes sense to add R2DBC connection factory getter to the containers (because it is trivial to do on the user's side). Also, R2DBC is not available in Maven Central yet and we can't depend on it directly, only with Gradle's |
Already discussing internally. |
We do provide a However, I'm not to keen to having |
|
I've refactored the code into a single module with support for postgres and mssql. |
modules/r2dbc/src/main/java/org/testcontainers/r2dbc/R2dbcMSSQLServerContainer.java
Outdated
Show resolved
Hide resolved
Move tests to separate module
modules/r2dbc-test/src/test/java/org/testcontainers/r2dbc/SimpleR2dbcMSSQLServerTest.java
Outdated
Show resolved
Hide resolved
modules/r2dbc-test/src/test/java/org/testcontainers/r2dbc/SimpleR2dbcPostgreSQLTest.java
Outdated
Show resolved
Hide resolved
modules/r2dbc/src/main/java/org/testcontainers/r2dbc/R2dbcMSSQLServerContainer.java
Outdated
Show resolved
Hide resolved
modules/r2dbc/src/main/java/org/testcontainers/r2dbc/R2dbcPostgresContainer.java
Outdated
Show resolved
Hide resolved
|
I believe I've resolved all the conflicts and done all requested changes. I've also added a sample doc section. Anything else left to improve? |
|
FYI r2dbc/r2dbc-spi#37 was merged and now we can finally continue with the R2DBC support 🎉 |
|
R2DBC 0.8.0.M8 is released and so URL formats are stable. R2DBC Javadoc: https://r2dbc.io/spec/0.8.0.M8/api/ |
|
@mp911de, @kiview and I met and discussed a couple of weeks ago. Sorry for the late writeup, but what we discussed was a plan to:
The latter would have a binary dependency on R2DBC and thus belongs in a new module. As such, I think this particular PR can be trimmed a lot or replaced, unfortunately @Humblehound. Thank you for sparking the conversations, and sorry it's taken a long time so far. |
|
No problem, I'm glad to have the problem resolved one way or another. |
|
Hello, so what about testing r2dbc spring-boot apps with postgres and testcontainers? Thanks |
I've recently decided to try R2DBC and noticed that TestContainers is currently only compatible with JDBC. I've decided to add the support for it, however there are lots of impactful decisions to be made so I'd like some feedback on the assumptions I've made. I've currently implemented a very basic support for Postgresql containers. Before I go any further I'd like to discuss the following topics:
Packaging. So far it seems possible to reuse
GenericContainer, so I've decided to work with that and created a new package equivalent to theorg.testcontainers.jdbc. The existing container implementations are tightly coupled with JDBC, so it would be best to have a separate class for each R2DBC container. The container implementations would be prefixed withR2dbcand reside in the packages next to original JDBC versions.JDBC URI. As @mp911de has mentioned here and also here it would be desirable to not reimplement DataSource discovery based on string parsing. For the time being, I suggest a following approach:
ConnectionFactory, but so far I see no benefit in this.When ConnectionFactory discovery is merged maybe we could use that.
R2dbcDatabaseContaineris mostly copied fromJdbcDatabaseContainer, and all concrete implementation would contain lots of duplicate code as well. To solve this we could either:R2dbcDatabaseContainerandGenericDatabaseContainerGenericDatabaseContaineras possible add R2dbc compatibility at that level (seems unlikely)Looking forward to your opinions, I'm happy to be devastated in a review