Skip to content

Commit

Permalink
Add GraalVM Reachability Metadata and corresponding nativeTest for Op…
Browse files Browse the repository at this point in the history
…enGauss integration
  • Loading branch information
linghengqian committed Dec 13, 2023
1 parent 4fe1fcb commit f875e9c
Show file tree
Hide file tree
Showing 10 changed files with 309 additions and 135 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ ShardingSphere 定义了 `nativeTestInShardingSphere` 的 Maven Profile 用于
假设贡献者处于新的 Ubuntu 22.04.3 LTS 实例下,其可通过如下 bash 命令通过 SDKMAN! 管理 JDK 和工具链,
并为 `shardingsphere-test-native` 子模块执行 nativeTest。

你必须安装 Docker Engine 或 PodMan 等 container tools 以执行 `testcontainers-java` 相关的单元测试。
你必须安装 Docker Engine 以执行 `testcontainers-java` 相关的单元测试。

```bash
sudo apt install unzip zip curl sed -y
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ ShardingSphere defines the Maven Profile of `nativeTestInShardingSphere` for exe
Assuming that the contributor is under a new Ubuntu 22.04.3 LTS instance, Contributors can manage the JDK and tool chain through
`SDKMAN!` through the following bash command, and execute nativeTest for the `shardingsphere-test-native` submodule.

You must install container tools such as Docker Engine or PodMan to execute `testcontainers-java` related unit tests.
You must install Docker Engine to execute `testcontainers-java` related unit tests.

```bash
sudo apt install unzip zip curl sed -y
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
{
"resources":{
"includes":[{
"condition":{"typeReachable":"org.apache.shardingsphere.infra.metadata.database.schema.builder.SystemSchemaBuilderRule"},
"pattern":".*schema/.+\\.yaml$"
}, {
"condition":{"typeReachable":"org.apache.shardingsphere.mode.repository.standalone.jdbc.sql.JDBCRepositorySQLLoader"},
"pattern":".*sql/.+\\.xml$"
}, {
"condition":{"typeReachable":"org.apache.shardingsphere.driver.ShardingSphereDriver"},
"pattern":"\\QMETA-INF/services/java.sql.Driver\\E"
}, {
Expand Down Expand Up @@ -126,12 +132,6 @@
}, {
"condition":{"typeReachable":"org.apache.shardingsphere.mode.repository.standalone.jdbc.sql.JDBCRepositorySQLLoader"},
"pattern":"\\Qsql\\E"
}, {
"condition":{"typeReachable":"org.apache.shardingsphere.mode.repository.standalone.jdbc.sql.JDBCRepositorySQLLoader"},
"pattern":".*sql/.+\\.xml$"
}, {
"condition":{"typeReachable":"org.apache.shardingsphere.infra.metadata.database.schema.builder.SystemSchemaBuilderRule"},
"pattern":".*schema/.+\\.yaml$"
}]},
"bundles":[]
}
6 changes: 4 additions & 2 deletions test/native/native-image-filter/extra-filter.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,23 @@
{"excludeClasses": "sun.misc.**"},
{"excludeClasses": "sun.security.**"},

{"excludeClasses": "com.fasterxml.jackson.databind.**"},
{"excludeClasses": "com.github.benmanes.caffeine.cache.**"},
{"excludeClasses": "com.github.dockerjava.api.**"},
{"excludeClasses": "com.google.common.util.concurrent.**"},
{"excludeClasses": "com.ibm.icu.text.**"},
{"excludeClasses": "com.mysql.cj.**"},
{"excludeClasses": "com.sun.xml.bind.v2.**"},
{"excludeClasses": "com.zaxxer.hikari.**"},
{"excludeClasses": "javax.xml.bind.annotation.**"},
{"excludeClasses": "groovy.**"},
{"excludeClasses": "org.apache.calcite.**"},
{"excludeClasses": "org.codehaus.groovy.**"},
{"excludeClasses": "org.h2.**"},
{"excludeClasses": "org.locationtech.jts.geom.**"},
{"excludeClasses": "org.opengauss.**"},
{"excludeClasses": "org.postgresql.**"},
{"excludeClasses": "org.slf4j.event.**"},
{"excludeClasses": "org.testcontainers.jdbc.**"},
{"excludeClasses": "org.testcontainers.**"},

{"excludeClasses": "org.apache.shardingsphere.test.natived.**"}
],
Expand Down
5 changes: 5 additions & 0 deletions test/native/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@
<artifactId>postgresql</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.opengauss</groupId>
<artifactId>opengauss-jdbc</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>postgresql</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import org.apache.shardingsphere.test.natived.jdbc.commons.AbstractShardingCommonTest;
import org.apache.shardingsphere.test.natived.jdbc.commons.FileTestUtils;
import org.awaitility.Awaitility;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledInNativeImage;

Expand All @@ -50,6 +48,27 @@ public class MySQLTest {

private AbstractShardingCommonTest abstractShardingCommonTest;

@Test
@EnabledInNativeImage
void assertShardingInLocalTransactions() throws SQLException, IOException {
beforeAll();
DataSource dataSource = YamlShardingSphereDataSourceFactory.createDataSource(FileTestUtils.readFromFileURLString("test-native/yaml/databases/mysql.yaml"));
abstractShardingCommonTest = new AbstractShardingCommonTest(dataSource);
this.initEnvironment();
abstractShardingCommonTest.processSuccess();
abstractShardingCommonTest.cleanEnvironment();
tearDown();
}

private void initEnvironment() throws SQLException {
abstractShardingCommonTest.getOrderRepository().createTableIfNotExistsInMySQL();
abstractShardingCommonTest.getOrderItemRepository().createTableIfNotExistsInMySQL();
abstractShardingCommonTest.getAddressRepository().createTableIfNotExists();
abstractShardingCommonTest.getOrderRepository().truncateTable();
abstractShardingCommonTest.getOrderItemRepository().truncateTable();
abstractShardingCommonTest.getAddressRepository().truncateTable();
}

private static Connection openConnection() throws SQLException {
Properties props = new Properties();
props.setProperty("user", USERNAME);
Expand All @@ -58,8 +77,7 @@ private static Connection openConnection() throws SQLException {
}

@SuppressWarnings({"SqlDialectInspection", "SqlNoDataSourceInspection"})
@BeforeAll
static void beforeAll() throws IOException {
private static void beforeAll() throws IOException {
System.out.println("Starting MySQL ...");
process = new ProcessBuilder(
"docker", "run", "--rm", "-p", "65107:3306", "-e", "MYSQL_DATABASE=" + DATABASE,
Expand All @@ -82,30 +100,10 @@ static void beforeAll() throws IOException {
System.out.println("MySQL started");
}

@AfterAll
static void tearDown() {
private static void tearDown() {
if (null != process && process.isAlive()) {
System.out.println("Shutting down MySQL");
process.destroy();
}
}

@Test
@EnabledInNativeImage
void assertShardingInLocalTransactions() throws SQLException, IOException {
DataSource dataSource = YamlShardingSphereDataSourceFactory.createDataSource(FileTestUtils.readFromFileURLString("test-native/yaml/databases/mysql.yaml"));
abstractShardingCommonTest = new AbstractShardingCommonTest(dataSource);
this.initEnvironment();
abstractShardingCommonTest.processSuccess();
abstractShardingCommonTest.cleanEnvironment();
}

private void initEnvironment() throws SQLException {
abstractShardingCommonTest.getOrderRepository().createTableIfNotExistsInMySQL();
abstractShardingCommonTest.getOrderItemRepository().createTableIfNotExistsInMySQL();
abstractShardingCommonTest.getAddressRepository().createTableIfNotExists();
abstractShardingCommonTest.getOrderRepository().truncateTable();
abstractShardingCommonTest.getOrderItemRepository().truncateTable();
abstractShardingCommonTest.getAddressRepository().truncateTable();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
* 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.jdbc.databases;

import org.apache.shardingsphere.driver.api.yaml.YamlShardingSphereDataSourceFactory;
import org.apache.shardingsphere.test.natived.jdbc.commons.AbstractShardingCommonTest;
import org.apache.shardingsphere.test.natived.jdbc.commons.FileTestUtils;
import org.awaitility.Awaitility;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledInNativeImage;

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

public class OpenGaussTest {

private static final String USERNAME = "gaussdb";

private static final String PASSWORD = "openGauss@123";

private static final String DATABASE = "postgres";

private static final String JDBC_URL = "jdbc:opengauss://localhost:62390/" + DATABASE;

private static Process process;

private AbstractShardingCommonTest abstractShardingCommonTest;

@Test
@EnabledInNativeImage
void assertShardingInLocalTransactions() throws SQLException, IOException {
beforeAll();
DataSource dataSource = YamlShardingSphereDataSourceFactory.createDataSource(FileTestUtils.readFromFileURLString("test-native/yaml/databases/opengauss.yaml"));
abstractShardingCommonTest = new AbstractShardingCommonTest(dataSource);
this.initEnvironment();
abstractShardingCommonTest.processSuccess();
abstractShardingCommonTest.cleanEnvironment();
tearDown();
}

private void initEnvironment() throws SQLException {
abstractShardingCommonTest.getOrderRepository().createTableIfNotExistsInPostgres();
abstractShardingCommonTest.getOrderItemRepository().createTableIfNotExistsInPostgres();
abstractShardingCommonTest.getAddressRepository().createTableIfNotExists();
abstractShardingCommonTest.getOrderRepository().truncateTable();
abstractShardingCommonTest.getOrderItemRepository().truncateTable();
abstractShardingCommonTest.getAddressRepository().truncateTable();
}

private static Connection openConnection() throws SQLException {
Properties props = new Properties();
props.setProperty("user", USERNAME);
props.setProperty("password", PASSWORD);
return DriverManager.getConnection(JDBC_URL, props);
}

@SuppressWarnings({"SqlDialectInspection", "SqlNoDataSourceInspection"})
private static void beforeAll() throws IOException {
System.out.println("Starting OpenGauss ...");
process = new ProcessBuilder(
"docker", "run", "--rm", "-p", "62390:5432", "-e", "GS_PASSWORD=" + PASSWORD,
"opengauss/opengauss:5.0.0")
.redirectOutput(new File("target/opengauss-stdout.txt"))
.redirectError(new File("target/opengauss-stderr.txt"))
.start();
Awaitility.await().atMost(Duration.ofMinutes(1)).ignoreExceptions().until(() -> {
openConnection().close();
return true;
});
try (Connection connection = openConnection()) {
connection.createStatement().executeUpdate("CREATE DATABASE demo_ds_0;");
connection.createStatement().executeUpdate("CREATE DATABASE demo_ds_1;");
connection.createStatement().executeUpdate("CREATE DATABASE demo_ds_2;");
} catch (SQLException e) {
throw new RuntimeException(e);
}
System.out.println("OpenGauss started");
}

private static void tearDown() {
if (null != process && process.isAlive()) {
System.out.println("Shutting down OpenGauss");
process.destroy();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"includes":[{
"condition":{"typeReachable":"org.apache.shardingsphere.test.natived.jdbc.databases.MySQLTest"},
"pattern":"\\Qtest-native/yaml/databases/mysql.yaml\\E"
}, {
"condition":{"typeReachable":"org.apache.shardingsphere.test.natived.jdbc.databases.OpenGaussTest"},
"pattern":"\\Qtest-native/yaml/databases/opengauss.yaml\\E"
}, {
"condition":{"typeReachable":"org.apache.shardingsphere.test.natived.jdbc.databases.PostgresTest"},
"pattern":"\\Qtest-native/yaml/databases/postgresql.yaml\\E"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#
# 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.
#

mode:
type: Standalone
repository:
type: JDBC

dataSources:
ds_0:
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
driverClassName: org.opengauss.Driver
jdbcUrl: jdbc:opengauss://localhost:62390/demo_ds_0
username: gaussdb
password: openGauss@123
ds_1:
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
driverClassName: org.opengauss.Driver
jdbcUrl: jdbc:opengauss://localhost:62390/demo_ds_1
username: gaussdb
password: openGauss@123
ds_2:
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
driverClassName: org.opengauss.Driver
jdbcUrl: jdbc:opengauss://localhost:62390/demo_ds_2
username: gaussdb
password: openGauss@123

rules:
- !SHARDING
tables:
t_order:
actualDataNodes:
keyGenerateStrategy:
column: order_id
keyGeneratorName: snowflake
t_order_item:
actualDataNodes:
keyGenerateStrategy:
column: order_item_id
keyGeneratorName: snowflake
defaultDatabaseStrategy:
standard:
shardingColumn: user_id
shardingAlgorithmName: inline
shardingAlgorithms:
inline:
type: CLASS_BASED
props:
strategy: STANDARD
algorithmClassName: org.apache.shardingsphere.test.natived.jdbc.commons.algorithm.ClassBasedInlineShardingAlgorithmFixture
keyGenerators:
snowflake:
type: SNOWFLAKE
auditors:
sharding_key_required_auditor:
type: DML_SHARDING_CONDITIONS

- !BROADCAST
tables:
- t_address

props:
sql-show: false

0 comments on commit f875e9c

Please sign in to comment.