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

sunnianjun 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 be9b6fbb084 Remove ResourceMetaData.close (#28600)
be9b6fbb084 is described below

commit be9b6fbb084f87ebe01e2cffb4cc75cd4c905f9a
Author: Liang Zhang <[email protected]>
AuthorDate: Wed Sep 27 17:49:16 2023 +0800

    Remove ResourceMetaData.close (#28600)
---
 .../infra/metadata/ShardingSphereMetaData.java     |  3 +-
 .../database/resource/ResourceMetaData.java        | 12 +------
 .../infra/metadata/ShardingSphereMetaDataTest.java |  7 ++--
 .../resource/ShardingSphereResourceTest.java       | 38 ----------------------
 .../mode/manager/switcher/SwitchingResource.java   |  3 +-
 .../manager/switcher/SwitchingResourceTest.java    | 11 ++++---
 6 files changed, 17 insertions(+), 57 deletions(-)

diff --git 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaData.java
 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaData.java
index 6e96d54075d..648bb580df4 100644
--- 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaData.java
+++ 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaData.java
@@ -21,6 +21,7 @@ import lombok.Getter;
 import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
 import 
org.apache.shardingsphere.infra.config.props.temporary.TemporaryConfigurationProperties;
 import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
+import 
org.apache.shardingsphere.infra.datasource.pool.destroyer.DataSourcePoolDestroyer;
 import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
 import 
org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData;
 import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
@@ -112,6 +113,6 @@ public final class ShardingSphereMetaData {
         
database.getRuleMetaData().findRules(ResourceHeldRule.class).forEach(each -> 
each.closeStaleResource(databaseName));
         
database.getRuleMetaData().findSingleRule(StaticDataSourceContainedRule.class).ifPresent(StaticDataSourceContainedRule::cleanStorageNodeDataSources);
         Optional.ofNullable(database.getResourceMetaData())
-                .ifPresent(optional -> 
optional.getStorageUnitMetaData().getStorageUnits().values().forEach(each -> 
database.getResourceMetaData().close(each.getDataSource())));
+                .ifPresent(optional -> 
optional.getStorageUnitMetaData().getStorageUnits().values().forEach(each -> 
new DataSourcePoolDestroyer(each.getDataSource()).asyncDestroy()));
     }
 }
diff --git 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/ResourceMetaData.java
 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/ResourceMetaData.java
index c92a0f6aa09..2d0fd6f44a5 100644
--- 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/ResourceMetaData.java
+++ 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/ResourceMetaData.java
@@ -20,9 +20,8 @@ package 
org.apache.shardingsphere.infra.metadata.database.resource;
 import lombok.Getter;
 import 
org.apache.shardingsphere.infra.database.core.connector.ConnectionProperties;
 import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
-import 
org.apache.shardingsphere.infra.datasource.pool.destroyer.DataSourcePoolDestroyer;
-import 
org.apache.shardingsphere.infra.datasource.pool.props.domain.DataSourcePoolProperties;
 import 
org.apache.shardingsphere.infra.datasource.pool.props.creator.DataSourcePoolPropertiesCreator;
+import 
org.apache.shardingsphere.infra.datasource.pool.props.domain.DataSourcePoolProperties;
 import 
org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNode;
 import 
org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnit;
 import 
org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnitMetaData;
@@ -112,13 +111,4 @@ public final class ResourceMetaData {
     public Collection<String> getNotExistedDataSources(final 
Collection<String> resourceNames) {
         return resourceNames.stream().filter(each -> 
!storageUnitMetaData.getStorageUnits().containsKey(each)).collect(Collectors.toSet());
     }
-    
-    /**
-     * Close data source.
-     *
-     * @param dataSource data source to be closed
-     */
-    public void close(final DataSource dataSource) {
-        new DataSourcePoolDestroyer(dataSource).asyncDestroy();
-    }
 }
diff --git 
a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaDataTest.java
 
b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaDataTest.java
index 28980753c56..92201836379 100644
--- 
a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaDataTest.java
+++ 
b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaDataTest.java
@@ -27,6 +27,7 @@ import 
org.apache.shardingsphere.infra.rule.identifier.type.ResourceHeldRule;
 import org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource;
 import org.apache.shardingsphere.test.mock.AutoMockExtension;
 import org.apache.shardingsphere.test.mock.StaticMockSettings;
+import org.awaitility.Awaitility;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
 import org.mockito.junit.jupiter.MockitoSettings;
@@ -37,6 +38,7 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Properties;
+import java.util.concurrent.TimeUnit;
 
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
@@ -69,14 +71,15 @@ class ShardingSphereMetaDataTest {
     @Test
     void assertDropDatabase() {
         ResourceMetaData resourceMetaData = mock(ResourceMetaData.class, 
RETURNS_DEEP_STUBS);
-        DataSource dataSource = new MockedDataSource();
+        MockedDataSource dataSource = new MockedDataSource();
         ResourceHeldRule<?> databaseResourceHeldRule = 
mock(ResourceHeldRule.class);
         ResourceHeldRule<?> globalResourceHeldRule = 
mock(ResourceHeldRule.class);
         ShardingSphereMetaData metaData = new ShardingSphereMetaData(new 
HashMap<>(Collections.singletonMap("foo_db", mockDatabase(resourceMetaData, 
dataSource, databaseResourceHeldRule))),
                 mock(ResourceMetaData.class), new 
RuleMetaData(Collections.singleton(globalResourceHeldRule)), new 
ConfigurationProperties(new Properties()));
         metaData.dropDatabase("foo_db");
         assertTrue(metaData.getDatabases().isEmpty());
-        verify(resourceMetaData).close(dataSource);
+        Awaitility.await().pollDelay(10L, 
TimeUnit.MILLISECONDS).until(dataSource::isClosed);
+        assertTrue(dataSource.isClosed());
         verify(databaseResourceHeldRule).closeStaleResource("foo_db");
         verify(globalResourceHeldRule).closeStaleResource("foo_db");
     }
diff --git 
a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/resource/ShardingSphereResourceTest.java
 
b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/resource/ShardingSphereResourceTest.java
deleted file mode 100644
index bd313fe248d..00000000000
--- 
a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/resource/ShardingSphereResourceTest.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * 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.infra.metadata.database.resource;
-
-import org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource;
-import org.awaitility.Awaitility;
-import org.junit.jupiter.api.Test;
-
-import java.util.Collections;
-import java.util.concurrent.TimeUnit;
-
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-class ShardingSphereResourceTest {
-    
-    @Test
-    void assertClose() {
-        MockedDataSource dataSource = new MockedDataSource();
-        new ResourceMetaData("sharding_db", Collections.singletonMap("foo_ds", 
dataSource)).close(dataSource);
-        Awaitility.await().atMost(1L, TimeUnit.MINUTES).pollInterval(10L, 
TimeUnit.MILLISECONDS).until(dataSource::isClosed);
-        assertTrue(dataSource.isClosed());
-    }
-}
diff --git 
a/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/switcher/SwitchingResource.java
 
b/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/switcher/SwitchingResource.java
index 096615fe80b..2c2459e07e6 100644
--- 
a/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/switcher/SwitchingResource.java
+++ 
b/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/switcher/SwitchingResource.java
@@ -20,6 +20,7 @@ package org.apache.shardingsphere.mode.manager.switcher;
 import lombok.AccessLevel;
 import lombok.Getter;
 import lombok.RequiredArgsConstructor;
+import 
org.apache.shardingsphere.infra.datasource.pool.destroyer.DataSourcePoolDestroyer;
 import 
org.apache.shardingsphere.infra.datasource.pool.props.domain.DataSourcePoolProperties;
 import 
org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData;
 import 
org.apache.shardingsphere.infra.metadata.database.resource.StorageResource;
@@ -47,6 +48,6 @@ public final class SwitchingResource {
      * Close stale data sources.
      */
     public void closeStaleDataSources() {
-        
staleStorageResource.getDataSourceMap().values().stream().filter(Objects::nonNull).forEach(resourceMetaData::close);
+        
staleStorageResource.getDataSourceMap().values().stream().filter(Objects::nonNull).forEach(each
 -> new DataSourcePoolDestroyer(each).asyncDestroy());
     }
 }
diff --git 
a/mode/core/src/test/java/org/apache/shardingsphere/mode/manager/switcher/SwitchingResourceTest.java
 
b/mode/core/src/test/java/org/apache/shardingsphere/mode/manager/switcher/SwitchingResourceTest.java
index 5d91cb5872d..59453e49369 100644
--- 
a/mode/core/src/test/java/org/apache/shardingsphere/mode/manager/switcher/SwitchingResourceTest.java
+++ 
b/mode/core/src/test/java/org/apache/shardingsphere/mode/manager/switcher/SwitchingResourceTest.java
@@ -17,16 +17,18 @@
 
 package org.apache.shardingsphere.mode.manager.switcher;
 
-import 
org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNode;
-import 
org.apache.shardingsphere.infra.metadata.database.resource.StorageResource;
 import 
org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData;
+import 
org.apache.shardingsphere.infra.metadata.database.resource.StorageResource;
+import 
org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNode;
 import org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource;
+import org.awaitility.Awaitility;
 import org.junit.jupiter.api.Test;
 
 import java.util.Collections;
+import java.util.concurrent.TimeUnit;
 
+import static org.junit.jupiter.api.Assertions.assertTrue;
 import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
 
 class SwitchingResourceTest {
     
@@ -37,6 +39,7 @@ class SwitchingResourceTest {
         StorageResource newStorageResource = new 
StorageResource(Collections.singletonMap(new StorageNode("new_ds"), new 
MockedDataSource()), Collections.emptyMap());
         StorageResource staleStorageResource = new 
StorageResource(Collections.singletonMap(new StorageNode("stale_ds"), 
staleDataSource), Collections.emptyMap());
         new SwitchingResource(resourceMetaData, newStorageResource, 
staleStorageResource, Collections.emptyMap()).closeStaleDataSources();
-        verify(resourceMetaData).close(staleDataSource);
+        Awaitility.await().pollDelay(10L, 
TimeUnit.MILLISECONDS).until(staleDataSource::isClosed);
+        assertTrue(staleDataSource.isClosed());
     }
 }

Reply via email to