Search in sources :

Example 16 with Vertex

use of com.baidu.hugegraph.structure.graph.Vertex in project incubator-hugegraph-toolchain by apache.

the class VertexApiTest method testCreateWithUndefinedLabel.

@Test
public void testCreateWithUndefinedLabel() {
    Vertex vertex = new Vertex("undefined");
    vertex.property("name", "James");
    vertex.property("city", "Beijing");
    vertex.property("age", 19);
    Utils.assertResponseError(400, () -> {
        vertexAPI.create(vertex);
    });
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) Test(org.junit.Test)

Example 17 with Vertex

use of com.baidu.hugegraph.structure.graph.Vertex in project incubator-hugegraph-toolchain by apache.

the class VertexApiTest method testCreateVertexWithTtl.

@Test
public void testCreateVertexWithTtl() {
    SchemaManager schema = schema();
    schema.vertexLabel("fan").properties("name", "age", "city").primaryKeys("name").ttl(3000L).ifNotExist().create();
    Vertex vertex = graph().addVertex(T.label, "fan", "name", "Baby", "age", 3, "city", "Beijing");
    Vertex result = graph().getVertex(vertex.id());
    Assert.assertEquals("fan", result.label());
    Map<String, Object> props = ImmutableMap.of("name", "Baby", "city", "Beijing", "age", 3);
    Assert.assertEquals(props, result.properties());
    try {
        Thread.sleep(1100L);
    } catch (InterruptedException e) {
    // Ignore
    }
    result = graph().getVertex(vertex.id());
    Assert.assertEquals("fan", result.label());
    Assert.assertEquals(props, result.properties());
    try {
        Thread.sleep(1100L);
    } catch (InterruptedException e) {
    // Ignore
    }
    result = graph().getVertex(vertex.id());
    Assert.assertEquals("fan", result.label());
    Assert.assertEquals(props, result.properties());
    try {
        Thread.sleep(1100L);
    } catch (InterruptedException e) {
    // Ignore
    }
    Assert.assertThrows(ServerException.class, () -> {
        graph().getVertex(vertex.id());
    }, e -> {
        Assert.assertContains("does not exist", e.getMessage());
    });
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) SchemaManager(com.baidu.hugegraph.driver.SchemaManager) Test(org.junit.Test)

Example 18 with Vertex

use of com.baidu.hugegraph.structure.graph.Vertex in project incubator-hugegraph-toolchain by apache.

the class VertexApiTest method testGetWithCustomizeUuidId.

@Test
public void testGetWithCustomizeUuidId() {
    schema().vertexLabel("user").useCustomizeUuidId().properties("date").ifNotExist().create();
    Vertex vertex1 = new Vertex("user");
    vertex1.id("835e1153-9281-4957-8691-cf79258e90eb");
    vertex1.property("date", "2018-01-01");
    vertex1 = vertexAPI.create(vertex1);
    UUID id = UUID.fromString("835e1153-9281-4957-8691-cf79258e90eb");
    Vertex vertex2 = vertexAPI.get(id);
    Assert.assertEquals(vertex1.id(), vertex2.id());
    Assert.assertEquals(vertex1.label(), vertex2.label());
    Assert.assertEquals(vertex1.properties(), vertex2.properties());
    // NOTE: must clean here due to type info
    vertexAPI.delete(id);
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) UUID(java.util.UUID) Test(org.junit.Test)

Example 19 with Vertex

use of com.baidu.hugegraph.structure.graph.Vertex in project incubator-hugegraph-toolchain by apache.

the class JaccardSimilarityApiTest method initShortestPathGraph.

@BeforeClass
public static void initShortestPathGraph() {
    schema().vertexLabel("node").useCustomizeNumberId().ifNotExist().create();
    schema().edgeLabel("link").sourceLabel("node").targetLabel("node").ifNotExist().create();
    schema().edgeLabel("relateTo").sourceLabel("node").targetLabel("node").ifNotExist().create();
    Vertex v1 = graph().addVertex(T.label, "node", T.id, 1);
    Vertex v2 = graph().addVertex(T.label, "node", T.id, 2);
    Vertex v3 = graph().addVertex(T.label, "node", T.id, 3);
    Vertex v4 = graph().addVertex(T.label, "node", T.id, 4);
    Vertex v5 = graph().addVertex(T.label, "node", T.id, 5);
    Vertex v6 = graph().addVertex(T.label, "node", T.id, 6);
    Vertex v7 = graph().addVertex(T.label, "node", T.id, 7);
    Vertex v8 = graph().addVertex(T.label, "node", T.id, 8);
    Vertex v9 = graph().addVertex(T.label, "node", T.id, 9);
    Vertex v10 = graph().addVertex(T.label, "node", T.id, 10);
    v1.addEdge("link", v3);
    v2.addEdge("link", v3);
    v4.addEdge("link", v1);
    v4.addEdge("link", v2);
    v1.addEdge("relateTo", v5);
    v2.addEdge("relateTo", v5);
    v6.addEdge("relateTo", v1);
    v6.addEdge("relateTo", v2);
    v1.addEdge("link", v7);
    v8.addEdge("link", v1);
    v2.addEdge("link", v9);
    v10.addEdge("link", v2);
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) BeforeClass(org.junit.BeforeClass)

Example 20 with Vertex

use of com.baidu.hugegraph.structure.graph.Vertex in project incubator-hugegraph-toolchain by apache.

the class KoutApiTest method testKoutPostWithVertex.

@Test
public void testKoutPostWithVertex() {
    Object markoId = getVertexId("person", "name", "marko");
    Object rippleId = getVertexId("software", "name", "ripple");
    Object joshId = getVertexId("person", "name", "josh");
    Object lopId = getVertexId("software", "name", "lop");
    Object vadasId = getVertexId("person", "name", "vadas");
    Object peterId = getVertexId("person", "name", "peter");
    KoutRequest.Builder builder = KoutRequest.builder();
    builder.source(markoId);
    builder.step().direction(Direction.BOTH);
    builder.maxDepth(1);
    builder.withPath(false);
    builder.withVertex(true);
    KoutRequest request = builder.build();
    Kout koutResult = koutAPI.post(request);
    Assert.assertEquals(3, koutResult.size());
    Set<Object> expected = ImmutableSet.of(vadasId, lopId, joshId);
    Assert.assertEquals(expected, koutResult.ids());
    Assert.assertEquals(3, koutResult.vertices().size());
    Set<Object> expectedVids = ImmutableSet.of(vadasId, lopId, joshId);
    for (Vertex vertex : koutResult.vertices()) {
        Assert.assertTrue(expectedVids.contains(vertex.id()));
    }
    builder = KoutRequest.builder();
    builder.source(markoId);
    builder.step().direction(Direction.BOTH);
    builder.maxDepth(2);
    builder.withPath(false);
    builder.withVertex(true);
    request = builder.build();
    koutResult = koutAPI.post(request);
    Assert.assertEquals(2, koutResult.size());
    expected = ImmutableSet.of(peterId, rippleId);
    Assert.assertEquals(expected, koutResult.ids());
    Assert.assertEquals(2, koutResult.vertices().size());
    expectedVids = ImmutableSet.of(peterId, rippleId);
    for (Vertex vertex : koutResult.vertices()) {
        Assert.assertTrue(expectedVids.contains(vertex.id()));
    }
    builder = KoutRequest.builder();
    builder.source(markoId);
    builder.step().direction(Direction.BOTH);
    builder.maxDepth(1);
    builder.withPath(true);
    builder.withVertex(true);
    request = builder.build();
    koutResult = koutAPI.post(request);
    Assert.assertEquals(3, koutResult.size());
    expected = ImmutableSet.of(vadasId, lopId, joshId);
    Assert.assertEquals(expected, koutResult.ids());
    Assert.assertEquals(3, koutResult.paths().size());
    Set<List<Object>> expectedPaths = ImmutableSet.of(ImmutableList.of(markoId, vadasId), ImmutableList.of(markoId, lopId), ImmutableList.of(markoId, joshId));
    for (Path path : koutResult.paths()) {
        Assert.assertTrue(expectedPaths.contains(path.objects()));
    }
    Assert.assertEquals(4, koutResult.vertices().size());
    expectedVids = ImmutableSet.of(markoId, vadasId, lopId, joshId);
    for (Vertex vertex : koutResult.vertices()) {
        Assert.assertTrue(expectedVids.contains(vertex.id()));
    }
    builder = KoutRequest.builder();
    builder.source(markoId);
    builder.step().direction(Direction.BOTH);
    builder.maxDepth(2);
    builder.withPath(true);
    builder.withVertex(true);
    request = builder.build();
    koutResult = koutAPI.post(request);
    Assert.assertEquals(2, koutResult.size());
    expected = ImmutableSet.of(peterId, rippleId);
    Assert.assertEquals(expected, koutResult.ids());
    Assert.assertEquals(2, koutResult.paths().size());
    expectedPaths = ImmutableSet.of(ImmutableList.of(markoId, lopId, peterId), ImmutableList.of(markoId, joshId, rippleId));
    for (Path path : koutResult.paths()) {
        Assert.assertTrue(expectedPaths.contains(path.objects()));
    }
    Assert.assertEquals(5, koutResult.vertices().size());
    expectedVids = ImmutableSet.of(markoId, peterId, lopId, joshId, rippleId);
    for (Vertex vertex : koutResult.vertices()) {
        Assert.assertTrue(expectedVids.contains(vertex.id()));
    }
}
Also used : Kout(com.baidu.hugegraph.structure.traverser.Kout) Path(com.baidu.hugegraph.structure.graph.Path) Vertex(com.baidu.hugegraph.structure.graph.Vertex) KoutRequest(com.baidu.hugegraph.structure.traverser.KoutRequest) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Test(org.junit.Test) BaseApiTest(com.baidu.hugegraph.api.BaseApiTest)

Aggregations

Vertex (com.baidu.hugegraph.structure.graph.Vertex)165 Test (org.junit.Test)110 Edge (com.baidu.hugegraph.structure.graph.Edge)33 HugeClient (com.baidu.hugegraph.driver.HugeClient)22 ArrayList (java.util.ArrayList)21 SchemaManager (com.baidu.hugegraph.driver.SchemaManager)18 BaseClientTest (com.baidu.hugegraph.BaseClientTest)17 BeforeClass (org.junit.BeforeClass)17 GraphManager (com.baidu.hugegraph.driver.GraphManager)14 BatchVertexRequest (com.baidu.hugegraph.structure.graph.BatchVertexRequest)13 Path (com.baidu.hugegraph.structure.graph.Path)11 Result (com.baidu.hugegraph.structure.gremlin.Result)10 ResultSet (com.baidu.hugegraph.structure.gremlin.ResultSet)10 List (java.util.List)10 BaseApiTest (com.baidu.hugegraph.api.BaseApiTest)9 ImmutableList (com.google.common.collect.ImmutableList)6 ImmutableMap (com.google.common.collect.ImmutableMap)6 Map (java.util.Map)6 RestResult (com.baidu.hugegraph.rest.RestResult)5 PathsWithVertices (com.baidu.hugegraph.structure.traverser.PathsWithVertices)5