Repository navigation
feat(r2dbc): add getR2dbcUrl() helper method to R2DBC containers #12203
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,4 +32,16 @@ public ConnectionFactoryOptions configure(ConnectionFactoryOptions options) { | |
| .option(ConnectionFactoryOptions.PASSWORD, container.getPassword()) | ||
| .build(); | ||
| } | ||
|
|
||
| @Override | ||
| public String getR2dbcUrl() { | ||
| String additionalParams = container.getUrlParameters(); | ||
| return "r2dbc:mysql://" + | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. MySQL container URL omits the required user.
Include the configured username and [REDACTED] in the returned URL, in the form
|
||
| container.getHost() + | ||
| ":" + | ||
| container.getMappedPort(MySQLContainer.MYSQL_PORT) + | ||
| "/" + | ||
| container.getDatabaseName() + | ||
| additionalParams; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,4 +32,16 @@ public ConnectionFactoryOptions configure(ConnectionFactoryOptions options) { | |
| .option(ConnectionFactoryOptions.PASSWORD, container.getPassword()) | ||
| .build(); | ||
| } | ||
|
|
||
| @Override | ||
| public String getR2dbcUrl() { | ||
| String additionalParams = container.getUrlParameters(); | ||
| return "r2dbc:postgresql://" + | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Include credentials in the URL-only connection path.
|
||
| container.getHost() + | ||
| ":" + | ||
| container.getMappedPort(PostgreSQLContainer.POSTGRESQL_PORT) + | ||
| "/" + | ||
| container.getDatabaseName() + | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Encode the database name as a URL path component. For a database named
|
||
| additionalParams; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -5,4 +5,11 @@ | |||||||
|
|
||||||||
| public interface R2DBCDatabaseContainer extends Startable { | ||||||||
| ConnectionFactoryOptions configure(ConnectionFactoryOptions options); | ||||||||
|
|
||||||||
| /** | ||||||||
| * @return an R2DBC connection URL that may be used to connect to the dockerized database | ||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Document the Implementations that do not override Suggested fix
Committable suggestion
|
||||||||
| */ | ||||||||
| default String getR2dbcUrl() { | ||||||||
| throw new UnsupportedOperationException("getR2dbcUrl not implemented for this container"); | ||||||||
|
Comment on lines
+12
to
+13
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The new PostgreSQL, MySQL and MariaDB R2DBC wrappers throw on
Locations:
|
||||||||
| } | ||||||||
| } | ||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
R2DBC URLs drop parameter values after an
&.withUrlParamvalues go into the R2DBC URL without encoding. r2dbc-spi 0.9.0 splits the query at every&. For this input:the parser gets
applicationName=alpha. It dropsbetawithout an error. A value such asalpha&sslmode=disablealso adds an unintended option to the connection.Percent-encode each value before it is appended to the R2DBC URL, including
&. The parser decodes each value after it splits the query, so%26arrives as&. Apply this to all fourgetR2dbcUrl()builders.