From 28e3d2c5c8953d02234c82bc922e17970b849d0c Mon Sep 17 00:00:00 2001 From: Liang Zhang Date: Tue, 17 Sep 2024 00:44:41 +0800 Subject: [PATCH] Refactor StateContext (#32909) --- .../apache/shardingsphere/mode/state/StateContext.java | 10 +++------- .../shardingsphere/mode/state/StateContextTest.java | 2 +- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/state/StateContext.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/state/StateContext.java index 83f30ae85ce56..d5f8e289db0af 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/state/StateContext.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/state/StateContext.java @@ -17,7 +17,6 @@ package org.apache.shardingsphere.mode.state; -import lombok.extern.slf4j.Slf4j; import org.apache.shardingsphere.infra.state.cluster.ClusterState; import java.util.concurrent.atomic.AtomicReference; @@ -25,15 +24,12 @@ /** * State context. */ -@Slf4j public final class StateContext { - private final AtomicReference clusterState = new AtomicReference<>(ClusterState.OK); + private final AtomicReference clusterState; - public StateContext(final ClusterState repositoryClusterState) { - if (clusterState.get() != repositoryClusterState) { - switchClusterState(repositoryClusterState); - } + public StateContext(final ClusterState clusterState) { + this.clusterState = new AtomicReference<>(clusterState); } /** diff --git a/mode/core/src/test/java/org/apache/shardingsphere/mode/state/StateContextTest.java b/mode/core/src/test/java/org/apache/shardingsphere/mode/state/StateContextTest.java index 805889735a84e..fd1458c7a7db3 100644 --- a/mode/core/src/test/java/org/apache/shardingsphere/mode/state/StateContextTest.java +++ b/mode/core/src/test/java/org/apache/shardingsphere/mode/state/StateContextTest.java @@ -28,7 +28,7 @@ class StateContextTest { private final StateContext stateContext = new StateContext(ClusterState.OK); @Test - void assertGetCurrentClusterState() { + void assertGetClusterState() { assertThat(stateContext.getClusterState(), is(ClusterState.OK)); }