Skip to content

Commit 577c4eb

Browse files
committed
update(cluster-test): Bump cluster-test version to 1.7.0
1 parent a71c269 commit 577c4eb

8 files changed

Lines changed: 358 additions & 292 deletions

File tree

hugegraph-cluster-test/hugegraph-clustertest-dist/src/assembly/static/conf/hugegraph.properties.template

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
#
1717

1818
# gremlin entrance to create graph
19-
# auth config: org.apache.hugegraph.auth.HugeFactoryAuthProxy
20-
gremlin.graph=org.apache.hugegraph.HugeFactory
19+
gremlin.graph=org.apache.hugegraph.auth.HugeFactoryAuthProxy
2120

2221
# cache config
2322
#schema.cache_capacity=100000

hugegraph-cluster-test/hugegraph-clustertest-dist/src/assembly/static/conf/rest-server.properties.template

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,12 @@ arthas.disabled_commands=jad
3636
# authentication configs
3737
# choose 'org.apache.hugegraph.auth.StandardAuthenticator' or
3838
# 'org.apache.hugegraph.auth.ConfigAuthenticator'
39-
#auth.authenticator=
39+
auth.authenticator=org.apache.hugegraph.auth.StandardAuthenticator
40+
# true if using hstore mode
41+
usePD=true
42+
43+
# default password
44+
auth.admin_pa=pa
4045

4146
# for StandardAuthenticator mode
4247
#auth.graph_store=hugegraph

hugegraph-cluster-test/hugegraph-clustertest-minicluster/src/main/java/org/apache/hugegraph/ct/node/ServerNodeWrapper.java

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,20 @@
3434
import static org.apache.hugegraph.ct.base.ClusterConstant.SERVER_TEMPLATE_PATH;
3535
import static org.apache.hugegraph.ct.base.ClusterConstant.isJava11OrHigher;
3636

37+
import java.io.BufferedReader;
3738
import java.io.File;
3839
import java.io.IOException;
40+
import java.io.InputStream;
41+
import java.io.InputStreamReader;
42+
import java.nio.charset.StandardCharsets;
3943
import java.nio.file.Paths;
4044
import java.util.ArrayList;
4145
import java.util.Arrays;
4246
import java.util.List;
4347

4448
public class ServerNodeWrapper extends AbstractNodeWrapper {
4549

50+
private static List<String> hgJars = new ArrayList<>();
4651
public ServerNodeWrapper(int clusterIndex, int index) {
4752
super(clusterIndex, index);
4853
this.fileNames = new ArrayList<>(
@@ -54,6 +59,7 @@ public ServerNodeWrapper(int clusterIndex, int index) {
5459
this.startLine = "INFO: [HttpServer] Started.";
5560
createNodeDir(Paths.get(SERVER_PACKAGE_PATH), getNodePath());
5661
createLogDir();
62+
loadHgJars();
5763
}
5864

5965
private static void addJarsToClasspath(File directory, List<String> classpath) {
@@ -67,6 +73,36 @@ private static void addJarsToClasspath(File directory, List<String> classpath) {
6773
}
6874
}
6975

76+
private static void addCpJarsToClasspath(File directory, List<String> classpath) {
77+
// Add jar starts with hugegraph in proper order
78+
String path = directory.getAbsolutePath();
79+
for (String jar : hgJars) {
80+
classpath.add(path + File.separator + jar);
81+
}
82+
if (directory.exists() && directory.isDirectory()) {
83+
File[] files =
84+
directory.listFiles((dir, name) -> name.endsWith(".jar") && !name.contains(
85+
"hugegraph"));
86+
if (files != null) {
87+
for (File file : files) {
88+
classpath.add(file.getAbsolutePath());
89+
}
90+
}
91+
}
92+
}
93+
94+
private void loadHgJars(){
95+
try (InputStream is = ServerNodeWrapper.class.getResourceAsStream("/jar.txt");
96+
BufferedReader reader = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))) {
97+
String line;
98+
while ((line = reader.readLine()) != null) {
99+
hgJars.add(line);
100+
}
101+
} catch (IOException e) {
102+
e.printStackTrace();
103+
}
104+
}
105+
70106
@Override
71107
public void start() {
72108
try {
@@ -79,14 +115,16 @@ public void start() {
79115
}
80116

81117
List<String> classpath = new ArrayList<>();
82-
addJarsToClasspath(new File(workPath + LIB_DIR), classpath);
118+
addCpJarsToClasspath(new File(workPath + LIB_DIR), classpath);
83119
addJarsToClasspath(new File(workPath + EXT_DIR), classpath);
84120
addJarsToClasspath(new File(workPath + PLUGINS_DIR), classpath);
85121
String storeClassPath = String.join(":", classpath);
86122

87123
startCmd.addAll(Arrays.asList(
88124
"-Dname=HugeGraphServer" + this.index,
89125
"--add-exports=java.base/jdk.internal.reflect=ALL-UNNAMED",
126+
"--add-modules=jdk.unsupported",
127+
"--add-exports=java.base/sun.nio.ch=ALL-UNNAMED",
90128
"-cp", storeClassPath,
91129
"org.apache.hugegraph.dist.HugeGraphServer",
92130
"./conf/gremlin-server.yaml",

hugegraph-cluster-test/hugegraph-clustertest-test/src/main/java/org/apache/hugegraph/MultiClusterTest/BaseMultiClusterTest.java

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,20 @@
2020
import java.io.BufferedReader;
2121
import java.io.IOException;
2222
import java.io.InputStreamReader;
23+
import java.util.ArrayList;
24+
import java.util.List;
2325

26+
import org.apache.hugegraph.SimpleClusterTest.BaseSimpleTest;
27+
import org.apache.hugegraph.SimpleClusterTest.BaseSimpleTest.RestClient;
2428
import org.apache.hugegraph.ct.env.BaseEnv;
2529
import org.apache.hugegraph.ct.env.MultiNodeEnv;
30+
import org.apache.hugegraph.serializer.direct.util.HugeException;
2631
import org.junit.AfterClass;
32+
import org.junit.Assert;
2733
import org.junit.BeforeClass;
2834

35+
import jakarta.ws.rs.core.Response;
36+
2937
/**
3038
* MultiNode Test generate the cluster env with 3 pd node + 3 store node + 3 server node.
3139
* Or you can set different num of nodes by using env = new MultiNodeEnv(pdNum, storeNum, serverNum)
@@ -36,16 +44,47 @@ public class BaseMultiClusterTest {
3644

3745
protected static BaseEnv env;
3846
protected static Process p;
47+
protected static List<RestClient> clients = new ArrayList<>();
48+
protected static String BASE_URL = "http://";
49+
protected static final String GRAPH = "hugegraphapi";
50+
protected static final String URL_PREFIX = "graphspaces/DEFAULT/graphs/" + GRAPH;
51+
protected static final String SCHEMA_PKS = "/schema/propertykeys";
3952

4053
@BeforeClass
4154
public static void initEnv() {
4255
env = new MultiNodeEnv();
4356
env.startCluster();
57+
for (String addr : env.getServerRestAddrs()) {
58+
clients.add(new RestClient(BASE_URL + addr));
59+
}
60+
initGraph();
4461
}
4562

4663
@AfterClass
4764
public static void clearEnv() {
4865
env.stopCluster();
66+
for (RestClient client : clients) {
67+
client.close();
68+
}
69+
}
70+
71+
protected static void initGraph() {
72+
BaseSimpleTest.RestClient client = clients.get(0);
73+
Response r = clients.get(0).get(URL_PREFIX);
74+
if (r.getStatus() != 200) {
75+
String body = "{\n" +
76+
" \"backend\": \"hstore\",\n" +
77+
" \"serializer\": \"binary\",\n" +
78+
" \"store\": \"hugegraphapi\",\n" +
79+
" \"search.text_analyzer\": \"jieba\",\n" +
80+
" \"search.text_analyzer_mode\": \"INDEX\"\n" +
81+
"}";
82+
r = client.post(URL_PREFIX, body);
83+
if (r.getStatus() != 201) {
84+
throw new HugeException("Failed to create graph: " + GRAPH +
85+
r.readEntity(String.class));
86+
}
87+
}
4988
}
5089

5190
protected String execCmd(String[] cmds) throws IOException {
@@ -61,4 +100,21 @@ protected String execCmd(String[] cmds) throws IOException {
61100
p.destroy();
62101
return builder.toString();
63102
}
103+
104+
protected static String assertResponseStatus(int status,
105+
Response response) {
106+
String content = response.readEntity(String.class);
107+
String message = String.format("Response with status %s and content %s",
108+
response.getStatus(), content);
109+
Assert.assertEquals(message, status, response.getStatus());
110+
return content;
111+
}
112+
113+
public static Response createAndAssert(RestClient client, String path,
114+
String body,
115+
int status) {
116+
Response r = client.post(path, body);
117+
assertResponseStatus(status, r);
118+
return r;
119+
}
64120
}

0 commit comments

Comments
 (0)