This is an automated email from the ASF dual-hosted git repository.
panjuan 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 3285ad5 modify tableRules to Map to improve performance (#11768)
3285ad5 is described below
commit 3285ad55e9a0f7308b9377b2251a3121b03df220
Author: Zhengqiang Duan <[email protected]>
AuthorDate: Wed Aug 11 20:42:35 2021 +0800
modify tableRules to Map to improve performance (#11768)
* modify tableRules to Map to improve performance
* fix test case
* fix test case
---
...rdingDataSourceGroupBroadcastRoutingEngine.java | 2 +-
.../impl/ShardingDropTableStatementValidator.java | 2 +-
.../shardingsphere/sharding/rule/ShardingRule.java | 41 +++++++++++-----------
...gDataSourceGroupBroadcastRoutingEngineTest.java | 10 +++---
.../ShardingDropTableStatementValidatorTest.java | 8 +++--
.../sharding/rule/ShardingRuleTest.java | 4 +--
.../spring/boot/SpringBootStarterTest.java | 2 +-
.../GovernanceShardingNamespaceTest.java | 8 ++---
...nceShardingReadwriteSplittingNamespaceTest.java | 2 +-
.../scaling/core/util/JobConfigurationUtil.java | 2 +-
10 files changed, 43 insertions(+), 38 deletions(-)
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/broadcast/ShardingDataSourceGroupBroadcastRoutingEngine.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/broadcast/ShardingDataSourceGroupBroadcastRoutingEngine.java
index a9ccacc..f4c13a5 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/broadcast/ShardingDataSourceGroupBroadcastRoutingEngine.java
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/broadcast/ShardingDataSourceGroupBroadcastRoutingEngine.java
@@ -56,7 +56,7 @@ public final class
ShardingDataSourceGroupBroadcastRoutingEngine implements Shar
private Collection<Set<String>> getDataSourceGroup(final ShardingRule
shardingRule) {
Collection<Set<String>> result = new LinkedList<>();
- for (TableRule each : shardingRule.getTableRules()) {
+ for (TableRule each : shardingRule.getTableRules().values()) {
result.add(each.getDataNodeGroups().keySet());
}
return result;
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingDropTableStatementValidator.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingDropTableStatementValidator.java
index 3870690..c9e7a08 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingDropTableStatementValidator.java
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingDropTableStatementValidator.java
@@ -63,7 +63,7 @@ public final class ShardingDropTableStatementValidator
extends ShardingDDLStatem
Collection<String> inUsedTable = new LinkedList<>();
Set<String> dropTables = sqlStatement.getTables().stream().map(each ->
each.getTableName().getIdentifier().getValue()).collect(Collectors.toSet());
Set<String> actualTables =
routeContext.getRouteUnits().stream().flatMap(each ->
each.getTableMappers().stream().map(RouteMapper::getActualName)).collect(Collectors.toSet());
- Collection<String> tableMeta =
shardingRule.getTableRules().stream().filter(each ->
!dropTables.contains(each.getLogicTable()))
+ Collection<String> tableMeta =
shardingRule.getTableRules().values().stream().filter(each ->
!dropTables.contains(each.getLogicTable()))
.flatMap(each ->
each.getActualDataNodes().stream().map(DataNode::getTableName)).collect(Collectors.toSet());
for (String each : actualTables) {
if (tableMeta.contains(each)) {
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java
index 9188caf..fdb2677 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java
@@ -55,6 +55,7 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.TreeSet;
+import java.util.function.Function;
import java.util.stream.Collectors;
/**
@@ -74,7 +75,7 @@ public final class ShardingRule implements FeatureRule,
SchemaRule, DataNodeCont
private final Map<String, KeyGenerateAlgorithm> keyGenerators = new
LinkedHashMap<>();
- private final Collection<TableRule> tableRules;
+ private final Map<String, TableRule> tableRules = new LinkedHashMap<>();
private final Collection<BindingTableRule> bindingTableRules;
@@ -93,8 +94,8 @@ public final class ShardingRule implements FeatureRule,
SchemaRule, DataNodeCont
dataSourceNames = getDataSourceNames(config.getTables(),
config.getAutoTables(), dataSourceMap.keySet());
config.getShardingAlgorithms().forEach((key, value) ->
shardingAlgorithms.put(key,
ShardingSphereAlgorithmFactory.createAlgorithm(value,
ShardingAlgorithm.class)));
config.getKeyGenerators().forEach((key, value) ->
keyGenerators.put(key, ShardingSphereAlgorithmFactory.createAlgorithm(value,
KeyGenerateAlgorithm.class)));
- tableRules = new LinkedList<>(createTableRules(config.getTables(),
config.getDefaultKeyGenerateStrategy()));
- tableRules.addAll(createAutoTableRules(config.getAutoTables(),
config.getDefaultKeyGenerateStrategy()));
+ tableRules.putAll(createTableRules(config.getTables(),
config.getDefaultKeyGenerateStrategy()));
+ tableRules.putAll(createAutoTableRules(config.getAutoTables(),
config.getDefaultKeyGenerateStrategy()));
broadcastTables = config.getBroadcastTables();
bindingTableRules =
createBindingTableRules(config.getBindingTableGroups());
defaultDatabaseShardingStrategyConfig = null ==
config.getDefaultDatabaseShardingStrategy() ? new
NoneShardingStrategyConfiguration() :
config.getDefaultDatabaseShardingStrategy();
@@ -109,8 +110,8 @@ public final class ShardingRule implements FeatureRule,
SchemaRule, DataNodeCont
dataSourceNames = getDataSourceNames(config.getTables(),
config.getAutoTables(), dataSourceMap.keySet());
shardingAlgorithms.putAll(config.getShardingAlgorithms());
keyGenerators.putAll(config.getKeyGenerators());
- tableRules = new LinkedList<>(createTableRules(config.getTables(),
config.getDefaultKeyGenerateStrategy()));
- tableRules.addAll(createAutoTableRules(config.getAutoTables(),
config.getDefaultKeyGenerateStrategy()));
+ tableRules.putAll(createTableRules(config.getTables(),
config.getDefaultKeyGenerateStrategy()));
+ tableRules.putAll(createAutoTableRules(config.getAutoTables(),
config.getDefaultKeyGenerateStrategy()));
broadcastTables = config.getBroadcastTables();
bindingTableRules =
createBindingTableRules(config.getBindingTableGroups());
defaultDatabaseShardingStrategyConfig = null ==
config.getDefaultDatabaseShardingStrategy() ? new
NoneShardingStrategyConfiguration() :
config.getDefaultDatabaseShardingStrategy();
@@ -144,14 +145,15 @@ public final class ShardingRule implements FeatureRule,
SchemaRule, DataNodeCont
return actualDataNodes.stream().map(each -> new
DataNode(each).getDataSourceName()).collect(Collectors.toList());
}
- private Collection<TableRule> createTableRules(final
Collection<ShardingTableRuleConfiguration> tableRuleConfigurations, final
KeyGenerateStrategyConfiguration defaultKeyGenerateStrategyConfig) {
- return tableRuleConfigurations.stream().map(each -> new
TableRule(each, dataSourceNames,
getDefaultGenerateKeyColumn(defaultKeyGenerateStrategyConfig))).collect(Collectors.toList());
+ private Map<String, TableRule> createTableRules(final
Collection<ShardingTableRuleConfiguration> tableRuleConfigurations, final
KeyGenerateStrategyConfiguration defaultKeyGenerateStrategyConfig) {
+ return tableRuleConfigurations.stream().map(each -> new
TableRule(each, dataSourceNames,
getDefaultGenerateKeyColumn(defaultKeyGenerateStrategyConfig)))
+ .collect(Collectors.toMap(TableRule::getLogicTable,
Function.identity(), (oldValue, currentValue) -> oldValue, LinkedHashMap::new));
}
- private Collection<TableRule> createAutoTableRules(final
Collection<ShardingAutoTableRuleConfiguration> autoTableRuleConfigurations,
+ private Map<String, TableRule> createAutoTableRules(final
Collection<ShardingAutoTableRuleConfiguration> autoTableRuleConfigurations,
final
KeyGenerateStrategyConfiguration defaultKeyGenerateStrategyConfig) {
- return autoTableRuleConfigurations.stream().map(
- each -> createAutoTableRule(defaultKeyGenerateStrategyConfig,
each)).collect(Collectors.toList());
+ return autoTableRuleConfigurations.stream().map(each ->
createAutoTableRule(defaultKeyGenerateStrategyConfig, each))
+ .collect(Collectors.toMap(TableRule::getLogicTable,
Function.identity(), (oldValue, currentValue) -> oldValue, LinkedHashMap::new));
}
private TableRule createAutoTableRule(final
KeyGenerateStrategyConfiguration defaultKeyGenerateStrategyConfig, final
ShardingAutoTableRuleConfiguration each) {
@@ -207,7 +209,7 @@ public final class ShardingRule implements FeatureRule,
SchemaRule, DataNodeCont
* @return table rule
*/
public Optional<TableRule> findTableRule(final String logicTableName) {
- return tableRules.stream().filter(each ->
each.getLogicTable().equalsIgnoreCase(logicTableName)).findFirst();
+ return
Optional.ofNullable(tableRules.getOrDefault(logicTableName.toLowerCase(),
null));
}
/**
@@ -217,7 +219,7 @@ public final class ShardingRule implements FeatureRule,
SchemaRule, DataNodeCont
* @return table rule
*/
public Optional<TableRule> findTableRuleByActualTable(final String
actualTableName) {
- return tableRules.stream().filter(each ->
each.isExisted(actualTableName)).findFirst();
+ return tableRules.values().stream().filter(each ->
each.isExisted(actualTableName)).findFirst();
}
/**
@@ -322,7 +324,7 @@ public final class ShardingRule implements FeatureRule,
SchemaRule, DataNodeCont
}
Collection<String> tableNames = new HashSet<>(logicTableNames);
Collection<String> dataSourceNames = new HashSet<>();
- dataSourceNames.addAll(tableRules.stream().filter(each ->
tableNames.contains(each.getLogicTable())).flatMap(each
+ dataSourceNames.addAll(tableRules.values().stream().filter(each ->
tableNames.contains(each.getLogicTable())).flatMap(each
->
each.getActualDataNodes().stream()).map(DataNode::getDataSourceName).collect(Collectors.toSet()));
dataSourceNames.addAll(broadcastTables.stream().filter(tableNames::contains).flatMap(each
-> getDataSourceNames().stream()).collect(Collectors.toSet()));
return 1 == dataSourceNames.size();
@@ -357,7 +359,7 @@ public final class ShardingRule implements FeatureRule,
SchemaRule, DataNodeCont
* @return is sharding column or not
*/
public boolean isShardingColumn(final String columnName, final String
tableName) {
- return tableRules.stream().anyMatch(each ->
each.getLogicTable().equalsIgnoreCase(tableName) && isShardingColumn(each,
columnName));
+ return
Optional.ofNullable(tableRules.getOrDefault(tableName.toLowerCase(),
null)).filter(each -> isShardingColumn(each, columnName)).isPresent();
}
private boolean isShardingColumn(final TableRule tableRule, final String
columnName) {
@@ -384,7 +386,7 @@ public final class ShardingRule implements FeatureRule,
SchemaRule, DataNodeCont
* @return is generate key column or not
*/
public boolean isGenerateKeyColumn(final String columnName, final String
tableName) {
- return tableRules.stream().anyMatch(each ->
each.getLogicTable().equalsIgnoreCase(tableName) && isGenerateKeyColumn(each,
columnName));
+ return
Optional.ofNullable(tableRules.getOrDefault(tableName.toLowerCase(),
null)).filter(each -> isGenerateKeyColumn(each, columnName)).isPresent();
}
private boolean isGenerateKeyColumn(final TableRule tableRule, final
String columnName) {
@@ -399,8 +401,7 @@ public final class ShardingRule implements FeatureRule,
SchemaRule, DataNodeCont
* @return column name of generated key
*/
public Optional<String> findGenerateKeyColumnName(final String
logicTableName) {
- return tableRules.stream().filter(each ->
each.getLogicTable().equalsIgnoreCase(logicTableName) &&
each.getGenerateKeyColumn().isPresent())
-
.map(TableRule::getGenerateKeyColumn).findFirst().orElse(Optional.empty());
+ return
Optional.ofNullable(tableRules.getOrDefault(logicTableName.toLowerCase(),
null)).filter(each ->
each.getGenerateKeyColumn().isPresent()).flatMap(TableRule::getGenerateKeyColumn);
}
/**
@@ -468,13 +469,13 @@ public final class ShardingRule implements FeatureRule,
SchemaRule, DataNodeCont
@Override
public Map<String, Collection<DataNode>> getAllDataNodes() {
Map<String, Collection<DataNode>> result = new LinkedHashMap<>();
-
result.putAll(tableRules.stream().collect(Collectors.toMap(TableRule::getLogicTable,
TableRule::getActualDataNodes, (oldValue, currentValue) -> oldValue,
LinkedHashMap::new)));
+
result.putAll(tableRules.values().stream().collect(Collectors.toMap(TableRule::getLogicTable,
TableRule::getActualDataNodes, (oldValue, currentValue) -> oldValue,
LinkedHashMap::new)));
return result;
}
@Override
public Collection<String> getAllActualTables() {
- return tableRules.stream().flatMap(each ->
each.getActualDataNodes().stream().map(DataNode::getTableName)).collect(Collectors.toSet());
+ return tableRules.values().stream().flatMap(each ->
each.getActualDataNodes().stream().map(DataNode::getTableName)).collect(Collectors.toSet());
}
@Override
@@ -494,7 +495,7 @@ public final class ShardingRule implements FeatureRule,
SchemaRule, DataNodeCont
@Override
public Collection<String> getTables() {
- return
tableRules.stream().map(TableRule::getLogicTable).collect(Collectors.toList());
+ return tableRules.keySet();
}
@Override
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/broadcast/ShardingDataSourceGroupBroadcastRoutingEngineTest.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/broadcast/ShardingDataSourceGroupBroadcastRoutingEngineTest.java
index 66db7af..0155ca3 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/broadcast/ShardingDataSourceGroupBroadcastRoutingEngineTest.java
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/broadcast/ShardingDataSourceGroupBroadcastRoutingEngineTest.java
@@ -30,6 +30,7 @@ import org.mockito.junit.MockitoJUnitRunner;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -48,10 +49,11 @@ public final class
ShardingDataSourceGroupBroadcastRoutingEngineTest {
@Mock
private ShardingRule shardingRule;
- private List<TableRule> mockTableRules(final List<List<String>> shards) {
- List<TableRule> result = new LinkedList<>();
+ private Map<String, TableRule> mockTableRules(final List<List<String>>
shards) {
+ Map<String, TableRule> result = new LinkedHashMap<>();
+ int index = 0;
for (List<String> each : shards) {
- result.add(mockTableRule(each));
+ result.put("table_" + index++, mockTableRule(each));
}
return result;
}
@@ -72,7 +74,7 @@ public final class
ShardingDataSourceGroupBroadcastRoutingEngineTest {
shards.add(Arrays.asList("ds1", "ds2", "ds3"));
shards.add(Arrays.asList("ds1", "ds2", "ds3"));
shards.add(Arrays.asList("ds1", "ds2", "ds3"));
- List<TableRule> tableRules = mockTableRules(shards);
+ Map<String, TableRule> tableRules = mockTableRules(shards);
when(shardingRule.getTableRules()).thenReturn(tableRules);
RouteContext routeContext = new RouteContext();
shardingDataSourceGroupBroadcastRoutingEngine.route(routeContext,
shardingRule);
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingDropTableStatementValidatorTest.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingDropTableStatementValidatorTest.java
index 8bc88c0..a20442f 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingDropTableStatementValidatorTest.java
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingDropTableStatementValidatorTest.java
@@ -45,8 +45,10 @@ import org.mockito.junit.MockitoJUnitRunner;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
+import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -62,9 +64,9 @@ public final class ShardingDropTableStatementValidatorTest {
@Before
public void init() {
- Collection<TableRule> tableRules = new LinkedList<>();
- tableRules.add(generateShardingRule("t_order_item"));
- tableRules.add(generateShardingRule("t_order"));
+ Map<String, TableRule> tableRules = new LinkedHashMap<>();
+ tableRules.put("t_order_item", generateShardingRule("t_order_item"));
+ tableRules.put("t_order", generateShardingRule("t_order"));
when(shardingRule.getTableRules()).thenReturn(tableRules);
}
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java
index ae3a750..daab3aa 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java
@@ -42,9 +42,9 @@ import java.util.Properties;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
@@ -301,7 +301,7 @@ public final class ShardingRuleTest {
@Test
public void assertGetTables() {
- assertThat(createMaximumShardingRule().getTables(),
is(Arrays.asList("logic_table", "sub_logic_table")));
+ assertThat(createMaximumShardingRule().getTables(), is(new
LinkedHashSet<>(Arrays.asList("logic_table", "sub_logic_table"))));
}
@Test
diff --git
a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/java/org/apache/shardingsphere/spring/boot/SpringBootStarterTest.java
b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/java/org/apache/shardingsphere/spring/boot/SpringBootStarterTest.java
index 647910a..705de02 100644
---
a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/java/org/apache/shardingsphere/spring/boot/SpringBootStarterTest.java
+++
b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/java/org/apache/shardingsphere/spring/boot/SpringBootStarterTest.java
@@ -96,7 +96,7 @@ public class SpringBootStarterTest {
assertThat(databaseShardingAlgorithm.getProps().getProperty("algorithm-expression"),
is("ds_$->{user_id % 2}"));
InlineShardingAlgorithm orderTableShardingAlgorithm =
(InlineShardingAlgorithm)
shardingAlgorithmMap.get("orderTableShardingAlgorithm");
assertThat(orderTableShardingAlgorithm.getProps().getProperty("algorithm-expression"),
is("t_order_$->{order_id % 2}"));
- Collection<TableRule> tableRules = rule.getTableRules();
+ Collection<TableRule> tableRules = rule.getTableRules().values();
assertNotNull(tableRules);
assertThat(tableRules.size(), is(1));
TableRule tableRule = tableRules.iterator().next();
diff --git
a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-governance-spring/shardingsphere-jdbc-governance-spring-namespace/src/test/java/org/apache/shardingsphere/spring/namespace/governance/GovernanceShardingNamespaceTest.java
b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-governance-spring/shardingsphere-jdbc-governance-spring-namespace/src/test/java/org/apache/shardingsphere/spring/namespace/governance/GovernanceShardingNamespaceTest.java
index 050ac68..c4f8c59 100644
---
a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-governance-spring/shardingsphere-jdbc-governance-spring-namespace/src/test/java/org/apache/shardingsphere/spring/namespace/governance/GovernanceShardingNamespaceTest.java
+++
b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-governance-spring/shardingsphere-jdbc-governance-spring-namespace/src/test/java/org/apache/shardingsphere/spring/namespace/governance/GovernanceShardingNamespaceTest.java
@@ -58,7 +58,7 @@ public class GovernanceShardingNamespaceTest extends
AbstractJUnit4SpringContext
ShardingRule shardingRule =
getShardingRule("simpleShardingGovernance");
assertNotNull(dataSourceMap.get("dbtbl_0"));
assertThat(shardingRule.getTableRules().size(), is(1));
-
assertThat(shardingRule.getTableRules().iterator().next().getLogicTable(),
is("t_order"));
+
assertThat(shardingRule.getTableRules().values().iterator().next().getLogicTable(),
is("t_order"));
}
@Test
@@ -74,7 +74,7 @@ public class GovernanceShardingNamespaceTest extends
AbstractJUnit4SpringContext
public void assertTableRuleWithAttributesDataSource() {
ShardingRule shardingRule =
getShardingRule("tableRuleWithAttributesDataSourceGovernance");
assertThat(shardingRule.getTableRules().size(), is(1));
- TableRule tableRule = shardingRule.getTableRules().iterator().next();
+ TableRule tableRule =
shardingRule.getTableRules().values().iterator().next();
assertThat(tableRule.getLogicTable(), is("t_order"));
assertThat(tableRule.getActualDataNodes().size(), is(8));
assertTrue(tableRule.getActualDataNodes().contains(new
DataNode("dbtbl_0", "t_order_0")));
@@ -94,7 +94,7 @@ public class GovernanceShardingNamespaceTest extends
AbstractJUnit4SpringContext
public void assertMultiTableRulesDataSource() {
ShardingRule shardingRule =
getShardingRule("multiTableRulesDataSourceGovernance");
assertThat(shardingRule.getTableRules().size(), is(2));
- Iterator<TableRule> tableRules =
shardingRule.getTableRules().iterator();
+ Iterator<TableRule> tableRules =
shardingRule.getTableRules().values().iterator();
assertThat(tableRules.next().getLogicTable(), is("t_order"));
assertThat(tableRules.next().getLogicTable(), is("t_order_item"));
}
@@ -159,7 +159,7 @@ public class GovernanceShardingNamespaceTest extends
AbstractJUnit4SpringContext
Iterator<ShardingSphereRule> iterator =
metaDataContexts.getMetaData(DefaultSchema.LOGIC_NAME).getRuleMetaData().getRules().iterator();
ShardingRule shardingRule = (ShardingRule) iterator.next();
assertThat(shardingRule.getTableRules().size(), is(2));
- Iterator<TableRule> tableRules =
shardingRule.getTableRules().iterator();
+ Iterator<TableRule> tableRules =
shardingRule.getTableRules().values().iterator();
TableRule orderRule = tableRules.next();
assertThat(orderRule.getActualDataNodes().size(), is(2));
assertTrue(orderRule.getActualDataNodes().contains(new
DataNode("dbtbl_0", "t_order")));
diff --git
a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-governance-spring/shardingsphere-jdbc-governance-spring-namespace/src/test/java/org/apache/shardingsphere/spring/namespace/governance/GovernanceShardingReadwriteSplittingNamespaceTest.java
b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-governance-spring/shardingsphere-jdbc-governance-spring-namespace/src/test/java/org/apache/shardingsphere/spring/namespace/governance/GovernanceShardingRea
[...]
index dde2a4f..eb804e8 100644
---
a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-governance-spring/shardingsphere-jdbc-governance-spring-namespace/src/test/java/org/apache/shardingsphere/spring/namespace/governance/GovernanceShardingReadwriteSplittingNamespaceTest.java
+++
b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-governance-spring/shardingsphere-jdbc-governance-spring-namespace/src/test/java/org/apache/shardingsphere/spring/namespace/governance/GovernanceShardingReadwriteSplittingNamespaceTest.java
@@ -57,7 +57,7 @@ public class
GovernanceShardingReadwriteSplittingNamespaceTest extends AbstractJ
Optional<ShardingRule> shardingRule =
getShardingRule("dataSourceByUserStrategyGovernance");
assertTrue(shardingRule.isPresent());
assertThat(shardingRule.get().getTableRules().size(), is(1));
-
assertThat(shardingRule.get().getTableRules().iterator().next().getLogicTable(),
is("t_order"));
+
assertThat(shardingRule.get().getTableRules().values().iterator().next().getLogicTable(),
is("t_order"));
}
private Map<String, DataSource> getDataSourceMap(final String
dataSourceName) {
diff --git
a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/util/JobConfigurationUtil.java
b/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/util/JobConfigurationUtil.java
index fe7af8d..eedb74d 100644
---
a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/util/JobConfigurationUtil.java
+++
b/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/util/JobConfigurationUtil.java
@@ -292,7 +292,7 @@ public final class JobConfigurationUtil {
private static Map<String, Map<String, String>>
toDataSourceTableNameMap(final ShardingRule shardingRule) {
Map<String, Map<String, String>> result = new HashMap<>();
- for (TableRule each : shardingRule.getTableRules()) {
+ for (TableRule each : shardingRule.getTableRules().values()) {
mergeDataSourceTableNameMap(result,
toDataSourceTableNameMap(each));
}
return result;