diff --git a/spring-boot-project/spring-boot-docker-compose/build.gradle b/spring-boot-project/spring-boot-docker-compose/build.gradle index 1cfb0f46e956..73c4c32df884 100644 --- a/spring-boot-project/spring-boot-docker-compose/build.gradle +++ b/spring-boot-project/spring-boot-docker-compose/build.gradle @@ -19,6 +19,8 @@ dependencies { dockerTestImplementation("org.junit.jupiter:junit-jupiter") dockerTestImplementation("org.testcontainers:testcontainers") + dockerTestRuntimeOnly("com.clickhouse:clickhouse-jdbc") + dockerTestRuntimeOnly("com.clickhouse:clickhouse-r2dbc") dockerTestRuntimeOnly("com.microsoft.sqlserver:mssql-jdbc") dockerTestRuntimeOnly("com.oracle.database.r2dbc:oracle-r2dbc") dockerTestRuntimeOnly("io.r2dbc:r2dbc-mssql") diff --git a/spring-boot-project/spring-boot-docker-compose/src/dockerTest/java/org/springframework/boot/docker/compose/service/connection/clickhouse/ClickHouseJdbcDockerComposeConnectionDetailsFactoryIntegrationTests.java b/spring-boot-project/spring-boot-docker-compose/src/dockerTest/java/org/springframework/boot/docker/compose/service/connection/clickhouse/ClickHouseJdbcDockerComposeConnectionDetailsFactoryIntegrationTests.java new file mode 100644 index 000000000000..efd49a088168 --- /dev/null +++ b/spring-boot-project/spring-boot-docker-compose/src/dockerTest/java/org/springframework/boot/docker/compose/service/connection/clickhouse/ClickHouseJdbcDockerComposeConnectionDetailsFactoryIntegrationTests.java @@ -0,0 +1,66 @@ +/* + * Copyright 2012-2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.docker.compose.service.connection.clickhouse; + +import javax.sql.DataSource; + +import org.springframework.boot.autoconfigure.jdbc.JdbcConnectionDetails; +import org.springframework.boot.docker.compose.service.connection.test.DockerComposeTest; +import org.springframework.boot.jdbc.DataSourceBuilder; +import org.springframework.boot.jdbc.DatabaseDriver; +import org.springframework.boot.testsupport.container.TestImage; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.datasource.SimpleDriverDataSource; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Integration tests for {@link ClickHouseJdbcDockerComposeConnectionDetailsFactory}. + * + * @author Dmytro Nosan + */ +class ClickHouseJdbcDockerComposeConnectionDetailsFactoryIntegrationTests { + + @DockerComposeTest(composeFile = "clickhouse-defaults-compose.yaml", image = TestImage.CLICKHOUSE) + void runCreatesJdbcConnectionDetailsWithDefaultValues(JdbcConnectionDetails connectionDetails) { + assertThat(connectionDetails.getUsername()).isEqualTo("default"); + assertThat(connectionDetails.getPassword()).isEqualTo(""); + assertThat(connectionDetails.getJdbcUrl()).startsWith("jdbc:clickhouse://").endsWith("/default"); + checkDatabaseAccess(connectionDetails); + } + + @DockerComposeTest(composeFile = "clickhouse-compose.yaml", image = TestImage.CLICKHOUSE) + void runCreatesJdbcConnectionDetails(JdbcConnectionDetails connectionDetails) { + assertThat(connectionDetails.getUsername()).isEqualTo("myuser"); + assertThat(connectionDetails.getPassword()).isEqualTo("secret"); + assertThat(connectionDetails.getJdbcUrl()).startsWith("jdbc:clickhouse://").endsWith("/mydatabase"); + checkDatabaseAccess(connectionDetails); + } + + private void checkDatabaseAccess(JdbcConnectionDetails connectionDetails) { + DataSource dataSource = DataSourceBuilder.create() + .type(SimpleDriverDataSource.class) + .url(connectionDetails.getJdbcUrl()) + .username(connectionDetails.getUsername()) + .password(connectionDetails.getPassword()) + .build(); + JdbcTemplate template = new JdbcTemplate(dataSource); + String sql = DatabaseDriver.CLICKHOUSE.getValidationQuery(); + assertThat(template.queryForObject(sql, Integer.class)).isEqualTo(1); + } + +} diff --git a/spring-boot-project/spring-boot-docker-compose/src/dockerTest/java/org/springframework/boot/docker/compose/service/connection/clickhouse/ClickHouseR2dbcDockerComposeConnectionDetailsFactoryIntegrationTests.java b/spring-boot-project/spring-boot-docker-compose/src/dockerTest/java/org/springframework/boot/docker/compose/service/connection/clickhouse/ClickHouseR2dbcDockerComposeConnectionDetailsFactoryIntegrationTests.java new file mode 100644 index 000000000000..21d175ddfa04 --- /dev/null +++ b/spring-boot-project/spring-boot-docker-compose/src/dockerTest/java/org/springframework/boot/docker/compose/service/connection/clickhouse/ClickHouseR2dbcDockerComposeConnectionDetailsFactoryIntegrationTests.java @@ -0,0 +1,77 @@ +/* + * Copyright 2012-2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.docker.compose.service.connection.clickhouse; + +import java.time.Duration; + +import io.r2dbc.spi.ConnectionFactories; +import io.r2dbc.spi.ConnectionFactory; +import io.r2dbc.spi.ConnectionFactoryOptions; +import reactor.core.publisher.Mono; + +import org.springframework.boot.autoconfigure.r2dbc.R2dbcConnectionDetails; +import org.springframework.boot.docker.compose.service.connection.test.DockerComposeTest; +import org.springframework.boot.jdbc.DatabaseDriver; +import org.springframework.boot.testsupport.container.TestImage; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Integration tests for {@link ClickHouseR2dbcDockerComposeConnectionDetailsFactory}. + * + * @author Dmytro Nosan + */ +class ClickHouseR2dbcDockerComposeConnectionDetailsFactoryIntegrationTests { + + @DockerComposeTest(composeFile = "clickhouse-defaults-compose.yaml", image = TestImage.CLICKHOUSE) + void runCreatesR2dbcConnectionDetailsWithDefaultValues(R2dbcConnectionDetails connectionDetails) { + ConnectionFactoryOptions options = connectionDetails.getConnectionFactoryOptions(); + assertCommonOptions(options); + assertThat(options.getRequiredValue(ConnectionFactoryOptions.DATABASE)).isEqualTo("default"); + assertThat(options.getRequiredValue(ConnectionFactoryOptions.USER)).isEqualTo("default"); + assertThat(options.hasOption(ConnectionFactoryOptions.PASSWORD)).isFalse(); + checkDatabaseAccess(connectionDetails); + } + + @DockerComposeTest(composeFile = "clickhouse-compose.yaml", image = TestImage.CLICKHOUSE) + void runCreatesR2dbcConnectionDetails(R2dbcConnectionDetails connectionDetails) { + ConnectionFactoryOptions options = connectionDetails.getConnectionFactoryOptions(); + assertCommonOptions(options); + assertThat(options.getRequiredValue(ConnectionFactoryOptions.DATABASE)).isEqualTo("mydatabase"); + assertThat(options.getRequiredValue(ConnectionFactoryOptions.USER)).isEqualTo("myuser"); + assertThat(options.getRequiredValue(ConnectionFactoryOptions.PASSWORD)).isEqualTo("secret"); + checkDatabaseAccess(connectionDetails); + } + + private void assertCommonOptions(ConnectionFactoryOptions options) { + assertThat(options.getRequiredValue(ConnectionFactoryOptions.HOST)).isNotNull(); + assertThat(options.getRequiredValue(ConnectionFactoryOptions.PORT)).isNotNull(); + assertThat(options.getRequiredValue(ConnectionFactoryOptions.DRIVER)).isEqualTo("clickhouse"); + } + + private void checkDatabaseAccess(R2dbcConnectionDetails connectionDetails) { + ConnectionFactoryOptions connectionFactoryOptions = connectionDetails.getConnectionFactoryOptions(); + ConnectionFactory connectionFactory = ConnectionFactories.get(connectionFactoryOptions); + String sql = DatabaseDriver.CLICKHOUSE.getValidationQuery(); + Integer result = Mono.from(connectionFactory.create()) + .flatMapMany((connection) -> connection.createStatement(sql).execute()) + .flatMap((r) -> r.map((row, rowMetadata) -> row.get(0, Integer.class))) + .blockFirst(Duration.ofSeconds(30)); + assertThat(result).isEqualTo(1); + } + +} diff --git a/spring-boot-project/spring-boot-docker-compose/src/dockerTest/resources/org/springframework/boot/docker/compose/service/connection/clickhouse/clickhouse-compose.yaml b/spring-boot-project/spring-boot-docker-compose/src/dockerTest/resources/org/springframework/boot/docker/compose/service/connection/clickhouse/clickhouse-compose.yaml new file mode 100644 index 000000000000..2d56633e7c47 --- /dev/null +++ b/spring-boot-project/spring-boot-docker-compose/src/dockerTest/resources/org/springframework/boot/docker/compose/service/connection/clickhouse/clickhouse-compose.yaml @@ -0,0 +1,9 @@ +services: + database: + image: '{imageName}' + ports: + - '8123' + environment: + - 'CLICKHOUSE_USER=myuser' + - 'CLICKHOUSE_PASSWORD=secret' + - 'CLICKHOUSE_DB=mydatabase' diff --git a/spring-boot-project/spring-boot-docker-compose/src/dockerTest/resources/org/springframework/boot/docker/compose/service/connection/clickhouse/clickhouse-defaults-compose.yaml b/spring-boot-project/spring-boot-docker-compose/src/dockerTest/resources/org/springframework/boot/docker/compose/service/connection/clickhouse/clickhouse-defaults-compose.yaml new file mode 100644 index 000000000000..fd91f0e7964d --- /dev/null +++ b/spring-boot-project/spring-boot-docker-compose/src/dockerTest/resources/org/springframework/boot/docker/compose/service/connection/clickhouse/clickhouse-defaults-compose.yaml @@ -0,0 +1,5 @@ +services: + database: + image: '{imageName}' + ports: + - '8123' diff --git a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/clickhouse/ClickHouseEnvironment.java b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/clickhouse/ClickHouseEnvironment.java new file mode 100644 index 000000000000..520e34e62e3c --- /dev/null +++ b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/clickhouse/ClickHouseEnvironment.java @@ -0,0 +1,52 @@ +/* + * Copyright 2012-2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.docker.compose.service.connection.clickhouse; + +import java.util.Map; + +/** + * ClickHouse environment details. + * + * @author Dmytro Nosan + */ +class ClickHouseEnvironment { + + private final String username; + + private final String password; + + private final String database; + + ClickHouseEnvironment(Map env) { + this.username = env.getOrDefault("CLICKHOUSE_USER", "default"); + this.password = env.getOrDefault("CLICKHOUSE_PASSWORD", ""); + this.database = env.getOrDefault("CLICKHOUSE_DB", "default"); + } + + String getUsername() { + return this.username; + } + + String getPassword() { + return this.password; + } + + String getDatabase() { + return this.database; + } + +} diff --git a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/clickhouse/ClickHouseJdbcDockerComposeConnectionDetailsFactory.java b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/clickhouse/ClickHouseJdbcDockerComposeConnectionDetailsFactory.java new file mode 100644 index 000000000000..75951e78c9ff --- /dev/null +++ b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/clickhouse/ClickHouseJdbcDockerComposeConnectionDetailsFactory.java @@ -0,0 +1,79 @@ +/* + * Copyright 2012-2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.docker.compose.service.connection.clickhouse; + +import org.springframework.boot.autoconfigure.jdbc.JdbcConnectionDetails; +import org.springframework.boot.docker.compose.core.RunningService; +import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionDetailsFactory; +import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionSource; +import org.springframework.boot.docker.compose.service.connection.jdbc.JdbcUrlBuilder; + +/** + * {@link DockerComposeConnectionDetailsFactory} to create {@link JdbcConnectionDetails} + * for a {@code ClickHouse} service. + * + * @author Dmytro Nosan + */ +class ClickHouseJdbcDockerComposeConnectionDetailsFactory + extends DockerComposeConnectionDetailsFactory { + + protected ClickHouseJdbcDockerComposeConnectionDetailsFactory() { + super("clickhouse/clickhouse-server"); + } + + @Override + protected JdbcConnectionDetails getDockerComposeConnectionDetails(DockerComposeConnectionSource source) { + return new ClickHouseJdbcDockerComposeConnectionDetails(source.getRunningService()); + } + + /** + * {@link JdbcConnectionDetails} backed by a {@code ClickHouse} + * {@link RunningService}. + */ + static class ClickHouseJdbcDockerComposeConnectionDetails extends DockerComposeConnectionDetails + implements JdbcConnectionDetails { + + private static final JdbcUrlBuilder jdbcUrlBuilder = new JdbcUrlBuilder("clickhouse", 8123); + + private final ClickHouseEnvironment environment; + + private final String jdbcUrl; + + ClickHouseJdbcDockerComposeConnectionDetails(RunningService service) { + super(service); + this.environment = new ClickHouseEnvironment(service.env()); + this.jdbcUrl = jdbcUrlBuilder.build(service, this.environment.getDatabase()); + } + + @Override + public String getUsername() { + return this.environment.getUsername(); + } + + @Override + public String getPassword() { + return this.environment.getPassword(); + } + + @Override + public String getJdbcUrl() { + return this.jdbcUrl; + } + + } + +} diff --git a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/clickhouse/ClickHouseR2dbcDockerComposeConnectionDetailsFactory.java b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/clickhouse/ClickHouseR2dbcDockerComposeConnectionDetailsFactory.java new file mode 100644 index 000000000000..a595f279bb55 --- /dev/null +++ b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/clickhouse/ClickHouseR2dbcDockerComposeConnectionDetailsFactory.java @@ -0,0 +1,71 @@ +/* + * Copyright 2012-2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.docker.compose.service.connection.clickhouse; + +import io.r2dbc.spi.ConnectionFactoryOptions; + +import org.springframework.boot.autoconfigure.r2dbc.R2dbcConnectionDetails; +import org.springframework.boot.docker.compose.core.RunningService; +import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionDetailsFactory; +import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionSource; +import org.springframework.boot.docker.compose.service.connection.r2dbc.ConnectionFactoryOptionsBuilder; + +/** + * {@link DockerComposeConnectionDetailsFactory} to create {@link R2dbcConnectionDetails} + * for a {@code ClickHouse} service. + * + * @author Dmytro Nosan + */ +class ClickHouseR2dbcDockerComposeConnectionDetailsFactory + extends DockerComposeConnectionDetailsFactory { + + ClickHouseR2dbcDockerComposeConnectionDetailsFactory() { + super("clickhouse/clickhouse-server", "io.r2dbc.spi.ConnectionFactoryOptions"); + } + + @Override + protected R2dbcConnectionDetails getDockerComposeConnectionDetails(DockerComposeConnectionSource source) { + return new ClickHouseR2dbcDockerComposeConnectionDetails(source.getRunningService()); + } + + /** + * {@link R2dbcConnectionDetails} backed by a {@code ClickHouse} + * {@link RunningService}. + */ + static class ClickHouseR2dbcDockerComposeConnectionDetails extends DockerComposeConnectionDetails + implements R2dbcConnectionDetails { + + private static final ConnectionFactoryOptionsBuilder connectionFactoryOptionsBuilder = new ConnectionFactoryOptionsBuilder( + "clickhouse", 8123); + + private final ConnectionFactoryOptions connectionFactoryOptions; + + ClickHouseR2dbcDockerComposeConnectionDetails(RunningService service) { + super(service); + ClickHouseEnvironment environment = new ClickHouseEnvironment(service.env()); + this.connectionFactoryOptions = connectionFactoryOptionsBuilder.build(service, environment.getDatabase(), + environment.getUsername(), environment.getPassword()); + } + + @Override + public ConnectionFactoryOptions getConnectionFactoryOptions() { + return this.connectionFactoryOptions; + } + + } + +} diff --git a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/clickhouse/package-info.java b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/clickhouse/package-info.java new file mode 100644 index 000000000000..9ec09361e8ba --- /dev/null +++ b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/clickhouse/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Auto-configuration for Docker Compose ClickHouse service connections. + */ +package org.springframework.boot.docker.compose.service.connection.clickhouse; diff --git a/spring-boot-project/spring-boot-docker-compose/src/main/resources/META-INF/spring.factories b/spring-boot-project/spring-boot-docker-compose/src/main/resources/META-INF/spring.factories index 12d13e5f65c4..ad1a5dfc2416 100644 --- a/spring-boot-project/spring-boot-docker-compose/src/main/resources/META-INF/spring.factories +++ b/spring-boot-project/spring-boot-docker-compose/src/main/resources/META-INF/spring.factories @@ -9,6 +9,8 @@ org.springframework.boot.docker.compose.service.connection.activemq.ActiveMQClas org.springframework.boot.docker.compose.service.connection.activemq.ActiveMQDockerComposeConnectionDetailsFactory,\ org.springframework.boot.docker.compose.service.connection.activemq.ArtemisDockerComposeConnectionDetailsFactory,\ org.springframework.boot.docker.compose.service.connection.cassandra.CassandraDockerComposeConnectionDetailsFactory,\ +org.springframework.boot.docker.compose.service.connection.clickhouse.ClickHouseJdbcDockerComposeConnectionDetailsFactory,\ +org.springframework.boot.docker.compose.service.connection.clickhouse.ClickHouseR2dbcDockerComposeConnectionDetailsFactory,\ org.springframework.boot.docker.compose.service.connection.elasticsearch.ElasticsearchDockerComposeConnectionDetailsFactory,\ org.springframework.boot.docker.compose.service.connection.flyway.JdbcAdaptingFlywayConnectionDetailsFactory,\ org.springframework.boot.docker.compose.service.connection.hazelcast.HazelcastDockerComposeConnectionDetailsFactory,\ diff --git a/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/clickhouse/ClickHouseEnvironmentTests.java b/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/clickhouse/ClickHouseEnvironmentTests.java new file mode 100644 index 000000000000..5ccc30f51f43 --- /dev/null +++ b/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/clickhouse/ClickHouseEnvironmentTests.java @@ -0,0 +1,73 @@ +/* + * Copyright 2012-2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.docker.compose.service.connection.clickhouse; + +import java.util.Collections; +import java.util.Map; + +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for {@link ClickHouseEnvironment}. + * + * @author Dmytro Nosan + */ +class ClickHouseEnvironmentTests { + + @Test + void getUsernameWhenClickHouseUserEnvIsPresent() { + ClickHouseEnvironment environment = createEnvironment(Map.of("CLICKHOUSE_USER", "test")); + assertThat(environment.getUsername()).isEqualTo("test"); + } + + @Test + void getUsernameWhenClickHouseUserEnvDoesNotExist() { + ClickHouseEnvironment environment = createEnvironment(Collections.emptyMap()); + assertThat(environment.getUsername()).isEqualTo("default"); + } + + @Test + void getPasswordWhenClickHousePasswordEnvIsPresent() { + ClickHouseEnvironment environment = createEnvironment(Map.of("CLICKHOUSE_PASSWORD", "test")); + assertThat(environment.getPassword()).isEqualTo("test"); + } + + @Test + void getPasswordWhenClickHousePasswordEnvDoesNotExist() { + ClickHouseEnvironment environment = createEnvironment(Collections.emptyMap()); + assertThat(environment.getPassword()).isEqualTo(""); + } + + @Test + void getDatabaseWhenClickHouseDbEnvIsPresent() { + ClickHouseEnvironment environment = createEnvironment(Map.of("CLICKHOUSE_DB", "test")); + assertThat(environment.getDatabase()).isEqualTo("test"); + } + + @Test + void getDatabaseWhenClickHouseDbEnvDoesNotExist() { + ClickHouseEnvironment environment = createEnvironment(Collections.emptyMap()); + assertThat(environment.getDatabase()).isEqualTo("default"); + } + + private ClickHouseEnvironment createEnvironment(Map env) { + return new ClickHouseEnvironment(env); + } + +} diff --git a/spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/features/dev-services.adoc b/spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/features/dev-services.adoc index c769d9003de9..f8133064f01f 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/features/dev-services.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/features/dev-services.adoc @@ -99,7 +99,7 @@ The following service connections are currently supported: | Containers named "hazelcast/hazelcast". | `JdbcConnectionDetails` -| Containers named "gvenzl/oracle-free", "gvenzl/oracle-xe", "mariadb", "bitnami/mariadb", "mssql/server", "mysql", "bitnami/mysql", "postgres", or "bitnami/postgresql" +| Containers named "clickhouse/clickhouse-server", "gvenzl/oracle-free", "gvenzl/oracle-xe", "mariadb", "bitnami/mariadb", "mssql/server", "mysql", "bitnami/mysql", "postgres", or "bitnami/postgresql" | `LdapConnectionDetails` | Containers named "osixia/openldap" @@ -123,7 +123,7 @@ The following service connections are currently supported: | Containers named "apachepulsar/pulsar" | `R2dbcConnectionDetails` -| Containers named "gvenzl/oracle-free", "gvenzl/oracle-xe", "mariadb", "bitnami/mariadb", "mssql/server", "mysql", "bitnami/mysql", "postgres", or "bitnami/postgresql" +| Containers named "clickhouse/clickhouse-server", "gvenzl/oracle-free", "gvenzl/oracle-xe", "mariadb", "bitnami/mariadb", "mssql/server", "mysql", "bitnami/mysql", "postgres", or "bitnami/postgresql" | `RabbitConnectionDetails` | Containers named "rabbitmq" or "bitnami/rabbitmq" diff --git a/spring-boot-project/spring-boot-parent/build.gradle b/spring-boot-project/spring-boot-parent/build.gradle index 2f9173cd0d4f..923fb02ca1c9 100644 --- a/spring-boot-project/spring-boot-parent/build.gradle +++ b/spring-boot-project/spring-boot-parent/build.gradle @@ -36,7 +36,8 @@ bom { library("ClickHouse", "0.6.5") { group("com.clickhouse") { modules = [ - "clickhouse-jdbc" + "clickhouse-jdbc", + "clickhouse-r2dbc" ] } } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-test-support-docker/build.gradle b/spring-boot-project/spring-boot-tools/spring-boot-test-support-docker/build.gradle index aae510e78bc2..1acec1c77588 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-test-support-docker/build.gradle +++ b/spring-boot-project/spring-boot-tools/spring-boot-test-support-docker/build.gradle @@ -16,6 +16,7 @@ dependencies { optional("org.testcontainers:activemq") optional("org.testcontainers:cassandra") + optional("org.testcontainers:clickhouse") optional("org.testcontainers:couchbase") optional("org.testcontainers:elasticsearch") optional("org.testcontainers:grafana") diff --git a/spring-boot-project/spring-boot-tools/spring-boot-test-support-docker/src/main/java/org/springframework/boot/testsupport/container/TestImage.java b/spring-boot-project/spring-boot-tools/spring-boot-test-support-docker/src/main/java/org/springframework/boot/testsupport/container/TestImage.java index 9c5922723b44..6eb413a4f1da 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-test-support-docker/src/main/java/org/springframework/boot/testsupport/container/TestImage.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-test-support-docker/src/main/java/org/springframework/boot/testsupport/container/TestImage.java @@ -28,6 +28,7 @@ import org.testcontainers.activemq.ActiveMQContainer; import org.testcontainers.activemq.ArtemisContainer; import org.testcontainers.cassandra.CassandraContainer; +import org.testcontainers.clickhouse.ClickHouseContainer; import org.testcontainers.containers.Container; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.MongoDBContainer; @@ -100,6 +101,11 @@ public enum TestImage { (container) -> ((CouchbaseContainer) container).withStartupAttempts(5) .withStartupTimeout(Duration.ofMinutes(10))), + /** + * A container image suitable for testing ClickHouse. + */ + CLICKHOUSE("clickhouse/clickhouse-server", "24.3-alpine", () -> ClickHouseContainer.class), + /** * A container image suitable for testing Elasticsearch 7. */