Search in sources :

Example 66 with Vertex

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

the class BatchUpdateElementApiTest method testVertexBatchUpdateStrategySmaller.

@Test
public void testVertexBatchUpdateStrategySmaller() {
    BatchVertexRequest req = batchVertexRequest("price", -3, 1, UpdateStrategy.SMALLER);
    List<Vertex> vertices = vertexAPI.update(req);
    assertBatchResponse(vertices, "price", -3);
    req = batchVertexRequest("price", 7, 3, UpdateStrategy.SMALLER);
    vertices = vertexAPI.update(req);
    assertBatchResponse(vertices, "price", 3);
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) BatchVertexRequest(com.baidu.hugegraph.structure.graph.BatchVertexRequest) Test(org.junit.Test)

Example 67 with Vertex

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

the class BatchUpdateElementApiTest method testVertexBatchUpdateStrategyIntersection.

@Test
public void testVertexBatchUpdateStrategyIntersection() {
    BatchVertexRequest req = batchVertexRequest("set", "old", "new", INTERSECTION);
    List<Vertex> vertices = vertexAPI.update(req);
    assertBatchResponse(vertices, "set");
    req = batchVertexRequest("set", "old", "old", INTERSECTION);
    vertices = vertexAPI.update(req);
    assertBatchResponse(vertices, "set", "old");
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) BatchVertexRequest(com.baidu.hugegraph.structure.graph.BatchVertexRequest) Test(org.junit.Test)

Example 68 with Vertex

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

the class BatchUpdateElementApiTest method testVertexBatchUpdateStrategyUnion.

@Test
public void testVertexBatchUpdateStrategyUnion() {
    BatchVertexRequest req = batchVertexRequest("set", "old", "new", UpdateStrategy.UNION);
    List<Vertex> vertices = vertexAPI.update(req);
    assertBatchResponse(vertices, "set", "new", "old");
    req = batchVertexRequest("set", "old", "old", UpdateStrategy.UNION);
    vertices = vertexAPI.update(req);
    assertBatchResponse(vertices, "set", "old");
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) BatchVertexRequest(com.baidu.hugegraph.structure.graph.BatchVertexRequest) Test(org.junit.Test)

Example 69 with Vertex

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

the class BatchUpdateElementApiTest method testVertexBatchUpdateStrategyOverride.

@Test
public void testVertexBatchUpdateStrategyOverride() {
    BatchVertexRequest req = batchVertexRequest("price", -1, 1, UpdateStrategy.OVERRIDE);
    assertBatchResponse(vertexAPI.update(req), "price", 1);
    // Construct a specialized test case
    graph().addVertices(this.createNVertexBatch("object", -1, 2));
    List<String> list = ImmutableList.of("newStr1", "newStr2");
    Vertex v1 = new Vertex("object");
    v1.property("name", "tom");
    v1.property("price", 1);
    v1.property("list", list);
    Vertex v2 = new Vertex("object");
    v2.property("name", "tom");
    Map<String, UpdateStrategy> strategies;
    strategies = ImmutableMap.of("price", UpdateStrategy.OVERRIDE, "list", UpdateStrategy.OVERRIDE);
    req = BatchVertexRequest.createBuilder().vertices(ImmutableList.of(v1, v2)).updatingStrategies(strategies).createIfNotExist(true).build();
    List<Vertex> vertices = vertexAPI.update(req);
    Assert.assertEquals(1, vertices.size());
    Map<String, Object> expectProperties = ImmutableMap.of("name", "tom", "price", 1, "list", list);
    Assert.assertEquals(vertices.get(0).properties(), expectProperties);
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) BatchVertexRequest(com.baidu.hugegraph.structure.graph.BatchVertexRequest) UpdateStrategy(com.baidu.hugegraph.structure.graph.UpdateStrategy) Test(org.junit.Test)

Example 70 with Vertex

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

the class GraphsApiTest method testCreateAndDropGraph.

@Test
public void testCreateAndDropGraph() {
    int initialGraphNumber = graphsAPI.list().size();
    // Create new graph dynamically
    String config;
    try {
        config = FileUtils.readFileToString(new File(CONFIG2_PATH), StandardCharsets.UTF_8);
    } catch (IOException e) {
        throw new ClientException("Failed to read config file: %s", CONFIG2_PATH);
    }
    Map<String, String> result = graphsAPI.create(GRAPH2, null, config);
    Assert.assertEquals(2, result.size());
    Assert.assertEquals(GRAPH2, result.get("name"));
    Assert.assertEquals("rocksdb", result.get("backend"));
    Assert.assertEquals(initialGraphNumber + 1, graphsAPI.list().size());
    HugeClient client = new HugeClient(baseClient(), GRAPH2);
    // Insert graph schema and data
    initPropertyKey(client);
    initVertexLabel(client);
    initEdgeLabel(client);
    List<Vertex> vertices = new ArrayList<>(100);
    for (int i = 0; i < 100; i++) {
        Vertex vertex = new Vertex("person").property("name", "person" + i).property("city", "Beijing").property("age", 19);
        vertices.add(vertex);
    }
    vertices = client.graph().addVertices(vertices);
    List<Edge> edges = new ArrayList<>(100);
    for (int i = 0; i < 100; i++) {
        Edge edge = new Edge("knows").source(vertices.get(i)).target(vertices.get((i + 1) % 100)).property("date", "2016-01-10");
        edges.add(edge);
    }
    client.graph().addEdges(edges, false);
    // Query vertices and edges count from new created graph
    ResultSet resultSet = client.gremlin().gremlin("g.V().count()").execute();
    Assert.assertEquals(100, resultSet.iterator().next().getInt());
    resultSet = client.gremlin().gremlin("g.E().count()").execute();
    Assert.assertEquals(100, resultSet.iterator().next().getInt());
    // Clear graph schema and data from new created graph
    graphsAPI.clear(GRAPH2, "I'm sure to delete all data");
    resultSet = client.gremlin().gremlin("g.V().count()").execute();
    Assert.assertEquals(0, resultSet.iterator().next().getInt());
    resultSet = client.gremlin().gremlin("g.E().count()").execute();
    Assert.assertEquals(0, resultSet.iterator().next().getInt());
    Assert.assertTrue(client.schema().getPropertyKeys().isEmpty());
    Assert.assertEquals(initialGraphNumber + 1, graphsAPI.list().size());
    // Remove new created graph dynamically
    graphsAPI.drop(GRAPH2, "I'm sure to drop the graph");
    Assert.assertEquals(initialGraphNumber, graphsAPI.list().size());
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) HugeClient(com.baidu.hugegraph.driver.HugeClient) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ResultSet(com.baidu.hugegraph.structure.gremlin.ResultSet) ClientException(com.baidu.hugegraph.rest.ClientException) File(java.io.File) Edge(com.baidu.hugegraph.structure.graph.Edge) Test(org.junit.Test)

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