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 18
18
package com .datastax .oss .driver .api .testinfra .ccm ;
19
19
20
20
import java .util .concurrent .atomic .AtomicReference ;
21
+ import org .slf4j .Logger ;
22
+ import org .slf4j .LoggerFactory ;
21
23
22
24
/**
23
25
* A rule that creates a ccm cluster that can be used in a test. This should be used if you plan on
30
32
*/
31
33
public class CustomCcmRule extends BaseCcmRule {
32
34
35
+ private static final Logger LOG = LoggerFactory .getLogger (CustomCcmRule .class );
33
36
private static final AtomicReference <CustomCcmRule > CURRENT = new AtomicReference <>();
34
37
35
38
CustomCcmRule (CcmBridge ccmBridge ) {
@@ -39,7 +42,20 @@ public class CustomCcmRule extends BaseCcmRule {
39
42
@ Override
40
43
protected void before () {
41
44
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
+ }
43
59
} else if (CURRENT .get () != this ) {
44
60
throw new IllegalStateException (
45
61
"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