@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(); }
@Override public default GraphTraversal<S, E> iterate() { return GraphTraversal.super.iterate(); }
@Test public void testSupportDirectCommitOfSchemaChangesForVertexProperties() { clopen(option(AUTO_TYPE), "none", option(SCHEMA_CONSTRAINTS), true); GraphTraversalSource g = graph.traversal(); VertexLabel label = mgmt.makeVertexLabel("user").make(); PropertyKey prop = mgmt.makePropertyKey("id").dataType(Integer.class).make(); mgmt.addProperties(label, prop); mgmt.commit(); g.addV("user").property("id", 10).iterate(); }
/** * Used by the default implementation of {@link AbstractGraphProvider#loadGraphData(Graph, LoadGraphWith, Class, String)} * to read the graph from a Kryo file using the default {@link GryoReader} implementation. If the default * implementation does not work (perhaps a graph implementation needs to register some special {@link IoRegistry} * then this method or its caller should be overridden to suit the implementation. * * @param graph the graph to load to * @param path the path to the file to load into the graph */ protected void readIntoGraph(final Graph graph, final String path) throws IOException { final String dataFile = TestHelper.generateTempFileFromResource(graph.getClass(), GryoResourceAccess.class, path.substring(path.lastIndexOf(File.separator) + 1), "", false).getAbsolutePath(); graph.traversal().io(dataFile).read().iterate(); } }
@Test @Ignore @LoadGraphWith(MODERN) public void shouldNotAlterTraversalAfterTraversalBecomesLocked() { final GraphTraversal<Vertex, Vertex> traversal = this.g.V(); assertTrue(traversal.hasNext()); try { traversal.count().next(); fail("Should throw: " + Traversal.Exceptions.traversalIsLocked()); } catch (IllegalStateException e) { assertEquals(Traversal.Exceptions.traversalIsLocked().getMessage(), e.getMessage()); } catch (Exception e) { fail("Should throw: " + Traversal.Exceptions.traversalIsLocked() + " not " + e + ":" + e.getMessage()); } traversal.iterate(); assertFalse(traversal.hasNext()); }
@Test @LoadGraphWith public void shouldNeverPropagateANullValuedTraverser() { try { assertFalse(g.V().map(t -> null).hasNext()); assertEquals(0, g.V().map(t -> null).toList().size()); g.V().map(t -> null).sideEffect(t -> fail("this should not have happened")).iterate(); } catch (VerificationException e) { // its okay if lambdas can't be serialized by the test suite } }
@Test @LoadGraphWith @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_REMOVE_VERTICES) @IgnoreEngine(TraversalEngine.Type.COMPUTER) public void g_VX1_2_3_4X_name() { final Object vLop = convertToVertexId("lop"); g.V(vLop).drop().iterate(); final Traversal<Vertex, String> traversal = get_g_VX1_2_3_4X_name(convertToVertexId("marko"), convertToVertexId("vadas"), vLop, convertToVertexId("josh")); printTraversalForm(traversal); checkResults(Arrays.asList("marko", "vadas", "josh"), traversal); assertFalse(traversal.hasNext()); }
/** * 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 public void testUpdateEdgePropertyOfRemovingEdgeWithDrop() { HugeGraph graph = graph(); Edge edge = initEdgeTransfer(); graph.traversal().E(edge.id()).drop().iterate(); // Update on dirty vertex Assert.assertThrows(IllegalArgumentException.class, () -> { edge.property("message").remove(); }); Assert.assertThrows(IllegalArgumentException.class, () -> { edge.property("message", "*"); }); }
@Test @LoadGraphWith(MODERN) @IgnoreEngine(TraversalEngine.Type.COMPUTER) // we can't modify the graph in computer mode public void shouldProperlyHandleMetaProperties() throws Exception { graph.traversal().V().has("name", "marko").properties("name").property("alias", "okram").iterate(); final BulkLoaderVertexProgram blvp = BulkLoaderVertexProgram.build() .userSuppliedIds(true) .writeGraph(getWriteGraphConfiguration()).create(graph); graphProvider.getGraphComputer(graph).workers(1).program(blvp).submit().get(); assertGraphEquality(graph, getWriteGraph()); }
@Test @LoadGraphWith public void shouldNeverPropagateANoBulkTraverser() { try { assertFalse(g.V().dedup().sideEffect(t -> t.asAdmin().setBulk(0)).hasNext()); assertEquals(0, g.V().dedup().sideEffect(t -> t.asAdmin().setBulk(0)).toList().size()); g.V().dedup().sideEffect(t -> t.asAdmin().setBulk(0)).sideEffect(t -> fail("this should not have happened")).iterate(); } catch (VerificationException e) { // its okay if lambdas can't be serialized by the test suite } }
@Test public void testUpdateVertexPropertyOfRemovingVertexWithDrop() { HugeGraph graph = graph(); Vertex vertex = graph.addVertex(T.label, "author", "id", 1, "name", "Tom", "lived", "Beijing"); graph.tx().commit(); graph.traversal().V(vertex.id()).drop().iterate(); // Update on dirty vertex Assert.assertThrows(IllegalArgumentException.class, () -> { vertex.property("lived").remove(); }); Assert.assertThrows(IllegalArgumentException.class, () -> { vertex.property("lived", "Shanghai"); }); }
@Test @LoadGraphWith(MODERN) public void shouldFilterOnIterate() { final Traversal<Vertex,String> traversal = g.V().out().out().<String>values("name").aggregate("x").iterate(); assertFalse(traversal.hasNext()); assertEquals(2, traversal.asAdmin().getSideEffects().<BulkSet>get("x").size()); assertTrue(traversal.asAdmin().getSideEffects().<BulkSet>get("x").contains("ripple")); assertTrue(traversal.asAdmin().getSideEffects().<BulkSet>get("x").contains("lop")); assertEquals(Traversal.Symbols.none, traversal.asAdmin().getBytecode().getStepInstructions().get(traversal.asAdmin().getBytecode().getStepInstructions().size()-1).getOperator()); }
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_REMOVE_EDGES) public void shouldTriggerRemoveEdge() { 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 v = graph.addVertex("some", "thing"); v.addEdge("self", v); final GraphTraversalSource gts = create(eventStrategy); gts.E().drop().iterate(); tryCommit(graph); assertEquals(1, listener1.edgeRemovedEventRecorded()); assertEquals(1, listener2.edgeRemovedEventRecorded()); }
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_REMOVE_VERTICES) public void shouldTriggerRemoveVertex() { 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().drop().iterate(); tryCommit(graph, g -> assertEquals(0, IteratorUtils.count(gts.V()))); assertEquals(1, listener1.vertexRemovedEventRecorded()); assertEquals(1, listener2.vertexRemovedEventRecorded()); }
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_REMOVE_PROPERTY) public void shouldTriggerRemoveVertexProperty() { 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().properties().drop().iterate(); tryCommit(graph, g -> assertEquals(0, IteratorUtils.count(gts.V().properties()))); assertEquals(1, listener1.vertexPropertyRemovedEventRecorded()); assertEquals(1, listener2.vertexPropertyRemovedEventRecorded()); }
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE) @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_REMOVE_PROPERTY) public void shouldTriggerRemoveEdgeProperty() { 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 v = graph.addVertex(); v.addEdge("self", v, "some", "thing"); final GraphTraversalSource gts = create(eventStrategy); gts.E().properties().drop().iterate(); tryCommit(graph, g -> assertEquals(0, IteratorUtils.count(gts.E().properties()))); assertEquals(1, listener1.edgePropertyRemovedEventRecorded()); assertEquals(1, listener2.edgePropertyRemovedEventRecorded()); }
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_META_PROPERTIES) public void shouldTriggerAddVertexPropertyPropertyRemoved() { 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(); gts.V(vAny).properties("any").properties("is").drop().iterate(); 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()); assertEquals(1, listener2.vertexPropertyPropertyRemovedEventRecorded()); assertEquals(1, listener1.vertexPropertyPropertyRemovedEventRecorded()); }