Search in sources :

Example 11 with DynamicConfiguration

use of com.netflix.config.DynamicConfiguration in project archaius by Netflix.

the class JDBCConfigurationSourceTest method testSimpleInMemoryJDBCDynamicPropertySource.

@Test
public void testSimpleInMemoryJDBCDynamicPropertySource() throws Throwable {
    final String dbName = "MySiteConfiguration";
    DataSource ds = createDataConfigSource(dbName);
    try {
        JDBCConfigurationSource source = new JDBCConfigurationSource(ds, "select distinct property_key, property_value from MySiteProperties", "property_key", "property_value");
        FixedDelayPollingScheduler scheduler = new FixedDelayPollingScheduler(0, 10, false);
        DynamicConfiguration configuration = new DynamicConfiguration(source, scheduler);
        DynamicPropertyFactory.initWithConfigurationSource(configuration);
        DynamicStringProperty defaultProp = DynamicPropertyFactory.getInstance().getStringProperty("this.prop.does.not.exist.use.default", "default");
        assertEquals("default", defaultProp.get());
        DynamicStringProperty prop1 = DynamicPropertyFactory.getInstance().getStringProperty("prop1", "default");
        assertEquals("value1", prop1.get());
    } finally {
        // Clean up the data files generated by the embedded DB.
        FileUtils.deleteDirectory(new File(".", dbName));
    }
}
Also used : DynamicConfiguration(com.netflix.config.DynamicConfiguration) DynamicStringProperty(com.netflix.config.DynamicStringProperty) FixedDelayPollingScheduler(com.netflix.config.FixedDelayPollingScheduler) File(java.io.File) JDBCConfigurationSource(com.netflix.config.sources.JDBCConfigurationSource) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Example 12 with DynamicConfiguration

use of com.netflix.config.DynamicConfiguration in project archaius by Netflix.

the class BlobStoreBackedConfigurationTest method testPropertyChange.

@Test
public void testPropertyChange() throws Exception {
    BlobStoreConfigurationSource source = new BlobStoreConfigurationSource(ctx);
    FixedDelayPollingScheduler scheduler = new FixedDelayPollingScheduler(0, 1000, false);
    DynamicConfiguration dynamicConfig = new DynamicConfiguration(source, scheduler);
    ConfigurationManager.loadPropertiesFromConfiguration(dynamicConfig);
    DynamicStringProperty test1 = DynamicPropertyFactory.getInstance().getStringProperty("test1", "");
    DynamicStringProperty test2 = DynamicPropertyFactory.getInstance().getStringProperty("test2", "");
    DynamicStringProperty test3 = DynamicPropertyFactory.getInstance().getStringProperty("test3", "");
    assertEquals("val1", test1.get());
    assertEquals("val2", test2.get());
    assertEquals("val3", test3.get());
    update();
    Thread.sleep(1250);
    assertEquals("vala", test1.get());
    assertEquals("valb", test2.get());
    assertEquals("valc", test3.get());
}
Also used : DynamicConfiguration(com.netflix.config.DynamicConfiguration) DynamicStringProperty(com.netflix.config.DynamicStringProperty) FixedDelayPollingScheduler(com.netflix.config.FixedDelayPollingScheduler) Test(org.junit.Test)

Example 13 with DynamicConfiguration

use of com.netflix.config.DynamicConfiguration in project archaius by Netflix.

the class TypesafeConfigurationSourceTest method props.

private static DynamicPropertyFactory props() {
    FixedDelayPollingScheduler scheduler = new FixedDelayPollingScheduler(0, 10, false);
    DynamicConfiguration configuration = new DynamicConfiguration(source(), scheduler);
    DynamicPropertyFactory.initWithConfigurationSource(configuration);
    return DynamicPropertyFactory.getInstance();
}
Also used : DynamicConfiguration(com.netflix.config.DynamicConfiguration) FixedDelayPollingScheduler(com.netflix.config.FixedDelayPollingScheduler)

Example 14 with DynamicConfiguration

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

the class TestYAMLConfigurationSource method testFullOperation.

@Test
public void testFullOperation() {
    // configuration from system properties
    ConcurrentMapConfiguration configFromSystemProperties = new ConcurrentMapConfiguration(new SystemConfiguration());
    // configuration from yaml file
    YAMLConfigurationSource configSource = new YAMLConfigurationSource();
    DynamicConfiguration configFromYamlFile = new DynamicConfiguration(configSource, 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");
    ConfigurationManager.install(finalConfig);
    DynamicDoubleProperty myprop = DynamicPropertyFactory.getInstance().getDoubleProperty("trace.handler.sampler.percent", 0.1);
    Assert.assertEquals(0.5, myprop.getValue().doubleValue(), 0.5);
    //        DynamicStringListProperty property = new DynamicStringListProperty("trace.handler.tlist", "|", DynamicStringListProperty.DEFAULT_DELIMITER);
    //        List<String> ll = property.get();
    //        for (String s : ll) {
    //            System.out.println(s);
    //        }
    Object o = ConfigUtil.getProperty("zq");
    @SuppressWarnings("unchecked") List<Map<String, Object>> listO = (List<Map<String, Object>>) o;
    Assert.assertEquals(3, listO.size());
}
Also used : ConcurrentMapConfiguration(com.netflix.config.ConcurrentMapConfiguration) SystemConfiguration(org.apache.commons.configuration.SystemConfiguration) NeverStartPollingScheduler(io.servicecomb.config.archaius.scheduler.NeverStartPollingScheduler) ConcurrentCompositeConfiguration(com.netflix.config.ConcurrentCompositeConfiguration) DynamicDoubleProperty(com.netflix.config.DynamicDoubleProperty) DynamicConfiguration(com.netflix.config.DynamicConfiguration) List(java.util.List) Map(java.util.Map) Test(org.junit.Test)

Example 15 with DynamicConfiguration

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

the class TestPropertiesLoader method init.

@BeforeClass
public static void init() {
    ConcurrentCompositeConfiguration finalConfig = new ConcurrentCompositeConfiguration();
    YAMLConfigurationSource yamlConfigurationSource = new YAMLConfigurationSource();
    DynamicConfiguration configFromYamlFile = new DynamicConfiguration(yamlConfigurationSource, new NeverStartPollingScheduler());
    finalConfig.addConfiguration(configFromYamlFile, "configFromYamlFile");
    ConfigurationManager.install(finalConfig);
}
Also used : DynamicConfiguration(com.netflix.config.DynamicConfiguration) YAMLConfigurationSource(io.servicecomb.config.archaius.sources.YAMLConfigurationSource) ConcurrentCompositeConfiguration(com.netflix.config.ConcurrentCompositeConfiguration) NeverStartPollingScheduler(io.servicecomb.config.archaius.scheduler.NeverStartPollingScheduler) BeforeClass(org.junit.BeforeClass)

Aggregations

DynamicConfiguration (com.netflix.config.DynamicConfiguration)27 Test (org.junit.Test)21 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 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 DynamicDoubleProperty (com.netflix.config.DynamicDoubleProperty)1