From a4aa8497451d1a4c805e96ae1b798099d238323b Mon Sep 17 00:00:00 2001 From: zhangliang Date: Wed, 4 Oct 2023 18:16:06 +0800 Subject: [PATCH] Fix test cases --- .../mode/manager/ContextManagerTest.java | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/mode/core/src/test/java/org/apache/shardingsphere/mode/manager/ContextManagerTest.java b/mode/core/src/test/java/org/apache/shardingsphere/mode/manager/ContextManagerTest.java index b6a29531c9174..b9329f189fe00 100644 --- a/mode/core/src/test/java/org/apache/shardingsphere/mode/manager/ContextManagerTest.java +++ b/mode/core/src/test/java/org/apache/shardingsphere/mode/manager/ContextManagerTest.java @@ -107,8 +107,10 @@ private ShardingSphereDatabase mockDatabase() { StorageUnitMetaData storageUnitMetaData = mock(StorageUnitMetaData.class, RETURNS_DEEP_STUBS); when(storageUnitMetaData.getStorageUnit().getStorageType()).thenReturn(TypedSPILoader.getService(DatabaseType.class, "FIXTURE")); when(result.getResourceMetaData().getStorageUnitMetaDataMap()).thenReturn(Collections.singletonMap("foo_ds", storageUnitMetaData)); + DataSourcePoolProperties dataSourcePoolProps = mock(DataSourcePoolProperties.class, RETURNS_DEEP_STUBS); + when(dataSourcePoolProps.getConnectionPropertySynonyms().getStandardProperties()).thenReturn(Collections.emptyMap()); Map metaDataMap = Collections.singletonMap("foo_ds", - new StorageUnitMetaData("foo_db", mock(StorageNode.class, RETURNS_DEEP_STUBS), mock(DataSourcePoolProperties.class), new MockedDataSource())); + new StorageUnitMetaData("foo_db", mock(StorageNode.class, RETURNS_DEEP_STUBS), dataSourcePoolProps, new MockedDataSource())); when(result.getResourceMetaData().getStorageUnitMetaDataMap()).thenReturn(metaDataMap); return result; } @@ -241,8 +243,8 @@ void assertAlterDataSourceConfiguration() { "foo_db", TypedSPILoader.getService(DatabaseType.class, "FIXTURE"), createOriginalResource(), createOriginalRuleMetaData(), Collections.emptyMap()); when(metaDataContexts.getMetaData().getDatabase("foo_db")).thenReturn(originalDatabaseMetaData); when(metaDataContexts.getMetaData().getGlobalRuleMetaData()).thenReturn(new RuleMetaData(Collections.emptyList())); - contextManager.getConfigurationContextManager().alterDataSourceUnitsConfiguration("foo_db", - Collections.singletonMap("foo_ds", new DataSourcePoolProperties(MockedDataSource.class.getName(), createProperties("test", "test")))); + Map dataSourcePoolPropsMap = getToBeAlteredDataSourcePoolPropertiesMap(); + contextManager.getConfigurationContextManager().alterDataSourceUnitsConfiguration("foo_db", dataSourcePoolPropsMap); assertThat(contextManager.getMetaDataContexts().getMetaData().getDatabase("foo_db").getResourceMetaData().getStorageUnitMetaDataMap().size(), is(3)); assertAlteredDataSource((MockedDataSource) contextManager.getMetaDataContexts().getMetaData().getDatabase("foo_db") .getResourceMetaData().getDataSources().get(new StorageNodeName("foo_ds"))); @@ -256,8 +258,10 @@ private ResourceMetaData createOriginalResource() { Map storageUnitNodeMap = StorageUnitNodeMapUtils.fromDataSources(originalDataSources); Map metaDataMap = new LinkedHashMap<>(2, 1F); for (Entry entry : storageUnitNodeMap.entrySet()) { + DataSourcePoolProperties dataSourcePoolProps = mock(DataSourcePoolProperties.class, RETURNS_DEEP_STUBS); + when(dataSourcePoolProps.getConnectionPropertySynonyms().getStandardProperties()).thenReturn(Collections.emptyMap()); metaDataMap.put(entry.getKey(), new StorageUnitMetaData( - "foo_db", storageUnitNodeMap.get(entry.getKey()), mock(DataSourcePoolProperties.class), storageNodeDataSourceMap.get(entry.getValue().getName()))); + "foo_db", storageUnitNodeMap.get(entry.getKey()), dataSourcePoolProps, storageNodeDataSourceMap.get(entry.getValue().getName()))); } ResourceMetaData result = mock(ResourceMetaData.class, RETURNS_DEEP_STUBS); when(result.getStorageUnitMetaDataMap()).thenReturn(metaDataMap); @@ -271,6 +275,14 @@ private RuleMetaData createOriginalRuleMetaData() { return result; } + private Map getToBeAlteredDataSourcePoolPropertiesMap() { + Map result = new HashMap<>(3, 1F); + result.put("foo_ds", new DataSourcePoolProperties(MockedDataSource.class.getName(), createProperties("test", "test"))); + result.put("ds_1", new DataSourcePoolProperties(MockedDataSource.class.getName(), createProperties("test", "test"))); + result.put("ds_2", new DataSourcePoolProperties(MockedDataSource.class.getName(), createProperties("test", "test"))); + return result; + } + @Test void assertAlterGlobalRuleConfiguration() { RuleConfiguration ruleConfig = new TransactionRuleConfiguration("LOCAL", null, new Properties()); @@ -307,9 +319,9 @@ void assertReloadTable() { private Map createProperties(final String username, final String password) { Map result = new HashMap<>(3, 1F); - result.putIfAbsent("url", "jdbc:mock://127.0.0.1/foo_ds"); - result.putIfAbsent("username", username); - result.putIfAbsent("password", password); + result.put("url", "jdbc:mock://127.0.0.1/foo_ds"); + result.put("username", username); + result.put("password", password); return result; }