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