Skip to content

Commit 4200ef8

Browse files
authored
Fix IllegalState Attempting to use a Ccm error (#338)
If rule throw an exception on `before` it's `after` is not being executed. It needs to be respected in CustomCcmRule.
1 parent fe5d469 commit 4200ef8

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

test-infra/src/main/java/com/datastax/oss/driver/api/testinfra/ccm/CustomCcmRule.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,15 @@ public class CustomCcmRule extends BaseCcmRule {
3939
@Override
4040
protected void before() {
4141
if (CURRENT.get() == null && CURRENT.compareAndSet(null, this)) {
42-
super.before();
42+
try {
43+
super.before();
44+
} catch (Exception e) {
45+
// If exception is thrown in this rule, `after` is not going to be executed and test suit is
46+
// going to become broken
47+
// So we need to drop CURRENT to let other tests run
48+
CURRENT.set(null);
49+
throw e;
50+
}
4351
} else if (CURRENT.get() != this) {
4452
throw new IllegalStateException(
4553
"Attempting to use a Ccm rule while another is in use. This is disallowed");
@@ -48,8 +56,11 @@ protected void before() {
4856

4957
@Override
5058
protected void after() {
51-
super.after();
52-
CURRENT.compareAndSet(this, null);
59+
try {
60+
super.after();
61+
} finally {
62+
CURRENT.compareAndSet(this, null);
63+
}
5364
}
5465

5566
public CcmBridge getCcmBridge() {

0 commit comments

Comments
 (0)