@Test public void testTinkerPopOptimizationStrategies() { PropertyKey id = mgmt.makePropertyKey("id").cardinality(Cardinality.SINGLE).dataType(Integer.class).make(); assertNumStep(numV / 5, 1, gts.V(sv[0]).outE("knows").has("weight", 1), TitanVertexStep.class); assertNumStep(numV, 1, gts.V(sv[0]).outE("knows"), TitanVertexStep.class); assertNumStep(numV, 1, gts.V(sv[0]).out("knows"), TitanVertexStep.class); assertNumStep(10, 1, gts.V(sv[0]).local(__.outE("knows").limit(10)), TitanVertexStep.class); assertNumStep(10, 1, gts.V(sv[0]).local(__.outE("knows").range(10, 20)), LocalStep.class); assertNumStep(numV, 2, gts.V(sv[0]).outE("knows").order().by("weight", decr), TitanVertexStep.class, OrderGlobalStep.class); assertNumStep(10, 1, gts.V(sv[0]).local(__.outE("knows").order().by("weight", decr).limit(10)), TitanVertexStep.class); assertNumStep(numV / 5, 2, gts.V(sv[0]).outE("knows").has("weight", 1).order().by("weight", incr), TitanVertexStep.class, OrderGlobalStep.class); assertNumStep(10, 1, gts.V(sv[0]).local(__.outE("knows").has("weight", 1).order().by("weight", incr).limit(10)), TitanVertexStep.class); assertNumStep(5, 1, gts.V(sv[0]).local(__.outE("knows").has("weight", 1).has("weight", 1).order().by("weight", incr).range(10, 15)), LocalStep.class); assertNumStep(superV, 1, gts.V().has("id", sid), TitanGraphStep.class); assertNumStep(1, 1, gts.V().has("id", numV / 5).as("x"), TitanGraphStep.class); assertNumStep(1, 1, gts.V().has("id", numV / 5).has("weight", (numV / 5) % 5).as("x"), TitanGraphStep.class);
@Test @LoadGraphWith(MODERN) public void shouldFilterVertexCriterionAndKeepLabels() throws Exception { // this will exclude "peter" final Traversal<Vertex, ?> vertexCriterion = has("name", P.within("ripple", "josh", "marko")); final GraphTraversalSource sg = g.withStrategies(SubgraphStrategy.build().vertices(vertexCriterion).create()); assertEquals(9, g.V().as("a").out().in().as("b").dedup("a", "b").count().next().intValue()); assertEquals(2, sg.V().as("a").out().in().as("b").dedup("a", "b").count().next().intValue()); final List<Object> list = sg.V().as("a").out().in().as("b").dedup("a", "b").values("name").toList(); assertThat(list, hasItems("marko", "josh")); }
@Test @LoadGraphWith(MODERN) public void shouldFilterEdgeCriterion() throws Exception { assertEquals(6, g.V().count().next().longValue()); final Traversal t = sg.V(); t.hasNext(); printTraversalForm(t); assertEquals(6, sg.V().count().next().longValue()); assertEquals(6, g.E().count().next().longValue()); assertEquals(2, g.V(convertToVertexId("marko")).out("knows").count().next().longValue()); assertEquals(1, sg.V(convertToVertexId("marko")).out("knows").count().next().longValue()); assertEquals(2, g.V(convertToVertexId("josh")).out("created").count().next().longValue()); assertEquals(1, sg.V(convertToVertexId("josh")).out("created").count().next().longValue()); assertEquals(2, g.V(convertToVertexId("josh")).out().count().next().longValue()); assertEquals(1, sg.V(convertToVertexId("josh")).out().count().next().longValue()); assertEquals(1, g.V(convertToVertexId("josh")).in().count().next().longValue()); assertEquals(1, sg.V(convertToVertexId("josh")).in().count().next().longValue()); assertEquals(2, g.V(convertToVertexId("josh")).out("created").count().next().longValue()); assertEquals(1, sg.V(convertToVertexId("josh")).out("created").count().next().longValue()); assertEquals(1, g.V(convertToVertexId("josh")).in("knows").count().next().longValue());
@Test @LoadGraphWith(MODERN) public void shouldGenerateCorrectTraversers() throws Exception { traversal = itag.V().outE().iterate().asAdmin(); assertTrue(traversal.getTraverserGenerator() instanceof B_O_TraverserGenerator); traversal = itag.V().outE().inV().iterate().asAdmin(); assertTrue(traversal.getTraverserGenerator() instanceof B_O_TraverserGenerator); traversal = itag.V().outE().otherV().iterate().asAdmin(); assertTrue(traversal.getTraverserGenerator() instanceof B_O_TraverserGenerator); traversal = itag.V().out().iterate().asAdmin(); assertTrue(traversal.getTraverserGenerator() instanceof B_O_TraverserGenerator);
@Test @LoadGraphWith(LoadGraphWith.GraphData.MODERN) public void shouldSerializeTree() throws Exception { final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V1_0)).mapper().version(GraphSONVersion.V1_0).create().createMapper(); final Tree t = g.V(convertToVertexId("marko")).out().properties("name").tree().next(); final String json = mapper.writeValueAsString(t); assertEquals(1, m.size()); assertTrue(m.containsKey(convertToVertexId("marko").toString())); assertEquals(2, branch.size()); assertTrue(branch.containsKey(GraphSONTokens.KEY)); assertTrue(branch.containsKey(GraphSONTokens.VALUE)); assertTrue(branchKey.containsKey(GraphSONTokens.TYPE)); assertTrue(branchKey.containsKey(GraphSONTokens.PROPERTIES)); assertEquals(convertToVertexId("marko").toString(), branchKey.get(GraphSONTokens.ID).toString()); assertEquals("person", branchKey.get(GraphSONTokens.LABEL)); assertEquals("vertex", branchKey.get(GraphSONTokens.TYPE));
@Test @LoadGraphWith(MODERN) public void shouldFilterMixedCriteria() throws Exception { assertEquals(6, g.V().count().next().longValue()); assertEquals(3, sg.V().count().next().longValue()); assertEquals(6, g.E().count().next().longValue()); assertEquals(2, sg.E().count().next().longValue()); assertEquals(2, g.V(convertToVertexId("josh")).outE().count().next().longValue()); assertEquals(2, sg.V(convertToVertexId("josh")).outE().count().next().longValue()); assertEquals(2, g.V(convertToVertexId("josh")).out().count().next().longValue()); assertEquals(2, sg.V(convertToVertexId("josh")).out().count().next().longValue()); assertEquals(3, g.V(convertToVertexId("josh")).bothE().count().next().longValue()); assertEquals(2, g.V(convertToVertexId("josh")).outE("created").count().next().longValue()); assertEquals(2, sg.V(convertToVertexId("josh")).outE("created").count().next().longValue()); assertEquals(2, g.V(convertToVertexId("josh")).out("created").count().next().longValue()); assertEquals(2, sg.V(convertToVertexId("josh")).out("created").count().next().longValue()); assertEquals(2, g.V(convertToVertexId("josh")).bothE("created").count().next().longValue()); assertEquals(2, sg.V(convertToVertexId("josh")).bothE("created").count().next().longValue());
@Test public void testTinkerPopOptimizationStrategies() { PropertyKey id = mgmt.makePropertyKey("id").cardinality(Cardinality.SINGLE).dataType(Integer.class).make(); assertNumStep(numV / 5, 1, gts.V(sv[0]).outE("knows").has("weight", 1), JanusGraphVertexStep.class); assertNumStep(numV, 1, gts.V(sv[0]).outE("knows"), JanusGraphVertexStep.class); assertNumStep(numV, 1, gts.V(sv[0]).out("knows"), JanusGraphVertexStep.class); assertNumStep(10, 1, gts.V(sv[0]).local(__.outE("knows").limit(10)), JanusGraphVertexStep.class); assertNumStep(10, 1, gts.V(sv[0]).local(__.outE("knows").range(10, 20)), LocalStep.class); assertNumStep(numV, 2, gts.V(sv[0]).outE("knows").order().by("weight", decr), JanusGraphVertexStep.class, OrderGlobalStep.class); assertNumStep(10, 0, gts.V(sv[0]).local(__.outE("knows").order().by("weight", decr).limit(10)), LocalStep.class); assertNumStep(numV / 5, 2, gts.V(sv[0]).outE("knows").has("weight", 1).order().by("weight", incr), JanusGraphVertexStep.class, OrderGlobalStep.class); assertNumStep(10, 0, gts.V(sv[0]).local(__.outE("knows").has("weight", 1).order().by("weight", incr).limit(10)), LocalStep.class); assertNumStep(superV, 1, gts.V().has("id", sid), JanusGraphStep.class); assertNumStep(1, 1, gts.V().has("id", numV / 5).as("x"), JanusGraphStep.class); assertNumStep(1, 1, gts.V().has("id", numV / 5).has("weight", (numV / 5) % 5).as("x"), JanusGraphStep.class);
@Test @LoadGraphWith(MODERN) public void shouldGenerateCorrectTraversers() throws Exception { sg = g.withStrategies(strategy); traversal = sg.V().outE().iterate().asAdmin(); assertTrue(traversal.getTraverserGenerator() instanceof B_O_TraverserGenerator); traversal = sg.V().outE().inV().iterate().asAdmin(); assertTrue(traversal.getTraverserGenerator() instanceof B_O_TraverserGenerator); traversal = sg.V().out().iterate().asAdmin(); assertTrue(traversal.getTraverserGenerator() instanceof B_O_TraverserGenerator); sg = g.withStrategies(strategy); traversal = sg.V().out().iterate().asAdmin(); assertTrue(traversal.getTraverserGenerator() instanceof B_LP_O_P_S_SE_SL_TraverserGenerator);
@Test @LoadGraphWith(LoadGraphWith.GraphData.MODERN) @org.junit.Ignore("TINKERPOP-1509") public void shouldSerializeTree() throws Exception { final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().version(GraphSONVersion.V2_0).create().createMapper(); final Tree t = g.V(convertToVertexId("marko")).out().properties("name").tree().next(); final String json = mapper.writeValueAsString(t); assertEquals(1, m.size()); assertTrue(m.containsKey(convertToVertexId("marko").toString())); assertEquals(2, branch.size()); assertTrue(branch.containsKey(GraphSONTokens.KEY)); assertTrue(branch.containsKey(GraphSONTokens.VALUE)); assertTrue(branchKey.containsKey(GraphSONTokens.TYPE)); assertTrue(branchKey.containsKey(GraphSONTokens.PROPERTIES)); assertEquals(convertToVertexId("marko").toString(), branchKey.get(GraphSONTokens.ID).toString()); assertEquals("person", branchKey.get(GraphSONTokens.LABEL)); assertEquals("vertex", branchKey.get(GraphSONTokens.TYPE));
@Test @LoadGraphWith(MODERN) public void shouldFilterMixedCriteriaButNotCheckAdjacentVertices() { assertEquals(6, g.V().count().next().longValue()); assertEquals(3, sg.V().count().next().longValue()); assertEquals(6, g.E().count().next().longValue()); assertEquals(3, sg.E().count().next().longValue()); assertEquals(2, g.V(convertToVertexId("josh")).outE().count().next().longValue()); assertEquals(2, sg.V(convertToVertexId("josh")).outE().count().next().longValue()); assertEquals(2, g.V(convertToVertexId("josh")).out().count().next().longValue()); assertEquals(2, sg.V(convertToVertexId("josh")).out().count().next().longValue()); assertEquals(3, g.V(convertToVertexId("josh")).bothE().count().next().longValue()); assertEquals(2, g.V(convertToVertexId("josh")).outE("created").count().next().longValue()); assertEquals(2, sg.V(convertToVertexId("josh")).outE("created").count().next().longValue()); assertEquals(2, g.V(convertToVertexId("josh")).out("created").count().next().longValue()); assertEquals(2, sg.V(convertToVertexId("josh")).out("created").count().next().longValue()); assertEquals(2, g.V(convertToVertexId("josh")).bothE("created").count().next().longValue()); assertEquals(2, sg.V(convertToVertexId("josh")).bothE("created").count().next().longValue());
@Test public void testQueryOutVerticesOfVertexWithSortkey() { HugeGraph graph = graph(); init18Edges(); Vertex louise = vertex("person", "name", "Louise"); Assert.assertEquals(4, graph.traversal().V(louise.id()) .out("look").count().next().longValue()); List<Vertex> vertices = graph.traversal().V(louise.id()) .out("look").toList(); // Expect duplicated vertex "java-1" Assert.assertEquals(4, vertices.size()); }
@Test @LoadGraphWith(LoadGraphWith.GraphData.MODERN) @org.junit.Ignore("TINKERPOP-1509") public void shouldSerializeTree() throws Exception { final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V3_0)).mapper().version(GraphSONVersion.V3_0).create().createMapper(); final Tree t = g.V(convertToVertexId("marko")).out().properties("name").tree().next(); final String json = mapper.writeValueAsString(t); assertEquals(1, m.size()); assertTrue(m.containsKey(convertToVertexId("marko").toString())); assertEquals(2, branch.size()); assertTrue(branch.containsKey(GraphSONTokens.KEY)); assertTrue(branch.containsKey(GraphSONTokens.VALUE)); assertTrue(branchKey.containsKey(GraphSONTokens.TYPE)); assertTrue(branchKey.containsKey(GraphSONTokens.PROPERTIES)); assertEquals(convertToVertexId("marko").toString(), branchKey.get(GraphSONTokens.ID).toString()); assertEquals("person", branchKey.get(GraphSONTokens.LABEL)); assertEquals("vertex", branchKey.get(GraphSONTokens.TYPE));