use of com.baidu.hugegraph.structure.traverser.KneighborRequest in project incubator-hugegraph-toolchain by apache.
the class KneighborApiTest method testKneighborPostWithVertex.
@Test
public void testKneighborPostWithVertex() {
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);
builder.withPath(false);
builder.withVertex(true);
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());
Assert.assertEquals(3, kneighborResult.vertices().size());
Set<Object> expectedVids = ImmutableSet.of(vadasId, lopId, joshId);
for (Vertex vertex : kneighborResult.vertices()) {
Assert.assertTrue(expectedVids.contains(vertex.id()));
}
builder = KneighborRequest.builder();
builder.source(markoId);
builder.step().direction(Direction.BOTH);
builder.maxDepth(2);
builder.withPath(false);
builder.withVertex(true);
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());
Assert.assertEquals(5, kneighborResult.vertices().size());
expectedVids = ImmutableSet.of(vadasId, lopId, joshId, peterId, rippleId);
for (Vertex vertex : kneighborResult.vertices()) {
Assert.assertTrue(expectedVids.contains(vertex.id()));
}
builder = KneighborRequest.builder();
builder.source(markoId);
builder.step().direction(Direction.BOTH);
builder.maxDepth(1);
builder.withPath(true);
builder.withVertex(true);
request = builder.build();
kneighborResult = kneighborAPI.post(request);
Assert.assertEquals(3, kneighborResult.size());
expected = ImmutableSet.of(vadasId, lopId, joshId);
Assert.assertEquals(expected, kneighborResult.ids());
Assert.assertEquals(3, kneighborResult.paths().size());
Set<List<Object>> expectedPaths = ImmutableSet.of(ImmutableList.of(markoId, vadasId), ImmutableList.of(markoId, lopId), ImmutableList.of(markoId, joshId));
for (Path path : kneighborResult.paths()) {
Assert.assertTrue(expectedPaths.contains(path.objects()));
}
Assert.assertEquals(4, kneighborResult.vertices().size());
expectedVids = ImmutableSet.of(markoId, vadasId, lopId, joshId);
for (Vertex vertex : kneighborResult.vertices()) {
Assert.assertTrue(expectedVids.contains(vertex.id()));
}
builder = KneighborRequest.builder();
builder.source(markoId);
builder.step().direction(Direction.BOTH);
builder.maxDepth(2);
builder.withPath(true);
builder.withVertex(true);
request = builder.build();
kneighborResult = kneighborAPI.post(request);
Assert.assertEquals(5, kneighborResult.size());
expected = ImmutableSet.of(peterId, lopId, joshId, rippleId, vadasId);
Assert.assertEquals(expected, kneighborResult.ids());
Assert.assertEquals(5, kneighborResult.paths().size());
expectedPaths = ImmutableSet.of(ImmutableList.of(markoId, vadasId), ImmutableList.of(markoId, lopId), ImmutableList.of(markoId, joshId), ImmutableList.of(markoId, lopId, peterId), ImmutableList.of(markoId, joshId, rippleId));
for (Path path : kneighborResult.paths()) {
Assert.assertTrue(expectedPaths.contains(path.objects()));
}
Assert.assertEquals(6, kneighborResult.vertices().size());
expectedVids = ImmutableSet.of(markoId, peterId, lopId, joshId, rippleId, vadasId);
for (Vertex vertex : kneighborResult.vertices()) {
Assert.assertTrue(expectedVids.contains(vertex.id()));
}
}
use of com.baidu.hugegraph.structure.traverser.KneighborRequest in project incubator-hugegraph-toolchain by apache.
the class KneighborApiTest method testKneighborPostWithDirection.
@Test
public void testKneighborPostWithDirection() {
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");
KneighborRequest.Builder builder = KneighborRequest.builder();
builder.source(markoId);
builder.step().direction(Direction.OUT);
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.OUT);
builder.maxDepth(2);
request = builder.build();
kneighborResult = kneighborAPI.post(request);
Assert.assertEquals(4, kneighborResult.size());
expected = ImmutableSet.of(vadasId, lopId, joshId, rippleId);
Assert.assertEquals(expected, kneighborResult.ids());
}
use of com.baidu.hugegraph.structure.traverser.KneighborRequest in project incubator-hugegraph-toolchain by apache.
the class KneighborApiTest method testKneighborPostWithLabel.
@Test
public void testKneighborPostWithLabel() {
Object markoId = getVertexId("person", "name", "marko");
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).labels("created");
builder.maxDepth(1);
KneighborRequest request = builder.build();
Kneighbor kneighborResult = kneighborAPI.post(request);
Assert.assertEquals(1, kneighborResult.size());
Set<Object> expected = ImmutableSet.of(lopId);
Assert.assertEquals(expected, kneighborResult.ids());
builder = KneighborRequest.builder();
builder.source(markoId);
builder.step().direction(Direction.BOTH).labels("created");
builder.maxDepth(2);
request = builder.build();
kneighborResult = kneighborAPI.post(request);
Assert.assertEquals(3, kneighborResult.size());
expected = ImmutableSet.of(lopId, peterId, joshId);
Assert.assertEquals(expected, kneighborResult.ids());
builder = KneighborRequest.builder();
builder.source(markoId);
builder.step().direction(Direction.BOTH).labels("knows");
builder.maxDepth(1);
request = builder.build();
kneighborResult = kneighborAPI.post(request);
Assert.assertEquals(2, kneighborResult.size());
expected = ImmutableSet.of(vadasId, joshId);
Assert.assertEquals(expected, kneighborResult.ids());
builder = KneighborRequest.builder();
builder.source(markoId);
builder.step().direction(Direction.BOTH).labels("knows");
builder.maxDepth(2);
request = builder.build();
kneighborResult = kneighborAPI.post(request);
Assert.assertEquals(2, kneighborResult.size());
expected = ImmutableSet.of(vadasId, joshId);
Assert.assertEquals(expected, kneighborResult.ids());
}
use of com.baidu.hugegraph.structure.traverser.KneighborRequest in project incubator-hugegraph-toolchain by apache.
the class KneighborApiTest method testKneighborPostWithPath.
@Test
public void testKneighborPostWithPath() {
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);
builder.withPath(true);
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());
Assert.assertEquals(3, kneighborResult.paths().size());
List<Object> expectedPaths = ImmutableList.of(ImmutableList.of(markoId, vadasId), ImmutableList.of(markoId, lopId), ImmutableList.of(markoId, joshId));
for (Path path : kneighborResult.paths()) {
Assert.assertTrue(expectedPaths.contains(path.objects()));
}
builder = KneighborRequest.builder();
builder.source(markoId);
builder.step().direction(Direction.BOTH);
builder.maxDepth(2);
builder.withPath(true);
request = builder.build();
kneighborResult = kneighborAPI.post(request);
Assert.assertEquals(5, kneighborResult.size());
expected = ImmutableSet.of(vadasId, peterId, joshId, lopId, rippleId);
Assert.assertEquals(expected, kneighborResult.ids());
Assert.assertEquals(5, kneighborResult.paths().size());
expectedPaths = ImmutableList.of(ImmutableList.of(markoId, vadasId), ImmutableList.of(markoId, lopId), ImmutableList.of(markoId, joshId), ImmutableList.of(markoId, lopId, peterId), ImmutableList.of(markoId, joshId, rippleId));
for (Path path : kneighborResult.paths()) {
Assert.assertTrue(expectedPaths.contains(path.objects()));
}
}
use of com.baidu.hugegraph.structure.traverser.KneighborRequest in project incubator-hugegraph-toolchain by apache.
the class KneighborApiTest method testKneighborPostWithProperties.
@Test
public void testKneighborPostWithProperties() {
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 peterId = getVertexId("person", "name", "peter");
KneighborRequest.Builder builder = KneighborRequest.builder();
builder.source(markoId);
builder.step().direction(Direction.BOTH).properties("date", "P.gt(\"2014-01-01 00:00:00\")");
builder.maxDepth(1);
KneighborRequest request = builder.build();
Kneighbor kneighborResult = kneighborAPI.post(request);
Assert.assertEquals(1, kneighborResult.size());
Set<Object> expected = ImmutableSet.of(lopId);
Assert.assertEquals(expected, kneighborResult.ids());
builder = KneighborRequest.builder();
builder.source(markoId);
builder.step().direction(Direction.BOTH).properties("date", "P.gt(\"2014-01-01 00:00:00\")");
builder.maxDepth(2);
request = builder.build();
kneighborResult = kneighborAPI.post(request);
Assert.assertEquals(3, kneighborResult.size());
expected = ImmutableSet.of(lopId, peterId, joshId);
Assert.assertEquals(expected, kneighborResult.ids());
builder = KneighborRequest.builder();
builder.source(markoId);
builder.step().direction(Direction.BOTH).properties("date", "P.gt(\"2014-01-01 00:00:00\")");
builder.maxDepth(3);
request = builder.build();
kneighborResult = kneighborAPI.post(request);
Assert.assertEquals(4, kneighborResult.size());
expected = ImmutableSet.of(lopId, peterId, joshId, rippleId);
Assert.assertEquals(expected, kneighborResult.ids());
}
Aggregations