Example usage for org.apache.commons.configuration Configuration setProperty

List of usage examples for org.apache.commons.configuration Configuration setProperty

Introduction

In this page you can find the example usage for org.apache.commons.configuration Configuration setProperty.

Prototype

void setProperty(String key, Object value);

Source Link

Document

Set a property, this will replace any previously set values.

Usage

From source file:org.lable.oss.dynamicconfig.provider.OnClasspathConfigSourceIT.java

@Test
public void testLoad() throws ConfigurationException {
    ConfigChangeListener mockListener = mock(ConfigChangeListener.class);
    ArgumentCaptor<HierarchicalConfiguration> argument = ArgumentCaptor
            .forClass(HierarchicalConfiguration.class);

    OnClasspathConfigSource source = new OnClasspathConfigSource();
    Configuration config = new BaseConfiguration();
    config.setProperty("path", "testConfigOnClasspath.yml");
    source.configure(config);/*from   w  w  w.  j  av a2s .  com*/

    source.load(new YamlDeserializer(), mockListener);

    verify(mockListener).changed(argument.capture());
    assertThat(argument.getValue().getString("config.string"), is("XXX"));
}

From source file:org.lable.oss.dynamicconfig.provider.OnClasspathConfigSourceTest.java

@Test(expected = ConfigurationException.class)
public void testLoadNoResource() throws ConfigurationException {
    ConfigChangeListener mockListener = mock(ConfigChangeListener.class);
    HierarchicalConfigurationDeserializer mockLoader = mock(HierarchicalConfigurationDeserializer.class);

    OnClasspathConfigSource source = new OnClasspathConfigSource();
    Configuration config = new BaseConfiguration();
    config.setProperty("path", "bogusPath");
    source.configure(config);/*  w  w w . j a v a2s  .c  o  m*/

    source.load(mockLoader, mockListener);
}

From source file:org.lable.oss.dynamicconfig.provider.OnClasspathConfigSourceTest.java

@Test(expected = ConfigurationException.class)
public void testLoadFailedLoadConfig() throws ConfigurationException {
    ConfigChangeListener mockListener = mock(ConfigChangeListener.class);
    HierarchicalConfigurationDeserializer mockLoader = mock(HierarchicalConfigurationDeserializer.class);

    when(mockLoader.deserialize(any(InputStream.class))).thenThrow(new ConfigurationException("!"));

    OnClasspathConfigSource source = new OnClasspathConfigSource();
    Configuration config = new BaseConfiguration();
    config.setProperty("path", "dummy.txt");
    source.configure(config);/*from   www .  ja va  2s  .  co  m*/
    source.load(mockLoader, mockListener);
}

From source file:org.lable.oss.dynamicconfig.provider.zookeeper.ZookeepersAsConfigSourceIT.java

@Test(expected = ConfigurationException.class)
public void testLoadNoNode() throws ConfigurationException {
    ConfigChangeListener mockListener = mock(ConfigChangeListener.class);
    HierarchicalConfigurationDeserializer mockLoader = mock(HierarchicalConfigurationDeserializer.class);

    // Assert that load() fails when a nonexistent node is passed as argument.
    ZookeepersAsConfigSource source = new ZookeepersAsConfigSource();
    Configuration config = new BaseConfiguration();
    config.setProperty("quorum", zookeeperHost);
    config.setProperty("znode", "/nope/nope");
    config.setProperty(APPNAME_PROPERTY, "nope");
    source.configure(config);/* w  w  w .ja v a2  s  .c o m*/

    source.load(mockLoader, mockListener);
}

From source file:org.lable.oss.dynamicconfig.provider.zookeeper.ZookeepersAsConfigSourceTest.java

@Test
public void testConstructorSlashPath() throws ConfigurationException {
    ZookeepersAsConfigSource source = new ZookeepersAsConfigSource();
    Configuration config = new BaseConfiguration();
    config.setProperty("quorum", "QUORUM");
    config.setProperty("znode", "/path/node");
    config.setProperty(ConfigurationInitializer.APPNAME_PROPERTY, "my-app");
    source.configure(config);//from  w w  w  .  j a va  2s  .  c  o m

    assertThat(source.znode, is("/path/node/my-app"));
    assertThat(source.quorum.length, is(1));
    assertThat(source.quorum[0], is("QUORUM"));
}

From source file:org.lable.oss.dynamicconfig.provider.zookeeper.ZookeepersAsConfigSourceTest.java

@Test
public void testConstructorWithAppNameAndQuorumList() throws ConfigurationException {
    ZookeepersAsConfigSource source = new ZookeepersAsConfigSource();
    Configuration config = new BaseConfiguration();
    config.setProperty("quorum", "zk1,zk2");
    config.setProperty("znode", "/path");
    config.setProperty(ConfigurationInitializer.APPNAME_PROPERTY, "node");
    source.configure(config);/*w  w  w  .  j  av a2 s.  c  o  m*/

    assertThat(source.znode, is("/path/node"));
    assertThat(source.quorum.length, is(2));
    assertThat(source.quorum[0], is("zk1"));
    assertThat(source.quorum[1], is("zk2"));
}

From source file:org.lable.oss.dynamicconfig.provider.zookeeper.ZookeepersAsConfigSourceTest.java

@Test(expected = ConfigurationException.class)
public void testConstructorNoAppName() throws ConfigurationException {
    ZookeepersAsConfigSource source = new ZookeepersAsConfigSource();
    Configuration config = new BaseConfiguration();
    config.setProperty("quorum", "QUORUM");
    config.setProperty("znode", "/path/node");
    source.configure(config);/*from   w w w .j a v  a  2  s  .c om*/
}

From source file:org.loggo.server.Server.java

void initialize(HierarchicalINIConfiguration config)
        throws ConfigurationException, AccumuloException, AccumuloSecurityException {
    Configuration kafkaConsumerSection = config.getSection("KafkaConsumer");
    Configuration serverSection = config.getSection("server");
    Configuration accumuloSection = config.getSection("accumulo");
    Configuration batchSection = config.getSection("batchwriter");
    Configuration kafkaSection = config.getSection("kafka");
    ClientConfiguration clientConfig = new ClientConfiguration(accumuloSection);

    // connect to accumulo, check on the table
    String username = batchSection.getString("user", Defaults.USER);
    String password = batchSection.getString("password", Defaults.PASSWORD);
    String table = batchSection.getString("table", Defaults.TABLE);
    Instance instance = new ZooKeeperInstance(clientConfig);
    Connector connector = instance.getConnector(username, new PasswordToken(password.getBytes()));
    if (!connector.tableOperations().exists(table)) {
        createTable(connector, table);//from   www . j a v  a  2 s . c o m
    }
    createTopic(kafkaConsumerSection.getString("zookeeper.connect"), kafkaSection);

    LinkedBlockingDeque<LogEntry> queue = new LinkedBlockingDeque<LogEntry>(
            config.getInt("queue.size", Defaults.QUEUE_SIZE));
    this.writer = new Writer(queue, clientConfig, batchSection);

    ServerBootstrap b = new ServerBootstrap();
    // @formatter:off

    // tcp
    b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
            .handler(new LoggingHandler(LogLevel.INFO)).childHandler(new LoggerReaderInitializer(queue));

    // udp
    Bootstrap bb = new Bootstrap();
    bb.group(dgramGroup).channel(NioDatagramChannel.class).handler(new DgramHandler(queue));

    // @formatter:on
    String host = serverSection.getString("host", Defaults.HOST);
    serverSection.setProperty("host", host);
    if (host.equals(Defaults.HOST)) {
        try {
            serverSection.setProperty("host", InetAddress.getLocalHost().getHostName());
        } catch (UnknownHostException ex) {
            throw new RuntimeException("Unable to determine local hostname: " + ex.toString());
        }
    }
    try {
        int tcpPort = serverSection.getInteger("tcp.port", Defaults.PORT);
        channel = b.bind(host, tcpPort).sync().channel();
        tcpPort = ((InetSocketAddress) channel.localAddress()).getPort();
        serverSection.setProperty("tcp.port", tcpPort);

        int udpPort = serverSection.getInteger("udp.port", Defaults.PORT);
        Channel channel2 = bb.bind(host, udpPort).sync().channel();
        udpPort = ((InetSocketAddress) channel2.localAddress()).getPort();
        serverSection.setProperty("udp.port", udpPort);

        registerInZookeeper(serverSection);
    } catch (IOException | KeeperException | InterruptedException ex) {
        throw new RuntimeException(ex);
    }
    String zookeeperConnect = kafkaConsumerSection.getString("zookeeper.connect");
    if (zookeeperConnect != null) {
        kafkaConsumer = new KafkaConsumer();
        kafkaConsumer.initialize(config, queue);
        kafkaConsumer.start();
    }
}

From source file:org.lrodero.blueprintstests.TestDistributed.java

protected static Graph createRemoteTitanCassandraGraph(String cassandraHostName, int cassandraPort) {
    logger.info("Creating remote Titan database configuration (using Cassandra for storage)");
    Configuration conf = new BaseConfiguration();
    conf.setProperty("storage.backend", "cassandra");
    conf.setProperty("storage.hostname", cassandraHostName);
    conf.setProperty("storage.port", cassandraPort);
    logger.info("Creating remote Titan database instance (using Cassandra for storage)");
    return TitanFactory.open(conf);
}

From source file:org.lrodero.blueprintstests.TestDistributed.java

protected static Graph createRemoteOrientDBGraph(String orientdbHostName, int orientdbPort, String dbName,
        String userName, String password) {
    logger.info("Creating remote OrientDB database configuration");
    Configuration conf = new BaseConfiguration();
    conf.setProperty("blueprints.graph", "com.tinkerpop.blueprints.impls.orient.OrientGraph");
    conf.setProperty("blueprints.orientdb.url",
            "remote:" + orientdbHostName + ":" + orientdbPort + "/" + dbName);
    conf.setProperty("blueprints.orientdb.username", userName); // In fact we should use the 'guest' user for security, but anyway
    conf.setProperty("blueprints.orientdb.password", password); // Extracted from <users> tag in config/orientdb-server-config.xml)
    logger.info("Creating remote OrientDB database instance");
    return GraphFactory.open(conf);
}