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

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


The following commit(s) were added to refs/heads/main by this push:
     new 0b218b026db NIFI-16562 - Fix flaky ClusteredStopSourcesIT and 
ClusteredConnectorAutoResumeIT (#11897)
0b218b026db is described below

commit 0b218b026db9ffe03f728334b01b13910da7b46b
Author: Pierre Villard <[email protected]>
AuthorDate: Thu Nov 12 16:21:16 2026 +0100

    NIFI-16562 - Fix flaky ClusteredStopSourcesIT and 
ClusteredConnectorAutoResumeIT (#11897)
    
    Signed-off-by: David Handermann <[email protected]>
---
 .../nifi/tests/system/AggregateNiFiInstance.java   | 16 ++++++++++-
 .../SpawnedStandaloneNiFiInstanceFactory.java      |  5 ++++
 .../tests/system/pg/ClusteredStopSourcesIT.java    | 32 ++++++++++++++++++----
 .../resources/conf/clustered/node1/nifi.properties |  2 +-
 .../resources/conf/clustered/node2/nifi.properties |  2 +-
 5 files changed, 49 insertions(+), 8 deletions(-)

diff --git 
a/nifi-system-tests/nifi-system-test-suite/src/test/java/org/apache/nifi/tests/system/AggregateNiFiInstance.java
 
b/nifi-system-tests/nifi-system-test-suite/src/test/java/org/apache/nifi/tests/system/AggregateNiFiInstance.java
index f43277d102d..92e9e9c1fb7 100644
--- 
a/nifi-system-tests/nifi-system-test-suite/src/test/java/org/apache/nifi/tests/system/AggregateNiFiInstance.java
+++ 
b/nifi-system-tests/nifi-system-test-suite/src/test/java/org/apache/nifi/tests/system/AggregateNiFiInstance.java
@@ -23,6 +23,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Optional;
 import java.util.Properties;
+import java.util.concurrent.CopyOnWriteArrayList;
 import javax.net.ssl.SSLContext;
 
 public class AggregateNiFiInstance implements NiFiInstance {
@@ -35,10 +36,17 @@ public class AggregateNiFiInstance implements NiFiInstance {
     @Override
     public void start(boolean waitForCompletion) {
         final Map<Thread, NiFiInstance> startupThreads = new HashMap<>();
+        final List<RuntimeException> startupFailures = new 
CopyOnWriteArrayList<>();
 
         for (final NiFiInstance instance : instances) {
             if (instance.isAutoStart()) {
-                final Thread t = new Thread(() -> 
instance.start(waitForCompletion));
+                final Thread t = new Thread(() -> {
+                    try {
+                        instance.start(waitForCompletion);
+                    } catch (final RuntimeException e) {
+                        startupFailures.add(e);
+                    }
+                });
                 t.start();
                 startupThreads.put(t, instance);
             }
@@ -53,6 +61,12 @@ public class AggregateNiFiInstance implements NiFiInstance {
                 throw new RuntimeException("Interrupted while waiting for 
instance " + entry.getValue() + " to finish starting");
             }
         }
+
+        if (!startupFailures.isEmpty()) {
+            final RuntimeException startupFailure = new 
RuntimeException("Failed to start %d NiFi 
instance(s)".formatted(startupFailures.size()), startupFailures.getFirst());
+            
startupFailures.stream().skip(1).forEach(startupFailure::addSuppressed);
+            throw startupFailure;
+        }
     }
 
     @Override
diff --git 
a/nifi-system-tests/nifi-system-test-suite/src/test/java/org/apache/nifi/tests/system/SpawnedStandaloneNiFiInstanceFactory.java
 
b/nifi-system-tests/nifi-system-test-suite/src/test/java/org/apache/nifi/tests/system/SpawnedStandaloneNiFiInstanceFactory.java
index 588ddd63d16..50a67239ab1 100644
--- 
a/nifi-system-tests/nifi-system-test-suite/src/test/java/org/apache/nifi/tests/system/SpawnedStandaloneNiFiInstanceFactory.java
+++ 
b/nifi-system-tests/nifi-system-test-suite/src/test/java/org/apache/nifi/tests/system/SpawnedStandaloneNiFiInstanceFactory.java
@@ -334,6 +334,11 @@ public class SpawnedStandaloneNiFiInstanceFactory 
implements NiFiInstanceFactory
                         logger.info("NiFi Startup Completed [{}]", 
instanceDirectory.getName());
                         return;
                     } catch (final Exception e) {
+                        if (!process.isAlive()) {
+                            throw new IOException("NiFi instance [%s] process 
exited with code %d before startup completed; see %s/logs/nifi-app.log"
+                                    .formatted(instanceDirectory.getName(), 
process.exitValue(), instanceDirectory.getAbsolutePath()), e);
+                        }
+
                         if (System.currentTimeMillis() > timeoutMillis) {
                             throw new IOException("After waiting 5 minutes, 
NiFi instance still has not started");
                         }
diff --git 
a/nifi-system-tests/nifi-system-test-suite/src/test/java/org/apache/nifi/tests/system/pg/ClusteredStopSourcesIT.java
 
b/nifi-system-tests/nifi-system-test-suite/src/test/java/org/apache/nifi/tests/system/pg/ClusteredStopSourcesIT.java
index 3b5b2c9e1ec..768b1c4a7a4 100644
--- 
a/nifi-system-tests/nifi-system-test-suite/src/test/java/org/apache/nifi/tests/system/pg/ClusteredStopSourcesIT.java
+++ 
b/nifi-system-tests/nifi-system-test-suite/src/test/java/org/apache/nifi/tests/system/pg/ClusteredStopSourcesIT.java
@@ -19,6 +19,7 @@ package org.apache.nifi.tests.system.pg;
 import jakarta.ws.rs.WebApplicationException;
 import org.apache.nifi.controller.ScheduledState;
 import org.apache.nifi.groups.StatelessGroupScheduledState;
+import org.apache.nifi.tests.system.ExceptionalBooleanSupplier;
 import org.apache.nifi.tests.system.NiFiInstanceFactory;
 import org.apache.nifi.tests.system.NiFiSystemIT;
 import org.apache.nifi.toolkit.client.NiFiClientException;
@@ -28,6 +29,7 @@ import 
org.apache.nifi.web.api.entity.ScheduleComponentsEntity;
 import org.junit.jupiter.api.Test;
 
 import java.io.IOException;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
@@ -143,6 +145,24 @@ public class ClusteredStopSourcesIT extends NiFiSystemIT {
         
getClientUtil().waitForRunningProcessor(flow.standardDownstream().getId());
         
getClientUtil().waitForRunningProcessor(flow.statelessSource().getId());
         
getClientUtil().waitForRunningProcessor(flow.statelessDownstream().getId());
+
+        // Stateless Group components are started asynchronously on each node, 
so the merged cluster response may not reflect every node
+        for (final ProcessorEntity processor : List.of(flow.standardSource(), 
flow.standardDownstream(), flow.statelessSource(), flow.statelessDownstream())) 
{
+            waitForOnAllNodes(() -> 
isProcessorStateOnCurrentNode(processor.getId(), ScheduledState.RUNNING), 
"Processor " + processor.getId() + " to be RUNNING");
+        }
+        waitForOnAllNodes(() -> 
StatelessGroupScheduledState.RUNNING.name().equals(getNifiClient().getProcessGroupClient(DO_NOT_REPLICATE)
+                
.getProcessGroup(flow.statelessGroup().getId()).getComponent().getStatelessGroupScheduledState()),
 "Stateless Group to be RUNNING");
+    }
+
+    private void waitForOnAllNodes(final ExceptionalBooleanSupplier condition, 
final String description) throws InterruptedException {
+        try {
+            for (int nodeIndex = 1; nodeIndex <= 2; nodeIndex++) {
+                switchClientToNode(nodeIndex);
+                waitFor(condition, 100L, description + " on Node " + 
nodeIndex);
+            }
+        } finally {
+            switchClientToNode(1);
+        }
     }
 
     private ScheduleComponentsEntity stopSourcesRequest(final String groupId) {
@@ -191,11 +211,13 @@ public class ClusteredStopSourcesIT extends NiFiSystemIT {
     }
 
     private void waitForProcessorStateOnCurrentNode(final String processorId, 
final ScheduledState expectedState) throws InterruptedException {
-        waitFor(() -> {
-            final ProcessorEntity processor = 
getNifiClient().getProcessorClient(DO_NOT_REPLICATE).getProcessor(processorId);
-            return 
expectedState.name().equals(processor.getComponent().getState())
-                    && 
expectedState.name().equals(processor.getComponent().getPhysicalState());
-        });
+        waitFor(() -> isProcessorStateOnCurrentNode(processorId, 
expectedState));
+    }
+
+    private boolean isProcessorStateOnCurrentNode(final String processorId, 
final ScheduledState expectedState) throws NiFiClientException, IOException {
+        final ProcessorEntity processor = 
getNifiClient().getProcessorClient(DO_NOT_REPLICATE).getProcessor(processorId);
+        return expectedState.name().equals(processor.getComponent().getState())
+                && 
expectedState.name().equals(processor.getComponent().getPhysicalState());
     }
 
     private void assertProcessorStateOnNode(final String processorId, final 
ScheduledState expectedState, final int nodeIndex)
diff --git 
a/nifi-system-tests/nifi-system-test-suite/src/test/resources/conf/clustered/node1/nifi.properties
 
b/nifi-system-tests/nifi-system-test-suite/src/test/resources/conf/clustered/node1/nifi.properties
index 80754ed3899..2ebd2b8cd2f 100644
--- 
a/nifi-system-tests/nifi-system-test-suite/src/test/resources/conf/clustered/node1/nifi.properties
+++ 
b/nifi-system-tests/nifi-system-test-suite/src/test/resources/conf/clustered/node1/nifi.properties
@@ -198,7 +198,7 @@ nifi.cluster.protocol.heartbeat.interval=2 sec
 # cluster node properties (only configure for cluster nodes) #
 nifi.cluster.is.node=true
 nifi.cluster.node.address=
-nifi.cluster.node.protocol.port=48101
+nifi.cluster.node.protocol.port=6351
 nifi.cluster.node.protocol.threads=10
 nifi.cluster.node.protocol.max.threads=50
 nifi.cluster.node.event.history.size=25
diff --git 
a/nifi-system-tests/nifi-system-test-suite/src/test/resources/conf/clustered/node2/nifi.properties
 
b/nifi-system-tests/nifi-system-test-suite/src/test/resources/conf/clustered/node2/nifi.properties
index 5e511ebea8b..b9b2d889a9f 100644
--- 
a/nifi-system-tests/nifi-system-test-suite/src/test/resources/conf/clustered/node2/nifi.properties
+++ 
b/nifi-system-tests/nifi-system-test-suite/src/test/resources/conf/clustered/node2/nifi.properties
@@ -198,7 +198,7 @@ nifi.cluster.protocol.heartbeat.interval=2 sec
 # cluster node properties (only configure for cluster nodes) #
 nifi.cluster.is.node=true
 nifi.cluster.node.address=
-nifi.cluster.node.protocol.port=48102
+nifi.cluster.node.protocol.port=6352
 nifi.cluster.node.protocol.threads=10
 nifi.cluster.node.protocol.max.threads=50
 nifi.cluster.node.event.history.size=25

Reply via email to