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

shuber pushed a commit to branch unomi-3-dev
in repository https://gitbox.apache.org/repos/asf/unomi.git


The following commit(s) were added to refs/heads/unomi-3-dev by this push:
     new 07a6fd925 Enhance BaseIT with Camel debugging capabilities and improve 
test reliability
07a6fd925 is described below

commit 07a6fd92500cf960f3eeeda0a910f9a9e3144ffc
Author: Serge Huber <[email protected]>
AuthorDate: Sat Dec 6 21:45:46 2025 +0100

    Enhance BaseIT with Camel debugging capabilities and improve test 
reliability
    
    - Added support for enabling Apache Camel debug logging and tracing via 
system properties, providing better visibility into Camel operations during 
tests.
    - Implemented methods to check Camel route status, existence, and detailed 
information, enhancing test diagnostics.
    - Updated ProfileImportIT classes to wait for Camel routes to start and 
check for specific import configurations, improving test reliability and 
reducing flakiness.
    - Refactored import configuration checks to focus on specific item IDs 
instead of exact counts, addressing potential issues with leftover 
configurations.
---
 .../test/java/org/apache/unomi/itests/BaseIT.java  | 288 ++++++++++++++++++++-
 .../apache/unomi/itests/ProfileImportActorsIT.java |  24 +-
 .../unomi/itests/ProfileImportRankingIT.java       |  13 +-
 .../unomi/itests/ProfileImportSurfersIT.java       |  33 ++-
 4 files changed, 344 insertions(+), 14 deletions(-)

diff --git a/itests/src/test/java/org/apache/unomi/itests/BaseIT.java 
b/itests/src/test/java/org/apache/unomi/itests/BaseIT.java
index fe719240d..e5f0c8059 100644
--- a/itests/src/test/java/org/apache/unomi/itests/BaseIT.java
+++ b/itests/src/test/java/org/apache/unomi/itests/BaseIT.java
@@ -139,6 +139,7 @@ public abstract class BaseIT extends KarafTestSupport {
     protected static final String SEARCH_ENGINE_OPENSEARCH = "opensearch";
     protected static final String RESOLVER_DEBUG_PROPERTY = 
"it.unomi.resolver.debug";
     protected static final String ENABLE_LOG_CHECKING_PROPERTY = 
"it.unomi.log.checking.enabled";
+    protected static final String CAMEL_DEBUG_PROPERTY = 
"it.unomi.camel.debug";
 
     protected final static ObjectMapper objectMapper;
     protected static boolean unomiStarted = false;
@@ -291,6 +292,9 @@ public abstract class BaseIT extends KarafTestSupport {
 
         
executionContextManager.setCurrentContext(executionContextManager.createContext(testTenant.getItemId()));
 
+        // Enable Camel tracing and debug logging if requested (for test 
visibility)
+        enableCamelDebugIfRequested();
+
         // Set up test tenant for HttpClientThatWaitsForUnomi
         HttpClientThatWaitsForUnomi.setTestTenant(testTenant, testPublicKey, 
testPrivateKey);
 
@@ -655,6 +659,23 @@ public abstract class BaseIT extends KarafTestSupport {
             System.out.println("Karaf Resolver debug logging is disabled (set 
-Dit.unomi.resolver.debug=true to enable)");
         }
 
+        // Enable Camel debug logging if requested (for test visibility into 
Camel operations)
+        boolean enableCamelDebug = 
Boolean.parseBoolean(System.getProperty(CAMEL_DEBUG_PROPERTY, "false"));
+        if (enableCamelDebug) {
+            LOGGER.info("Enabling debug logging for Apache Camel");
+            System.out.println("Enabling debug logging for Apache Camel (set 
-Dit.unomi.camel.debug=true to enable)");
+            // Enable logging for Camel core, routes, and router components
+            
karafOptions.add(editConfigurationFilePut("etc/org.ops4j.pax.logging.cfg", 
"log4j2.logger.camelCore.name", "org.apache.camel"));
+            
karafOptions.add(editConfigurationFilePut("etc/org.ops4j.pax.logging.cfg", 
"log4j2.logger.camelCore.level", "DEBUG"));
+            
karafOptions.add(editConfigurationFilePut("etc/org.ops4j.pax.logging.cfg", 
"log4j2.logger.camelRouter.name", "org.apache.unomi.router"));
+            
karafOptions.add(editConfigurationFilePut("etc/org.ops4j.pax.logging.cfg", 
"log4j2.logger.camelRouter.level", "DEBUG"));
+            
karafOptions.add(editConfigurationFilePut("etc/org.ops4j.pax.logging.cfg", 
"log4j2.logger.camelFile.name", "org.apache.camel.component.file"));
+            
karafOptions.add(editConfigurationFilePut("etc/org.ops4j.pax.logging.cfg", 
"log4j2.logger.camelFile.level", "DEBUG"));
+        } else {
+            LOGGER.info("Camel debug logging is disabled (set 
-Dit.unomi.camel.debug=true to enable)");
+            System.out.println("Camel debug logging is disabled (set 
-Dit.unomi.camel.debug=true to enable)");
+        }
+
         searchEngine = System.getProperty(SEARCH_ENGINE_PROPERTY, 
SEARCH_ENGINE_ELASTICSEARCH);
         LOGGER.info("Search Engine: {}", searchEngine);
         System.out.println("Search Engine: " + searchEngine);
@@ -698,12 +719,18 @@ public abstract class BaseIT extends KarafTestSupport {
             throws InterruptedException {
         int count = 0;
         T value = null;
+        T lastValue = null;
         while (value == null || !predicate.test(value)) {
             if (count++ > retries) {
-                Assert.fail(failMessage);
+                String detailedMessage = failMessage;
+                if (lastValue != null) {
+                    detailedMessage += " (last value: " + lastValue + ")";
+                }
+                Assert.fail(detailedMessage);
             }
             Thread.sleep(timeout);
             value = call.get();
+            lastValue = value;
         }
         return value;
     }
@@ -1505,4 +1532,263 @@ public abstract class BaseIT extends KarafTestSupport {
             }
         }
     }
+
+    /**
+     * Enables Camel tracing and debug logging if requested via system 
property.
+     * This provides visibility into Camel operations during test execution 
without modifying production code.
+     * 
+     * To enable: Set system property -Dit.unomi.camel.debug=true
+     * 
+     * This will:
+     * - Enable Camel tracing (logs detailed message flow, body content, 
headers as messages traverse routes)
+     *   Tracing is useful for understanding WHAT is happening in routes 
(message content, transformations)
+     * - Enable DEBUG logging for Camel packages (configured in config() 
method)
+     * 
+     * Note: Tracing provides different information than route status checking:
+     * - Tracing: Shows message flow and content (useful for debugging message 
transformations)
+     * - Route Status API: Shows if routes are running, exchange counts, 
processing times (useful for verifying execution)
+     * Both can be used together for comprehensive visibility.
+     */
+    protected void enableCamelDebugIfRequested() {
+        boolean enableCamelDebug = 
Boolean.parseBoolean(System.getProperty(CAMEL_DEBUG_PROPERTY, "false"));
+        if (enableCamelDebug && routerCamelContext != null) {
+            try {
+                routerCamelContext.setTracing(true);
+                LOGGER.info("Camel tracing enabled for test visibility (shows 
message flow and content)");
+                System.out.println("==== Camel tracing enabled for test 
visibility ====");
+                System.out.println("==== Use getCamelRouteInfo() for route 
status and statistics ====");
+            } catch (Exception e) {
+                LOGGER.warn("Failed to enable Camel tracing: {}", 
e.getMessage());
+            }
+        }
+    }
+
+    /**
+     * Gets the Camel context from the router Camel context service using 
reflection.
+     * This allows test code to inspect Camel routes without modifying 
production code.
+     * Based on official Camel API: https://camel.apache.org/manual/
+     * 
+     * @return The CamelContext instance, or null if not available
+     */
+    protected Object getCamelContext() {
+        if (routerCamelContext == null) {
+            return null;
+        }
+        try {
+            // Use reflection to access getCamelContext() method which exists 
but isn't in the interface
+            java.lang.reflect.Method method = 
routerCamelContext.getClass().getMethod("getCamelContext");
+            return method.invoke(routerCamelContext);
+        } catch (Exception e) {
+            LOGGER.debug("Could not access CamelContext: {}", e.getMessage());
+            return null;
+        }
+    }
+
+    /**
+     * Checks if a Camel route with the given route ID exists.
+     * Uses official Camel API: CamelContext.getRoute(String routeId)
+     * 
+     * @param routeId The route ID to check (typically the import 
configuration itemId)
+     * @return true if the route exists, false otherwise
+     */
+    protected boolean camelRouteExists(String routeId) {
+        Object camelContext = getCamelContext();
+        if (camelContext == null) {
+            return false;
+        }
+        try {
+            // Official Camel API: context.getRoute(routeId)
+            java.lang.reflect.Method getRouteMethod = 
camelContext.getClass().getMethod("getRoute", String.class);
+            Object route = getRouteMethod.invoke(camelContext, routeId);
+            return route != null;
+        } catch (Exception e) {
+            LOGGER.debug("Error checking if route exists for {}: {}", routeId, 
e.getMessage());
+            return false;
+        }
+    }
+
+    /**
+     * Gets the status of a Camel route.
+     * Uses official Camel API: 
CamelContext.getRouteController().getRouteStatus(routeId)
+     * Returns ServiceStatus enum: Started, Stopped, Suspended, etc.
+     * 
+     * @param routeId The route ID to get status for
+     * @return The route status as a string, or null if route doesn't exist or 
status unavailable
+     */
+    protected String getCamelRouteStatus(String routeId) {
+        Object camelContext = getCamelContext();
+        if (camelContext == null) {
+            return null;
+        }
+        try {
+            // Official Camel API: 
context.getRouteController().getRouteStatus(routeId)
+            java.lang.reflect.Method getRouteControllerMethod = 
camelContext.getClass().getMethod("getRouteController");
+            Object routeController = 
getRouteControllerMethod.invoke(camelContext);
+            if (routeController != null) {
+                java.lang.reflect.Method getRouteStatusMethod = 
routeController.getClass().getMethod("getRouteStatus", String.class);
+                Object status = getRouteStatusMethod.invoke(routeController, 
routeId);
+                return status != null ? status.toString() : null;
+            }
+        } catch (Exception e) {
+            LOGGER.debug("Error getting route status for {}: {}", routeId, 
e.getMessage());
+        }
+        return null;
+    }
+
+    /**
+     * Checks if a Camel route is started (running).
+     * Uses official Camel API to check route status.
+     * 
+     * @param routeId The route ID to check
+     * @return true if the route exists and is started, false otherwise
+     */
+    protected boolean isCamelRouteStarted(String routeId) {
+        String status = getCamelRouteStatus(routeId);
+        return status != null && status.contains("Started");
+    }
+
+    /**
+     * Gets detailed information about a Camel route including status and 
statistics.
+     * Uses official Camel Management API when available.
+     * 
+     * @param routeId The route ID to get information for
+     * @return A string describing the route status and statistics, or error 
message if route doesn't exist
+     */
+    protected String getCamelRouteInfo(String routeId) {
+        Object camelContext = getCamelContext();
+        if (camelContext == null) {
+            return "CamelContext not available";
+        }
+        try {
+            // Check if route exists
+            java.lang.reflect.Method getRouteMethod = 
camelContext.getClass().getMethod("getRoute", String.class);
+            Object route = getRouteMethod.invoke(camelContext, routeId);
+            if (route == null) {
+                return "Route '" + routeId + "' does not exist";
+            }
+            
+            StringBuilder info = new StringBuilder();
+            info.append("Route '").append(routeId).append("': ");
+            
+            // Get route status using official API
+            String status = getCamelRouteStatus(routeId);
+            if (status != null) {
+                info.append("status=").append(status);
+            } else {
+                info.append("status=unknown");
+            }
+            
+            // Try to get route statistics from Management API
+            try {
+                java.lang.reflect.Method getManagementStrategyMethod = 
camelContext.getClass().getMethod("getManagementStrategy");
+                Object managementStrategy = 
getManagementStrategyMethod.invoke(camelContext);
+                if (managementStrategy != null) {
+                    // Try to get ManagedRouteMBean for statistics
+                    java.lang.reflect.Method getManagementObjectMethod = 
managementStrategy.getClass().getMethod("getManagementObject", 
route.getClass());
+                    Object managedRoute = 
getManagementObjectMethod.invoke(managementStrategy, route);
+                    if (managedRoute != null) {
+                        // Get exchange statistics
+                        try {
+                            java.lang.reflect.Method getExchangesTotalMethod = 
managedRoute.getClass().getMethod("getExchangesTotal");
+                            Long exchangesTotal = (Long) 
getExchangesTotalMethod.invoke(managedRoute);
+                            info.append(", 
exchangesTotal=").append(exchangesTotal);
+                            
+                            java.lang.reflect.Method 
getExchangesCompletedMethod = 
managedRoute.getClass().getMethod("getExchangesCompleted");
+                            Long exchangesCompleted = (Long) 
getExchangesCompletedMethod.invoke(managedRoute);
+                            info.append(", 
exchangesCompleted=").append(exchangesCompleted);
+                            
+                            java.lang.reflect.Method getExchangesFailedMethod 
= managedRoute.getClass().getMethod("getExchangesFailed");
+                            Long exchangesFailed = (Long) 
getExchangesFailedMethod.invoke(managedRoute);
+                            info.append(", 
exchangesFailed=").append(exchangesFailed);
+                            
+                            java.lang.reflect.Method 
getLastProcessingTimeMethod = 
managedRoute.getClass().getMethod("getLastProcessingTime");
+                            Long lastProcessingTime = (Long) 
getLastProcessingTimeMethod.invoke(managedRoute);
+                            if (lastProcessingTime != null) {
+                                info.append(", 
lastProcessingTime=").append(lastProcessingTime).append("ms");
+                            }
+                        } catch (Exception e) {
+                            // Statistics methods not available, that's okay
+                        }
+                    }
+                }
+            } catch (Exception e) {
+                // Management API not available, that's okay - we still have 
status
+            }
+            
+            return info.toString();
+        } catch (Exception e) {
+            return "Error getting route info for '" + routeId + "': " + 
e.getMessage();
+        }
+    }
+
+    /**
+     * Waits for a Camel route to be created and started.
+     * This is useful for tests that need to verify the route was created by 
the timer.
+     * 
+     * @param routeId The route ID to wait for
+     * @param timeoutMs Timeout in milliseconds between retries
+     * @param maxRetries Maximum number of retries
+     * @return true if the route exists and is started, false if timeout
+     * @throws InterruptedException if interrupted
+     */
+    protected boolean waitForCamelRouteStarted(String routeId, int timeoutMs, 
int maxRetries) throws InterruptedException {
+        for (int i = 0; i < maxRetries; i++) {
+            if (isCamelRouteStarted(routeId)) {
+                String routeInfo = getCamelRouteInfo(routeId);
+                LOGGER.debug("Camel route '{}' is started. {}", routeId, 
routeInfo);
+                return true;
+            }
+            Thread.sleep(timeoutMs);
+        }
+        String routeInfo = getCamelRouteInfo(routeId);
+        LOGGER.warn("Camel route '{}' did not start within timeout. {}", 
routeId, routeInfo);
+        return false;
+    }
+
+    /**
+     * Gets a list of all Camel route IDs with their statuses.
+     * Uses official Camel API: CamelContext.getRoutes()
+     * 
+     * @return Map of route ID to status, or empty map if CamelContext is not 
available
+     */
+    protected java.util.Map<String, String> getAllCamelRoutesWithStatus() {
+        java.util.Map<String, String> routes = new java.util.HashMap<>();
+        Object camelContext = getCamelContext();
+        if (camelContext == null) {
+            return routes;
+        }
+        try {
+            // Official Camel API: context.getRoutes()
+            java.lang.reflect.Method getRoutesMethod = 
camelContext.getClass().getMethod("getRoutes");
+            @SuppressWarnings("unchecked")
+            java.util.Collection<Object> routeCollection = 
(java.util.Collection<Object>) getRoutesMethod.invoke(camelContext);
+            if (routeCollection != null) {
+                for (Object route : routeCollection) {
+                    try {
+                        java.lang.reflect.Method getRouteIdMethod = 
route.getClass().getMethod("getRouteId");
+                        Object routeId = getRouteIdMethod.invoke(route);
+                        if (routeId != null) {
+                            String routeIdStr = routeId.toString();
+                            String status = getCamelRouteStatus(routeIdStr);
+                            routes.put(routeIdStr, status != null ? status : 
"unknown");
+                        }
+                    } catch (Exception e) {
+                        // Could not get route ID, skip
+                    }
+                }
+            }
+        } catch (Exception e) {
+            LOGGER.debug("Error getting all routes: {}", e.getMessage());
+        }
+        return routes;
+    }
+
+    /**
+     * Gets a list of all Camel route IDs.
+     * 
+     * @return List of route IDs, or empty list if CamelContext is not 
available
+     */
+    protected java.util.List<String> getAllCamelRouteIds() {
+        return new 
java.util.ArrayList<>(getAllCamelRoutesWithStatus().keySet());
+    }
 }
diff --git 
a/itests/src/test/java/org/apache/unomi/itests/ProfileImportActorsIT.java 
b/itests/src/test/java/org/apache/unomi/itests/ProfileImportActorsIT.java
index 0d3c17799..22866aa69 100644
--- a/itests/src/test/java/org/apache/unomi/itests/ProfileImportActorsIT.java
+++ b/itests/src/test/java/org/apache/unomi/itests/ProfileImportActorsIT.java
@@ -94,17 +94,35 @@ public class ProfileImportActorsIT extends BaseIT {
         ImportConfiguration savedImportConfigActors = 
importConfigurationService.save(importConfigActors, true);
         keepTrying("Failed waiting for actors import configuration to be 
saved", () -> importConfigurationService.load(importConfigActors.getItemId()), 
Objects::nonNull, DEFAULT_TRYING_TIMEOUT, DEFAULT_TRYING_TRIES);
 
+        // Wait for Camel route to be created and started (the timer runs 
every 1 second to process config refreshes)
+        // This gives us visibility into what Camel is doing instead of just 
waiting for results
+        // Using official Camel API: getRouteController().getRouteStatus() and 
Management API for statistics
+        boolean routeStarted = waitForCamelRouteStarted(itemId, 1000, 5);
+        if (routeStarted) {
+            String routeInfo = getCamelRouteInfo(itemId);
+            System.out.println("==== Camel Route Status: " + routeInfo + " 
====");
+        } else {
+            System.out.println("==== Camel Route '" + itemId + "' was not 
started within timeout ====");
+            System.out.println("==== All Camel routes with status: " + 
getAllCamelRoutesWithStatus() + " ====");
+        }
+
         //Wait for data to be processed
         keepTrying("Failed waiting for actors initial import to complete",
                 () -> 
profileService.findProfilesByPropertyValue("properties.city", "hollywood", 0, 
10, null), (p) -> p.getTotalSize() == 6,
                 1000, 200);
 
+        // Refresh the persistence index to ensure the saved configuration is 
queryable in getAll()
+        // This addresses the flakiness where getAll() returns 0 items due to 
index refresh delay
+        persistenceService.refreshIndex(ImportConfiguration.class);
+
         // Wait for import configuration to be properly saved and available
-        List<ImportConfiguration> importConfigurations = keepTrying("Failed 
waiting for import configurations list with 1 item",
+        // Check for the specific item ID instead of exact count to avoid 
flakiness from leftover configurations
+        List<ImportConfiguration> importConfigurations = keepTrying("Failed 
waiting for import configuration '" + itemId + "' to be available in getAll()",
                 () -> importConfigurationService.getAll(), 
-                (list) -> Objects.nonNull(list) && list.size() == 1, 
+                (list) -> Objects.nonNull(list) && 
list.stream().anyMatch(config -> itemId.equals(config.getItemId())), 
                 1000, 100);
-        Assert.assertEquals(1, importConfigurations.size());
+        Assert.assertTrue("Import configuration '" + itemId + "' should be in 
the list", 
+                importConfigurations.stream().anyMatch(config -> 
itemId.equals(config.getItemId())));
 
         PartialList<Profile> jeanneProfile = 
profileService.findProfilesByPropertyValue("properties.twitterId", "4", 0, 10, 
null);
         Assert.assertEquals(1, jeanneProfile.getList().size());
diff --git 
a/itests/src/test/java/org/apache/unomi/itests/ProfileImportRankingIT.java 
b/itests/src/test/java/org/apache/unomi/itests/ProfileImportRankingIT.java
index 8dc2ff5ad..6bf53825c 100644
--- a/itests/src/test/java/org/apache/unomi/itests/ProfileImportRankingIT.java
+++ b/itests/src/test/java/org/apache/unomi/itests/ProfileImportRankingIT.java
@@ -45,8 +45,6 @@ public class ProfileImportRankingIT extends BaseIT {
     @Test
     public void testImportRanking() throws InterruptedException {
 
-        routerCamelContext.setTracing(true);
-
         /*** Create Missing Properties ***/
         PropertyType propertyTypeUciId = new PropertyType(new 
Metadata("integration", "uciId", "UCI ID", "UCI ID"));
         propertyTypeUciId.setValueTypeId("string");
@@ -100,8 +98,15 @@ public class ProfileImportRankingIT extends BaseIT {
                 () -> 
profileService.findProfilesByPropertyValue("properties.city", "rankingCity", 0, 
50, null),
                 (p) -> p.getTotalSize() == 25, 1000, 200);
 
-        List<ImportConfiguration> importConfigurations = keepTrying("Failed 
waiting for import configurations list with 1 item",
-                () -> importConfigurationService.getAll(), (list) -> 
Objects.nonNull(list) && list.size() == 1, 1000, 100);
+        // Refresh the persistence index to ensure the saved configuration is 
queryable in getAll()
+        // This addresses the flakiness where getAll() returns 0 items due to 
index refresh delay
+        persistenceService.refreshIndex(ImportConfiguration.class);
+
+        // Check for the specific item ID instead of exact count to avoid 
flakiness from leftover configurations
+        List<ImportConfiguration> importConfigurations = keepTrying("Failed 
waiting for import configuration '" + itemId + "' to be available in getAll()",
+                () -> importConfigurationService.getAll(), 
+                (list) -> Objects.nonNull(list) && 
list.stream().anyMatch(config -> itemId.equals(config.getItemId())), 
+                1000, 100);
 
         PartialList<Profile> gregProfileList = 
profileService.findProfilesByPropertyValue("properties.uciId", "10004451371", 
0, 10, null);
         Assert.assertEquals(1, gregProfileList.getList().size());
diff --git 
a/itests/src/test/java/org/apache/unomi/itests/ProfileImportSurfersIT.java 
b/itests/src/test/java/org/apache/unomi/itests/ProfileImportSurfersIT.java
index f9074fa9f..8c630879a 100644
--- a/itests/src/test/java/org/apache/unomi/itests/ProfileImportSurfersIT.java
+++ b/itests/src/test/java/org/apache/unomi/itests/ProfileImportSurfersIT.java
@@ -98,8 +98,15 @@ public class ProfileImportSurfersIT extends BaseIT {
                 () -> 
profileService.findProfilesByPropertyValue("properties.city", "surfersCity", 0, 
50, null),
                 (p) -> p.getTotalSize() == 34, 1000, 100);
 
-        keepTrying("Failed waiting for import configurations list with 1 
item", () -> importConfigurationService.getAll(),
-                (list) -> Objects.nonNull(list) && list.size() == 1, 1000, 
100);
+        // Refresh the persistence index to ensure the saved configuration is 
queryable in getAll()
+        // This addresses the flakiness where getAll() returns 0 items due to 
index refresh delay
+        persistenceService.refreshIndex(ImportConfiguration.class);
+
+        // Check for the specific item ID instead of exact count to avoid 
flakiness from leftover configurations
+        keepTrying("Failed waiting for import configuration '" + itemId1 + "' 
to be available in getAll()", 
+                () -> importConfigurationService.getAll(),
+                (list) -> Objects.nonNull(list) && 
list.stream().anyMatch(config -> itemId1.equals(config.getItemId())), 
+                1000, 100);
 
         //Profile not to delete
         PartialList<Profile> jordyProfile = 
profileService.findProfilesByPropertyValue("properties.email", 
"[email protected]", 0, 10, null);
@@ -146,8 +153,15 @@ public class ProfileImportSurfersIT extends BaseIT {
                 () -> 
profileService.findProfilesByPropertyValue("properties.city", "surfersCity", 0, 
50, null),
                 (p) -> p.getTotalSize() == 36, 1000, 100);
 
-        keepTrying("Failed waiting for import configurations list with 1 
item", () -> importConfigurationService.getAll(),
-                (list) -> Objects.nonNull(list) && list.size() == 1, 1000, 
100);
+        // Refresh the persistence index to ensure the saved configuration is 
queryable in getAll()
+        // This addresses the flakiness where getAll() returns 0 items due to 
index refresh delay
+        persistenceService.refreshIndex(ImportConfiguration.class);
+
+        // Check for the specific item ID instead of exact count to avoid 
flakiness from leftover configurations
+        keepTrying("Failed waiting for import configuration '" + itemId2 + "' 
to be available in getAll()", 
+                () -> importConfigurationService.getAll(),
+                (list) -> Objects.nonNull(list) && 
list.stream().anyMatch(config -> itemId2.equals(config.getItemId())), 
+                1000, 100);
 
         //Profile not to delete
         PartialList<Profile> aliveProfiles = 
profileService.findProfilesByPropertyValue("properties.alive", "true", 0, 50, 
null);
@@ -189,8 +203,15 @@ public class ProfileImportSurfersIT extends BaseIT {
                 () -> 
profileService.findProfilesByPropertyValue("properties.city", "surfersCity", 0, 
50, null),
                 (p) -> p.getTotalSize() == 0, 1000, 100);
 
-        keepTrying("Failed waiting for import configurations list with 1 
item", () -> importConfigurationService.getAll(),
-                (list) -> Objects.nonNull(list) && list.size() == 1, 1000, 
100);
+        // Refresh the persistence index to ensure the saved configuration is 
queryable in getAll()
+        // This addresses the flakiness where getAll() returns 0 items due to 
index refresh delay
+        persistenceService.refreshIndex(ImportConfiguration.class);
+
+        // Check for the specific item ID instead of exact count to avoid 
flakiness from leftover configurations
+        keepTrying("Failed waiting for import configuration '" + itemId3 + "' 
to be available in getAll()", 
+                () -> importConfigurationService.getAll(),
+                (list) -> Objects.nonNull(list) && 
list.stream().anyMatch(config -> itemId3.equals(config.getItemId())), 
+                1000, 100);
 
         PartialList<Profile> jordyProfileDelete = profileService
                 .findProfilesByPropertyValue("properties.email", 
"[email protected]", 0, 10, null);

Reply via email to