use of com.netflix.config.DynamicWatchedConfiguration in project archaius by Netflix.
the class ZooKeeperConfigurationSourceTest method setUp.
@BeforeClass
public static void setUp() throws Exception {
System.setProperty(DebugUtils.PROPERTY_DONT_LOG_CONNECTION_ISSUES, "true");
server = new TestingServer();
logger.info("Initialized local ZK with connect string [{}]", server.getConnectString());
client = CuratorFrameworkFactory.newClient(server.getConnectString(), new ExponentialBackoffRetry(1000, 3));
client.start();
zkConfigSource = new ZooKeeperConfigurationSource(client, CONFIG_ROOT_PATH);
zkConfigSource.start();
// setup system properties
System.setProperty("test.key4", "test.value4-system");
System.setProperty("test.key5", "test.value5-system");
final ConcurrentMapConfiguration systemConfig = new ConcurrentMapConfiguration();
systemConfig.loadProperties(System.getProperties());
final DynamicWatchedConfiguration zkDynamicOverrideConfig = new DynamicWatchedConfiguration(zkConfigSource);
mapConfig = new ConcurrentMapConfiguration();
mapConfig.addProperty("test.key1", "test.value1-map");
mapConfig.addProperty("test.key2", "test.value2-map");
mapConfig.addProperty("test.key3", "test.value3-map");
mapConfig.addProperty("test.key4", "test.value4-map");
final ConcurrentCompositeConfiguration compositeConfig = new ConcurrentCompositeConfiguration();
compositeConfig.addConfiguration(zkDynamicOverrideConfig, "zk dynamic override configuration");
compositeConfig.addConfiguration(mapConfig, "map configuration");
compositeConfig.addConfiguration(systemConfig, "system configuration");
// setup ZK properties
setZkProperty("test.key1", "test.value1-zk");
setZkProperty("test.key2", "test.value2-zk");
setZkProperty("test.key4", "test.value4-zk");
ConfigurationManager.install(compositeConfig);
}
use of com.netflix.config.DynamicWatchedConfiguration in project chassis by Kixeye.
the class DynamicZookeeperConfigurationSourceTest method instanceConfigAddedAfterStartup.
@Test
public void instanceConfigAddedAfterStartup() throws Exception {
String instanceConfigNode = CONFIG_BASE_PATH + "/" + node;
Assert.assertNull(curatorFramework.checkExists().forPath(instanceConfigNode));
config.addConfiguration(new DynamicWatchedConfiguration(new DynamicZookeeperConfigurationSource(curatorFramework, CONFIG_BASE_PATH, node)));
config.addConfiguration(defaultConfiguration);
Assert.assertEquals(DEF_VAL1, config.getString(DEF_KEY1));
Assert.assertEquals(DEF_VAL2, config.getString(DEF_KEY2));
//create the instance node
curatorFramework.create().forPath(instanceConfigNode);
Thread.sleep(1000);
Assert.assertEquals(DEF_VAL1, config.getString(DEF_KEY1));
Assert.assertEquals(DEF_VAL2, config.getString(DEF_KEY2));
//create a property
String key = instanceConfigNode + "/" + DEF_KEY1;
String val = DEF_VAL1 + "--override";
curatorFramework.create().forPath(key, val.getBytes());
Thread.sleep(1000);
Assert.assertEquals(val, config.getString(DEF_KEY1));
Assert.assertEquals(DEF_VAL2, config.getString(DEF_KEY2));
}
use of com.netflix.config.DynamicWatchedConfiguration in project chassis by Kixeye.
the class DynamicZookeeperConfigurationSourceTest method instanceConfigExistsAtStartup.
@Test
public void instanceConfigExistsAtStartup() throws Exception {
curatorFramework.create().forPath(CONFIG_BASE_PATH + "/" + node);
String key = CONFIG_BASE_PATH + "/" + node + "/" + DEF_KEY1;
curatorFramework.create().forPath(key, "val1-override".getBytes());
Assert.assertNotNull(curatorFramework.checkExists().forPath(key));
config.addConfiguration(new DynamicWatchedConfiguration(new DynamicZookeeperConfigurationSource(curatorFramework, CONFIG_BASE_PATH, node)));
config.addConfiguration(defaultConfiguration);
Assert.assertEquals("val1-override", config.getString(DEF_KEY1));
Assert.assertEquals(DEF_VAL2, config.getString(DEF_KEY2));
}
use of com.netflix.config.DynamicWatchedConfiguration in project chassis by Kixeye.
the class DynamicZookeeperConfigurationSourceTest method instanceConfigDoesNotExistAtStartup.
@Test
public void instanceConfigDoesNotExistAtStartup() {
config.addConfiguration(new DynamicWatchedConfiguration(new DynamicZookeeperConfigurationSource(curatorFramework, CONFIG_BASE_PATH, node)));
config.addConfiguration(defaultConfiguration);
Assert.assertEquals(DEF_VAL1, config.getString(DEF_KEY1));
Assert.assertEquals(DEF_VAL2, config.getString(DEF_KEY2));
}
use of com.netflix.config.DynamicWatchedConfiguration in project chassis by Kixeye.
the class DynamicZookeeperConfigurationSourceTest method instanceConfigPropertyDeleted.
@Test
public void instanceConfigPropertyDeleted() throws Exception {
curatorFramework.create().forPath(CONFIG_BASE_PATH + "/" + node);
config.addConfiguration(new DynamicWatchedConfiguration(new DynamicZookeeperConfigurationSource(curatorFramework, CONFIG_BASE_PATH, node)));
config.addConfiguration(defaultConfiguration);
Assert.assertEquals(DEF_VAL1, config.getString(DEF_KEY1));
curatorFramework.create().forPath(CONFIG_BASE_PATH + "/" + node + "/" + DEF_KEY1, "override".getBytes());
Thread.sleep(1000);
Assert.assertEquals("override", config.getString(DEF_KEY1));
curatorFramework.delete().forPath(CONFIG_BASE_PATH + "/" + node + "/" + DEF_KEY1);
Thread.sleep(1000);
Assert.assertEquals(DEF_VAL1, config.getString(DEF_KEY1));
}
Aggregations