You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by li...@apache.org on 2019/12/03 03:25:42 UTC

[dubbo] branch configmanger-bugfix created (now 92c0cb2)

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

liujun pushed a change to branch configmanger-bugfix
in repository https://gitbox.apache.org/repos/asf/dubbo.git.


      at 92c0cb2  Fix addConfig and getConfig in ConfigManger does not match.

This branch includes the following new commits:

     new 92c0cb2  Fix addConfig and getConfig in ConfigManger does not match.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[dubbo] 01/01: Fix addConfig and getConfig in ConfigManger does not match.

Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

liujun pushed a commit to branch configmanger-bugfix
in repository https://gitbox.apache.org/repos/asf/dubbo.git

commit 92c0cb287095161b7fa7367b4806deb64860d3dc
Author: ken.lj <ke...@gmail.com>
AuthorDate: Tue Dec 3 11:25:25 2019 +0800

    Fix addConfig and getConfig in ConfigManger does not match.
---
 .../apache/dubbo/config/context/ConfigManager.java | 28 ++++++++++++----------
 .../dubbo/config/context/ConfigManagerTest.java    |  4 ++--
 2 files changed, 18 insertions(+), 14 deletions(-)

diff --git a/dubbo-common/src/main/java/org/apache/dubbo/config/context/ConfigManager.java b/dubbo-common/src/main/java/org/apache/dubbo/config/context/ConfigManager.java
index a49876d..dfd91a9 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/config/context/ConfigManager.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/config/context/ConfigManager.java
@@ -179,7 +179,7 @@ public class ConfigManager extends LifecycleAdapter implements FrameworkExt {
     }
 
     public Optional<ProviderConfig> getDefaultProvider() {
-        return getProvider(DEFAULT_KEY);
+        return getProvider(genDefaultId(ProviderConfig.class));
     }
 
     public Collection<ProviderConfig> getProviders() {
@@ -201,7 +201,7 @@ public class ConfigManager extends LifecycleAdapter implements FrameworkExt {
     }
 
     public Optional<ConsumerConfig> getDefaultConsumer() {
-        return getConsumer(DEFAULT_KEY);
+        return getConsumer(genDefaultId(ConsumerConfig.class));
     }
 
     public Collection<ConsumerConfig> getConsumers() {
@@ -336,7 +336,7 @@ public class ConfigManager extends LifecycleAdapter implements FrameworkExt {
     }
 
     /**
-     * In some scenario,  we may nee to add and remove ServiceConfig or ReferenceConfig dynamically.
+     * In some scenario,  we may need to add and remove ServiceConfig or ReferenceConfig dynamically.
      *
      * @param config the config instance to remove.
      */
@@ -351,13 +351,6 @@ public class ConfigManager extends LifecycleAdapter implements FrameworkExt {
         }
     }
 
-    // For test purpose
-    public void clear() {
-        write(() -> {
-            this.configsCache.clear();
-        });
-    }
-
     /**
      * Add the dubbo {@link AbstractConfig config}
      *
@@ -485,8 +478,7 @@ public class ConfigManager extends LifecycleAdapter implements FrameworkExt {
 
     static <C extends AbstractConfig> String getId(C config) {
         String id = config.getId();
-        return isNotEmpty(id) ? id : isDefaultConfig(config) ?
-                config.getClass().getSimpleName() + "#" + DEFAULT_KEY : null;
+        return isNotEmpty(id) ? id : (isDefaultConfig(config) ? genDefaultId(config.getClass()) : null);
     }
 
     static <C extends AbstractConfig> boolean isDefaultConfig(C config) {
@@ -500,4 +492,16 @@ public class ConfigManager extends LifecycleAdapter implements FrameworkExt {
                 .filter(ConfigManager::isDefaultConfig)
                 .collect(Collectors.toList());
     }
+
+    static String genDefaultId(Class<?> clazz) {
+        return clazz.getSimpleName() + "#" + DEFAULT_KEY;
+    }
+
+    // For test purpose
+    public void clear() {
+        write(() -> {
+            this.configsCache.clear();
+        });
+    }
+
 }
diff --git a/dubbo-common/src/test/java/org/apache/dubbo/config/context/ConfigManagerTest.java b/dubbo-common/src/test/java/org/apache/dubbo/config/context/ConfigManagerTest.java
index 2314370..07d0a52 100644
--- a/dubbo-common/src/test/java/org/apache/dubbo/config/context/ConfigManagerTest.java
+++ b/dubbo-common/src/test/java/org/apache/dubbo/config/context/ConfigManagerTest.java
@@ -132,7 +132,7 @@ public class ConfigManagerTest {
         Collection<ProviderConfig> configs = configManager.getProviders();
         assertEquals(1, configs.size());
         assertEquals(config, configs.iterator().next());
-        assertFalse(configManager.getDefaultProvider().isPresent());
+        assertTrue(configManager.getDefaultProvider().isPresent());
 
         config.setId(DEFAULT_KEY);
         configManager.addProvider(config);
@@ -149,7 +149,7 @@ public class ConfigManagerTest {
         Collection<ConsumerConfig> configs = configManager.getConsumers();
         assertEquals(1, configs.size());
         assertEquals(config, configs.iterator().next());
-        assertFalse(configManager.getDefaultConsumer().isPresent());
+        assertTrue(configManager.getDefaultConsumer().isPresent());
 
         config.setId(DEFAULT_KEY);
         configManager.addConsumer(config);