assertEquals(v1, getOnlyElement(graph.query().has(property, value1).vertices())); v1 = getV(graph, v1.id()); v1.property(property, value2); assertEquals(v1, getOnlyElement(graph.query().has(property, value1).vertices())); assertEquals(v1, getOnlyElement(graph.query().has(property, value2).vertices())); assertEquals(v1, getOnlyElement(graph.query().has(property, value1).vertices())); v1 = getV(graph, v1.id()); v1.properties(property).forEachRemaining(p -> { if (p.value().equals(value1)) { v1 = getV(graph, v1.id()); v1.property(property, value1); assertEquals(v1, getOnlyElement(graph.query().has(property, value1).vertices())); v1 = getV(graph, v1.id()); v1.property(property, value1);
assertEquals(v1, getOnlyElement(graph.query().has(property, value1).vertices())); v1 = getV(graph, v1.id()); v1.property(property, value2); assertEquals(v1, getOnlyElement(graph.query().has(property, value1).vertices())); assertEquals(v1, getOnlyElement(graph.query().has(property, value2).vertices())); assertEquals(v1, getOnlyElement(graph.query().has(property, value1).vertices())); v1 = getV(graph, v1.id()); v1.properties(property).forEachRemaining(p -> { if (p.value().equals(value1)) { v1 = getV(graph, v1.id()); v1.property(property, value1); assertEquals(v1, getOnlyElement(graph.query().has(property, value1).vertices())); v1 = getV(graph, v1.id()); v1.property(property, value1); g.V().drop().iterate(); v1 = g.addV().property(property, value1).property(property, value2).next(); g.addV().property(property, value1).property(property, value2).next(); assertEquals(2, g.V().has(property, value1).toList().size()); g.V().properties().drop().iterate();
private void assertCommonA(Traversal<Vertex, Map<String, Collection<Vertex>>> traversal) { final Map<String, Collection<Vertex>> map = traversal.next(); assertEquals(6, map.size()); map.forEach((key, values) -> { assertEquals(1, values.size()); assertEquals(convertToVertexId(key), values.iterator().next().id()); }); assertFalse(traversal.hasNext()); }
private static void assertGraphEquality(final Graph source, final Graph target, final Function<Vertex, Object> idAccessor) { final GraphTraversalSource tg = target.traversal(); assertEquals(IteratorUtils.count(source.vertices()), IteratorUtils.count(target.vertices())); assertEquals(IteratorUtils.count(target.edges()), IteratorUtils.count(target.edges())); source.vertices().forEachRemaining(originalVertex -> { Vertex tmpVertex = null; final Iterator<Vertex> vertexIterator = target.vertices(); while (vertexIterator.hasNext()) { final Vertex v = vertexIterator.next(); if (idAccessor.apply(v).toString().equals(originalVertex.id().toString())) { tmpVertex = v; break; assertEquals(IteratorUtils.count(originalVertex.edges(Direction.IN)), IteratorUtils.count(clonedVertex.edges(Direction.IN))); assertEquals(IteratorUtils.count(originalVertex.edges(Direction.OUT)), IteratorUtils.count(clonedVertex.edges(Direction.OUT))); assertEquals(originalVertex.label(), clonedVertex.label()); final Iterator<VertexProperty<Object>> vertexPropertyIterator = clonedVertex.properties(originalProperty.key()); while (vertexPropertyIterator.hasNext()) { final VertexProperty p = vertexPropertyIterator.next(); if (p.value().equals(originalProperty.value())) { clonedProperty = p; }); originalVertex.edges(Direction.OUT).forEachRemaining(originalEdge -> { GraphTraversal t = tg.V(clonedVertex).outE(originalEdge.label()); originalEdge.properties().forEachRemaining(p -> t.has(p.key(), p.value())); assertTrue(t.hasNext());
/** * {@inheritDoc} */ @Override public Vertex getOrCreateVertex(final Vertex vertex, final Graph graph, final GraphTraversalSource g) { final Iterator<Vertex> iterator = useUserSuppliedIds() ? g.V().hasId(vertex.id()) : g.V().has(vertex.label(), bulkLoaderVertexId, vertex.id().toString()); return iterator.hasNext() ? iterator.next() : useUserSuppliedIds() ? g.addV(vertex.label()).property(T.id, vertex.id()).next() : g.addV(vertex.label()).property(bulkLoaderVertexId, vertex.id().toString()).next(); }
/** * Creates a clone of the given vertex in the given graph. */ @Override public Vertex getOrCreateVertex(final Vertex vertex, final Graph graph, final GraphTraversalSource g) { final GraphTraversal<Vertex, Vertex> t = g.addV(vertex.label()); return (useUserSuppliedIds() ? t.property(T.id, vertex.id()) : t).next(); }
@Test public void testConsistencyModifier() throws InterruptedException { PropertyKey sig = makeKey("sig",Integer.class); assertEquals(6.0,v.<Double>value("weight").doubleValue(),0.00001); VertexProperty p = getOnlyElement(v.properties("weight")); assertEquals(wintx,p.<Integer>value("sig").intValue()); p = getOnlyElement(v.properties("name")); assertEquals("Bob",p.value()); assertEquals(wintx,p.<Integer>value("sig").intValue()); p = getOnlyElement(v.properties("value")); assertCount(2,v.properties("valuef")); for (Iterator<VertexProperty<Object>> ppiter = v.properties("valuef"); ppiter.hasNext(); ) { VertexProperty pp = ppiter.next(); assertNotEquals(rs[3].longId(),getId(pp)); assertEquals(2,pp.value()); for (Edge ee : v.query().direction(OUT).labels("emf").edges()) { assertNotEquals(rs[5].longId(),getId(ee)); assertEquals(uid,ee.inVertex().id());
@Test public void testQueryInEdgesOfVertexByLabel() { HugeGraph graph = graph(); init18Edges(); Vertex java3 = vertex("book", "name", "java-3"); List<Edge> edges = graph.traversal().V(java3.id()).inE().toList(); Assert.assertEquals(5, edges.size()); edges = graph.traversal().V(java3.id()).inE("look").toList(); Assert.assertEquals(4, edges.size()); }
/** * {@inheritDoc} */ @Override public Vertex getOrCreateVertex(final Vertex vertex, final Graph graph, final GraphTraversalSource g) { final Iterator<Vertex> iterator = useUserSuppliedIds() ? g.V().hasId(vertex.id()) : g.V().has(vertex.label(), bulkLoaderVertexId, vertex.id().toString()); return iterator.hasNext() ? iterator.next() : useUserSuppliedIds() ? g.addV(vertex.label()).property(T.id, vertex.id()).next() : g.addV(vertex.label()).property(bulkLoaderVertexId, vertex.id().toString()).next(); }
/** * Creates a clone of the given vertex in the given graph. */ @Override public Vertex getOrCreateVertex(final Vertex vertex, final Graph graph, final GraphTraversalSource g) { final GraphTraversal<Vertex, Vertex> t = g.addV(vertex.label()); return (useUserSuppliedIds() ? t.property(T.id, vertex.id()) : t).next(); }
@Test public void testConsistencyModifier() throws InterruptedException { makeKey("sig",Integer.class); assertEquals(6.0, v.<Double>value("weight"),0.00001); VertexProperty p = getOnlyElement(v.properties("weight")); assertEquals(wintx,p.<Integer>value("sig").intValue()); p = getOnlyElement(v.properties("name")); assertEquals("Bob",p.value()); assertEquals(wintx,p.<Integer>value("sig").intValue()); p = getOnlyElement(v.properties("value")); assertCount(2,v.properties("valuef")); for (Iterator<VertexProperty<Object>> ppiter = v.properties("valuef"); ppiter.hasNext(); ) { VertexProperty pp = ppiter.next(); assertNotEquals(rs[3].longId(),getId(pp)); assertEquals(2,pp.value()); Edge ee = (Edge) o; assertNotEquals(rs[5].longId(),getId(ee)); assertEquals(uid,ee.inVertex().id());
@Test public void testQueryBothVerticesOfVertex() { HugeGraph graph = graph(); init18Edges(); Vertex jeff = vertex("person", "name", "Jeff"); List<Vertex> vertices = graph.traversal().V(jeff.id()) .both("friend").toList(); Assert.assertEquals(2, vertices.size()); vertices = ImmutableList.copyOf( jeff.vertices(Direction.BOTH, "friend")); Assert.assertEquals(2, vertices.size()); }
private void postProcess(long startIndex) { LOG.info("postProcess: Starting... : counter at: {}", counter.get()); try { PostProcessManager.WorkItemsManager wim = PostProcessManager.create(bulkLoadGraph, relationshipCache.getPropertiesToPostProcess(), batchSize, numWorkers); GraphTraversal query = bulkLoadGraph.traversal().V(); while (query.hasNext()) { handleInterrupt(bulkLoadGraph, counter.incrementAndGet()); if(shouldSkip(startIndex, counter.get())) { continue; } Vertex v = (Vertex) query.next(); wim.produce(v.id()); updateStatusConditionally(bulkLoadGraph, counter.get()); } wim.shutdown(); } catch (Exception ex) { LOG.error("postProcess: failed!", ex); } finally { LOG.info("postProcess: Done! : [{}]", counter.get()); readerStatusManager.update(bulkLoadGraph, counter.get(), true); } }
@Test @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_CUSTOM_IDS) public void shouldIterateVerticesWithCustomIdSupportUsingStringRepresentation() { final Vertex v1 = graph.addVertex(); graph.addVertex(); tryCommit(graph, graph -> { final Vertex v = graph.vertices(v1.id().toString()).next(); assertEquals(v1.id(), v.id()); }); }
@Test public void testQueryInEdgesOfVertexBySortkey() { HugeGraph graph = graph(); init18Edges(); Vertex java3 = vertex("book", "name", "java-3"); List<Edge> edges = graph.traversal().V(java3.id()) .inE("look").toList(); Assert.assertEquals(4, edges.size()); edges = graph.traversal().V(java3.id()) .inE("look").has("time", "2017-5-27").toList(); Assert.assertEquals(3, edges.size()); }
@Test @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_CUSTOM_IDS) public void shouldIterateVerticesWithCustomIdSupportUsingVertexId() { final Vertex v1 = graph.addVertex(); graph.addVertex(); tryCommit(graph, graph -> { final Vertex v = graph.vertices(v1.id()).next(); assertEquals(v1.id(), v.id()); }); }