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);
}
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");
}
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");
}
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);
}
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());
}
Aggregations