You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by du...@apache.org on 2022/05/15 15:08:39 UTC
[shardingsphere] branch master updated: Refactor new HashMap<>(1, 1) to Collections.singletonMap() (#17675)
This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang 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 70b465ecafa Refactor new HashMap<>(1, 1) to Collections.singletonMap() (#17675)
70b465ecafa is described below
commit 70b465ecafa317a5c9b829e3e89318160ee7fcc1
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Sun May 15 23:08:33 2022 +0800
Refactor new HashMap<>(1, 1) to Collections.singletonMap() (#17675)
---
.../framework/type/JDBCExampleScenario.java | 2 +-
.../type/SpringBootStarterJdbcExampleScenario.java | 9 ++----
.../type/SpringBootStarterJpaExampleScenario.java | 9 ++----
.../SpringBootStarterMyBatisExampleScenario.java | 10 ++----
.../type/SpringNamespaceJdbcExampleScenario.java | 9 ++----
.../type/SpringNamespaceJpaExampleScenario.java | 9 ++----
.../SpringNamespaceMyBatisExampleScenario.java | 12 +++----
.../dbdiscovery/rule/DatabaseDiscoveryRule.java | 5 ++-
.../rule/DatabaseDiscoveryRuleTest.java | 7 ++--
...tabaseDiscoveryHeartbeatQueryResultSetTest.java | 4 +--
...scoveryProviderAlgorithmQueryResultSetTest.java | 4 +--
.../DatabaseDiscoveryRuleQueryResultSetTest.java | 11 +++----
...pDatabaseDiscoveryRuleStatementUpdaterTest.java | 9 +++---
.../impl/EncryptOrderByItemTokenGeneratorTest.java | 15 ++-------
.../EncryptParameterRewriterBuilderTest.java | 13 ++------
.../DropEncryptRuleStatementUpdaterTest.java | 7 ++--
.../ReadwriteSplittingRuleQueryResultSetTest.java | 18 ++---------
...ReadwriteSplittingRuleStatementUpdaterTest.java | 20 +++++-------
.../dal/show/ShowCreateTableMergedResultTest.java | 19 +++--------
.../dal/show/ShowTableStatusMergedResultTest.java | 23 ++++----------
.../merge/dal/show/ShowTablesMergedResultTest.java | 37 ++++++++--------------
.../CreateShardingScalingRuleStatementUpdater.java | 15 ++-------
.../ShardingScalingRulesQueryResultSetTest.java | 20 ++++--------
.../engine/GeneratedKeyContextEngineTest.java | 9 ++----
.../YamlOnRuleAlteredActionConfiguration.java | 2 +-
.../pool/creator/DataSourcePoolCreatorTest.java | 9 ++----
.../fixture/MockedDataSourcePoolMetaData.java | 4 +--
.../schema/util/IndexMetaDataUtilTest.java | 4 +--
.../rewrite/context/SQLRewriteContextTest.java | 19 ++++-------
.../token/generator/SQLTokenGeneratorsTest.java | 13 +++-----
.../yaml/YamlShardingSphereDataSourceFactory.java | 7 ++--
.../ShardingSphereDatabaseMetaDataTest.java | 2 +-
.../singletable/rule/SingleTableRule.java | 5 +--
.../traffic/rule/TrafficRuleTest.java | 30 +++++-------------
.../ExportDatabaseConfigurationHandlerTest.java | 9 ++----
.../scenario/MixSQLRewriterParameterizedTest.java | 8 ++---
.../ShardingSQLRewriterParameterizedTest.java | 8 ++---
37 files changed, 122 insertions(+), 294 deletions(-)
diff --git a/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/scenario/framework/type/JDBCExampleScenario.java b/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/scenario/framework/type/JDBCExampleScenario.java
index 638b7e8ab42..710980af858 100644
--- a/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/scenario/framework/type/JDBCExampleScenario.java
+++ b/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/scenario/framework/type/JDBCExampleScenario.java
@@ -48,7 +48,7 @@ public final class JDBCExampleScenario implements FrameworkExampleScenario {
@Override
public Collection<String> getJavaClassPaths() {
- Collection<String> result = new HashSet<>();
+ Collection<String> result = new HashSet<>(2, 1);
result.add("config");
result.add("repository");
return result;
diff --git a/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/scenario/framework/type/SpringBootStarterJdbcExampleScenario.java b/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/scenario/framework/type/SpringBootStarterJdbcExampleScenario.java
index 2625787654d..812eb1b3b10 100644
--- a/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/scenario/framework/type/SpringBootStarterJdbcExampleScenario.java
+++ b/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/scenario/framework/type/SpringBootStarterJdbcExampleScenario.java
@@ -22,7 +22,6 @@ import org.apache.shardingsphere.example.generator.scenario.framework.FrameworkE
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.Map;
/**
@@ -42,16 +41,12 @@ public final class SpringBootStarterJdbcExampleScenario implements FrameworkExam
@Override
public Map<String, String> getResourceTemplateMap() {
- Map<String, String> result = new HashMap<>(1, 1);
- result.put("resources/properties/application.ftl", "application.properties");
- return result;
+ return Collections.singletonMap("resources/properties/application.ftl", "application.properties");
}
@Override
public Collection<String> getJavaClassPaths() {
- Collection<String> result = new HashSet<>();
- result.add("repository");
- return result;
+ return Collections.singleton("repository");
}
@Override
diff --git a/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/scenario/framework/type/SpringBootStarterJpaExampleScenario.java b/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/scenario/framework/type/SpringBootStarterJpaExampleScenario.java
index 01683ec2d1c..bd29497a2db 100644
--- a/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/scenario/framework/type/SpringBootStarterJpaExampleScenario.java
+++ b/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/scenario/framework/type/SpringBootStarterJpaExampleScenario.java
@@ -22,7 +22,6 @@ import org.apache.shardingsphere.example.generator.scenario.framework.FrameworkE
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.Map;
/**
@@ -42,16 +41,12 @@ public final class SpringBootStarterJpaExampleScenario implements FrameworkExamp
@Override
public Map<String, String> getResourceTemplateMap() {
- Map<String, String> result = new HashMap<>(1, 1);
- result.put("resources/properties/application.ftl", "application.properties");
- return result;
+ return Collections.singletonMap("resources/properties/application.ftl", "application.properties");
}
@Override
public Collection<String> getJavaClassPaths() {
- Collection<String> result = new HashSet<>();
- result.add("repository");
- return result;
+ return Collections.singleton("repository");
}
@Override
diff --git a/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/scenario/framework/type/SpringBootStarterMyBatisExampleScenario.java b/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/scenario/framework/type/SpringBootStarterMyBatisExampleScenario.java
index 953fca122d3..5513d3dd498 100644
--- a/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/scenario/framework/type/SpringBootStarterMyBatisExampleScenario.java
+++ b/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/scenario/framework/type/SpringBootStarterMyBatisExampleScenario.java
@@ -20,8 +20,8 @@ package org.apache.shardingsphere.example.generator.scenario.framework.type;
import org.apache.shardingsphere.example.generator.scenario.framework.FrameworkExampleScenario;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.Map;
/**
@@ -51,16 +51,12 @@ public final class SpringBootStarterMyBatisExampleScenario implements FrameworkE
@Override
public Collection<String> getJavaClassPaths() {
- Collection<String> result = new HashSet<>();
- result.add("repository");
- return result;
+ return Collections.singleton("repository");
}
@Override
public Collection<String> getResourcePaths() {
- Collection<String> result = new HashSet<>();
- result.add("mappers");
- return result;
+ return Collections.singleton("mappers");
}
@Override
diff --git a/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/scenario/framework/type/SpringNamespaceJdbcExampleScenario.java b/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/scenario/framework/type/SpringNamespaceJdbcExampleScenario.java
index e801b4ca441..39cfade0e50 100644
--- a/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/scenario/framework/type/SpringNamespaceJdbcExampleScenario.java
+++ b/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/scenario/framework/type/SpringNamespaceJdbcExampleScenario.java
@@ -22,7 +22,6 @@ import org.apache.shardingsphere.example.generator.scenario.framework.FrameworkE
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.Map;
/**
@@ -42,16 +41,12 @@ public final class SpringNamespaceJdbcExampleScenario implements FrameworkExampl
@Override
public Map<String, String> getResourceTemplateMap() {
- Map<String, String> result = new HashMap<>(1, 1);
- result.put("resources/xml/application.ftl", "application.xml");
- return result;
+ return Collections.singletonMap("resources/xml/application.ftl", "application.xml");
}
@Override
public Collection<String> getJavaClassPaths() {
- Collection<String> result = new HashSet<>();
- result.add("repository");
- return result;
+ return Collections.singleton("repository");
}
@Override
diff --git a/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/scenario/framework/type/SpringNamespaceJpaExampleScenario.java b/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/scenario/framework/type/SpringNamespaceJpaExampleScenario.java
index a76ef025b68..9e3ba642ec4 100644
--- a/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/scenario/framework/type/SpringNamespaceJpaExampleScenario.java
+++ b/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/scenario/framework/type/SpringNamespaceJpaExampleScenario.java
@@ -22,7 +22,6 @@ import org.apache.shardingsphere.example.generator.scenario.framework.FrameworkE
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.Map;
/**
@@ -42,16 +41,12 @@ public final class SpringNamespaceJpaExampleScenario implements FrameworkExample
@Override
public Map<String, String> getResourceTemplateMap() {
- Map<String, String> result = new HashMap<>(1, 1);
- result.put("resources/xml/application.ftl", "application.xml");
- return result;
+ return Collections.singletonMap("resources/xml/application.ftl", "application.xml");
}
@Override
public Collection<String> getJavaClassPaths() {
- Collection<String> result = new HashSet<>();
- result.add("repository");
- return result;
+ return Collections.singleton("repository");
}
@Override
diff --git a/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/scenario/framework/type/SpringNamespaceMyBatisExampleScenario.java b/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/scenario/framework/type/SpringNamespaceMyBatisExampleScenario.java
index daf301922fb..4adad5462c7 100644
--- a/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/scenario/framework/type/SpringNamespaceMyBatisExampleScenario.java
+++ b/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/scenario/framework/type/SpringNamespaceMyBatisExampleScenario.java
@@ -20,8 +20,8 @@ package org.apache.shardingsphere.example.generator.scenario.framework.type;
import org.apache.shardingsphere.example.generator.scenario.framework.FrameworkExampleScenario;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.Map;
/**
@@ -41,7 +41,7 @@ public final class SpringNamespaceMyBatisExampleScenario implements FrameworkExa
@Override
public Map<String, String> getResourceTemplateMap() {
- Map<String, String> result = new HashMap<>(1, 1);
+ Map<String, String> result = new HashMap<>(4, 1);
result.put("resources/xml/application.ftl", "application.xml");
result.put("resources/mappers/OrderItemMapper.ftl", "mappers/OrderItemMapper.xml");
result.put("resources/mappers/OrderMapper.ftl", "mappers/OrderMapper.xml");
@@ -51,16 +51,12 @@ public final class SpringNamespaceMyBatisExampleScenario implements FrameworkExa
@Override
public Collection<String> getJavaClassPaths() {
- Collection<String> result = new HashSet<>();
- result.add("repository");
- return result;
+ return Collections.singleton("repository");
}
@Override
public Collection<String> getResourcePaths() {
- Collection<String> result = new HashSet<>();
- result.add("mappers");
- return result;
+ return Collections.singleton("mappers");
}
@Override
diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRule.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRule.java
index 2881f7d3536..6e8eb1f760e 100644
--- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRule.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRule.java
@@ -45,6 +45,7 @@ import org.apache.shardingsphere.schedule.core.api.ModeScheduleContextFactory;
import javax.sql.DataSource;
import java.sql.SQLException;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
@@ -168,9 +169,7 @@ public final class DatabaseDiscoveryRule implements SchemaRule, DataSourceContai
@Override
public Map<String, Supplier<Object>> getExportedMethods() {
- Map<String, Supplier<Object>> result = new HashMap<>(1, 1);
- result.put(ExportableConstants.EXPORTABLE_KEY_PRIMARY_DATA_SOURCE, this::exportPrimaryDataSourceMap);
- return result;
+ return Collections.singletonMap(ExportableConstants.EXPORTABLE_KEY_PRIMARY_DATA_SOURCE, this::exportPrimaryDataSourceMap);
}
private Map<String, String> exportPrimaryDataSourceMap() {
diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRuleTest.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRuleTest.java
index 9d526263551..939b2d5ea63 100644
--- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRuleTest.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRuleTest.java
@@ -32,7 +32,6 @@ import java.util.Collections;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;
-import java.util.HashMap;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
@@ -71,15 +70,13 @@ public final class DatabaseDiscoveryRuleTest {
@Test
public void assertGetExportedMethods() {
DatabaseDiscoveryRule databaseDiscoveryRule = createRule();
- Map<String, String> singleDataSourceRuleMap = new HashMap<>(1, 1);
- singleDataSourceRuleMap.put("test_pr", "primary");
- assertThat(databaseDiscoveryRule.getExportedMethods().get(ExportableConstants.EXPORTABLE_KEY_PRIMARY_DATA_SOURCE).get(), is(singleDataSourceRuleMap));
+ assertThat(databaseDiscoveryRule.getExportedMethods().get(ExportableConstants.EXPORTABLE_KEY_PRIMARY_DATA_SOURCE).get(), is(Collections.singletonMap("test_pr", "primary")));
}
private DatabaseDiscoveryRule createRule() {
DatabaseDiscoveryDataSourceRuleConfiguration config = new DatabaseDiscoveryDataSourceRuleConfiguration("test_pr", Arrays.asList("ds_0", "ds_1"), "", "CORE.FIXTURE");
return new DatabaseDiscoveryRule("db_discovery", dataSourceMap, new DatabaseDiscoveryRuleConfiguration(
Collections.singleton(config), Collections.singletonMap("discovery_heartbeat", new DatabaseDiscoveryHeartBeatConfiguration(new Properties())),
- ImmutableMap.of("CORE.FIXTURE", new ShardingSphereAlgorithmConfiguration("CORE.FIXTURE", new Properties()))));
+ Collections.singletonMap("CORE.FIXTURE", new ShardingSphereAlgorithmConfiguration("CORE.FIXTURE", new Properties()))));
}
}
diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/DatabaseDiscoveryHeartbeatQueryResultSetTest.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/DatabaseDiscover [...]
index bab53d7cb44..14853ce2d71 100644
--- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/DatabaseDiscoveryHeartbeatQueryResultSetTest.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/DatabaseDiscoveryHeartbeatQueryResultSetTest.java
@@ -30,7 +30,6 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
@@ -64,8 +63,7 @@ public final class DatabaseDiscoveryHeartbeatQueryResultSetTest {
Properties discoveryTypeProps = new Properties();
discoveryTypeProps.put("type_key", "type_value");
DatabaseDiscoveryHeartBeatConfiguration shardingSphereAlgorithmConfig = new DatabaseDiscoveryHeartBeatConfiguration(discoveryTypeProps);
- Map<String, DatabaseDiscoveryHeartBeatConfiguration> discoverHeartbeat = new HashMap<>(1, 1);
- discoverHeartbeat.put("test_name", shardingSphereAlgorithmConfig);
+ Map<String, DatabaseDiscoveryHeartBeatConfiguration> discoverHeartbeat = Collections.singletonMap("test_name", shardingSphereAlgorithmConfig);
return new DatabaseDiscoveryRuleConfiguration(Collections.singleton(databaseDiscoveryDataSourceRuleConfig), discoverHeartbeat, Collections.emptyMap());
}
}
diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/DatabaseDiscoveryProviderAlgorithmQueryResultSetTest.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/Database [...]
index f282311c867..e3febd6de79 100644
--- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/DatabaseDiscoveryProviderAlgorithmQueryResultSetTest.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/DatabaseDiscoveryProviderAlgorithmQueryResultSetTest.java
@@ -30,7 +30,6 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
@@ -65,8 +64,7 @@ public final class DatabaseDiscoveryProviderAlgorithmQueryResultSetTest {
Properties discoveryTypeProps = new Properties();
discoveryTypeProps.put("type_key", "type_value");
ShardingSphereAlgorithmConfiguration shardingSphereAlgorithmConfig = new ShardingSphereAlgorithmConfiguration("MySQL.MGR", discoveryTypeProps);
- Map<String, ShardingSphereAlgorithmConfiguration> discoverTypes = new HashMap<>(1, 1);
- discoverTypes.put("test_name", shardingSphereAlgorithmConfig);
+ Map<String, ShardingSphereAlgorithmConfiguration> discoverTypes = Collections.singletonMap("test_name", shardingSphereAlgorithmConfig);
return new DatabaseDiscoveryRuleConfiguration(Collections.singleton(databaseDiscoveryDataSourceRuleConfig), Collections.emptyMap(), discoverTypes);
}
}
diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/DatabaseDiscoveryRuleQueryResultSetTest.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/DatabaseDiscoveryRule [...]
index 85cb55e3f34..4d065ceccef 100644
--- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/DatabaseDiscoveryRuleQueryResultSetTest.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/DatabaseDiscoveryRuleQueryResultSetTest.java
@@ -32,7 +32,6 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
@@ -69,13 +68,11 @@ public final class DatabaseDiscoveryRuleQueryResultSetTest {
}
private RuleConfiguration createRuleConfiguration() {
- DatabaseDiscoveryDataSourceRuleConfiguration databaseDiscoveryDataSourceRuleConfig = new DatabaseDiscoveryDataSourceRuleConfiguration("ms_group", Arrays.asList("ds_0", "ds_1"),
- "heartbeat_test", "type_test");
+ DatabaseDiscoveryDataSourceRuleConfiguration databaseDiscoveryDataSourceRuleConfig = new DatabaseDiscoveryDataSourceRuleConfiguration(
+ "ms_group", Arrays.asList("ds_0", "ds_1"), "heartbeat_test", "type_test");
ShardingSphereAlgorithmConfiguration shardingSphereAlgorithmConfig = new ShardingSphereAlgorithmConfiguration("MySQL.MGR", new Properties());
- Map<String, ShardingSphereAlgorithmConfiguration> discoverTypes = new HashMap<>(1, 1);
- discoverTypes.put("type_test", shardingSphereAlgorithmConfig);
- Map<String, DatabaseDiscoveryHeartBeatConfiguration> discoveryHeartbeat = new HashMap<>(1, 1);
- discoveryHeartbeat.put("heartbeat_test", new DatabaseDiscoveryHeartBeatConfiguration(new Properties()));
+ Map<String, DatabaseDiscoveryHeartBeatConfiguration> discoveryHeartbeat = Collections.singletonMap("heartbeat_test", new DatabaseDiscoveryHeartBeatConfiguration(new Properties()));
+ Map<String, ShardingSphereAlgorithmConfiguration> discoverTypes = Collections.singletonMap("type_test", shardingSphereAlgorithmConfig);
return new DatabaseDiscoveryRuleConfiguration(Collections.singleton(databaseDiscoveryDataSourceRuleConfig), discoveryHeartbeat, discoverTypes);
}
}
diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryRuleStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseD [...]
index bf44267763d..fceda1ff093 100644
--- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryRuleStatementUpdaterTest.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryRuleStatementUpdaterTest.java
@@ -30,7 +30,6 @@ import org.junit.Test;
import java.util.Arrays;
import java.util.Collections;
-import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.Properties;
@@ -99,15 +98,15 @@ public final class DropDatabaseDiscoveryRuleStatementUpdaterTest {
private DatabaseDiscoveryRuleConfiguration createCurrentRuleConfiguration() {
DatabaseDiscoveryDataSourceRuleConfiguration dataSourceRuleConfig = new DatabaseDiscoveryDataSourceRuleConfiguration("ha_group", Collections.emptyList(), "ha_heartbeat", "readwrite_ds_MGR");
- Map<String, ShardingSphereAlgorithmConfiguration> discoveryTypes = new HashMap<>(1, 1);
- discoveryTypes.put("readwrite_ds_MGR", new ShardingSphereAlgorithmConfiguration("readwrite_ds_MGR", new Properties()));
+ Map<String, ShardingSphereAlgorithmConfiguration> discoveryTypes = Collections.singletonMap(
+ "readwrite_ds_MGR", new ShardingSphereAlgorithmConfiguration("readwrite_ds_MGR", new Properties()));
return new DatabaseDiscoveryRuleConfiguration(new LinkedList<>(Collections.singleton(dataSourceRuleConfig)), Collections.emptyMap(), discoveryTypes);
}
private DatabaseDiscoveryRuleConfiguration createMultipleCurrentRuleConfigurations() {
DatabaseDiscoveryDataSourceRuleConfiguration dataSourceRuleConfig = new DatabaseDiscoveryDataSourceRuleConfiguration("ha_group", Collections.emptyList(), "ha_heartbeat", "readwrite_ds_MGR");
- Map<String, ShardingSphereAlgorithmConfiguration> discoveryTypes = new HashMap<>(1, 1);
- discoveryTypes.put("readwrite_ds_MGR", new ShardingSphereAlgorithmConfiguration("readwrite_ds_MGR", new Properties()));
+ Map<String, ShardingSphereAlgorithmConfiguration> discoveryTypes = Collections.singletonMap(
+ "readwrite_ds_MGR", new ShardingSphereAlgorithmConfiguration("readwrite_ds_MGR", new Properties()));
return new DatabaseDiscoveryRuleConfiguration(new LinkedList<>(Arrays.asList(dataSourceRuleConfig,
new DatabaseDiscoveryDataSourceRuleConfiguration("ha_group_another", Collections.emptyList(), "ha_heartbeat", "readwrite_ds_MGR"))), Collections.emptyMap(), discoveryTypes);
}
diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/impl/EncryptOrderByItemTokenGeneratorTest.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/impl/EncryptOrderByItemTokenGeneratorTest.java
index 7d74615d407..385004e7c3c 100644
--- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/impl/EncryptOrderByItemTokenGeneratorTest.java
+++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/impl/EncryptOrderByItemTokenGeneratorTest.java
@@ -26,7 +26,6 @@ import org.apache.shardingsphere.infra.binder.segment.table.TablesContext;
import org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
import org.apache.shardingsphere.infra.database.type.DatabaseTypeEngine;
import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
-import org.apache.shardingsphere.infra.rewrite.sql.token.pojo.generic.SubstitutableColumnNameToken;
import org.apache.shardingsphere.sql.parser.sql.common.constant.OrderDirection;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.order.item.ColumnOrderByItemSegment;
@@ -38,10 +37,7 @@ import org.apache.shardingsphere.sql.parser.sql.common.value.identifier.Identifi
import org.junit.Before;
import org.junit.Test;
-import java.util.Collection;
import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
import java.util.Optional;
import static org.hamcrest.CoreMatchers.is;
@@ -58,13 +54,12 @@ public final class EncryptOrderByItemTokenGeneratorTest {
public void setup() {
generator = new EncryptOrderByItemTokenGenerator();
generator.setEncryptRule(buildEncryptRule());
- generator.setSchemas(mockSchemaMap());
+ generator.setSchemas(Collections.singletonMap("test", mock(ShardingSphereSchema.class)));
}
@Test
public void assertGenerateSQLTokens() {
- Collection<SubstitutableColumnNameToken> sqlTokens = generator.generateSQLTokens(buildSelectStatementContext());
- assertThat(sqlTokens.size(), is(1));
+ assertThat(generator.generateSQLTokens(buildSelectStatementContext()).size(), is(1));
}
private SelectStatementContext buildSelectStatementContext() {
@@ -93,10 +88,4 @@ public final class EncryptOrderByItemTokenGeneratorTest {
when(result.findEncryptTable("t_encrypt")).thenReturn(Optional.of(encryptTable));
return result;
}
-
- private Map<String, ShardingSphereSchema> mockSchemaMap() {
- Map<String, ShardingSphereSchema> result = new HashMap<>(1, 1);
- result.put("test", mock(ShardingSphereSchema.class));
- return result;
- }
}
diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/parameter/EncryptParameterRewriterBuilderTest.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/parameter/EncryptParameterRewriterBuilderTest.java
index 45730159bae..71ad88f1539 100644
--- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/parameter/EncryptParameterRewriterBuilderTest.java
+++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/parameter/EncryptParameterRewriterBuilderTest.java
@@ -28,8 +28,6 @@ import org.junit.Test;
import java.util.Collection;
import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
@@ -50,7 +48,7 @@ public final class EncryptParameterRewriterBuilderTest {
SQLStatementContext<?> sqlStatementContext = mock(SelectStatementContext.class, RETURNS_DEEP_STUBS);
when(sqlStatementContext.getTablesContext().getTableNames()).thenReturn(Collections.singletonList("t_order"));
Collection<ParameterRewriter> actual = new EncryptParameterRewriterBuilder(
- encryptRule, DefaultDatabase.LOGIC_NAME, mockSchemaMap(), sqlStatementContext, Collections.emptyList()).getParameterRewriters();
+ encryptRule, DefaultDatabase.LOGIC_NAME, Collections.singletonMap("test", mock(ShardingSphereSchema.class)), sqlStatementContext, Collections.emptyList()).getParameterRewriters();
assertThat(actual.size(), is(1));
ParameterRewriter parameterRewriter = actual.iterator().next();
assertThat(parameterRewriter, instanceOf(EncryptPredicateParameterRewriter.class));
@@ -63,12 +61,7 @@ public final class EncryptParameterRewriterBuilderTest {
SelectStatementContext sqlStatementContext = mock(SelectStatementContext.class, RETURNS_DEEP_STUBS);
when(sqlStatementContext.getTablesContext().getTableNames()).thenReturn(Collections.singletonList("t_order"));
when(sqlStatementContext.getWhereSegments()).thenReturn(Collections.emptyList());
- assertTrue(new EncryptParameterRewriterBuilder(encryptRule, DefaultDatabase.LOGIC_NAME, mockSchemaMap(), sqlStatementContext, Collections.emptyList()).getParameterRewriters().isEmpty());
- }
-
- private Map<String, ShardingSphereSchema> mockSchemaMap() {
- Map<String, ShardingSphereSchema> result = new HashMap<>(1, 1);
- result.put("test", mock(ShardingSphereSchema.class));
- return result;
+ assertTrue(new EncryptParameterRewriterBuilder(encryptRule,
+ DefaultDatabase.LOGIC_NAME, Collections.singletonMap("test", mock(ShardingSphereSchema.class)), sqlStatementContext, Collections.emptyList()).getParameterRewriters().isEmpty());
}
}
diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/DropEncryptRuleStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/DropEncryptRuleStatementUpdaterTest.java
index 621d8dbb1de..046b9e69fb9 100644
--- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/DropEncryptRuleStatementUpdaterTest.java
+++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/DropEncryptRuleStatementUpdaterTest.java
@@ -92,16 +92,15 @@ public final class DropEncryptRuleStatementUpdaterTest {
private EncryptRuleConfiguration createCurrentRuleConfiguration() {
EncryptColumnRuleConfiguration columnRuleConfig = new EncryptColumnRuleConfiguration("user_id", "user_cipher", "", "user_plain", "t_encrypt_user_id_MD5");
EncryptTableRuleConfiguration tableRuleConfig = new EncryptTableRuleConfiguration("t_encrypt", Collections.singleton(columnRuleConfig), null);
- Map<String, ShardingSphereAlgorithmConfiguration> encryptors = new HashMap<>(1, 1);
- encryptors.put("t_encrypt_user_id_MD5", new ShardingSphereAlgorithmConfiguration("TEST", new Properties()));
+ Map<String, ShardingSphereAlgorithmConfiguration> encryptors = new HashMap<>(
+ Collections.singletonMap("t_encrypt_user_id_MD5", new ShardingSphereAlgorithmConfiguration("TEST", new Properties())));
return new EncryptRuleConfiguration(new LinkedList<>(Collections.singleton(tableRuleConfig)), encryptors, true);
}
private EncryptRuleConfiguration createCurrentRuleConfigurationWithMultipleTableRules() {
EncryptColumnRuleConfiguration columnRuleConfig = new EncryptColumnRuleConfiguration("user_id", "user_cipher", "", "user_plain", "t_encrypt_user_id_MD5");
EncryptTableRuleConfiguration tableRuleConfig = new EncryptTableRuleConfiguration("t_encrypt", Collections.singleton(columnRuleConfig), null);
- Map<String, ShardingSphereAlgorithmConfiguration> encryptors = new HashMap<>(1, 1);
- encryptors.put("t_encrypt_user_id_MD5", new ShardingSphereAlgorithmConfiguration("TEST", new Properties()));
+ Map<String, ShardingSphereAlgorithmConfiguration> encryptors = Collections.singletonMap("t_encrypt_user_id_MD5", new ShardingSphereAlgorithmConfiguration("TEST", new Properties()));
return new EncryptRuleConfiguration(new LinkedList<>(Arrays.asList(tableRuleConfig,
new EncryptTableRuleConfiguration("t_encrypt_another", Collections.singleton(columnRuleConfig), null))), encryptors, true);
}
diff --git a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ReadwriteSplittingRuleQueryResultSetTest.java b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/test/java/org/apache/shardingsphere/readw [...]
index 51ab3f93358..34aefb3fd87 100644
--- a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ReadwriteSplittingRuleQueryResultSetTest.java
+++ b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ReadwriteSplittingRuleQueryResultSetTest.java
@@ -105,7 +105,8 @@ public final class ReadwriteSplittingRuleQueryResultSetTest {
ExportableRule exportableRule = mock(ExportableRule.class);
when(exportableRule.containExportableKey(anyCollection())).thenReturn(true);
when(metaData.getRuleMetaData().findRules(any())).thenReturn(Collections.singletonList(exportableRule));
- when(exportableRule.export(anyCollection())).thenReturn(createAutoAwareDataSources());
+ when(exportableRule.export(anyCollection())).thenReturn(
+ Collections.singletonMap(ExportableConstants.EXPORTABLE_KEY_AUTO_AWARE_DATA_SOURCE, Collections.singletonMap("readwrite_ds", getAutoAwareDataSources())));
when(metaData.getRuleMetaData().findRuleConfiguration(any())).thenReturn(Collections.singleton(createRuleConfigurationWithAutoAwareDataSource()));
ReadwriteSplittingRuleQueryResultSet resultSet = new ReadwriteSplittingRuleQueryResultSet();
resultSet.init(metaData, mock(ShowReadwriteSplittingRulesStatement.class));
@@ -120,23 +121,10 @@ public final class ReadwriteSplittingRuleQueryResultSetTest {
private RuleConfiguration createRuleConfigurationWithAutoAwareDataSource() {
Properties props = new Properties();
props.setProperty("auto-aware-data-source-name", "rd_rs");
- ReadwriteSplittingDataSourceRuleConfiguration dataSourceRuleConfig =
- new ReadwriteSplittingDataSourceRuleConfiguration("readwrite_ds", "Dynamic", props, "");
+ ReadwriteSplittingDataSourceRuleConfiguration dataSourceRuleConfig = new ReadwriteSplittingDataSourceRuleConfiguration("readwrite_ds", "Dynamic", props, "");
return new ReadwriteSplittingRuleConfiguration(Collections.singleton(dataSourceRuleConfig), null);
}
- private Map<String, Object> createAutoAwareDataSources() {
- Map<String, Object> result = new HashMap<>(1, 1);
- result.put(ExportableConstants.EXPORTABLE_KEY_AUTO_AWARE_DATA_SOURCE, exportAutoAwareDataSourceMap());
- return result;
- }
-
- private Map<String, Map<String, String>> exportAutoAwareDataSourceMap() {
- Map<String, Map<String, String>> result = new HashMap<>(1, 1);
- result.put("readwrite_ds", getAutoAwareDataSources());
- return result;
- }
-
private Map<String, String> getAutoAwareDataSources() {
Map<String, String> result = new HashMap<>(2, 1);
result.put(ExportableConstants.PRIMARY_DATA_SOURCE_NAME, "write_ds");
diff --git a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/DropReadwriteSplittingRuleStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/test/java/org/apache/shardingspher [...]
index 7e84a6174e3..e12a3a78208 100644
--- a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/DropReadwriteSplittingRuleStatementUpdaterTest.java
+++ b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/DropReadwriteSplittingRuleStatementUpdaterTest.java
@@ -34,7 +34,6 @@ import org.mockito.junit.MockitoJUnitRunner;
import java.util.Arrays;
import java.util.Collections;
-import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.Properties;
@@ -49,11 +48,11 @@ import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
public final class DropReadwriteSplittingRuleStatementUpdaterTest {
+ private final DropReadwriteSplittingRuleStatementUpdater updater = new DropReadwriteSplittingRuleStatementUpdater();
+
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private ShardingSphereMetaData shardingSphereMetaData;
- private final DropReadwriteSplittingRuleStatementUpdater updater = new DropReadwriteSplittingRuleStatementUpdater();
-
@Test(expected = RequiredRuleMissedException.class)
public void assertCheckSQLStatementWithoutCurrentRule() throws RuleDefinitionViolationException {
updater.checkSQLStatement(shardingSphereMetaData, createSQLStatement(), null);
@@ -98,18 +97,15 @@ public final class DropReadwriteSplittingRuleStatementUpdaterTest {
}
private ReadwriteSplittingRuleConfiguration createCurrentRuleConfiguration() {
- Map<String, ShardingSphereAlgorithmConfiguration> loadBalancers = new HashMap<>(1, 1);
- loadBalancers.put("readwrite_ds", new ShardingSphereAlgorithmConfiguration("TEST", new Properties()));
- ReadwriteSplittingDataSourceRuleConfiguration dataSourceRuleConfig = new ReadwriteSplittingDataSourceRuleConfiguration("readwrite_ds",
- "Static", new Properties(), "TEST");
+ ReadwriteSplittingDataSourceRuleConfiguration dataSourceRuleConfig = new ReadwriteSplittingDataSourceRuleConfiguration("readwrite_ds", "Static", new Properties(), "TEST");
+ Map<String, ShardingSphereAlgorithmConfiguration> loadBalancers = Collections.singletonMap("readwrite_ds", new ShardingSphereAlgorithmConfiguration("TEST", new Properties()));
return new ReadwriteSplittingRuleConfiguration(new LinkedList<>(Collections.singleton(dataSourceRuleConfig)), loadBalancers);
}
private ReadwriteSplittingRuleConfiguration createMultipleCurrentRuleConfigurations() {
- Map<String, ShardingSphereAlgorithmConfiguration> loadBalancers = new HashMap<>(1, 1);
- loadBalancers.put("readwrite_ds", new ShardingSphereAlgorithmConfiguration("TEST", new Properties()));
- ReadwriteSplittingDataSourceRuleConfiguration dataSourceRuleConfig = new ReadwriteSplittingDataSourceRuleConfiguration("readwrite_ds", "Static", new Properties(), "TEST");
- return new ReadwriteSplittingRuleConfiguration(new LinkedList<>(Arrays.asList(dataSourceRuleConfig,
- new ReadwriteSplittingDataSourceRuleConfiguration("readwrite_ds_another", "Static", new Properties(), "TEST"))), loadBalancers);
+ ReadwriteSplittingDataSourceRuleConfiguration fooDataSourceRuleConfig = new ReadwriteSplittingDataSourceRuleConfiguration("foo_ds", "Static", new Properties(), "TEST");
+ ReadwriteSplittingDataSourceRuleConfiguration barDataSourceRuleConfig = new ReadwriteSplittingDataSourceRuleConfiguration("bar_ds", "Static", new Properties(), "TEST");
+ Map<String, ShardingSphereAlgorithmConfiguration> loadBalancers = Collections.singletonMap("foo_ds", new ShardingSphereAlgorithmConfiguration("TEST", new Properties()));
+ return new ReadwriteSplittingRuleConfiguration(new LinkedList<>(Arrays.asList(fooDataSourceRuleConfig, barDataSourceRuleConfig)), loadBalancers);
}
}
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dal/show/ShowCreateTableMergedResultTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dal/show/ShowCreateTableMergedResultTest.java
index 2b2d968aeca..e557d07fcc8 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dal/show/ShowCreateTableMergedResultTest.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dal/show/ShowCreateTableMergedResultTest.java
@@ -29,10 +29,8 @@ import org.junit.Before;
import org.junit.Test;
import java.sql.SQLException;
-import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
-import java.util.LinkedList;
import java.util.Map;
import static org.hamcrest.CoreMatchers.is;
@@ -56,27 +54,20 @@ public final class ShowCreateTableMergedResultTest {
}
private ShardingRule buildShardingRule() {
- ShardingTableRuleConfiguration orderTableRuleConfig = new ShardingTableRuleConfiguration("t_order", "ds.t_order_${0..2}");
- ShardingTableRuleConfiguration userTableRuleConfig = new ShardingTableRuleConfiguration("t_user", "ds.t_user_${0..2}");
ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
- shardingRuleConfig.getTables().add(orderTableRuleConfig);
- shardingRuleConfig.getTables().add(userTableRuleConfig);
+ shardingRuleConfig.getTables().add(new ShardingTableRuleConfiguration("t_order", "ds.t_order_${0..2}"));
+ shardingRuleConfig.getTables().add(new ShardingTableRuleConfiguration("t_user", "ds.t_user_${0..2}"));
return new ShardingRule(shardingRuleConfig, Collections.singletonList("ds"));
}
private ShardingSphereSchema buildSchema() {
- Map<String, TableMetaData> tableMetaDataMap = new HashMap<>(1, 1);
- tableMetaDataMap.put("t_order", new TableMetaData("t_order", Collections.emptyList(), Collections.emptyList(), buildConstraintMetaData()));
+ Map<String, TableMetaData> tableMetaDataMap = new HashMap<>(2, 1);
+ tableMetaDataMap.put("t_order",
+ new TableMetaData("t_order", Collections.emptyList(), Collections.emptyList(), Collections.singleton(new ConstraintMetaData("t_order_foreign_key", "t_user"))));
tableMetaDataMap.put("t_user", new TableMetaData("t_user", Collections.emptyList(), Collections.emptyList(), Collections.emptyList()));
return new ShardingSphereSchema(tableMetaDataMap);
}
- private Collection<ConstraintMetaData> buildConstraintMetaData() {
- Collection<ConstraintMetaData> result = new LinkedList<>();
- result.add(new ConstraintMetaData("t_order_foreign_key", "t_user"));
- return result;
- }
-
@Test
public void assertNextForEmptyQueryResult() throws SQLException {
assertFalse(new ShowCreateTableMergedResult(shardingRule, mock(SQLStatementContext.class), schema, Collections.emptyList()).next());
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dal/show/ShowTableStatusMergedResultTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dal/show/ShowTableStatusMergedResultTest.java
index 14feddc8a5a..a2044c259f4 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dal/show/ShowTableStatusMergedResultTest.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dal/show/ShowTableStatusMergedResultTest.java
@@ -35,8 +35,6 @@ import java.math.BigInteger;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -56,7 +54,13 @@ public final class ShowTableStatusMergedResultTest {
@Before
public void setUp() {
shardingRule = buildShardingRule();
- schema = buildSchema();
+ schema = new ShardingSphereSchema(Collections.singletonMap("table", new TableMetaData("table", Collections.emptyList(), Collections.emptyList(), Collections.emptyList())));
+ }
+
+ private ShardingRule buildShardingRule() {
+ ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
+ shardingRuleConfig.getTables().add(new ShardingTableRuleConfiguration("table", "ds.table_${0..2}"));
+ return new ShardingRule(shardingRuleConfig, Collections.singletonList("ds"));
}
@Test
@@ -95,17 +99,4 @@ public final class ShowTableStatusMergedResultTest {
when(result.getValue(18, Object.class)).thenReturn("");
return result;
}
-
- private ShardingRule buildShardingRule() {
- ShardingTableRuleConfiguration tableRuleConfig = new ShardingTableRuleConfiguration("table", "ds.table_${0..2}");
- ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
- shardingRuleConfig.getTables().add(tableRuleConfig);
- return new ShardingRule(shardingRuleConfig, Collections.singletonList("ds"));
- }
-
- private ShardingSphereSchema buildSchema() {
- Map<String, TableMetaData> tableMetaDataMap = new HashMap<>(1, 1);
- tableMetaDataMap.put("table", new TableMetaData("table", Collections.emptyList(), Collections.emptyList(), Collections.emptyList()));
- return new ShardingSphereSchema(tableMetaDataMap);
- }
}
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dal/show/ShowTablesMergedResultTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dal/show/ShowTablesMergedResultTest.java
index e008474fd9a..4ba47d1d0b5 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dal/show/ShowTablesMergedResultTest.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dal/show/ShowTablesMergedResultTest.java
@@ -29,8 +29,6 @@ import org.junit.Test;
import java.sql.SQLException;
import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -46,21 +44,24 @@ public final class ShowTablesMergedResultTest {
@Before
public void setUp() {
- shardingRule = buildShardingRule();
- schema = buildSchema();
+ shardingRule = createShardingRule();
+ schema = new ShardingSphereSchema(Collections.singletonMap("table", new TableMetaData("table", Collections.emptyList(), Collections.emptyList(), Collections.emptyList())));
}
- private ShardingRule buildShardingRule() {
- ShardingTableRuleConfiguration tableRuleConfig = new ShardingTableRuleConfiguration("table", "ds.table_${0..2}");
+ private ShardingRule createShardingRule() {
ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
- shardingRuleConfig.getTables().add(tableRuleConfig);
- return new ShardingRule(shardingRuleConfig, Collections.singletonList("ds"));
+ shardingRuleConfig.getTables().add(new ShardingTableRuleConfiguration("table", "ds.table_${0..2}"));
+ return new ShardingRule(shardingRuleConfig, Collections.singleton("ds"));
}
- private ShardingSphereSchema buildSchema() {
- Map<String, TableMetaData> tableMetaDataMap = new HashMap<>(1, 1);
- tableMetaDataMap.put("table", new TableMetaData("table", Collections.emptyList(), Collections.emptyList(), Collections.emptyList()));
- return new ShardingSphereSchema(tableMetaDataMap);
+ @Test
+ public void assertNextForEmptyQueryResult() throws SQLException {
+ assertFalse(new LogicTablesMergedResult(shardingRule, mock(SQLStatementContext.class), schema, Collections.emptyList()).next());
+ }
+
+ @Test
+ public void assertNextForActualTableNameInTableRule() throws SQLException {
+ assertTrue(new LogicTablesMergedResult(shardingRule, mock(SQLStatementContext.class), schema, Collections.singletonList(mockQueryResult("table_0"))).next());
}
private QueryResult mockQueryResult(final String value) throws SQLException {
@@ -70,16 +71,4 @@ public final class ShowTablesMergedResultTest {
when(result.getMetaData().getColumnCount()).thenReturn(1);
return result;
}
-
- @Test
- public void assertNextForEmptyQueryResult() throws SQLException {
- LogicTablesMergedResult actual = new LogicTablesMergedResult(shardingRule, mock(SQLStatementContext.class), schema, Collections.emptyList());
- assertFalse(actual.next());
- }
-
- @Test
- public void assertNextForActualTableNameInTableRule() throws SQLException {
- LogicTablesMergedResult actual = new LogicTablesMergedResult(shardingRule, mock(SQLStatementContext.class), schema, Collections.singletonList(mockQueryResult("table_0")));
- assertTrue(actual.next());
- }
}
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/scaling/distsql/handler/update/CreateShardingScalingRuleStatementUpdater.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/scaling/distsql/handler/update/CreateShardingScalingRuleStatementUpdater.java
index 37ad0fa5ac6..a05ed434d5c 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/scaling/distsql/handler/update/CreateShardingScalingRuleStatementUpdater.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/scaling/distsql/handler/update/CreateShardingScalingRuleStatementUpdater.java
@@ -36,8 +36,6 @@ import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.spi.exception.ServiceProviderNotFoundException;
import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
import java.util.Properties;
/**
@@ -116,21 +114,12 @@ public final class CreateShardingScalingRuleStatementUpdater implements RuleDefi
@Override
public ShardingRuleConfiguration buildToBeCreatedRuleConfiguration(final CreateShardingScalingRuleStatement sqlStatement) {
ShardingRuleConfiguration result = new ShardingRuleConfiguration();
- Map<String, OnRuleAlteredActionConfiguration> scalingConfigurationMap = new HashMap<>(1, 1);
- scalingConfigurationMap.put(sqlStatement.getScalingName(), buildScalingConfiguration(sqlStatement.getScalingRuleConfigSegment()));
- result.setScaling(scalingConfigurationMap);
+ result.setScaling(Collections.singletonMap(sqlStatement.getScalingName(), buildScalingConfiguration(sqlStatement.getScalingRuleConfigSegment())));
return result;
}
private OnRuleAlteredActionConfiguration buildScalingConfiguration(final ShardingScalingRuleConfigurationSegment segment) {
- if (null == segment) {
- return buildNullScalingConfiguration();
- }
- return ShardingScalingRuleStatementConverter.convert(segment);
- }
-
- private OnRuleAlteredActionConfiguration buildNullScalingConfiguration() {
- return null;
+ return null == segment ? null : ShardingScalingRuleStatementConverter.convert(segment);
}
@Override
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/scaling/distsql/handler/query/ShardingScalingRulesQueryResultSetTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/scaling/distsql/handler/query/ShardingScalingRulesQueryResultSetTest.java
index 64e71059592..60f9ad0c5ee 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/scaling/distsql/handler/query/ShardingScalingRulesQueryResultSetTest.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/scaling/distsql/handler/query/ShardingScalingRulesQueryResultSetTest.java
@@ -29,9 +29,7 @@ import org.junit.Test;
import java.util.ArrayList;
import java.util.Collections;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
import java.util.Properties;
import static org.hamcrest.CoreMatchers.containsString;
@@ -64,32 +62,26 @@ public final class ShardingScalingRulesQueryResultSetTest {
}
private RuleConfiguration createRuleConfiguration() {
- Map<String, OnRuleAlteredActionConfiguration> scalingRuleConfigurationMap = new HashMap<>(1, 1);
- scalingRuleConfigurationMap.put("scaling_name", buildCompleteConfiguration());
ShardingRuleConfiguration result = new ShardingRuleConfiguration();
- result.setScaling(scalingRuleConfigurationMap);
+ result.setScaling(Collections.singletonMap("scaling_name", buildCompleteConfiguration()));
return result;
}
private OnRuleAlteredActionConfiguration buildCompleteConfiguration() {
InputConfiguration inputConfig = createInputConfiguration("QPS", newProperties("qps", "50"));
OutputConfiguration outputConfig = createOutputConfiguration("TPS", newProperties("tps", "2000"));
- ShardingSphereAlgorithmConfiguration streamChannel = createAlgorithm("MEMORY", newProperties("block-queue-size", "10000"));
- ShardingSphereAlgorithmConfiguration completionDetector = createAlgorithm("IDLE", newProperties("incremental-task-idle-seconds-threshold", "1800"));
- ShardingSphereAlgorithmConfiguration dataConsistencyChecker = createAlgorithm("DATA_MATCH", newProperties("chunk-size", "1000"));
+ ShardingSphereAlgorithmConfiguration streamChannel = new ShardingSphereAlgorithmConfiguration("MEMORY", newProperties("block-queue-size", "10000"));
+ ShardingSphereAlgorithmConfiguration completionDetector = new ShardingSphereAlgorithmConfiguration("IDLE", newProperties("incremental-task-idle-seconds-threshold", "1800"));
+ ShardingSphereAlgorithmConfiguration dataConsistencyChecker = new ShardingSphereAlgorithmConfiguration("DATA_MATCH", newProperties("chunk-size", "1000"));
return new OnRuleAlteredActionConfiguration(inputConfig, outputConfig, streamChannel, completionDetector, dataConsistencyChecker);
}
private InputConfiguration createInputConfiguration(final String type, final Properties props) {
- return new InputConfiguration(10, 100, 10, createAlgorithm(type, props));
+ return new InputConfiguration(10, 100, 10, new ShardingSphereAlgorithmConfiguration(type, props));
}
private OutputConfiguration createOutputConfiguration(final String type, final Properties props) {
- return new OutputConfiguration(10, 100, createAlgorithm(type, props));
- }
-
- private ShardingSphereAlgorithmConfiguration createAlgorithm(final String type, final Properties props) {
- return new ShardingSphereAlgorithmConfiguration(type, props);
+ return new OutputConfiguration(10, 100, new ShardingSphereAlgorithmConfiguration(type, props));
}
private Properties newProperties(final String key, final String value) {
diff --git a/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/insert/keygen/engine/GeneratedKeyContextEngineTest.java b/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/insert/keygen/engine/GeneratedKeyContextEngineTest.java
index 820645e303f..88ead2d06ec 100644
--- a/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/insert/keygen/engine/GeneratedKeyContextEngineTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/insert/keygen/engine/GeneratedKeyContextEngineTest.java
@@ -44,10 +44,8 @@ import org.mockito.junit.MockitoJUnitRunner;
import java.sql.Types;
import java.util.Collections;
-import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
-import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
@@ -63,10 +61,9 @@ public final class GeneratedKeyContextEngineTest {
@Before
public void setUp() {
- TableMetaData tableMetaData = new TableMetaData("tbl", Collections.singletonList(new ColumnMetaData("id", Types.INTEGER, true, true, false)), Collections.emptyList(), Collections.emptyList());
- Map<String, TableMetaData> tableMetaDataMap = new HashMap<>(1, 1);
- tableMetaDataMap.put("tbl", tableMetaData);
- schema = new ShardingSphereSchema(tableMetaDataMap);
+ TableMetaData tableMetaData = new TableMetaData(
+ "tbl", Collections.singletonList(new ColumnMetaData("id", Types.INTEGER, true, true, false)), Collections.emptyList(), Collections.emptyList());
+ schema = new ShardingSphereSchema(Collections.singletonMap("tbl", tableMetaData));
}
@Test
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/yaml/config/pojo/rulealtered/YamlOnRuleAlteredActionConfiguration.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/yaml/config/pojo/rulealtered/YamlOnRuleAlteredActionConfiguration.java
index 5a1caa7dbef..80f510f2dac 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/yaml/config/pojo/rulealtered/YamlOnRuleAlteredActionConfiguration.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/yaml/config/pojo/rulealtered/YamlOnRuleAlteredActionConfiguration.java
@@ -105,7 +105,7 @@ public final class YamlOnRuleAlteredActionConfiguration implements YamlConfigura
public static YamlOutputConfiguration buildWithDefaultValue() {
return new YamlOutputConfiguration();
}
-
+
/**
* Fill in null fields with default value.
*/
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/datasource/pool/creator/DataSourcePoolCreatorTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/datasource/pool/creator/DataSourcePoolCreatorTest.java
index 6f8ff695071..62f1587a655 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/datasource/pool/creator/DataSourcePoolCreatorTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/datasource/pool/creator/DataSourcePoolCreatorTest.java
@@ -22,7 +22,7 @@ import org.apache.shardingsphere.test.mock.MockedDataSource;
import org.junit.Test;
import javax.sql.DataSource;
-import java.util.HashMap;
+import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
@@ -34,17 +34,14 @@ public final class DataSourcePoolCreatorTest {
@Test
public void assertCreateMap() {
- Map<String, DataSourceProperties> dataSourcePropsMap = new HashMap<>(1, 1);
- dataSourcePropsMap.put("foo_ds", new DataSourceProperties(MockedDataSource.class.getName(), createProperties()));
- Map<String, DataSource> actual = DataSourcePoolCreator.create(dataSourcePropsMap);
+ Map<String, DataSource> actual = DataSourcePoolCreator.create(Collections.singletonMap("foo_ds", new DataSourceProperties(MockedDataSource.class.getName(), createProperties())));
assertThat(actual.size(), is(1));
assertDataSource((MockedDataSource) actual.get("foo_ds"));
}
@Test
public void assertCreate() {
- MockedDataSource actual = (MockedDataSource) DataSourcePoolCreator.create(new DataSourceProperties(MockedDataSource.class.getName(), createProperties()));
- assertDataSource(actual);
+ assertDataSource((MockedDataSource) DataSourcePoolCreator.create(new DataSourceProperties(MockedDataSource.class.getName(), createProperties())));
}
private Map<String, Object> createProperties() {
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/datasource/pool/metadata/fixture/MockedDataSourcePoolMetaData.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/datasource/pool/metadata/fixture/MockedDataSourcePoolMetaData.java
index 5f6b2b7f575..cd53a7bf19a 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/datasource/pool/metadata/fixture/MockedDataSourcePoolMetaData.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/datasource/pool/metadata/fixture/MockedDataSourcePoolMetaData.java
@@ -28,9 +28,7 @@ public final class MockedDataSourcePoolMetaData implements DataSourcePoolMetaDat
@Override
public Map<String, Object> getDefaultProperties() {
- Map<String, Object> result = new HashMap<>(1, 1);
- result.put("maxPoolSize", 100);
- return result;
+ return Collections.singletonMap("maxPoolSize", 100);
}
@Override
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/util/IndexMetaDataUtilTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/util/IndexMetaDataUtilTest.java
index a92fa884c9f..cc8cf952eea 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/util/IndexMetaDataUtilTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/util/IndexMetaDataUtilTest.java
@@ -37,7 +37,6 @@ import org.junit.Test;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
-import java.util.HashMap;
import java.util.Map;
import static org.hamcrest.CoreMatchers.is;
@@ -93,8 +92,7 @@ public final class IndexMetaDataUtilTest {
private ShardingSphereMetaData buildMetaData() {
TableMetaData tableMetaData = new TableMetaData(TABLE_NAME, Collections.emptyList(), Collections.singletonList(new IndexMetaData(INDEX_NAME)), Collections.emptyList());
- Map<String, TableMetaData> tables = new HashMap<>(1, 1);
- tables.put(TABLE_NAME, tableMetaData);
+ Map<String, TableMetaData> tables = Collections.singletonMap(TABLE_NAME, tableMetaData);
Map<String, ShardingSphereSchema> schemas = Collections.singletonMap(DefaultDatabase.LOGIC_NAME, new ShardingSphereSchema(tables));
return new ShardingSphereMetaData(DefaultDatabase.LOGIC_NAME, mock(DatabaseType.class), mock(ShardingSphereResource.class), mock(ShardingSphereRuleMetaData.class), schemas);
}
diff --git a/shardingsphere-infra/shardingsphere-infra-rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/context/SQLRewriteContextTest.java b/shardingsphere-infra/shardingsphere-infra-rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/context/SQLRewriteContextTest.java
index 8089f7e02b5..99e7e75768d 100644
--- a/shardingsphere-infra/shardingsphere-infra-rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/context/SQLRewriteContextTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/context/SQLRewriteContextTest.java
@@ -35,8 +35,6 @@ import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.junit.Assert.assertFalse;
@@ -49,7 +47,7 @@ import static org.mockito.Mockito.when;
public final class SQLRewriteContextTest {
@Mock
- private SQLStatementContext sqlStatementContext;
+ private SQLStatementContext<?> sqlStatementContext;
@Mock
private SQLToken sqlToken;
@@ -60,6 +58,7 @@ public final class SQLRewriteContextTest {
@Mock
private CollectionSQLTokenGenerator collectionSQLTokenGenerator;
+ @SuppressWarnings("unchecked")
@Before
public void setUp() {
when(optionalSQLTokenGenerator.generateSQLToken(sqlStatementContext)).thenReturn(sqlToken);
@@ -72,7 +71,7 @@ public final class SQLRewriteContextTest {
when(((TableAvailable) statementContext).getTablesContext().getDatabaseName().isPresent()).thenReturn(false);
when(statementContext.getInsertSelectContext()).thenReturn(null);
SQLRewriteContext sqlRewriteContext = new SQLRewriteContext(DefaultDatabase.LOGIC_NAME,
- mockSchemaMap(), statementContext, "INSERT INTO tbl VALUES (?)", Collections.singletonList(1));
+ Collections.singletonMap("test", mock(ShardingSphereSchema.class)), statementContext, "INSERT INTO tbl VALUES (?)", Collections.singletonList(1));
assertThat(sqlRewriteContext.getParameterBuilder(), instanceOf(GroupedParameterBuilder.class));
}
@@ -81,14 +80,14 @@ public final class SQLRewriteContextTest {
SelectStatementContext statementContext = mock(SelectStatementContext.class, RETURNS_DEEP_STUBS);
when(((TableAvailable) statementContext).getTablesContext().getDatabaseName().isPresent()).thenReturn(false);
SQLRewriteContext sqlRewriteContext = new SQLRewriteContext(DefaultDatabase.LOGIC_NAME,
- mockSchemaMap(), statementContext, "SELECT * FROM tbl WHERE id = ?", Collections.singletonList(1));
+ Collections.singletonMap("test", mock(ShardingSphereSchema.class)), statementContext, "SELECT * FROM tbl WHERE id = ?", Collections.singletonList(1));
assertThat(sqlRewriteContext.getParameterBuilder(), instanceOf(StandardParameterBuilder.class));
}
@Test
public void assertGenerateOptionalSQLToken() {
SQLRewriteContext sqlRewriteContext = new SQLRewriteContext(DefaultDatabase.LOGIC_NAME,
- mockSchemaMap(), sqlStatementContext, "INSERT INTO tbl VALUES (?)", Collections.singletonList(1));
+ Collections.singletonMap("test", mock(ShardingSphereSchema.class)), sqlStatementContext, "INSERT INTO tbl VALUES (?)", Collections.singletonList(1));
sqlRewriteContext.addSQLTokenGenerators(Collections.singleton(optionalSQLTokenGenerator));
sqlRewriteContext.generateSQLTokens();
assertFalse(sqlRewriteContext.getSqlTokens().isEmpty());
@@ -98,16 +97,10 @@ public final class SQLRewriteContextTest {
@Test
public void assertGenerateCollectionSQLToken() {
SQLRewriteContext sqlRewriteContext = new SQLRewriteContext(DefaultDatabase.LOGIC_NAME,
- mockSchemaMap(), sqlStatementContext, "INSERT INTO tbl VALUES (?)", Collections.singletonList(1));
+ Collections.singletonMap("test", mock(ShardingSphereSchema.class)), sqlStatementContext, "INSERT INTO tbl VALUES (?)", Collections.singletonList(1));
sqlRewriteContext.addSQLTokenGenerators(Collections.singleton(collectionSQLTokenGenerator));
sqlRewriteContext.generateSQLTokens();
assertFalse(sqlRewriteContext.getSqlTokens().isEmpty());
assertThat(sqlRewriteContext.getSqlTokens().get(0), instanceOf(SQLToken.class));
}
-
- private Map<String, ShardingSphereSchema> mockSchemaMap() {
- Map<String, ShardingSphereSchema> result = new HashMap<>(1, 1);
- result.put("test", mock(ShardingSphereSchema.class));
- return result;
- }
}
diff --git a/shardingsphere-infra/shardingsphere-infra-rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/sql/token/generator/SQLTokenGeneratorsTest.java b/shardingsphere-infra/shardingsphere-infra-rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/sql/token/generator/SQLTokenGeneratorsTest.java
index e72c29e133c..0854b9ffb4c 100644
--- a/shardingsphere-infra/shardingsphere-infra-rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/sql/token/generator/SQLTokenGeneratorsTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/sql/token/generator/SQLTokenGeneratorsTest.java
@@ -29,7 +29,6 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
-import java.util.HashMap;
import java.util.Map;
import static org.hamcrest.CoreMatchers.is;
@@ -77,7 +76,8 @@ public final class SQLTokenGeneratorsTest {
sqlTokenGenerators.addAll(Collections.singleton(optionalSQLTokenGenerator));
SQLToken expectedToken = mock(SQLToken.class);
when(optionalSQLTokenGenerator.generateSQLToken(any(SQLStatementContext.class))).thenReturn(expectedToken);
- Collection<SQLToken> actualSqlTokens = sqlTokenGenerators.generateSQLTokens("sharding_db", mockSchemaMap(), mock(SQLStatementContext.class), Collections.emptyList());
+ Collection<SQLToken> actualSqlTokens = sqlTokenGenerators.generateSQLTokens(
+ "sharding_db", Collections.singletonMap("test", mock(ShardingSphereSchema.class)), mock(SQLStatementContext.class), Collections.emptyList());
assertThat(actualSqlTokens.size(), is(1));
assertThat(actualSqlTokens.iterator().next(), is(expectedToken));
}
@@ -90,7 +90,8 @@ public final class SQLTokenGeneratorsTest {
sqlTokenGenerators.addAll(Collections.singleton(collectionSQLTokenGenerator));
Collection<SQLToken> expectedSQLTokens = Arrays.asList(mock(SQLToken.class), mock(SQLToken.class));
doReturn(expectedSQLTokens).when(collectionSQLTokenGenerator).generateSQLTokens(any());
- Collection<SQLToken> actualSQLTokens = sqlTokenGenerators.generateSQLTokens("sharding_db", mockSchemaMap(), mock(SQLStatementContext.class), Collections.emptyList());
+ Collection<SQLToken> actualSQLTokens = sqlTokenGenerators.generateSQLTokens(
+ "sharding_db", Collections.singletonMap("test", mock(ShardingSphereSchema.class)), mock(SQLStatementContext.class), Collections.emptyList());
assertThat(actualSQLTokens.size(), is(2));
assertThat(actualSQLTokens, is(expectedSQLTokens));
}
@@ -101,10 +102,4 @@ public final class SQLTokenGeneratorsTest {
field.setAccessible(true);
return (Map<Class<?>, SQLTokenGenerator>) field.get(sqlTokenGenerators);
}
-
- private Map<String, ShardingSphereSchema> mockSchemaMap() {
- Map<String, ShardingSphereSchema> result = new HashMap<>(1, 1);
- result.put("test", mock(ShardingSphereSchema.class));
- return result;
- }
}
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/api/yaml/YamlShardingSphereDataSourceFactory.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/api/yaml/YamlShardingSphereDataSourceFactory.java
index 4720eb36975..70f42844527 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/api/yaml/YamlShardingSphereDataSourceFactory.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/api/yaml/YamlShardingSphereDataSourceFactory.java
@@ -35,7 +35,8 @@ import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
import java.util.Collection;
-import java.util.HashMap;
+import java.util.Collections;
+import java.util.LinkedHashMap;
import java.util.Map;
/**
@@ -133,8 +134,8 @@ public final class YamlShardingSphereDataSourceFactory {
}
private static DataSource createDataSource(final DataSource dataSource, final YamlRootConfiguration rootConfig) throws SQLException {
- Map<String, DataSource> dataSourceMap = new HashMap<>(1, 1);
- dataSourceMap.put(Strings.isNullOrEmpty(rootConfig.getDatabaseName()) ? DefaultDatabase.LOGIC_NAME : rootConfig.getDatabaseName(), dataSource);
+ Map<String, DataSource> dataSourceMap = new LinkedHashMap<>(
+ Collections.singletonMap(Strings.isNullOrEmpty(rootConfig.getDatabaseName()) ? DefaultDatabase.LOGIC_NAME : rootConfig.getDatabaseName(), dataSource));
return createDataSource(dataSourceMap, rootConfig);
}
}
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/datasource/metadata/ShardingSphereDatabaseMetaDataTest.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/datasource/metadata/ShardingSphereDatabaseMetaDataTest.java
index d7ca624ab6d..9c3986bde23 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/datasource/metadata/ShardingSphereDatabaseMetaDataTest.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/datasource/metadata/ShardingSphereDatabaseMetaDataTest.java
@@ -77,7 +77,7 @@ public final class ShardingSphereDatabaseMetaDataTest {
@Mock
private MetaDataContexts metaDataContexts;
- private final Map<String, DataSource> dataSourceMap = new HashMap<>(1, 1);
+ private final Map<String, DataSource> dataSourceMap = new HashMap<>();
private ShardingSphereDatabaseMetaData shardingSphereDatabaseMetaData;
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 347d1bb8da2..4227e34a0bb 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
@@ -38,7 +38,6 @@ import org.apache.shardingsphere.singletable.datanode.SingleTableDataNodeLoader;
import javax.sql.DataSource;
import java.util.Collection;
import java.util.Collections;
-import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
@@ -270,8 +269,6 @@ public final class SingleTableRule implements SchemaRule, DataNodeContainedRule,
@Override
public Map<String, Supplier<Object>> getExportedMethods() {
- Map<String, Supplier<Object>> result = new HashMap<>(1, 1);
- result.put(ExportableConstants.EXPORTABLE_KEY_SINGLE_TABLES, tableNames::keySet);
- return result;
+ return Collections.singletonMap(ExportableConstants.EXPORTABLE_KEY_SINGLE_TABLES, tableNames::keySet);
}
}
diff --git a/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-core/src/test/java/org/apache/shardingsphere/traffic/rule/TrafficRuleTest.java b/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-core/src/test/java/org/apache/shardingsphere/traffic/rule/TrafficRuleTest.java
index 81bff3ad1af..56f4a8ff1fe 100644
--- a/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-core/src/test/java/org/apache/shardingsphere/traffic/rule/TrafficRuleTest.java
+++ b/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-core/src/test/java/org/apache/shardingsphere/traffic/rule/TrafficRuleTest.java
@@ -17,7 +17,6 @@
package org.apache.shardingsphere.traffic.rule;
-import com.google.common.collect.Sets;
import org.apache.shardingsphere.infra.binder.LogicSQL;
import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
@@ -34,10 +33,8 @@ import org.apache.shardingsphere.traffic.api.config.TrafficStrategyConfiguration
import org.junit.Test;
import java.util.Arrays;
-import java.util.Collection;
import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
+import java.util.HashSet;
import java.util.Optional;
import java.util.Properties;
@@ -57,16 +54,14 @@ public final class TrafficRuleTest {
Optional<TrafficStrategyRule> actual = trafficRule.findMatchedStrategyRule(createLogicSQL(true), false);
assertTrue(actual.isPresent());
assertThat(actual.get().getName(), is("sql_hint_traffic"));
- assertThat(actual.get().getLabels(), is(Sets.newHashSet("OLTP", "OLAP")));
+ assertThat(actual.get().getLabels(), is(new HashSet<>(Arrays.asList("OLTP", "OLAP"))));
assertThat(actual.get().getTrafficAlgorithm(), instanceOf(SQLHintTrafficAlgorithm.class));
assertThat(actual.get().getLoadBalancer(), instanceOf(RandomTrafficLoadBalanceAlgorithm.class));
}
@Test
public void assertFindMatchedStrategyRuleWhenSQLHintNotMatch() {
- TrafficRule trafficRule = new TrafficRule(createTrafficRuleConfig());
- Optional<TrafficStrategyRule> actual = trafficRule.findMatchedStrategyRule(createLogicSQL(false), false);
- assertFalse(actual.isPresent());
+ assertFalse(new TrafficRule(createTrafficRuleConfig()).findMatchedStrategyRule(createLogicSQL(false), false).isPresent());
}
@Test
@@ -75,37 +70,28 @@ public final class TrafficRuleTest {
Optional<TrafficStrategyRule> actual = trafficRule.findMatchedStrategyRule(createLogicSQL(false), true);
assertTrue(actual.isPresent());
assertThat(actual.get().getName(), is("transaction_traffic"));
- assertThat(actual.get().getLabels(), is(Sets.newHashSet("OLAP")));
+ assertThat(actual.get().getLabels(), is(Collections.singleton("OLAP")));
assertThat(actual.get().getTrafficAlgorithm(), instanceOf(ProxyTrafficAlgorithm.class));
assertThat(actual.get().getLoadBalancer(), instanceOf(RandomTrafficLoadBalanceAlgorithm.class));
}
@Test
public void assertGetLabels() {
- TrafficRule trafficRule = new TrafficRule(createTrafficRuleConfig());
- Collection<String> actual = trafficRule.getLabels();
- assertThat(actual, is(Sets.newHashSet("OLAP", "OLTP")));
+ assertThat(new TrafficRule(createTrafficRuleConfig()).getLabels(), is(new HashSet<>(Arrays.asList("OLAP", "OLTP"))));
}
@SuppressWarnings({"rawtypes", "unchecked"})
private LogicSQL createLogicSQL(final boolean includeComments) {
LogicSQL result = mock(LogicSQL.class);
MySQLSelectStatement sqlStatement = mock(MySQLSelectStatement.class);
- Collection<CommentSegment> comments = includeComments ? Collections.singletonList(
- new CommentSegment("/* ShardingSphere hint: useTraffic=true */", 0, 0)) : Collections.emptyList();
- when(sqlStatement.getCommentSegments()).thenReturn(comments);
+ when(sqlStatement.getCommentSegments()).thenReturn(includeComments ? Collections.singleton(new CommentSegment("/* ShardingSphere hint: useTraffic=true */", 0, 0)) : Collections.emptyList());
when(sqlStatement.getProjections()).thenReturn(new ProjectionsSegment(0, 0));
- SQLStatementContext statementContext = new SelectStatementContext(createMetaDataMap(), Collections.emptyList(), sqlStatement, "sharding_db");
+ SQLStatementContext statementContext = new SelectStatementContext(
+ Collections.singletonMap("sharding_db", mock(ShardingSphereMetaData.class)), Collections.emptyList(), sqlStatement, "sharding_db");
when(result.getSqlStatementContext()).thenReturn(statementContext);
return result;
}
- private Map<String, ShardingSphereMetaData> createMetaDataMap() {
- Map<String, ShardingSphereMetaData> result = new HashMap<>(1, 1);
- result.put("sharding_db", mock(ShardingSphereMetaData.class));
- return result;
- }
-
private TrafficRuleConfiguration createTrafficRuleConfig() {
TrafficRuleConfiguration result = new TrafficRuleConfiguration();
result.getTrafficStrategies().add(new TrafficStrategyConfiguration("sql_hint_traffic", Arrays.asList("OLTP", "OLAP"), "sql_hint_match", "random"));
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ExportDatabaseConfigurationHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ExportDatabaseConfigurationHandlerTest.java
index 7d347fc5ab1..6970c27dc22 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ExportDatabaseConfigurationHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ExportDatabaseConfigurationHandlerTest.java
@@ -44,7 +44,6 @@ import javax.sql.DataSource;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
-import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -72,7 +71,7 @@ public final class ExportDatabaseConfigurationHandlerTest {
@Test
public void assertExportDatabaseExecutor() throws SQLException {
- ExportDatabaseConfigurationHandler handler = new ExportDatabaseConfigurationHandler().init(getParameter(createSQLStatement(), mock(ConnectionSession.class)));
+ ExportDatabaseConfigurationHandler handler = new ExportDatabaseConfigurationHandler().init(createParameter(createSQLStatement(), mock(ConnectionSession.class)));
handler.execute();
handler.next();
List<Object> data = new ArrayList<>(handler.getRowData());
@@ -119,11 +118,9 @@ public final class ExportDatabaseConfigurationHandlerTest {
}
private Map<String, TableMetaData> createTableMap() {
- Map<String, TableMetaData> result = new HashMap<>(1, 1);
List<ColumnMetaData> columns = Collections.singletonList(new ColumnMetaData("order_id", 0, false, false, false));
List<IndexMetaData> indexes = Collections.singletonList(new IndexMetaData("primary"));
- result.put("t_order", new TableMetaData("t_order", columns, indexes, Collections.emptyList()));
- return result;
+ return Collections.singletonMap("t_order", new TableMetaData("t_order", columns, indexes, Collections.emptyList()));
}
private ShardingTableRuleConfiguration createTableRuleConfiguration() {
@@ -136,7 +133,7 @@ public final class ExportDatabaseConfigurationHandlerTest {
return new ExportDatabaseConfigurationStatement(new SchemaSegment(0, 0, new IdentifierValue("sharding_db")), null);
}
- private HandlerParameter<ExportDatabaseConfigurationStatement> getParameter(final ExportDatabaseConfigurationStatement statement, final ConnectionSession connectionSession) {
+ private HandlerParameter<ExportDatabaseConfigurationStatement> createParameter(final ExportDatabaseConfigurationStatement statement, final ConnectionSession connectionSession) {
return new HandlerParameter<>(statement, new MySQLDatabaseType(), connectionSession);
}
}
diff --git a/shardingsphere-test/shardingsphere-rewrite-test/src/test/java/org/apache/shardingsphere/sharding/rewrite/parameterized/scenario/MixSQLRewriterParameterizedTest.java b/shardingsphere-test/shardingsphere-rewrite-test/src/test/java/org/apache/shardingsphere/sharding/rewrite/parameterized/scenario/MixSQLRewriterParameterizedTest.java
index 7ccc3382476..deda6f71dcb 100644
--- a/shardingsphere-test/shardingsphere-rewrite-test/src/test/java/org/apache/shardingsphere/sharding/rewrite/parameterized/scenario/MixSQLRewriterParameterizedTest.java
+++ b/shardingsphere-test/shardingsphere-rewrite-test/src/test/java/org/apache/shardingsphere/sharding/rewrite/parameterized/scenario/MixSQLRewriterParameterizedTest.java
@@ -34,12 +34,10 @@ import javax.sql.DataSource;
import java.io.File;
import java.io.IOException;
import java.net.URL;
-import java.sql.SQLException;
import java.sql.Types;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
-import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
@@ -73,9 +71,7 @@ public final class MixSQLRewriterParameterizedTest extends AbstractSQLRewriterPa
when(result.getAllTableNames()).thenReturn(Arrays.asList("t_account", "t_account_bak", "t_account_detail"));
TableMetaData accountTableMetaData = mock(TableMetaData.class);
when(accountTableMetaData.getColumns()).thenReturn(createColumnMetaDataMap());
- Map<String, IndexMetaData> indexMetaDataMap = new HashMap<>(1, 1);
- indexMetaDataMap.put("index_name", new IndexMetaData("index_name"));
- when(accountTableMetaData.getIndexes()).thenReturn(indexMetaDataMap);
+ when(accountTableMetaData.getIndexes()).thenReturn(Collections.singletonMap("index_name", new IndexMetaData("index_name")));
when(result.containsTable("t_account")).thenReturn(true);
when(result.get("t_account")).thenReturn(accountTableMetaData);
TableMetaData accountBakTableMetaData = mock(TableMetaData.class);
@@ -93,7 +89,7 @@ public final class MixSQLRewriterParameterizedTest extends AbstractSQLRewriterPa
}
@Override
- protected void mockDataSource(final Map<String, DataSource> dataSources) throws SQLException {
+ protected void mockDataSource(final Map<String, DataSource> dataSources) {
}
private Map<String, ColumnMetaData> createColumnMetaDataMap() {
diff --git a/shardingsphere-test/shardingsphere-rewrite-test/src/test/java/org/apache/shardingsphere/sharding/rewrite/parameterized/scenario/ShardingSQLRewriterParameterizedTest.java b/shardingsphere-test/shardingsphere-rewrite-test/src/test/java/org/apache/shardingsphere/sharding/rewrite/parameterized/scenario/ShardingSQLRewriterParameterizedTest.java
index acdc26b9d16..b1e944e3b4f 100644
--- a/shardingsphere-test/shardingsphere-rewrite-test/src/test/java/org/apache/shardingsphere/sharding/rewrite/parameterized/scenario/ShardingSQLRewriterParameterizedTest.java
+++ b/shardingsphere-test/shardingsphere-rewrite-test/src/test/java/org/apache/shardingsphere/sharding/rewrite/parameterized/scenario/ShardingSQLRewriterParameterizedTest.java
@@ -35,13 +35,11 @@ import javax.sql.DataSource;
import java.io.File;
import java.io.IOException;
import java.net.URL;
-import java.sql.SQLException;
import java.sql.Types;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
-import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Optional;
@@ -85,9 +83,7 @@ public final class ShardingSQLRewriterParameterizedTest extends AbstractSQLRewri
when(result.getAllTableNames()).thenReturn(Arrays.asList("t_account", "t_account_detail"));
TableMetaData accountTableMetaData = mock(TableMetaData.class);
when(accountTableMetaData.getColumns()).thenReturn(createColumnMetaDataMap());
- Map<String, IndexMetaData> indexMetaDataMap = new HashMap<>(1, 1);
- indexMetaDataMap.put("status_idx_exist", new IndexMetaData("status_idx_exist"));
- when(accountTableMetaData.getIndexes()).thenReturn(indexMetaDataMap);
+ when(accountTableMetaData.getIndexes()).thenReturn(Collections.singletonMap("status_idx_exist", new IndexMetaData("status_idx_exist")));
when(accountTableMetaData.getPrimaryKeyColumns()).thenReturn(Collections.singletonList("account_id"));
when(result.containsTable("t_account")).thenReturn(true);
when(result.get("t_account")).thenReturn(accountTableMetaData);
@@ -108,6 +104,6 @@ public final class ShardingSQLRewriterParameterizedTest extends AbstractSQLRewri
}
@Override
- protected void mockDataSource(final Map<String, DataSource> dataSources) throws SQLException {
+ protected void mockDataSource(final Map<String, DataSource> dataSources) {
}
}