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 2022/07/06 06:03:55 UTC
[shardingsphere] branch master updated: Supplement GlobalRulesBuilder test cases (#18885)
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 5b973ee0bba Supplement GlobalRulesBuilder test cases (#18885)
5b973ee0bba is described below
commit 5b973ee0bbae51b8a8d3a07462f30c5b579bac4e
Author: 小马哥 <ma...@163.com>
AuthorDate: Wed Jul 6 14:03:47 2022 +0800
Supplement GlobalRulesBuilder test cases (#18885)
* Supplement GlobalRulesBuilder test cases
* Repair column is too long
---
.../builder/global/GlobalRulesBuilderTest.java | 38 ++++++++++++++++++++--
1 file changed, 35 insertions(+), 3 deletions(-)
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilderTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilderTest.java
index 67291bd6fe3..7aec9d7151b 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilderTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilderTest.java
@@ -17,22 +17,54 @@
package org.apache.shardingsphere.infra.rule.builder.global;
-import org.apache.shardingsphere.infra.config.RuleConfiguration;
+import lombok.SneakyThrows;
+import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
+import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
+import org.apache.shardingsphere.infra.instance.ComputeNodeInstance;
import org.apache.shardingsphere.infra.instance.InstanceContext;
+import org.apache.shardingsphere.infra.instance.metadata.jdbc.JDBCInstanceMetaData;
+import org.apache.shardingsphere.infra.lock.LockContext;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
+import org.apache.shardingsphere.infra.rule.builder.fixture.FixtureGlobalRule;
+import org.apache.shardingsphere.infra.rule.builder.fixture.FixtureGlobalRuleConfiguration;
import org.junit.Test;
+import java.util.Collection;
import java.util.Collections;
+import java.util.UUID;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
public final class GlobalRulesBuilderTest {
@Test
public void assertBuildRules() {
- assertThat(GlobalRulesBuilder.buildRules(
- Collections.singletonList(mock(RuleConfiguration.class)), Collections.singletonMap("logic_db", mock(ShardingSphereDatabase.class)), mock(InstanceContext.class)).size(), is(1));
+ Collection<ShardingSphereRule> shardingSphereRules = GlobalRulesBuilder
+ .buildRules(Collections.singletonList(new FixtureGlobalRuleConfiguration()), Collections.singletonMap("logic_db", buildShardingSphereDatabase()), buildInstanceContext());
+ assertThat(shardingSphereRules.size(), is(1));
+ }
+
+ @Test
+ public void assertBuildRulesClassType() {
+ Collection<ShardingSphereRule> shardingSphereRules = GlobalRulesBuilder
+ .buildRules(Collections.singletonList(new FixtureGlobalRuleConfiguration()), Collections.singletonMap("logic_db", buildShardingSphereDatabase()), buildInstanceContext());
+ assertTrue(shardingSphereRules.toArray()[0] instanceof FixtureGlobalRule);
+ }
+
+ private InstanceContext buildInstanceContext() {
+ ComputeNodeInstance computeNodeInstance = new ComputeNodeInstance(new JDBCInstanceMetaData(UUID.randomUUID().toString()));
+ ModeConfiguration modeConfiguration = new ModeConfiguration("Standalone", null, false);
+ InstanceContext instanceContext = new InstanceContext(computeNodeInstance, () -> 0, modeConfiguration, mock(LockContext.class));
+ return instanceContext;
+ }
+
+ @SneakyThrows
+ private ShardingSphereDatabase buildShardingSphereDatabase() {
+ ShardingSphereDatabase shardingSphereDatabase = ShardingSphereDatabase.create("logic_db", new MySQLDatabaseType());
+ return shardingSphereDatabase;
}
}