use of org.apache.commons.configuration.CompositeConfiguration 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);
}
}
use of org.apache.commons.configuration.CompositeConfiguration in project bookkeeper by apache.
the class TestConfUtils method testLoadConfiguration.
@Test(timeout = 60000)
public void testLoadConfiguration() {
Configuration conf1 = new CompositeConfiguration();
conf1.setProperty("key1", "value1");
conf1.setProperty("key2", "value2");
conf1.setProperty("key3", "value3");
Configuration conf2 = new CompositeConfiguration();
conf2.setProperty("bkc.key1", "bkc.value1");
conf2.setProperty("bkc.key4", "bkc.value4");
assertEquals("value1", conf1.getString("key1"));
assertEquals("value2", conf1.getString("key2"));
assertEquals("value3", conf1.getString("key3"));
assertEquals(null, conf1.getString("key4"));
ConfUtils.loadConfiguration(conf1, conf2, "bkc.");
assertEquals("bkc.value1", conf1.getString("key1"));
assertEquals("value2", conf1.getString("key2"));
assertEquals("value3", conf1.getString("key3"));
assertEquals("bkc.value4", conf1.getString("key4"));
assertEquals(null, conf1.getString("bkc.key1"));
assertEquals(null, conf1.getString("bkc.key4"));
}
use of org.apache.commons.configuration.CompositeConfiguration in project bookkeeper by apache.
the class StorageServer method loadConfFile.
private static void loadConfFile(CompositeConfiguration conf, String confFile) throws IllegalArgumentException {
try {
Configuration loadedConf = new PropertiesConfiguration(new File(confFile).toURI().toURL());
conf.addConfiguration(loadedConf);
} catch (MalformedURLException e) {
log.error("Could not open configuration file {}", confFile, e);
throw new IllegalArgumentException("Could not open configuration file " + confFile, e);
} catch (ConfigurationException e) {
log.error("Malformed configuration file {}", confFile, e);
throw new IllegalArgumentException("Malformed configuration file " + confFile, e);
}
log.info("Loaded configuration file {}", confFile);
}
use of org.apache.commons.configuration.CompositeConfiguration in project bookkeeper by apache.
the class StorageServer method doMain.
static int doMain(String[] args) {
// register thread uncaught exception handler
Thread.setDefaultUncaughtExceptionHandler((thread, exception) -> log.error("Uncaught exception in thread {}: {}", thread.getName(), exception.getMessage()));
// parse the commandline
ServerArguments arguments = new ServerArguments();
JCommander jCommander = new JCommander(arguments);
jCommander.setProgramName("StorageServer");
jCommander.parse(args);
if (arguments.help) {
jCommander.usage();
return ExitCode.INVALID_CONF.code();
}
CompositeConfiguration conf = new CompositeConfiguration();
if (null != arguments.serverConfigFile) {
loadConfFile(conf, arguments.serverConfigFile);
}
int grpcPort = arguments.port;
LifecycleComponent storageServer;
try {
storageServer = startStorageServer(conf, grpcPort, 1024, Optional.empty());
} catch (ConfigurationException e) {
log.error("Invalid storage configuration", e);
return ExitCode.INVALID_CONF.code();
} catch (UnknownHostException e) {
log.error("Unknonw host name", e);
return ExitCode.UNKNOWN_HOSTNAME.code();
}
CompletableFuture<Void> liveFuture = ComponentStarter.startComponent(storageServer);
try {
liveFuture.get();
} catch (InterruptedException e) {
// the server is interrupted.
Thread.currentThread().interrupt();
log.info("Storage server is interrupted. Exiting ...");
} catch (ExecutionException e) {
log.info("Storage server is exiting ...");
}
return ExitCode.OK.code();
}
use of org.apache.commons.configuration.CompositeConfiguration in project bookkeeper by apache.
the class TestDefaultStorageContainerFactory method testCreate.
@Test
public void testCreate() throws Exception {
OrderedScheduler scheduler = mock(OrderedScheduler.class);
OrderedScheduler snapshotScheduler = mock(OrderedScheduler.class);
MVCCStoreFactory storeFactory = mock(MVCCStoreFactory.class);
ListeningScheduledExecutorService snapshotExecutor = mock(ListeningScheduledExecutorService.class);
when(snapshotScheduler.chooseThread(anyLong())).thenReturn(snapshotExecutor);
Mockito.doReturn(mock(ListenableScheduledFuture.class)).when(snapshotExecutor).scheduleWithFixedDelay(any(Runnable.class), anyInt(), anyInt(), any(TimeUnit.class));
DefaultStorageContainerFactory factory = new DefaultStorageContainerFactory(new StorageConfiguration(new CompositeConfiguration()), (streamId, rangeId) -> streamId, scheduler, storeFactory, URI.create("distributedlog://127.0.0.1/stream/storage"));
StorageContainer sc = factory.createStorageContainer(1234L);
assertTrue(sc instanceof StorageContainerImpl);
assertEquals(1234L, sc.getId());
}
Aggregations