You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by do...@apache.org on 2019/04/19 14:18:18 UTC
[incubator-iotdb] 01/01: add test for import/export script on
windows
This is an automated email from the ASF dual-hosted git repository.
dope pushed a commit to branch fix_jira_issue_80
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git
commit 72ff66bc71faa4a249c7c97b21a73a5c1126c16f
Author: xuyi556677@163.com <xu...@163.com>
AuthorDate: Fri Apr 19 22:17:58 2019 +0800
add test for import/export script on windows
---
iotdb-cli/cli/bin/export-csv.bat | 5 +-
iotdb-cli/cli/bin/export-csv.sh | 2 +-
iotdb-cli/cli/bin/import-csv.bat | 5 +-
iotdb-cli/cli/bin/import-csv.sh | 2 +-
.../java/org/apache/iotdb/cli/tool/ExportCsv.java | 59 +++++++++--------
.../java/org/apache/iotdb/cli/tool/ImportCsv.java | 59 ++++++++---------
.../apache/iotdb/cli/client/AbstractScript.java | 65 +++++++++++++++++++
.../iotdb/cli/client/StartClientScriptIT.java | 51 +++------------
.../ExportCsvTestIT.java} | 70 ++++++--------------
.../org/apache/iotdb/cli/tool/ImportCsvTestIT.java | 75 ++++++++++++++++++++++
10 files changed, 235 insertions(+), 158 deletions(-)
diff --git a/iotdb-cli/cli/bin/export-csv.bat b/iotdb-cli/cli/bin/export-csv.bat
index 3d6c1fa..23c3158 100644
--- a/iotdb-cli/cli/bin/export-csv.bat
+++ b/iotdb-cli/cli/bin/export-csv.bat
@@ -18,6 +18,9 @@
@REM
@echo off
+echo ````````````````````````````````````````````````
+echo Starting IoTDB Client Export Script
+echo ````````````````````````````````````````````````
if "%OS%" == "Windows_NT" setlocal
@@ -25,7 +28,7 @@ pushd %~dp0..
if NOT DEFINED IOTDB_HOME set IOTDB_HOME=%CD%
popd
-if NOT DEFINED MAIN_CLASS set MAIN_CLASS=org.apache.iotdb.db.tool.ExportCsv
+if NOT DEFINED MAIN_CLASS set MAIN_CLASS=org.apache.iotdb.cli.tool.ExportCsv
if NOT DEFINED JAVA_HOME goto :err
@REM -----------------------------------------------------------------------------
diff --git a/iotdb-cli/cli/bin/export-csv.sh b/iotdb-cli/cli/bin/export-csv.sh
index 5914ba7..32db7ff 100755
--- a/iotdb-cli/cli/bin/export-csv.sh
+++ b/iotdb-cli/cli/bin/export-csv.sh
@@ -44,7 +44,7 @@ for f in ${IOTDB_HOME}/lib/*.jar; do
CLASSPATH=${CLASSPATH}":"$f
done
-MAIN_CLASS=org.apache.iotdb.db.tool.ExportCsv
+MAIN_CLASS=org.apache.iotdb.cli.tool.ExportCsv
"$JAVA" -DIOTDB_HOME=${IOTDB_HOME} -cp "$CLASSPATH" "$MAIN_CLASS" "$@"
exit $?
\ No newline at end of file
diff --git a/iotdb-cli/cli/bin/import-csv.bat b/iotdb-cli/cli/bin/import-csv.bat
index c29b434..4dfcdd2 100644
--- a/iotdb-cli/cli/bin/import-csv.bat
+++ b/iotdb-cli/cli/bin/import-csv.bat
@@ -18,6 +18,9 @@
@REM
@echo off
+echo ````````````````````````````````````````````````
+echo Starting IoTDB Client Import Script
+echo ````````````````````````````````````````````````
if "%OS%" == "Windows_NT" setlocal
@@ -25,7 +28,7 @@ pushd %~dp0..
if NOT DEFINED IOTDB_HOME set IOTDB_HOME=%CD%
popd
-if NOT DEFINED MAIN_CLASS set MAIN_CLASS=org.apache.iotdb.db.tool.ImportCsv
+if NOT DEFINED MAIN_CLASS set MAIN_CLASS=org.apache.iotdb.cli.tool.ImportCsv
if NOT DEFINED JAVA_HOME goto :err
@REM -----------------------------------------------------------------------------
diff --git a/iotdb-cli/cli/bin/import-csv.sh b/iotdb-cli/cli/bin/import-csv.sh
index 6bcd595..eae5044 100755
--- a/iotdb-cli/cli/bin/import-csv.sh
+++ b/iotdb-cli/cli/bin/import-csv.sh
@@ -44,7 +44,7 @@ for f in ${IOTDB_HOME}/lib/*.jar; do
CLASSPATH=${CLASSPATH}":"$f
done
-MAIN_CLASS=org.apache.iotdb.db.tool.ImportCsv
+MAIN_CLASS=org.apache.iotdb.cli.tool.ImportCsv
"$JAVA" -DIOTDB_HOME=${IOTDB_HOME} -cp "$CLASSPATH" "$MAIN_CLASS" "$@"
exit $?
\ No newline at end of file
diff --git a/iotdb-cli/src/main/java/org/apache/iotdb/cli/tool/ExportCsv.java b/iotdb-cli/src/main/java/org/apache/iotdb/cli/tool/ExportCsv.java
index 3d103d0..4762519 100644
--- a/iotdb-cli/src/main/java/org/apache/iotdb/cli/tool/ExportCsv.java
+++ b/iotdb-cli/src/main/java/org/apache/iotdb/cli/tool/ExportCsv.java
@@ -44,8 +44,6 @@ import org.apache.iotdb.cli.exception.ArgsErrorException;
import org.apache.iotdb.jdbc.Config;
import org.apache.iotdb.jdbc.IoTDBConnection;
import org.apache.thrift.TException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
* Export CSV file.
@@ -55,20 +53,22 @@ import org.slf4j.LoggerFactory;
*/
public class ExportCsv extends AbstractCsvTool {
- private static final String TARGET_FILE_ARGS = "td";
- private static final String TARGET_FILE_NAME = "targetDirectory";
+ private static final String TARGET_DIR_ARGS = "td";
+ private static final String TARGET_DIR_NAME = "targetDirectory";
+
+ private static final String TARGET_FILE_ARGS = "f";
+ private static final String TARGET_FILE_NAME = "targetFile";
private static final String SQL_FILE_ARGS = "s";
private static final String SQL_FILE_NAME = "sqlfile";
private static final String TSFILEDB_CLI_PREFIX = "ExportCsv";
- private static final String DUMP_FILE_NAME = "dump";
+ private static final String DUMP_FILE_NAME_DEFAULT = "dump";
+ private static String targetFile = DUMP_FILE_NAME_DEFAULT;
private static String targetDirectory;
-
- private static final Logger LOGGER = LoggerFactory.getLogger(ExportCsv.class);
-
+
/**
* main function of export csv tool.
*/
@@ -81,14 +81,14 @@ public class ExportCsv extends AbstractCsvTool {
CommandLineParser parser = new DefaultParser();
if (args == null || args.length == 0) {
- LOGGER.error("Too few params input, please check the following hint.");
+ System.out.println("Too few params input, please check the following hint.");
hf.printHelp(TSFILEDB_CLI_PREFIX, options, true);
return;
}
try {
commandLine = parser.parse(options, args);
} catch (ParseException e) {
- LOGGER.error(e.getMessage());
+ System.out.println(e.getMessage());
hf.printHelp(TSFILEDB_CLI_PREFIX, options, true);
return;
}
@@ -125,18 +125,16 @@ public class ExportCsv extends AbstractCsvTool {
dumpFromSqlFile(sqlFile);
}
} catch (ClassNotFoundException e) {
- LOGGER.error(
- "Failed to dump data because cannot find TsFile JDBC Driver, "
- + "please check whether you have imported driver or not", e);
+ System.out.println("Failed to export data because cannot find IoTDB JDBC Driver, "
+ + "please check whether you have imported driver or not: " + e.getMessage());
+ } catch (TException e) {
+ System.out.println("Encounter an error when connecting to server, because " + e.getMessage());
} catch (SQLException e) {
- LOGGER.error("Encounter an error when dumping data, error is ", e);
+ System.out.println("Encounter an error when exporting data, error is: " + e.getMessage());
} catch (IOException e) {
- LOGGER.error("Failed to operate on file, because ", e);
- } catch (TException e) {
- LOGGER.error("Encounter an error when connecting to server, because ",
- e);
+ System.out.println("Failed to operate on file, because " + e.getMessage());
} catch (ArgsErrorException e) {
- LOGGER.error("Invalid args.", e);
+ System.out.println("Invalid args: " + e.getMessage());
} finally {
reader.close();
if (connection != null) {
@@ -147,7 +145,8 @@ public class ExportCsv extends AbstractCsvTool {
private static void parseSpecialParams(CommandLine commandLine)
throws ArgsErrorException {
- targetDirectory = checkRequiredArg(TARGET_FILE_ARGS, TARGET_FILE_NAME, commandLine);
+ targetDirectory = checkRequiredArg(TARGET_DIR_ARGS, TARGET_DIR_NAME, commandLine);
+ targetFile = commandLine.getOptionValue(TARGET_FILE_ARGS);
timeFormat = commandLine.getOptionValue(TIME_FORMAT_ARGS);
if (timeFormat == null) {
timeFormat = "default";
@@ -185,11 +184,15 @@ public class ExportCsv extends AbstractCsvTool {
.argName(PASSWORD_NAME).hasArg().desc("Password (optional)").build();
options.addOption(opPassword);
- Option opTargetFile = Option.builder(TARGET_FILE_ARGS).required().argName(TARGET_FILE_NAME)
+ Option opTargetFile = Option.builder(TARGET_DIR_ARGS).required().argName(TARGET_DIR_NAME)
.hasArg()
.desc("Target File Directory (required)").build();
options.addOption(opTargetFile);
+ Option targetFileName = Option.builder(TARGET_FILE_ARGS).argName(TARGET_FILE_NAME).hasArg()
+ .desc("Export file name (optional)").build();
+ options.addOption(targetFileName);
+
Option opSqlFile = Option.builder(SQL_FILE_ARGS).argName(SQL_FILE_NAME).hasArg()
.desc("SQL File Path (optional)").build();
options.addOption(opSqlFile);
@@ -221,7 +224,7 @@ public class ExportCsv extends AbstractCsvTool {
try {
dumpResult(sql, index);
} catch (SQLException e) {
- LOGGER.error("Cannot dump data for statement {}, because ", sql, e);
+ System.out.println("Cannot dump data for statement " + sql + ", because : " + e.getMessage());
}
index++;
}
@@ -238,15 +241,15 @@ public class ExportCsv extends AbstractCsvTool {
private static void dumpResult(String sql, int index)
throws SQLException {
- final String path = targetDirectory + DUMP_FILE_NAME + index + ".csv";
+ final String path = index > 0 ? targetDirectory + targetFile + ".csv" : targetDirectory + targetFile + index + ".csv";
File tf = new File(path);
try {
if (!tf.exists() && !tf.createNewFile()) {
- LOGGER.error("Could not create target file for sql statement: {}", sql);
+ System.out.println("Could not create target file for sql statement: " + sql);
return;
}
} catch (IOException e) {
- LOGGER.error("Cannot create dump file {}", path, e);
+ System.out.println("Cannot create dump file "+ path + "because: " + e.getMessage());
return;
}
@@ -261,10 +264,10 @@ public class ExportCsv extends AbstractCsvTool {
writeMetadata(bw, count, metadata);
writeResultSet(rs, bw, count);
- LOGGER.info("Statement [{}] has dumped to file {} successfully! It costs {}ms.",
- sql, path, System.currentTimeMillis() - startTime);
+ System.out.println(String.format("Statement [%s] has dumped to file %s successfully! "
+ + "It costs %dms.", sql, path, System.currentTimeMillis() - startTime));
} catch (IOException e) {
- LOGGER.error("Cannot dump result because", e);
+ System.out.println("Cannot dump result because: " + e.getMessage());
}
}
diff --git a/iotdb-cli/src/main/java/org/apache/iotdb/cli/tool/ImportCsv.java b/iotdb-cli/src/main/java/org/apache/iotdb/cli/tool/ImportCsv.java
index 6414d92..d3318f9 100644
--- a/iotdb-cli/src/main/java/org/apache/iotdb/cli/tool/ImportCsv.java
+++ b/iotdb-cli/src/main/java/org/apache/iotdb/cli/tool/ImportCsv.java
@@ -58,9 +58,6 @@ import org.slf4j.LoggerFactory;
* @author zhanggr
*/
public class ImportCsv extends AbstractCsvTool {
-
- private static final Logger LOGGER = LoggerFactory.getLogger(ImportCsv.class);
-
private static final String FILE_ARGS = "f";
private static final String FILE_NAME = "file or folder";
private static final String FILE_SUFFIX = "csv";
@@ -131,7 +128,7 @@ public class ImportCsv extends AbstractCsvTool {
try {
errorFile.createNewFile();
} catch (IOException e) {
- LOGGER.error("Cannot create a errorFile because, ", e);
+ System.out.println("Cannot create a errorFile because: " + e.getMessage());
return;
}
}
@@ -158,7 +155,7 @@ public class ImportCsv extends AbstractCsvTool {
String[] strHeadInfo = header.split(",");
if (strHeadInfo.length <= 1) {
- LOGGER.error("The CSV file {} illegal, please check first line", file.getName());
+ System.out.println("The CSV file "+ file.getName() +" illegal, please check first line");
return;
}
@@ -185,11 +182,11 @@ public class ImportCsv extends AbstractCsvTool {
executeSqls(bw, tmp, startTime, file);
} catch (FileNotFoundException e) {
- LOGGER.error("Cannot find {}", file.getName(), e);
+ System.out.println("Cannot find " + file.getName() + " because: "+e.getMessage());
} catch (IOException e) {
- LOGGER.error("CSV file read exception! ", e);
+ System.out.println("CSV file read exception because: " + e.getMessage());
} catch (SQLException e) {
- LOGGER.error("Database connection exception!", e);
+ System.out.println("Database connection exception because: " + e.getMessage());
} finally {
try {
if (statement != null) {
@@ -198,13 +195,13 @@ public class ImportCsv extends AbstractCsvTool {
if (errorFlag) {
FileUtils.forceDelete(errorFile);
} else {
- LOGGER.error("Format of some lines in {} error, please check {} for more "
- + "information", file.getAbsolutePath(), errorFile.getAbsolutePath());
+ System.out.println("Format of some lines in "+ file.getAbsolutePath() + " error, please "
+ + "check "+errorFile.getAbsolutePath()+" for more information");
}
} catch (SQLException e) {
- LOGGER.error("Sql statement can not be closed ! ", e);
+ System.out.println("Sql statement can not be closed because: " + e.getMessage());
} catch (IOException e) {
- LOGGER.error("Close file error ! ", e);
+ System.out.println("Close file error because: " + e.getMessage());
}
}
}
@@ -222,13 +219,13 @@ public class ImportCsv extends AbstractCsvTool {
}
statement.clearBatch();
tmp.clear();
- LOGGER.info("Load data from {} successfully, it takes {}ms", file.getName(),
- System.currentTimeMillis() - startTime);
+ System.out.println("Load data from "+ file.getName() +" successfully, it takes "
+ + ""+(System.currentTimeMillis() - startTime)+"ms");
} catch (SQLException e) {
bw.write(e.getMessage());
bw.newLine();
errorFlag = false;
- LOGGER.error("Cannot execute sql because ", e);
+ System.out.println("Cannot execute sql because: " + e.getMessage());
}
}
@@ -244,7 +241,7 @@ public class ImportCsv extends AbstractCsvTool {
} catch (Exception e) {
bw.write(String.format("error input line, maybe it is not complete: %s", line));
bw.newLine();
- LOGGER.error("Cannot create sql for {} because ", line, e);
+ System.out.println("Cannot create sql for " + line + " because: " + e.getMessage());
errorFlag = false;
return false;
}
@@ -269,7 +266,7 @@ public class ImportCsv extends AbstractCsvTool {
bw.write(e.getMessage());
bw.newLine();
errorFlag = false;
- LOGGER.error("Cannot execute sql because ", e);
+ System.out.println("Cannot execute sql because: " + e.getMessage());
return false;
}
}
@@ -308,8 +305,8 @@ public class ImportCsv extends AbstractCsvTool {
} else {
String errorInfo = String.format("Database cannot find %s in %s, stop import!",
strHeadInfo[i], file.getAbsolutePath());
- LOGGER.error("Database cannot find {} in {}, stop import!",
- strHeadInfo[i], file.getAbsolutePath());
+ System.out.println("Database cannot find "+strHeadInfo[i]+" in "+file.getAbsolutePath()+", "
+ + "stop import!");
bw.write(errorInfo);
return false;
}
@@ -389,14 +386,14 @@ public class ImportCsv extends AbstractCsvTool {
CommandLineParser parser = new DefaultParser();
if (args == null || args.length == 0) {
- LOGGER.error("Too few params input, please check the following hint.");
+ System.out.println("Too few params input, please check the following hint.");
hf.printHelp(TSFILEDB_CLI_PREFIX, options, true);
return;
}
try {
commandLine = parser.parse(options, args);
} catch (ParseException e) {
- LOGGER.error("Parse error ", e);
+ System.out.println("Parse error: " + e.getMessage());
hf.printHelp(TSFILEDB_CLI_PREFIX, options, true);
return;
}
@@ -417,9 +414,9 @@ public class ImportCsv extends AbstractCsvTool {
parseSpecialParams(commandLine);
importCsvFromFile(host, port, username, password, filename, timeZoneID);
} catch (ArgsErrorException e) {
- LOGGER.error("Args error", e);
+ System.out.println("Args error: " + e.getMessage());
} catch (Exception e) {
- LOGGER.error("Encounter an error, because ", e);
+ System.out.println("Encounter an error, because: " + e.getMessage());
} finally {
reader.close();
}
@@ -454,14 +451,14 @@ public class ImportCsv extends AbstractCsvTool {
}
} catch (ClassNotFoundException e) {
- LOGGER.error(
- "Failed to dump data because cannot find TsFile JDBC Driver, "
- + "please check whether you have imported driver or not", e);
+ System.out.println("Failed to import data because cannot find IoTDB JDBC Driver, "
+ + "please check whether you have imported driver or not: " + e.getMessage());
} catch (TException e) {
- LOGGER.error("Encounter an error when connecting to server, because ",
- e);
+ System.out.println("Encounter an error when connecting to server, because " + e.getMessage());
+ } catch (SQLException e){
+ System.out.println("Encounter an error when importing data, error is: " + e.getMessage());
} catch (Exception e) {
- LOGGER.error("Encounter an error, because ", e);
+ System.out.println("Encounter an error, because: " + e.getMessage());
} finally {
if (connection != null) {
connection.close();
@@ -473,7 +470,7 @@ public class ImportCsv extends AbstractCsvTool {
if (file.getName().endsWith(FILE_SUFFIX)) {
loadDataFromCSV(file, 1);
} else {
- LOGGER.warn("File {} should ends with '.csv' if you want to import", file.getName());
+ System.out.println("File "+ file.getName() +" should ends with '.csv' if you want to import");
}
}
@@ -490,7 +487,7 @@ public class ImportCsv extends AbstractCsvTool {
loadDataFromCSV(subFile, i);
i++;
} else {
- LOGGER.warn("File {} should ends with '.csv' if you want to import", file.getName());
+ System.out.println("File " + file.getName() + " should ends with '.csv' if you want to import");
}
}
}
diff --git a/iotdb-cli/src/test/java/org/apache/iotdb/cli/client/AbstractScript.java b/iotdb-cli/src/test/java/org/apache/iotdb/cli/client/AbstractScript.java
new file mode 100644
index 0000000..4ca8c33
--- /dev/null
+++ b/iotdb-cli/src/test/java/org/apache/iotdb/cli/client/AbstractScript.java
@@ -0,0 +1,65 @@
+/**
+ * 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.client;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.List;
+
+public abstract class AbstractScript {
+
+ protected void testOutput(ProcessBuilder builder, String[] output) 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();
+
+ for (int i = 0; i < output.length; i++) {
+ assertEquals(output[output.length - 1 - i], outputList.get(outputList.size() - 1 - i));
+ }
+ }
+
+ protected String getCurrentPath(String... command) throws IOException {
+ ProcessBuilder builder = new ProcessBuilder(command);
+ builder.redirectErrorStream(true);
+ Process p = builder.start();
+ BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
+ String path = r.readLine();
+ return path;
+ }
+
+ protected abstract void testOnWindows() throws IOException;
+
+ protected abstract void testOnUnix() throws IOException;
+}
diff --git a/iotdb-cli/src/test/java/org/apache/iotdb/cli/client/StartClientScriptIT.java b/iotdb-cli/src/test/java/org/apache/iotdb/cli/client/StartClientScriptIT.java
index bf717ac..74b7162 100644
--- a/iotdb-cli/src/test/java/org/apache/iotdb/cli/client/StartClientScriptIT.java
+++ b/iotdb-cli/src/test/java/org/apache/iotdb/cli/client/StartClientScriptIT.java
@@ -18,19 +18,14 @@
*/
package org.apache.iotdb.cli.client;
-import static org.junit.Assert.assertEquals;
-
-import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
-import java.io.InputStreamReader;
-import java.util.ArrayList;
-import java.util.List;
+
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-public class StartClientScriptIT {
+public class StartClientScriptIT extends AbstractScript {
@Before
public void setUp() throws Exception {
@@ -42,16 +37,16 @@ public class StartClientScriptIT {
@Test
public void test() throws IOException, InterruptedException {
-
String os = System.getProperty("os.name").toLowerCase();
if (os.startsWith("windows")) {
- testStartClientOnWindows();
+ testOnWindows();
} else {
- testStartClientOnUnix();
+ testOnUnix();
}
}
- private void testStartClientOnWindows() throws IOException {
+ @Override
+ protected void testOnWindows() throws IOException {
final String[] output = {"````````````````````````", "Starting IoTDB Client",
"````````````````````````",
"IoTDB> Connection Error, please check whether the network is available or the server has started. Host is 127.0.0.1, port is 6668."};
@@ -63,7 +58,8 @@ public class StartClientScriptIT {
testOutput(builder, output);
}
- private void testStartClientOnUnix() throws IOException {
+ @Override
+ protected void testOnUnix() throws IOException {
final String[] output = {"---------------------", "Starting IoTDB Client",
"---------------------",
"IoTDB> Connection Error, please check whether the network is available or the server has started. Host is 127.0.0.1, port is 6668."};
@@ -75,35 +71,4 @@ public class StartClientScriptIT {
"127.0.0.1", "-p", "6668", "-u", "root", "-pw", "root");
testOutput(builder, output);
}
-
- private void testOutput(ProcessBuilder builder, String[] output) 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();
-
- for (int i = 0; i < output.length; i++) {
- assertEquals(output[output.length - 1 - i], outputList.get(outputList.size() - 1 - i));
- }
- }
-
- private String getCurrentPath(String... command) throws IOException {
- ProcessBuilder builder = new ProcessBuilder(command);
- builder.redirectErrorStream(true);
- Process p = builder.start();
- BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
- String path = r.readLine();
- return path;
- }
}
diff --git a/iotdb-cli/src/test/java/org/apache/iotdb/cli/client/StartClientScriptIT.java b/iotdb-cli/src/test/java/org/apache/iotdb/cli/tool/ExportCsvTestIT.java
similarity index 51%
copy from iotdb-cli/src/test/java/org/apache/iotdb/cli/client/StartClientScriptIT.java
copy to iotdb-cli/src/test/java/org/apache/iotdb/cli/tool/ExportCsvTestIT.java
index bf717ac..f635567 100644
--- a/iotdb-cli/src/test/java/org/apache/iotdb/cli/client/StartClientScriptIT.java
+++ b/iotdb-cli/src/test/java/org/apache/iotdb/cli/tool/ExportCsvTestIT.java
@@ -16,21 +16,16 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.iotdb.cli.client;
+package org.apache.iotdb.cli.tool;
-import static org.junit.Assert.assertEquals;
-
-import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
-import java.io.InputStreamReader;
-import java.util.ArrayList;
-import java.util.List;
+import org.apache.iotdb.cli.client.AbstractScript;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-public class StartClientScriptIT {
+public class ExportCsvTestIT extends AbstractScript{
@Before
public void setUp() throws Exception {
@@ -41,69 +36,40 @@ public class StartClientScriptIT {
}
@Test
- public void test() throws IOException, InterruptedException {
-
+ public void test() throws IOException{
String os = System.getProperty("os.name").toLowerCase();
if (os.startsWith("windows")) {
- testStartClientOnWindows();
+ testOnWindows();
} else {
- testStartClientOnUnix();
+ testOnUnix();
}
}
- private void testStartClientOnWindows() throws IOException {
- final String[] output = {"````````````````````````", "Starting IoTDB Client",
- "````````````````````````",
- "IoTDB> Connection Error, please check whether the network is available or the server has started. Host is 127.0.0.1, port is 6668."};
+ @Override
+ protected void testOnWindows() throws IOException {
+ final String[] output = {"````````````````````````````````````````````````",
+ "Starting IoTDB Client Export Script",
+ "````````````````````````````````````````````````",
+ "Encounter an error when exporting data, error is: Connection Error, "
+ + "please check whether the network is available or the server has started."};
String dir = getCurrentPath("cmd.exe", "/c", "echo %cd%");
ProcessBuilder builder = new ProcessBuilder("cmd.exe", "/c",
- dir + File.separator + "cli" + File.separator + "bin" + File.separator + "start-client.bat",
- "-h",
- "127.0.0.1", "-p", "6668", "-u", "root", "-pw", "root");
+ dir + File.separator + "cli" + File.separator + "bin" + File.separator + "export-csv.bat",
+ "-h", "127.0.0.1", "-p", "6668", "-u", "root", "-pw", "root", "-td", "./");
testOutput(builder, output);
}
- private void testStartClientOnUnix() throws IOException {
+ @Override
+ protected void testOnUnix() throws IOException {
final String[] output = {"---------------------", "Starting IoTDB Client",
"---------------------",
"IoTDB> Connection Error, please check whether the network is available or the server has started. Host is 127.0.0.1, port is 6668."};
String dir = getCurrentPath("pwd");
System.out.println(dir);
ProcessBuilder builder = new ProcessBuilder("sh",
- dir + File.separator + "cli" + File.separator + "bin" + File.separator + "start-client.sh",
+ dir + File.separator + "cli" + File.separator + "bin" + File.separator + "export-csv.sh",
"-h",
"127.0.0.1", "-p", "6668", "-u", "root", "-pw", "root");
testOutput(builder, output);
}
-
- private void testOutput(ProcessBuilder builder, String[] output) 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();
-
- for (int i = 0; i < output.length; i++) {
- assertEquals(output[output.length - 1 - i], outputList.get(outputList.size() - 1 - i));
- }
- }
-
- private String getCurrentPath(String... command) throws IOException {
- ProcessBuilder builder = new ProcessBuilder(command);
- builder.redirectErrorStream(true);
- Process p = builder.start();
- BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
- String path = r.readLine();
- return path;
- }
}
diff --git a/iotdb-cli/src/test/java/org/apache/iotdb/cli/tool/ImportCsvTestIT.java b/iotdb-cli/src/test/java/org/apache/iotdb/cli/tool/ImportCsvTestIT.java
new file mode 100644
index 0000000..621c682
--- /dev/null
+++ b/iotdb-cli/src/test/java/org/apache/iotdb/cli/tool/ImportCsvTestIT.java
@@ -0,0 +1,75 @@
+/**
+ * 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.tool;
+
+import java.io.File;
+import java.io.IOException;
+import org.apache.iotdb.cli.client.AbstractScript;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class ImportCsvTestIT extends AbstractScript {
+
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ @Test
+ public void test() throws IOException{
+ String os = System.getProperty("os.name").toLowerCase();
+ if (os.startsWith("windows")) {
+ testOnWindows();
+ } else {
+ testOnUnix();
+ }
+ }
+
+ @Override
+ protected void testOnWindows() throws IOException {
+ final String[] output = {"````````````````````````````````````````````````",
+ "Starting IoTDB Client Import Script",
+ "````````````````````````````````````````````````",
+ "Encounter an error when importing data, error is: Connection Error, please check whether "
+ + "the network is available or the server has started."};
+ String dir = getCurrentPath("cmd.exe", "/c", "echo %cd%");
+ ProcessBuilder builder = new ProcessBuilder("cmd.exe", "/c",
+ dir + File.separator + "cli" + File.separator + "bin" + File.separator + "import-csv.bat",
+ "-h", "127.0.0.1", "-p", "6668", "-u", "root", "-pw", "root", "-f", "./");
+ testOutput(builder, output);
+ }
+
+ @Override
+ protected void testOnUnix() throws IOException {
+ final String[] output = {"---------------------", "Starting IoTDB Client",
+ "---------------------",
+ "IoTDB> Connection Error, please check whether the network is available or the server has started. Host is 127.0.0.1, port is 6668."};
+ String dir = getCurrentPath("pwd");
+ System.out.println(dir);
+ ProcessBuilder builder = new ProcessBuilder("sh",
+ dir + File.separator + "cli" + File.separator + "bin" + File.separator + "import-csv.sh",
+ "-h",
+ "127.0.0.1", "-p", "6668", "-u", "root", "-pw", "root");
+ testOutput(builder, output);
+ }
+}