Search in sources :

Example 21 with StandardJanusGraph

use of org.janusgraph.graphdb.database.StandardJanusGraph in project janusgraph by JanusGraph.

the class ConfiguredGraphFactoryTest method updateConfigurationShouldRemoveGraphFromCache.

@Test
public void updateConfigurationShouldRemoveGraphFromCache() throws Exception {
    try {
        final Map<String, Object> map = new HashMap<>();
        map.put(STORAGE_BACKEND.toStringWithoutRoot(), "inmemory");
        map.put(GRAPH_NAME.toStringWithoutRoot(), "graph1");
        ConfiguredGraphFactory.createConfiguration(new MapConfiguration(map));
        final StandardJanusGraph graph = (StandardJanusGraph) ConfiguredGraphFactory.open("graph1");
        assertNotNull(graph);
        map.put(STORAGE_BACKEND.toStringWithoutRoot(), "bogusBackend");
        ConfiguredGraphFactory.updateConfiguration("graph1", new MapConfiguration(map));
        assertNull(gm.getGraph("graph1"));
        // we should throw an error since the config has been updated and we are attempting
        // to open a bogus backend
        thrown.expect(IllegalArgumentException.class);
        thrown.expectMessage(equalTo("Could not find implementation class: bogusBackend"));
        final StandardJanusGraph graph2 = (StandardJanusGraph) ConfiguredGraphFactory.open("graph1");
    } finally {
        ConfiguredGraphFactory.removeConfiguration("graph1");
        ConfiguredGraphFactory.close("graph1");
    }
}
Also used : HashMap(java.util.HashMap) MapConfiguration(org.apache.commons.configuration.MapConfiguration) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) Test(org.junit.Test)

Example 22 with StandardJanusGraph

use of org.janusgraph.graphdb.database.StandardJanusGraph in project janusgraph by JanusGraph.

the class ConfiguredGraphFactoryTest method graphConfigurationShouldBeWhatWeExpectWhenUsingTemplateConfiguration.

@Test
public void graphConfigurationShouldBeWhatWeExpectWhenUsingTemplateConfiguration() throws Exception {
    try {
        final Map<String, Object> map = new HashMap<>();
        map.put(STORAGE_BACKEND.toStringWithoutRoot(), "inmemory");
        ConfiguredGraphFactory.createTemplateConfiguration(new MapConfiguration(map));
        final StandardJanusGraph graph = (StandardJanusGraph) ConfiguredGraphFactory.create("graph1");
        final StandardJanusGraph graph1 = (StandardJanusGraph) ConfiguredGraphFactory.open("graph1");
        assertNotNull(graph);
        assertEquals(graph, graph1);
        assertEquals("graph1", graph.getConfiguration().getConfiguration().get(GRAPH_NAME));
        assertEquals("inmemory", graph.getConfiguration().getConfiguration().get(STORAGE_BACKEND));
    } finally {
        ConfiguredGraphFactory.removeConfiguration("graph1");
        ConfiguredGraphFactory.close("graph1");
    }
}
Also used : HashMap(java.util.HashMap) MapConfiguration(org.apache.commons.configuration.MapConfiguration) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) Test(org.junit.Test)

Example 23 with StandardJanusGraph

use of org.janusgraph.graphdb.database.StandardJanusGraph in project janusgraph by JanusGraph.

the class ConfiguredGraphFactoryTest method ensureCallingGraphCloseResultsInNewGraphReferenceOnNextCallToOpen.

@Test
public void ensureCallingGraphCloseResultsInNewGraphReferenceOnNextCallToOpen() throws Exception {
    try {
        final Map<String, Object> map = new HashMap<>();
        map.put(STORAGE_BACKEND.toStringWithoutRoot(), "inmemory");
        ConfiguredGraphFactory.createTemplateConfiguration(new MapConfiguration(map));
        final StandardJanusGraph graph = (StandardJanusGraph) ConfiguredGraphFactory.create("graph1");
        assertNotNull(graph);
        assertEquals("graph1", graph.getConfiguration().getConfiguration().get(GRAPH_NAME));
        graph.close();
        assertTrue(graph.isClosed());
        final StandardJanusGraph newGraph = (StandardJanusGraph) ConfiguredGraphFactory.open("graph1");
        assertFalse(newGraph.isClosed());
    } finally {
        ConfiguredGraphFactory.removeConfiguration("graph1");
        ConfiguredGraphFactory.close("graph1");
    }
}
Also used : HashMap(java.util.HashMap) MapConfiguration(org.apache.commons.configuration.MapConfiguration) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) Test(org.junit.Test)

Example 24 with StandardJanusGraph

use of org.janusgraph.graphdb.database.StandardJanusGraph in project janusgraph by JanusGraph.

the class GraphDatabaseConfigurationInstanceIdTest method graphShouldNotOpenWithSameInstanceId.

@Test
public void graphShouldNotOpenWithSameInstanceId() {
    final Map<String, Object> map = new HashMap<String, Object>();
    map.put(STORAGE_BACKEND.toStringWithoutRoot(), "inmemory");
    map.put(UNIQUE_INSTANCE_ID.toStringWithoutRoot(), "not-unique");
    final MapConfiguration config = new MapConfiguration(map);
    final StandardJanusGraph graph1 = new StandardJanusGraph(new GraphDatabaseConfiguration(new CommonsConfiguration(config)));
    assertEquals(graph1.openManagement().getOpenInstances().size(), 1);
    assertEquals(graph1.openManagement().getOpenInstances().toArray()[0], "not-unique");
    thrown.expect(JanusGraphException.class);
    final String err = "A JanusGraph graph with the same instance id [not-unique] is already open. Might required forced shutdown.";
    thrown.expectMessage(equalTo(err));
    final StandardJanusGraph graph2 = new StandardJanusGraph(new GraphDatabaseConfiguration(new CommonsConfiguration(config)));
    graph1.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 25 with StandardJanusGraph

use of org.janusgraph.graphdb.database.StandardJanusGraph in project janusgraph by JanusGraph.

the class GraphDatabaseConfigurationInstanceIdTest method graphShouldOpenWithSameInstanceId.

@Test
public void graphShouldOpenWithSameInstanceId() {
    final Map<String, Object> map = new HashMap<String, Object>();
    map.put(STORAGE_BACKEND.toStringWithoutRoot(), "inmemory");
    map.put(UNIQUE_INSTANCE_ID.toStringWithoutRoot(), "not-unique");
    map.put(REPLACE_INSTANCE_IF_EXISTS.toStringWithoutRoot(), true);
    final MapConfiguration config = new MapConfiguration(map);
    final StandardJanusGraph graph1 = new StandardJanusGraph(new GraphDatabaseConfiguration(new CommonsConfiguration(config)));
    assertEquals(graph1.openManagement().getOpenInstances().size(), 1);
    assertEquals(graph1.openManagement().getOpenInstances().toArray()[0], "not-unique");
    final StandardJanusGraph graph2 = new StandardJanusGraph(new GraphDatabaseConfiguration(new CommonsConfiguration(config)));
    assertEquals(graph1.openManagement().getOpenInstances().size(), 1);
    assertEquals(graph1.openManagement().getOpenInstances().toArray()[0], "not-unique");
    assertEquals(graph2.openManagement().getOpenInstances().size(), 1);
    assertEquals(graph2.openManagement().getOpenInstances().toArray()[0], "not-unique");
    graph1.close();
    graph2.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)

Aggregations

StandardJanusGraph (org.janusgraph.graphdb.database.StandardJanusGraph)29 Test (org.junit.Test)18 MapConfiguration (org.apache.commons.configuration.MapConfiguration)16 HashMap (java.util.HashMap)14 GraphDatabaseConfiguration (org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration)11 CommonsConfiguration (org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration)9 JanusGraphManagement (org.janusgraph.core.schema.JanusGraphManagement)4 JanusGraphManager (org.janusgraph.graphdb.management.JanusGraphManager)4 Graph (org.apache.tinkerpop.gremlin.structure.Graph)3 JanusGraphTransaction (org.janusgraph.core.JanusGraphTransaction)3 PropertyKey (org.janusgraph.core.PropertyKey)3 Instant (java.time.Instant)2 JanusGraph (org.janusgraph.core.JanusGraph)2 JanusGraphIndex (org.janusgraph.core.schema.JanusGraphIndex)2 Backend (org.janusgraph.diskstorage.Backend)2 TimestampProvider (org.janusgraph.diskstorage.util.time.TimestampProvider)2 ManagementSystem (org.janusgraph.graphdb.database.management.ManagementSystem)2 ElementCategory (org.janusgraph.graphdb.internal.ElementCategory)2 GraknTxJanus (ai.grakn.kb.internal.GraknTxJanus)1 Preconditions (com.google.common.base.Preconditions)1