You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2024/10/14 06:45:20 UTC
(shardingsphere) branch master updated: Add more test cases for GlobalRulesBuilder (#33241)
This is an automated email from the ASF dual-hosted git repository.
zhangliang 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 310837aca3d Add more test cases for GlobalRulesBuilder (#33241)
310837aca3d is described below
commit 310837aca3db77845b63a4c6d305b716168e0797
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Mon Oct 14 14:45:13 2024 +0800
Add more test cases for GlobalRulesBuilder (#33241)
* Remove useless DatabaseTypeUtils
* Add more test cases for GlobalRulesBuilder
---
.../infra/rule/builder/global/GlobalRulesBuilder.java | 12 ++++--------
.../rule/builder/global/GlobalRulesBuilderTest.java | 17 +++++++++--------
2 files changed, 13 insertions(+), 16 deletions(-)
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilder.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilder.java
index c53618fe23f..eabd82769b4 100644
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilder.java
+++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilder.java
@@ -90,13 +90,9 @@ public final class GlobalRulesBuilder {
* @param props props
* @return built rule
*/
- @SuppressWarnings({"unchecked", "rawtypes"})
- public static Collection<ShardingSphereRule> buildSingleRules(final RuleConfiguration globalRuleConfig,
- final Map<String, ShardingSphereDatabase> databases, final ConfigurationProperties props) {
- Collection<ShardingSphereRule> result = new LinkedList<>();
- for (Entry<RuleConfiguration, GlobalRuleBuilder> each : OrderedSPILoader.getServices(GlobalRuleBuilder.class, Collections.singleton(globalRuleConfig)).entrySet()) {
- result.add(each.getValue().build(each.getKey(), databases, props));
- }
- return result;
+ @SuppressWarnings("unchecked")
+ public static Collection<ShardingSphereRule> buildSingleRules(final RuleConfiguration globalRuleConfig, final Map<String, ShardingSphereDatabase> databases, final ConfigurationProperties props) {
+ return OrderedSPILoader.getServices(GlobalRuleBuilder.class, Collections.singleton(globalRuleConfig)).entrySet()
+ .stream().map(each -> each.getValue().build(each.getKey(), databases, props)).collect(Collectors.toList());
}
}
diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilderTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilderTest.java
index 97c5944f6cc..7825f71a7b7 100644
--- a/infra/common/src/test/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilderTest.java
+++ b/infra/common/src/test/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilderTest.java
@@ -32,26 +32,27 @@ import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.hamcrest.Matchers.instanceOf;
import static org.mockito.Mockito.mock;
class GlobalRulesBuilderTest {
@Test
void assertBuildRules() {
- Collection<ShardingSphereRule> shardingSphereRules = GlobalRulesBuilder
- .buildRules(Collections.singletonList(new FixtureGlobalRuleConfiguration()), Collections.singletonMap("logic_db", buildDatabase()), mock(ConfigurationProperties.class));
+ Collection<ShardingSphereRule> shardingSphereRules = GlobalRulesBuilder.buildRules(
+ Collections.singletonList(new FixtureGlobalRuleConfiguration()), Collections.singletonMap("foo_db", buildDatabase()), mock(ConfigurationProperties.class));
assertThat(shardingSphereRules.size(), is(1));
+ assertThat(shardingSphereRules.iterator().next(), instanceOf(FixtureGlobalRule.class));
}
@Test
- void assertBuildRulesClassType() {
- Collection<ShardingSphereRule> shardingSphereRules = GlobalRulesBuilder
- .buildRules(Collections.singletonList(new FixtureGlobalRuleConfiguration()), Collections.singletonMap("logic_db", buildDatabase()), mock(ConfigurationProperties.class));
- assertTrue(shardingSphereRules.toArray()[0] instanceof FixtureGlobalRule);
+ void assertBuildSingleRules() {
+ Collection<ShardingSphereRule> shardingSphereRules = GlobalRulesBuilder.buildSingleRules(
+ new FixtureGlobalRuleConfiguration(), Collections.singletonMap("foo_db", buildDatabase()), mock(ConfigurationProperties.class));
+ assertThat(shardingSphereRules.size(), is(1));
}
private ShardingSphereDatabase buildDatabase() {
- return ShardingSphereDatabase.create("logic_db", TypedSPILoader.getService(DatabaseType.class, "MySQL"), new ConfigurationProperties(new Properties()));
+ return ShardingSphereDatabase.create("foo_db", TypedSPILoader.getService(DatabaseType.class, "FIXTURE"), new ConfigurationProperties(new Properties()));
}
}