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

ningjiang pushed a commit to branch master
in repository 
https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git

commit d382ead39b3bc63a8c2240af4cb659ea9f88988a
Author: jeho0815 <jeho0...@email.com>
AuthorDate: Sat Feb 3 10:25:54 2018 +0800

    SCB-315 Config Center module can't get config by 
DynamicPropertyFactory.getInstance().getStringProperty, so has to use 
ConcurrentCompositeConfiguration
---
 .../foundation/vertx/AddressResolverConfig.java    | 89 +++++++---------------
 .../vertx/TestAddressResolverConfig.java           | 31 +++-----
 2 files changed, 37 insertions(+), 83 deletions(-)

diff --git 
a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/AddressResolverConfig.java
 
b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/AddressResolverConfig.java
index 08412f1..b503643 100644
--- 
a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/AddressResolverConfig.java
+++ 
b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/AddressResolverConfig.java
@@ -20,7 +20,8 @@ package org.apache.servicecomb.foundation.vertx;
 import java.util.Arrays;
 import java.util.List;
 
-import com.netflix.config.ConcurrentCompositeConfiguration;
+import org.apache.commons.configuration.Configuration;
+
 import com.netflix.config.DynamicPropertyFactory;
 
 import io.vertx.core.dns.AddressResolverOptions;
@@ -42,7 +43,7 @@ public class AddressResolverConfig {
    * @param configSource get config from special config source
    * @return AddressResolverOptions
    */
-  public static AddressResolverOptions getAddressResover(String tag, 
ConcurrentCompositeConfiguration configSource) {
+  public static AddressResolverOptions getAddressResover(String tag, 
Configuration configSource) {
     AddressResolverOptions addressResolverOptions = new 
AddressResolverOptions();
     addressResolverOptions
         .setServers(getStringListProperty(configSource,
@@ -102,80 +103,44 @@ public class AddressResolverConfig {
     return addressResolverOptions;
   }
 
-  private static List<String> 
getStringListProperty(ConcurrentCompositeConfiguration configSource,
+  private static List<String> getStringListProperty(Configuration configSource,
       List<String> defaultValue, String... keys) {
-    String property = null;
+    if (configSource == null) {
+      configSource = (Configuration) 
DynamicPropertyFactory.getBackingConfigurationSource();
+    }
     for (String key : keys) {
-      if (configSource != null) {
-        Object v = configSource.getProperty(key);
-        if (List.class.isInstance(v)) {
-          property = listToString(((List<?>) v).toArray());
-        } else {
-          property = (String) configSource.getProperty(key);
-        }
-      } else {
-        property = DynamicPropertyFactory.getInstance().getStringProperty(key, 
null).get();
+      String[] vals = configSource.getStringArray(key);
+      if (vals != null && vals.length > 0) {
+        return Arrays.asList(vals);
       }
-      if (property != null) {
-        break;
-      }
-    }
-    if (property != null) {
-      return Arrays.asList(property.split(","));
-    } else {
-      return defaultValue;
     }
+    return defaultValue;
   }
 
-  private static int getIntProperty(ConcurrentCompositeConfiguration 
configSource, int defaultValue, String... keys) {
-    int property = -1;
+  private static int getIntProperty(Configuration configSource, int 
defaultValue, String... keys) {
+    if (configSource == null) {
+      configSource = (Configuration) 
DynamicPropertyFactory.getBackingConfigurationSource();
+    }
     for (String key : keys) {
-      if (configSource != null) {
-        if (configSource.getProperty(key) != null) {
-          return configSource.getInt(key);
-        }
-      } else {
-        property = DynamicPropertyFactory.getInstance().getIntProperty(key, 
-1).get();
+      Integer val = configSource.getInteger(key, null);
+      if (val != null && val > 0) {
+        return val;
       }
     }
-
-    if (property > 0) {
-      return property;
-    } else {
-      return defaultValue;
-    }
+    return defaultValue;
   }
 
-  private static boolean getBooleanProperty(ConcurrentCompositeConfiguration 
configSource, boolean defaultValue,
+  private static boolean getBooleanProperty(Configuration configSource, 
boolean defaultValue,
       String... keys) {
-    String property = null;
+    if (configSource == null) {
+      configSource = (Configuration) 
DynamicPropertyFactory.getBackingConfigurationSource();
+    }
     for (String key : keys) {
-      if (configSource != null) {
-        if (configSource.getProperty(key) != null) {
-          return configSource.getBoolean(key);
-        }
-      } else {
-        property = DynamicPropertyFactory.getInstance().getStringProperty(key, 
null).get();
-      }
-      if (property != null) {
-        break;
+      Boolean val = configSource.getBoolean(key, null);
+      if (val != null) {
+        return val;
       }
     }
-
-    if (property != null) {
-      return Boolean.parseBoolean(property);
-    } else {
-      return defaultValue;
-    }
-  }
-
-  private static String listToString(Object[] lists) {
-    StringBuilder sb = new StringBuilder();
-    sb.append(lists[0]);
-    for (int i = 1; i < lists.length; i++) {
-      sb.append(",");
-      sb.append(lists[i]);
-    }
-    return sb.toString();
+    return defaultValue;
   }
 }
diff --git 
a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/TestAddressResolverConfig.java
 
b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/TestAddressResolverConfig.java
index 91a680b..dd6c511 100644
--- 
a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/TestAddressResolverConfig.java
+++ 
b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/TestAddressResolverConfig.java
@@ -21,14 +21,13 @@ import static org.hamcrest.CoreMatchers.is;
 
 import java.util.Arrays;
 
+import org.apache.commons.configuration.Configuration;
 import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
 import org.junit.AfterClass;
 import org.junit.Assert;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
-import com.netflix.config.ConcurrentCompositeConfiguration;
-
 import io.vertx.core.dns.AddressResolverOptions;
 import mockit.Expectations;
 import mockit.Mocked;
@@ -46,35 +45,25 @@ public class TestAddressResolverConfig {
   }
 
   @Test
-  public void testGetResoverFromResource(@Mocked 
ConcurrentCompositeConfiguration finalConfig) {
+  public void testGetResoverFromResource(@Mocked Configuration finalConfig) {
     ArchaiusUtils.resetConfig();
     ArchaiusUtils.setProperty("addressResolver.servers", "8.8.8.8,8.8.4.4");
-    ArchaiusUtils.setProperty("addressResolver.optResourceEnabled", true);
-    ArchaiusUtils.setProperty("addressResolver.cacheMinTimeToLive", 0);
-    ArchaiusUtils.setProperty("addressResolver.cacheMaxTimeToLive", 10000);
-    ArchaiusUtils.setProperty("addressResolver.cacheNegativeTimeToLive", 0);
-    ArchaiusUtils.setProperty("addressResolver.queryTimeout", 1000);
-    ArchaiusUtils.setProperty("addressResolver.maxQueries", 3);
-    ArchaiusUtils.setProperty("addressResolver.test.maxQueries", 3);
-    ArchaiusUtils.setProperty("addressResolver.rdFlag", true);
-    ArchaiusUtils.setProperty("addressResolver.searchDomains",
-        "default.svc.local.cluster,svc.local.cluster,local.cluster");
-    ArchaiusUtils.setProperty("addressResolver.test.searchDomains",
-        "test.svc.local.cluster,svc.local.cluster,local.cluster");
-    ArchaiusUtils.setProperty("addressResolver.ndots", 3);
-    ArchaiusUtils.setProperty("addressResolver.rotateServers", true);
     new Expectations() {
       {
-        finalConfig.getProperty("addressResolver.servers");
-        result = "6.6.6.6,6.6.4.4";
-        finalConfig.getProperty("addressResolver.searchDomains");
-        result = "default.svc.local.cluster";
+        finalConfig.getStringArray("addressResolver.servers");
+        result = new String[] {"6.6.6.6", "6.6.4.4"};
+        finalConfig.getStringArray("addressResolver.searchDomains");
+        result = new String[] {"default.svc.local.cluster"};
+        finalConfig.getInteger("addressResolver.queryTimeout", null);
+        result = 2000;
       }
     };
     AddressResolverOptions aroc = 
AddressResolverConfig.getAddressResover("test", finalConfig);
     Assert.assertThat(aroc.getServers(), is(Arrays.asList("6.6.6.6", 
"6.6.4.4")));
     Assert.assertThat(aroc.getSearchDomains(),
         is(Arrays.asList("default.svc.local.cluster")));
+    Assert.assertEquals(aroc.getQueryTimeout(),
+        2000);
   }
 
   @Test

-- 
To stop receiving notification emails like this one, please contact
ningji...@apache.org.

Reply via email to