Search in sources :

Example 1 with ExpandedConfigurationListenerAdapter

use of com.netflix.config.ExpandedConfigurationListenerAdapter 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 2 with ExpandedConfigurationListenerAdapter

use of com.netflix.config.ExpandedConfigurationListenerAdapter in project archaius by Netflix.

the class DynamicPropertyUpdaterTest method testUpdateProperties.

/**
 * Test method for {@link com.charter.aesd.archaius.DynamicPropertyUpdater#updateProperties(com.netflix.config.WatchedUpdateResult, org.apache.commons.configuration.Configuration, boolean)}.
 * @throws InterruptedException
 */
@Test
public void testUpdateProperties() throws InterruptedException {
    AbstractConfiguration.setDefaultListDelimiter(',');
    AbstractConfiguration config = new ConcurrentCompositeConfiguration();
    config.addConfigurationListener(new ExpandedConfigurationListenerAdapter(new MyListener()));
    MyListener.resetCount();
    config.setProperty("test", "host,host1,host2");
    config.setProperty("test12", "host12");
    Map<String, Object> added = Maps.newHashMap();
    added.put("test.host", "test,test1");
    Map<String, Object> changed = Maps.newHashMap();
    changed.put("test", "host,host1");
    changed.put("test.host", "");
    dynamicPropertyUpdater.updateProperties(WatchedUpdateResult.createIncremental(added, changed, null), config, false);
    assertEquals("", config.getProperty("test.host"));
    assertEquals(2, ((CopyOnWriteArrayList) (config.getProperty("test"))).size());
    assertTrue(((CopyOnWriteArrayList) (config.getProperty("test"))).contains("host"));
    assertTrue(((CopyOnWriteArrayList) (config.getProperty("test"))).contains("host1"));
    assertEquals(5, 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 3 with ExpandedConfigurationListenerAdapter

use of com.netflix.config.ExpandedConfigurationListenerAdapter in project archaius by Netflix.

the class DynamicPropertyUpdaterTest method testAddorChangeProperty.

@Test
public void testAddorChangeProperty() {
    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"));
    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"));
    assertEquals(1, MyListener.count);
    dynamicPropertyUpdater.addOrChangeProperty("test.host", "test,test1", config);
    assertEquals(2, ((CopyOnWriteArrayList) (config.getProperty("test.host"))).size());
    assertTrue(((CopyOnWriteArrayList) (config.getProperty("test.host"))).contains("test"));
    assertTrue(((CopyOnWriteArrayList) (config.getProperty("test.host"))).contains("test1"));
    assertEquals(2, MyListener.count);
    dynamicPropertyUpdater.addOrChangeProperty("test.host1", "test1,test12", config);
    assertEquals(2, ((CopyOnWriteArrayList) (config.getProperty("test.host1"))).size());
    assertTrue(((CopyOnWriteArrayList) (config.getProperty("test.host1"))).contains("test1"));
    assertTrue(((CopyOnWriteArrayList) (config.getProperty("test.host1"))).contains("test12"));
    assertEquals(3, MyListener.count);
    config.setProperty("test.host1", "test1.test12");
    dynamicPropertyUpdater.addOrChangeProperty("test.host1", "test1.test12", config);
    assertEquals("test1.test12", config.getProperty("test.host1"));
    assertEquals(4, MyListener.count);
}
Also used : AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration) ConcurrentCompositeConfiguration(com.netflix.config.ConcurrentCompositeConfiguration) ExpandedConfigurationListenerAdapter(com.netflix.config.ExpandedConfigurationListenerAdapter) Test(org.junit.Test)

Aggregations

ConcurrentCompositeConfiguration (com.netflix.config.ConcurrentCompositeConfiguration)3 ExpandedConfigurationListenerAdapter (com.netflix.config.ExpandedConfigurationListenerAdapter)3 AbstractConfiguration (org.apache.commons.configuration.AbstractConfiguration)3 Test (org.junit.Test)3