You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ja...@apache.org on 2022/12/15 12:20:43 UTC
[iotdb] 03/03: fix
This is an automated email from the ASF dual-hosted git repository.
jackietien pushed a commit to branch DeleteStaleQueryCode
in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit 6e799ef2179bd6067464a5cbf6c6037cb023ad9f
Author: JackieTien97 <ja...@gmail.com>
AuthorDate: Thu Dec 15 20:20:24 2022 +0800
fix
---
cli/src/assembly/resources/sbin/start-cli.sh | 2 -
integration-test/import-control.xml | 1 +
integration-test/pom.xml | 5 +
.../java/org/apache/iotdb/it/env/AbstractEnv.java | 22 +++++
.../apache/iotdb/it/env/AbstractNodeWrapper.java | 4 +-
.../org/apache/iotdb/it/env/RemoteServerEnv.java | 20 ++++
.../java/org/apache/iotdb/itbase/env/BaseEnv.java | 8 ++
.../org/apache/iotdb/cli/it/AbstractScript.java | 105 +++++++++++++++++++++
.../apache/iotdb/cli/it}/StartClientScriptIT.java | 71 ++++++++++----
.../confignode/it/IoTDBClusterAuthorityIT.java | 3 +-
.../org/apache/iotdb/db/it/env/StandaloneEnv.java | 20 ++++
.../db/wal/recover/WALRecoverManagerTest.java | 5 +
12 files changed, 241 insertions(+), 25 deletions(-)
diff --git a/cli/src/assembly/resources/sbin/start-cli.sh b/cli/src/assembly/resources/sbin/start-cli.sh
index 137d04c0ad..d9650ce94e 100755
--- a/cli/src/assembly/resources/sbin/start-cli.sh
+++ b/cli/src/assembly/resources/sbin/start-cli.sh
@@ -110,8 +110,6 @@ IOTDB_CLI_CONF=${IOTDB_HOME}/conf
MAIN_CLASS=org.apache.iotdb.cli.Cli
-
-CLASSPATH=""
for f in ${IOTDB_HOME}/lib/*.jar; do
CLASSPATH=${CLASSPATH}":"$f
done
diff --git a/integration-test/import-control.xml b/integration-test/import-control.xml
index 9e7bee380d..9bc1cb14d2 100644
--- a/integration-test/import-control.xml
+++ b/integration-test/import-control.xml
@@ -65,6 +65,7 @@
<allow class="org.apache.iotdb.commons.exception.IllegalPathException" />
<allow class="org.apache.commons.codec.digest.DigestUtils" />
<allow class="org.apache.iotdb.commons.trigger.service.TriggerExecutableManager" />
+ <allow class="org.apache.iotdb.db.mpp.plan.statement.AuthorType" />
<allow class="org.apache.iotdb.commons.trigger.TriggerInformation" />
<allow class="org.apache.iotdb.commons.udf.UDFInformation" />
<allow class="org.apache.iotdb.commons.cq.CQState" />
diff --git a/integration-test/pom.xml b/integration-test/pom.xml
index 324f7e8ddd..597592706e 100644
--- a/integration-test/pom.xml
+++ b/integration-test/pom.xml
@@ -63,6 +63,11 @@
<artifactId>iotdb-jdbc</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.iotdb</groupId>
+ <artifactId>iotdb-cli</artifactId>
+ <version>${project.version}</version>
+ </dependency>
<dependency>
<groupId>org.apache.iotdb</groupId>
<artifactId>iotdb-confignode</artifactId>
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 86cc649615..9c42e9e12a 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
@@ -59,6 +59,8 @@ import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.stream.Stream;
+import static org.apache.iotdb.it.env.AbstractNodeWrapper.templateNodeLibPath;
+import static org.apache.iotdb.it.env.AbstractNodeWrapper.templateNodePath;
import static org.apache.iotdb.jdbc.Config.VERSION;
import static org.junit.Assert.fail;
@@ -596,4 +598,24 @@ public abstract class AbstractEnv implements BaseEnv {
int randomIndex = new Random(System.currentTimeMillis()).nextInt(dataNodeWrapperList.size());
return dataNodeWrapperList.get(randomIndex).getMqttPort();
}
+
+ @Override
+ public String getIP() {
+ return dataNodeWrapperList.get(0).getIp();
+ }
+
+ @Override
+ public String getPort() {
+ return String.valueOf(dataNodeWrapperList.get(0).getPort());
+ }
+
+ @Override
+ public String getSbinPath() {
+ return templateNodePath + File.separator + "sbin";
+ }
+
+ @Override
+ public String getLibPath() {
+ return templateNodeLibPath;
+ }
}
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 561cfe20fe..02c056dbd1 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
@@ -68,9 +68,9 @@ public abstract class AbstractNodeWrapper implements BaseNodeWrapper {
+ "bin"
+ File.separator
+ (SystemUtils.IS_OS_WINDOWS ? "java.exe" : "java");
- private final String templateNodePath =
+ public static final String templateNodePath =
System.getProperty("user.dir") + File.separator + "target" + File.separator + "template-node";
- protected static final String templateNodeLibPath =
+ public static final String templateNodeLibPath =
System.getProperty("user.dir")
+ File.separator
+ "target"
diff --git a/integration-test/src/main/java/org/apache/iotdb/it/env/RemoteServerEnv.java b/integration-test/src/main/java/org/apache/iotdb/it/env/RemoteServerEnv.java
index ba62c5e0c4..bacbe1be0c 100644
--- a/integration-test/src/main/java/org/apache/iotdb/it/env/RemoteServerEnv.java
+++ b/integration-test/src/main/java/org/apache/iotdb/it/env/RemoteServerEnv.java
@@ -213,4 +213,24 @@ public class RemoteServerEnv implements BaseEnv {
public int getMqttPort() {
throw new UnsupportedOperationException();
}
+
+ @Override
+ public String getIP() {
+ return ip_addr;
+ }
+
+ @Override
+ public String getPort() {
+ return port;
+ }
+
+ @Override
+ public String getSbinPath() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public String getLibPath() {
+ throw new UnsupportedOperationException();
+ }
}
diff --git a/integration-test/src/main/java/org/apache/iotdb/itbase/env/BaseEnv.java b/integration-test/src/main/java/org/apache/iotdb/itbase/env/BaseEnv.java
index ad57243849..266828c48a 100644
--- a/integration-test/src/main/java/org/apache/iotdb/itbase/env/BaseEnv.java
+++ b/integration-test/src/main/java/org/apache/iotdb/itbase/env/BaseEnv.java
@@ -210,4 +210,12 @@ public interface BaseEnv {
void shutdownDataNode(int index);
int getMqttPort();
+
+ String getIP();
+
+ String getPort();
+
+ String getSbinPath();
+
+ String getLibPath();
}
diff --git a/integration-test/src/test/java/org/apache/iotdb/cli/it/AbstractScript.java b/integration-test/src/test/java/org/apache/iotdb/cli/it/AbstractScript.java
new file mode 100644
index 0000000000..646df15582
--- /dev/null
+++ b/integration-test/src/test/java/org/apache/iotdb/cli/it/AbstractScript.java
@@ -0,0 +1,105 @@
+/*
+ * 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.iotdb.cli.it;
+
+import org.apache.iotdb.it.framework.IoTDBTestRunner;
+
+import org.apache.thrift.annotation.Nullable;
+import org.junit.runner.RunWith;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+@RunWith(IoTDBTestRunner.class)
+public abstract class AbstractScript {
+
+ protected void testOutput(ProcessBuilder builder, @Nullable String[] output, int statusCode)
+ throws IOException {
+ builder.redirectErrorStream(true);
+ Process p = builder.start();
+ BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
+ String line;
+ List<String> outputList = new ArrayList<>();
+ while (true) {
+ line = r.readLine();
+ if (line == null) {
+ break;
+ } else {
+ outputList.add(line);
+ }
+ }
+ r.close();
+ p.destroy();
+
+ System.out.println("Process output:");
+ for (String s : outputList) {
+ System.out.println(s);
+ }
+
+ if (output != null) {
+ for (int i = 0; i < output.length; i++) {
+ assertEquals(output[output.length - 1 - i], outputList.get(outputList.size() - 1 - i));
+ }
+ }
+ while (p.isAlive()) {
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ fail();
+ }
+ }
+ assertEquals(statusCode, p.exitValue());
+ }
+
+ protected String getCliPath() {
+ // This is usually always set by the JVM
+
+ File userDir = new File(System.getProperty("user.dir"));
+ if (!userDir.exists()) {
+ throw new RuntimeException("user.dir " + userDir.getAbsolutePath() + " doesn't exist.");
+ }
+ File target = new File(userDir, "target/maven-archiver/pom.properties");
+ Properties properties = new Properties();
+ try {
+ properties.load(new FileReader(target));
+ } catch (IOException e) {
+ return "target/iotdb-cli-";
+ }
+ return new File(
+ userDir,
+ String.format(
+ "target/%s-%s",
+ properties.getProperty("artifactId"), properties.getProperty("version")))
+ .getAbsolutePath();
+ }
+
+ protected abstract void testOnWindows() throws IOException;
+
+ protected abstract void testOnUnix() throws IOException;
+}
diff --git a/cli/src/test/java/org/apache/iotdb/cli/StartClientScriptIT.java b/integration-test/src/test/java/org/apache/iotdb/cli/it/StartClientScriptIT.java
similarity index 66%
rename from cli/src/test/java/org/apache/iotdb/cli/StartClientScriptIT.java
rename to integration-test/src/test/java/org/apache/iotdb/cli/it/StartClientScriptIT.java
index 6d8809568e..3214a4db5e 100644
--- a/cli/src/test/java/org/apache/iotdb/cli/StartClientScriptIT.java
+++ b/integration-test/src/test/java/org/apache/iotdb/cli/it/StartClientScriptIT.java
@@ -16,27 +16,46 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.iotdb.cli;
+package org.apache.iotdb.cli.it;
-import org.apache.iotdb.db.utils.EnvironmentUtils;
+import org.apache.iotdb.it.env.EnvFactory;
+import org.apache.iotdb.it.framework.IoTDBTestRunner;
+import org.apache.iotdb.itbase.category.ClusterIT;
+import org.apache.iotdb.itbase.category.LocalStandaloneIT;
-import org.junit.After;
-import org.junit.Before;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
import java.io.File;
import java.io.IOException;
+@RunWith(IoTDBTestRunner.class)
+@Category({LocalStandaloneIT.class, ClusterIT.class})
public class StartClientScriptIT extends AbstractScript {
- @Before
- public void setUp() {
- EnvironmentUtils.envSetUp();
+ private static String ip;
+
+ private static String port;
+
+ private static String sbinPath;
+
+ private static String libPath;
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+ EnvFactory.getEnv().initBeforeClass();
+ ip = EnvFactory.getEnv().getIP();
+ port = EnvFactory.getEnv().getPort();
+ sbinPath = EnvFactory.getEnv().getSbinPath();
+ libPath = EnvFactory.getEnv().getLibPath();
}
- @After
- public void tearDown() throws Exception {
- EnvironmentUtils.cleanEnv();
+ @AfterClass
+ public static void tearDown() throws Exception {
+ EnvFactory.getEnv().cleanAfterClass();
}
@Test
@@ -51,7 +70,6 @@ public class StartClientScriptIT extends AbstractScript {
@Override
protected void testOnWindows() throws IOException {
- String dir = getCliPath();
final String[] output = {
"Error: Connection Error, please check whether the network is available or the server has started. Host is 127.0.0.1, port is 6668."
};
@@ -59,9 +77,9 @@ public class StartClientScriptIT extends AbstractScript {
new ProcessBuilder(
"cmd.exe",
"/c",
- dir + File.separator + "sbin" + File.separator + "start-cli.bat",
+ sbinPath + File.separator + "start-cli.bat",
"-h",
- "127.0.0.1",
+ ip,
"-p",
"6668",
"-u",
@@ -71,6 +89,7 @@ public class StartClientScriptIT extends AbstractScript {
"&",
"exit",
"%^errorlevel%");
+ builder.environment().put("CLASSPATH", libPath);
testOutput(builder, output, 1);
final String[] output2 = {"Msg: The statement is executed successfully."};
@@ -78,7 +97,11 @@ public class StartClientScriptIT extends AbstractScript {
new ProcessBuilder(
"cmd.exe",
"/c",
- dir + File.separator + "sbin" + File.separator + "start-cli.bat",
+ sbinPath + File.separator + "start-cli.bat",
+ "-h",
+ ip,
+ "-p",
+ port,
"-maxPRC",
"0",
"-e",
@@ -86,6 +109,7 @@ public class StartClientScriptIT extends AbstractScript {
"&",
"exit",
"%^errorlevel%");
+ builder2.environment().put("CLASSPATH", libPath);
testOutput(builder2, output2, 0);
final String[] output3 = {
@@ -95,44 +119,50 @@ public class StartClientScriptIT extends AbstractScript {
new ProcessBuilder(
"cmd.exe",
"/c",
- dir + File.separator + "sbin" + File.separator + "start-cli.bat",
+ sbinPath + File.separator + "start-cli.bat",
"-maxPRC",
"-1111111111111111111111111111",
"&",
"exit",
"%^errorlevel%");
+ builder3.environment().put("CLASSPATH", libPath);
testOutput(builder3, output3, 1);
}
@Override
protected void testOnUnix() throws IOException {
- String dir = getCliPath();
final String[] output = {
"Error: Connection Error, please check whether the network is available or the server has started. Host is 127.0.0.1, port is 6668."
};
ProcessBuilder builder =
new ProcessBuilder(
"sh",
- dir + File.separator + "sbin" + File.separator + "start-cli.sh",
+ sbinPath + File.separator + "start-cli.sh",
"-h",
- "127.0.0.1",
+ ip,
"-p",
"6668",
"-u",
"root",
"-pw",
"root");
+ builder.environment().put("CLASSPATH", libPath);
testOutput(builder, output, 1);
final String[] output2 = {"Msg: The statement is executed successfully."};
ProcessBuilder builder2 =
new ProcessBuilder(
"sh",
- dir + File.separator + "sbin" + File.separator + "start-cli.sh",
+ sbinPath + File.separator + "start-cli.sh",
+ "-h",
+ ip,
+ "-p",
+ port,
"-maxPRC",
"0",
"-e",
"\"flush\"");
+ builder2.environment().put("CLASSPATH", libPath);
testOutput(builder2, output2, 0);
final String[] output3 = {
@@ -141,9 +171,10 @@ public class StartClientScriptIT extends AbstractScript {
ProcessBuilder builder3 =
new ProcessBuilder(
"sh",
- dir + File.separator + "sbin" + File.separator + "start-cli.sh",
+ sbinPath + File.separator + "start-cli.sh",
"-maxPRC",
"-1111111111111111111111111111");
+ builder3.environment().put("CLASSPATH", libPath);
testOutput(builder3, output3, 1);
}
}
diff --git a/integration-test/src/test/java/org/apache/iotdb/confignode/it/IoTDBClusterAuthorityIT.java b/integration-test/src/test/java/org/apache/iotdb/confignode/it/IoTDBClusterAuthorityIT.java
index 7a6dfc6b69..d23781343f 100644
--- a/integration-test/src/test/java/org/apache/iotdb/confignode/it/IoTDBClusterAuthorityIT.java
+++ b/integration-test/src/test/java/org/apache/iotdb/confignode/it/IoTDBClusterAuthorityIT.java
@@ -30,6 +30,7 @@ import org.apache.iotdb.db.mpp.plan.statement.AuthorType;
import org.apache.iotdb.it.env.EnvFactory;
import org.apache.iotdb.it.framework.IoTDBTestRunner;
import org.apache.iotdb.itbase.category.ClusterIT;
+import org.apache.iotdb.itbase.category.LocalStandaloneIT;
import org.apache.iotdb.rpc.TSStatusCode;
import org.apache.thrift.TException;
@@ -50,7 +51,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
@RunWith(IoTDBTestRunner.class)
-@Category({ClusterIT.class})
+@Category({LocalStandaloneIT.class, ClusterIT.class})
public class IoTDBClusterAuthorityIT {
@Before
diff --git a/integration-test/src/test/java/org/apache/iotdb/db/it/env/StandaloneEnv.java b/integration-test/src/test/java/org/apache/iotdb/db/it/env/StandaloneEnv.java
index ac2ca63976..37e7b9ad2d 100644
--- a/integration-test/src/test/java/org/apache/iotdb/db/it/env/StandaloneEnv.java
+++ b/integration-test/src/test/java/org/apache/iotdb/db/it/env/StandaloneEnv.java
@@ -222,4 +222,24 @@ public class StandaloneEnv implements BaseEnv {
public int getMqttPort() {
return 1883;
}
+
+ @Override
+ public String getIP() {
+ return "127.0.0.1";
+ }
+
+ @Override
+ public String getPort() {
+ return "6667";
+ }
+
+ @Override
+ public String getSbinPath() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public String getLibPath() {
+ throw new UnsupportedOperationException();
+ }
}
diff --git a/server/src/test/java/org/apache/iotdb/db/wal/recover/WALRecoverManagerTest.java b/server/src/test/java/org/apache/iotdb/db/wal/recover/WALRecoverManagerTest.java
index 0b8b3ebaa4..8464b92b23 100644
--- a/server/src/test/java/org/apache/iotdb/db/wal/recover/WALRecoverManagerTest.java
+++ b/server/src/test/java/org/apache/iotdb/db/wal/recover/WALRecoverManagerTest.java
@@ -108,10 +108,14 @@ public class WALRecoverManagerTest {
private TsFileResource tsFileWithWALResource;
private TsFileResource tsFileWithoutWALResource;
+ private boolean isClusterMode;
+
@Before
public void setUp() throws Exception {
+ isClusterMode = config.isClusterMode();
EnvironmentUtils.cleanDir(new File(FILE_WITH_WAL_NAME).getParent());
EnvironmentUtils.envSetUp();
+ config.setClusterMode(true);
prevMode = config.getWalMode();
config.setWalMode(WALMode.SYNC);
walBuffer = new WALBuffer(WAL_NODE_IDENTIFIER, WAL_NODE_FOLDER);
@@ -158,6 +162,7 @@ public class WALRecoverManagerTest {
checkpointManager.close();
walBuffer.close();
config.setWalMode(prevMode);
+ config.setClusterMode(isClusterMode);
EnvironmentUtils.cleanDir(new File(FILE_WITH_WAL_NAME).getParent());
EnvironmentUtils.cleanDir(new File(FILE_WITHOUT_WAL_NAME).getParent());
EnvironmentUtils.cleanEnv();