in hugegraph-test/src/main/java/org/apache/hugegraph/core/EdgeCoreTest.java [3402:3504]
public void testQueryAdjacentVerticesOfEdgesWithoutVertexAndNoLazyLoad()
throws InterruptedException, ExecutionException {
HugeGraph graph = graph();
Vertex james = graph.addVertex(T.label, "author", "id", 1,
"name", "James Gosling", "age", 62,
"lived", "Canadian");
Vertex java = new HugeVertex(graph, IdGenerator.of("java"),
graph.vertexLabel("book"));
james.addEdge("authored", java, "score", 3);
graph.tx().commit();
Whitebox.setInternalState(params().graphTransaction(),
"lazyLoadAdjacentVertex", false);
try {
List<Edge> edges = graph.traversal().V(james.id()).outE().toList();
Assert.assertEquals(1, edges.size());
Assert.assertEquals(0, graph.traversal().V(java).toList().size());
List<Vertex> vertices = graph.traversal().V(james.id())
.out().toList();
Assert.assertEquals(1, vertices.size());
HugeVertex adjacent = (HugeVertex) vertices.get(0);
Assert.assertTrue("label: " + adjacent.schemaLabel(),
adjacent.schemaLabel().undefined());
Assert.assertEquals("~undefined", adjacent.label());
vertices = graph.traversal().V(james.id()).outE().otherV().toList();
Assert.assertEquals(1, vertices.size());
adjacent = (HugeVertex) vertices.get(0);
Assert.assertTrue(adjacent.schemaLabel().undefined());
Assert.assertEquals("~undefined", adjacent.label());
vertices = graph.traversal().V(james.id()).outE()
.has("score", 3).otherV().toList();
Assert.assertEquals(1, vertices.size());
adjacent = (HugeVertex) vertices.get(0);
// NOTE: if not load, adjacent.label() will return 'book'
Assert.assertEquals("book", adjacent.label());
adjacent.forceLoad();
Assert.assertTrue(adjacent.schemaLabel().undefined());
Assert.assertEquals("~undefined", adjacent.label());
Assert.assertFalse(adjacent.properties().hasNext());
vertices = graph.traversal().V(james.id()).outE()
.has("score", 3).otherV().toList();
Assert.assertEquals(1, vertices.size());
adjacent = (HugeVertex) vertices.get(0);
Assert.assertTrue(adjacent.schemaLabel().undefined());
Assert.assertEquals("~undefined", adjacent.label());
} finally {
Whitebox.setInternalState(params().graphTransaction(),
"lazyLoadAdjacentVertex", true);
}
Whitebox.setInternalState(params().graphTransaction(),
"lazyLoadAdjacentVertex", false);
Whitebox.setInternalState(params().graphTransaction(),
"checkAdjacentVertexExist", true);
params().graphEventHub().notify(Events.CACHE, "clear", null).get();
try {
Assert.assertEquals(0, graph.traversal().V(java).toList().size());
Assert.assertThrows(HugeException.class, () -> {
graph.traversal().V(james.id()).out().toList();
}, e -> {
Assert.assertContains("Vertex 'java' does not exist",
e.getMessage());
});
Assert.assertThrows(HugeException.class, () -> {
graph.traversal().V(james.id()).outE().otherV().toList();
}, e -> {
Assert.assertContains("Vertex 'java' does not exist",
e.getMessage());
});
Assert.assertThrows(HugeException.class, () -> {
Vertex v = graph.traversal().V(james.id()).outE()
.has("score", 3).otherV().next();
v.properties(); // throw
}, e -> {
Assert.assertContains("Vertex 'java' does not exist",
e.getMessage());
});
Assert.assertThrows(HugeException.class, () -> {
Vertex v = graph.traversal().V(james.id()).outE()
.has("score", 3).otherV().next();
v.values(); // throw
}, e -> {
Assert.assertContains("Vertex 'java' does not exist",
e.getMessage());
});
} finally {
Whitebox.setInternalState(params().graphTransaction(),
"lazyLoadAdjacentVertex", true);
Whitebox.setInternalState(params().graphTransaction(),
"checkAdjacentVertexExist", false);
}
}