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

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

commit 8550aabb57931f9e5232111ce0033c2e261c1504
Author: Otavio Rodolfo Piske <angusyo...@gmail.com>
AuthorDate: Tue Aug 27 13:28:16 2024 +0200

    (chores) camel-infinispan: retry creating the cache to reduce flakiness
---
 .../remote/InfinispanRemoteTestSupport.java        | 39 +++++++++++++++++-----
 1 file changed, 31 insertions(+), 8 deletions(-)

diff --git 
a/components/camel-infinispan/camel-infinispan/src/test/java/org/apache/camel/component/infinispan/remote/InfinispanRemoteTestSupport.java
 
b/components/camel-infinispan/camel-infinispan/src/test/java/org/apache/camel/component/infinispan/remote/InfinispanRemoteTestSupport.java
index c26fb8f0a97..766f7139748 100644
--- 
a/components/camel-infinispan/camel-infinispan/src/test/java/org/apache/camel/component/infinispan/remote/InfinispanRemoteTestSupport.java
+++ 
b/components/camel-infinispan/camel-infinispan/src/test/java/org/apache/camel/component/infinispan/remote/InfinispanRemoteTestSupport.java
@@ -16,25 +16,33 @@
  */
 package org.apache.camel.component.infinispan.remote;
 
+import java.time.Duration;
 import java.util.Properties;
 
 import org.apache.camel.BindToRegistry;
 import org.apache.camel.component.infinispan.InfinispanTestSupport;
 import org.apache.camel.spi.ComponentCustomizer;
+import org.apache.camel.support.task.ForegroundTask;
+import org.apache.camel.support.task.Tasks;
+import org.apache.camel.support.task.budget.Budgets;
+import org.apache.camel.support.task.budget.IterationBoundedBudget;
 import org.apache.camel.test.infra.infinispan.services.InfinispanService;
 import 
org.apache.camel.test.infra.infinispan.services.InfinispanServiceFactory;
 import org.infinispan.client.hotrod.RemoteCacheManager;
 import org.infinispan.client.hotrod.configuration.ConfigurationBuilder;
 import org.infinispan.commons.api.BasicCache;
 import org.infinispan.configuration.cache.CacheMode;
+import org.junit.jupiter.api.Assumptions;
 import org.junit.jupiter.api.MethodOrderer;
 import org.junit.jupiter.api.TestMethodOrder;
 import org.junit.jupiter.api.extension.RegisterExtension;
+import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.testcontainers.shaded.org.apache.commons.lang3.SystemUtils;
 
 @TestMethodOrder(MethodOrderer.MethodName.class)
 public class InfinispanRemoteTestSupport extends InfinispanTestSupport {
+    private static final Logger LOG = 
LoggerFactory.getLogger(InfinispanRemoteTestSupport.class);
     @RegisterExtension
     public static InfinispanService service = 
InfinispanServiceFactory.createSingletonInfinispanService();
 
@@ -42,17 +50,32 @@ public class InfinispanRemoteTestSupport extends 
InfinispanTestSupport {
 
     @Override
     protected void setupResources() throws Exception {
-        LoggerFactory.getLogger(getClass()).info("setupResources");
+        super.setupResources();
 
         cacheContainer = new RemoteCacheManager(getConfiguration().build());
-        cacheContainer.administration()
-                .getOrCreateCache(
-                        getCacheName(),
-                        new 
org.infinispan.configuration.cache.ConfigurationBuilder()
-                                .clustering()
-                                .cacheMode(CacheMode.DIST_SYNC).build());
 
-        super.setupResources();
+        final IterationBoundedBudget budget
+                = 
Budgets.iterationBudget().withInterval(Duration.ofSeconds(1)).withMaxIterations(10).build();
+        final ForegroundTask task = Tasks.foregroundTask()
+                .withBudget(budget).build();
+
+        final boolean cacheCreated = task.run(this::createCache);
+        Assumptions.assumeTrue(cacheCreated, "The container cache is not 
running healthily");
+    }
+
+    private boolean createCache() {
+        try {
+            cacheContainer.administration()
+                    .getOrCreateCache(
+                            getCacheName(),
+                            new 
org.infinispan.configuration.cache.ConfigurationBuilder()
+                                    .clustering()
+                                    .cacheMode(CacheMode.DIST_SYNC).build());
+            return true;
+        } catch (Exception e) {
+            LOG.warn("Unable to create cache: {}", e.getMessage(), e);
+            return false;
+        }
     }
 
     @Override

Reply via email to