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");
}
}
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");
}
}
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");
}
}
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();
}
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();
}
Aggregations