use of org.jmock.lib.concurrent.DeterministicScheduler in project bookkeeper by apache.
the class TestConfigurationSubscription method testInitialConfigLoad.
@Test(timeout = 60000)
public void testInitialConfigLoad() throws Exception {
PropertiesWriter writer = new PropertiesWriter();
writer.setProperty("prop1", "1");
writer.setProperty("prop2", "abc");
writer.setProperty("prop3", "123.0");
writer.setProperty("prop4", "11132");
writer.setProperty("prop5", "true");
writer.save();
ScheduledExecutorService mockScheduler = new DeterministicScheduler();
FileConfigurationBuilder builder = new PropertiesConfigurationBuilder(writer.getFile().toURI().toURL());
ConcurrentConstConfiguration conf = new ConcurrentConstConfiguration(new CompositeConfiguration());
List<FileConfigurationBuilder> fileConfigBuilders = Lists.newArrayList(builder);
ConfigurationSubscription confSub = new ConfigurationSubscription(conf, fileConfigBuilders, mockScheduler, 100, TimeUnit.MILLISECONDS);
assertEquals(1, conf.getInt("prop1"));
assertEquals("abc", conf.getString("prop2"));
assertEquals(123.0, conf.getFloat("prop3"), 0);
assertEquals(11132, conf.getInt("prop4"));
assertEquals(true, conf.getBoolean("prop5"));
}
use of org.jmock.lib.concurrent.DeterministicScheduler in project distributedlog by twitter.
the class TestConfigurationSubscription method testInitialConfigLoad.
@Test(timeout = 60000)
public void testInitialConfigLoad() throws Exception {
PropertiesWriter writer = new PropertiesWriter();
writer.setProperty("prop1", "1");
writer.setProperty("prop2", "abc");
writer.setProperty("prop3", "123.0");
writer.setProperty("prop4", "11132");
writer.setProperty("prop5", "true");
writer.save();
ScheduledExecutorService 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);
assertEquals(1, conf.getInt("prop1"));
assertEquals("abc", conf.getString("prop2"));
assertEquals(123.0, conf.getFloat("prop3"), 0);
assertEquals(11132, conf.getInt("prop4"));
assertEquals(true, conf.getBoolean("prop5"));
}
use of org.jmock.lib.concurrent.DeterministicScheduler in project bookkeeper by apache.
the class TestConfigurationSubscription method testReloadConfiguration.
@Test(timeout = 60000)
public void testReloadConfiguration() throws Exception {
PropertiesWriter writer = new PropertiesWriter();
FileConfigurationBuilder builder = new PropertiesConfigurationBuilder(writer.getFile().toURI().toURL());
ConcurrentConstConfiguration conf = new ConcurrentConstConfiguration(new CompositeConfiguration());
DeterministicScheduler executorService = new DeterministicScheduler();
List<FileConfigurationBuilder> fileConfigBuilders = Lists.newArrayList(builder);
ConfigurationSubscription confSub = new ConfigurationSubscription(conf, fileConfigBuilders, executorService, 100, TimeUnit.MILLISECONDS);
final AtomicReference<ConcurrentBaseConfiguration> confHolder = new AtomicReference<>();
confSub.registerListener(new org.apache.distributedlog.common.config.ConfigurationListener() {
@Override
public void onReload(ConcurrentBaseConfiguration conf) {
confHolder.set(conf);
}
});
assertEquals(null, conf.getProperty("prop1"));
// add
writer.setProperty("prop1", "1");
writer.save();
// ensure the file change reloading event can be triggered
ensureConfigReloaded();
// reload the config
confSub.reload();
assertNotNull(confHolder.get());
assertTrue(conf == confHolder.get());
assertEquals("1", conf.getProperty("prop1"));
}
use of org.jmock.lib.concurrent.DeterministicScheduler in project bookkeeper by apache.
the class TestConfigurationSubscription method testAddReloadBasicsConfig.
@Test(timeout = 60000)
public void testAddReloadBasicsConfig() throws Exception {
PropertiesWriter writer = new PropertiesWriter();
DeterministicScheduler mockScheduler = new DeterministicScheduler();
FileConfigurationBuilder builder = new PropertiesConfigurationBuilder(writer.getFile().toURI().toURL());
ConcurrentConstConfiguration conf = new ConcurrentConstConfiguration(new CompositeConfiguration());
List<FileConfigurationBuilder> fileConfigBuilders = Lists.newArrayList(builder);
ConfigurationSubscription confSub = new ConfigurationSubscription(conf, fileConfigBuilders, mockScheduler, 100, TimeUnit.MILLISECONDS);
assertEquals(null, conf.getProperty("prop1"));
// add
writer.setProperty("prop1", "1");
writer.save();
// ensure the file change reloading event can be triggered
ensureConfigReloaded();
mockScheduler.tick(100, TimeUnit.MILLISECONDS);
assertEquals("1", conf.getProperty("prop1"));
}
use of org.jmock.lib.concurrent.DeterministicScheduler in project bookkeeper by apache.
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 CompositeConfiguration());
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);
}
}
Aggregations