use of com.baidu.hugegraph.structure.HugeVertex in project incubator-hugegraph by apache.
the class RamTableTest method testAddInvalidVertexOrEdge.
@Test
public void testAddInvalidVertexOrEdge() {
HugeGraph graph = this.graph();
VertexLabel vl3 = graph.vertexLabel("vl3");
EdgeLabel el3 = graph.edgeLabel("el3");
VertexLabel vl2 = graph.vertexLabel("vl2");
EdgeLabel el2 = graph.edgeLabel("el2");
RamTable table = new RamTable(graph, VERTEX_SIZE, EDGE_SIZE);
HugeVertex ownerVertex = new HugeVertex(graph, IdGenerator.of(1), vl3);
HugeEdge edge1 = HugeEdge.constructEdge(ownerVertex, true, el3, "marko", IdGenerator.of(2));
Assert.assertThrows(HugeException.class, () -> {
table.addEdge(true, edge1);
}, e -> {
Assert.assertContains("Only edge label without sortkey is " + "supported by ramtable, but got 'el3(id=3)'", e.getMessage());
});
HugeVertex v1 = new HugeVertex(graph, IdGenerator.of("s1"), vl2);
HugeEdge edge2 = HugeEdge.constructEdge(v1, true, el2, "marko", IdGenerator.of("s2"));
Assert.assertThrows(HugeException.class, () -> {
table.addEdge(true, edge2);
}, e -> {
Assert.assertContains("Only number id is supported by ramtable, " + "but got string id 's1'", e.getMessage());
});
HugeVertex v2 = new HugeVertex(graph, IdGenerator.of(2), vl2);
HugeEdge edge3 = HugeEdge.constructEdge(v2, true, el2, "marko", IdGenerator.of("s2"));
Assert.assertThrows(HugeException.class, () -> {
table.addEdge(true, edge3);
}, e -> {
Assert.assertContains("Only number id is supported by ramtable, " + "but got string id 's2'", e.getMessage());
});
}
use of com.baidu.hugegraph.structure.HugeVertex in project incubator-hugegraph by apache.
the class CachedGraphTransactionTest method newVertex.
private HugeVertex newVertex(Id id) {
HugeGraph graph = this.cache().graph();
graph.schema().propertyKey("name").asText().checkExist(false).create();
graph.schema().vertexLabel("person").idStrategy(IdStrategy.CUSTOMIZE_NUMBER).properties("name").nullableKeys("name").checkExist(false).create();
VertexLabel vl = graph.vertexLabel("person");
return new HugeVertex(graph, id, vl);
}
use of com.baidu.hugegraph.structure.HugeVertex in project incubator-hugegraph by apache.
the class CachedGraphTransactionTest method testEdgeCacheClearWhenUpdateVertex.
@Test
public void testEdgeCacheClearWhenUpdateVertex() {
CachedGraphTransaction cache = this.cache();
HugeVertex v1 = this.newVertex(IdGenerator.of(1));
HugeVertex v2 = this.newVertex(IdGenerator.of(2));
HugeVertex v3 = this.newVertex(IdGenerator.of(3));
cache.addVertex(v1);
cache.addVertex(v2);
cache.commit();
HugeEdge edge = this.newEdge(v1, v2);
cache.addEdge(edge);
cache.commit();
Assert.assertTrue(cache.queryEdgesByVertex(IdGenerator.of(1)).hasNext());
Assert.assertTrue(cache.queryEdgesByVertex(IdGenerator.of(2)).hasNext());
Assert.assertEquals(2L, Whitebox.invoke(cache, "edgesCache", "size"));
cache.addVertexProperty(new HugeVertexProperty<>(v3, cache.graph().schema().getPropertyKey("name"), "test-name"));
cache.commit();
Assert.assertEquals(0L, Whitebox.invoke(cache, "edgesCache", "size"));
Assert.assertTrue(cache.queryEdgesByVertex(IdGenerator.of(1)).hasNext());
Assert.assertTrue(cache.queryEdgesByVertex(IdGenerator.of(2)).hasNext());
Assert.assertEquals(2L, Whitebox.invoke(cache, "edgesCache", "size"));
cache.addVertexProperty(new HugeVertexProperty<>(v1, cache.graph().schema().getPropertyKey("name"), "test-name"));
cache.commit();
Assert.assertEquals(0L, Whitebox.invoke(cache, "edgesCache", "size"));
String name = cache.queryEdgesByVertex(IdGenerator.of(1)).next().outVertex().value("name");
Assert.assertEquals("test-name", name);
}
use of com.baidu.hugegraph.structure.HugeVertex in project incubator-hugegraph by apache.
the class JsonUtilTest method testSerializeEdge.
@Test
public void testSerializeEdge() {
FakeObjects fakeObject = new FakeObjects();
PropertyKey name = fakeObject.newPropertyKey(IdGenerator.of(1), "name");
PropertyKey age = fakeObject.newPropertyKey(IdGenerator.of(2), "age", DataType.INT, Cardinality.SINGLE);
PropertyKey city = fakeObject.newPropertyKey(IdGenerator.of(3), "city");
PropertyKey date = fakeObject.newPropertyKey(IdGenerator.of(4), "date", DataType.DATE);
PropertyKey weight = fakeObject.newPropertyKey(IdGenerator.of(5), "weight", DataType.DOUBLE);
VertexLabel vl = fakeObject.newVertexLabel(IdGenerator.of(1), "person", IdStrategy.CUSTOMIZE_NUMBER, name.id(), age.id(), city.id());
EdgeLabel el = fakeObject.newEdgeLabel(IdGenerator.of(1), "knows", Frequency.SINGLE, vl.id(), vl.id(), date.id(), weight.id());
HugeVertex source = new HugeVertex(fakeObject.graph(), IdGenerator.of(123456), vl);
HugeVertex target = new HugeVertex(fakeObject.graph(), IdGenerator.of(987654), vl);
Id id = EdgeId.parse("L123456>1>>L987654");
HugeEdge edge = new HugeEdge(fakeObject.graph(), id, el);
Whitebox.setInternalState(edge, "sourceVertex", source);
Whitebox.setInternalState(edge, "targetVertex", target);
Date dateValue = Utils.date("2019-03-12");
MutableIntObjectMap<HugeProperty<?>> properties = CollectionFactory.newIntObjectMap(date.id(), new HugeEdgeProperty<>(edge, date, dateValue), weight.id(), new HugeEdgeProperty<>(edge, weight, 0.8));
Whitebox.setInternalState(edge, "properties", properties);
String json = JsonUtil.toJson(edge);
Assert.assertEquals("{\"id\":\"L123456>1>>L987654\"," + "\"label\":\"knows\",\"type\":\"edge\"," + "\"outV\":123456,\"outVLabel\":\"person\"," + "\"inV\":987654,\"inVLabel\":\"person\"," + "\"properties\":{\"date\":" + "\"2019-03-12 00:00:00.000\"," + "\"weight\":0.8}}", json);
}
use of com.baidu.hugegraph.structure.HugeVertex in project incubator-hugegraph by apache.
the class BinarySerializerTest method testEdge.
@Test
public void testEdge() {
HugeConfig config = FakeObjects.newConfig();
BinarySerializer ser = new BinarySerializer(config);
FakeObjects objects = new FakeObjects();
HugeEdge edge1 = objects.newEdge(123, 456);
HugeEdge edge2 = objects.newEdge(147, 789);
BackendEntry entry1 = ser.writeEdge(edge1);
HugeVertex vertex1 = ser.readVertex(edge1.graph(), entry1);
Assert.assertEquals(1, vertex1.getEdges().size());
HugeEdge edge = vertex1.getEdges().iterator().next();
Assert.assertEquals(edge1, edge);
assertCollectionEquals(edge1.getProperties(), edge.getProperties());
BackendEntry entry2 = ser.writeEdge(edge2);
HugeVertex vertex2 = ser.readVertex(edge1.graph(), entry2);
Assert.assertEquals(1, vertex2.getEdges().size());
edge = vertex2.getEdges().iterator().next();
Assert.assertEquals(edge2, edge);
assertCollectionEquals(edge2.getProperties(), edge.getProperties());
}
Aggregations