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

frankgh pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/cassandra-analytics.git


The following commit(s) were added to refs/heads/trunk by this push:
     new d949d8c  CASSANDRA-19275 Fix flaxy host replacement tests and shrink 
tests
d949d8c is described below

commit d949d8c2b9813c3e8429ece34c364a356bd7d6eb
Author: Francisco Guerrero <fran...@apache.org>
AuthorDate: Mon Jan 22 09:00:52 2024 -0800

    CASSANDRA-19275 Fix flaxy host replacement tests and shrink tests
    
    This patch fixes flaky tests when a `BindException` occurs during cluster 
provisioning.
    When a `BindException` is encountered, cluster provisioning is retried for 
up-to
    `MAX_CLUSTER_PROVISION_RETRIES`.
    
    Patch by Francisco Guerrero; Reviewed by Yifan Cai for CASSANDRA-19275
---
 .../testing/SharedClusterIntegrationTestBase.java  | 32 +++++++++++++++++++++-
 1 file changed, 31 insertions(+), 1 deletion(-)

diff --git 
a/cassandra-analytics-integration-framework/src/main/java/org/apache/cassandra/sidecar/testing/SharedClusterIntegrationTestBase.java
 
b/cassandra-analytics-integration-framework/src/main/java/org/apache/cassandra/sidecar/testing/SharedClusterIntegrationTestBase.java
index d306d65..cdc0708 100644
--- 
a/cassandra-analytics-integration-framework/src/main/java/org/apache/cassandra/sidecar/testing/SharedClusterIntegrationTestBase.java
+++ 
b/cassandra-analytics-integration-framework/src/main/java/org/apache/cassandra/sidecar/testing/SharedClusterIntegrationTestBase.java
@@ -20,6 +20,7 @@
 package org.apache.cassandra.sidecar.testing;
 
 import java.io.IOException;
+import java.net.BindException;
 import java.net.InetSocketAddress;
 import java.net.UnknownHostException;
 import java.nio.file.Path;
@@ -34,6 +35,7 @@ import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
 import java.util.stream.IntStream;
 
+import org.apache.commons.lang3.StringUtils;
 import org.junit.jupiter.api.AfterAll;
 import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.TestInstance;
@@ -77,6 +79,7 @@ import 
org.apache.cassandra.sidecar.utils.CassandraVersionProvider;
 import org.apache.cassandra.testing.TestUtils;
 import org.apache.cassandra.testing.TestVersion;
 import org.apache.cassandra.testing.TestVersionSupplier;
+import org.apache.cassandra.utils.Throwables;
 
 import static 
org.apache.cassandra.sidecar.testing.CassandraSidecarTestContext.tryGetIntConfig;
 import static org.assertj.core.api.Assertions.assertThat;
@@ -119,6 +122,7 @@ import static org.assertj.core.api.Assertions.assertThat;
 public abstract class SharedClusterIntegrationTestBase
 {
     protected final Logger logger = 
LoggerFactory.getLogger(SharedClusterIntegrationTestBase.class);
+    private static final int MAX_CLUSTER_PROVISION_RETRIES = 5;
 
     protected Vertx vertx;
     protected DnsResolver dnsResolver;
@@ -138,13 +142,39 @@ public abstract class SharedClusterIntegrationTestBase
         Optional<TestVersion> testVersion = 
TestVersionSupplier.testVersions().findFirst();
         assertThat(testVersion).isPresent();
         logger.info("Testing with version={}", testVersion);
-        cluster = provisionCluster(testVersion.get());
+        cluster = provisionClusterWithRetries(testVersion.get());
         assertThat(cluster).isNotNull();
         initializeSchemaForTest();
         startSidecar(cluster);
         beforeTestStart();
     }
 
+    protected AbstractCluster<? extends IInstance> 
provisionClusterWithRetries(TestVersion testVersion) throws IOException
+    {
+        for (int retry = 0; retry < MAX_CLUSTER_PROVISION_RETRIES; retry++)
+        {
+            try
+            {
+                return provisionCluster(testVersion);
+            }
+            catch (RuntimeException runtimeException)
+            {
+                boolean addressAlreadyInUse = 
Throwables.anyCauseMatches(runtimeException,
+                                                                         ex -> 
ex instanceof BindException &&
+                                                                               
StringUtils.contains(ex.getMessage(), "Address already in use"));
+                if (addressAlreadyInUse)
+                {
+                    logger.warn("Failed to provision cluster after {} 
retries", retry, runtimeException);
+                }
+                else
+                {
+                    throw runtimeException;
+                }
+            }
+        }
+        throw new RuntimeException("Unable to provision cluster");
+    }
+
     @AfterAll
     protected void tearDown() throws InterruptedException
     {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org
For additional commands, e-mail: commits-h...@cassandra.apache.org

Reply via email to