You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by to...@apache.org on 2024/09/11 18:04:18 UTC

(cassandra-java-driver) branch 4.x updated: JAVA-3117: Call CcmCustomRule#after if CcmCustomRule#before fails to allow subsequent tests to run

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

tolbertam pushed a commit to branch 4.x
in repository https://gitbox.apache.org/repos/asf/cassandra-java-driver.git


The following commit(s) were added to refs/heads/4.x by this push:
     new c96101200 JAVA-3117: Call CcmCustomRule#after if CcmCustomRule#before fails to allow subsequent tests to run
c96101200 is described below

commit c961012000efffd3d50476d4549487f7fc538c01
Author: Henry Hughes <he...@datastax.com>
AuthorDate: Wed Aug 23 15:35:42 2023 -0700

    JAVA-3117: Call CcmCustomRule#after if CcmCustomRule#before fails to allow subsequent tests to run
    
    patch by Henry Hughes; reviewed by Alexandre Dutra and Andy Tolbert for JAVA-3117
---
 .../oss/driver/api/testinfra/ccm/CustomCcmRule.java    | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/test-infra/src/main/java/com/datastax/oss/driver/api/testinfra/ccm/CustomCcmRule.java b/test-infra/src/main/java/com/datastax/oss/driver/api/testinfra/ccm/CustomCcmRule.java
index 58bafd438..cf150b12f 100644
--- a/test-infra/src/main/java/com/datastax/oss/driver/api/testinfra/ccm/CustomCcmRule.java
+++ b/test-infra/src/main/java/com/datastax/oss/driver/api/testinfra/ccm/CustomCcmRule.java
@@ -18,6 +18,8 @@
 package com.datastax.oss.driver.api.testinfra.ccm;
 
 import java.util.concurrent.atomic.AtomicReference;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * A rule that creates a ccm cluster that can be used in a test. This should be used if you plan on
@@ -30,6 +32,7 @@ import java.util.concurrent.atomic.AtomicReference;
  */
 public class CustomCcmRule extends BaseCcmRule {
 
+  private static final Logger LOG = LoggerFactory.getLogger(CustomCcmRule.class);
   private static final AtomicReference<CustomCcmRule> CURRENT = new AtomicReference<>();
 
   CustomCcmRule(CcmBridge ccmBridge) {
@@ -39,7 +42,20 @@ public class CustomCcmRule extends BaseCcmRule {
   @Override
   protected void before() {
     if (CURRENT.get() == null && CURRENT.compareAndSet(null, this)) {
-      super.before();
+      try {
+        super.before();
+      } catch (Exception e) {
+        // ExternalResource will not call after() when before() throws an exception
+        // Let's try and clean up and release the lock we have in CURRENT
+        LOG.warn(
+            "Error in CustomCcmRule before() method, attempting to clean up leftover state", e);
+        try {
+          after();
+        } catch (Exception e1) {
+          LOG.warn("Error cleaning up CustomCcmRule before() failure", e1);
+        }
+        throw e;
+      }
     } else if (CURRENT.get() != this) {
       throw new IllegalStateException(
           "Attempting to use a Ccm rule while another is in use.  This is disallowed");


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