This is an automated email from the ASF dual-hosted git repository.
ericpai pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/master by this push:
new dce7c472c0 [IOTDB-3543] Use raw Java command to start nodes in cluster
test (#6549)
dce7c472c0 is described below
commit dce7c472c08946e0e7f07076151f61c262300634
Author: BaiJian <[email protected]>
AuthorDate: Tue Jul 5 19:55:37 2022 +0800
[IOTDB-3543] Use raw Java command to start nodes in cluster test (#6549)
---
integration-test/pom.xml | 46 --------
.../java/org/apache/iotdb/it/env/AbstractEnv.java | 2 +
.../apache/iotdb/it/env/AbstractNodeWrapper.java | 118 ++++++++-------------
.../org/apache/iotdb/it/env/ConfigNodeWrapper.java | 43 +++-----
.../org/apache/iotdb/it/env/DataNodeWrapper.java | 45 ++++----
.../iotdb/it/env/StandaloneDataNodeWrapper.java | 21 +---
6 files changed, 84 insertions(+), 191 deletions(-)
diff --git a/integration-test/pom.xml b/integration-test/pom.xml
index fccb4f5309..31328c9e96 100644
--- a/integration-test/pom.xml
+++ b/integration-test/pom.xml
@@ -142,52 +142,6 @@
</execution>
</executions>
</plugin>
- <!-- If the test starts separate processes, we can set
maximum-heap and new-heap size -->
- <plugin>
- <groupId>com.google.code.maven-replacer-plugin</groupId>
- <artifactId>replacer</artifactId>
- <version>1.5.3</version>
- <configuration>
- <skip>${integrationTest.launchNodeInSameJVM}</skip>
- </configuration>
- <executions>
- <execution>
- <phase>package</phase>
- <goals>
- <goal>replace</goal>
- </goals>
- <configuration>
-
<basedir>${project.build.directory}/template-node</basedir>
- <regex>true</regex>
- <commentsEnabled>false</commentsEnabled>
- <includes>
-
<include>datanode/conf/datanode-env.sh</include>
-
<include>confignode/conf/confignode-env.sh</include>
-
<include>datanode/conf/datanode-env.bat</include>
-
<include>confignode/conf/confignode-env.bat</include>
- </includes>
- <replacements>
- <replacement>
- <token>#HEAP_NEWSIZE=.*</token>
-
<value>HEAP_NEWSIZE="${integrationTest.nodeNewHeapSize}"</value>
- </replacement>
- <replacement>
- <token>#MAX_HEAP_SIZE=.*</token>
-
<value>MAX_HEAP_SIZE="${integrationTest.nodeMaxHeapSize}"</value>
- </replacement>
- <replacement>
- <token>@REM set HEAP_NEWSIZE.*</token>
- <value>set
HEAP_NEWSIZE="${integrationTest.nodeNewHeapSize}"</value>
- </replacement>
- <replacement>
- <token>@REM set MAX_HEAP_SIZE=.*</token>
- <value>set
MAX_HEAP_SIZE="${integrationTest.nodeMaxHeapSize}"</value>
- </replacement>
- </replacements>
- </configuration>
- </execution>
- </executions>
- </plugin>
<!-- Run integration tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
diff --git
a/integration-test/src/main/java/org/apache/iotdb/it/env/AbstractEnv.java
b/integration-test/src/main/java/org/apache/iotdb/it/env/AbstractEnv.java
index 7c4a104b8b..c09b07951d 100644
--- a/integration-test/src/main/java/org/apache/iotdb/it/env/AbstractEnv.java
+++ b/integration-test/src/main/java/org/apache/iotdb/it/env/AbstractEnv.java
@@ -177,7 +177,9 @@ public abstract class AbstractEnv implements BaseEnv {
});
}
try {
+ long startTime = System.currentTimeMillis();
testDelegate.requestAll();
+ logger.info("Start cluster costs: {}s", (System.currentTimeMillis() -
startTime) / 1000.0);
} catch (Exception e) {
fail("After 30 times retry, the cluster can't work!");
}
diff --git
a/integration-test/src/main/java/org/apache/iotdb/it/env/AbstractNodeWrapper.java
b/integration-test/src/main/java/org/apache/iotdb/it/env/AbstractNodeWrapper.java
index 6d02fd2f28..7e44cc3a4e 100644
---
a/integration-test/src/main/java/org/apache/iotdb/it/env/AbstractNodeWrapper.java
+++
b/integration-test/src/main/java/org/apache/iotdb/it/env/AbstractNodeWrapper.java
@@ -49,8 +49,10 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.time.LocalDateTime;
-import java.util.Collections;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
@@ -60,24 +62,28 @@ import static org.junit.Assert.fail;
public abstract class AbstractNodeWrapper implements BaseNodeWrapper {
private static final Logger logger =
LoggerFactory.getLogger(AbstractNodeWrapper.class);
+ private static final String javaCmd =
+ System.getProperty("java.home")
+ + File.separator
+ + "bin"
+ + File.separator
+ + (SystemUtils.IS_OS_WINDOWS ? "java.exe" : "java");
private final String templateNodePath =
System.getProperty("user.dir") + File.separator + "target" +
File.separator + "template-node";
- private final String templateNodeLibPath =
+ protected static final String templateNodeLibPath =
System.getProperty("user.dir")
+ File.separator
+ "target"
+ File.separator
+ "template-node-share"
+ File.separator
- + "lib";
- private final File NULL_FILE =
- SystemUtils.IS_OS_WINDOWS ? new File("nul") : new File("/dev/null");
+ + "lib"
+ + File.separator
+ + "*";
protected final String testClassName;
protected final String testMethodName;
protected final int[] portList;
- private final int jmxPort;
- private final String jmxUserName = "root";
- private final String jmxPassword = "passw!d";
+ protected final int jmxPort;
private final String TAB = " ";
private Process instance;
@@ -115,33 +121,6 @@ public abstract class AbstractNodeWrapper implements
BaseNodeWrapper {
}
});
}
- Path destLibPath = Paths.get(destPath, "lib");
- FileUtils.forceMkdir(destLibPath.toFile());
- // Create hard link for libs to decrease copy size
- try (Stream<Path> s = Files.walk(Paths.get(this.templateNodeLibPath))) {
- s.forEach(
- source -> {
- if (source.toFile().isFile()) {
- Path destination =
- Paths.get(
- destLibPath.toString(),
-
source.toString().substring(this.templateNodeLibPath.length()));
- try {
- Files.createLink(destination, source);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
- });
- }
- String startScriptPath = getStartScriptPath();
- String stopScriptPath = getStopScriptPath();
- if (!new File(startScriptPath).setExecutable(true)) {
- logger.error("Change {} to executable failed.", startScriptPath);
- }
- if (!new File(stopScriptPath).setExecutable(true)) {
- logger.error("Change {} to executable failed.", stopScriptPath);
- }
// Make sure the log dir exist, as the first file is output by starting
script directly.
FileUtils.createParentDirectories(new File(getLogPath()));
} catch (IOException ex) {
@@ -174,10 +153,36 @@ public abstract class AbstractNodeWrapper implements
BaseNodeWrapper {
public void start() {
try {
File stdoutFile = new File(getLogPath());
+ List<String> startCmd = new ArrayList<>();
+ startCmd.add(javaCmd);
+ if (!SystemUtils.IS_JAVA_1_8) {
+ startCmd.add("--add-opens=java.base/java.util.concurrent=ALL-UNNAMED");
+ startCmd.add("--add-opens=java.base/java.lang=ALL-UNNAMED");
+ startCmd.add("--add-opens=java.base/java.util=ALL-UNNAMED");
+ startCmd.add("--add-opens=java.base/java.nio=ALL-UNNAMED");
+ startCmd.add("--add-opens=java.base/java.io=ALL-UNNAMED");
+ startCmd.add("--add-opens=java.base/java.net=ALL-UNNAMED");
+ }
+ startCmd.addAll(
+ Arrays.asList(
+ "-Dcom.sun.management.jmxremote.port=" + jmxPort,
+ "-Dcom.sun.management.jmxremote.rmi.port=" + jmxPort,
+ "-Djava.rmi.server.randomIDs=true",
+ "-Dcom.sun.management.jmxremote.ssl=false",
+ "-Dcom.sun.management.jmxremote.authenticate=false",
+ "-Djava.rmi.server.hostname=" + getIp(),
+ "-Xms200m",
+ "-Xmx200m",
+ "-XX:MaxDirectMemorySize=200m",
+ "-Djdk.nio.maxCachedBufferSize=262144"));
+ addStartCmdParams(startCmd);
+ FileUtils.write(
+ stdoutFile, String.join(" ", startCmd) + "\n\n",
StandardCharsets.UTF_8, true);
ProcessBuilder processBuilder =
- new ProcessBuilder(getStartScriptPath())
- .redirectOutput(stdoutFile)
- .redirectError(stdoutFile);
+ new ProcessBuilder(startCmd)
+ .redirectOutput(ProcessBuilder.Redirect.appendTo(stdoutFile))
+ .redirectError(ProcessBuilder.Redirect.appendTo(stdoutFile));
+ processBuilder.environment().put("CLASSPATH", templateNodeLibPath);
this.instance = processBuilder.start();
logger.info("In test {} {} started.", getTestLogDirName(), getId());
} catch (IOException ex) {
@@ -191,25 +196,6 @@ public abstract class AbstractNodeWrapper implements
BaseNodeWrapper {
return;
}
this.instance.destroy();
- // In Windows, the IoTDB process is started as a subprocess of the
original batch script with a
- // new pid, so we need to kill the new subprocess as well.
- if (SystemUtils.IS_OS_WINDOWS) {
- ProcessBuilder processBuilder =
- new ProcessBuilder(getStopScriptPath())
- .redirectOutput(NULL_FILE)
- .redirectError(NULL_FILE);
- processBuilder.environment().put("CONSOLE_LOG_LEVEL", "DEBUG");
- Process p = null;
- try {
- p = processBuilder.start();
- p.waitFor(5, TimeUnit.SECONDS);
- } catch (IOException | InterruptedException e) {
- logger.error("Stop instance in Windows failed", e);
- if (p != null) {
- p.destroyForcibly();
- }
- }
- }
}
@Override
@@ -238,12 +224,6 @@ public abstract class AbstractNodeWrapper implements
BaseNodeWrapper {
try (FileWriter confOutput = new FileWriter(configPath)) {
configProperties.store(confOutput, null);
}
- // Change JMX config
- Path path = Paths.get(getEnvConfigPath());
- String content = new String(Files.readAllBytes(path),
StandardCharsets.UTF_8);
- content = content.replaceAll("JMX_LOCAL=\"true\"",
"JMX_LOCAL=\"false\"");
- content = content.replaceAll("JMX_PORT=\"\\d+\"",
String.format("JMX_PORT=\"%d\"", jmxPort));
- Files.write(path, content.getBytes(StandardCharsets.UTF_8));
} catch (IOException ex) {
fail("Change the config of data node failed. " + ex);
}
@@ -270,13 +250,9 @@ public abstract class AbstractNodeWrapper implements
BaseNodeWrapper {
protected abstract String getConfigPath();
- protected abstract String getEnvConfigPath();
-
protected abstract void updateConfig(Properties properties);
- protected abstract String getStartScriptPath();
-
- protected abstract String getStopScriptPath();
+ protected abstract void addStartCmdParams(List<String> params);
private String getLogPath() {
return getLogDirPath() + File.separator + getId() + ".log";
@@ -292,7 +268,7 @@ public abstract class AbstractNodeWrapper implements
BaseNodeWrapper {
+ getTestLogDirName();
}
- private String getNodePath() {
+ protected String getNodePath() {
return System.getProperty("user.dir") + File.separator + "target" +
File.separator + getId();
}
@@ -307,10 +283,8 @@ public abstract class AbstractNodeWrapper implements
BaseNodeWrapper {
logger.error("Construct JMX URL failed", e);
return;
}
- Map<String, Object> environment =
- Collections.singletonMap(JMXConnector.CREDENTIALS, new String[]
{jmxUserName, jmxPassword});
- try (JMXConnector connector = JMXConnectorFactory.connect(url,
environment)) {
+ try (JMXConnector connector = JMXConnectorFactory.connect(url)) {
MBeanServerConnection mbsc = connector.getMBeanServerConnection();
ThreadMXBean tmbean =
ManagementFactory.newPlatformMXBeanProxy(
diff --git
a/integration-test/src/main/java/org/apache/iotdb/it/env/ConfigNodeWrapper.java
b/integration-test/src/main/java/org/apache/iotdb/it/env/ConfigNodeWrapper.java
index b581a16d75..4fdcdda362 100644
---
a/integration-test/src/main/java/org/apache/iotdb/it/env/ConfigNodeWrapper.java
+++
b/integration-test/src/main/java/org/apache/iotdb/it/env/ConfigNodeWrapper.java
@@ -20,9 +20,9 @@ package org.apache.iotdb.it.env;
import org.apache.iotdb.commons.conf.IoTDBConstant;
-import org.apache.commons.lang3.SystemUtils;
-
import java.io.File;
+import java.util.Arrays;
+import java.util.List;
import java.util.Properties;
public class ConfigNodeWrapper extends AbstractNodeWrapper {
@@ -72,32 +72,6 @@ public class ConfigNodeWrapper extends AbstractNodeWrapper {
return workDirFilePath("confignode" + File.separator + "conf",
"iotdb-confignode.properties");
}
- @Override
- protected String getEnvConfigPath() {
- if (SystemUtils.IS_OS_WINDOWS) {
- return workDirFilePath("confignode" + File.separator + "conf",
"confignode-env.bat");
- }
- return workDirFilePath("confignode" + File.separator + "conf",
"confignode-env.sh");
- }
-
- @Override
- protected String getStartScriptPath() {
- String scriptName = "start-confignode.sh";
- if (SystemUtils.IS_OS_WINDOWS) {
- scriptName = "start-confignode.bat";
- }
- return workDirFilePath("confignode" + File.separator + "sbin", scriptName);
- }
-
- @Override
- protected String getStopScriptPath() {
- String scriptName = "stop-confignode.sh";
- if (SystemUtils.IS_OS_WINDOWS) {
- scriptName = "stop-confignode.bat";
- }
- return workDirFilePath("confignode" + File.separator + "sbin", scriptName);
- }
-
@Override
public final String getId() {
if (isSeed) {
@@ -105,4 +79,17 @@ public class ConfigNodeWrapper extends AbstractNodeWrapper {
}
return "ConfigNode" + getPort();
}
+
+ @Override
+ protected void addStartCmdParams(List<String> params) {
+ final String workDir = getNodePath() + File.separator + "confignode";
+ final String confDir = workDir + File.separator + "conf";
+ params.addAll(
+ Arrays.asList(
+ "-Dlogback.configurationFile=" + confDir + File.separator +
"logback.xml",
+ "-DCONFIGNODE_HOME=" + workDir,
+ "-DCONFIGNODE_CONF=" + confDir,
+ "org.apache.iotdb.confignode.service.ConfigNode",
+ "-s"));
+ }
}
diff --git
a/integration-test/src/main/java/org/apache/iotdb/it/env/DataNodeWrapper.java
b/integration-test/src/main/java/org/apache/iotdb/it/env/DataNodeWrapper.java
index 5e9848f117..53511f3803 100644
---
a/integration-test/src/main/java/org/apache/iotdb/it/env/DataNodeWrapper.java
+++
b/integration-test/src/main/java/org/apache/iotdb/it/env/DataNodeWrapper.java
@@ -20,9 +20,9 @@ package org.apache.iotdb.it.env;
import org.apache.iotdb.commons.conf.IoTDBConstant;
-import org.apache.commons.lang3.SystemUtils;
-
import java.io.File;
+import java.util.Arrays;
+import java.util.List;
import java.util.Properties;
public class DataNodeWrapper extends AbstractNodeWrapper {
@@ -46,7 +46,7 @@ public class DataNodeWrapper extends AbstractNodeWrapper {
@Override
protected void updateConfig(Properties properties) {
properties.setProperty(IoTDBConstant.RPC_ADDRESS, super.getIp());
- properties.setProperty(IoTDBConstant.INTERNAL_ADDRESS, "127.0.0.1");
+ properties.setProperty(IoTDBConstant.INTERNAL_ADDRESS, super.getIp());
properties.setProperty(IoTDBConstant.RPC_PORT, String.valueOf(getPort()));
properties.setProperty("mpp_data_exchange_port",
String.valueOf(this.mppDataExchangePort));
properties.setProperty(IoTDBConstant.INTERNAL_PORT,
String.valueOf(this.internalPort));
@@ -66,33 +66,26 @@ public class DataNodeWrapper extends AbstractNodeWrapper {
}
@Override
- protected String getEnvConfigPath() {
- if (SystemUtils.IS_OS_WINDOWS) {
- return workDirFilePath("datanode" + File.separator + "conf",
"datanode-env.bat");
- }
- return workDirFilePath("datanode" + File.separator + "conf",
"datanode-env.sh");
- }
-
- @Override
- protected String getStartScriptPath() {
- String scriptName = "start-datanode.sh";
- if (SystemUtils.IS_OS_WINDOWS) {
- scriptName = "start-datanode.bat";
- }
- return workDirFilePath("datanode" + File.separator + "sbin", scriptName);
+ public final String getId() {
+ return "DataNode" + getPort();
}
@Override
- protected String getStopScriptPath() {
- String scriptName = "stop-datanode.sh";
- if (SystemUtils.IS_OS_WINDOWS) {
- scriptName = "stop-datanode.bat";
- }
- return workDirFilePath("datanode" + File.separator + "sbin", scriptName);
+ protected void addStartCmdParams(List<String> params) {
+ final String workDir = getNodePath() + File.separator + "datanode";
+ final String confDir = workDir + File.separator + "conf";
+ params.addAll(
+ Arrays.asList(
+ "-Dlogback.configurationFile=" + confDir + File.separator +
"logback.xml",
+ "-DIOTDB_HOME=" + workDir,
+ "-DTSFILE_HOME=" + workDir,
+ "-DIOTDB_CONF=" + confDir,
+ "-DTSFILE_CONF=" + confDir,
+ mainClassName(),
+ "-s"));
}
- @Override
- public final String getId() {
- return "DataNode" + getPort();
+ protected String mainClassName() {
+ return "org.apache.iotdb.db.service.DataNode";
}
}
diff --git
a/integration-test/src/main/java/org/apache/iotdb/it/env/StandaloneDataNodeWrapper.java
b/integration-test/src/main/java/org/apache/iotdb/it/env/StandaloneDataNodeWrapper.java
index 5bf6de27e8..3c245f3ae5 100644
---
a/integration-test/src/main/java/org/apache/iotdb/it/env/StandaloneDataNodeWrapper.java
+++
b/integration-test/src/main/java/org/apache/iotdb/it/env/StandaloneDataNodeWrapper.java
@@ -18,10 +18,6 @@
*/
package org.apache.iotdb.it.env;
-import org.apache.commons.lang3.SystemUtils;
-
-import java.io.File;
-
public class StandaloneDataNodeWrapper extends DataNodeWrapper {
public StandaloneDataNodeWrapper(
@@ -30,20 +26,7 @@ public class StandaloneDataNodeWrapper extends
DataNodeWrapper {
}
@Override
- protected String getStartScriptPath() {
- String scriptName = "start-new-server.sh";
- if (SystemUtils.IS_OS_WINDOWS) {
- scriptName = "start-new-server.bat";
- }
- return workDirFilePath("datanode" + File.separator + "sbin", scriptName);
- }
-
- @Override
- protected String getStopScriptPath() {
- String scriptName = "stop-server.sh";
- if (SystemUtils.IS_OS_WINDOWS) {
- scriptName = "stop-server.bat";
- }
- return workDirFilePath("datanode" + File.separator + "sbin", scriptName);
+ protected String mainClassName() {
+ return "org.apache.iotdb.db.service.NewIoTDB";
}
}