Example usage for org.apache.commons.configuration BaseConfiguration BaseConfiguration

List of usage examples for org.apache.commons.configuration BaseConfiguration BaseConfiguration

Introduction

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

Prototype

BaseConfiguration

Source Link

Usage

From source file:org.janusgraph.diskstorage.configuration.CommonConfigTest.java

@Test
public void testDateParsing() {
    BaseConfiguration base = new BaseConfiguration();
    CommonsConfiguration config = new CommonsConfiguration(base);

    for (ChronoUnit unit : Arrays.asList(ChronoUnit.NANOS, ChronoUnit.MICROS, ChronoUnit.MILLIS,
            ChronoUnit.SECONDS, ChronoUnit.MINUTES, ChronoUnit.HOURS, ChronoUnit.DAYS)) {
        base.setProperty("test", "100 " + unit.toString());
        Duration d = config.get("test", Duration.class);
        assertEquals(TimeUnit.NANOSECONDS.convert(100, Temporals.timeUnit(unit)), d.toNanos());
    }/*from   w w w  .j  av  a2 s  .  c  o m*/

    Map<ChronoUnit, String> mapping = ImmutableMap.of(ChronoUnit.MICROS, "us", ChronoUnit.DAYS, "d");
    for (Map.Entry<ChronoUnit, String> entry : mapping.entrySet()) {
        base.setProperty("test", "100 " + entry.getValue());
        Duration d = config.get("test", Duration.class);
        assertEquals(TimeUnit.NANOSECONDS.convert(100, Temporals.timeUnit(entry.getKey())), d.toNanos());
    }

}

From source file:org.janusgraph.diskstorage.configuration.ConfigurationTest.java

@Test
public void testConfigHierarchy() {
    ConfigNamespace root = new ConfigNamespace(null, "config", "root");
    ConfigNamespace indexes = new ConfigNamespace(root, "indexes", "Index definitions", true);
    ConfigNamespace storage = new ConfigNamespace(root, "storage", "Storage definitions");
    ConfigNamespace special = new ConfigNamespace(storage, "special", "Special storage definitions");
    ConfigOption<String[]> hostnames = new ConfigOption<String[]>(storage, "hostname",
            "Storage backend hostname", ConfigOption.Type.LOCAL, String[].class);
    ConfigOption<Boolean> partition = new ConfigOption<Boolean>(storage, "partition",
            "whether to enable partition", ConfigOption.Type.MASKABLE, false);
    ConfigOption<Long> locktime = new ConfigOption<Long>(storage, "locktime", "how long to lock",
            ConfigOption.Type.FIXED, 500l);
    ConfigOption<Byte> bits = new ConfigOption<Byte>(storage, "bits", "number of unique bits",
            ConfigOption.Type.GLOBAL_OFFLINE, (byte) 8);
    ConfigOption<Short> retry = new ConfigOption<Short>(special, "retry", "retry wait time",
            ConfigOption.Type.GLOBAL, (short) 200);
    ConfigOption<Double> bar = new ConfigOption<Double>(special, "bar", "bar", ConfigOption.Type.GLOBAL, 1.5d);
    ConfigOption<Integer> bim = new ConfigOption<Integer>(special, "bim", "bim", ConfigOption.Type.MASKABLE,
            Integer.class);

    ConfigOption<String> indexback = new ConfigOption<String>(indexes, "name", "index name",
            ConfigOption.Type.MASKABLE, String.class);
    ConfigOption<Integer> ping = new ConfigOption<Integer>(indexes, "ping", "ping time",
            ConfigOption.Type.LOCAL, 100);
    ConfigOption<Boolean> presort = new ConfigOption<Boolean>(indexes, "presort", "presort result set",
            ConfigOption.Type.LOCAL, false);

    //Local configuration
    ModifiableConfiguration config = new ModifiableConfiguration(root,
            new CommonsConfiguration(new BaseConfiguration()), BasicConfiguration.Restriction.LOCAL);
    UserModifiableConfiguration userconfig = new UserModifiableConfiguration(config);
    assertFalse(config.get(partition));/*  w ww . ja  v a2 s  . c  om*/
    assertEquals("false", userconfig.get("storage.partition"));
    userconfig.set("storage.partition", true);
    assertEquals("true", userconfig.get("storage.partition"));
    userconfig.set("storage.hostname", new String[] { "localhost", "some.where.org" });
    assertEquals("[localhost,some.where.org]", userconfig.get("storage.hostname"));
    userconfig.set("storage.hostname", "localhost");
    assertEquals("[localhost]", userconfig.get("storage.hostname"));
    assertEquals("null", userconfig.get("storage.special.bim"));
    assertEquals("", userconfig.get("indexes"));
    userconfig.set("indexes.search.name", "foo");
    assertEquals("+ search", userconfig.get("indexes").trim());
    assertEquals("foo", userconfig.get("indexes.search.name"));
    assertEquals("100", userconfig.get("indexes.search.ping"));
    userconfig.set("indexes.search.ping", 400l);
    assertEquals("400", userconfig.get("indexes.search.ping"));
    assertFalse(config.isFrozen());
    try {
        userconfig.set("storage.locktime", 500);
        fail();
    } catch (IllegalArgumentException e) {
    }
    try {
        config.set(retry, (short) 100);
        fail();
    } catch (IllegalArgumentException e) {
    }
    //        System.out.println(userconfig.get("storage"));
    userconfig.close();
    ReadConfiguration localConfig = userconfig.getConfiguration();

    config = new ModifiableConfiguration(root, new CommonsConfiguration(new BaseConfiguration()),
            BasicConfiguration.Restriction.GLOBAL);
    userconfig = new UserModifiableConfiguration(config);

    userconfig.set("storage.locktime", 1111);
    userconfig.set("storage.bits", 5);
    userconfig.set("storage.special.retry", 222);
    assertEquals("5", userconfig.get("storage.bits"));
    assertEquals("222", userconfig.get("storage.special.retry"));

    config.freezeConfiguration();
    userconfig.set("storage.special.retry", 333);
    assertEquals("333", userconfig.get("storage.special.retry"));
    try {
        userconfig.set("storage.bits", 6);
    } catch (IllegalArgumentException e) {
    }
    userconfig.set("storage.bits", 6);
    try {
        userconfig.set("storage.locktime", 1221);
    } catch (IllegalArgumentException e) {
    }
    try {
        userconfig.set("storage.locktime", 1221);
    } catch (IllegalArgumentException e) {
    }
    userconfig.set("indexes.find.name", "lulu");

    userconfig.close();
    ReadConfiguration globalConfig = userconfig.getConfiguration();

    MixedConfiguration mixed = new MixedConfiguration(root, globalConfig, localConfig);
    assertEquals(ImmutableSet.of("search", "find"), mixed.getContainedNamespaces(indexes));
    Configuration search = mixed.restrictTo("search");
    assertEquals("foo", search.get(indexback));
    assertEquals(400, search.get(ping).intValue());
    assertEquals(100, mixed.get(ping, "find").intValue());
    assertEquals(false, mixed.get(presort, "find").booleanValue());
    assertEquals(400, mixed.get(ping, "search").intValue());
    assertEquals(false, mixed.get(presort, "search").booleanValue());
    assertFalse(mixed.has(bim));
    assertTrue(mixed.has(bits));
    assertEquals(5, mixed.getSubset(storage).size());

    assertEquals(1.5d, mixed.get(bar).doubleValue(), 0.0);
    assertEquals("localhost", mixed.get(hostnames)[0]);
    assertEquals(1111, mixed.get(locktime).longValue());

    mixed.close();

    //System.out.println(ConfigElement.toString(root));

}

From source file:org.janusgraph.diskstorage.configuration.converter.ReadConfigurationConverter.java

public BaseConfiguration convert(ReadConfiguration readConfiguration) {
    BaseConfiguration result = new BaseConfiguration();
    for (String k : readConfiguration.getKeys("")) {
        result.setProperty(k, readConfiguration.get(k, Object.class));
    }//  www. j av  a2 s.  c  o  m
    return result;
}

From source file:org.janusgraph.diskstorage.es.ElasticSearchConfigTest.java

@Test
public void testLocalNodeUsingExt() throws BackendException, InterruptedException {

    String baseDir = Joiner.on(File.separator).join("target", "es", "jvmlocal_ext");

    assertFalse(new File(baseDir + File.separator + "data").exists());

    CommonsConfiguration cc = new CommonsConfiguration(new BaseConfiguration());
    cc.set("index." + INDEX_NAME + ".elasticsearch.ext.node.data", "true");
    cc.set("index." + INDEX_NAME + ".elasticsearch.ext.node.client", "false");
    cc.set("index." + INDEX_NAME + ".elasticsearch.ext.node.local", "true");
    cc.set("index." + INDEX_NAME + ".elasticsearch.ext.path.data", baseDir + File.separator + "data");
    cc.set("index." + INDEX_NAME + ".elasticsearch.ext.path.work", baseDir + File.separator + "work");
    cc.set("index." + INDEX_NAME + ".elasticsearch.ext.path.logs", baseDir + File.separator + "logs");
    ModifiableConfiguration config = new ModifiableConfiguration(GraphDatabaseConfiguration.ROOT_NS, cc,
            BasicConfiguration.Restriction.NONE);
    config.set(INTERFACE, ElasticSearchSetup.NODE.toString(), INDEX_NAME);
    Configuration indexConfig = config.restrictTo(INDEX_NAME);
    IndexProvider idx = new ElasticSearchIndex(indexConfig);
    simpleWriteAndQuery(idx);//from   w  w w .  ja  va  2 s.com
    idx.close();

    assertTrue(new File(baseDir + File.separator + "data").exists());
}

From source file:org.janusgraph.diskstorage.es.ElasticSearchConfigTest.java

@Test
public void testLocalNodeUsingExtAndIndexDirectory() throws BackendException, InterruptedException {

    String baseDir = Joiner.on(File.separator).join("target", "es", "jvmlocal_ext2");

    assertFalse(new File(baseDir + File.separator + "data").exists());

    CommonsConfiguration cc = new CommonsConfiguration(new BaseConfiguration());
    cc.set("index." + INDEX_NAME + ".elasticsearch.ext.node.data", "true");
    cc.set("index." + INDEX_NAME + ".elasticsearch.ext.node.client", "false");
    cc.set("index." + INDEX_NAME + ".elasticsearch.ext.node.local", "true");
    ModifiableConfiguration config = new ModifiableConfiguration(GraphDatabaseConfiguration.ROOT_NS, cc,
            BasicConfiguration.Restriction.NONE);
    config.set(INTERFACE, ElasticSearchSetup.NODE.toString(), INDEX_NAME);
    config.set(INDEX_DIRECTORY, baseDir, INDEX_NAME);
    Configuration indexConfig = config.restrictTo(INDEX_NAME);
    IndexProvider idx = new ElasticSearchIndex(indexConfig);
    simpleWriteAndQuery(idx);//  w  w w  . j a v a 2 s  .  c  om
    idx.close();

    assertTrue(new File(baseDir + File.separator + "data").exists());
}

From source file:org.janusgraph.diskstorage.es.ElasticSearchConfigTest.java

@Test
public void testNetworkNodeUsingExt() throws BackendException, InterruptedException {
    ElasticsearchRunner esr = new ElasticsearchRunner(".", "networkNodeUsingExt.yml");
    esr.start();/*  ww  w  .  java 2s.co m*/
    CommonsConfiguration cc = new CommonsConfiguration(new BaseConfiguration());
    cc.set("index." + INDEX_NAME + ".elasticsearch.ext.node.data", "false");
    cc.set("index." + INDEX_NAME + ".elasticsearch.ext.node.client", "true");
    cc.set("index." + INDEX_NAME + ".elasticsearch.ext.cluster.name", "networkNodeUsingExt");
    cc.set("index." + INDEX_NAME + ".elasticsearch.ext.discovery.zen.ping.multicast.enabled", "false");
    cc.set("index." + INDEX_NAME + ".elasticsearch.ext.discovery.zen.ping.unicast.hosts",
            "localhost,127.0.0.1:9300");
    ModifiableConfiguration config = new ModifiableConfiguration(GraphDatabaseConfiguration.ROOT_NS, cc,
            BasicConfiguration.Restriction.NONE);
    config.set(INTERFACE, ElasticSearchSetup.NODE.toString(), INDEX_NAME);
    Configuration indexConfig = config.restrictTo(INDEX_NAME);
    IndexProvider idx = new ElasticSearchIndex(indexConfig);
    simpleWriteAndQuery(idx);
    idx.close();

    cc.set("index." + INDEX_NAME + ".elasticsearch.ext.discovery.zen.ping.unicast.hosts", "10.11.12.13");
    config = new ModifiableConfiguration(GraphDatabaseConfiguration.ROOT_NS, cc,
            BasicConfiguration.Restriction.NONE);
    config.set(INTERFACE, ElasticSearchSetup.NODE.toString(), INDEX_NAME);
    config.set(HEALTH_REQUEST_TIMEOUT, "5s", INDEX_NAME);
    indexConfig = config.restrictTo(INDEX_NAME);

    Throwable failure = null;
    try {
        idx = new ElasticSearchIndex(indexConfig);
    } catch (Throwable t) {
        failure = t;
    }
    // idx.close();
    Assert.assertNotNull("ES client failed to throw exception on connection failure", failure);
    esr.stop();
}

From source file:org.janusgraph.diskstorage.es.ElasticSearchConfigTest.java

@Test
public void testIndexCreationOptions() throws InterruptedException, BackendException {
    final int shards = 77;

    ElasticsearchRunner esr = new ElasticsearchRunner(".", "indexCreationOptions.yml");
    esr.start();//from w  w w.  j  a va  2 s .  c o  m
    CommonsConfiguration cc = new CommonsConfiguration(new BaseConfiguration());
    cc.set("index." + INDEX_NAME + ".elasticsearch.create.ext.number_of_shards", String.valueOf(shards));
    cc.set("index." + INDEX_NAME + ".elasticsearch.ext.cluster.name", "indexCreationOptions");
    ModifiableConfiguration config = new ModifiableConfiguration(GraphDatabaseConfiguration.ROOT_NS, cc,
            BasicConfiguration.Restriction.NONE);
    config.set(INTERFACE, ElasticSearchSetup.NODE.toString(), INDEX_NAME);
    Configuration indexConfig = config.restrictTo(INDEX_NAME);
    IndexProvider idx = new ElasticSearchIndex(indexConfig);
    simpleWriteAndQuery(idx);

    ImmutableSettings.Builder settingsBuilder = ImmutableSettings.settingsBuilder();
    settingsBuilder.put("discovery.zen.ping.multicast.enabled", "false");
    settingsBuilder.put("discovery.zen.ping.unicast.hosts", "localhost,127.0.0.1:9300");
    settingsBuilder.put("cluster.name", "indexCreationOptions");
    NodeBuilder nodeBuilder = NodeBuilder.nodeBuilder().settings(settingsBuilder.build());
    nodeBuilder.client(true).data(false).local(false);
    Node n = nodeBuilder.build().start();

    GetSettingsResponse response = n.client().admin().indices()
            .getSettings(new GetSettingsRequest().indices("janusgraph")).actionGet();
    assertEquals(String.valueOf(shards), response.getSetting("janusgraph", "index.number_of_shards"));

    idx.close();
    n.stop();
    esr.stop();
}

From source file:org.janusgraph.diskstorage.es.ElasticSearchIndexTest.java

public Configuration getESTestConfig() {
    final String index = "es";
    final CommonsConfiguration cc = new CommonsConfiguration(new BaseConfiguration());
    if (esr.getEsMajorVersion().value > 2) {
        cc.set("index." + index + ".elasticsearch.ingest-pipeline.ingestvertex", "pipeline_1");
    }//from   w  w w  .  ja v  a 2  s.  c o m
    return esr
            .setElasticsearchConfiguration(new ModifiableConfiguration(GraphDatabaseConfiguration.ROOT_NS, cc,
                    BasicConfiguration.Restriction.NONE), index)
            .set(GraphDatabaseConfiguration.INDEX_MAX_RESULT_SET_SIZE, 3, index).restrictTo(index);
}

From source file:org.janusgraph.diskstorage.es.ElasticSearchMultiTypeIndexTest.java

public Configuration getESTestConfig() {
    final String index = "es";
    final CommonsConfiguration cc = new CommonsConfiguration(new BaseConfiguration());
    if (esr.getEsMajorVersion().value > 2) {
        cc.set("index." + index + ".elasticsearch.ingest-pipeline.ingestvertex", "pipeline_1");
    }//www .  ja  v a2  s .com
    final ModifiableConfiguration config = esr.setElasticsearchConfiguration(new ModifiableConfiguration(
            GraphDatabaseConfiguration.ROOT_NS, cc, BasicConfiguration.Restriction.NONE), index);
    config.set(USE_DEPRECATED_MULTITYPE_INDEX, true, index);
    config.set(GraphDatabaseConfiguration.INDEX_MAX_RESULT_SET_SIZE, 3, index);
    return config.restrictTo(index);
}

From source file:org.janusgraph.diskstorage.es.rest.RestClientSetupTest.java

private ElasticSearchClient baseConfigTest(Map<String, String> extraConfigValues) throws Exception {
    final CommonsConfiguration cc = new CommonsConfiguration(new BaseConfiguration());
    cc.set("index." + INDEX_NAME + ".backend", "elasticsearch");
    cc.set("index." + INDEX_NAME + ".elasticsearch.interface", "REST_CLIENT");
    for (Map.Entry<String, String> me : extraConfigValues.entrySet()) {
        cc.set(me.getKey(), me.getValue());
    }/*from  ww w  . ja v a 2 s.  co  m*/

    final ModifiableConfiguration config = new ModifiableConfiguration(GraphDatabaseConfiguration.ROOT_NS, cc,
            BasicConfiguration.Restriction.NONE);

    doReturn(restClientBuilderMock).when(restClientSetup).getRestClientBuilder(any());
    doReturn(restElasticSearchClientMock).when(restClientSetup).getElasticSearchClient(any(RestClient.class),
            anyInt());

    return restClientSetup.connect(config.restrictTo(INDEX_NAME));
}