use of com.baidu.hugegraph.structure.graph.BatchEdgeRequest in project incubator-hugegraph-toolchain by apache.
the class BatchUpdateElementApiTest method testEdgeBatchUpdateStrategyEliminate.
@Test
public void testEdgeBatchUpdateStrategyEliminate() {
BatchEdgeRequest req = batchEdgeRequest("list", "old", "old", UpdateStrategy.ELIMINATE);
List<Edge> edges = edgeAPI.update(req);
assertBatchResponse(edges, "list");
req = batchEdgeRequest("list", "old", "new", UpdateStrategy.ELIMINATE);
edges = edgeAPI.update(req);
assertBatchResponse(edges, "list", "old");
}
use of com.baidu.hugegraph.structure.graph.BatchEdgeRequest in project incubator-hugegraph-toolchain by apache.
the class BatchUpdateElementApiTest method testEdgeInvalidUpdateStrategy.
@Test
public void testEdgeInvalidUpdateStrategy() {
BatchEdgeRequest req1 = batchEdgeRequest("name", "old", "new", UpdateStrategy.SUM);
Assert.assertThrows(ServerException.class, () -> {
edgeAPI.update(req1);
}, e -> {
String expect = "Property type must be Number for strategy SUM, " + "but got type String, String";
Assert.assertContains(expect, e.getMessage());
});
BatchEdgeRequest req2 = batchEdgeRequest("name", "old", "new", UpdateStrategy.BIGGER);
Assert.assertThrows(ServerException.class, () -> {
edgeAPI.update(req2);
}, e -> {
String expect = "Property type must be Date or Number " + "for strategy BIGGER, but got type String, String";
Assert.assertContains(expect, e.getMessage());
});
BatchEdgeRequest req3 = batchEdgeRequest("name", "old", "new", UpdateStrategy.SMALLER);
Assert.assertThrows(ServerException.class, () -> {
edgeAPI.update(req3);
}, e -> {
String expect = "Property type must be Date or Number " + "for strategy SMALLER, but got type String, String";
Assert.assertContains(expect, e.getMessage());
});
BatchEdgeRequest req4 = batchEdgeRequest("price", 1, -1, UpdateStrategy.UNION);
Assert.assertThrows(ServerException.class, () -> {
edgeAPI.update(req4);
}, e -> {
String expect = "Property type must be Set or List " + "for strategy UNION, but got type Integer, Integer";
Assert.assertContains(expect, e.getMessage());
});
BatchEdgeRequest req5 = batchEdgeRequest("date", "old", "new", INTERSECTION);
Assert.assertThrows(ServerException.class, () -> {
edgeAPI.update(req5);
}, e -> {
String expect = "Property type must be Set or List for " + "strategy INTERSECTION, but got type Date, Long";
Assert.assertContains(expect, e.getMessage());
});
BatchEdgeRequest req6 = batchEdgeRequest("price", 1, -1, UpdateStrategy.APPEND);
Assert.assertThrows(ServerException.class, () -> {
edgeAPI.update(req6);
}, e -> {
String expect = "Property type must be Set or List for " + "strategy APPEND, but got type Integer, Integer";
Assert.assertContains(expect, e.getMessage());
});
BatchEdgeRequest req7 = batchEdgeRequest("name", "old", "new", UpdateStrategy.ELIMINATE);
Assert.assertThrows(ServerException.class, () -> {
edgeAPI.update(req7);
}, e -> {
String expect = "Property type must be Set or List for " + "strategy ELIMINATE, but got type String, String";
Assert.assertContains(expect, e.getMessage());
});
}
use of com.baidu.hugegraph.structure.graph.BatchEdgeRequest in project incubator-hugegraph-toolchain by apache.
the class BatchUpdateElementApiTest method testEdgeBatchUpdateStrategyAppend.
@Test
public void testEdgeBatchUpdateStrategyAppend() {
BatchEdgeRequest req = batchEdgeRequest("list", "old", "old", UpdateStrategy.APPEND);
List<Edge> edges = edgeAPI.update(req);
assertBatchResponse(edges, "list", "old", "old");
req = batchEdgeRequest("list", "old", "new", UpdateStrategy.APPEND);
edges = edgeAPI.update(req);
assertBatchResponse(edges, "list", "old", "new");
}
use of com.baidu.hugegraph.structure.graph.BatchEdgeRequest in project incubator-hugegraph-toolchain by apache.
the class BatchUpdateElementApiTest method testEdgeBatchUpdateWithInvalidArgs.
@Test
public void testEdgeBatchUpdateWithInvalidArgs() {
BatchEdgeRequest req1 = batchEdgeRequest("list", "old", "old", UpdateStrategy.ELIMINATE);
Assert.assertThrows(ServerException.class, () -> {
List<Edge> edges = Whitebox.getInternalState(req1, "edges");
edges.set(1, null);
Whitebox.setInternalState(req1, "edges", edges);
edgeAPI.update(req1);
}, e -> {
String expect = "The batch body can't contain null record";
Assert.assertContains(expect, e.getMessage());
});
BatchEdgeRequest req2 = batchEdgeRequest("list", "old", "old", UpdateStrategy.ELIMINATE);
Assert.assertThrows(ServerException.class, () -> {
Whitebox.setInternalState(req2, "edges", null);
edgeAPI.update(req2);
}, e -> {
String expect = "Parameter 'edges' can't be null";
Assert.assertContains(expect, e.getMessage());
});
BatchEdgeRequest req3 = batchEdgeRequest("list", "old", "old", UpdateStrategy.ELIMINATE);
Assert.assertThrows(ServerException.class, () -> {
Whitebox.setInternalState(req3, "edges", ImmutableList.of());
edgeAPI.update(req3);
}, e -> {
String expect = "The number of edges can't be 0";
Assert.assertContains(expect, e.getMessage());
});
BatchEdgeRequest req4 = batchEdgeRequest("list", "old", "old", UpdateStrategy.ELIMINATE);
Assert.assertThrows(ServerException.class, () -> {
Whitebox.setInternalState(req4, "createIfNotExist", false);
edgeAPI.update(req4);
}, e -> {
String expect = "Parameter 'create_if_not_exist' " + "dose not support false now";
Assert.assertContains(expect, e.getMessage());
});
BatchEdgeRequest req5 = batchEdgeRequest("list", "old", "old", UpdateStrategy.ELIMINATE);
Assert.assertThrows(ServerException.class, () -> {
Whitebox.setInternalState(req5, "updateStrategies", null);
edgeAPI.update(req5);
}, e -> {
String expect = "Parameter 'update_strategies' can't be empty";
Assert.assertContains(expect, e.getMessage());
});
BatchEdgeRequest req6 = batchEdgeRequest("list", "old", "old", UpdateStrategy.ELIMINATE);
Assert.assertThrows(ServerException.class, () -> {
Whitebox.setInternalState(req6, "updateStrategies", ImmutableMap.of());
edgeAPI.update(req6);
}, e -> {
String expect = "Parameter 'update_strategies' can't be empty";
Assert.assertContains(expect, e.getMessage());
});
BatchEdgeRequest req7 = batchEdgeRequest("list", "old", "old", UpdateStrategy.ELIMINATE);
Assert.assertThrows(ServerException.class, () -> {
List<Edge> edges = this.createNEdgesBatch("object", "updates", "old", 501);
Whitebox.setInternalState(req7, "edges", edges);
edgeAPI.update(req7);
}, e -> {
String expect = "Too many edges for one time post";
Assert.assertContains(expect, e.getMessage());
});
}
use of com.baidu.hugegraph.structure.graph.BatchEdgeRequest in project incubator-hugegraph-toolchain by apache.
the class BatchUpdateElementApiTest method testEdgeBatchUpdateStrategyBigger.
@Test
public void testEdgeBatchUpdateStrategyBigger() {
// TODO: Add date comparison after fixing the date serialization bug
BatchEdgeRequest req = batchEdgeRequest("price", -3, 1, UpdateStrategy.BIGGER);
List<Edge> edges = edgeAPI.update(req);
assertBatchResponse(edges, "price", 1);
req = batchEdgeRequest("price", 7, 3, UpdateStrategy.BIGGER);
edges = edgeAPI.update(req);
assertBatchResponse(edges, "price", 7);
}
Aggregations