Search in sources :

Example 51 with HugeVertex

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());
    });
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) VertexLabel(com.baidu.hugegraph.schema.VertexLabel) EdgeLabel(com.baidu.hugegraph.schema.EdgeLabel) HugeEdge(com.baidu.hugegraph.structure.HugeEdge) RamTable(com.baidu.hugegraph.backend.store.ram.RamTable) HugeVertex(com.baidu.hugegraph.structure.HugeVertex) Test(org.junit.Test)

Example 52 with HugeVertex

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);
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) VertexLabel(com.baidu.hugegraph.schema.VertexLabel) HugeVertex(com.baidu.hugegraph.structure.HugeVertex)

Example 53 with HugeVertex

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);
}
Also used : CachedGraphTransaction(com.baidu.hugegraph.backend.cache.CachedGraphTransaction) HugeEdge(com.baidu.hugegraph.structure.HugeEdge) HugeVertex(com.baidu.hugegraph.structure.HugeVertex) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Example 54 with HugeVertex

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);
}
Also used : HugeProperty(com.baidu.hugegraph.structure.HugeProperty) FakeObjects(com.baidu.hugegraph.unit.FakeObjects) VertexLabel(com.baidu.hugegraph.schema.VertexLabel) EdgeLabel(com.baidu.hugegraph.schema.EdgeLabel) HugeEdge(com.baidu.hugegraph.structure.HugeEdge) EdgeId(com.baidu.hugegraph.backend.id.EdgeId) Id(com.baidu.hugegraph.backend.id.Id) HugeVertex(com.baidu.hugegraph.structure.HugeVertex) PropertyKey(com.baidu.hugegraph.schema.PropertyKey) Date(java.util.Date) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Example 55 with HugeVertex

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());
}
Also used : BackendEntry(com.baidu.hugegraph.backend.store.BackendEntry) FakeObjects(com.baidu.hugegraph.unit.FakeObjects) HugeEdge(com.baidu.hugegraph.structure.HugeEdge) HugeConfig(com.baidu.hugegraph.config.HugeConfig) HugeVertex(com.baidu.hugegraph.structure.HugeVertex) BinarySerializer(com.baidu.hugegraph.backend.serializer.BinarySerializer) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Aggregations

HugeVertex (com.baidu.hugegraph.structure.HugeVertex)58 Id (com.baidu.hugegraph.backend.id.Id)27 HugeEdge (com.baidu.hugegraph.structure.HugeEdge)26 VertexLabel (com.baidu.hugegraph.schema.VertexLabel)18 EdgeId (com.baidu.hugegraph.backend.id.EdgeId)16 Test (org.junit.Test)16 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)11 BaseUnitTest (com.baidu.hugegraph.unit.BaseUnitTest)10 FakeObjects (com.baidu.hugegraph.unit.FakeObjects)9 HugeGraph (com.baidu.hugegraph.HugeGraph)8 BackendEntry (com.baidu.hugegraph.backend.store.BackendEntry)8 PropertyKey (com.baidu.hugegraph.schema.PropertyKey)8 Watched (com.baidu.hugegraph.perf.PerfUtil.Watched)7 EdgeLabel (com.baidu.hugegraph.schema.EdgeLabel)7 Edge (org.apache.tinkerpop.gremlin.structure.Edge)7 IdQuery (com.baidu.hugegraph.backend.query.IdQuery)6 HugeException (com.baidu.hugegraph.HugeException)5 HugeConfig (com.baidu.hugegraph.config.HugeConfig)5 HugeProperty (com.baidu.hugegraph.structure.HugeProperty)4 ConditionQuery (com.baidu.hugegraph.backend.query.ConditionQuery)3