Search in sources :

Example 21 with Path

use of com.baidu.hugegraph.structure.graph.Path in project incubator-hugegraph-toolchain by apache.

the class PathSerializerTest method testSerializeAndDeserializePathWithVertexAndEdge.

@Test
public void testSerializeAndDeserializePathWithVertexAndEdge() {
    Vertex vertex = new Vertex("person");
    vertex.id("person:marko");
    vertex.property("name", "marko");
    vertex.property("age", 29);
    vertex.property("city", "Beijing");
    Edge edge = new Edge("knows");
    edge.id("person:marko>knows>>person:vadas");
    edge.sourceId("person:marko");
    edge.sourceLabel("person");
    edge.targetId("person:vadas");
    edge.targetLabel("person");
    edge.property("date", "2016-01-10");
    edge.property("weight", 0.5);
    Path path = new Path();
    path.labels(ImmutableList.of());
    path.labels(ImmutableList.of());
    path.objects(vertex);
    path.objects(edge);
    String json = serialize(path);
    Path pathCopy = deserialize(json, Path.class);
    Assert.assertEquals(2, pathCopy.objects().size());
    Utils.assertGraphEqual(ImmutableList.of(vertex), ImmutableList.of(edge), path.objects());
}
Also used : Path(com.baidu.hugegraph.structure.graph.Path) Vertex(com.baidu.hugegraph.structure.graph.Vertex) Edge(com.baidu.hugegraph.structure.graph.Edge) Test(org.junit.Test)

Example 22 with Path

use of com.baidu.hugegraph.structure.graph.Path in project incubator-hugegraph-toolchain by apache.

the class CommonTraverserApiTest method testCustomizedCrosspoints.

@Test
public void testCustomizedCrosspoints() {
    Object lopId = getVertexId("software", "name", "lop");
    Object joshId = getVertexId("person", "name", "josh");
    Object rippleId = getVertexId("software", "name", "ripple");
    CrosspointsRequest.Builder builder = CrosspointsRequest.builder();
    builder.sources().ids(lopId, rippleId);
    builder.pathPatterns().steps().direction(Direction.IN).labels("created").degree(-1);
    builder.withPath(true).withVertex(true).capacity(-1).limit(-1);
    CustomizedCrosspoints customizedCrosspoints = customizedCrosspointsAPI.post(builder.build());
    List<Object> crosspoints = customizedCrosspoints.crosspoints();
    Assert.assertEquals(1, crosspoints.size());
    Assert.assertEquals(joshId, crosspoints.get(0));
    List<Path> paths = customizedCrosspoints.paths();
    Assert.assertEquals(2, paths.size());
    List<Object> path1 = ImmutableList.of(rippleId, joshId);
    List<Object> path2 = ImmutableList.of(lopId, joshId);
    List<List<Object>> expectedPaths = ImmutableList.of(path1, path2);
    Assert.assertTrue(expectedPaths.contains(paths.get(0).objects()));
    Assert.assertTrue(expectedPaths.contains(paths.get(1).objects()));
    Set<?> vertices = customizedCrosspoints.vertices().stream().map(Vertex::id).collect(Collectors.toSet());
    List<Object> expectedVids = ImmutableList.of(rippleId, joshId, lopId);
    Assert.assertTrue(expectedVids.containsAll(vertices));
}
Also used : Path(com.baidu.hugegraph.structure.graph.Path) CrosspointsRequest(com.baidu.hugegraph.structure.traverser.CrosspointsRequest) CustomizedCrosspoints(com.baidu.hugegraph.structure.traverser.CustomizedCrosspoints) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) LinkedList(java.util.LinkedList) Test(org.junit.Test) BaseApiTest(com.baidu.hugegraph.api.BaseApiTest)

Example 23 with Path

use of com.baidu.hugegraph.structure.graph.Path in project incubator-hugegraph-toolchain by apache.

the class AllShortestPathsApiTest method testAllShortestPathWithMaxDepth.

@Test
public void testAllShortestPathWithMaxDepth() {
    List<Path> paths = allShortestPathsAPI.get(14, 6, Direction.BOTH, null, 4, 5L, 0L, 19L);
    Assert.assertEquals(1, paths.size());
    Path path = paths.get(0);
    Assert.assertEquals(ImmutableList.of(14, 7, 8, 9, 6), path.objects());
    paths = allShortestPathsAPI.get(14, 6, Direction.BOTH, null, 3, 5L, 0L, 19L);
    Assert.assertEquals(0, paths.size());
}
Also used : Path(com.baidu.hugegraph.structure.graph.Path) Test(org.junit.Test)

Example 24 with Path

use of com.baidu.hugegraph.structure.graph.Path in project incubator-hugegraph-toolchain by apache.

the class AllShortestPathsApiTest method testAllShortestPathWithCapacity.

@Test
public void testAllShortestPathWithCapacity() {
    List<Path> paths = allShortestPathsAPI.get(1, 6, Direction.BOTH, null, 6, -1L, 0L, -1L);
    Assert.assertEquals(4, paths.size());
    List<List<Object>> expected = ImmutableList.of(ImmutableList.of(1, 10, 11, 6), ImmutableList.of(1, 19, 20, 6), ImmutableList.of(1, 21, 22, 6), ImmutableList.of(1, 23, 24, 6));
    for (Path path : paths) {
        Assert.assertTrue(expected.contains(path.objects()));
    }
    Assert.assertThrows(ServerException.class, () -> {
        allShortestPathsAPI.get(1, 6, Direction.BOTH, null, 6, 6, 0L, 10L);
    }, e -> {
        String expect = "Exceed capacity '10' while finding shortest path";
        Assert.assertContains(expect, e.getMessage());
    });
}
Also used : Path(com.baidu.hugegraph.structure.graph.Path) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Test(org.junit.Test)

Example 25 with Path

use of com.baidu.hugegraph.structure.graph.Path in project incubator-hugegraph-toolchain by apache.

the class AllShortestPathsApiTest method testAllShortestPathWithLabel.

@Test
public void testAllShortestPathWithLabel() {
    List<Path> paths = allShortestPathsAPI.get(1, 6, Direction.BOTH, "link", 6, -1L, 0L, -1L);
    Assert.assertEquals(4, paths.size());
    List<List<Object>> expected = ImmutableList.of(ImmutableList.of(1, 10, 11, 6), ImmutableList.of(1, 19, 20, 6), ImmutableList.of(1, 21, 22, 6), ImmutableList.of(1, 23, 24, 6));
    for (Path path : paths) {
        Assert.assertTrue(expected.contains(path.objects()));
    }
}
Also used : Path(com.baidu.hugegraph.structure.graph.Path) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Test(org.junit.Test)

Aggregations

Path (com.baidu.hugegraph.structure.graph.Path)30 Test (org.junit.Test)21 Vertex (com.baidu.hugegraph.structure.graph.Vertex)11 Edge (com.baidu.hugegraph.structure.graph.Edge)9 List (java.util.List)9 ImmutableList (com.google.common.collect.ImmutableList)7 BaseApiTest (com.baidu.hugegraph.api.BaseApiTest)6 Result (com.baidu.hugegraph.structure.gremlin.Result)6 HugeClient (com.baidu.hugegraph.driver.HugeClient)4 GraphView (com.baidu.hugegraph.entity.query.GraphView)4 ResultSet (com.baidu.hugegraph.structure.gremlin.ResultSet)4 ArrayList (java.util.ArrayList)4 GremlinResult (com.baidu.hugegraph.entity.query.GremlinResult)3 TableView (com.baidu.hugegraph.entity.query.TableView)3 TypedResult (com.baidu.hugegraph.entity.query.TypedResult)3 HashMap (java.util.HashMap)3 GremlinRequest (com.baidu.hugegraph.api.gremlin.GremlinRequest)2 Type (com.baidu.hugegraph.entity.query.GremlinResult.Type)2 JsonView (com.baidu.hugegraph.entity.query.JsonView)2 RestResult (com.baidu.hugegraph.rest.RestResult)2