You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by me...@apache.org on 2019/11/15 09:21:14 UTC

[dubbo] 01/02: [Bugfix] Resolve the issues about the demos using DubboBootstrap (#5314)

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

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

commit 37ddb35024227155fcc08222d1615d91ff12dc56
Author: Mercy Ma <me...@gmail.com>
AuthorDate: Thu Nov 14 10:19:30 2019 +0800

    [Bugfix] Resolve the issues about the demos using DubboBootstrap (#5314)
    
    * Polish apache/dubbo#5306 : [Migration] Upgrade the @since tags in Javadoc migration cloud native to master
    
    * Polish apache/dubbo#5306 : [Migration] Upgrade the @since tags in Javadoc migration cloud native to master
    
    * Polish apache/dubbo#5309 : [ISSURE] The beans of Dubbo's Config can't be found on the ReferenceBean's initialization
    
    * Polish apache/dubbo#5312 : Resolve the demos' issues of zookeeper and nacos
    
    * Polish apache/dubbo#5313 : [Migration] migrate the code in common module from cloud-native branch to master
---
 .../configcenter/DynamicConfigurationFactory.java  |   2 +-
 .../apache/dubbo/common/function/Predicates.java   |  74 +++++++
 .../org/apache/dubbo/common/function/Streams.java  |  71 +++++++
 .../apache/dubbo/common/utils/CollectionUtils.java |  21 +-
 .../org/apache/dubbo/common/utils/StringUtils.java |  29 +++
 .../apache/dubbo/config/context/ConfigManager.java |   4 +-
 .../dubbo/common/function/PredicatesTest.java      |  60 ++++++
 .../apache/dubbo/common/function/StreamsTest.java  |  57 ++++++
 .../dubbo/common/utils/CollectionUtilsTest.java    |  26 ++-
 .../dubbo/config/context/ConfigManagerTest.java    | 223 +++++++++++++++++++++
 dubbo-config/dubbo-config-api/pom.xml              |  95 +++++++++
 .../NacosDubboServiceConsumerBootstrap.java        |   2 +-
 .../ZookeeperDubboServiceConsumerBootstrap.java    |   7 +-
 13 files changed, 660 insertions(+), 11 deletions(-)

diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/DynamicConfigurationFactory.java b/dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/DynamicConfigurationFactory.java
index b010964..1c25a40 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/DynamicConfigurationFactory.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/DynamicConfigurationFactory.java
@@ -25,7 +25,7 @@ import static org.apache.dubbo.common.extension.ExtensionLoader.getExtensionLoad
 /**
  * The factory interface to create the instance of {@link DynamicConfiguration}
  */
-@SPI("nop")
+@SPI("file") // 2.7.5 change the default SPI implementation
 public interface DynamicConfigurationFactory {
 
     DynamicConfiguration getDynamicConfiguration(URL url);
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/function/Predicates.java b/dubbo-common/src/main/java/org/apache/dubbo/common/function/Predicates.java
new file mode 100644
index 0000000..445b169
--- /dev/null
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/function/Predicates.java
@@ -0,0 +1,74 @@
+/*
+ * 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.dubbo.common.function;
+
+import java.util.function.Predicate;
+
+import static java.util.stream.Stream.of;
+
+/**
+ * The utilities class for Java {@link Predicate}
+ *
+ * @since 2.7.5
+ */
+public interface Predicates {
+
+    Predicate[] EMPTY_ARRAY = new Predicate[0];
+
+    /**
+     * {@link Predicate} always return <code>true</code>
+     *
+     * @param <T> the type to test
+     * @return <code>true</code>
+     */
+    static <T> Predicate<T> alwaysTrue() {
+        return e -> true;
+    }
+
+    /**
+     * {@link Predicate} always return <code>false</code>
+     *
+     * @param <T> the type to test
+     * @return <code>false</code>
+     */
+    static <T> Predicate<T> alwaysFalse() {
+        return e -> false;
+    }
+
+    /**
+     * a composed predicate that represents a short-circuiting logical AND of {@link Predicate predicates}
+     *
+     * @param predicates {@link Predicate predicates}
+     * @param <T>        the type to test
+     * @return non-null
+     */
+    static <T> Predicate<T> and(Predicate<T>... predicates) {
+        return of(predicates).reduce((a, b) -> a.and(b)).orElseGet(Predicates::alwaysTrue);
+    }
+
+    /**
+     * a composed predicate that represents a short-circuiting logical OR of {@link Predicate predicates}
+     *
+     * @param predicates {@link Predicate predicates}
+     * @param <T>        the detected type
+     * @return non-null
+     */
+    static <T> Predicate<T> or(Predicate<T>... predicates) {
+        return of(predicates).reduce((a, b) -> a.or(b)).orElse(e -> true);
+    }
+
+}
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/function/Streams.java b/dubbo-common/src/main/java/org/apache/dubbo/common/function/Streams.java
new file mode 100644
index 0000000..65e4fa6
--- /dev/null
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/function/Streams.java
@@ -0,0 +1,71 @@
+/*
+ * 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.dubbo.common.function;
+
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.function.Predicate;
+import java.util.stream.Stream;
+
+import static java.util.stream.Collectors.toList;
+import static java.util.stream.StreamSupport.stream;
+import static org.apache.dubbo.common.function.Predicates.and;
+import static org.apache.dubbo.common.function.Predicates.or;
+
+/**
+ * The utilities class for {@link Stream}
+ *
+ * @since 2.7.5
+ */
+public interface Streams {
+
+    static <T, S extends Iterable<T>> Stream<T> filterStream(S values, Predicate<T> predicate) {
+        return stream(values.spliterator(), false).filter(predicate);
+    }
+
+    static <T, S extends Iterable<T>> List<T> filterList(S values, Predicate<T> predicate) {
+        return filterStream(values, predicate).collect(toList());
+    }
+
+    static <T, S extends Iterable<T>> Set<T> filterSet(S values, Predicate<T> predicate) {
+        // new Set with insertion order
+        return filterStream(values, predicate).collect(LinkedHashSet::new, Set::add, Set::addAll);
+    }
+
+    static <T, S extends Iterable<T>> S filter(S values, Predicate<T> predicate) {
+        final boolean isSet = Set.class.isAssignableFrom(values.getClass());
+        return (S) (isSet ? filterSet(values, predicate) : filterList(values, predicate));
+    }
+
+    static <T, S extends Iterable<T>> S filterAll(S values, Predicate<T>... predicates) {
+        return filter(values, and(predicates));
+    }
+
+    static <T, S extends Iterable<T>> S filterAny(S values, Predicate<T>... predicates) {
+        return filter(values, or(predicates));
+    }
+
+    static <T> T filterFirst(Iterable<T> values, Predicate<T>... predicates) {
+        return stream(values.spliterator(), false)
+                .filter(and(predicates))
+                .findFirst()
+                .orElse(null);
+    }
+}
+
+
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/CollectionUtils.java b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/CollectionUtils.java
index 4e924b3..28e9821 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/CollectionUtils.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/CollectionUtils.java
@@ -21,8 +21,14 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.HashMap;
+import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
+
+import static java.util.Arrays.asList;
+import static java.util.Collections.emptySet;
+import static java.util.Collections.unmodifiableSet;
 
 public class CollectionUtils {
 
@@ -173,7 +179,7 @@ public class CollectionUtils {
 
     public static Map<String, String> toStringMap(String... pairs) {
         Map<String, String> parameters = new HashMap<>();
-        if(ArrayUtils.isEmpty(pairs)){
+        if (ArrayUtils.isEmpty(pairs)) {
             return parameters;
         }
 
@@ -221,4 +227,17 @@ public class CollectionUtils {
         return !isEmptyMap(map);
     }
 
+    /**
+     * Convert to multiple values to be {@link LinkedHashSet}
+     *
+     * @param values one or more values
+     * @param <T>    the type of <code>values</code>
+     * @return read-only {@link Set}
+     */
+    public static <T> Set<T> ofSet(T... values) {
+        if (values == null || values.length < 1) {
+            return emptySet();
+        }
+        return unmodifiableSet(new LinkedHashSet<>(asList(values)));
+    }
 }
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/StringUtils.java b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/StringUtils.java
index c49d106..c904800 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/StringUtils.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/StringUtils.java
@@ -33,6 +33,7 @@ import java.util.TreeMap;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import static java.lang.String.valueOf;
 import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SEPARATOR;
 import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN;
 import static org.apache.dubbo.common.constants.CommonConstants.DOT_REGEX;
@@ -58,6 +59,34 @@ public final class StringUtils {
     private static final Pattern INT_PATTERN = Pattern.compile("^\\d+$");
     private static final int PAD_LIMIT = 8192;
 
+    /**
+     * @since 2.7.5
+     */
+    public static final char EQUAL_CHAR = '=';
+
+    public static final String EQUAL = valueOf(EQUAL_CHAR);
+
+    public static final char AND_CHAR = '&';
+
+    public static final String AND = valueOf(AND_CHAR);
+
+    public static final char SEMICOLON_CHAR = ';';
+
+    public static final String SEMICOLON = valueOf(SEMICOLON_CHAR);
+
+    public static final char QUESTION_MASK_CHAR = '?';
+
+    public static final String QUESTION_MASK = valueOf(QUESTION_MASK_CHAR);
+
+    public static final char SLASH_CHAR = '/';
+
+    public static final String SLASH = valueOf(SLASH_CHAR);
+
+    /**
+     * The empty value
+     */
+    public static final String EMPTY_VALUE = "";
+
     private StringUtils() {
     }
 
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 4175c2e..a49876d 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
@@ -62,9 +62,11 @@ import static org.apache.dubbo.config.Constants.PROTOCOLS_SUFFIX;
 import static org.apache.dubbo.config.Constants.REGISTRIES_SUFFIX;
 
 public class ConfigManager extends LifecycleAdapter implements FrameworkExt {
-    public static final String NAME = "config";
+
     private static final Logger logger = LoggerFactory.getLogger(ConfigManager.class);
 
+    public static final String NAME = "config";
+
     private final Map<String, Map<String, AbstractConfig>> configsCache = newMap();
 
     private final ReadWriteLock lock = new ReentrantReadWriteLock();
diff --git a/dubbo-common/src/test/java/org/apache/dubbo/common/function/PredicatesTest.java b/dubbo-common/src/test/java/org/apache/dubbo/common/function/PredicatesTest.java
new file mode 100644
index 0000000..d042e64
--- /dev/null
+++ b/dubbo-common/src/test/java/org/apache/dubbo/common/function/PredicatesTest.java
@@ -0,0 +1,60 @@
+/*
+ * 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.dubbo.common.function;
+
+import org.junit.jupiter.api.Test;
+
+import static org.apache.dubbo.common.function.Predicates.alwaysFalse;
+import static org.apache.dubbo.common.function.Predicates.alwaysTrue;
+import static org.apache.dubbo.common.function.Predicates.and;
+import static org.apache.dubbo.common.function.Predicates.or;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * {@link Predicates} Test
+ *
+ * @since 2.7.5
+ */
+public class PredicatesTest {
+
+    @Test
+    public void testAlwaysTrue() {
+        assertTrue(alwaysTrue().test(null));
+    }
+
+    @Test
+    public void testAlwaysFalse() {
+        assertFalse(alwaysFalse().test(null));
+    }
+
+    @Test
+    public void testAnd() {
+        assertTrue(and(alwaysTrue(), alwaysTrue(), alwaysTrue()).test(null));
+        assertFalse(and(alwaysFalse(), alwaysFalse(), alwaysFalse()).test(null));
+        assertFalse(and(alwaysTrue(), alwaysFalse(), alwaysFalse()).test(null));
+        assertFalse(and(alwaysTrue(), alwaysTrue(), alwaysFalse()).test(null));
+    }
+
+    @Test
+    public void testOr() {
+        assertTrue(or(alwaysTrue(), alwaysTrue(), alwaysTrue()).test(null));
+        assertTrue(or(alwaysTrue(), alwaysTrue(), alwaysFalse()).test(null));
+        assertTrue(or(alwaysTrue(), alwaysFalse(), alwaysFalse()).test(null));
+        assertFalse(or(alwaysFalse(), alwaysFalse(), alwaysFalse()).test(null));
+    }
+}
diff --git a/dubbo-common/src/test/java/org/apache/dubbo/common/function/StreamsTest.java b/dubbo-common/src/test/java/org/apache/dubbo/common/function/StreamsTest.java
new file mode 100644
index 0000000..d55a009
--- /dev/null
+++ b/dubbo-common/src/test/java/org/apache/dubbo/common/function/StreamsTest.java
@@ -0,0 +1,57 @@
+/*
+ * 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.dubbo.common.function;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Stream;
+
+import static java.util.Arrays.asList;
+import static java.util.stream.Collectors.toList;
+import static org.apache.dubbo.common.function.Streams.filterList;
+import static org.apache.dubbo.common.function.Streams.filterSet;
+import static org.apache.dubbo.common.function.Streams.filterStream;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * {@link Streams} Test
+ *
+ * @since 2.7.5
+ */
+public class StreamsTest {
+
+    @Test
+    public void testFilterStream() {
+        Stream<Integer> stream = filterStream(asList(1, 2, 3, 4, 5), i -> i % 2 == 0);
+        assertEquals(asList(2, 4), stream.collect(toList()));
+    }
+
+    @Test
+    public void testFilterList() {
+        List<Integer> list = filterList(asList(1, 2, 3, 4, 5), i -> i % 2 == 0);
+        assertEquals(asList(2, 4), list);
+    }
+
+    @Test
+    public void testFilterSet() {
+        Set<Integer> set = filterSet(asList(1, 2, 3, 4, 5), i -> i % 2 == 0);
+        assertEquals(new LinkedHashSet<>(asList(2, 4)), set);
+    }
+}
diff --git a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/CollectionUtilsTest.java b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/CollectionUtilsTest.java
index 22d8d92..36af51d 100644
--- a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/CollectionUtilsTest.java
+++ b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/CollectionUtilsTest.java
@@ -24,21 +24,25 @@ import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
+import static java.util.Collections.emptyList;
+import static java.util.Collections.emptySet;
+import static java.util.Collections.singleton;
 import static org.apache.dubbo.common.utils.CollectionUtils.isEmpty;
 import static org.apache.dubbo.common.utils.CollectionUtils.isNotEmpty;
+import static org.apache.dubbo.common.utils.CollectionUtils.ofSet;
 import static org.apache.dubbo.common.utils.CollectionUtils.toMap;
 import static org.apache.dubbo.common.utils.CollectionUtils.toStringMap;
-import static java.util.Collections.emptyList;
-import static java.util.Collections.singleton;
+import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.equalTo;
 import static org.hamcrest.Matchers.is;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertNull;
-import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 public class CollectionUtilsTest {
@@ -195,4 +199,20 @@ public class CollectionUtilsTest {
     public void testIsNotEmpty() throws Exception {
         assertThat(isNotEmpty(singleton("a")), is(true));
     }
+
+    @Test
+    public void testOfSet() {
+        Set<String> set = ofSet();
+        assertEquals(emptySet(), set);
+
+        set = ofSet(((String[]) null));
+        assertEquals(emptySet(), set);
+
+        set = ofSet("A", "B", "C");
+        Set<String> expectedSet = new LinkedHashSet<>();
+        expectedSet.add("A");
+        expectedSet.add("B");
+        expectedSet.add("C");
+        assertEquals(expectedSet, set);
+    }
 }
\ No newline at end of file
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
new file mode 100644
index 0000000..5a40296
--- /dev/null
+++ b/dubbo-common/src/test/java/org/apache/dubbo/config/context/ConfigManagerTest.java
@@ -0,0 +1,223 @@
+/*
+ * 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.dubbo.config.context;
+
+import org.apache.dubbo.config.ApplicationConfig;
+import org.apache.dubbo.config.ConfigCenterConfig;
+import org.apache.dubbo.config.ConsumerConfig;
+import org.apache.dubbo.config.MetricsConfig;
+import org.apache.dubbo.config.ModuleConfig;
+import org.apache.dubbo.config.MonitorConfig;
+import org.apache.dubbo.config.ProtocolConfig;
+import org.apache.dubbo.config.ProviderConfig;
+import org.apache.dubbo.config.RegistryConfig;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.util.Collection;
+
+import static java.util.Arrays.asList;
+import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_KEY;
+import static org.apache.dubbo.rpc.model.ApplicationModel.getConfigManager;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * {@link ConfigManager} Test
+ *
+ * @since 2.7.5
+ */
+public class ConfigManagerTest {
+
+    private ConfigManager configManager = getConfigManager();
+
+    @BeforeEach
+    public void init() {
+        configManager.clear();
+    }
+
+    @Test
+    public void testDefaultValues() {
+        // assert single
+        assertFalse(configManager.getApplication().isPresent());
+        assertFalse(configManager.getMonitor().isPresent());
+        assertFalse(configManager.getModule().isPresent());
+        assertFalse(configManager.getMetrics().isPresent());
+
+        // providers and consumers
+        assertFalse(configManager.getDefaultProvider().isPresent());
+        assertFalse(configManager.getDefaultConsumer().isPresent());
+        assertTrue(configManager.getProviders().isEmpty());
+        assertTrue(configManager.getConsumers().isEmpty());
+
+        // protocols
+        assertTrue(configManager.getProtocols().isEmpty());
+        assertTrue(configManager.getDefaultProtocols().isEmpty());
+        assertTrue(configManager.getProtocolIds().isEmpty());
+
+        // registries
+        assertTrue(configManager.getRegistries().isEmpty());
+        assertTrue(configManager.getDefaultRegistries().isEmpty());
+        assertTrue(configManager.getRegistryIds().isEmpty());
+
+        // services and references
+        assertTrue(configManager.getServices().isEmpty());
+        assertTrue(configManager.getReferences().isEmpty());
+
+        // config centers
+        assertTrue(configManager.getConfigCenters().isEmpty());
+
+        // metadata
+        assertTrue(configManager.getMetadataConfigs().isEmpty());
+    }
+
+    // Test ApplicationConfig correlative methods
+    @Test
+    public void testApplicationConfig() {
+        ApplicationConfig config = new ApplicationConfig();
+        configManager.setApplication(config);
+        assertTrue(configManager.getApplication().isPresent());
+        assertEquals(config, configManager.getApplication().get());
+        assertThrows(IllegalStateException.class, () -> {
+            configManager.setApplication(new ApplicationConfig("test"));
+        });
+    }
+
+    // Test MonitorConfig correlative methods
+    @Test
+    public void testMonitorConfig() {
+        MonitorConfig monitorConfig = new MonitorConfig();
+        monitorConfig.setGroup("test");
+        configManager.setMonitor(monitorConfig);
+        assertTrue(configManager.getMonitor().isPresent());
+        assertEquals(monitorConfig, configManager.getMonitor().get());
+        assertThrows(IllegalStateException.class, () -> {
+            configManager.setMonitor(new MonitorConfig());
+        });
+    }
+
+    // Test MonitorConfig correlative methods
+    @Test
+    public void tesModuleConfig() {
+        ModuleConfig config = new ModuleConfig();
+        configManager.setModule(config);
+        assertTrue(configManager.getModule().isPresent());
+        assertEquals(config, configManager.getModule().get());
+        assertThrows(IllegalStateException.class, () -> {
+            configManager.setModule(new ModuleConfig("test"));
+        });
+    }
+
+    // Test MetricsConfig correlative methods
+    @Test
+    public void tesMetricsConfig() {
+        MetricsConfig config = new MetricsConfig();
+        configManager.setMetrics(config);
+        assertTrue(configManager.getMetrics().isPresent());
+        assertEquals(config, configManager.getMetrics().get());
+        assertThrows(IllegalStateException.class, () -> {
+            MetricsConfig metricsConfig = new MetricsConfig();
+            metricsConfig.setPort("101");
+            configManager.setMetrics(metricsConfig);
+        });
+    }
+
+    // Test ProviderConfig correlative methods
+    @Test
+    public void testProviderConfig() {
+        ProviderConfig config = new ProviderConfig();
+        configManager.addProviders(asList(config, null));
+        Collection<ProviderConfig> configs = configManager.getProviders();
+        assertEquals(1, configs.size());
+        assertEquals(config, configs.iterator().next());
+        assertFalse(configManager.getDefaultProvider().isPresent());
+
+        config.setId(DEFAULT_KEY);
+        configManager.addProvider(config);
+        assertTrue(configManager.getDefaultProvider().isPresent());
+        configs = configManager.getProviders();
+        assertEquals(2, configs.size());
+    }
+
+    // Test ConsumerConfig correlative methods
+    @Test
+    public void testConsumerConfig() {
+        ConsumerConfig config = new ConsumerConfig();
+        configManager.addConsumers(asList(config, null));
+        Collection<ConsumerConfig> configs = configManager.getConsumers();
+        assertEquals(1, configs.size());
+        assertEquals(config, configs.iterator().next());
+        assertFalse(configManager.getDefaultConsumer().isPresent());
+
+        config.setId(DEFAULT_KEY);
+        configManager.addConsumer(config);
+        assertTrue(configManager.getDefaultConsumer().isPresent());
+        configs = configManager.getConsumers();
+        assertEquals(2, configs.size());
+    }
+
+    // Test ProtocolConfig correlative methods
+    @Test
+    public void testProtocolConfig() {
+        ProtocolConfig config = new ProtocolConfig();
+        configManager.addProtocols(asList(config, null));
+        Collection<ProtocolConfig> configs = configManager.getProtocols();
+        assertEquals(1, configs.size());
+        assertEquals(config, configs.iterator().next());
+        assertFalse(configManager.getDefaultProtocols().isEmpty());
+    }
+
+    // Test RegistryConfig correlative methods
+    @Test
+    public void testRegistryConfig() {
+        RegistryConfig config = new RegistryConfig();
+        configManager.addRegistries(asList(config, null));
+        Collection<RegistryConfig> configs = configManager.getRegistries();
+        assertEquals(1, configs.size());
+        assertEquals(config, configs.iterator().next());
+        assertFalse(configManager.getDefaultRegistries().isEmpty());
+    }
+
+    // Test ConfigCenterConfig correlative methods
+    @Test
+    public void testConfigCenterConfig() {
+        ConfigCenterConfig config = new ConfigCenterConfig();
+        configManager.addConfigCenters(asList(config, null));
+        Collection<ConfigCenterConfig> configs = configManager.getConfigCenters();
+        assertEquals(1, configs.size());
+        assertEquals(config, configs.iterator().next());
+    }
+
+    @Test
+    public void testAddConfig() {
+        configManager.addConfig(new ApplicationConfig());
+        configManager.addConfig(new ProviderConfig());
+        configManager.addConfig(new ProtocolConfig());
+
+        assertTrue(configManager.getApplication().isPresent());
+        assertFalse(configManager.getProviders().isEmpty());
+        assertFalse(configManager.getProtocols().isEmpty());
+    }
+
+    @Test
+    public void testRefreshAll() {
+        configManager.refreshAll();
+    }
+}
diff --git a/dubbo-config/dubbo-config-api/pom.xml b/dubbo-config/dubbo-config-api/pom.xml
index 9183a3e..5937993 100644
--- a/dubbo-config/dubbo-config-api/pom.xml
+++ b/dubbo-config/dubbo-config-api/pom.xml
@@ -69,27 +69,122 @@
         <!-- FIXME, we shouldn't rely on these modules, even in test scope -->
         <dependency>
             <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo-rpc-dubbo</artifactId>
+            <version>${project.parent.version}</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.dubbo</groupId>
             <artifactId>dubbo-rpc-rest</artifactId>
             <version>${project.parent.version}</version>
             <scope>test</scope>
         </dependency>
+
         <dependency>
             <groupId>org.apache.dubbo</groupId>
             <artifactId>dubbo-rpc-rmi</artifactId>
             <version>${project.parent.version}</version>
             <scope>test</scope>
         </dependency>
+
+        <dependency>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo-rpc-hessian</artifactId>
+            <version>${project.parent.version}</version>
+            <scope>test</scope>
+        </dependency>
+
         <dependency>
             <groupId>org.apache.dubbo</groupId>
             <artifactId>dubbo-remoting-netty4</artifactId>
             <version>${project.parent.version}</version>
             <scope>test</scope>
         </dependency>
+
+        <dependency>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo-serialization-hessian2</artifactId>
+            <version>${project.parent.version}</version>
+            <scope>test</scope>
+        </dependency>
+
         <dependency>
             <groupId>org.apache.dubbo</groupId>
             <artifactId>dubbo-registry-multicast</artifactId>
             <version>${project.parent.version}</version>
             <scope>test</scope>
         </dependency>
+
+        <dependency>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo-registry-zookeeper</artifactId>
+            <version>${project.parent.version}</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo-registry-nacos</artifactId>
+            <version>${project.parent.version}</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo-registry-eureka</artifactId>
+            <version>${project.parent.version}</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo-registry-etcd3</artifactId>
+            <version>${project.parent.version}</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo-registry-consul</artifactId>
+            <version>${project.parent.version}</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo-metadata-report-zookeeper</artifactId>
+            <version>${project.parent.version}</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo-metadata-report-etcd</artifactId>
+            <version>${project.parent.version}</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo-metadata-report-nacos</artifactId>
+            <version>${project.parent.version}</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo-metadata-report-redis</artifactId>
+            <version>${project.parent.version}</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo-configcenter-zookeeper</artifactId>
+            <version>${project.parent.version}</version>
+            <scope>test</scope>
+        </dependency>
+
     </dependencies>
 </project>
diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/NacosDubboServiceConsumerBootstrap.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/NacosDubboServiceConsumerBootstrap.java
index 552fb20..b91659d 100644
--- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/NacosDubboServiceConsumerBootstrap.java
+++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/NacosDubboServiceConsumerBootstrap.java
@@ -36,7 +36,7 @@ public class NacosDubboServiceConsumerBootstrap {
                 // Zookeeper
 //                .registry("nacos", builder -> builder.address("nacos://127.0.0.1:8848?registry.type=service&subscribed.services=dubbo-nacos-provider-demo"))
 //                .registry("nacos", builder -> builder.address("nacos://127.0.0.1:8848?registry-type=service&subscribed-services=dubbo-nacos-provider-demo"))
-                .registry("nacos", builder -> builder.address("nacos://127.0.0.1:8848?registry-type=service&subscribed-services=service-provider"))
+                .registry("nacos", builder -> builder.address("nacos://127.0.0.1:8848?registry-type=service&subscribed-services=dubbo-nacos-provider-demo"))
                 .metadataReport(new MetadataReportConfig("nacos://127.0.0.1:8848"))
                 .reference("user", builder -> builder.interfaceClass(UserService.class).protocol("rest"))
                 .start();
diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/ZookeeperDubboServiceConsumerBootstrap.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/ZookeeperDubboServiceConsumerBootstrap.java
index ed421b1..9b0d866 100644
--- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/ZookeeperDubboServiceConsumerBootstrap.java
+++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/ZookeeperDubboServiceConsumerBootstrap.java
@@ -32,18 +32,17 @@ public class ZookeeperDubboServiceConsumerBootstrap {
                 .registry("zookeeper", builder -> builder.address("zookeeper://127.0.0.1:2181?registry-type=service&subscribed-services=zookeeper-dubbo-provider"))
                 .reference("echo", builder -> builder.interfaceClass(EchoService.class).protocol("dubbo"))
                 .reference("user", builder -> builder.interfaceClass(UserService.class).protocol("rest"))
-                .start()
-                .await();
+                .start();
 
         EchoService echoService = bootstrap.getCache().get(EchoService.class);
         UserService userService = bootstrap.getCache().get(UserService.class);
 
-        for (int i = 0; i < 500; i++) {
+        for (int i = 0; i < 5; i++) {
             Thread.sleep(2000L);
             System.out.println(echoService.echo("Hello,World"));
             System.out.println(userService.getUser(i * 1L));
         }
 
-
+        bootstrap.stop();
     }
 }