@Test public void testSupportDirectCommitOfSchemaChangesForConnection() { GraphTraversalSource g = prepareGraphForDirectCommitTests(); g.addV("user").as("p1").addV("user").addE("knows").from("p1").iterate(); }
@Test public void testSupportDirectCommitOfSchemaChangesForEdgeProperties() { GraphTraversalSource g = prepareGraphForDirectCommitTests(); g.addV("user").as("p1").addV("user").addE("knows").from("p1").property("id", 10).iterate(); }
/** * @see GraphTraversal#addV(org.apache.tinkerpop.gremlin.process.traversal.Traversal) */ public static <A> GraphTraversal<A, Vertex> addV(final Traversal<?, String> vertexLabelTraversal) { return __.<A>start().addV(vertexLabelTraversal); }
/** * @see GraphTraversal#addV() */ public static <A> GraphTraversal<A, Vertex> addV() { return __.<A>start().addV(); }
/** * @see GraphTraversal#addV(String) */ public static <A> GraphTraversal<A, Vertex> addV(final String vertexLabel) { return __.<A>start().addV(vertexLabel); }
@Override public Traversal<Vertex, Vertex> get_g_V_addVXanimalX_propertyXage_0X() { return g.V().addV("animal").property("age", 0); }
@Benchmark public Vertex testAddVWithPropsChained() { // construct a traversal that adds 100 vertices with 32 properties each GraphTraversal<Vertex, Vertex> t = null; for (int ix = 0; ix < 100; ix++) { if (null == t) t = g.addV("person"); else t = t.addV("person"); for (int iy = 0; iy < 32; iy++) { if (iy % 2 == 0) t = t.property("x" + String.valueOf(iy), iy * ix); else t = t.property("x" + String.valueOf(iy), String.valueOf(iy + ix)); } } return t.next(); }
@Override public Traversal<Vertex, Vertex> get_g_VX1X_addVXanimalX_propertyXage_selectXaX_byXageXX_propertyXname_puppyX(final Object v1Id) { return g.V(v1Id).as("a").addV("animal").property("age", select("a").by("age")).property("name", "puppy"); }
@Override public Traversal<Vertex, Vertex> get_g_V_addVXanimalX_propertyXname_valuesXnameXX_propertyXname_an_animalX_propertyXvaluesXnameX_labelX() { return g.V().addV("animal").property("name", __.values("name")).property("name", "an animal").property(__.values("name"), __.label()); }
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) public void shouldGenerateDefaultIdOnAddVWithGeneratedDefaultId() throws Exception { final ElementIdStrategy strategy = ElementIdStrategy.build().create(); final GraphTraversalSource sg = create(strategy); sg.addV().next(); assertEquals(1, IteratorUtils.count(sg.V())); final Vertex v = sg.V().addV().property("name", "stephen").next(); assertEquals("stephen", v.value("name")); assertNotNull(UUID.fromString(sg.V(v).id().next().toString())); }
@Override public Traversal<Vertex, Map<Object, Object>> get_g_V_asXaX_hasXname_markoX_outXcreatedX_asXbX_addVXselectXaX_labelX_propertyXtest_selectXbX_labelX_valueMap_withXtokensX() { return g.V().as("a").has("name", "marko").out("created").as("b").addV(select("a").label()).property("test", select("b").label()).valueMap().with(WithOptions.tokens); } }
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) public void shouldGenerateDefaultIdOnAddVWithGeneratedCustomId() throws Exception { final AtomicBoolean first = new AtomicBoolean(false); final ElementIdStrategy strategy = ElementIdStrategy.build().idMaker(() -> { final String key = first.get() ? "xxx" : "yyy"; first.set(true); return key; }).create(); final GraphTraversalSource sg = create(strategy); sg.addV().next(); assertEquals(1, IteratorUtils.count(sg.V())); final Vertex v = sg.V().addV().property("name", "stephen").next(); assertEquals("stephen", v.value("name")); assertEquals("xxx", sg.V(v).id().next()); assertEquals("xxx", sg.V("xxx").id().next()); assertEquals("yyy", sg.V("yyy").id().next()); }
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) @FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = Graph.Features.GraphFeatures.FEATURE_TRANSACTIONS) public void shouldTriggerAfterCommit() { final StubMutationListener listener1 = new StubMutationListener(); final StubMutationListener listener2 = new StubMutationListener(); final EventStrategy.Builder builder = EventStrategy.build() .eventQueue(new EventStrategy.TransactionalEventQueue(graph)) .addListener(listener1) .addListener(listener2); final EventStrategy eventStrategy = builder.create(); graph.addVertex("some", "thing"); final GraphTraversalSource gts = create(eventStrategy); gts.V().addV().property("any", "thing").next(); gts.V().addV().property("any", "one").next(); assertEquals(0, listener1.addVertexEventRecorded()); assertEquals(0, listener2.addVertexEventRecorded()); gts.tx().commit(); assertEquals(2, IteratorUtils.count(gts.V().has("any"))); assertEquals(2, listener1.addVertexEventRecorded()); assertEquals(2, listener2.addVertexEventRecorded()); }
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) public void shouldGenerateDefaultIdOnAddVWithSpecifiedId() throws Exception { final ElementIdStrategy strategy = ElementIdStrategy.build().create(); final GraphTraversalSource sg = create(strategy); sg.addV().next(); assertEquals(1, IteratorUtils.count(sg.V())); final Vertex v = sg.V().addV().property(T.id, "STEPHEN").property("name", "stephen").next(); assertEquals("stephen", v.value("name")); assertEquals("STEPHEN", sg.V(v).id().next()); assertEquals("STEPHEN", sg.V("STEPHEN").id().next()); }
/** * Generate the graph in {@link #createKitchenSink()} into an existing graph. */ public static void generateKitchenSink(final TinkerGraph graph) { final GraphTraversalSource g = graph.traversal(); g.addV("loops").property(T.id, 1000).property("name", "loop").as("me"). addE("self").to("me").property(T.id, 1001). iterate(); g.addV("message").property(T.id, 2000).property("name", "a").as("a"). addV("message").property(T.id, 2001).property("name", "b").as("b"). addE("link").from("a").to("b").property(T.id, 2002). addE("link").from("a").to("a").property(T.id, 2003).iterate(); }
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) public void shouldTriggerAddVertex() { final StubMutationListener listener1 = new StubMutationListener(); final StubMutationListener listener2 = new StubMutationListener(); final EventStrategy.Builder builder = EventStrategy.build() .addListener(listener1) .addListener(listener2); if (graph.features().graph().supportsTransactions()) builder.eventQueue(new EventStrategy.TransactionalEventQueue(graph)); final EventStrategy eventStrategy = builder.create(); graph.addVertex("some", "thing"); final GraphTraversalSource gts = create(eventStrategy); gts.V().addV().property("any", "thing").next(); tryCommit(graph, g -> assertEquals(1, IteratorUtils.count(gts.V().has("any", "thing")))); assertEquals(1, listener1.addVertexEventRecorded()); assertEquals(1, listener2.addVertexEventRecorded()); }
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) public void shouldTriggerAddVertexPropertyAdded() { final StubMutationListener listener1 = new StubMutationListener(); final StubMutationListener listener2 = new StubMutationListener(); final EventStrategy.Builder builder = EventStrategy.build() .addListener(listener1) .addListener(listener2); if (graph.features().graph().supportsTransactions()) builder.eventQueue(new EventStrategy.TransactionalEventQueue(graph)); final EventStrategy eventStrategy = builder.create(); final Vertex vSome = graph.addVertex("some", "thing"); vSome.property(VertexProperty.Cardinality.single, "that", "thing"); final GraphTraversalSource gts = create(eventStrategy); gts.V().addV().property("this", "thing").next(); tryCommit(graph, g -> assertEquals(1, IteratorUtils.count(gts.V().has("this", "thing")))); assertEquals(1, listener1.addVertexEventRecorded()); assertEquals(1, listener2.addVertexEventRecorded()); assertEquals(0, listener2.vertexPropertyChangedEventRecorded()); assertEquals(0, listener1.vertexPropertyChangedEventRecorded()); }
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) public void shouldTriggerAddVertexWithPropertyThenPropertyAdded() { final StubMutationListener listener1 = new StubMutationListener(); final StubMutationListener listener2 = new StubMutationListener(); final EventStrategy.Builder builder = EventStrategy.build() .addListener(listener1) .addListener(listener2); if (graph.features().graph().supportsTransactions()) builder.eventQueue(new EventStrategy.TransactionalEventQueue(graph)); final EventStrategy eventStrategy = builder.create(); final Vertex vSome = graph.addVertex("some", "thing"); vSome.property(VertexProperty.Cardinality.single, "that", "thing"); final GraphTraversalSource gts = create(eventStrategy); gts.V().addV().property("any", "thing").property(VertexProperty.Cardinality.single, "this", "thing").next(); tryCommit(graph, g -> assertEquals(1, IteratorUtils.count(gts.V().has("this", "thing")))); assertEquals(1, listener1.addVertexEventRecorded()); assertEquals(1, listener2.addVertexEventRecorded()); assertEquals(1, listener2.vertexPropertyChangedEventRecorded()); assertEquals(1, listener1.vertexPropertyChangedEventRecorded()); }
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) public void shouldTriggerAddVertexPropertyChanged() { final StubMutationListener listener1 = new StubMutationListener(); final StubMutationListener listener2 = new StubMutationListener(); final EventStrategy.Builder builder = EventStrategy.build() .addListener(listener1) .addListener(listener2); if (graph.features().graph().supportsTransactions()) builder.eventQueue(new EventStrategy.TransactionalEventQueue(graph)); final EventStrategy eventStrategy = builder.create(); final Vertex vSome = graph.addVertex("some", "thing"); vSome.property(VertexProperty.Cardinality.single, "that", "thing"); final GraphTraversalSource gts = create(eventStrategy); final Vertex vAny = gts.V().addV().property("any", "thing").next(); gts.V(vAny).property(VertexProperty.Cardinality.single, "any", "thing else").next(); tryCommit(graph, g -> assertEquals(1, IteratorUtils.count(gts.V().has("any", "thing else")))); assertEquals(1, listener1.addVertexEventRecorded()); assertEquals(1, listener2.addVertexEventRecorded()); assertEquals(1, listener2.vertexPropertyChangedEventRecorded()); assertEquals(1, listener1.vertexPropertyChangedEventRecorded()); }
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_META_PROPERTIES) public void shouldTriggerAddVertexPropertyPropertyChanged() { final StubMutationListener listener1 = new StubMutationListener(); final StubMutationListener listener2 = new StubMutationListener(); final EventStrategy.Builder builder = EventStrategy.build() .addListener(listener1) .addListener(listener2); if (graph.features().graph().supportsTransactions()) builder.eventQueue(new EventStrategy.TransactionalEventQueue(graph)); final EventStrategy eventStrategy = builder.create(); final Vertex vSome = graph.addVertex("some", "thing"); vSome.property(VertexProperty.Cardinality.single, "that", "thing", "is", "good"); final GraphTraversalSource gts = create(eventStrategy); final Vertex vAny = gts.V().addV().property("any", "thing").next(); gts.V(vAny).properties("any").property("is", "bad").next(); tryCommit(graph, g -> assertEquals(1, IteratorUtils.count(gts.V().has("any", "thing")))); assertEquals(1, listener1.addVertexEventRecorded()); assertEquals(1, listener2.addVertexEventRecorded()); assertEquals(1, listener2.vertexPropertyPropertyChangedEventRecorded()); assertEquals(1, listener1.vertexPropertyPropertyChangedEventRecorded()); }