You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by ma...@apache.org on 2022/10/21 03:16:33 UTC

[shardingsphere] branch master updated: Revise TransactionRuleBuilderTest (#21665)

This is an automated email from the ASF dual-hosted git repository.

machen 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 ede3dbd2f89 Revise TransactionRuleBuilderTest (#21665)
ede3dbd2f89 is described below

commit ede3dbd2f89ba30c2d7cd9b20cdcadd35e657f07
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Fri Oct 21 11:16:26 2022 +0800

    Revise TransactionRuleBuilderTest (#21665)
---
 .../rule/builder/TransactionRuleBuilderTest.java   | 61 ++++++++--------------
 1 file changed, 22 insertions(+), 39 deletions(-)

diff --git a/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/test/java/org/apache/shardingsphere/transaction/rule/builder/TransactionRuleBuilderTest.java b/kernel/transaction/core/src/test/java/org/apache/shardingsphere/transaction/rule/builder/TransactionRuleBuilderTest.java
similarity index 64%
rename from shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/test/java/org/apache/shardingsphere/transaction/rule/builder/TransactionRuleBuilderTest.java
rename to kernel/transaction/core/src/test/java/org/apache/shardingsphere/transaction/rule/builder/TransactionRuleBuilderTest.java
index 704dbe3751a..cb613b27f3b 100644
--- a/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/test/java/org/apache/shardingsphere/transaction/rule/builder/TransactionRuleBuilderTest.java
+++ b/kernel/transaction/core/src/test/java/org/apache/shardingsphere/transaction/rule/builder/TransactionRuleBuilderTest.java
@@ -17,16 +17,6 @@
 
 package org.apache.shardingsphere.transaction.rule.builder;
 
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.hasSize;
-import static org.hamcrest.Matchers.notNullValue;
-import static org.mockito.Mockito.mock;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-import javax.sql.DataSource;
 import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
 import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
 import org.apache.shardingsphere.infra.database.DefaultDatabase;
@@ -36,50 +26,43 @@ import org.apache.shardingsphere.infra.instance.metadata.InstanceMetaData;
 import org.apache.shardingsphere.infra.instance.workerid.WorkerIdGenerator;
 import org.apache.shardingsphere.infra.lock.LockContext;
 import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import org.apache.shardingsphere.infra.metadata.database.resource.ShardingSphereResource;
+import org.apache.shardingsphere.infra.metadata.database.resource.ShardingSphereResourceMetaData;
 import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
 import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereSchema;
 import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
-import org.apache.shardingsphere.infra.schedule.ScheduleContext;
 import org.apache.shardingsphere.infra.util.eventbus.EventBusContext;
 import org.apache.shardingsphere.test.mock.MockedDataSource;
 import org.apache.shardingsphere.transaction.config.TransactionRuleConfiguration;
 import org.apache.shardingsphere.transaction.rule.TransactionRule;
 import org.junit.Test;
 
-public class TransactionRuleBuilderTest {
+import javax.sql.DataSource;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Mockito.mock;
+
+public final class TransactionRuleBuilderTest {
 
     @Test
     public void assertBuild() {
-        TransactionRuleConfiguration rule = new TransactionRuleConfiguration("LOCAL", "provider", new Properties());
-        ShardingSphereResource resource = new ShardingSphereResource("db", createDataSourceMap());
-        ShardingSphereDatabase database = new ShardingSphereDatabase(
-                "sphereDb",
-                null,
-                resource,
-                new ShardingSphereRuleMetaData(Collections.singletonList(mock(ShardingSphereRule.class))),
-                Collections.singletonMap("test", mock(ShardingSphereSchema.class))
-        );
-        InstanceContext instanceContext = new InstanceContext(
-                new ComputeNodeInstance(mock(InstanceMetaData.class)),
-                mock(WorkerIdGenerator.class),
-                new ModeConfiguration("Standalone", null),
-                mock(LockContext.class),
-                new EventBusContext(),
-                mock(ScheduleContext.class)
-        );
-        TransactionRule build = new TransactionRuleBuilder().build(
-                rule,
-                Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database),
-                instanceContext,
-                mock(ConfigurationProperties.class)
-        );
-        assertThat(build.getConfiguration(), notNullValue());
-        assertThat(build.getDatabases().get("logic_db").getResource().getDataSources().entrySet(), hasSize(2));
+        TransactionRuleConfiguration ruleConfig = new TransactionRuleConfiguration("LOCAL", "provider", new Properties());
+        ShardingSphereDatabase database = new ShardingSphereDatabase("logic_db", null, new ShardingSphereResourceMetaData("db", createDataSourceMap()),
+                new ShardingSphereRuleMetaData(Collections.singletonList(mock(ShardingSphereRule.class))), Collections.singletonMap("test", mock(ShardingSphereSchema.class)));
+        InstanceContext instanceContext = new InstanceContext(new ComputeNodeInstance(mock(InstanceMetaData.class)),
+                mock(WorkerIdGenerator.class), new ModeConfiguration("Standalone", null), mock(LockContext.class), new EventBusContext());
+        TransactionRule rule = new TransactionRuleBuilder().build(ruleConfig, Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), instanceContext, mock(ConfigurationProperties.class));
+        assertNotNull(rule.getConfiguration());
+        assertThat(rule.getDatabases().get("logic_db").getResourceMetaData().getDataSources().size(), is(2));
     }
 
     private Map<String, DataSource> createDataSourceMap() {
-        Map<String, DataSource> result = new HashMap<>(3, 1);
+        Map<String, DataSource> result = new HashMap<>(2, 1);
         result.put("not_change", new MockedDataSource());
         result.put("replace", new MockedDataSource());
         return result;