diff --git a/docs/document/content/user-manual/shardingsphere-jdbc/optional-plugins/_index.cn.md b/docs/document/content/user-manual/shardingsphere-jdbc/optional-plugins/_index.cn.md index 423d9b0e1d68a..a884f47178fbe 100644 --- a/docs/document/content/user-manual/shardingsphere-jdbc/optional-plugins/_index.cn.md +++ b/docs/document/content/user-manual/shardingsphere-jdbc/optional-plugins/_index.cn.md @@ -52,5 +52,7 @@ ShardingSphere 默认情况下仅包含核心 SPI 的实现,在 Git Source 存 - `org.apache.shardingsphere:shardingsphere-sql-translator-jooq-provider`,使用 JooQ 的 SQL 翻译器 - 行表达式 - `org.apache.shardingsphere:shardingsphere-infra-expr-espresso`,基于 GraalVM Truffle 的 Espresso 实现的使用 Groovy 语法的行表达式 +- 数据库类型识别 + - `org.apache.shardingsphere:shardingsphere-infra-database-testcontainers`, 对 `testcontainers-java` 的 `JDBC support` 的 jdbcURL 的识别适配 除了以上可选插件外,ShardingSphere 社区开发者还贡献了大量的插件实现,可以在 [ShardingSphere Plugin](https://github.com/apache/shardingsphere-plugin) 仓库中查看插件的使用说明,ShardingSphere Plugin 仓库中的插件会和 ShardingSphere 保持相同的发布节奏,可以在 https://central.sonatype.com/ 进行检索,并安装到 ShardingSphere 中。 diff --git a/docs/document/content/user-manual/shardingsphere-jdbc/optional-plugins/_index.en.md b/docs/document/content/user-manual/shardingsphere-jdbc/optional-plugins/_index.en.md index 009973ee41b53..a8dc0adf92d82 100644 --- a/docs/document/content/user-manual/shardingsphere-jdbc/optional-plugins/_index.en.md +++ b/docs/document/content/user-manual/shardingsphere-jdbc/optional-plugins/_index.en.md @@ -52,5 +52,7 @@ All optional plugins are listed below in the form of `groupId:artifactId`. - `org.apache.shardingsphere:shardingsphere-sql-translator-jooq-provider`, JooQ SQL translator - Row Value Expressions definition - `org.apache.shardingsphere:shardingsphere-infra-expr-espresso`,Row Value Expressions that uses the Groovy syntax based on GraalVM Truffle's Espresso implementation +- Database type identification + - `org.apache.shardingsphere:shardingsphere-infra-database-testcontainers`, Adaptation of jdbcURL for `JDBC support` of `testcontainers-java` In addition to the above optional plugins, ShardingSphere community developers have contributed a number of plugin implementations. These plugins can be found in [ShardingSphere Plugins] (https://github.com/apache/shardingsphere-plugin) repository. Plugins in ShardingSphere Plugin repository would remain the same release plan with ShardingSphere, they can be retrieved at https://central.sonatype.com/, and install into ShardingSphere. diff --git a/docs/document/content/user-manual/shardingsphere-proxy/optional-plugins/_index.cn.md b/docs/document/content/user-manual/shardingsphere-proxy/optional-plugins/_index.cn.md index 0233fe8eee85c..2fdf18541eed0 100644 --- a/docs/document/content/user-manual/shardingsphere-proxy/optional-plugins/_index.cn.md +++ b/docs/document/content/user-manual/shardingsphere-proxy/optional-plugins/_index.cn.md @@ -40,5 +40,7 @@ ShardingSphere 默认情况下仅包含核心 SPI 的实现,在 Git Source 存 - `org.apache.shardingsphere:shardingsphere-sql-translator-jooq-provider`,使用 JooQ 的 SQL 翻译器 - 行表达式 - `org.apache.shardingsphere:shardingsphere-infra-expr-espresso`,基于 GraalVM Truffle 的 Espresso 实现的使用 Groovy 语法的行表达式 +- 数据库类型识别 + - `org.apache.shardingsphere:shardingsphere-infra-database-testcontainers`, 对 `testcontainers-java` 的 `JDBC support` 的 jdbcURL 的识别适配 除了以上可选插件外,ShardingSphere 社区开发者还贡献了大量的插件实现,可以在 [ShardingSphere Plugin](https://github.com/apache/shardingsphere-plugin) 仓库中查看插件的使用说明,ShardingSphere Plugin 仓库中的插件会和 ShardingSphere 保持相同的发布节奏,可以在 https://central.sonatype.com/ 进行检索,并安装到 ShardingSphere 中。 diff --git a/docs/document/content/user-manual/shardingsphere-proxy/optional-plugins/_index.en.md b/docs/document/content/user-manual/shardingsphere-proxy/optional-plugins/_index.en.md index d056937ca045b..b39fd6b4c37af 100644 --- a/docs/document/content/user-manual/shardingsphere-proxy/optional-plugins/_index.en.md +++ b/docs/document/content/user-manual/shardingsphere-proxy/optional-plugins/_index.en.md @@ -40,5 +40,7 @@ All optional plugins are listed below in the form of `groupId:artifactId`. - `org.apache.shardingsphere:shardingsphere-sql-translator-jooq-provider`, JooQ SQL translator - Row Value Expressions definition - `org.apache.shardingsphere:shardingsphere-infra-expr-espresso`,Row Value Expressions that uses the Groovy syntax based on GraalVM Truffle's Espresso implementation +- Database type identification + - `org.apache.shardingsphere:shardingsphere-infra-database-testcontainers`, Adaptation of jdbcURL for `JDBC support` of `testcontainers-java` In addition to the above optional plugins, ShardingSphere community developers have contributed a number of plugin implementations. These plugins can be found in [ShardingSphere Plugins](https://github.com/apache/shardingsphere-plugin) repository. Plugins in ShardingSphere Plugin repository would remain the same release plan with ShardingSphere, they can be retrieved at https://central.sonatype.com/, and install into ShardingSphere. diff --git a/infra/database/type/clickhouse/src/main/java/org/apache/shardingsphere/infra/database/clickhouse/type/ClickHouseDatabaseType.java b/infra/database/type/clickhouse/src/main/java/org/apache/shardingsphere/infra/database/clickhouse/type/ClickHouseDatabaseType.java index 84b1daacecd73..c03b7b18bb2dd 100644 --- a/infra/database/type/clickhouse/src/main/java/org/apache/shardingsphere/infra/database/clickhouse/type/ClickHouseDatabaseType.java +++ b/infra/database/type/clickhouse/src/main/java/org/apache/shardingsphere/infra/database/clickhouse/type/ClickHouseDatabaseType.java @@ -25,14 +25,14 @@ import java.util.Optional; /** - * Database type of ClickHouse. Includes verification of Docker Images involved in commonly used testcontainers. + * Database type of ClickHouse. * ClickHouse currently uses MySQL dialect parsing. */ public final class ClickHouseDatabaseType implements DatabaseType { @Override public Collection getJdbcUrlPrefixes() { - return Arrays.asList("jdbc:ch:", "jdbc:clickhouse:", "jdbc:tc:clickhouse/clickhouse-server:", "jdbc:tc:yandex/clickhouse-server:"); + return Arrays.asList("jdbc:ch:", "jdbc:clickhouse:"); } @Override diff --git a/infra/database/type/clickhouse/src/test/java/org/apache/shardingsphere/infra/database/clickhouse/type/ClickHouseDatabaseTypeTest.java b/infra/database/type/clickhouse/src/test/java/org/apache/shardingsphere/infra/database/clickhouse/type/ClickHouseDatabaseTypeTest.java index 9b91e31b0e335..87e7dc7ed45d7 100644 --- a/infra/database/type/clickhouse/src/test/java/org/apache/shardingsphere/infra/database/clickhouse/type/ClickHouseDatabaseTypeTest.java +++ b/infra/database/type/clickhouse/src/test/java/org/apache/shardingsphere/infra/database/clickhouse/type/ClickHouseDatabaseTypeTest.java @@ -30,7 +30,6 @@ class ClickHouseDatabaseTypeTest { @Test void assertGetJdbcUrlPrefixes() { - assertThat(TypedSPILoader.getService(DatabaseType.class, "ClickHouse").getJdbcUrlPrefixes(), - is(Arrays.asList("jdbc:ch:", "jdbc:clickhouse:", "jdbc:tc:clickhouse/clickhouse-server:", "jdbc:tc:yandex/clickhouse-server:"))); + assertThat(TypedSPILoader.getService(DatabaseType.class, "ClickHouse").getJdbcUrlPrefixes(), is(Arrays.asList("jdbc:ch:", "jdbc:clickhouse:"))); } } diff --git a/infra/database/type/mariadb/src/main/java/org/apache/shardingsphere/infra/database/mariadb/type/MariaDBDatabaseType.java b/infra/database/type/mariadb/src/main/java/org/apache/shardingsphere/infra/database/mariadb/type/MariaDBDatabaseType.java index c53ff914878a8..a8a621b494914 100644 --- a/infra/database/type/mariadb/src/main/java/org/apache/shardingsphere/infra/database/mariadb/type/MariaDBDatabaseType.java +++ b/infra/database/type/mariadb/src/main/java/org/apache/shardingsphere/infra/database/mariadb/type/MariaDBDatabaseType.java @@ -20,18 +20,18 @@ import org.apache.shardingsphere.infra.database.core.type.DatabaseType; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; -import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.Optional; /** - * Database type of MariaDB. Includes verification of Docker Images involved in commonly used testcontainers. + * Database type of MariaDB. */ public final class MariaDBDatabaseType implements DatabaseType { @Override public Collection getJdbcUrlPrefixes() { - return Arrays.asList(String.format("jdbc:%s:", getType().toLowerCase()), "jdbc:tc:mariadb:"); + return Collections.singletonList(String.format("jdbc:%s:", getType().toLowerCase())); } @Override diff --git a/infra/database/type/mariadb/src/test/java/org/apache/shardingsphere/infra/database/mariadb/type/MariaDBDatabaseTypeTest.java b/infra/database/type/mariadb/src/test/java/org/apache/shardingsphere/infra/database/mariadb/type/MariaDBDatabaseTypeTest.java index 3530facdb94e5..da4e68d408e57 100644 --- a/infra/database/type/mariadb/src/test/java/org/apache/shardingsphere/infra/database/mariadb/type/MariaDBDatabaseTypeTest.java +++ b/infra/database/type/mariadb/src/test/java/org/apache/shardingsphere/infra/database/mariadb/type/MariaDBDatabaseTypeTest.java @@ -21,7 +21,7 @@ import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.junit.jupiter.api.Test; -import java.util.Arrays; +import java.util.Collections; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; @@ -30,6 +30,6 @@ class MariaDBDatabaseTypeTest { @Test void assertGetJdbcUrlPrefixes() { - assertThat(TypedSPILoader.getService(DatabaseType.class, "MariaDB").getJdbcUrlPrefixes(), is(Arrays.asList("jdbc:mariadb:", "jdbc:tc:mariadb:"))); + assertThat(TypedSPILoader.getService(DatabaseType.class, "MariaDB").getJdbcUrlPrefixes(), is(Collections.singletonList("jdbc:mariadb:"))); } } diff --git a/infra/database/type/mysql/src/main/java/org/apache/shardingsphere/infra/database/mysql/type/MySQLDatabaseType.java b/infra/database/type/mysql/src/main/java/org/apache/shardingsphere/infra/database/mysql/type/MySQLDatabaseType.java index fd3f14f4258fc..bd8c635575990 100644 --- a/infra/database/type/mysql/src/main/java/org/apache/shardingsphere/infra/database/mysql/type/MySQLDatabaseType.java +++ b/infra/database/type/mysql/src/main/java/org/apache/shardingsphere/infra/database/mysql/type/MySQLDatabaseType.java @@ -23,13 +23,13 @@ import java.util.Collection; /** - * Database type of MySQL. Includes verification of Docker Images involved in commonly used testcontainers. + * Database type of MySQL. */ public final class MySQLDatabaseType implements DatabaseType { @Override public Collection getJdbcUrlPrefixes() { - return Arrays.asList("jdbc:mysql:", "jdbc:mysqlx:", "jdbc:tc:mysql:"); + return Arrays.asList("jdbc:mysql:", "jdbc:mysqlx:"); } @Override diff --git a/infra/database/type/mysql/src/test/java/org/apache/shardingsphere/infra/database/mysql/type/MySQLDatabaseTypeTest.java b/infra/database/type/mysql/src/test/java/org/apache/shardingsphere/infra/database/mysql/type/MySQLDatabaseTypeTest.java index 64f2927bcd1a6..63d7970db3887 100644 --- a/infra/database/type/mysql/src/test/java/org/apache/shardingsphere/infra/database/mysql/type/MySQLDatabaseTypeTest.java +++ b/infra/database/type/mysql/src/test/java/org/apache/shardingsphere/infra/database/mysql/type/MySQLDatabaseTypeTest.java @@ -30,6 +30,6 @@ class MySQLDatabaseTypeTest { @Test void assertGetJdbcUrlPrefixes() { - assertThat(TypedSPILoader.getService(DatabaseType.class, "MySQL").getJdbcUrlPrefixes(), is(Arrays.asList("jdbc:mysql:", "jdbc:mysqlx:", "jdbc:tc:mysql:"))); + assertThat(TypedSPILoader.getService(DatabaseType.class, "MySQL").getJdbcUrlPrefixes(), is(Arrays.asList("jdbc:mysql:", "jdbc:mysqlx:"))); } } diff --git a/infra/database/type/oracle/src/main/java/org/apache/shardingsphere/infra/database/oracle/type/OracleDatabaseType.java b/infra/database/type/oracle/src/main/java/org/apache/shardingsphere/infra/database/oracle/type/OracleDatabaseType.java index 1404fa1a0638a..39961ae07f4c0 100644 --- a/infra/database/type/oracle/src/main/java/org/apache/shardingsphere/infra/database/oracle/type/OracleDatabaseType.java +++ b/infra/database/type/oracle/src/main/java/org/apache/shardingsphere/infra/database/oracle/type/OracleDatabaseType.java @@ -19,17 +19,17 @@ import org.apache.shardingsphere.infra.database.core.type.DatabaseType; -import java.util.Arrays; import java.util.Collection; +import java.util.Collections; /** - * Database type of Oracle. Includes verification of Docker Images involved in commonly used testcontainers. + * Database type of Oracle. */ public final class OracleDatabaseType implements DatabaseType { @Override public Collection getJdbcUrlPrefixes() { - return Arrays.asList(String.format("jdbc:%s:", getType().toLowerCase()), "jdbc:tc:gvenzl/oracle-free:", "jdbc:tc:gvenzl/oracle-xe:"); + return Collections.singletonList(String.format("jdbc:%s:", getType().toLowerCase())); } @Override diff --git a/infra/database/type/oracle/src/test/java/org/apache/shardingsphere/infra/database/oracle/type/OracleDatabaseTypeTest.java b/infra/database/type/oracle/src/test/java/org/apache/shardingsphere/infra/database/oracle/type/OracleDatabaseTypeTest.java index 5cca23fdb8e51..f7ec24a15f4e2 100644 --- a/infra/database/type/oracle/src/test/java/org/apache/shardingsphere/infra/database/oracle/type/OracleDatabaseTypeTest.java +++ b/infra/database/type/oracle/src/test/java/org/apache/shardingsphere/infra/database/oracle/type/OracleDatabaseTypeTest.java @@ -21,7 +21,7 @@ import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.junit.jupiter.api.Test; -import java.util.Arrays; +import java.util.Collections; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; @@ -30,6 +30,6 @@ class OracleDatabaseTypeTest { @Test void assertGetJdbcUrlPrefixes() { - assertThat(TypedSPILoader.getService(DatabaseType.class, "Oracle").getJdbcUrlPrefixes(), is(Arrays.asList("jdbc:oracle:", "jdbc:tc:gvenzl/oracle-free:", "jdbc:tc:gvenzl/oracle-xe:"))); + assertThat(TypedSPILoader.getService(DatabaseType.class, "Oracle").getJdbcUrlPrefixes(), is(Collections.singletonList("jdbc:oracle:"))); } } diff --git a/infra/database/type/pom.xml b/infra/database/type/pom.xml index 0d2e4169b7e62..a70e18f3415d3 100644 --- a/infra/database/type/pom.xml +++ b/infra/database/type/pom.xml @@ -37,5 +37,6 @@ h2 sql92 clickhouse + testcontainers diff --git a/infra/database/type/postgresql/src/main/java/org/apache/shardingsphere/infra/database/postgresql/type/PostgreSQLDatabaseType.java b/infra/database/type/postgresql/src/main/java/org/apache/shardingsphere/infra/database/postgresql/type/PostgreSQLDatabaseType.java index 6a0ee5c741e2c..2300718051e20 100644 --- a/infra/database/type/postgresql/src/main/java/org/apache/shardingsphere/infra/database/postgresql/type/PostgreSQLDatabaseType.java +++ b/infra/database/type/postgresql/src/main/java/org/apache/shardingsphere/infra/database/postgresql/type/PostgreSQLDatabaseType.java @@ -19,17 +19,17 @@ import org.apache.shardingsphere.infra.database.core.type.DatabaseType; -import java.util.Arrays; import java.util.Collection; +import java.util.Collections; /** - * Database type of PostgreSQL. Includes verification of Docker Images involved in commonly used testcontainers. + * Database type of PostgreSQL. */ public final class PostgreSQLDatabaseType implements DatabaseType { @Override public Collection getJdbcUrlPrefixes() { - return Arrays.asList(String.format("jdbc:%s:", getType().toLowerCase()), "jdbc:tc:postgresql:"); + return Collections.singletonList(String.format("jdbc:%s:", getType().toLowerCase())); } @Override diff --git a/infra/database/type/postgresql/src/test/java/org/apache/shardingsphere/infra/database/postgresql/type/PostgreSQLDatabaseTypeTest.java b/infra/database/type/postgresql/src/test/java/org/apache/shardingsphere/infra/database/postgresql/type/PostgreSQLDatabaseTypeTest.java index c784dee54f970..de62363e1211a 100644 --- a/infra/database/type/postgresql/src/test/java/org/apache/shardingsphere/infra/database/postgresql/type/PostgreSQLDatabaseTypeTest.java +++ b/infra/database/type/postgresql/src/test/java/org/apache/shardingsphere/infra/database/postgresql/type/PostgreSQLDatabaseTypeTest.java @@ -21,7 +21,7 @@ import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.junit.jupiter.api.Test; -import java.util.Arrays; +import java.util.Collections; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; @@ -30,6 +30,6 @@ class PostgreSQLDatabaseTypeTest { @Test void assertGetJdbcUrlPrefixes() { - assertThat(TypedSPILoader.getService(DatabaseType.class, "PostgreSQL").getJdbcUrlPrefixes(), is(Arrays.asList("jdbc:postgresql:", "jdbc:tc:postgresql:"))); + assertThat(TypedSPILoader.getService(DatabaseType.class, "PostgreSQL").getJdbcUrlPrefixes(), is(Collections.singletonList("jdbc:postgresql:"))); } } diff --git a/infra/database/type/sqlserver/src/main/java/org/apache/shardingsphere/infra/database/sqlserver/type/SQLServerDatabaseType.java b/infra/database/type/sqlserver/src/main/java/org/apache/shardingsphere/infra/database/sqlserver/type/SQLServerDatabaseType.java index e1725acb12bfe..69e7e4763d0e4 100644 --- a/infra/database/type/sqlserver/src/main/java/org/apache/shardingsphere/infra/database/sqlserver/type/SQLServerDatabaseType.java +++ b/infra/database/type/sqlserver/src/main/java/org/apache/shardingsphere/infra/database/sqlserver/type/SQLServerDatabaseType.java @@ -23,13 +23,13 @@ import java.util.Collection; /** - * Database type of SQLServer. Includes verification of Docker Images involved in commonly used testcontainers. + * Database type of SQLServer. */ public final class SQLServerDatabaseType implements DatabaseType { @Override public Collection getJdbcUrlPrefixes() { - return Arrays.asList("jdbc:microsoft:sqlserver:", "jdbc:sqlserver:", "jdbc:tc:mcr.microsoft.com/mssql/server:"); + return Arrays.asList("jdbc:microsoft:sqlserver:", "jdbc:sqlserver:"); } @Override diff --git a/infra/database/type/sqlserver/src/test/java/org/apache/shardingsphere/infra/database/sqlserver/type/SQLServerDatabaseTypeTest.java b/infra/database/type/sqlserver/src/test/java/org/apache/shardingsphere/infra/database/sqlserver/type/SQLServerDatabaseTypeTest.java index 33e75ae4bea45..9edf61a616137 100644 --- a/infra/database/type/sqlserver/src/test/java/org/apache/shardingsphere/infra/database/sqlserver/type/SQLServerDatabaseTypeTest.java +++ b/infra/database/type/sqlserver/src/test/java/org/apache/shardingsphere/infra/database/sqlserver/type/SQLServerDatabaseTypeTest.java @@ -31,6 +31,6 @@ class SQLServerDatabaseTypeTest { @Test void assertGetJdbcUrlPrefixes() { assertThat(TypedSPILoader.getService(DatabaseType.class, "SQLServer").getJdbcUrlPrefixes(), - is(Arrays.asList("jdbc:microsoft:sqlserver:", "jdbc:sqlserver:", "jdbc:tc:mcr.microsoft.com/mssql/server:"))); + is(Arrays.asList("jdbc:microsoft:sqlserver:", "jdbc:sqlserver:"))); } } diff --git a/infra/database/type/testcontainers/pom.xml b/infra/database/type/testcontainers/pom.xml new file mode 100644 index 0000000000000..1a2af7427f007 --- /dev/null +++ b/infra/database/type/testcontainers/pom.xml @@ -0,0 +1,43 @@ + + + + + 4.0.0 + + org.apache.shardingsphere + shardingsphere-infra-database-type + 5.4.2-SNAPSHOT + + shardingsphere-infra-database-testcontainers + ${project.artifactId} + + + + org.apache.shardingsphere + shardingsphere-infra-database-core + ${project.version} + + + + org.apache.shardingsphere + shardingsphere-test-util + ${project.version} + test + + + diff --git a/infra/database/type/testcontainers/src/main/java/org/apache/shardingsphere/infra/database/testcontainers/type/AbstractTestcontainersDatabaseType.java b/infra/database/type/testcontainers/src/main/java/org/apache/shardingsphere/infra/database/testcontainers/type/AbstractTestcontainersDatabaseType.java new file mode 100644 index 0000000000000..328f3cbf91113 --- /dev/null +++ b/infra/database/type/testcontainers/src/main/java/org/apache/shardingsphere/infra/database/testcontainers/type/AbstractTestcontainersDatabaseType.java @@ -0,0 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 + * + * http://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.apache.shardingsphere.infra.database.testcontainers.type; + +import org.apache.shardingsphere.infra.database.core.type.DatabaseType; + +/** + * Abstract Database type in testcontainers-java. + * All jdbcUrl prefixes supported by testcontainers-java should extend this class. + */ +public abstract class AbstractTestcontainersDatabaseType implements DatabaseType { +} diff --git a/infra/database/type/testcontainers/src/main/java/org/apache/shardingsphere/infra/database/testcontainers/type/TcClickHouseDatabaseType.java b/infra/database/type/testcontainers/src/main/java/org/apache/shardingsphere/infra/database/testcontainers/type/TcClickHouseDatabaseType.java new file mode 100644 index 0000000000000..77f6ab97d6c2c --- /dev/null +++ b/infra/database/type/testcontainers/src/main/java/org/apache/shardingsphere/infra/database/testcontainers/type/TcClickHouseDatabaseType.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 + * + * http://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.apache.shardingsphere.infra.database.testcontainers.type; + +import org.apache.shardingsphere.infra.database.core.type.DatabaseType; +import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; + +import java.util.Collection; +import java.util.Collections; +import java.util.Optional; + +/** + * Database type of ClickHouse in testcontainers-java. + */ +public final class TcClickHouseDatabaseType extends AbstractTestcontainersDatabaseType { + + @Override + public Collection getJdbcUrlPrefixes() { + return Collections.singletonList("jdbc:tc:clickhouse:"); + } + + @Override + public Optional getTrunkDatabaseType() { + return Optional.of(TypedSPILoader.getService(DatabaseType.class, "ClickHouse")); + } + + @Override + public String getType() { + return "TestContainersClickHouse"; + } +} diff --git a/infra/database/type/testcontainers/src/main/java/org/apache/shardingsphere/infra/database/testcontainers/type/TcMariaDBDatabaseType.java b/infra/database/type/testcontainers/src/main/java/org/apache/shardingsphere/infra/database/testcontainers/type/TcMariaDBDatabaseType.java new file mode 100644 index 0000000000000..36bf2f124b37d --- /dev/null +++ b/infra/database/type/testcontainers/src/main/java/org/apache/shardingsphere/infra/database/testcontainers/type/TcMariaDBDatabaseType.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 + * + * http://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.apache.shardingsphere.infra.database.testcontainers.type; + +import org.apache.shardingsphere.infra.database.core.type.DatabaseType; +import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; + +import java.util.Collection; +import java.util.Collections; +import java.util.Optional; + +/** + * Database type of MariaDB in testcontainers-java. + */ +public final class TcMariaDBDatabaseType extends AbstractTestcontainersDatabaseType { + + @Override + public Collection getJdbcUrlPrefixes() { + return Collections.singletonList("jdbc:tc:mariadb:"); + } + + @Override + public Optional getTrunkDatabaseType() { + return Optional.of(TypedSPILoader.getService(DatabaseType.class, "MariaDB")); + } + + @Override + public String getType() { + return "TestContainersMariaDB"; + } +} diff --git a/infra/database/type/testcontainers/src/main/java/org/apache/shardingsphere/infra/database/testcontainers/type/TcMySQLDatabaseType.java b/infra/database/type/testcontainers/src/main/java/org/apache/shardingsphere/infra/database/testcontainers/type/TcMySQLDatabaseType.java new file mode 100644 index 0000000000000..c19545a69ea27 --- /dev/null +++ b/infra/database/type/testcontainers/src/main/java/org/apache/shardingsphere/infra/database/testcontainers/type/TcMySQLDatabaseType.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 + * + * http://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.apache.shardingsphere.infra.database.testcontainers.type; + +import org.apache.shardingsphere.infra.database.core.type.DatabaseType; +import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; + +import java.util.Collection; +import java.util.Collections; +import java.util.Optional; + +/** + * Database type of MySQL in testcontainers-java. + */ +public final class TcMySQLDatabaseType extends AbstractTestcontainersDatabaseType { + + @Override + public Collection getJdbcUrlPrefixes() { + return Collections.singletonList("jdbc:tc:mysql:"); + } + + @Override + public Optional getTrunkDatabaseType() { + return Optional.of(TypedSPILoader.getService(DatabaseType.class, "MySQL")); + } + + @Override + public String getType() { + return "TestContainersMySQL"; + } +} diff --git a/infra/database/type/testcontainers/src/main/java/org/apache/shardingsphere/infra/database/testcontainers/type/TcOracleDatabaseType.java b/infra/database/type/testcontainers/src/main/java/org/apache/shardingsphere/infra/database/testcontainers/type/TcOracleDatabaseType.java new file mode 100644 index 0000000000000..d5169f1d88521 --- /dev/null +++ b/infra/database/type/testcontainers/src/main/java/org/apache/shardingsphere/infra/database/testcontainers/type/TcOracleDatabaseType.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 + * + * http://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.apache.shardingsphere.infra.database.testcontainers.type; + +import org.apache.shardingsphere.infra.database.core.type.DatabaseType; +import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; + +import java.util.Collection; +import java.util.Collections; +import java.util.Optional; + +/** + * Database type of Oracle in testcontainers-java. + */ +public final class TcOracleDatabaseType extends AbstractTestcontainersDatabaseType { + + @Override + public Collection getJdbcUrlPrefixes() { + return Collections.singletonList("jdbc:tc:oracle:"); + } + + @Override + public Optional getTrunkDatabaseType() { + return Optional.of(TypedSPILoader.getService(DatabaseType.class, "Oracle")); + } + + @Override + public String getType() { + return "TestContainersOracle"; + } +} diff --git a/infra/database/type/testcontainers/src/main/java/org/apache/shardingsphere/infra/database/testcontainers/type/TcPostgreSQLDatabaseType.java b/infra/database/type/testcontainers/src/main/java/org/apache/shardingsphere/infra/database/testcontainers/type/TcPostgreSQLDatabaseType.java new file mode 100644 index 0000000000000..d9136e6fb0678 --- /dev/null +++ b/infra/database/type/testcontainers/src/main/java/org/apache/shardingsphere/infra/database/testcontainers/type/TcPostgreSQLDatabaseType.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 + * + * http://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.apache.shardingsphere.infra.database.testcontainers.type; + +import org.apache.shardingsphere.infra.database.core.type.DatabaseType; +import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; + +import java.util.Collection; +import java.util.Collections; +import java.util.Optional; + +/** + * Database type of PostgreSQL in testcontainers-java. + */ +public final class TcPostgreSQLDatabaseType extends AbstractTestcontainersDatabaseType { + + @Override + public Collection getJdbcUrlPrefixes() { + return Collections.singletonList("jdbc:tc:postgresql:"); + } + + @Override + public Optional getTrunkDatabaseType() { + return Optional.of(TypedSPILoader.getService(DatabaseType.class, "PostgreSQL")); + } + + @Override + public String getType() { + return "TestContainersPostgreSQL"; + } +} diff --git a/infra/database/type/testcontainers/src/main/java/org/apache/shardingsphere/infra/database/testcontainers/type/TcSQLServerDatabaseType.java b/infra/database/type/testcontainers/src/main/java/org/apache/shardingsphere/infra/database/testcontainers/type/TcSQLServerDatabaseType.java new file mode 100644 index 0000000000000..92049f5b30e90 --- /dev/null +++ b/infra/database/type/testcontainers/src/main/java/org/apache/shardingsphere/infra/database/testcontainers/type/TcSQLServerDatabaseType.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 + * + * http://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.apache.shardingsphere.infra.database.testcontainers.type; + +import org.apache.shardingsphere.infra.database.core.type.DatabaseType; +import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; + +import java.util.Collection; +import java.util.Collections; +import java.util.Optional; + +/** + * Database type of MSSQL Server in testcontainers-java. + */ +public final class TcSQLServerDatabaseType extends AbstractTestcontainersDatabaseType { + + @Override + public Collection getJdbcUrlPrefixes() { + return Collections.singletonList("jdbc:tc:sqlserver:"); + } + + @Override + public Optional getTrunkDatabaseType() { + return Optional.of(TypedSPILoader.getService(DatabaseType.class, "SQLServer")); + } + + @Override + public String getType() { + return "TestContainersSQLServer"; + } +} diff --git a/infra/database/type/testcontainers/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.database.core.type.DatabaseType b/infra/database/type/testcontainers/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.database.core.type.DatabaseType new file mode 100644 index 0000000000000..081085fcf0d93 --- /dev/null +++ b/infra/database/type/testcontainers/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.database.core.type.DatabaseType @@ -0,0 +1,23 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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 +# +# http://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. +# + +org.apache.shardingsphere.infra.database.testcontainers.type.TcClickHouseDatabaseType +org.apache.shardingsphere.infra.database.testcontainers.type.TcMariaDBDatabaseType +org.apache.shardingsphere.infra.database.testcontainers.type.TcMySQLDatabaseType +org.apache.shardingsphere.infra.database.testcontainers.type.TcOracleDatabaseType +org.apache.shardingsphere.infra.database.testcontainers.type.TcPostgreSQLDatabaseType +org.apache.shardingsphere.infra.database.testcontainers.type.TcSQLServerDatabaseType diff --git a/infra/database/type/testcontainers/src/test/java/org/apache/shardingsphere/infra/database/testcontainers/type/TestcontainersDatabaseTypeTest.java b/infra/database/type/testcontainers/src/test/java/org/apache/shardingsphere/infra/database/testcontainers/type/TestcontainersDatabaseTypeTest.java new file mode 100644 index 0000000000000..91dcaac330775 --- /dev/null +++ b/infra/database/type/testcontainers/src/test/java/org/apache/shardingsphere/infra/database/testcontainers/type/TestcontainersDatabaseTypeTest.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 + * + * http://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.apache.shardingsphere.infra.database.testcontainers.type; + +import org.apache.shardingsphere.infra.database.core.type.DatabaseType; +import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; +import org.junit.jupiter.api.Test; + +import java.util.Collections; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + +class TestcontainersDatabaseTypeTest { + + @Test + void assertGetJdbcUrlPrefixes() { + assertThat(TypedSPILoader.getService(DatabaseType.class, "TestContainersClickHouse").getJdbcUrlPrefixes(), is(Collections.singletonList("jdbc:tc:clickhouse:"))); + assertThat(TypedSPILoader.getService(DatabaseType.class, "TestContainersMariaDB").getJdbcUrlPrefixes(), is(Collections.singletonList("jdbc:tc:mariadb:"))); + assertThat(TypedSPILoader.getService(DatabaseType.class, "TestContainersMySQL").getJdbcUrlPrefixes(), is(Collections.singletonList("jdbc:tc:mysql:"))); + assertThat(TypedSPILoader.getService(DatabaseType.class, "TestContainersOracle").getJdbcUrlPrefixes(), is(Collections.singletonList("jdbc:tc:oracle:"))); + assertThat(TypedSPILoader.getService(DatabaseType.class, "TestContainersPostgreSQL").getJdbcUrlPrefixes(), is(Collections.singletonList("jdbc:tc:postgresql:"))); + assertThat(TypedSPILoader.getService(DatabaseType.class, "TestContainersSQLServer").getJdbcUrlPrefixes(), is(Collections.singletonList("jdbc:tc:sqlserver:"))); + } +} diff --git a/test/native/pom.xml b/test/native/pom.xml index fa00a4ee96614..c5f1e8d494807 100644 --- a/test/native/pom.xml +++ b/test/native/pom.xml @@ -33,6 +33,12 @@ ${project.version} test + + org.apache.shardingsphere + shardingsphere-infra-database-testcontainers + ${project.version} + test + org.hamcrest