Search in sources :

Example 1 with AbstractConfiguration

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;
}
Also used : AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration)

Example 2 with AbstractConfiguration

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;
}
Also used : AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 3 with AbstractConfiguration

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());
}
Also used : AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration) Test(org.junit.Test)

Example 4 with AbstractConfiguration

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);
}
Also used : AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration) ConcurrentCompositeConfiguration(com.netflix.config.ConcurrentCompositeConfiguration) ExpandedConfigurationListenerAdapter(com.netflix.config.ExpandedConfigurationListenerAdapter) Test(org.junit.Test)

Example 5 with AbstractConfiguration

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));
}
Also used : AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration) BaseConfiguration(org.apache.commons.configuration.BaseConfiguration) Configuration(org.apache.commons.configuration.Configuration) AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration) BaseConfiguration(org.apache.commons.configuration.BaseConfiguration) Test(org.junit.Test)

Aggregations

AbstractConfiguration (org.apache.commons.configuration.AbstractConfiguration)80 Test (org.junit.Test)29 ConcurrentCompositeConfiguration (com.netflix.config.ConcurrentCompositeConfiguration)18 BeforeClass (org.junit.BeforeClass)10 Configuration (org.apache.commons.configuration.Configuration)9 URI (java.net.URI)6 BaseConfiguration (org.apache.commons.configuration.BaseConfiguration)6 HttpRequest (com.netflix.client.http.HttpRequest)5 ArrayList (java.util.ArrayList)5 DynamicConfiguration (com.netflix.config.DynamicConfiguration)4 EnvironmentConfiguration (org.apache.commons.configuration.EnvironmentConfiguration)4 SystemConfiguration (org.apache.commons.configuration.SystemConfiguration)4 HttpResponse (com.netflix.client.http.HttpResponse)3 ConcurrentMapConfiguration (com.netflix.config.ConcurrentMapConfiguration)3 ExpandedConfigurationListenerAdapter (com.netflix.config.ExpandedConfigurationListenerAdapter)3 LinkedHashMap (java.util.LinkedHashMap)3 Properties (java.util.Properties)3 AggregatedConfiguration (com.netflix.config.AggregatedConfiguration)2 ConfigurationManager (com.netflix.config.ConfigurationManager)2 DynamicURLConfiguration (com.netflix.config.DynamicURLConfiguration)2