Search in sources :

Example 86 with Edge

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

the class BatchUpdateElementApiTest method testEdgeBatchUpdateStrategyOverride.

@Test
public void testEdgeBatchUpdateStrategyOverride() {
    BatchEdgeRequest req = batchEdgeRequest("price", -1, 1, UpdateStrategy.OVERRIDE);
    assertBatchResponse(edgeAPI.update(req), "price", 1);
    // Construct a specialized test case
    graph().addEdges(this.createNEdgesBatch("object", "updates", -1, 2));
    List<String> list = ImmutableList.of("newStr1", "newStr2");
    String vid = "1:a";
    Edge e1 = new Edge("updates");
    e1.sourceLabel("object");
    e1.targetLabel("object");
    e1.sourceId(vid);
    e1.targetId(vid);
    e1.property("name", "tom");
    e1.property("price", 1);
    e1.property("list", list);
    Edge e2 = new Edge("updates");
    e2.sourceLabel("object");
    e2.targetLabel("object");
    e2.sourceId(vid);
    e2.targetId(vid);
    e2.property("name", "tom");
    Map<String, UpdateStrategy> strategies;
    strategies = ImmutableMap.of("price", UpdateStrategy.OVERRIDE, "list", UpdateStrategy.OVERRIDE);
    req = BatchEdgeRequest.createBuilder().edges(ImmutableList.of(e1, e2)).updatingStrategies(strategies).checkVertex(false).createIfNotExist(true).build();
    List<Edge> edges = edgeAPI.update(req);
    Assert.assertEquals(1, edges.size());
    Map<String, Object> expectProperties = ImmutableMap.of("name", "tom", "price", 1, "list", list);
    Assert.assertEquals(edges.get(0).properties(), expectProperties);
}
Also used : BatchEdgeRequest(com.baidu.hugegraph.structure.graph.BatchEdgeRequest) UpdateStrategy(com.baidu.hugegraph.structure.graph.UpdateStrategy) Edge(com.baidu.hugegraph.structure.graph.Edge) Test(org.junit.Test)

Example 87 with Edge

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

the class GremlinApiTest method testAttachedManager.

@Test
public void testAttachedManager() {
    GremlinRequest request = new GremlinRequest("g.V()");
    ResultSet resultSet = gremlin().execute(request);
    Assert.assertEquals(6, resultSet.size());
    Iterator<Result> results = resultSet.iterator();
    while (results.hasNext()) {
        Result result = results.next();
        Object object = result.getObject();
        Assert.assertEquals(Vertex.class, object.getClass());
        Vertex vertex = (Vertex) object;
        Assert.assertNotNull(Whitebox.getInternalState(vertex, "manager"));
    }
    request = new GremlinRequest("g.E()");
    resultSet = gremlin().execute(request);
    Assert.assertEquals(6, resultSet.size());
    results = resultSet.iterator();
    while (results.hasNext()) {
        Result result = results.next();
        Object object = result.getObject();
        Assert.assertEquals(Edge.class, object.getClass());
        Edge edge = (Edge) object;
        Assert.assertNotNull(Whitebox.getInternalState(edge, "manager"));
    }
    request = new GremlinRequest("g.V().outE().path()");
    resultSet = gremlin().execute(request);
    Assert.assertEquals(6, resultSet.size());
    results = resultSet.iterator();
    while (results.hasNext()) {
        Result result = results.next();
        Object object = result.getObject();
        Assert.assertEquals(Path.class, object.getClass());
        Path path = (Path) object;
        Assert.assertNotNull(path.objects());
        for (Object pathObject : path.objects()) {
            Assert.assertTrue(pathObject instanceof GraphAttachable);
            Assert.assertNotNull(Whitebox.getInternalState(pathObject, "manager"));
        }
        Assert.assertNull(path.crosspoint());
    }
}
Also used : Path(com.baidu.hugegraph.structure.graph.Path) Vertex(com.baidu.hugegraph.structure.graph.Vertex) GraphAttachable(com.baidu.hugegraph.structure.constant.GraphAttachable) ResultSet(com.baidu.hugegraph.structure.gremlin.ResultSet) GremlinRequest(com.baidu.hugegraph.api.gremlin.GremlinRequest) Edge(com.baidu.hugegraph.structure.graph.Edge) Result(com.baidu.hugegraph.structure.gremlin.Result) Test(org.junit.Test)

Example 88 with Edge

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

the class EdgeApiTest method testCreateWithoutSourceOrTargetId.

@Test
public void testCreateWithoutSourceOrTargetId() {
    Edge edge = new Edge("created");
    edge.sourceLabel("person");
    edge.targetLabel("software");
    edge.property("date", "2017-03-24");
    edge.property("city", "Hongkong");
    Utils.assertResponseError(400, () -> {
        edgeAPI.create(edge);
    });
}
Also used : Edge(com.baidu.hugegraph.structure.graph.Edge) Test(org.junit.Test)

Example 89 with Edge

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

the class EdgeApiTest method testBatchCreateWithInvalidVertexIdAndCheck.

@Test
public void testBatchCreateWithInvalidVertexIdAndCheck() {
    List<Edge> edges = new ArrayList<>(2);
    Edge edge1 = new Edge("created");
    edge1.sourceLabel("person");
    edge1.targetLabel("software");
    edge1.sourceId("person:invalid");
    edge1.targetId("software:lop");
    edge1.property("date", "2017-03-24");
    edge1.property("city", "Hongkong");
    edges.add(edge1);
    Edge edge2 = new Edge("knows");
    edge2.sourceLabel("person");
    edge2.targetLabel("person");
    edge2.sourceId("person:peter");
    edge2.targetId("person:invalid");
    edge2.property("date", "2017-03-24");
    edges.add(edge2);
    Utils.assertResponseError(400, () -> {
        edgeAPI.create(edges, true);
    });
}
Also used : ArrayList(java.util.ArrayList) Edge(com.baidu.hugegraph.structure.graph.Edge) Test(org.junit.Test)

Example 90 with Edge

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

the class EdgeApiTest method testAddEdgeWithTtl.

@Test
public void testAddEdgeWithTtl() {
    SchemaManager schema = schema();
    schema.propertyKey("place").asText().ifNotExist().create();
    schema.edgeLabel("read").link("person", "book").properties("place", "date").ttl(3000L).enableLabelIndex(true).ifNotExist().create();
    Vertex baby = graph().addVertex(T.label, "person", "name", "Baby", "age", 3, "city", "Beijing");
    Vertex java = graph().addVertex(T.label, "book", T.id, "java", "name", "Java in action");
    Edge edge = baby.addEdge("read", java, "place", "library of school", "date", "2019-12-23 12:00:00");
    Edge result = graph().getEdge(edge.id());
    Assert.assertEquals("read", result.label());
    Assert.assertEquals("person", edge.sourceLabel());
    Assert.assertEquals("book", edge.targetLabel());
    Assert.assertEquals(baby.id(), edge.sourceId());
    Assert.assertEquals(java.id(), edge.targetId());
    Map<String, Object> props = ImmutableMap.of("place", "library of school", "date", "2019-12-23 12:00:00.000");
    Assert.assertEquals(props, result.properties());
    try {
        Thread.sleep(1100L);
    } catch (InterruptedException e) {
    // Ignore
    }
    result = graph().getEdge(edge.id());
    Assert.assertEquals("read", result.label());
    Assert.assertEquals("person", edge.sourceLabel());
    Assert.assertEquals("book", edge.targetLabel());
    Assert.assertEquals(baby.id(), edge.sourceId());
    Assert.assertEquals(java.id(), edge.targetId());
    Assert.assertEquals(props, result.properties());
    try {
        Thread.sleep(1100L);
    } catch (InterruptedException e) {
    // Ignore
    }
    result = graph().getEdge(edge.id());
    Assert.assertEquals("read", result.label());
    Assert.assertEquals("person", edge.sourceLabel());
    Assert.assertEquals("book", edge.targetLabel());
    Assert.assertEquals(baby.id(), edge.sourceId());
    Assert.assertEquals(java.id(), edge.targetId());
    Assert.assertEquals(props, result.properties());
    try {
        Thread.sleep(1100L);
    } catch (InterruptedException e) {
    // Ignore
    }
    Assert.assertThrows(ServerException.class, () -> {
        graph().getEdge(edge.id());
    }, e -> {
        Assert.assertContains("does not exist", e.getMessage());
    });
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) SchemaManager(com.baidu.hugegraph.driver.SchemaManager) Edge(com.baidu.hugegraph.structure.graph.Edge) Test(org.junit.Test)

Aggregations

Edge (com.baidu.hugegraph.structure.graph.Edge)103 Test (org.junit.Test)73 Vertex (com.baidu.hugegraph.structure.graph.Vertex)33 ArrayList (java.util.ArrayList)22 BaseClientTest (com.baidu.hugegraph.BaseClientTest)20 BatchEdgeRequest (com.baidu.hugegraph.structure.graph.BatchEdgeRequest)12 HugeClient (com.baidu.hugegraph.driver.HugeClient)10 Path (com.baidu.hugegraph.structure.graph.Path)9 Result (com.baidu.hugegraph.structure.gremlin.Result)8 ResultSet (com.baidu.hugegraph.structure.gremlin.ResultSet)7 RestResult (com.baidu.hugegraph.rest.RestResult)5 VertexLabel (com.baidu.hugegraph.structure.schema.VertexLabel)5 GraphManager (com.baidu.hugegraph.driver.GraphManager)4 SchemaManager (com.baidu.hugegraph.driver.SchemaManager)4 GraphView (com.baidu.hugegraph.entity.query.GraphView)4 Edges (com.baidu.hugegraph.structure.graph.Edges)4 Date (java.util.Date)4 HashMap (java.util.HashMap)4 GremlinResult (com.baidu.hugegraph.entity.query.GremlinResult)3 TypedResult (com.baidu.hugegraph.entity.query.TypedResult)3