gh-40772
I added since 3.4.0 everywhere but maybe it could be merged earlier if everything is ok.
Thanks in advance
Comment From: nosan
Should I also configure ApplicationName in PostgresR2dbcDockerComposeConnectionDetailsFactory?
Comment From: nosan
Should I also configure ApplicationName in
PostgresR2dbcDockerComposeConnectionDetailsFactory?
Auto-configure for r2dbc as well.
Comment From: nosan
Thank you for your feedback @snicoll and @wilkinsona
- I can add unit tests for
PostgresJdbcDockerComposeConnectionDetailsandPostgresDbR2dbcDockerComposeConnectionDetailswithout involving docker, to verify that all options are set correctly. - I can add a docker integration test for
PostgresJdbcDockerComposeConnectionDetailsFactoryandPostgresR2dbcDockerComposeConnectionDetailsFactoryto verify the application name is correctly set.
@DockerComposeTest(composeFile = "postgres-compose.yaml", image = TestImage.POSTGRESQL,
properties = "spring.application.name=my-app")
void runCreatesConnectionDetailsWithAutoConfiguredApplicationName(JdbcConnectionDetails connectionDetails)
throws ClassNotFoundException {
assertThat(connectionDetails.getUsername()).isEqualTo("myuser");
assertThat(connectionDetails.getPassword()).isEqualTo("secret");
assertThat(connectionDetails.getJdbcUrl()).startsWith("jdbc:postgresql://").endsWith("?ApplicationName=my-app");
assertThat(getApplicationName(connectionDetails)).isEqualTo("my-app");
}
private String getApplicationName(JdbcConnectionDetails connectionDetails) throws ClassNotFoundException {
JdbcTemplate template = getJdbcTemplate(connectionDetails);
return template.queryForObject("select current_setting('application_name')", String.class);
}
and
@DockerComposeTest(composeFile = "postgres-compose.yaml", image = TestImage.POSTGRESQL,
properties = "spring.application.name=my-app")
void runCreatesConnectionDetailsWithAutoConfiguredApplicationName(R2dbcConnectionDetails connectionDetails) {
assertConnectionDetails(connectionDetails);
assertThat(getApplicationName(connectionDetails)).isEqualTo("my-app");
}
private String getApplicationName(R2dbcConnectionDetails connectionDetails) {
ConnectionFactoryOptions connectionFactoryOptions = connectionDetails.getConnectionFactoryOptions();
return DatabaseClient.create(ConnectionFactories.get(connectionFactoryOptions))
.sql("select current_setting('application_name')")
.map((row, metadata) -> row.get(0))
.first()
.map(Objects::toString)
.block(Duration.ofSeconds(30));
}
Does it make sense?
Comment From: nosan
Also, should I revert my DockerComposeTestExtension changes? I can test the application name is set via docker-compose labels.
Comment From: nosan
PR has been updated.
- I reverted my
DockerComposeTestExtensionandJdbcUrlBuilderchanges. - I added unit tests for both
ConnectionDetailsand removed docker-compose integration tests. - I left only two docker-compose integration tests for checking that
application_namehad the desired effect on the Postgres side.