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 f6d0e3ddaa7b9..2f5e5dfda4f50 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 @@ -49,15 +49,16 @@ public final class ResourceMetaData { public ResourceMetaData(final Map dataSources) { this.dataSources = StorageNodeUtils.getStorageNodeDataSources(dataSources); - storageUnitMetaData = new StorageUnitMetaData(null, this.dataSources, dataSources.entrySet().stream() - .collect(Collectors.toMap(Entry::getKey, entry -> DataSourcePoolPropertiesCreator.create(entry.getValue()), (oldValue, currentValue) -> oldValue, LinkedHashMap::new)), - StorageUnitNodeMapUtils.fromDataSources(dataSources)); + storageUnitMetaData = new StorageUnitMetaData(null, StorageUnitNodeMapUtils.fromDataSources(dataSources), + dataSources.entrySet().stream().collect( + Collectors.toMap(Entry::getKey, entry -> DataSourcePoolPropertiesCreator.create(entry.getValue()), (oldValue, currentValue) -> oldValue, LinkedHashMap::new)), + this.dataSources); } public ResourceMetaData(final String databaseName, final Map dataSources, final Map storageUnitNodeMap, final Map propsMap) { this.dataSources = dataSources; - storageUnitMetaData = new StorageUnitMetaData(databaseName, dataSources, propsMap, storageUnitNodeMap); + storageUnitMetaData = new StorageUnitMetaData(databaseName, storageUnitNodeMap, propsMap, dataSources); } /** diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/unit/StorageUnitMetaData.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/unit/StorageUnitMetaData.java index 34ce3e90ef46e..5981c1915f9f7 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/unit/StorageUnitMetaData.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/unit/StorageUnitMetaData.java @@ -37,28 +37,21 @@ public final class StorageUnitMetaData { // TODO zhangliang: should refactor private final Map storageNodes; + private final Map dataSourcePoolPropertiesMap; + private final Map storageUnits; // TODO zhangliang: should refactor private final Map dataSources; - public StorageUnitMetaData(final String databaseName, final Map storageNodeDataSources, - final Map dataSourcePoolPropertiesMap, final Map storageNodes) { + public StorageUnitMetaData(final String databaseName, final Map storageNodes, final Map dataSourcePoolPropertiesMap, + final Map storageNodeDataSources) { this.storageNodes = storageNodes; + this.dataSourcePoolPropertiesMap = dataSourcePoolPropertiesMap; storageUnits = storageNodes.entrySet().stream().collect( Collectors.toMap(Entry::getKey, entry -> new StorageUnit(databaseName, storageNodeDataSources, dataSourcePoolPropertiesMap.get(entry.getKey()), entry.getValue()), (oldValue, currentValue) -> currentValue, () -> new LinkedHashMap<>(this.storageNodes.size(), 1F))); dataSources = storageUnits.entrySet().stream().collect( Collectors.toMap(Entry::getKey, entry -> entry.getValue().getDataSource(), (oldValue, currentValue) -> currentValue, () -> new LinkedHashMap<>(storageUnits.size(), 1F))); } - - /** - * Get data source pool properties map. - * - * @return data source pool properties map - */ - public Map getDataSourcePoolPropertiesMap() { - return storageUnits.entrySet().stream() - .collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().getDataSourcePoolProperties(), (oldValue, currentValue) -> oldValue, LinkedHashMap::new)); - } } diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ConfigurationChangedSubscriberTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ConfigurationChangedSubscriberTest.java index 3b76384bebba1..b2dd14aa6926a 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ConfigurationChangedSubscriberTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ConfigurationChangedSubscriberTest.java @@ -113,6 +113,7 @@ private ContextManagerBuilderParameter createContextManagerBuilderParameter() { private Map createDatabases() { when(database.getName()).thenReturn("db"); ResourceMetaData resourceMetaData = mock(ResourceMetaData.class, RETURNS_DEEP_STUBS); + when(resourceMetaData.getStorageUnitMetaData().getStorageNodes()).thenReturn(Collections.emptyMap()); when(database.getResourceMetaData()).thenReturn(resourceMetaData); when(database.getSchemas()).thenReturn(Collections.singletonMap("foo_schema", new ShardingSphereSchema())); when(database.getProtocolType()).thenReturn(TypedSPILoader.getService(DatabaseType.class, "FIXTURE"));