diff --git a/hugegraph-cluster-test/hugegraph-clustertest-dist/pom.xml b/hugegraph-cluster-test/hugegraph-clustertest-dist/pom.xml index 7ec79efba0..e318f06bd0 100644 --- a/hugegraph-cluster-test/hugegraph-clustertest-dist/pom.xml +++ b/hugegraph-cluster-test/hugegraph-clustertest-dist/pom.xml @@ -1,19 +1,19 @@ diff --git a/hugegraph-cluster-test/hugegraph-clustertest-dist/src/assembly/static/conf/hugegraph.properties.template b/hugegraph-cluster-test/hugegraph-clustertest-dist/src/assembly/static/conf/hugegraph.properties.template index 2a086bd325..005031fe60 100644 --- a/hugegraph-cluster-test/hugegraph-clustertest-dist/src/assembly/static/conf/hugegraph.properties.template +++ b/hugegraph-cluster-test/hugegraph-clustertest-dist/src/assembly/static/conf/hugegraph.properties.template @@ -16,8 +16,7 @@ # # gremlin entrance to create graph -# auth config: org.apache.hugegraph.auth.HugeFactoryAuthProxy -gremlin.graph=org.apache.hugegraph.HugeFactory +gremlin.graph=org.apache.hugegraph.auth.HugeFactoryAuthProxy # cache config #schema.cache_capacity=100000 diff --git a/hugegraph-cluster-test/hugegraph-clustertest-dist/src/assembly/static/conf/rest-server.properties.template b/hugegraph-cluster-test/hugegraph-clustertest-dist/src/assembly/static/conf/rest-server.properties.template index 106b171767..01744ac2c0 100644 --- a/hugegraph-cluster-test/hugegraph-clustertest-dist/src/assembly/static/conf/rest-server.properties.template +++ b/hugegraph-cluster-test/hugegraph-clustertest-dist/src/assembly/static/conf/rest-server.properties.template @@ -34,10 +34,14 @@ arthas.ip=127.0.0.1 arthas.disabled_commands=jad # authentication configs -# choose 'org.apache.hugegraph.auth.StandardAuthenticator' or a custom implementation -#auth.authenticator= -# for admin password, By default, it is pa and takes effect upon the first startup -#auth.admin_pa=pa +# choose 'org.apache.hugegraph.auth.StandardAuthenticator' or +# 'org.apache.hugegraph.auth.ConfigAuthenticator' +auth.authenticator=org.apache.hugegraph.auth.StandardAuthenticator +# true if using hstore mode +usePD=true + +# default password +auth.admin_pa=pa # for StandardAuthenticator mode #auth.graph_store=hugegraph diff --git a/hugegraph-cluster-test/hugegraph-clustertest-minicluster/pom.xml b/hugegraph-cluster-test/hugegraph-clustertest-minicluster/pom.xml index 8feb6181f2..b59648304f 100644 --- a/hugegraph-cluster-test/hugegraph-clustertest-minicluster/pom.xml +++ b/hugegraph-cluster-test/hugegraph-clustertest-minicluster/pom.xml @@ -1,19 +1,19 @@ 11 11 UTF-8 - 2.17.0 diff --git a/hugegraph-cluster-test/hugegraph-clustertest-minicluster/src/main/java/org/apache/hugegraph/ct/node/ServerNodeWrapper.java b/hugegraph-cluster-test/hugegraph-clustertest-minicluster/src/main/java/org/apache/hugegraph/ct/node/ServerNodeWrapper.java index e39bc39557..e16b96781e 100644 --- a/hugegraph-cluster-test/hugegraph-clustertest-minicluster/src/main/java/org/apache/hugegraph/ct/node/ServerNodeWrapper.java +++ b/hugegraph-cluster-test/hugegraph-clustertest-minicluster/src/main/java/org/apache/hugegraph/ct/node/ServerNodeWrapper.java @@ -34,15 +34,21 @@ import static org.apache.hugegraph.ct.base.ClusterConstant.SERVER_TEMPLATE_PATH; import static org.apache.hugegraph.ct.base.ClusterConstant.isJava11OrHigher; +import java.io.BufferedReader; import java.io.File; import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; public class ServerNodeWrapper extends AbstractNodeWrapper { + private static List hgJars = loadHgJarsOnce(); public ServerNodeWrapper(int clusterIndex, int index) { super(clusterIndex, index); this.fileNames = new ArrayList<>( @@ -67,6 +73,38 @@ private static void addJarsToClasspath(File directory, List classpath) { } } + private static void addOrderedJarsToClasspath(File directory, List classpath) { + // Add jar starts with hugegraph in proper order + String path = directory.getAbsolutePath(); + for (String jar : hgJars) { + classpath.add(path + File.separator + jar); + } + if (directory.exists() && directory.isDirectory()) { + File[] files = + directory.listFiles((dir, name) -> name.endsWith(".jar") && !name.contains( + "hugegraph")); + if (files != null) { + for (File file : files) { + classpath.add(file.getAbsolutePath()); + } + } + } + } + + private static List loadHgJarsOnce(){ + ArrayList jars = new ArrayList<>(); + try (InputStream is = ServerNodeWrapper.class.getResourceAsStream("/jar.txt"); + BufferedReader reader = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))) { + String line; + while ((line = reader.readLine()) != null) { + jars.add(line); + } + } catch (IOException e) { + e.printStackTrace(); + } + return Collections.unmodifiableList(jars); + } + @Override public void start() { try { @@ -79,7 +117,7 @@ public void start() { } List classpath = new ArrayList<>(); - addJarsToClasspath(new File(workPath + LIB_DIR), classpath); + addOrderedJarsToClasspath(new File(workPath + LIB_DIR), classpath); addJarsToClasspath(new File(workPath + EXT_DIR), classpath); addJarsToClasspath(new File(workPath + PLUGINS_DIR), classpath); String storeClassPath = String.join(":", classpath); @@ -87,6 +125,8 @@ public void start() { startCmd.addAll(Arrays.asList( "-Dname=HugeGraphServer" + this.index, "--add-exports=java.base/jdk.internal.reflect=ALL-UNNAMED", + "--add-modules=jdk.unsupported", + "--add-exports=java.base/sun.nio.ch=ALL-UNNAMED", "-cp", storeClassPath, "org.apache.hugegraph.dist.HugeGraphServer", "./conf/gremlin-server.yaml", diff --git a/hugegraph-cluster-test/hugegraph-clustertest-test/pom.xml b/hugegraph-cluster-test/hugegraph-clustertest-test/pom.xml index c888404545..735ea66b43 100644 --- a/hugegraph-cluster-test/hugegraph-clustertest-test/pom.xml +++ b/hugegraph-cluster-test/hugegraph-clustertest-test/pom.xml @@ -1,19 +1,19 @@ 4.13.2 compile + + jakarta.ws.rs + jakarta.ws.rs-api + 3.0.0 + + + org.glassfish.jersey.inject + jersey-hk2 + 3.0.3 + test + + + org.glassfish.jersey.core + jersey-client + 3.0.3 + compile + @@ -92,6 +109,31 @@ + + org.apache.maven.plugins + maven-resources-plugin + + + generate-version + process-resources + + copy-resources + + + ${project.build.directory}/classes + + + src/main/resources + true + + jar.txt + + + + + + + diff --git a/hugegraph-cluster-test/hugegraph-clustertest-test/src/main/java/org/apache/hugegraph/MultiClusterTest/BaseMultiClusterTest.java b/hugegraph-cluster-test/hugegraph-clustertest-test/src/main/java/org/apache/hugegraph/MultiClusterTest/BaseMultiClusterTest.java index 59394101c2..af640b3a94 100644 --- a/hugegraph-cluster-test/hugegraph-clustertest-test/src/main/java/org/apache/hugegraph/MultiClusterTest/BaseMultiClusterTest.java +++ b/hugegraph-cluster-test/hugegraph-clustertest-test/src/main/java/org/apache/hugegraph/MultiClusterTest/BaseMultiClusterTest.java @@ -20,32 +20,73 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; +import org.apache.hugegraph.SimpleClusterTest.BaseSimpleTest; +import org.apache.hugegraph.SimpleClusterTest.BaseSimpleTest.RestClient; import org.apache.hugegraph.ct.env.BaseEnv; import org.apache.hugegraph.ct.env.MultiNodeEnv; +import org.apache.hugegraph.serializer.direct.util.HugeException; import org.junit.AfterClass; +import org.junit.Assert; import org.junit.BeforeClass; +import jakarta.ws.rs.core.Response; + /** * MultiNode Test generate the cluster env with 3 pd node + 3 store node + 3 server node. * Or you can set different num of nodes by using env = new MultiNodeEnv(pdNum, storeNum, serverNum) * All nodes are deployed in ports generated randomly, the application of nodes are stored - * in /apache-hugegraph-ct-incubating-1.5.0, you can visit each node with rest api. + * in /apache-hugegraph-ct-incubating-1.7.0, you can visit each node with rest api. */ public class BaseMultiClusterTest { protected static BaseEnv env; protected static Process p; + protected static List clients = new ArrayList<>(); + protected static String BASE_URL = "http://"; + protected static final String GRAPH = "hugegraphapi"; + protected static final String URL_PREFIX = "graphspaces/DEFAULT/graphs/" + GRAPH; + protected static final String SCHEMA_PKS = "/schema/propertykeys"; @BeforeClass public static void initEnv() { env = new MultiNodeEnv(); env.startCluster(); + clients.clear(); + for (String addr : env.getServerRestAddrs()) { + clients.add(new RestClient(BASE_URL + addr)); + } + initGraph(); } @AfterClass public static void clearEnv() { env.stopCluster(); + for (RestClient client : clients) { + client.close(); + } + } + + protected static void initGraph() { + BaseSimpleTest.RestClient client = clients.get(0); + Response r = client.get(URL_PREFIX); + if (r.getStatus() != 200) { + String body = "{\n" + + " \"backend\": \"hstore\",\n" + + " \"serializer\": \"binary\",\n" + + " \"store\": \"hugegraphapi\",\n" + + " \"search.text_analyzer\": \"jieba\",\n" + + " \"search.text_analyzer_mode\": \"INDEX\"\n" + + "}"; + r = client.post(URL_PREFIX, body); + if (r.getStatus() != 201) { + throw new HugeException(String.format( + "Failed to initialize graph %s %s",GRAPH, r.readEntity(String.class) + )); + } + } } protected String execCmd(String[] cmds) throws IOException { @@ -61,4 +102,21 @@ protected String execCmd(String[] cmds) throws IOException { p.destroy(); return builder.toString(); } + + protected static String assertResponseStatus(int status, + Response response) { + String content = response.readEntity(String.class); + String message = String.format("Response with status %s and content %s", + response.getStatus(), content); + Assert.assertEquals(message, status, response.getStatus()); + return content; + } + + public static Response createAndAssert(RestClient client, String path, + String body, + int status) { + Response r = client.post(path, body); + assertResponseStatus(status, r); + return r; + } } diff --git a/hugegraph-cluster-test/hugegraph-clustertest-test/src/main/java/org/apache/hugegraph/MultiClusterTest/MultiClusterDeployTest.java b/hugegraph-cluster-test/hugegraph-clustertest-test/src/main/java/org/apache/hugegraph/MultiClusterTest/MultiClusterDeployTest.java index 0318df1ad0..4229fc35f5 100644 --- a/hugegraph-cluster-test/hugegraph-clustertest-test/src/main/java/org/apache/hugegraph/MultiClusterTest/MultiClusterDeployTest.java +++ b/hugegraph-cluster-test/hugegraph-clustertest-test/src/main/java/org/apache/hugegraph/MultiClusterTest/MultiClusterDeployTest.java @@ -18,22 +18,12 @@ package org.apache.hugegraph.MultiClusterTest; import java.io.IOException; -import java.util.Iterator; import java.util.List; -import org.apache.hugegraph.driver.GraphManager; -import org.apache.hugegraph.driver.GremlinManager; -import org.apache.hugegraph.driver.HugeClient; -import org.apache.hugegraph.driver.SchemaManager; +import org.apache.hugegraph.SimpleClusterTest.BaseSimpleTest.RestClient; import org.apache.hugegraph.pd.client.PDClient; import org.apache.hugegraph.pd.client.PDConfig; import org.apache.hugegraph.pd.common.PDException; -import org.apache.hugegraph.structure.constant.T; -import org.apache.hugegraph.structure.graph.Edge; -import org.apache.hugegraph.structure.graph.Path; -import org.apache.hugegraph.structure.graph.Vertex; -import org.apache.hugegraph.structure.gremlin.Result; -import org.apache.hugegraph.structure.gremlin.ResultSet; import org.junit.Assert; import org.junit.Test; @@ -59,11 +49,6 @@ public void testStoreNodesDeployment() throws IOException { List addrs = env.getStoreRestAddrs(); for (String addr : addrs) { String[] cmds = {"curl", addr}; - // TODO: why not use the sb param? - StringBuilder sb = new StringBuilder(); - for (String cmd : cmds) { - sb.append(cmd).append(" "); - } String responseMsg = execCmd(cmds); Assert.assertTrue(responseMsg.startsWith("{")); } @@ -71,133 +56,64 @@ public void testStoreNodesDeployment() throws IOException { @Test public void testServerNodesDeployment() { - List addrs = env.getServerRestAddrs(); - for (String addr : addrs) { - HugeClient hugeClient = HugeClient.builder("http://" + addr, "hugegraph") - .build(); - SchemaManager schema = hugeClient.schema(); - - schema.propertyKey("name").asText().ifNotExist().create(); - schema.propertyKey("age").asInt().ifNotExist().create(); - schema.propertyKey("city").asText().ifNotExist().create(); - schema.propertyKey("weight").asDouble().ifNotExist().create(); - schema.propertyKey("lang").asText().ifNotExist().create(); - schema.propertyKey("date").asDate().ifNotExist().create(); - schema.propertyKey("price").asInt().ifNotExist().create(); - - schema.vertexLabel("person") - .properties("name", "age", "city") - .primaryKeys("name") - .ifNotExist() - .create(); - - schema.vertexLabel("software") - .properties("name", "lang", "price") - .primaryKeys("name") - .ifNotExist() - .create(); - - schema.indexLabel("personByCity") - .onV("person") - .by("city") - .secondary() - .ifNotExist() - .create(); - - schema.indexLabel("personByAgeAndCity") - .onV("person") - .by("age", "city") - .secondary() - .ifNotExist() - .create(); - - schema.indexLabel("softwareByPrice") - .onV("software") - .by("price") - .range() - .ifNotExist() - .create(); - - schema.edgeLabel("knows") - .sourceLabel("person") - .targetLabel("person") - .properties("date", "weight") - .ifNotExist() - .create(); - - schema.edgeLabel("created") - .sourceLabel("person").targetLabel("software") - .properties("date", "weight") - .ifNotExist() - .create(); - - schema.indexLabel("createdByDate") - .onE("created") - .by("date") - .secondary() - .ifNotExist() - .create(); - - schema.indexLabel("createdByWeight") - .onE("created") - .by("weight") - .range() - .ifNotExist() - .create(); - - schema.indexLabel("knowsByWeight") - .onE("knows") - .by("weight") - .range() - .ifNotExist() - .create(); - - GraphManager graph = hugeClient.graph(); - Vertex marko = graph.addVertex(T.LABEL, "person", "name", "marko", - "age", 29, "city", "Beijing"); - Vertex vadas = graph.addVertex(T.LABEL, "person", "name", "vadas", - "age", 27, "city", "Hongkong"); - Vertex lop = graph.addVertex(T.LABEL, "software", "name", "lop", - "lang", "java", "price", 328); - Vertex josh = graph.addVertex(T.LABEL, "person", "name", "josh", - "age", 32, "city", "Beijing"); - Vertex ripple = graph.addVertex(T.LABEL, "software", "name", "ripple", - "lang", "java", "price", 199); - Vertex peter = graph.addVertex(T.LABEL, "person", "name", "peter", - "age", 35, "city", "Shanghai"); - - marko.addEdge("knows", vadas, "date", "2016-01-10", "weight", 0.5); - marko.addEdge("knows", josh, "date", "2013-02-20", "weight", 1.0); - marko.addEdge("created", lop, "date", "2017-12-10", "weight", 0.4); - josh.addEdge("created", lop, "date", "2009-11-11", "weight", 0.4); - josh.addEdge("created", ripple, "date", "2017-12-10", "weight", 1.0); - peter.addEdge("created", lop, "date", "2017-03-24", "weight", 0.2); - - GremlinManager gremlin = hugeClient.gremlin(); - System.out.println("==== Path ===="); - ResultSet resultSet = gremlin.gremlin("g.V().outE().path()").execute(); - Iterator results = resultSet.iterator(); - results.forEachRemaining(result -> { - System.out.println(result.getObject().getClass()); - Object object = result.getObject(); - if (object instanceof Vertex) { - System.out.println(((Vertex) object).id()); - } else if (object instanceof Edge) { - System.out.println(((Edge) object).id()); - } else if (object instanceof Path) { - List elements = ((Path) object).objects(); - elements.forEach(element -> { - System.out.println(element.getClass()); - System.out.println(element); - }); - } else { - System.out.println(object); - } - }); - - hugeClient.close(); - assert true; - break; + for (RestClient client : clients) { + String path = URL_PREFIX + SCHEMA_PKS; + createAndAssert(client, path, "{\n" + + "\"name\": \"name\",\n" + + "\"data_type\": \"TEXT\",\n" + + "\"cardinality\": \"SINGLE\",\n" + + "\"check_exist\": false,\n" + + "\"properties\":[]\n" + + "}", 202); + createAndAssert(client, path, "{\n" + + "\"name\": \"age\",\n" + + "\"data_type\": \"INT\",\n" + + "\"cardinality\": \"SINGLE\",\n" + + "\"check_exist\": false,\n" + + "\"properties\":[]\n" + + "}", 202); + createAndAssert(client, path, "{\n" + + "\"name\": \"city\",\n" + + "\"data_type\": \"TEXT\",\n" + + "\"cardinality\": \"SINGLE\",\n" + + "\"check_exist\": false,\n" + + "\"properties\":[]\n" + + "}", 202); + createAndAssert(client, path, "{\n" + + "\"name\": \"lang\",\n" + + "\"data_type\": \"TEXT\",\n" + + "\"cardinality\": \"SINGLE\",\n" + + "\"check_exist\": false,\n" + + "\"properties\":[]\n" + + "}", 202); + createAndAssert(client, path, "{\n" + + "\"name\": \"date\",\n" + + "\"data_type\": \"TEXT\",\n" + + "\"cardinality\": \"SINGLE\",\n" + + "\"check_exist\": false,\n" + + "\"properties\":[]\n" + + "}", 202); + createAndAssert(client, path, "{\n" + + "\"name\": \"price\",\n" + + "\"data_type\": \"INT\",\n" + + "\"cardinality\": \"SINGLE\",\n" + + "\"check_exist\": false,\n" + + "\"properties\":[]\n" + + "}", 202); + createAndAssert(client, path, "{\n" + + "\"name\": \"weight\",\n" + + "\"data_type\": \"DOUBLE\",\n" + + "\"cardinality\": \"SINGLE\",\n" + + "\"check_exist\": false,\n" + + "\"properties\":[]\n" + + "}", 202); + createAndAssert(client, path, "{\n" + + "\"name\": \"rank\",\n" + + "\"data_type\": \"TEXT\",\n" + + "\"cardinality\": \"SINGLE\",\n" + + "\"check_exist\": false,\n" + + "\"properties\":[]\n" + + "}", 202); } } } diff --git a/hugegraph-cluster-test/hugegraph-clustertest-test/src/main/java/org/apache/hugegraph/SimpleClusterTest/BaseSimpleTest.java b/hugegraph-cluster-test/hugegraph-clustertest-test/src/main/java/org/apache/hugegraph/SimpleClusterTest/BaseSimpleTest.java index 61954de811..849b4b835f 100644 --- a/hugegraph-cluster-test/hugegraph-clustertest-test/src/main/java/org/apache/hugegraph/SimpleClusterTest/BaseSimpleTest.java +++ b/hugegraph-cluster-test/hugegraph-clustertest-test/src/main/java/org/apache/hugegraph/SimpleClusterTest/BaseSimpleTest.java @@ -20,36 +20,61 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; +import java.util.Map; import org.apache.hugegraph.ct.env.BaseEnv; import org.apache.hugegraph.ct.env.SimpleEnv; -import org.apache.hugegraph.driver.HugeClient; import org.apache.hugegraph.pd.client.PDClient; +import org.apache.hugegraph.serializer.direct.util.HugeException; +import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; +import org.glassfish.jersey.client.filter.EncodingFilter; +import org.glassfish.jersey.message.GZipEncoder; import org.junit.AfterClass; +import org.junit.Assert; import org.junit.BeforeClass; +import com.google.common.collect.Multimap; + +import jakarta.ws.rs.client.Client; +import jakarta.ws.rs.client.ClientBuilder; +import jakarta.ws.rs.client.Entity; +import jakarta.ws.rs.client.WebTarget; +import jakarta.ws.rs.core.MultivaluedMap; +import jakarta.ws.rs.core.Response; + /** * Simple Test generate the cluster env with 1 pd node + 1 store node + 1 server node. * All nodes are deployed in ports generated randomly; The application of nodes is stored - * in /apache-hugegraph-ct-incubating-1.5.0, you can visit each node with rest api. + * in /apache-hugegraph-ct-incubating-1.7.0, you can visit each node with rest api. */ public class BaseSimpleTest { protected static BaseEnv env; protected static Process p; protected static PDClient pdClient; - protected static HugeClient hugeClient; + + protected static String BASE_URL = "http://"; + protected static final String GRAPH = "hugegraphapi"; + protected static final String USERNAME = "admin"; + private static final String PASSWORD = "pa"; + + protected static final String URL_PREFIX = "graphspaces/DEFAULT/graphs/" + GRAPH; + protected static final String SCHEMA_PKS = "/schema/propertykeys"; + protected static RestClient client; @BeforeClass public static void initEnv() { env = new SimpleEnv(); env.startCluster(); + client = new RestClient(BASE_URL + env.getServerRestAddrs().get(0)); + initGraph(); } @AfterClass public static void clearEnv() throws InterruptedException { env.stopCluster(); Thread.sleep(2000); + client.close(); } protected String execCmd(String[] cmds) throws IOException { @@ -66,4 +91,101 @@ protected String execCmd(String[] cmds) throws IOException { return builder.toString(); } + protected static void initGraph() { + Response r = client.get(URL_PREFIX); + if (r.getStatus() != 200) { + String body = "{\n" + + " \"backend\": \"hstore\",\n" + + " \"serializer\": \"binary\",\n" + + " \"store\": \"hugegraphapi\",\n" + + " \"search.text_analyzer\": \"jieba\",\n" + + " \"search.text_analyzer_mode\": \"INDEX\"\n" + + "}"; + r = client.post(URL_PREFIX, body); + if (r.getStatus() != 201) { + throw new HugeException("Failed to create graph: " + GRAPH + + r.readEntity(String.class)); + } + } + } + + public static class RestClient { + + private final Client client; + private final WebTarget target; + + public RestClient(String url) { + this.client = ClientBuilder.newClient(); + this.client.register(EncodingFilter.class); + this.client.register(GZipEncoder.class); + this.client.register(HttpAuthenticationFeature.basic(USERNAME, + PASSWORD)); + this.target = this.client.target(url); + } + + public void close() { + this.client.close(); + } + + public WebTarget target() { + return this.target; + } + + public WebTarget target(String url) { + return this.client.target(url); + } + + public Response get(String path) { + return this.target.path(path).request().get(); + } + + public Response get(String path, String id) { + return this.target.path(path).path(id).request().get(); + } + + public Response get(String path, + MultivaluedMap headers) { + return this.target.path(path).request().headers(headers).get(); + } + + public Response get(String path, Multimap params) { + WebTarget target = this.target.path(path); + for (Map.Entry entries : params.entries()) { + target = target.queryParam(entries.getKey(), entries.getValue()); + } + return target.request().get(); + } + + public Response get(String path, Map params) { + WebTarget target = this.target.path(path); + for (Map.Entry i : params.entrySet()) { + target = target.queryParam(i.getKey(), i.getValue()); + } + return target.request().get(); + } + + public Response post(String path, String content) { + return this.post(path, Entity.json(content)); + } + + public Response post(String path, Entity entity) { + return this.target.path(path).request().post(entity); + } + } + + protected static String assertResponseStatus(int status, + Response response) { + String content = response.readEntity(String.class); + String message = String.format("Response with status %s and content %s", + response.getStatus(), content); + Assert.assertEquals(message, status, response.getStatus()); + return content; + } + + public static Response createAndAssert(String path, String body, + int status) { + Response r = client.post(path, body); + assertResponseStatus(status, r); + return r; + } } diff --git a/hugegraph-cluster-test/hugegraph-clustertest-test/src/main/java/org/apache/hugegraph/SimpleClusterTest/SimpleClusterDeployTest.java b/hugegraph-cluster-test/hugegraph-clustertest-test/src/main/java/org/apache/hugegraph/SimpleClusterTest/SimpleClusterDeployTest.java index 61a73ff0f4..267e186f9e 100644 --- a/hugegraph-cluster-test/hugegraph-clustertest-test/src/main/java/org/apache/hugegraph/SimpleClusterTest/SimpleClusterDeployTest.java +++ b/hugegraph-cluster-test/hugegraph-clustertest-test/src/main/java/org/apache/hugegraph/SimpleClusterTest/SimpleClusterDeployTest.java @@ -18,22 +18,11 @@ package org.apache.hugegraph.SimpleClusterTest; import java.io.IOException; -import java.util.Iterator; import java.util.List; -import org.apache.hugegraph.driver.GraphManager; -import org.apache.hugegraph.driver.GremlinManager; -import org.apache.hugegraph.driver.HugeClient; -import org.apache.hugegraph.driver.SchemaManager; import org.apache.hugegraph.pd.client.PDClient; import org.apache.hugegraph.pd.client.PDConfig; import org.apache.hugegraph.pd.common.PDException; -import org.apache.hugegraph.structure.constant.T; -import org.apache.hugegraph.structure.graph.Edge; -import org.apache.hugegraph.structure.graph.Path; -import org.apache.hugegraph.structure.graph.Vertex; -import org.apache.hugegraph.structure.gremlin.Result; -import org.apache.hugegraph.structure.gremlin.ResultSet; import org.junit.Assert; import org.junit.Test; @@ -44,7 +33,7 @@ public void testPDNodesDeployment() { try { List addrs = env.getPDGrpcAddrs(); for (String addr : addrs) { - PDConfig pdConfig = PDConfig.of(addr); + PDConfig pdConfig = PDConfig.of(addr, Long.MAX_VALUE); pdClient = PDClient.create(pdConfig); pdClient.dbCompaction(); } @@ -59,142 +48,69 @@ public void testStoreNodesDeployment() throws IOException { List addrs = env.getStoreRestAddrs(); for (String addr : addrs) { String[] cmds = {"curl", addr}; - // TODO: what's the purpose of this? - StringBuilder sb = new StringBuilder(); - for (String cmd : cmds) { - sb.append(cmd).append(" "); - } String responseMsg = execCmd(cmds); Assert.assertTrue(responseMsg.startsWith("{")); } } @Test - public void testServerNodesDeployment() { - List addrs = env.getServerRestAddrs(); - for (String addr : addrs) { - hugeClient = HugeClient.builder("http://" + addr, "hugegraph").build(); - SchemaManager schema = hugeClient.schema(); - - schema.propertyKey("name").asText().ifNotExist().create(); - schema.propertyKey("age").asInt().ifNotExist().create(); - schema.propertyKey("city").asText().ifNotExist().create(); - schema.propertyKey("weight").asDouble().ifNotExist().create(); - schema.propertyKey("lang").asText().ifNotExist().create(); - schema.propertyKey("date").asDate().ifNotExist().create(); - schema.propertyKey("price").asInt().ifNotExist().create(); - - schema.vertexLabel("person") - .properties("name", "age", "city") - .primaryKeys("name") - .ifNotExist() - .create(); - - schema.vertexLabel("software") - .properties("name", "lang", "price") - .primaryKeys("name") - .ifNotExist() - .create(); - - schema.indexLabel("personByCity") - .onV("person") - .by("city") - .secondary() - .ifNotExist() - .create(); - - schema.indexLabel("personByAgeAndCity") - .onV("person") - .by("age", "city") - .secondary() - .ifNotExist() - .create(); - - schema.indexLabel("softwareByPrice") - .onV("software") - .by("price") - .range() - .ifNotExist() - .create(); - - schema.edgeLabel("knows") - .sourceLabel("person") - .targetLabel("person") - .properties("date", "weight") - .ifNotExist() - .create(); - - schema.edgeLabel("created") - .sourceLabel("person").targetLabel("software") - .properties("date", "weight") - .ifNotExist() - .create(); - - schema.indexLabel("createdByDate") - .onE("created") - .by("date") - .secondary() - .ifNotExist() - .create(); - - schema.indexLabel("createdByWeight") - .onE("created") - .by("weight") - .range() - .ifNotExist() - .create(); - - schema.indexLabel("knowsByWeight") - .onE("knows") - .by("weight") - .range() - .ifNotExist() - .create(); - - GraphManager graph = hugeClient.graph(); - Vertex marko = graph.addVertex(T.LABEL, "person", "name", "marko", - "age", 29, "city", "Beijing"); - Vertex vadas = graph.addVertex(T.LABEL, "person", "name", "vadas", - "age", 27, "city", "Hongkong"); - Vertex lop = graph.addVertex(T.LABEL, "software", "name", "lop", - "lang", "java", "price", 328); - Vertex josh = graph.addVertex(T.LABEL, "person", "name", "josh", - "age", 32, "city", "Beijing"); - Vertex ripple = graph.addVertex(T.LABEL, "software", "name", "ripple", - "lang", "java", "price", 199); - Vertex peter = graph.addVertex(T.LABEL, "person", "name", "peter", - "age", 35, "city", "Shanghai"); - - marko.addEdge("knows", vadas, "date", "2016-01-10", "weight", 0.5); - marko.addEdge("knows", josh, "date", "2013-02-20", "weight", 1.0); - marko.addEdge("created", lop, "date", "2017-12-10", "weight", 0.4); - josh.addEdge("created", lop, "date", "2009-11-11", "weight", 0.4); - josh.addEdge("created", ripple, "date", "2017-12-10", "weight", 1.0); - peter.addEdge("created", lop, "date", "2017-03-24", "weight", 0.2); - - GremlinManager gremlin = hugeClient.gremlin(); - System.out.println("==== Path ===="); - ResultSet resultSet = gremlin.gremlin("g.V().outE().path()").execute(); - Iterator results = resultSet.iterator(); - results.forEachRemaining(result -> { - System.out.println(result.getObject().getClass()); - Object object = result.getObject(); - if (object instanceof Vertex) { - System.out.println(((Vertex) object).id()); - } else if (object instanceof Edge) { - System.out.println(((Edge) object).id()); - } else if (object instanceof Path) { - List elements = ((Path) object).objects(); - elements.forEach(element -> { - System.out.println(element.getClass()); - System.out.println(element); - }); - } else { - System.out.println(object); - } - }); - - hugeClient.close(); - } + public void testServerNode() { + String path = URL_PREFIX + SCHEMA_PKS; + createAndAssert(path, "{\n" + + "\"name\": \"name\",\n" + + "\"data_type\": \"TEXT\",\n" + + "\"cardinality\": \"SINGLE\",\n" + + "\"check_exist\": false,\n" + + "\"properties\":[]\n" + + "}", 202); + createAndAssert(path, "{\n" + + "\"name\": \"age\",\n" + + "\"data_type\": \"INT\",\n" + + "\"cardinality\": \"SINGLE\",\n" + + "\"check_exist\": false,\n" + + "\"properties\":[]\n" + + "}", 202); + createAndAssert(path, "{\n" + + "\"name\": \"city\",\n" + + "\"data_type\": \"TEXT\",\n" + + "\"cardinality\": \"SINGLE\",\n" + + "\"check_exist\": false,\n" + + "\"properties\":[]\n" + + "}", 202); + createAndAssert(path, "{\n" + + "\"name\": \"lang\",\n" + + "\"data_type\": \"TEXT\",\n" + + "\"cardinality\": \"SINGLE\",\n" + + "\"check_exist\": false,\n" + + "\"properties\":[]\n" + + "}", 202); + createAndAssert(path, "{\n" + + "\"name\": \"date\",\n" + + "\"data_type\": \"TEXT\",\n" + + "\"cardinality\": \"SINGLE\",\n" + + "\"check_exist\": false,\n" + + "\"properties\":[]\n" + + "}", 202); + createAndAssert(path, "{\n" + + "\"name\": \"price\",\n" + + "\"data_type\": \"INT\",\n" + + "\"cardinality\": \"SINGLE\",\n" + + "\"check_exist\": false,\n" + + "\"properties\":[]\n" + + "}", 202); + createAndAssert(path, "{\n" + + "\"name\": \"weight\",\n" + + "\"data_type\": \"DOUBLE\",\n" + + "\"cardinality\": \"SINGLE\",\n" + + "\"check_exist\": false,\n" + + "\"properties\":[]\n" + + "}", 202); + createAndAssert(path, "{\n" + + "\"name\": \"rank\",\n" + + "\"data_type\": \"TEXT\",\n" + + "\"cardinality\": \"SINGLE\",\n" + + "\"check_exist\": false,\n" + + "\"properties\":[]\n" + + "}", 202); } } diff --git a/hugegraph-cluster-test/hugegraph-clustertest-test/src/main/resources/jar.txt b/hugegraph-cluster-test/hugegraph-clustertest-test/src/main/resources/jar.txt new file mode 100644 index 0000000000..7a566545ce --- /dev/null +++ b/hugegraph-cluster-test/hugegraph-clustertest-test/src/main/resources/jar.txt @@ -0,0 +1,14 @@ +hugegraph-api-${revision}.jar +hugegraph-cassandra-${revision}.jar +hugegraph-common-${revision}.jar +hugegraph-core-${revision}.jar +hugegraph-dist-${revision}.jar +hugegraph-hbase-${revision}.jar +hugegraph-hstore-${revision}.jar +hugegraph-mysql-${revision}.jar +hugegraph-palo-${revision}.jar +hugegraph-postgresql-${revision}.jar +hugegraph-rocksdb-${revision}.jar +hugegraph-rpc-${revision}.jar +hugegraph-scylladb-${revision}.jar +hugegraph-struct-${revision}.jar diff --git a/hugegraph-cluster-test/pom.xml b/hugegraph-cluster-test/pom.xml index fcc409d6ad..ecb47b7970 100644 --- a/hugegraph-cluster-test/pom.xml +++ b/hugegraph-cluster-test/pom.xml @@ -1,19 +1,19 @@