From 8652bd97abf6d490155cfcca56cc27a44cd53368 Mon Sep 17 00:00:00 2001 From: liningrui Date: Mon, 24 Dec 2018 15:39:40 +0800 Subject: [PATCH] Add travis api-test Change-Id: I01d10dc092f2f2147155bc2b523b49e741d8d571 --- .travis.yml | 3 +- .../src/assembly/travis/install-cassandra.sh | 2 +- .../src/assembly/travis/install-hbase.sh | 2 +- .../src/assembly/travis/start-server.sh | 22 ++++++++ .../backend/store/hbase/HbaseSessions.java | 1 - hugegraph-test/pom.xml | 12 +++++ .../com/baidu/hugegraph/api/ApiTestSuite.java | 3 +- .../com/baidu/hugegraph/api/BaseApiTest.java | 53 ++++++++++++++++++- .../baidu/hugegraph/core/CoreTestSuite.java | 5 +- pom.xml | 21 ++++++++ 10 files changed, 113 insertions(+), 11 deletions(-) create mode 100755 hugegraph-dist/src/assembly/travis/start-server.sh diff --git a/.travis.yml b/.travis.yml index 3e5db076b6..91cce0cef6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,7 +22,8 @@ before_script: - $TRAVIS_DIR/install-backend.sh script: - - mvn test -P core-test,$BACKEND + - mvn test -P core-test,$BACKEND && + mvn package -DskipTests && $TRAVIS_DIR/start-server.sh && mvn test -P api-test,$BACKEND - | if [ "$BACKEND" == "memory" ]; then mvn test -P unit-test diff --git a/hugegraph-dist/src/assembly/travis/install-cassandra.sh b/hugegraph-dist/src/assembly/travis/install-cassandra.sh index 3d11311aa6..7df6f5d424 100755 --- a/hugegraph-dist/src/assembly/travis/install-cassandra.sh +++ b/hugegraph-dist/src/assembly/travis/install-cassandra.sh @@ -16,7 +16,7 @@ fi # decompress cassandra cp $HOME/downloads/${CASSA_TAR} ${CASSA_TAR} && tar xzf ${CASSA_TAR} -# Using tmpfs for the Cassandra data directory reduces travis test runtime by +# using tmpfs for the Cassandra data directory reduces travis test runtime sudo mkdir /mnt/ramdisk sudo mount -t tmpfs -o size=1024m tmpfs /mnt/ramdisk sudo ln -s /mnt/ramdisk $CASSA_PACKAGE/data diff --git a/hugegraph-dist/src/assembly/travis/install-hbase.sh b/hugegraph-dist/src/assembly/travis/install-hbase.sh index a074a74fc5..700254890e 100755 --- a/hugegraph-dist/src/assembly/travis/install-hbase.sh +++ b/hugegraph-dist/src/assembly/travis/install-hbase.sh @@ -16,7 +16,7 @@ fi # decompress hbase sudo cp $HOME/downloads/${HBASE_TAR} ${HBASE_TAR} && tar xzf ${HBASE_TAR} -# Using tmpfs for the Hbase data directory reduces travis test runtime by +# using tmpfs for the Hbase data directory reduces travis test runtime sudo mkdir /mnt/ramdisk sudo mount -t tmpfs -o size=1024m tmpfs /mnt/ramdisk sudo ln -s /mnt/ramdisk /tmp/hbase diff --git a/hugegraph-dist/src/assembly/travis/start-server.sh b/hugegraph-dist/src/assembly/travis/start-server.sh new file mode 100755 index 0000000000..873151d722 --- /dev/null +++ b/hugegraph-dist/src/assembly/travis/start-server.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +set -ev + +VERSION=`mvn help:evaluate -Dexpression=project.version -q -DforceStdout` +BASE_DIR=hugegraph-$VERSION +BIN=$BASE_DIR/bin +CONF=$BASE_DIR/conf/hugegraph.properties + +declare -A backend_serializer_map=(["memory"]="text" ["cassandra"]="cassandra" \ + ["scylladb"]="scylladb" ["mysql"]="mysql" \ + ["hbase"]="hbase" ["rocksdb"]="binary") + +SERIALIZER=${backend_serializer_map[$BACKEND]} + +sed -i "s/backend=.*/backend=$BACKEND/" $CONF +sed -i "s/serializer=.*/serializer=$SERIALIZER/" $CONF + +# Append schema.sync_deletion=true to config file +echo "schema.sync_deletion=true" >> $CONF + +$BIN/init-store.sh && $BIN/start-hugegraph.sh diff --git a/hugegraph-hbase/src/main/java/com/baidu/hugegraph/backend/store/hbase/HbaseSessions.java b/hugegraph-hbase/src/main/java/com/baidu/hugegraph/backend/store/hbase/HbaseSessions.java index 6f116de4a5..937645cc6f 100644 --- a/hugegraph-hbase/src/main/java/com/baidu/hugegraph/backend/store/hbase/HbaseSessions.java +++ b/hugegraph-hbase/src/main/java/com/baidu/hugegraph/backend/store/hbase/HbaseSessions.java @@ -23,7 +23,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.List; diff --git a/hugegraph-test/pom.xml b/hugegraph-test/pom.xml index 5412cb2c10..5cf6edba6b 100644 --- a/hugegraph-test/pom.xml +++ b/hugegraph-test/pom.xml @@ -66,6 +66,18 @@ + + api-test + + ${basedir}/src/main/java/ + + ${basedir}/target/classes/ + + + **/ApiTestSuite.java + + + tinkerpop-structure-test diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/ApiTestSuite.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/ApiTestSuite.java index 6a2cd2e12c..fd6ffd34a0 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/ApiTestSuite.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/ApiTestSuite.java @@ -19,7 +19,6 @@ package com.baidu.hugegraph.api; -import org.apache.commons.configuration.ConfigurationException; import org.junit.BeforeClass; import org.junit.runner.RunWith; import org.junit.runners.Suite; @@ -40,7 +39,7 @@ public class ApiTestSuite { @BeforeClass - public static void initEnv() throws ConfigurationException { + public static void initEnv() { RegisterUtil.registerBackends(); } } diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/BaseApiTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/BaseApiTest.java index c14b1e4ce0..90285063b7 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/BaseApiTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/BaseApiTest.java @@ -23,6 +23,8 @@ import java.net.URLEncoder; import java.util.List; import java.util.Map; +import java.util.function.Consumer; +import java.util.stream.Collectors; import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder; @@ -53,10 +55,8 @@ public class BaseApiTest { private static final String SCHEMA_PKS = "/schema/propertykeys"; private static final String SCHEMA_VLS = "/schema/vertexlabels"; private static final String SCHEMA_ELS = "/schema/edgelabels"; - @SuppressWarnings("unused") private static final String SCHEMA_ILS = "/schema/indexlabels"; private static final String GRAPH_VERTEX = "/graph/vertices"; - @SuppressWarnings("unused") private static final String GRAPH_EDGE = "/graph/edges"; private static RestClient client; @@ -329,6 +329,50 @@ protected static String getVertexId(String label, String key, String value) return (String) list.get(0).get("id"); } + protected static void clearGraph() { + Consumer consumer = (urlSuffix) -> { + String path = URL_PREFIX + urlSuffix; + String type = urlSuffix.substring(urlSuffix.lastIndexOf('/') + 1); + Response r = client.get(path); + if (r.getStatus() != 200) { + throw new HugeException("Failed to list " + type); + } + String content = r.readEntity(String.class); + List list = readList(content, type, Map.class); + List ids = list.stream().map(e -> e.get("id")) + .collect(Collectors.toList()); + ids.forEach(id -> { + client.delete(path, (String) id); + }); + }; + + consumer.accept(GRAPH_EDGE); + consumer.accept(GRAPH_VERTEX); + } + + protected static void clearSchema() { + Consumer consumer = (urlSuffix) -> { + String path = URL_PREFIX + urlSuffix; + String type = urlSuffix.substring(urlSuffix.lastIndexOf('/') + 1); + Response r = client.get(path); + if (r.getStatus() != 200) { + throw new HugeException("Failed to list " + type); + } + String content = r.readEntity(String.class); + List list = readList(content, type, Map.class); + List names = list.stream().map(e -> e.get("name")) + .collect(Collectors.toList()); + names.forEach(name -> { + client.delete(path, (String) name); + }); + }; + + consumer.accept(SCHEMA_ILS); + consumer.accept(SCHEMA_ELS); + consumer.accept(SCHEMA_VLS); + consumer.accept(SCHEMA_PKS); + } + protected static String parseId(String content) throws IOException { Map map = mapper.readValue(content, Map.class); return (String) map.get("id"); @@ -354,6 +398,11 @@ protected static List readList(String content, } protected static void clearData() { + clearGraph(); + clearSchema(); + } + + protected static void truncate() { String token = "162f7848-0b6d-4faf-b557-3a0797869c55"; String message = "I'm sure to delete all data"; diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/core/CoreTestSuite.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/core/CoreTestSuite.java index 85da8b9906..0f1b713720 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/core/CoreTestSuite.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/core/CoreTestSuite.java @@ -19,7 +19,6 @@ package com.baidu.hugegraph.core; -import org.apache.commons.configuration.ConfigurationException; import org.junit.AfterClass; import org.junit.Assert; import org.junit.BeforeClass; @@ -53,7 +52,7 @@ public class CoreTestSuite { private static HugeGraph graph = null; @BeforeClass - public static void initEnv() throws ConfigurationException { + public static void initEnv() { RegisterUtil.registerBackends(); } @@ -65,7 +64,7 @@ public static void init() { } @AfterClass - public static void clear() throws Exception { + public static void clear() { if (graph == null) { return; } diff --git a/pom.xml b/pom.xml index fa28d63ab6..277a46f329 100644 --- a/pom.xml +++ b/pom.xml @@ -392,6 +392,27 @@ + + api-test + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.20 + + + api-test + + test + + test + + + + + + tinkerpop-structure-test