diff --git a/integration-test/src/test/java/org/apache/iotdb/cli/it/ExplainJsonCliOutputIT.java b/integration-test/src/test/java/org/apache/iotdb/cli/it/ExplainJsonCliOutputIT.java index d7d54f5cd1ba..4450f50a68df 100644 --- a/integration-test/src/test/java/org/apache/iotdb/cli/it/ExplainJsonCliOutputIT.java +++ b/integration-test/src/test/java/org/apache/iotdb/cli/it/ExplainJsonCliOutputIT.java @@ -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; @@ -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; @@ -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 diff --git a/iotdb-client/cli/src/main/java/org/apache/iotdb/cli/AbstractCli.java b/iotdb-client/cli/src/main/java/org/apache/iotdb/cli/AbstractCli.java index 7eff9ab9bf1c..3d5f61261891 100644 --- a/iotdb-client/cli/src/main/java/org/apache/iotdb/cli/AbstractCli.java +++ b/iotdb-client/cli/src/main/java/org/apache/iotdb/cli/AbstractCli.java @@ -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) { diff --git a/iotdb-client/cli/src/test/java/org/apache/iotdb/cli/AbstractCliTest.java b/iotdb-client/cli/src/test/java/org/apache/iotdb/cli/AbstractCliTest.java index 6f1e30031a81..1c6c6d73af81 100644 --- a/iotdb-client/cli/src/test/java/org/apache/iotdb/cli/AbstractCliTest.java +++ b/iotdb-client/cli/src/test/java/org/apache/iotdb/cli/AbstractCliTest.java @@ -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; @@ -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. " @@ -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."; @@ -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); } }