Search in sources :

Example 6 with Configuration

use of org.apache.commons.configuration.Configuration 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)

Example 7 with Configuration

use of org.apache.commons.configuration.Configuration in project eureka by Netflix.

the class PropertiesInstanceConfig method getMetadataMap.

/**
     * Gets the metadata map associated with the instance. The properties that
     * will be looked up for this will be <code>namespace + ".metadata"</code>.
     *
     * <p>
     * For instance, if the given namespace is <code>eureka.appinfo</code>, the
     * metadata keys are searched under the namespace
     * <code>eureka.appinfo.metadata</code>.
     * </p>
     */
@Override
public Map<String, String> getMetadataMap() {
    String metadataNamespace = namespace + INSTANCE_METADATA_PREFIX + ".";
    Map<String, String> metadataMap = new LinkedHashMap<String, String>();
    Configuration config = (Configuration) configInstance.getBackingConfigurationSource();
    String subsetPrefix = metadataNamespace.charAt(metadataNamespace.length() - 1) == '.' ? metadataNamespace.substring(0, metadataNamespace.length() - 1) : metadataNamespace;
    for (Iterator<String> iter = config.subset(subsetPrefix).getKeys(); iter.hasNext(); ) {
        String key = iter.next();
        String value = config.getString(subsetPrefix + "." + key);
        metadataMap.put(key, value);
    }
    return metadataMap;
}
Also used : Configuration(org.apache.commons.configuration.Configuration) LinkedHashMap(java.util.LinkedHashMap)

Example 8 with Configuration

use of org.apache.commons.configuration.Configuration in project ribbon by Netflix.

the class LBBuilderTest method testBuildWithArchaiusProperties.

@Test
public void testBuildWithArchaiusProperties() {
    Configuration config = ConfigurationManager.getConfigInstance();
    config.setProperty("client1.niws.client." + Keys.DeploymentContextBasedVipAddresses, "dummy:7001");
    config.setProperty("client1.niws.client." + Keys.InitializeNFLoadBalancer, "true");
    config.setProperty("client1.niws.client." + Keys.NFLoadBalancerClassName, DynamicServerListLoadBalancer.class.getName());
    config.setProperty("client1.niws.client." + Keys.NFLoadBalancerRuleClassName, RoundRobinRule.class.getName());
    config.setProperty("client1.niws.client." + Keys.NIWSServerListClassName, DiscoveryEnabledNIWSServerList.class.getName());
    config.setProperty("client1.niws.client." + Keys.NIWSServerListFilterClassName, ZoneAffinityServerListFilter.class.getName());
    IClientConfig clientConfig = IClientConfig.Builder.newBuilder(NiwsClientConfig.class, "client1").build();
    ILoadBalancer lb = LoadBalancerBuilder.newBuilder().withClientConfig(clientConfig).buildLoadBalancerFromConfigWithReflection();
    assertNotNull(lb);
    assertEquals(DynamicServerListLoadBalancer.class.getName(), lb.getClass().getName());
    DynamicServerListLoadBalancer<Server> dynamicLB = (DynamicServerListLoadBalancer<Server>) lb;
    assertTrue(dynamicLB.getFilter() instanceof ZoneAffinityServerListFilter);
    assertTrue(dynamicLB.getRule() instanceof RoundRobinRule);
    assertTrue(dynamicLB.getPing() instanceof DummyPing);
    assertEquals(Lists.newArrayList(expected), lb.getAllServers());
}
Also used : Configuration(org.apache.commons.configuration.Configuration) Server(com.netflix.loadbalancer.Server) DynamicServerListLoadBalancer(com.netflix.loadbalancer.DynamicServerListLoadBalancer) ZoneAffinityServerListFilter(com.netflix.loadbalancer.ZoneAffinityServerListFilter) ILoadBalancer(com.netflix.loadbalancer.ILoadBalancer) DummyPing(com.netflix.loadbalancer.DummyPing) IClientConfig(com.netflix.client.config.IClientConfig) RoundRobinRule(com.netflix.loadbalancer.RoundRobinRule) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 9 with Configuration

use of org.apache.commons.configuration.Configuration in project ribbon by Netflix.

the class DefaultClientConfigImpl method loadProperties.

/**
     * Load properties for a given client. It first loads the default values for all properties,
     * and any properties already defined with Archaius ConfigurationManager.
     */
@Override
public void loadProperties(String restClientName) {
    enableDynamicProperties = true;
    setClientName(restClientName);
    loadDefaultValues();
    Configuration props = ConfigurationManager.getConfigInstance().subset(restClientName);
    for (Iterator<String> keys = props.getKeys(); keys.hasNext(); ) {
        String key = keys.next();
        String prop = key;
        try {
            if (prop.startsWith(getNameSpace())) {
                prop = prop.substring(getNameSpace().length() + 1);
            }
            setPropertyInternal(prop, getStringValue(props, key));
        } catch (Exception ex) {
            throw new RuntimeException(String.format("Property %s is invalid", prop));
        }
    }
}
Also used : Configuration(org.apache.commons.configuration.Configuration) AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration)

Example 10 with Configuration

use of org.apache.commons.configuration.Configuration in project ribbon by Netflix.

the class ClientPropertiesTest method testAnnotation.

@Test
public void testAnnotation() {
    MyTransportFactory transportFactory = new MyTransportFactory(ClientConfigFactory.DEFAULT);
    RibbonResourceFactory resourceFactory = new DefaultResourceFactory(ClientConfigFactory.DEFAULT, transportFactory);
    RibbonDynamicProxy.newInstance(SampleMovieService.class, resourceFactory, ClientConfigFactory.DEFAULT, transportFactory);
    IClientConfig clientConfig = transportFactory.getClientConfig();
    assertEquals(1000, clientConfig.get(Keys.ConnectTimeout).longValue());
    assertEquals(2000, clientConfig.get(Keys.ReadTimeout).longValue());
    Configuration config = ConfigurationManager.getConfigInstance();
    assertEquals("2000", config.getProperty("SampleMovieService.ribbon.ReadTimeout"));
    assertEquals("1000", config.getProperty("SampleMovieService.ribbon.ConnectTimeout"));
    config.setProperty("SampleMovieService.ribbon.ReadTimeout", "5000");
    assertEquals(5000, clientConfig.get(Keys.ReadTimeout).longValue());
}
Also used : Configuration(org.apache.commons.configuration.Configuration) DefaultResourceFactory(com.netflix.ribbon.DefaultResourceFactory) IClientConfig(com.netflix.client.config.IClientConfig) RibbonResourceFactory(com.netflix.ribbon.RibbonResourceFactory) Test(org.junit.Test)

Aggregations

Configuration (org.apache.commons.configuration.Configuration)169 Test (org.junit.Test)42 PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)39 ZapXmlConfiguration (org.zaproxy.zap.utils.ZapXmlConfiguration)23 Test (org.testng.annotations.Test)22 File (java.io.File)13 AbstractConfiguration (org.apache.commons.configuration.AbstractConfiguration)13 MidpointConfiguration (com.evolveum.midpoint.common.configuration.api.MidpointConfiguration)11 Properties (java.util.Properties)10 AtlasException (org.apache.atlas.AtlasException)9 ZkUtils (kafka.utils.ZkUtils)8 IndexLoadingConfigMetadata (com.linkedin.pinot.common.metadata.segment.IndexLoadingConfigMetadata)7 HashMap (java.util.HashMap)7 CompositeConfiguration (org.apache.commons.configuration.CompositeConfiguration)7 ArrayList (java.util.ArrayList)6 AtlasClient (org.apache.atlas.AtlasClient)6 BeforeClass (org.testng.annotations.BeforeClass)6 IOException (java.io.IOException)5 SimpleEntry (java.util.AbstractMap.SimpleEntry)5 ConfigurationException (org.apache.commons.configuration.ConfigurationException)5