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
Added additional url params in JdbcDatabaseContainer (#1802) #1874
Changes from all commits
0af8b12
456d477
00536ce
e55eb25
5417319
8af81ac
96c955e
709ad1e
722f32b
062070f
2022e5d
701a1b0
21f63e2
7eadac4
d89543e
128b69f
fd56078
f005def
4f1d18f
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 |
---|---|---|
|
@@ -55,6 +55,8 @@ protected Set<Integer> getLivenessCheckPorts() { | |
|
||
@Override | ||
protected void configure() { | ||
// Disable Postgres driver use of java.util.logging to reduce noise at startup time | ||
withUrlParam("loggerLevel", "OFF"); | ||
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. I haven't investigated what exactly this does, but it looks a bit weird. I can understand if by default the logging level should not be DEBUG or so, but I would definitely like to see errors and probably also warnings by default (i.e. without having to investigate how to change this manually). Please disregard if I missed something. 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. It used to be in the return "jdbc:postgresql://" + getContainerIpAddress() + ":" + getMappedPort(POSTGRESQL_PORT) + "/" + databaseName + "?loggerLevel=OFF"; I just moved it to the I'm guessing the logger was turned off on purpose to remove the noise at the start of the container. |
||
addEnv("POSTGRES_DB", databaseName); | ||
addEnv("POSTGRES_USER", username); | ||
addEnv("POSTGRES_PASSWORD", password); | ||
|
@@ -67,25 +69,9 @@ public String getDriverClassName() { | |
|
||
@Override | ||
public String getJdbcUrl() { | ||
// Disable Postgres driver use of java.util.logging to reduce noise at startup time | ||
return format("jdbc:postgresql://%s:%d/%s?loggerLevel=OFF", getHost(), getMappedPort(POSTGRESQL_PORT), databaseName); | ||
} | ||
|
||
@Override | ||
protected String constructUrlForConnection(String queryString) { | ||
String baseUrl = getJdbcUrl(); | ||
|
||
if ("".equals(queryString)) { | ||
return baseUrl; | ||
} | ||
|
||
if (!queryString.startsWith("?")) { | ||
throw new IllegalArgumentException("The '?' character must be included"); | ||
} | ||
|
||
return baseUrl.contains("?") | ||
? baseUrl + QUERY_PARAM_SEPARATOR + queryString.substring(1) | ||
: baseUrl + queryString; | ||
String additionalUrlParams = constructUrlParameters("?", "&"); | ||
return "jdbc:postgresql://" + getContainerIpAddress() + ":" + getMappedPort(POSTGRESQL_PORT) | ||
+ "/" + databaseName + additionalUrlParams; | ||
} | ||
|
||
@Override | ||
|
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.
Since some DBs like Oracle don't support URL parameters, but do support
Properties
parameters, I think it is worth considering renaming this method towithParam()
orwithJdbcParam()
, so that client code doesn't have to callwithUrlParameter()
for some DBs and something likewithPropertiesParam()
for others (assuming that will be also supported in the future). I just think this would be worth considering.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.
I think this is not entirely correct. What do you think about that, @rnorth ? Thx!
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.
Sorry to take so long to come back to this PR to break the tie...
I think the current form is reasonable; Oracle does not support JDBC URL parameters (in the normal sense of a URL parameter, anyway). Also, we don't support setting connection properties for the Oracle driver.
It's good to think about the future case of being agnostic of whether the connection params are set in the URL or as properties. However, I think that:
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.
Makes sense. Let's tackle that problem with connection properties separately. From my POV this commit looks good to go!