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

panjuan 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 f1edd6f  Refactor ComputeNodeInstance (#15766)
f1edd6f is described below

commit f1edd6f3615624a77feb88b3b009680ac671fd1c
Author: Liang Zhang <[email protected]>
AuthorDate: Thu Mar 3 03:11:41 2022 +0800

    Refactor ComputeNodeInstance (#15766)
    
    * Refactor ComputeNodeInstance
    
    * Refactor ComputeNodeInstance
---
 .../prometheus/collector/ProxyInfoCollectorTest.java   |  5 +++--
 .../service/PrometheusPluginBootServiceTest.java       |  5 +++--
 .../keygen/CosIdSnowflakeKeyGenerateAlgorithmTest.java | 18 ++++++++++--------
 .../keygen/SnowflakeKeyGenerateAlgorithmTest.java      | 10 ++++++----
 .../infra/instance/ComputeNodeInstance.java            |  8 +++++---
 .../shardingsphere/infra/instance/InstanceContext.java |  2 +-
 .../infra/instance/InstanceContextTest.java            | 16 +++++++++-------
 .../jdbc/core/connection/ConnectionManagerTest.java    |  3 +--
 .../traffic/algorithm/engine/TrafficEngineTest.java    | 14 ++++++--------
 .../persist/service/ComputeNodePersistService.java     |  6 ++----
 .../manager/memory/MemoryContextManagerBuilder.java    |  3 +--
 11 files changed, 47 insertions(+), 43 deletions(-)

diff --git 
a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/collector/ProxyInfoCollectorTest.java
 
b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/collector/ProxyInfoCollectorTest.java
index 2f2ba52..24c34bb 100644
--- 
a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/collector/ProxyInfoCollectorTest.java
+++ 
b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/collector/ProxyInfoCollectorTest.java
@@ -21,6 +21,7 @@ import io.prometheus.client.Collector;
 import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
 import org.apache.shardingsphere.infra.instance.ComputeNodeInstance;
 import org.apache.shardingsphere.infra.instance.InstanceContext;
+import org.apache.shardingsphere.infra.instance.definition.InstanceDefinition;
 import 
org.apache.shardingsphere.mode.manager.memory.workerid.generator.MemoryWorkerIdGenerator;
 import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
 import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
@@ -36,8 +37,8 @@ public final class ProxyInfoCollectorTest {
     
     @Test
     public void assertCollect() {
-        
ProxyContext.getInstance().getContextManager().init(mock(MetaDataContexts.class),
 mock(TransactionContexts.class), new InstanceContext(new 
ComputeNodeInstance(), 
-                new MemoryWorkerIdGenerator(), new ModeConfiguration("Memory", 
null, false)));
+        
ProxyContext.getInstance().getContextManager().init(mock(MetaDataContexts.class),
 mock(TransactionContexts.class), 
+                new InstanceContext(new 
ComputeNodeInstance(mock(InstanceDefinition.class)), new 
MemoryWorkerIdGenerator(), new ModeConfiguration("Memory", null, false)));
         ProxyInfoCollector proxyInfoCollector = new ProxyInfoCollector();
         List<Collector.MetricFamilySamples> metricFamilySamples = 
proxyInfoCollector.collect();
         assertFalse(metricFamilySamples.isEmpty());
diff --git 
a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/service/PrometheusPluginBootServiceTest.java
 
b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/service/PrometheusPluginBootServiceTest.java
index b485e52..cbb4191 100644
--- 
a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/service/PrometheusPluginBootServiceTest.java
+++ 
b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/service/PrometheusPluginBootServiceTest.java
@@ -23,6 +23,7 @@ import 
org.apache.shardingsphere.agent.config.PluginConfiguration;
 import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
 import org.apache.shardingsphere.infra.instance.ComputeNodeInstance;
 import org.apache.shardingsphere.infra.instance.InstanceContext;
+import org.apache.shardingsphere.infra.instance.definition.InstanceDefinition;
 import 
org.apache.shardingsphere.mode.manager.memory.workerid.generator.MemoryWorkerIdGenerator;
 import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
 import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
@@ -45,8 +46,8 @@ public final class PrometheusPluginBootServiceTest {
     @SneakyThrows
     @Test
     public void assertStart() {
-        
ProxyContext.getInstance().getContextManager().init(mock(MetaDataContexts.class),
 mock(TransactionContexts.class), new InstanceContext(new 
ComputeNodeInstance(), 
-                new MemoryWorkerIdGenerator(), new ModeConfiguration("Memory", 
null, false)));
+        
ProxyContext.getInstance().getContextManager().init(mock(MetaDataContexts.class),
 mock(TransactionContexts.class), 
+                new InstanceContext(new 
ComputeNodeInstance(mock(InstanceDefinition.class)), new 
MemoryWorkerIdGenerator(), new ModeConfiguration("Memory", null, false)));
         Properties props = new Properties();
         props.setProperty("JVM_INFORMATION_COLLECTOR_ENABLED", "true");
         PluginConfiguration configuration = new 
PluginConfiguration("localhost", 8090, "", props);
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/algorithm/keygen/CosIdSnowflakeKeyGenerateAlgorithmTest.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/algorithm/keygen/CosIdSnowflakeKeyGenerateAlgorithmTest.java
index 6f78839..b98367c 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/algorithm/keygen/CosIdSnowflakeKeyGenerateAlgorithmTest.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/algorithm/keygen/CosIdSnowflakeKeyGenerateAlgorithmTest.java
@@ -23,6 +23,7 @@ import me.ahoo.cosid.snowflake.SnowflakeIdStateParser;
 import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
 import org.apache.shardingsphere.infra.instance.ComputeNodeInstance;
 import org.apache.shardingsphere.infra.instance.InstanceContext;
+import org.apache.shardingsphere.infra.instance.definition.InstanceDefinition;
 import 
org.apache.shardingsphere.sharding.algorithm.keygen.fixture.WorkerIdGeneratorFixture;
 import org.hamcrest.Matchers;
 import org.junit.Test;
@@ -31,6 +32,7 @@ import java.util.Properties;
 
 import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
 
 public final class CosIdSnowflakeKeyGenerateAlgorithmTest {
     
@@ -47,8 +49,8 @@ public final class CosIdSnowflakeKeyGenerateAlgorithmTest {
     public void assertGenerateKey() {
         CosIdSnowflakeKeyGenerateAlgorithm cosIdSnowflakeKeyGenerateAlgorithm 
= new CosIdSnowflakeKeyGenerateAlgorithm();
         Properties properties = new Properties();
-        cosIdSnowflakeKeyGenerateAlgorithm.setInstanceContext(new 
InstanceContext(new ComputeNodeInstance(), new 
WorkerIdGeneratorFixture(FIXTURE_WORKER_ID), 
-                new ModeConfiguration("Memory", null, false)));
+        cosIdSnowflakeKeyGenerateAlgorithm.setInstanceContext(new 
InstanceContext(new ComputeNodeInstance(mock(InstanceDefinition.class)), 
+                new WorkerIdGeneratorFixture(FIXTURE_WORKER_ID), new 
ModeConfiguration("Memory", null, false)));
         cosIdSnowflakeKeyGenerateAlgorithm.setProps(properties);
         cosIdSnowflakeKeyGenerateAlgorithm.init();
         long firstActualKey = (Long) 
cosIdSnowflakeKeyGenerateAlgorithm.generateKey();
@@ -67,8 +69,8 @@ public final class CosIdSnowflakeKeyGenerateAlgorithmTest {
         CosIdSnowflakeKeyGenerateAlgorithm cosIdSnowflakeKeyGenerateAlgorithm 
= new CosIdSnowflakeKeyGenerateAlgorithm();
         Properties properties = new Properties();
         
properties.setProperty(CosIdSnowflakeKeyGenerateAlgorithm.AS_STRING_KEY, 
"true");
-        cosIdSnowflakeKeyGenerateAlgorithm.setInstanceContext(new 
InstanceContext(new ComputeNodeInstance(), new 
WorkerIdGeneratorFixture(FIXTURE_WORKER_ID), 
-                new ModeConfiguration("Memory", null, false)));
+        cosIdSnowflakeKeyGenerateAlgorithm.setInstanceContext(new 
InstanceContext(new ComputeNodeInstance(mock(InstanceDefinition.class)), 
+                new WorkerIdGeneratorFixture(FIXTURE_WORKER_ID), new 
ModeConfiguration("Memory", null, false)));
         cosIdSnowflakeKeyGenerateAlgorithm.setProps(properties);
         cosIdSnowflakeKeyGenerateAlgorithm.init();
         Comparable<?> actualKey = 
cosIdSnowflakeKeyGenerateAlgorithm.generateKey();
@@ -94,8 +96,8 @@ public final class CosIdSnowflakeKeyGenerateAlgorithmTest {
     public void assertGenerateKeyWhenNegative() {
         CosIdSnowflakeKeyGenerateAlgorithm cosIdSnowflakeKeyGenerateAlgorithm 
= new CosIdSnowflakeKeyGenerateAlgorithm();
         Properties properties = new Properties();
-        cosIdSnowflakeKeyGenerateAlgorithm.setInstanceContext(new 
InstanceContext(new ComputeNodeInstance(), new WorkerIdGeneratorFixture(-1), 
-                new ModeConfiguration("Memory", null, false)));
+        cosIdSnowflakeKeyGenerateAlgorithm.setInstanceContext(new 
InstanceContext(new ComputeNodeInstance(mock(InstanceDefinition.class)), 
+                new WorkerIdGeneratorFixture(-1), new 
ModeConfiguration("Memory", null, false)));
         cosIdSnowflakeKeyGenerateAlgorithm.setProps(properties);
         cosIdSnowflakeKeyGenerateAlgorithm.init();
         cosIdSnowflakeKeyGenerateAlgorithm.generateKey();
@@ -105,8 +107,8 @@ public final class CosIdSnowflakeKeyGenerateAlgorithmTest {
     public void assertGenerateKeyWhenGreaterThen1023() {
         CosIdSnowflakeKeyGenerateAlgorithm cosIdSnowflakeKeyGenerateAlgorithm 
= new CosIdSnowflakeKeyGenerateAlgorithm();
         Properties properties = new Properties();
-        cosIdSnowflakeKeyGenerateAlgorithm.setInstanceContext(new 
InstanceContext(new ComputeNodeInstance(), new WorkerIdGeneratorFixture(1024), 
-                new ModeConfiguration("Memory", null, false)));
+        cosIdSnowflakeKeyGenerateAlgorithm.setInstanceContext(new 
InstanceContext(new ComputeNodeInstance(mock(InstanceDefinition.class)), 
+                new WorkerIdGeneratorFixture(1024), new 
ModeConfiguration("Memory", null, false)));
         cosIdSnowflakeKeyGenerateAlgorithm.setProps(properties);
         cosIdSnowflakeKeyGenerateAlgorithm.init();
         cosIdSnowflakeKeyGenerateAlgorithm.generateKey();
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/algorithm/keygen/SnowflakeKeyGenerateAlgorithmTest.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/algorithm/keygen/SnowflakeKeyGenerateAlgorithmTest.java
index 9f5c64e..8a2300b 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/algorithm/keygen/SnowflakeKeyGenerateAlgorithmTest.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/algorithm/keygen/SnowflakeKeyGenerateAlgorithmTest.java
@@ -21,6 +21,7 @@ import lombok.SneakyThrows;
 import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
 import org.apache.shardingsphere.infra.instance.ComputeNodeInstance;
 import org.apache.shardingsphere.infra.instance.InstanceContext;
+import org.apache.shardingsphere.infra.instance.definition.InstanceDefinition;
 import 
org.apache.shardingsphere.sharding.algorithm.keygen.fixture.FixedTimeService;
 import 
org.apache.shardingsphere.sharding.algorithm.keygen.fixture.WorkerIdGeneratorFixture;
 import org.junit.Test;
@@ -40,6 +41,7 @@ import java.util.concurrent.Executors;
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.CoreMatchers.not;
 import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
 
 public final class SnowflakeKeyGenerateAlgorithmTest {
     
@@ -176,8 +178,8 @@ public final class SnowflakeKeyGenerateAlgorithmTest {
     
     @Test(expected = IllegalArgumentException.class)
     public void assertSetWorkerIdFailureWhenNegative() {
-        keyGenerateAlgorithm.setInstanceContext(new InstanceContext(new 
ComputeNodeInstance(), new WorkerIdGeneratorFixture(-1L), 
-                new ModeConfiguration("Memory", null, false)));
+        keyGenerateAlgorithm.setInstanceContext(new InstanceContext(new 
ComputeNodeInstance(mock(InstanceDefinition.class)), 
+                new WorkerIdGeneratorFixture(-1L), new 
ModeConfiguration("Memory", null, false)));
         keyGenerateAlgorithm.init();
         keyGenerateAlgorithm.generateKey();
         clearInstanceContext();
@@ -194,8 +196,8 @@ public final class SnowflakeKeyGenerateAlgorithmTest {
     
     @Test(expected = IllegalArgumentException.class)
     public void assertSetWorkerIdFailureWhenOutOfRange() {
-        keyGenerateAlgorithm.setInstanceContext(new InstanceContext(new 
ComputeNodeInstance(), new WorkerIdGeneratorFixture(Long.MIN_VALUE), 
-                new ModeConfiguration("Memory", null, false)));
+        keyGenerateAlgorithm.setInstanceContext(new InstanceContext(new 
ComputeNodeInstance(mock(InstanceDefinition.class)), 
+                new WorkerIdGeneratorFixture(Long.MIN_VALUE), new 
ModeConfiguration("Memory", null, false)));
         keyGenerateAlgorithm.init();
         keyGenerateAlgorithm.generateKey();
         clearInstanceContext();
diff --git 
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/ComputeNodeInstance.java
 
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/ComputeNodeInstance.java
index 8fe8d86..6ce9ae5 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/ComputeNodeInstance.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/ComputeNodeInstance.java
@@ -18,6 +18,7 @@
 package org.apache.shardingsphere.infra.instance;
 
 import lombok.Getter;
+import lombok.RequiredArgsConstructor;
 import lombok.Setter;
 import org.apache.shardingsphere.infra.instance.definition.InstanceDefinition;
 
@@ -26,17 +27,18 @@ import java.util.Collection;
 /**
  * Instance of compute node.
  */
+@RequiredArgsConstructor
 @Getter
 @Setter
 public final class ComputeNodeInstance {
     
-    private InstanceDefinition instanceDefinition;
-    
-    private String xaRecoveryId;
+    private final InstanceDefinition instanceDefinition;
     
     private Collection<String> labels;
     
     private Collection<String> status;
     
     private Long workerId;
+    
+    private String xaRecoveryId;
 }
diff --git 
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/InstanceContext.java
 
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/InstanceContext.java
index c18bff8..fa0e8fb 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/InstanceContext.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/InstanceContext.java
@@ -90,7 +90,7 @@ public final class InstanceContext {
     public long getWorkerId() {
         if (null == instance.getWorkerId()) {
             // TODO process generate failed
-            
Optional.ofNullable(workerIdGenerator.generate()).ifPresent(instance::setWorkerId);
+            
Optional.of(workerIdGenerator.generate()).ifPresent(instance::setWorkerId);
         }
         return instance.getWorkerId();
     }
diff --git 
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/instance/InstanceContextTest.java
 
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/instance/InstanceContextTest.java
index 617fcf4..a269136 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/instance/InstanceContextTest.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/instance/InstanceContextTest.java
@@ -19,6 +19,7 @@ package org.apache.shardingsphere.infra.instance;
 
 import com.google.common.collect.Lists;
 import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
+import org.apache.shardingsphere.infra.instance.definition.InstanceDefinition;
 import 
org.apache.shardingsphere.infra.instance.fixture.WorkerIdGeneratorFixture;
 import org.apache.shardingsphere.infra.state.StateContext;
 import org.apache.shardingsphere.infra.state.StateType;
@@ -31,6 +32,7 @@ import java.util.Random;
 import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
 
 public final class InstanceContextTest {
 
@@ -38,7 +40,7 @@ public final class InstanceContextTest {
 
     @Test
     public void assertUpdateInstanceStatus() {
-        InstanceContext context = new InstanceContext(new 
ComputeNodeInstance(), new WorkerIdGeneratorFixture(Long.MIN_VALUE), 
modeConfiguration);
+        InstanceContext context = new InstanceContext(new 
ComputeNodeInstance(mock(InstanceDefinition.class)), new 
WorkerIdGeneratorFixture(Long.MIN_VALUE), modeConfiguration);
         StateType actual = context.getState().getCurrentState();
         assertThat(actual, is(StateType.OK));
         
context.updateInstanceStatus(Lists.newArrayList(StateType.CIRCUIT_BREAK.name()));
@@ -51,7 +53,7 @@ public final class InstanceContextTest {
 
     @Test
     public void assertUpdateWorkerId() {
-        InstanceContext context = new InstanceContext(new 
ComputeNodeInstance(), new WorkerIdGeneratorFixture(Long.MIN_VALUE), 
modeConfiguration);
+        InstanceContext context = new InstanceContext(new 
ComputeNodeInstance(mock(InstanceDefinition.class)), new 
WorkerIdGeneratorFixture(Long.MIN_VALUE), modeConfiguration);
         Long actual = context.getWorkerId();
         assertThat(actual, is(Long.MIN_VALUE));
         Random random = new Random();
@@ -63,7 +65,7 @@ public final class InstanceContextTest {
 
     @Test
     public void assertUpdateLabel() {
-        InstanceContext context = new InstanceContext(new 
ComputeNodeInstance(), new WorkerIdGeneratorFixture(Long.MIN_VALUE), 
modeConfiguration);
+        InstanceContext context = new InstanceContext(new 
ComputeNodeInstance(mock(InstanceDefinition.class)), new 
WorkerIdGeneratorFixture(Long.MIN_VALUE), modeConfiguration);
         Collection<String> expected = Arrays.asList("label_1", "label_2");
         context.updateLabel(expected);
         Collection<String> actual = context.getInstance().getLabels();
@@ -72,7 +74,7 @@ public final class InstanceContextTest {
 
     @Test
     public void assertGetInstance() {
-        ComputeNodeInstance expected = new ComputeNodeInstance();
+        ComputeNodeInstance expected = new 
ComputeNodeInstance(mock(InstanceDefinition.class));
         InstanceContext context = new InstanceContext(expected, new 
WorkerIdGeneratorFixture(Long.MIN_VALUE), modeConfiguration);
         ComputeNodeInstance actual = context.getInstance();
         assertThat(actual, is(expected));
@@ -80,7 +82,7 @@ public final class InstanceContextTest {
 
     @Test
     public void assertGetState() {
-        InstanceContext context = new InstanceContext(new 
ComputeNodeInstance(), new WorkerIdGeneratorFixture(Long.MIN_VALUE), 
modeConfiguration);
+        InstanceContext context = new InstanceContext(new 
ComputeNodeInstance(mock(InstanceDefinition.class)), new 
WorkerIdGeneratorFixture(Long.MIN_VALUE), modeConfiguration);
         StateContext actual = context.getState();
         assertNotNull(actual);
     }
@@ -88,14 +90,14 @@ public final class InstanceContextTest {
     @Test
     public void assertGetWorkerIdGenerator() {
         WorkerIdGeneratorFixture expected = new 
WorkerIdGeneratorFixture(Long.MIN_VALUE);
-        InstanceContext context = new InstanceContext(new 
ComputeNodeInstance(), expected, modeConfiguration);
+        InstanceContext context = new InstanceContext(new 
ComputeNodeInstance(mock(InstanceDefinition.class)), expected, 
modeConfiguration);
         WorkerIdGeneratorFixture actual = (WorkerIdGeneratorFixture) 
context.getWorkerIdGenerator();
         assertThat(actual, is(expected));
     }
 
     @Test
     public void assertGetModeConfiguration() {
-        InstanceContext context = new InstanceContext(new 
ComputeNodeInstance(), new WorkerIdGeneratorFixture(Long.MIN_VALUE), 
modeConfiguration);
+        InstanceContext context = new InstanceContext(new 
ComputeNodeInstance(mock(InstanceDefinition.class)), new 
WorkerIdGeneratorFixture(Long.MIN_VALUE), modeConfiguration);
         ModeConfiguration actual = context.getModeConfiguration();
         assertThat(actual, is(modeConfiguration));
     }
diff --git 
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/ConnectionManagerTest.java
 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/ConnectionManagerTest.java
index a6e35f5..e43ac1c 100644
--- 
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/ConnectionManagerTest.java
+++ 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/ConnectionManagerTest.java
@@ -126,9 +126,8 @@ public final class ConnectionManagerTest {
     }
     
     private ComputeNodeInstance mockComputeNodeInstance() {
-        ComputeNodeInstance result = new ComputeNodeInstance();
+        ComputeNodeInstance result = new ComputeNodeInstance(new 
InstanceDefinition(InstanceType.PROXY, "127.0.0.1@3307"));
         result.setLabels(Collections.singletonList("OLTP"));
-        result.setInstanceDefinition(new 
InstanceDefinition(InstanceType.PROXY, "127.0.0.1@3307"));
         return result;
     }
     
diff --git 
a/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-core/src/test/java/org/apache/shardingsphere/traffic/algorithm/engine/TrafficEngineTest.java
 
b/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-core/src/test/java/org/apache/shardingsphere/traffic/algorithm/engine/TrafficEngineTest.java
index 1807fe7..7c51a46 100644
--- 
a/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-core/src/test/java/org/apache/shardingsphere/traffic/algorithm/engine/TrafficEngineTest.java
+++ 
b/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-core/src/test/java/org/apache/shardingsphere/traffic/algorithm/engine/TrafficEngineTest.java
@@ -114,14 +114,12 @@ public final class TrafficEngineTest {
     
     private Collection<ComputeNodeInstance> mockComputeNodeInstances() {
         Collection<ComputeNodeInstance> result = new LinkedList<>();
-        ComputeNodeInstance instanceOlap = new ComputeNodeInstance();
-        instanceOlap.setLabels(Collections.singletonList("OLAP"));
-        instanceOlap.setInstanceDefinition(new 
InstanceDefinition(InstanceType.PROXY, "127.0.0.1@3307"));
-        result.add(instanceOlap);
-        ComputeNodeInstance instanceOltp = new ComputeNodeInstance();
-        instanceOltp.setLabels(Collections.singletonList("OLTP"));
-        instanceOltp.setInstanceDefinition(new 
InstanceDefinition(InstanceType.PROXY, "127.0.0.1@3308"));
-        result.add(instanceOltp);
+        ComputeNodeInstance instanceOLAP = new ComputeNodeInstance(new 
InstanceDefinition(InstanceType.PROXY, "127.0.0.1@3307"));
+        instanceOLAP.setLabels(Collections.singletonList("OLAP"));
+        result.add(instanceOLAP);
+        ComputeNodeInstance instanceOLTP = new ComputeNodeInstance(new 
InstanceDefinition(InstanceType.PROXY, "127.0.0.1@3308"));
+        instanceOLTP.setLabels(Collections.singletonList("OLTP"));
+        result.add(instanceOLTP);
         return result;
     }
 }
diff --git 
a/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/service/ComputeNodePersistService.java
 
b/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/service/ComputeNodePersistService.java
index 1803478..170ef99 100644
--- 
a/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/service/ComputeNodePersistService.java
+++ 
b/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/service/ComputeNodePersistService.java
@@ -151,8 +151,7 @@ public final class ComputeNodePersistService {
         onlineComputeNodes.forEach(each -> {
             Collection<String> actualLabels = loadInstanceLabels(each);
             if (actualLabels.stream().anyMatch(labels::contains)) {
-                ComputeNodeInstance instance = new ComputeNodeInstance();
-                instance.setInstanceDefinition(new 
InstanceDefinition(instanceType, each));
+                ComputeNodeInstance instance = new ComputeNodeInstance(new 
InstanceDefinition(instanceType, each));
                 instance.setLabels(actualLabels);
                 instance.setStatus(loadInstanceStatus(each));
                 loadInstanceWorkerId(each).ifPresent(instance::setWorkerId);
@@ -183,8 +182,7 @@ public final class ComputeNodePersistService {
      * @return compute node instance
      */
     public ComputeNodeInstance loadComputeNodeInstance(final 
InstanceDefinition instanceDefinition) {
-        ComputeNodeInstance result = new ComputeNodeInstance();
-        result.setInstanceDefinition(instanceDefinition);
+        ComputeNodeInstance result = new 
ComputeNodeInstance(instanceDefinition);
         
result.setLabels(loadInstanceLabels(instanceDefinition.getInstanceId().getId()));
         
result.setStatus(loadInstanceStatus(instanceDefinition.getInstanceId().getId()));
         
loadInstanceWorkerId(instanceDefinition.getInstanceId().getId()).ifPresent(result::setWorkerId);
diff --git 
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-memory-mode/shardingsphere-memory-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/memory/MemoryContextManagerBuilder.java
 
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-memory-mode/shardingsphere-memory-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/memory/MemoryContextManagerBuilder.java
index be11a62..d885403 100644
--- 
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-memory-mode/shardingsphere-memory-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/memory/MemoryContextManagerBuilder.java
+++ 
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-memory-mode/shardingsphere-memory-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/memory/MemoryContextManagerBuilder.java
@@ -60,8 +60,7 @@ public final class MemoryContextManagerBuilder implements 
ContextManagerBuilder
     }
     
     private InstanceContext buildInstanceContext(final 
ContextManagerBuilderParameter parameter) {
-        ComputeNodeInstance instance = new ComputeNodeInstance();
-        instance.setInstanceDefinition(parameter.getInstanceDefinition());
+        ComputeNodeInstance instance = new 
ComputeNodeInstance(parameter.getInstanceDefinition());
         instance.setLabels(parameter.getLabels());
         return new InstanceContext(instance, new MemoryWorkerIdGenerator(), 
buildMemoryModeConfiguration(parameter.getModeConfig()));
     }

Reply via email to