Search in sources :

Example 6 with Kneighbor

use of com.baidu.hugegraph.structure.traverser.Kneighbor in project incubator-hugegraph-toolchain by apache.

the class KneighborApiTest method testKneighborPostWithLimit.

@Test
public void testKneighborPostWithLimit() {
    Object markoId = getVertexId("person", "name", "marko");
    Object rippleId = getVertexId("software", "name", "ripple");
    Object joshId = getVertexId("person", "name", "josh");
    Object lopId = getVertexId("software", "name", "lop");
    Object vadasId = getVertexId("person", "name", "vadas");
    Object peterId = getVertexId("person", "name", "peter");
    // 1 depth with in&out edges
    KneighborRequest.Builder builder = KneighborRequest.builder();
    builder.source(markoId);
    builder.step().direction(Direction.BOTH);
    builder.maxDepth(1);
    builder.limit(3);
    KneighborRequest request = builder.build();
    Kneighbor kneighborResult = kneighborAPI.post(request);
    Assert.assertEquals(3, kneighborResult.size());
    Set<Object> expected = ImmutableSet.of(vadasId, lopId, joshId);
    Assert.assertTrue(expected.containsAll(kneighborResult.ids()));
    // 2 depth with out edges
    builder = KneighborRequest.builder();
    builder.source(markoId);
    builder.step().direction(Direction.OUT);
    builder.maxDepth(2);
    builder.limit(5);
    request = builder.build();
    kneighborResult = kneighborAPI.post(request);
    Assert.assertEquals(4, kneighborResult.size());
    expected = ImmutableSet.of(vadasId, lopId, joshId, rippleId);
    Assert.assertTrue(expected.containsAll(kneighborResult.ids()));
    // 2 depth with in&out edges
    builder = KneighborRequest.builder();
    builder.source(markoId);
    builder.step().direction(Direction.BOTH);
    builder.maxDepth(2);
    builder.limit(5);
    request = builder.build();
    kneighborResult = kneighborAPI.post(request);
    Assert.assertEquals(5, kneighborResult.size());
    expected = ImmutableSet.of(vadasId, lopId, joshId, peterId, rippleId);
    Assert.assertTrue(expected.containsAll(kneighborResult.ids()));
}
Also used : Kneighbor(com.baidu.hugegraph.structure.traverser.Kneighbor) KneighborRequest(com.baidu.hugegraph.structure.traverser.KneighborRequest) Test(org.junit.Test) BaseApiTest(com.baidu.hugegraph.api.BaseApiTest)

Example 7 with Kneighbor

use of com.baidu.hugegraph.structure.traverser.Kneighbor in project incubator-hugegraph-toolchain by apache.

the class KneighborApiTest method testKneighborPostWithCountOnly.

@Test
public void testKneighborPostWithCountOnly() {
    Object markoId = getVertexId("person", "name", "marko");
    KneighborRequest.Builder builder = KneighborRequest.builder();
    builder.source(markoId);
    builder.step().direction(Direction.BOTH);
    builder.maxDepth(1);
    builder.countOnly(true);
    KneighborRequest request = builder.build();
    Kneighbor kneighborResult = kneighborAPI.post(request);
    Assert.assertEquals(3, kneighborResult.size());
    Assert.assertTrue(kneighborResult.ids().isEmpty());
    Assert.assertTrue(kneighborResult.paths().isEmpty());
    Assert.assertTrue(kneighborResult.vertices().isEmpty());
    builder = KneighborRequest.builder();
    builder.source(markoId);
    builder.step().direction(Direction.BOTH);
    builder.maxDepth(2);
    builder.countOnly(true);
    request = builder.build();
    kneighborResult = kneighborAPI.post(request);
    Assert.assertEquals(5, kneighborResult.size());
    Assert.assertTrue(kneighborResult.ids().isEmpty());
    Assert.assertTrue(kneighborResult.paths().isEmpty());
    Assert.assertTrue(kneighborResult.vertices().isEmpty());
    builder = KneighborRequest.builder();
    builder.source(markoId);
    builder.step().direction(Direction.BOTH);
    builder.maxDepth(1);
    builder.countOnly(true);
    builder.withPath(true);
    KneighborRequest.Builder finalBuilder = builder;
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        finalBuilder.build();
    });
    builder = KneighborRequest.builder();
    builder.source(markoId);
    builder.step().direction(Direction.BOTH);
    builder.maxDepth(1);
    builder.countOnly(true);
    builder.withVertex(true);
    KneighborRequest.Builder finalBuilder1 = builder;
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        finalBuilder1.build();
    });
}
Also used : Kneighbor(com.baidu.hugegraph.structure.traverser.Kneighbor) KneighborRequest(com.baidu.hugegraph.structure.traverser.KneighborRequest) Test(org.junit.Test) BaseApiTest(com.baidu.hugegraph.api.BaseApiTest)

Example 8 with Kneighbor

use of com.baidu.hugegraph.structure.traverser.Kneighbor in project incubator-hugegraph-toolchain by apache.

the class KneighborApiTest method testKneighborPost.

@Test
public void testKneighborPost() {
    Object markoId = getVertexId("person", "name", "marko");
    Object rippleId = getVertexId("software", "name", "ripple");
    Object joshId = getVertexId("person", "name", "josh");
    Object lopId = getVertexId("software", "name", "lop");
    Object vadasId = getVertexId("person", "name", "vadas");
    Object peterId = getVertexId("person", "name", "peter");
    KneighborRequest.Builder builder = KneighborRequest.builder();
    builder.source(markoId);
    builder.step().direction(Direction.BOTH);
    builder.maxDepth(1);
    KneighborRequest request = builder.build();
    Kneighbor kneighborResult = kneighborAPI.post(request);
    Assert.assertEquals(3, kneighborResult.size());
    Set<Object> expected = ImmutableSet.of(vadasId, lopId, joshId);
    Assert.assertEquals(expected, kneighborResult.ids());
    builder = KneighborRequest.builder();
    builder.source(markoId);
    builder.step().direction(Direction.BOTH);
    builder.maxDepth(2);
    request = builder.build();
    kneighborResult = kneighborAPI.post(request);
    Assert.assertEquals(5, kneighborResult.size());
    expected = ImmutableSet.of(vadasId, lopId, joshId, peterId, rippleId);
    Assert.assertEquals(expected, kneighborResult.ids());
}
Also used : Kneighbor(com.baidu.hugegraph.structure.traverser.Kneighbor) KneighborRequest(com.baidu.hugegraph.structure.traverser.KneighborRequest) Test(org.junit.Test) BaseApiTest(com.baidu.hugegraph.api.BaseApiTest)

Aggregations

BaseApiTest (com.baidu.hugegraph.api.BaseApiTest)8 Kneighbor (com.baidu.hugegraph.structure.traverser.Kneighbor)8 KneighborRequest (com.baidu.hugegraph.structure.traverser.KneighborRequest)8 Test (org.junit.Test)8 Path (com.baidu.hugegraph.structure.graph.Path)2 Vertex (com.baidu.hugegraph.structure.graph.Vertex)1 ImmutableList (com.google.common.collect.ImmutableList)1 List (java.util.List)1