use of com.baidu.hugegraph.structure.traverser.KneighborRequest 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()));
}
use of com.baidu.hugegraph.structure.traverser.KneighborRequest 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();
});
}
use of com.baidu.hugegraph.structure.traverser.KneighborRequest 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());
}
Aggregations