public void initEnv() { // Cost about 6s this.hugegraph.graphTransaction(); }
@Override protected <V> V property(String key, V value) { HugeGraph graph = graph(); Vertex vertex1 = graph.addVertex(T.label, "person", "id", 1); Vertex vertex2 = graph.addVertex(T.label, "person", "id", 2); Edge edge = vertex1.addEdge("transfer", vertex2, "id", 1, key, value); graph.tx().commit(); return graph.edges(edge.id()).next().value(key); } }
@AfterClass public static void clear() { if (graph == null) { return; } try { graph.clearBackend(); } finally { try { graph.close(); } catch (Throwable e) { LOG.error("Error when close()", e); } graph = null; } }
public static SnowflakeIdGenerator instance(HugeGraph graph) { String graphname = graph.name(); SnowflakeIdGenerator generator = INSTANCES.get(graphname); if (generator == null) { synchronized (INSTANCES) { if (!INSTANCES.containsKey(graphname)) { HugeConfig conf = graph.configuration(); INSTANCES.put(graphname, new SnowflakeIdGenerator(conf)); } generator = INSTANCES.get(graphname); assert generator != null; } } return generator; }
@BeforeClass public static void init() { graph = Utils.open(); graph.clearBackend(); graph.initBackend(); }
@Test public void testInsertAndInsertVertex() { HugeGraph graph = graph(); graph.addVertex(T.label, "author", "id", 1, "name", "Tom", "lived", "Beijing"); graph.addVertex(T.label, "author", "id", 1, "name", "Tom", "lived", "Shanghai"); graph.tx().commit(); Vertex vertex = vertex("author", "id", 1); Assert.assertEquals("Shanghai", vertex.property("lived").value()); }
@Test public void testQueryFilterByPropName() { HugeGraph graph = graph(); BackendFeatures features = graph.graphTransaction().store().features(); Assume.assumeTrue("Not support CONTAINS_KEY query", features.supportsQueryWithContainsKey()); init10Vertices(); VertexLabel language = graph.vertexLabel("language"); PropertyKey dynamic = graph.propertyKey("dynamic"); // Query vertex by condition (does contain the property name?) ConditionQuery q = new ConditionQuery(HugeType.VERTEX); q.eq(HugeKeys.LABEL, language.id()); q.key(HugeKeys.PROPERTIES, dynamic.id()); List<Vertex> vertexes = ImmutableList.copyOf(graph.vertices(q)); Assert.assertEquals(1, vertexes.size()); assertContains(vertexes, T.label, "language", "name", "python", "dynamic", true); }
private void checkBackendVersionOrExit() { for (String graph : this.graphs()) { HugeGraph hugegraph = this.graph(graph); if (InMemoryDBStoreProvider.matchType(hugegraph.backend())) { hugegraph.initBackend(); } BackendStoreSystemInfo info = new BackendStoreSystemInfo(hugegraph); if (!info.exist()) { LOG.error("The backend store of '{}' has not been initialized", hugegraph.name()); System.exit(-1); } if (!info.checkVersion()) { // Exit if versions are inconsistent System.exit(-1); } } }
public List<Id> mapPkName2Id(Collection<String> pkeys) { List<Id> ids = new ArrayList<>(pkeys.size()); for (String pkey : pkeys) { PropertyKey propertyKey = this.propertyKey(pkey); ids.add(propertyKey.id()); } return ids; }
private HugeVertex queryVariableVertex(String key) { ConditionQuery query = new ConditionQuery(HugeType.VERTEX); VertexLabel vl = this.graph.vertexLabel(Hidden.hide(VARIABLES)); query.eq(HugeKeys.LABEL, vl.id()); PropertyKey pkey = this.graph.propertyKey(Hidden.hide(VARIABLE_KEY)); query.query(Condition.eq(pkey.id(), key)); query.showHidden(true); Iterator<Vertex> vertices = this.graph.vertices(query); if (!vertices.hasNext()) { return null; } return (HugeVertex) vertices.next(); }
@Watched @Override public Iterator<Edge> edges(Object... edgeIds) { return this.graph.edges(edgeIds); }
public VertexLabel vertexLabel(Id id) { VertexLabel vl = this.schemaTransaction().getVertexLabel(id); E.checkArgument(vl != null, "Undefined vertex label id: '%s'", id); return vl; }
private String createPropertyKey(String name, DataType dataType, Cardinality cardinality) { HugeGraph graph = this.graph(); SchemaManager schema = graph.schema(); PropertyKey propertyKey = schema.propertyKey(name) .dataType(dataType) .cardinality(cardinality) .build(); graph.schemaTransaction().addPropertyKey(propertyKey); return name; }
@SuppressWarnings("unchecked") @Test public void testScanEdge() { HugeGraph graph = graph(); Assume.assumeTrue("Not support scan", storeFeatures().supportsScanToken() || storeFeatures().supportsScanKeyRange()); init18Edges(); Set<Edge> edges = new HashSet<>(); long splitSize = 1 * 1024 * 1024; Object splits = graph.graphTransaction() .metadata(HugeType.EDGE_OUT, "splits", splitSize); for (Shard split : (List<Shard>) splits) { ConditionQuery q = new ConditionQuery(HugeType.EDGE); q.scan(split.start(), split.end()); edges.addAll(ImmutableList.copyOf(graph.edges(q))); } Assert.assertEquals(18, edges.size()); }
private HugeElement newestElement(HugeElement element) { boolean isVertex = element instanceof HugeVertex; if (isVertex) { Iterator<Vertex> iterV = this.graph().vertices(element.id()); if (iterV.hasNext()) { return (HugeVertex) iterV.next(); } } else { assert element instanceof HugeEdge; Iterator<Edge> iterE = this.graph().edges(element.id()); if (iterE.hasNext()) { return (HugeEdge) iterE.next(); } } return null; } }
private static void initGraph(String config) throws InterruptedException { LOG.info("Init graph with config file: {}", config); HugeGraph graph = HugeFactory.open(config); BackendStoreSystemInfo sysInfo = new BackendStoreSystemInfo(graph); try { if (sysInfo.exist()) { LOG.info("Skip init-store due to the backend store of '{}' " + "had been initialized", graph.name()); sysInfo.checkVersion(); } else { initBackend(graph); } } finally { graph.close(); } }
public int test(String[] args) throws Exception { if (args.length != 4) { System.out.println("Usage: threadCount times multiple profile"); return -1; } int threadCount = Integer.parseInt(args[0]); int times = Integer.parseInt(args[1]); int multiple = Integer.parseInt(args[2]); this.profile = Boolean.parseBoolean(args[3]); // NOTE: this test with HugeGraph is for local, change it into // client if test with restful server from remote HugeGraph hugegraph = ExampleUtil.loadGraph(true, this.profile); GraphManager graph = new GraphManager(hugegraph); initSchema(hugegraph.schema()); testInsertPerf(graph, threadCount, times, multiple); testQueryVertexPerf(graph, threadCount, times, multiple); testQueryEdgePerf(graph, threadCount, times, multiple); hugegraph.close(); return 0; }
public HugeGraphAuthProxy(HugeGraph hugegraph) { LOG.info("Wrap graph '{}' with HugeGraphAuthProxy", hugegraph.name()); this.hugegraph = hugegraph; }