You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by al...@apache.org on 2021/10/13 07:42:42 UTC

[dubbo] branch 3.0 updated: Extract constants and fix typo (#9019)

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

albumenj pushed a commit to branch 3.0
in repository https://gitbox.apache.org/repos/asf/dubbo.git


The following commit(s) were added to refs/heads/3.0 by this push:
     new 3a3fa4a  Extract constants and fix typo (#9019)
3a3fa4a is described below

commit 3a3fa4a4c32b177d74058c68d8167190b949d371
Author: 灼华 <43...@users.noreply.github.com>
AuthorDate: Wed Oct 13 15:42:29 2021 +0800

    Extract constants and fix typo (#9019)
---
 .../dubbo/common/constants/CommonConstants.java    |  2 +
 ...egistryCenterExportProviderIntegrationTest.java |  3 +-
 .../registry/integration/RegistryProtocol.java     | 24 +++++---
 .../dubbo/registry/retry/AbstractRetryTask.java    |  2 +-
 .../apache/dubbo/registry/retry/ReExportTask.java  |  2 +-
 .../dubbo/registry/support/AbstractRegistry.java   |  2 +-
 .../support/CacheableFailbackRegistry.java         |  2 +-
 ...est.java => CacheableFailbackRegistryTest.java} |  4 +-
 .../registry/integration/RegistryProtocolTest.java | 15 ++---
 .../registry/support/AbstractRegistryTest.java     | 40 ++++++-------
 .../registry/support/FailbackRegistryTest.java     | 69 +++++++---------------
 11 files changed, 73 insertions(+), 92 deletions(-)

diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java b/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java
index a45c12e..17e94a0 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java
@@ -304,6 +304,8 @@ public interface CommonConstants {
 
     String INVOKER_LISTENER_KEY = "invoker.listener";
 
+    String REGISTRY_PROTOCOL_LISTENER_KEY = "registry.protocol.listener";
+
     String DUBBO_VERSION_KEY = "dubbo";
 
     String TAG_KEY = "dubbo.tag";
diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/exportprovider/SingleRegistryCenterExportProviderIntegrationTest.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/exportprovider/SingleRegistryCenterExportProviderIntegrationTest.java
index bb511cc..5a92db8 100644
--- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/exportprovider/SingleRegistryCenterExportProviderIntegrationTest.java
+++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/integration/single/exportprovider/SingleRegistryCenterExportProviderIntegrationTest.java
@@ -46,6 +46,7 @@ import java.io.IOException;
 import java.util.HashMap;
 import java.util.Map;
 
+import static org.apache.dubbo.common.constants.CommonConstants.REGISTRY_PROTOCOL_LISTENER_KEY;
 import static org.apache.dubbo.integration.Constants.SINGLE_CONFIG_CENTER_EXPORT_PROVIDER;
 import static org.apache.dubbo.rpc.Constants.SCOPE_LOCAL;
 
@@ -124,7 +125,7 @@ public class SingleRegistryCenterExportProviderIntegrationTest implements Integr
             instance.getHostname(),
             instance.getPort()));
         Map<String, String> parameters = new HashMap<>();
-        parameters.put("registry.protocol.listener", "singleConfigCenterExportProvider");
+        parameters.put(REGISTRY_PROTOCOL_LISTENER_KEY, "singleConfigCenterExportProvider");
         registryConfig.updateParameters(parameters);
         DubboBootstrap.getInstance().registry(registryConfig);
     }
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java
index d9bb2f9..c2bedc3 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java
@@ -73,6 +73,7 @@ import static org.apache.dubbo.common.constants.CommonConstants.CLUSTER_KEY;
 import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN;
 import static org.apache.dubbo.common.constants.CommonConstants.DUBBO;
 import static org.apache.dubbo.common.constants.CommonConstants.DUBBO_VERSION_KEY;
+import static org.apache.dubbo.common.constants.CommonConstants.ENABLED_KEY;
 import static org.apache.dubbo.common.constants.CommonConstants.EXTRA_KEYS_KEY;
 import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
 import static org.apache.dubbo.common.constants.CommonConstants.HIDE_KEY_PREFIX;
@@ -82,6 +83,7 @@ import static org.apache.dubbo.common.constants.CommonConstants.METHODS_KEY;
 import static org.apache.dubbo.common.constants.CommonConstants.MONITOR_KEY;
 import static org.apache.dubbo.common.constants.CommonConstants.PATH_KEY;
 import static org.apache.dubbo.common.constants.CommonConstants.PROTOCOL_KEY;
+import static org.apache.dubbo.common.constants.CommonConstants.REGISTRY_PROTOCOL_LISTENER_KEY;
 import static org.apache.dubbo.common.constants.CommonConstants.RELEASE_KEY;
 import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY;
 import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY;
@@ -93,6 +95,7 @@ import static org.apache.dubbo.common.constants.QosConstants.QOS_PORT;
 import static org.apache.dubbo.common.constants.RegistryConstants.ALL_CATEGORIES;
 import static org.apache.dubbo.common.constants.RegistryConstants.CATEGORY_KEY;
 import static org.apache.dubbo.common.constants.RegistryConstants.CONFIGURATORS_CATEGORY;
+import static org.apache.dubbo.common.constants.RegistryConstants.DYNAMIC_KEY;
 import static org.apache.dubbo.common.constants.RegistryConstants.OVERRIDE_PROTOCOL;
 import static org.apache.dubbo.common.constants.RegistryConstants.REGISTRY_KEY;
 import static org.apache.dubbo.common.constants.RegistryConstants.SERVICE_REGISTRY_PROTOCOL;
@@ -261,7 +264,7 @@ public class RegistryProtocol implements Protocol, ScopeModelAware {
     private <T> void notifyExport(ExporterChangeableWrapper<T> exporter) {
         ScopeModel scopeModel = exporter.getRegisterUrl().getScopeModel();
         List<RegistryProtocolListener> listeners = ScopeModelUtil.getExtensionLoader(RegistryProtocolListener.class, scopeModel)
-            .getActivateExtension(exporter.getOriginInvoker().getUrl(), "registry.protocol.listener");
+            .getActivateExtension(exporter.getOriginInvoker().getUrl(), REGISTRY_PROTOCOL_LISTENER_KEY);
         if (CollectionUtils.isNotEmpty(listeners)) {
             for (RegistryProtocolListener listener : listeners) {
                 listener.onExport(this, exporter);
@@ -342,7 +345,7 @@ public class RegistryProtocol implements Protocol, ScopeModelAware {
     private <T> void doReExport(final Invoker<T> originInvoker, ExporterChangeableWrapper<T> exporter,
                                 URL registryUrl, URL oldProviderUrl, URL newProviderUrl) {
         if (getProviderUrl(originInvoker).getParameter(REGISTER_KEY, true)) {
-            Registry registry = null;
+            Registry registry;
             try {
                 registry = getRegistry(getRegistryUrl(originInvoker));
             } catch (Exception e) {
@@ -454,7 +457,7 @@ public class RegistryProtocol implements Protocol, ScopeModelAware {
      */
     private String getCacheKey(final Invoker<?> originInvoker) {
         URL providerUrl = getProviderUrl(originInvoker);
-        String key = providerUrl.removeParameters("dynamic", "enabled").toFullString();
+        String key = providerUrl.removeParameters(DYNAMIC_KEY, ENABLED_KEY).toFullString();
         return key;
     }
 
@@ -575,7 +578,7 @@ public class RegistryProtocol implements Protocol, ScopeModelAware {
 
     protected List<RegistryProtocolListener> findRegistryProtocolListeners(URL url) {
         return ScopeModelUtil.getExtensionLoader(RegistryProtocolListener.class, url.getScopeModel())
-            .getActivateExtension(url, "registry.protocol.listener");
+            .getActivateExtension(url, REGISTRY_PROTOCOL_LISTENER_KEY);
     }
 
     // available to test
@@ -632,7 +635,7 @@ public class RegistryProtocol implements Protocol, ScopeModelAware {
 
     //Merge the urls of configurators
     private static URL getConfiguredInvokerUrl(List<Configurator> configurators, URL url) {
-        if (configurators != null && configurators.size() > 0) {
+        if (CollectionUtils.isNotEmpty(configurators)) {
             for (Configurator configurator : configurators) {
                 url = configurator.configure(url);
             }
@@ -682,7 +685,7 @@ public class RegistryProtocol implements Protocol, ScopeModelAware {
 
     /**
      * Reexport: the exporter destroy problem in protocol
-     * 1.Ensure that the exporter returned by registryprotocol can be normal destroyed
+     * 1.Ensure that the exporter returned by registry protocol can be normal destroyed
      * 2.No need to re-register to the registry after notify
      * 3.The invoker passed by the export method , would better to be the invoker of exporter
      */
@@ -690,7 +693,6 @@ public class RegistryProtocol implements Protocol, ScopeModelAware {
         private final URL subscribeUrl;
         private final Invoker originInvoker;
 
-
         private List<Configurator> configurators;
 
         public OverrideListener(URL subscribeUrl, Invoker originalInvoker) {
@@ -704,11 +706,15 @@ public class RegistryProtocol implements Protocol, ScopeModelAware {
          */
         @Override
         public synchronized void notify(List<URL> urls) {
-            logger.debug("original override urls: " + urls);
+            if (logger.isDebugEnabled()) {
+                logger.debug("original override urls: " + urls);
+            }
 
             List<URL> matchedUrls = getMatchedUrls(urls, subscribeUrl.addParameter(CATEGORY_KEY,
                 CONFIGURATORS_CATEGORY));
-            logger.debug("subscribe url: " + subscribeUrl + ", override urls: " + matchedUrls);
+            if (logger.isDebugEnabled()) {
+                logger.debug("subscribe url: " + subscribeUrl + ", override urls: " + matchedUrls);
+            }
 
             // No matching results
             if (matchedUrls.isEmpty()) {
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/retry/AbstractRetryTask.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/retry/AbstractRetryTask.java
index 4c1f75e..ac939c7 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/retry/AbstractRetryTask.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/retry/AbstractRetryTask.java
@@ -53,7 +53,7 @@ public abstract class AbstractRetryTask implements TimerTask {
     /**
      * retry period
      */
-    final long retryPeriod;
+    private final long retryPeriod;
 
     /**
      * define the most retry times
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/retry/ReExportTask.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/retry/ReExportTask.java
index 952bbba..31e151c 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/retry/ReExportTask.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/retry/ReExportTask.java
@@ -21,7 +21,7 @@ import org.apache.dubbo.common.timer.Timeout;
 import org.apache.dubbo.registry.support.FailbackRegistry;
 
 /**
- *
+ * ReExportTask
  */
 public class ReExportTask extends AbstractRetryTask {
 
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistry.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistry.java
index 9232c16..21b5bd9 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistry.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistry.java
@@ -182,7 +182,7 @@ public abstract class AbstractRegistry implements Registry {
                 lockfile.createNewFile();
             }
             try (RandomAccessFile raf = new RandomAccessFile(lockfile, "rw");
-                 FileChannel channel = raf.getChannel()) {
+                FileChannel channel = raf.getChannel()) {
                 FileLock lock = channel.tryLock();
                 if (lock == null) {
                     throw new IOException("Can not lock the registry cache file " + file.getAbsolutePath() + ", ignore and retry later, maybe multi java process use the file, please config: dubbo.registry.file=xxx.properties");
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/CacheableFailbackRegistry.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/CacheableFailbackRegistry.java
index 45066f2..bc8b986 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/CacheableFailbackRegistry.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/CacheableFailbackRegistry.java
@@ -199,7 +199,7 @@ public abstract class CacheableFailbackRegistry extends FailbackRegistry {
         boolean encoded = true;
         // use encoded value directly to avoid URLDecoder.decode allocation.
         int paramStartIdx = rawProvider.indexOf(ENCODED_QUESTION_MARK);
-        if (paramStartIdx == -1) {// if ENCODED_QUESTION_MARK does not shown, mark as not encoded.
+        if (paramStartIdx == -1) {// if ENCODED_QUESTION_MARK does not show, mark as not encoded.
             encoded = false;
         }
         String[] parts = URLStrParser.parseRawURLToArrays(rawProvider, paramStartIdx);
diff --git a/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/CacheableFallbackRegistryTest.java b/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/CacheableFailbackRegistryTest.java
similarity index 98%
rename from dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/CacheableFallbackRegistryTest.java
rename to dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/CacheableFailbackRegistryTest.java
index c57b8aa..118e86f 100644
--- a/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/CacheableFallbackRegistryTest.java
+++ b/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/CacheableFailbackRegistryTest.java
@@ -28,7 +28,7 @@ import java.util.concurrent.atomic.AtomicReference;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
-public class CacheableFallbackRegistryTest {
+public class CacheableFailbackRegistryTest {
 
     static String service;
     static URL serviceUrl;
@@ -142,7 +142,7 @@ public class CacheableFallbackRegistryTest {
     }
 
     @Test
-    public void testRemove() throws Exception {
+    public void testRemove() {
         final AtomicReference<Integer> resCount = new AtomicReference<>(0);
         registry = new MockCacheableRegistryImpl(registryUrl);
         URL url = URLStrParser.parseEncodedStr(urlStr);
diff --git a/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/integration/RegistryProtocolTest.java b/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/integration/RegistryProtocolTest.java
index 8695411..6a04bb9 100644
--- a/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/integration/RegistryProtocolTest.java
+++ b/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/integration/RegistryProtocolTest.java
@@ -50,6 +50,7 @@ import static org.apache.dubbo.common.constants.CommonConstants.DUBBO;
 import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
 import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY;
 import static org.apache.dubbo.common.constants.CommonConstants.PROTOCOL_KEY;
+import static org.apache.dubbo.common.constants.CommonConstants.REGISTRY_PROTOCOL_LISTENER_KEY;
 import static org.apache.dubbo.common.constants.RegistryConstants.CATEGORY_KEY;
 import static org.apache.dubbo.common.constants.RegistryConstants.CONSUMERS_CATEGORY;
 import static org.apache.dubbo.registry.Constants.ENABLE_CONFIGURATION_LISTEN;
@@ -115,7 +116,7 @@ public class RegistryProtocolTest {
         moduleModel.getApplicationModel().getApplicationConfigManager().setApplication(new ApplicationConfig("application1"));
         ExtensionLoader<RegistryProtocolListener> extensionLoaderMock = mock(ExtensionLoader.class);
         Mockito.when(moduleModel.getExtensionLoader(RegistryProtocolListener.class)).thenReturn(extensionLoaderMock);
-        Mockito.when(extensionLoaderMock.getActivateExtension(url, "registry.protocol.listener"))
+        Mockito.when(extensionLoaderMock.getActivateExtension(url, REGISTRY_PROTOCOL_LISTENER_KEY))
             .thenReturn(registryProtocolListeners);
         url = url.setScopeModel(moduleModel);
 
@@ -182,7 +183,7 @@ public class RegistryProtocolTest {
         moduleModel.getApplicationModel().getApplicationConfigManager().setApplication(new ApplicationConfig("application1"));
         ExtensionLoader<RegistryProtocolListener> extensionLoaderMock = mock(ExtensionLoader.class);
         Mockito.when(moduleModel.getExtensionLoader(RegistryProtocolListener.class)).thenReturn(extensionLoaderMock);
-        Mockito.when(extensionLoaderMock.getActivateExtension(url, "registry.protocol.listener"))
+        Mockito.when(extensionLoaderMock.getActivateExtension(url, REGISTRY_PROTOCOL_LISTENER_KEY))
             .thenReturn(registryProtocolListeners);
         url = url.setScopeModel(moduleModel);
 
@@ -251,7 +252,7 @@ public class RegistryProtocolTest {
         moduleModel.getApplicationModel().getApplicationConfigManager().setApplication(new ApplicationConfig("application1"));
         ExtensionLoader extensionLoaderMock = mock(ExtensionLoader.class);
         Mockito.when(moduleModel.getExtensionLoader(RegistryProtocolListener.class)).thenReturn(extensionLoaderMock);
-        Mockito.when(extensionLoaderMock.getActivateExtension(url, "registry.protocol.listener"))
+        Mockito.when(extensionLoaderMock.getActivateExtension(url, REGISTRY_PROTOCOL_LISTENER_KEY))
             .thenReturn(registryProtocolListeners);
         Mockito.when(moduleModel.getExtensionLoader(RegistryFactory.class)).thenReturn(extensionLoaderMock);
         Mockito.when(extensionLoaderMock.getAdaptiveExtension()).thenReturn(registryFactory);
@@ -313,7 +314,7 @@ public class RegistryProtocolTest {
         moduleModel.getApplicationModel().getApplicationConfigManager().setApplication(new ApplicationConfig("application1"));
         ExtensionLoader extensionLoaderMock = mock(ExtensionLoader.class);
         Mockito.when(moduleModel.getExtensionLoader(RegistryProtocolListener.class)).thenReturn(extensionLoaderMock);
-        Mockito.when(extensionLoaderMock.getActivateExtension(url, "registry.protocol.listener"))
+        Mockito.when(extensionLoaderMock.getActivateExtension(url, REGISTRY_PROTOCOL_LISTENER_KEY))
             .thenReturn(registryProtocolListeners);
         Mockito.when(moduleModel.getExtensionLoader(RegistryFactory.class)).thenReturn(extensionLoaderMock);
         Mockito.when(extensionLoaderMock.getAdaptiveExtension()).thenReturn(registryFactory);
@@ -387,7 +388,7 @@ public class RegistryProtocolTest {
         moduleModel.getApplicationModel().getApplicationConfigManager().setApplication(new ApplicationConfig("application1"));
         ExtensionLoader<RegistryProtocolListener> extensionLoaderMock = mock(ExtensionLoader.class);
         Mockito.when(moduleModel.getExtensionLoader(RegistryProtocolListener.class)).thenReturn(extensionLoaderMock);
-        Mockito.when(extensionLoaderMock.getActivateExtension(url, "registry.protocol.listener"))
+        Mockito.when(extensionLoaderMock.getActivateExtension(url, REGISTRY_PROTOCOL_LISTENER_KEY))
             .thenReturn(registryProtocolListeners);
         url = url.setScopeModel(moduleModel);
 
@@ -418,7 +419,7 @@ public class RegistryProtocolTest {
         parameters.put(INTERFACE_KEY, DemoService.class.getName());
         parameters.put("registry", "zookeeper");
         parameters.put("register", "false");
-        parameters.put("registry.protocol.listener", "count");
+        parameters.put(REGISTRY_PROTOCOL_LISTENER_KEY, "count");
 
         Map<String, Object> attributes = new HashMap<>();
         ServiceConfigURL serviceConfigURL = new ServiceConfigURL(
@@ -453,7 +454,7 @@ public class RegistryProtocolTest {
         moduleModel.getApplicationModel().getApplicationConfigManager().setApplication(new ApplicationConfig("application1"));
         ExtensionLoader<RegistryProtocolListener> extensionLoaderMock = mock(ExtensionLoader.class);
         Mockito.when(moduleModel.getExtensionLoader(RegistryProtocolListener.class)).thenReturn(extensionLoaderMock);
-        Mockito.when(extensionLoaderMock.getActivateExtension(url, "registry.protocol.listener"))
+        Mockito.when(extensionLoaderMock.getActivateExtension(url, REGISTRY_PROTOCOL_LISTENER_KEY))
             .thenReturn(registryProtocolListeners);
         url = url.setScopeModel(moduleModel);
 
diff --git a/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/support/AbstractRegistryTest.java b/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/support/AbstractRegistryTest.java
index ccce6a7..8114694 100644
--- a/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/support/AbstractRegistryTest.java
+++ b/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/support/AbstractRegistryTest.java
@@ -109,7 +109,7 @@ public class AbstractRegistryTest {
     }
 
     @Test
-    public void testRegisterIfURLNULL() throws Exception {
+    public void testRegisterIfURLNULL() {
         Assertions.assertThrows(IllegalArgumentException.class, () -> {
             abstractRegistry.register(null);
             Assertions.fail("register url == null");
@@ -120,10 +120,9 @@ public class AbstractRegistryTest {
      * Test method for
      * {@link org.apache.dubbo.registry.support.AbstractRegistry#unregister(URL)}.
      *
-     * @throws Exception
      */
     @Test
-    public void testUnregister() throws Exception {
+    public void testUnregister() {
         //test one unregister
         URL url = new ServiceConfigURL("dubbo", "192.168.0.1", 2200);
         abstractRegistry.register(url);
@@ -144,7 +143,7 @@ public class AbstractRegistryTest {
     }
 
     @Test
-    public void testUnregisterIfUrlNull() throws Exception {
+    public void testUnregisterIfUrlNull() {
         Assertions.assertThrows(IllegalArgumentException.class, () -> {
             abstractRegistry.unregister(null);
             Assertions.fail("unregister url == null");
@@ -155,7 +154,7 @@ public class AbstractRegistryTest {
      * test subscribe and unsubscribe
      */
     @Test
-    public void testSubscribeAndUnsubscribe() throws Exception {
+    public void testSubscribeAndUnsubscribe() {
         //test subscribe
         final AtomicReference<Boolean> notified = new AtomicReference<Boolean>(false);
         NotifyListener listener = urls -> notified.set(Boolean.TRUE);
@@ -170,7 +169,7 @@ public class AbstractRegistryTest {
     }
 
     @Test
-    public void testSubscribeIfUrlNull() throws Exception {
+    public void testSubscribeIfUrlNull() {
         Assertions.assertThrows(IllegalArgumentException.class, () -> {
             final AtomicReference<Boolean> notified = new AtomicReference<Boolean>(false);
             NotifyListener listener = urls -> notified.set(Boolean.TRUE);
@@ -181,7 +180,7 @@ public class AbstractRegistryTest {
     }
 
     @Test
-    public void testSubscribeIfListenerNull() throws Exception {
+    public void testSubscribeIfListenerNull() {
         Assertions.assertThrows(IllegalArgumentException.class, () -> {
             final AtomicReference<Boolean> notified = new AtomicReference<Boolean>(false);
             NotifyListener listener = urls -> notified.set(Boolean.TRUE);
@@ -192,7 +191,7 @@ public class AbstractRegistryTest {
     }
 
     @Test
-    public void testUnsubscribeIfUrlNull() throws Exception {
+    public void testUnsubscribeIfUrlNull() {
         Assertions.assertThrows(IllegalArgumentException.class, () -> {
             final AtomicReference<Boolean> notified = new AtomicReference<Boolean>(false);
             NotifyListener listener = urls -> notified.set(Boolean.TRUE);
@@ -202,7 +201,7 @@ public class AbstractRegistryTest {
     }
 
     @Test
-    public void testUnsubscribeIfNotifyNull() throws Exception {
+    public void testUnsubscribeIfNotifyNull() {
         Assertions.assertThrows(IllegalArgumentException.class, () -> {
             final AtomicReference<Boolean> notified = new AtomicReference<Boolean>(false);
             URL url = new ServiceConfigURL("dubbo", "192.168.0.1", 2200);
@@ -215,10 +214,9 @@ public class AbstractRegistryTest {
      * Test method for
      * {@link org.apache.dubbo.registry.support.AbstractRegistry#subscribe(URL, NotifyListener)}.
      *
-     * @throws Exception
      */
     @Test
-    public void testSubscribe() throws Exception {
+    public void testSubscribe() {
         // check parameters
         try {
             abstractRegistry.subscribe(testUrl, null);
@@ -244,10 +242,9 @@ public class AbstractRegistryTest {
      * Test method for
      * {@link org.apache.dubbo.registry.support.AbstractRegistry#unsubscribe(URL, NotifyListener)}.
      *
-     * @throws Exception
      */
     @Test
-    public void testUnsubscribe() throws Exception {
+    public void testUnsubscribe() {
         // check parameters
         try {
             abstractRegistry.unsubscribe(testUrl, null);
@@ -312,7 +309,7 @@ public class AbstractRegistryTest {
      * {@link org.apache.dubbo.registry.support.AbstractRegistry#notify(List)}.
      */
     @Test
-    public void testNotify() throws Exception {
+    public void testNotify() {
         final AtomicReference<Boolean> notified = new AtomicReference<Boolean>(false);
         NotifyListener listener1 = urls -> notified.set(Boolean.TRUE);
         URL url1 = new ServiceConfigURL("dubbo", "192.168.0.1", 2200, parametersConsumer);
@@ -338,7 +335,7 @@ public class AbstractRegistryTest {
      * test notifyList
      */
     @Test
-    public void testNotifyList() throws Exception {
+    public void testNotifyList() {
         final AtomicReference<Boolean> notified = new AtomicReference<Boolean>(false);
         NotifyListener listener1 = urls -> notified.set(Boolean.TRUE);
         URL url1 = new ServiceConfigURL("dubbo", "192.168.0.1", 2200, parametersConsumer);
@@ -361,7 +358,7 @@ public class AbstractRegistryTest {
     }
 
     @Test
-    public void testNotifyIfURLNull() throws Exception {
+    public void testNotifyIfURLNull() {
         Assertions.assertThrows(IllegalArgumentException.class, () -> {
             final AtomicReference<Boolean> notified = new AtomicReference<Boolean>(false);
             NotifyListener listener1 = urls -> notified.set(Boolean.TRUE);
@@ -409,10 +406,9 @@ public class AbstractRegistryTest {
      * Test method for
      * {@link org.apache.dubbo.registry.support.AbstractRegistry#notify(URL, NotifyListener, List)}.
      *
-     * @throws Exception
      */
     @Test
-    public void testNotifyArgs() throws Exception {
+    public void testNotifyArgs() {
         // check parameters
         try {
             abstractRegistry.notify(null, null, null);
@@ -448,7 +444,7 @@ public class AbstractRegistryTest {
     }
 
     @Test
-    public void filterEmptyTest() throws Exception {
+    public void filterEmptyTest() {
         // check parameters
         try {
             AbstractRegistry.filterEmpty(null, null);
@@ -481,7 +477,7 @@ public class AbstractRegistryTest {
 
 
     @Test
-    public void lookupTest() throws Exception {
+    public void lookupTest() {
         // loop up before registry
         try {
             abstractRegistry.lookup(null);
@@ -501,7 +497,7 @@ public class AbstractRegistryTest {
     }
 
     @Test
-    public void destroyTest() throws Exception {
+    public void destroyTest() {
         abstractRegistry.register(testUrl);
         abstractRegistry.subscribe(testUrl, listener);
         Assertions.assertEquals(1, abstractRegistry.getRegistered().size());
@@ -513,7 +509,7 @@ public class AbstractRegistryTest {
     }
 
     @Test
-    public void allTest() throws Exception {
+    public void allTest() {
         // test all methods
         List<URL> urls = new ArrayList<>();
         urls.add(testUrl);
diff --git a/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/support/FailbackRegistryTest.java b/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/support/FailbackRegistryTest.java
index 76a02df..1fbaa34 100644
--- a/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/support/FailbackRegistryTest.java
+++ b/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/support/FailbackRegistryTest.java
@@ -25,7 +25,6 @@ import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
 import java.util.Arrays;
-import java.util.List;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.atomic.AtomicReference;
 
@@ -34,20 +33,18 @@ import static org.apache.dubbo.registry.Constants.REGISTRY_RETRY_PERIOD_KEY;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
 public class FailbackRegistryTest {
-    static String service;
-    static URL serviceUrl;
-    static URL registryUrl;
-    MockRegistry registry;
-    private int FAILED_PERIOD = 200;
-    private int sleeptime = 100;
-    private int trytimes = 5;
+    private static URL serviceUrl;
+    private static URL registryUrl;
+    private MockRegistry registry;
+    private final int FAILED_PERIOD = 200;
+    private final int sleepTime = 100;
+    private final int tryTimes = 5;
 
     /**
      * @throws java.lang.Exception
      */
     @BeforeEach
     public void setUp() throws Exception {
-        service = "org.apache.dubbo.test.DemoService";
         serviceUrl = URL.valueOf("remote://127.0.0.1/demoservice?method=get");
         registryUrl = URL.valueOf("http://1.2.3.4:9090/registry?check=false&file=N/A").addParameter(REGISTRY_RETRY_PERIOD_KEY, String.valueOf(FAILED_PERIOD));
     }
@@ -65,18 +62,13 @@ public class FailbackRegistryTest {
         // the latest latch just for 3. Because retry method has been removed.
         final CountDownLatch latch = new CountDownLatch(2);
 
-        NotifyListener listner = new NotifyListener() {
-            @Override
-            public void notify(List<URL> urls) {
-                notified.set(Boolean.TRUE);
-            }
-        };
+        NotifyListener listener = urls -> notified.set(Boolean.TRUE);
         registry = new MockRegistry(registryUrl, latch);
         registry.setBad(true);
         registry.register(serviceUrl);
         registry.unregister(serviceUrl);
-        registry.subscribe(serviceUrl.setProtocol(CONSUMER_PROTOCOL).addParameters(CollectionUtils.toStringMap("check", "false")), listner);
-        registry.unsubscribe(serviceUrl.setProtocol(CONSUMER_PROTOCOL).addParameters(CollectionUtils.toStringMap("check", "false")), listner);
+        registry.subscribe(serviceUrl.setProtocol(CONSUMER_PROTOCOL).addParameters(CollectionUtils.toStringMap("check", "false")), listener);
+        registry.unsubscribe(serviceUrl.setProtocol(CONSUMER_PROTOCOL).addParameters(CollectionUtils.toStringMap("check", "false")), listener);
 
         //Failure can not be called to listener.
         assertEquals(false, notified.get());
@@ -84,21 +76,20 @@ public class FailbackRegistryTest {
 
         registry.setBad(false);
 
-        for (int i = 0; i < trytimes; i++) {
+        for (int i = 0; i < tryTimes; i++) {
             System.out.println("failback registry retry ,times:" + i);
             //System.out.println(latch.getCount());
             if (latch.getCount() == 0)
                 break;
-            Thread.sleep(sleeptime);
+            Thread.sleep(sleepTime);
         }
-//        Thread.sleep(100000);//for debug
         assertEquals(0, latch.getCount());
-        //The failedsubcribe corresponding key will be cleared when unsubscribing
+        //The failed subscribe corresponding key will be cleared when unsubscribing
         assertEquals(false, notified.get());
     }
 
     @Test
-    public void testDoRetry_subscribe() throws Exception {
+    public void testDoRetryRegister() throws Exception {
 
         final CountDownLatch latch = new CountDownLatch(1);//All of them are called 4 times. A successful attempt to lose 1. subscribe will not be done
 
@@ -108,30 +99,25 @@ public class FailbackRegistryTest {
 
         registry.setBad(false);
 
-        for (int i = 0; i < trytimes; i++) {
+        for (int i = 0; i < tryTimes; i++) {
             System.out.println("failback registry retry ,times:" + i);
             if (latch.getCount() == 0)
                 break;
-            Thread.sleep(sleeptime);
+            Thread.sleep(sleepTime);
         }
         assertEquals(0, latch.getCount());
     }
 
     @Test
-    public void testDoRetry_register() throws Exception {
+    public void testDoRetrySubscribe() throws Exception {
 
         final AtomicReference<Boolean> notified = new AtomicReference<Boolean>(false);
         final CountDownLatch latch = new CountDownLatch(1);//All of them are called 4 times. A successful attempt to lose 1. subscribe will not be done
 
-        NotifyListener listner = new NotifyListener() {
-            @Override
-            public void notify(List<URL> urls) {
-                notified.set(Boolean.TRUE);
-            }
-        };
+        NotifyListener listener = urls -> notified.set(Boolean.TRUE);
         registry = new MockRegistry(registryUrl, latch);
         registry.setBad(true);
-        registry.subscribe(serviceUrl.setProtocol(CONSUMER_PROTOCOL).addParameters(CollectionUtils.toStringMap("check", "false")), listner);
+        registry.subscribe(serviceUrl.setProtocol(CONSUMER_PROTOCOL).addParameters(CollectionUtils.toStringMap("check", "false")), listener);
 
         //Failure can not be called to listener.
         assertEquals(false, notified.get());
@@ -139,16 +125,14 @@ public class FailbackRegistryTest {
 
         registry.setBad(false);
 
-        for (int i = 0; i < trytimes; i++) {
+        for (int i = 0; i < tryTimes; i++) {
             System.out.println("failback registry retry ,times:" + i);
-            //System.out.println(latch.getCount());
             if (latch.getCount() == 0)
                 break;
-            Thread.sleep(sleeptime);
+            Thread.sleep(sleepTime);
         }
-//        Thread.sleep(100000);
         assertEquals(0, latch.getCount());
-        //The failedsubcribe corresponding key will be cleared when unsubscribing
+        //The failed subscribe corresponding key will be cleared when unsubscribing
         assertEquals(true, notified.get());
     }
 
@@ -156,12 +140,7 @@ public class FailbackRegistryTest {
     public void testRecover() throws Exception {
         CountDownLatch countDownLatch = new CountDownLatch(6);
         final AtomicReference<Boolean> notified = new AtomicReference<Boolean>(false);
-        NotifyListener listener = new NotifyListener() {
-            @Override
-            public void notify(List<URL> urls) {
-                notified.set(Boolean.TRUE);
-            }
-        };
+        NotifyListener listener = urls -> notified.set(Boolean.TRUE);
 
         MockRegistry mockRegistry = new MockRegistry(registryUrl, countDownLatch);
         mockRegistry.register(serviceUrl);
@@ -200,7 +179,6 @@ public class FailbackRegistryTest {
             if (bad) {
                 throw new RuntimeException("can not invoke!");
             }
-            //System.out.println("do doRegister");
             latch.countDown();
 
         }
@@ -210,7 +188,6 @@ public class FailbackRegistryTest {
             if (bad) {
                 throw new RuntimeException("can not invoke!");
             }
-            //System.out.println("do doUnregister");
             latch.countDown();
 
         }
@@ -220,7 +197,6 @@ public class FailbackRegistryTest {
             if (bad) {
                 throw new RuntimeException("can not invoke!");
             }
-            //System.out.println("do doSubscribe");
             super.notify(url, listener, Arrays.asList(new URL[]{serviceUrl}));
             latch.countDown();
         }
@@ -230,7 +206,6 @@ public class FailbackRegistryTest {
             if (bad) {
                 throw new RuntimeException("can not invoke!");
             }
-            //System.out.println("do doUnsubscribe");
             latch.countDown();
         }