diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/BaseApiTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/BaseApiTest.java index ffe8a08524..b298669227 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/BaseApiTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/BaseApiTest.java @@ -74,7 +74,7 @@ public class BaseApiTest { private static RestClient client; - private static final ObjectMapper mapper = new ObjectMapper(); + private static final ObjectMapper MAPPER = new ObjectMapper(); @BeforeClass public static void init() { @@ -197,118 +197,118 @@ public Response delete(String path, protected static void initPropertyKey() { String path = URL_PREFIX + SCHEMA_PKS; - createAndAssert(path, "{\n" - + "\"name\": \"name\",\n" - + "\"data_type\": \"TEXT\",\n" - + "\"cardinality\": \"SINGLE\",\n" - + "\"check_exist\": false,\n" - + "\"properties\":[]\n" - + "}", 202); - createAndAssert(path, "{\n" - + "\"name\": \"age\",\n" - + "\"data_type\": \"INT\",\n" - + "\"cardinality\": \"SINGLE\",\n" - + "\"check_exist\": false,\n" - + "\"properties\":[]\n" - + "}", 202); - createAndAssert(path, "{\n" - + "\"name\": \"city\",\n" - + "\"data_type\": \"TEXT\",\n" - + "\"cardinality\": \"SINGLE\",\n" - + "\"check_exist\": false,\n" - + "\"properties\":[]\n" - + "}", 202); - createAndAssert(path, "{\n" - + "\"name\": \"lang\",\n" - + "\"data_type\": \"TEXT\",\n" - + "\"cardinality\": \"SINGLE\",\n" - + "\"check_exist\": false,\n" - + "\"properties\":[]\n" - + "}", 202); - createAndAssert(path, "{\n" - + "\"name\": \"date\",\n" - + "\"data_type\": \"TEXT\",\n" - + "\"cardinality\": \"SINGLE\",\n" - + "\"check_exist\": false,\n" - + "\"properties\":[]\n" - + "}", 202); - createAndAssert(path, "{\n" - + "\"name\": \"price\",\n" - + "\"data_type\": \"INT\",\n" - + "\"cardinality\": \"SINGLE\",\n" - + "\"check_exist\": false,\n" - + "\"properties\":[]\n" - + "}", 202); - createAndAssert(path, "{\n" - + "\"name\": \"weight\",\n" - + "\"data_type\": \"DOUBLE\",\n" - + "\"cardinality\": \"SINGLE\",\n" - + "\"check_exist\": false,\n" - + "\"properties\":[]\n" - + "}", 202); + createAndAssert(path, "{\n" + + "\"name\": \"name\",\n" + + "\"data_type\": \"TEXT\",\n" + + "\"cardinality\": \"SINGLE\",\n" + + "\"check_exist\": false,\n" + + "\"properties\":[]\n" + + "}", 202); + createAndAssert(path, "{\n" + + "\"name\": \"age\",\n" + + "\"data_type\": \"INT\",\n" + + "\"cardinality\": \"SINGLE\",\n" + + "\"check_exist\": false,\n" + + "\"properties\":[]\n" + + "}", 202); + createAndAssert(path, "{\n" + + "\"name\": \"city\",\n" + + "\"data_type\": \"TEXT\",\n" + + "\"cardinality\": \"SINGLE\",\n" + + "\"check_exist\": false,\n" + + "\"properties\":[]\n" + + "}", 202); + createAndAssert(path, "{\n" + + "\"name\": \"lang\",\n" + + "\"data_type\": \"TEXT\",\n" + + "\"cardinality\": \"SINGLE\",\n" + + "\"check_exist\": false,\n" + + "\"properties\":[]\n" + + "}", 202); + createAndAssert(path, "{\n" + + "\"name\": \"date\",\n" + + "\"data_type\": \"TEXT\",\n" + + "\"cardinality\": \"SINGLE\",\n" + + "\"check_exist\": false,\n" + + "\"properties\":[]\n" + + "}", 202); + createAndAssert(path, "{\n" + + "\"name\": \"price\",\n" + + "\"data_type\": \"INT\",\n" + + "\"cardinality\": \"SINGLE\",\n" + + "\"check_exist\": false,\n" + + "\"properties\":[]\n" + + "}", 202); + createAndAssert(path, "{\n" + + "\"name\": \"weight\",\n" + + "\"data_type\": \"DOUBLE\",\n" + + "\"cardinality\": \"SINGLE\",\n" + + "\"check_exist\": false,\n" + + "\"properties\":[]\n" + + "}", 202); } protected static void initVertexLabel() { String path = URL_PREFIX + SCHEMA_VLS; - createAndAssert(path, "{\n" - + "\"primary_keys\":[\"name\"],\n" - + "\"id_strategy\": \"PRIMARY_KEY\",\n" - + "\"name\": \"person\",\n" - + "\"properties\":[\"city\", \"name\", \"age\"],\n" - + "\"check_exist\": false,\n" - + "\"nullable_keys\":[]\n" - + "}"); - - createAndAssert(path, "{\n" - + "\"primary_keys\":[\"name\"],\n" - + "\"id_strategy\": \"PRIMARY_KEY\",\n" - + "\"name\": \"software\",\n" - + "\"properties\":[\"price\", \"name\", \"lang\"],\n" - + "\"check_exist\": false,\n" - + "\"nullable_keys\":[]\n" - + "}"); + createAndAssert(path, "{\n" + + "\"primary_keys\":[\"name\"],\n" + + "\"id_strategy\": \"PRIMARY_KEY\",\n" + + "\"name\": \"person\",\n" + + "\"properties\":[\"city\", \"name\", \"age\"],\n" + + "\"check_exist\": false,\n" + + "\"nullable_keys\":[]\n" + + "}"); + + createAndAssert(path, "{\n" + + "\"primary_keys\":[\"name\"],\n" + + "\"id_strategy\": \"PRIMARY_KEY\",\n" + + "\"name\": \"software\",\n" + + "\"properties\":[\"price\", \"name\", \"lang\"],\n" + + "\"check_exist\": false,\n" + + "\"nullable_keys\":[]\n" + + "}"); } protected static void initEdgeLabel() { String path = URL_PREFIX + SCHEMA_ELS; - createAndAssert(path, "{\n" - + "\"name\": \"created\",\n" - + "\"source_label\": \"person\",\n" - + "\"target_label\": \"software\",\n" - + "\"frequency\": \"SINGLE\",\n" - + "\"properties\":[\"date\", \"weight\"],\n" - + "\"sort_keys\":[],\n" - + "\"check_exist\": false,\n" - + "\"nullable_keys\":[]\n" - + "}"); - createAndAssert(path, "{\n" - + "\"name\": \"knows\",\n" - + "\"source_label\": \"person\",\n" - + "\"target_label\": \"person\",\n" - + "\"frequency\": \"MULTIPLE\",\n" - + "\"properties\":[\"date\", \"weight\"],\n" - + "\"sort_keys\":[\"date\"],\n" - + "\"check_exist\": false,\n" - + "\"nullable_keys\":[]\n" - + "}"); + createAndAssert(path, "{\n" + + "\"name\": \"created\",\n" + + "\"source_label\": \"person\",\n" + + "\"target_label\": \"software\",\n" + + "\"frequency\": \"SINGLE\",\n" + + "\"properties\":[\"date\", \"weight\"],\n" + + "\"sort_keys\":[],\n" + + "\"check_exist\": false,\n" + + "\"nullable_keys\":[]\n" + + "}"); + createAndAssert(path, "{\n" + + "\"name\": \"knows\",\n" + + "\"source_label\": \"person\",\n" + + "\"target_label\": \"person\",\n" + + "\"frequency\": \"MULTIPLE\",\n" + + "\"properties\":[\"date\", \"weight\"],\n" + + "\"sort_keys\":[\"date\"],\n" + + "\"check_exist\": false,\n" + + "\"nullable_keys\":[]\n" + + "}"); } protected static int initIndexLabel() { String path = URL_PREFIX + SCHEMA_ILS; - Response r = client.post(path, "{\n" - + "\"name\": \"personByCity\",\n" - + "\"base_type\": \"VERTEX_LABEL\",\n" - + "\"base_value\": \"person\",\n" - + "\"index_type\": \"SECONDARY\",\n" - + "\"check_exist\": false,\n" - + "\"rebuild\": false,\n" - + "\"fields\": [\n" - + "\"city\"\n" - + "]\n" - + "}"); + Response r = client.post(path, "{\n" + + "\"name\": \"personByCity\",\n" + + "\"base_type\": \"VERTEX_LABEL\",\n" + + "\"base_value\": \"person\",\n" + + "\"index_type\": \"SECONDARY\",\n" + + "\"check_exist\": false,\n" + + "\"rebuild\": false,\n" + + "\"fields\": [\n" + + "\"city\"\n" + + "]\n" + + "}"); String content = assertResponseStatus(202, r); return assertJsonContains(content, "task_id"); } @@ -322,48 +322,48 @@ protected static void initEdge() { String vadasId = ret.get("vadas"); String rippleId = ret.get("ripple"); - String body = String.format("[{" - + "\"label\": \"knows\"," - + "\"outV\": \"%s\"," - + "\"inV\": \"%s\"," - + "\"outVLabel\": \"person\"," - + "\"inVLabel\": \"person\"," - + "\"properties\": {" - + " \"date\": \"2021-01-01\"," - + " \"weight\":0.5}},{" - + "\"label\": \"knows\"," - + "\"outV\": \"%s\"," - + "\"inV\": \"%s\"," - + "\"outVLabel\": \"person\"," - + "\"inVLabel\": \"person\"," - + "\"properties\": {" - + " \"date\": \"2021-01-01\"," - + " \"weight\":0.4}},{" - + "\"label\": \"knows\"," - + "\"outV\": \"%s\"," - + "\"inV\": \"%s\"," - + "\"outVLabel\": \"person\"," - + "\"inVLabel\": \"person\"," - + "\"properties\": {" - + " \"date\": \"2021-01-01\"," - + " \"weight\":0.3}},{" - + "\"label\": \"created\"," - + "\"outV\": \"%s\"," - + "\"inV\": \"%s\"," - + "\"outVLabel\": \"person\"," - + "\"inVLabel\": \"software\"," - + "\"properties\": {" - + " \"date\": \"2021-01-01\"," - + " \"weight\":0.2}" - + "},{" - + "\"label\": \"created\"," - + "\"outV\": \"%s\"," - + "\"inV\": \"%s\"," - + "\"outVLabel\": \"person\"," - + "\"inVLabel\": \"software\"," - + "\"properties\": {" - + " \"date\": \"2021-01-01\"," - + " \"weight\":0.1}}]", + String body = String.format("[{" + + "\"label\": \"knows\"," + + "\"outV\": \"%s\"," + + "\"inV\": \"%s\"," + + "\"outVLabel\": \"person\"," + + "\"inVLabel\": \"person\"," + + "\"properties\": {" + + " \"date\": \"2021-01-01\"," + + " \"weight\":0.5}},{" + + "\"label\": \"knows\"," + + "\"outV\": \"%s\"," + + "\"inV\": \"%s\"," + + "\"outVLabel\": \"person\"," + + "\"inVLabel\": \"person\"," + + "\"properties\": {" + + " \"date\": \"2021-01-01\"," + + " \"weight\":0.4}},{" + + "\"label\": \"knows\"," + + "\"outV\": \"%s\"," + + "\"inV\": \"%s\"," + + "\"outVLabel\": \"person\"," + + "\"inVLabel\": \"person\"," + + "\"properties\": {" + + " \"date\": \"2021-01-01\"," + + " \"weight\":0.3}},{" + + "\"label\": \"created\"," + + "\"outV\": \"%s\"," + + "\"inV\": \"%s\"," + + "\"outVLabel\": \"person\"," + + "\"inVLabel\": \"software\"," + + "\"properties\": {" + + " \"date\": \"2021-01-01\"," + + " \"weight\":0.2}" + + "},{" + + "\"label\": \"created\"," + + "\"outV\": \"%s\"," + + "\"inV\": \"%s\"," + + "\"outVLabel\": \"person\"," + + "\"inVLabel\": \"software\"," + + "\"properties\": {" + + " \"date\": \"2021-01-01\"," + + " \"weight\":0.1}}]", markoId, peterId, peterId, joshId, joshId, vadasId, markoId, rippleId, peterId, rippleId); @@ -373,60 +373,60 @@ protected static void initEdge() { protected static void initVertex() { String path = URL_PREFIX + GRAPH_VERTEX; - createAndAssert(path, "{\n" - + "\"label\": \"person\",\n" - + "\"type\": \"vertex\",\n" - + "\"properties\":{" - + "\"name\": \"marko\"," - + "\"age\": 29," - + "\"city\": \"Beijing\"" - + "}\n" - + "}"); - createAndAssert(path, "{\n" - + "\"label\": \"person\",\n" - + "\"type\": \"vertex\",\n" - + "\"properties\":{" - + "\"name\": \"vadas\"," - + "\"age\": 27," - + "\"city\": \"HongKong\"" - + "}\n" - + "}"); - createAndAssert(path, "{\n" - + "\"label\": \"person\",\n" - + "\"type\": \"vertex\",\n" - + "\"properties\":{" - + "\"name\": \"josh\"," - + "\"age\": 32," - + "\"city\": \"Beijing\"" - + "}\n" - + "}"); - createAndAssert(path, "{\n" - + "\"label\": \"person\",\n" - + "\"type\": \"vertex\",\n" - + "\"properties\":{" - + "\"name\": \"peter\"," - + "\"age\": 35," - + "\"city\": \"Shanghai\"" - + "}\n" - + "}"); - createAndAssert(path, "{\n" - + "\"label\": \"software\",\n" - + "\"type\": \"vertex\",\n" - + "\"properties\":{" - + "\"name\": \"ripple\"," - + "\"lang\": \"java\"," - + "\"price\": 199" - + "}\n" - + "}"); - createAndAssert(path, "{\n" - + "\"label\": \"software\",\n" - + "\"type\": \"vertex\",\n" - + "\"properties\":{" - + "\"name\": \"lop\"," - + "\"lang\": \"java\"," - + "\"price\": 328" - + "}\n" - + "}"); + createAndAssert(path, "{\n" + + "\"label\": \"person\",\n" + + "\"type\": \"vertex\",\n" + + "\"properties\":{" + + "\"name\": \"marko\"," + + "\"age\": 29," + + "\"city\": \"Beijing\"" + + "}\n" + + "}"); + createAndAssert(path, "{\n" + + "\"label\": \"person\",\n" + + "\"type\": \"vertex\",\n" + + "\"properties\":{" + + "\"name\": \"vadas\"," + + "\"age\": 27," + + "\"city\": \"HongKong\"" + + "}\n" + + "}"); + createAndAssert(path, "{\n" + + "\"label\": \"person\",\n" + + "\"type\": \"vertex\",\n" + + "\"properties\":{" + + "\"name\": \"josh\"," + + "\"age\": 32," + + "\"city\": \"Beijing\"" + + "}\n" + + "}"); + createAndAssert(path, "{\n" + + "\"label\": \"person\",\n" + + "\"type\": \"vertex\",\n" + + "\"properties\":{" + + "\"name\": \"peter\"," + + "\"age\": 35," + + "\"city\": \"Shanghai\"" + + "}\n" + + "}"); + createAndAssert(path, "{\n" + + "\"label\": \"software\",\n" + + "\"type\": \"vertex\",\n" + + "\"properties\":{" + + "\"name\": \"ripple\"," + + "\"lang\": \"java\"," + + "\"price\": 199" + + "}\n" + + "}"); + createAndAssert(path, "{\n" + + "\"label\": \"software\",\n" + + "\"type\": \"vertex\",\n" + + "\"properties\":{" + + "\"name\": \"lop\"," + + "\"lang\": \"java\"," + + "\"price\": 328" + + "}\n" + + "}"); } protected static Response createAndAssert(String path, String body) { @@ -477,7 +477,7 @@ protected static String id2Json(String params) { protected static String getVertexId(String label, String key, String value) throws IOException { - String props = mapper.writeValueAsString(ImmutableMap.of(key, value)); + String props = MAPPER.writeValueAsString(ImmutableMap.of(key, value)); Map params = ImmutableMap.of( "label", label, "properties", URLEncoder.encode(props, "UTF-8") @@ -549,10 +549,10 @@ protected static void waitTaskSuccess(int task) { } protected static void waitTaskCompleted(int task) { - Set completed = ImmutableSet.of("success", - "cancelled", - "failed"); - waitTaskStatus(task, completed); + Set completed = ImmutableSet.of("success", + "cancelled", + "failed"); + waitTaskStatus(task, completed); } protected static void waitTaskStatus(int task, Set expectedStatus) { @@ -572,7 +572,7 @@ protected static void waitTaskStatus(int task, Set expectedStatus) { } protected static String parseId(String content) throws IOException { - Map map = mapper.readValue(content, Map.class); + Map map = MAPPER.readValue(content, Map.class); return (String) map.get("id"); } @@ -580,15 +580,15 @@ protected static List readList(String content, String key, Class clazz) { try { - JsonNode root = mapper.readTree(content); + JsonNode root = MAPPER.readTree(content); JsonNode element = root.get(key); if (element == null) { throw new HugeException(String.format( "Can't find value of the key: %s in json.", key)); } - JavaType type = mapper.getTypeFactory() + JavaType type = MAPPER.getTypeFactory() .constructParametricType(List.class, clazz); - return mapper.readValue(element.toString(), type); + return MAPPER.readValue(element.toString(), type); } catch (IOException e) { throw new HugeException(String.format( "Failed to deserialize %s", content), e); diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/EdgeApiTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/EdgeApiTest.java index 486a3cddf7..9e0b76ed0f 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/EdgeApiTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/EdgeApiTest.java @@ -45,16 +45,16 @@ public void testCreate() throws IOException { String outVId = getVertexId("person", "name", "peter"); String inVId = getVertexId("software", "name", "lop"); - String edge = String.format("{" - + "\"label\": \"created\"," - + "\"outVLabel\": \"person\"," - + "\"inVLabel\": \"software\"," - + "\"outV\": \"%s\"," - + "\"inV\": \"%s\"," - + "\"properties\":{" - + "\"date\": \"20170324\"," - + "\"weight\": 0.5}" - + "}", outVId, inVId); + String edge = String.format("{" + + "\"label\": \"created\"," + + "\"outVLabel\": \"person\"," + + "\"inVLabel\": \"software\"," + + "\"outV\": \"%s\"," + + "\"inV\": \"%s\"," + + "\"properties\":{" + + "\"date\": \"20170324\"," + + "\"weight\": 0.5}" + + "}", outVId, inVId); Response r = client().post(path, edge); assertResponseStatus(201, r); } @@ -64,44 +64,44 @@ public void testBatchUpdate() throws IOException { String outVId = getVertexId("person", "name", "marko"); String inVId = getVertexId("person", "name", "josh"); // Create - String edge = String.format("{" - + "\"label\": \"knows\"," - + "\"outVLabel\": \"person\"," - + "\"inVLabel\": \"person\"," - + "\"outV\": \"%s\"," - + "\"inV\": \"%s\"," - + "\"properties\":{" - + "\"date\": \"2013-02-20\"," - + "\"weight\": 1.0}" - + "}", outVId, inVId); + String edge = String.format("{" + + "\"label\": \"knows\"," + + "\"outVLabel\": \"person\"," + + "\"inVLabel\": \"person\"," + + "\"outV\": \"%s\"," + + "\"inV\": \"%s\"," + + "\"properties\":{" + + "\"date\": \"2013-02-20\"," + + "\"weight\": 1.0}" + + "}", outVId, inVId); Response r = client().post(path, edge); // The edge id is 'S1:marko>1>7JooBil0>S1:josh' String content = assertResponseStatus(201, r); String edgeId = parseId(content); // Update edge with edgeId - edge = String.format("{" - + "\"edges\":[" - + "{" - + "\"id\":\"%s\"," - + "\"label\":\"knows\"," - + "\"outV\":\"%s\"," - + "\"outVLabel\":\"person\"," - + "\"inV\":\"%s\"," - + "\"inVLabel\":\"person\"," - + "\"properties\":{" - + "\"weight\":0.2," - + "\"date\":\"2014-02-20\"" - + "}" - + "}" - + "]," - + "\"update_strategies\":{" - + "\"weight\":\"SUM\"," - + "\"date\":\"BIGGER\"" - + "}," - + "\"check_vertex\":false," - + "\"create_if_not_exist\":true" - + "}", edgeId, outVId, inVId); + edge = String.format("{" + + "\"edges\":[" + + "{" + + "\"id\":\"%s\"," + + "\"label\":\"knows\"," + + "\"outV\":\"%s\"," + + "\"outVLabel\":\"person\"," + + "\"inV\":\"%s\"," + + "\"inVLabel\":\"person\"," + + "\"properties\":{" + + "\"weight\":0.2," + + "\"date\":\"2014-02-20\"" + + "}" + + "}" + + "]," + + "\"update_strategies\":{" + + "\"weight\":\"SUM\"," + + "\"date\":\"BIGGER\"" + + "}," + + "\"check_vertex\":false," + + "\"create_if_not_exist\":true" + + "}", edgeId, outVId, inVId); r = client().put(path, "batch", edge, ImmutableMap.of()); // Now allowed to modify sortkey values, the property 'date' has changed content = assertResponseStatus(400, r); @@ -110,27 +110,27 @@ public void testBatchUpdate() throws IOException { "specified edge id")); // Update edge without edgeId - edge = String.format("{" - + "\"edges\":[" - + "{" - + "\"label\":\"knows\"," - + "\"outV\":\"%s\"," - + "\"outVLabel\":\"person\"," - + "\"inV\":\"%s\"," - + "\"inVLabel\":\"person\"," - + "\"properties\":{" - + "\"weight\":0.2," - + "\"date\":\"2014-02-20\"" - + "}" - + "}" - + "]," - + "\"update_strategies\":{" - + "\"weight\":\"SUM\"," - + "\"date\":\"BIGGER\"" - + "}," - + "\"check_vertex\":false," - + "\"create_if_not_exist\":true" - + "}", outVId, inVId); + edge = String.format("{" + + "\"edges\":[" + + "{" + + "\"label\":\"knows\"," + + "\"outV\":\"%s\"," + + "\"outVLabel\":\"person\"," + + "\"inV\":\"%s\"," + + "\"inVLabel\":\"person\"," + + "\"properties\":{" + + "\"weight\":0.2," + + "\"date\":\"2014-02-20\"" + + "}" + + "}" + + "]," + + "\"update_strategies\":{" + + "\"weight\":\"SUM\"," + + "\"date\":\"BIGGER\"" + + "}," + + "\"check_vertex\":false," + + "\"create_if_not_exist\":true" + + "}", outVId, inVId); r = client().put(path, "batch", edge, ImmutableMap.of()); // Add a new edge when sortkey value has changed content = assertResponseStatus(200, r); @@ -143,16 +143,16 @@ public void testGet() throws IOException { String outVId = getVertexId("person", "name", "peter"); String inVId = getVertexId("software", "name", "lop"); - String edge = String.format("{" - + "\"label\": \"created\"," - + "\"outVLabel\": \"person\"," - + "\"inVLabel\": \"software\"," - + "\"outV\": \"%s\"," - + "\"inV\": \"%s\"," - + "\"properties\":{" - + "\"date\": \"20170324\"," - + "\"weight\": 0.5}" - + "}", outVId, inVId); + String edge = String.format("{" + + "\"label\": \"created\"," + + "\"outVLabel\": \"person\"," + + "\"inVLabel\": \"software\"," + + "\"outV\": \"%s\"," + + "\"inV\": \"%s\"," + + "\"properties\":{" + + "\"date\": \"20170324\"," + + "\"weight\": 0.5}" + + "}", outVId, inVId); Response r = client().post(path, edge); String content = assertResponseStatus(201, r); @@ -166,16 +166,16 @@ public void testList() throws IOException { String outVId = getVertexId("person", "name", "peter"); String inVId = getVertexId("software", "name", "lop"); - String edge = String.format("{" - + "\"label\": \"created\"," - + "\"outVLabel\": \"person\"," - + "\"inVLabel\": \"software\"," - + "\"outV\": \"%s\"," - + "\"inV\": \"%s\"," - + "\"properties\":{" - + "\"date\": \"20170324\"," - + "\"weight\": 0.5}" - + "}", outVId, inVId); + String edge = String.format("{" + + "\"label\": \"created\"," + + "\"outVLabel\": \"person\"," + + "\"inVLabel\": \"software\"," + + "\"outV\": \"%s\"," + + "\"inV\": \"%s\"," + + "\"properties\":{" + + "\"date\": \"20170324\"," + + "\"weight\": 0.5}" + + "}", outVId, inVId); Response r = client().post(path, edge); assertResponseStatus(201, r); @@ -188,16 +188,16 @@ public void testDelete() throws IOException { String outVId = getVertexId("person", "name", "peter"); String inVId = getVertexId("software", "name", "lop"); - String edge = String.format("{" - + "\"label\": \"created\"," - + "\"outVLabel\": \"person\"," - + "\"inVLabel\": \"software\"," - + "\"outV\": \"%s\"," - + "\"inV\": \"%s\"," - + "\"properties\":{" - + "\"date\": \"20170324\"," - + "\"weight\": 0.5}" - + "}", outVId, inVId); + String edge = String.format("{" + + "\"label\": \"created\"," + + "\"outVLabel\": \"person\"," + + "\"inVLabel\": \"software\"," + + "\"outV\": \"%s\"," + + "\"inV\": \"%s\"," + + "\"properties\":{" + + "\"date\": \"20170324\"," + + "\"weight\": 0.5}" + + "}", outVId, inVId); Response r = client().post(path, edge); String content = assertResponseStatus(201, r); diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/EdgeLabelApiTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/EdgeLabelApiTest.java index aeec84826d..e8fedba83a 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/EdgeLabelApiTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/EdgeLabelApiTest.java @@ -39,42 +39,42 @@ public void prepareSchema() { @Test public void testCreate() { - String edgeLabel = "{" - + "\"name\": \"created\"," - + "\"source_label\": \"person\"," - + "\"target_label\": \"software\"," - + "\"frequency\": \"SINGLE\"," - + "\"properties\":[\"date\", \"city\"]," - + "\"nullable_keys\":[\"city\"]," - + "\"sort_keys\":[]" - + "}"; + String edgeLabel = "{" + + "\"name\": \"created\"," + + "\"source_label\": \"person\"," + + "\"target_label\": \"software\"," + + "\"frequency\": \"SINGLE\"," + + "\"properties\":[\"date\", \"city\"]," + + "\"nullable_keys\":[\"city\"]," + + "\"sort_keys\":[]" + + "}"; Response r = client().post(path, edgeLabel); assertResponseStatus(201, r); } @Test public void testAppend() { - String edgeLabel = "{" - + "\"name\": \"created\"," - + "\"source_label\": \"person\"," - + "\"target_label\": \"software\"," - + "\"frequency\": \"SINGLE\"," - + "\"properties\":[\"date\", \"city\"]," - + "\"nullable_keys\":[\"city\"]," - + "\"sort_keys\":[]" - + "}"; + String edgeLabel = "{" + + "\"name\": \"created\"," + + "\"source_label\": \"person\"," + + "\"target_label\": \"software\"," + + "\"frequency\": \"SINGLE\"," + + "\"properties\":[\"date\", \"city\"]," + + "\"nullable_keys\":[\"city\"]," + + "\"sort_keys\":[]" + + "}"; Response r = client().post(path, edgeLabel); assertResponseStatus(201, r); - edgeLabel = "{" - + "\"name\": \"created\"," - + "\"source_label\": null," - + "\"target_label\": null," - + "\"frequency\": \"DEFAULT\"," - + "\"properties\":[\"lang\"]," - + "\"nullable_keys\":[\"lang\"]," - + "\"sort_keys\":[]" - + "}"; + edgeLabel = "{" + + "\"name\": \"created\"," + + "\"source_label\": null," + + "\"target_label\": null," + + "\"frequency\": \"DEFAULT\"," + + "\"properties\":[\"lang\"]," + + "\"nullable_keys\":[\"lang\"]," + + "\"sort_keys\":[]" + + "}"; Map params = ImmutableMap.of("action", "append"); r = client().put(path, "created", edgeLabel, params); assertResponseStatus(200, r); @@ -82,15 +82,15 @@ public void testAppend() { @Test public void testGet() { - String edgeLabel = "{" - + "\"name\": \"created\"," - + "\"source_label\": \"person\"," - + "\"target_label\": \"software\"," - + "\"frequency\": \"SINGLE\"," - + "\"properties\":[\"date\", \"city\"]," - + "\"nullable_keys\":[\"city\"]," - + "\"sort_keys\":[]" - + "}"; + String edgeLabel = "{" + + "\"name\": \"created\"," + + "\"source_label\": \"person\"," + + "\"target_label\": \"software\"," + + "\"frequency\": \"SINGLE\"," + + "\"properties\":[\"date\", \"city\"]," + + "\"nullable_keys\":[\"city\"]," + + "\"sort_keys\":[]" + + "}"; Response r = client().post(path, edgeLabel); assertResponseStatus(201, r); @@ -101,15 +101,15 @@ public void testGet() { @Test public void testList() { - String edgeLabel = "{" - + "\"name\": \"created\"," - + "\"source_label\": \"person\"," - + "\"target_label\": \"software\"," - + "\"frequency\": \"SINGLE\"," - + "\"properties\":[\"date\", \"city\"]," - + "\"nullable_keys\":[\"city\"]," - + "\"sort_keys\":[]" - + "}"; + String edgeLabel = "{" + + "\"name\": \"created\"," + + "\"source_label\": \"person\"," + + "\"target_label\": \"software\"," + + "\"frequency\": \"SINGLE\"," + + "\"properties\":[\"date\", \"city\"]," + + "\"nullable_keys\":[\"city\"]," + + "\"sort_keys\":[]" + + "}"; Response r = client().post(path, edgeLabel); assertResponseStatus(201, r); @@ -119,15 +119,15 @@ public void testList() { @Test public void testDelete() { - String edgeLabel = "{" - + "\"name\": \"created\"," - + "\"source_label\": \"person\"," - + "\"target_label\": \"software\"," - + "\"frequency\": \"SINGLE\"," - + "\"properties\":[\"date\", \"city\"]," - + "\"nullable_keys\":[\"city\"]," - + "\"sort_keys\":[]" - + "}"; + String edgeLabel = "{" + + "\"name\": \"created\"," + + "\"source_label\": \"person\"," + + "\"target_label\": \"software\"," + + "\"frequency\": \"SINGLE\"," + + "\"properties\":[\"date\", \"city\"]," + + "\"nullable_keys\":[\"city\"]," + + "\"sort_keys\":[]" + + "}"; Response r = client().post(path, edgeLabel); assertResponseStatus(201, r); diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/GremlinApiTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/GremlinApiTest.java index f5843875d4..a854ddfaa1 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/GremlinApiTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/GremlinApiTest.java @@ -36,11 +36,11 @@ public class GremlinApiTest extends BaseApiTest { @Test public void testPost() { - String body = "{" - + "\"gremlin\":\"g.V()\"," - + "\"bindings\":{}," - + "\"language\":\"gremlin-groovy\"," - + "\"aliases\":{\"g\":\"__g_hugegraph\"}}"; + String body = "{" + + "\"gremlin\":\"g.V()\"," + + "\"bindings\":{}," + + "\"language\":\"gremlin-groovy\"," + + "\"aliases\":{\"g\":\"__g_hugegraph\"}}"; assertResponseStatus(200, client().post(path, body)); } @@ -54,24 +54,30 @@ public void testGet() { @Test public void testScript() { - String bodyTemplate = "{" - + "\"gremlin\":\"%s\"," - + "\"bindings\":{}," - + "\"language\":\"gremlin-groovy\"," - + "\"aliases\":{\"g\":\"__g_hugegraph\"}}"; - - String script = "schema=hugegraph.schema();" - + "schema.propertyKey('name').asText().ifNotExist().create();" - + "schema.propertyKey('age').asInt().ifNotExist().create();" - + "schema.propertyKey('city').asUUID().ifNotExist().create();" - + "schema.propertyKey('lang').asText().ifNotExist().create();" - + "schema.propertyKey('date').asText().ifNotExist().create();" - + "schema.propertyKey('price').asInt().ifNotExist().create();" - + "person=schema.vertexLabel('person').properties('name','age','city').useCustomizeUuidId().ifNotExist().create();" - + "knows=schema.edgeLabel('knows').sourceLabel('person').targetLabel('person').properties('date').ifNotExist().create();" - + "marko=hugegraph.addVertex(T.id,'835e1153928149578691cf79258e90eb',T.label,'person','name','marko','age',29,'city','135e1153928149578691cf79258e90eb');" - + "vadas=hugegraph.addVertex(T.id,'935e1153928149578691cf79258e90eb',T.label,'person','name','vadas','age',27,'city','235e1153928149578691cf79258e90eb');" - + "marko.addEdge('knows',vadas,'date','20160110');"; + String bodyTemplate = "{" + + "\"gremlin\":\"%s\"," + + "\"bindings\":{}," + + "\"language\":\"gremlin-groovy\"," + + "\"aliases\":{\"g\":\"__g_hugegraph\"}}"; + + String script = "schema=hugegraph.schema();" + + "schema.propertyKey('name').asText().ifNotExist().create();" + + "schema.propertyKey('age').asInt().ifNotExist().create();" + + "schema.propertyKey('city').asUUID().ifNotExist().create();" + + "schema.propertyKey('lang').asText().ifNotExist().create();" + + "schema.propertyKey('date').asText().ifNotExist().create();" + + "schema.propertyKey('price').asInt().ifNotExist().create();" + + "person=schema.vertexLabel('person').properties('name','age','city')." + + "useCustomizeUuidId().ifNotExist().create();" + + "knows=schema.edgeLabel('knows').sourceLabel('person').targetLabel('person')." + + "properties('date').ifNotExist().create();" + + "marko=hugegraph.addVertex(T.id,'835e1153928149578691cf79258e90eb'" + + ",T.label,'person','name','marko','age',29," + + "'city','135e1153928149578691cf79258e90eb');" + + "vadas=hugegraph.addVertex(T.id,'935e1153928149578691cf79258e90eb'" + + ",T.label,'person','name','vadas','age',27," + + "'city','235e1153928149578691cf79258e90eb');" + + "marko.addEdge('knows',vadas,'date','20160110');"; String body = String.format(bodyTemplate, script); assertResponseStatus(200, client().post(path, body)); @@ -86,12 +92,12 @@ public void testScript() { @Test public void testClearAndInit() { - String body = "{" - + "\"gremlin\":\"hugegraph.backendStoreFeatures()" - + " .supportsSharedStorage();\"," - + "\"bindings\":{}," - + "\"language\":\"gremlin-groovy\"," - + "\"aliases\":{\"g\":\"__g_hugegraph\"}}"; + String body = "{" + + "\"gremlin\":\"hugegraph.backendStoreFeatures()" + + " .supportsSharedStorage();\"," + + "\"bindings\":{}," + + "\"language\":\"gremlin-groovy\"," + + "\"aliases\":{\"g\":\"__g_hugegraph\"}}"; String content = assertResponseStatus(200, client().post(path, body)); Map result = assertJsonContains(content, "result"); @SuppressWarnings({ "unchecked" }) @@ -100,38 +106,38 @@ public void testClearAndInit() { Assume.assumeTrue("Can't clear non-shared-storage backend", supportsSharedStorage); - body = "{" - + "\"gremlin\":\"" - + " if (!hugegraph.backendStoreFeatures()" - + " .supportsSharedStorage())" - + " return;" - + " def auth = hugegraph.hugegraph().authManager();" - + " def admin = auth.findUser('admin');" - + " hugegraph.clearBackend();" - + " hugegraph.initBackend();" - + " auth.createUser(admin);\"," - + "\"bindings\":{}," - + "\"language\":\"gremlin-groovy\"," - + "\"aliases\":{\"g\":\"__g_hugegraph\"}}"; + body = "{" + + "\"gremlin\":\"" + + " if (!hugegraph.backendStoreFeatures()" + + " .supportsSharedStorage())" + + " return;" + + " def auth = hugegraph.hugegraph().authManager();" + + " def admin = auth.findUser('admin');" + + " hugegraph.clearBackend();" + + " hugegraph.initBackend();" + + " auth.createUser(admin);\"," + + "\"bindings\":{}," + + "\"language\":\"gremlin-groovy\"," + + "\"aliases\":{\"g\":\"__g_hugegraph\"}}"; assertResponseStatus(200, client().post(path, body)); - body = "{" - + "\"gremlin\":\"hugegraph.serverStarted(" - + " IdGenerator.of('server1'), NodeRole.MASTER)\"," - + "\"bindings\":{}," - + "\"language\":\"gremlin-groovy\"," - + "\"aliases\":{\"g\":\"__g_hugegraph\"}}"; + body = "{" + + "\"gremlin\":\"hugegraph.serverStarted(" + + " IdGenerator.of('server1'), NodeRole.MASTER)\"," + + "\"bindings\":{}," + + "\"language\":\"gremlin-groovy\"," + + "\"aliases\":{\"g\":\"__g_hugegraph\"}}"; assertResponseStatus(200, client().post(path, body)); } @Test public void testTruncate() { - String body = "{" - + "\"gremlin\":\"try {hugegraph.truncateBackend()} " - + "catch (UnsupportedOperationException e) {}\"," - + "\"bindings\":{}," - + "\"language\":\"gremlin-groovy\"," - + "\"aliases\":{\"g\":\"__g_hugegraph\"}}"; + String body = "{" + + "\"gremlin\":\"try {hugegraph.truncateBackend()} " + + "catch (UnsupportedOperationException e) {}\"," + + "\"bindings\":{}," + + "\"language\":\"gremlin-groovy\"," + + "\"aliases\":{\"g\":\"__g_hugegraph\"}}"; assertResponseStatus(200, client().post(path, body)); } @@ -139,74 +145,74 @@ public void testTruncate() { public void testSetVertexProperty() { String pkPath = "/graphs/hugegraph/schema/propertykeys/"; // Cardinality single - String foo = "{" - + "\"name\": \"foo\"," - + "\"data_type\": \"TEXT\"," - + "\"cardinality\": \"SINGLE\"," - + "\"properties\":[]" - + "}"; + String foo = "{" + + "\"name\": \"foo\"," + + "\"data_type\": \"TEXT\"," + + "\"cardinality\": \"SINGLE\"," + + "\"properties\":[]" + + "}"; assertResponseStatus(202, client().post(pkPath, foo)); // Cardinality list - String bar = "{" - + "\"name\": \"bar\"," - + "\"data_type\": \"TEXT\"," - + "\"cardinality\": \"LIST\"," - + "\"properties\":[]" - + "}"; + String bar = "{" + + "\"name\": \"bar\"," + + "\"data_type\": \"TEXT\"," + + "\"cardinality\": \"LIST\"," + + "\"properties\":[]" + + "}"; assertResponseStatus(202, client().post(pkPath, bar)); String vlPath = "/graphs/hugegraph/schema/vertexlabels/"; - String vertexLabel = "{" - + "\"name\": \"person\"," - + "\"id_strategy\": \"CUSTOMIZE_STRING\"," - + "\"properties\": [\"foo\", \"bar\"]" - + "}"; + String vertexLabel = "{" + + "\"name\": \"person\"," + + "\"id_strategy\": \"CUSTOMIZE_STRING\"," + + "\"properties\": [\"foo\", \"bar\"]" + + "}"; assertResponseStatus(201, client().post(vlPath, vertexLabel)); // Not supply cardinality - String body = "{" - + "\"gremlin\":\"g.addV('person').property(T.id, '1')" - + ".property('foo', '123').property('bar', '123')\"," - + "\"bindings\":{}," - + "\"language\":\"gremlin-groovy\"," - + "\"aliases\":{\"g\":\"__g_hugegraph\"}}"; + String body = "{" + + "\"gremlin\":\"g.addV('person').property(T.id, '1')" + + ".property('foo', '123').property('bar', '123')\"," + + "\"bindings\":{}," + + "\"language\":\"gremlin-groovy\"," + + "\"aliases\":{\"g\":\"__g_hugegraph\"}}"; assertResponseStatus(200, client().post(path, body)); // Supply matched cardinality - body = "{\"gremlin\":\"g.addV('person').property(T.id, '1')" - + ".property(single, 'foo', '123')" - + ".property(list, 'bar', '123')\"," - + "\"bindings\":{}," - + "\"language\":\"gremlin-groovy\"," - + "\"aliases\":{\"g\":\"__g_hugegraph\"}}"; + body = "{\"gremlin\":\"g.addV('person').property(T.id, '1')" + + ".property(single, 'foo', '123')" + + ".property(list, 'bar', '123')\"," + + "\"bindings\":{}," + + "\"language\":\"gremlin-groovy\"," + + "\"aliases\":{\"g\":\"__g_hugegraph\"}}"; assertResponseStatus(200, client().post(path, body)); // Supply unmatch cardinality - body = "{\"gremlin\":\"g.addV('person').property(T.id, '1')" - + ".property(list, 'foo', '123')" - + ".property(list, 'bar', '123')\"," - + "\"bindings\":{}," - + "\"language\":\"gremlin-groovy\"," - + "\"aliases\":{\"g\":\"__g_hugegraph\"}}"; + body = "{\"gremlin\":\"g.addV('person').property(T.id, '1')" + + ".property(list, 'foo', '123')" + + ".property(list, 'bar', '123')\"," + + "\"bindings\":{}," + + "\"language\":\"gremlin-groovy\"," + + "\"aliases\":{\"g\":\"__g_hugegraph\"}}"; assertResponseStatus(400, client().post(path, body)); // NOTE: supply unmatch cardinality, but we give up the check - body = "{\"gremlin\":\"g.addV('person').property(T.id, '1')" - + ".property(single, 'foo', '123')" - + ".property(single, 'bar', '123')\"," - + "\"bindings\":{}," - + "\"language\":\"gremlin-groovy\"," - + "\"aliases\":{\"g\":\"__g_hugegraph\"}}"; + body = "{\"gremlin\":\"g.addV('person').property(T.id, '1')" + + ".property(single, 'foo', '123')" + + ".property(single, 'bar', '123')\"," + + "\"bindings\":{}," + + "\"language\":\"gremlin-groovy\"," + + "\"aliases\":{\"g\":\"__g_hugegraph\"}}"; assertResponseStatus(200, client().post(path, body)); } @Test public void testFileSerialize() { - String body = "{" - + "\"gremlin\":\"File file = new File('test.text')\"," - + "\"bindings\":{}," - + "\"language\":\"gremlin-groovy\"," - + "\"aliases\":{\"g\":\"__g_hugegraph\"}}"; + String body = "{" + + "\"gremlin\":\"File file = new File('test.text')\"," + + "\"bindings\":{}," + + "\"language\":\"gremlin-groovy\"," + + "\"aliases\":{\"g\":\"__g_hugegraph\"}}"; Response r = client().post(path, body); String content = r.readEntity(String.class); Assert.assertTrue(content, r.getStatus() == 200); diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/IndexLabelApiTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/IndexLabelApiTest.java index ac68408364..77a6ba766f 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/IndexLabelApiTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/IndexLabelApiTest.java @@ -40,37 +40,37 @@ public void prepareSchema() { @Test public void testCreate() { - String indexLabel = "{" - + "\"name\": \"personByAge\"," - + "\"base_type\": \"VERTEX_LABEL\"," - + "\"base_value\": \"person\"," - + "\"index_type\": \"RANGE\"," - + "\"fields\":[\"age\"]" - + "}"; + String indexLabel = "{" + + "\"name\": \"personByAge\"," + + "\"base_type\": \"VERTEX_LABEL\"," + + "\"base_value\": \"person\"," + + "\"index_type\": \"RANGE\"," + + "\"fields\":[\"age\"]" + + "}"; Response r = client().post(path, indexLabel); assertResponseStatus(202, r); } @Test public void testAppend() { - String indexLabel = "{" - + "\"name\": \"personByAge\"," - + "\"base_type\": \"VERTEX_LABEL\"," - + "\"base_value\": \"person\"," - + "\"index_type\": \"RANGE\"," - + "\"fields\":[\"age\"]" - + "}"; + String indexLabel = "{" + + "\"name\": \"personByAge\"," + + "\"base_type\": \"VERTEX_LABEL\"," + + "\"base_value\": \"person\"," + + "\"index_type\": \"RANGE\"," + + "\"fields\":[\"age\"]" + + "}"; Response r = client().post(path, indexLabel); assertResponseStatus(202, r); - indexLabel = "{" - + "\"name\": \"personByAge\"," - + "\"user_data\": {" - + "\"min\": 0," - + "\"max\": 100" - + "}" - + "}"; + indexLabel = "{" + + "\"name\": \"personByAge\"," + + "\"user_data\": {" + + "\"min\": 0," + + "\"max\": 100" + + "}" + + "}"; Map params = ImmutableMap.of("action", "append"); r = client().put(path, "personByAge", indexLabel, params); assertResponseStatus(200, r); @@ -78,26 +78,26 @@ public void testAppend() { @Test public void testEliminate() { - String indexLabel = "{" - + "\"name\": \"personByAge\"," - + "\"base_type\": \"VERTEX_LABEL\"," - + "\"base_value\": \"person\"," - + "\"index_type\": \"RANGE\"," - + "\"fields\":[\"age\"]," - + "\"user_data\": {" - + "\"min\": 0," - + "\"max\": 100" - + "}" - + "}"; + String indexLabel = "{" + + "\"name\": \"personByAge\"," + + "\"base_type\": \"VERTEX_LABEL\"," + + "\"base_value\": \"person\"," + + "\"index_type\": \"RANGE\"," + + "\"fields\":[\"age\"]," + + "\"user_data\": {" + + "\"min\": 0," + + "\"max\": 100" + + "}" + + "}"; Response r = client().post(path, indexLabel); assertResponseStatus(202, r); - indexLabel = "{" - + "\"name\": \"personByAge\"," - + "\"user_data\": {" - + "\"min\": 0" - + "}" - + "}"; + indexLabel = "{" + + "\"name\": \"personByAge\"," + + "\"user_data\": {" + + "\"min\": 0" + + "}" + + "}"; Map params = ImmutableMap.of("action", "eliminate"); r = client().put(path, "personByAge", indexLabel, params); assertResponseStatus(200, r); @@ -105,13 +105,13 @@ public void testEliminate() { @Test public void testGet() { - String indexLabel = "{" - + "\"name\": \"personByAge\"," - + "\"base_type\": \"VERTEX_LABEL\"," - + "\"base_value\": \"person\"," - + "\"index_type\": \"RANGE\"," - + "\"fields\":[\"age\"]" - + "}"; + String indexLabel = "{" + + "\"name\": \"personByAge\"," + + "\"base_type\": \"VERTEX_LABEL\"," + + "\"base_value\": \"person\"," + + "\"index_type\": \"RANGE\"," + + "\"fields\":[\"age\"]" + + "}"; Response r = client().post(path, indexLabel); assertResponseStatus(202, r); @@ -122,13 +122,13 @@ public void testGet() { @Test public void testList() { - String indexLabel = "{" - + "\"name\": \"personByAge\"," - + "\"base_type\": \"VERTEX_LABEL\"," - + "\"base_value\": \"person\"," - + "\"index_type\": \"RANGE\"," - + "\"fields\":[\"age\"]" - + "}"; + String indexLabel = "{" + + "\"name\": \"personByAge\"," + + "\"base_type\": \"VERTEX_LABEL\"," + + "\"base_value\": \"person\"," + + "\"index_type\": \"RANGE\"," + + "\"fields\":[\"age\"]" + + "}"; Response r = client().post(path, indexLabel); assertResponseStatus(202, r); @@ -138,13 +138,13 @@ public void testList() { @Test public void testDelete() { - String indexLabel = "{" - + "\"name\": \"personByAge\"," - + "\"base_type\": \"VERTEX_LABEL\"," - + "\"base_value\": \"person\"," - + "\"index_type\": \"RANGE\"," - + "\"fields\":[\"age\"]" - + "}"; + String indexLabel = "{" + + "\"name\": \"personByAge\"," + + "\"base_type\": \"VERTEX_LABEL\"," + + "\"base_value\": \"person\"," + + "\"index_type\": \"RANGE\"," + + "\"fields\":[\"age\"]" + + "}"; Response r = client().post(path, indexLabel); assertResponseStatus(202, r); diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/LoginApiTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/LoginApiTest.java index 5ebc025174..2a3b63d9c5 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/LoginApiTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/LoginApiTest.java @@ -87,7 +87,10 @@ public void testLogout() { r = client().delete(path, headers); assertResponseStatus(204, r); - String invalidToken = "eyJhbGciOiJIUzI1NiJ9.eyJ1caVyX25hbWUiOiJ0ZXN0IiwidXNlcl9pZCI6Ii02Mzp0ZXN0IiwiZXhwIjoxNjI0MzUzMjUyfQ.kYot-3mSGlfSbEMzxrTs84q8YanhTTxtsKPPG25CNxA"; + String invalidToken = "eyJhbGciOiJIUzI1NiJ9.eyJ1caVyX25hb" + + "WUiOiJ0ZXN0IiwidXNlcl9pZCI6Ii02Mzp0ZXN0I" + + "iwiZXhwIjoxNjI0MzUzMjUyfQ.kYot-3mSGlfSbE" + + "MzxrTs84q8YanhTTxtsKPPG25CNxA"; headers = new MultivaluedHashMap<>(); headers.add(HttpHeaders.AUTHORIZATION, "Bearer " + invalidToken); r = client().delete(path, headers); @@ -120,7 +123,10 @@ public void testVerify() { Assert.assertEquals(this.userId4Test, user.get("user_id")); Assert.assertEquals("test", user.get("user_name")); - String invalidToken = "eyJhbGciOiJIUzI1NiJ9.eyJ1caVyX25hbWUiOiJ0ZXN0IiwidXNlcl9pZCI6Ii02Mzp0ZXN0IiwiZXhwIjoxNjI0MzUzMjUyfQ.kYot-3mSGlfSbEMzxrTs84q8YanhTTxtsKPPG25CNxA"; + String invalidToken = "eyJhbGciOiJIUzI1NiJ9.eyJ1caVyX25hb" + + "WUiOiJ0ZXN0IiwidXNlcl9pZCI6Ii02Mzp0ZXN0I" + + "iwiZXhwIjoxNjI0MzUzMjUyfQ.kYot-3mSGlfSbE" + + "MzxrTs84q8YanhTTxtsKPPG25CNxA"; headers = new MultivaluedHashMap<>(); headers.add(HttpHeaders.AUTHORIZATION, "Bearer " + invalidToken); r = client().get(path, headers); diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/ProjectApiTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/ProjectApiTest.java index 89d6611ae0..bed6992d9c 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/ProjectApiTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/ProjectApiTest.java @@ -35,12 +35,12 @@ public class ProjectApiTest extends BaseApiTest { - private final static String path = "graphs/hugegraph/auth/projects"; + private static final String PATH = "graphs/hugegraph/auth/projects"; @Override @After public void teardown() throws Exception { - Response resp = client().get(path); + Response resp = client().get(PATH); String respBody = assertResponseStatus(200, resp); List projects = readList(respBody, "projects", Map.class); for (Object project : projects) { @@ -53,7 +53,7 @@ public void teardown() throws Exception { Map graphs = ImmutableMap.of("project_graphs", projectGraphs); resp = client().target() - .path(path) + .path(PATH) .path(projectId) .queryParam("action", "remove_graph") .request() @@ -62,7 +62,7 @@ public void teardown() throws Exception { } // delete project resp = client().target() - .path(path) + .path(PATH) .path(projectId) .request() .delete(); @@ -75,7 +75,7 @@ public void testCreate() { String project = String.format("{\"project_name\": \"test_project\"," + "\"project_description\": " + "\"this is a good project\"}"); - Response resp = client().post(path, project); + Response resp = client().post(PATH, project); String respBody = assertResponseStatus(201, resp); String projectName = assertJsonContains(respBody, "project_name"); Assert.assertEquals("test_project", projectName); @@ -98,7 +98,7 @@ public void testDelete() { "this is a good project"); String projectId = assertJsonContains(project, "id"); Response resp = client().target() - .path(path) + .path(PATH) .path(projectId) .request() .delete(); @@ -118,7 +118,7 @@ public void testGet() { public void testList() { createProject("test_project", null); createProject("test_project2", null); - Response resp = client().get(path); + Response resp = client().get(PATH); String respBody = assertResponseStatus(200, resp); List projects = readList(respBody, "projects", Map.class); Assert.assertNotNull(projects); @@ -129,7 +129,7 @@ public void testList() { public void testUpdate() { String project = "{\"project_description\": \"update desc\"}"; Response resp = client().target() - .path(path) + .path(PATH) .path("no_exist_id") .request() .put(Entity.json(project)); @@ -139,7 +139,7 @@ public void testUpdate() { "desc"), "id"); resp = client().target() - .path(path) + .path(PATH) .path(projectId) .request() .put(Entity.json(project)); @@ -156,7 +156,7 @@ public void testAddGraphs() { String graphs = "{\"project_graphs\":[\"graph_test\", " + "\"graph_test2\"]}"; Response resp = client().target() - .path(path) + .path(PATH) .path(projectId) .queryParam("action", "add_graph") .request() @@ -176,7 +176,7 @@ public void testRemoveGraphs() { "graph_test"); String graphs = "{\"project_graphs\":[\"graph_test\"]}"; Response resp = client().target() - .path(path) + .path(PATH) .path(projectId) .queryParam("action", "remove_graph") .request() @@ -190,7 +190,7 @@ public void testRemoveGraphs() { graphs = "{\"project_graphs\":[\"graph_test1\"]}"; resp = client().target() - .path(path) + .path(PATH) .path(projectId) .queryParam("action", "remove_graph") .request() @@ -207,7 +207,7 @@ private String createProject(String name, String desc) { String project = String.format("{\"project_name\": \"%s\"," + "\"project_description\": " + "\"%s\"}", name, desc); - Response resp = client().post(path, project); + Response resp = client().post(PATH, project); String respBody = assertResponseStatus(201, resp); String projectName = assertJsonContains(respBody, "project_name"); Assert.assertEquals(name, projectName); @@ -244,7 +244,7 @@ private void addGraphsToProject(String projectId, String... graphNames) { String graphs = String.format("{\"project_graphs\":[%s]}", graphNamesBuilder); Response resp = client().target() - .path(path) + .path(PATH) .path(projectId) .queryParam("action", "add_graph") .request() @@ -254,7 +254,7 @@ private void addGraphsToProject(String projectId, String... graphNames) { private String getProject(String projectId) { Response resp = client().target() - .path(path) + .path(PATH) .path(projectId) .request() .get(); diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/PropertyKeyApiTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/PropertyKeyApiTest.java index fe804325b0..3b93e5cbd3 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/PropertyKeyApiTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/PropertyKeyApiTest.java @@ -30,24 +30,24 @@ public class PropertyKeyApiTest extends BaseApiTest { @Test public void testCreate() { - String propertyKey = "{" - + "\"name\": \"id\"," - + "\"data_type\": \"TEXT\"," - + "\"cardinality\": \"SINGLE\"," - + "\"properties\":[]" - + "}"; + String propertyKey = "{" + + "\"name\": \"id\"," + + "\"data_type\": \"TEXT\"," + + "\"cardinality\": \"SINGLE\"," + + "\"properties\":[]" + + "}"; Response r = client().post(path, propertyKey); assertResponseStatus(202, r); } @Test public void testGet() { - String propertyKey = "{" - + "\"name\": \"id\"," - + "\"data_type\": \"TEXT\"," - + "\"cardinality\": \"SINGLE\"," - + "\"properties\":[]" - + "}"; + String propertyKey = "{" + + "\"name\": \"id\"," + + "\"data_type\": \"TEXT\"," + + "\"cardinality\": \"SINGLE\"," + + "\"properties\":[]" + + "}"; Response r = client().post(path, propertyKey); assertResponseStatus(202, r); @@ -58,12 +58,12 @@ public void testGet() { @Test public void testList() { - String propertyKey = "{" - + "\"name\": \"id\"," - + "\"data_type\": \"TEXT\"," - + "\"cardinality\": \"SINGLE\"," - + "\"properties\":[]" - + "}"; + String propertyKey = "{" + + "\"name\": \"id\"," + + "\"data_type\": \"TEXT\"," + + "\"cardinality\": \"SINGLE\"," + + "\"properties\":[]" + + "}"; Response r = client().post(path, propertyKey); assertResponseStatus(202, r); @@ -73,12 +73,12 @@ public void testList() { @Test public void testDelete() { - String propertyKey = "{" - + "\"name\": \"id\"," - + "\"data_type\": \"TEXT\"," - + "\"cardinality\": \"SINGLE\"," - + "\"properties\":[]" - + "}"; + String propertyKey = "{" + + "\"name\": \"id\"," + + "\"data_type\": \"TEXT\"," + + "\"cardinality\": \"SINGLE\"," + + "\"properties\":[]" + + "}"; Response r = client().post(path, propertyKey); assertResponseStatus(202, r); diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/TaskApiTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/TaskApiTest.java index ff936bae7c..f105217dda 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/TaskApiTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/TaskApiTest.java @@ -147,11 +147,11 @@ private int rebuild() { } private int gremlinJob() { - String body = "{" - + "\"gremlin\":\"Thread.sleep(1000L)\"," - + "\"bindings\":{}," - + "\"language\":\"gremlin-groovy\"," - + "\"aliases\":{}}"; + String body = "{" + + "\"gremlin\":\"Thread.sleep(1000L)\"," + + "\"bindings\":{}," + + "\"language\":\"gremlin-groovy\"," + + "\"aliases\":{}}"; String path = "/graphs/hugegraph/jobs/gremlin"; String content = assertResponseStatus(201, client().post(path, body)); return assertJsonContains(content, "task_id"); diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/UserApiTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/UserApiTest.java index 29eb5a7a8a..ac78a6ceec 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/UserApiTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/UserApiTest.java @@ -34,14 +34,14 @@ public class UserApiTest extends BaseApiTest { - private static final String path = "graphs/hugegraph/auth/users"; + private static final String PATH = "graphs/hugegraph/auth/users"; private static final int NO_LIMIT = -1; @Override @After public void teardown() throws Exception { super.teardown(); - Response r = this.client().get(path, + Response r = this.client().get(PATH, ImmutableMap.of("limit", NO_LIMIT)); String result = r.readEntity(String.class); Map>> resultMap = @@ -53,7 +53,7 @@ public void teardown() throws Exception { if (user.get("user_name").equals("admin")) { continue; } - this.client().delete(path, (String) user.get("id")); + this.client().delete(PATH, (String) user.get("id")); } } @@ -68,9 +68,9 @@ public void testCreate() { "\"user_phone\":\"1357924680\"," + "\"user_avatar\":\"image2.jpg\"}"; - Response r = client().post(path, user1); + Response r = client().post(PATH, user1); String result = assertResponseStatus(201, r); - Response r2 = client().post(path, user2); + Response r2 = client().post(PATH, user2); String result2 = assertResponseStatus(201, r2); assertJsonContains(result, "user_name"); @@ -85,14 +85,14 @@ public void testCreate() { assertJsonContains(result2, "user_phone"); assertJsonContains(result2, "user_avatar"); - Response r3 = client().post(path, "{}"); + Response r3 = client().post(PATH, "{}"); assertResponseStatus(400, r3); String user3 = "{\"user_name\":\"user1\",\"user_password\":\"p1\"," + "\"user_email\":\"user1@baidu.com\"," + "\"user_phone\":\"123456789\",\"user_avatar\":\"image1" + ".jpg\"}"; - Response r4 = client().post(path, user3); + Response r4 = client().post(PATH, user3); String result4 = assertResponseStatus(400, r4); String message = assertJsonContains(result4, "message"); Assert.assertThat(message, @@ -114,7 +114,7 @@ public void testGetUser() { createUser("test2"); List> users = listUsers(); for (Map user : users) { - Response r = client().get(path, (String) user.get("id")); + Response r = client().get(PATH, (String) user.get("id")); String result = assertResponseStatus(200, r); assertJsonContains(result, "user_name"); } @@ -134,7 +134,7 @@ public void testUpdate() { "\"user_phone\":\"111111\"," + "\"user_avatar\":\"image1" + ".jpg\"}"; - Response r = client().put(path, (String) user.get("id"), user1, + Response r = client().put(PATH, (String) user.get("id"), user1, ImmutableMap.of()); assertResponseStatus(200, r); } @@ -151,10 +151,10 @@ public void testDelete() { if (user.get("user_name").equals("admin")) { continue; } - Response r = client().delete(path, (String) user.get("id")); + Response r = client().delete(PATH, (String) user.get("id")); assertResponseStatus(204, r); } - Response r = client().delete(path, "test1"); + Response r = client().delete(PATH, "test1"); String result = assertResponseStatus(400, r); String message = assertJsonContains(result, "message"); Assert.assertThat(message, @@ -166,12 +166,12 @@ protected void createUser(String name) { "\", \"user_email\":\"user1@baidu.com\"," + "\"user_phone\":\"123456789\",\"user_avatar\":\"image1" + ".jpg\"}"; - Response r = this.client().post(path, user); + Response r = this.client().post(PATH, user); assertResponseStatus(201, r); } protected List> listUsers() { - Response r = this.client().get(path, ImmutableMap.of("limit", + Response r = this.client().get(PATH, ImmutableMap.of("limit", NO_LIMIT)); String result = assertResponseStatus(200, r); diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/VertexApiTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/VertexApiTest.java index 3be1c26514..a1073dcdde 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/VertexApiTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/VertexApiTest.java @@ -37,26 +37,26 @@ public void prepareSchema() { @Test public void testCreate() { - String vertex = "{" - + "\"label\":\"person\"," - + "\"properties\":{" - + "\"name\":\"James\"," - + "\"city\":\"Beijing\"," - + "\"age\":19}" - + "}"; + String vertex = "{" + + "\"label\":\"person\"," + + "\"properties\":{" + + "\"name\":\"James\"," + + "\"city\":\"Beijing\"," + + "\"age\":19}" + + "}"; Response r = client().post(path, vertex); assertResponseStatus(201, r); } @Test public void testGet() throws IOException { - String vertex = "{" - + "\"label\":\"person\"," - + "\"properties\":{" - + "\"name\":\"James\"," - + "\"city\":\"Beijing\"," - + "\"age\":19}" - + "}"; + String vertex = "{" + + "\"label\":\"person\"," + + "\"properties\":{" + + "\"name\":\"James\"," + + "\"city\":\"Beijing\"," + + "\"age\":19}" + + "}"; Response r = client().post(path, vertex); String content = assertResponseStatus(201, r); @@ -68,13 +68,13 @@ public void testGet() throws IOException { @Test public void testList() { - String vertex = "{" - + "\"label\":\"person\"," - + "\"properties\":{" - + "\"name\":\"James\"," - + "\"city\":\"Beijing\"," - + "\"age\":19}" - + "}"; + String vertex = "{" + + "\"label\":\"person\"," + + "\"properties\":{" + + "\"name\":\"James\"," + + "\"city\":\"Beijing\"," + + "\"age\":19}" + + "}"; Response r = client().post(path, vertex); assertResponseStatus(201, r); @@ -84,13 +84,13 @@ public void testList() { @Test public void testDelete() throws IOException { - String vertex = "{" - + "\"label\":\"person\"," - + "\"properties\":{" - + "\"name\":\"James\"," - + "\"city\":\"Beijing\"," - + "\"age\":19}" - + "}"; + String vertex = "{" + + "\"label\":\"person\"," + + "\"properties\":{" + + "\"name\":\"James\"," + + "\"city\":\"Beijing\"," + + "\"age\":19}" + + "}"; Response r = client().post(path, vertex); String content = assertResponseStatus(201, r); diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/VertexLabelApiTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/VertexLabelApiTest.java index 006db0d1b2..be7a420889 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/VertexLabelApiTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/VertexLabelApiTest.java @@ -38,36 +38,36 @@ public void prepareSchema() { @Test public void testCreate() { - String vertexLabel = "{" - + "\"name\": \"person\"," - + "\"id_strategy\": \"PRIMARY_KEY\"," - + "\"properties\": [\"name\", \"age\", \"city\"]," - + "\"primary_keys\":[\"name\"]," - + "\"nullable_keys\":[\"city\"]" - + "}"; + String vertexLabel = "{" + + "\"name\": \"person\"," + + "\"id_strategy\": \"PRIMARY_KEY\"," + + "\"properties\": [\"name\", \"age\", \"city\"]," + + "\"primary_keys\":[\"name\"]," + + "\"nullable_keys\":[\"city\"]" + + "}"; Response r = client().post(path, vertexLabel); assertResponseStatus(201, r); } @Test public void testAppend() { - String vertexLabel = "{" - + "\"name\": \"person\"," - + "\"id_strategy\": \"PRIMARY_KEY\"," - + "\"properties\": [\"name\", \"age\", \"city\"]," - + "\"primary_keys\":[\"name\"]," - + "\"nullable_keys\":[\"city\"]" - + "}"; + String vertexLabel = "{" + + "\"name\": \"person\"," + + "\"id_strategy\": \"PRIMARY_KEY\"," + + "\"properties\": [\"name\", \"age\", \"city\"]," + + "\"primary_keys\":[\"name\"]," + + "\"nullable_keys\":[\"city\"]" + + "}"; Response r = client().post(path, vertexLabel); assertResponseStatus(201, r); - vertexLabel = "{" - + "\"name\": \"person\"," - + "\"id_strategy\":\"DEFAULT\"," - + "\"properties\":[\"lang\"]," - + "\"primary_keys\":[]," - + "\"nullable_keys\":[\"lang\"]" - + "}"; + vertexLabel = "{" + + "\"name\": \"person\"," + + "\"id_strategy\":\"DEFAULT\"," + + "\"properties\":[\"lang\"]," + + "\"primary_keys\":[]," + + "\"nullable_keys\":[\"lang\"]" + + "}"; Map params = ImmutableMap.of("action", "append"); r = client().put(path, "person", vertexLabel, params); assertResponseStatus(200, r); @@ -75,13 +75,13 @@ public void testAppend() { @Test public void testGet() { - String vertexLabel = "{" - + "\"name\": \"person\"," - + "\"id_strategy\": \"PRIMARY_KEY\"," - + "\"properties\": [\"name\", \"age\", \"city\"]," - + "\"primary_keys\":[\"name\"]," - + "\"nullable_keys\":[\"city\"]" - + "}"; + String vertexLabel = "{" + + "\"name\": \"person\"," + + "\"id_strategy\": \"PRIMARY_KEY\"," + + "\"properties\": [\"name\", \"age\", \"city\"]," + + "\"primary_keys\":[\"name\"]," + + "\"nullable_keys\":[\"city\"]" + + "}"; Response r = client().post(path, vertexLabel); assertResponseStatus(201, r); @@ -92,13 +92,13 @@ public void testGet() { @Test public void testList() { - String vertexLabel = "{" - + "\"name\": \"person\"," - + "\"id_strategy\": \"PRIMARY_KEY\"," - + "\"properties\": [\"name\", \"age\", \"city\"]," - + "\"primary_keys\":[\"name\"]," - + "\"nullable_keys\":[\"city\"]" - + "}"; + String vertexLabel = "{" + + "\"name\": \"person\"," + + "\"id_strategy\": \"PRIMARY_KEY\"," + + "\"properties\": [\"name\", \"age\", \"city\"]," + + "\"primary_keys\":[\"name\"]," + + "\"nullable_keys\":[\"city\"]" + + "}"; Response r = client().post(path, vertexLabel); assertResponseStatus(201, r); @@ -108,13 +108,13 @@ public void testList() { @Test public void testDelete() { - String vertexLabel = "{" - + "\"name\": \"person\"," - + "\"id_strategy\": \"PRIMARY_KEY\"," - + "\"properties\": [\"name\", \"age\", \"city\"]," - + "\"primary_keys\":[\"name\"]," - + "\"nullable_keys\":[\"city\"]" - + "}"; + String vertexLabel = "{" + + "\"name\": \"person\"," + + "\"id_strategy\": \"PRIMARY_KEY\"," + + "\"properties\": [\"name\", \"age\", \"city\"]," + + "\"primary_keys\":[\"name\"]," + + "\"nullable_keys\":[\"city\"]" + + "}"; Response r = client().post(path, vertexLabel); assertResponseStatus(201, r); diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/AdamicAdarAPITest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/AdamicAdarAPITest.java index 52fe7992de..6fb438909a 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/AdamicAdarAPITest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/AdamicAdarAPITest.java @@ -31,7 +31,7 @@ public class AdamicAdarAPITest extends BaseApiTest { - private final static String PATH = TRAVERSERS_API + "/adamicadar"; + private static final String PATH = TRAVERSERS_API + "/adamicadar"; @Before public void prepareSchema() { diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/CustomizedCrosspointsApiTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/CustomizedCrosspointsApiTest.java index e1ee4e642f..df99e00222 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/CustomizedCrosspointsApiTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/CustomizedCrosspointsApiTest.java @@ -41,6 +41,7 @@ public void prepareSchema() { BaseApiTest.initVertex(); BaseApiTest.initEdge(); } + @Test public void testPost() { Map name2Ids = listAllVertexName2Ids(); diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/EdgesApiTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/EdgesApiTest.java index 042842bf2d..18cde518f7 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/EdgesApiTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/EdgesApiTest.java @@ -31,12 +31,11 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMultimap; - public class EdgesApiTest extends BaseApiTest { - final static String EDGE_PATH = TRAVERSERS_API + "/edges"; - final static String SHARES_PATH = TRAVERSERS_API + "/edges/shards"; - final static String SCAN_PATH = TRAVERSERS_API + "/edges/scan"; + static final String EDGE_PATH = TRAVERSERS_API + "/edges"; + static final String SHARES_PATH = TRAVERSERS_API + "/edges/shards"; + static final String SCAN_PATH = TRAVERSERS_API + "/edges/scan"; @Before public void prepareSchema() { diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/FusiformSimilarityApiTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/FusiformSimilarityApiTest.java index da6bbff33e..9a7fcdfeb3 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/FusiformSimilarityApiTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/FusiformSimilarityApiTest.java @@ -31,7 +31,7 @@ public class FusiformSimilarityApiTest extends BaseApiTest { - final static String path = TRAVERSERS_API + "/fusiformsimilarity"; + static final String PATH = TRAVERSERS_API + "/fusiformsimilarity"; @Before public void prepareSchema() { @@ -44,7 +44,7 @@ public void prepareSchema() { @Test public void testPost() { - Response r = client().post(path, "{ " + + Response r = client().post(PATH, "{ " + "\"sources\":{ " + " \"ids\":[], " + " \"label\": \"person\", " + diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/JaccardSimilarityApiTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/JaccardSimilarityApiTest.java index 23a1df8107..d3782fb192 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/JaccardSimilarityApiTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/JaccardSimilarityApiTest.java @@ -31,7 +31,7 @@ public class JaccardSimilarityApiTest extends BaseApiTest { - final static String path = TRAVERSERS_API + "/jaccardsimilarity"; + static final String PATH = TRAVERSERS_API + "/jaccardsimilarity"; @Before public void prepareSchema() { @@ -47,7 +47,7 @@ public void testGet() { Map name2Ids = listAllVertexName2Ids(); String markoId = name2Ids.get("marko"); String peterId = name2Ids.get("peter"); - Response r = client().get(path, ImmutableMap.of("vertex", + Response r = client().get(PATH, ImmutableMap.of("vertex", id2Json(markoId), "other", id2Json(peterId))); @@ -72,7 +72,7 @@ public void testPost() { " \"degree\": 10000, " + " \"skip_degree\": 100000 }, " + "\"top\": 3}", markoId); - Response r = client().post(path, reqBody); + Response r = client().post(PATH, reqBody); String content = assertResponseStatus(200, r); Double rippleJaccardSimilarity = assertJsonContains(content, rippleId); Double peterJaccardSimilarity = assertJsonContains(content, peterId); diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/KneighborApiTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/KneighborApiTest.java index a2b54a18be..7be50f4225 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/KneighborApiTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/KneighborApiTest.java @@ -33,7 +33,7 @@ public class KneighborApiTest extends BaseApiTest { - final static String path = TRAVERSERS_API + "/kneighbor"; + static final String PATH = TRAVERSERS_API + "/kneighbor"; @Before public void prepareSchema() { @@ -51,7 +51,7 @@ public void testGet() { String rippleId = name2Ids.get("ripple"); String peterId = name2Ids.get("peter"); String joshId = name2Ids.get("josh"); - Response r = client().get(path, ImmutableMap.of("source", + Response r = client().get(PATH, ImmutableMap.of("source", id2Json(markoId), "max_depth", 2)); String content = assertResponseStatus(200, r); @@ -78,7 +78,7 @@ public void testPost() { "\"limit\": 10000, " + "\"with_vertex\": true, " + "\"with_path\": true}", markoId); - Response r = client().post(path, reqBody); + Response r = client().post(PATH, reqBody); String content = assertResponseStatus(200, r); assertJsonContains(content, "kneighbor"); assertJsonContains(content, "paths"); diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/KoutApiTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/KoutApiTest.java index e26fed0c76..23b59b62fd 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/KoutApiTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/KoutApiTest.java @@ -33,7 +33,7 @@ public class KoutApiTest extends BaseApiTest { - final static String path = TRAVERSERS_API + "/kout"; + static final String PATH = TRAVERSERS_API + "/kout"; @Before public void prepareSchema() { @@ -52,7 +52,7 @@ public void testGet() { String joshId = name2Ids.get("josh"); String rippleId = name2Ids.get("ripple"); // Test for nearest=true - Response r = client().get(path, ImmutableMap.of("source", + Response r = client().get(PATH, ImmutableMap.of("source", id2Json(markoId), "max_depth", 2)); String content = assertResponseStatus(200, r); @@ -60,7 +60,7 @@ public void testGet() { Assert.assertEquals(1, vertices.size()); Assert.assertTrue(vertices.contains(joshId)); // Test for nearest=false - r = client().get(path, ImmutableMap.of("source", id2Json(markoId), + r = client().get(PATH, ImmutableMap.of("source", id2Json(markoId), "max_depth", 2, "nearest", "false")); content = assertResponseStatus(200, r); @@ -90,7 +90,7 @@ public void testPost() { "\"limit\": 10000, " + "\"with_vertex\": true, " + "\"with_path\": true}", markoId); - Response resp = client().post(path, reqBody); + Response resp = client().post(PATH, reqBody); String content = assertResponseStatus(200, resp); Object size = assertJsonContains(content, "size"); Assert.assertEquals(2, size); diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/NeighborRankApiTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/NeighborRankApiTest.java index f25e7cb749..dc6b1e95a7 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/NeighborRankApiTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/NeighborRankApiTest.java @@ -31,7 +31,7 @@ public class NeighborRankApiTest extends BaseApiTest { - final static String path = TRAVERSERS_API + "/neighborrank"; + static final String PATH = TRAVERSERS_API + "/neighborrank"; @Before public void prepareSchema() { @@ -51,7 +51,7 @@ public void testNeighborRank() { "\"steps\": [{" + " \"direction\": \"BOTH\"}]," + "\"alpha\":%s}", markoId, 1); - Response r = client().post(path, reqBody); + Response r = client().post(PATH, reqBody); String content = assertResponseStatus(200, r); List ranks = assertJsonContains(content, "ranks"); Assert.assertEquals(2, ranks.size()); diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/PathsApiTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/PathsApiTest.java index ab71bba758..6aeb3b2423 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/PathsApiTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/PathsApiTest.java @@ -28,11 +28,12 @@ import org.junit.Test; import com.baidu.hugegraph.api.BaseApiTest; + import com.google.common.collect.ImmutableMap; public class PathsApiTest extends BaseApiTest { - final static String path = TRAVERSERS_API + "/paths"; + static final String PATH = TRAVERSERS_API + "/paths"; @Before public void prepareSchema() { @@ -48,7 +49,7 @@ public void testGet() { Map name2Ids = listAllVertexName2Ids(); String markoId = name2Ids.get("marko"); String vadasId = name2Ids.get("vadas"); - Response r = client().get(path, ImmutableMap.of("source", + Response r = client().get(PATH, ImmutableMap.of("source", id2Json(markoId), "target", id2Json(vadasId), @@ -78,7 +79,7 @@ public void testPost() { "\"limit\": 10000000, " + "\"with_vertex\": false}", markoId, joshId); - Response r = client().post(path, reqBody); + Response r = client().post(PATH, reqBody); String content = assertResponseStatus(200, r); List> paths = assertJsonContains(content, "paths"); Assert.assertEquals(2, paths.size()); diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/PersonalRankApiTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/PersonalRankApiTest.java index 51c77ac56f..8c92d29130 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/PersonalRankApiTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/PersonalRankApiTest.java @@ -29,7 +29,7 @@ public class PersonalRankApiTest extends BaseApiTest { - final static String path = TRAVERSERS_API + "/personalrank"; + static final String PATH = TRAVERSERS_API + "/personalrank"; @Before public void prepareSchema() { @@ -51,7 +51,7 @@ public void testPersonalRank() { "\"label\":\"%s\"," + "\"alpha\":\"%s\"}", markoId, 3, "created", 1); - Response r = client().post(path, reqBody); + Response r = client().post(PATH, reqBody); String content = assertResponseStatus(200, r); assertJsonContains(content, peterId); } diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/RaysApiTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/RaysApiTest.java index 811ee8301a..6cfda4e309 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/RaysApiTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/RaysApiTest.java @@ -32,7 +32,7 @@ public class RaysApiTest extends BaseApiTest { - final static String path = TRAVERSERS_API + "/rays"; + static final String PATH = TRAVERSERS_API + "/rays"; @Before public void prepareSchema() { @@ -48,7 +48,7 @@ public void testGet() { Map name2Ids = listAllVertexName2Ids(); String markoId = name2Ids.get("marko"); String vadasId = name2Ids.get("vadas"); - Response r = client().get(path, ImmutableMap.of("source", + Response r = client().get(PATH, ImmutableMap.of("source", id2Json(markoId), "max_depth", 10)); String content = assertResponseStatus(200, r); diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/ResourceAllocationAPITest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/ResourceAllocationAPITest.java index 236ab144f4..2a8d432998 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/ResourceAllocationAPITest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/ResourceAllocationAPITest.java @@ -31,7 +31,7 @@ public class ResourceAllocationAPITest extends BaseApiTest { - private final static String PATH = TRAVERSERS_API + "/resourceallocation"; + private static final String PATH = TRAVERSERS_API + "/resourceallocation"; @Before public void prepareSchema() { diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/RingsApiTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/RingsApiTest.java index a1d7820aef..67a1d7ef1a 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/RingsApiTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/RingsApiTest.java @@ -32,7 +32,7 @@ public class RingsApiTest extends BaseApiTest { - final static String path = TRAVERSERS_API + "/rings"; + static final String PATH = TRAVERSERS_API + "/rings"; @Before public void prepareSchema() { @@ -50,7 +50,7 @@ public void testGet() { Map params = ImmutableMap.of("source", id2Json(markoId), "max_depth", 10); - Response r = client().get(path, params); + Response r = client().get(PATH, params); String content = assertResponseStatus(200, r); List>> rings = assertJsonContains(content, "rings"); diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/SameNeighborsApiTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/SameNeighborsApiTest.java index 64f3837a61..89af06ff28 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/SameNeighborsApiTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/SameNeighborsApiTest.java @@ -32,7 +32,7 @@ public class SameNeighborsApiTest extends BaseApiTest { - final static String path = TRAVERSERS_API + "/sameneighbors"; + static final String PATH = TRAVERSERS_API + "/sameneighbors"; @Before public void prepareSchema() { @@ -49,7 +49,7 @@ public void testGet() { String markoId = name2Ids.get("marko"); String joshId = name2Ids.get("josh"); String peterId = name2Ids.get("peter"); - Response r = client().get(path, ImmutableMap.of("vertex", + Response r = client().get(PATH, ImmutableMap.of("vertex", id2Json(markoId), "other", id2Json(joshId))); diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/ShortestPathApiTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/ShortestPathApiTest.java index c105ddf321..a09f85eec9 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/ShortestPathApiTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/ShortestPathApiTest.java @@ -33,7 +33,7 @@ public class ShortestPathApiTest extends BaseApiTest { - final static String path = TRAVERSERS_API + "/shortestpath"; + static final String PATH = TRAVERSERS_API + "/shortestpath"; @Before public void prepareSchema() { @@ -50,7 +50,7 @@ public void testGet() { String markoId = name2Ids.get("marko"); String joshId = name2Ids.get("josh"); String peterId = name2Ids.get("peter"); - Response r = client().get(path, ImmutableMap.of("source", + Response r = client().get(PATH, ImmutableMap.of("source", id2Json(markoId), "target", id2Json(joshId), diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/SingleSourceShortestPathApiTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/SingleSourceShortestPathApiTest.java index 76a9d8aed5..b9295f6627 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/SingleSourceShortestPathApiTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/SingleSourceShortestPathApiTest.java @@ -31,7 +31,7 @@ public class SingleSourceShortestPathApiTest extends BaseApiTest { - final static String path = TRAVERSERS_API + "/singlesourceshortestpath"; + static final String PATH = TRAVERSERS_API + "/singlesourceshortestpath"; @Before public void prepareSchema() { @@ -46,7 +46,7 @@ public void prepareSchema() { public void testGet() { Map name2Ids = listAllVertexName2Ids(); String markoId = name2Ids.get("marko"); - Response r = client().get(path, ImmutableMap.of("source", + Response r = client().get(PATH, ImmutableMap.of("source", id2Json(markoId), "with_vertex", true)); diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/TemplatePathsApiTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/TemplatePathsApiTest.java index e5f4ed436d..9671d3c842 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/TemplatePathsApiTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/TemplatePathsApiTest.java @@ -32,7 +32,7 @@ public class TemplatePathsApiTest extends BaseApiTest { - final static String path = TRAVERSERS_API + "/templatepaths"; + static final String PATH = TRAVERSERS_API + "/templatepaths"; @Before public void prepareSchema() { @@ -76,7 +76,7 @@ public void testPost() { " \"capacity\": 10000," + " \"limit\": 10," + " \"with_vertex\": true}"; - Response r = client().post(path, template); + Response r = client().post(PATH, template); String content = assertResponseStatus(200, r); List> objects = assertJsonContains(content, "paths"); Assert.assertEquals(1, objects.size()); diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/WeightedShortestPathApiTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/WeightedShortestPathApiTest.java index 86879069a8..1b798b7501 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/WeightedShortestPathApiTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/WeightedShortestPathApiTest.java @@ -33,7 +33,7 @@ public class WeightedShortestPathApiTest extends BaseApiTest { - final static String path = TRAVERSERS_API + "/weightedshortestpath"; + static final String PATH = TRAVERSERS_API + "/weightedshortestpath"; @Before public void prepareSchema() { @@ -51,7 +51,7 @@ public void testGet() { String joshId = name2Ids.get("josh"); String peterId = name2Ids.get("peter"); String rippleId = name2Ids.get("ripple"); - Response r = client().get(path, ImmutableMap.of("source", + Response r = client().get(PATH, ImmutableMap.of("source", id2Json(markoId), "target", id2Json(joshId), diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/core/AuthTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/core/AuthTest.java index cfde50882b..ac0b09f4ab 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/core/AuthTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/core/AuthTest.java @@ -1227,14 +1227,11 @@ public void testRolePermission() { " {\"type\": \"EDGE_LABEL\"}, {\"type\": \"INDEX_LABEL\"}]"); List rg = HugeResource.parseResources( "[{\"type\": \"GREMLIN\"}]"); - Id graph1v = authManager.createTarget(makeTarget("hugegraph-v", - "hugegraph", + Id graph1v = authManager.createTarget(makeTarget("hugegraph-v", "hugegraph", "url1", rv)); - Id graph1e = authManager.createTarget(makeTarget("hugegraph-e", - "hugegraph", + Id graph1e = authManager.createTarget(makeTarget("hugegraph-e", "hugegraph", "url1", re)); - Id graph1gremlin = authManager.createTarget(makeTarget("hugegraph-g", - "hugegraph", + Id graph1gremlin = authManager.createTarget(makeTarget("hugegraph-g", "hugegraph", "url1", rg)); Id belong1 = authManager.createBelong(makeBelong(user0, group1)); @@ -1260,7 +1257,23 @@ public void testRolePermission() { RolePermission role; role = authManager.rolePermission(authManager.getUser(user0)); - String expected = "{\"roles\":{\"hugegraph\":{\"READ\":[{\"type\":\"EDGE\",\"label\":\"write\",\"properties\":null},{\"type\":\"PROPERTY_KEY\",\"label\":\"*\",\"properties\":null},{\"type\":\"VERTEX_LABEL\",\"label\":\"*\",\"properties\":null},{\"type\":\"EDGE_LABEL\",\"label\":\"*\",\"properties\":null},{\"type\":\"INDEX_LABEL\",\"label\":\"*\",\"properties\":null},{\"type\":\"VERTEX\",\"label\":\"person\",\"properties\":{\"city\":\"Beijing\",\"age\":\"P.gte(20)\"}},{\"type\":\"VERTEX_LABEL\",\"label\":\"*\",\"properties\":null},{\"type\":\"PROPERTY_KEY\",\"label\":\"*\",\"properties\":null}],\"WRITE\":[{\"type\":\"VERTEX\",\"label\":\"person\",\"properties\":{\"city\":\"Beijing\",\"age\":\"P.gte(20)\"}},{\"type\":\"VERTEX_LABEL\",\"label\":\"*\",\"properties\":null},{\"type\":\"PROPERTY_KEY\",\"label\":\"*\",\"properties\":null}],\"EXECUTE\":[{\"type\":\"GREMLIN\",\"label\":\"*\",\"properties\":null}]},\"hugegraph1\":{\"READ\":[]}}}"; + String expected = "{\"roles\":" + + "{\"hugegraph\":{\"READ\":[" + + "{\"type\":\"EDGE\",\"label\":\"write\",\"properties\":null}," + + "{\"type\":\"PROPERTY_KEY\",\"label\":\"*\",\"properties\":null}," + + "{\"type\":\"VERTEX_LABEL\",\"label\":\"*\",\"properties\":null}," + + "{\"type\":\"EDGE_LABEL\",\"label\":\"*\",\"properties\":null}," + + "{\"type\":\"INDEX_LABEL\",\"label\":\"*\",\"properties\":null}," + + "{\"type\":\"VERTEX\",\"label\":\"person\",\"properties\":" + + "{\"city\":\"Beijing\",\"age\":\"P.gte(20)\"}}," + + "{\"type\":\"VERTEX_LABEL\",\"label\":\"*\",\"properties\":null}," + + "{\"type\":\"PROPERTY_KEY\",\"label\":\"*\",\"properties\":null}],\"WRITE\":" + + "[{\"type\":\"VERTEX\",\"label\":\"person\",\"properties\":" + + "{\"city\":\"Beijing\",\"age\":\"P.gte(20)\"}}," + + "{\"type\":\"VERTEX_LABEL\",\"label\":\"*\",\"properties\":null}," + + "{\"type\":\"PROPERTY_KEY\",\"label\":\"*\",\"properties\":null}],\"EXECUTE\":" + + "[{\"type\":\"GREMLIN\",\"label\":\"*\",\"properties\":null}]}," + + "\"hugegraph1\":{\"READ\":[]}}}"; Assert.assertEquals(expected, role.toJson()); role = authManager.rolePermission(authManager.getBelong(belong1)); @@ -1270,11 +1283,16 @@ public void testRolePermission() { Assert.assertEquals(expected, role.toJson()); role = authManager.rolePermission(authManager.getAccess(access1v)); - expected = "{\"roles\":{\"hugegraph\":{\"READ\":[{\"type\":\"VERTEX\",\"label\":\"person\",\"properties\":{\"city\":\"Beijing\",\"age\":\"P.gte(20)\"}},{\"type\":\"VERTEX_LABEL\",\"label\":\"*\",\"properties\":null},{\"type\":\"PROPERTY_KEY\",\"label\":\"*\",\"properties\":null}]}}}"; + expected = "{\"roles\":" + + "{\"hugegraph\":{\"READ\":[{\"type\":\"VERTEX\",\"label\":\"person\"," + + "\"properties\":{\"city\":\"Beijing\",\"age\":\"P.gte(20)\"}}," + + "{\"type\":\"VERTEX_LABEL\",\"label\":\"*\",\"properties\":null}," + + "{\"type\":\"PROPERTY_KEY\",\"label\":\"*\",\"properties\":null}]}}}"; Assert.assertEquals(expected, role.toJson()); role = authManager.rolePermission(authManager.getAccess(access1g)); - expected = "{\"roles\":{\"hugegraph\":{\"EXECUTE\":[{\"type\":\"GREMLIN\",\"label\":\"*\",\"properties\":null}]}}}"; + expected = "{\"roles\":{\"hugegraph\":{\"EXECUTE\":[" + + "{\"type\":\"GREMLIN\",\"label\":\"*\",\"properties\":null}]}}}"; Assert.assertEquals(expected, role.toJson()); role = authManager.rolePermission(authManager.getUser(user1)); @@ -1286,7 +1304,12 @@ public void testRolePermission() { Assert.assertEquals(expected, role.toJson()); role = authManager.rolePermission(authManager.getTarget(graph1v)); - expected = "{\"roles\":{\"hugegraph\":{\"READ\":[{\"type\":\"VERTEX\",\"label\":\"person\",\"properties\":{\"city\":\"Beijing\",\"age\":\"P.gte(20)\"}},{\"type\":\"VERTEX_LABEL\",\"label\":\"*\",\"properties\":null},{\"type\":\"PROPERTY_KEY\",\"label\":\"*\",\"properties\":null}]}}}"; + expected = "{\"roles\":" + + "{\"hugegraph\":" + + "{\"READ\":[{\"type\":\"VERTEX\",\"label\":\"person\",\"properties\":" + + "{\"city\":\"Beijing\",\"age\":\"P.gte(20)\"}}," + + "{\"type\":\"VERTEX_LABEL\",\"label\":\"*\",\"properties\":null}," + + "{\"type\":\"PROPERTY_KEY\",\"label\":\"*\",\"properties\":null}]}}}"; Assert.assertEquals(expected, role.toJson()); } diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/core/EdgeCoreTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/core/EdgeCoreTest.java index d6f3544cb2..ddd6841b5b 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/core/EdgeCoreTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/core/EdgeCoreTest.java @@ -4865,9 +4865,9 @@ public void testQueryByDatePropertyInString() { Vertex java3 = graph.addVertex(T.label, "book", "name", "java-3"); String[] dates = new String[]{ - "2012-01-01 00:00:00.000", - "2013-01-01 00:00:00.000", - "2014-01-01 00:00:00.000" + "2012-01-01 00:00:00.000", + "2013-01-01 00:00:00.000", + "2014-01-01 00:00:00.000" }; louise.addEdge("buy", java1, "place", "haidian", "date", dates[0]); @@ -4917,9 +4917,9 @@ public void testQueryByUnionHasDate() { Vertex java3 = graph.addVertex(T.label, "book", "name", "java-3"); String[] dates = new String[]{ - "2012-01-01 00:00:00.000", - "2013-01-01 00:00:00.000", - "2014-01-01 00:00:00.000" + "2012-01-01 00:00:00.000", + "2013-01-01 00:00:00.000", + "2014-01-01 00:00:00.000" }; louise.addEdge("buy", java1, "place", "haidian", "date", dates[0]); @@ -4970,9 +4970,9 @@ public void testQueryByDatePropertyInMultiFormatString() { Vertex java3 = graph.addVertex(T.label, "book", "name", "java-3"); String[] dates = new String[]{ - "2012-01-01", - "2013-01-01 00:00:00", - "2014-01-01 00:00:00.000" + "2012-01-01", + "2013-01-01 00:00:00", + "2014-01-01 00:00:00.000" }; louise.addEdge("buy", java1, "place", "haidian", "date", dates[0]); @@ -5020,9 +5020,9 @@ public void testQueryByOutEWithDateProperty() { Vertex java3 = graph.addVertex(T.label, "book", "name", "java-3"); String[] dates = new String[]{ - "2012-01-01 00:00:00.000", - "2013-01-01 00:00:00.000", - "2014-01-01 00:00:00.000" + "2012-01-01 00:00:00.000", + "2013-01-01 00:00:00.000", + "2014-01-01 00:00:00.000" }; louise.addEdge("buy", java1, "place", "haidian", "date", dates[0]); @@ -7307,7 +7307,6 @@ public void testAddEdgeWithCollectionIndex() { "gremlin").toList(); }); - List edges = graph.traversal().E() .has("related", "tags", ConditionP.contains("gremlin")) diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/core/EdgeLabelCoreTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/core/EdgeLabelCoreTest.java index 764c3f753f..909dd2f32d 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/core/EdgeLabelCoreTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/core/EdgeLabelCoreTest.java @@ -1141,7 +1141,6 @@ public void testEliminateEdgeLabelWithUserdata() { write.userdata().get("multiplicity")); Assert.assertEquals("picture2", write.userdata().get("icon")); - write = schema.edgeLabel("write") .userdata("icon", "") .eliminate(); diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/core/MultiGraphsTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/core/MultiGraphsTest.java index 42d2b48680..3545185c13 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/core/MultiGraphsTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/core/MultiGraphsTest.java @@ -50,7 +50,6 @@ import com.baidu.hugegraph.testutil.Utils; import com.baidu.hugegraph.type.define.NodeRole; - public class MultiGraphsTest { private static final String NAME48 = diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/core/PropertyCoreTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/core/PropertyCoreTest.java index c63d95721a..f71760ebd3 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/core/PropertyCoreTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/core/PropertyCoreTest.java @@ -46,7 +46,9 @@ public abstract class PropertyCoreTest extends BaseCoreTest { protected abstract V property(String key, V value); + protected abstract V propertyList(String key, Object... values); + protected abstract V propertySet(String key, Object... values); @Before diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/core/TaskCoreTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/core/TaskCoreTest.java index 4f8a8d9a0c..05a6d39369 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/core/TaskCoreTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/core/TaskCoreTest.java @@ -67,7 +67,6 @@ public void testTask() throws TimeoutException { HugeGraph graph = graph(); TaskScheduler scheduler = graph.taskScheduler(); - TaskCallable callable = new SleepCallable<>(); Id id = IdGenerator.of(88888); @@ -129,6 +128,7 @@ public Integer call() throws Exception { sleepAWhile(); return 125; } + @Override protected void done() { scheduler.save(this.task()); @@ -181,15 +181,16 @@ public void testEphemeralJob() throws TimeoutException { EphemeralJobBuilder builder = EphemeralJobBuilder.of(graph); builder.name("test-job-ephemeral") .job(new EphemeralJob() { - @Override - public String type() { - return "test"; - } - @Override - public Object execute() throws Exception { - sleepAWhile(); - return ImmutableMap.of("k1", 13579, "k2", "24680"); - } + @Override + public String type() { + return "test"; + } + + @Override + public Object execute() throws Exception { + sleepAWhile(); + return ImmutableMap.of("k1", 13579, "k2", "24680"); + } }); HugeTask task = builder.schedule(); @@ -249,20 +250,21 @@ public void testGremlinJobWithScript() throws TimeoutException { HugeGraph graph = graph(); TaskScheduler scheduler = graph.taskScheduler(); - String script = "schema=graph.schema();" - + "schema.propertyKey('name').asText().ifNotExist().create();" - + "schema.propertyKey('age').asInt().ifNotExist().create();" - + "schema.propertyKey('lang').asText().ifNotExist().create();" - + "schema.propertyKey('date').asDate().ifNotExist().create();" - + "schema.propertyKey('price').asInt().ifNotExist().create();" - + "schema.vertexLabel('person1').properties('name','age').ifNotExist().create();" - + "schema.vertexLabel('person2').properties('name','age').ifNotExist().create();" - + "schema.edgeLabel('knows').sourceLabel('person1').targetLabel('person2').properties('date').ifNotExist().create();" - + "for(int i = 0; i < 1000; i++) {" - + " p1=graph.addVertex(T.label,'person1','name','p1-'+i,'age',29);" - + " p2=graph.addVertex(T.label,'person2','name','p2-'+i,'age',27);" - + " p1.addEdge('knows',p2,'date','2016-01-10');" - + "}"; + String script = "schema=graph.schema();" + + "schema.propertyKey('name').asText().ifNotExist().create();" + + "schema.propertyKey('age').asInt().ifNotExist().create();" + + "schema.propertyKey('lang').asText().ifNotExist().create();" + + "schema.propertyKey('date').asDate().ifNotExist().create();" + + "schema.propertyKey('price').asInt().ifNotExist().create();" + + "schema.vertexLabel('person1').properties('name','age').ifNotExist().create();" + + "schema.vertexLabel('person2').properties('name','age').ifNotExist().create();" + + "schema.edgeLabel('knows').sourceLabel('person1').targetLabel('person2')." + + "properties('date').ifNotExist().create();" + + "for(int i = 0; i < 1000; i++) {" + + " p1=graph.addVertex(T.label,'person1','name','p1-'+i,'age',29);" + + " p2=graph.addVertex(T.label,'person2','name','p2-'+i,'age',27);" + + " p1.addEdge('knows',p2,'date','2016-01-10');" + + "}"; HugeTask task = runGremlinJob(script); task = scheduler.waitUntilTaskCompleted(task.id(), 10); @@ -307,26 +309,28 @@ public void testGremlinJobWithSerializedResults() throws TimeoutException { HugeGraph graph = graph(); TaskScheduler scheduler = graph.taskScheduler(); - String script = "schema=graph.schema();" - + "schema.propertyKey('name').asText().ifNotExist().create();" - + "schema.vertexLabel('char').useCustomizeNumberId().properties('name').ifNotExist().create();" - + "schema.edgeLabel('next').sourceLabel('char').targetLabel('char').properties('name').ifNotExist().create();" - + "g.addV('char').property(id,1).property('name','A').as('a')" - + " .addV('char').property(id,2).property('name','B').as('b')" - + " .addV('char').property(id,3).property('name','C').as('c')" - + " .addV('char').property(id,4).property('name','D').as('d')" - + " .addV('char').property(id,5).property('name','E').as('e')" - + " .addV('char').property(id,6).property('name','F').as('f')" - + " .addE('next').from('a').to('b').property('name','ab')" - + " .addE('next').from('b').to('c').property('name','bc')" - + " .addE('next').from('b').to('d').property('name','bd')" - + " .addE('next').from('c').to('d').property('name','cd')" - + " .addE('next').from('c').to('e').property('name','ce')" - + " .addE('next').from('d').to('e').property('name','de')" - + " .addE('next').from('e').to('f').property('name','ef')" - + " .addE('next').from('f').to('d').property('name','fd')" - + " .iterate();" - + "g.tx().commit(); g.E().count();"; + String script = "schema=graph.schema();" + + "schema.propertyKey('name').asText().ifNotExist().create();" + + "schema.vertexLabel('char').useCustomizeNumberId()" + + " .properties('name').ifNotExist().create();" + + "schema.edgeLabel('next').sourceLabel('char').targetLabel('char')" + + " .properties('name').ifNotExist().create();" + + "g.addV('char').property(id,1).property('name','A').as('a')" + + " .addV('char').property(id,2).property('name','B').as('b')" + + " .addV('char').property(id,3).property('name','C').as('c')" + + " .addV('char').property(id,4).property('name','D').as('d')" + + " .addV('char').property(id,5).property('name','E').as('e')" + + " .addV('char').property(id,6).property('name','F').as('f')" + + " .addE('next').from('a').to('b').property('name','ab')" + + " .addE('next').from('b').to('c').property('name','bc')" + + " .addE('next').from('b').to('d').property('name','bd')" + + " .addE('next').from('c').to('d').property('name','cd')" + + " .addE('next').from('c').to('e').property('name','ce')" + + " .addE('next').from('d').to('e').property('name','de')" + + " .addE('next').from('e').to('f').property('name','ef')" + + " .addE('next').from('f').to('d').property('name','fd')" + + " .iterate();" + + "g.tx().commit(); g.E().count();"; HugeTask task = runGremlinJob(script); task = scheduler.waitUntilTaskCompleted(task.id(), 10); @@ -341,35 +345,49 @@ public void testGremlinJobWithSerializedResults() throws TimeoutException { task = runGremlinJob(script); task = scheduler.waitUntilTaskCompleted(task.id(), 10); Assert.assertEquals(TaskStatus.SUCCESS, task.status()); - String expected = String.format("[{\"labels\":[[],[],[]],\"objects\":[" - + "{\"id\":1,\"label\":\"char\",\"type\":\"vertex\",\"properties\":{\"name\":\"A\"}}," - + "{\"id\":\"L1>%s>>L2\",\"label\":\"next\",\"type\":\"edge\",\"outV\":1,\"outVLabel\":\"char\",\"inV\":2,\"inVLabel\":\"char\",\"properties\":{\"name\":\"ab\"}}," - + "{\"id\":2,\"label\":\"char\",\"type\":\"vertex\",\"properties\":{\"name\":\"B\"}}" - + "]}]", edgeLabelId); + String expected = String.format("[{\"labels\":[[],[],[]],\"objects\":[" + + "{\"id\":1,\"label\":\"char\",\"type\":\"vertex\"," + + "\"properties\":{\"name\":\"A\"}}," + + "{\"id\":\"L1>%s>>L2\",\"label\":\"next\",\"type\":\"edge\",\"outV\":1," + + "\"outVLabel\":\"char\",\"inV\":2,\"" + + "inVLabel\":\"char\",\"properties\":{\"name\":\"ab\"}}," + + "{\"id\":2,\"label\":\"char\",\"type\":\"vertex\"," + + "\"properties\":{\"name\":\"B\"}}" + + "]}]", edgeLabelId); Assert.assertEquals(expected, task.result()); script = "g.V(1).out().out().path()"; task = runGremlinJob(script); task = scheduler.waitUntilTaskCompleted(task.id(), 10); Assert.assertEquals(TaskStatus.SUCCESS, task.status()); - expected = "[{\"labels\":[[],[],[]],\"objects\":[" - + "{\"id\":1,\"label\":\"char\",\"type\":\"vertex\",\"properties\":{\"name\":\"A\"}}," - + "{\"id\":2,\"label\":\"char\",\"type\":\"vertex\",\"properties\":{\"name\":\"B\"}}," - + "{\"id\":3,\"label\":\"char\",\"type\":\"vertex\",\"properties\":{\"name\":\"C\"}}]}," - + "{\"labels\":[[],[],[]],\"objects\":[" - + "{\"id\":1,\"label\":\"char\",\"type\":\"vertex\",\"properties\":{\"name\":\"A\"}}," - + "{\"id\":2,\"label\":\"char\",\"type\":\"vertex\",\"properties\":{\"name\":\"B\"}}," - + "{\"id\":4,\"label\":\"char\",\"type\":\"vertex\",\"properties\":{\"name\":\"D\"}}]}]"; + expected = "[{\"labels\":[[],[],[]],\"objects\":[" + + "{\"id\":1,\"label\":\"char\",\"type\":\"vertex\"," + + "\"properties\":{\"name\":\"A\"}}," + + "{\"id\":2,\"label\":\"char\",\"type\":\"vertex\"," + + "\"properties\":{\"name\":\"B\"}}," + + "{\"id\":3,\"label\":\"char\",\"type\":\"vertex\"," + + "\"properties\":{\"name\":\"C\"}}]}," + + "{\"labels\":[[],[],[]],\"objects\":[" + + "{\"id\":1,\"label\":\"char\",\"type\":\"vertex\"," + + "\"properties\":{\"name\":\"A\"}}," + + "{\"id\":2,\"label\":\"char\",\"type\":\"vertex\"," + + "\"properties\":{\"name\":\"B\"}}," + + "{\"id\":4,\"label\":\"char\",\"type\":\"vertex\"," + + "\"properties\":{\"name\":\"D\"}}]}]"; Assert.assertEquals(expected, task.result()); script = "g.V(1).outE().inV().tree()"; task = runGremlinJob(script); task = scheduler.waitUntilTaskCompleted(task.id(), 10); Assert.assertEquals(TaskStatus.SUCCESS, task.status()); - expected = String.format("[[{\"key\":{\"id\":1,\"label\":\"char\",\"type\":\"vertex\",\"properties\":{\"name\":\"A\"}}," - + "\"value\":[" - + "{\"key\":{\"id\":\"L1>%s>>L2\",\"label\":\"next\",\"type\":\"edge\",\"outV\":1,\"outVLabel\":\"char\",\"inV\":2,\"inVLabel\":\"char\",\"properties\":{\"name\":\"ab\"}}," - + "\"value\":[{\"key\":{\"id\":2,\"label\":\"char\",\"type\":\"vertex\",\"properties\":{\"name\":\"B\"}},\"value\":[]}]}]}]]", + expected = String.format("[[{\"key\":{\"id\":1,\"label\":\"char\",\"type\":\"vertex\"," + + "\"properties\":{\"name\":\"A\"}}," + + "\"value\":[" + + "{\"key\":{\"id\":\"L1>%s>>L2\",\"label\":\"next\",\"type\":\"edge\",\"outV\":1," + + "\"outVLabel\":\"char\",\"inV\":2,\"inVLabel\":\"char\"," + + "\"properties\":{\"name\":\"ab\"}}," + + "\"value\":[{\"key\":{\"id\":2,\"label\":\"char\",\"type\":\"vertex\"," + + "\"properties\":{\"name\":\"B\"}},\"value\":[]}]}]}]]", edgeLabelId); Assert.assertEquals(expected, task.result()); @@ -377,11 +395,15 @@ public void testGremlinJobWithSerializedResults() throws TimeoutException { task = runGremlinJob(script); task = scheduler.waitUntilTaskCompleted(task.id(), 10); Assert.assertEquals(TaskStatus.SUCCESS, task.status()); - expected = "[[{\"key\":{\"id\":1,\"label\":\"char\",\"type\":\"vertex\",\"properties\":{\"name\":\"A\"}}," - + "\"value\":[{\"key\":{\"id\":2,\"label\":\"char\",\"type\":\"vertex\",\"properties\":{\"name\":\"B\"}}," - + "\"value\":[" - + "{\"key\":{\"id\":3,\"label\":\"char\",\"type\":\"vertex\",\"properties\":{\"name\":\"C\"}},\"value\":[]}," - + "{\"key\":{\"id\":4,\"label\":\"char\",\"type\":\"vertex\",\"properties\":{\"name\":\"D\"}},\"value\":[]}]}]}]]"; + expected = "[[{\"key\":{\"id\":1,\"label\":\"char\",\"type\":\"vertex\"," + + "\"properties\":{\"name\":\"A\"}}," + + "\"value\":[{\"key\":{\"id\":2,\"label\":\"char\",\"type\":\"vertex\"," + + "\"properties\":{\"name\":\"B\"}}," + + "\"value\":[" + + "{\"key\":{\"id\":3,\"label\":\"char\",\"type\":\"vertex\",\"properties\":" + + "{\"name\":\"C\"}},\"value\":[]}," + + "{\"key\":{\"id\":4,\"label\":\"char\",\"type\":\"vertex\",\"properties\":" + + "{\"name\":\"D\"}},\"value\":[]}]}]}]]"; Assert.assertEquals(expected, task.result()); } @@ -591,11 +613,11 @@ public void testGremlinJobAndRestore() throws Exception { HugeGraph graph = graph(); TaskScheduler scheduler = graph.taskScheduler(); - String gremlin = "System.out.println('task start');" + + String gremlin = "println('task start');" + "for(int i=gremlinJob.progress(); i<=10; i++) {" + " gremlinJob.updateProgress(i);" + " Thread.sleep(200); " + - " System.out.println('sleep=>'+i);" + + " println('sleep=>'+i);" + "}; 100;"; HugeTask task = runGremlinJob(gremlin); diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/core/VertexCoreTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/core/VertexCoreTest.java index 39d4c88409..47ac8c201d 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/core/VertexCoreTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/core/VertexCoreTest.java @@ -516,7 +516,7 @@ public void testRemoveLeftRangeIndex() throws InterruptedException { } @Test - public void testLeftUnionIndex(){ + public void testLeftUnionIndex() { HugeGraph graph = graph(); SchemaManager schema = graph.schema(); @@ -2703,13 +2703,14 @@ public void testQueryOlapWithUpdates() { graph.readMode(GraphReadMode.ALL); // FIXME: expect to throw error here -// Assert.assertThrows(IllegalArgumentException.class, () -> { -// graph.traversal().V().has("pagerank", 0.1D).toList(); -// }, e -> { -// Assert.assertContains("not allowed to query by olap " + -// "when there are uncommitted records", -// e.toString()); -// }); + + // Assert.assertThrows(IllegalArgumentException.class, () -> { + // graph.traversal().V().has("pagerank", 0.1D).toList(); + // }, e -> { + // Assert.assertContains("not allowed to query by olap " + + // "when there are uncommitted records", + // e.toString()); + // }); this.commitTx(); @@ -4339,11 +4340,11 @@ public void testQueryByDatePropertyInString() { List vertices = null; String[] dates = new String[]{ - "2012-01-01 00:00:00.000", - "2013-01-01 00:00:00.000", - "2014-01-01 00:00:00.000", - "2015-01-01 00:00:00.000", - "2016-01-01 00:00:00.000" + "2012-01-01 00:00:00.000", + "2013-01-01 00:00:00.000", + "2014-01-01 00:00:00.000", + "2015-01-01 00:00:00.000", + "2016-01-01 00:00:00.000" }; vertices = graph.traversal().V().hasLabel("person") @@ -4377,11 +4378,11 @@ public void testQueryByDatePropertyWithUnion() { List vertices = null; String[] dates = new String[]{ - "2012-01-01 00:00:00.000", - "2013-01-01 00:00:00.000", - "2014-01-01 00:00:00.000", - "2015-01-01 00:00:00.000", - "2016-01-01 00:00:00.000" + "2012-01-01 00:00:00.000", + "2013-01-01 00:00:00.000", + "2014-01-01 00:00:00.000", + "2015-01-01 00:00:00.000", + "2016-01-01 00:00:00.000" }; vertices = g.V() @@ -4415,11 +4416,11 @@ public void testQueryByDatePropertyInMultiFormatString() { List vertices = null; String[] dates = new String[]{ - "2012-01-01", - "2013-01-01 00:00:00.000", - "2014-01-01 00:00:00.000", - "2015-01-01 00:00:00", - "2016-01-01 00:00:00.000" + "2012-01-01", + "2013-01-01 00:00:00.000", + "2014-01-01 00:00:00.000", + "2015-01-01 00:00:00", + "2016-01-01 00:00:00.000" }; vertices = graph.traversal().V().hasLabel("person") @@ -4571,7 +4572,6 @@ public void testQueryByTextContainsAndExactMatchProperty() { T.label, "author", "id", 1, "name", "James Gosling", "age", 62, "lived", "San Francisco Bay Area"); - vertices = graph.traversal().V() .hasLabel("author") .has("lived", "Bay Area") @@ -4875,7 +4875,7 @@ public void testQueryWithTxNotCommittedByIdInOtherThread() .toList(); size.set(vertices.size()); } finally { - params().closeTx(); + params().closeTx(); } }); t.start(); @@ -9014,7 +9014,7 @@ public void testQueryBySearchIndexWithSpecialSymbol() { GraphTraversalSource g = graph.traversal(); - String city;; + String city; city = g.V().hasLabel("person").has("name", "1") .next().value("city"); Assert.assertEquals(vertex1.value("city"), city); diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/core/VertexLabelCoreTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/core/VertexLabelCoreTest.java index e26c76613c..a077bbf96d 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/core/VertexLabelCoreTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/core/VertexLabelCoreTest.java @@ -567,7 +567,6 @@ public void testAddVertexLabelWithDisableLabelIndex() { } } - @Test public void testAddVertexLabelWithTtl() { super.initPropertyKeys(); diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/testutil/Utils.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/testutil/Utils.java index 7f178f4afd..d1f245b323 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/testutil/Utils.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/testutil/Utils.java @@ -51,6 +51,7 @@ public static HugeGraph open() { confPath = Utils.class.getClassLoader() .getResource(confPath).getPath(); } catch (Exception ignored) { + // ignored Exception } return HugeFactory.open(confPath); } diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/tinkerpop/ProcessBasicSuite.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/tinkerpop/ProcessBasicSuite.java index 804f8354a6..a4fabb4ce3 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/tinkerpop/ProcessBasicSuite.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/tinkerpop/ProcessBasicSuite.java @@ -109,169 +109,169 @@ public class ProcessBasicSuite extends AbstractGremlinSuite { * This list of tests in the suite that will be executed * as part of this suite. */ - private static final Class[] allTests = new Class[] { - // branch - BranchTest.Traversals.class, - ChooseTest.Traversals.class, - OptionalTest.Traversals.class, - LocalTest.Traversals.class, - RepeatTest.Traversals.class, - UnionTest.Traversals.class, + private static final Class[] ALL_TESTS = new Class[] { + // branch + BranchTest.Traversals.class, + ChooseTest.Traversals.class, + OptionalTest.Traversals.class, + LocalTest.Traversals.class, + RepeatTest.Traversals.class, + UnionTest.Traversals.class, - // filter - AndTest.Traversals.class, - CoinTest.Traversals.class, - CyclicPathTest.Traversals.class, - DedupTest.Traversals.class, - DropTest.Traversals.class, - FilterTest.Traversals.class, - HasTest.Traversals.class, - IsTest.Traversals.class, - OrTest.Traversals.class, - RangeTest.Traversals.class, - SampleTest.Traversals.class, - SimplePathTest.Traversals.class, - TailTest.Traversals.class, - WhereTest.Traversals.class, + // filter + AndTest.Traversals.class, + CoinTest.Traversals.class, + CyclicPathTest.Traversals.class, + DedupTest.Traversals.class, + DropTest.Traversals.class, + FilterTest.Traversals.class, + HasTest.Traversals.class, + IsTest.Traversals.class, + OrTest.Traversals.class, + RangeTest.Traversals.class, + SampleTest.Traversals.class, + SimplePathTest.Traversals.class, + TailTest.Traversals.class, + WhereTest.Traversals.class, - // map - AddEdgeTest.Traversals.class, - AddVertexTest.Traversals.class, - CoalesceTest.Traversals.class, - ConstantTest.Traversals.class, - CountTest.Traversals.class, - FlatMapTest.Traversals.class, - FoldTest.Traversals.class, - GraphTest.Traversals.class, - LoopsTest.Traversals.class, - IndexTest.Traversals.class, - MapTest.Traversals.class, - MatchTest.CountMatchTraversals.class, - MatchTest.GreedyMatchTraversals.class, - MathTest.Traversals.class, - MaxTest.Traversals.class, - MeanTest.Traversals.class, - MinTest.Traversals.class, - SumTest.Traversals.class, - OrderTest.Traversals.class, - PathTest.Traversals.class, - ProfileTest.Traversals.class, - ProjectTest.Traversals.class, - PropertiesTest.Traversals.class, - ReadTest.Traversals.class, - SelectTest.Traversals.class, - VertexTest.Traversals.class, - UnfoldTest.Traversals.class, - ValueMapTest.Traversals.class, - // Override WriteTest.Traversals.class - HugeGraphWriteTest.class, + // map + AddEdgeTest.Traversals.class, + AddVertexTest.Traversals.class, + CoalesceTest.Traversals.class, + ConstantTest.Traversals.class, + CountTest.Traversals.class, + FlatMapTest.Traversals.class, + FoldTest.Traversals.class, + GraphTest.Traversals.class, + LoopsTest.Traversals.class, + IndexTest.Traversals.class, + MapTest.Traversals.class, + MatchTest.CountMatchTraversals.class, + MatchTest.GreedyMatchTraversals.class, + MathTest.Traversals.class, + MaxTest.Traversals.class, + MeanTest.Traversals.class, + MinTest.Traversals.class, + SumTest.Traversals.class, + OrderTest.Traversals.class, + PathTest.Traversals.class, + ProfileTest.Traversals.class, + ProjectTest.Traversals.class, + PropertiesTest.Traversals.class, + ReadTest.Traversals.class, + SelectTest.Traversals.class, + VertexTest.Traversals.class, + UnfoldTest.Traversals.class, + ValueMapTest.Traversals.class, + // Override WriteTest.Traversals.class + HugeGraphWriteTest.class, - // sideEffect - AggregateTest.Traversals.class, - ExplainTest.Traversals.class, - GroupTest.Traversals.class, - GroupCountTest.Traversals.class, - InjectTest.Traversals.class, - SackTest.Traversals.class, - SideEffectCapTest.Traversals.class, - SideEffectTest.Traversals.class, - StoreTest.Traversals.class, - SubgraphTest.Traversals.class, - TreeTest.Traversals.class, + // sideEffect + AggregateTest.Traversals.class, + ExplainTest.Traversals.class, + GroupTest.Traversals.class, + GroupCountTest.Traversals.class, + InjectTest.Traversals.class, + SackTest.Traversals.class, + SideEffectCapTest.Traversals.class, + SideEffectTest.Traversals.class, + StoreTest.Traversals.class, + SubgraphTest.Traversals.class, + TreeTest.Traversals.class, - // compliance - ComplexTest.Traversals.class, - CoreTraversalTest.class, - TraversalInterruptionTest.class, + // compliance + ComplexTest.Traversals.class, + CoreTraversalTest.class, + TraversalInterruptionTest.class, - // creations - TranslationStrategyProcessTest.class, + // creations + TranslationStrategyProcessTest.class, - // decorations - ElementIdStrategyProcessTest.class, - EventStrategyProcessTest.class, - ReadOnlyStrategyProcessTest.class, - PartitionStrategyProcessTest.class, - SubgraphStrategyProcessTest.class, + // decorations + ElementIdStrategyProcessTest.class, + EventStrategyProcessTest.class, + ReadOnlyStrategyProcessTest.class, + PartitionStrategyProcessTest.class, + SubgraphStrategyProcessTest.class, - // optimizations - IncidentToAdjacentStrategyProcessTest.class, - EarlyLimitStrategyProcessTest.class + // optimizations + IncidentToAdjacentStrategyProcessTest.class, + EarlyLimitStrategyProcessTest.class }; /** * A list of the minimum set of base tests that * Gremlin flavors should implement to be compliant with Gremlin. */ - private static final Class[] testsToEnforce = new Class[] { - // branch - BranchTest.class, - ChooseTest.class, - OptionalTest.class, - LocalTest.class, - RepeatTest.class, - UnionTest.class, + private static final Class[] TESTS_TO_ENFORCE = new Class[] { + // branch + BranchTest.class, + ChooseTest.class, + OptionalTest.class, + LocalTest.class, + RepeatTest.class, + UnionTest.class, - // filter - AndTest.class, - CoinTest.class, - CyclicPathTest.class, - DedupTest.class, - DropTest.class, - FilterTest.class, - HasTest.class, - IsTest.class, - OrTest.class, - RangeTest.class, - SampleTest.class, - SimplePathTest.class, - TailTest.class, - WhereTest.class, + // filter + AndTest.class, + CoinTest.class, + CyclicPathTest.class, + DedupTest.class, + DropTest.class, + FilterTest.class, + HasTest.class, + IsTest.class, + OrTest.class, + RangeTest.class, + SampleTest.class, + SimplePathTest.class, + TailTest.class, + WhereTest.class, - // map - AddEdgeTest.class, - AddVertexTest.class, - CoalesceTest.class, - ConstantTest.class, - CountTest.class, - FlatMapTest.class, - FoldTest.class, - LoopsTest.class, - IndexTest.class, - MapTest.class, - MatchTest.class, - MathTest.class, - MaxTest.class, - MeanTest.class, - MinTest.class, - SumTest.class, - OrderTest.class, - PathTest.class, - PropertiesTest.class, - ProfileTest.class, - ProjectTest.class, - SelectTest.class, - VertexTest.class, - UnfoldTest.class, - ValueMapTest.class, + // map + AddEdgeTest.class, + AddVertexTest.class, + CoalesceTest.class, + ConstantTest.class, + CountTest.class, + FlatMapTest.class, + FoldTest.class, + LoopsTest.class, + IndexTest.class, + MapTest.class, + MatchTest.class, + MathTest.class, + MaxTest.class, + MeanTest.class, + MinTest.class, + SumTest.class, + OrderTest.class, + PathTest.class, + PropertiesTest.class, + ProfileTest.class, + ProjectTest.class, + SelectTest.class, + VertexTest.class, + UnfoldTest.class, + ValueMapTest.class, - // sideEffect - AggregateTest.class, - GroupTest.class, - GroupCountTest.class, - InjectTest.class, - SackTest.class, - SideEffectCapTest.class, - SideEffectTest.class, - StoreTest.class, - SubgraphTest.class, - TreeTest.class + // sideEffect + AggregateTest.class, + GroupTest.class, + GroupCountTest.class, + InjectTest.class, + SackTest.class, + SideEffectCapTest.class, + SideEffectTest.class, + StoreTest.class, + SubgraphTest.class, + TreeTest.class }; public ProcessBasicSuite(final Class klass, final RunnerBuilder builder) throws InitializationError { - super(klass, builder, allTests, testsToEnforce, true, + super(klass, builder, ALL_TESTS, TESTS_TO_ENFORCE, true, TraversalEngine.Type.STANDARD); RegisterUtil.registerBackends(); } @@ -280,7 +280,7 @@ public ProcessBasicSuite(final Class klass, final RunnerBuilder builder, final Class[] testsToExecute) throws InitializationError { - super(klass, builder, testsToExecute, testsToEnforce, true, + super(klass, builder, testsToExecute, TESTS_TO_ENFORCE, true, TraversalEngine.Type.STANDARD); RegisterUtil.registerBackends(); } diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/tinkerpop/StructureBasicSuite.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/tinkerpop/StructureBasicSuite.java index 0f2800295c..b6cb39e5f8 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/tinkerpop/StructureBasicSuite.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/tinkerpop/StructureBasicSuite.java @@ -69,42 +69,42 @@ public class StructureBasicSuite extends AbstractGremlinSuite { * Gremlin developers should add to this list * as needed to enforce tests upon implementations. */ - private static final Class[] allTests = new Class[] { - CommunityGeneratorTest.class, - DetachedGraphTest.class, - DetachedEdgeTest.class, - DetachedVertexPropertyTest.class, - DetachedPropertyTest.class, - DetachedVertexTest.class, - DistributionGeneratorTest.class, - EdgeTest.class, - FeatureSupportTest.class, - IoCustomTest.class, - IoEdgeTest.class, - IoGraphTest.class, - IoVertexTest.class, - IoPropertyTest.class, - GraphTest.class, - GraphConstructionTest.class, - IoTest.class, - VertexPropertyTest.class, - VariablesTest.class, - PropertyTest.class, - ReferenceGraphTest.class, - ReferenceEdgeTest.class, - ReferenceVertexPropertyTest.class, - ReferenceVertexTest.class, - SerializationTest.class, - StarGraphTest.class, - TransactionTest.class, - VertexTest.class + private static final Class[] ALL_TESTS = new Class[] { + CommunityGeneratorTest.class, + DetachedGraphTest.class, + DetachedEdgeTest.class, + DetachedVertexPropertyTest.class, + DetachedPropertyTest.class, + DetachedVertexTest.class, + DistributionGeneratorTest.class, + EdgeTest.class, + FeatureSupportTest.class, + IoCustomTest.class, + IoEdgeTest.class, + IoGraphTest.class, + IoVertexTest.class, + IoPropertyTest.class, + GraphTest.class, + GraphConstructionTest.class, + IoTest.class, + VertexPropertyTest.class, + VariablesTest.class, + PropertyTest.class, + ReferenceGraphTest.class, + ReferenceEdgeTest.class, + ReferenceVertexPropertyTest.class, + ReferenceVertexTest.class, + SerializationTest.class, + StarGraphTest.class, + TransactionTest.class, + VertexTest.class }; public StructureBasicSuite(final Class klass, final RunnerBuilder builder) throws InitializationError, ConfigurationException { - super(klass, builder, allTests, null, true, + super(klass, builder, ALL_TESTS, null, true, TraversalEngine.Type.STANDARD); RegisterUtil.registerBackends(); diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/FakeObjects.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/FakeObjects.java index 4da5056280..8daa55134f 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/FakeObjects.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/FakeObjects.java @@ -19,7 +19,6 @@ package com.baidu.hugegraph.unit; -import java.util.Collections; import java.util.Date; import org.apache.commons.configuration2.Configuration; diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/cache/CacheTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/cache/CacheTest.java index 7774ae8ff9..5749750319 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/cache/CacheTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/cache/CacheTest.java @@ -45,7 +45,6 @@ import com.baidu.hugegraph.util.Blob; import com.baidu.hugegraph.util.Bytes; - public abstract class CacheTest extends BaseUnitTest { @Before @@ -64,7 +63,9 @@ public void teardown() throws Exception { protected abstract void checkSize(Cache cache, long size, Map kvs); + protected abstract void checkNotInCache(Cache cache, Id id); + protected abstract void checkInCache(Cache cache, Id id); public static class LimitMap extends LinkedHashMap { @@ -99,7 +100,7 @@ protected Cache newCache(long capacity) { protected void checkSize(Cache cache, long size, Map kvs) { Assert.assertEquals(size, cache.size()); - if (kvs !=null) { + if (kvs != null) { for (Map.Entry kv : kvs.entrySet()) { Assert.assertEquals(kv.getValue(), cache.get(kv.getKey())); } @@ -158,7 +159,7 @@ protected void checkSize(Cache cache, long size, // NOTE: offheap cache is calculated based on bytes, not accurate long apprSize = (long) (size * 1.2); Assert.assertLte(apprSize, cache.size()); - if (kvs !=null) { + if (kvs != null) { long matched = 0L; for (Map.Entry kv : kvs.entrySet()) { Object value = cache.get(kv.getKey()); diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/cache/CachedGraphTransactionTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/cache/CachedGraphTransactionTest.java index 20fee3d735..0f9751588a 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/cache/CachedGraphTransactionTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/cache/CachedGraphTransactionTest.java @@ -197,7 +197,8 @@ public void testEdgeCacheClearWhenUpdateVertex() { Whitebox.invoke(cache, "edgesCache", "size")); cache.addVertexProperty(new HugeVertexProperty<>(v3, - cache.graph().schema().getPropertyKey("name"), + cache.graph().schema() + .getPropertyKey("name"), "test-name")); cache.commit(); Assert.assertEquals(0L, @@ -209,7 +210,8 @@ public void testEdgeCacheClearWhenUpdateVertex() { Whitebox.invoke(cache, "edgesCache", "size")); cache.addVertexProperty(new HugeVertexProperty<>(v1, - cache.graph().schema().getPropertyKey("name"), + cache.graph().schema() + .getPropertyKey("name"), "test-name")); cache.commit(); diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/cassandra/CassandraTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/cassandra/CassandraTest.java index 07aea36aba..8c1236ac21 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/cassandra/CassandraTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/cassandra/CassandraTest.java @@ -27,7 +27,6 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.mockito.Mockito; import com.baidu.hugegraph.backend.store.cassandra.CassandraOptions; import com.baidu.hugegraph.backend.store.cassandra.CassandraStore; @@ -42,7 +41,7 @@ public class CassandraTest { @Before public void setup() { OptionSpace.register("cassandra", - "com.baidu.hugegraph.backend.store.cassandra.CassandraOptions"); + "com.baidu.hugegraph.backend.store.cassandra.CassandraOptions"); } @After diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/core/ConditionQueryFlattenTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/core/ConditionQueryFlattenTest.java index d887f041ad..e0bd953ef4 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/core/ConditionQueryFlattenTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/core/ConditionQueryFlattenTest.java @@ -220,7 +220,6 @@ public void testFlattenWithOrAndTree() { Assert.assertEquals(expect, actual); } - @Test public void testFlattenWithIn() { Id key = IdGenerator.of("c1"); diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/core/RangeTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/core/RangeTest.java index 45c63dd6ea..6fb93a389f 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/core/RangeTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/core/RangeTest.java @@ -34,8 +34,8 @@ public class RangeTest { private static final byte[] START = new byte[]{0x0}; private static final byte[] END = new byte[]{ - -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1 + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1 }; @Before diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/core/RolePermissionTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/core/RolePermissionTest.java index 2d6f62ef2a..0478c88487 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/core/RolePermissionTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/core/RolePermissionTest.java @@ -50,7 +50,9 @@ public void testBuiltinAdmin() { Assert.assertSame(admin, RolePermission.builtin(admin)); Assert.assertSame(admin, RolePermission.builtin(role1)); - RolePermission role = RolePermission.fromJson("{\"roles\":{\"admin\":{\"ANY\":[{\"type\":\"ALL\",\"label\":\"write\",\"properties\":null}]}}"); + RolePermission role = RolePermission.fromJson("{\"roles\":{\"admin\":{\"ANY\":[" + + "{\"type\":\"ALL\",\"label\":\"write\"," + + "\"properties\":null}]}}"); Assert.assertTrue(roleContains(admin, role)); RolePermission role2 = RolePermission.all("admin"); @@ -59,7 +61,11 @@ public void testBuiltinAdmin() { Assert.assertTrue(roleContains(role2, role)); RolePermission hg = RolePermission.all("hg1"); - RolePermission role3 = RolePermission.fromJson("{\"roles\":{\"hg1\":{\"ANY\":[{\"type\":\"ALL\",\"label\":\"write\",\"properties\":null}]}}"); + RolePermission role3 = RolePermission.fromJson("{\"roles\":" + + "{\"hg1\":{\"ANY\":" + + "[{\"type\":\"ALL\",\"label\":" + + "\"write\",\"properties\":null}" + + "]}}"); Assert.assertSame(hg, RolePermission.builtin(hg)); Assert.assertSame(hg, RolePermission.fromJson(hg)); Assert.assertTrue(roleContains(hg, role3)); @@ -79,14 +85,34 @@ public void testBuiltinNone() { Assert.assertSame(none, RolePermission.builtin(none)); Assert.assertSame(none, RolePermission.builtin(role1)); - Assert.assertEquals("{\"roles\":{\"none\":{\"NONE\":[{\"type\":\"ALL\",\"label\":\"*\",\"properties\":null}]}}}", none.toJson()); - RolePermission role = RolePermission.fromJson("{\"roles\":{\"none\":{\"NONE\":[{\"type\":\"ALL\",\"label\":\"write\",\"properties\":null}]}}"); + Assert.assertEquals("{\"roles\":{\"none\":{\"NONE\":[" + + "{\"type\":\"ALL\",\"label\":\"*\",\"properties\":null}]}}}", + none.toJson()); + RolePermission role = RolePermission.fromJson("{\"roles\":{\"none\":{\"NONE\":[" + + "{\"type\":\"ALL\",\"label\":\"write\"," + + "\"properties\":null}]}}"); Assert.assertTrue(roleContains(none, role)); } @Test public void testContains() { - String json = "{\"roles\":{\"hugegraph\":{\"READ\":[{\"type\":\"EDGE\",\"label\":\"write\",\"properties\":null},{\"type\":\"PROPERTY_KEY\",\"label\":\"*\",\"properties\":null},{\"type\":\"VERTEX_LABEL\",\"label\":\"*\",\"properties\":null},{\"type\":\"EDGE_LABEL\",\"label\":\"*\",\"properties\":null},{\"type\":\"INDEX_LABEL\",\"label\":\"*\",\"properties\":null},{\"type\":\"VERTEX\",\"label\":\"person\",\"properties\":{\"city\":\"Beijing\",\"age\":\"P.gte(20)\"}},{\"type\":\"VERTEX_LABEL\",\"label\":\"*\",\"properties\":null},{\"type\":\"PROPERTY_KEY\",\"label\":\"*\",\"properties\":null}],\"WRITE\":[{\"type\":\"VERTEX\",\"label\":\"person\",\"properties\":{\"city\":\"Beijing\",\"age\":\"P.gte(20)\"}},{\"type\":\"VERTEX_LABEL\",\"label\":\"*\",\"properties\":null},{\"type\":\"PROPERTY_KEY\",\"label\":\"*\",\"properties\":null}],\"EXECUTE\":[{\"type\":\"GREMLIN\",\"label\":\"*\",\"properties\":null}]},\"hugegraph1\":{\"READ\":[]}}}"; + String json = "{\"roles\":" + + "{\"hugegraph\":{\"READ\":[" + + "{\"type\":\"EDGE\",\"label\":\"write\",\"properties\":null}," + + "{\"type\":\"PROPERTY_KEY\",\"label\":\"*\",\"properties\":null}," + + "{\"type\":\"VERTEX_LABEL\",\"label\":\"*\",\"properties\":null}," + + "{\"type\":\"EDGE_LABEL\",\"label\":\"*\",\"properties\":null}," + + "{\"type\":\"INDEX_LABEL\",\"label\":\"*\",\"properties\":null}," + + "{\"type\":\"VERTEX\",\"label\":\"person\",\"properties\":" + + "{\"city\":\"Beijing\",\"age\":\"P.gte(20)\"}}," + + "{\"type\":\"VERTEX_LABEL\",\"label\":\"*\",\"properties\":null}," + + "{\"type\":\"PROPERTY_KEY\",\"label\":\"*\",\"properties\":null}],\"WRITE\":[" + + "{\"type\":\"VERTEX\",\"label\":\"person\",\"properties\":" + + "{\"city\":\"Beijing\",\"age\":\"P.gte(20)\"}}," + + "{\"type\":\"VERTEX_LABEL\",\"label\":\"*\",\"properties\":null}," + + "{\"type\":\"PROPERTY_KEY\",\"label\":\"*\",\"properties\":null}],\"EXECUTE\":[" + + "{\"type\":\"GREMLIN\",\"label\":\"*\",\"properties\":null}]}," + + "\"hugegraph1\":{\"READ\":[]}}}"; RolePermission role = RolePermission.fromJson(json); @@ -94,44 +120,76 @@ public void testContains() { Assert.assertEquals(role, r1); Assert.assertTrue(roleContains(role, r1)); - RolePermission r2 = RolePermission.fromJson("{\"roles\":{\"hugegraph\":{\"READ\":[{\"type\":\"EDGE\",\"label\":\"write\",\"properties\":null}]}}"); + RolePermission r2 = RolePermission.fromJson("{\"roles\":{\"hugegraph\":{\"READ\":[" + + "{\"type\":\"EDGE\",\"label\":\"write\"," + + "\"properties\":null}]}}"); Assert.assertTrue(roleContains(role, r2)); - RolePermission r3 = RolePermission.fromJson("{\"roles\":{\"hugegraph\":{\"READ\":[{\"type\":\"EDGE\",\"label\":\"write\",\"properties\":{\"date\":\"2018-8-8\"}}]}}"); + RolePermission r3 = RolePermission.fromJson("{\"roles\":{\"hugegraph\":{\"READ\":[" + + "{\"type\":\"EDGE\",\"label\":\"write\"," + + "\"properties\":{\"date\":\"2018-8-8\"}}]}}"); Assert.assertTrue(roleContains(role, r3)); - RolePermission r4 = RolePermission.fromJson("{\"roles\":{\"hugegraph\":{\"WRITE\":[{\"type\":\"VERTEX\",\"label\":\"person\",\"properties\":{\"city\":\"Beijing\",\"age\":\"P.gte(20)\"}}]}}"); + RolePermission r4 = RolePermission.fromJson("{\"roles\":{\"hugegraph\":{\"WRITE\":[" + + "{\"type\":\"VERTEX\",\"label\":\"person\"," + + "\"properties\":{\"city\":\"Beijing\"," + + "\"age\":\"P.gte(20)\"}}]}}"); Assert.assertTrue(roleContains(role, r4)); - RolePermission r5 = RolePermission.fromJson("{\"roles\":{\"hugegraph\":{\"WRITE\":[{\"type\":\"VERTEX\",\"label\":\"person\",\"properties\":{\"city\":\"Beijing\",\"age\":\"P.gte(21)\"}}]}}"); + RolePermission r5 = RolePermission.fromJson("{\"roles\":{\"hugegraph\":{\"WRITE\":[" + + "{\"type\":\"VERTEX\",\"label\":\"person\"," + + "\"properties\":{\"city\":\"Beijing\"," + + "\"age\":\"P.gte(21)\"}}]}}"); Assert.assertFalse(roleContains(role, r5)); - RolePermission r6 = RolePermission.fromJson("{\"roles\":{\"hugegraph\":{\"WRITE\":[{\"type\":\"VERTEX\",\"label\":\"person\",\"properties\":null}]}}"); + RolePermission r6 = RolePermission.fromJson("{\"roles\":{\"hugegraph\":{\"WRITE\":[" + + "{\"type\":\"VERTEX\",\"label\":\"person\"," + + "\"properties\":null}]}}"); Assert.assertFalse(roleContains(role, r6)); - RolePermission r7 = RolePermission.fromJson("{\"roles\":{\"hugegraph\":{\"WRITE\":[{\"type\":\"VERTEX\",\"label\":\"person2\",\"properties\":{\"city\":\"Beijing\",\"age\":\"P.gte(20)\"}}]}}"); + RolePermission r7 = RolePermission.fromJson("{\"roles\":{\"hugegraph\":{\"WRITE\":[" + + "{\"type\":\"VERTEX\",\"label\":\"person2\"," + + "\"properties\":{\"city\":\"Beijing\"," + + "\"age\":\"P.gte(20)\"}}]}}"); Assert.assertFalse(roleContains(role, r7)); - RolePermission r8 = RolePermission.fromJson("{\"roles\":{\"hugegraph\":{\"WRITE\":[{\"type\":\"EDGE\",\"label\":\"person\",\"properties\":{\"city\":\"Beijing\",\"age\":\"P.gte(20)\"}}]}}"); + RolePermission r8 = RolePermission.fromJson("{\"roles\":{\"hugegraph\":{\"WRITE\":[" + + "{\"type\":\"EDGE\",\"label\":\"person\"," + + "\"properties\":{\"city\":\"Beijing\"," + + "\"age\":\"P.gte(20)\"}}]}}"); Assert.assertFalse(roleContains(role, r8)); - role = RolePermission.fromJson("{\"roles\":{\"hugegraph\":{\"READ\":[{\"type\":\"ALL\",\"label\":\"write\",\"properties\":null}]}}"); - RolePermission r9 = RolePermission.fromJson("{\"roles\":{\"hugegraph\":{\"READ\":[{\"type\":\"ALL\",\"label\":\"write\",\"properties\":null}]}}"); + role = RolePermission.fromJson("{\"roles\":{\"hugegraph\":{\"READ\":[" + + "{\"type\":\"ALL\",\"label\":\"write\"," + + "\"properties\":null}]}}"); + RolePermission r9 = RolePermission.fromJson("{\"roles\":{\"hugegraph\":{\"READ\":[" + + "{\"type\":\"ALL\",\"label\":\"write\"," + + "\"properties\":null}]}}"); Assert.assertTrue(roleContains(role, r9)); - RolePermission r10 = RolePermission.fromJson("{\"roles\":{\"hugegraph\":{\"READ\":[{\"type\":\"EDGE\",\"label\":\"write\",\"properties\":null}]}}"); + RolePermission r10 = RolePermission.fromJson("{\"roles\":{\"hugegraph\":{\"READ\":[" + + "{\"type\":\"EDGE\",\"label\":\"write\"," + + "\"properties\":null}]}}"); Assert.assertTrue(roleContains(role, r10)); - RolePermission r11 = RolePermission.fromJson("{\"roles\":{\"hugegraph\":{\"READ\":[{\"type\":\"VERTEX\",\"label\":\"write\",\"properties\":null}]}}"); + RolePermission r11 = RolePermission.fromJson("{\"roles\":{\"hugegraph\":{\"READ\":[" + + "{\"type\":\"VERTEX\",\"label\":\"write\"," + + "\"properties\":null}]}}"); Assert.assertTrue(roleContains(role, r11)); - RolePermission r12 = RolePermission.fromJson("{\"roles\":{\"hugegraph\":{\"READ\":[{\"type\":\"VERTEX\",\"label\":\"person\",\"properties\":null}]}}"); + RolePermission r12 = RolePermission.fromJson("{\"roles\":{\"hugegraph\":{\"READ\":[" + + "{\"type\":\"VERTEX\",\"label\":\"person\"," + + "\"properties\":null}]}}"); Assert.assertFalse(roleContains(role, r12)); - RolePermission r13 = RolePermission.fromJson("{\"roles\":{\"hugegraph\":{\"WRITE\":[{\"type\":\"VERTEX\",\"label\":\"write\",\"properties\":null}]}}"); + RolePermission r13 = RolePermission.fromJson("{\"roles\":{\"hugegraph\":{\"WRITE\":[" + + "{\"type\":\"VERTEX\",\"label\":\"write\"," + + "\"properties\":null}]}}"); Assert.assertFalse(roleContains(role, r13)); - RolePermission r14 = RolePermission.fromJson("{\"roles\":{\"hugegraph2\":{\"READ\":[{\"type\":\"VERTEX\",\"label\":\"write\",\"properties\":null}]}}"); + RolePermission r14 = RolePermission.fromJson("{\"roles\":{\"hugegraph2\":{\"READ\":[" + + "{\"type\":\"VERTEX\",\"label\":\"write\"," + + "\"properties\":null}]}}"); Assert.assertFalse(roleContains(role, r14)); } @@ -270,7 +328,8 @@ public void testResourceType() { public void testHugeResource() { HugeResource r = new HugeResource(ResourceType.VERTEX, "person", ImmutableMap.of("city", "Beijing")); - String json = "{\"type\":\"VERTEX\",\"label\":\"person\",\"properties\":{\"city\":\"Beijing\"}}"; + String json = "{\"type\":\"VERTEX\",\"label\":\"person\",\"properties\":" + + "{\"city\":\"Beijing\"}}"; Assert.assertEquals(json, r.toString()); Assert.assertEquals(r, HugeResource.parseResource(json)); @@ -292,7 +351,8 @@ public void testHugeResource() { }); Assert.assertThrows(HugeException.class, () -> { - String resource = "{\"type\":\"VERTEX\",\"label\":\"person\",\"properties\":{\"city\":\"P.(1)\"}}"; + String resource = "{\"type\":\"VERTEX\",\"label\":\"person\",\"properties\":" + + "{\"city\":\"P.(1)\"}}"; HugeResource.parseResource(resource); }, e -> { Assert.assertContains("Invalid predicate: P.(1)", @@ -300,7 +360,8 @@ public void testHugeResource() { }); Assert.assertThrows(HugeException.class, () -> { - String resources = "[{\"type\":\"VERTEX\",\"label\":\"person\",\"properties\":{\"city\":\"P.(1)\"}}]"; + String resources = "[{\"type\":\"VERTEX\",\"label\":\"person\",\"properties\":" + + "{\"city\":\"P.(1)\"}}]"; HugeResource.parseResources(resources); }, e -> { Assert.assertContains("Invalid predicate: P.(1)", diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/core/SecurityManagerTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/core/SecurityManagerTest.java index 5c35f544af..9f04c875db 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/core/SecurityManagerTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/core/SecurityManagerTest.java @@ -120,14 +120,20 @@ public void testExit() { public void testFile() { // read file try (FileInputStream fis = new FileInputStream(new File(""))) { - } catch (IOException ignored) {} + // pass + } catch (IOException ignored) { + // ignored exception + } String result = runGremlinJob("new FileInputStream(new File(\"\"))"); assertError(result, "Not allowed to read file via Gremlin"); // read file String pom = System.getProperty("user.dir") + "/a.groovy"; try (FileInputStream fis = new FileInputStream(new File(pom))) { - } catch (IOException ignored) {} + // pass + } catch (IOException ignored) { + // ignored exception + } result = runGremlinJob(String.format( "new FileInputStream(new File(\"%s\"))", pom)); assertError(result, "(No such file or directory)"); @@ -145,7 +151,10 @@ public void testFile() { // write file try (FileOutputStream fos = new FileOutputStream(new File(""))) { - } catch (IOException ignored) {} + // pass + } catch (IOException ignored) { + // ignored IOException + } result = runGremlinJob("new FileOutputStream(new File(\"\"))"); assertError(result, "Not allowed to write file via Gremlin"); @@ -173,7 +182,11 @@ public void testSocket() throws IOException { * NOTE: if remove this, gremlin job will call System.loadLibrary("net") * then throw exception because checkLink failed */ - try (ServerSocket serverSocket = new ServerSocket(8200)) {} + try (ServerSocket serverSocket = new ServerSocket(8200)) { + // pass + } catch (IOException ignored) { + // ignored UnsatisfiedLinkError + } String result = runGremlinJob("new ServerSocket(8200)"); assertError(result, "Not allowed to listen socket via Gremlin"); @@ -189,7 +202,9 @@ public void testSocket() throws IOException { try (Socket socket = new Socket()) { SocketAddress address = new InetSocketAddress("localhost", 8200); socket.connect(address); - } catch (ConnectException ignored) {} + } catch (ConnectException ignored) { + // ignored ConnectException + } result = runGremlinJob("new Socket().connect(" + "new InetSocketAddress(\"localhost\", 8200))"); assertError(result, "Not allowed to connect socket via Gremlin"); @@ -233,7 +248,9 @@ public void testExec() throws IOException, InterruptedException { public void testLink() { try { System.loadLibrary("hugegraph.jar"); - } catch (UnsatisfiedLinkError ignored) {} + } catch (UnsatisfiedLinkError ignored) { + // ignored UnsatisfiedLinkError + } String result = runGremlinJob("Runtime.getRuntime().loadLibrary" + "(\"test.jar\")"); diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/rocksdb/BaseRocksDBUnitTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/rocksdb/BaseRocksDBUnitTest.java index e6478f4fad..c9859e73da 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/rocksdb/BaseRocksDBUnitTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/rocksdb/BaseRocksDBUnitTest.java @@ -68,12 +68,12 @@ public void teardown() throws RocksDBException { } protected void put(String key, String value) { - this.rocks.session().put(TABLE, b(key), b(value)); + this.rocks.session().put(TABLE, getBytes(key), getBytes(value)); this.commit(); } protected String get(String key) throws RocksDBException { - return s(this.rocks.session().get(TABLE, b(key))); + return getString(this.rocks.session().get(TABLE, getBytes(key))); } protected void clearData() throws RocksDBException { @@ -92,21 +92,21 @@ protected void commit() { } } - protected static byte[] b(String str) { + protected static byte[] getBytes(String str) { return str.getBytes(); } - protected static String s(byte[] bytes) { + protected static String getString(byte[] bytes) { return bytes == null ? null : new String(bytes); } - protected static byte[] b(long val) { + protected static byte[] getBytes(long val) { ByteBuffer buf = ByteBuffer.allocate(8).order(ByteOrder.nativeOrder()); buf.putLong(val); return buf.array(); } - protected static long l(byte[] bytes) { + protected static long getLong(byte[] bytes) { ByteBuffer buf = ByteBuffer.wrap(bytes).order(ByteOrder.nativeOrder()); return buf.getLong(); } diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/rocksdb/RocksDBCountersTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/rocksdb/RocksDBCountersTest.java index 9767ceeca9..097ce90c75 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/rocksdb/RocksDBCountersTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/rocksdb/RocksDBCountersTest.java @@ -108,7 +108,7 @@ private Id nextId(Session session, HugeType type) { // Do get-increase-get-compare operation long counter = 0L; long expect = -1L; - synchronized(this) { + synchronized (this) { for (int i = 0; i < MAX_TIMES; i++) { counter = this.counters.getCounter(session, type); diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/rocksdb/RocksDBPerfTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/rocksdb/RocksDBPerfTest.java index 9849195c2d..ded05734e8 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/rocksdb/RocksDBPerfTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/rocksdb/RocksDBPerfTest.java @@ -43,7 +43,7 @@ public void testSeekExistKey() throws RocksDBException { Session session = this.rocks.session(); for (int i = 0; i < TIMES; i++) { - Iterator iter = session.scan(TABLE, b("exist")); + Iterator iter = session.scan(TABLE, getBytes("exist")); while (iter.hasNext()) { iter.next(); } @@ -56,7 +56,7 @@ public void testSeekNonExistKey() throws RocksDBException { Session session = this.rocks.session(); for (int i = 0; i < TIMES; i++) { - Iterator iter = session.scan(TABLE, b("non-exist")); + Iterator iter = session.scan(TABLE, getBytes("non-exist")); while (iter.hasNext()) { iter.next(); } @@ -69,7 +69,7 @@ public void testGetExistKey() throws RocksDBException { Session session = this.rocks.session(); for (int i = 0; i < TIMES; i++) { - byte[] value = session.get(TABLE, b("exist")); + byte[] value = session.get(TABLE, getBytes("exist")); assert value.length == "value".length(); } } @@ -80,7 +80,7 @@ public void testGetNonExistKey() throws RocksDBException { Session session = this.rocks.session(); for (int i = 0; i < TIMES; i++) { - byte[] value = session.get(TABLE, b("non-exist")); + byte[] value = session.get(TABLE, getBytes("non-exist")); assert value == null; } } @@ -105,9 +105,9 @@ public void testGet3Keys() throws RocksDBException { Session session = this.rocks.session(); for (int i = 0; i < TIMES; i++) { - session.get(TABLE, b("person:1gname")); - session.get(TABLE, b("person:1gage")); - session.get(TABLE, b("person:1gcity")); + session.get(TABLE, getBytes("person:1gname")); + session.get(TABLE, getBytes("person:1gage")); + session.get(TABLE, getBytes("person:1gcity")); } } @@ -125,9 +125,9 @@ public void testMultiGet3Keys() throws RocksDBException { Session session = this.rocks.session(); BackendColumnIterator iter; for (int i = 0; i < TIMES; i++) { - List keys = Arrays.asList(b("person:1gname"), - b("person:1gage"), - b("person:1gcity")); + List keys = Arrays.asList(getBytes("person:1gname"), + getBytes("person:1gage"), + getBytes("person:1gcity")); iter = session.get(TABLE, keys); iter.next(); iter.next(); @@ -150,7 +150,7 @@ public void testGet1KeyWithMultiValues() throws RocksDBException { Session session = this.rocks.session(); for (int i = 0; i < TIMES; i++) { - session.get(TABLE, b("person:2all")); + session.get(TABLE, getBytes("person:2all")); } } @@ -167,7 +167,7 @@ public void testScanByPrefix() throws RocksDBException { Session session = this.rocks.session(); for (int i = 0; i < TIMES; i++) { - Iterator iter = session.scan(TABLE, b("person:1")); + Iterator iter = session.scan(TABLE, getBytes("person:1")); while (iter.hasNext()) { iter.next(); } @@ -211,7 +211,7 @@ public void testUpdate() throws RocksDBException { int value = i; comms.put(i, value); String key = String.format("index:%3d:%d", i, value); - session.put(TABLE, b(key), empty); + session.put(TABLE, getBytes(key), empty); } session.commit(); @@ -220,13 +220,13 @@ public void testUpdate() throws RocksDBException { for (int i = 0; i < n; i++) { int value = comms.get(i); String old = String.format("index:%3d:%d", i, value); - session.delete(TABLE, b(old)); + session.delete(TABLE, getBytes(old)); value = r.nextInt(n); // TODO: aggregate value = i + 1; comms.put(i, value); String key = String.format("index:%3d:%d", i, value); - session.put(TABLE, b(key), empty); + session.put(TABLE, getBytes(key), empty); } session.commit(); } @@ -243,7 +243,7 @@ public void testScanByPrefixAfterUpdate() throws RocksDBException { for (int j = 0; j < queryTimes; j++) { for (int i = 0; i < n; i++) { String key = String.format("index:%3d", i); - Iterator iter = session.scan(TABLE, b(key)); + Iterator iter = session.scan(TABLE, getBytes(key)); while (iter.hasNext()) { iter.next(); } diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/rocksdb/RocksDBSessionTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/rocksdb/RocksDBSessionTest.java index 085524eeee..2e870d858e 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/rocksdb/RocksDBSessionTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/rocksdb/RocksDBSessionTest.java @@ -26,6 +26,7 @@ import java.util.Map; import java.util.Random; +import com.baidu.hugegraph.unit.BaseUnitTest; import org.junit.Assume; import org.junit.Test; import org.rocksdb.RocksDBException; @@ -39,71 +40,71 @@ public class RocksDBSessionTest extends BaseRocksDBUnitTest { @Test public void testPutAndGet() throws RocksDBException { - String value = s(this.rocks.session().get(TABLE, b("person:1gname"))); + String value = getString(this.rocks.session().get(TABLE, getBytes("person:1gname"))); Assert.assertEquals(null, value); - this.rocks.session().put(TABLE, b("person:1gname"), b("James")); - this.rocks.session().put(TABLE, b("person:1gage"), b(19)); - this.rocks.session().put(TABLE, b("person:1gcity"), b("Beijing")); + this.rocks.session().put(TABLE, getBytes("person:1gname"), getBytes("James")); + this.rocks.session().put(TABLE, getBytes("person:1gage"), getBytes(19)); + this.rocks.session().put(TABLE, getBytes("person:1gcity"), getBytes("Beijing")); this.commit(); - value = s(this.rocks.session().get(TABLE, b("person:1gname"))); + value = getString(this.rocks.session().get(TABLE, getBytes("person:1gname"))); Assert.assertEquals("James", value); - long age = l(this.rocks.session().get(TABLE, b("person:1gage"))); + long age = getLong(this.rocks.session().get(TABLE, getBytes("person:1gage"))); Assert.assertEquals(19, age); - value = s(this.rocks.session().get(TABLE, b("person:1gcity"))); + value = getString(this.rocks.session().get(TABLE, getBytes("person:1gcity"))); Assert.assertEquals("Beijing", value); } @Test public void testPutAndMultiGet() throws RocksDBException { BackendColumnIterator values = this.rocks.session().get(TABLE, - Arrays.asList(b("person:1gname"))); + Arrays.asList(getBytes("person:1gname"))); Assert.assertFalse(values.hasNext()); - this.rocks.session().put(TABLE, b("person:1gname"), b("James")); - this.rocks.session().put(TABLE, b("person:1gage"), b(19)); - this.rocks.session().put(TABLE, b("person:1gcity"), b("Beijing")); + this.rocks.session().put(TABLE, getBytes("person:1gname"), getBytes("James")); + this.rocks.session().put(TABLE, getBytes("person:1gage"), getBytes(19)); + this.rocks.session().put(TABLE, getBytes("person:1gcity"), getBytes("Beijing")); this.commit(); values = this.rocks.session().get(TABLE, Arrays.asList( - b("person:1gname"), - b("person:1gage"))); + getBytes("person:1gname"), + getBytes("person:1gage"))); Assert.assertTrue(values.hasNext()); - Assert.assertEquals("James", s(values.next().value)); - Assert.assertEquals(19, l(values.next().value)); + Assert.assertEquals("James", getString(values.next().value)); + Assert.assertEquals(19, getLong(values.next().value)); Assert.assertFalse(values.hasNext()); values = this.rocks.session().get(TABLE, Arrays.asList( - b("person:1gname"), - b("person:1gage"), - b("person:1gcity"))); + getBytes("person:1gname"), + getBytes("person:1gage"), + getBytes("person:1gcity"))); Assert.assertTrue(values.hasNext()); - Assert.assertEquals("James", s(values.next().value)); - Assert.assertEquals(19, l(values.next().value)); - Assert.assertEquals("Beijing", s(values.next().value)); + Assert.assertEquals("James", getString(values.next().value)); + Assert.assertEquals(19, getLong(values.next().value)); + Assert.assertEquals("Beijing", getString(values.next().value)); Assert.assertFalse(values.hasNext()); values = this.rocks.session().get(TABLE, Arrays.asList( - b("person:1gname"), - b("person:1gage-non-exist"), - b("person:1gcity"))); + getBytes("person:1gname"), + getBytes("person:1gage-non-exist"), + getBytes("person:1gcity"))); Assert.assertTrue(values.hasNext()); - Assert.assertEquals("James", s(values.next().value)); - Assert.assertEquals("Beijing", s(values.next().value)); + Assert.assertEquals("James", getString(values.next().value)); + Assert.assertEquals("Beijing", getString(values.next().value)); Assert.assertFalse(values.hasNext()); values = this.rocks.session().get(TABLE, Arrays.asList( - b("person:1gname"), - b("person:1gage-non-exist"), - b("person:1gcity"), - b("person:1gname"))); + getBytes("person:1gname"), + getBytes("person:1gage-non-exist"), + getBytes("person:1gcity"), + getBytes("person:1gname"))); Assert.assertTrue(values.hasNext()); - Assert.assertEquals("James", s(values.next().value)); - Assert.assertEquals("Beijing", s(values.next().value)); - Assert.assertEquals("James", s(values.next().value)); + Assert.assertEquals("James", getString(values.next().value)); + Assert.assertEquals("Beijing", getString(values.next().value)); + Assert.assertEquals("James", getString(values.next().value)); Assert.assertFalse(values.hasNext()); } @@ -112,52 +113,52 @@ public void testPutAndGetWithMultiTables() throws RocksDBException { final String TABLE2 = "test-table2"; this.rocks.createTable(TABLE2); - this.rocks.session().put(TABLE, b("person:1gname"), b("James")); - this.rocks.session().put(TABLE2, b("person:1gname"), b("James2")); + this.rocks.session().put(TABLE, getBytes("person:1gname"), getBytes("James")); + this.rocks.session().put(TABLE2, getBytes("person:1gname"), getBytes("James2")); this.commit(); - String value = s(this.rocks.session().get(TABLE, b("person:1gname"))); + String value = getString(this.rocks.session().get(TABLE, getBytes("person:1gname"))); Assert.assertEquals("James", value); - String value2 = s(this.rocks.session().get(TABLE2, b("person:1gname"))); + String value2 = getString(this.rocks.session().get(TABLE2, getBytes("person:1gname"))); Assert.assertEquals("James2", value2); } @Test public void testMergeWithCounter() throws RocksDBException { - this.rocks.session().put(TABLE, b("person:1gage"), b(19)); + this.rocks.session().put(TABLE, getBytes("person:1gage"), getBytes(19)); this.commit(); - this.rocks.session().merge(TABLE, b("person:1gage"), b(1)); + this.rocks.session().merge(TABLE, getBytes("person:1gage"), getBytes(1)); this.commit(); - byte[] value = this.rocks.session().get(TABLE, b("person:1gage")); - Assert.assertEquals(20L, l(value)); + byte[] value = this.rocks.session().get(TABLE, getBytes("person:1gage")); + Assert.assertEquals(20L, getLong(value)); - this.rocks.session().merge(TABLE, b("person:1gage"), b(123456789000L)); + this.rocks.session().merge(TABLE, getBytes("person:1gage"), getBytes(123456789000L)); this.commit(); - value = this.rocks.session().get(TABLE, b("person:1gage")); - Assert.assertEquals(123456789020L, l(value)); + value = this.rocks.session().get(TABLE, getBytes("person:1gage")); + Assert.assertEquals(123456789020L, getLong(value)); - this.rocks.session().put(TABLE, b("person:1gage"), b(250)); + this.rocks.session().put(TABLE, getBytes("person:1gage"), getBytes(250)); this.commit(); - this.rocks.session().merge(TABLE, b("person:1gage"), b(10)); + this.rocks.session().merge(TABLE, getBytes("person:1gage"), getBytes(10)); this.commit(); - value = this.rocks.session().get(TABLE, b("person:1gage")); - Assert.assertEquals(260L, l(value)); + value = this.rocks.session().get(TABLE, getBytes("person:1gage")); + Assert.assertEquals(260L, getLong(value)); } @Test public void testMergeWithStringList() throws RocksDBException { Assume.assumeTrue("Not support string append now", false); - this.rocks.session().put(TABLE, b("person:1gphoneno"), b("12306")); + this.rocks.session().put(TABLE, getBytes("person:1gphoneno"), getBytes("12306")); this.commit(); - this.rocks.session().merge(TABLE, b("person:1gphoneno"), b("12315")); + this.rocks.session().merge(TABLE, getBytes("person:1gphoneno"), getBytes("12315")); this.commit(); Assert.assertEquals("12306,12315", get("person:1gphoneno")); @@ -173,7 +174,7 @@ public void testScanByAll() throws RocksDBException { Iterator iter = session.scan(TABLE); while (iter.hasNext()) { BackendColumn col = iter.next(); - results.put(s(col.name), s(col.value)); + results.put(getString(col.name), getString(col.value)); } Assert.assertEquals(2, results.size()); @@ -185,15 +186,15 @@ public void testScanByAll() throws RocksDBException { iter = session.scan(TABLE); while (iter.hasNext()) { BackendColumn col = iter.next(); - results.put(s(col.name), s(col.value)); + results.put(getString(col.name), getString(col.value)); } Assert.assertEquals(4, results.size()); // delete some keys then scan again - this.rocks.session().delete(TABLE, b("person:2gname")); + this.rocks.session().delete(TABLE, getBytes("person:2gname")); this.rocks.session().commit(); - runWithThreads(1, () ->{ - this.rocks.session().delete(TABLE, b("person:3gname")); + BaseUnitTest.runWithThreads(1, () -> { + this.rocks.session().delete(TABLE, getBytes("person:3gname")); this.rocks.session().commit(); this.rocks.close(); }); @@ -202,19 +203,19 @@ public void testScanByAll() throws RocksDBException { iter = session.scan(TABLE); while (iter.hasNext()) { BackendColumn col = iter.next(); - results.put(s(col.name), s(col.value)); + results.put(getString(col.name), getString(col.value)); } Assert.assertEquals(2, results.size()); // delete some keys by prefix then scan again - this.rocks.session().deletePrefix(TABLE, b("person:1")); + this.rocks.session().deletePrefix(TABLE, getBytes("person:1")); this.rocks.session().commit(); results = new HashMap<>(); iter = session.scan(TABLE); while (iter.hasNext()) { BackendColumn col = iter.next(); - results.put(s(col.name), s(col.value)); + results.put(getString(col.name), getString(col.value)); } Assert.assertEquals(1, results.size()); } @@ -231,10 +232,10 @@ public void testScanByPrefix() throws RocksDBException { Map results = new HashMap<>(); Session session = this.rocks.session(); - Iterator iter = session.scan(TABLE, b("person:1")); + Iterator iter = session.scan(TABLE, getBytes("person:1")); while (iter.hasNext()) { BackendColumn col = iter.next(); - results.put(s(col.name), s(col.value)); + results.put(getString(col.name), getString(col.value)); } Assert.assertEquals(3, results.size()); @@ -262,11 +263,11 @@ public void testScanByRange() throws RocksDBException { Map results = new HashMap<>(); Session session = this.rocks.session(); Iterator iter = session.scan(TABLE, - b("person:1"), - b("person:3")); + getBytes("person:1"), + getBytes("person:3")); while (iter.hasNext()) { BackendColumn col = iter.next(); - results.put(s(col.name), s(col.value)); + results.put(getString(col.name), getString(col.value)); } Assert.assertEquals(6, results.size()); @@ -286,23 +287,23 @@ public void testScanByRangeWithBytes() throws RocksDBException { Session session = this.rocks.session(); byte[] key11 = new byte[]{1, 1}; - byte[] value11 = b("value-1-1"); + byte[] value11 = getBytes("value-1-1"); session.put(TABLE, key11, value11); byte[] key12 = new byte[]{1, 2}; - byte[] value12 = b("value-1-2"); + byte[] value12 = getBytes("value-1-2"); session.put(TABLE, key12, value12); byte[] key21 = new byte[]{2, 1}; - byte[] value21 = b("value-2-1"); + byte[] value21 = getBytes("value-2-1"); session.put(TABLE, key21, value21); byte[] key22 = new byte[]{2, 2}; - byte[] value22 = b("value-2-2"); + byte[] value22 = getBytes("value-2-2"); session.put(TABLE, key22, value22); byte[] key23 = new byte[]{2, 3}; - byte[] value23 = b("value-2-3"); + byte[] value23 = getBytes("value-2-3"); session.put(TABLE, key23, value23); this.commit(); @@ -330,19 +331,19 @@ public void testScanByRangeWithSignedBytes() throws RocksDBException { Session session = this.rocks.session(); byte[] key11 = new byte[]{1, 1}; - byte[] value11 = b("value-1-1"); + byte[] value11 = getBytes("value-1-1"); session.put(TABLE, key11, value11); byte[] key12 = new byte[]{1, 2}; - byte[] value12 = b("value-1-2"); + byte[] value12 = getBytes("value-1-2"); session.put(TABLE, key12, value12); byte[] key13 = new byte[]{1, -3}; - byte[] value13 = b("value-1-3"); + byte[] value13 = getBytes("value-1-3"); session.put(TABLE, key13, value13); byte[] key21 = new byte[]{2, 1}; - byte[] value21 = b("value-2-1"); + byte[] value21 = getBytes("value-2-1"); session.put(TABLE, key21, value21); this.commit(); @@ -394,7 +395,7 @@ public void testDeleteByKey() throws RocksDBException { Assert.assertEquals("19", get("person:1gage")); Assert.assertEquals("Beijing", get("person:1gcity")); - this.rocks.session().delete(TABLE, b("person:1gage")); + this.rocks.session().delete(TABLE, getBytes("person:1gage")); this.commit(); Assert.assertEquals("James", get("person:1gname")); @@ -412,7 +413,7 @@ public void testDeleteByKeyButNotExist() throws RocksDBException { Assert.assertEquals("19", get("person:1gage")); Assert.assertEquals("Beijing", get("person:1gcity")); - this.rocks.session().delete(TABLE, b("person:1")); + this.rocks.session().delete(TABLE, getBytes("person:1")); this.commit(); Assert.assertEquals("James", get("person:1gname")); @@ -434,7 +435,7 @@ public void testDeleteByPrefix() throws RocksDBException { Assert.assertEquals("19", get("person:1gage")); Assert.assertEquals("Beijing", get("person:1gcity")); - this.rocks.session().deletePrefix(TABLE, b("person:1")); + this.rocks.session().deletePrefix(TABLE, getBytes("person:1")); this.commit(); Assert.assertEquals(null, get("person:1gname")); @@ -462,7 +463,7 @@ public void testDeleteByRange() throws RocksDBException { Assert.assertEquals("Lisa", get("person:2gname")); Assert.assertEquals("Hebe", get("person:3gname")); - this.rocks.session().deleteRange(TABLE, b("person:1"), b("person:3")); + this.rocks.session().deleteRange(TABLE, getBytes("person:1"), getBytes("person:3")); this.commit(); Assert.assertEquals(null, get("person:1gname")); @@ -483,15 +484,15 @@ public void testDeleteByRangeWithBytes() throws RocksDBException { Session session = this.rocks.session(); byte[] key11 = new byte[]{1, 1}; - byte[] value11 = b("value-1-1"); + byte[] value11 = getBytes("value-1-1"); session.put(TABLE, key11, value11); byte[] key12 = new byte[]{1, 2}; - byte[] value12 = b("value-1-2"); + byte[] value12 = getBytes("value-1-2"); session.put(TABLE, key12, value12); byte[] key21 = new byte[]{2, 1}; - byte[] value21 = b("value-2-1"); + byte[] value21 = getBytes("value-2-1"); session.put(TABLE, key21, value21); session.deleteRange(TABLE, key11, new byte[]{1, 3}); @@ -507,15 +508,15 @@ public void testDeleteByRangeWithSignedBytes() throws RocksDBException { Session session = this.rocks.session(); byte[] key11 = new byte[]{1, 1}; - byte[] value11 = b("value-1-1"); + byte[] value11 = getBytes("value-1-1"); session.put(TABLE, key11, value11); byte[] key12 = new byte[]{1, -2}; - byte[] value12 = b("value-1-2"); + byte[] value12 = getBytes("value-1-2"); session.put(TABLE, key12, value12); byte[] key21 = new byte[]{2, 1}; - byte[] value21 = b("value-2-1"); + byte[] value21 = getBytes("value-2-1"); session.put(TABLE, key21, value21); session.deleteRange(TABLE, new byte[]{1, -3}, new byte[]{1, 3}); @@ -538,23 +539,23 @@ public void testDeleteByRangeWithMinMaxByteValue() throws RocksDBException { Session session = this.rocks.session(); byte[] key11 = new byte[]{1, 0}; - byte[] value11 = b("value-1-1"); + byte[] value11 = getBytes("value-1-1"); session.put(TABLE, key11, value11); byte[] key12 = new byte[]{1, 127}; - byte[] value12 = b("value-1-2"); + byte[] value12 = getBytes("value-1-2"); session.put(TABLE, key12, value12); byte[] key13 = new byte[]{1, (byte) 0x80}; // 128 - byte[] value13 = b("value-1-3"); + byte[] value13 = getBytes("value-1-3"); session.put(TABLE, key13, value13); byte[] key14 = new byte[]{1, (byte) 0xff}; // 255 - byte[] value14 = b("value-1-4"); + byte[] value14 = getBytes("value-1-4"); session.put(TABLE, key14, value14); byte[] key20 = new byte[]{2, 0}; - byte[] value20 = b("value-2-0"); + byte[] value20 = getBytes("value-2-0"); session.put(TABLE, key20, value20); session.deleteRange(TABLE, @@ -588,14 +589,14 @@ public void testDeleteSingle() throws RocksDBException { Assert.assertEquals("19", get("person:1gage")); // deleteSingle after put once - this.rocks.session().deleteSingle(TABLE, b("person:1gage")); + this.rocks.session().deleteSingle(TABLE, getBytes("person:1gage")); this.commit(); Assert.assertEquals("James2", get("person:1gname")); Assert.assertEquals(null, get("person:1gage")); // deleteSingle after put twice - this.rocks.session().deleteSingle(TABLE, b("person:1gname")); + this.rocks.session().deleteSingle(TABLE, getBytes("person:1gname")); this.commit(); // NOTE: maybe return "James" here @@ -615,7 +616,7 @@ public void testCompact() throws RocksDBException { Assert.assertEquals("19", get("person:1gage")); Assert.assertEquals("Beijing", get("person:1gcity")); - this.rocks.session().delete(TABLE, b("person:1gage")); + this.rocks.session().delete(TABLE, getBytes("person:1gage")); this.commit(); Assert.assertEquals("James", get("person:1gname")); diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/rocksdb/RocksDBSessionsTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/rocksdb/RocksDBSessionsTest.java index a0739905dc..71e497f595 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/rocksdb/RocksDBSessionsTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/rocksdb/RocksDBSessionsTest.java @@ -51,14 +51,14 @@ public void testTable() throws RocksDBException { Assert.assertEquals(ImmutableSet.of(TABLE, TABLE2), this.rocks.openedTables()); - this.rocks.session().put(TABLE, b("person:1gname"), b("James")); - this.rocks.session().put(TABLE2, b("person:1gname"), b("James2")); + this.rocks.session().put(TABLE, getBytes("person:1gname"), getBytes("James")); + this.rocks.session().put(TABLE2, getBytes("person:1gname"), getBytes("James2")); this.commit(); - String value = s(this.rocks.session().get(TABLE, b("person:1gname"))); + String value = getString(this.rocks.session().get(TABLE, getBytes("person:1gname"))); Assert.assertEquals("James", value); - String value2 = s(this.rocks.session().get(TABLE2, b("person:1gname"))); + String value2 = getString(this.rocks.session().get(TABLE2, getBytes("person:1gname"))); Assert.assertEquals("James2", value2); this.rocks.dropTable(TABLE2); @@ -72,8 +72,8 @@ public void testProperty() throws RocksDBException { final String TABLE2 = "test-table2"; this.rocks.createTable(TABLE2); - this.rocks.session().put(TABLE, b("person:1gname"), b("James")); - this.rocks.session().put(TABLE, b("person:2gname"), b("James2")); + this.rocks.session().put(TABLE, getBytes("person:1gname"), getBytes("James")); + this.rocks.session().put(TABLE, getBytes("person:2gname"), getBytes("James2")); this.commit(); Assert.assertEquals(ImmutableList.of("0"), @@ -81,9 +81,9 @@ public void testProperty() throws RocksDBException { Assert.assertEquals(ImmutableList.of("2", "0"), this.rocks.property(RocksDBMetrics.KEY_NUM_KEYS)); - this.rocks.session().put(TABLE2, b("person:1gname"), b("James1")); - this.rocks.session().put(TABLE2, b("person:2gname"), b("James2")); - this.rocks.session().put(TABLE2, b("person:3gname"), b("James3")); + this.rocks.session().put(TABLE2, getBytes("person:1gname"), getBytes("James1")); + this.rocks.session().put(TABLE2, getBytes("person:2gname"), getBytes("James2")); + this.rocks.session().put(TABLE2, getBytes("person:3gname"), getBytes("James3")); this.commit(); Assert.assertEquals(ImmutableList.of("0"), @@ -94,41 +94,41 @@ public void testProperty() throws RocksDBException { @Test public void testCompactRange() throws RocksDBException { - this.rocks.session().put(TABLE, b("person:1gname"), b("James")); - this.rocks.session().put(TABLE, b("person:2gname"), b("James2")); + this.rocks.session().put(TABLE, getBytes("person:1gname"), getBytes("James")); + this.rocks.session().put(TABLE, getBytes("person:2gname"), getBytes("James2")); this.commit(); this.rocks.compactRange(); - String value = s(this.rocks.session().get(TABLE, b("person:1gname"))); + String value = getString(this.rocks.session().get(TABLE, getBytes("person:1gname"))); Assert.assertEquals("James", value); - value = s(this.rocks.session().get(TABLE, b("person:2gname"))); + value = getString(this.rocks.session().get(TABLE, getBytes("person:2gname"))); Assert.assertEquals("James2", value); } @Test public void testSnapshot() throws RocksDBException, IOException { - this.rocks.session().put(TABLE, b("person:1gname"), b("James")); + this.rocks.session().put(TABLE, getBytes("person:1gname"), getBytes("James")); this.rocks.session().commit(); String snapshotPath = SNAPSHOT_PATH + "/rocksdb"; try { this.rocks.createSnapshot(snapshotPath); - byte[] value = this.rocks.session().get(TABLE, b("person:1gname")); - Assert.assertEquals("James", s(value)); + byte[] value = this.rocks.session().get(TABLE, getBytes("person:1gname")); + Assert.assertEquals("James", getString(value)); - this.rocks.session().put(TABLE, b("person:1gname"), b("James2")); + this.rocks.session().put(TABLE, getBytes("person:1gname"), getBytes("James2")); this.rocks.session().commit(); - value = this.rocks.session().get(TABLE, b("person:1gname")); - Assert.assertEquals("James2", s(value)); + value = this.rocks.session().get(TABLE, getBytes("person:1gname")); + Assert.assertEquals("James2", getString(value)); this.rocks.resumeSnapshot(snapshotPath); - value = this.rocks.session().get(TABLE, b("person:1gname")); - Assert.assertEquals("James", s(value)); + value = this.rocks.session().get(TABLE, getBytes("person:1gname")); + Assert.assertEquals("James", getString(value)); } finally { File snapshotFile = FileUtils.getFile(SNAPSHOT_PATH); if (snapshotFile.exists()) { @@ -148,10 +148,10 @@ public void testCopySessions() throws RocksDBException { final String TABLE2 = "test-table2"; copy.createTable(TABLE2); - copy.session().put(TABLE2, b("person:1gname"), b("James")); + copy.session().put(TABLE2, getBytes("person:1gname"), getBytes("James")); copy.session().commit(); - String value = s(copy.session().get(TABLE2, b("person:1gname"))); + String value = getString(copy.session().get(TABLE2, getBytes("person:1gname"))); Assert.assertEquals("James", value); copy.close(); @@ -179,11 +179,11 @@ public void testIngestSst() throws RocksDBException { // Write some data to sst file for (int i = 0; i < 1000; i++) { String k = String.format("%03d", i); - sstSessions.session().put(TABLE1, b("person:" + k), b("James" + i)); + sstSessions.session().put(TABLE1, getBytes("person:" + k), getBytes("James" + i)); } for (int i = 0; i < 2000; i++) { String k = String.format("%04d", i); - sstSessions.session().put(TABLE2, b("book:" + k), b("Java" + i)); + sstSessions.session().put(TABLE2, getBytes("book:" + k), getBytes("Java" + i)); } sstSessions.session().commit(); sstSessions.close(); @@ -200,24 +200,24 @@ public void testIngestSst() throws RocksDBException { rocks.createTable(TABLE1); Assert.assertEquals(ImmutableList.of("1000"), rocks.property(RocksDBMetrics.KEY_NUM_KEYS)); - String value = s(rocks.session().get(TABLE1, b("person:001"))); + String value = getString(rocks.session().get(TABLE1, getBytes("person:001"))); Assert.assertEquals("James1", value); - value = s(rocks.session().get(TABLE1, b("person:010"))); + value = getString(rocks.session().get(TABLE1, getBytes("person:010"))); Assert.assertEquals("James10", value); - value = s(rocks.session().get(TABLE1, b("person:999"))); + value = getString(rocks.session().get(TABLE1, getBytes("person:999"))); Assert.assertEquals("James999", value); // Will ingest sst file of TABLE2 rocks.createTable(TABLE2); Assert.assertEquals(ImmutableList.of("1000", "2000"), rocks.property(RocksDBMetrics.KEY_NUM_KEYS)); - value = s(rocks.session().get(TABLE2, b("book:0001"))); + value = getString(rocks.session().get(TABLE2, getBytes("book:0001"))); Assert.assertEquals("Java1", value); - value = s(rocks.session().get(TABLE2, b("book:0010"))); + value = getString(rocks.session().get(TABLE2, getBytes("book:0010"))); Assert.assertEquals("Java10", value); - value = s(rocks.session().get(TABLE2, b("book:0999"))); + value = getString(rocks.session().get(TABLE2, getBytes("book:0999"))); Assert.assertEquals("Java999", value); - value = s(rocks.session().get(TABLE2, b("book:1999"))); + value = getString(rocks.session().get(TABLE2, getBytes("book:1999"))); Assert.assertEquals("Java1999", value); } } diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/serializer/SerializerFactoryTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/serializer/SerializerFactoryTest.java index dec6fb9bc5..4889af4a30 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/serializer/SerializerFactoryTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/serializer/SerializerFactoryTest.java @@ -86,7 +86,7 @@ public void testRegister() { public static class FakeSerializer extends BinarySerializer { - public FakeSerializer(HugeConfig config){ + public FakeSerializer(HugeConfig config) { super(config); } diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/util/RateLimiterTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/util/RateLimiterTest.java index 3a14d41e30..d4d63e4372 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/util/RateLimiterTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/util/RateLimiterTest.java @@ -74,7 +74,7 @@ public static class FixedTimerWindowRateLimiterTest extends @Override public RateLimiter newRateLimiter(int rate) { - return new FixedTimerWindowRateLimiter(rate) ; + return new FixedTimerWindowRateLimiter(rate); } @Test @@ -146,7 +146,6 @@ public void testTryAcquireAfterPeriod() throws Exception { Assert.assertEquals(1, count.intValue()); } - @Test public void testStopWatchRateLimiterWithIdle() throws Exception { int rateLimit = 100; diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/util/collection/IdSetTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/util/collection/IdSetTest.java index 0275070c62..7c52a6230e 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/util/collection/IdSetTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/util/collection/IdSetTest.java @@ -103,7 +103,6 @@ public void testIdSetWithOnlyUUIDId() { } } - @Test public void testIdSetWithOnlyStringId() { Set strings = new HashSet<>(); diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/util/collection/Int2IntsMapTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/util/collection/Int2IntsMapTest.java index 7e250b9bf9..a94f0483f4 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/util/collection/Int2IntsMapTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/util/collection/Int2IntsMapTest.java @@ -82,6 +82,8 @@ public void testInt2IntsMap() { map.add(5, m++); } break; + default: + break; } } diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/util/collection/IntMapTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/util/collection/IntMapTest.java index 9d7fc8112d..c195bc3da5 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/util/collection/IntMapTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/util/collection/IntMapTest.java @@ -48,24 +48,24 @@ public void teardown() throws Exception { } static final int THREADS_NUM = 4; - static final int batchCount = 2000; - static final int eachCount = 10000; + static final int BATCH_COUNT = 2000; + static final int EACH_COUNT = 10000; @Test public void testIntFixedMap() { - IntMap map = fixed(eachCount); + IntMap map = fixed(EACH_COUNT); testIntMap(map); } @Test public void testIntFixedMapBySegments() { - IntMap map = fixedBySegments(eachCount, 4); + IntMap map = fixedBySegments(EACH_COUNT, 4); testIntMap(map); - IntMap map2 = fixedBySegments(eachCount, 400); + IntMap map2 = fixedBySegments(EACH_COUNT, 400); testIntMap(map2); - IntMap map3 = fixedBySegments(eachCount, 4000); + IntMap map3 = fixedBySegments(EACH_COUNT, 4000); testIntMap(map3); } @@ -78,16 +78,16 @@ private void testIntMap(IntMap map) { int modUpdate = 1 + new Random().nextInt(100); Random random = new Random(); - for (int k = 0; k < eachCount; k++) { - if(k % modUpdate == 0) { - int v = random.nextInt(eachCount); + for (int k = 0; k < EACH_COUNT; k++) { + if (k % modUpdate == 0) { + int v = random.nextInt(EACH_COUNT); map.put(k, v); jucMap.put(k, v); } } Assert.assertEquals(jucMap.size(), map.size()); - for (int k = 0; k < eachCount; k++) { + for (int k = 0; k < EACH_COUNT; k++) { if (jucMap.containsKey(k)) { Assert.assertTrue("expect " + k, map.containsKey(k)); Assert.assertEquals((int) jucMap.get(k), map.get(k)); @@ -96,28 +96,28 @@ private void testIntMap(IntMap map) { } } - for (int k = 0; k < eachCount; k++) { - int v = random.nextInt(eachCount); + for (int k = 0; k < EACH_COUNT; k++) { + int v = random.nextInt(EACH_COUNT); map.put(k, v); jucMap.put(k, v); } - Assert.assertEquals(eachCount, map.size()); - for (int k = 0; k < eachCount; k++) { + Assert.assertEquals(EACH_COUNT, map.size()); + for (int k = 0; k < EACH_COUNT; k++) { Assert.assertTrue("expect " + k, map.containsKey(k)); Assert.assertEquals((int) jucMap.get(k), map.get(k)); } int modRemove = 1 + new Random().nextInt(100); - for (int k = 0; k < eachCount; k++) { - if(k % modRemove == 0) { + for (int k = 0; k < EACH_COUNT; k++) { + if (k % modRemove == 0) { map.remove(k); jucMap.remove(k); } } Assert.assertEquals(jucMap.size(), map.size()); - for (int k = 0; k < eachCount; k++) { + for (int k = 0; k < EACH_COUNT; k++) { if (jucMap.containsKey(k)) { Assert.assertTrue("expect " + k, map.containsKey(k)); Assert.assertEquals((int) jucMap.get(k), map.get(k)); @@ -126,7 +126,7 @@ private void testIntMap(IntMap map) { } } - int outOfBoundKey = eachCount; + int outOfBoundKey = EACH_COUNT; Assert.assertFalse(map.containsKey(outOfBoundKey)); @@ -144,18 +144,18 @@ private void testIntMap(IntMap map) { map.clear(); Assert.assertEquals(0, map.size()); - for (int k = 0; k < eachCount; k++) { + for (int k = 0; k < EACH_COUNT; k++) { Assert.assertFalse("unexpect " + k, map.containsKey(k)); } } @Test public void testIntFixedMapConcurrent() { - IntMap map = fixed(eachCount); + IntMap map = fixed(EACH_COUNT); runWithThreads(THREADS_NUM, () -> { - for (int i = 0; i < batchCount; i++) { - for (int k = 0; k < eachCount; k++) { + for (int i = 0; i < BATCH_COUNT; i++) { + for (int k = 0; k < EACH_COUNT; k++) { map.containsKey(k); map.put(k, k); } @@ -163,19 +163,19 @@ public void testIntFixedMapConcurrent() { } }); - Assert.assertEquals(eachCount, map.size()); - for (int k = 0; k < eachCount; k++) { + Assert.assertEquals(EACH_COUNT, map.size()); + for (int k = 0; k < EACH_COUNT; k++) { Assert.assertTrue("expect " + k, map.containsKey(k)); } } @Test public void testIntFixedMapBySegmentsConcurrent() { - IntMap map = fixedBySegments(eachCount, 4); + IntMap map = fixedBySegments(EACH_COUNT, 4); runWithThreads(THREADS_NUM, () -> { - for (int i = 0; i < batchCount; i++) { - for (int k = 0; k < eachCount; k++) { + for (int i = 0; i < BATCH_COUNT; i++) { + for (int k = 0; k < EACH_COUNT; k++) { map.containsKey(k); map.put(k, k); } @@ -183,8 +183,8 @@ public void testIntFixedMapBySegmentsConcurrent() { } }); - Assert.assertEquals(eachCount, map.size()); - for (int k = 0; k < eachCount; k++) { + Assert.assertEquals(EACH_COUNT, map.size()); + for (int k = 0; k < EACH_COUNT; k++) { Assert.assertTrue("expect " + k, map.containsKey(k)); } } diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/util/collection/IntSetTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/util/collection/IntSetTest.java index 4bb15b40c0..ceb05d4278 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/util/collection/IntSetTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/unit/util/collection/IntSetTest.java @@ -44,25 +44,25 @@ public void teardown() throws Exception { } static final int THREADS_NUM = 4; - static final int batchCount = 2000; - static final int eachCount = 10000; + static final int BATCH_COUNT = 2000; + static final int EACH_COUNT = 10000; @Test public void testIntFixedSet() { - IntSet set = fixed(eachCount); + IntSet set = fixed(EACH_COUNT); testIntSet(set); } @Test public void testIntFixedSetBySegments() { - IntSet set = fixedBySegments(eachCount, 4); + IntSet set = fixedBySegments(EACH_COUNT, 4); testIntSet(set); - set = fixedBySegments(eachCount, 400); + set = fixedBySegments(EACH_COUNT, 400); testIntSet(set); Assert.assertThrows(IllegalArgumentException.class, () -> { - fixedBySegments(eachCount, eachCount + 1); + fixedBySegments(EACH_COUNT, EACH_COUNT + 1); }, e -> { Assert.assertContains("Invalid capacity", e.getMessage()); }); @@ -70,7 +70,7 @@ public void testIntFixedSetBySegments() { @Test public void testIntFixedSetConcurrent() { - IntSet set = fixed(eachCount); + IntSet set = fixed(EACH_COUNT); testIntSetConcurrent(set); } @@ -87,10 +87,10 @@ private void testIntSet(IntSet set) { Assert.assertTrue(set.concurrent()); int mod = 1 + new Random().nextInt(100); - for (int i = 0; i < batchCount; i++) { - for (int k = 0; k < eachCount; k++) { + for (int i = 0; i < BATCH_COUNT; i++) { + for (int k = 0; k < EACH_COUNT; k++) { set.contains(k); - if(k % mod == 0) { + if (k % mod == 0) { set.add(k); jucSet.add(k); } @@ -104,9 +104,9 @@ private void testIntSet(IntSet set) { Assert.assertTrue("expect " + k, exist); } - for (int k = 0; k < eachCount; k++) { + for (int k = 0; k < EACH_COUNT; k++) { boolean exist = set.contains(k); - if(k % mod == 0) { + if (k % mod == 0) { Assert.assertTrue("expect " + k, exist); } else { Assert.assertFalse("unexpect " + k, exist); @@ -114,9 +114,9 @@ private void testIntSet(IntSet set) { } int count = set.size(); - for (int k = 0; k < eachCount; k++) { + for (int k = 0; k < EACH_COUNT; k++) { boolean exist = set.contains(k); - if(k % mod == 0) { + if (k % mod == 0) { Assert.assertTrue("expect " + k, exist); Assert.assertFalse(set.add(k)); @@ -133,7 +133,7 @@ private void testIntSet(IntSet set) { } } - int outOfBoundKey = eachCount; + int outOfBoundKey = EACH_COUNT; Assert.assertFalse(set.contains(outOfBoundKey)); @@ -151,7 +151,7 @@ private void testIntSet(IntSet set) { set.clear(); Assert.assertEquals(0, set.size()); - for (int k = 0; k < eachCount; k++) { + for (int k = 0; k < EACH_COUNT; k++) { boolean exist = set.contains(k); Assert.assertFalse("unexpect " + k, exist); } @@ -159,8 +159,8 @@ private void testIntSet(IntSet set) { private void testIntSetConcurrent(IntSet set) { runWithThreads(THREADS_NUM, () -> { - for (int i = 0; i < batchCount; i++) { - for (int k = 0; k < eachCount; k++) { + for (int i = 0; i < BATCH_COUNT; i++) { + for (int k = 0; k < EACH_COUNT; k++) { set.contains(k); set.add(k); } @@ -169,8 +169,8 @@ private void testIntSetConcurrent(IntSet set) { } }); - Assert.assertEquals(eachCount, set.size()); - for (int k = 0; k < eachCount; k++) { + Assert.assertEquals(EACH_COUNT, set.size()); + for (int k = 0; k < EACH_COUNT; k++) { Assert.assertTrue("expect " + k, set.contains(k)); } }