This is an automated email from the ASF dual-hosted git repository.

mattcasters pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/hop.git


The following commit(s) were added to refs/heads/main by this push:
     new 889d6fa49d Fix#9171  result/logging issues in Table exists, Wait for 
SQL, and Truncate… (#9194)
889d6fa49d is described below

commit 889d6fa49d38d5abd775cc3896de56d4b7f3d4b8
Author: Lance <[email protected]>
AuthorDate: Tue Nov 3 16:24:00 2026 +0800

    Fix#9171  result/logging issues in Table exists, Wait for SQL, and 
Truncate… (#9194)
    
    * Fix result/logging issues in Table exists, Wait for SQL, and Truncate 
tables
    
    Signed-off-by: leehaut <[email protected]>
    
    * Fix result/logging issues in Table exists, Wait for SQL, and Truncate 
tables
    
    Signed-off-by: leehaut <[email protected]>
    
    * Fix result/logging issues in Table exists, Wait for SQL, and Truncate 
tables
    
    Signed-off-by: leehaut <[email protected]>
    
    ---------
    
    Signed-off-by: leehaut <[email protected]>
---
 .../ROOT/pages/workflow/actions/tableexists.adoc   |   3 +-
 .../pages/workflow/actions/truncatetables.adoc     |   5 +-
 .../actions/tableexists/ActionTableExists.java     |  31 +---
 .../tableexists/messages/messages_en_US.properties |   1 +
 .../tableexists/messages/messages_zh_CN.properties |   1 +
 .../actions/tableexists/ActionTableExistsTest.java | 143 ++++++++++++++++
 .../truncatetables/ActionTruncateTables.java       | 180 +++++++++++----------
 .../actions/truncatetables/TruncateTableItem.java  |  24 +--
 .../messages/messages_en_US.properties             |   1 +
 .../messages/messages_zh_CN.properties             |   1 +
 .../truncatetables/ActionTruncateTablesTest.java   | 127 ++++++++++++++-
 .../actions/waitforsql/ActionWaitForSql.java       |   4 +-
 .../actions/waitforsql/ActionWaitForSqlTest.java   |  41 +++++
 13 files changed, 427 insertions(+), 135 deletions(-)

diff --git 
a/docs/hop-user-manual/modules/ROOT/pages/workflow/actions/tableexists.adoc 
b/docs/hop-user-manual/modules/ROOT/pages/workflow/actions/tableexists.adoc
index 060133d7cb..66a3c3ba21 100644
--- a/docs/hop-user-manual/modules/ROOT/pages/workflow/actions/tableexists.adoc
+++ b/docs/hop-user-manual/modules/ROOT/pages/workflow/actions/tableexists.adoc
@@ -53,9 +53,8 @@ What this action passes on to the next action. See 
xref:workflow/action-results.
 |===
 |Result|Value
 |True|The table exists, with 0 errors.
-|False|The table doesn't exist: the number of errors is 0. When the connection 
is empty or can't be opened, the number of errors is 1.
+|False|The table doesn't exist: the number of errors is 0. When the connection 
is empty, unknown, or can't be opened, the number of errors is 1.
 |Result files|Passed on unchanged.
 |Result rows|Passed on unchanged.
 |===
 
-NOTE: A *Connection* that doesn't exist in the project also gives false with 0 
errors, and nothing is logged: the same result as a table that doesn't exist.
diff --git 
a/docs/hop-user-manual/modules/ROOT/pages/workflow/actions/truncatetables.adoc 
b/docs/hop-user-manual/modules/ROOT/pages/workflow/actions/truncatetables.adoc
index c2f4e781b3..b21a99f2f6 100644
--- 
a/docs/hop-user-manual/modules/ROOT/pages/workflow/actions/truncatetables.adoc
+++ 
b/docs/hop-user-manual/modules/ROOT/pages/workflow/actions/truncatetables.adoc
@@ -47,10 +47,11 @@ What this action passes on to the next action. See 
xref:workflow/action-results.
 |===
 |Result|Value
 |True|Every table was truncated, with 0 errors. Also true when there is 
nothing to truncate: an empty list, or *Previous results to args* checked while 
there are no previous result rows (the tables in the grid are not truncated 
then).
-|False|A table doesn't exist, or the connection is unknown or can't be opened. 
The number of errors is 1: the action stops at the first table that fails, and 
the tables after it are not truncated.
+|False|At least one error occurred. A table that doesn't exist, or a 
connection that is unknown or can't be opened, counts as an error and stops the 
action: the tables after it are not truncated. An empty table name (in the 
selected tables grid or in a previous result row) also counts as an error, but 
later tables are still truncated.
 |Result files|Passed on unchanged.
 |Result rows|Passed on unchanged.
 |Lines deleted|The number of tables truncated, not the number of rows.
 |===
 
-NOTE: With *Previous results to args*, the first field of each result row is 
the table name and the second field the schema name. A row with an empty table 
name is skipped: it is logged as an error, but doesn't count as one.
+NOTE: With *Previous results to args*, the first field of each result row is 
the table name and the second field the schema name. A row with an empty table 
name is logged as an error and counts as one: later rows are still processed.
+
diff --git 
a/plugins/actions/tableexists/src/main/java/org/apache/hop/workflow/actions/tableexists/ActionTableExists.java
 
b/plugins/actions/tableexists/src/main/java/org/apache/hop/workflow/actions/tableexists/ActionTableExists.java
index 2bd8e966c1..3c110d9a7b 100644
--- 
a/plugins/actions/tableexists/src/main/java/org/apache/hop/workflow/actions/tableexists/ActionTableExists.java
+++ 
b/plugins/actions/tableexists/src/main/java/org/apache/hop/workflow/actions/tableexists/ActionTableExists.java
@@ -18,6 +18,8 @@
 package org.apache.hop.workflow.actions.tableexists;
 
 import java.util.List;
+import lombok.Getter;
+import lombok.Setter;
 import org.apache.hop.core.ICheckResult;
 import org.apache.hop.core.Result;
 import org.apache.hop.core.annotations.Action;
@@ -40,6 +42,8 @@ import 
org.apache.hop.workflow.action.validator.ActionValidatorUtils;
 import org.apache.hop.workflow.action.validator.AndValidator;
 
 /** This defines a table exists action. */
+@Getter
+@Setter
 @Action(
     id = "TABLE_EXISTS",
     name = "i18n::ActionTableExists.Name",
@@ -77,30 +81,6 @@ public class ActionTableExists extends ActionBase implements 
Cloneable, IAction
     this("");
   }
 
-  public void setTableName(String tableName) {
-    this.tableName = tableName;
-  }
-
-  public String getTableName() {
-    return tableName;
-  }
-
-  public String getSchemaName() {
-    return schemaName;
-  }
-
-  public void setSchemaName(String schemaName) {
-    this.schemaName = schemaName;
-  }
-
-  public String getConnection() {
-    return connection;
-  }
-
-  public void setConnection(String connection) {
-    this.connection = connection;
-  }
-
   @Override
   public boolean isEvaluation() {
     return true;
@@ -141,6 +121,9 @@ public class ActionTableExists extends ActionBase 
implements Cloneable, IAction
           logError(
               BaseMessages.getString(PKG, "TableExists.Error.RunningAction", 
dbe.getMessage()));
         }
+      } else {
+        result.setNrErrors(1);
+        logError(BaseMessages.getString(PKG, 
"TableExists.Error.ConnectionNotFound", connection));
       }
     } else {
       result.setNrErrors(1);
diff --git 
a/plugins/actions/tableexists/src/main/resources/org/apache/hop/workflow/actions/tableexists/messages/messages_en_US.properties
 
b/plugins/actions/tableexists/src/main/resources/org/apache/hop/workflow/actions/tableexists/messages/messages_en_US.properties
index 6dd5e52a19..cb6d2a2cff 100644
--- 
a/plugins/actions/tableexists/src/main/resources/org/apache/hop/workflow/actions/tableexists/messages/messages_en_US.properties
+++ 
b/plugins/actions/tableexists/src/main/resources/org/apache/hop/workflow/actions/tableexists/messages/messages_en_US.properties
@@ -24,6 +24,7 @@ ActionTableExists.Schemaname.Label=Schema name
 ActionTableExists.Tablename.Label=Table name
 ActionTableExists.Title=Table exists
 TableExists.Error.NoConnectionDefined=No database connection is defined.
+TableExists.Error.ConnectionNotFound=Database connection [{0}] could not be 
found.
 TableExists.Error.RunningAction=An error occurred executing this transform: {0}
 TableExists.Log.TableExists=Table [{0}] exists.
 TableExists.Log.TableNotExists=Table [{0}] does not exist!
diff --git 
a/plugins/actions/tableexists/src/main/resources/org/apache/hop/workflow/actions/tableexists/messages/messages_zh_CN.properties
 
b/plugins/actions/tableexists/src/main/resources/org/apache/hop/workflow/actions/tableexists/messages/messages_zh_CN.properties
index b0068be272..168e5e7b2e 100644
--- 
a/plugins/actions/tableexists/src/main/resources/org/apache/hop/workflow/actions/tableexists/messages/messages_zh_CN.properties
+++ 
b/plugins/actions/tableexists/src/main/resources/org/apache/hop/workflow/actions/tableexists/messages/messages_zh_CN.properties
@@ -26,6 +26,7 @@ ActionTableExists.Schemaname.Label=\u6A21\u5F0F\u540D\u79F0
 ActionTableExists.Tablename.Label=\u8868\u540D
 ActionTableExists.Title=\u68C0\u67E5\u8868\u662F\u5426\u5B58\u5728
 
TableExists.Error.NoConnectionDefined=\u6CA1\u6709\u5B9A\u4E49\u6570\u636E\u5E93\u8FDE\u63A5
+TableExists.Error.ConnectionNotFound=\u627E\u4E0D\u5230\u6570\u636E\u5E93\u8FDE\u63A5
 [{0}]
 TableExists.Error.RunningAction=\u5728\u6267\u884C\u8BE5 Transform 
\u65F6\u51FA\u9519:{0}
 TableExists.Log.TableExists=\u8868[{0}]\u5B58\u5728
 TableExists.Log.TableNotExists=\u8868[{0}]\u4E0D\u5B58\u5728!
diff --git 
a/plugins/actions/tableexists/src/test/java/org/apache/hop/workflow/actions/tableexists/ActionTableExistsTest.java
 
b/plugins/actions/tableexists/src/test/java/org/apache/hop/workflow/actions/tableexists/ActionTableExistsTest.java
new file mode 100644
index 0000000000..48e89a1c2c
--- /dev/null
+++ 
b/plugins/actions/tableexists/src/test/java/org/apache/hop/workflow/actions/tableexists/ActionTableExistsTest.java
@@ -0,0 +1,143 @@
+/*
+ * 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.hop.workflow.actions.tableexists;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.contains;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.mockConstruction;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import org.apache.hop.core.HopClientEnvironment;
+import org.apache.hop.core.Result;
+import org.apache.hop.core.database.Database;
+import org.apache.hop.core.database.DatabaseMeta;
+import org.apache.hop.core.logging.HopLogStore;
+import org.apache.hop.core.logging.LogLevel;
+import org.apache.hop.workflow.Workflow;
+import org.apache.hop.workflow.WorkflowMeta;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.mockito.MockedConstruction;
+
+/** Unit test for {@link ActionTableExists} */
+class ActionTableExistsTest {
+
+  @BeforeAll
+  static void setUpBeforeClass() throws Exception {
+    HopClientEnvironment.init();
+    HopLogStore.init();
+  }
+
+  @Test
+  void emptyConnectionCountsAsError() {
+    ActionTableExists action = spy(new ActionTableExists("Table exists"));
+    action.setConnection(null);
+    action.setTableName("any_table");
+
+    Result result = action.execute(new Result(), 0);
+
+    assertFalse(result.getResult());
+    assertEquals(1, result.getNrErrors());
+    verify(action).logError(contains("No database connection is defined"));
+  }
+
+  @Test
+  void unknownConnectionCountsAsError() {
+    ActionTableExists action = spy(new ActionTableExists("Table exists"));
+    action.setConnection("mysql-does-not-exist");
+    action.setTableName("any_table");
+
+    WorkflowMeta workflowMeta = mock(WorkflowMeta.class);
+    when(workflowMeta.findDatabase(anyString(), any())).thenReturn(null);
+    action.setParentWorkflowMeta(workflowMeta);
+
+    Workflow workflow = mock(Workflow.class);
+    when(workflow.getLogLevel()).thenReturn(LogLevel.BASIC);
+    action.setParentWorkflow(workflow);
+
+    Result result = action.execute(new Result(), 0);
+
+    assertFalse(result.getResult());
+    assertEquals(1, result.getNrErrors());
+    verify(action).logError(contains("mysql-does-not-exist"));
+  }
+
+  @Test
+  void existingTableReturnsTrueWithoutErrors() throws Exception {
+    ActionTableExists action = new ActionTableExists("Table exists");
+    action.setConnection("unit-test-db");
+    action.setTableName("present_table");
+
+    DatabaseMeta databaseMeta = mock(DatabaseMeta.class);
+    WorkflowMeta workflowMeta = mock(WorkflowMeta.class);
+    when(workflowMeta.findDatabase(anyString(), 
any())).thenReturn(databaseMeta);
+    action.setParentWorkflowMeta(workflowMeta);
+
+    Workflow workflow = mock(Workflow.class);
+    when(workflow.getLogLevel()).thenReturn(LogLevel.BASIC);
+    action.setParentWorkflow(workflow);
+
+    try (MockedConstruction<Database> databases =
+        mockConstruction(
+            Database.class,
+            (db, context) ->
+                when(db.checkTableExists(any(), 
eq("present_table"))).thenReturn(true))) {
+      Result result = action.execute(new Result(), 0);
+
+      assertTrue(result.getResult());
+      assertEquals(0, result.getNrErrors());
+      assertEquals(1, databases.constructed().size());
+    }
+  }
+
+  @Test
+  void missingTableReturnsFalseWithoutErrors() throws Exception {
+    ActionTableExists action = new ActionTableExists("Table exists");
+    action.setConnection("unit-test-db");
+    action.setTableName("missing_table");
+
+    DatabaseMeta databaseMeta = mock(DatabaseMeta.class);
+    WorkflowMeta workflowMeta = mock(WorkflowMeta.class);
+    when(workflowMeta.findDatabase(anyString(), 
any())).thenReturn(databaseMeta);
+    action.setParentWorkflowMeta(workflowMeta);
+
+    Workflow workflow = mock(Workflow.class);
+    when(workflow.getLogLevel()).thenReturn(LogLevel.BASIC);
+    action.setParentWorkflow(workflow);
+
+    try (MockedConstruction<Database> databases =
+        mockConstruction(
+            Database.class,
+            (db, context) ->
+                when(db.checkTableExists(any(), 
eq("missing_table"))).thenReturn(false))) {
+      Result result = action.execute(new Result(), 0);
+
+      assertFalse(result.getResult());
+      assertEquals(0, result.getNrErrors());
+      assertEquals(1, databases.constructed().size());
+    }
+  }
+}
diff --git 
a/plugins/actions/truncatetables/src/main/java/org/apache/hop/workflow/actions/truncatetables/ActionTruncateTables.java
 
b/plugins/actions/truncatetables/src/main/java/org/apache/hop/workflow/actions/truncatetables/ActionTruncateTables.java
index 605b0a0da1..f389903996 100644
--- 
a/plugins/actions/truncatetables/src/main/java/org/apache/hop/workflow/actions/truncatetables/ActionTruncateTables.java
+++ 
b/plugins/actions/truncatetables/src/main/java/org/apache/hop/workflow/actions/truncatetables/ActionTruncateTables.java
@@ -19,6 +19,8 @@ package org.apache.hop.workflow.actions.truncatetables;
 
 import java.util.ArrayList;
 import java.util.List;
+import lombok.Getter;
+import lombok.Setter;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.hop.core.CheckResult;
 import org.apache.hop.core.ICheckResult;
@@ -26,6 +28,7 @@ import org.apache.hop.core.Result;
 import org.apache.hop.core.RowMetaAndData;
 import org.apache.hop.core.annotations.Action;
 import org.apache.hop.core.database.Database;
+import org.apache.hop.core.database.DatabaseMeta;
 import org.apache.hop.core.util.Utils;
 import org.apache.hop.core.variables.IVariables;
 import org.apache.hop.i18n.BaseMessages;
@@ -51,15 +54,22 @@ import org.apache.hop.workflow.action.IAction;
 public class ActionTruncateTables extends ActionBase implements Cloneable, 
IAction {
   private static final Class<?> PKG = ActionTruncateTables.class;
 
+  @Getter
+  @Setter
   @HopMetadataProperty(key = "arg_from_previous")
   private boolean argFromPrevious;
 
+  @Getter
+  @Setter
   @HopMetadataProperty(hopMetadataPropertyType = 
HopMetadataPropertyType.RDBMS_CONNECTION)
   private String connection;
 
+  @Getter
+  @Setter
   @HopMetadataProperty(key = "field", groupKey = "fields")
   private List<TruncateTableItem> items;
 
+  // Runtime counters for a single execute(); keep package-private accessors 
out of the public API.
   private int nrErrors = 0;
   private int nrSuccess = 0;
   private boolean continueProcess = true;
@@ -85,22 +95,6 @@ public class ActionTruncateTables extends ActionBase 
implements Cloneable, IActi
     return true;
   }
 
-  public String getConnection() {
-    return connection;
-  }
-
-  public void setConnection(String connection) {
-    this.connection = connection;
-  }
-
-  public List<TruncateTableItem> getItems() {
-    return items;
-  }
-
-  public void setItems(List<TruncateTableItem> items) {
-    this.items = items;
-  }
-
   private boolean truncateTables(String tableName, String schemaName, Database 
db) {
     boolean retval = false;
     try {
@@ -153,69 +147,92 @@ public class ActionTruncateTables extends ActionBase 
implements Cloneable, IActi
         return result;
       }
     }
-    if (connection != null) {
-
-      try (Database db =
-          new Database(
-              this, this, getParentWorkflowMeta().findDatabase(connection, 
getVariables()))) {
-        db.connect();
-        if (argFromPrevious && rows != null) { // Copy the input row to the 
(command line) arguments
-
-          for (int iteration = 0;
-              iteration < rows.size() && !parentWorkflow.isStopped() && 
continueProcess;
-              iteration++) {
-            resultRow = rows.get(iteration);
-
-            // Get values from previous result
-            String tableNamePrevious = resultRow.getString(0, null);
-            String schemaNamePrevious = resultRow.getString(1, null);
-
-            if (!Utils.isEmpty(tableNamePrevious)) {
-              if (isDetailed()) {
-                logDetailed(
-                    BaseMessages.getString(
-                        PKG,
-                        "ActionTruncateTables.ProcessingRow",
-                        tableNamePrevious,
-                        schemaNamePrevious));
-              }
-
-              // let's truncate table
-              if (truncateTables(tableNamePrevious, schemaNamePrevious, db)) {
-                updateSuccess();
-              } else {
-                updateErrors();
-              }
-            } else {
-              logError(BaseMessages.getString(PKG, 
"ActionTruncateTables.RowEmpty"));
-            }
-          }
-
-        } else if (!Utils.isEmpty(this.items)) {
-
-          for (int i = 0;
-              i < this.items.size() && !parentWorkflow.isStopped() && 
continueProcess;
-              i++) {
-            TruncateTableItem tableItem = this.items.get(i);
-            String realTableName = resolve(tableItem.getTableName());
-            String realSchemaName = resolve(tableItem.getSchemaName());
-            if (!Utils.isEmpty(realTableName)) {
-              if (isDetailed()) {
-                logDetailed(
-                    BaseMessages.getString(
-                        PKG, "ActionTruncateTables.ProcessingArg", 
realTableName, realSchemaName));
+    String realConnection = resolve(connection);
+    if (Utils.isEmpty(realConnection)) {
+      updateErrors();
+      logError(BaseMessages.getString(PKG, 
"ActionTruncateTables.NoDbConnection"));
+    } else {
+      // Keep findDatabase() inside try/catch so HopRuntimeException becomes 
an action failure.
+      try {
+        DatabaseMeta databaseMeta =
+            getParentWorkflowMeta() == null
+                ? null
+                : getParentWorkflowMeta().findDatabase(realConnection, 
getVariables());
+        if (databaseMeta == null) {
+          updateErrors();
+          logError(
+              BaseMessages.getString(
+                  PKG, "ActionTruncateTables.Error.ConnectionNotFound", 
realConnection));
+        } else {
+          try (Database db = new Database(this, this, databaseMeta)) {
+            db.connect();
+            if (argFromPrevious
+                && rows != null) { // Copy the input row to the (command line) 
arguments
+
+              for (int iteration = 0;
+                  iteration < rows.size() && !parentWorkflow.isStopped() && 
continueProcess;
+                  iteration++) {
+                resultRow = rows.get(iteration);
+
+                // Get values from previous result
+                String tableNamePrevious = resultRow.getString(0, null);
+                String schemaNamePrevious = resultRow.getString(1, null);
+
+                if (!Utils.isEmpty(tableNamePrevious)) {
+                  if (isDetailed()) {
+                    logDetailed(
+                        BaseMessages.getString(
+                            PKG,
+                            "ActionTruncateTables.ProcessingRow",
+                            tableNamePrevious,
+                            schemaNamePrevious));
+                  }
+
+                  // let's truncate table
+                  if (truncateTables(tableNamePrevious, schemaNamePrevious, 
db)) {
+                    updateSuccess();
+                  } else {
+                    updateErrors();
+                  }
+                } else {
+                  // Count as error but keep going so later valid table names 
are still processed
+                  logError(BaseMessages.getString(PKG, 
"ActionTruncateTables.RowEmpty"));
+                  nrErrors++;
+                }
               }
 
-              // let's truncate table
-              if (truncateTables(realTableName, realSchemaName, db)) {
-                updateSuccess();
-              } else {
-                updateErrors();
+            } else if (!Utils.isEmpty(this.items)) {
+
+              for (int i = 0;
+                  i < this.items.size() && !parentWorkflow.isStopped() && 
continueProcess;
+                  i++) {
+                TruncateTableItem tableItem = this.items.get(i);
+                String realTableName = resolve(tableItem.getTableName());
+                String realSchemaName = resolve(tableItem.getSchemaName());
+                if (!Utils.isEmpty(realTableName)) {
+                  if (isDetailed()) {
+                    logDetailed(
+                        BaseMessages.getString(
+                            PKG,
+                            "ActionTruncateTables.ProcessingArg",
+                            realTableName,
+                            realSchemaName));
+                  }
+
+                  // let's truncate table
+                  if (truncateTables(realTableName, realSchemaName, db)) {
+                    updateSuccess();
+                  } else {
+                    updateErrors();
+                  }
+                } else {
+                  // Count as error but keep going so later valid table names 
are still processed
+                  logError(
+                      BaseMessages.getString(
+                          PKG, "ActionTruncateTables.ArgEmpty", realTableName, 
realSchemaName));
+                  nrErrors++;
+                }
               }
-            } else {
-              logError(
-                  BaseMessages.getString(
-                      PKG, "ActionTruncateTables.ArgEmpty", realTableName, 
realSchemaName));
             }
           }
         }
@@ -225,9 +242,6 @@ public class ActionTruncateTables extends ActionBase 
implements Cloneable, IActi
             BaseMessages.getString(
                 PKG, "ActionTruncateTables.Error.RunningEntry", 
dbe.getMessage()));
       }
-    } else {
-      updateErrors();
-      logError(BaseMessages.getString(PKG, 
"ActionTruncateTables.NoDbConnection"));
     }
 
     result.setNrErrors(nrErrors);
@@ -263,14 +277,6 @@ public class ActionTruncateTables extends ActionBase 
implements Cloneable, IActi
     return references;
   }
 
-  public boolean isArgFromPrevious() {
-    return argFromPrevious;
-  }
-
-  public void setArgFromPrevious(boolean argFromPrevious) {
-    this.argFromPrevious = argFromPrevious;
-  }
-
   @Override
   public void check(
       List<ICheckResult> remarks,
diff --git 
a/plugins/actions/truncatetables/src/main/java/org/apache/hop/workflow/actions/truncatetables/TruncateTableItem.java
 
b/plugins/actions/truncatetables/src/main/java/org/apache/hop/workflow/actions/truncatetables/TruncateTableItem.java
index 6c7f3ee1e2..a4ddebe16b 100644
--- 
a/plugins/actions/truncatetables/src/main/java/org/apache/hop/workflow/actions/truncatetables/TruncateTableItem.java
+++ 
b/plugins/actions/truncatetables/src/main/java/org/apache/hop/workflow/actions/truncatetables/TruncateTableItem.java
@@ -17,8 +17,14 @@
 
 package org.apache.hop.workflow.actions.truncatetables;
 
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
 import org.apache.hop.metadata.api.HopMetadataProperty;
 
+@Getter
+@Setter
+@NoArgsConstructor
 public class TruncateTableItem {
 
   @HopMetadataProperty(key = "name")
@@ -27,29 +33,11 @@ public class TruncateTableItem {
   @HopMetadataProperty(key = "schemaname")
   private String schemaName;
 
-  public TruncateTableItem() {}
-
   public TruncateTableItem(String tableName, String schemaName) {
     this.tableName = tableName;
     this.schemaName = schemaName;
   }
 
-  public String getTableName() {
-    return tableName;
-  }
-
-  public void setTableName(String tableName) {
-    this.tableName = tableName;
-  }
-
-  public String getSchemaName() {
-    return schemaName;
-  }
-
-  public void setSchemaName(String schemaName) {
-    this.schemaName = schemaName;
-  }
-
   @Override
   public String toString() {
     return "TruncateTableItem{"
diff --git 
a/plugins/actions/truncatetables/src/main/resources/org/apache/hop/workflow/actions/truncatetables/messages/messages_en_US.properties
 
b/plugins/actions/truncatetables/src/main/resources/org/apache/hop/workflow/actions/truncatetables/messages/messages_en_US.properties
index 53b8427f2d..9329470780 100644
--- 
a/plugins/actions/truncatetables/src/main/resources/org/apache/hop/workflow/actions/truncatetables/messages/messages_en_US.properties
+++ 
b/plugins/actions/truncatetables/src/main/resources/org/apache/hop/workflow/actions/truncatetables/messages/messages_en_US.properties
@@ -24,6 +24,7 @@ ActionTruncateTables.ConnectionError.DialogMessage=Error!Can 
not return table na
 ActionTruncateTables.Description=Truncate one or several tables.
 ActionTruncateTables.Error.CanNotFindTable=We can not find table [{0}]!
 ActionTruncateTables.Error.CanNotTruncateTables=Can not truncate table [{0}]. 
Exception : {1}
+ActionTruncateTables.Error.ConnectionNotFound=Database connection [{0}] could 
not be found.
 ActionTruncateTables.Error.RunningEntry=An error occurred executing this 
action: {0}
 ActionTruncateTables.Fields.Label=Selected tables
 ActionTruncateTables.Fields.Schema.Label=Schema name
diff --git 
a/plugins/actions/truncatetables/src/main/resources/org/apache/hop/workflow/actions/truncatetables/messages/messages_zh_CN.properties
 
b/plugins/actions/truncatetables/src/main/resources/org/apache/hop/workflow/actions/truncatetables/messages/messages_zh_CN.properties
index 90ab14f134..f71bfd001d 100644
--- 
a/plugins/actions/truncatetables/src/main/resources/org/apache/hop/workflow/actions/truncatetables/messages/messages_zh_CN.properties
+++ 
b/plugins/actions/truncatetables/src/main/resources/org/apache/hop/workflow/actions/truncatetables/messages/messages_zh_CN.properties
@@ -22,6 +22,7 @@ 
ActionTruncateTables.ConnectionError.DialogMessage=\u9519\u8BEF, \u65E0\u6CD5\u8
 ActionTruncateTables.Description=Truncate one or several tables.
 ActionTruncateTables.Error.CanNotFindTable=\u65E0\u6CD5\u627E\u5230\u8868 
[{0}]!
 ActionTruncateTables.Error.CanNotTruncateTables=\u65E0\u6CD5\u6E05\u7A7A\u8868 
[{0}], \u5F02\u5E38: {1}
+ActionTruncateTables.Error.ConnectionNotFound=\u627E\u4E0D\u5230\u6570\u636E\u5E93\u8FDE\u63A5
 [{0}]
 ActionTruncateTables.Error.RunningEntry=\u6267\u884C\u8BE5 Action 
\u65F6\u53D1\u751F\u9519\u8BEF: {0}
 ActionTruncateTables.Fields.Label=\u9009\u62E9\u7684\u8868
 ActionTruncateTables.Fields.Schema.Label=\u6A21\u5F0F\u540D\u79F0
diff --git 
a/plugins/actions/truncatetables/src/test/java/org/apache/hop/workflow/actions/truncatetables/ActionTruncateTablesTest.java
 
b/plugins/actions/truncatetables/src/test/java/org/apache/hop/workflow/actions/truncatetables/ActionTruncateTablesTest.java
index e3c1238b90..6f2e798bac 100644
--- 
a/plugins/actions/truncatetables/src/test/java/org/apache/hop/workflow/actions/truncatetables/ActionTruncateTablesTest.java
+++ 
b/plugins/actions/truncatetables/src/test/java/org/apache/hop/workflow/actions/truncatetables/ActionTruncateTablesTest.java
@@ -21,18 +21,33 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.contains;
+import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.mockConstruction;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
+import java.util.ArrayList;
+import java.util.List;
 import org.apache.hop.core.HopClientEnvironment;
 import org.apache.hop.core.Result;
+import org.apache.hop.core.RowMetaAndData;
+import org.apache.hop.core.database.Database;
+import org.apache.hop.core.database.DatabaseMeta;
+import org.apache.hop.core.exception.HopRuntimeException;
 import org.apache.hop.core.logging.HopLogStore;
 import org.apache.hop.core.logging.LogLevel;
+import org.apache.hop.core.row.RowMeta;
+import org.apache.hop.core.row.value.ValueMetaString;
 import org.apache.hop.workflow.Workflow;
 import org.apache.hop.workflow.WorkflowMeta;
 import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.Test;
+import org.mockito.MockedConstruction;
 
+/** Unit test for {@link ActionTruncateTables} */
 class ActionTruncateTablesTest {
 
   @BeforeAll
@@ -54,7 +69,7 @@ class ActionTruncateTablesTest {
 
   @Test
   void testExecuteWithNonExistentConnection() {
-    ActionTruncateTables action = new ActionTruncateTables();
+    ActionTruncateTables action = spy(new ActionTruncateTables());
     action.setConnection("non-existent-db");
 
     WorkflowMeta workflowMeta = mock(WorkflowMeta.class);
@@ -71,6 +86,116 @@ class ActionTruncateTablesTest {
 
     assertFalse(result.getResult());
     assertEquals(1, result.getNrErrors());
+    verify(action).logError(contains("non-existent-db"));
+  }
+
+  @Test
+  void testExecuteWithBlankConnection() {
+    ActionTruncateTables action = spy(new ActionTruncateTables());
+    action.setConnection("");
+
+    Result result = action.execute(new Result(), 0);
+
+    assertFalse(result.getResult());
+    assertEquals(1, result.getNrErrors());
+    verify(action).logError(contains("No database connection is defined"));
+  }
+
+  @Test
+  void findDatabaseRuntimeExceptionIsActionFailureNotWorkflowAbort() {
+    ActionTruncateTables action = spy(new ActionTruncateTables());
+    action.setConnection("corrupt-db");
+
+    WorkflowMeta workflowMeta = mock(WorkflowMeta.class);
+    when(workflowMeta.findDatabase(anyString(), any()))
+        .thenThrow(new HopRuntimeException("Unable to load connection 
corrupt-db from metadata"));
+
+    Workflow workflow = mock(Workflow.class);
+    when(workflow.getWorkflowMeta()).thenReturn(workflowMeta);
+    when(workflow.getLogLevel()).thenReturn(LogLevel.BASIC);
+
+    action.setParentWorkflow(workflow);
+    action.setParentWorkflowMeta(workflowMeta);
+
+    Result result = action.execute(new Result(), 0);
+
+    assertFalse(result.getResult());
+    assertEquals(1, result.getNrErrors());
+    verify(action).logError(contains("Unable to load connection corrupt-db 
from metadata"));
+  }
+
+  @Test
+  void emptyTableNameInListIsCountedAsErrorAndLaterTablesStillRun() throws 
Exception {
+    ActionTruncateTables action = spy(new ActionTruncateTables());
+    action.setConnection("unit-test-db");
+    List<TruncateTableItem> items = new ArrayList<>();
+    items.add(new TruncateTableItem("", null));
+    items.add(new TruncateTableItem("valid_table", null));
+    action.setItems(items);
+
+    DatabaseMeta databaseMeta = mock(DatabaseMeta.class);
+    WorkflowMeta workflowMeta = mock(WorkflowMeta.class);
+    when(workflowMeta.findDatabase(anyString(), 
any())).thenReturn(databaseMeta);
+
+    Workflow workflow = mock(Workflow.class);
+    when(workflow.isStopped()).thenReturn(false);
+    when(workflow.getLogLevel()).thenReturn(LogLevel.BASIC);
+
+    action.setParentWorkflow(workflow);
+    action.setParentWorkflowMeta(workflowMeta);
+
+    try (MockedConstruction<Database> databases =
+        mockConstruction(
+            Database.class,
+            (db, context) ->
+                when(db.checkTableExists(any(), 
eq("valid_table"))).thenReturn(true))) {
+      Result result = action.execute(new Result(), 0);
+
+      assertFalse(result.getResult());
+      assertEquals(1, result.getNrErrors());
+      assertEquals(1, result.getNrLinesDeleted());
+      verify(action).logError(contains("empty"));
+      verify(databases.constructed().get(0)).truncateTable("valid_table");
+    }
+  }
+
+  @Test
+  void emptyPreviousResultRowIsCountedAsErrorAndLaterRowsStillRun() throws 
Exception {
+    ActionTruncateTables action = spy(new ActionTruncateTables());
+    action.setConnection("unit-test-db");
+    action.setArgFromPrevious(true);
+
+    DatabaseMeta databaseMeta = mock(DatabaseMeta.class);
+    WorkflowMeta workflowMeta = mock(WorkflowMeta.class);
+    when(workflowMeta.findDatabase(anyString(), 
any())).thenReturn(databaseMeta);
+
+    Workflow workflow = mock(Workflow.class);
+    when(workflow.isStopped()).thenReturn(false);
+    when(workflow.getLogLevel()).thenReturn(LogLevel.BASIC);
+
+    action.setParentWorkflow(workflow);
+    action.setParentWorkflowMeta(workflowMeta);
+
+    Result previous = new Result();
+    RowMeta rowMeta = new RowMeta();
+    rowMeta.addValueMeta(new ValueMetaString("table"));
+    rowMeta.addValueMeta(new ValueMetaString("schema"));
+    previous.getRows().add(new RowMetaAndData(rowMeta, "", null));
+    previous.getRows().add(new RowMetaAndData(rowMeta, "valid_table", null));
+
+    try (MockedConstruction<Database> databases =
+        mockConstruction(
+            Database.class,
+            (db, context) ->
+                when(db.checkTableExists(any(), 
eq("valid_table"))).thenReturn(true))) {
+      Result result = action.execute(previous, 0);
+
+      assertFalse(result.getResult());
+      assertEquals(1, result.getNrErrors());
+      assertEquals(1, result.getNrLinesDeleted());
+      verify(action).logError(contains("empty"));
+      verify(databases.constructed().get(0)).truncateTable("valid_table");
+    }
   }
 
   @Test
diff --git 
a/plugins/actions/waitforsql/src/main/java/org/apache/hop/workflow/actions/waitforsql/ActionWaitForSql.java
 
b/plugins/actions/waitforsql/src/main/java/org/apache/hop/workflow/actions/waitforsql/ActionWaitForSql.java
index ce3ce30192..62d8b97201 100644
--- 
a/plugins/actions/waitforsql/src/main/java/org/apache/hop/workflow/actions/waitforsql/ActionWaitForSql.java
+++ 
b/plugins/actions/waitforsql/src/main/java/org/apache/hop/workflow/actions/waitforsql/ActionWaitForSql.java
@@ -353,7 +353,9 @@ public class ActionWaitForSql extends ActionBase implements 
Cloneable, IAction {
         }
       }
     } catch (Exception e) {
-      logBasic("Exception while waiting for SQL data: " + e.getMessage());
+      // Keep Error level (issue #9171) but log a concise root-cause message. 
Passing the
+      // throwable dumps a long stack that duplicates what Database.connect() 
already logged.
+      logError("Exception while waiting for SQL data: " + 
Const.getRootCauseMessage(e));
     }
 
     if (result.isResult()) {
diff --git 
a/plugins/actions/waitforsql/src/test/java/org/apache/hop/workflow/actions/waitforsql/ActionWaitForSqlTest.java
 
b/plugins/actions/waitforsql/src/test/java/org/apache/hop/workflow/actions/waitforsql/ActionWaitForSqlTest.java
index 7042de812b..86d05c8043 100644
--- 
a/plugins/actions/waitforsql/src/test/java/org/apache/hop/workflow/actions/waitforsql/ActionWaitForSqlTest.java
+++ 
b/plugins/actions/waitforsql/src/test/java/org/apache/hop/workflow/actions/waitforsql/ActionWaitForSqlTest.java
@@ -21,20 +21,40 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertNull;
 import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.contains;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
 
 import java.util.List;
 import org.apache.hop.core.HopClientEnvironment;
+import org.apache.hop.core.Result;
 import org.apache.hop.core.database.DatabaseMeta;
+import org.apache.hop.core.exception.HopDatabaseException;
+import org.apache.hop.core.logging.HopLogStore;
+import org.apache.hop.core.logging.LogLevel;
 import org.apache.hop.i18n.BaseMessages;
 import org.apache.hop.metadata.serializer.memory.MemoryMetadataProvider;
+import org.apache.hop.workflow.Workflow;
+import org.apache.hop.workflow.WorkflowMeta;
 import org.apache.hop.workflow.action.ActionSerializationTestUtil;
 import 
org.apache.hop.workflow.actions.waitforsql.ActionWaitForSql.SuccessCondition;
 import org.jetbrains.annotations.NotNull;
+import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.Test;
 
 /** Unit tests for wait for sql action. */
 class ActionWaitForSqlTest {
 
+  @BeforeAll
+  static void setUpBeforeClass() throws Exception {
+    HopClientEnvironment.init();
+    HopLogStore.init();
+  }
+
   @Test
   void testSerialization() throws Exception {
     HopClientEnvironment.init();
@@ -119,6 +139,27 @@ class ActionWaitForSqlTest {
         SuccessCondition.ROWS_COUNT_EQUAL, 
SuccessCondition.lookupCode("rows_count_equal"));
   }
 
+  @Test
+  void connectionFailureIsLoggedAsError() throws Exception {
+    ActionWaitForSql action = spy(new ActionWaitForSql("Wait for SQL"));
+    action.setConnection("mysql-refused");
+    action.setTableName("any_table");
+    doThrow(new HopDatabaseException("Connection 
refused")).when(action).checkConnection();
+
+    Workflow workflow = mock(Workflow.class);
+    when(workflow.getLogLevel()).thenReturn(LogLevel.BASIC);
+    when(workflow.isStopped()).thenReturn(false);
+    action.setParentWorkflow(workflow);
+    action.setParentWorkflowMeta(mock(WorkflowMeta.class));
+
+    Result result = action.execute(new Result(), 0);
+
+    assertFalse(result.getResult());
+    assertEquals(1, result.getNrErrors());
+    verify(action).logError(contains("Exception while waiting for SQL data"));
+    verify(action, never()).logBasic(contains("Exception while waiting for SQL 
data"));
+  }
+
   private static @NotNull ActionWaitForSql getActionWaitForSql() {
     ActionWaitForSql action = new ActionWaitForSql("Action wait for SQL");
     action.setClearResultList(false);

Reply via email to