Skip to content
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

Add shardingsphere-infra-database-testcontainers optional module to unify JDBC support for testcontainers-java #29397

Merged
merged 1 commit into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 中。
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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 中。
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> getJdbcUrlPrefixes() {
return Arrays.asList(String.format("jdbc:%s:", getType().toLowerCase()), "jdbc:tc:mariadb:");
return Collections.singletonList(String.format("jdbc:%s:", getType().toLowerCase()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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:")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> getJdbcUrlPrefixes() {
return Arrays.asList("jdbc:mysql:", "jdbc:mysqlx:", "jdbc:tc:mysql:");
return Arrays.asList("jdbc:mysql:", "jdbc:mysqlx:");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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:")));
}
}
1 change: 1 addition & 0 deletions infra/database/type/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@
<module>h2</module>
<module>sql92</module>
<module>clickhouse</module>
<module>testcontainers</module>
</modules>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> getJdbcUrlPrefixes() {
return Arrays.asList(String.format("jdbc:%s:", getType().toLowerCase()), "jdbc:tc:postgresql:");
return Collections.singletonList(String.format("jdbc:%s:", getType().toLowerCase()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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:")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:")));
}
}
43 changes: 43 additions & 0 deletions infra/database/type/testcontainers/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-infra-database-type</artifactId>
<version>5.4.2-SNAPSHOT</version>
</parent>
<artifactId>shardingsphere-infra-database-testcontainers</artifactId>
<name>${project.artifactId}</name>

<dependencies>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-infra-database-core</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-test-util</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -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 {
}
Original file line number Diff line number Diff line change
@@ -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<String> getJdbcUrlPrefixes() {
return Collections.singletonList("jdbc:tc:clickhouse:");
}

@Override
public Optional<DatabaseType> getTrunkDatabaseType() {
return Optional.of(TypedSPILoader.getService(DatabaseType.class, "ClickHouse"));
}

@Override
public String getType() {
return "TestContainersClickHouse";
}
}
Original file line number Diff line number Diff line change
@@ -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<String> getJdbcUrlPrefixes() {
return Collections.singletonList("jdbc:tc:mariadb:");
}

@Override
public Optional<DatabaseType> getTrunkDatabaseType() {
return Optional.of(TypedSPILoader.getService(DatabaseType.class, "MariaDB"));
}

@Override
public String getType() {
return "TestContainersMariaDB";
}
}
Loading