Skip to content

Commit 6b7dd23

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 6b7dd23

File tree

3 files changed

+34
-23
lines changed

3 files changed

+34
-23
lines changed

integration-tests/src/test/java/com/datastax/oss/driver/core/pool/AdvancedShardAwarenessIT.java

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -94,17 +94,13 @@ public void stopCapturingLogs() {
9494
public void should_initialize_all_channels(boolean reuseAddress) {
9595
Map<Pattern, Integer> expectedOccurences =
9696
ImmutableMap.of(
97-
Pattern.compile(
98-
".*127\\.0\\.0\\.2:19042.*Reconnection attempt complete, 6/6 channels.*"),
99-
1,
100-
Pattern.compile(
101-
".*127\\.0\\.0\\.1:19042.*Reconnection attempt complete, 6/6 channels.*"),
102-
1,
97+
Pattern.compile(".*\\.2:19042.*Reconnection attempt complete, 6/6 channels.*"), 1,
98+
Pattern.compile(".*\\.1:19042.*Reconnection attempt complete, 6/6 channels.*"), 1,
10399
Pattern.compile(".*Reconnection attempt complete.*"), 2,
104-
Pattern.compile(".*127\\.0\\.0\\.1:19042.*New channel added \\[.*"), 5,
105-
Pattern.compile(".*127\\.0\\.0\\.2:19042.*New channel added \\[.*"), 5,
106-
Pattern.compile(".*127\\.0\\.0\\.1:19042\\] Trying to create 5 missing channels.*"), 1,
107-
Pattern.compile(".*127\\.0\\.0\\.2:19042\\] Trying to create 5 missing channels.*"), 1);
100+
Pattern.compile(".*\\.1:19042.*New channel added \\[.*"), 5,
101+
Pattern.compile(".*\\.2:19042.*New channel added \\[.*"), 5,
102+
Pattern.compile(".*\\.1:19042\\] Trying to create 5 missing channels.*"), 1,
103+
Pattern.compile(".*\\.2:19042\\] Trying to create 5 missing channels.*"), 1);
108104
DriverConfigLoader loader =
109105
SessionUtils.configLoaderBuilder()
110106
.withBoolean(DefaultDriverOption.SOCKET_REUSE_ADDRESS, reuseAddress)
@@ -204,20 +200,15 @@ public void should_not_struggle_to_fill_pools() {
204200
int tolerance = 2; // Sometimes socket ends up already in use
205201
Map<Pattern, Integer> expectedOccurences =
206202
ImmutableMap.of(
207-
Pattern.compile(
208-
".*127\\.0\\.0\\.2:19042.*Reconnection attempt complete, 66/66 channels.*"),
203+
Pattern.compile(".*\\.2:19042.*Reconnection attempt complete, 66/66 channels.*"),
209204
1 * sessions,
210-
Pattern.compile(
211-
".*127\\.0\\.0\\.1:19042.*Reconnection attempt complete, 66/66 channels.*"),
205+
Pattern.compile(".*\\.1:19042.*Reconnection attempt complete, 66/66 channels.*"),
212206
1 * sessions,
213207
Pattern.compile(".*Reconnection attempt complete.*"), 2 * sessions,
214-
Pattern.compile(".*127\\.0\\.0\\.1:19042.*New channel added \\[.*"),
215-
65 * sessions - tolerance,
216-
Pattern.compile(".*127\\.0\\.0\\.2:19042.*New channel added \\[.*"),
217-
65 * sessions - tolerance,
218-
Pattern.compile(".*127\\.0\\.0\\.1:19042\\] Trying to create 65 missing channels.*"),
219-
1 * sessions,
220-
Pattern.compile(".*127\\.0\\.0\\.2:19042\\] Trying to create 65 missing channels.*"),
208+
Pattern.compile(".*.1:19042.*New channel added \\[.*"), 65 * sessions - tolerance,
209+
Pattern.compile(".*.2:19042.*New channel added \\[.*"), 65 * sessions - tolerance,
210+
Pattern.compile(".*.1:19042\\] Trying to create 65 missing channels.*"), 1 * sessions,
211+
Pattern.compile(".*.2:19042\\] Trying to create 65 missing channels.*"),
221212
1 * sessions);
222213
expectedOccurences.forEach(
223214
(pattern, times) -> assertMatchesAtLeast(pattern, times, appender.list));

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,19 @@
2626
import com.datastax.oss.driver.api.core.DefaultProtocolVersion;
2727
import com.datastax.oss.driver.api.core.ProtocolVersion;
2828
import com.datastax.oss.driver.api.core.Version;
29+
import com.datastax.oss.driver.api.core.metadata.EndPoint;
2930
import com.datastax.oss.driver.api.testinfra.CassandraResourceRule;
3031
import com.datastax.oss.driver.api.testinfra.CassandraSkip;
3132
import com.datastax.oss.driver.api.testinfra.ScyllaRequirement;
3233
import com.datastax.oss.driver.api.testinfra.ScyllaSkip;
3334
import com.datastax.oss.driver.api.testinfra.requirement.BackendRequirementRule;
3435
import com.datastax.oss.driver.api.testinfra.requirement.BackendType;
36+
import com.datastax.oss.driver.internal.core.metadata.DefaultEndPoint;
37+
import java.net.InetSocketAddress;
38+
import java.util.Collections;
3539
import java.util.Objects;
3640
import java.util.Optional;
41+
import java.util.Set;
3742
import org.junit.AssumptionViolatedException;
3843
import org.junit.runner.Description;
3944
import org.junit.runners.model.Statement;
@@ -211,4 +216,10 @@ public ProtocolVersion getHighestProtocolVersion() {
211216
return DefaultProtocolVersion.V3;
212217
}
213218
}
219+
220+
@Override
221+
public Set<EndPoint> getContactPoints() {
222+
return Collections.singleton(
223+
new DefaultEndPoint(new InetSocketAddress(ccmBridge.getNodeIpAddress(1), 9042)));
224+
}
214225
}

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)