Search in sources :

Example 1 with MapConfiguration

use of org.apache.commons.configuration2.MapConfiguration in project bitflyer4j by after-the-sunrise.

the class KeyTypeTest method test.

@Test
public void test() throws ConfigurationException {
    // Null input.  (= Default value.)
    assertEquals(VERSION.fetch(null), VERSION.getDefaultValue());
    // Not found. (= Default value.)
    Configuration conf = new MapConfiguration(new HashMap<>());
    assertEquals(VERSION.fetch(conf), VERSION.getDefaultValue());
    // Retrieved from properties. (Empty)
    conf.setProperty(VERSION.getKey(), "");
    assertNull(VERSION.fetch(conf));
    // Retrieved from properties. (Configured)
    conf.setProperty(VERSION.getKey(), "test");
    assertEquals(VERSION.fetch(conf), "test");
}
Also used : MapConfiguration(org.apache.commons.configuration2.MapConfiguration) Configuration(org.apache.commons.configuration2.Configuration) MapConfiguration(org.apache.commons.configuration2.MapConfiguration) Test(org.testng.annotations.Test)

Example 2 with MapConfiguration

use of org.apache.commons.configuration2.MapConfiguration in project bitflyer4j by after-the-sunrise.

the class EnvironmentImplTest method setUp.

@BeforeMethod
public void setUp() throws Exception {
    conf = new MapConfiguration(new HashMap<>());
    target = new EnvironmentImpl(conf, conf);
}
Also used : HashMap(java.util.HashMap) MapConfiguration(org.apache.commons.configuration2.MapConfiguration) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 3 with MapConfiguration

use of org.apache.commons.configuration2.MapConfiguration in project janusgraph by JanusGraph.

the class ConfiguredGraphFactory method create.

/**
 * Creates a {@link JanusGraph} configuration stored in the {@link ConfigurationManagementGraph}
 * graph and a {@link JanusGraph} graph reference according to the single
 * Template Configuration  previously created by the {@link ConfigurationManagementGraph} API;
 * A configuration for this graph must not already exist, and a Template Configuration must
 * exist. If the Template Configuration does not include its
 * backend's respective keyspace/table/storage_directory parameter, we set the keyspace/table
 * to the supplied graphName or we append the graphName to the supplied
 * storage_root parameter.
 *
 * @param graphName
 *
 * @return JanusGraph
 */
public static synchronized JanusGraph create(final String graphName) {
    final ConfigurationManagementGraph configManagementGraph = getConfigGraphManagementInstance();
    final Map<String, Object> graphConfigMap = configManagementGraph.getConfiguration(graphName);
    Preconditions.checkState(null == graphConfigMap, String.format("Configuration for graph %s already exists.", graphName));
    final Map<String, Object> templateConfigMap = configManagementGraph.getTemplateConfiguration();
    Preconditions.checkNotNull(templateConfigMap, "Please create a template Configuration using the ConfigurationManagementGraph#createTemplateConfiguration API.");
    templateConfigMap.put(ConfigurationManagementGraph.PROPERTY_GRAPH_NAME, graphName);
    templateConfigMap.put(ConfigurationManagementGraph.PROPERTY_CREATED_USING_TEMPLATE, true);
    final JanusGraphManager jgm = JanusGraphManagerUtility.getInstance();
    Preconditions.checkNotNull(jgm, JANUS_GRAPH_MANAGER_EXPECTED_STATE_MSG);
    final CommonsConfiguration config = new CommonsConfiguration(ConfigurationUtil.loadMapConfiguration(templateConfigMap));
    final JanusGraph g = (JanusGraph) jgm.openGraph(graphName, (String gName) -> new StandardJanusGraph(new GraphDatabaseConfigurationBuilder().build(config)));
    configManagementGraph.createConfiguration(new MapConfiguration(templateConfigMap));
    return g;
}
Also used : GraphDatabaseConfigurationBuilder(org.janusgraph.graphdb.configuration.builder.GraphDatabaseConfigurationBuilder) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) MapConfiguration(org.apache.commons.configuration2.MapConfiguration) JanusGraphManager(org.janusgraph.graphdb.management.JanusGraphManager) CommonsConfiguration(org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration) ConfigurationManagementGraph(org.janusgraph.graphdb.management.ConfigurationManagementGraph) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph)

Example 4 with MapConfiguration

use of org.apache.commons.configuration2.MapConfiguration in project janusgraph by JanusGraph.

the class ConfigurationUtil method loadMapConfiguration.

/**
 * Load properties from a map object and return a MapConfiguration object. Comma-delimited values are interpreted as
 * a list of values.
 * @param configMap
 * @return
 */
public static MapConfiguration loadMapConfiguration(Map<String, Object> configMap) {
    final MapConfiguration mapConfiguration = new MapConfiguration(configMap);
    mapConfiguration.setListDelimiterHandler(COMMA_DELIMITER_HANDLER);
    return mapConfiguration;
}
Also used : MapConfiguration(org.apache.commons.configuration2.MapConfiguration)

Example 5 with MapConfiguration

use of org.apache.commons.configuration2.MapConfiguration in project janusgraph by JanusGraph.

the class CQLConfiguredGraphFactoryTest method createConfigurationShouldSupportMultiHosts.

@Test
public void createConfigurationShouldSupportMultiHosts() throws Exception {
    final MapConfiguration graphConfig = getGraphConfigWithMultiHosts();
    final String graphName = graphConfig.getString(GRAPH_NAME.toStringWithoutRoot());
    try {
        ConfiguredGraphFactory.createConfiguration(graphConfig);
        final StandardJanusGraph graph = (StandardJanusGraph) ConfiguredGraphFactory.open(graphName);
        assertNotNull(graph);
    } finally {
        ConfiguredGraphFactory.removeConfiguration(graphName);
        ConfiguredGraphFactory.close(graphName);
    }
}
Also used : MapConfiguration(org.apache.commons.configuration2.MapConfiguration) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) Test(org.junit.jupiter.api.Test) AbstractConfiguredGraphFactoryTest(org.janusgraph.core.AbstractConfiguredGraphFactoryTest)

Aggregations

MapConfiguration (org.apache.commons.configuration2.MapConfiguration)33 StandardJanusGraph (org.janusgraph.graphdb.database.StandardJanusGraph)25 Test (org.junit.jupiter.api.Test)25 CommonsConfiguration (org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration)16 GraphDatabaseConfigurationBuilder (org.janusgraph.graphdb.configuration.builder.GraphDatabaseConfigurationBuilder)16 HashMap (java.util.HashMap)5 JanusGraphManager (org.janusgraph.graphdb.management.JanusGraphManager)3 Configuration (org.apache.commons.configuration2.Configuration)2 Settings (org.apache.tinkerpop.gremlin.server.Settings)2 AbstractConfiguredGraphFactoryTest (org.janusgraph.core.AbstractConfiguredGraphFactoryTest)2 ManagementSystem (org.janusgraph.graphdb.database.management.ManagementSystem)2 ConfigurationManagementGraph (org.janusgraph.graphdb.management.ConfigurationManagementGraph)2 Test (org.testng.annotations.Test)2 Session (com.datastax.driver.core.Session)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Bindings (javax.script.Bindings)1 SimpleBindings (javax.script.SimpleBindings)1 CompositeConfiguration (org.apache.commons.configuration2.CompositeConfiguration)1 JanusGraphException (org.janusgraph.core.JanusGraphException)1 PropertyKey (org.janusgraph.core.PropertyKey)1