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

zhangliang 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 110a15a6a55 Add more test cases on H2DatabaseInstanceJudgerTest 
(#38369)
110a15a6a55 is described below

commit 110a15a6a55f42a5241105522e789966d428b5f9
Author: Liang Zhang <[email protected]>
AuthorDate: Sat Mar 7 21:17:01 2026 +0800

    Add more test cases on H2DatabaseInstanceJudgerTest (#38369)
---
 .../h2/jdbcurl/H2DatabaseInstanceJudgerTest.java   | 51 +++++++++++-----------
 1 file changed, 25 insertions(+), 26 deletions(-)

diff --git 
a/database/connector/dialect/h2/src/test/java/org/apache/shardingsphere/database/connector/h2/jdbcurl/H2DatabaseInstanceJudgerTest.java
 
b/database/connector/dialect/h2/src/test/java/org/apache/shardingsphere/database/connector/h2/jdbcurl/H2DatabaseInstanceJudgerTest.java
index e12ee0b1d18..42db3202acc 100644
--- 
a/database/connector/dialect/h2/src/test/java/org/apache/shardingsphere/database/connector/h2/jdbcurl/H2DatabaseInstanceJudgerTest.java
+++ 
b/database/connector/dialect/h2/src/test/java/org/apache/shardingsphere/database/connector/h2/jdbcurl/H2DatabaseInstanceJudgerTest.java
@@ -18,50 +18,49 @@
 package org.apache.shardingsphere.database.connector.h2.jdbcurl;
 
 import 
org.apache.shardingsphere.database.connector.core.jdbcurl.judger.DialectDatabaseInstanceJudger;
-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.spi.DatabaseTypedSPILoader;
 import org.apache.shardingsphere.database.connector.core.type.DatabaseType;
 import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
-import org.junit.jupiter.api.extension.ExtensionContext;
 import org.junit.jupiter.params.ParameterizedTest;
 import org.junit.jupiter.params.provider.Arguments;
-import org.junit.jupiter.params.provider.ArgumentsProvider;
-import org.junit.jupiter.params.provider.ArgumentsSource;
-import org.junit.jupiter.params.support.ParameterDeclarations;
+import org.junit.jupiter.params.provider.MethodSource;
 
 import java.util.stream.Stream;
 
-import static org.hamcrest.Matchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
 
 class H2DatabaseInstanceJudgerTest {
     
-    private final DialectDatabaseInstanceJudger judger = 
DatabaseTypedSPILoader.getService(DialectDatabaseInstanceJudger.class, 
TypedSPILoader.getService(DatabaseType.class, "H2"));
+    private final DatabaseType databaseType = 
TypedSPILoader.getService(DatabaseType.class, "H2");
+    
+    private final DialectDatabaseInstanceJudger judger = 
DatabaseTypedSPILoader.getService(DialectDatabaseInstanceJudger.class, 
databaseType);
     
-    private final ConnectionPropertiesParser parser = new 
H2ConnectionPropertiesParser();
+    private final ConnectionPropertiesParser parser = 
DatabaseTypedSPILoader.getService(ConnectionPropertiesParser.class, 
databaseType);
     
     @ParameterizedTest(name = "{0}")
-    
@ArgumentsSource(H2DatabaseInstanceJudgerTest.IsInSameDatabaseInstanceTestCaseArgumentsProvider.class)
+    @MethodSource("isInSameDatabaseInstanceArguments")
     void assertIsInSameDatabaseInstance(final String name, final String url1, 
final String url2, final boolean isSame) {
-        ConnectionProperties actual1 = parser.parse(url1, null, null);
-        ConnectionProperties actual2 = parser.parse(url2, null, null);
-        assertThat(judger.isInSameDatabaseInstance(actual1, actual2), 
is(isSame));
+        assertThat(judger.isInSameDatabaseInstance(parser.parse(url1, null, 
null), parser.parse(url2, null, null)), is(isSame));
     }
     
-    private static final class 
IsInSameDatabaseInstanceTestCaseArgumentsProvider implements ArgumentsProvider {
-        
-        @Override
-        public Stream<? extends Arguments> provideArguments(final 
ParameterDeclarations parameters, final ExtensionContext context) {
-            return Stream.of(
-                    Arguments.of("mem", 
"jdbc:h2:mem:ds_0;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL", 
"jdbc:h2:mem:ds_1;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL", true),
-                    Arguments.of("symbol", 
"jdbc:h2:~:ds-0;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL", 
"jdbc:h2:~:ds-1;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL", true),
-                    Arguments.of("memAndSymbol", 
"jdbc:h2:mem:ds_0;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL", 
"jdbc:h2:~:ds-1;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL", true),
-                    Arguments.of("tcp", 
"jdbc:h2:tcp://localhost:8082/~/test1/test2;DB_CLOSE_DELAY=-1", 
"jdbc:h2:tcp://localhost:8082/~/test3/test4;DB_CLOSE_DELAY=-1", true),
-                    Arguments.of("tcpNotSame", 
"jdbc:h2:tcp://localhost:8082/~/test1/test2;DB_CLOSE_DELAY=-1", 
"jdbc:h2:tcp://192.168.64.76:8082/~/test3/test4;DB_CLOSE_DELAY=-1", false),
-                    Arguments.of("ssl", "jdbc:h2:ssl:127.0.0.1/home/test-one", 
"jdbc:h2:ssl:127.0.0.1/home/test-two", true),
-                    Arguments.of("sslNotSame", 
"jdbc:h2:ssl:127.0.0.1/home/test-one", "jdbc:h2:ssl:127.0.0.2/home/test-two", 
false),
-                    Arguments.of("file", 
"jdbc:h2:file:/data/ds-0;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false", 
"jdbc:h2:file:/data/ds-1;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false", true));
-        }
+    private static Stream<Arguments> isInSameDatabaseInstanceArguments() {
+        return Stream.of(
+                Arguments.of("memWithMem", "jdbc:h2:mem:ds_0", 
"jdbc:h2:mem:ds_1", true),
+                Arguments.of("memWithPwd", "jdbc:h2:mem:ds_0", 
"jdbc:h2:~:ds-1", true),
+                Arguments.of("memWithFile", "jdbc:h2:mem:ds_0", 
"jdbc:h2:file:/data/ds-1", true),
+                Arguments.of("memWithTcp", "jdbc:h2:mem:ds_0", 
"jdbc:h2:tcp://localhost:8082/~/test2/test3", false),
+                Arguments.of("pwdWithPwd", "jdbc:h2:~:ds-0", "jdbc:h2:~:ds-1", 
true),
+                Arguments.of("pwdWithMem", "jdbc:h2:~:ds-0", 
"jdbc:h2:mem:ds_1", true),
+                Arguments.of("pwdWithFile", "jdbc:h2:~:ds-0", 
"jdbc:h2:file:/data/ds-1", true),
+                Arguments.of("pwdWithTcp", "jdbc:h2:~:ds-0", 
"jdbc:h2:tcp://localhost:8082/~/test2/test3", false),
+                Arguments.of("fileWithFile", "jdbc:h2:file:/data/ds-0", 
"jdbc:h2:file:/data/ds-1", true),
+                Arguments.of("fileWithMem", "jdbc:h2:file:/data/ds-0", 
"jdbc:h2:mem:ds_1", true),
+                Arguments.of("fileWithPwd", "jdbc:h2:file:/data/ds-0", 
"jdbc:h2:~:ds-1", true),
+                Arguments.of("fileWithTcp", "jdbc:h2:file:/data/ds-0", 
"jdbc:h2:tcp://localhost:8082/~/test2/test3", false),
+                Arguments.of("tcpWithTcp", 
"jdbc:h2:tcp://localhost:8082/~/test1/test2", 
"jdbc:h2:tcp://localhost:8082/~/test3/test4", true),
+                Arguments.of("tcpWithTcpDifferentHost", 
"jdbc:h2:tcp://localhost:8082/~/test1/test2", 
"jdbc:h2:tcp://192.168.64.76:8082/~/test3/test4", false),
+                Arguments.of("tcpWithSsl", 
"jdbc:h2:tcp://localhost:8082/~/test1/test2", 
"jdbc:h2:ssl:127.0.0.1/home/test-two", false));
     }
 }

Reply via email to