use of com.baidu.hugegraph.structure.graph.Path in project incubator-hugegraph-toolchain by apache.
the class ShortestPathApiTest method testShortestPath.
@Test
public void testShortestPath() {
Path path = shortestPathAPI.get(1, 6, Direction.BOTH, null, 6, -1L, 0L, -1L);
Assert.assertEquals(4, path.size());
Assert.assertEquals(ImmutableList.of(1, 10, 11, 6), path.objects());
}
use of com.baidu.hugegraph.structure.graph.Path in project incubator-hugegraph-toolchain by apache.
the class ShortestPathApiTest method testShortestPathWithMaxDepth.
@Test
public void testShortestPathWithMaxDepth() {
Path path = shortestPathAPI.get(14, 6, Direction.BOTH, null, 4, 5L, 0L, 19L);
Assert.assertEquals(5, path.size());
Assert.assertEquals(ImmutableList.of(14, 7, 8, 9, 6), path.objects());
path = shortestPathAPI.get(14, 6, Direction.BOTH, null, 3, 5L, 0L, 19L);
Assert.assertEquals(0, path.size());
}
use of com.baidu.hugegraph.structure.graph.Path in project incubator-hugegraph-toolchain by apache.
the class ShortestPathApiTest method testShortestPathWithDegree.
@Test
public void testShortestPathWithDegree() {
Path path = shortestPathAPI.get(1, 6, Direction.OUT, null, 6, 1L, 0L, -1L);
/*
* Following results can be guaranteed in RocksDB backend,
* but different results exist in table type backend(like Cassandra).
*/
Assert.assertEquals(6, path.size());
Assert.assertEquals(ImmutableList.of(1, 2, 3, 4, 5, 6), path.objects());
}
use of com.baidu.hugegraph.structure.graph.Path in project incubator-hugegraph-toolchain by apache.
the class GremlinApiTest method testAttachedManager.
@Test
public void testAttachedManager() {
GremlinRequest request = new GremlinRequest("g.V()");
ResultSet resultSet = gremlin().execute(request);
Assert.assertEquals(6, resultSet.size());
Iterator<Result> results = resultSet.iterator();
while (results.hasNext()) {
Result result = results.next();
Object object = result.getObject();
Assert.assertEquals(Vertex.class, object.getClass());
Vertex vertex = (Vertex) object;
Assert.assertNotNull(Whitebox.getInternalState(vertex, "manager"));
}
request = new GremlinRequest("g.E()");
resultSet = gremlin().execute(request);
Assert.assertEquals(6, resultSet.size());
results = resultSet.iterator();
while (results.hasNext()) {
Result result = results.next();
Object object = result.getObject();
Assert.assertEquals(Edge.class, object.getClass());
Edge edge = (Edge) object;
Assert.assertNotNull(Whitebox.getInternalState(edge, "manager"));
}
request = new GremlinRequest("g.V().outE().path()");
resultSet = gremlin().execute(request);
Assert.assertEquals(6, resultSet.size());
results = resultSet.iterator();
while (results.hasNext()) {
Result result = results.next();
Object object = result.getObject();
Assert.assertEquals(Path.class, object.getClass());
Path path = (Path) object;
Assert.assertNotNull(path.objects());
for (Object pathObject : path.objects()) {
Assert.assertTrue(pathObject instanceof GraphAttachable);
Assert.assertNotNull(Whitebox.getInternalState(pathObject, "manager"));
}
Assert.assertNull(path.crosspoint());
}
}
use of com.baidu.hugegraph.structure.graph.Path in project incubator-hugegraph-toolchain by apache.
the class PathDeserializer method deserialize.
@Override
public Path deserialize(JsonParser parser, DeserializationContext ctxt) throws IOException {
JsonNode node = parser.getCodec().readTree(parser);
Path path = new Path();
// Parse node 'labels'
JsonNode labelsNode = node.get("labels");
if (labelsNode != null) {
if (labelsNode.getNodeType() != JsonNodeType.ARRAY) {
throw InvalidResponseException.expectField("labels", node);
}
Object labels = JsonUtil.convertValue(labelsNode, Object.class);
((List<?>) labels).forEach(path::labels);
}
// Parse node 'objects'
JsonNode objectsNode = node.get("objects");
if (objectsNode == null || objectsNode.getNodeType() != JsonNodeType.ARRAY) {
throw InvalidResponseException.expectField("objects", node);
}
Iterator<JsonNode> objects = objectsNode.elements();
while (objects.hasNext()) {
JsonNode objectNode = objects.next();
JsonNode typeNode = objectNode.get("type");
Object object;
if (typeNode != null) {
object = parseTypedNode(objectNode, typeNode);
} else {
object = JsonUtil.convertValue(objectNode, Object.class);
}
path.objects(object);
}
// Parse node 'crosspoint'
JsonNode crosspointNode = node.get("crosspoint");
if (crosspointNode != null) {
Object object = JsonUtil.convertValue(crosspointNode, Object.class);
path.crosspoint(object);
}
return path;
}
Aggregations