This is an automated email from the ASF dual-hosted git repository.
menghaoran 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 144bec26516 Remove useless props in SingleTableRule (#18615)
144bec26516 is described below
commit 144bec26516ba6adde7f2c0e161b15f3e4ebf024
Author: Liang Zhang <[email protected]>
AuthorDate: Mon Jun 27 07:39:56 2022 +0800
Remove useless props in SingleTableRule (#18615)
---
.../engine/fixture/AbstractRoutingEngineTest.java | 3 +-
.../datanode/SingleTableDataNodeLoader.java | 6 +--
.../singletable/rule/SingleTableRule.java | 6 +--
.../rule/builder/SingleTableRuleBuilder.java | 2 +-
.../datanode/SingleTableDataNodeLoaderTest.java | 7 +--
.../route/SingleTableSQLRouterTest.java | 11 +++--
...ingleTableDatabaseBroadcastRouteEngineTest.java | 5 +--
.../engine/SingleTableStandardRouteEngineTest.java | 14 ++----
.../singletable/rule/SingleTableRuleTest.java | 50 +++++++---------------
9 files changed, 34 insertions(+), 70 deletions(-)
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/fixture/AbstractRoutingEngineTest.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/fixture/AbstractRoutingEngineTest.java
index 64e320276de..cb34b69d37e 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/fixture/AbstractRoutingEngineTest.java
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/fixture/AbstractRoutingEngineTest.java
@@ -20,7 +20,6 @@ package
org.apache.shardingsphere.sharding.route.engine.fixture;
import lombok.SneakyThrows;
import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import
org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
-import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.database.DefaultDatabase;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
@@ -240,7 +239,7 @@ public abstract class AbstractRoutingEngineTest {
protected final SingleTableRule createSingleTableRule(final
Collection<ShardingSphereRule> rules) {
Map<String, DataSource> dataSourceMap = createDataSourceMap();
- SingleTableRule result = new SingleTableRule(new
SingleTableRuleConfiguration(), DefaultDatabase.LOGIC_NAME, dataSourceMap,
rules, new ConfigurationProperties(new Properties()));
+ SingleTableRule result = new SingleTableRule(new
SingleTableRuleConfiguration(), DefaultDatabase.LOGIC_NAME, dataSourceMap,
rules);
result.put(dataSourceMap.keySet().iterator().next(),
DefaultDatabase.LOGIC_NAME, "t_category");
return result;
}
diff --git
a/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/datanode/SingleTableDataNodeLoader.java
b/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/datanode/SingleTableDataNodeLoader.java
index 02b8b839de0..483e9baf7ec 100644
---
a/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/datanode/SingleTableDataNodeLoader.java
+++
b/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/datanode/SingleTableDataNodeLoader.java
@@ -21,7 +21,6 @@ import com.google.common.base.Preconditions;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import
org.apache.shardingsphere.infra.config.exception.ShardingSphereConfigurationException;
-import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.datanode.DataNode;
import
org.apache.shardingsphere.infra.metadata.database.schema.loader.common.SchemaTableNamesLoader;
@@ -50,11 +49,10 @@ public final class SingleTableDataNodeLoader {
* @param databaseType database type
* @param dataSourceMap data source map
* @param excludedTables excluded tables
- * @param props configuration properties
* @return single table data node map
*/
- public static Map<String, Collection<DataNode>> load(final String
databaseName, final DatabaseType databaseType, final Map<String, DataSource>
dataSourceMap,
- final
Collection<String> excludedTables, final ConfigurationProperties props) {
+ public static Map<String, Collection<DataNode>> load(final String
databaseName, final DatabaseType databaseType,
+ final Map<String,
DataSource> dataSourceMap, final Collection<String> excludedTables) {
Map<String, Collection<DataNode>> result = new ConcurrentHashMap<>();
for (Entry<String, DataSource> entry : dataSourceMap.entrySet()) {
Map<String, Collection<DataNode>> dataNodeMap = load(databaseName,
databaseType, entry.getKey(), entry.getValue(), excludedTables);
diff --git
a/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/rule/SingleTableRule.java
b/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/rule/SingleTableRule.java
index f62238da652..36d36444c80 100644
---
a/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/rule/SingleTableRule.java
+++
b/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/rule/SingleTableRule.java
@@ -18,7 +18,6 @@
package org.apache.shardingsphere.singletable.rule;
import lombok.Getter;
-import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.database.type.DatabaseTypeEngine;
import org.apache.shardingsphere.infra.datanode.DataNode;
import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedTable;
@@ -67,13 +66,12 @@ public final class SingleTableRule implements DatabaseRule,
DataNodeContainedRul
private final Map<String, String> tableNames;
- public SingleTableRule(final SingleTableRuleConfiguration ruleConfig,
final String databaseName,
- final Map<String, DataSource> dataSourceMap, final
Collection<ShardingSphereRule> builtRules, final ConfigurationProperties props)
{
+ public SingleTableRule(final SingleTableRuleConfiguration ruleConfig,
final String databaseName, final Map<String, DataSource> dataSourceMap, final
Collection<ShardingSphereRule> builtRules) {
configuration = ruleConfig;
defaultDataSource = ruleConfig.getDefaultDataSource().orElse(null);
Map<String, DataSource> aggregateDataSourceMap =
getAggregateDataSourceMap(dataSourceMap, builtRules);
dataSourceNames = aggregateDataSourceMap.keySet();
- singleTableDataNodes = SingleTableDataNodeLoader.load(databaseName,
DatabaseTypeEngine.getDatabaseType(dataSourceMap.values()),
aggregateDataSourceMap, getLoadedTables(builtRules), props);
+ singleTableDataNodes = SingleTableDataNodeLoader.load(databaseName,
DatabaseTypeEngine.getDatabaseType(dataSourceMap.values()),
aggregateDataSourceMap, getLoadedTables(builtRules));
tableNames =
singleTableDataNodes.entrySet().stream().collect(Collectors.toConcurrentMap(Entry::getKey,
entry -> entry.getValue().iterator().next().getTableName()));
}
diff --git
a/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/rule/builder/SingleTableRuleBuilder.java
b/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/rule/builder/SingleTableRuleBuilder.java
index 2742e271a19..02e08d879ca 100644
---
a/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/rule/builder/SingleTableRuleBuilder.java
+++
b/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/rule/builder/SingleTableRuleBuilder.java
@@ -36,7 +36,7 @@ public final class SingleTableRuleBuilder implements
DatabaseRuleBuilder<SingleT
@Override
public SingleTableRule build(final SingleTableRuleConfiguration config,
final String databaseName,
final Map<String, DataSource> dataSources,
final Collection<ShardingSphereRule> builtRules, final ConfigurationProperties
props) {
- return new SingleTableRule(config, databaseName, dataSources,
builtRules, props);
+ return new SingleTableRule(config, databaseName, dataSources,
builtRules);
}
@Override
diff --git
a/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/test/java/org/apache/shardingsphere/singletable/datanode/SingleTableDataNodeLoaderTest.java
b/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/test/java/org/apache/shardingsphere/singletable/datanode/SingleTableDataNodeLoaderTest.java
index da9be3b79ff..ddc9ad45367 100644
---
a/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/test/java/org/apache/shardingsphere/singletable/datanode/SingleTableDataNodeLoaderTest.java
+++
b/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/test/java/org/apache/shardingsphere/singletable/datanode/SingleTableDataNodeLoaderTest.java
@@ -17,7 +17,6 @@
package org.apache.shardingsphere.singletable.datanode;
-import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.database.DefaultDatabase;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.datanode.DataNode;
@@ -35,7 +34,6 @@ import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
-import java.util.Properties;
import java.util.stream.Collectors;
import static org.hamcrest.CoreMatchers.is;
@@ -85,8 +83,7 @@ public final class SingleTableDataNodeLoaderTest {
@Test
public void assertLoad() {
Collection<String> excludedTables = Arrays.asList("salary",
"employee", "student");
- Map<String, Collection<DataNode>> dataNodeMap =
SingleTableDataNodeLoader.load(
- DefaultDatabase.LOGIC_NAME, mock(DatabaseType.class),
dataSourceMap, excludedTables, new ConfigurationProperties(new Properties()));
+ Map<String, Collection<DataNode>> dataNodeMap =
SingleTableDataNodeLoader.load(DefaultDatabase.LOGIC_NAME,
mock(DatabaseType.class), dataSourceMap, excludedTables);
assertFalse(dataNodeMap.containsKey("employee"));
assertFalse(dataNodeMap.containsKey("salary"));
assertFalse(dataNodeMap.containsKey("student"));
@@ -100,6 +97,6 @@ public final class SingleTableDataNodeLoaderTest {
@Test(expected = IllegalStateException.class)
public void assertLoadWithConflictTables() {
- SingleTableDataNodeLoader.load(DefaultDatabase.LOGIC_NAME,
mock(DatabaseType.class), dataSourceMap, Collections.emptyList(), new
ConfigurationProperties(new Properties()));
+ SingleTableDataNodeLoader.load(DefaultDatabase.LOGIC_NAME,
mock(DatabaseType.class), dataSourceMap, Collections.emptyList());
}
}
diff --git
a/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/test/java/org/apache/shardingsphere/singletable/route/SingleTableSQLRouterTest.java
b/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/test/java/org/apache/shardingsphere/singletable/route/SingleTableSQLRouterTest.java
index 82be65921ae..6b9c6c845f6 100644
---
a/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/test/java/org/apache/shardingsphere/singletable/route/SingleTableSQLRouterTest.java
+++
b/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/test/java/org/apache/shardingsphere/singletable/route/SingleTableSQLRouterTest.java
@@ -59,8 +59,8 @@ public final class SingleTableSQLRouterTest {
@Test
public void assertCreateRouteContextWithSingleDataSource() throws
SQLException {
- SingleTableRule rule = new SingleTableRule(new
SingleTableRuleConfiguration(), DefaultDatabase.LOGIC_NAME,
- Collections.singletonMap("foo_ds", new
MockedDataSource(mockConnection())), Collections.emptyList(), new
ConfigurationProperties(new Properties()));
+ SingleTableRule rule = new SingleTableRule(new
SingleTableRuleConfiguration(),
+ DefaultDatabase.LOGIC_NAME, Collections.singletonMap("foo_ds",
new MockedDataSource(mockConnection())), Collections.emptyList());
rule.getSingleTableDataNodes().put("t_order",
Collections.singletonList(createDataNode("foo_ds")));
ShardingSphereDatabase database = mockSingleDatabase();
RouteContext actual = new
SingleTableSQLRouter().createRouteContext(createLogicSQL(), database, rule, new
ConfigurationProperties(new Properties()));
@@ -80,8 +80,8 @@ public final class SingleTableSQLRouterTest {
@Test
public void assertCreateRouteContextWithReadwriteSplittingDataSource()
throws SQLException {
- SingleTableRule rule = new SingleTableRule(new
SingleTableRuleConfiguration(), DefaultDatabase.LOGIC_NAME,
- Collections.singletonMap("readwrite_ds", new
MockedDataSource(mockConnection())), Collections.emptyList(), new
ConfigurationProperties(new Properties()));
+ SingleTableRule rule = new SingleTableRule(new
SingleTableRuleConfiguration(),
+ DefaultDatabase.LOGIC_NAME,
Collections.singletonMap("readwrite_ds", new
MockedDataSource(mockConnection())), Collections.emptyList());
rule.getSingleTableDataNodes().put("t_order",
Collections.singletonList(createDataNode("write_ds")));
ShardingSphereDatabase database = mockReadwriteSplittingDatabase();
RouteContext actual = new
SingleTableSQLRouter().createRouteContext(createLogicSQL(), database, rule, new
ConfigurationProperties(new Properties()));
@@ -101,8 +101,7 @@ public final class SingleTableSQLRouterTest {
@Test
public void assertCreateRouteContextWithMultiDataSource() throws
SQLException {
- SingleTableRule rule = new SingleTableRule(new
SingleTableRuleConfiguration(), DefaultDatabase.LOGIC_NAME,
- createMultiDataSourceMap(), Collections.emptyList(), new
ConfigurationProperties(new Properties()));
+ SingleTableRule rule = new SingleTableRule(new
SingleTableRuleConfiguration(), DefaultDatabase.LOGIC_NAME,
createMultiDataSourceMap(), Collections.emptyList());
rule.getSingleTableDataNodes().put("t_order",
Collections.singleton(createDataNode("ds_0")));
ShardingSphereDatabase database = mockDatabaseWithMultipleResources();
RouteContext actual = new
SingleTableSQLRouter().createRouteContext(createLogicSQL(), database, rule, new
ConfigurationProperties(new Properties()));
diff --git
a/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/test/java/org/apache/shardingsphere/singletable/route/engine/SingleTableDatabaseBroadcastRouteEngineTest.java
b/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/test/java/org/apache/shardingsphere/singletable/route/engine/SingleTableDatabaseBroadcastRouteEngineTest.java
index 37466c7c91a..e6e2346c192 100644
---
a/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/test/java/org/apache/shardingsphere/singletable/route/engine/SingleTableDatabaseBroadcastRouteEngineTest.java
+++
b/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/test/java/org/apache/shardingsphere/singletable/route/engine/SingleTableDatabaseBroadcastRouteEngineTest.java
@@ -17,7 +17,6 @@
package org.apache.shardingsphere.singletable.route.engine;
-import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.database.DefaultDatabase;
import org.apache.shardingsphere.infra.route.context.RouteContext;
import org.apache.shardingsphere.infra.route.context.RouteUnit;
@@ -34,7 +33,6 @@ import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
-import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
@@ -47,8 +45,7 @@ public final class
SingleTableDatabaseBroadcastRouteEngineTest {
@Test
public void assertRoute() throws SQLException {
- SingleTableRule singleTableRule = new SingleTableRule(
- new SingleTableRuleConfiguration(),
DefaultDatabase.LOGIC_NAME, createDataSourceMap(), Collections.emptyList(), new
ConfigurationProperties(new Properties()));
+ SingleTableRule singleTableRule = new SingleTableRule(new
SingleTableRuleConfiguration(), DefaultDatabase.LOGIC_NAME,
createDataSourceMap(), Collections.emptyList());
RouteContext routeContext = new RouteContext();
SingleTableDatabaseBroadcastRouteEngine engine = new
SingleTableDatabaseBroadcastRouteEngine();
engine.route(routeContext, singleTableRule);
diff --git
a/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/test/java/org/apache/shardingsphere/singletable/route/engine/SingleTableStandardRouteEngineTest.java
b/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/test/java/org/apache/shardingsphere/singletable/route/engine/SingleTableStandardRouteEngineTest.java
index f5a827910e2..06c56970155 100644
---
a/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/test/java/org/apache/shardingsphere/singletable/route/engine/SingleTableStandardRouteEngineTest.java
+++
b/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/test/java/org/apache/shardingsphere/singletable/route/engine/SingleTableStandardRouteEngineTest.java
@@ -17,7 +17,6 @@
package org.apache.shardingsphere.singletable.route.engine;
-import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.database.DefaultDatabase;
import org.apache.shardingsphere.infra.datanode.DataNode;
import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedTable;
@@ -41,7 +40,6 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertFalse;
@@ -56,8 +54,7 @@ public final class SingleTableStandardRouteEngineTest {
@Test
public void assertRouteInSameDataSource() throws SQLException {
SingleTableStandardRouteEngine engine = new
SingleTableStandardRouteEngine(mockQualifiedTables(), null);
- SingleTableRule singleTableRule = new SingleTableRule(
- new SingleTableRuleConfiguration(),
DefaultDatabase.LOGIC_NAME, createDataSourceMap(), Collections.emptyList(), new
ConfigurationProperties(new Properties()));
+ SingleTableRule singleTableRule = new SingleTableRule(new
SingleTableRuleConfiguration(), DefaultDatabase.LOGIC_NAME,
createDataSourceMap(), Collections.emptyList());
singleTableRule.getSingleTableDataNodes().put("t_order",
Collections.singletonList(mockDataNode("ds_0", "t_order")));
singleTableRule.getSingleTableDataNodes().put("t_order_item",
Collections.singletonList(mockDataNode("ds_0", "t_order_item")));
RouteContext routeContext = new RouteContext();
@@ -89,8 +86,7 @@ public final class SingleTableStandardRouteEngineTest {
@Test
public void assertRouteInDifferentDataSource() throws SQLException {
SingleTableStandardRouteEngine engine = new
SingleTableStandardRouteEngine(mockQualifiedTables(), null);
- SingleTableRule singleTableRule = new SingleTableRule(
- new SingleTableRuleConfiguration(),
DefaultDatabase.LOGIC_NAME, createDataSourceMap(), Collections.emptyList(), new
ConfigurationProperties(new Properties()));
+ SingleTableRule singleTableRule = new SingleTableRule(new
SingleTableRuleConfiguration(), DefaultDatabase.LOGIC_NAME,
createDataSourceMap(), Collections.emptyList());
singleTableRule.getSingleTableDataNodes().put("t_order",
Collections.singletonList(mockDataNode("ds_0", "t_order")));
singleTableRule.getSingleTableDataNodes().put("t_order_item",
Collections.singletonList(mockDataNode("ds_1", "t_order_item")));
RouteContext routeContext = new RouteContext();
@@ -113,8 +109,7 @@ public final class SingleTableStandardRouteEngineTest {
@Test
public void assertRouteWithoutSingleTableRule() throws SQLException {
SingleTableStandardRouteEngine engine = new
SingleTableStandardRouteEngine(mockQualifiedTables(), new
MySQLCreateTableStatement(false));
- SingleTableRule singleTableRule = new SingleTableRule(
- new SingleTableRuleConfiguration(),
DefaultDatabase.LOGIC_NAME, createDataSourceMap(), Collections.emptyList(), new
ConfigurationProperties(new Properties()));
+ SingleTableRule singleTableRule = new SingleTableRule(new
SingleTableRuleConfiguration(), DefaultDatabase.LOGIC_NAME,
createDataSourceMap(), Collections.emptyList());
RouteContext routeContext = new RouteContext();
engine.route(routeContext, singleTableRule);
List<RouteUnit> routeUnits = new
ArrayList<>(routeContext.getRouteUnits());
@@ -129,8 +124,7 @@ public final class SingleTableStandardRouteEngineTest {
@Test
public void assertRouteWithDefaultSingleTableRule() throws SQLException {
SingleTableStandardRouteEngine engine = new
SingleTableStandardRouteEngine(mockQualifiedTables(), new
MySQLCreateTableStatement(false));
- SingleTableRule singleTableRule = new SingleTableRule(
- new SingleTableRuleConfiguration("ds_0"),
DefaultDatabase.LOGIC_NAME, createDataSourceMap(), Collections.emptyList(), new
ConfigurationProperties(new Properties()));
+ SingleTableRule singleTableRule = new SingleTableRule(new
SingleTableRuleConfiguration("ds_0"), DefaultDatabase.LOGIC_NAME,
createDataSourceMap(), Collections.emptyList());
RouteContext routeContext = new RouteContext();
engine.route(routeContext, singleTableRule);
List<RouteUnit> routeUnits = new
ArrayList<>(routeContext.getRouteUnits());
diff --git
a/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/test/java/org/apache/shardingsphere/singletable/rule/SingleTableRuleTest.java
b/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/test/java/org/apache/shardingsphere/singletable/rule/SingleTableRuleTest.java
index 5b48d5c3cd9..592f73789c0 100644
---
a/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/test/java/org/apache/shardingsphere/singletable/rule/SingleTableRuleTest.java
+++
b/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/test/java/org/apache/shardingsphere/singletable/rule/SingleTableRuleTest.java
@@ -17,7 +17,6 @@
package org.apache.shardingsphere.singletable.rule;
-import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.database.DefaultDatabase;
import org.apache.shardingsphere.infra.datanode.DataNode;
import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedTable;
@@ -41,7 +40,6 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
-import java.util.Properties;
import java.util.stream.Collectors;
import static org.hamcrest.CoreMatchers.is;
@@ -94,8 +92,7 @@ public final class SingleTableRuleTest {
public void assertGetSingleTableDataNodes() {
DataNodeContainedRule dataNodeContainedRule =
mock(DataNodeContainedRule.class);
when(dataNodeContainedRule.getAllTables()).thenReturn(Arrays.asList("t_order",
"t_order_0", "t_order_1"));
- SingleTableRule singleTableRule = new SingleTableRule(
- new SingleTableRuleConfiguration(),
DefaultDatabase.LOGIC_NAME, dataSourceMap,
Collections.singleton(dataNodeContainedRule), new ConfigurationProperties(new
Properties()));
+ SingleTableRule singleTableRule = new SingleTableRule(new
SingleTableRuleConfiguration(), DefaultDatabase.LOGIC_NAME, dataSourceMap,
Collections.singleton(dataNodeContainedRule));
Map<String, Collection<DataNode>> actual =
singleTableRule.getSingleTableDataNodes();
assertThat(actual.size(), is(2));
assertTrue(actual.containsKey("employee"));
@@ -106,8 +103,7 @@ public final class SingleTableRuleTest {
public void assertGetSingleTableDataNodesWithUpperCase() {
DataNodeContainedRule dataNodeContainedRule =
mock(DataNodeContainedRule.class);
when(dataNodeContainedRule.getAllTables()).thenReturn(Arrays.asList("T_ORDER",
"T_ORDER_0", "T_ORDER_1"));
- SingleTableRule singleTableRule = new SingleTableRule(
- new SingleTableRuleConfiguration(),
DefaultDatabase.LOGIC_NAME, dataSourceMap,
Collections.singleton(dataNodeContainedRule), new ConfigurationProperties(new
Properties()));
+ SingleTableRule singleTableRule = new SingleTableRule(new
SingleTableRuleConfiguration(), DefaultDatabase.LOGIC_NAME, dataSourceMap,
Collections.singleton(dataNodeContainedRule));
Map<String, Collection<DataNode>> actual =
singleTableRule.getSingleTableDataNodes();
assertThat(actual.size(), is(2));
assertTrue(actual.containsKey("employee"));
@@ -117,8 +113,7 @@ public final class SingleTableRuleTest {
@Test
public void assertFindSingleTableDataNode() {
DataNodeContainedRule dataNodeContainedRule =
mock(DataNodeContainedRule.class);
- SingleTableRule singleTableRule = new SingleTableRule(
- new SingleTableRuleConfiguration(),
DefaultDatabase.LOGIC_NAME, dataSourceMap,
Collections.singleton(dataNodeContainedRule), new ConfigurationProperties(new
Properties()));
+ SingleTableRule singleTableRule = new SingleTableRule(new
SingleTableRuleConfiguration(), DefaultDatabase.LOGIC_NAME, dataSourceMap,
Collections.singleton(dataNodeContainedRule));
Optional<DataNode> actual =
singleTableRule.findSingleTableDataNode(DefaultDatabase.LOGIC_NAME, "employee");
assertTrue(actual.isPresent());
assertThat(actual.get().getDataSourceName(), is("foo_ds"));
@@ -128,8 +123,7 @@ public final class SingleTableRuleTest {
@Test
public void assertFindSingleTableDataNodeWithUpperCase() {
DataNodeContainedRule dataNodeContainedRule =
mock(DataNodeContainedRule.class);
- SingleTableRule singleTableRule = new SingleTableRule(
- new SingleTableRuleConfiguration(),
DefaultDatabase.LOGIC_NAME, dataSourceMap,
Collections.singleton(dataNodeContainedRule), new ConfigurationProperties(new
Properties()));
+ SingleTableRule singleTableRule = new SingleTableRule(new
SingleTableRuleConfiguration(), DefaultDatabase.LOGIC_NAME, dataSourceMap,
Collections.singleton(dataNodeContainedRule));
Optional<DataNode> actual =
singleTableRule.findSingleTableDataNode(DefaultDatabase.LOGIC_NAME, "EMPLOYEE");
assertTrue(actual.isPresent());
assertThat(actual.get().getDataSourceName(), is("foo_ds"));
@@ -139,8 +133,7 @@ public final class SingleTableRuleTest {
@Test
public void assertIsSingleTablesInSameDataSource() {
DataNodeContainedRule dataNodeContainedRule =
mock(DataNodeContainedRule.class);
- SingleTableRule singleTableRule = new SingleTableRule(
- new SingleTableRuleConfiguration(),
DefaultDatabase.LOGIC_NAME, dataSourceMap,
Collections.singleton(dataNodeContainedRule), new ConfigurationProperties(new
Properties()));
+ SingleTableRule singleTableRule = new SingleTableRule(new
SingleTableRuleConfiguration(), DefaultDatabase.LOGIC_NAME, dataSourceMap,
Collections.singleton(dataNodeContainedRule));
Collection<QualifiedTable> singleTableNames = new LinkedList<>();
singleTableNames.add(new QualifiedTable(DefaultDatabase.LOGIC_NAME,
"employee"));
assertTrue(singleTableRule.isSingleTablesInSameDataSource(singleTableNames));
@@ -156,8 +149,7 @@ public final class SingleTableRuleTest {
RouteContext routeContext = new RouteContext();
routeContext.putRouteUnit(dataSourceMapper, tableMappers);
DataNodeContainedRule dataNodeContainedRule =
mock(DataNodeContainedRule.class);
- SingleTableRule singleTableRule = new SingleTableRule(
- new SingleTableRuleConfiguration(),
DefaultDatabase.LOGIC_NAME, dataSourceMap,
Collections.singleton(dataNodeContainedRule), new ConfigurationProperties(new
Properties()));
+ SingleTableRule singleTableRule = new SingleTableRule(new
SingleTableRuleConfiguration(), DefaultDatabase.LOGIC_NAME, dataSourceMap,
Collections.singleton(dataNodeContainedRule));
assertTrue(singleTableRule.isAllTablesInSameDataSource(routeContext,
singleTableNames));
}
@@ -166,16 +158,14 @@ public final class SingleTableRuleTest {
DataNodeContainedRule dataNodeContainedRule =
mock(DataNodeContainedRule.class);
SingleTableRuleConfiguration singleTableRuleConfig = new
SingleTableRuleConfiguration();
singleTableRuleConfig.setDefaultDataSource("foo_ds");
- SingleTableRule singleTableRule = new SingleTableRule(
- singleTableRuleConfig, DefaultDatabase.LOGIC_NAME,
dataSourceMap, Collections.singleton(dataNodeContainedRule), new
ConfigurationProperties(new Properties()));
+ SingleTableRule singleTableRule = new
SingleTableRule(singleTableRuleConfig, DefaultDatabase.LOGIC_NAME,
dataSourceMap, Collections.singleton(dataNodeContainedRule));
assertThat(singleTableRule.assignNewDataSourceName(), is("foo_ds"));
}
@Test
public void assertGetSingleTableNames() {
DataNodeContainedRule dataNodeContainedRule =
mock(DataNodeContainedRule.class);
- SingleTableRule singleTableRule = new SingleTableRule(
- new SingleTableRuleConfiguration(),
DefaultDatabase.LOGIC_NAME, dataSourceMap,
Collections.singleton(dataNodeContainedRule), new ConfigurationProperties(new
Properties()));
+ SingleTableRule singleTableRule = new SingleTableRule(new
SingleTableRuleConfiguration(), DefaultDatabase.LOGIC_NAME, dataSourceMap,
Collections.singleton(dataNodeContainedRule));
Collection<QualifiedTable> tableNames = new LinkedList<>();
tableNames.add(new QualifiedTable(DefaultDatabase.LOGIC_NAME,
"employee"));
assertThat(singleTableRule.getSingleTableNames(tableNames).iterator().next().getSchemaName(),
is(DefaultDatabase.LOGIC_NAME));
@@ -185,8 +175,7 @@ public final class SingleTableRuleTest {
@Test
public void assertPut() {
DataNodeContainedRule dataNodeContainedRule =
mock(DataNodeContainedRule.class);
- SingleTableRule singleTableRule = new SingleTableRule(
- new SingleTableRuleConfiguration(),
DefaultDatabase.LOGIC_NAME, dataSourceMap,
Collections.singleton(dataNodeContainedRule), new ConfigurationProperties(new
Properties()));
+ SingleTableRule singleTableRule = new SingleTableRule(new
SingleTableRuleConfiguration(), DefaultDatabase.LOGIC_NAME, dataSourceMap,
Collections.singleton(dataNodeContainedRule));
String tableName = "teacher";
String dataSourceName = "foo_ds";
singleTableRule.put(dataSourceName, DefaultDatabase.LOGIC_NAME,
tableName);
@@ -204,8 +193,7 @@ public final class SingleTableRuleTest {
@Test
public void assertRemove() {
DataNodeContainedRule dataNodeContainedRule =
mock(DataNodeContainedRule.class);
- SingleTableRule singleTableRule = new SingleTableRule(
- new SingleTableRuleConfiguration(),
DefaultDatabase.LOGIC_NAME, dataSourceMap,
Collections.singleton(dataNodeContainedRule), new ConfigurationProperties(new
Properties()));
+ SingleTableRule singleTableRule = new SingleTableRule(new
SingleTableRuleConfiguration(), DefaultDatabase.LOGIC_NAME, dataSourceMap,
Collections.singleton(dataNodeContainedRule));
String tableName = "employee";
singleTableRule.remove(DefaultDatabase.LOGIC_NAME, tableName);
Collection<QualifiedTable> tableNames = new LinkedList<>();
@@ -219,8 +207,7 @@ public final class SingleTableRuleTest {
@Test
public void assertGetAllDataNodes() {
DataNodeContainedRule dataNodeContainedRule =
mock(DataNodeContainedRule.class);
- SingleTableRule singleTableRule = new SingleTableRule(
- new SingleTableRuleConfiguration(),
DefaultDatabase.LOGIC_NAME, dataSourceMap,
Collections.singleton(dataNodeContainedRule), new ConfigurationProperties(new
Properties()));
+ SingleTableRule singleTableRule = new SingleTableRule(new
SingleTableRuleConfiguration(), DefaultDatabase.LOGIC_NAME, dataSourceMap,
Collections.singleton(dataNodeContainedRule));
assertTrue(singleTableRule.getAllDataNodes().containsKey("employee"));
assertTrue(singleTableRule.getAllDataNodes().containsKey("student"));
assertTrue(singleTableRule.getAllDataNodes().containsKey("t_order_0"));
@@ -230,8 +217,7 @@ public final class SingleTableRuleTest {
@Test
public void assertGetDataNodesByTableName() {
DataNodeContainedRule dataNodeContainedRule =
mock(DataNodeContainedRule.class);
- SingleTableRule singleTableRule = new SingleTableRule(
- new SingleTableRuleConfiguration(),
DefaultDatabase.LOGIC_NAME, dataSourceMap,
Collections.singleton(dataNodeContainedRule), new ConfigurationProperties(new
Properties()));
+ SingleTableRule singleTableRule = new SingleTableRule(new
SingleTableRuleConfiguration(), DefaultDatabase.LOGIC_NAME, dataSourceMap,
Collections.singleton(dataNodeContainedRule));
Collection<DataNode> actual =
singleTableRule.getDataNodesByTableName("EMPLOYEE");
assertThat(actual.size(), is(1));
DataNode dataNode = actual.iterator().next();
@@ -242,8 +228,7 @@ public final class SingleTableRuleTest {
@Test
public void assertFindFirstActualTable() {
DataNodeContainedRule dataNodeContainedRule =
mock(DataNodeContainedRule.class);
- SingleTableRule singleTableRule = new SingleTableRule(
- new SingleTableRuleConfiguration(),
DefaultDatabase.LOGIC_NAME, dataSourceMap,
Collections.singleton(dataNodeContainedRule), new ConfigurationProperties(new
Properties()));
+ SingleTableRule singleTableRule = new SingleTableRule(new
SingleTableRuleConfiguration(), DefaultDatabase.LOGIC_NAME, dataSourceMap,
Collections.singleton(dataNodeContainedRule));
String logicTable = "employee";
assertFalse(singleTableRule.findFirstActualTable(logicTable).isPresent());
}
@@ -251,16 +236,14 @@ public final class SingleTableRuleTest {
@Test
public void assertIsNeedAccumulate() {
DataNodeContainedRule dataNodeContainedRule =
mock(DataNodeContainedRule.class);
- SingleTableRule singleTableRule = new SingleTableRule(
- new SingleTableRuleConfiguration(),
DefaultDatabase.LOGIC_NAME, dataSourceMap,
Collections.singleton(dataNodeContainedRule), new ConfigurationProperties(new
Properties()));
+ SingleTableRule singleTableRule = new SingleTableRule(new
SingleTableRuleConfiguration(), DefaultDatabase.LOGIC_NAME, dataSourceMap,
Collections.singleton(dataNodeContainedRule));
assertFalse(singleTableRule.isNeedAccumulate(Collections.emptyList()));
}
@Test
public void assertFindLogicTableByActualTable() {
DataNodeContainedRule dataNodeContainedRule =
mock(DataNodeContainedRule.class);
- SingleTableRule singleTableRule = new SingleTableRule(
- new SingleTableRuleConfiguration(),
DefaultDatabase.LOGIC_NAME, dataSourceMap,
Collections.singleton(dataNodeContainedRule), new ConfigurationProperties(new
Properties()));
+ SingleTableRule singleTableRule = new SingleTableRule(new
SingleTableRuleConfiguration(), DefaultDatabase.LOGIC_NAME, dataSourceMap,
Collections.singleton(dataNodeContainedRule));
String actualTable = "student";
assertFalse(singleTableRule.findLogicTableByActualTable(actualTable).isPresent());
}
@@ -268,8 +251,7 @@ public final class SingleTableRuleTest {
@Test
public void assertFindActualTableByCatalog() {
DataNodeContainedRule dataNodeContainedRule =
mock(DataNodeContainedRule.class);
- SingleTableRule singleTableRule = new SingleTableRule(
- new SingleTableRuleConfiguration(),
DefaultDatabase.LOGIC_NAME, dataSourceMap,
Collections.singleton(dataNodeContainedRule), new ConfigurationProperties(new
Properties()));
+ SingleTableRule singleTableRule = new SingleTableRule(new
SingleTableRuleConfiguration(), DefaultDatabase.LOGIC_NAME, dataSourceMap,
Collections.singleton(dataNodeContainedRule));
String catalog = "employee";
String logicTable = "t_order_0";
assertFalse(singleTableRule.findActualTableByCatalog(catalog,
logicTable).isPresent());