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 a3e5d8c446ce CAMEL-25451: Fix flaky 
SmppTRXProducerSupervisingRouteControllerIT (#27734)
a3e5d8c446ce is described below

commit a3e5d8c446cec00cc73e1b3b9223e5c5b5122638
Author: AurĂ©lien Pupier <[email protected]>
AuthorDate: Mon Oct 12 22:50:15 2026 +0200

    CAMEL-25451: Fix flaky SmppTRXProducerSupervisingRouteControllerIT (#27734)
    
    Co-authored-by: IBM Bob 2.2.1
---
 components/camel-smpp/pom.xml                      |  6 ++++
 ...mppTRXProducerSupervisingRouteControllerIT.java | 41 ++++++++++++----------
 2 files changed, 28 insertions(+), 19 deletions(-)

diff --git a/components/camel-smpp/pom.xml b/components/camel-smpp/pom.xml
index 67347610f12b..ef9d981e9f8c 100644
--- a/components/camel-smpp/pom.xml
+++ b/components/camel-smpp/pom.xml
@@ -69,6 +69,12 @@
             <version>${hamcrest-version}</version>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.awaitility</groupId>
+            <artifactId>awaitility</artifactId>
+            <version>${awaitility-version}</version>
+            <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>org.jsmpp</groupId>
             <artifactId>jsmpp-examples</artifactId>
diff --git 
a/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/integration/SmppTRXProducerSupervisingRouteControllerIT.java
 
b/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/integration/SmppTRXProducerSupervisingRouteControllerIT.java
index 77c2b94a0afd..ed584f013acd 100644
--- 
a/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/integration/SmppTRXProducerSupervisingRouteControllerIT.java
+++ 
b/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/integration/SmppTRXProducerSupervisingRouteControllerIT.java
@@ -16,9 +16,8 @@
  */
 package org.apache.camel.component.smpp.integration;
 
-import java.util.ArrayList;
 import java.util.List;
-import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.concurrent.TimeUnit;
 
 import org.apache.camel.CamelContext;
@@ -38,11 +37,11 @@ import org.apache.camel.test.AvailablePortFinder;
 import org.apache.camel.test.junit6.CamelTestSupport;
 import org.jsmpp.examples.SMPPServerSimulator;
 import org.junit.jupiter.api.AfterAll;
-import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.RegisterExtension;
 import org.junit.jupiter.api.parallel.Isolated;
 
+import static org.awaitility.Awaitility.await;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertNull;
@@ -52,17 +51,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
 class SmppTRXProducerSupervisingRouteControllerIT extends CamelTestSupport {
     @RegisterExtension
     static AvailablePortFinder.Port PORT = AvailablePortFinder.find();
-    private static final CountDownLatch LATCH = new CountDownLatch(1);
-    private static final Thread SMPP_SERVER_SIMULATOR = new Thread(() -> {
-        try {
-            // timeout after 3 sec
-            LATCH.await(3, TimeUnit.SECONDS);
-        } catch (Exception e) {
-            // ignore
-        }
-        System.setProperty("jsmpp.simulator.port", "" + PORT.getPort());
-        SMPPServerSimulator.main(null);
-    });
+    private static Thread smppServerSimulator;
 
     @EndpointInject("mock:result")
     private MockEndpoint result;
@@ -82,7 +71,7 @@ class SmppTRXProducerSupervisingRouteControllerIT extends 
CamelTestSupport {
         src.setInitialDelay(100);
         src.setThreadPoolSize(2);
 
-        events = new ArrayList<>();
+        events = new CopyOnWriteArrayList<>();
         context.getManagementStrategy().addEventNotifier(new 
SimpleEventNotifierSupport() {
             @Override
             public void notify(CamelEvent event) throws Exception {
@@ -95,18 +84,32 @@ class SmppTRXProducerSupervisingRouteControllerIT extends 
CamelTestSupport {
         return context;
     }
 
-    @BeforeAll
-    public static void runSMPPServerSimulator() {
-        SMPP_SERVER_SIMULATOR.start();
+    private static void runSMPPServerSimulator() {
+        // a new thread is created each time, as the test class can be re-run 
in the same JVM
+        smppServerSimulator = new Thread(() -> {
+            System.setProperty("jsmpp.simulator.port", "" + PORT.getPort());
+            SMPPServerSimulator.main(null);
+        });
+        smppServerSimulator.setDaemon(true);
+        smppServerSimulator.start();
     }
 
     @AfterAll
     public static void stopSMPPServerSimulator() {
-        SMPP_SERVER_SIMULATOR.interrupt();
+        if (smppServerSimulator != null) {
+            smppServerSimulator.interrupt();
+        }
     }
 
     @Test
     void sendSubmitSMInOnly() throws Exception {
+        // the SMPP server is not available yet, so the supervising route 
controller must be restarting the route
+        await().atMost(20, TimeUnit.SECONDS)
+                .untilAsserted(() -> assertTrue(events.size() >= 3,
+                        "There should be restarting events, size: " + 
events.size()));
+
+        runSMPPServerSimulator();
+
         result.expectedMessageCount(1);
 
         Exchange exchange = start.createExchange(ExchangePattern.InOnly);

Reply via email to