use of com.baidu.hugegraph.structure.HugeVertex in project incubator-hugegraph by apache.
the class EdgeCoreTest method testQueryAdjacentVerticesOfEdgesWithoutVertexAndNoLazyLoad.
@Test
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();
// throw
v.properties();
}, 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();
// throw
v.values();
}, e -> {
Assert.assertContains("Vertex 'java' does not exist", e.getMessage());
});
} finally {
Whitebox.setInternalState(params().graphTransaction(), "lazyLoadAdjacentVertex", true);
Whitebox.setInternalState(params().graphTransaction(), "checkAdjacentVertexExist", false);
}
}
use of com.baidu.hugegraph.structure.HugeVertex in project incubator-hugegraph by apache.
the class VertexAPI method update.
@PUT
@Timed(name = "single-update")
@Path("{id}")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON_WITH_CHARSET)
@RolesAllowed({ "admin", "$owner=$graph $action=vertex_write" })
public String update(@Context GraphManager manager, @PathParam("graph") String graph, @PathParam("id") String idValue, @QueryParam("action") String action, JsonVertex jsonVertex) {
LOG.debug("Graph [{}] update vertex: {}", graph, jsonVertex);
checkUpdatingBody(jsonVertex);
Id id = checkAndParseVertexId(idValue);
// Parse action param
boolean append = checkAndParseAction(action);
HugeGraph g = graph(manager, graph);
HugeVertex vertex = (HugeVertex) g.vertex(id);
VertexLabel vertexLabel = vertex.schemaLabel();
for (String key : jsonVertex.properties.keySet()) {
PropertyKey pkey = g.propertyKey(key);
E.checkArgument(vertexLabel.properties().contains(pkey.id()), "Can't update property for vertex '%s' because " + "there is no property key '%s' in its vertex label", id, key);
}
commit(g, () -> updateProperties(vertex, jsonVertex, append));
return manager.serializer(g).writeVertex(vertex);
}
use of com.baidu.hugegraph.structure.HugeVertex in project incubator-hugegraph by apache.
the class HugeVariables method createVariableVertex.
private void createVariableVertex(String key, Object value) {
VertexLabel vl = this.variableVertexLabel();
GraphTransaction tx = this.params.graphTransaction();
HugeVertex vertex = HugeVertex.create(tx, null, vl);
try {
this.setProperty(vertex, key, value);
} catch (IllegalArgumentException e) {
throw Graph.Variables.Exceptions.dataTypeOfVariableValueNotSupported(value, e);
}
// PrimaryKey id
vertex.assignId(null);
tx.addVertex(vertex);
}
use of com.baidu.hugegraph.structure.HugeVertex in project incubator-hugegraph by apache.
the class BinaryScatterSerializerTest method testVertex.
@Test
public void testVertex() {
HugeConfig config = FakeObjects.newConfig();
BinaryScatterSerializer ser = new BinaryScatterSerializer(config);
HugeEdge edge = new FakeObjects().newEdge(123, 456);
BackendEntry entry1 = ser.writeVertex(edge.sourceVertex());
HugeVertex vertex1 = ser.readVertex(edge.graph(), entry1);
Assert.assertEquals(edge.sourceVertex(), vertex1);
assertCollectionEquals(edge.sourceVertex().getProperties(), vertex1.getProperties());
BackendEntry entry2 = ser.writeVertex(edge.targetVertex());
HugeVertex vertex2 = ser.readVertex(edge.graph(), entry2);
Assert.assertEquals(edge.targetVertex(), vertex2);
assertCollectionEquals(edge.targetVertex().getProperties(), vertex2.getProperties());
Whitebox.setInternalState(vertex2, "removed", true);
Assert.assertTrue(vertex2.removed());
BackendEntry entry3 = ser.writeVertex(vertex2);
Assert.assertEquals(0, entry3.columnsSize());
Assert.assertNull(ser.readVertex(edge.graph(), null));
}
use of com.baidu.hugegraph.structure.HugeVertex in project incubator-hugegraph by apache.
the class BinarySerializerTest method testVertexForPartition.
@Test
public void testVertexForPartition() {
BinarySerializer ser = new BinarySerializer(true, true, true);
HugeEdge edge = new FakeObjects().newEdge("123", "456");
BackendEntry entry1 = ser.writeVertex(edge.sourceVertex());
HugeVertex vertex1 = ser.readVertex(edge.graph(), entry1);
Assert.assertEquals(edge.sourceVertex(), vertex1);
assertCollectionEquals(edge.sourceVertex().getProperties(), vertex1.getProperties());
BackendEntry entry2 = ser.writeVertex(edge.targetVertex());
HugeVertex vertex2 = ser.readVertex(edge.graph(), entry2);
Assert.assertEquals(edge.targetVertex(), vertex2);
assertCollectionEquals(edge.targetVertex().getProperties(), vertex2.getProperties());
Whitebox.setInternalState(vertex2, "removed", true);
Assert.assertTrue(vertex2.removed());
BackendEntry entry3 = ser.writeVertex(vertex2);
Assert.assertEquals(0, entry3.columnsSize());
Assert.assertNull(ser.readVertex(edge.graph(), null));
}
Aggregations