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 0f953db2681 Add test coverage for DataSourcesCloser.close() in 
DataSourceGeneratedDatabaseConfiguration (#36913)
0f953db2681 is described below

commit 0f953db2681b05f5e3b90b330d69bb3df316ca5d
Author: Liang Zhang <[email protected]>
AuthorDate: Wed Oct 22 01:02:12 2025 +0800

    Add test coverage for DataSourcesCloser.close() in 
DataSourceGeneratedDatabaseConfiguration (#36913)
    
    * Update CLAUDE.md
    
    * Add test coverage for DataSourcesCloser.close() in 
DataSourceGeneratedDatabaseConfiguration
    
    - Add assertCloseDataSourcesWhenExceptionThrown() test method to cover 
exception handling path
    - Test covers DataSourcesCloser.close(result.values()) line when 
DataSourcePoolCreator.create() fails
    - Include createInvalidDataSourceConfiguration() helper method using 
non-existent DataSource class
    
    🤖 Generated with [Claude Code](https://claude.com/claude-code)
    
    Co-Authored-By: Claude <[email protected]>
    
    ---------
    
    Co-authored-by: Claude <[email protected]>
---
 .../impl/DataSourceGeneratedDatabaseConfigurationTest.java   | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git 
a/infra/common/src/test/java/org/apache/shardingsphere/infra/config/database/impl/DataSourceGeneratedDatabaseConfigurationTest.java
 
b/infra/common/src/test/java/org/apache/shardingsphere/infra/config/database/impl/DataSourceGeneratedDatabaseConfigurationTest.java
index bc01121791c..a9205e0451a 100644
--- 
a/infra/common/src/test/java/org/apache/shardingsphere/infra/config/database/impl/DataSourceGeneratedDatabaseConfigurationTest.java
+++ 
b/infra/common/src/test/java/org/apache/shardingsphere/infra/config/database/impl/DataSourceGeneratedDatabaseConfigurationTest.java
@@ -35,6 +35,7 @@ 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.assertThrows;
 
 class DataSourceGeneratedDatabaseConfigurationTest {
     
@@ -96,4 +97,15 @@ class DataSourceGeneratedDatabaseConfigurationTest {
         PoolConfiguration poolConfig = new PoolConfiguration(2000L, 1000L, 
1000L, 2, 1, false, new Properties());
         return new DataSourceConfiguration(new 
ConnectionConfiguration(MockedDataSource.class.getName(), 
"jdbc:mock://127.0.0.1/foo_db", "root", ""), poolConfig);
     }
+    
+    @Test
+    void assertCloseDataSourcesWhenExceptionThrown() {
+        Map<String, DataSourceConfiguration> dataSourceConfigs = 
Collections.singletonMap("invalid_ds", createInvalidDataSourceConfiguration());
+        assertThrows(Exception.class, () -> new 
DataSourceGeneratedDatabaseConfiguration(dataSourceConfigs, 
Collections.singleton(new FixtureRuleConfiguration("foo_rule"))));
+    }
+    
+    private DataSourceConfiguration createInvalidDataSourceConfiguration() {
+        PoolConfiguration poolConfig = new PoolConfiguration(2000L, 1000L, 
1000L, 2, 1, false, new Properties());
+        return new DataSourceConfiguration(new 
ConnectionConfiguration("non.existent.DataSourceClass", 
"jdbc:mock://127.0.0.1/invalid_ds", "root", ""), poolConfig);
+    }
 }

Reply via email to