Search in sources :

Example 6 with CommonsConfiguration

use of org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration in project janusgraph by JanusGraph.

the class ConfigurationTest method testConfigHierarchy.

@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<>(storage, "hostname", "Storage backend hostname", ConfigOption.Type.LOCAL, String[].class);
    ConfigOption<Boolean> partition = new ConfigOption<>(storage, "partition", "whether to enable partition", ConfigOption.Type.MASKABLE, false);
    ConfigOption<Long> locktime = new ConfigOption<>(storage, "locktime", "how long to lock", ConfigOption.Type.FIXED, 500L);
    ConfigOption<Byte> bits = new ConfigOption<>(storage, "bits", "number of unique bits", ConfigOption.Type.GLOBAL_OFFLINE, (byte) 8);
    ConfigOption<Short> retry = new ConfigOption<>(special, "retry", "retry wait time", ConfigOption.Type.GLOBAL, (short) 200);
    ConfigOption<Double> bar = new ConfigOption<>(special, "bar", "bar", ConfigOption.Type.GLOBAL, 1.5d);
    ConfigOption<Integer> bim = new ConfigOption<>(special, "bim", "bim", ConfigOption.Type.MASKABLE, Integer.class);
    ConfigOption<String> indexback = new ConfigOption<>(indexes, "name", "index name", ConfigOption.Type.MASKABLE, String.class);
    ConfigOption<Integer> ping = new ConfigOption<>(indexes, "ping", "ping time", ConfigOption.Type.LOCAL, 100);
    ConfigOption<Boolean> presort = new ConfigOption<>(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));
    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 ignored) {
    }
    try {
        config.set(retry, (short) 100);
        fail();
    } catch (IllegalArgumentException ignored) {
    }
    // 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 ignored) {
    }
    userconfig.set("storage.bits", 6);
    try {
        userconfig.set("storage.locktime", 1221);
    } catch (IllegalArgumentException ignored) {
    }
    try {
        userconfig.set("storage.locktime", 1221);
    } catch (IllegalArgumentException ignored) {
    }
    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"));
    assertEquals(400, mixed.get(ping, "search").intValue());
    assertEquals(false, mixed.get(presort, "search"));
    assertFalse(mixed.has(bim));
    assertTrue(mixed.has(bits));
    assertEquals(5, mixed.getSubset(storage).size());
    assertEquals(1.5d, mixed.get(bar), 0.0);
    assertEquals("localhost", mixed.get(hostnames)[0]);
    assertEquals(1111, mixed.get(locktime).longValue());
    mixed.close();
// System.out.println(ConfigElement.toString(root));
}
Also used : GraphDatabaseConfiguration(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration) CommonsConfiguration(org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration) BaseConfiguration(org.apache.commons.configuration.BaseConfiguration) CommonsConfiguration(org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration) BaseConfiguration(org.apache.commons.configuration.BaseConfiguration) Test(org.junit.Test)

Example 7 with CommonsConfiguration

use of org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration in project janusgraph by JanusGraph.

the class CommonConfigTest method testDateParsing.

@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());
    }
    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());
    }
}
Also used : BaseConfiguration(org.apache.commons.configuration.BaseConfiguration) CommonsConfiguration(org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration) Duration(java.time.Duration) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) ChronoUnit(java.time.temporal.ChronoUnit) Test(org.junit.Test)

Example 8 with CommonsConfiguration

use of org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration in project janusgraph by JanusGraph.

the class GraphDatabaseConfigurationInstanceIdTest method instanceIdShouldEqualHostnamePlusSuffix.

@Test
public void instanceIdShouldEqualHostnamePlusSuffix() throws UnknownHostException {
    final Map<String, Object> map = new HashMap<String, Object>();
    map.put(STORAGE_BACKEND.toStringWithoutRoot(), "inmemory");
    map.put(UNIQUE_INSTANCE_ID_HOSTNAME.toStringWithoutRoot(), true);
    map.put(UNIQUE_INSTANCE_ID_SUFFIX.toStringWithoutRoot(), 1);
    final MapConfiguration config = new MapConfiguration(map);
    final StandardJanusGraph graph = new StandardJanusGraph(new GraphDatabaseConfiguration(new CommonsConfiguration(config)));
    assertEquals(graph.openManagement().getOpenInstances().size(), 1);
    assertEquals(graph.openManagement().getOpenInstances().toArray()[0], Inet4Address.getLocalHost().getHostName() + "1");
    graph.close();
}
Also used : HashMap(java.util.HashMap) MapConfiguration(org.apache.commons.configuration.MapConfiguration) GraphDatabaseConfiguration(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration) CommonsConfiguration(org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) Test(org.junit.Test)

Example 9 with CommonsConfiguration

use of org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration in project janusgraph by JanusGraph.

the class GraphDatabaseConfigurationInstanceIdTest method instanceIdShouldEqualHostname.

@Test
public void instanceIdShouldEqualHostname() throws UnknownHostException {
    final Map<String, Object> map = new HashMap<String, Object>();
    map.put(STORAGE_BACKEND.toStringWithoutRoot(), "inmemory");
    map.put(UNIQUE_INSTANCE_ID_HOSTNAME.toStringWithoutRoot(), true);
    final MapConfiguration config = new MapConfiguration(map);
    final StandardJanusGraph graph = new StandardJanusGraph(new GraphDatabaseConfiguration(new CommonsConfiguration(config)));
    assertEquals(graph.openManagement().getOpenInstances().size(), 1);
    assertEquals(graph.openManagement().getOpenInstances().toArray()[0], Inet4Address.getLocalHost().getHostName());
    graph.close();
}
Also used : HashMap(java.util.HashMap) MapConfiguration(org.apache.commons.configuration.MapConfiguration) GraphDatabaseConfiguration(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration) CommonsConfiguration(org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) Test(org.junit.Test)

Example 10 with CommonsConfiguration

use of org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration in project janusgraph by JanusGraph.

the class ManagementLoggerGraphCacheEvictionTest method shouldNotBeAbleToEvictGraphWhenJanusGraphManagerIsNull.

@Test
public void shouldNotBeAbleToEvictGraphWhenJanusGraphManagerIsNull() {
    final Map<String, Object> map = new HashMap<>();
    map.put(STORAGE_BACKEND.toStringWithoutRoot(), "inmemory");
    final MapConfiguration config = new MapConfiguration(map);
    final StandardJanusGraph graph = new StandardJanusGraph(new GraphDatabaseConfiguration(new CommonsConfiguration(config)));
    final ManagementSystem mgmt = (ManagementSystem) graph.openManagement();
    mgmt.evictGraphFromCache();
    mgmt.commit();
    assertNull(JanusGraphManager.getInstance());
}
Also used : ManagementSystem(org.janusgraph.graphdb.database.management.ManagementSystem) HashMap(java.util.HashMap) MapConfiguration(org.apache.commons.configuration.MapConfiguration) GraphDatabaseConfiguration(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration) CommonsConfiguration(org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) Test(org.junit.Test)

Aggregations

CommonsConfiguration (org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration)20 GraphDatabaseConfiguration (org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration)10 BaseConfiguration (org.apache.commons.configuration.BaseConfiguration)9 StandardJanusGraph (org.janusgraph.graphdb.database.StandardJanusGraph)9 Test (org.junit.Test)9 MapConfiguration (org.apache.commons.configuration.MapConfiguration)8 HashMap (java.util.HashMap)7 ModifiableConfiguration (org.janusgraph.diskstorage.configuration.ModifiableConfiguration)6 ImmutableMap (com.google.common.collect.ImmutableMap)2 File (java.io.File)2 IOException (java.io.IOException)2 Map (java.util.Map)2 ConfigurationException (org.apache.commons.configuration.ConfigurationException)2 PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)2 BasicConfiguration (org.janusgraph.diskstorage.configuration.BasicConfiguration)2 ManagementSystem (org.janusgraph.graphdb.database.management.ManagementSystem)2 ConfigurationManagementGraph (org.janusgraph.graphdb.management.ConfigurationManagementGraph)2 JanusGraphManager (org.janusgraph.graphdb.management.JanusGraphManager)2 FileInputStream (java.io.FileInputStream)1 Duration (java.time.Duration)1