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 aa7d57ee1e2 Add full coverage for connector registry and dialect 
utilities (#37582)
aa7d57ee1e2 is described below

commit aa7d57ee1e28559c85a6daed8fd724c4b5499b2a
Author: Liang Zhang <[email protected]>
AuthorDate: Tue Dec 30 18:43:07 2025 +0800

    Add full coverage for connector registry and dialect utilities (#37582)
---
 AGENTS.md                                          |   1 +
 .../core/GlobalDataSourceRegistryTest.java         |  31 ++++++
 .../option/schema/DefaultSchemaOptionTest.java     |  76 ++++++++++++++
 .../jdbcurl/H2ConnectionPropertiesParserTest.java  |  62 +++++++++++
 .../hive/jdbcurl/HiveJdbcUrlFetcherTest.java       |  48 +++++++++
 .../database/MariaDBDatabaseMetaDataTest.java      | 114 +++++++++++++++++++++
 6 files changed, 332 insertions(+)

diff --git a/AGENTS.md b/AGENTS.md
index 2188cfe9b70..0a458a62e51 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -34,6 +34,7 @@ This guide is written **for AI coding agents only**. Follow 
it literally; improv
 - **Continuous Verification**: rely on automated tests and integration 
validation.
 - **Test Naming Simplicity**: keep test names concise and scenario-focused 
(avoid “ReturnsXXX”/overly wordy or AI-like phrasing); describe the scenario 
directly.
 - **Coverage Discipline**: follow the dedicated coverage & branch checklist 
before coding when coverage targets are stated.
+- **One public method, one test**: each public production method must be 
covered by exactly one dedicated test method.
 - **Mocking Rule**: default to mocks; see Mocking & SPI Guidance for 
static/constructor mocking and spy avoidance details.
 ## Tool Usage Guide
 
diff --git 
a/database/connector/core/src/test/java/org/apache/shardingsphere/database/connector/core/GlobalDataSourceRegistryTest.java
 
b/database/connector/core/src/test/java/org/apache/shardingsphere/database/connector/core/GlobalDataSourceRegistryTest.java
new file mode 100644
index 00000000000..4f4465eebc5
--- /dev/null
+++ 
b/database/connector/core/src/test/java/org/apache/shardingsphere/database/connector/core/GlobalDataSourceRegistryTest.java
@@ -0,0 +1,31 @@
+/*
+ * 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.database.connector.core;
+
+import org.junit.jupiter.api.Test;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+class GlobalDataSourceRegistryTest {
+    
+    @Test
+    void assertGetInstance() {
+        assertThat(GlobalDataSourceRegistry.getInstance(), 
is(GlobalDataSourceRegistry.getInstance()));
+    }
+}
diff --git 
a/database/connector/core/src/test/java/org/apache/shardingsphere/database/connector/core/metadata/database/metadata/option/schema/DefaultSchemaOptionTest.java
 
b/database/connector/core/src/test/java/org/apache/shardingsphere/database/connector/core/metadata/database/metadata/option/schema/DefaultSchemaOptionTest.java
new file mode 100644
index 00000000000..e3132628b98
--- /dev/null
+++ 
b/database/connector/core/src/test/java/org/apache/shardingsphere/database/connector/core/metadata/database/metadata/option/schema/DefaultSchemaOptionTest.java
@@ -0,0 +1,76 @@
+/*
+ * 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.database.connector.core.metadata.database.metadata.option.schema;
+
+import org.junit.jupiter.api.Test;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.Optional;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+class DefaultSchemaOptionTest {
+    
+    @Test
+    void assertGetSchema() throws SQLException {
+        Connection successConnection = mock(Connection.class);
+        when(successConnection.getSchema()).thenReturn("actual_schema");
+        assertThat(new DefaultSchemaOption(true, 
"foo_schema").getSchema(successConnection), is("actual_schema"));
+    }
+    
+    @Test
+    void assertGetSchemaWithException() throws SQLException {
+        Connection connection = mock(Connection.class);
+        when(connection.getSchema()).thenThrow(SQLException.class);
+        assertNull(new DefaultSchemaOption(false, null).getSchema(connection));
+    }
+    
+    @Test
+    void assertGetDefaultSchemaWithSchemaAvailable() {
+        Optional<String> defaultSchema = new DefaultSchemaOption(true, 
"foo_schema").getDefaultSchema();
+        assertTrue(defaultSchema.isPresent());
+        assertThat(defaultSchema.get(), is("foo_schema"));
+    }
+    
+    @Test
+    void assertGetDefaultSchemaWithSchemaUnavailable() {
+        assertFalse(new DefaultSchemaOption(false, 
null).getDefaultSchema().isPresent());
+    }
+    
+    @Test
+    void assertGetDefaultSystemSchema() {
+        assertFalse(new DefaultSchemaOption(true, 
"foo_schema").getDefaultSystemSchema().isPresent());
+    }
+    
+    @Test
+    void assertIsSchemaAvailable() {
+        assertTrue(new DefaultSchemaOption(true, 
"foo_schema").isSchemaAvailable());
+    }
+    
+    @Test
+    void assertIsSchemaUnavailable() {
+        assertFalse(new DefaultSchemaOption(false, 
"foo_schema").isSchemaAvailable());
+    }
+}
diff --git 
a/database/connector/dialect/h2/src/test/java/org/apache/shardingsphere/database/connector/h2/jdbcurl/H2ConnectionPropertiesParserTest.java
 
b/database/connector/dialect/h2/src/test/java/org/apache/shardingsphere/database/connector/h2/jdbcurl/H2ConnectionPropertiesParserTest.java
new file mode 100644
index 00000000000..64d5f200a19
--- /dev/null
+++ 
b/database/connector/dialect/h2/src/test/java/org/apache/shardingsphere/database/connector/h2/jdbcurl/H2ConnectionPropertiesParserTest.java
@@ -0,0 +1,62 @@
+/*
+ * 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.database.connector.h2.jdbcurl;
+
+import 
org.apache.shardingsphere.database.connector.core.exception.UnrecognizedDatabaseURLException;
+import 
org.apache.shardingsphere.database.connector.core.jdbcurl.parser.ConnectionProperties;
+import 
org.apache.shardingsphere.database.connector.core.jdbcurl.parser.ConnectionPropertiesParser;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+
+import java.util.stream.Stream;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+class H2ConnectionPropertiesParserTest {
+    
+    private final ConnectionPropertiesParser parser = new 
H2ConnectionPropertiesParser();
+    
+    @ParameterizedTest(name = "{index}: {0}")
+    @MethodSource("provideArguments")
+    void assertParse(final String name, final String url, final String 
expectedHost, final int expectedPort, final String expectedCatalog, final 
String expectedModel, final boolean expectException) {
+        if (expectException) {
+            assertThrows(UnrecognizedDatabaseURLException.class, () -> 
parser.parse(url, null, null));
+        } else {
+            assertParseSuccess(url, expectedHost, expectedPort, 
expectedCatalog, expectedModel);
+        }
+    }
+    
+    private void assertParseSuccess(final String url, final String 
expectedHost, final int expectedPort, final String expectedCatalog, final 
String expectedModel) {
+        ConnectionProperties actual = parser.parse(url, null, null);
+        assertThat(actual.getHostname(), is(expectedHost));
+        assertThat(actual.getPort(), is(expectedPort));
+        assertThat(actual.getCatalog(), is(expectedCatalog));
+        assertThat(actual.getQueryProperties().getProperty("model"), 
is(expectedModel));
+    }
+    
+    private static Stream<Arguments> provideArguments() {
+        return Stream.of(
+                Arguments.of("mem", "jdbc:h2:mem:ds_mem;MODE=MySQL", "", -1, 
"ds_mem", "mem", false),
+                Arguments.of("tcp", 
"jdbc:h2:tcp://127.0.0.1:9092/~/demo/name;DB_CLOSE_DELAY=-1", "127.0.0.1", 
9092, "name", "tcp:", false),
+                Arguments.of("file", 
"jdbc:h2:file:/data/demo/db_file;MODE=MySQL", "", -1, "db_file", "file:", 
false),
+                Arguments.of("invalid", "jdbc:invalid:h2", "", -1, "", "", 
true));
+    }
+}
diff --git 
a/database/connector/dialect/hive/src/test/java/org/apache/shardingsphere/database/connector/hive/jdbcurl/HiveJdbcUrlFetcherTest.java
 
b/database/connector/dialect/hive/src/test/java/org/apache/shardingsphere/database/connector/hive/jdbcurl/HiveJdbcUrlFetcherTest.java
new file mode 100644
index 00000000000..1b7dd4c7734
--- /dev/null
+++ 
b/database/connector/dialect/hive/src/test/java/org/apache/shardingsphere/database/connector/hive/jdbcurl/HiveJdbcUrlFetcherTest.java
@@ -0,0 +1,48 @@
+/*
+ * 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.database.connector.hive.jdbcurl;
+
+import org.apache.hive.jdbc.HiveConnection;
+import org.junit.jupiter.api.Test;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+class HiveJdbcUrlFetcherTest {
+    
+    private final HiveJdbcUrlFetcher fetcher = new HiveJdbcUrlFetcher();
+    
+    @Test
+    void assertFetch() throws SQLException {
+        HiveConnection hiveConnection = mock(HiveConnection.class);
+        
when(hiveConnection.getConnectedUrl()).thenReturn("jdbc:hive2://localhost:10000/db");
+        Connection connection = mock(Connection.class);
+        
when(connection.unwrap(HiveConnection.class)).thenReturn(hiveConnection);
+        assertThat(fetcher.fetch(connection), 
is("jdbc:hive2://localhost:10000/db"));
+    }
+    
+    @Test
+    void assertGetConnectionClass() {
+        assertThat(fetcher.getConnectionClass(), is(HiveConnection.class));
+    }
+}
diff --git 
a/database/connector/dialect/mariadb/src/test/java/org/apache/shardingsphere/database/connector/mariadb/metadata/database/MariaDBDatabaseMetaDataTest.java
 
b/database/connector/dialect/mariadb/src/test/java/org/apache/shardingsphere/database/connector/mariadb/metadata/database/MariaDBDatabaseMetaDataTest.java
new file mode 100644
index 00000000000..ed0a8c8a2bd
--- /dev/null
+++ 
b/database/connector/dialect/mariadb/src/test/java/org/apache/shardingsphere/database/connector/mariadb/metadata/database/MariaDBDatabaseMetaDataTest.java
@@ -0,0 +1,114 @@
+/*
+ * 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.database.connector.mariadb.metadata.database;
+
+import 
org.apache.shardingsphere.database.connector.core.metadata.database.enums.NullsOrderType;
+import 
org.apache.shardingsphere.database.connector.core.metadata.database.enums.QuoteCharacter;
+import 
org.apache.shardingsphere.database.connector.core.metadata.database.metadata.DialectDatabaseMetaData;
+import 
org.apache.shardingsphere.database.connector.core.metadata.database.metadata.option.IdentifierPatternType;
+import 
org.apache.shardingsphere.database.connector.core.metadata.database.metadata.option.connection.DialectConnectionOption;
+import 
org.apache.shardingsphere.database.connector.core.metadata.database.metadata.option.join.DialectJoinOption;
+import 
org.apache.shardingsphere.database.connector.core.metadata.database.metadata.option.keygen.DialectGeneratedKeyOption;
+import 
org.apache.shardingsphere.database.connector.core.metadata.database.metadata.option.transaction.DialectTransactionOption;
+import 
org.apache.shardingsphere.database.connector.core.spi.DatabaseTypedSPILoader;
+import org.apache.shardingsphere.database.connector.core.type.DatabaseType;
+import 
org.apache.shardingsphere.database.connector.mysql.metadata.database.option.MySQLDataTypeOption;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
+import org.junit.jupiter.api.Test;
+
+import java.sql.Connection;
+import java.util.Optional;
+
+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.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class MariaDBDatabaseMetaDataTest {
+    
+    private final DatabaseType databaseType = 
TypedSPILoader.getService(DatabaseType.class, "MariaDB");
+    
+    private final DialectDatabaseMetaData metaData = 
DatabaseTypedSPILoader.getService(DialectDatabaseMetaData.class, databaseType);
+    
+    @Test
+    void assertGetQuoteCharacter() {
+        assertThat(metaData.getQuoteCharacter(), 
is(QuoteCharacter.BACK_QUOTE));
+    }
+    
+    @Test
+    void assertGetIdentifierPatternType() {
+        assertThat(metaData.getIdentifierPatternType(), 
is(IdentifierPatternType.KEEP_ORIGIN));
+    }
+    
+    @Test
+    void assertGetDefaultNullsOrderType() {
+        assertThat(metaData.getDefaultNullsOrderType(), 
is(NullsOrderType.LOW));
+    }
+    
+    @Test
+    void assertGetDataTypeOption() {
+        assertThat(metaData.getDataTypeOption(), 
isA(MySQLDataTypeOption.class));
+    }
+    
+    @Test
+    void assertGetColumnOption() {
+        
assertFalse(metaData.getColumnOption().isColumnNameEqualsLabelInColumnProjection());
+    }
+    
+    @Test
+    void assertGetConnectionOption() {
+        DialectConnectionOption actual = metaData.getConnectionOption();
+        assertTrue(actual.isInstanceConnectionAvailable());
+        assertTrue(actual.isSupportThreeTierStorageStructure());
+    }
+    
+    @Test
+    void assertGetTransactionOption() {
+        DialectTransactionOption actual = metaData.getTransactionOption();
+        assertFalse(actual.isSupportGlobalCSN());
+        assertFalse(actual.isDDLNeedImplicitCommit());
+        assertTrue(actual.isSupportAutoCommitInNestedTransaction());
+        assertFalse(actual.isSupportDDLInXATransaction());
+        assertTrue(actual.isSupportMetaDataRefreshInTransaction());
+        assertThat(actual.getDefaultIsolationLevel(), 
is(Connection.TRANSACTION_REPEATABLE_READ));
+        assertFalse(actual.isReturnRollbackStatementWhenCommitFailed());
+        
assertFalse(actual.isAllowCommitAndRollbackOnlyWhenTransactionFailed());
+        assertThat(actual.getXaDriverClassNames().size(), is(1));
+        
assertTrue(actual.getXaDriverClassNames().contains("org.mariadb.jdbc.MariaDbDataSource"));
+    }
+    
+    @Test
+    void assertGetJoinOption() {
+        DialectJoinOption actual = metaData.getJoinOption();
+        assertTrue(actual.isUsingColumnsByProjectionOrder());
+        assertTrue(actual.isRightColumnsByFirstOrder());
+    }
+    
+    @Test
+    void assertGetGeneratedKeyOption() {
+        Optional<DialectGeneratedKeyOption> actual = 
metaData.getGeneratedKeyOption();
+        assertTrue(actual.isPresent());
+        
assertThat(actual.map(DialectGeneratedKeyOption::getColumnName).orElse(""), 
is("GENERATED_KEY"));
+    }
+    
+    @Test
+    void assertGetProtocolVersionOption() {
+        assertThat(metaData.getProtocolVersionOption().getDefaultVersion(), 
is("5.7.22"));
+    }
+}

Reply via email to