Search in sources :

Example 11 with AbstractConfiguration

use of org.apache.commons.configuration.AbstractConfiguration in project java-chassis by ServiceComb.

the class ConfigurePropertyUtils method getPropertiesWithPrefix.

public static Map<String, String> getPropertiesWithPrefix(String prefix) {
    Map<String, String> propertiesMap = new HashMap<>();
    Object config = DynamicPropertyFactory.getBackingConfigurationSource();
    if (null != config && AbstractConfiguration.class.isInstance(config)) {
        AbstractConfiguration composite = (AbstractConfiguration) config;
        Iterator<String> keysIterator = composite.getKeys(prefix);
        while (keysIterator.hasNext()) {
            String key = keysIterator.next();
            propertiesMap.put(key.substring(prefix.length() + 1), String.valueOf(composite.getProperty(key)));
        }
    }
    return propertiesMap;
}
Also used : AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration) HashMap(java.util.HashMap)

Example 12 with AbstractConfiguration

use of org.apache.commons.configuration.AbstractConfiguration in project incubator-servicecomb-java-chassis by apache.

the class ConfigUtil method installDynamicConfig.

public static void installDynamicConfig() {
    if (ConfigurationManager.isConfigurationInstalled()) {
        LOGGER.warn("Configuration installed by others, will ignore this configuration.");
        return;
    }
    AbstractConfiguration dynamicConfig = ConfigUtil.createDynamicConfig();
    ConfigurationManager.install(dynamicConfig);
}
Also used : AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration)

Example 13 with AbstractConfiguration

use of org.apache.commons.configuration.AbstractConfiguration in project incubator-servicecomb-java-chassis by apache.

the class ConfigurationSpringInitializer method mergeProperties.

@Override
protected Properties mergeProperties() throws IOException {
    Properties properties = super.mergeProperties();
    AbstractConfiguration config = ConfigurationManager.getConfigInstance();
    Iterator<String> iter = config.getKeys();
    while (iter.hasNext()) {
        String key = iter.next();
        Object value = config.getProperty(key);
        properties.put(key, value);
    }
    return properties;
}
Also used : AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration) Properties(java.util.Properties)

Example 14 with AbstractConfiguration

use of org.apache.commons.configuration.AbstractConfiguration in project incubator-servicecomb-java-chassis by apache.

the class TestConfigUtil method duplicateServiceCombConfigToCseListValue.

@Test
public void duplicateServiceCombConfigToCseListValue() throws Exception {
    List<String> list = Arrays.asList("a", "b");
    AbstractConfiguration config = new DynamicConfiguration();
    config.addProperty("servicecomb.list", list);
    Deencapsulation.invoke(ConfigUtil.class, "duplicateServiceCombConfigToCse", config);
    Object result = config.getProperty("cse.list");
    assertThat(result, instanceOf(List.class));
    assertThat(result, equalTo(list));
}
Also used : AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration) DynamicConfiguration(com.netflix.config.DynamicConfiguration) List(java.util.List) Test(org.junit.Test)

Example 15 with AbstractConfiguration

use of org.apache.commons.configuration.AbstractConfiguration in project incubator-servicecomb-java-chassis by apache.

the class TestConfigUtil method testCreateDynamicConfigNoConfigCenterSPI.

@Test
public void testCreateDynamicConfigNoConfigCenterSPI() {
    new Expectations(SPIServiceUtils.class) {

        {
            SPIServiceUtils.getTargetService(ConfigCenterConfigurationSource.class);
            result = null;
        }
    };
    AbstractConfiguration dynamicConfig = ConfigUtil.createDynamicConfig();
    MicroserviceConfigLoader loader = ConfigUtil.getMicroserviceConfigLoader(dynamicConfig);
    List<ConfigModel> list = loader.getConfigModels();
    Assert.assertEquals(loader, ConfigUtil.getMicroserviceConfigLoader(dynamicConfig));
    Assert.assertEquals(1, list.size());
    Assert.assertNotEquals(DynamicWatchedConfiguration.class, ((ConcurrentCompositeConfiguration) dynamicConfig).getConfiguration(0).getClass());
}
Also used : Expectations(mockit.Expectations) AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration) ConfigModel(org.apache.servicecomb.config.archaius.sources.ConfigModel) MicroserviceConfigLoader(org.apache.servicecomb.config.archaius.sources.MicroserviceConfigLoader) ConcurrentCompositeConfiguration(com.netflix.config.ConcurrentCompositeConfiguration) Test(org.junit.Test)

Aggregations

AbstractConfiguration (org.apache.commons.configuration.AbstractConfiguration)80 Test (org.junit.Test)29 ConcurrentCompositeConfiguration (com.netflix.config.ConcurrentCompositeConfiguration)18 BeforeClass (org.junit.BeforeClass)10 Configuration (org.apache.commons.configuration.Configuration)9 URI (java.net.URI)6 BaseConfiguration (org.apache.commons.configuration.BaseConfiguration)6 HttpRequest (com.netflix.client.http.HttpRequest)5 ArrayList (java.util.ArrayList)5 DynamicConfiguration (com.netflix.config.DynamicConfiguration)4 EnvironmentConfiguration (org.apache.commons.configuration.EnvironmentConfiguration)4 SystemConfiguration (org.apache.commons.configuration.SystemConfiguration)4 HttpResponse (com.netflix.client.http.HttpResponse)3 ConcurrentMapConfiguration (com.netflix.config.ConcurrentMapConfiguration)3 ExpandedConfigurationListenerAdapter (com.netflix.config.ExpandedConfigurationListenerAdapter)3 LinkedHashMap (java.util.LinkedHashMap)3 Properties (java.util.Properties)3 AggregatedConfiguration (com.netflix.config.AggregatedConfiguration)2 ConfigurationManager (com.netflix.config.ConfigurationManager)2 DynamicURLConfiguration (com.netflix.config.DynamicURLConfiguration)2