This is an automated email from the ASF dual-hosted git repository.

zhonghongsheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new 04596732fa6 Extract ShardingSphereDriver test for PostgreSQL (#37818)
04596732fa6 is described below

commit 04596732fa685812937338f800d71d8c550c588f
Author: Hongsheng Zhong <[email protected]>
AuthorDate: Fri Jan 23 09:51:56 2026 +0800

    Extract ShardingSphereDriver test for PostgreSQL (#37818)
    
    * Extract driver-fixture-h2-mysql.yaml
    
    * Add ShardingSphereDriverPostgreSQLTest
---
 .../resources/config/to-be-replaced-fixture.yaml   |  2 +-
 .../driver/ShardingSphereDriverTest.java           |  9 ++--
 ...r-fixture.yaml => driver-fixture-h2-mysql.yaml} |  6 +--
 .../config/driver/foo-driver-fixture.yaml          | 39 ---------------
 test/it/pipeline/pom.xml                           |  5 ++
 .../driver/ShardingSphereDriverPostgreSQLTest.java | 57 ++++++++++++++++++++++
 .../driver/driver-fixture-h2-postgresql.yaml       |  6 +--
 7 files changed, 74 insertions(+), 50 deletions(-)

diff --git 
a/infra/url/core/src/test/resources/config/to-be-replaced-fixture.yaml 
b/infra/url/core/src/test/resources/config/to-be-replaced-fixture.yaml
index 9668e2350d5..598694332fc 100644
--- a/infra/url/core/src/test/resources/config/to-be-replaced-fixture.yaml
+++ b/infra/url/core/src/test/resources/config/to-be-replaced-fixture.yaml
@@ -15,7 +15,7 @@
 # limitations under the License.
 #
 
-# After `ShardingSphereURLManager.getContent`, this file should be equivalent 
to `foo-driver-fixture.yaml` in the same folder.
+# After `ShardingSphereURLManager.getContent`, this file should be equivalent 
to `driver-fixture-h2-mysql.yaml` in the same folder.
 databaseName: foo_driver_fixture_db
 
 dataSources:
diff --git 
a/jdbc/src/test/java/org/apache/shardingsphere/driver/ShardingSphereDriverTest.java
 
b/jdbc/src/test/java/org/apache/shardingsphere/driver/ShardingSphereDriverTest.java
index 839bcc43754..50b3a1ba2ad 100644
--- 
a/jdbc/src/test/java/org/apache/shardingsphere/driver/ShardingSphereDriverTest.java
+++ 
b/jdbc/src/test/java/org/apache/shardingsphere/driver/ShardingSphereDriverTest.java
@@ -60,11 +60,12 @@ class ShardingSphereDriverTest {
     @Test
     void assertDriverWorks() throws SQLException {
         try (
-                Connection connection = 
DriverManager.getConnection("jdbc:shardingsphere:classpath:config/driver/foo-driver-fixture.yaml");
+                Connection connection = 
DriverManager.getConnection("jdbc:shardingsphere:classpath:config/driver/driver-fixture-h2-mysql.yaml");
                 Statement statement = connection.createStatement()) {
             assertThat(connection, isA(ShardingSphereConnection.class));
             statement.execute("DROP TABLE IF EXISTS t_order");
             statement.execute("CREATE TABLE t_order (order_id INT PRIMARY KEY, 
user_id INT)");
+            statement.execute("CREATE INDEX idx_uid ON t_order (user_id)");
             statement.execute("INSERT INTO t_order (order_id, user_id) VALUES 
(1, 101), (2, 102)");
             try (ResultSet resultSet = statement.executeQuery("SELECT COUNT(1) 
FROM t_order")) {
                 assertTrue(resultSet.next());
@@ -75,7 +76,7 @@ class ShardingSphereDriverTest {
     
     @Test
     void assertHashModSetLongOnIntColumnWorks() throws SQLException {
-        try (Connection connection = 
DriverManager.getConnection("jdbc:shardingsphere:classpath:config/driver/foo-driver-fixture.yaml"))
 {
+        try (Connection connection = 
DriverManager.getConnection("jdbc:shardingsphere:classpath:config/driver/driver-fixture-h2-mysql.yaml"))
 {
             assertThat(connection, isA(ShardingSphereConnection.class));
             try (Statement statement = connection.createStatement()) {
                 statement.execute("DROP TABLE IF EXISTS t_order");
@@ -109,7 +110,7 @@ class ShardingSphereDriverTest {
     @Test
     void assertVarbinaryColumnWorks() throws SQLException {
         try (
-                Connection connection = 
DriverManager.getConnection("jdbc:shardingsphere:classpath:config/driver/foo-driver-fixture.yaml");
+                Connection connection = 
DriverManager.getConnection("jdbc:shardingsphere:classpath:config/driver/driver-fixture-h2-mysql.yaml");
                 Statement statement = connection.createStatement()) {
             assertThat(connection, isA(ShardingSphereConnection.class));
             statement.execute("DROP TABLE IF EXISTS t_order");
@@ -129,7 +130,7 @@ class ShardingSphereDriverTest {
     @Test
     void assertDatabaseNameTransparentWithHintManager() throws SQLException {
         try (
-                Connection connection = 
DriverManager.getConnection("jdbc:shardingsphere:classpath:config/driver/foo-driver-fixture.yaml");
+                Connection connection = 
DriverManager.getConnection("jdbc:shardingsphere:classpath:config/driver/driver-fixture-h2-mysql.yaml");
                 Statement statement = connection.createStatement()) {
             assertThat(connection, isA(ShardingSphereConnection.class));
             statement.execute("DROP TABLE IF EXISTS t_order");
diff --git a/jdbc/src/test/resources/config/driver/foo-driver-fixture.yaml 
b/jdbc/src/test/resources/config/driver/driver-fixture-h2-mysql.yaml
similarity index 87%
copy from jdbc/src/test/resources/config/driver/foo-driver-fixture.yaml
copy to jdbc/src/test/resources/config/driver/driver-fixture-h2-mysql.yaml
index 026cec85155..c8c5a35c297 100644
--- a/jdbc/src/test/resources/config/driver/foo-driver-fixture.yaml
+++ b/jdbc/src/test/resources/config/driver/driver-fixture-h2-mysql.yaml
@@ -15,19 +15,19 @@
 # limitations under the License.
 #
 
-databaseName: foo_driver_fixture_db
+databaseName: driver_fixture_h2_mysql
 
 dataSources:
   ds_0:
     dataSourceClassName: com.zaxxer.hikari.HikariDataSource
     driverClassName: org.h2.Driver
-    jdbcUrl: 
jdbc:h2:mem:foo_ds_0;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL
+    jdbcUrl: 
jdbc:h2:mem:mysql_ds_0;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL
     username: sa
     password:
   ds_1:
     dataSourceClassName: com.zaxxer.hikari.HikariDataSource
     driverClassName: org.h2.Driver
-    jdbcUrl: 
jdbc:h2:mem:foo_ds_1;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL
+    jdbcUrl: 
jdbc:h2:mem:mysql_ds_1;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL
     username: sa
     password:
 
diff --git a/jdbc/src/test/resources/config/driver/foo-driver-fixture.yaml 
b/jdbc/src/test/resources/config/driver/foo-driver-fixture.yaml
index 026cec85155..51c73d240b1 100644
--- a/jdbc/src/test/resources/config/driver/foo-driver-fixture.yaml
+++ b/jdbc/src/test/resources/config/driver/foo-driver-fixture.yaml
@@ -16,42 +16,3 @@
 #
 
 databaseName: foo_driver_fixture_db
-
-dataSources:
-  ds_0:
-    dataSourceClassName: com.zaxxer.hikari.HikariDataSource
-    driverClassName: org.h2.Driver
-    jdbcUrl: 
jdbc:h2:mem:foo_ds_0;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL
-    username: sa
-    password:
-  ds_1:
-    dataSourceClassName: com.zaxxer.hikari.HikariDataSource
-    driverClassName: org.h2.Driver
-    jdbcUrl: 
jdbc:h2:mem:foo_ds_1;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL
-    username: sa
-    password:
-
-rules:
-  - !SHARDING
-    autoTables:
-      t_order:
-        actualDataSources: ds_0,ds_1
-        shardingStrategy:
-          standard:
-            shardingColumn: order_id
-            shardingAlgorithmName: auto_mod
-        keyGenerateStrategy:
-          column: user_id
-          keyGeneratorName: snowflake
-    shardingAlgorithms:
-      auto_mod:
-        type: HASH_MOD
-        props:
-          sharding-count: 2
-    
-    keyGenerators:
-      snowflake:
-        type: SNOWFLAKE
-
-props:
-  sql-show: true
diff --git a/test/it/pipeline/pom.xml b/test/it/pipeline/pom.xml
index f96af0566dc..ce909eb7f38 100644
--- a/test/it/pipeline/pom.xml
+++ b/test/it/pipeline/pom.xml
@@ -57,6 +57,11 @@
             <artifactId>shardingsphere-jdbc</artifactId>
             <version>${project.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.apache.shardingsphere</groupId>
+            <artifactId>shardingsphere-infra-url-classpath</artifactId>
+            <version>${project.version}</version>
+        </dependency>
         <dependency>
             <groupId>org.apache.shardingsphere</groupId>
             
<artifactId>shardingsphere-cluster-mode-repository-zookeeper</artifactId>
diff --git 
a/test/it/pipeline/src/test/java/org/apache/shardingsphere/driver/ShardingSphereDriverPostgreSQLTest.java
 
b/test/it/pipeline/src/test/java/org/apache/shardingsphere/driver/ShardingSphereDriverPostgreSQLTest.java
new file mode 100644
index 00000000000..65367379281
--- /dev/null
+++ 
b/test/it/pipeline/src/test/java/org/apache/shardingsphere/driver/ShardingSphereDriverPostgreSQLTest.java
@@ -0,0 +1,57 @@
+/*
+ * 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.driver;
+
+import 
org.apache.shardingsphere.driver.jdbc.core.connection.ShardingSphereConnection;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.isA;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+// TODO Enable it after H2DatabaseType supports different MODEs (MySQL and 
PostgreSQL)
+@Disabled
+class ShardingSphereDriverPostgreSQLTest {
+    
+    @Test
+    void assertDriverWorks() throws SQLException {
+        try (
+                Connection connection = 
DriverManager.getConnection("jdbc:shardingsphere:classpath:config/driver/driver-fixture-h2-postgresql.yaml");
+                Statement statement = connection.createStatement()) {
+            assertThat(connection, isA(ShardingSphereConnection.class));
+            statement.execute("DROP SCHEMA IF EXISTS test");
+            statement.execute("CREATE SCHEMA test");
+            statement.execute("DROP TABLE IF EXISTS test.t_order");
+            statement.execute("CREATE TABLE test.t_order (order_id INT PRIMARY 
KEY, user_id INT)");
+            statement.execute("CREATE INDEX idx_uid ON test.t_order 
(user_id)");
+            statement.execute("INSERT INTO test.t_order (order_id, user_id) 
VALUES (1, 101), (2, 102)");
+            try (ResultSet resultSet = statement.executeQuery("SELECT COUNT(1) 
AS cnt FROM test.t_order")) {
+                assertTrue(resultSet.next());
+                assertThat(resultSet.getInt(1), is(2));
+            }
+        }
+    }
+}
diff --git a/jdbc/src/test/resources/config/driver/foo-driver-fixture.yaml 
b/test/it/pipeline/src/test/resources/config/driver/driver-fixture-h2-postgresql.yaml
similarity index 87%
copy from jdbc/src/test/resources/config/driver/foo-driver-fixture.yaml
copy to 
test/it/pipeline/src/test/resources/config/driver/driver-fixture-h2-postgresql.yaml
index 026cec85155..680cd124c38 100644
--- a/jdbc/src/test/resources/config/driver/foo-driver-fixture.yaml
+++ 
b/test/it/pipeline/src/test/resources/config/driver/driver-fixture-h2-postgresql.yaml
@@ -15,19 +15,19 @@
 # limitations under the License.
 #
 
-databaseName: foo_driver_fixture_db
+databaseName: driver_fixture_h2_postgresql
 
 dataSources:
   ds_0:
     dataSourceClassName: com.zaxxer.hikari.HikariDataSource
     driverClassName: org.h2.Driver
-    jdbcUrl: 
jdbc:h2:mem:foo_ds_0;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL
+    jdbcUrl: 
jdbc:h2:mem:pg_ds_0;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=PostgreSQL
     username: sa
     password:
   ds_1:
     dataSourceClassName: com.zaxxer.hikari.HikariDataSource
     driverClassName: org.h2.Driver
-    jdbcUrl: 
jdbc:h2:mem:foo_ds_1;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL
+    jdbcUrl: 
jdbc:h2:mem:pg_ds_1;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=PostgreSQL
     username: sa
     password:
 

Reply via email to