Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refact(client): update tests for new OLTP traverser APIs #550

Merged
merged 14 commits into from
Dec 12, 2023
3 changes: 1 addition & 2 deletions .github/workflows/client-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ jobs:
env:
USE_STAGE: 'true' # Whether to include the stage repository.
TRAVIS_DIR: hugegraph-client/assembly/travis
# TODO: replace it with the (latest - n) commit id (n >= 15)
COMMIT_ID: be6ee386b9939dc6bd6fcbdf2274b8acc3a0a314
COMMIT_ID: bfe9fae150446857412db23ada0dae9d05035837
strategy:
fail-fast: false
matrix:
Expand Down
9 changes: 8 additions & 1 deletion .github/workflows/client-go-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ jobs:
client-go-ci:
runs-on: ubuntu-latest
env:
USE_STAGE: 'true' # Whether to include the stage repository.
TRAVIS_DIR: hugegraph-client/assembly/travis
COMMIT_ID: be6ee386b9939dc6bd6fcbdf2274b8acc3a0a314
COMMIT_ID: bfe9fae150446857412db23ada0dae9d05035837
strategy:
fail-fast: false
matrix:
Expand All @@ -46,6 +47,12 @@ jobs:
with:
fetch-depth: 2

- name: Use staged maven repo
if: ${{ env.USE_STAGE == 'true' }}
run: |
cp $HOME/.m2/settings.xml /tmp/settings.xml
mv -vf .github/configs/settings.xml $HOME/.m2/settings.xml

- name: Prepare env and service
run: |
$TRAVIS_DIR/install-hugegraph-from-source.sh $COMMIT_ID
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/hubble-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ on:

env:
TRAVIS_DIR: hugegraph-hubble/hubble-dist/assembly/travis
# TODO: replace it with the (latest - n) commit id (n >= 15)
COMMIT_ID: be6ee386b9939dc6bd6fcbdf2274b8acc3a0a314
# TODO: need update it later (eed6103359fe40d2f1476fb8c56d9388c3111a99)
COMMIT_ID: bfe9fae150446857412db23ada0dae9d05035837

jobs:
hubble-ci:
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/loader-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ jobs:
USE_STAGE: 'true' # Whether to include the stage repository.
TRAVIS_DIR: hugegraph-loader/assembly/travis
STATIC_DIR: hugegraph-loader/assembly/static
# TODO: replace it with the (latest - n) commit id (n >= 15)
COMMIT_ID: be6ee386b9939dc6bd6fcbdf2274b8acc3a0a314
COMMIT_ID: bfe9fae150446857412db23ada0dae9d05035837
DB_USER: root
DB_PASS: root
DB_DATABASE: load_test
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tools-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
USE_STAGE: 'true' # Whether to include the stage repository.
TRAVIS_DIR: hugegraph-tools/assembly/travis
# TODO: could we use one param to unify it? or use a action template (could use one ci file)
COMMIT_ID: be6ee386b9939dc6bd6fcbdf2274b8acc3a0a314
COMMIT_ID: bfe9fae150446857412db23ada0dae9d05035837
steps:
- name: Install JDK 11
uses: actions/setup-java@v3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ git checkout "${COMMIT_ID}"
mvn package -DskipTests -Dmaven.javadoc.skip=true -ntp

# TODO: lack incubator after apache package release (update it later)
cd hugegraph-server
TAR=$(echo apache-hugegraph-*.tar.gz)
tar zxf "${TAR}" -C ../
cd ../
tar zxf "${TAR}" -C ../../
cd ../../
rm -rf "${GIT_DIR}"
# TODO: lack incubator after apache package release (update it later)
HTTP_SERVER_DIR=$(echo apache-hugegraph-*.*)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.hugegraph.api.metrics;

import java.util.HashMap;
import java.util.Map;

import org.apache.hugegraph.util.CommonUtil;
Expand All @@ -27,6 +28,8 @@

public class MetricsAPI extends API {

public static final String STATISTICS_PATH = "/statistics";

public MetricsAPI(RestClient client) {
super(client);
this.path(this.type());
Expand Down Expand Up @@ -65,12 +68,39 @@ public Map<String, Object> backend(String graph) {

@SuppressWarnings("unchecked")
public Map<String, Map<String, Object>> all() {
Map<String,Object> params = new HashMap<>();
params.put("type", "json");
RestResult result = this.client.get(this.path(), params);
Map<?, ?> map = result.readObject(Map.class);
CommonUtil.checkMapClass(map, String.class, Map.class);
for (Object mapValue : map.values()) {
CommonUtil.checkMapClass(mapValue, String.class, Object.class);
}
return (Map<String, Map<String, Object>>) map;
}

@SuppressWarnings("unchecked")
public String allWithPromFormat() {
RestResult result = this.client.get(this.path());
return result.content();
}

public Map<String, Map<String, Object>> statistics() {
Map<String,Object> params = new HashMap<>();
params.put("type", "json");
RestResult result = this.client.get(this.path() + STATISTICS_PATH, params);
Map<?, ?> map = result.readObject(Map.class);
CommonUtil.checkMapClass(map, String.class, Map.class);
for (Object mapValue : map.values()) {
CommonUtil.checkMapClass(mapValue, String.class, Object.class);
}

return (Map<String, Map<String, Object>>) map;
}

@SuppressWarnings("unchecked")
public String statisticsWithPromFormat() {
RestResult result = this.client.get(this.path() + STATISTICS_PATH);
return result.content();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.hugegraph.rest.RestResult;

import org.apache.hugegraph.structure.constant.Direction;
import org.apache.hugegraph.structure.traverser.JaccardSimilarity;
import org.apache.hugegraph.structure.traverser.SingleSourceJaccardSimilarityRequest;

import org.apache.hugegraph.util.E;
Expand Down Expand Up @@ -64,9 +65,9 @@ public double get(Object vertexId, Object otherId, Direction direction,
}

@SuppressWarnings("unchecked")
public Map<Object, Double> post(SingleSourceJaccardSimilarityRequest request) {
public JaccardSimilarity post(SingleSourceJaccardSimilarityRequest request) {
this.client.checkApiVersion("0.58", "jaccard similar");
RestResult result = this.client.post(this.path(), request);
return result.readObject(Map.class);
return result.readObject(JaccardSimilarity.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ protected String type() {

public WeightedPaths get(Object sourceId, Direction direction, String label,
String weight, long degree, long skipDegree,
long capacity, int limit, boolean withVertex) {
long capacity, int limit, boolean withVertex, boolean withEdge) {
this.client.checkApiVersion("0.51", "single source shortest path");
String source = GraphAPI.formatVertexId(sourceId, false);

Expand All @@ -60,6 +60,7 @@ public WeightedPaths get(Object sourceId, Direction direction, String label,
params.put("capacity", capacity);
params.put("limit", limit);
params.put("with_vertex", withVertex);
params.put("with_edge", withEdge);
RestResult result = this.client.get(this.path(), params);
return result.readObject(WeightedPaths.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected String type() {
public WeightedPath get(Object sourceId, Object targetId,
Direction direction, String label,
String weight, long degree, long skipDegree,
long capacity, boolean withVertex) {
long capacity, boolean withVertex, boolean withEdge) {
this.client.checkApiVersion("0.51", "weighted shortest path");
String source = GraphAPI.formatVertexId(sourceId, false);
String target = GraphAPI.formatVertexId(targetId, false);
Expand All @@ -61,6 +61,7 @@ public WeightedPath get(Object sourceId, Object targetId,
params.put("skip_degree", skipDegree);
params.put("capacity", capacity);
params.put("with_vertex", withVertex);
params.put("with_edge", withEdge);
RestResult result = this.client.get(this.path(), params);
return result.readObject(WeightedPath.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,16 @@ public Map<String, Map<String, Object>> system() {
public Map<String, Map<String, Object>> all() {
return this.metricsAPI.all();
}

public String allWithPromFormat() {
return this.metricsAPI.allWithPromFormat();
}

public Map<String, Map<String, Object>> statistics() {
return this.metricsAPI.statistics();
}

public String statisticsWithPromFormat() {
return this.metricsAPI.statisticsWithPromFormat();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@

import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.apache.hugegraph.structure.constant.Direction;
import org.apache.hugegraph.structure.constant.Traverser;
import org.apache.hugegraph.api.traverser.AllShortestPathsAPI;
import org.apache.hugegraph.api.traverser.CountAPI;
import org.apache.hugegraph.api.traverser.CrosspointsAPI;
Expand All @@ -46,6 +43,8 @@
import org.apache.hugegraph.api.traverser.VerticesAPI;
import org.apache.hugegraph.api.traverser.WeightedShortestPathAPI;
import org.apache.hugegraph.client.RestClient;
import org.apache.hugegraph.structure.constant.Direction;
import org.apache.hugegraph.structure.constant.Traverser;
import org.apache.hugegraph.structure.graph.Edge;
import org.apache.hugegraph.structure.graph.Edges;
import org.apache.hugegraph.structure.graph.GraphIterator;
Expand All @@ -56,18 +55,19 @@
import org.apache.hugegraph.structure.traverser.CountRequest;
import org.apache.hugegraph.structure.traverser.CrosspointsRequest;
import org.apache.hugegraph.structure.traverser.CustomizedCrosspoints;
import org.apache.hugegraph.structure.traverser.MultiNodeShortestPathRequest;
import org.apache.hugegraph.structure.traverser.PathsWithVertices;
import org.apache.hugegraph.structure.traverser.CustomizedPathsRequest;
import org.apache.hugegraph.structure.traverser.FusiformSimilarity;
import org.apache.hugegraph.structure.traverser.FusiformSimilarityRequest;
import org.apache.hugegraph.structure.traverser.SingleSourceJaccardSimilarityRequest;
import org.apache.hugegraph.structure.traverser.JaccardSimilarity;
import org.apache.hugegraph.structure.traverser.Kneighbor;
import org.apache.hugegraph.structure.traverser.KneighborRequest;
import org.apache.hugegraph.structure.traverser.Kout;
import org.apache.hugegraph.structure.traverser.KoutRequest;
import org.apache.hugegraph.structure.traverser.CustomizedPathsRequest;
import org.apache.hugegraph.structure.traverser.MultiNodeShortestPathRequest;
import org.apache.hugegraph.structure.traverser.PathsRequest;
import org.apache.hugegraph.structure.traverser.PathsWithVertices;
import org.apache.hugegraph.structure.traverser.Ranks;
import org.apache.hugegraph.structure.traverser.SingleSourceJaccardSimilarityRequest;
import org.apache.hugegraph.structure.traverser.TemplatePathsRequest;
import org.apache.hugegraph.structure.traverser.WeightedPath;
import org.apache.hugegraph.structure.traverser.WeightedPaths;
Expand Down Expand Up @@ -143,7 +143,7 @@ public double jaccardSimilarity(Object vertexId, Object otherId,
label, degree);
}

public Map<Object, Double> jaccardSimilarity(SingleSourceJaccardSimilarityRequest request) {
public JaccardSimilarity jaccardSimilarity(SingleSourceJaccardSimilarityRequest request) {
return this.jaccardSimilarityAPI.post(request);
}

Expand Down Expand Up @@ -241,55 +241,57 @@ public List<Path> allShortestPaths(Object sourceId, Object targetId,

public WeightedPaths singleSourceShortestPath(Object sourceId,
String weight,
boolean withVertex) {
boolean withVertex,
boolean withEdge) {
return this.singleSourceShortestPath(sourceId, Direction.BOTH, null,
weight, withVertex);
weight, withVertex, withEdge);
}

public WeightedPaths singleSourceShortestPath(Object sourceId,
Direction direction,
String label, String weight,
boolean withVertex) {
boolean withVertex, boolean withEdge) {
return this.singleSourceShortestPath(sourceId, direction, label, weight,
Traverser.DEFAULT_MAX_DEGREE, 0L,
Traverser.DEFAULT_CAPACITY,
Traverser.DEFAULT_PATHS_LIMIT, withVertex);
Traverser.DEFAULT_PATHS_LIMIT, withVertex, withEdge);
}

public WeightedPaths singleSourceShortestPath(Object sourceId,
Direction direction,
String label, String weight,
long degree, long skipDegree,
long capacity, int limit,
boolean withVertex) {
boolean withVertex, boolean withEdge) {
return this.singleSourceShortestPathAPI.get(sourceId, direction, label,
weight, degree, skipDegree,
capacity, limit,
withVertex);
withVertex, withEdge);
}

public WeightedPath weightedShortestPath(Object sourceId, Object targetId,
String weight, boolean withVertex) {
String weight, boolean withVertex, boolean withEdge) {
return this.weightedShortestPath(sourceId, targetId, Direction.BOTH,
null, weight, withVertex);
null, weight, withVertex, withEdge);
}

public WeightedPath weightedShortestPath(Object sourceId, Object targetId,
Direction direction, String label,
String weight,
boolean withVertex) {
boolean withVertex,
boolean withEdge) {
return this.weightedShortestPath(sourceId, targetId, direction, label,
weight, Traverser.DEFAULT_MAX_DEGREE, 0L,
Traverser.DEFAULT_CAPACITY, withVertex);
Traverser.DEFAULT_CAPACITY, withVertex, withEdge);
}

public WeightedPath weightedShortestPath(Object sourceId, Object targetId,
Direction direction,
String label, String weight,
long degree, long skipDegree,
long capacity, boolean withVertex) {
long capacity, boolean withVertex, boolean withEdge) {
return this.weightedShortestPathAPI.get(sourceId, targetId, direction, label, weight,
degree, skipDegree, capacity, withVertex);
degree, skipDegree, capacity, withVertex, withEdge);
}

public PathsWithVertices multiNodeShortestPath(MultiNodeShortestPathRequest request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@ public class Traverser {
public static final double DEFAULT_ALPHA = 0.9;
public static final int DEFAULT_MAX_TOP = 1000;
public static final int DEFAULT_MAX_DEPTH = 5000;
public static final String TRAVERSE_MODE_BFS = "breadth_first_search";
public static final String TRAVERSE_MODE_DFS = "depth_first_search";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with this
* work for additional information regarding copyright ownership. The ASF
* licenses this file to You under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

package org.apache.hugegraph.structure.traverser;

import com.fasterxml.jackson.annotation.JsonProperty;

public class ApiMeasure {

@JsonProperty("edge_iterations")
private Long edgeIters;
@JsonProperty("vertice_iterations")
private Long verticeIters;
@JsonProperty("cost(ns)")
private Long totalTime;

public Long edgeIters() {
return this.edgeIters;

Check warning on line 32 in hugegraph-client/src/main/java/org/apache/hugegraph/structure/traverser/ApiMeasure.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-client/src/main/java/org/apache/hugegraph/structure/traverser/ApiMeasure.java#L32

Added line #L32 was not covered by tests
}

public Long verticeIters() {
return this.verticeIters;

Check warning on line 36 in hugegraph-client/src/main/java/org/apache/hugegraph/structure/traverser/ApiMeasure.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-client/src/main/java/org/apache/hugegraph/structure/traverser/ApiMeasure.java#L36

Added line #L36 was not covered by tests
}

public Long totalTime() {
return this.totalTime;

Check warning on line 40 in hugegraph-client/src/main/java/org/apache/hugegraph/structure/traverser/ApiMeasure.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-client/src/main/java/org/apache/hugegraph/structure/traverser/ApiMeasure.java#L40

Added line #L40 was not covered by tests
}
}
Loading
Loading