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

gnodet 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 d69196a4b5ff CAMEL-23896: Fix flaky SqlFunctionDataSourceTest MariaDB 
startup timeout (#24410)
d69196a4b5ff is described below

commit d69196a4b5ff27785cabf1b9c2a002d604b0bd51
Author: Guillaume Nodet <[email protected]>
AuthorDate: Sat Jul 4 12:03:42 2026 +0200

    CAMEL-23896: Fix flaky SqlFunctionDataSourceTest MariaDB startup timeout 
(#24410)
    
    * CAMEL-23896: Fix flaky SqlFunctionDataSourceTest MariaDB startup timeout
    
    The embedded MariaDB4j database has a hardcoded 30s startup timeout
    (dbStartMaxWaitInMS) which is too short for CI machines under load.
    This caused intermittent test failures when InnoDB initialization took
    longer than 30s before emitting the "ready for connections" message.
    
    Two fixes applied:
    - Increase the MariaDB startup timeout from 30s to 120s via reflection
      on the protected dbStartMaxWaitInMS field
    - Move sharedMariaDb assignment after successful start() so that
      surefire retries properly re-attempt initialization instead of
      skipping it with a broken DB reference
    
    Co-Authored-By: Claude Opus 4.6 <[email protected]>
    
    * CAMEL-23896: Move sentinel assignment to after all init steps complete
    
    Address review feedback: move sharedMariaDb/sharedDataSource assignment
    to after schema population completes, not just after start(). This
    ensures surefire retries re-attempt the full initialization if any step
    fails (start, DataSource creation, or schema population).
    
    Co-Authored-By: Claude Opus 4.6 <[email protected]>
    
    ---------
    
    Co-authored-by: Claude Opus 4.6 <[email protected]>
---
 .../sql/stored/SqlFunctionDataSourceTest.java      | 31 +++++++++++++++++-----
 1 file changed, 25 insertions(+), 6 deletions(-)

diff --git 
a/components/camel-sql/src/test/java/org/apache/camel/component/sql/stored/SqlFunctionDataSourceTest.java
 
b/components/camel-sql/src/test/java/org/apache/camel/component/sql/stored/SqlFunctionDataSourceTest.java
index e8ffe8bab1c3..d51346802ba5 100644
--- 
a/components/camel-sql/src/test/java/org/apache/camel/component/sql/stored/SqlFunctionDataSourceTest.java
+++ 
b/components/camel-sql/src/test/java/org/apache/camel/component/sql/stored/SqlFunctionDataSourceTest.java
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.component.sql.stored;
 
+import java.lang.reflect.Field;
 import java.sql.SQLException;
 import java.util.HashMap;
 import java.util.Map;
@@ -61,24 +62,43 @@ public class SqlFunctionDataSourceTest extends 
CamelTestSupport {
     private static JdbcTemplate jdbcTemplate;
     private TemplateParser templateParser;
 
+    /**
+     * MariaDB startup timeout in milliseconds. The default 30s in MariaDB4j 
is too short for CI environments under
+     * load, where InnoDB initialization can take longer. 120s provides a 
comfortable margin.
+     */
+    private static final int MARIADB_START_TIMEOUT_MS = 120_000;
+
     /** Initialize the shared MariaDB database for the tests. */
     private static void initSharedMariaDb() throws Exception {
         DBConfigurationBuilder config = DBConfigurationBuilder.newBuilder();
         config.setPort(0);
-        sharedMariaDb = DB.newEmbeddedDB(config.build());
-        sharedMariaDb.start();
+        DB db = DB.newEmbeddedDB(config.build());
+
+        // Increase the startup timeout from the default 30s — CI machines 
under load
+        // may need more time for InnoDB initialization before "ready for 
connections"
+        Field timeoutField = DB.class.getDeclaredField("dbStartMaxWaitInMS");
+        timeoutField.setAccessible(true);
+        timeoutField.setInt(db, MARIADB_START_TIMEOUT_MS);
+
+        db.start();
 
         DriverManagerDataSource dataSource = new DriverManagerDataSource();
         dataSource.setDriverClassName("org.mariadb.jdbc.Driver");
-        dataSource.setUrl(sharedMariaDb.getConfiguration().getURL(DB_NAME));
+        dataSource.setUrl(db.getConfiguration().getURL(DB_NAME));
         dataSource.setUsername("root");
         dataSource.setPassword("");
-        sharedDataSource = dataSource;
 
         ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
         populator.addScript(new 
ClassPathResource("sql/storedFunctionMariaDB.sql"));
         populator.setSeparator("$$");
-        populator.execute(sharedDataSource);
+        populator.execute(dataSource);
+
+        // Only assign to static fields after all initialization succeeds 
(start,
+        // DataSource creation, schema population), so that surefire retries 
will
+        // re-attempt the full initialization if any step fails
+        sharedMariaDb = db;
+        sharedDataSource = dataSource;
+        jdbcTemplate = new JdbcTemplate(sharedDataSource);
 
         Runtime.getRuntime().addShutdownHook(new Thread(() -> {
             if (sharedMariaDb != null) {
@@ -89,7 +109,6 @@ public class SqlFunctionDataSourceTest extends 
CamelTestSupport {
                 }
             }
         }));
-        jdbcTemplate = new JdbcTemplate(sharedDataSource);
     }
 
     /** Initialize the database for the tests. */

Reply via email to