Search in sources :

Example 26 with DynamicConfiguration

use of com.netflix.config.DynamicConfiguration in project servicecomb-java-chassis by apache.

the class TestYAMLConfigurationSource method testFullOperation.

@Test
public void testFullOperation() {
    // configuration from system properties
    ConcurrentMapConfiguration configFromSystemProperties = new ConcurrentMapConfiguration(new SystemConfiguration());
    // configuration from yaml file
    MicroserviceConfigLoader loader = new MicroserviceConfigLoader();
    loader.loadAndSort();
    DynamicConfiguration configFromYamlFile = new DynamicConfiguration(new MicroserviceConfigurationSource(loader.getConfigModels()), new NeverStartPollingScheduler());
    // create a hierarchy of configuration that makes
    // 1) dynamic configuration source override system properties
    ConcurrentCompositeConfiguration finalConfig = new ConcurrentCompositeConfiguration();
    finalConfig.addConfiguration(configFromYamlFile, "yamlConfig");
    finalConfig.addConfiguration(configFromSystemProperties, "systemEnvConfig");
    Assertions.assertEquals(0.5, finalConfig.getDouble("trace.handler.sampler.percent"), 0.5);
    Object o = finalConfig.getProperty("zq");
    @SuppressWarnings("unchecked") List<Map<String, Object>> listO = (List<Map<String, Object>>) o;
    Assertions.assertEquals(3, listO.size());
}
Also used : ConcurrentMapConfiguration(com.netflix.config.ConcurrentMapConfiguration) SystemConfiguration(org.apache.commons.configuration.SystemConfiguration) NeverStartPollingScheduler(org.apache.servicecomb.config.archaius.scheduler.NeverStartPollingScheduler) ConcurrentCompositeConfiguration(com.netflix.config.ConcurrentCompositeConfiguration) DynamicConfiguration(com.netflix.config.DynamicConfiguration) List(java.util.List) Map(java.util.Map) Test(org.junit.Test)

Example 27 with DynamicConfiguration

use of com.netflix.config.DynamicConfiguration in project servicecomb-java-chassis by apache.

the class TestAbstractPropertiesLoader method testExtendedClassCompatible.

@Test
public void testExtendedClassCompatible() {
    Configuration configuration = new DynamicConfiguration();
    configuration.setProperty(BootStrapProperties.CONFIG_SERVICE_EXTENDED_CLASS, "invalidClass");
    AbstractPropertiesLoader loader = MicroservicePropertiesLoader.INSTANCE;
    try {
        loader.loadProperties(configuration);
        Assertions.fail("Must throw exception");
    } catch (Error e) {
        Assertions.assertEquals(ClassNotFoundException.class, e.getCause().getClass());
        Assertions.assertEquals("invalidClass", e.getCause().getMessage());
    }
}
Also used : Configuration(org.apache.commons.configuration.Configuration) DynamicConfiguration(com.netflix.config.DynamicConfiguration) DynamicConfiguration(com.netflix.config.DynamicConfiguration) Test(org.junit.jupiter.api.Test)

Aggregations

DynamicConfiguration (com.netflix.config.DynamicConfiguration)27 Test (org.junit.Test)19 ConcurrentCompositeConfiguration (com.netflix.config.ConcurrentCompositeConfiguration)12 SystemConfiguration (org.apache.commons.configuration.SystemConfiguration)11 ConcurrentMapConfiguration (com.netflix.config.ConcurrentMapConfiguration)10 FixedDelayPollingScheduler (com.netflix.config.FixedDelayPollingScheduler)9 List (java.util.List)7 AbstractConfiguration (org.apache.commons.configuration.AbstractConfiguration)6 NeverStartPollingScheduler (io.servicecomb.config.archaius.scheduler.NeverStartPollingScheduler)4 YAMLConfigurationSource (io.servicecomb.config.archaius.sources.YAMLConfigurationSource)4 Map (java.util.Map)4 Configuration (org.apache.commons.configuration.Configuration)4 NeverStartPollingScheduler (org.apache.servicecomb.config.archaius.scheduler.NeverStartPollingScheduler)3 BeforeClass (org.junit.BeforeClass)3 Test (org.junit.jupiter.api.Test)3 AbstractPollingScheduler (com.netflix.config.AbstractPollingScheduler)2 DynamicStringProperty (com.netflix.config.DynamicStringProperty)2 PolledConfigurationSource (com.netflix.config.PolledConfigurationSource)2 InMemoryPropertyStore (org.ff4j.property.store.InMemoryPropertyStore)2 PropertyStore (org.ff4j.property.store.PropertyStore)2