public String getGraphName() { return getConfigurationAtOpen().getString(GRAPH_NAME.toStringWithoutRoot()); }
@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(); } }
public LocalStoreManager(Configuration storageConfig) throws BackendException { super(storageConfig); Preconditions.checkArgument(storageConfig.has(STORAGE_DIRECTORY) || (storageConfig.has(STORAGE_ROOT) && storageConfig.has(GRAPH_NAME)), String.format("Please supply configuration parameter \"%s\" or both \"%s\" and \"%s\".", STORAGE_DIRECTORY.toStringWithoutRoot(), STORAGE_ROOT.toStringWithoutRoot(), GRAPH_NAME.toStringWithoutRoot() )); if (storageConfig.has(STORAGE_DIRECTORY)) { final String storageDir = storageConfig.get(STORAGE_DIRECTORY); directory = DirectoryUtil.getOrCreateDataDirectory(storageDir); } else { final String storageRoot = storageConfig.get(STORAGE_ROOT); final String graphName = storageConfig.get(GRAPH_NAME); directory = DirectoryUtil.getOrCreateDataDirectory(storageRoot, graphName); } } }
@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(); }
@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(); }
@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(); }