Skip to content

Commit

Permalink
chore(ct): reformat code & update config files
Browse files Browse the repository at this point in the history
  • Loading branch information
HJ-Young committed Sep 23, 2024
1 parent 4fa78c2 commit 48cfc6e
Show file tree
Hide file tree
Showing 13 changed files with 67 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 自动激活
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ public abstract class AbstractConfig {
protected Map<String, String> 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);
}
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<String> raftPeerList) {
Expand All @@ -83,10 +67,10 @@ public void setStoreGrpcList(List<String> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public void startCluster() {
}
}

public void clearCluster() {
public void stopCluster() {
for (ServerNodeWrapper serverNodeWrapper : serverNodeWrappers) {
serverNodeWrapper.stop();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public interface BaseEnv {
void startCluster();

/* clear the cluster env and all config*/
void clearCluster();
void stopCluster();

ClusterConf getConf();

Expand Down
20 changes: 20 additions & 0 deletions hugegraph-cluster-test/hugegraph-clustertest-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,26 @@
<version>${revision}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.hugegraph</groupId>
<artifactId>hugegraph-common</artifactId>
<version>1.5.0</version>
</dependency>
<dependency>
<groupId>org.apache.hugegraph</groupId>
<artifactId>hugegraph-client</artifactId>
<version>1.3.0</version>
</dependency>
<dependency>
<groupId>org.apache.hugegraph</groupId>
<artifactId>hg-store-client</artifactId>
<version>1.5.0</version>
</dependency>
<dependency>
<groupId>org.apache.hugegraph</groupId>
<artifactId>hg-pd-client</artifactId>
<version>1.5.0</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, "");
}
}
Expand All @@ -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("{"));
}
}
Expand All @@ -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("{"));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
public class BaseSimpleTest {

protected static BaseEnv env;

protected static Process p;

@BeforeClass
Expand All @@ -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()));
Expand All @@ -57,4 +56,5 @@ protected String execCurl(String[] cmds) throws IOException {
p.destroy();
return builder.toString();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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<String> 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("{"));
}
}
Expand Down

0 comments on commit 48cfc6e

Please sign in to comment.