Search in sources :

Example 21 with AbstractConfiguration

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());
}
Also used : AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration) Invocation(org.apache.servicecomb.core.Invocation) CseServer(org.apache.servicecomb.loadbalance.CseServer) CseServer(org.apache.servicecomb.loadbalance.CseServer) Server(com.netflix.loadbalancer.Server) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 22 with AbstractConfiguration

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

Example 23 with AbstractConfiguration

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

Example 24 with AbstractConfiguration

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;
}
Also used : Set(java.util.Set) Configuration(org.apache.commons.configuration.Configuration) ConcurrentMapConfiguration(com.netflix.config.ConcurrentMapConfiguration) AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) ConcurrentCompositeConfiguration(com.netflix.config.ConcurrentCompositeConfiguration) CombinedConfiguration(org.apache.commons.configuration.CombinedConfiguration) ConcurrentMapConfiguration(com.netflix.config.ConcurrentMapConfiguration) IdentityHashMap(java.util.IdentityHashMap) CombinedConfiguration(org.apache.commons.configuration.CombinedConfiguration) ConcurrentCompositeConfiguration(com.netflix.config.ConcurrentCompositeConfiguration)

Example 25 with AbstractConfiguration

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

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