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

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


The following commit(s) were added to refs/heads/main by this push:
     new a0f6ca3d486a CAMEL-27106: camel-ftp - fix flaky 
SftpConsumerWrongPasswordIT (#30270)
a0f6ca3d486a is described below

commit a0f6ca3d486aa9b92a58333535d627d59730e647
Author: Guillaume Nodet <[email protected]>
AuthorDate: Wed Nov 18 20:58:49 2026 +0100

    CAMEL-27106: camel-ftp - fix flaky SftpConsumerWrongPasswordIT (#30270)
    
    RemoteFileConsumerWarnCapture.attach() adds an appender to the global 
Log4j2 root logger. With camel.failsafe.parallel
    the Sftp*IT classes run concurrently in the same JVM, so WARNs of sibling 
test routes bled into the capture and broke
    the count-based assertions of SftpConsumerWrongPasswordIT.
    
    - RemoteFileConsumerWarnCapture uses a unique appender name, so two 
instances attached at once do not collide and
      detach() of one no longer removes the other.
    - SftpConsumerWrongPasswordIT filters the captured WARNs by its own server 
port, so stray WARNs from concurrent tests
      are ignored. It needs no @Isolated.
    - The embedded server extensions of SftpServerTestSupport, 
FtpServerTestSupport and SftpConsumerWrongPasswordIT are
      @Order(0), so the server outlives the CamelContext shutdown and polls in 
flight do not log spurious
      "Connection refused" WARNs during teardown.
    - ClosingServer reads before closing the accepted socket, so the connection 
reset on macOS does not change the WARN
      text that the test asserts.
    
    Co-authored-by: Claude Sonnet 4.6 <[email protected]>
---
 .../file/remote/RemoteFileConsumerWarnCapture.java |  6 ++++-
 .../remote/integration/FtpServerTestSupport.java   |  4 +++
 .../integration/SftpConsumerWrongPasswordIT.java   | 29 +++++++++++++++++++---
 .../sftp/integration/SftpServerTestSupport.java    |  4 +++
 4 files changed, 38 insertions(+), 5 deletions(-)

diff --git 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/RemoteFileConsumerWarnCapture.java
 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/RemoteFileConsumerWarnCapture.java
index 97189d74f305..e707098a2ce4 100644
--- 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/RemoteFileConsumerWarnCapture.java
+++ 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/RemoteFileConsumerWarnCapture.java
@@ -17,6 +17,7 @@
 package org.apache.camel.component.file.remote;
 
 import java.util.List;
+import java.util.UUID;
 import java.util.concurrent.CopyOnWriteArrayList;
 
 import org.apache.logging.log4j.Level;
@@ -28,13 +29,16 @@ import org.apache.logging.log4j.core.config.Property;
 
 /**
  * Captures the WARN messages of the remote file consumer, between {@link 
#attach()} and {@link #detach()}.
+ * <p>
+ * Each instance uses a unique appender name so that two instances attached at 
the same time do not collide on the root
+ * logger, and {@link #detach()} of one does not remove the other.
  */
 public class RemoteFileConsumerWarnCapture extends AbstractAppender {
 
     private final List<String> messages = new CopyOnWriteArrayList<>();
 
     public RemoteFileConsumerWarnCapture() {
-        super("RemoteFileConsumerWarnCapture", null, null, true, 
Property.EMPTY_ARRAY);
+        super("RemoteFileConsumerWarnCapture-" + UUID.randomUUID(), null, 
null, true, Property.EMPTY_ARRAY);
     }
 
     public void attach() {
diff --git 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpServerTestSupport.java
 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpServerTestSupport.java
index 3648c1bde060..8a591b42cb71 100644
--- 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpServerTestSupport.java
+++ 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FtpServerTestSupport.java
@@ -21,6 +21,7 @@ import 
org.apache.camel.component.file.remote.BaseServerTestSupport;
 import org.apache.camel.model.language.SimpleExpression;
 import org.apache.camel.test.infra.ftp.services.FtpServiceFactory;
 import org.apache.camel.test.infra.ftp.services.embedded.FtpEmbeddedService;
+import org.junit.jupiter.api.Order;
 import org.junit.jupiter.api.extension.RegisterExtension;
 
 /**
@@ -28,6 +29,9 @@ import org.junit.jupiter.api.extension.RegisterExtension;
  */
 public abstract class FtpServerTestSupport extends BaseServerTestSupport {
 
+    // @Order(0) keeps the server alive until after the CamelContext 
(@Order(1) in CamelTestSupport) shuts down,
+    // which prevents in-flight polls from logging spurious "Connection 
refused" WARNs during teardown.
+    @Order(0)
     @RegisterExtension
     public FtpEmbeddedService service = 
FtpServiceFactory.createEmbeddedService();
 
diff --git 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/integration/SftpConsumerWrongPasswordIT.java
 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/integration/SftpConsumerWrongPasswordIT.java
index be7c77ee06dc..fe3b1d747ac3 100644
--- 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/integration/SftpConsumerWrongPasswordIT.java
+++ 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/integration/SftpConsumerWrongPasswordIT.java
@@ -41,6 +41,7 @@ import 
org.apache.sshd.server.auth.keyboard.UserAuthKeyboardInteractiveFactory;
 import org.apache.sshd.server.auth.password.UserAuthPasswordFactory;
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Order;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.condition.EnabledIf;
 import org.junit.jupiter.api.extension.RegisterExtension;
@@ -60,6 +61,9 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
 @EnabledIf(value = 
"org.apache.camel.test.infra.ftp.services.embedded.SftpUtil#hasRequiredAlgorithms('src/test/resources/hostkey.pem')")
 class SftpConsumerWrongPasswordIT extends CamelTestSupport {
 
+    // @Order(0) keeps the server alive until after the CamelContext 
(@Order(1) in CamelTestSupport) shuts down,
+    // which prevents in-flight polls from logging spurious "Connection 
refused" WARNs during teardown.
+    @Order(0)
     @RegisterExtension
     CountingSftpEmbeddedService service = new CountingSftpEmbeddedService();
 
@@ -75,6 +79,18 @@ class SftpConsumerWrongPasswordIT extends CamelTestSupport {
         warnings.detach();
     }
 
+    /**
+     * Filters the captured WARNs to those logged by the consumer for this 
test's server port. Each WARN contains
+     * {@code localhost:<port>}, which is unique per test instance, so this 
removes any stray WARNs from a concurrent
+     * test using a different port.
+     */
+    private List<String> warningsForThisTest(int port) {
+        String portMarker = "@localhost:" + port;
+        return warnings.messages().stream()
+                .filter(m -> m.contains(portMarker))
+                .toList();
+    }
+
     @ParameterizedTest
     @ValueSource(strings = { "password", "keyboard-interactive" })
     void wrongPasswordIsSentOncePerPoll(String method) throws Exception {
@@ -90,7 +106,7 @@ class SftpConsumerWrongPasswordIT extends CamelTestSupport {
         assertEquals(List.of("Cannot connect/login to: 
sftp://admin@localhost:"; + service.getPort()
                              + " due to: Auth fail for user 'admin': the 
server did not accept the password."
                              + " Will skip this poll."),
-                warnings.messages());
+                warningsForThisTest(service.getPort()));
     }
 
     @Test
@@ -119,7 +135,7 @@ class SftpConsumerWrongPasswordIT extends CamelTestSupport {
 
         MockEndpoint.assertIsSatisfied(context);
         assertEquals(1, service.passwordChecks());
-        assertTrue(warnings.messages().isEmpty(), "No WARN: " + 
warnings.messages());
+        assertTrue(warningsForThisTest(service.getPort()).isEmpty(), "No WARN: 
" + warnings.messages());
     }
 
     @Test
@@ -144,7 +160,7 @@ class SftpConsumerWrongPasswordIT extends CamelTestSupport {
 
             assertEquals(List.of("Cannot connect/login to: 
sftp://admin@localhost:"; + server.getPort()
                                  + " due to: connection is closed by foreign 
host. Will skip this poll."),
-                    warnings.messages());
+                    warningsForThisTest(server.getPort()));
         }
     }
 
@@ -235,8 +251,13 @@ class SftpConsumerWrongPasswordIT extends CamelTestSupport 
{
 
         private void accept() {
             while (!socket.isClosed()) {
-                try (Socket ignored = socket.accept()) {
+                try (Socket accepted = socket.accept()) {
                     connections.incrementAndGet();
+                    // Read and discard whatever the client sent before 
closing. Without this, closing with unread data
+                    // resets the connection on some platforms (e.g. macOS), 
and JSch reports "Connection reset" instead
+                    // of "connection is closed by foreign host".
+                    accepted.setSoTimeout(1000);
+                    accepted.getInputStream().read(new byte[256]);
                 } catch (IOException e) {
                     // closed
                 }
diff --git 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/integration/SftpServerTestSupport.java
 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/integration/SftpServerTestSupport.java
index 00ca8f36fc58..82554af5261b 100644
--- 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/integration/SftpServerTestSupport.java
+++ 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/integration/SftpServerTestSupport.java
@@ -20,9 +20,13 @@ import java.nio.file.Path;
 
 import org.apache.camel.component.file.remote.BaseServerTestSupport;
 import org.apache.camel.test.infra.ftp.services.embedded.SftpEmbeddedService;
+import org.junit.jupiter.api.Order;
 import org.junit.jupiter.api.extension.RegisterExtension;
 
 public class SftpServerTestSupport extends BaseServerTestSupport {
+    // @Order(0) keeps the server alive until after the CamelContext 
(@Order(1) in CamelTestSupport) shuts down,
+    // which prevents in-flight polls from logging spurious "Connection 
refused" WARNs during teardown.
+    @Order(0)
     @RegisterExtension
     protected SftpEmbeddedService service = new SftpEmbeddedService();
 

Reply via email to