|
| 1 | +diff --git a/test-infra/src/main/java/com/datastax/oss/driver/api/testinfra/ccm/BaseCcmRule.java b/test-infra/src/main/java/com/datastax/oss/driver/api/testinfra/ccm/BaseCcmRule.java |
| 2 | +index 8537c89f8..6207e2df1 100644 |
| 3 | +--- a/test-infra/src/main/java/com/datastax/oss/driver/api/testinfra/ccm/BaseCcmRule.java |
| 4 | ++++ b/test-infra/src/main/java/com/datastax/oss/driver/api/testinfra/ccm/BaseCcmRule.java |
| 5 | +@@ -24,13 +24,18 @@ package com.datastax.oss.driver.api.testinfra.ccm; |
| 6 | + import com.datastax.oss.driver.api.core.DefaultProtocolVersion; |
| 7 | + import com.datastax.oss.driver.api.core.ProtocolVersion; |
| 8 | + import com.datastax.oss.driver.api.core.Version; |
| 9 | ++import com.datastax.oss.driver.api.core.metadata.EndPoint; |
| 10 | + import com.datastax.oss.driver.api.testinfra.*; |
| 11 | + import com.datastax.oss.driver.api.testinfra.CassandraResourceRule; |
| 12 | + import com.datastax.oss.driver.api.testinfra.requirement.BackendType; |
| 13 | + import com.datastax.oss.driver.api.testinfra.requirement.VersionRequirement; |
| 14 | ++import com.datastax.oss.driver.internal.core.metadata.DefaultEndPoint; |
| 15 | ++import java.net.InetSocketAddress; |
| 16 | ++import java.util.Collections; |
| 17 | + import java.util.Collection; |
| 18 | + import java.util.Objects; |
| 19 | + import java.util.Optional; |
| 20 | ++import java.util.Set; |
| 21 | + import org.junit.AssumptionViolatedException; |
| 22 | + import org.junit.runner.Description; |
| 23 | + import org.junit.runners.model.Statement; |
| 24 | +@@ -64,6 +69,13 @@ public abstract class BaseCcmRule extends CassandraResourceRule { |
| 25 | + ccmBridge.remove(); |
| 26 | + } |
| 27 | + |
| 28 | ++ @Override |
| 29 | ++ public Set<EndPoint> getContactPoints() { |
| 30 | ++ return Collections.singleton( |
| 31 | ++ new DefaultEndPoint( |
| 32 | ++ new InetSocketAddress(String.format("127.0.%s.1", ccmBridge.idPrefix), 9042))); |
| 33 | ++ } |
| 34 | ++ |
| 35 | + private Statement buildErrorStatement( |
| 36 | + Version requirement, String description, boolean lessThan, boolean dse) { |
| 37 | + return new Statement() { |
| 38 | +diff --git a/test-infra/src/main/java/com/datastax/oss/driver/api/testinfra/ccm/CcmBridge.java b/test-infra/src/main/java/com/datastax/oss/driver/api/testinfra/ccm/CcmBridge.java |
| 39 | +index 074dcb6c0..f69f083b1 100644 |
| 40 | +--- a/test-infra/src/main/java/com/datastax/oss/driver/api/testinfra/ccm/CcmBridge.java |
| 41 | ++++ b/test-infra/src/main/java/com/datastax/oss/driver/api/testinfra/ccm/CcmBridge.java |
| 42 | +@@ -62,6 +62,10 @@ public class CcmBridge implements AutoCloseable { |
| 43 | + public static final Version VERSION = |
| 44 | + Objects.requireNonNull(Version.parse(System.getProperty("ccm.version", "4.0.0"))); |
| 45 | + |
| 46 | ++ public String idPrefix = "0"; |
| 47 | ++ |
| 48 | ++ public static final String SCYLLA_VERSION = System.getProperty("scylla.version"); |
| 49 | ++ |
| 50 | + public static final String INSTALL_DIRECTORY = System.getProperty("ccm.directory"); |
| 51 | + |
| 52 | + public static final String BRANCH = System.getProperty("ccm.branch"); |
| 53 | +@@ -171,7 +175,6 @@ public class CcmBridge implements AutoCloseable { |
| 54 | + private final Path configDirectory; |
| 55 | + private final AtomicBoolean started = new AtomicBoolean(); |
| 56 | + private final AtomicBoolean created = new AtomicBoolean(); |
| 57 | +- private final String ipPrefix; |
| 58 | + private final Map<String, Object> cassandraConfiguration; |
| 59 | + private final Map<String, Object> dseConfiguration; |
| 60 | + private final List<String> rawDseYaml; |
| 61 | +@@ -182,7 +185,7 @@ public class CcmBridge implements AutoCloseable { |
| 62 | + private CcmBridge( |
| 63 | + Path configDirectory, |
| 64 | + int[] nodes, |
| 65 | +- String ipPrefix, |
| 66 | ++ String idPrefix, |
| 67 | + Map<String, Object> cassandraConfiguration, |
| 68 | + Map<String, Object> dseConfiguration, |
| 69 | + List<String> dseConfigurationRawYaml, |
| 70 | +@@ -198,7 +201,7 @@ public class CcmBridge implements AutoCloseable { |
| 71 | + } else { |
| 72 | + this.nodes = nodes; |
| 73 | + } |
| 74 | +- this.ipPrefix = ipPrefix; |
| 75 | ++ this.idPrefix = idPrefix; |
| 76 | + this.cassandraConfiguration = cassandraConfiguration; |
| 77 | + this.dseConfiguration = dseConfiguration; |
| 78 | + this.rawDseYaml = dseConfigurationRawYaml; |
| 79 | +@@ -262,41 +265,6 @@ public class CcmBridge implements AutoCloseable { |
| 80 | + } |
| 81 | + } |
| 82 | + |
| 83 | +- private String getCcmVersionString(Version version) { |
| 84 | +- if (SCYLLA_ENABLEMENT) { |
| 85 | +- // Scylla OSS versions before 5.1 had RC versioning scheme of 5.0.rc3. |
| 86 | +- // Scylla OSS versions after (and including 5.1) have RC versioning of 5.1.0-rc3. |
| 87 | +- // A similar situation occurs with Scylla Enterprise after 2022.2. |
| 88 | +- // |
| 89 | +- // CcmBridge parses the version numbers to a newer format (5.1.0-rc3), so a replacement |
| 90 | +- // must be performed for older Scylla version numbers. |
| 91 | +- String versionString = version.toString(); |
| 92 | +- |
| 93 | +- boolean shouldReplace = |
| 94 | +- (SCYLLA_ENTERPRISE && version.compareTo(Version.parse("2022.2.0-rc0")) < 0) |
| 95 | +- || (!SCYLLA_ENTERPRISE && version.compareTo(Version.parse("5.1.0-rc0")) < 0); |
| 96 | +- if (shouldReplace) { |
| 97 | +- versionString = versionString.replace(".0-", "."); |
| 98 | +- } |
| 99 | +- return "release:" + versionString; |
| 100 | +- } |
| 101 | +- // for 4.0 pre-releases, the CCM version string needs to be "4.0-alpha1" or "4.0-alpha2" |
| 102 | +- // Version.toString() always adds a patch value, even if it's not specified when parsing. |
| 103 | +- if (version.getMajor() == 4 |
| 104 | +- && version.getMinor() == 0 |
| 105 | +- && version.getPatch() == 0 |
| 106 | +- && version.getPreReleaseLabels() != null) { |
| 107 | +- // truncate the patch version from the Version string |
| 108 | +- StringBuilder sb = new StringBuilder(); |
| 109 | +- sb.append(version.getMajor()).append('.').append(version.getMinor()); |
| 110 | +- for (String preReleaseString : version.getPreReleaseLabels()) { |
| 111 | +- sb.append('-').append(preReleaseString); |
| 112 | +- } |
| 113 | +- return sb.toString(); |
| 114 | +- } |
| 115 | +- return version.toString(); |
| 116 | +- } |
| 117 | +- |
| 118 | + public void create() { |
| 119 | + if (created.compareAndSet(false, true)) { |
| 120 | + if (INSTALL_DIRECTORY != null) { |
| 121 | +@@ -305,7 +273,7 @@ public class CcmBridge implements AutoCloseable { |
| 122 | + createOptions.add("-v git:" + BRANCH.trim().replaceAll("\"", "")); |
| 123 | + |
| 124 | + } else { |
| 125 | +- createOptions.add("-v " + getCcmVersionString(VERSION)); |
| 126 | ++ createOptions.add("-v " + SCYLLA_VERSION); |
| 127 | + } |
| 128 | + if (DSE_ENABLEMENT) { |
| 129 | + createOptions.add("--dse"); |
| 130 | +@@ -316,8 +284,8 @@ public class CcmBridge implements AutoCloseable { |
| 131 | + execute( |
| 132 | + "create", |
| 133 | + CLUSTER_NAME, |
| 134 | +- "-i", |
| 135 | +- ipPrefix, |
| 136 | ++ "--id", |
| 137 | ++ idPrefix, |
| 138 | + "-n", |
| 139 | + Arrays.stream(nodes).mapToObj(n -> "" + n).collect(Collectors.joining(":")), |
| 140 | + createOptions.stream().collect(Collectors.joining(" "))); |
| 141 | +@@ -417,9 +385,9 @@ public class CcmBridge implements AutoCloseable { |
| 142 | + |
| 143 | + public void add(int n, String dc) { |
| 144 | + if (getDseVersion().isPresent()) { |
| 145 | +- execute("add", "-i", ipPrefix + n, "-d", dc, "node" + n, "--dse"); |
| 146 | ++ execute("add", "-d", dc, "node" + n, "--dse"); |
| 147 | + } else { |
| 148 | +- execute("add", "-i", ipPrefix + n, "-d", dc, "node" + n); |
| 149 | ++ execute("add", "-d", dc, "node" + n); |
| 150 | + } |
| 151 | + start(n); |
| 152 | + } |
| 153 | +@@ -525,7 +493,7 @@ public class CcmBridge implements AutoCloseable { |
| 154 | + private final Map<String, Object> dseConfiguration = new LinkedHashMap<>(); |
| 155 | + private final List<String> dseRawYaml = new ArrayList<>(); |
| 156 | + private final List<String> jvmArgs = new ArrayList<>(); |
| 157 | +- private String ipPrefix = "127.0.0."; |
| 158 | ++ private String idPrefix = "0"; |
| 159 | + private final List<String> createOptions = new ArrayList<>(); |
| 160 | + private final List<String> dseWorkloads = new ArrayList<>(); |
| 161 | + |
| 162 | +@@ -569,8 +537,8 @@ public class CcmBridge implements AutoCloseable { |
| 163 | + return this; |
| 164 | + } |
| 165 | + |
| 166 | +- public Builder withIpPrefix(String ipPrefix) { |
| 167 | +- this.ipPrefix = ipPrefix; |
| 168 | ++ public Builder withIdPrefix(String idPrefix) { |
| 169 | ++ this.idPrefix = idPrefix; |
| 170 | + return this; |
| 171 | + } |
| 172 | + |
| 173 | +@@ -639,7 +607,7 @@ public class CcmBridge implements AutoCloseable { |
| 174 | + return new CcmBridge( |
| 175 | + configDirectory, |
| 176 | + nodes, |
| 177 | +- ipPrefix, |
| 178 | ++ idPrefix, |
| 179 | + cassandraConfiguration, |
| 180 | + dseConfiguration, |
| 181 | + dseRawYaml, |
| 182 | +diff --git a/test-infra/src/main/java/com/datastax/oss/driver/api/testinfra/ccm/CustomCcmRule.java b/test-infra/src/main/java/com/datastax/oss/driver/api/testinfra/ccm/CustomCcmRule.java |
| 183 | +index 4ea1b3843..45029cc10 100644 |
| 184 | +--- a/test-infra/src/main/java/com/datastax/oss/driver/api/testinfra/ccm/CustomCcmRule.java |
| 185 | ++++ b/test-infra/src/main/java/com/datastax/oss/driver/api/testinfra/ccm/CustomCcmRule.java |
| 186 | +@@ -15,6 +15,7 @@ |
| 187 | + */ |
| 188 | + package com.datastax.oss.driver.api.testinfra.ccm; |
| 189 | + |
| 190 | ++import java.util.concurrent.atomic.AtomicInteger; |
| 191 | + import java.util.concurrent.atomic.AtomicReference; |
| 192 | + |
| 193 | + /** |
| 194 | +@@ -30,6 +31,8 @@ public class CustomCcmRule extends BaseCcmRule { |
| 195 | + |
| 196 | + private static final AtomicReference<CustomCcmRule> CURRENT = new AtomicReference<>(); |
| 197 | + |
| 198 | ++ private static AtomicInteger cluster_id = new AtomicInteger(1); |
| 199 | ++ |
| 200 | + CustomCcmRule(CcmBridge ccmBridge) { |
| 201 | + super(ccmBridge); |
| 202 | + } |
| 203 | +@@ -62,6 +65,10 @@ public class CustomCcmRule extends BaseCcmRule { |
| 204 | + |
| 205 | + private final CcmBridge.Builder bridgeBuilder = CcmBridge.builder(); |
| 206 | + |
| 207 | ++ public Builder() { |
| 208 | ++ this.withIdPrefix(Integer.toString(cluster_id.incrementAndGet())); |
| 209 | ++ } |
| 210 | ++ |
| 211 | + public Builder withNodes(int... nodes) { |
| 212 | + bridgeBuilder.withNodes(nodes); |
| 213 | + return this; |
| 214 | +@@ -112,6 +119,11 @@ public class CustomCcmRule extends BaseCcmRule { |
| 215 | + return this; |
| 216 | + } |
| 217 | + |
| 218 | ++ public Builder withIdPrefix(String idPrefix) { |
| 219 | ++ bridgeBuilder.withIdPrefix(idPrefix); |
| 220 | ++ return this; |
| 221 | ++ } |
| 222 | ++ |
| 223 | + public CustomCcmRule build() { |
| 224 | + return new CustomCcmRule(bridgeBuilder.build()); |
| 225 | + } |
0 commit comments