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