Skip to content

Commit 974d73f

Browse files
committed
tests: create every cluster with its own ip prefix
Sometimes test can fail to cleanup ccm cluster which will lead to failure of next tests if their IP addresses clashes. To avoid that let's spin every cluster on it's own prefix.
1 parent 8e2ee00 commit 974d73f

File tree

1 file changed

+11
-2
lines changed
  • test-infra/src/main/java/com/datastax/oss/driver/api/testinfra/ccm

1 file changed

+11
-2
lines changed

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import java.util.Optional;
4949
import java.util.concurrent.TimeUnit;
5050
import java.util.concurrent.atomic.AtomicBoolean;
51+
import java.util.concurrent.atomic.AtomicInteger;
5152
import java.util.stream.Collectors;
5253
import org.apache.commons.exec.CommandLine;
5354
import org.apache.commons.exec.DefaultExecutor;
@@ -62,6 +63,7 @@
6263
public class CcmBridge implements AutoCloseable {
6364

6465
private static final Logger LOG = LoggerFactory.getLogger(CcmBridge.class);
66+
private static final AtomicInteger CLUSTER_ID = new AtomicInteger();
6567

6668
public static BackendType DISTRIBUTION =
6769
BackendType.valueOf(
@@ -209,7 +211,14 @@ private CcmBridge(
209211
} else {
210212
this.nodes = nodes;
211213
}
212-
this.ipPrefix = ipPrefix;
214+
215+
if (ipPrefix == null || ipPrefix.isEmpty()) {
216+
Integer clusterId = CLUSTER_ID.addAndGet(1);
217+
this.ipPrefix = String.format("127.%d.%d.", clusterId / 255, (clusterId % 255) + 1);
218+
} else {
219+
this.ipPrefix = ipPrefix;
220+
}
221+
213222
this.cassandraConfiguration = cassandraConfiguration;
214223
this.dseConfiguration = dseConfiguration;
215224
this.rawDseYaml = dseConfigurationRawYaml;
@@ -665,7 +674,7 @@ public static class Builder {
665674
private final Map<String, Object> dseConfiguration = new LinkedHashMap<>();
666675
private final List<String> dseRawYaml = new ArrayList<>();
667676
private final List<String> jvmArgs = new ArrayList<>();
668-
private String ipPrefix = "127.0.0.";
677+
private String ipPrefix;
669678
private final List<String> createOptions = new ArrayList<>();
670679
private final List<String> dseWorkloads = new ArrayList<>();
671680

0 commit comments

Comments
 (0)