File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed
test-infra/src/main/java/com/datastax/oss/driver/api/testinfra/ccm Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change 1818package com .datastax .oss .driver .api .testinfra .ccm ;
1919
2020import java .util .concurrent .atomic .AtomicReference ;
21+ import org .slf4j .Logger ;
22+ import org .slf4j .LoggerFactory ;
2123
2224/**
2325 * A rule that creates a ccm cluster that can be used in a test. This should be used if you plan on
3032 */
3133public class CustomCcmRule extends BaseCcmRule {
3234
35+ private static final Logger LOG = LoggerFactory .getLogger (CustomCcmRule .class );
3336 private static final AtomicReference <CustomCcmRule > CURRENT = new AtomicReference <>();
3437
3538 CustomCcmRule (CcmBridge ccmBridge ) {
@@ -39,7 +42,20 @@ public class CustomCcmRule extends BaseCcmRule {
3942 @ Override
4043 protected void before () {
4144 if (CURRENT .get () == null && CURRENT .compareAndSet (null , this )) {
42- super .before ();
45+ try {
46+ super .before ();
47+ } catch (Exception e ) {
48+ // ExternalResource will not call after() when before() throws an exception
49+ // Let's try and clean up and release the lock we have in CURRENT
50+ LOG .warn (
51+ "Error in CustomCcmRule before() method, attempting to clean up leftover state" , e );
52+ try {
53+ after ();
54+ } catch (Exception e1 ) {
55+ LOG .warn ("Error cleaning up CustomCcmRule before() failure" , e1 );
56+ }
57+ throw e ;
58+ }
4359 } else if (CURRENT .get () != this ) {
4460 throw new IllegalStateException (
4561 "Attempting to use a Ccm rule while another is in use. This is disallowed" );
You can’t perform that action at this time.
0 commit comments