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 542ead3  Remove MetaDataContexts.isCircuitBreak() (#8191)
542ead3 is described below

commit 542ead3694f8ebcab4f59174d2d95436436163f2
Author: Liang Zhang <[email protected]>
AuthorDate: Tue Nov 17 17:53:20 2020 +0800

    Remove MetaDataContexts.isCircuitBreak() (#8191)
    
    * Add CircuitBreakDriverStateTest
    
    * Add OKDriverStateTest
    
    * Remove MetaDataContexts.isCircuitBreak()
---
 .../metadata/GovernanceMetaDataContexts.java       | 23 ++----------
 .../metadata/GovernanceMetaDataContextsTest.java   | 13 -------
 .../infra/context/metadata/MetaDataContexts.java   |  7 ----
 .../metadata/impl/StandardMetaDataContexts.java    |  9 +----
 .../metadata/MetaDataContextsBuilderTest.java      |  4 --
 .../internal/state/DriverStateContext.java         | 10 ++---
 .../state/impl/CircuitBreakDriverStateTest.java    | 40 ++++++++++++++++++++
 .../internal/state/impl/OKDriverStateTest.java     | 43 ++++++++++++++++++++++
 .../impl/GovernanceBootstrapInitializerTest.java   |  1 -
 .../proxy/frontend/state/ProxyStateContext.java    | 10 ++---
 10 files changed, 97 insertions(+), 63 deletions(-)

diff --git 
a/shardingsphere-governance/shardingsphere-governance-core/shardingsphere-governance-core-context/src/main/java/org/apache/shardingsphere/governance/context/metadata/GovernanceMetaDataContexts.java
 
b/shardingsphere-governance/shardingsphere-governance-core/shardingsphere-governance-core-context/src/main/java/org/apache/shardingsphere/governance/context/metadata/GovernanceMetaDataContexts.java
index e21cf97..6a06e69 100644
--- 
a/shardingsphere-governance/shardingsphere-governance-core/shardingsphere-governance-core-context/src/main/java/org/apache/shardingsphere/governance/context/metadata/GovernanceMetaDataContexts.java
+++ 
b/shardingsphere-governance/shardingsphere-governance-core/shardingsphere-governance-core-context/src/main/java/org/apache/shardingsphere/governance/context/metadata/GovernanceMetaDataContexts.java
@@ -23,13 +23,12 @@ import 
org.apache.shardingsphere.governance.core.event.GovernanceEventBus;
 import 
org.apache.shardingsphere.governance.core.event.model.auth.AuthenticationChangedEvent;
 import 
org.apache.shardingsphere.governance.core.event.model.datasource.DataSourceChangeCompletedEvent;
 import 
org.apache.shardingsphere.governance.core.event.model.datasource.DataSourceChangedEvent;
-import 
org.apache.shardingsphere.governance.core.event.model.schema.SchemaChangedEvent;
-import 
org.apache.shardingsphere.governance.core.event.model.props.PropertiesChangedEvent;
-import 
org.apache.shardingsphere.governance.core.event.model.rule.RuleConfigurationsChangedEvent;
 import 
org.apache.shardingsphere.governance.core.event.model.metadata.MetaDataAddedEvent;
 import 
org.apache.shardingsphere.governance.core.event.model.metadata.MetaDataDeletedEvent;
+import 
org.apache.shardingsphere.governance.core.event.model.props.PropertiesChangedEvent;
+import 
org.apache.shardingsphere.governance.core.event.model.rule.RuleConfigurationsChangedEvent;
+import 
org.apache.shardingsphere.governance.core.event.model.schema.SchemaChangedEvent;
 import org.apache.shardingsphere.governance.core.facade.GovernanceFacade;
-import 
org.apache.shardingsphere.governance.core.registry.event.CircuitStateChangedEvent;
 import 
org.apache.shardingsphere.governance.core.registry.event.DisabledStateChangedEvent;
 import 
org.apache.shardingsphere.governance.core.registry.schema.GovernanceSchema;
 import org.apache.shardingsphere.infra.auth.Authentication;
@@ -138,11 +137,6 @@ public final class GovernanceMetaDataContexts implements 
MetaDataContexts {
     }
     
     @Override
-    public boolean isCircuitBreak() {
-        return metaDataContexts.isCircuitBreak();
-    }
-    
-    @Override
     public void close() throws IOException {
         metaDataContexts.close();
         governanceFacade.close();
@@ -270,17 +264,6 @@ public final class GovernanceMetaDataContexts implements 
MetaDataContexts {
         }
     }
     
-    /**
-     * Renew circuit breaker state.
-     *
-     * @param event circuit state changed event
-     */
-    @Subscribe
-    public synchronized void renew(final CircuitStateChangedEvent event) {
-        metaDataContexts = new 
StandardMetaDataContexts(metaDataContexts.getMetaDataMap(), 
-                metaDataContexts.getExecutorKernel(), 
metaDataContexts.getAuthentication(), metaDataContexts.getProps(), 
metaDataContexts.getDatabaseType(), event.isCircuitBreak());
-    }
-    
     private ShardingSphereMetaData createAddedMetaData(final 
MetaDataAddedEvent event) throws SQLException {
         String schemaName = event.getSchemaName();
         Map<String, Map<String, DataSource>> dataSourcesMap = 
createDataSourcesMap(Collections.singletonMap(schemaName, 
diff --git 
a/shardingsphere-governance/shardingsphere-governance-core/shardingsphere-governance-core-context/src/test/java/org/apache/shardingsphere/governance/context/metadata/GovernanceMetaDataContextsTest.java
 
b/shardingsphere-governance/shardingsphere-governance-core/shardingsphere-governance-core-context/src/test/java/org/apache/shardingsphere/governance/context/metadata/GovernanceMetaDataContextsTest.java
index 3e461bf..2f0468f 100644
--- 
a/shardingsphere-governance/shardingsphere-governance-core/shardingsphere-governance-core-context/src/test/java/org/apache/shardingsphere/governance/context/metadata/GovernanceMetaDataContextsTest.java
+++ 
b/shardingsphere-governance/shardingsphere-governance-core/shardingsphere-governance-core-context/src/test/java/org/apache/shardingsphere/governance/context/metadata/GovernanceMetaDataContextsTest.java
@@ -27,7 +27,6 @@ import 
org.apache.shardingsphere.governance.core.event.model.rule.RuleConfigurat
 import 
org.apache.shardingsphere.governance.core.event.model.schema.SchemaChangedEvent;
 import org.apache.shardingsphere.governance.core.facade.GovernanceFacade;
 import org.apache.shardingsphere.governance.core.registry.RegistryCenter;
-import 
org.apache.shardingsphere.governance.core.registry.event.CircuitStateChangedEvent;
 import 
org.apache.shardingsphere.governance.core.registry.event.DisabledStateChangedEvent;
 import 
org.apache.shardingsphere.governance.core.registry.schema.GovernanceSchema;
 import org.apache.shardingsphere.infra.auth.Authentication;
@@ -144,11 +143,6 @@ public final class GovernanceMetaDataContextsTest {
     }
     
     @Test
-    public void assertIsCircuitBreak() {
-        assertFalse(governanceMetaDataContexts.isCircuitBreak());
-    }
-    
-    @Test
     public void assertSchemaAdd() throws SQLException {
         MetaDataAddedEvent event = new MetaDataAddedEvent("schema_add", new 
HashMap<>(), new LinkedList<>());
         
when(configCenter.loadDataSourceConfigurations("schema_add")).thenReturn(getDataSourceConfigurations());
@@ -235,11 +229,4 @@ public final class GovernanceMetaDataContextsTest {
         result.put("ds_2", 
DataSourceConfiguration.getDataSourceConfiguration(dataSource));
         return result;
     }
-    
-    @Test
-    public void assertCircuitStateChanged() {
-        CircuitStateChangedEvent event = new CircuitStateChangedEvent(true);
-        governanceMetaDataContexts.renew(event);
-        assertTrue(governanceMetaDataContexts.isCircuitBreak());
-    }
 }
diff --git 
a/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/metadata/MetaDataContexts.java
 
b/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/metadata/MetaDataContexts.java
index a8afc87..0c7f62b 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/metadata/MetaDataContexts.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/metadata/MetaDataContexts.java
@@ -72,11 +72,4 @@ public interface MetaDataContexts extends Closeable {
      * @return configuration properties
      */
     ConfigurationProperties getProps();
-    
-    /**
-     * Is circuit break or not.
-     * 
-     * @return is circuit break or not
-     */
-    boolean isCircuitBreak();
 }
diff --git 
a/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/metadata/impl/StandardMetaDataContexts.java
 
b/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/metadata/impl/StandardMetaDataContexts.java
index cdd5ae1..6597c83 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/metadata/impl/StandardMetaDataContexts.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/metadata/impl/StandardMetaDataContexts.java
@@ -49,16 +49,9 @@ public final class StandardMetaDataContexts implements 
MetaDataContexts {
     
     private final DatabaseType databaseType;
     
-    private final boolean isCircuitBreak;
-    
     public StandardMetaDataContexts() {
         // TODO MySQLDatabaseType is invalid because it can not update again
-        this(new HashMap<>(), null, new Authentication(), new 
ConfigurationProperties(new Properties()), new MySQLDatabaseType(), false);
-    }
-    
-    public StandardMetaDataContexts(final Map<String, ShardingSphereMetaData> 
metaDataMap, final ExecutorKernel executorKernel,
-                                    final Authentication authentication, final 
ConfigurationProperties props, final DatabaseType databaseType) {
-        this(metaDataMap, executorKernel, authentication, props, databaseType, 
false);
+        this(new HashMap<>(), null, new Authentication(), new 
ConfigurationProperties(new Properties()), new MySQLDatabaseType());
     }
     
     @Override
diff --git 
a/shardingsphere-infra/shardingsphere-infra-context/src/test/java/org/apache/shardingsphere/infra/context/metadata/MetaDataContextsBuilderTest.java
 
b/shardingsphere-infra/shardingsphere-infra-context/src/test/java/org/apache/shardingsphere/infra/context/metadata/MetaDataContextsBuilderTest.java
index 07b063f..89525de 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-context/src/test/java/org/apache/shardingsphere/infra/context/metadata/MetaDataContextsBuilderTest.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-context/src/test/java/org/apache/shardingsphere/infra/context/metadata/MetaDataContextsBuilderTest.java
@@ -32,7 +32,6 @@ import java.sql.SQLException;
 import java.util.Collections;
 import java.util.Properties;
 
-import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 
@@ -47,7 +46,6 @@ public final class MetaDataContextsBuilderTest {
         assertTrue(actual.getMetaDataMap().isEmpty());
         assertTrue(actual.getAuthentication().getUsers().isEmpty());
         assertTrue(actual.getProps().getProps().isEmpty());
-        assertFalse(actual.isCircuitBreak());
     }
     
     @Test
@@ -63,7 +61,6 @@ public final class MetaDataContextsBuilderTest {
         assertTrue(actual.getAuthentication().getUsers().isEmpty());
         assertThat(actual.getProps().getProps().size(), CoreMatchers.is(1));
         
assertThat(actual.getProps().getValue(ConfigurationPropertyKey.EXECUTOR_SIZE), 
CoreMatchers.is(1));
-        assertFalse(actual.isCircuitBreak());
     }
     
     @Test
@@ -79,7 +76,6 @@ public final class MetaDataContextsBuilderTest {
         assertTrue(actual.getAuthentication().getUsers().isEmpty());
         assertThat(actual.getProps().getProps().size(), CoreMatchers.is(1));
         
assertThat(actual.getProps().getValue(ConfigurationPropertyKey.EXECUTOR_SIZE), 
CoreMatchers.is(1));
-        assertFalse(actual.isCircuitBreak());
     }
     
     private void assertRules(final MetaDataContexts actual) {
diff --git 
a/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/main/java/org/apache/shardingsphere/driver/governance/internal/state/DriverStateContext.java
 
b/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/main/java/org/apache/shardingsphere/driver/governance/internal/state/DriverStateContext.java
index 3b45648..802ce9b 100644
--- 
a/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/main/java/org/apache/shardingsphere/driver/governance/internal/state/DriverStateContext.java
+++ 
b/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/main/java/org/apache/shardingsphere/driver/governance/internal/state/DriverStateContext.java
@@ -39,12 +39,12 @@ import java.util.concurrent.ConcurrentHashMap;
 @NoArgsConstructor(access = AccessLevel.PRIVATE)
 public final class DriverStateContext {
     
-    private static final Map<StateType, DriverState> STATE_MAP = new 
ConcurrentHashMap<>(3, 1);
+    private static final Map<StateType, DriverState> STATES = new 
ConcurrentHashMap<>(3, 1);
     
     static {
-        STATE_MAP.put(StateType.OK, new OKDriverState());
-        STATE_MAP.put(StateType.LOCK, new LockDriverState());
-        STATE_MAP.put(StateType.CIRCUIT_BREAK, new CircuitBreakDriverState());
+        STATES.put(StateType.OK, new OKDriverState());
+        STATES.put(StateType.LOCK, new LockDriverState());
+        STATES.put(StateType.CIRCUIT_BREAK, new CircuitBreakDriverState());
     }
     
     /**
@@ -58,6 +58,6 @@ public final class DriverStateContext {
      */
     public static Connection getConnection(final Map<String, DataSource> 
dataSourceMap, 
                                            final MetaDataContexts 
metaDataContexts, final TransactionContexts transactionContexts, final 
TransactionType transactionType) {
-        return 
STATE_MAP.get(StateContext.getCurrentState()).getConnection(dataSourceMap, 
metaDataContexts, transactionContexts, transactionType);
+        return 
STATES.get(StateContext.getCurrentState()).getConnection(dataSourceMap, 
metaDataContexts, transactionContexts, transactionType);
     }
 }
diff --git 
a/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/test/java/org/apache/shardingsphere/driver/governance/internal/state/impl/CircuitBreakDriverStateTest.java
 
b/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/test/java/org/apache/shardingsphere/driver/governance/internal/state/impl/CircuitBreakDriverStateTest.java
new file mode 100644
index 0000000..3859db7
--- /dev/null
+++ 
b/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/test/java/org/apache/shardingsphere/driver/governance/internal/state/impl/CircuitBreakDriverStateTest.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.driver.governance.internal.state.impl;
+
+import 
org.apache.shardingsphere.driver.governance.internal.circuit.connection.CircuitBreakerConnection;
+import org.apache.shardingsphere.infra.context.metadata.MetaDataContexts;
+import org.apache.shardingsphere.transaction.context.TransactionContexts;
+import org.apache.shardingsphere.transaction.core.TransactionType;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.util.Collections;
+
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
+
+public final class CircuitBreakDriverStateTest {
+    
+    @Test
+    public void assertGetConnection() {
+        Connection actual = new 
CircuitBreakDriverState().getConnection(Collections.emptyMap(), 
mock(MetaDataContexts.class), mock(TransactionContexts.class), 
TransactionType.LOCAL);
+        assertThat(actual, instanceOf(CircuitBreakerConnection.class));
+    }
+}
diff --git 
a/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/test/java/org/apache/shardingsphere/driver/governance/internal/state/impl/OKDriverStateTest.java
 
b/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/test/java/org/apache/shardingsphere/driver/governance/internal/state/impl/OKDriverStateTest.java
new file mode 100644
index 0000000..4bbe999
--- /dev/null
+++ 
b/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/test/java/org/apache/shardingsphere/driver/governance/internal/state/impl/OKDriverStateTest.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.driver.governance.internal.state.impl;
+
+import 
org.apache.shardingsphere.driver.jdbc.core.connection.ShardingSphereConnection;
+import org.apache.shardingsphere.infra.context.metadata.MetaDataContexts;
+import org.apache.shardingsphere.transaction.context.TransactionContexts;
+import org.apache.shardingsphere.transaction.core.TransactionType;
+import org.junit.Test;
+
+import javax.sql.DataSource;
+import java.sql.Connection;
+import java.util.Collections;
+
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
+import static org.mockito.Mockito.mock;
+
+public final class OKDriverStateTest {
+    
+    @Test
+    public void assertGetConnection() {
+        Connection actual = new OKDriverState().getConnection(
+                Collections.singletonMap("ds", mock(DataSource.class, 
RETURNS_DEEP_STUBS)), mock(MetaDataContexts.class), 
mock(TransactionContexts.class, RETURNS_DEEP_STUBS), TransactionType.LOCAL);
+        assertThat(actual, instanceOf(ShardingSphereConnection.class));
+    }
+}
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/java/org/apache/shardingsphere/proxy/initializer/impl/GovernanceBootstrapInitializerTest.java
 
b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/java/org/apache/shardingsphere/proxy/initializer/impl/GovernanceBootstrapInitializerTest.java
index fe71019..35679e9 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/java/org/apache/shardingsphere/proxy/initializer/impl/GovernanceBootstrapInitializerTest.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/java/org/apache/shardingsphere/proxy/initializer/impl/GovernanceBootstrapInitializerTest.java
@@ -216,7 +216,6 @@ public final class GovernanceBootstrapInitializerTest 
extends AbstractBootstrapI
         assertThat(actualMetaDataContexts.getDefaultMetaData(), 
is(metaDataContexts.getDefaultMetaData()));
         assertThat(actualMetaDataContexts.getAuthentication(), 
is(metaDataContexts.getAuthentication()));
         assertThat(actualMetaDataContexts.getProps(), 
is(metaDataContexts.getProps()));
-        assertThat(actualMetaDataContexts.isCircuitBreak(), 
is(metaDataContexts.isCircuitBreak()));
     }
     
     @Test
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/state/ProxyStateContext.java
 
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/state/ProxyStateContext.java
index 87c2ec8..b4b8c9f 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/state/ProxyStateContext.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/state/ProxyStateContext.java
@@ -37,12 +37,12 @@ import java.util.concurrent.ConcurrentHashMap;
 @NoArgsConstructor(access = AccessLevel.PRIVATE)
 public final class ProxyStateContext {
     
-    private static final Map<StateType, ProxyState> STATE_MAP = new 
ConcurrentHashMap<>(3, 1);
+    private static final Map<StateType, ProxyState> STATES = new 
ConcurrentHashMap<>(3, 1);
     
     static {
-        STATE_MAP.put(StateType.OK, new OKProxyState());
-        STATE_MAP.put(StateType.LOCK, new LockProxyState());
-        STATE_MAP.put(StateType.CIRCUIT_BREAK, new CircuitBreakProxyState());
+        STATES.put(StateType.OK, new OKProxyState());
+        STATES.put(StateType.LOCK, new LockProxyState());
+        STATES.put(StateType.CIRCUIT_BREAK, new CircuitBreakProxyState());
     }
     
     /**
@@ -55,6 +55,6 @@ public final class ProxyStateContext {
      */
     public static void execute(final ChannelHandlerContext context, final 
Object message, 
                                final DatabaseProtocolFrontendEngine 
databaseProtocolFrontendEngine, final BackendConnection backendConnection) {
-        STATE_MAP.get(StateContext.getCurrentState()).execute(context, 
message, databaseProtocolFrontendEngine, backendConnection);
+        STATES.get(StateContext.getCurrentState()).execute(context, message, 
databaseProtocolFrontendEngine, backendConnection);
     }
 }

Reply via email to