in hugegraph-test/src/main/java/org/apache/hugegraph/core/EdgeCoreTest.java [3195:3325]
public void testQueryAdjacentVerticesOfEdgesWithoutVertex()
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();
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.assertFalse(adjacent.schemaLabel().undefined());
adjacent.forceLoad(); // force load
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.isPropLoaded());
Assert.assertTrue(adjacent.schemaLabel().undefined());
adjacent.forceLoad();
Assert.assertTrue(adjacent.schemaLabel().undefined());
Assert.assertEquals("~undefined", adjacent.label());
params().graphEventHub().notify(Events.CACHE, "clear", null).get();
vertices = graph.traversal().V(james.id()).outE().otherV().toList();
Assert.assertEquals(1, vertices.size());
adjacent = (HugeVertex) vertices.get(0);
Assert.assertFalse(adjacent.isPropLoaded());
Assert.assertFalse(adjacent.schemaLabel().undefined());
adjacent.forceLoad();
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);
adjacent.forceLoad();
// NOTE: if not commit, adjacent.label() will return 'book'
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());
Whitebox.setInternalState(params().graphTransaction(),
"checkAdjacentVertexExist", true);
try {
Assert.assertThrows(HugeException.class, () -> {
// read from cache
graph.traversal().V(james.id()).outE().has("score", 3)
.otherV().values().toList();
}, e -> {
Assert.assertContains("Vertex 'java' does not exist",
e.getMessage());
});
} finally {
Whitebox.setInternalState(params().graphTransaction(),
"checkAdjacentVertexExist", 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().values().toList();
}, e -> {
Assert.assertContains("Vertex 'java' does not exist",
e.getMessage());
});
Assert.assertThrows(HugeException.class, () -> {
graph.traversal().V(james.id()).outE().otherV()
.values().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());
});
Assert.assertThrows(HugeException.class, () -> {
Vertex v = graph.traversal().V(james.id()).outE()
.has("score", 3).otherV().next();
((HugeVertex) v).forceLoad(); // throw
}, e -> {
Assert.assertContains("Vertex 'java' does not exist",
e.getMessage());
});
} finally {
Whitebox.setInternalState(params().graphTransaction(),
"checkAdjacentVertexExist", false);
}
}