Search in sources :

Example 6 with MapConfiguration

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

the class AbstractConfiguredGraphFactoryTest method shouldFailToOpenGraphAfterRemoveConfiguration.

@Test
public void shouldFailToOpenGraphAfterRemoveConfiguration() {
    final MapConfiguration graphConfig = getGraphConfig();
    final String graphName = graphConfig.getString(GRAPH_NAME.toStringWithoutRoot());
    ConfiguredGraphFactory.createConfiguration(graphConfig);
    ConfiguredGraphFactory.removeConfiguration(graphName);
    RuntimeException graph1 = assertThrows(RuntimeException.class, () -> ConfiguredGraphFactory.create(graphName));
    assertEquals("Please create a template Configuration using the " + "ConfigurationManagementGraph#createTemplateConfiguration API.", graph1.getMessage());
}
Also used : MapConfiguration(org.apache.commons.configuration2.MapConfiguration) Test(org.junit.jupiter.api.Test)

Example 7 with MapConfiguration

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

the class AbstractConfiguredGraphFactoryTest method graphConfigurationShouldBeWhatWeExpect.

@Test
public void graphConfigurationShouldBeWhatWeExpect() throws Exception {
    final MapConfiguration graphConfig = getGraphConfig();
    final String graphName = graphConfig.getString(GRAPH_NAME.toStringWithoutRoot());
    try {
        ConfiguredGraphFactory.createConfiguration(getGraphConfig());
        final String backend = graphConfig.getString(STORAGE_BACKEND.toStringWithoutRoot());
        final StandardJanusGraph graph = (StandardJanusGraph) ConfiguredGraphFactory.open(graphName);
        assertNotNull(graph);
        assertEquals(graphName, graph.getConfiguration().getConfiguration().get(GRAPH_NAME));
        assertEquals(backend, graph.getConfiguration().getConfiguration().get(STORAGE_BACKEND));
    } 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)

Example 8 with MapConfiguration

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

the class AbstractConfiguredGraphFactoryTest method shouldFailToOpenNewGraphAfterRemoveConfiguration.

@Test
public void shouldFailToOpenNewGraphAfterRemoveConfiguration() {
    final MapConfiguration graphConfig = getGraphConfig();
    final String graphName = graphConfig.getString(GRAPH_NAME.toStringWithoutRoot());
    ConfiguredGraphFactory.createConfiguration(graphConfig);
    ConfiguredGraphFactory.removeConfiguration(graphName);
    RuntimeException graph1 = assertThrows(RuntimeException.class, () -> ConfiguredGraphFactory.open(graphName));
    assertEquals("Please create configuration for this graph using the " + "ConfigurationManagementGraph#createConfiguration API.", graph1.getMessage());
}
Also used : MapConfiguration(org.apache.commons.configuration2.MapConfiguration) Test(org.junit.jupiter.api.Test)

Example 9 with MapConfiguration

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

the class AbstractConfiguredGraphFactoryTest method updateConfigurationShouldRemoveGraphFromCache.

@Test
public void updateConfigurationShouldRemoveGraphFromCache() throws Exception {
    final MapConfiguration graphConfig = getGraphConfig();
    final String graphName = graphConfig.getString(GRAPH_NAME.toStringWithoutRoot());
    try {
        ConfiguredGraphFactory.createConfiguration(graphConfig);
        final StandardJanusGraph graph = (StandardJanusGraph) ConfiguredGraphFactory.open(graphName);
        assertNotNull(graph);
        final Map<String, Object> map = graphConfig.getMap();
        map.put(STORAGE_BACKEND.toStringWithoutRoot(), "bogusBackend");
        ConfiguredGraphFactory.updateConfiguration(graphName, ConfigurationUtil.loadMapConfiguration(map));
        assertNull(gm.getGraph(graphName));
        // we should throw an error since the config has been updated and we are attempting
        // to open a bogus backend
        IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> ConfiguredGraphFactory.open(graphName));
        assertEquals("Could not find implementation class: bogusBackend", exception.getMessage());
    } 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)

Example 10 with MapConfiguration

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

the class GraphDatabaseConfigurationInstanceIdTest method instanceIdShouldEqualHostnamePlusSuffix.

@Test
public void instanceIdShouldEqualHostnamePlusSuffix() throws UnknownHostException {
    final Map<String, Object> map = getStorageConfiguration();
    map.put(UNIQUE_INSTANCE_ID_HOSTNAME.toStringWithoutRoot(), true);
    map.put(UNIQUE_INSTANCE_ID_SUFFIX.toStringWithoutRoot(), 1);
    final MapConfiguration config = ConfigurationUtil.loadMapConfiguration(map);
    final StandardJanusGraph graph = new StandardJanusGraph(new GraphDatabaseConfigurationBuilder().build(new CommonsConfiguration(config)));
    assertEquals(1, graph.openManagement().getOpenInstances().size());
    assertEquals(toCurrentInstance(Inet4Address.getLocalHost().getHostName() + "1"), graph.openManagement().getOpenInstances().iterator().next());
    graph.close();
}
Also used : GraphDatabaseConfigurationBuilder(org.janusgraph.graphdb.configuration.builder.GraphDatabaseConfigurationBuilder) MapConfiguration(org.apache.commons.configuration2.MapConfiguration) CommonsConfiguration(org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) Test(org.junit.jupiter.api.Test)

Aggregations

MapConfiguration (org.apache.commons.configuration2.MapConfiguration)34 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)6 JanusGraphManager (org.janusgraph.graphdb.management.JanusGraphManager)3 Test (org.testng.annotations.Test)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 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