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

[shardingsphere] branch master updated: Refactor InstanceContext (#21670)

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

yx9o 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 5849de330a5 Refactor InstanceContext (#21670)
5849de330a5 is described below

commit 5849de330a5591935c1a80972b4a61ec1fbf51e9
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Fri Oct 21 12:43:16 2022 +0800

    Refactor InstanceContext (#21670)
    
    * Refactor InstanceContext
    
    * Refactor InstanceContext
    
    * For code format
---
 .../shardingsphere/infra/instance/InstanceContext.java      | 13 +++----------
 .../rule/builder/TransactionRuleBuilderTest.java            |  5 ++---
 2 files changed, 5 insertions(+), 13 deletions(-)

diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/InstanceContext.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/InstanceContext.java
index 463c39e35df..aa57d857500 100644
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/InstanceContext.java
+++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/InstanceContext.java
@@ -19,6 +19,7 @@ package org.apache.shardingsphere.infra.instance;
 
 import lombok.AccessLevel;
 import lombok.Getter;
+import lombok.RequiredArgsConstructor;
 import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
 import org.apache.shardingsphere.infra.util.eventbus.EventBusContext;
 import org.apache.shardingsphere.infra.instance.metadata.InstanceMetaData;
@@ -36,6 +37,7 @@ import java.util.Properties;
 /**
  * Instance context.
  */
+@RequiredArgsConstructor
 @Getter
 public final class InstanceContext {
     
@@ -52,15 +54,6 @@ public final class InstanceContext {
     
     private final Collection<ComputeNodeInstance> allClusterInstances = new LinkedList<>();
     
-    public InstanceContext(final ComputeNodeInstance instance, final WorkerIdGenerator workerIdGenerator,
-                           final ModeConfiguration modeConfiguration, final LockContext lockContext, final EventBusContext eventBusContext) {
-        this.instance = instance;
-        this.workerIdGenerator = workerIdGenerator;
-        this.modeConfiguration = modeConfiguration;
-        this.lockContext = lockContext;
-        this.eventBusContext = eventBusContext;
-    }
-    
     /**
      * Update instance status.
      *
@@ -113,7 +106,7 @@ public final class InstanceContext {
     public long generateWorkerId(final Properties props) {
         long result = workerIdGenerator.generate(props);
         instance.setWorkerId(result);
-        return getWorkerId();
+        return result;
     }
     
     /**
diff --git a/kernel/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
index cb613b27f3b..98f72bcb992 100644
--- a/kernel/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
@@ -48,7 +48,7 @@ import static org.junit.Assert.assertNotNull;
 import static org.mockito.Mockito.mock;
 
 public final class TransactionRuleBuilderTest {
-
+    
     @Test
     public void assertBuild() {
         TransactionRuleConfiguration ruleConfig = new TransactionRuleConfiguration("LOCAL", "provider", new Properties());
@@ -60,12 +60,11 @@ public final class TransactionRuleBuilderTest {
         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<>(2, 1);
         result.put("not_change", new MockedDataSource());
         result.put("replace", new MockedDataSource());
         return result;
     }
-
 }