Skip to content
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 @@ -43,7 +43,7 @@ ShardingSphere 对 ClickHouse JDBC Driver 的支持位于可选模块中。
```yaml
services:
clickhouse-server:
image: clickhouse/clickhouse-server:25.6.5.41
image: clickhouse/clickhouse-server:25.9.6.117
environment:
CLICKHOUSE_SKIP_USER_SETUP: "1"
ports:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Write a Docker Compose file to start ClickHouse.
```yaml
services:
clickhouse-server:
image: clickhouse/clickhouse-server:25.6.5.41
image: clickhouse/clickhouse-server:25.9.6.117
environment:
CLICKHOUSE_SKIP_USER_SETUP: "1"
ports:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11690,6 +11690,18 @@
},
"glob": "current-git-commit.properties"
},
{
"condition": {
"typeReached": "org.apache.shardingsphere.driver.jdbc.core.statement.StatementManager"
},
"glob": "isc_error_msg.properties"
},
{
"condition": {
"typeReached": "org.apache.shardingsphere.driver.jdbc.core.statement.StatementManager"
},
"glob": "isc_error_sqlstates.properties"
},
{
"condition": {
"typeReached": "org.apache.shardingsphere.transaction.xa.atomikos.manager.AtomikosTransactionManagerProvider"
Expand All @@ -11702,6 +11714,18 @@
},
"glob": "lib/sqlparser/druid.jar"
},
{
"condition": {
"typeReached": "org.apache.shardingsphere.driver.jdbc.core.statement.StatementManager"
},
"glob": "org/firebirdsql/jaybird_error_msg.properties"
},
{
"condition": {
"typeReached": "org.apache.shardingsphere.driver.jdbc.core.statement.StatementManager"
},
"glob": "org/firebirdsql/jaybird_error_sqlstates.properties"
},
{
"condition": {
"typeReached": "org.apache.shardingsphere.transaction.base.seata.at.SeataATShardingSphereTransactionManager"
Expand Down
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
<hamcrest.version>3.0</hamcrest.version>
<mockito.version>4.11.0</mockito.version>
<awaitility.version>4.3.0</awaitility.version>
<firebird-testcontainers-java.version>1.6.0</firebird-testcontainers-java.version>
<commons-csv.version>1.9.0</commons-csv.version>

<graal-sdk.version>24.1.2</graal-sdk.version>
Expand Down
6 changes: 6 additions & 0 deletions test/native/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@
<artifactId>clickhouse</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.firebirdsql</groupId>
<artifactId>firebird-testcontainers-java</artifactId>
<version>${firebird-testcontainers-java.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-test</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -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.test.natived.commons.algorithm.testcontainers.jdbcurl;

import org.apache.shardingsphere.database.connector.core.jdbcurl.parser.ConnectionProperties;
import org.apache.shardingsphere.database.connector.core.jdbcurl.parser.ConnectionPropertiesParser;
import org.apache.shardingsphere.database.connector.core.jdbcurl.parser.StandardJdbcUrlParser;

/**
* Connection properties parser of Firebird.
*/
public final class TcFirebirdConnectionPropertiesParser implements ConnectionPropertiesParser {

private static final int DEFAULT_PORT = 3050;

@Override
public ConnectionProperties parse(final String url, final String username, final String catalog) {
return new StandardJdbcUrlParser().parse(url, DEFAULT_PORT);
}

@Override
public String getDatabaseType() {
return "TC-Firebird";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package org.apache.shardingsphere.test.natived.commons.algorithm.testcontainers;
package org.apache.shardingsphere.test.natived.commons.algorithm.testcontainers.type;

import org.apache.shardingsphere.database.connector.core.type.DatabaseType;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
Expand Down
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.test.natived.commons.algorithm.testcontainers.type;

import org.apache.shardingsphere.database.connector.core.type.DatabaseType;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;

import java.util.Arrays;
import java.util.Collection;
import java.util.Optional;

/**
* Database type of Firebird in testcontainers.
*/
public final class TcFirebirdDatabaseType implements TestcontainersDatabaseType {

@Override
public Collection<String> getJdbcUrlPrefixes() {
return Arrays.asList("jdbc:tc:firebird:", "jdbc:tc:firebirdsql:");
}

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

@Override
public String getType() {
return "TC-Firebird";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package org.apache.shardingsphere.test.natived.commons.algorithm.testcontainers;
package org.apache.shardingsphere.test.natived.commons.algorithm.testcontainers.type;

import org.apache.shardingsphere.database.connector.core.type.DatabaseType;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package org.apache.shardingsphere.test.natived.commons.algorithm.testcontainers;
package org.apache.shardingsphere.test.natived.commons.algorithm.testcontainers.type;

import org.apache.shardingsphere.database.connector.core.type.DatabaseType;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package org.apache.shardingsphere.test.natived.commons.algorithm.testcontainers;
package org.apache.shardingsphere.test.natived.commons.algorithm.testcontainers.type;

import org.apache.shardingsphere.database.connector.core.type.DatabaseType;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,13 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledInNativeImage;
import org.testcontainers.jdbc.ContainerDatabaseDriver;
import org.testcontainers.junit.jupiter.Testcontainers;

import javax.sql.DataSource;
import java.sql.SQLException;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;

@EnabledInNativeImage
@Testcontainers
class ClickHouseTest {

private DataSource logicDataSource;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,71 +21,33 @@
import com.zaxxer.hikari.HikariDataSource;
import org.apache.shardingsphere.test.natived.commons.TestShardingService;
import org.apache.shardingsphere.test.natived.commons.util.ResourceUtils;
import org.awaitility.Awaitility;
import org.firebirdsql.management.FBManager;
import org.firebirdsql.management.PageSizeConstants;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledInNativeImage;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.testcontainers.jdbc.ContainerDatabaseDriver;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.time.Duration;
import java.util.Properties;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;

@EnabledInNativeImage
@Testcontainers
class FirebirdTest {

private final String systemPropKeyPrefix = "fixture.test-native.yaml.database.firebird.";

private final String password = "masterkey";

@SuppressWarnings("resource")
@Container
private final GenericContainer<?> container = new GenericContainer<>("firebirdsql/firebird:5.0.3")
.withEnv("FIREBIRD_ROOT_PASSWORD", password)
.withEnv("FIREBIRD_USER", "alice")
.withEnv("FIREBIRD_PASSWORD", password)
.withEnv("FIREBIRD_DATABASE", "mirror.fdb")
.withEnv("FIREBIRD_DATABASE_DEFAULT_CHARSET", "UTF8")
.withExposedPorts(3050);

private DataSource logicDataSource;

private String jdbcUrlPrefix;

private TestShardingService testShardingService;

@BeforeEach
void beforeEach() {
assertThat(System.getProperty(systemPropKeyPrefix + "ds0.jdbc-url"), is(nullValue()));
assertThat(System.getProperty(systemPropKeyPrefix + "ds1.jdbc-url"), is(nullValue()));
assertThat(System.getProperty(systemPropKeyPrefix + "ds2.jdbc-url"), is(nullValue()));
}

@AfterEach
void afterEach() throws SQLException {
ResourceUtils.closeJdbcDataSource(logicDataSource);
System.clearProperty(systemPropKeyPrefix + "ds0.jdbc-url");
System.clearProperty(systemPropKeyPrefix + "ds1.jdbc-url");
System.clearProperty(systemPropKeyPrefix + "ds2.jdbc-url");
ContainerDatabaseDriver.killContainers();
}

@Test
void assertShardingInLocalTransactions() throws Exception {
jdbcUrlPrefix = "jdbc:firebird://localhost:" + container.getMappedPort(3050) + "//var/lib/firebird/data/";
logicDataSource = createDataSource();
void assertShardingInLocalTransactions() throws SQLException {
HikariConfig config = new HikariConfig();
config.setDriverClassName("org.apache.shardingsphere.driver.ShardingSphereDriver");
config.setJdbcUrl("jdbc:shardingsphere:classpath:test-native/yaml/jdbc/databases/firebird.yaml");
logicDataSource = new HikariDataSource(config);
testShardingService = new TestShardingService(logicDataSource);
initEnvironment();
testShardingService.processSuccess();
Expand All @@ -103,48 +65,4 @@ private void initEnvironment() throws SQLException {
testShardingService.getOrderItemRepository().createTableInFirebird();
testShardingService.getAddressRepository().createTableInFirebird();
}

private Connection openConnection() throws SQLException {
Properties props = new Properties();
props.setProperty("user", "alice");
props.setProperty("password", password);
return DriverManager.getConnection(jdbcUrlPrefix + "mirror.fdb", props);
}

/**
* Due to <a href="https://github.com/FirebirdSQL/jaybird/issues/629">FirebirdSQL/jaybird#629</a>,
* the SQL statement `Create Database` cannot be executed on the Firebird JDBC driver.
* Unit testing requires the use of {@link org.firebirdsql.management.FBManager}.
*
* @return Data Source
* @throws Exception Exception
* @see org.firebirdsql.management.FBManager
*/
@SuppressWarnings({"SqlDialectInspection", "SqlNoDataSourceInspection"})
private DataSource createDataSource() throws Exception {
Awaitility.await().atMost(Duration.ofMinutes(1L)).ignoreExceptions().until(() -> {
openConnection().close();
return true;
});
try (FBManager fbManager = new FBManager()) {
fbManager.setServer("localhost");
fbManager.setUserName("alice");
fbManager.setPassword(password);
fbManager.setFileName("/var/lib/firebird/data/mirror.fdb");
fbManager.setPageSize(PageSizeConstants.SIZE_16K);
fbManager.setDefaultCharacterSet("UTF8");
fbManager.setPort(container.getMappedPort(3050));
fbManager.start();
fbManager.createDatabase("/var/lib/firebird/data/demo_ds_0.fdb", "alice", password);
fbManager.createDatabase("/var/lib/firebird/data/demo_ds_1.fdb", "alice", password);
fbManager.createDatabase("/var/lib/firebird/data/demo_ds_2.fdb", "alice", password);
}
HikariConfig config = new HikariConfig();
config.setDriverClassName("org.apache.shardingsphere.driver.ShardingSphereDriver");
config.setJdbcUrl("jdbc:shardingsphere:classpath:test-native/yaml/jdbc/databases/firebird.yaml?placeholder-type=system_props");
System.setProperty(systemPropKeyPrefix + "ds0.jdbc-url", jdbcUrlPrefix + "demo_ds_0.fdb");
System.setProperty(systemPropKeyPrefix + "ds1.jdbc-url", jdbcUrlPrefix + "demo_ds_1.fdb");
System.setProperty(systemPropKeyPrefix + "ds2.jdbc-url", jdbcUrlPrefix + "demo_ds_2.fdb");
return new HikariDataSource(config);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#
# 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.test.natived.commons.algorithm.testcontainers.jdbcurl.TcFirebirdConnectionPropertiesParser
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# limitations under the License.
#

org.apache.shardingsphere.test.natived.commons.algorithm.testcontainers.TcPostgreSQLDatabaseType
org.apache.shardingsphere.test.natived.commons.algorithm.testcontainers.TcSQLServerDatabaseType
org.apache.shardingsphere.test.natived.commons.algorithm.testcontainers.TcClickhouseDatabaseType
org.apache.shardingsphere.test.natived.commons.algorithm.testcontainers.type.TcPostgreSQLDatabaseType
org.apache.shardingsphere.test.natived.commons.algorithm.testcontainers.type.TcSQLServerDatabaseType
org.apache.shardingsphere.test.natived.commons.algorithm.testcontainers.type.TcClickhouseDatabaseType
org.apache.shardingsphere.test.natived.commons.algorithm.testcontainers.type.TcFirebirdDatabaseType
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ dataSources:
ds_0:
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
driverClassName: org.testcontainers.jdbc.ContainerDatabaseDriver
jdbcUrl: jdbc:tc:clickhouse:25.6.5.41:///demo_ds_0?TC_INITSCRIPT=test-native/sql/clickhouse-init.sql
jdbcUrl: jdbc:tc:clickhouse:25.9.6.117:///demo_ds_0?TC_INITSCRIPT=test-native/sql/clickhouse-init.sql
ds_1:
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
driverClassName: org.testcontainers.jdbc.ContainerDatabaseDriver
jdbcUrl: jdbc:tc:clickhouse:25.6.5.41:///demo_ds_1?TC_INITSCRIPT=test-native/sql/clickhouse-init.sql
jdbcUrl: jdbc:tc:clickhouse:25.9.6.117:///demo_ds_1?TC_INITSCRIPT=test-native/sql/clickhouse-init.sql
ds_2:
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
driverClassName: org.testcontainers.jdbc.ContainerDatabaseDriver
jdbcUrl: jdbc:tc:clickhouse:25.6.5.41:///demo_ds_2?TC_INITSCRIPT=test-native/sql/clickhouse-init.sql
jdbcUrl: jdbc:tc:clickhouse:25.9.6.117:///demo_ds_2?TC_INITSCRIPT=test-native/sql/clickhouse-init.sql

rules:
- !SHARDING
Expand Down
Loading
Loading