From 48cfc6e5fcb01fca6d90d8ce62a29190ae5df866 Mon Sep 17 00:00:00 2001 From: 145425491 <1245294786@qq.com> Date: Mon, 23 Sep 2024 22:43:15 +0800 Subject: [PATCH] chore(ct): reformat code & update config files --- .../static/pd-application.yml.template | 4 +-- .../hugegraph/ct/config/AbstractConfig.java | 12 ++++---- .../hugegraph/ct/config/GraphConfig.java | 4 ++- .../apache/hugegraph/ct/config/PDConfig.java | 30 +++++-------------- .../hugegraph/ct/config/ServerConfig.java | 5 +++- .../hugegraph/ct/config/StoreConfig.java | 4 ++- .../apache/hugegraph/ct/env/AbstractEnv.java | 2 +- .../org/apache/hugegraph/ct/env/BaseEnv.java | 2 +- .../hugegraph-clustertest-test/pom.xml | 20 +++++++++++++ .../BaseMultiClusterTest.java | 5 ++-- .../MultiClusterDeployTest.java | 6 ++-- .../SimpleClusterTest/BaseSimpleTest.java | 6 ++-- .../SimpleClusterDeployTest.java | 26 ++++++++-------- 13 files changed, 67 insertions(+), 59 deletions(-) diff --git a/hugegraph-cluster-test/hugegraph-clustertest-dist/src/assembly/static/pd-application.yml.template b/hugegraph-cluster-test/hugegraph-clustertest-dist/src/assembly/static/pd-application.yml.template index b76ae93618..35ee68c8c8 100644 --- a/hugegraph-cluster-test/hugegraph-clustertest-dist/src/assembly/static/pd-application.yml.template +++ b/hugegraph-cluster-test/hugegraph-clustertest-dist/src/assembly/static/pd-application.yml.template @@ -36,14 +36,14 @@ license: license-path: ./conf/hugegraph.license grpc: port: $GRPC_PORT$ - host: $GRPC_HOST$ + host: 127.0.0.1 server: port : $REST_PORT$ pd: # 存储路径 - data-path: $PD_DATA_PATH$ + data-path: ./pd_data # 自动扩容的检查周期,定时检查每个 store 的分区数量,自动进行分区数量平衡 patrol-interval: 1800 # 初始 store 列表,在列表内的 store 自动激活 diff --git a/hugegraph-cluster-test/hugegraph-clustertest-minicluster/src/main/java/org/apache/hugegraph/ct/config/AbstractConfig.java b/hugegraph-cluster-test/hugegraph-clustertest-minicluster/src/main/java/org/apache/hugegraph/ct/config/AbstractConfig.java index 91510bf07e..7efae358c2 100644 --- a/hugegraph-cluster-test/hugegraph-clustertest-minicluster/src/main/java/org/apache/hugegraph/ct/config/AbstractConfig.java +++ b/hugegraph-cluster-test/hugegraph-clustertest-minicluster/src/main/java/org/apache/hugegraph/ct/config/AbstractConfig.java @@ -36,9 +36,9 @@ public abstract class AbstractConfig { protected Map properties = new HashMap<>(); protected String fileName; - protected void readTemplate(String filePath) { + protected void readTemplate(Path filePath) { try { - this.config = new String(Files.readAllBytes(Paths.get(filePath))); + this.config = new String(Files.readAllBytes(filePath)); } catch (IOException e) { LOG.error("failed to get file", e); } @@ -53,15 +53,15 @@ protected void updateConfigs() { public void writeConfig(String filePath) { updateConfigs(); - String destPath = filePath + File.separator + fileName; + Path destPath = Paths.get(filePath + File.separator + fileName); try { - if (Files.notExists(Path.of(destPath).getParent())) { - Files.createDirectories(Path.of(destPath).getParent()); + if (Files.notExists(destPath.getParent())) { + Files.createDirectories(destPath.getParent()); } } catch (IOException e) { e.printStackTrace(); } - try (FileWriter writer = new FileWriter(destPath)) { + try (FileWriter writer = new FileWriter(String.valueOf(destPath))) { writer.write(config); } catch (IOException e) { e.printStackTrace(); diff --git a/hugegraph-cluster-test/hugegraph-clustertest-minicluster/src/main/java/org/apache/hugegraph/ct/config/GraphConfig.java b/hugegraph-cluster-test/hugegraph-clustertest-minicluster/src/main/java/org/apache/hugegraph/ct/config/GraphConfig.java index 7c04f4b07c..b28e4e57f4 100644 --- a/hugegraph-cluster-test/hugegraph-clustertest-minicluster/src/main/java/org/apache/hugegraph/ct/config/GraphConfig.java +++ b/hugegraph-cluster-test/hugegraph-clustertest-minicluster/src/main/java/org/apache/hugegraph/ct/config/GraphConfig.java @@ -21,13 +21,15 @@ import static org.apache.hugegraph.ct.base.ClusterConstant.GRAPH_TEMPLATE_FILE; import static org.apache.hugegraph.ct.base.ClusterConstant.HUGEGRAPH_PROPERTIES; +import java.nio.file.Paths; import java.util.List; import java.util.stream.Collectors; public class GraphConfig extends AbstractConfig { public GraphConfig() { - readTemplate(CT_PACKAGE_PATH + GRAPH_TEMPLATE_FILE); + readTemplate( + Paths.get(CT_PACKAGE_PATH + GRAPH_TEMPLATE_FILE)); this.fileName = HUGEGRAPH_PROPERTIES; } diff --git a/hugegraph-cluster-test/hugegraph-clustertest-minicluster/src/main/java/org/apache/hugegraph/ct/config/PDConfig.java b/hugegraph-cluster-test/hugegraph-clustertest-minicluster/src/main/java/org/apache/hugegraph/ct/config/PDConfig.java index 83a774a3c8..dae0c1b7cf 100644 --- a/hugegraph-cluster-test/hugegraph-clustertest-minicluster/src/main/java/org/apache/hugegraph/ct/config/PDConfig.java +++ b/hugegraph-cluster-test/hugegraph-clustertest-minicluster/src/main/java/org/apache/hugegraph/ct/config/PDConfig.java @@ -22,6 +22,7 @@ import static org.apache.hugegraph.ct.base.ClusterConstant.PD_TEMPLATE_FILE; import static org.apache.hugegraph.ct.base.EnvUtil.getAvailablePort; +import java.nio.file.Paths; import java.util.List; import java.util.stream.Collectors; @@ -31,39 +32,22 @@ public class PDConfig extends AbstractConfig { @Getter private final int raftPort, grpcPort, restPort; - @Getter - private String grpcHost, dataPath, raftHost; public PDConfig() { - readTemplate(CT_PACKAGE_PATH + PD_TEMPLATE_FILE); + readTemplate( + Paths.get(CT_PACKAGE_PATH + PD_TEMPLATE_FILE)); this.fileName = APPLICATION_FILE; - this.grpcHost = "127.0.0.1"; - this.raftHost = "127.0.0.1"; - this.dataPath = "./pd_data"; this.raftPort = getAvailablePort(); this.grpcPort = getAvailablePort(); this.restPort = getAvailablePort(); - properties.put("GRPC_HOST", grpcHost); properties.put("GRPC_PORT", String.valueOf(grpcPort)); properties.put("REST_PORT", String.valueOf(restPort)); - properties.put("PD_DATA_PATH", dataPath); - properties.put("RAFT_ADDRESS", raftHost + ":" + properties.put("RAFT_ADDRESS", "127.0.0.1:" + raftPort); } - public void setGrpcHost(String grpcHost) { - this.grpcHost = grpcHost; - setProperty("GRPC_HOST", grpcHost); - } - - public void setDataPath(String dataPath) { - this.dataPath = dataPath; - setProperty("PD_DATA_PATH", dataPath); - } - public void setRaftHost(String raftHost) { - this.raftHost = raftHost; - setProperty("RAFT_ADDRESS", raftHost + ":" + raftPort); + setProperty("RAFT_ADDRESS", "127.0.0.1:" + raftPort); } public void setRaftPeerList(List raftPeerList) { @@ -83,10 +67,10 @@ public void setStoreGrpcList(List storeGrpcList) { } public String getRaftAddress() { - return raftHost + ":" + raftPort; + return "127.0.0.1:" + raftPort; } public String getGrpcAddress() { - return grpcHost + ":" + grpcPort; + return "127.0.0.1:" + grpcPort; } } diff --git a/hugegraph-cluster-test/hugegraph-clustertest-minicluster/src/main/java/org/apache/hugegraph/ct/config/ServerConfig.java b/hugegraph-cluster-test/hugegraph-clustertest-minicluster/src/main/java/org/apache/hugegraph/ct/config/ServerConfig.java index c166aa4e9c..8cb0b61c1b 100644 --- a/hugegraph-cluster-test/hugegraph-clustertest-minicluster/src/main/java/org/apache/hugegraph/ct/config/ServerConfig.java +++ b/hugegraph-cluster-test/hugegraph-clustertest-minicluster/src/main/java/org/apache/hugegraph/ct/config/ServerConfig.java @@ -22,6 +22,8 @@ import static org.apache.hugegraph.ct.base.ClusterConstant.SERVER_TEMPLATE_FILE; import static org.apache.hugegraph.ct.base.EnvUtil.getAvailablePort; +import java.nio.file.Paths; + import lombok.Getter; public class ServerConfig extends AbstractConfig { @@ -32,7 +34,8 @@ public class ServerConfig extends AbstractConfig { private String restHost, rpcHost; public ServerConfig() { - readTemplate(CT_PACKAGE_PATH + SERVER_TEMPLATE_FILE); + readTemplate( + Paths.get(CT_PACKAGE_PATH + SERVER_TEMPLATE_FILE)); this.fileName = SERVER_PROPERTIES; this.restHost = "127.0.0.1"; this.rpcHost = "127.0.0.1"; diff --git a/hugegraph-cluster-test/hugegraph-clustertest-minicluster/src/main/java/org/apache/hugegraph/ct/config/StoreConfig.java b/hugegraph-cluster-test/hugegraph-clustertest-minicluster/src/main/java/org/apache/hugegraph/ct/config/StoreConfig.java index 96132e9c39..6fd8908873 100644 --- a/hugegraph-cluster-test/hugegraph-clustertest-minicluster/src/main/java/org/apache/hugegraph/ct/config/StoreConfig.java +++ b/hugegraph-cluster-test/hugegraph-clustertest-minicluster/src/main/java/org/apache/hugegraph/ct/config/StoreConfig.java @@ -22,6 +22,7 @@ import static org.apache.hugegraph.ct.base.ClusterConstant.STORE_TEMPLATE_FILE; import static org.apache.hugegraph.ct.base.EnvUtil.getAvailablePort; +import java.nio.file.Paths; import java.util.List; import java.util.stream.Collectors; @@ -35,7 +36,8 @@ public class StoreConfig extends AbstractConfig { private String grpcHost, dataPath, raftHost; public StoreConfig() { - readTemplate(CT_PACKAGE_PATH + STORE_TEMPLATE_FILE); + readTemplate( + Paths.get(CT_PACKAGE_PATH + STORE_TEMPLATE_FILE)); this.fileName = APPLICATION_FILE; this.grpcHost = "127.0.0.1"; this.raftHost = "127.0.0.1"; diff --git a/hugegraph-cluster-test/hugegraph-clustertest-minicluster/src/main/java/org/apache/hugegraph/ct/env/AbstractEnv.java b/hugegraph-cluster-test/hugegraph-clustertest-minicluster/src/main/java/org/apache/hugegraph/ct/env/AbstractEnv.java index 2565c5d679..daa42a7c3d 100644 --- a/hugegraph-cluster-test/hugegraph-clustertest-minicluster/src/main/java/org/apache/hugegraph/ct/env/AbstractEnv.java +++ b/hugegraph-cluster-test/hugegraph-clustertest-minicluster/src/main/java/org/apache/hugegraph/ct/env/AbstractEnv.java @@ -124,7 +124,7 @@ public void startCluster() { } } - public void clearCluster() { + public void stopCluster() { for (ServerNodeWrapper serverNodeWrapper : serverNodeWrappers) { serverNodeWrapper.stop(); } diff --git a/hugegraph-cluster-test/hugegraph-clustertest-minicluster/src/main/java/org/apache/hugegraph/ct/env/BaseEnv.java b/hugegraph-cluster-test/hugegraph-clustertest-minicluster/src/main/java/org/apache/hugegraph/ct/env/BaseEnv.java index bdf41b1f0f..bfc5cee506 100644 --- a/hugegraph-cluster-test/hugegraph-clustertest-minicluster/src/main/java/org/apache/hugegraph/ct/env/BaseEnv.java +++ b/hugegraph-cluster-test/hugegraph-clustertest-minicluster/src/main/java/org/apache/hugegraph/ct/env/BaseEnv.java @@ -27,7 +27,7 @@ public interface BaseEnv { void startCluster(); /* clear the cluster env and all config*/ - void clearCluster(); + void stopCluster(); ClusterConf getConf(); diff --git a/hugegraph-cluster-test/hugegraph-clustertest-test/pom.xml b/hugegraph-cluster-test/hugegraph-clustertest-test/pom.xml index 0a5b77b698..1505edbb7a 100644 --- a/hugegraph-cluster-test/hugegraph-clustertest-test/pom.xml +++ b/hugegraph-cluster-test/hugegraph-clustertest-test/pom.xml @@ -40,6 +40,26 @@ ${revision} compile + + org.apache.hugegraph + hugegraph-common + 1.5.0 + + + org.apache.hugegraph + hugegraph-client + 1.3.0 + + + org.apache.hugegraph + hg-store-client + 1.5.0 + + + org.apache.hugegraph + hg-pd-client + 1.5.0 + 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 11d19f0a02..378a162c3f 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 @@ -40,11 +40,10 @@ public static void initEnv() throws InterruptedException { @AfterClass public static void clearEnv() throws InterruptedException { - env.clearCluster(); - Thread.sleep(2000); + env.stopCluster(); } - protected String execCurl(String[] cmds) throws IOException { + protected String execCmd(String[] cmds) throws IOException { ProcessBuilder process = new ProcessBuilder(cmds); p = process.start(); BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream())); 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 1f576ec969..71e0be31dc 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 @@ -35,7 +35,7 @@ public void testPDNodesDeployment() throws IOException { for (int i = 0; i < cmds.length; i++) { sb.append(cmds[i] + " "); } - String responseMsg = execCurl(cmds); + String responseMsg = execCmd(cmds); Assert.assertEquals(responseMsg, ""); } } @@ -50,7 +50,7 @@ public void testStoreNodesDeployment() throws IOException, InterruptedException for (int i = 0; i < cmds.length; i++) { sb.append(cmds[i] + " "); } - String responseMsg = execCurl(cmds); + String responseMsg = execCmd(cmds); Assert.assertTrue(responseMsg.startsWith("{")); } } @@ -65,7 +65,7 @@ public void testServerNodesDeployment() throws IOException, InterruptedException for (int i = 0; i < cmds.length; i++) { sb.append(cmds[i] + " "); } - String responseMsg = execCurl(cmds); + String responseMsg = execCmd(cmds); Assert.assertTrue(responseMsg.startsWith("{")); } } 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 e42bd7711c..eb6092ae84 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 @@ -29,7 +29,6 @@ public class BaseSimpleTest { protected static BaseEnv env; - protected static Process p; @BeforeClass @@ -40,11 +39,11 @@ public static void initEnv() throws InterruptedException { @AfterClass public static void clearEnv() throws InterruptedException { - env.clearCluster(); + env.stopCluster(); Thread.sleep(2000); } - protected String execCurl(String[] cmds) throws IOException { + protected String execCmd(String[] cmds) throws IOException { ProcessBuilder process = new ProcessBuilder(cmds); p = process.start(); BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream())); @@ -57,4 +56,5 @@ protected String execCurl(String[] cmds) throws IOException { p.destroy(); return builder.toString(); } + } 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 9dee5ec306..c254fdbe3e 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 @@ -35,37 +35,35 @@ public void testPDNodesDeployment() throws IOException { for (int i = 0; i < cmds.length; i++) { sb.append(cmds[i] + " "); } - String responseMsg = execCurl(cmds); + String responseMsg = execCmd(cmds); Assert.assertEquals(responseMsg, ""); } } @Test - public void testStoreNodesDeployment() throws IOException, InterruptedException { + public void testStoreNodesDeployment() throws IOException { List addrs = env.getStoreRestAddrs(); for (String addr : addrs) { - String url = addr; - String[] cmds = {"curl", url}; - StringBuffer sb = new StringBuffer(); - for (int i = 0; i < cmds.length; i++) { - sb.append(cmds[i] + " "); + String[] cmds = {"curl", addr}; + StringBuilder sb = new StringBuilder(); + for (String cmd : cmds) { + sb.append(cmd).append(" "); } - String responseMsg = execCurl(cmds); + String responseMsg = execCmd(cmds); Assert.assertTrue(responseMsg.startsWith("{")); } } @Test - public void testServerNodesDeployment() throws IOException, InterruptedException { + public void testServerNodesDeployment() throws IOException { List addrs = env.getServerRestAddrs(); for (String addr : addrs) { - String url = addr; - String[] cmds = {"curl", url}; + String[] cmds = {"curl", addr}; StringBuffer sb = new StringBuffer(); - for (int i = 0; i < cmds.length; i++) { - sb.append(cmds[i] + " "); + for (String cmd : cmds) { + sb.append(cmd).append(" "); } - String responseMsg = execCurl(cmds); + String responseMsg = execCmd(cmds); Assert.assertTrue(responseMsg.startsWith("{")); } }