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));
}
}
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());
}
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();
}
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());
}
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);
}
Aggregations