Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.apache.iotdb.it.env.EnvFactory;
import org.apache.iotdb.it.framework.IoTDBTestRunner;
import org.apache.iotdb.itbase.category.TableLocalStandaloneIT;
import org.apache.iotdb.itbase.env.BaseEnv;

import org.apache.ratis.thirdparty.com.google.gson.JsonParser;
import org.junit.AfterClass;
Expand All @@ -34,8 +35,11 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.sql.Connection;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
Expand Down Expand Up @@ -83,6 +87,57 @@ public void test() throws IOException {
}
}

@Test
public void testServerMessageIsAppendedToSuccessMessage() throws Exception {
String database = "test_cli_server_message_" + UUID.randomUUID().toString().replace("-", "");
try (Connection connection = EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT);
Statement statement = connection.createStatement()) {
statement.execute("CREATE DATABASE " + database);
statement.execute(
"CREATE TABLE " + database + ".drop_target (device STRING TAG, reading INT32 FIELD)");
statement.execute(
"INSERT INTO " + database + ".drop_target(time, device, reading) VALUES (1, 'd1', 1)");
statement.execute("FLUSH");
}

String dropTableSql = "DROP TABLE " + database + ".drop_target";
ProcessBuilder builder;
if (System.getProperty("os.name").toLowerCase().startsWith("windows")) {
builder =
new ProcessBuilder(
"cmd.exe",
"/c",
sbinPath + File.separator + "windows" + File.separator + "start-cli.bat",
"-h",
ip,
"-p",
port,
"-sql_dialect",
"table",
"-e",
dropTableSql,
"&",
"exit",
"%^errorlevel%");
} else {
builder =
new ProcessBuilder(
"bash",
sbinPath + File.separator + "start-cli.sh",
"-h",
ip,
"-p",
port,
"-sql_dialect",
"table",
"-e",
"\"" + dropTableSql + "\"");
}
builder.environment().put("IOTDB_HOME", homePath);
testOutput(
builder, new String[] {"The statement is executed successfully. Table deletion task"}, 0);
}

@Override
protected void testOnWindows() throws IOException {
// Setup test data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -775,13 +775,10 @@ private static int executeQuery(CliContext ctx, IoTDBConnection connection, Stri
String.format(
CliMessages.LOG_MSG_ARG_240992E0, Objects.toString(SUCCESS_MESSAGE)));
} else {
ctx.getPrinter()
.println(
String.format(CliMessages.LOG_MSG_ARG_240992E0, Objects.toString(serverMessage)));
ctx.getPrinter()
.println(
String.format(
CliMessages.LOG_MSG_ARG_240992E0, Objects.toString(SUCCESS_MESSAGE)));
CliMessages.LOG_MSG_ARG_240992E0, SUCCESS_MESSAGE + " " + serverMessage));
}
}
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.apache.iotdb.cli;

import org.apache.iotdb.cli.AbstractCli.OperationResult;
import org.apache.iotdb.cli.i18n.CliMessages;
import org.apache.iotdb.cli.type.ExitType;
import org.apache.iotdb.cli.utils.CliContext;
import org.apache.iotdb.common.rpc.thrift.TSStatus;
Expand Down Expand Up @@ -118,7 +119,7 @@ public void testRegionValidationErrorIsPrintedAndReturnsErrorStatus() throws Exc
}

@Test
public void testCustomSuccessMessageIsSeparateFromGenericMessage() throws Exception {
public void testServerMessageIsAppendedToSuccessMessage() throws Exception {
String sql = "DROP TABLE test_table";
String statusMessage =
"Table deletion task 123 has been submitted for asynchronous execution. "
Expand All @@ -136,16 +137,19 @@ public void testCustomSuccessMessageIsSeparateFromGenericMessage() throws Except
AbstractCli.handleInputCmd(ctx, sql, connection);

String output = new String(out.toByteArray(), StandardCharsets.UTF_8);
assertTrue(output.contains(statusMessage));
assertTrue(output.contains("The statement is executed successfully"));
assertTrue(
output.indexOf(statusMessage) < output.indexOf("The statement is executed successfully"));
assertFalse(output.contains("The statement is executed successfully. " + statusMessage));
assertEquals(
String.format(
CliMessages.LOG_MSG_ARG_240992E0,
CliMessages.EXCEPTION_THE_STATEMENT_IS_EXECUTED_SUCCESSFULLY_B07F8CCB
+ " "
+ statusMessage)
+ System.lineSeparator(),
output);
}
}

@Test
public void testNoOpSuccessMessageIsSeparateFromGenericMessage() throws Exception {
public void testNoOpServerMessageIsAppendedToSuccessMessage() throws Exception {
String sql = "DROP TABLE IF EXISTS missing_table";
String statusMessage =
"Table deletion is asynchronous. The specified table does not exist; no task was submitted.";
Expand All @@ -162,11 +166,14 @@ public void testNoOpSuccessMessageIsSeparateFromGenericMessage() throws Exceptio
AbstractCli.handleInputCmd(ctx, sql, connection);

String output = new String(out.toByteArray(), StandardCharsets.UTF_8);
assertTrue(output.contains(statusMessage));
assertTrue(output.contains("The statement is executed successfully"));
assertTrue(
output.indexOf(statusMessage) < output.indexOf("The statement is executed successfully"));
assertFalse(output.contains("The statement is executed successfully. " + statusMessage));
assertEquals(
String.format(
CliMessages.LOG_MSG_ARG_240992E0,
CliMessages.EXCEPTION_THE_STATEMENT_IS_EXECUTED_SUCCESSFULLY_B07F8CCB
+ " "
+ statusMessage)
+ System.lineSeparator(),
output);
}
}

Expand Down
Loading