Search in sources :

Example 11 with ConfigurationEvent

use of org.apache.commons.configuration.event.ConfigurationEvent in project distributedlog by twitter.

the class TestConfigurationSubscription method testExceptionInConfigLoad.

@Test(timeout = 60000)
public void testExceptionInConfigLoad() throws Exception {
    PropertiesWriter writer = new PropertiesWriter();
    writer.setProperty("prop1", "1");
    writer.save();
    DeterministicScheduler mockScheduler = new DeterministicScheduler();
    FileConfigurationBuilder builder = new PropertiesConfigurationBuilder(writer.getFile().toURI().toURL());
    ConcurrentConstConfiguration conf = new ConcurrentConstConfiguration(new DistributedLogConfiguration());
    List<FileConfigurationBuilder> fileConfigBuilders = Lists.newArrayList(builder);
    ConfigurationSubscription confSub = new ConfigurationSubscription(conf, fileConfigBuilders, mockScheduler, 100, TimeUnit.MILLISECONDS);
    final AtomicInteger count = new AtomicInteger(1);
    conf.addConfigurationListener(new ConfigurationListener() {

        @Override
        public void configurationChanged(ConfigurationEvent event) {
            LOG.info("config changed {}", event);
            // Throw after so we actually see the update anyway.
            if (!event.isBeforeUpdate()) {
                count.getAndIncrement();
                throw new RuntimeException("config listener threw and exception");
            }
        }
    });
    int i = 0;
    int initial = 0;
    while (count.get() == initial) {
        writer.setProperty("prop1", Integer.toString(i++));
        writer.save();
        mockScheduler.tick(100, TimeUnit.MILLISECONDS);
    }
    initial = count.get();
    while (count.get() == initial) {
        writer.setProperty("prop1", Integer.toString(i++));
        writer.save();
        mockScheduler.tick(100, TimeUnit.MILLISECONDS);
    }
}
Also used : ConfigurationEvent(org.apache.commons.configuration.event.ConfigurationEvent) ConfigurationListener(org.apache.commons.configuration.event.ConfigurationListener) DistributedLogConfiguration(com.twitter.distributedlog.DistributedLogConfiguration) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DeterministicScheduler(org.jmock.lib.concurrent.DeterministicScheduler) Test(org.junit.Test)

Example 12 with ConfigurationEvent

use of org.apache.commons.configuration.event.ConfigurationEvent in project spring-cloud-netflix by spring-cloud.

the class ArchaiusAutoConfigurationTests method environmentChangeEventPropagated.

@Test
public void environmentChangeEventPropagated() {
    this.context = new AnnotationConfigApplicationContext(ArchaiusAutoConfiguration.class);
    ConfigurationManager.getConfigInstance().addConfigurationListener(new ConfigurationListener() {

        @Override
        public void configurationChanged(ConfigurationEvent event) {
            if (event.getPropertyName().equals("my.prop")) {
                ArchaiusAutoConfigurationTests.this.propertyValue = event.getPropertyValue();
            }
        }
    });
    EnvironmentTestUtils.addEnvironment(this.context, "my.prop=my.newval");
    this.context.publishEvent(new EnvironmentChangeEvent(Collections.singleton("my.prop")));
    assertEquals("my.newval", this.propertyValue);
}
Also used : ConfigurationListener(org.apache.commons.configuration.event.ConfigurationListener) ConfigurationEvent(org.apache.commons.configuration.event.ConfigurationEvent) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) EnvironmentChangeEvent(org.springframework.cloud.context.environment.EnvironmentChangeEvent) Test(org.junit.Test)

Aggregations

ConfigurationEvent (org.apache.commons.configuration.event.ConfigurationEvent)12 ConfigurationListener (org.apache.commons.configuration.event.ConfigurationListener)11 Test (org.junit.Test)5 PanelBuilder (com.jgoodies.forms.builder.PanelBuilder)3 CellConstraints (com.jgoodies.forms.layout.CellConstraints)3 FormLayout (com.jgoodies.forms.layout.FormLayout)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 DeterministicScheduler (org.jmock.lib.concurrent.DeterministicScheduler)2 LoggerContext (ch.qos.logback.classic.LoggerContext)1 DistributedLogConfiguration (com.twitter.distributedlog.DistributedLogConfiguration)1 Color (java.awt.Color)1 Dimension (java.awt.Dimension)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 ItemEvent (java.awt.event.ItemEvent)1 ItemListener (java.awt.event.ItemListener)1 BindException (java.net.BindException)1 IllegalCharsetNameException (java.nio.charset.IllegalCharsetNameException)1 UnsupportedCharsetException (java.nio.charset.UnsupportedCharsetException)1 AccessControlException (java.security.AccessControlException)1