use of org.apache.commons.configuration.AbstractConfiguration in project incubator-servicecomb-java-chassis by apache.
the class TestIsolationServerListFilter method testGetFilteredListOfServersOnContinuousFailureReachesThreshold.
@Test
public void testGetFilteredListOfServersOnContinuousFailureReachesThreshold() {
((AbstractConfiguration) DynamicPropertyFactory.getBackingConfigurationSource()).addProperty("cse.loadbalance.isolation.continuousFailureThreshold", "3");
Invocation invocation = Mockito.mock(Invocation.class);
CseServer testServer = Mockito.mock(CseServer.class);
Mockito.when(invocation.getMicroserviceName()).thenReturn("microserviceName");
Mockito.when(testServer.getCountinuousFailureCount()).thenReturn(3);
Mockito.when(testServer.getLastVisitTime()).thenReturn(System.currentTimeMillis());
for (int i = 0; i < 3; ++i) {
loadBalancerStats.incrementNumRequests(testServer);
}
List<Server> serverList = new ArrayList<>();
serverList.add(testServer);
IsolationServerListFilter.setLoadBalancerStats(loadBalancerStats);
IsolationServerListFilter.setInvocation(invocation);
List<Server> returnedServerList = IsolationServerListFilter.getFilteredListOfServers(serverList);
Assert.assertEquals(0, returnedServerList.size());
}
use of org.apache.commons.configuration.AbstractConfiguration in project incubator-servicecomb-java-chassis by apache.
the class TestHighwayClient method beforeCls.
@BeforeClass
public static void beforeCls() {
ConfigUtil.installDynamicConfig();
AbstractConfiguration configuration = (AbstractConfiguration) DynamicPropertyFactory.getBackingConfigurationSource();
configuration.addProperty(REQUEST_TIMEOUT_KEY, 2000);
}
use of org.apache.commons.configuration.AbstractConfiguration in project archaius by Netflix.
the class SampleBean method main.
/**
* SampleApplication entrypoint
* @param args
*/
public static void main(String[] args) {
// @SuppressWarnings(value = {"unused" })
new SampleApplication();
// Step 1.
// Create a Source of Configuration
// Here we use a simple ConcurrentMapConfiguration
// You can use your own, or use of the pre built ones including JDBCConfigurationSource
// which lets you load properties from any RDBMS
AbstractConfiguration myConfiguration = new ConcurrentMapConfiguration();
myConfiguration.setProperty("com.netflix.config.samples.sampleapp.prop1", "value1");
myConfiguration.setProperty("com.netflix.config.samples.SampleApp.SampleBean.name", "A Coffee Bean from Gautemala");
// STEP 2: Optional. Dynamic Runtime property change option
// We would like to utilize the benefits of obtaining dynamic property
// changes
// initialize the DynamicPropertyFactory with our configuration source
DynamicPropertyFactory.initWithConfigurationSource(myConfiguration);
// STEP 3: Optional. Option to inspect and modify properties using JConsole
// We would like to inspect properties via JMX JConsole and potentially
// update
// these properties too
// Register the MBean
//
// This can be also achieved automatically by setting "true" to
// system property "archaius.dynamicPropertyFactory.registerConfigWithJMX"
configMBean = ConfigJMXManager.registerConfigMbean(myConfiguration);
// once this application is launched, launch JConsole and navigate to
// the
// Config MBean (under the MBeans tab)
System.out.println("Started SampleApplication. Launch JConsole to inspect and update properties");
System.out.println("To see how callback work, update property com.netflix.config.samples.SampleApp.SampleBean.sensitiveBeanData from BaseConfigBean in JConsole");
SampleBean sampleBean = new SampleBean();
System.out.println("SampleBean:" + sampleBean);
System.out.println(sampleBean.getName());
}
use of org.apache.commons.configuration.AbstractConfiguration in project archaius by Netflix.
the class OverridingPropertiesConfiguration method convertToConcurrentCompositeConfiguration.
/**
* Convert CombinedConfiguration into {@link ConcurrentCompositeConfiguration} as the later has better performance
* and thread safety.
*
* @param config Configuration to be converted
*/
public static ConcurrentCompositeConfiguration convertToConcurrentCompositeConfiguration(CombinedConfiguration config) {
ConcurrentCompositeConfiguration root = new ConcurrentCompositeConfiguration();
IdentityHashMap<Configuration, String> reverseMap = new IdentityHashMap<Configuration, String>();
for (String name : (Set<String>) config.getConfigurationNames()) {
Configuration child = config.getConfiguration(name);
reverseMap.put(child, name);
}
for (int i = 0; i < config.getNumberOfConfigurations(); i++) {
Configuration child = config.getConfiguration(i);
String name = reverseMap.get(child);
if (child instanceof CombinedConfiguration) {
CombinedConfiguration combinedConf = (CombinedConfiguration) child;
ConcurrentCompositeConfiguration newConf = convertToConcurrentCompositeConfiguration(combinedConf);
root.addConfiguration(newConf, name);
} else {
Configuration conf = new ConcurrentMapConfiguration(child);
root.addConfiguration((AbstractConfiguration) conf, name);
}
}
return root;
}
use of org.apache.commons.configuration.AbstractConfiguration in project archaius by Netflix.
the class ConcurrentCompositeConfiguration method getList.
/**
* Get a List of objects associated with the given configuration key.
* If the key doesn't map to an existing object, the default value
* is returned.
*
* @param key The configuration key.
* @param defaultValue The default value.
* @return The associated List of value.
*/
@Override
public List getList(String key, List defaultValue) {
List<Object> list = new ArrayList<Object>();
// add all elements from the first configuration containing the requested key
Iterator<AbstractConfiguration> it = configList.iterator();
if (overrideProperties.containsKey(key)) {
appendListProperty(list, overrideProperties, key);
}
while (it.hasNext() && list.isEmpty()) {
Configuration config = it.next();
if ((config != containerConfiguration || containerConfigurationChanged) && config.containsKey(key)) {
appendListProperty(list, config, key);
}
}
// add all elements from the in memory configuration
if (list.isEmpty()) {
appendListProperty(list, containerConfiguration, key);
}
if (list.isEmpty()) {
return defaultValue;
}
ListIterator<Object> lit = list.listIterator();
while (lit.hasNext()) {
lit.set(interpolate(lit.next()));
}
return list;
}
Aggregations