javeme commented on code in PR #2615: URL: https://github.com/apache/incubator-hugegraph/pull/2615#discussion_r1769700195
########## hugegraph-cluster-test/hugegraph-clustertest-minicluster/src/main/java/org/apache/hugegraph/ct/base/EnvType.java: ########## @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hugegraph.ct.base; + +public enum EnvType { + Simple, + MultiNode; + + public static EnvType getSystemEnvType() { + String envType = System.getProperty("TestEnv", Simple.name()); Review Comment: expect "test_env" style ########## hugegraph-cluster-test/hugegraph-clustertest-minicluster/src/main/java/org/apache/hugegraph/ct/base/EnvUtil.java: ########## @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hugegraph.ct.base; + +import java.io.IOException; +import java.net.ServerSocket; +import java.util.ArrayList; +import java.util.List; + +import org.slf4j.Logger; + +public class EnvUtil { + + private static final Logger LOG = HGTestLogger.LOG; + private static final List<Integer> ports = new ArrayList<>(); + + public static int getAvailablePort() { + try { + ServerSocket socket = new ServerSocket(0); + int port = socket.getLocalPort(); + while (ports.contains(port)) { + socket.close(); + socket = new ServerSocket(0); + port = socket.getLocalPort(); + } Review Comment: can we use do-while to avoid repeated code? ########## hugegraph-cluster-test/hugegraph-clustertest-minicluster/src/main/java/org/apache/hugegraph/ct/config/PDConfig.java: ########## @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hugegraph.ct.config; + +import static org.apache.hugegraph.ct.base.ClusterConstant.APPLICATION_FILE; +import static org.apache.hugegraph.ct.base.ClusterConstant.CT_PACKAGE_PATH; +import static org.apache.hugegraph.ct.base.ClusterConstant.PD_TEMPLATE_FILE; +import static org.apache.hugegraph.ct.base.EnvUtil.getAvailablePort; + +import java.util.List; +import java.util.stream.Collectors; + +import lombok.Getter; + +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); + 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 + ":" + + 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); + } + + public void setRaftPeerList(List<String> raftPeerList) { + String raftPeers = raftPeerList.stream() + .collect(Collectors.joining(",")); + setProperty("RAFT_PEERS_LIST", raftPeers); + } + + public void setStoreCount(int storeCount) { + setProperty("STORE_COUNT", String.valueOf(storeCount)); + } + + public void setStoreGrpcList(List<String> storeGrpcList) { + String storeGrpcLists = storeGrpcList.stream() + .collect(Collectors.joining(",")); + setProperty("STORE_GRPC_LIST", storeGrpcLists); + } + + public String getRaftAddress() { + return raftHost + ":" + raftPort; Review Comment: expect "this." prefix for member access ########## hugegraph-cluster-test/hugegraph-clustertest-minicluster/src/main/java/org/apache/hugegraph/ct/base/HGTestLogger.java: ########## @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hugegraph.ct.base; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class HGTestLogger { + + public static Logger LOG = LoggerFactory.getLogger(HGTestLogger.class); Review Comment: prefer to don't share one LOG in whole module ########## hugegraph-cluster-test/hugegraph-clustertest-minicluster/src/main/java/org/apache/hugegraph/ct/base/EnvUtil.java: ########## @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hugegraph.ct.base; + +import java.io.IOException; +import java.net.ServerSocket; +import java.util.ArrayList; +import java.util.List; + +import org.slf4j.Logger; + +public class EnvUtil { + + private static final Logger LOG = HGTestLogger.LOG; + private static final List<Integer> ports = new ArrayList<>(); + + public static int getAvailablePort() { + try { + ServerSocket socket = new ServerSocket(0); + int port = socket.getLocalPort(); + while (ports.contains(port)) { + socket.close(); + socket = new ServerSocket(0); + port = socket.getLocalPort(); + } + ports.add(port); + socket.close(); + return port; + } catch (IOException e) { + LOG.error("fail to get available ports", e); Review Comment: `Failed to ...` ########## hugegraph-cluster-test/hugegraph-clustertest-minicluster/src/main/java/org/apache/hugegraph/ct/base/EnvType.java: ########## @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hugegraph.ct.base; + +public enum EnvType { + Simple, Review Comment: SingleNode ########## hugegraph-cluster-test/hugegraph-clustertest-minicluster/src/main/java/org/apache/hugegraph/ct/base/EnvUtil.java: ########## @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hugegraph.ct.base; + +import java.io.IOException; +import java.net.ServerSocket; +import java.util.ArrayList; +import java.util.List; + +import org.slf4j.Logger; + +public class EnvUtil { + + private static final Logger LOG = HGTestLogger.LOG; + private static final List<Integer> ports = new ArrayList<>(); + + public static int getAvailablePort() { + try { + ServerSocket socket = new ServerSocket(0); + int port = socket.getLocalPort(); + while (ports.contains(port)) { + socket.close(); + socket = new ServerSocket(0); + port = socket.getLocalPort(); + } + ports.add(port); + socket.close(); + return port; + } catch (IOException e) { + LOG.error("fail to get available ports", e); + return -1; + } + } + Review Comment: remove the blank line? ########## hugegraph-cluster-test/hugegraph-clustertest-minicluster/src/main/java/org/apache/hugegraph/ct/base/EnvUtil.java: ########## @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hugegraph.ct.base; + +import java.io.IOException; +import java.net.ServerSocket; +import java.util.ArrayList; +import java.util.List; + +import org.slf4j.Logger; + +public class EnvUtil { + + private static final Logger LOG = HGTestLogger.LOG; + private static final List<Integer> ports = new ArrayList<>(); Review Comment: prefer `Set<Integer>` ########## hugegraph-cluster-test/hugegraph-clustertest-minicluster/src/main/java/org/apache/hugegraph/ct/base/EnvType.java: ########## @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hugegraph.ct.base; + +public enum EnvType { Review Comment: expect a blank line ########## hugegraph-cluster-test/hugegraph-clustertest-minicluster/src/main/java/org/apache/hugegraph/ct/node/AbstractNodeWrapper.java: ########## @@ -0,0 +1,202 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hugegraph.ct.node; + +import static org.apache.hugegraph.ct.base.ClusterConstant.CT_PACKAGE_PATH; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.NoSuchFileException; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; +import java.util.concurrent.TimeUnit; +import java.util.stream.Stream; + +import org.apache.commons.io.FileUtils; +import org.apache.commons.io.file.PathUtils; +import org.apache.hugegraph.ct.base.ClusterConstant; +import org.apache.hugegraph.ct.base.HGTestLogger; +import org.slf4j.Logger; + +import lombok.Getter; + +public abstract class AbstractNodeWrapper implements BaseNodeWrapper { + + protected static final Logger LOG = HGTestLogger.LOG; + protected int clusterIndex; + @Getter + protected String workPath; + @Getter + protected String configPath; + protected Process instance; + protected int index; + protected List<String> fileNames; + protected String startLine; + + public AbstractNodeWrapper() { + this.clusterIndex = 1; + fileNames = new ArrayList<>(); + this.configPath = getNodePath(); + } + + public AbstractNodeWrapper(int clusterIndex, int index) { + this.clusterIndex = clusterIndex; + this.index = index; + fileNames = new ArrayList<>(); + this.configPath = getNodePath(); + } + + /** + * Node Dir should be created before changing Config + */ + public void createNodeDir(String destDir) { + try { + try { + if (!new File(destDir).exists()) { + FileUtils.createParentDirectories(new File(destDir)); + } + } catch (NoSuchFileException fileException) { + } + Path sourcePath = Paths.get(CT_PACKAGE_PATH); + // To avoid following symbolic links + try (Stream<Path> stream = Files.walk(sourcePath)) { + stream.forEach( + source -> { + Path relativePath = sourcePath.relativize(source); + Path destination = + Paths.get(destDir).resolve(relativePath); + if (fileNames.contains(relativePath.toString())) { + try { + if (Files.notExists(destination.getParent())) { + Files.createDirectories(destination.getParent()); + } + Files.copy(source, Review Comment: can we reduce the level of code nesting? ########## hugegraph-cluster-test/hugegraph-clustertest-minicluster/src/main/java/org/apache/hugegraph/ct/config/ServerConfig.java: ########## @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hugegraph.ct.config; + +import static org.apache.hugegraph.ct.base.ClusterConstant.CT_PACKAGE_PATH; +import static org.apache.hugegraph.ct.base.ClusterConstant.SERVER_PROPERTIES; +import static org.apache.hugegraph.ct.base.ClusterConstant.SERVER_TEMPLATE_FILE; +import static org.apache.hugegraph.ct.base.EnvUtil.getAvailablePort; Review Comment: expect we don't use import static ASAP ########## hugegraph-cluster-test/hugegraph-clustertest-minicluster/src/main/java/org/apache/hugegraph/ct/node/AbstractNodeWrapper.java: ########## @@ -0,0 +1,202 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hugegraph.ct.node; + +import static org.apache.hugegraph.ct.base.ClusterConstant.CT_PACKAGE_PATH; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.NoSuchFileException; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; +import java.util.concurrent.TimeUnit; +import java.util.stream.Stream; + +import org.apache.commons.io.FileUtils; +import org.apache.commons.io.file.PathUtils; +import org.apache.hugegraph.ct.base.ClusterConstant; +import org.apache.hugegraph.ct.base.HGTestLogger; +import org.slf4j.Logger; + +import lombok.Getter; + +public abstract class AbstractNodeWrapper implements BaseNodeWrapper { + + protected static final Logger LOG = HGTestLogger.LOG; + protected int clusterIndex; + @Getter + protected String workPath; + @Getter + protected String configPath; + protected Process instance; + protected int index; + protected List<String> fileNames; + protected String startLine; + + public AbstractNodeWrapper() { + this.clusterIndex = 1; + fileNames = new ArrayList<>(); + this.configPath = getNodePath(); + } + + public AbstractNodeWrapper(int clusterIndex, int index) { + this.clusterIndex = clusterIndex; + this.index = index; + fileNames = new ArrayList<>(); + this.configPath = getNodePath(); + } + + /** + * Node Dir should be created before changing Config + */ + public void createNodeDir(String destDir) { + try { + try { + if (!new File(destDir).exists()) { + FileUtils.createParentDirectories(new File(destDir)); + } + } catch (NoSuchFileException fileException) { Review Comment: can we mark ignored if it's expected or else handle the exception ########## hugegraph-cluster-test/hugegraph-clustertest-minicluster/src/main/java/org/apache/hugegraph/ct/config/ServerConfig.java: ########## @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hugegraph.ct.config; + +import static org.apache.hugegraph.ct.base.ClusterConstant.CT_PACKAGE_PATH; +import static org.apache.hugegraph.ct.base.ClusterConstant.SERVER_PROPERTIES; +import static org.apache.hugegraph.ct.base.ClusterConstant.SERVER_TEMPLATE_FILE; +import static org.apache.hugegraph.ct.base.EnvUtil.getAvailablePort; + +import lombok.Getter; + +public class ServerConfig extends AbstractConfig { + + @Getter + private int rpcPort, restPort; + @Getter + private String restHost, rpcHost; + + public ServerConfig() { + readTemplate(CT_PACKAGE_PATH + SERVER_TEMPLATE_FILE); + this.fileName = SERVER_PROPERTIES; + this.restHost = "127.0.0.1"; + this.rpcHost = "127.0.0.1"; + this.rpcPort = getAvailablePort(); + this.restPort = getAvailablePort(); + properties.put("REST_SERVER_ADDRESS", restHost + ":" + restPort); + properties.put("RPC_PORT", String.valueOf(rpcPort)); + properties.put("RPC_HOST", rpcHost); + } + + public void setRestHost(String restHost) { + this.restHost = restHost; + setProperty("REST_SERVER_ADDRESS", restHost + ":" + restPort); + } + + public void setServerID(String serverID) { + setProperty("SERVER_ID", serverID); + } + + public void setRole(String role) { + setProperty("ROLE", role); + } +} + Review Comment: ditto ########## hugegraph-cluster-test/hugegraph-clustertest-minicluster/src/main/java/org/apache/hugegraph/ct/config/AbstractConfig.java: ########## @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hugegraph.ct.config; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.HashMap; +import java.util.Map; + +import org.apache.hugegraph.ct.base.HGTestLogger; +import org.slf4j.Logger; + +public abstract class AbstractConfig { + + protected static final Logger LOG = HGTestLogger.LOG; + protected String config; + protected Map<String, String> properties = new HashMap<>(); + protected String fileName; + + protected void readTemplate(String filePath) { + try { + this.config = new String(Files.readAllBytes(Paths.get(filePath))); + } catch (IOException e) { + LOG.error("failed to get file", e); + } + } + + protected void updateConfigs() { + for (Map.Entry<String, String> entry : properties.entrySet()) { + String placeholder = "$" + entry.getKey() + "$"; + config = config.replace(placeholder, entry.getValue()); + } + } + + public void writeConfig(String filePath) { + updateConfigs(); + String destPath = filePath + File.separator + fileName; + try { + if (Files.notExists(Path.of(destPath).getParent())) { + Files.createDirectories(Path.of(destPath).getParent()); + } + } catch (IOException e) { + e.printStackTrace(); Review Comment: use log instead ########## hugegraph-cluster-test/hugegraph-clustertest-minicluster/src/main/java/org/apache/hugegraph/ct/config/ServerConfig.java: ########## @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hugegraph.ct.config; + +import static org.apache.hugegraph.ct.base.ClusterConstant.CT_PACKAGE_PATH; +import static org.apache.hugegraph.ct.base.ClusterConstant.SERVER_PROPERTIES; +import static org.apache.hugegraph.ct.base.ClusterConstant.SERVER_TEMPLATE_FILE; +import static org.apache.hugegraph.ct.base.EnvUtil.getAvailablePort; + +import lombok.Getter; + +public class ServerConfig extends AbstractConfig { + + @Getter + private int rpcPort, restPort; Review Comment: expect one member each line ########## hugegraph-cluster-test/hugegraph-clustertest-minicluster/src/main/java/org/apache/hugegraph/ct/config/AbstractConfig.java: ########## @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hugegraph.ct.config; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.HashMap; +import java.util.Map; + +import org.apache.hugegraph.ct.base.HGTestLogger; +import org.slf4j.Logger; + +public abstract class AbstractConfig { + + protected static final Logger LOG = HGTestLogger.LOG; + protected String config; + protected Map<String, String> properties = new HashMap<>(); + protected String fileName; + + protected void readTemplate(String filePath) { + try { + this.config = new String(Files.readAllBytes(Paths.get(filePath))); + } catch (IOException e) { + LOG.error("failed to get file", e); + } + } + + protected void updateConfigs() { + for (Map.Entry<String, String> entry : properties.entrySet()) { + String placeholder = "$" + entry.getKey() + "$"; + config = config.replace(placeholder, entry.getValue()); + } + } + + public void writeConfig(String filePath) { + updateConfigs(); + String destPath = filePath + File.separator + fileName; + try { + if (Files.notExists(Path.of(destPath).getParent())) { + Files.createDirectories(Path.of(destPath).getParent()); + } + } catch (IOException e) { + e.printStackTrace(); + } + try (FileWriter writer = new FileWriter(destPath)) { + writer.write(config); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public String getProperty(String propertyName) { + return properties.get(propertyName); + } + + protected void setProperty(String propertyName, String value) { + if (properties.containsKey(propertyName)) { + properties.replace(propertyName, value); + } else { + properties.put(propertyName, value); + } + } +} + + Review Comment: ditto ########## hugegraph-cluster-test/hugegraph-clustertest-minicluster/src/main/java/org/apache/hugegraph/ct/config/GraphConfig.java: ########## @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hugegraph.ct.config; + +import static org.apache.hugegraph.ct.base.ClusterConstant.CT_PACKAGE_PATH; +import static org.apache.hugegraph.ct.base.ClusterConstant.GRAPH_TEMPLATE_FILE; +import static org.apache.hugegraph.ct.base.ClusterConstant.HUGEGRAPH_PROPERTIES; + +import java.util.List; +import java.util.stream.Collectors; + +public class GraphConfig extends AbstractConfig { + + public GraphConfig() { + readTemplate(CT_PACKAGE_PATH + GRAPH_TEMPLATE_FILE); + this.fileName = HUGEGRAPH_PROPERTIES; + } + + public void setPDPeersList(List<String> pdPeersList) { + String pdPeers = pdPeersList.stream().collect(Collectors.joining(",")); + setProperty("PD_PEERS_LIST", pdPeers); + } + Review Comment: ditto ########## hugegraph-cluster-test/hugegraph-clustertest-minicluster/src/main/java/org/apache/hugegraph/ct/config/PDConfig.java: ########## @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hugegraph.ct.config; + +import static org.apache.hugegraph.ct.base.ClusterConstant.APPLICATION_FILE; +import static org.apache.hugegraph.ct.base.ClusterConstant.CT_PACKAGE_PATH; +import static org.apache.hugegraph.ct.base.ClusterConstant.PD_TEMPLATE_FILE; +import static org.apache.hugegraph.ct.base.EnvUtil.getAvailablePort; + +import java.util.List; +import java.util.stream.Collectors; + +import lombok.Getter; + +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); + 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 + ":" + + raftPort); Review Comment: keeping in one line is ok ########## hugegraph-cluster-test/hugegraph-clustertest-test/src/main/java/org/apache/hugegraph/SimpleClusterTest/SimpleClusterDeployTest.java: ########## @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hugegraph.SimpleClusterTest; + +import java.io.IOException; +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; + +public class SimpleClusterDeployTest extends BaseSimpleTest { + + @Test + public void testPDNodesDeployment() throws IOException { + List<String> addrs = env.getPDRestAddrs(); + 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 responseMsg = execCurl(cmds); + Assert.assertEquals(responseMsg, ""); + } + } + + @Test + public void testStoreNodesDeployment() throws IOException, InterruptedException { + 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 responseMsg = execCurl(cmds); + Assert.assertTrue(responseMsg.startsWith("{")); + } + } + + @Test + public void testServerNodesDeployment() throws IOException, InterruptedException { + List<String> addrs = env.getServerRestAddrs(); + for (String addr : addrs) { + String url = addr; + String[] cmds = {"curl", url}; Review Comment: not addressed? ########## hugegraph-cluster-test/hugegraph-clustertest-minicluster/pom.xml: ########## @@ -0,0 +1,66 @@ +<?xml version="1.0" encoding="UTF-8"?> Review Comment: this module is just for testing or can also be used for deployment in production environments? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
