From b42211a499be55a76fdda892050a6b4933626216 Mon Sep 17 00:00:00 2001 From: Jermy Li Date: Fri, 24 Dec 2021 21:49:44 +0800 Subject: [PATCH] fix ci Change-Id: Id14191f3c02ad85de67c6ba66535ce5a4b167543 --- .github/workflows/ci.yml | 4 +- BCLOUD | 1 - .../conf/{ => graphs}/hugegraph.properties | 0 assembly/travis/conf/gremlin-server.yaml | 26 +++-- assembly/travis/conf/rest-server.properties | 35 ++++++- .../travis/install-hugegraph-from-source.sh | 26 +++-- assembly/travis/install-hugegraph-from-tar.sh | 69 ------------- .../baidu/hugegraph/api/graphs/GraphsAPI.java | 33 ++++--- .../baidu/hugegraph/driver/GraphsManager.java | 44 ++------- .../baidu/hugegraph/driver/HugeClient.java | 16 ++- .../baidu/hugegraph/api/GraphsApiTest.java | 98 +++++++++++++++++-- ....properties => hugegraph-clone.properties} | 2 - ...properties => hugegraph-create.properties} | 1 + 13 files changed, 200 insertions(+), 155 deletions(-) delete mode 100644 BCLOUD rename assembly/travis/conf/{ => graphs}/hugegraph.properties (100%) delete mode 100755 assembly/travis/install-hugegraph-from-tar.sh rename src/test/resources/{hugegraph3.properties => hugegraph-clone.properties} (65%) rename src/test/resources/{hugegraph2.properties => hugegraph-create.properties} (62%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e1874aec..c44c08b6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,7 @@ jobs: runs-on: ubuntu-20.04 env: TRAVIS_DIR: assembly/travis - COMMIT_ID: 2dd2d7c3fd7cb42cd7338d70a73e04b0c5604487 + COMMIT_ID: d213166eb2185cbb6bd8bd5d201b7167e7b98993 steps: - name: Install JDK 8 uses: actions/setup-java@v2 @@ -43,7 +43,7 @@ jobs: - name: Prepare env and service run: | - $TRAVIS_DIR/install-hugegraph-from-source.sh $COMMIT_ID | grep -v "Downloading\|Downloaded" + $TRAVIS_DIR/install-hugegraph-from-source.sh $COMMIT_ID - name: Run test run: | diff --git a/BCLOUD b/BCLOUD deleted file mode 100644 index 4a4172a1..00000000 --- a/BCLOUD +++ /dev/null @@ -1 +0,0 @@ -BUILD_SUBMITTER -x -e CENTOS6U3 -m baidu/xbu-data/hugegraph-client -c "export MAVEN_HOME=/home/scmtools/buildkit/maven/apache-maven-3.3.9/ && export JAVA_HOME=/home/scmtools/buildkit/java/jdk1.8.0_25/ && export PATH=$JAVA_HOME/bin:$MAVEN_HOME/bin:$PATH && cd baidu/xbu-data/hugegraph-client && sh build.sh && mkdir output && cp BCLOUD ./output/" -u ./ diff --git a/assembly/travis/conf/hugegraph.properties b/assembly/travis/conf/graphs/hugegraph.properties similarity index 100% rename from assembly/travis/conf/hugegraph.properties rename to assembly/travis/conf/graphs/hugegraph.properties diff --git a/assembly/travis/conf/gremlin-server.yaml b/assembly/travis/conf/gremlin-server.yaml index 600e631c..69e89902 100644 --- a/assembly/travis/conf/gremlin-server.yaml +++ b/assembly/travis/conf/gremlin-server.yaml @@ -6,8 +6,8 @@ scriptEvaluationTimeout: 30000 channelizer: org.apache.tinkerpop.gremlin.server.channel.WsAndHttpChannelizer +# don't set graph at here, this happens after support for dynamically adding graph graphs: { - hugegraph: conf/hugegraph.properties } scriptEngines: { gremlin-groovy: { @@ -17,16 +17,30 @@ scriptEngines: { org.apache.tinkerpop.gremlin.jsr223.ImportGremlinPlugin: { classImports: [ java.lang.Math, + com.baidu.hugegraph.backend.id.IdGenerator, com.baidu.hugegraph.type.define.Directions, - com.baidu.hugegraph.traversal.algorithm.CustomizePathsTraverser, + com.baidu.hugegraph.type.define.NodeRole, + com.baidu.hugegraph.traversal.algorithm.CollectionPathsTraverser, + com.baidu.hugegraph.traversal.algorithm.CountTraverser, com.baidu.hugegraph.traversal.algorithm.CustomizedCrosspointsTraverser, + com.baidu.hugegraph.traversal.algorithm.CustomizePathsTraverser, com.baidu.hugegraph.traversal.algorithm.FusiformSimilarityTraverser, com.baidu.hugegraph.traversal.algorithm.HugeTraverser, + com.baidu.hugegraph.traversal.algorithm.JaccardSimilarTraverser, + com.baidu.hugegraph.traversal.algorithm.KneighborTraverser, + com.baidu.hugegraph.traversal.algorithm.KoutTraverser, + com.baidu.hugegraph.traversal.algorithm.MultiNodeShortestPathTraverser, com.baidu.hugegraph.traversal.algorithm.NeighborRankTraverser, com.baidu.hugegraph.traversal.algorithm.PathsTraverser, com.baidu.hugegraph.traversal.algorithm.PersonalRankTraverser, + com.baidu.hugegraph.traversal.algorithm.SameNeighborTraverser, com.baidu.hugegraph.traversal.algorithm.ShortestPathTraverser, + com.baidu.hugegraph.traversal.algorithm.SingleSourceShortestPathTraverser, com.baidu.hugegraph.traversal.algorithm.SubGraphTraverser, + com.baidu.hugegraph.traversal.algorithm.TemplatePathsTraverser, + com.baidu.hugegraph.traversal.algorithm.steps.EdgeStep, + com.baidu.hugegraph.traversal.algorithm.steps.RepeatEdgeStep, + com.baidu.hugegraph.traversal.algorithm.steps.WeightedEdgeStep, com.baidu.hugegraph.traversal.optimize.Text, com.baidu.hugegraph.traversal.optimize.TraversalUtil, com.baidu.hugegraph.util.DateUtil @@ -40,12 +54,6 @@ scriptEngines: { } } serializers: - - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoLiteMessageSerializerV1d0, - config: { - serializeResultToString: false, - ioRegistries: [com.baidu.hugegraph.io.HugeGraphIoRegistry] - } - } - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphBinaryMessageSerializerV1, config: { serializeResultToString: false, @@ -72,7 +80,7 @@ serializers: } metrics: { consoleReporter: {enabled: false, interval: 180000}, - csvReporter: {enabled: true, interval: 180000, fileName: /tmp/gremlin-server-metrics.csv}, + csvReporter: {enabled: false, interval: 180000, fileName: ./metrics/gremlin-server-metrics.csv}, jmxReporter: {enabled: false}, slf4jReporter: {enabled: false, interval: 180000}, gangliaReporter: {enabled: false, interval: 180000, addressingMode: MULTICAST}, diff --git a/assembly/travis/conf/rest-server.properties b/assembly/travis/conf/rest-server.properties index a9ea865b..d44ff6bc 100644 --- a/assembly/travis/conf/rest-server.properties +++ b/assembly/travis/conf/rest-server.properties @@ -3,10 +3,39 @@ restserver.url=http://127.0.0.1:8080 # gremlin server url, need to be consistent with host and port in gremlin-server.yaml #gremlinserver.url=http://127.0.0.1:8182 -# graphs list with pair NAME:CONF_PATH -graphs=[hugegraph:conf/hugegraph.properties] +graphs=./conf/graphs -# authentication +# The maximum thread ratio for batch writing, only take effect if the batch.max_write_threads is 0 +batch.max_write_ratio=80 +batch.max_write_threads=0 + +# authentication configs +# choose 'com.baidu.hugegraph.auth.StandardAuthenticator' or 'com.baidu.hugegraph.auth.ConfigAuthenticator' auth.authenticator=com.baidu.hugegraph.auth.StandardAuthenticator + +# for StandardAuthenticator mode +#auth.graph_store=hugegraph +# auth client config +#auth.remote_url=127.0.0.1:8899,127.0.0.1:8898,127.0.0.1:8897 + +# for ConfigAuthenticator mode #auth.admin_token= #auth.user_tokens=[] + +# rpc group configs of multi graph servers +# rpc server configs +rpc.server_host=127.0.0.1 +rpc.server_port=8090 +#rpc.server_timeout=30 + +# rpc client configs (like enable to keep cache consistency) +rpc.remote_url=127.0.0.1:8090 +#rpc.client_connect_timeout=20 +#rpc.client_reconnect_period=10 +#rpc.client_read_timeout=40 +#rpc.client_retries=3 +#rpc.client_load_balancer=consistentHash + +# lightweight load balancing (beta) +server.id=server-1 +server.role=master diff --git a/assembly/travis/install-hugegraph-from-source.sh b/assembly/travis/install-hugegraph-from-source.sh index 31d7e89c..c594320e 100755 --- a/assembly/travis/install-hugegraph-from-source.sh +++ b/assembly/travis/install-hugegraph-from-source.sh @@ -9,26 +9,34 @@ fi COMMIT_ID=$1 HUGEGRAPH_GIT_URL="https://github.com/hugegraph/hugegraph.git" +GIT_DIR=hugegraph +# download code and compile git clone --depth 100 ${HUGEGRAPH_GIT_URL} -cd hugegraph +cd "${GIT_DIR}" git checkout ${COMMIT_ID} mvn package -DskipTests -mv hugegraph-*.tar.gz ../ + +TAR=$(echo hugegraph-*.tar.gz) +tar -zxvf "${TAR}" -C ../ cd ../ -rm -rf hugegraph -tar -zxvf hugegraph-*.tar.gz +rm -rf "${GIT_DIR}" +HTTP_SERVER_DIR=$(echo hugegraph-*) HTTPS_SERVER_DIR="hugegraph_https" -mkdir ${HTTPS_SERVER_DIR} -cp -r hugegraph-*/. ${HTTPS_SERVER_DIR} -cd "$(find hugegraph-* | head -1)" -cp ../$TRAVIS_DIR/conf/* conf + +cp -r "${HTTP_SERVER_DIR}" "${HTTPS_SERVER_DIR}" + +# config auth options just for http server (must keep '/.') +cp -rf "${TRAVIS_DIR}"/conf/. "${HTTP_SERVER_DIR}"/conf/ + # start HugeGraphServer with http protocol +cd "${HTTP_SERVER_DIR}" echo -e "pa" | bin/init-store.sh || exit 1 bin/start-hugegraph.sh || exit 1 -cd ../${HTTPS_SERVER_DIR} +# config options for https server +cd ../"${HTTPS_SERVER_DIR}" REST_SERVER_CONFIG="conf/rest-server.properties" GREMLIN_SERVER_CONFIG="conf/gremlin-server.yaml" sed -i "s?http://127.0.0.1:8080?https://127.0.0.1:8443?g" "$REST_SERVER_CONFIG" diff --git a/assembly/travis/install-hugegraph-from-tar.sh b/assembly/travis/install-hugegraph-from-tar.sh deleted file mode 100755 index 6c546ddb..00000000 --- a/assembly/travis/install-hugegraph-from-tar.sh +++ /dev/null @@ -1,69 +0,0 @@ -#!/bin/bash - -set -ev - -TRAVIS_DIR=`dirname $0` - -if [ $# -ne 1 ]; then - echo "Must pass base branch name of pull request" - exit 1 -fi - -CLIENT_BRANCH=$1 -HUGEGRAPH_BRANCH=$CLIENT_BRANCH - -HUGEGRAPH_GIT_URL="https://github.com/hugegraph/hugegraph.git" - -git clone $HUGEGRAPH_GIT_URL - -cd hugegraph - -git checkout $HUGEGRAPH_BRANCH - -mvn package -DskipTests - -mv hugegraph-*.tar.gz ../ - -cd ../ - -rm -rf hugegraph - -tar -zxvf hugegraph-*.tar.gz - -HTTPS_SERVER_DIR="hugegraph_https" - -mkdir $HTTPS_SERVER_DIR - -cp -r hugegraph-*/. $HTTPS_SERVER_DIR - -cd hugegraph-* - -cp ../$TRAVIS_DIR/conf/* conf - -echo -e "pa" | bin/init-store.sh - -bin/start-hugegraph.sh - -cd ../ - -cd $HTTPS_SERVER_DIR - -REST_SERVER_CONFIG="conf/rest-server.properties" - -GREMLIN_SERVER_CONFIG="conf/gremlin-server.yaml" - -sed -i "s?http://127.0.0.1:8080?https://127.0.0.1:8443?g" "$REST_SERVER_CONFIG" - -sed -i "s/#port: 8182/port: 8282/g" "$GREMLIN_SERVER_CONFIG" - -echo "ssl.keystore_password=hugegraph" >> $REST_SERVER_CONFIG - -echo "ssl.keystore_file=conf/hugegraph-server.keystore" >> $REST_SERVER_CONFIG - -echo "gremlinserver.url=http://127.0.0.1:8282" >> $REST_SERVER_CONFIG - -bin/init-store.sh - -bin/start-hugegraph.sh - -cd ../ diff --git a/src/main/java/com/baidu/hugegraph/api/graphs/GraphsAPI.java b/src/main/java/com/baidu/hugegraph/api/graphs/GraphsAPI.java index 81b2d167..f33d3ea4 100644 --- a/src/main/java/com/baidu/hugegraph/api/graphs/GraphsAPI.java +++ b/src/main/java/com/baidu/hugegraph/api/graphs/GraphsAPI.java @@ -27,6 +27,8 @@ import javax.ws.rs.core.MultivaluedHashMap; import javax.ws.rs.core.MultivaluedMap; +import org.apache.commons.lang3.StringUtils; + import com.baidu.hugegraph.api.API; import com.baidu.hugegraph.client.RestClient; import com.baidu.hugegraph.exception.InvalidResponseException; @@ -38,10 +40,12 @@ public class GraphsAPI extends API { - private static final String CONFIRM_MESSAGE = "confirm_message"; private static final String DELIMITER = "/"; private static final String MODE = "mode"; private static final String GRAPH_READ_MODE = "graph_read_mode"; + private static final String CLEAR = "clear"; + + private static final String CONFIRM_MESSAGE = "confirm_message"; public GraphsAPI(RestClient client) { super(client); @@ -60,7 +64,7 @@ public Map create(String name, String cloneGraphName, MultivaluedMap headers = new MultivaluedHashMap<>(); headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON); Map params = null; - if (cloneGraphName != null && !cloneGraphName.isEmpty()) { + if (StringUtils.isNotEmpty(cloneGraphName)) { params = ImmutableMap.of("clone_graph_name", cloneGraphName); } RestResult result = this.client.post(joinPath(this.path(), name), @@ -80,11 +84,11 @@ public List list() { } public void clear(String graph, String message) { - this.client.delete(joinPath(this.path(), graph, "clear"), + this.client.delete(joinPath(this.path(), graph, CLEAR), ImmutableMap.of(CONFIRM_MESSAGE, message)); } - public void delete(String graph, String message) { + public void drop(String graph, String message) { this.client.checkApiVersion("0.67", "dynamic graph delete"); this.client.delete(joinPath(this.path(), graph), ImmutableMap.of(CONFIRM_MESSAGE, message)); @@ -93,12 +97,11 @@ public void delete(String graph, String message) { public void mode(String graph, GraphMode mode) { // NOTE: Must provide id for PUT. If use "graph/mode", "/" will // be encoded to "%2F". So use "mode" here although inaccurate. - this.client.put(joinPath(this.path(), graph), MODE, mode); + this.client.put(joinPath(this.path(), graph, MODE), null, mode); } public GraphMode mode(String graph) { - RestResult result = this.client.get(joinPath(this.path(), graph), - MODE); + RestResult result = this.client.get(joinPath(this.path(), graph), MODE); @SuppressWarnings("unchecked") Map mode = result.readObject(Map.class); String value = mode.get(MODE); @@ -119,14 +122,14 @@ public void readMode(String graph, GraphReadMode readMode) { // NOTE: Must provide id for PUT. If use "graph/graph_read_mode", "/" // will be encoded to "%2F". So use "graph_read_mode" here although // inaccurate. - this.client.put(joinPath(this.path(), graph), - GRAPH_READ_MODE, readMode); + this.client.put(joinPath(this.path(), graph, GRAPH_READ_MODE), + null, readMode); } public GraphReadMode readMode(String graph) { this.client.checkApiVersion("0.59", "graph read mode"); - RestResult result = this.client.get(joinPath(this.path(), graph), - GRAPH_READ_MODE); + RestResult result = this.client.get(joinPath(this.path(), graph), + GRAPH_READ_MODE); @SuppressWarnings("unchecked") Map readMode = result.readObject(Map.class); String value = readMode.get(GRAPH_READ_MODE); @@ -142,11 +145,11 @@ public GraphReadMode readMode(String graph) { } } - private static String joinPath(String path, String id) { - return String.join(DELIMITER, path, id); + private static String joinPath(String path, String graph) { + return String.join(DELIMITER, path, graph); } - private static String joinPath(String path, String id, String action) { - return String.join(DELIMITER, path, id, action); + private static String joinPath(String path, String graph, String action) { + return String.join(DELIMITER, path, graph, action); } } diff --git a/src/main/java/com/baidu/hugegraph/driver/GraphsManager.java b/src/main/java/com/baidu/hugegraph/driver/GraphsManager.java index a58831b8..bbb933ad 100644 --- a/src/main/java/com/baidu/hugegraph/driver/GraphsManager.java +++ b/src/main/java/com/baidu/hugegraph/driver/GraphsManager.java @@ -19,18 +19,11 @@ package com.baidu.hugegraph.driver; -import java.io.File; -import java.io.IOException; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; import java.util.List; import java.util.Map; -import org.apache.commons.io.FileUtils; - import com.baidu.hugegraph.api.graphs.GraphsAPI; import com.baidu.hugegraph.client.RestClient; -import com.baidu.hugegraph.rest.ClientException; import com.baidu.hugegraph.structure.constant.GraphMode; import com.baidu.hugegraph.structure.constant.GraphReadMode; @@ -42,34 +35,17 @@ public GraphsManager(RestClient client) { this.graphsAPI = new GraphsAPI(client); } - public Map createGraph(String name, String config) { - return this.createGraph(name, null, config); - } - - public Map createGraph(String name, String cloneGraphName, - String config) { - return this.graphsAPI.create(name, cloneGraphName, config); + public Map createGraph(String name, String configText) { + return this.graphsAPI.create(name, null, configText); } - public Map createGraph(String name, File file) { - String config; - try { - config = FileUtils.readFileToString(file, StandardCharsets.UTF_8); - } catch (IOException e) { - throw new ClientException("Failed to read config file: %s", file); - } - return this.createGraph(name, config); + public Map cloneGraph(String name, String cloneGraphName) { + return this.graphsAPI.create(name, cloneGraphName, null); } - public Map createGraph(String name, String cloneGraphName, - File file) { - String config; - try { - config = FileUtils.readFileToString(file, StandardCharsets.UTF_8); - } catch (IOException e) { - throw new ClientException("Failed to read config file: %s", file); - } - return this.createGraph(name, cloneGraphName, config); + public Map cloneGraph(String name, String cloneGraphName, + String configText) { + return this.graphsAPI.create(name, cloneGraphName, configText); } public Map getGraph(String graph) { @@ -80,12 +56,12 @@ public List listGraph() { return this.graphsAPI.list(); } - public void clear(String graph, String message) { + public void clearGraph(String graph, String message) { this.graphsAPI.clear(graph, message); } - public void remove(String graph, String message) { - this.graphsAPI.delete(graph, message); + public void dropGraph(String graph, String message) { + this.graphsAPI.drop(graph, message); } public void mode(String graph, GraphMode mode) { diff --git a/src/main/java/com/baidu/hugegraph/driver/HugeClient.java b/src/main/java/com/baidu/hugegraph/driver/HugeClient.java index 12325406..6f214e4e 100644 --- a/src/main/java/com/baidu/hugegraph/driver/HugeClient.java +++ b/src/main/java/com/baidu/hugegraph/driver/HugeClient.java @@ -34,6 +34,8 @@ public class HugeClient implements Closeable { ClientVersion.check(); } private final RestClient client; + private final boolean borrowedClient; + private VersionManager version; private GraphsManager graphs; private SchemaManager schema; @@ -47,6 +49,7 @@ public class HugeClient implements Closeable { private MetricsManager metrics; public HugeClient(HugeClientBuilder builder) { + this.borrowedClient = false; try { this.client = new RestClient(builder.url(), builder.username(), @@ -57,7 +60,8 @@ public HugeClient(HugeClientBuilder builder) { builder.trustStoreFile(), builder.trustStorePassword()); } catch (ProcessingException e) { - throw new ClientException("Failed to connect url '%s'", builder.url()); + throw new ClientException("Failed to connect url '%s'", + builder.url()); } try { this.initManagers(this.client, builder.graph()); @@ -67,13 +71,21 @@ public HugeClient(HugeClientBuilder builder) { } } + public HugeClient(HugeClient client, String graph) { + this.borrowedClient = true; + this.client = client.client; + this.initManagers(this.client, graph); + } + public static HugeClientBuilder builder(String url, String graph) { return new HugeClientBuilder(url, graph); } @Override public void close() { - this.client.close(); + if (!this.borrowedClient) { + this.client.close(); + } } private void initManagers(RestClient client, String graph) { diff --git a/src/test/java/com/baidu/hugegraph/api/GraphsApiTest.java b/src/test/java/com/baidu/hugegraph/api/GraphsApiTest.java index 59e0cb64..b9c9cfbe 100644 --- a/src/test/java/com/baidu/hugegraph/api/GraphsApiTest.java +++ b/src/test/java/com/baidu/hugegraph/api/GraphsApiTest.java @@ -27,6 +27,7 @@ import java.util.Map; import org.apache.commons.io.FileUtils; +import org.junit.After; import org.junit.Test; import com.baidu.hugegraph.driver.HugeClient; @@ -36,19 +37,33 @@ import com.baidu.hugegraph.structure.graph.Vertex; import com.baidu.hugegraph.structure.gremlin.ResultSet; import com.baidu.hugegraph.testutil.Assert; +import com.google.common.collect.ImmutableSet; public class GraphsApiTest extends BaseApiTest { private static final String GRAPH2 = "hugegraph2"; private static final String CONFIG2_PATH = - "src/test/resources/hugegraph2.properties"; + "src/test/resources/hugegraph-create.properties"; private static final String GRAPH3 = "hugegraph3"; private static final String CONFIG3_PATH = - "src/test/resources/hugegraph3.properties"; + "src/test/resources/hugegraph-clone.properties"; + + @Override + @After + public void teardown() { + for (String g : ImmutableSet.of(GRAPH2, GRAPH3)) { + try { + graphsAPI.get(g); + } catch (Exception ognored) { + continue; + } + graphsAPI.drop(g, "I'm sure to drop the graph"); + } + } @Test - public void testCreateAndRemoveGraph() { + public void testCreateAndDropGraph() { int initialGraphNumber = graphsAPI.list().size(); // Create new graph dynamically @@ -67,7 +82,7 @@ public void testCreateAndRemoveGraph() { Assert.assertEquals(initialGraphNumber + 1, graphsAPI.list().size()); - HugeClient client = HugeClient.builder(BASE_URL, GRAPH2).build(); + HugeClient client = new HugeClient(baseClient(), GRAPH2); // Insert graph schema and data initPropertyKey(client); initVertexLabel(client); @@ -113,16 +128,16 @@ public void testCreateAndRemoveGraph() { Assert.assertEquals(initialGraphNumber + 1, graphsAPI.list().size()); // Remove new created graph dynamically - graphsAPI.delete(GRAPH2, "I'm sure to drop the graph"); + graphsAPI.drop(GRAPH2, "I'm sure to drop the graph"); Assert.assertEquals(initialGraphNumber, graphsAPI.list().size()); } @Test - public void testCreateWithCloneAndRemoveGraph() { + public void testCloneAndDropGraph() { int initialGraphNumber = graphsAPI.list().size(); - // Create new graph dynamically + // Clone a new graph from exist a graph dynamically String config; try { config = FileUtils.readFileToString(new File(CONFIG3_PATH), @@ -139,7 +154,72 @@ public void testCreateWithCloneAndRemoveGraph() { Assert.assertEquals(initialGraphNumber + 1, graphsAPI.list().size()); - HugeClient client = HugeClient.builder(BASE_URL, GRAPH3).build(); + HugeClient client = new HugeClient(baseClient(), GRAPH3); + // Insert graph schema and data + initPropertyKey(client); + initVertexLabel(client); + initEdgeLabel(client); + + List vertices = new ArrayList<>(100); + for (int i = 0; i < 100; i++) { + Vertex vertex = new Vertex("person").property("name", "person" + i) + .property("city", "Beijing") + .property("age", 19); + vertices.add(vertex); + } + vertices = client.graph().addVertices(vertices); + + List edges = new ArrayList<>(100); + for (int i = 0; i < 100; i++) { + Edge edge = new Edge("knows").source(vertices.get(i)) + .target(vertices.get((i + 1) % 100)) + .property("date", "2016-01-10"); + edges.add(edge); + } + client.graph().addEdges(edges, false); + + // Query vertices and edges count from new created graph + ResultSet resultSet = client.gremlin().gremlin("g.V().count()") + .execute(); + Assert.assertEquals(100, resultSet.iterator().next().getInt()); + + resultSet = client.gremlin().gremlin("g.E().count()").execute(); + Assert.assertEquals(100, resultSet.iterator().next().getInt()); + + // Clear graph schema and data from new created graph + graphsAPI.clear(GRAPH3, "I'm sure to delete all data"); + + resultSet = client.gremlin().gremlin("g.V().count()").execute(); + Assert.assertEquals(0, resultSet.iterator().next().getInt()); + + resultSet = client.gremlin().gremlin("g.E().count()").execute(); + Assert.assertEquals(0, resultSet.iterator().next().getInt()); + + Assert.assertTrue(client.schema().getPropertyKeys().isEmpty()); + + Assert.assertEquals(initialGraphNumber + 1, graphsAPI.list().size()); + + // Remove new created graph dynamically + graphsAPI.drop(GRAPH3, "I'm sure to drop the graph"); + + Assert.assertEquals(initialGraphNumber, graphsAPI.list().size()); + } + + @Test + public void testCloneAndDropGraphWithoutConfig() { + int initialGraphNumber = graphsAPI.list().size(); + + // Clone a new graph from exist a graph dynamically + String config = null; + Map result = graphsAPI.create(GRAPH3, "hugegraph", + config); + Assert.assertEquals(2, result.size()); + Assert.assertEquals(GRAPH3, result.get("name")); + Assert.assertEquals("rocksdb", result.get("backend")); + + Assert.assertEquals(initialGraphNumber + 1, graphsAPI.list().size()); + + HugeClient client = new HugeClient(baseClient(), GRAPH3); // Insert graph schema and data initPropertyKey(client); initVertexLabel(client); @@ -185,7 +265,7 @@ public void testCreateWithCloneAndRemoveGraph() { Assert.assertEquals(initialGraphNumber + 1, graphsAPI.list().size()); // Remove new created graph dynamically - graphsAPI.delete(GRAPH3, "I'm sure to drop the graph"); + graphsAPI.drop(GRAPH3, "I'm sure to drop the graph"); Assert.assertEquals(initialGraphNumber, graphsAPI.list().size()); } diff --git a/src/test/resources/hugegraph3.properties b/src/test/resources/hugegraph-clone.properties similarity index 65% rename from src/test/resources/hugegraph3.properties rename to src/test/resources/hugegraph-clone.properties index 5d55a2bb..712b6636 100644 --- a/src/test/resources/hugegraph3.properties +++ b/src/test/resources/hugegraph-clone.properties @@ -1,5 +1,3 @@ -backend=rocksdb -serializer=binary store=hugegraph3 rocksdb.data_path=./hg3 rocksdb.wal_path=./hg3 diff --git a/src/test/resources/hugegraph2.properties b/src/test/resources/hugegraph-create.properties similarity index 62% rename from src/test/resources/hugegraph2.properties rename to src/test/resources/hugegraph-create.properties index 7c5d26b8..cc022b02 100644 --- a/src/test/resources/hugegraph2.properties +++ b/src/test/resources/hugegraph-create.properties @@ -1,3 +1,4 @@ +gremlin.graph=com.baidu.hugegraph.auth.HugeFactoryAuthProxy backend=rocksdb serializer=binary store=hugegraph2