use of org.apache.commons.configuration.AbstractConfiguration in project archaius by Netflix.
the class ConcurrentCompositeConfiguration method removeConfigurationAt.
public AbstractConfiguration removeConfigurationAt(int index) {
AbstractConfiguration config = configList.remove(index);
String nameFound = getNameForConfiguration(config);
if (nameFound != null) {
namedConfigurations.remove(nameFound);
}
return config;
}
use of org.apache.commons.configuration.AbstractConfiguration in project archaius by Netflix.
the class ConcurrentCompositeConfiguration method getConfigurationNameList.
public List<String> getConfigurationNameList() {
List<String> list = new ArrayList<String>(configList.size());
for (AbstractConfiguration configuration : configList) {
boolean foundName = false;
for (String name : namedConfigurations.keySet()) {
if (configuration == namedConfigurations.get(name)) {
foundName = true;
list.add(name);
break;
}
}
if (!foundName) {
list.add(null);
}
}
return list;
}
use of org.apache.commons.configuration.AbstractConfiguration in project archaius by Netflix.
the class DynamicFileConfigurationTest method testSwitchingToConfiguration.
@Test
public void testSwitchingToConfiguration() throws Exception {
longProp = propertyFactory.getLongProperty("dprops1", Long.MAX_VALUE, new Runnable() {
public void run() {
propertyChanged = true;
}
});
AbstractConfiguration newConfig = new ConcurrentMapConfiguration();
DynamicStringProperty prop = propertyFactory.getStringProperty("abc", "default");
newConfig.setProperty("abc", "nondefault");
newConfig.setProperty("dprops1", "0");
DynamicPropertyFactory.initWithConfigurationSource(newConfig);
Thread.sleep(2000);
assertEquals("nondefault", prop.get());
assertEquals(0, longProp.get());
assertTrue(newConfig == ConfigurationManager.getConfigInstance());
assertTrue(ConfigurationManager.isConfigurationInstalled());
}
use of org.apache.commons.configuration.AbstractConfiguration in project archaius by Netflix.
the class DynamicPropertyUpdaterTest method testAddorUpdatePropertyWithColonDelimiter.
@Test
public void testAddorUpdatePropertyWithColonDelimiter() {
AbstractConfiguration.setDefaultListDelimiter(':');
AbstractConfiguration config = new ConcurrentCompositeConfiguration();
config.addConfigurationListener(new ExpandedConfigurationListenerAdapter(new MyListener()));
MyListener.resetCount();
config.setProperty("test.host", "test:test1:test2");
assertEquals(1, MyListener.count);
dynamicPropertyUpdater.addOrChangeProperty("test.host", "test:test1:test2", config);
assertEquals(3, ((CopyOnWriteArrayList) (config.getProperty("test.host"))).size());
assertTrue(((CopyOnWriteArrayList) (config.getProperty("test.host"))).contains("test"));
assertTrue(((CopyOnWriteArrayList) (config.getProperty("test.host"))).contains("test1"));
assertTrue(((CopyOnWriteArrayList) (config.getProperty("test.host"))).contains("test2"));
// the config is not set again. when the value is still not changed.
assertEquals(1, MyListener.count);
config.setProperty("test.host1", "test1:test12");
// changing the new object value , the config.setProperty should be called again.
dynamicPropertyUpdater.addOrChangeProperty("test.host1", "test1.test12", config);
assertEquals("test1.test12", config.getProperty("test.host1"));
assertEquals(3, MyListener.count);
}
use of org.apache.commons.configuration.AbstractConfiguration in project archaius by Netflix.
the class ConcurrentCompositeConfigurationTest method testContainerConfiguration.
@Test
public void testContainerConfiguration() {
ConcurrentCompositeConfiguration config = new ConcurrentCompositeConfiguration();
assertEquals(0, config.getIndexOfContainerConfiguration());
Configuration originalContainerConfig = config.getContainerConfiguration();
AbstractConfiguration config1 = new BaseConfiguration();
config.addConfiguration(config1, "base");
assertEquals(1, config.getIndexOfContainerConfiguration());
config.setContainerConfigurationIndex(0);
assertEquals(0, config.getIndexOfContainerConfiguration());
assertEquals(2, config.getNumberOfConfigurations());
AbstractConfiguration config2 = new ConcurrentMapConfiguration();
config.addConfigurationAtIndex(config2, "new", 1);
AbstractConfiguration config3 = new ConcurrentMapConfiguration();
config.setContainerConfiguration(config3, "new container", 2);
assertEquals(config3, config.getContainerConfiguration());
try {
config.setContainerConfigurationIndex(4);
fail("expect IndexOutOfBoundsException");
} catch (IndexOutOfBoundsException e) {
assertNotNull(e);
}
try {
config.addConfigurationAtIndex(new BaseConfiguration(), "ignore", 5);
fail("expect IndexOutOfBoundsException");
} catch (IndexOutOfBoundsException e) {
assertNotNull(e);
}
List<AbstractConfiguration> list = config.getConfigurations();
assertEquals(originalContainerConfig, list.get(0));
assertEquals(config2, list.get(1));
assertEquals(config3, list.get(2));
assertEquals(config1, list.get(3));
assertEquals(4, list.size());
config.removeConfiguration(config1);
assertFalse(config.getConfigurationNames().contains("base"));
assertFalse(config.getConfigurations().contains(config1));
config.removeConfigurationAt(1);
assertFalse(config.getConfigurationNames().contains("new"));
assertFalse(config.getConfigurations().contains(config2));
AbstractConfiguration config4 = new ConcurrentMapConfiguration();
config.addConfiguration(config4, "another container");
config.removeConfiguration("another container");
assertFalse(config.getConfigurationNames().contains("another container"));
assertFalse(config.getConfigurations().contains(config4));
}
Aggregations