You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2020/11/17 12:10:56 UTC
[shardingsphere] branch master updated: Remove useless governance
codes (#8193)
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 a0d1743 Remove useless governance codes (#8193)
a0d1743 is described below
commit a0d1743e2f9c70f12e8686be4c94a32b3eb07978
Author: Liang Zhang <te...@163.com>
AuthorDate: Tue Nov 17 20:09:42 2020 +0800
Remove useless governance codes (#8193)
* Remove InstanceStateChangedListener
* Rename CreateEvent
* Remove CircuitStateChangedEvent
---
.../AuthenticationChangedListenerTest.java | 2 +-
.../listener/PropertiesChangedListenerTest.java | 2 +-
.../registry/event/CircuitStateChangedEvent.java | 32 ----------------
.../listener/InstanceStateChangedListener.java | 44 ----------------------
.../registry/listener/RegistryListenerManager.java | 4 --
.../DataSourceStateChangedListenerTest.java | 2 +-
.../listener/RegistryListenerManagerTest.java | 6 +--
....java => TerminalStateChangedListenerTest.java} | 20 +++++-----
8 files changed, 16 insertions(+), 96 deletions(-)
diff --git a/shardingsphere-governance/shardingsphere-governance-core/shardingsphere-governance-core-config/src/test/java/org/apache/shardingsphere/governance/core/config/listener/AuthenticationChangedListenerTest.java b/shardingsphere-governance/shardingsphere-governance-core/shardingsphere-governance-core-config/src/test/java/org/apache/shardingsphere/governance/core/config/listener/AuthenticationChangedListenerTest.java
index 2de8c53..1a2d55d 100644
--- a/shardingsphere-governance/shardingsphere-governance-core/shardingsphere-governance-core-config/src/test/java/org/apache/shardingsphere/governance/core/config/listener/AuthenticationChangedListenerTest.java
+++ b/shardingsphere-governance/shardingsphere-governance-core/shardingsphere-governance-core-config/src/test/java/org/apache/shardingsphere/governance/core/config/listener/AuthenticationChangedListenerTest.java
@@ -50,7 +50,7 @@ public final class AuthenticationChangedListenerTest {
}
@Test
- public void assertCreateGovernanceEvent() {
+ public void assertCreateEvent() {
Optional<Object> actual = authenticationChangedListener.createEvent(new DataChangedEvent("test", AUTHENTICATION_YAML, Type.UPDATED));
assertTrue(actual.isPresent());
assertThat(((AuthenticationChangedEvent) actual.get()).getAuthentication().getUsers().get("root1").getPassword(), is("root1"));
diff --git a/shardingsphere-governance/shardingsphere-governance-core/shardingsphere-governance-core-config/src/test/java/org/apache/shardingsphere/governance/core/config/listener/PropertiesChangedListenerTest.java b/shardingsphere-governance/shardingsphere-governance-core/shardingsphere-governance-core-config/src/test/java/org/apache/shardingsphere/governance/core/config/listener/PropertiesChangedListenerTest.java
index 1dd0ee5..0cffadc 100644
--- a/shardingsphere-governance/shardingsphere-governance-core/shardingsphere-governance-core-config/src/test/java/org/apache/shardingsphere/governance/core/config/listener/PropertiesChangedListenerTest.java
+++ b/shardingsphere-governance/shardingsphere-governance-core/shardingsphere-governance-core-config/src/test/java/org/apache/shardingsphere/governance/core/config/listener/PropertiesChangedListenerTest.java
@@ -50,7 +50,7 @@ public final class PropertiesChangedListenerTest {
}
@Test
- public void assertCreateGovernanceEvent() {
+ public void assertCreateEvent() {
Optional<Object> actual = propertiesChangedListener.createEvent(new DataChangedEvent("test", PROPERTIES_YAML, Type.UPDATED));
assertTrue(actual.isPresent());
assertThat(((PropertiesChangedEvent) actual.get()).getProps().get(ConfigurationPropertyKey.SQL_SHOW.getKey()), is(true));
diff --git a/shardingsphere-governance/shardingsphere-governance-core/shardingsphere-governance-core-registry/src/main/java/org/apache/shardingsphere/governance/core/registry/event/CircuitStateChangedEvent.java b/shardingsphere-governance/shardingsphere-governance-core/shardingsphere-governance-core-registry/src/main/java/org/apache/shardingsphere/governance/core/registry/event/CircuitStateChangedEvent.java
deleted file mode 100644
index 7db7c95..0000000
--- a/shardingsphere-governance/shardingsphere-governance-core/shardingsphere-governance-core-registry/src/main/java/org/apache/shardingsphere/governance/core/registry/event/CircuitStateChangedEvent.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * 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.governance.core.registry.event;
-
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.governance.core.event.model.GovernanceEvent;
-
-/**
- * Circuit state event.
- */
-@RequiredArgsConstructor
-@Getter
-public final class CircuitStateChangedEvent implements GovernanceEvent {
-
- private final boolean isCircuitBreak;
-}
diff --git a/shardingsphere-governance/shardingsphere-governance-core/shardingsphere-governance-core-registry/src/main/java/org/apache/shardingsphere/governance/core/registry/listener/InstanceStateChangedListener.java b/shardingsphere-governance/shardingsphere-governance-core/shardingsphere-governance-core-registry/src/main/java/org/apache/shardingsphere/governance/core/registry/listener/InstanceStateChangedListener.java
deleted file mode 100644
index 50fccfd..0000000
--- a/shardingsphere-governance/shardingsphere-governance-core/shardingsphere-governance-core-registry/src/main/java/org/apache/shardingsphere/governance/core/registry/listener/InstanceStateChangedListener.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * 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.governance.core.registry.listener;
-
-import org.apache.shardingsphere.governance.core.event.listener.PostGovernanceRepositoryEventListener;
-import org.apache.shardingsphere.governance.core.registry.RegistryCenterNode;
-import org.apache.shardingsphere.governance.core.registry.RegistryCenterNodeStatus;
-import org.apache.shardingsphere.governance.core.registry.event.CircuitStateChangedEvent;
-import org.apache.shardingsphere.governance.core.registry.instance.GovernanceInstance;
-import org.apache.shardingsphere.governance.repository.api.RegistryRepository;
-import org.apache.shardingsphere.governance.repository.api.listener.DataChangedEvent;
-
-import java.util.Collections;
-import java.util.Optional;
-
-/**
- * Instance state changed listener.
- */
-public final class InstanceStateChangedListener extends PostGovernanceRepositoryEventListener {
-
- public InstanceStateChangedListener(final RegistryRepository registryRepository) {
- super(registryRepository, Collections.singleton(new RegistryCenterNode().getProxyNodePath(GovernanceInstance.getInstance().getInstanceId())));
- }
-
- @Override
- protected Optional<Object> createEvent(final DataChangedEvent event) {
- return Optional.of(new CircuitStateChangedEvent(RegistryCenterNodeStatus.DISABLED.toString().equalsIgnoreCase(event.getValue())));
- }
-}
diff --git a/shardingsphere-governance/shardingsphere-governance-core/shardingsphere-governance-core-registry/src/main/java/org/apache/shardingsphere/governance/core/registry/listener/RegistryListenerManager.java b/shardingsphere-governance/shardingsphere-governance-core/shardingsphere-governance-core-registry/src/main/java/org/apache/shardingsphere/governance/core/registry/listener/RegistryListenerManager.java
index 5464708..5033679 100644
--- a/shardingsphere-governance/shardingsphere-governance-core/shardingsphere-governance-core-registry/src/main/java/org/apache/shardingsphere/governance/core/registry/listener/RegistryListenerManager.java
+++ b/shardingsphere-governance/shardingsphere-governance-core/shardingsphere-governance-core-registry/src/main/java/org/apache/shardingsphere/governance/core/registry/listener/RegistryListenerManager.java
@@ -27,14 +27,11 @@ import java.util.Collection;
*/
public final class RegistryListenerManager {
- private final InstanceStateChangedListener instanceStateChangedListener;
-
private final TerminalStateChangedListener terminalStateChangedListener;
private final DataSourceStateChangedListener dataSourceStateChangedListener;
public RegistryListenerManager(final RegistryRepository registryRepository, final Collection<String> schemaNames) {
- instanceStateChangedListener = new InstanceStateChangedListener(registryRepository);
terminalStateChangedListener = new TerminalStateChangedListener(registryRepository);
dataSourceStateChangedListener = new DataSourceStateChangedListener(registryRepository, schemaNames);
}
@@ -43,7 +40,6 @@ public final class RegistryListenerManager {
* Initialize all state changed listeners.
*/
public void initListeners() {
- instanceStateChangedListener.watch(Type.UPDATED);
terminalStateChangedListener.watch(Type.UPDATED);
dataSourceStateChangedListener.watch(Type.UPDATED, Type.DELETED, Type.ADDED);
}
diff --git a/shardingsphere-governance/shardingsphere-governance-core/shardingsphere-governance-core-registry/src/test/java/org/apache/shardingsphere/governance/core/registry/listener/DataSourceStateChangedListenerTest.java b/shardingsphere-governance/shardingsphere-governance-core/shardingsphere-governance-core-registry/src/test/java/org/apache/shardingsphere/governance/core/registry/listener/DataSourceStateChangedListenerTest.java
index ed71f33..369e36e 100644
--- a/shardingsphere-governance/shardingsphere-governance-core/shardingsphere-governance-core-registry/src/test/java/org/apache/shardingsphere/governance/core/registry/listener/DataSourceStateChangedListenerTest.java
+++ b/shardingsphere-governance/shardingsphere-governance-core/shardingsphere-governance-core-registry/src/test/java/org/apache/shardingsphere/governance/core/registry/listener/DataSourceStateChangedListenerTest.java
@@ -49,7 +49,7 @@ public final class DataSourceStateChangedListenerTest {
}
@Test
- public void assertCreateGovernanceEvent() {
+ public void assertCreateEvent() {
Optional<Object> actual = dataSourceStateChangedListener.createEvent(
new DataChangedEvent("/states/datanodes/replica_query_db/replica_ds_0", "disabled", Type.UPDATED));
assertTrue(actual.isPresent());
diff --git a/shardingsphere-governance/shardingsphere-governance-core/shardingsphere-governance-core-registry/src/test/java/org/apache/shardingsphere/governance/core/registry/listener/RegistryListenerManagerTest.java b/shardingsphere-governance/shardingsphere-governance-core/shardingsphere-governance-core-registry/src/test/java/org/apache/shardingsphere/governance/core/registry/listener/RegistryListenerManagerTest.java
index 2a47145b..c5fb69b 100644
--- a/shardingsphere-governance/shardingsphere-governance-core/shardingsphere-governance-core-registry/src/test/java/org/apache/shardingsphere/governance/core/registry/listener/RegistryListenerManagerTest.java
+++ b/shardingsphere-governance/shardingsphere-governance-core/shardingsphere-governance-core-registry/src/test/java/org/apache/shardingsphere/governance/core/registry/listener/RegistryListenerManagerTest.java
@@ -36,7 +36,7 @@ public final class RegistryListenerManagerTest {
private RegistryRepository registryRepository;
@Mock
- private InstanceStateChangedListener instanceStateChangedListener;
+ private TerminalStateChangedListener terminalStateChangedListener;
@Mock
private DataSourceStateChangedListener dataSourceStateChangedListener;
@@ -44,10 +44,10 @@ public final class RegistryListenerManagerTest {
@Test
public void assertInitListeners() {
RegistryListenerManager actual = new RegistryListenerManager(registryRepository, Arrays.asList("sharding_db", "replica_query_db", "encrypt_db"));
- FieldUtil.setField(actual, "instanceStateChangedListener", instanceStateChangedListener);
+ FieldUtil.setField(actual, "terminalStateChangedListener", terminalStateChangedListener);
FieldUtil.setField(actual, "dataSourceStateChangedListener", dataSourceStateChangedListener);
actual.initListeners();
- verify(instanceStateChangedListener).watch(Type.UPDATED);
+ verify(terminalStateChangedListener).watch(Type.UPDATED);
verify(dataSourceStateChangedListener).watch(Type.UPDATED, Type.DELETED, Type.ADDED);
}
}
diff --git a/shardingsphere-governance/shardingsphere-governance-core/shardingsphere-governance-core-registry/src/test/java/org/apache/shardingsphere/governance/core/registry/listener/InstanceStateChangedListenerTest.java b/shardingsphere-governance/shardingsphere-governance-core/shardingsphere-governance-core-registry/src/test/java/org/apache/shardingsphere/governance/core/registry/listener/TerminalStateChangedListenerTest.java
similarity index 74%
rename from shardingsphere-governance/shardingsphere-governance-core/shardingsphere-governance-core-registry/src/test/java/org/apache/shardingsphere/governance/core/registry/listener/InstanceStateChangedListenerTest.java
rename to shardingsphere-governance/shardingsphere-governance-core/shardingsphere-governance-core-registry/src/test/java/org/apache/shardingsphere/governance/core/registry/listener/TerminalStateChangedListenerTest.java
index 44dff99..451814d 100644
--- a/shardingsphere-governance/shardingsphere-governance-core/shardingsphere-governance-core-registry/src/test/java/org/apache/shardingsphere/governance/core/registry/listener/InstanceStateChangedListenerTest.java
+++ b/shardingsphere-governance/shardingsphere-governance-core/shardingsphere-governance-core-registry/src/test/java/org/apache/shardingsphere/governance/core/registry/listener/TerminalStateChangedListenerTest.java
@@ -18,10 +18,10 @@
package org.apache.shardingsphere.governance.core.registry.listener;
import org.apache.shardingsphere.governance.core.registry.RegistryCenterNodeStatus;
-import org.apache.shardingsphere.governance.core.registry.event.CircuitStateChangedEvent;
import org.apache.shardingsphere.governance.repository.api.RegistryRepository;
import org.apache.shardingsphere.governance.repository.api.listener.DataChangedEvent;
import org.apache.shardingsphere.governance.repository.api.listener.DataChangedEvent.Type;
+import org.apache.shardingsphere.infra.state.StateEvent;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -34,29 +34,29 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@RunWith(MockitoJUnitRunner.class)
-public final class InstanceStateChangedListenerTest {
+public final class TerminalStateChangedListenerTest {
- private InstanceStateChangedListener instanceStateChangedListener;
+ private TerminalStateChangedListener terminalStateChangedListener;
@Mock
private RegistryRepository registryRepository;
@Before
public void setUp() {
- instanceStateChangedListener = new InstanceStateChangedListener(registryRepository);
+ terminalStateChangedListener = new TerminalStateChangedListener(registryRepository);
}
@Test
- public void assertCreateGovernanceEventWhenEnabled() {
- Optional<Object> actual = instanceStateChangedListener.createEvent(new DataChangedEvent("/test_ds", "", Type.UPDATED));
+ public void assertCreateEventWhenEnabled() {
+ Optional<Object> actual = terminalStateChangedListener.createEvent(new DataChangedEvent("/test_ds", "", Type.UPDATED));
assertTrue(actual.isPresent());
- assertFalse(((CircuitStateChangedEvent) actual.get()).isCircuitBreak());
+ assertFalse(((StateEvent) actual.get()).isOn());
}
@Test
- public void assertCreateGovernanceEventWhenDisabled() {
- Optional<Object> actual = instanceStateChangedListener.createEvent(new DataChangedEvent("/test_ds", RegistryCenterNodeStatus.DISABLED.name(), Type.UPDATED));
+ public void assertCreateEventWhenDisabled() {
+ Optional<Object> actual = terminalStateChangedListener.createEvent(new DataChangedEvent("/test_ds", RegistryCenterNodeStatus.DISABLED.name(), Type.UPDATED));
assertTrue(actual.isPresent());
- assertTrue(((CircuitStateChangedEvent) actual.get()).isCircuitBreak());
+ assertTrue(((StateEvent) actual.get()).isOn());
}
}