diff --git a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/auth/LoginAPI.java b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/auth/LoginAPI.java index a227fd0b50..0982e01c1e 100644 --- a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/auth/LoginAPI.java +++ b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/auth/LoginAPI.java @@ -17,39 +17,40 @@ package org.apache.hugegraph.api.auth; -import io.swagger.v3.oas.annotations.tags.Tag; -import jakarta.inject.Singleton; import javax.security.sasl.AuthenticationException; -import jakarta.ws.rs.BadRequestException; -import jakarta.ws.rs.Consumes; -import jakarta.ws.rs.DELETE; -import jakarta.ws.rs.GET; -import jakarta.ws.rs.HeaderParam; -import jakarta.ws.rs.NotAuthorizedException; -import jakarta.ws.rs.POST; -import jakarta.ws.rs.Path; -import jakarta.ws.rs.PathParam; -import jakarta.ws.rs.Produces; -import jakarta.ws.rs.core.Context; -import jakarta.ws.rs.core.HttpHeaders; import org.apache.commons.lang3.StringUtils; -import org.apache.hugegraph.core.GraphManager; -import org.apache.hugegraph.define.Checkable; -import org.slf4j.Logger; - import org.apache.hugegraph.HugeGraph; import org.apache.hugegraph.api.API; import org.apache.hugegraph.api.filter.AuthenticationFilter; import org.apache.hugegraph.api.filter.StatusFilter.Status; import org.apache.hugegraph.auth.AuthConstant; import org.apache.hugegraph.auth.UserWithRole; +import org.apache.hugegraph.core.GraphManager; +import org.apache.hugegraph.define.Checkable; import org.apache.hugegraph.util.E; import org.apache.hugegraph.util.Log; +import org.slf4j.Logger; + import com.codahale.metrics.annotation.Timed; import com.fasterxml.jackson.annotation.JsonProperty; import com.google.common.collect.ImmutableMap; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.inject.Singleton; +import jakarta.ws.rs.BadRequestException; +import jakarta.ws.rs.Consumes; +import jakarta.ws.rs.DELETE; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.HeaderParam; +import jakarta.ws.rs.NotAuthorizedException; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.PathParam; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.Context; +import jakarta.ws.rs.core.HttpHeaders; + @Path("graphs/{graph}/auth") @Singleton @Tag(name = "LoginAPI") @@ -63,8 +64,7 @@ public class LoginAPI extends API { @Status(Status.OK) @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON_WITH_CHARSET) - public String login(@Context GraphManager manager, - @PathParam("graph") String graph, + public String login(@Context GraphManager manager, @PathParam("graph") String graph, JsonLogin jsonLogin) { LOG.debug("Graph [{}] user login: {}", graph, jsonLogin); checkCreatingBody(jsonLogin); @@ -94,13 +94,10 @@ public void logout(@Context GraphManager manager, LOG.debug("Graph [{}] user logout: {}", graph, auth); if (!auth.startsWith(AuthenticationFilter.BEARER_TOKEN_PREFIX)) { - throw new BadRequestException( - "Only HTTP Bearer authentication is supported"); + throw new BadRequestException("Only HTTP Bearer authentication is supported"); } - String token = auth.substring(AuthenticationFilter.BEARER_TOKEN_PREFIX - .length()); - + String token = auth.substring(AuthenticationFilter.BEARER_TOKEN_PREFIX.length()); manager.authManager().logoutUser(token); } @@ -119,12 +116,10 @@ public String verifyToken(@Context GraphManager manager, LOG.debug("Graph [{}] get user: {}", graph, token); if (!token.startsWith(AuthenticationFilter.BEARER_TOKEN_PREFIX)) { - throw new BadRequestException( - "Only HTTP Bearer authentication is supported"); + throw new BadRequestException("Only HTTP Bearer authentication is supported"); } - token = token.substring(AuthenticationFilter.BEARER_TOKEN_PREFIX - .length()); + token = token.substring(AuthenticationFilter.BEARER_TOKEN_PREFIX.length()); UserWithRole userWithRole = manager.authManager().validateUser(token); HugeGraph g = graph(manager, graph); @@ -144,8 +139,7 @@ private static class JsonLogin implements Checkable { @Override public void checkCreate(boolean isBatch) { - E.checkArgument(!StringUtils.isEmpty(this.name), - "The name of user can't be null"); + E.checkArgument(!StringUtils.isEmpty(this.name), "The name of user can't be null"); E.checkArgument(!StringUtils.isEmpty(this.password), "The password of user can't be null"); } diff --git a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphTransaction.java b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphTransaction.java index 0574318d74..3607129a6c 100644 --- a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphTransaction.java +++ b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphTransaction.java @@ -1712,7 +1712,7 @@ private Iterator filterUnmatchedRecords( Iterator results, Query query) { // Filter unused or incorrect records - return new FilterIterator(results, elem -> { + return new FilterIterator<>(results, elem -> { // TODO: Left vertex/edge should to be auto removed via async task if (elem.schemaLabel().undefined()) { LOG.warn("Left record is found: id={}, label={}, properties={}", @@ -1861,7 +1861,7 @@ private Iterator joinTxEdges(Query query, Iterator edges, return edges; } // Filter edges that belong to deleted vertex - return new FilterIterator(edges, edge -> { + return new FilterIterator<>(edges, edge -> { for (HugeVertex v : removingVertices.values()) { if (edge.belongToVertex(v)) { return false; @@ -1917,7 +1917,7 @@ private Iterator joinTxRecords( !removedTxRecords.containsKey(id); }); - return new ExtendableIterator(txResults.iterator(), backendResults); + return new ExtendableIterator<>(txResults.iterator(), backendResults); } private void checkTxVerticesCapacity() throws LimitExceedException { diff --git a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/structure/HugeEdgeProperty.java b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/structure/HugeEdgeProperty.java index 3f1f021535..787c66f448 100644 --- a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/structure/HugeEdgeProperty.java +++ b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/structure/HugeEdgeProperty.java @@ -20,11 +20,10 @@ import org.apache.hugegraph.schema.EdgeLabel; import org.apache.hugegraph.schema.PropertyKey; import org.apache.hugegraph.type.HugeType; +import org.apache.hugegraph.util.E; import org.apache.tinkerpop.gremlin.structure.Property; import org.apache.tinkerpop.gremlin.structure.util.ElementHelper; -import org.apache.hugegraph.util.E; - public class HugeEdgeProperty extends HugeProperty { public HugeEdgeProperty(HugeElement owner, PropertyKey key, V value) { @@ -67,7 +66,7 @@ public int hashCode() { public HugeEdgeProperty switchEdgeOwner() { assert this.owner instanceof HugeEdge; - return new HugeEdgeProperty(((HugeEdge) this.owner).switchOwner(), - this.pkey, this.value); + return new HugeEdgeProperty<>(((HugeEdge) this.owner).switchOwner(), + this.pkey, this.value); } } diff --git a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/HugePrimaryKeyStrategy.java b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/HugePrimaryKeyStrategy.java index e00e4caf80..d9f6654a52 100644 --- a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/HugePrimaryKeyStrategy.java +++ b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/HugePrimaryKeyStrategy.java @@ -17,21 +17,21 @@ package org.apache.hugegraph.traversal.optimize; +import java.util.LinkedList; +import java.util.List; + import org.apache.tinkerpop.gremlin.process.traversal.Step; import org.apache.tinkerpop.gremlin.process.traversal.Traversal; import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy; import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy.ProviderOptimizationStrategy; import org.apache.tinkerpop.gremlin.process.traversal.step.Mutating; import org.apache.tinkerpop.gremlin.process.traversal.step.map.AddVertexStartStep; +import org.apache.tinkerpop.gremlin.process.traversal.step.map.AddVertexStep; import org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.AddPropertyStep; import org.apache.tinkerpop.gremlin.process.traversal.strategy.AbstractTraversalStrategy; import org.apache.tinkerpop.gremlin.structure.T; -import org.apache.tinkerpop.gremlin.process.traversal.step.map.AddVertexStep; import org.apache.tinkerpop.gremlin.structure.VertexProperty.Cardinality; -import java.util.LinkedList; -import java.util.List; - public class HugePrimaryKeyStrategy extends AbstractTraversalStrategy implements ProviderOptimizationStrategy { @@ -53,17 +53,19 @@ public void apply(Traversal.Admin traversal) { for (int i = 0, s = stepList.size(); i < s; i++) { Step step = stepList.get(i); - if (i == 0 && AddVertexStartStep.class.isInstance(step)) { + if (i == 0 && step instanceof AddVertexStartStep) { curAddStep = (Mutating) step; continue; - } else if (curAddStep == null && AddVertexStep.class.isInstance((step))) { + } else if (curAddStep == null && (step) instanceof AddVertexStep) { curAddStep = (Mutating) step; continue; } - if (curAddStep == null) continue; + if (curAddStep == null) { + continue; + } - if (!AddPropertyStep.class.isInstance(step)) { + if (!(step instanceof AddPropertyStep)) { curAddStep = null; continue; } @@ -89,8 +91,8 @@ public void apply(Traversal.Admin traversal) { curAddStep.configure(kvs); - if (kvList.size() > 0) { - curAddStep.configure(kvList.toArray(new Object[kvList.size()])); + if (!kvList.isEmpty()) { + curAddStep.configure(kvList.toArray(new Object[0])); } removeSteps.add(step); diff --git a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/type/define/CollectionType.java b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/type/define/CollectionType.java index 3de1c850a6..3b011a0ba1 100644 --- a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/type/define/CollectionType.java +++ b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/type/define/CollectionType.java @@ -41,6 +41,7 @@ public enum CollectionType implements SerialEnum { this.name = name; } + @Override public byte code() { return this.code; } diff --git a/hugegraph-server/hugegraph-example/src/main/java/org/apache/hugegraph/example/PerfExampleBase.java b/hugegraph-server/hugegraph-example/src/main/java/org/apache/hugegraph/example/PerfExampleBase.java index dfd72a763f..b5ec0506f4 100644 --- a/hugegraph-server/hugegraph-example/src/main/java/org/apache/hugegraph/example/PerfExampleBase.java +++ b/hugegraph-server/hugegraph-example/src/main/java/org/apache/hugegraph/example/PerfExampleBase.java @@ -26,12 +26,6 @@ import java.util.concurrent.CyclicBarrier; import java.util.function.Consumer; -import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; -import org.apache.tinkerpop.gremlin.structure.Edge; -import org.apache.tinkerpop.gremlin.structure.Transaction; -import org.apache.tinkerpop.gremlin.structure.Vertex; -import org.slf4j.Logger; - import org.apache.hugegraph.HugeGraph; import org.apache.hugegraph.backend.cache.Cache; import org.apache.hugegraph.backend.cache.CacheManager; @@ -45,6 +39,11 @@ import org.apache.hugegraph.type.define.Directions; import org.apache.hugegraph.type.define.HugeKeys; import org.apache.hugegraph.util.Log; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.structure.Edge; +import org.apache.tinkerpop.gremlin.structure.Transaction; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.slf4j.Logger; public abstract class PerfExampleBase { @@ -54,8 +53,7 @@ public abstract class PerfExampleBase { protected static final Logger LOG = Log.logger(PerfExampleBase.class); - protected Set vertices = Collections.newSetFromMap( - new ConcurrentHashMap()); + protected Set vertices = Collections.newSetFromMap(new ConcurrentHashMap<>()); protected boolean profile = false; public int test(String[] args) throws Exception { @@ -69,8 +67,8 @@ public int test(String[] args) throws Exception { int multiple = Integer.parseInt(args[2]); this.profile = Boolean.parseBoolean(args[3]); - // NOTE: this test with HugeGraph is for local, change it into - // client if test with restful server from remote + // NOTE: this test with HugeGraph is for local, + // change it into a client if test with restful server from remote HugeGraph hugegraph = ExampleUtil.loadGraph(true, this.profile); GraphManager graph = new GraphManager(hugegraph); @@ -88,24 +86,19 @@ public int test(String[] args) throws Exception { /** * Multi-threaded and multi-commits and batch insertion test - * @param graph graph - * @param threadCount - * The count of threads that perform the insert operation at the - * same time - * @param times - * The transaction commit times for each thread - * @param multiple - * The coefficient to multiple number of vertices(100) and edges(100) - * for each transaction commit - * @throws Exception execute may throw Exception + * + * @param graph graph + * @param threadCount The count of threads that perform the insert operation at the + * same time + * @param times The transaction commit times for each thread + * @param multiple The coefficient to multiple number of vertices(100) and edges(100) + * for each transaction commit + * @throws Exception execute may throw Exception */ - public void testInsertPerf(GraphManager graph, - int threadCount, - int times, - int multiple) - throws Exception { + public void testInsertPerf(GraphManager graph, int threadCount, int times, int multiple) + throws Exception { // Total vertices/edges - long n = threadCount * times * multiple; + long n = (long) threadCount * times * multiple; long vertices = (PERSON_NUM + SOFTWARE_NUM) * n; long edges = EDGE_NUM * n; @@ -115,37 +108,29 @@ public void testInsertPerf(GraphManager graph, LOG.info("Insert rate with threads: {} vertices/s & {} edges/s, " + "insert total {} vertices & {} edges, cost time: {}ms", - vertices * 1000 / cost, edges * 1000 / cost, - vertices, edges, cost); - + vertices * 1000 / cost, edges * 1000 / cost, vertices, edges, cost); graph.clearVertexCache(); } - public void testQueryVertexPerf(GraphManager graph, - int threadCount, - int times, - int multiple) - throws Exception { + public void testQueryVertexPerf(GraphManager graph, int threadCount, int times, int multiple) + throws Exception { long cost = this.execute(graph, i -> { this.testQueryVertex(graph, threadCount, i, multiple); }, threadCount); - final long size = (PERSON_NUM + SOFTWARE_NUM) * threadCount * times; + final long size = (long) (PERSON_NUM + SOFTWARE_NUM) * threadCount * times; LOG.info("Query rate with threads: {} vertices/s, " + "query total vertices {}, cost time: {}ms", size * 1000 / cost, size, cost); } - public void testQueryEdgePerf(GraphManager graph, - int threadCount, - int times, - int multiple) - throws Exception { + public void testQueryEdgePerf(GraphManager graph, int threadCount, int times, int multiple) + throws Exception { long cost = this.execute(graph, i -> { this.testQueryEdge(graph, threadCount, i, multiple); }, threadCount); - final long size = (PERSON_NUM + SOFTWARE_NUM) * threadCount * times; + final long size = (long) (PERSON_NUM + SOFTWARE_NUM) * threadCount * times; LOG.info("Query rate with threads: {} vedges/s, " + "query total vedges {}, cost time: {}ms", size * 1000 / cost, size, cost); @@ -153,8 +138,8 @@ public void testQueryEdgePerf(GraphManager graph, protected long execute(GraphManager graph, Consumer task, int threadCount) throws Exception { - CyclicBarrier startBarrier = new CyclicBarrier(threadCount + 1); - CyclicBarrier endBarrier = new CyclicBarrier(threadCount + 1); + CyclicBarrier startBarrier = new CyclicBarrier(threadCount + 1); + CyclicBarrier endBarrier = new CyclicBarrier(threadCount + 1); List threads = new ArrayList<>(threadCount); for (int i = 0; i < threadCount; i++) { int j = i; @@ -201,14 +186,9 @@ protected long execute(GraphManager graph, Consumer task, protected abstract void initSchema(SchemaManager schema); - protected abstract void testInsert(GraphManager graph, - int times, - int multiple); + protected abstract void testInsert(GraphManager graph, int times, int multiple); - protected void testQueryVertex(GraphManager graph, - int threads, - int thread, - int multiple) { + protected void testQueryVertex(GraphManager graph, int threads, int thread, int multiple) { int i = 0; int j = 0; int total = 0; @@ -230,10 +210,7 @@ protected void testQueryVertex(GraphManager graph, LOG.debug("Query vertices with thread({}): {}", thread, total); } - protected void testQueryEdge(GraphManager graph, - int threads, - int thread, - int multiple) { + protected void testQueryEdge(GraphManager graph, int threads, int thread, int multiple) { int i = 0; int j = 0; int totalV = 0; @@ -259,9 +236,8 @@ protected void testQueryEdge(GraphManager graph, } protected static class GraphManager { - private HugeGraph hugegraph; - private Cache cache = CacheManager.instance() - .cache("perf-test"); + private final HugeGraph hugegraph; + private final Cache cache = CacheManager.instance().cache("perf-test"); public GraphManager(HugeGraph hugegraph) { this.hugegraph = hugegraph; @@ -269,13 +245,11 @@ public GraphManager(HugeGraph hugegraph) { public void initEnv() { // Cost about 6s - Whitebox.invoke(this.hugegraph.getClass(), - "graphTransaction", this.hugegraph); + Whitebox.invoke(this.hugegraph.getClass(), "graphTransaction", this.hugegraph); } public void destroyEnv() { - Whitebox.invoke(this.hugegraph.getClass(), - "closeTx", this.hugegraph); + Whitebox.invoke(this.hugegraph.getClass(), "closeTx", this.hugegraph); } public Transaction tx() { diff --git a/hugegraph-server/hugegraph-mysql/src/main/java/org/apache/hugegraph/backend/store/mysql/ResultSetWrapper.java b/hugegraph-server/hugegraph-mysql/src/main/java/org/apache/hugegraph/backend/store/mysql/ResultSetWrapper.java index eb98a1150a..6d4a2f0e49 100644 --- a/hugegraph-server/hugegraph-mysql/src/main/java/org/apache/hugegraph/backend/store/mysql/ResultSetWrapper.java +++ b/hugegraph-server/hugegraph-mysql/src/main/java/org/apache/hugegraph/backend/store/mysql/ResultSetWrapper.java @@ -17,12 +17,12 @@ package org.apache.hugegraph.backend.store.mysql; -import org.apache.hugegraph.backend.BackendException; - import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; +import org.apache.hugegraph.backend.BackendException; + public class ResultSetWrapper implements AutoCloseable { private final ResultSet resultSet; @@ -37,6 +37,7 @@ public boolean next() throws SQLException { return !this.resultSet.isClosed() && this.resultSet.next(); } + @Override public void close() { try { if (this.resultSet != null) { diff --git a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/ApiTestSuite.java b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/ApiTestSuite.java index 26e00e227a..0eed3e7049 100644 --- a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/ApiTestSuite.java +++ b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/ApiTestSuite.java @@ -18,12 +18,11 @@ package org.apache.hugegraph.api; import org.apache.hugegraph.api.traversers.TraversersApiTestSuite; +import org.apache.hugegraph.dist.RegisterUtil; import org.junit.BeforeClass; import org.junit.runner.RunWith; import org.junit.runners.Suite; -import org.apache.hugegraph.dist.RegisterUtil; - @RunWith(Suite.class) @Suite.SuiteClasses({ PropertyKeyApiTest.class, diff --git a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/ArthasApiTest.java b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/ArthasApiTest.java index 174b665fea..c73276b38d 100644 --- a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/ArthasApiTest.java +++ b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/ArthasApiTest.java @@ -46,8 +46,9 @@ public void testArthasApi() { " \"execTimeout\": \"10000\"\n" + "}"; RestClient arthasApiClient = new RestClient(ARTHAS_API_BASE_URL, false); - // If request header contains basic auth, and if we are not set auth when arthas attach hg, - // arthas will auth it and return 401. ref:https://arthas.aliyun.com/en/doc/auth.html#configure-username-and-password + // If the request header contains basic auth, + // and if we are not set auth when arthas attach hg, arthas will auth it and return 401. + // ref:https://arthas.aliyun.com/en/doc/auth.html#configure-username-and-password Response r = arthasApiClient.post(ARTHAS_API_PATH, body); String result = assertResponseStatus(200, r); assertJsonContains(result, "state"); diff --git a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/BaseApiTest.java b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/BaseApiTest.java index 24b19ba1ea..a964a7236d 100644 --- a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/BaseApiTest.java +++ b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/BaseApiTest.java @@ -139,8 +139,7 @@ public Response get(String path, String id) { return this.target.path(path).path(id).request().get(); } - public Response get(String path, - MultivaluedMap headers) { + public Response get(String path, MultivaluedMap headers) { return this.target.path(path).request().headers(headers).get(); } diff --git a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/EdgeApiTest.java b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/EdgeApiTest.java index 98390fc0ab..b55896f564 100644 --- a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/EdgeApiTest.java +++ b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/EdgeApiTest.java @@ -19,17 +19,17 @@ import java.io.IOException; +import org.apache.hugegraph.testutil.Assert; import org.junit.Before; import org.junit.Test; -import org.apache.hugegraph.testutil.Assert; import com.google.common.collect.ImmutableMap; import jakarta.ws.rs.core.Response; public class EdgeApiTest extends BaseApiTest { - private static String path = "/graphs/hugegraph/graph/edges/"; + private static final String PATH = "/graphs/hugegraph/graph/edges/"; @Before public void prepareSchema() { @@ -54,7 +54,7 @@ public void testCreate() throws IOException { "\"date\": \"20170324\"," + "\"weight\": 0.5}" + "}", outVId, inVId); - Response r = client().post(path, edge); + Response r = client().post(PATH, edge); assertResponseStatus(201, r); } @@ -73,7 +73,7 @@ public void testBatchUpdate() throws IOException { "\"date\": \"2013-02-20\"," + "\"weight\": 1.0}" + "}", outVId, inVId); - Response r = client().post(path, edge); + 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); @@ -101,7 +101,7 @@ public void testBatchUpdate() throws IOException { "\"check_vertex\":false," + "\"create_if_not_exist\":true" + "}", edgeId, outVId, inVId); - r = client().put(path, "batch", edge, ImmutableMap.of()); + r = client().put(PATH, "batch", edge, ImmutableMap.of()); // Now allowed to modify sortkey values, the property 'date' has changed content = assertResponseStatus(400, r); Assert.assertTrue(content.contains( @@ -130,7 +130,7 @@ public void testBatchUpdate() throws IOException { "\"check_vertex\":false," + "\"create_if_not_exist\":true" + "}", outVId, inVId); - r = client().put(path, "batch", edge, ImmutableMap.of()); + r = client().put(PATH, "batch", edge, ImmutableMap.of()); // Add a new edge when sortkey value has changed content = assertResponseStatus(200, r); String newEdgeId = parseId(content); @@ -152,11 +152,11 @@ public void testGet() throws IOException { "\"date\": \"20170324\"," + "\"weight\": 0.5}" + "}", outVId, inVId); - Response r = client().post(path, edge); + Response r = client().post(PATH, edge); String content = assertResponseStatus(201, r); String id = parseId(content); - r = client().get(path, id); + r = client().get(PATH, id); assertResponseStatus(200, r); } @@ -175,10 +175,10 @@ public void testList() throws IOException { "\"date\": \"20170324\"," + "\"weight\": 0.5}" + "}", outVId, inVId); - Response r = client().post(path, edge); + Response r = client().post(PATH, edge); assertResponseStatus(201, r); - r = client().get(path); + r = client().get(PATH); assertResponseStatus(200, r); } @@ -197,11 +197,11 @@ public void testDelete() throws IOException { "\"date\": \"20170324\"," + "\"weight\": 0.5}" + "}", outVId, inVId); - Response r = client().post(path, edge); + Response r = client().post(PATH, edge); String content = assertResponseStatus(201, r); String id = parseId(content); - r = client().delete(path, id); + r = client().delete(PATH, id); assertResponseStatus(204, r); } } diff --git a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/EdgeLabelApiTest.java b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/EdgeLabelApiTest.java index b03a435086..2cd1b5ede4 100644 --- a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/EdgeLabelApiTest.java +++ b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/EdgeLabelApiTest.java @@ -19,15 +19,16 @@ import java.util.Map; -import jakarta.ws.rs.core.Response; import org.junit.Before; import org.junit.Test; import com.google.common.collect.ImmutableMap; +import jakarta.ws.rs.core.Response; + public class EdgeLabelApiTest extends BaseApiTest { - private static String path = "/graphs/hugegraph/schema/edgelabels/"; + private static final String PATH = "/graphs/hugegraph/schema/edgelabels/"; @Before public void prepareSchema() { @@ -46,7 +47,7 @@ public void testCreate() { "\"nullable_keys\":[\"city\"]," + "\"sort_keys\":[]" + "}"; - Response r = client().post(path, edgeLabel); + Response r = client().post(PATH, edgeLabel); assertResponseStatus(201, r); } @@ -61,7 +62,7 @@ public void testAppend() { "\"nullable_keys\":[\"city\"]," + "\"sort_keys\":[]" + "}"; - Response r = client().post(path, edgeLabel); + Response r = client().post(PATH, edgeLabel); assertResponseStatus(201, r); edgeLabel = "{" + @@ -74,7 +75,7 @@ public void testAppend() { "\"sort_keys\":[]" + "}"; Map params = ImmutableMap.of("action", "append"); - r = client().put(path, "created", edgeLabel, params); + r = client().put(PATH, "created", edgeLabel, params); assertResponseStatus(200, r); } @@ -89,11 +90,11 @@ public void testGet() { "\"nullable_keys\":[\"city\"]," + "\"sort_keys\":[]" + "}"; - Response r = client().post(path, edgeLabel); + Response r = client().post(PATH, edgeLabel); assertResponseStatus(201, r); String name = "created"; - r = client().get(path, name); + r = client().get(PATH, name); assertResponseStatus(200, r); } @@ -108,10 +109,10 @@ public void testList() { "\"nullable_keys\":[\"city\"]," + "\"sort_keys\":[]" + "}"; - Response r = client().post(path, edgeLabel); + Response r = client().post(PATH, edgeLabel); assertResponseStatus(201, r); - r = client().get(path); + r = client().get(PATH); assertResponseStatus(200, r); } @@ -126,11 +127,11 @@ public void testDelete() { "\"nullable_keys\":[\"city\"]," + "\"sort_keys\":[]" + "}"; - Response r = client().post(path, edgeLabel); + Response r = client().post(PATH, edgeLabel); assertResponseStatus(201, r); String name = "created"; - r = client().delete(path, name); + r = client().delete(PATH, name); String content = assertResponseStatus(202, r); int task = assertJsonContains(content, "task_id"); waitTaskSuccess(task); diff --git a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/IndexLabelApiTest.java b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/IndexLabelApiTest.java index 68920c177d..b3eb89eb14 100644 --- a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/IndexLabelApiTest.java +++ b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/IndexLabelApiTest.java @@ -19,15 +19,16 @@ import java.util.Map; -import jakarta.ws.rs.core.Response; import org.junit.Before; import org.junit.Test; import com.google.common.collect.ImmutableMap; +import jakarta.ws.rs.core.Response; + public class IndexLabelApiTest extends BaseApiTest { - private static String path = "/graphs/hugegraph/schema/indexlabels/"; + private static final String PATH = "/graphs/hugegraph/schema/indexlabels/"; @Before public void prepareSchema() { @@ -45,7 +46,7 @@ public void testCreate() { "\"index_type\": \"RANGE\"," + "\"fields\":[\"age\"]" + "}"; - Response r = client().post(path, indexLabel); + Response r = client().post(PATH, indexLabel); assertResponseStatus(202, r); } @@ -59,7 +60,7 @@ public void testAppend() { "\"fields\":[\"age\"]" + "}"; - Response r = client().post(path, indexLabel); + Response r = client().post(PATH, indexLabel); assertResponseStatus(202, r); indexLabel = "{" + @@ -70,7 +71,7 @@ public void testAppend() { "}" + "}"; Map params = ImmutableMap.of("action", "append"); - r = client().put(path, "personByAge", indexLabel, params); + r = client().put(PATH, "personByAge", indexLabel, params); assertResponseStatus(200, r); } @@ -87,7 +88,7 @@ public void testEliminate() { "\"max\": 100" + "}" + "}"; - Response r = client().post(path, indexLabel); + Response r = client().post(PATH, indexLabel); assertResponseStatus(202, r); indexLabel = "{" + @@ -97,7 +98,7 @@ public void testEliminate() { "}" + "}"; Map params = ImmutableMap.of("action", "eliminate"); - r = client().put(path, "personByAge", indexLabel, params); + r = client().put(PATH, "personByAge", indexLabel, params); assertResponseStatus(200, r); } @@ -110,11 +111,11 @@ public void testGet() { "\"index_type\": \"RANGE\"," + "\"fields\":[\"age\"]" + "}"; - Response r = client().post(path, indexLabel); + Response r = client().post(PATH, indexLabel); assertResponseStatus(202, r); String name = "personByAge"; - r = client().get(path, name); + r = client().get(PATH, name); assertResponseStatus(200, r); } @@ -127,10 +128,10 @@ public void testList() { "\"index_type\": \"RANGE\"," + "\"fields\":[\"age\"]" + "}"; - Response r = client().post(path, indexLabel); + Response r = client().post(PATH, indexLabel); assertResponseStatus(202, r); - r = client().get(path); + r = client().get(PATH); assertResponseStatus(200, r); } @@ -143,11 +144,11 @@ public void testDelete() { "\"index_type\": \"RANGE\"," + "\"fields\":[\"age\"]" + "}"; - Response r = client().post(path, indexLabel); + Response r = client().post(PATH, indexLabel); assertResponseStatus(202, r); String name = "personByAge"; - r = client().delete(path, name); + r = client().delete(PATH, name); String content = assertResponseStatus(202, r); int task = assertJsonContains(content, "task_id"); waitTaskSuccess(task); diff --git a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/LoginApiTest.java b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/LoginApiTest.java index 40c83d5115..30775cb729 100644 --- a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/LoginApiTest.java +++ b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/LoginApiTest.java @@ -20,18 +20,18 @@ import java.nio.file.Paths; import java.util.Map; -import jakarta.ws.rs.core.GenericType; -import jakarta.ws.rs.core.HttpHeaders; -import jakarta.ws.rs.core.MultivaluedHashMap; -import jakarta.ws.rs.core.MultivaluedMap; -import jakarta.ws.rs.core.Response; +import org.apache.hugegraph.testutil.Assert; +import org.apache.hugegraph.util.JsonUtil; import org.apache.tinkerpop.shaded.jackson.core.type.TypeReference; import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.apache.hugegraph.testutil.Assert; -import org.apache.hugegraph.util.JsonUtil; +import jakarta.ws.rs.core.GenericType; +import jakarta.ws.rs.core.HttpHeaders; +import jakarta.ws.rs.core.MultivaluedHashMap; +import jakarta.ws.rs.core.MultivaluedMap; +import jakarta.ws.rs.core.Response; public class LoginApiTest extends BaseApiTest { @@ -42,8 +42,7 @@ public class LoginApiTest extends BaseApiTest { @Before public void setup() { Response r = this.createUser("test", "test"); - Map user = r.readEntity( - new GenericType>(){}); + Map user = r.readEntity(new GenericType>(){}); this.userId4Test = (String) user.get("id"); } @@ -115,9 +114,8 @@ public void testVerify() { assertJsonContains(result, "user_id"); assertJsonContains(result, "user_name"); - Map user = JsonUtil.fromJson( - result, - new TypeReference>(){}); + Map user = JsonUtil.fromJson(result, + new TypeReference>(){}); Assert.assertEquals(this.userId4Test, user.get("user_id")); Assert.assertEquals("test", user.get("user_name")); @@ -142,8 +140,7 @@ private Response createUser(String name, String password) { "\",\"user_email\":\"user1@baidu.com\"," + "\"user_phone\":\"123456789\",\"user_avatar\":\"image1" + ".jpg\"}"; - return this.client().post(USER_PATH, - String.format(user, name, password)); + return this.client().post(USER_PATH, String.format(user, name, password)); } private Response deleteUser(String id) { @@ -155,14 +152,12 @@ private Response login(String name, String password) { String loginUser = "{\"user_name\":\"%s\"," + "\"user_password\":\"%s\"}"; - return client().post(login, String.format(loginUser, - name, password)); + return client().post(login, String.format(loginUser, name, password)); } private String tokenFromResponse(String content) { - Map data = JsonUtil.fromJson( - content, - new TypeReference>(){}); + Map data = JsonUtil.fromJson(content, + new TypeReference>(){}); return (String) data.get("token"); } } diff --git a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/MetricsApiTest.java b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/MetricsApiTest.java index cce5af30cc..86759483c2 100644 --- a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/MetricsApiTest.java +++ b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/MetricsApiTest.java @@ -27,14 +27,14 @@ public class MetricsApiTest extends BaseApiTest { - private static final String path = "/metrics"; - private static final String statisticsPath = path + "/statistics"; + private static final String PATH = "/metrics"; + private static final String STATISTICS_PATH = PATH + "/statistics"; @Test public void testBaseMetricsAll() { Map params = new HashMap<>(); params.put("type", "json"); - Response r = client().get(path, params); + Response r = client().get(PATH, params); String result = assertResponseStatus(200, r); assertJsonContains(result, "gauges"); assertJsonContains(result, "counters"); @@ -45,7 +45,7 @@ public void testBaseMetricsAll() { @Test public void testBaseMetricsPromAll() { - Response r = client().get(path); + Response r = client().get(PATH); assertResponseStatus(200, r); } @@ -53,19 +53,19 @@ public void testBaseMetricsPromAll() { public void testStatisticsMetricsAll() { Map params = new HashMap<>(); params.put("type", "json"); - Response r = client().get(path); + Response r = client().get(PATH); assertResponseStatus(200, r); } @Test public void testStatisticsMetricsPromAll() { - Response r = client().get(statisticsPath); + Response r = client().get(STATISTICS_PATH); assertResponseStatus(200, r); } @Test public void testMetricsSystem() { - Response r = client().get(path, "system"); + Response r = client().get(PATH, "system"); String result = assertResponseStatus(200, r); assertJsonContains(result, "basic"); assertJsonContains(result, "heap"); @@ -77,7 +77,7 @@ public void testMetricsSystem() { @Test public void testMetricsBackend() { - Response r = client().get(path, "backend"); + Response r = client().get(PATH, "backend"); String result = assertResponseStatus(200, r); Object value = assertJsonContains(result, "hugegraph"); @@ -125,10 +125,8 @@ public void testMetricsBackend() { for (Map.Entry e : servers.entrySet()) { String key = (String) e.getKey(); value = e.getValue(); - Assert.assertTrue(String.format( - "Expect map value for key %s but got %s", - key, value), - value instanceof Map); + Assert.assertTrue(String.format("Expect map value for key %s but got %s", + key, value), value instanceof Map); host = (Map) value; assertMapContains(host, "mem_max"); assertMapContains(host, "mem_committed"); @@ -188,10 +186,8 @@ public void testMetricsBackend() { for (Map.Entry e : servers.entrySet()) { String key = (String) e.getKey(); value = e.getValue(); - Assert.assertTrue(String.format( - "Expect map value for key %s but got %s", - key, value), - value instanceof Map); + Assert.assertTrue(String.format("Expect map value for key %s but got %s", + key, value), value instanceof Map); host = (Map) value; assertMapContains(host, "mem_max"); assertMapContains(host, "mem_committed"); @@ -257,10 +253,8 @@ public void testMetricsBackend() { for (Map.Entry e : servers.entrySet()) { String key = (String) e.getKey(); value = e.getValue(); - Assert.assertTrue(String.format( - "Expect map value for key %s but got %s", - key, value), - value instanceof Map); + Assert.assertTrue(String.format("Expect map value for key %s but got %s", + key, value), value instanceof Map); Map regionServer = (Map) value; assertMapContains(regionServer, "mem_max"); assertMapContains(regionServer, "mem_used"); @@ -275,8 +269,7 @@ public void testMetricsBackend() { assertMapContains(regionServer, "request_count_per_second"); assertMapContains(regionServer, "coprocessor_names"); - Map regions = assertMapContains(regionServer, - "regions"); + Map regions = assertMapContains(regionServer, "regions"); Assert.assertGte(1, regions.size()); for (Map.Entry e2 : regions.entrySet()) { Map region = (Map) e2.getValue(); @@ -307,7 +300,7 @@ public void testMetricsBackend() { } break; default: - Assert.assertTrue("Unexpected backend " + backend, false); + Assert.fail("Unexpected backend " + backend); break; } } diff --git a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/ProjectApiTest.java b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/ProjectApiTest.java index 3f4239dfc6..b93b38f6b1 100644 --- a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/ProjectApiTest.java +++ b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/ProjectApiTest.java @@ -20,17 +20,18 @@ import java.util.List; import java.util.Map; -import jakarta.ws.rs.client.Entity; -import jakarta.ws.rs.core.Response; import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.StringUtils; +import org.apache.hugegraph.util.JsonUtil; import org.junit.After; import org.junit.Assert; import org.junit.Test; -import org.apache.hugegraph.util.JsonUtil; import com.google.common.collect.ImmutableMap; +import jakarta.ws.rs.client.Entity; +import jakarta.ws.rs.core.Response; + public class ProjectApiTest extends BaseApiTest { private static final String PATH = "graphs/hugegraph/auth/projects"; @@ -45,11 +46,10 @@ public void teardown() throws Exception { @SuppressWarnings("unchecked") Map projectMap = ((Map) project); String projectId = (String) projectMap.get("id"); - // remove graphs from project if needed + // remove graphs from a project if needed List projectGraphs = (List) projectMap.get("project_graphs"); - if (projectGraphs != null && projectGraphs.size() > 0) { - Map graphs = ImmutableMap.of("project_graphs", - projectGraphs); + if (projectGraphs != null && !projectGraphs.isEmpty()) { + Map graphs = ImmutableMap.of("project_graphs", projectGraphs); resp = client().target() .path(PATH) .path(projectId) @@ -70,30 +70,26 @@ public void teardown() throws Exception { @Test public void testCreate() { - String project = String.format("{\"project_name\": \"test_project\"," + - "\"project_description\": " + - "\"this is a good project\"}"); + String project = "{\"project_name\": \"test_project\"," + + "\"project_description\": " + + "\"this is a good project\"}"; Response resp = client().post(PATH, project); String respBody = assertResponseStatus(201, resp); String projectName = assertJsonContains(respBody, "project_name"); Assert.assertEquals("test_project", projectName); - String projectDescription = assertJsonContains(respBody, - "project_description"); + String projectDescription = assertJsonContains(respBody, "project_description"); Assert.assertEquals("this is a good project", projectDescription); String projectTarget = assertJsonContains(respBody, "project_target"); Assert.assertFalse(StringUtils.isEmpty(projectTarget)); - String projectAdminGroup = assertJsonContains(respBody, - "project_admin_group"); + String projectAdminGroup = assertJsonContains(respBody, "project_admin_group"); Assert.assertFalse(StringUtils.isEmpty(projectAdminGroup)); - String projectOpGroup = assertJsonContains(respBody, - "project_op_group"); + String projectOpGroup = assertJsonContains(respBody, "project_op_group"); Assert.assertFalse(StringUtils.isEmpty(projectOpGroup)); } @Test public void testDelete() { - String project = this.createProject("test_project1", - "this is a good project"); + String project = this.createProject("test_project1", "this is a good project"); String projectId = assertJsonContains(project, "id"); Response resp = client().target() .path(PATH) @@ -105,8 +101,7 @@ public void testDelete() { @Test public void testGet() { - String project = this.createProject("test_project", - "this is a good project"); + String project = this.createProject("test_project", "this is a good project"); String projectId = assertJsonContains(project, "id"); String project2 = this.getProject(projectId); Assert.assertEquals(project, project2); @@ -133,17 +128,14 @@ public void testUpdate() { .put(Entity.json(project)); assertResponseStatus(400, resp); - String projectId = assertJsonContains(createProject("test_project", - "desc"), - "id"); + String projectId = assertJsonContains(createProject("test_project", "desc"), "id"); resp = client().target() .path(PATH) .path(projectId) .request() .put(Entity.json(project)); String respBody = assertResponseStatus(200, resp); - String description = assertJsonContains(respBody, - "project_description"); + String description = assertJsonContains(respBody, "project_description"); Assert.assertEquals("update desc", description); } @@ -170,8 +162,7 @@ public void testAddGraphs() { @Test public void testRemoveGraphs() { - String projectId = this.createProjectAndAddGraph("project_test", - "graph_test"); + String projectId = this.createProjectAndAddGraph("project_test", "graph_test"); String graphs = "{\"project_graphs\":[\"graph_test\"]}"; Response resp = client().target() .path(PATH) @@ -215,18 +206,16 @@ private String createProject(String name, String desc) { Assert.assertEquals(desc, description); } Assert.assertFalse(StringUtils.isEmpty( - assertJsonContains(respBody, "project_target"))); + assertJsonContains(respBody, "project_target"))); Assert.assertFalse(StringUtils.isEmpty( - assertJsonContains(respBody, "project_admin_group"))); + assertJsonContains(respBody, "project_admin_group"))); Assert.assertFalse(StringUtils.isEmpty( - assertJsonContains(respBody, "project_op_group"))); + assertJsonContains(respBody, "project_op_group"))); return respBody; } - private String createProjectAndAddGraph(String projectName, - String graph) { - String projectId = assertJsonContains(createProject(projectName, null), - "id"); + private String createProjectAndAddGraph(String projectName, String graph) { + String projectId = assertJsonContains(createProject(projectName, null), "id"); this.addGraphsToProject(projectId, graph); return projectId; } @@ -237,8 +226,7 @@ private void addGraphsToProject(String projectId, String... graphNames) { for (int i = 0; i < graphNames.length - 1; i++) { graphNamesBuilder.append(String.format("\"%s\",", graphNames[i])); } - graphNamesBuilder.append(String.format("\"%s\"", - graphNames[graphNames.length - 1])); + graphNamesBuilder.append(String.format("\"%s\"", graphNames[graphNames.length - 1])); String graphs = String.format("{\"project_graphs\":[%s]}", graphNamesBuilder); Response resp = client().target() @@ -256,7 +244,6 @@ private String getProject(String projectId) { .path(projectId) .request() .get(); - String respBody = assertResponseStatus(200, resp); - return respBody; + return assertResponseStatus(200, resp); } } diff --git a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/PropertyKeyApiTest.java b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/PropertyKeyApiTest.java index 914c58f60a..9cb715b018 100644 --- a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/PropertyKeyApiTest.java +++ b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/PropertyKeyApiTest.java @@ -17,14 +17,14 @@ package org.apache.hugegraph.api; -import jakarta.ws.rs.core.Response; +import org.apache.hugegraph.testutil.Assert; import org.junit.Test; -import org.apache.hugegraph.testutil.Assert; +import jakarta.ws.rs.core.Response; public class PropertyKeyApiTest extends BaseApiTest { - private static String path = "/graphs/hugegraph/schema/propertykeys/"; + private static final String PATH = "/graphs/hugegraph/schema/propertykeys/"; @Test public void testCreate() { @@ -34,7 +34,7 @@ public void testCreate() { "\"cardinality\": \"SINGLE\"," + "\"properties\":[]" + "}"; - Response r = client().post(path, propertyKey); + Response r = client().post(PATH, propertyKey); assertResponseStatus(202, r); } @@ -46,11 +46,11 @@ public void testGet() { "\"cardinality\": \"SINGLE\"," + "\"properties\":[]" + "}"; - Response r = client().post(path, propertyKey); + Response r = client().post(PATH, propertyKey); assertResponseStatus(202, r); String name = "id"; - r = client().get(path, name); + r = client().get(PATH, name); assertResponseStatus(200, r); } @@ -62,10 +62,10 @@ public void testList() { "\"cardinality\": \"SINGLE\"," + "\"properties\":[]" + "}"; - Response r = client().post(path, propertyKey); + Response r = client().post(PATH, propertyKey); assertResponseStatus(202, r); - r = client().get(path); + r = client().get(PATH); assertResponseStatus(200, r); } @@ -77,11 +77,11 @@ public void testDelete() { "\"cardinality\": \"SINGLE\"," + "\"properties\":[]" + "}"; - Response r = client().post(path, propertyKey); + Response r = client().post(PATH, propertyKey); assertResponseStatus(202, r); String name = "id"; - r = client().delete(path, name); + r = client().delete(PATH, name); String content = assertResponseStatus(202, r); int task = assertJsonContains(content, "task_id"); Assert.assertEquals(0, task); diff --git a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/SchemaApiTest.java b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/SchemaApiTest.java index 370facea77..7d701eed59 100644 --- a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/SchemaApiTest.java +++ b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/SchemaApiTest.java @@ -17,16 +17,17 @@ package org.apache.hugegraph.api; -import jakarta.ws.rs.core.Response; import org.junit.Test; +import jakarta.ws.rs.core.Response; + public class SchemaApiTest extends BaseApiTest { - private static String path = "/graphs/hugegraph/schema"; + private static final String PATH = "/graphs/hugegraph/schema"; @Test public void testGet() { - Response r = client().get(path); + Response r = client().get(PATH); String content = assertResponseStatus(200, r); assertJsonContains(content, "propertykeys"); diff --git a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/TaskApiTest.java b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/TaskApiTest.java index 57659f6771..968a5d1c82 100644 --- a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/TaskApiTest.java +++ b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/TaskApiTest.java @@ -20,16 +20,17 @@ import java.util.List; import java.util.Map; -import com.google.common.collect.ImmutableMap; -import jakarta.ws.rs.core.Response; +import org.apache.hugegraph.testutil.Assert; import org.junit.Before; import org.junit.Test; -import org.apache.hugegraph.testutil.Assert; +import com.google.common.collect.ImmutableMap; + +import jakarta.ws.rs.core.Response; public class TaskApiTest extends BaseApiTest { - private static String path = "/graphs/hugegraph/tasks/"; + private static final String PATH = "/graphs/hugegraph/tasks/"; @Before public void prepareSchema() { @@ -43,14 +44,14 @@ public void testList() { // create a task int taskId = this.rebuild(); - Response r = client().get(path, ImmutableMap.of("limit", -1)); + Response r = client().get(PATH, ImmutableMap.of("limit", -1)); String content = assertResponseStatus(200, r); List> tasks = assertJsonContains(content, "tasks"); assertArrayContains(tasks, "id", taskId); waitTaskSuccess(taskId); - r = client().get(path, String.valueOf(taskId)); + r = client().get(PATH, String.valueOf(taskId)); content = assertResponseStatus(200, r); String status = assertJsonContains(content, "task_status"); Assert.assertEquals("success", status); @@ -62,11 +63,10 @@ public void testList() { * NOTE: seems the master node won't store task status in memory, * because only worker nodes store task status in memory. */ - r = client().get(path, ImmutableMap.of("status", "RUNNING")); + r = client().get(PATH, ImmutableMap.of("status", "RUNNING")); content = assertResponseStatus(200, r); tasks = assertJsonContains(content, "tasks"); - String message = String.format("Expect none RUNNING tasks(%d), " + - "but got %s", taskId, tasks); + String message = String.format("Expect none RUNNING tasks(%d), but got %s", taskId, tasks); Assert.assertTrue(message, tasks.isEmpty()); } @@ -75,13 +75,13 @@ public void testGet() { // create a task int taskId = this.rebuild(); - Response r = client().get(path, String.valueOf(taskId)); + Response r = client().get(PATH, String.valueOf(taskId)); String content = assertResponseStatus(200, r); assertJsonContains(content, "id"); waitTaskSuccess(taskId); - r = client().get(path, String.valueOf(taskId)); + r = client().get(PATH, String.valueOf(taskId)); content = assertResponseStatus(200, r); String status = assertJsonContains(content, "task_status"); Assert.assertEquals("success", status); @@ -96,27 +96,25 @@ public void testCancel() { // cancel task Map params = ImmutableMap.of("action", "cancel"); - Response r = client().put(path, String.valueOf(taskId), "", params); + Response r = client().put(PATH, String.valueOf(taskId), "", params); String content = r.readEntity(String.class); Assert.assertTrue(content, r.getStatus() == 202 || r.getStatus() == 400); if (r.getStatus() == 202) { String status = assertJsonContains(content, "task_status"); - Assert.assertTrue(status, status.equals("cancelling") || - status.equals("cancelled")); + Assert.assertTrue(status, "cancelling".equals(status) || "cancelled".equals(status)); /* * NOTE: should be waitTaskStatus(taskId, "cancelled"), but worker - * node may ignore the CANCELLING status due to now we can't atomic + * node may ignore the CANCELLING status due to now we can't atomically * update task status, and then the task is running to SUCCESS. */ waitTaskCompleted(taskId); } else { assert r.getStatus() == 400; - String error = String.format( - "Can't cancel task '%s' which is completed", taskId); + String error = String.format("Can't cancel task '%s' which is completed", taskId); Assert.assertContains(error, content); - r = client().get(path, String.valueOf(taskId)); + r = client().get(PATH, String.valueOf(taskId)); content = assertResponseStatus(200, r); String status = assertJsonContains(content, "task_status"); Assert.assertEquals("success", status); @@ -130,7 +128,7 @@ public void testDelete() { waitTaskSuccess(taskId); // delete task - Response r = client().delete(path, String.valueOf(taskId)); + Response r = client().delete(PATH, String.valueOf(taskId)); assertResponseStatus(204, r); } diff --git a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/UserApiTest.java b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/UserApiTest.java index e2759b6368..ff457242b0 100644 --- a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/UserApiTest.java +++ b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/UserApiTest.java @@ -20,16 +20,17 @@ import java.util.List; import java.util.Map; -import jakarta.ws.rs.core.Response; +import org.apache.hugegraph.util.JsonUtil; import org.apache.tinkerpop.shaded.jackson.core.type.TypeReference; import org.hamcrest.CoreMatchers; import org.junit.After; import org.junit.Assert; import org.junit.Test; -import org.apache.hugegraph.util.JsonUtil; import com.google.common.collect.ImmutableMap; +import jakarta.ws.rs.core.Response; + public class UserApiTest extends BaseApiTest { private static final String PATH = "graphs/hugegraph/auth/users"; @@ -39,16 +40,14 @@ public class UserApiTest extends BaseApiTest { @After public void teardown() throws Exception { super.teardown(); - Response r = this.client().get(PATH, - ImmutableMap.of("limit", NO_LIMIT)); + Response r = this.client().get(PATH, ImmutableMap.of("limit", NO_LIMIT)); String result = r.readEntity(String.class); Map>> resultMap = - JsonUtil.fromJson(result, - new TypeReference>>>() {}); + JsonUtil.fromJson(result, + new TypeReference>>>() {}); List> users = resultMap.get("users"); for (Map user : users) { - if (user.get("user_name").equals("admin")) { + if ("admin".equals(user.get("user_name"))) { continue; } this.client().delete(PATH, (String) user.get("id")); @@ -124,7 +123,7 @@ public void testUpdate() { createUser("test2"); List> users = listUsers(); for (Map user : users) { - if (user.get("user_name").equals("admin")) { + if ("admin".equals(user.get("user_name"))) { continue; } String user1 = "{\"user_password\":\"p1\"," + @@ -146,7 +145,7 @@ public void testDelete() { List> users = listUsers(); for (Map user : users) { - if (user.get("user_name").equals("admin")) { + if ("admin".equals(user.get("user_name"))) { continue; } Response r = client().delete(PATH, (String) user.get("id")); @@ -169,13 +168,12 @@ protected void createUser(String name) { } protected List> listUsers() { - Response r = this.client().get(PATH, ImmutableMap.of("limit", - NO_LIMIT)); + Response r = this.client().get(PATH, ImmutableMap.of("limit", NO_LIMIT)); String result = assertResponseStatus(200, r); Map>> resultMap = - JsonUtil.fromJson(result, new TypeReference>>>() {}); + JsonUtil.fromJson(result, + new TypeReference>>>() {}); return resultMap.get("users"); } } diff --git a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/VertexApiTest.java b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/VertexApiTest.java index a24f6cd167..aa93354fe0 100644 --- a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/VertexApiTest.java +++ b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/VertexApiTest.java @@ -19,13 +19,14 @@ import java.io.IOException; -import jakarta.ws.rs.core.Response; import org.junit.Before; import org.junit.Test; +import jakarta.ws.rs.core.Response; + public class VertexApiTest extends BaseApiTest { - private static String path = "/graphs/hugegraph/graph/vertices/"; + private static final String PATH = "/graphs/hugegraph/graph/vertices/"; @Before public void prepareSchema() { @@ -42,7 +43,7 @@ public void testCreate() { "\"city\":\"Beijing\"," + "\"age\":19}" + "}"; - Response r = client().post(path, vertex); + Response r = client().post(PATH, vertex); assertResponseStatus(201, r); } @@ -55,12 +56,12 @@ public void testGet() throws IOException { "\"city\":\"Beijing\"," + "\"age\":19}" + "}"; - Response r = client().post(path, vertex); + Response r = client().post(PATH, vertex); String content = assertResponseStatus(201, r); String id = parseId(content); id = String.format("\"%s\"", id); - r = client().get(path, id); + r = client().get(PATH, id); assertResponseStatus(200, r); } @@ -73,10 +74,10 @@ public void testList() { "\"city\":\"Beijing\"," + "\"age\":19}" + "}"; - Response r = client().post(path, vertex); + Response r = client().post(PATH, vertex); assertResponseStatus(201, r); - r = client().get(path); + r = client().get(PATH); assertResponseStatus(200, r); } @@ -89,12 +90,12 @@ public void testDelete() throws IOException { "\"city\":\"Beijing\"," + "\"age\":19}" + "}"; - Response r = client().post(path, vertex); + Response r = client().post(PATH, vertex); String content = assertResponseStatus(201, r); String id = parseId(content); id = String.format("\"%s\"", id); - r = client().delete(path, id); + r = client().delete(PATH, id); assertResponseStatus(204, r); } } diff --git a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/VertexLabelApiTest.java b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/VertexLabelApiTest.java index 3746deaece..a0fa10d5be 100644 --- a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/VertexLabelApiTest.java +++ b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/VertexLabelApiTest.java @@ -19,15 +19,16 @@ import java.util.Map; -import jakarta.ws.rs.core.Response; import org.junit.Before; import org.junit.Test; import com.google.common.collect.ImmutableMap; +import jakarta.ws.rs.core.Response; + public class VertexLabelApiTest extends BaseApiTest { - private static String path = "/graphs/hugegraph/schema/vertexlabels/"; + private static final String PATH = "/graphs/hugegraph/schema/vertexlabels/"; @Before public void prepareSchema() { @@ -43,7 +44,7 @@ public void testCreate() { "\"primary_keys\":[\"name\"]," + "\"nullable_keys\":[\"city\"]" + "}"; - Response r = client().post(path, vertexLabel); + Response r = client().post(PATH, vertexLabel); assertResponseStatus(201, r); } @@ -56,7 +57,7 @@ public void testAppend() { "\"primary_keys\":[\"name\"]," + "\"nullable_keys\":[\"city\"]" + "}"; - Response r = client().post(path, vertexLabel); + Response r = client().post(PATH, vertexLabel); assertResponseStatus(201, r); vertexLabel = "{" + @@ -67,7 +68,7 @@ public void testAppend() { "\"nullable_keys\":[\"lang\"]" + "}"; Map params = ImmutableMap.of("action", "append"); - r = client().put(path, "person", vertexLabel, params); + r = client().put(PATH, "person", vertexLabel, params); assertResponseStatus(200, r); } @@ -80,11 +81,11 @@ public void testGet() { "\"primary_keys\":[\"name\"]," + "\"nullable_keys\":[\"city\"]" + "}"; - Response r = client().post(path, vertexLabel); + Response r = client().post(PATH, vertexLabel); assertResponseStatus(201, r); String name = "person"; - r = client().get(path, name); + r = client().get(PATH, name); assertResponseStatus(200, r); } @@ -97,10 +98,10 @@ public void testList() { "\"primary_keys\":[\"name\"]," + "\"nullable_keys\":[\"city\"]" + "}"; - Response r = client().post(path, vertexLabel); + Response r = client().post(PATH, vertexLabel); assertResponseStatus(201, r); - r = client().get(path); + r = client().get(PATH); assertResponseStatus(200, r); } @@ -113,11 +114,11 @@ public void testDelete() { "\"primary_keys\":[\"name\"]," + "\"nullable_keys\":[\"city\"]" + "}"; - Response r = client().post(path, vertexLabel); + Response r = client().post(PATH, vertexLabel); assertResponseStatus(201, r); String name = "person"; - r = client().delete(path, name); + r = client().delete(PATH, name); String content = assertResponseStatus(202, r); int task = assertJsonContains(content, "task_id"); waitTaskSuccess(task); diff --git a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/traversers/RaysApiTest.java b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/traversers/RaysApiTest.java index c0156ebad5..15c81ae67e 100644 --- a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/traversers/RaysApiTest.java +++ b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/traversers/RaysApiTest.java @@ -20,14 +20,15 @@ import java.util.List; import java.util.Map; -import jakarta.ws.rs.core.Response; +import org.apache.hugegraph.api.BaseApiTest; import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import org.apache.hugegraph.api.BaseApiTest; import com.google.common.collect.ImmutableMap; +import jakarta.ws.rs.core.Response; + public class RaysApiTest extends BaseApiTest { static final String PATH = TRAVERSERS_API + "/rays"; @@ -46,12 +47,10 @@ public void testGet() { Map name2Ids = listAllVertexName2Ids(); String markoId = name2Ids.get("marko"); String vadasId = name2Ids.get("vadas"); - Response r = client().get(PATH, ImmutableMap.of("source", - id2Json(markoId), + Response r = client().get(PATH, ImmutableMap.of("source", id2Json(markoId), "max_depth", 10)); String content = assertResponseStatus(200, r); - List>> rays = assertJsonContains(content, - "rays"); + List>> rays = assertJsonContains(content, "rays"); Assert.assertNotNull(rays); Assert.assertEquals(2, rays.size()); Object[] valuesArray = rays.get(0).values().toArray(); diff --git a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/traversers/SameNeighborsApiTest.java b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/traversers/SameNeighborsApiTest.java index e4b3a6bfda..7e2670f10e 100644 --- a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/traversers/SameNeighborsApiTest.java +++ b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/traversers/SameNeighborsApiTest.java @@ -20,14 +20,15 @@ import java.util.List; import java.util.Map; -import jakarta.ws.rs.core.Response; +import org.apache.hugegraph.api.BaseApiTest; import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import org.apache.hugegraph.api.BaseApiTest; import com.google.common.collect.ImmutableMap; +import jakarta.ws.rs.core.Response; + public class SameNeighborsApiTest extends BaseApiTest { static final String PATH = TRAVERSERS_API + "/sameneighbors"; @@ -47,13 +48,10 @@ 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", - id2Json(markoId), - "other", - id2Json(joshId))); + Response r = client().get(PATH, ImmutableMap.of("vertex", id2Json(markoId), + "other", id2Json(joshId))); String content = assertResponseStatus(200, r); - List sameNeighbors = assertJsonContains(content, - "same_neighbors"); + List sameNeighbors = assertJsonContains(content, "same_neighbors"); Assert.assertFalse(sameNeighbors.isEmpty()); Assert.assertTrue(sameNeighbors.contains(peterId)); } diff --git a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/traversers/SingleSourceShortestPathApiTest.java b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/traversers/SingleSourceShortestPathApiTest.java index 39a5474255..663dd18380 100644 --- a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/traversers/SingleSourceShortestPathApiTest.java +++ b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/traversers/SingleSourceShortestPathApiTest.java @@ -19,14 +19,15 @@ import java.util.Map; -import jakarta.ws.rs.core.Response; +import org.apache.hugegraph.api.BaseApiTest; import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import org.apache.hugegraph.api.BaseApiTest; import com.google.common.collect.ImmutableMap; +import jakarta.ws.rs.core.Response; + public class SingleSourceShortestPathApiTest extends BaseApiTest { static final String PATH = TRAVERSERS_API + "/singlesourceshortestpath"; @@ -44,10 +45,8 @@ public void prepareSchema() { public void testGet() { Map name2Ids = listAllVertexName2Ids(); String markoId = name2Ids.get("marko"); - Response r = client().get(PATH, ImmutableMap.of("source", - id2Json(markoId), - "with_vertex", - true)); + Response r = client().get(PATH, ImmutableMap.of("source", id2Json(markoId), + "with_vertex", true)); String content = assertResponseStatus(200, r); Map> paths = assertJsonContains(content, "paths"); Assert.assertEquals(4, paths.size()); diff --git a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/UnitTestSuite.java b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/UnitTestSuite.java index d72269a4f5..eb1fb6ad3b 100644 --- a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/UnitTestSuite.java +++ b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/UnitTestSuite.java @@ -17,27 +17,12 @@ package org.apache.hugegraph.unit; -import org.apache.hugegraph.unit.cassandra.CassandraTest; -import org.apache.hugegraph.unit.id.EdgeIdTest; -import org.apache.hugegraph.unit.id.IdTest; -import org.apache.hugegraph.unit.id.IdUtilTest; -import org.apache.hugegraph.unit.id.SplicingIdGeneratorTest; -import org.apache.hugegraph.unit.mysql.MysqlUtilTest; -import org.apache.hugegraph.unit.mysql.WhereBuilderTest; -import org.apache.hugegraph.unit.rocksdb.RocksDBCountersTest; -import org.apache.hugegraph.unit.rocksdb.RocksDBSessionTest; -import org.apache.hugegraph.unit.rocksdb.RocksDBSessionsTest; -import org.apache.hugegraph.unit.store.RamIntObjectMapTest; -import org.junit.runner.RunWith; -import org.junit.runners.Suite; - -import org.apache.hugegraph.unit.core.SystemSchemaStoreTest; -import org.apache.hugegraph.unit.util.RateLimiterTest; import org.apache.hugegraph.unit.cache.CacheManagerTest; import org.apache.hugegraph.unit.cache.CacheTest; import org.apache.hugegraph.unit.cache.CachedGraphTransactionTest; import org.apache.hugegraph.unit.cache.CachedSchemaTransactionTest; import org.apache.hugegraph.unit.cache.RamTableTest; +import org.apache.hugegraph.unit.cassandra.CassandraTest; import org.apache.hugegraph.unit.core.AnalyzerTest; import org.apache.hugegraph.unit.core.BackendMutationTest; import org.apache.hugegraph.unit.core.BackendStoreInfoTest; @@ -54,7 +39,17 @@ import org.apache.hugegraph.unit.core.RowLockTest; import org.apache.hugegraph.unit.core.SecurityManagerTest; import org.apache.hugegraph.unit.core.SerialEnumTest; +import org.apache.hugegraph.unit.core.SystemSchemaStoreTest; import org.apache.hugegraph.unit.core.TraversalUtilTest; +import org.apache.hugegraph.unit.id.EdgeIdTest; +import org.apache.hugegraph.unit.id.IdTest; +import org.apache.hugegraph.unit.id.IdUtilTest; +import org.apache.hugegraph.unit.id.SplicingIdGeneratorTest; +import org.apache.hugegraph.unit.mysql.MysqlUtilTest; +import org.apache.hugegraph.unit.mysql.WhereBuilderTest; +import org.apache.hugegraph.unit.rocksdb.RocksDBCountersTest; +import org.apache.hugegraph.unit.rocksdb.RocksDBSessionTest; +import org.apache.hugegraph.unit.rocksdb.RocksDBSessionsTest; import org.apache.hugegraph.unit.serializer.BinaryBackendEntryTest; import org.apache.hugegraph.unit.serializer.BinaryScatterSerializerTest; import org.apache.hugegraph.unit.serializer.BinarySerializerTest; @@ -63,8 +58,10 @@ import org.apache.hugegraph.unit.serializer.StoreSerializerTest; import org.apache.hugegraph.unit.serializer.TableBackendEntryTest; import org.apache.hugegraph.unit.serializer.TextBackendEntryTest; +import org.apache.hugegraph.unit.store.RamIntObjectMapTest; import org.apache.hugegraph.unit.util.CompressUtilTest; import org.apache.hugegraph.unit.util.JsonUtilTest; +import org.apache.hugegraph.unit.util.RateLimiterTest; import org.apache.hugegraph.unit.util.StringEncodingTest; import org.apache.hugegraph.unit.util.VersionTest; import org.apache.hugegraph.unit.util.collection.CollectionFactoryTest; @@ -73,6 +70,8 @@ import org.apache.hugegraph.unit.util.collection.IntMapTest; import org.apache.hugegraph.unit.util.collection.IntSetTest; import org.apache.hugegraph.unit.util.collection.ObjectIntMappingTest; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; @RunWith(Suite.class) @Suite.SuiteClasses({