kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 446aa287b841361baefe105f672198a0a66d3d98e3c270b33cb756a08be0f6a7 |
|---|---|
| Author | Alexandre Dutra <adutra@users.noreply.github.com> · 2016-01-16 16:23 +01:00 |
| Committer | Alexandre Dutra <adutra@users.noreply.github.com> · 2016-01-16 16:23 +01:00 |
| Parents | 5ce316cb6b8b, b4e947eab72f |
38 files changed
added driver-core/src/test/java/com/datastax/driver/core/CCMAccess.java +219 −0
| @@ -0,0 +1,219 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (C) 2012-2015 DataStax Inc. | |
| 3 | + * | |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | + * you may not use this file except in compliance with the License. | |
| 6 | + * You may obtain a copy of the License at | |
| 7 | + * | |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | + * | |
| 10 | + * Unless required by applicable law or agreed to in writing, software | |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | + * See the License for the specific language governing permissions and | |
| 14 | + * limitations under the License. | |
| 15 | + */ | |
| 16 | +package com.datastax.driver.core; | |
| 17 | + | |
| 18 | +import java.io.Closeable; | |
| 19 | +import java.io.File; | |
| 20 | +import java.net.InetSocketAddress; | |
| 21 | +import java.util.Map; | |
| 22 | + | |
| 23 | +public interface CCMAccess extends Closeable { | |
| 24 | + | |
| 25 | + // Inspection methods | |
| 26 | + | |
| 27 | + /** | |
| 28 | + * @return The CCM cluster name. | |
| 29 | + */ | |
| 30 | + String getClusterName(); | |
| 31 | + | |
| 32 | + /** | |
| 33 | + * Returns the Cassandra version of this CCM cluster. | |
| 34 | + * <p/> | |
| 35 | + * By default the version is equal to {@link CCMBridge#getCassandraVersion()}. | |
| 36 | + * | |
| 37 | + * @return The version of this CCM cluster. | |
| 38 | + */ | |
| 39 | + VersionNumber getVersion(); | |
| 40 | + | |
| 41 | + /** | |
| 42 | + * @return The config directory for this CCM cluster. | |
| 43 | + */ | |
| 44 | + File getCcmDir(); | |
| 45 | + | |
| 46 | + /** | |
| 47 | + * @return The cluster directory for this CCM cluster. | |
| 48 | + */ | |
| 49 | + File getClusterDir(); | |
| 50 | + | |
| 51 | + /** | |
| 52 | + * @param n the node number, starting with 1. | |
| 53 | + * @return The node directory for this CCM cluster. | |
| 54 | + */ | |
| 55 | + File getNodeDir(int n); | |
| 56 | + | |
| 57 | + /** | |
| 58 | + * @param n the node number, starting with 1. | |
| 59 | + * @return The node config directory for this CCM cluster. | |
| 60 | + */ | |
| 61 | + File getNodeConfDir(int n); | |
| 62 | + | |
| 63 | + /** | |
| 64 | + * @return The storage port for this CCM cluster. | |
| 65 | + */ | |
| 66 | + int getStoragePort(); | |
| 67 | + | |
| 68 | + /** | |
| 69 | + * @return The thrift port for this CCM cluster. | |
| 70 | + */ | |
| 71 | + int getThriftPort(); | |
| 72 | + | |
| 73 | + /** | |
| 74 | + * @return The binary port for this CCM cluster. | |
| 75 | + */ | |
| 76 | + int getBinaryPort(); | |
| 77 | + | |
| 78 | + /** | |
| 79 | + * Signals that logs for this CCM cluster should be kept after the cluster is stopped. | |
| 80 | + */ | |
| 81 | + void setKeepLogs(boolean keepLogs); | |
| 82 | + | |
| 83 | + /** | |
| 84 | + * Returns the address of the {@code nth} host in the CCM cluster (counting from 1, i.e., | |
| 85 | + * {@code addressOfNode(1)} returns the address of the first node. | |
| 86 | + * <p/> | |
| 87 | + * In multi-DC setups, nodes are numbered in ascending order of their datacenter number. | |
| 88 | + * E.g. with 2 DCs and 3 nodes in each DC, the first node in DC 2 is number 4. | |
| 89 | + * | |
| 90 | + * @return the address of the {@code nth} host in the cluster. | |
| 91 | + */ | |
| 92 | + InetSocketAddress addressOfNode(int n); | |
| 93 | + | |
| 94 | + | |
| 95 | + // Methods altering the whole cluster | |
| 96 | + | |
| 97 | + /** | |
| 98 | + * Starts the cluster. | |
| 99 | + */ | |
| 100 | + void start(); | |
| 101 | + | |
| 102 | + /** | |
| 103 | + * Stops the cluster. | |
| 104 | + */ | |
| 105 | + void stop(); | |
| 106 | + | |
| 107 | + /** | |
| 108 | + * Aggressively stops the cluster. | |
| 109 | + */ | |
| 110 | + void forceStop(); | |
| 111 | + | |
| 112 | + /** | |
| 113 | + * Alias for {@link #stop()}. | |
| 114 | + */ | |
| 115 | + @Override | |
| 116 | + void close(); | |
| 117 | + | |
| 118 | + /** | |
| 119 | + * Removes this CCM cluster and deletes all of its files. | |
| 120 | + */ | |
| 121 | + void remove(); | |
| 122 | + | |
| 123 | + /** | |
| 124 | + * Updates the config files for all nodes in the CCM cluster. | |
| 125 | + */ | |
| 126 | + void updateConfig(Map<String, Object> configs); | |
| 127 | + | |
| 128 | + /** | |
| 129 | + * Updates the DSE config files for all nodes in the CCM cluster. | |
| 130 | + */ | |
| 131 | + void updateDSEConfig(Map<String, Object> configs); | |
| 132 | + | |
| 133 | + | |
| 134 | + // Methods altering nodes | |
| 135 | + | |
| 136 | + /** | |
| 137 | + * Starts the {@code nth} host in the CCM cluster. | |
| 138 | + * | |
| 139 | + * @param n the node number (starting from 1). | |
| 140 | + */ | |
| 141 | + void start(int n); | |
| 142 | + | |
| 143 | + /** | |
| 144 | + * Stops the {@code nth} host in the CCM cluster. | |
| 145 | + * | |
| 146 | + * @param n the node number (starting from 1). | |
| 147 | + */ | |
| 148 | + void stop(int n); | |
| 149 | + | |
| 150 | + /** | |
| 151 | + * Aggressively stops the {@code nth} host in the CCM cluster. | |
| 152 | + * | |
| 153 | + * @param n the node number (starting from 1). | |
| 154 | + */ | |
| 155 | + void forceStop(int n); | |
| 156 | + | |
| 157 | + /** | |
| 158 | + * Removes the {@code nth} host in the CCM cluster. | |
| 159 | + * | |
| 160 | + * @param n the node number (starting from 1). | |
| 161 | + */ | |
| 162 | + void remove(int n); | |
| 163 | + | |
| 164 | + /** | |
| 165 | + * Adds the {@code nth} host in the CCM cluster. | |
| 166 | + * | |
| 167 | + * @param n the node number (starting from 1). | |
| 168 | + */ | |
| 169 | + void add(int n); | |
| 170 | + | |
| 171 | + /** | |
| 172 | + * Adds the {@code nth} host in the CCM cluster. | |
| 173 | + * | |
| 174 | + * @param n the node number (starting from 1). | |
| 175 | + */ | |
| 176 | + void add(int dc, int n); | |
| 177 | + | |
| 178 | + /** | |
| 179 | + * Decommissions the {@code nth} host in the CCM cluster. | |
| 180 | + * | |
| 181 | + * @param n the node number (starting from 1). | |
| 182 | + */ | |
| 183 | + void decommision(int n); | |
| 184 | + | |
| 185 | + /** | |
| 186 | + * Updates the {@code nth} host's config file in the CCM cluster. | |
| 187 | + * | |
| 188 | + * @param n the node number (starting from 1). | |
| 189 | + */ | |
| 190 | + void updateNodeConfig(int n, String key, Object value); | |
| 191 | + | |
| 192 | + /** | |
| 193 | + * Updates the {@code nth} host's config file in the CCM cluster. | |
| 194 | + * | |
| 195 | + * @param n the node number (starting from 1). | |
| 196 | + */ | |
| 197 | + void updateNodeConfig(int n, Map<String, Object> configs); | |
| 198 | + | |
| 199 | + /** | |
| 200 | + * Sets the workload for the {@code nth} host in the CCM cluster. | |
| 201 | + * | |
| 202 | + * @param n the node number (starting from 1). | |
| 203 | + */ | |
| 204 | + void setWorkload(int n, String workload); | |
| 205 | + | |
| 206 | + | |
| 207 | + // Methods blocking until nodes are up or down | |
| 208 | + | |
| 209 | + /** | |
| 210 | + * Waits for a host to be up by pinging the TCP socket directly, without using the Java driver's API. | |
| 211 | + */ | |
| 212 | + void waitForUp(int node); | |
| 213 | + | |
| 214 | + /** | |
| 215 | + * Waits for a host to be down by pinging the TCP socket directly, without using the Java driver's API. | |
| 216 | + */ | |
| 217 | + void waitForDown(int node); | |
| 218 | + | |
| 219 | +} |
modified driver-core/src/test/java/com/datastax/driver/core/CCMBridge.java +70 −83
| @@ -15,10 +15,10 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import com.datastax.driver.core.policies.AddressTranslater; | |
| 19 | 18 | import com.google.common.base.Joiner; |
| 20 | 19 | import com.google.common.base.Throwables; |
| 21 | 20 | import com.google.common.collect.ImmutableMap; |
| 21 | +import com.google.common.collect.ImmutableSet; | |
| 22 | 22 | import com.google.common.collect.Maps; |
| 23 | 23 | import com.google.common.io.ByteStreams; |
| 24 | 24 | import com.google.common.io.Closer; |
| @@ -35,13 +35,13 @@ | ||
| 35 | 35 | import static com.datastax.driver.core.TestUtils.executeNoFail; |
| 36 | 36 | import static com.datastax.driver.core.TestUtils.findAvailablePort; |
| 37 | 37 | |
| 38 | -public class CCMBridge implements Closeable { | |
| 38 | +public class CCMBridge implements CCMAccess { | |
| 39 | 39 | |
| 40 | 40 | private static final Logger logger = LoggerFactory.getLogger(CCMBridge.class); |
| 41 | 41 | |
| 42 | 42 | private static final String CASSANDRA_VERSION; |
| 43 | 43 | |
| 44 | - private static final String CASSANDRA_INSTALL_ARGS; | |
| 44 | + private static final Set<String> CASSANDRA_INSTALL_ARGS; | |
| 45 | 45 | |
| 46 | 46 | private static final boolean IS_DSE; |
| 47 | 47 | |
| @@ -133,23 +133,20 @@ | ||
| 133 | 133 | // otherwise if there is a value, parse as boolean. |
| 134 | 134 | IS_DSE = dseProperty != null && (dseProperty.isEmpty() || Boolean.parseBoolean(dseProperty)); |
| 135 | 135 | |
| 136 | - StringBuilder installArgs = new StringBuilder(); | |
| 136 | + ImmutableSet.Builder<String> installArgs = ImmutableSet.builder(); | |
| 137 | 137 | if (installDirectory != null && !installDirectory.trim().isEmpty()) { |
| 138 | - installArgs.append("--install-dir="); | |
| 139 | - installArgs.append(new File(installDirectory).getAbsolutePath()); | |
| 138 | + installArgs.add("--install-dir=" + new File(installDirectory).getAbsolutePath()); | |
| 140 | 139 | } else if (branch != null && !branch.trim().isEmpty()) { |
| 141 | - installArgs.append("-v git:"); | |
| 142 | - installArgs.append(branch.trim().replaceAll("\"", "")); | |
| 140 | + installArgs.add("-v git:" + branch.trim().replaceAll("\"", "")); | |
| 143 | 141 | } else { |
| 144 | - installArgs.append("-v "); | |
| 145 | - installArgs.append(CASSANDRA_VERSION); | |
| 142 | + installArgs.add("-v " + CASSANDRA_VERSION); | |
| 146 | 143 | } |
| 147 | 144 | |
| 148 | 145 | if (IS_DSE) { |
| 149 | - installArgs.append(" --dse"); | |
| 146 | + installArgs.add("--dse"); | |
| 150 | 147 | } |
| 151 | 148 | |
| 152 | - CASSANDRA_INSTALL_ARGS = installArgs.toString(); | |
| 149 | + CASSANDRA_INSTALL_ARGS = installArgs.build(); | |
| 153 | 150 | |
| 154 | 151 | // Inherit the current environment. |
| 155 | 152 | Map<String, String> envMap = Maps.newHashMap(new ProcessBuilder().environment()); |
| @@ -177,10 +174,10 @@ | ||
| 177 | 174 | ENVIRONMENT_MAP = ImmutableMap.copyOf(envMap); |
| 178 | 175 | |
| 179 | 176 | if (CCMBridge.isDSE()) { |
| 180 | - logger.info("Tests requiring CCM will use DSE version {} (C* {}, install arguments: {})", | |
| 177 | + logger.info("Tests requiring CCM will by default use DSE version {} (C* {}, install arguments: {})", | |
| 181 | 178 | CCMBridge.getDSEVersion(), CCMBridge.getCassandraVersion(), CCMBridge.getInstallArguments()); |
| 182 | 179 | } else { |
| 183 | - logger.info("Tests requiring CCM will use Cassandra version {} (install arguments: {})", | |
| 180 | + logger.info("Tests requiring CCM will by default use Cassandra version {} (install arguments: {})", | |
| 184 | 181 | CCMBridge.getCassandraVersion(), CCMBridge.getInstallArguments()); |
| 185 | 182 | } |
| 186 | 183 | } |
| @@ -212,13 +209,11 @@ | ||
| 212 | 209 | |
| 213 | 210 | private final String jvmArgs; |
| 214 | 211 | |
| 215 | - private final int initialNumberOfNodes; | |
| 216 | - | |
| 217 | 212 | private boolean keepLogs = false; |
| 218 | 213 | |
| 219 | 214 | private boolean closed = false; |
| 220 | 215 | |
| 221 | - private CCMBridge(String clusterName, boolean isDSE, VersionNumber version, int storagePort, int thriftPort, int binaryPort, String jvmArgs, int initialNumberOfNodes) { | |
| 216 | + private CCMBridge(String clusterName, boolean isDSE, VersionNumber version, int storagePort, int thriftPort, int binaryPort, String jvmArgs) { | |
| 222 | 217 | this.clusterName = clusterName; |
| 223 | 218 | this.version = version; |
| 224 | 219 | this.storagePort = storagePort; |
| @@ -226,7 +221,6 @@ | ||
| 226 | 221 | this.binaryPort = binaryPort; |
| 227 | 222 | this.isDSE = isDSE; |
| 228 | 223 | this.jvmArgs = jvmArgs; |
| 229 | - this.initialNumberOfNodes = initialNumberOfNodes; | |
| 230 | 224 | this.ccmDir = Files.createTempDir(); |
| 231 | 225 | } |
| 232 | 226 | |
| @@ -283,7 +277,7 @@ | ||
| 283 | 277 | /** |
| 284 | 278 | * @return The install arguments to pass to CCM when creating the cluster. |
| 285 | 279 | */ |
| 286 | - public static String getInstallArguments() { | |
| 280 | + public static Set<String> getInstallArguments() { | |
| 287 | 281 | return CASSANDRA_INSTALL_ARGS; |
| 288 | 282 | } |
| 289 | 283 | |
| @@ -291,87 +285,57 @@ | ||
| 291 | 285 | return new Builder(); |
| 292 | 286 | } |
| 293 | 287 | |
| 294 | - /** | |
| 295 | - * Returns the address of the {@code nth} host in the CCM cluster (counting from 1, i.e., | |
| 296 | - * {@code getHostAddress(1)} returns the address of the first node. | |
| 297 | - * <p/> | |
| 298 | - * In multi-DC setups, nodes are numbered in ascending order of their datacenter number. | |
| 299 | - * E.g. with 2 DCs and 3 nodes in each DC, the first node in DC 2 is number 4. | |
| 300 | - * | |
| 301 | - * @return the address of the {@code nth} host in the cluster. | |
| 302 | - */ | |
| 303 | - public InetSocketAddress addressOfNode(int n) { | |
| 304 | - return new InetSocketAddress(TestUtils.ipOfNode(n), binaryPort); | |
| 288 | + @Override | |
| 289 | + public String getClusterName() { | |
| 290 | + return clusterName; | |
| 305 | 291 | } |
| 306 | 292 | |
| 307 | - /** | |
| 308 | - * Returns an {@link AddressTranslater} to use when tests must manually create | |
| 309 | - * {@link Cluster} instances. | |
| 310 | - * <p/> | |
| 311 | - * This translator is necessary because hosts in this cluster do not necessarily use standard ports. | |
| 312 | - * | |
| 313 | - * @return an {@link AddressTranslater} to use when tests must manually create | |
| 314 | - * {@link Cluster} instances. | |
| 315 | - */ | |
| 316 | - public AddressTranslater addressTranslator() { | |
| 317 | - return new AddressTranslater() { | |
| 318 | - @Override | |
| 319 | - public InetSocketAddress translate(InetSocketAddress address) { | |
| 320 | - return new InetSocketAddress(address.getAddress(), getBinaryPort()); | |
| 321 | - } | |
| 322 | - }; | |
| 293 | + @Override | |
| 294 | + public InetSocketAddress addressOfNode(int n) { | |
| 295 | + return new InetSocketAddress(TestUtils.ipOfNode(n), binaryPort); | |
| 323 | 296 | } |
| 324 | 297 | |
| 325 | - /** | |
| 326 | - * Returns the Cassandra version of this CCM cluster. | |
| 327 | - * <p/> | |
| 328 | - * By default the version is equal to {@link #getCassandraVersion()}. | |
| 329 | - * | |
| 330 | - * @return The version of this CCM cluster. | |
| 331 | - */ | |
| 298 | + @Override | |
| 332 | 299 | public VersionNumber getVersion() { |
| 333 | 300 | return version; |
| 334 | 301 | } |
| 335 | 302 | |
| 336 | - /** | |
| 337 | - * The number of nodes that were initially created with this CCM instance. | |
| 338 | - * <p/> | |
| 339 | - * This does not account for nodes created or removed during the cluster's lifecycle. | |
| 340 | - * | |
| 341 | - * @return The number of nodes that were initially created with this CCM instance. | |
| 342 | - */ | |
| 343 | - public int getInitialNumberOfNodes() { | |
| 344 | - return initialNumberOfNodes; | |
| 345 | - } | |
| 346 | - | |
| 303 | + @Override | |
| 347 | 304 | public File getCcmDir() { |
| 348 | 305 | return ccmDir; |
| 349 | 306 | } |
| 350 | 307 | |
| 308 | + @Override | |
| 351 | 309 | public File getClusterDir() { |
| 352 | 310 | return new File(ccmDir, clusterName); |
| 353 | 311 | } |
| 354 | 312 | |
| 313 | + @Override | |
| 355 | 314 | public File getNodeDir(int n) { |
| 356 | 315 | return new File(getClusterDir(), "node" + n); |
| 357 | 316 | } |
| 358 | 317 | |
| 318 | + @Override | |
| 359 | 319 | public File getNodeConfDir(int n) { |
| 360 | 320 | return new File(getNodeDir(n), "conf"); |
| 361 | 321 | } |
| 362 | 322 | |
| 323 | + @Override | |
| 363 | 324 | public int getStoragePort() { |
| 364 | 325 | return storagePort; |
| 365 | 326 | } |
| 366 | 327 | |
| 328 | + @Override | |
| 367 | 329 | public int getThriftPort() { |
| 368 | 330 | return thriftPort; |
| 369 | 331 | } |
| 370 | 332 | |
| 333 | + @Override | |
| 371 | 334 | public int getBinaryPort() { |
| 372 | 335 | return binaryPort; |
| 373 | 336 | } |
| 374 | 337 | |
| 338 | + @Override | |
| 375 | 339 | public void setKeepLogs(boolean keepLogs) { |
| 376 | 340 | this.keepLogs = keepLogs; |
| 377 | 341 | } |
| @@ -407,11 +371,13 @@ | ||
| 407 | 371 | logger.debug("Closed: " + this); |
| 408 | 372 | } |
| 409 | 373 | |
| 374 | + @Override | |
| 410 | 375 | public void start() { |
| 411 | 376 | logger.debug("Starting: " + this); |
| 412 | 377 | execute(CCM_COMMAND + " start --wait-other-notice --wait-for-binary-proto" + jvmArgs); |
| 413 | 378 | } |
| 414 | 379 | |
| 380 | + @Override | |
| 415 | 381 | public synchronized void stop() { |
| 416 | 382 | if (closed) |
| 417 | 383 | return; |
| @@ -420,6 +386,7 @@ | ||
| 420 | 386 | closed = true; |
| 421 | 387 | } |
| 422 | 388 | |
| 389 | + @Override | |
| 423 | 390 | public synchronized void forceStop() { |
| 424 | 391 | if (closed) |
| 425 | 392 | return; |
| @@ -428,36 +395,43 @@ | ||
| 428 | 395 | closed = true; |
| 429 | 396 | } |
| 430 | 397 | |
| 398 | + @Override | |
| 431 | 399 | public void start(int n) { |
| 432 | 400 | logger.debug(String.format("Starting: node %s (%s%s:%s) in %s", n, TestUtils.IP_PREFIX, n, binaryPort, this)); |
| 433 | 401 | execute(CCM_COMMAND + " node%d start --wait-other-notice --wait-for-binary-proto" + jvmArgs, n); |
| 434 | 402 | } |
| 435 | 403 | |
| 404 | + @Override | |
| 436 | 405 | public void stop(int n) { |
| 437 | 406 | logger.debug(String.format("Stopping: node %s (%s%s:%s) in %s", n, TestUtils.IP_PREFIX, n, binaryPort, this)); |
| 438 | 407 | execute(CCM_COMMAND + " node%d stop", n); |
| 439 | 408 | } |
| 440 | 409 | |
| 410 | + @Override | |
| 441 | 411 | public void forceStop(int n) { |
| 442 | 412 | logger.debug(String.format("Force stopping: node %s (%s%s:%s) in %s", n, TestUtils.IP_PREFIX, n, binaryPort, this)); |
| 443 | 413 | execute(CCM_COMMAND + " node%d stop --not-gently", n); |
| 444 | 414 | } |
| 445 | 415 | |
| 416 | + @Override | |
| 446 | 417 | public synchronized void remove() { |
| 447 | 418 | stop(); |
| 448 | 419 | logger.debug("Removing: " + this); |
| 449 | 420 | execute(CCM_COMMAND + " remove"); |
| 450 | 421 | } |
| 451 | 422 | |
| 423 | + @Override | |
| 452 | 424 | public void remove(int n) { |
| 453 | 425 | logger.debug(String.format("Removing: node %s (%s%s:%s) from %s", n, TestUtils.IP_PREFIX, n, binaryPort, this)); |
| 454 | 426 | execute(CCM_COMMAND + " node%d remove", n); |
| 455 | 427 | } |
| 456 | 428 | |
| 429 | + @Override | |
| 457 | 430 | public void add(int n) { |
| 458 | 431 | add(1, n); |
| 459 | 432 | } |
| 460 | 433 | |
| 434 | + @Override | |
| 461 | 435 | public void add(int dc, int n) { |
| 462 | 436 | logger.debug(String.format("Adding: node %s (%s%s:%s) to %s", n, TestUtils.IP_PREFIX, n, binaryPort, this)); |
| 463 | 437 | String thriftItf = TestUtils.ipOfNode(n) + ":" + thriftPort; |
| @@ -468,11 +442,13 @@ | ||
| 468 | 442 | n, dc, TestUtils.IP_PREFIX, n, thriftItf, storageItf, binaryItf, TestUtils.findAvailablePort(), remoteLogItf); |
| 469 | 443 | } |
| 470 | 444 | |
| 471 | - public void decommissionNode(int n) { | |
| 445 | + @Override | |
| 446 | + public void decommision(int n) { | |
| 472 | 447 | logger.debug(String.format("Decommissioning: node %s (%s%s:%s) from %s", n, TestUtils.IP_PREFIX, n, binaryPort, this)); |
| 473 | 448 | execute(CCM_COMMAND + " node%d decommission", n); |
| 474 | 449 | } |
| 475 | 450 | |
| 451 | + @Override | |
| 476 | 452 | public void updateConfig(Map<String, Object> configs) { |
| 477 | 453 | StringBuilder confStr = new StringBuilder(); |
| 478 | 454 | for (Map.Entry<String, Object> entry : configs.entrySet()) { |
| @@ -485,6 +461,7 @@ | ||
| 485 | 461 | execute(CCM_COMMAND + " updateconf " + confStr); |
| 486 | 462 | } |
| 487 | 463 | |
| 464 | + @Override | |
| 488 | 465 | public void updateDSEConfig(Map<String, Object> configs) { |
| 489 | 466 | StringBuilder confStr = new StringBuilder(); |
| 490 | 467 | for (Map.Entry<String, Object> entry : configs.entrySet()) { |
| @@ -497,10 +474,12 @@ | ||
| 497 | 474 | execute(CCM_COMMAND + " updatedseconf " + confStr); |
| 498 | 475 | } |
| 499 | 476 | |
| 477 | + @Override | |
| 500 | 478 | public void updateNodeConfig(int n, String key, Object value) { |
| 501 | 479 | updateNodeConfig(n, ImmutableMap.<String, Object>builder().put(key, value).build()); |
| 502 | 480 | } |
| 503 | 481 | |
| 482 | + @Override | |
| 504 | 483 | public void updateNodeConfig(int n, Map<String, Object> configs) { |
| 505 | 484 | StringBuilder confStr = new StringBuilder(); |
| 506 | 485 | for (Map.Entry<String, Object> entry : configs.entrySet()) { |
| @@ -513,6 +492,7 @@ | ||
| 513 | 492 | execute(CCM_COMMAND + " node%s updateconf %s", n, confStr); |
| 514 | 493 | } |
| 515 | 494 | |
| 495 | + @Override | |
| 516 | 496 | public void setWorkload(int node, String workload) { |
| 517 | 497 | execute(CCM_COMMAND + " node%d setworkload %s", node, workload); |
| 518 | 498 | } |
| @@ -619,6 +599,12 @@ | ||
| 619 | 599 | return "CCM cluster " + clusterName; |
| 620 | 600 | } |
| 621 | 601 | |
| 602 | + @Override | |
| 603 | + protected void finalize() throws Throwable { | |
| 604 | + close(); | |
| 605 | + super.finalize(); | |
| 606 | + } | |
| 607 | + | |
| 622 | 608 | /** |
| 623 | 609 | * use {@link #builder()} to get an instance |
| 624 | 610 | */ |
| @@ -628,8 +614,8 @@ | ||
| 628 | 614 | int[] nodes = {1}; |
| 629 | 615 | private boolean start = true; |
| 630 | 616 | private boolean isDSE = isDSE(); |
| 631 | - private String cassandraVersion = getCassandraVersion(); | |
| 632 | - private Set<String> createOptions = new LinkedHashSet<String>(); | |
| 617 | + private String version = getCassandraVersion(); | |
| 618 | + private Set<String> createOptions = new HashSet<String>(getInstallArguments()); | |
| 633 | 619 | private Set<String> jvmArgs = new LinkedHashSet<String>(); |
| 634 | 620 | private final Map<String, Object> cassandraConfiguration = Maps.newHashMap(); |
| 635 | 621 | private final Map<String, Object> dseConfiguration = Maps.newHashMap(); |
| @@ -687,6 +673,7 @@ | ||
| 687 | 673 | * Sets this cluster to be a DSE cluster (defaults to {@link #isDSE()} if this is never called). |
| 688 | 674 | */ |
| 689 | 675 | public Builder withDSE() { |
| 676 | + this.createOptions.add("--dse"); | |
| 690 | 677 | this.isDSE = true; |
| 691 | 678 | return this; |
| 692 | 679 | } |
| @@ -696,8 +683,17 @@ | ||
| 696 | 683 | * |
| 697 | 684 | * Defaults to {@link #getCassandraVersion()}. |
| 698 | 685 | */ |
| 699 | - public Builder withVersion(String cassandraVersion) { | |
| 700 | - this.cassandraVersion = cassandraVersion; | |
| 686 | + public Builder withVersion(String version) { | |
| 687 | + Iterator<String> it = createOptions.iterator(); | |
| 688 | + while (it.hasNext()) { | |
| 689 | + String option = it.next(); | |
| 690 | + // remove any version previously set and | |
| 691 | + // install-dir, which is incompatible | |
| 692 | + if (option.startsWith("-v ") || option.startsWith("--install-dir")) | |
| 693 | + it.remove(); | |
| 694 | + } | |
| 695 | + this.createOptions.add("-v " + version); | |
| 696 | + this.version = version; | |
| 701 | 697 | return this; |
| 702 | 698 | } |
| 703 | 699 | |
| @@ -752,15 +748,11 @@ | ||
| 752 | 748 | |
| 753 | 749 | public CCMBridge build() { |
| 754 | 750 | // be careful NOT to alter internal state (hashCode/equals) during build! |
| 755 | - int initialNumberOfNodes = 0; | |
| 756 | - for (int nodesPerDc : nodes) { | |
| 757 | - initialNumberOfNodes += nodesPerDc; | |
| 758 | - } | |
| 759 | 751 | int storagePort = this.storagePort == -1 ? findAvailablePort() : this.storagePort; |
| 760 | 752 | int thriftPort = this.thriftPort == -1 ? findAvailablePort() : this.thriftPort; |
| 761 | 753 | int binaryPort = this.binaryPort == -1 ? findAvailablePort() : this.binaryPort; |
| 762 | - VersionNumber version = VersionNumber.parse(cassandraVersion); | |
| 763 | - final CCMBridge ccm = new CCMBridge(clusterName, isDSE, version, storagePort, thriftPort, binaryPort, joinJvmArgs(), initialNumberOfNodes); | |
| 754 | + VersionNumber version = VersionNumber.parse(this.version); | |
| 755 | + final CCMBridge ccm = new CCMBridge(clusterName, isDSE, version, storagePort, thriftPort, binaryPort, joinJvmArgs()); | |
| 764 | 756 | Runtime.getRuntime().addShutdownHook(new Thread() { |
| 765 | 757 | @Override |
| 766 | 758 | public void run() { |
| @@ -795,10 +787,6 @@ | ||
| 795 | 787 | result.append(" ").append(clusterName); |
| 796 | 788 | result.append(" -i ").append(TestUtils.IP_PREFIX); |
| 797 | 789 | result.append(" "); |
| 798 | - if (cassandraVersion != null) | |
| 799 | - result.append("-v ").append(cassandraVersion); | |
| 800 | - else | |
| 801 | - result.append(CASSANDRA_INSTALL_ARGS); | |
| 802 | 790 | if (nodes.length > 0) { |
| 803 | 791 | result.append(" -n "); |
| 804 | 792 | for (int i = 0; i < nodes.length; i++) { |
| @@ -808,8 +796,7 @@ | ||
| 808 | 796 | result.append(node); |
| 809 | 797 | } |
| 810 | 798 | } |
| 811 | - if (!createOptions.isEmpty()) | |
| 812 | - result.append(" ").append(Joiner.on(" ").join(createOptions)); | |
| 799 | + result.append(" ").append(Joiner.on(" ").join(createOptions)); | |
| 813 | 800 | return result.toString(); |
| 814 | 801 | } |
| 815 | 802 | |
| @@ -879,7 +866,7 @@ | ||
| 879 | 866 | if (!jvmArgs.equals(builder.jvmArgs)) return false; |
| 880 | 867 | if (!dseConfiguration.equals(builder.dseConfiguration)) return false; |
| 881 | 868 | if (!cassandraConfiguration.equals(builder.cassandraConfiguration)) return false; |
| 882 | - return cassandraVersion.equals(builder.cassandraVersion); | |
| 869 | + return version.equals(builder.version); | |
| 883 | 870 | } |
| 884 | 871 | |
| 885 | 872 | @Override |
| @@ -895,7 +882,7 @@ | ||
| 895 | 882 | result = 31 * result + thriftPort; |
| 896 | 883 | result = 31 * result + binaryPort; |
| 897 | 884 | result = 31 * result + storagePort; |
| 898 | - result = 31 * result + cassandraVersion.hashCode(); | |
| 885 | + result = 31 * result + version.hashCode(); | |
| 899 | 886 | return result; |
| 900 | 887 | } |
| 901 | 888 | } |
modified driver-core/src/test/java/com/datastax/driver/core/CCMConfig.java +7 −0
| @@ -43,6 +43,10 @@ | ||
| 43 | 43 | /** |
| 44 | 44 | * The C* or DSE version to use; defaults to the version defined by |
| 45 | 45 | * the System property {@code cassandra.version}. |
| 46 | + * <p/> | |
| 47 | + * Note that setting this property completely | |
| 48 | + * overrides the System properties {@code cassandra.version} | |
| 49 | + * and {@code cassandra.directory}. | |
| 46 | 50 | * |
| 47 | 51 | * @return The C* or DSE version to use |
| 48 | 52 | * @see CCMBridge#getCassandraVersion() |
| @@ -51,6 +55,9 @@ | ||
| 51 | 55 | |
| 52 | 56 | /** |
| 53 | 57 | * Whether to launch a DSE instance rather than an OSS C*. |
| 58 | + * <p/> | |
| 59 | + * Note that setting this property completely | |
| 60 | + * overrides the System property {@code dse}. | |
| 54 | 61 | * |
| 55 | 62 | * @return {@code true} to launch a DSE instance, {@code false} to launch an OSS C* instance (default). |
| 56 | 63 | */ |
modified driver-core/src/test/java/com/datastax/driver/core/CCMTestsSupport.java +295 −59
| @@ -16,17 +16,19 @@ | ||
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | 18 | import com.datastax.driver.core.CreateCCM.TestMode; |
| 19 | -import com.datastax.driver.core.policies.AddressTranslater; | |
| 20 | 19 | import com.google.common.base.Throwables; |
| 21 | 20 | import com.google.common.cache.*; |
| 22 | 21 | import com.google.common.collect.Lists; |
| 23 | 22 | import com.google.common.io.Closer; |
| 23 | +import com.google.common.util.concurrent.MoreExecutors; | |
| 24 | +import com.google.common.util.concurrent.ThreadFactoryBuilder; | |
| 24 | 25 | import org.slf4j.Logger; |
| 25 | 26 | import org.slf4j.LoggerFactory; |
| 26 | 27 | import org.testng.ITestResult; |
| 27 | 28 | import org.testng.annotations.*; |
| 28 | 29 | |
| 29 | 30 | import java.io.Closeable; |
| 31 | +import java.io.File; | |
| 30 | 32 | import java.io.IOException; |
| 31 | 33 | import java.lang.annotation.Annotation; |
| 32 | 34 | import java.lang.reflect.Constructor; |
| @@ -35,8 +37,7 @@ | ||
| 35 | 37 | import java.lang.reflect.ParameterizedType; |
| 36 | 38 | import java.net.InetSocketAddress; |
| 37 | 39 | import java.util.*; |
| 38 | -import java.util.concurrent.Callable; | |
| 39 | -import java.util.concurrent.ExecutionException; | |
| 40 | +import java.util.concurrent.*; | |
| 40 | 41 | import java.util.concurrent.atomic.AtomicInteger; |
| 41 | 42 | |
| 42 | 43 | import static com.datastax.driver.core.CreateCCM.TestMode.PER_CLASS; |
| @@ -52,6 +53,166 @@ | ||
| 52 | 53 | |
| 53 | 54 | private static final List<String> TEST_GROUPS = Lists.newArrayList("isolated", "short", "long", "stress", "duration"); |
| 54 | 55 | |
| 56 | + | |
| 57 | + private static class ReadOnlyCCMBridge implements CCMAccess { | |
| 58 | + | |
| 59 | + private final CCMAccess delegate; | |
| 60 | + | |
| 61 | + private ReadOnlyCCMBridge(CCMAccess delegate) { | |
| 62 | + this.delegate = delegate; | |
| 63 | + } | |
| 64 | + | |
| 65 | + @Override | |
| 66 | + public String getClusterName() { | |
| 67 | + return delegate.getClusterName(); | |
| 68 | + } | |
| 69 | + | |
| 70 | + @Override | |
| 71 | + public InetSocketAddress addressOfNode(int n) { | |
| 72 | + return delegate.addressOfNode(n); | |
| 73 | + } | |
| 74 | + | |
| 75 | + @Override | |
| 76 | + public VersionNumber getVersion() { | |
| 77 | + return delegate.getVersion(); | |
| 78 | + } | |
| 79 | + | |
| 80 | + @Override | |
| 81 | + public File getCcmDir() { | |
| 82 | + return delegate.getCcmDir(); | |
| 83 | + } | |
| 84 | + | |
| 85 | + @Override | |
| 86 | + public File getClusterDir() { | |
| 87 | + return delegate.getClusterDir(); | |
| 88 | + } | |
| 89 | + | |
| 90 | + @Override | |
| 91 | + public File getNodeDir(int n) { | |
| 92 | + return delegate.getNodeDir(n); | |
| 93 | + } | |
| 94 | + | |
| 95 | + @Override | |
| 96 | + public File getNodeConfDir(int n) { | |
| 97 | + return delegate.getNodeConfDir(n); | |
| 98 | + } | |
| 99 | + | |
| 100 | + @Override | |
| 101 | + public int getStoragePort() { | |
| 102 | + return delegate.getStoragePort(); | |
| 103 | + } | |
| 104 | + | |
| 105 | + @Override | |
| 106 | + public int getThriftPort() { | |
| 107 | + return delegate.getThriftPort(); | |
| 108 | + } | |
| 109 | + | |
| 110 | + @Override | |
| 111 | + public int getBinaryPort() { | |
| 112 | + return delegate.getBinaryPort(); | |
| 113 | + } | |
| 114 | + | |
| 115 | + @Override | |
| 116 | + public void setKeepLogs(boolean keepLogs) { | |
| 117 | + delegate.setKeepLogs(keepLogs); | |
| 118 | + } | |
| 119 | + | |
| 120 | + @Override | |
| 121 | + public void close() { | |
| 122 | + throw new UnsupportedOperationException("This CCM cluster is read-only"); | |
| 123 | + } | |
| 124 | + | |
| 125 | + @Override | |
| 126 | + public void start() { | |
| 127 | + throw new UnsupportedOperationException("This CCM cluster is read-only"); | |
| 128 | + } | |
| 129 | + | |
| 130 | + @Override | |
| 131 | + public void stop() { | |
| 132 | + throw new UnsupportedOperationException("This CCM cluster is read-only"); | |
| 133 | + } | |
| 134 | + | |
| 135 | + @Override | |
| 136 | + public void forceStop() { | |
| 137 | + throw new UnsupportedOperationException("This CCM cluster is read-only"); | |
| 138 | + } | |
| 139 | + | |
| 140 | + @Override | |
| 141 | + public void remove() { | |
| 142 | + throw new UnsupportedOperationException("This CCM cluster is read-only"); | |
| 143 | + } | |
| 144 | + | |
| 145 | + @Override | |
| 146 | + public void start(int n) { | |
| 147 | + throw new UnsupportedOperationException("This CCM cluster is read-only"); | |
| 148 | + } | |
| 149 | + | |
| 150 | + @Override | |
| 151 | + public void stop(int n) { | |
| 152 | + throw new UnsupportedOperationException("This CCM cluster is read-only"); | |
| 153 | + } | |
| 154 | + | |
| 155 | + @Override | |
| 156 | + public void forceStop(int n) { | |
| 157 | + throw new UnsupportedOperationException("This CCM cluster is read-only"); | |
| 158 | + } | |
| 159 | + | |
| 160 | + @Override | |
| 161 | + public void remove(int n) { | |
| 162 | + throw new UnsupportedOperationException("This CCM cluster is read-only"); | |
| 163 | + } | |
| 164 | + | |
| 165 | + @Override | |
| 166 | + public void add(int n) { | |
| 167 | + throw new UnsupportedOperationException("This CCM cluster is read-only"); | |
| 168 | + } | |
| 169 | + | |
| 170 | + @Override | |
| 171 | + public void add(int dc, int n) { | |
| 172 | + throw new UnsupportedOperationException("This CCM cluster is read-only"); | |
| 173 | + } | |
| 174 | + | |
| 175 | + @Override | |
| 176 | + public void decommision(int n) { | |
| 177 | + throw new UnsupportedOperationException("This CCM cluster is read-only"); | |
| 178 | + } | |
| 179 | + | |
| 180 | + @Override | |
| 181 | + public void updateConfig(Map<String, Object> configs) { | |
| 182 | + throw new UnsupportedOperationException("This CCM cluster is read-only"); | |
| 183 | + } | |
| 184 | + | |
| 185 | + @Override | |
| 186 | + public void updateDSEConfig(Map<String, Object> configs) { | |
| 187 | + throw new UnsupportedOperationException("This CCM cluster is read-only"); | |
| 188 | + } | |
| 189 | + | |
| 190 | + @Override | |
| 191 | + public void updateNodeConfig(int n, String key, Object value) { | |
| 192 | + throw new UnsupportedOperationException("This CCM cluster is read-only"); | |
| 193 | + } | |
| 194 | + | |
| 195 | + @Override | |
| 196 | + public void updateNodeConfig(int n, Map<String, Object> configs) { | |
| 197 | + throw new UnsupportedOperationException("This CCM cluster is read-only"); | |
| 198 | + } | |
| 199 | + | |
| 200 | + @Override | |
| 201 | + public void setWorkload(int node, String workload) { | |
| 202 | + throw new UnsupportedOperationException("This CCM cluster is read-only"); | |
| 203 | + } | |
| 204 | + | |
| 205 | + @Override | |
| 206 | + public void waitForUp(int node) { | |
| 207 | + throw new UnsupportedOperationException("This CCM cluster is read-only"); | |
| 208 | + } | |
| 209 | + | |
| 210 | + @Override | |
| 211 | + public void waitForDown(int node) { | |
| 212 | + throw new UnsupportedOperationException("This CCM cluster is read-only"); | |
| 213 | + } | |
| 214 | + } | |
| 215 | + | |
| 55 | 216 | private static class CCMTestConfig { |
| 56 | 217 | |
| 57 | 218 | private final List<CCMConfig> annotations; |
| @@ -109,6 +270,7 @@ | ||
| 109 | 270 | @SuppressWarnings("SimplifiableIfStatement") |
| 110 | 271 | private Map<String, Object> config() { |
| 111 | 272 | Map<String, Object> config = new HashMap<String, Object>(); |
| 273 | + config.put("start_rpc", false); | |
| 112 | 274 | for (int i = annotations.size() - 1; i == 0; i--) { |
| 113 | 275 | CCMConfig ann = annotations.get(i); |
| 114 | 276 | addConfigOptions(ann.config(), config); |
| @@ -202,8 +364,7 @@ | ||
| 202 | 364 | |
| 203 | 365 | private CCMBridge.Builder ccmBuilder() { |
| 204 | 366 | if (ccmBuilder == null) { |
| 205 | - ccmBuilder = CCMBridge.builder() | |
| 206 | - .withNodes(numberOfNodes()); | |
| 367 | + ccmBuilder = CCMBridge.builder().withNodes(numberOfNodes()); | |
| 207 | 368 | if (version() != null) |
| 208 | 369 | ccmBuilder.withVersion(version()); |
| 209 | 370 | if (dse()) |
| @@ -283,31 +444,115 @@ | ||
| 283 | 444 | } |
| 284 | 445 | } |
| 285 | 446 | |
| 447 | + private int weight() { | |
| 448 | + int weight = 0; | |
| 449 | + weight += totalNodes() - 1; | |
| 450 | + weight += config().size() - 1; | |
| 451 | + weight += dseConfig().size(); | |
| 452 | + weight += dse() ? 1 : 0; | |
| 453 | + weight += jvmArgs().size(); | |
| 454 | + weight += startOptions().size(); | |
| 455 | + weight += ssl() ? 1 : 0; | |
| 456 | + weight += auth() ? 1 : 0; | |
| 457 | + weight += version() != null ? 1 : 0; | |
| 458 | + return weight; | |
| 459 | + } | |
| 460 | + | |
| 461 | + private int totalNodes() { | |
| 462 | + int nodes = 0; | |
| 463 | + for (int nodesPerDc : numberOfNodes()) { | |
| 464 | + nodes += nodesPerDc; | |
| 465 | + } | |
| 466 | + return nodes; | |
| 467 | + } | |
| 468 | + } | |
| 469 | + | |
| 470 | + private static class CCMTestContextKey { | |
| 471 | + | |
| 472 | + private final CCMBridge.Builder builder; | |
| 473 | + | |
| 474 | + private final int weight; | |
| 475 | + | |
| 476 | + private CCMTestContextKey(CCMBridge.Builder builder, int weight) { | |
| 477 | + this.builder = builder; | |
| 478 | + this.weight = weight; | |
| 479 | + } | |
| 480 | + | |
| 481 | + @Override | |
| 482 | + public boolean equals(Object o) { | |
| 483 | + if (this == o) return true; | |
| 484 | + if (o == null || getClass() != o.getClass()) return false; | |
| 485 | + CCMTestContextKey that = (CCMTestContextKey) o; | |
| 486 | + return builder.equals(that.builder); | |
| 487 | + } | |
| 488 | + | |
| 489 | + @Override | |
| 490 | + public int hashCode() { | |
| 491 | + return builder.hashCode(); | |
| 492 | + } | |
| 493 | + } | |
| 494 | + | |
| 495 | + private static class CCMTestContext implements Runnable { | |
| 496 | + | |
| 497 | + private CCMAccess ccm; | |
| 498 | + | |
| 499 | + private final AtomicInteger refCount = new AtomicInteger(1); | |
| 500 | + | |
| 501 | + private volatile boolean evicted = false; | |
| 502 | + | |
| 503 | + private CCMTestContext(CCMAccess ccm) { | |
| 504 | + this(ccm, false); | |
| 505 | + } | |
| 506 | + | |
| 507 | + public CCMTestContext(CCMAccess ccm, boolean evicted) { | |
| 508 | + this.ccm = ccm; | |
| 509 | + this.evicted = evicted; | |
| 510 | + } | |
| 511 | + | |
| 512 | + @Override | |
| 513 | + public void run() { | |
| 514 | + if (ccm != null) | |
| 515 | + ccm.close(); | |
| 516 | + ccm = null; | |
| 517 | + } | |
| 518 | + | |
| 519 | + private void markEvicted() { | |
| 520 | + evicted = true; | |
| 521 | + } | |
| 522 | + | |
| 523 | + private void maybeClose() { | |
| 524 | + if (refCount.get() <= 0 && evicted) | |
| 525 | + POOL.execute(this); | |
| 526 | + } | |
| 286 | 527 | } |
| 287 | 528 | |
| 288 | - private static class CCMTestContextLoader extends CacheLoader<CCMBridge.Builder, CCMBridge> { | |
| 529 | + private static class CCMTestContextLoader extends CacheLoader<CCMTestContextKey, CCMTestContext> { | |
| 289 | 530 | |
| 290 | 531 | @Override |
| 291 | - public CCMBridge load(CCMBridge.Builder builder) { | |
| 292 | - return builder.build(); | |
| 532 | + public CCMTestContext load(CCMTestContextKey key) { | |
| 533 | + return new CCMTestContext(key.builder.build()); | |
| 293 | 534 | } |
| 294 | 535 | |
| 295 | 536 | } |
| 296 | 537 | |
| 297 | - private static class CCMTestContextWeigher implements Weigher<CCMBridge.Builder, CCMBridge> { | |
| 538 | + private static class CCMTestContextWeigher implements Weigher<CCMTestContextKey, CCMTestContext> { | |
| 539 | + | |
| 298 | 540 | @Override |
| 299 | - public int weigh(CCMBridge.Builder key, CCMBridge value) { | |
| 300 | - return value.getInitialNumberOfNodes(); | |
| 541 | + public int weigh(CCMTestContextKey key, CCMTestContext value) { | |
| 542 | + return key.weight; | |
| 301 | 543 | } |
| 544 | + | |
| 302 | 545 | } |
| 303 | 546 | |
| 304 | - private static class CCMTestContextRemovalListener implements RemovalListener<CCMBridge.Builder, CCMBridge> { | |
| 547 | + private static class CCMTestContextRemovalListener implements RemovalListener<CCMTestContextKey, CCMTestContext> { | |
| 305 | 548 | |
| 306 | 549 | @Override |
| 307 | - public void onRemoval(RemovalNotification<CCMBridge.Builder, CCMBridge> notification) { | |
| 308 | - if (notification.getValue() != null) { | |
| 309 | - LOGGER.debug("Evicting: " + notification.getValue()); | |
| 310 | - notification.getValue().close(); | |
| 550 | + public void onRemoval(RemovalNotification<CCMTestContextKey, CCMTestContext> notification) { | |
| 551 | + CCMTestContext context = notification.getValue(); | |
| 552 | + if (context != null && context.ccm != null) { | |
| 553 | + LOGGER.debug("Evicting: {} because of {}", context.ccm, notification.getCause()); | |
| 554 | + context.markEvicted(); | |
| 555 | + context.maybeClose(); | |
| 311 | 556 | } |
| 312 | 557 | } |
| 313 | 558 | |
| @@ -316,7 +561,11 @@ | ||
| 316 | 561 | /** |
| 317 | 562 | * A LoadingCache that stores running CCM clusters. |
| 318 | 563 | */ |
| 319 | - private static final LoadingCache<CCMBridge.Builder, CCMBridge> CACHE; | |
| 564 | + private static final LoadingCache<CCMTestContextKey, CCMTestContext> CACHE; | |
| 565 | + | |
| 566 | + private static final ExecutorService POOL = MoreExecutors.getExitingExecutorService( | |
| 567 | + (ThreadPoolExecutor) Executors.newFixedThreadPool(2, | |
| 568 | + new ThreadFactoryBuilder().setNameFormat("ccm-removal-%d").build())); | |
| 320 | 569 | |
| 321 | 570 | static { |
| 322 | 571 | long maximumWeight; |
| @@ -326,24 +575,29 @@ | ||
| 326 | 575 | if (freeMemoryMB < 1000) |
| 327 | 576 | LOGGER.warn("Available memory below 1GB: {}MB, CCM clusters might fail to start", freeMemoryMB); |
| 328 | 577 | // CCM nodes are started with -Xms500M -Xmx500M |
| 329 | - // leave at least 500 MB out, with a minimum of 1 node and a maximum of 10 nodes | |
| 330 | - maximumWeight = Math.min(10, Math.max(1, (freeMemoryMB / 500) - 1)); | |
| 578 | + // so 1 "slot" is roughly 500MB | |
| 579 | + // leave at least 2 slots out, with a minimum of 1 slot and a maximum of 6 slots | |
| 580 | + long slotsAvailable = (freeMemoryMB / 500) - 2; | |
| 581 | + maximumWeight = Math.min(6, Math.max(1, slotsAvailable)); | |
| 331 | 582 | } else { |
| 332 | 583 | maximumWeight = Integer.parseInt(numberOfNodes); |
| 333 | 584 | } |
| 334 | 585 | LOGGER.info("Maximum number of running CCM nodes: {}", maximumWeight); |
| 335 | 586 | CACHE = CacheBuilder.newBuilder() |
| 336 | - .initialCapacity(1) | |
| 587 | + .initialCapacity(3) | |
| 337 | 588 | .maximumWeight(maximumWeight) |
| 338 | 589 | .weigher(new CCMTestContextWeigher()) |
| 339 | 590 | .removalListener(new CCMTestContextRemovalListener()) |
| 340 | 591 | .build(new CCMTestContextLoader()); |
| 341 | 592 | } |
| 593 | + | |
| 342 | 594 | private TestMode testMode; |
| 343 | 595 | |
| 344 | 596 | private CCMTestConfig ccmTestConfig; |
| 345 | 597 | |
| 346 | - protected CCMBridge ccm; | |
| 598 | + private CCMTestContext ccmTestContext; | |
| 599 | + | |
| 600 | + protected CCMAccess ccm; | |
| 347 | 601 | |
| 348 | 602 | protected Cluster cluster; |
| 349 | 603 | |
| @@ -533,36 +787,6 @@ | ||
| 533 | 787 | return contactPoints; |
| 534 | 788 | } |
| 535 | 789 | |
| 536 | - /** | |
| 537 | - * Returns the address of the {@code nth} host in the CCM cluster (counting from 1, i.e., | |
| 538 | - * {@code getHostAddress(1)} returns the address of the first node. | |
| 539 | - * <p/> | |
| 540 | - * In multi-DC setups, nodes are numbered in ascending order of their datacenter number. | |
| 541 | - * E.g. with 2 DCs and 3 nodes in each DC, the first node in DC 2 is number 4. | |
| 542 | - * <p/> | |
| 543 | - * This method should not be called before the test has started, nor after the test is finished. | |
| 544 | - * | |
| 545 | - * @return the address of the {@code nth} host in the cluster. | |
| 546 | - */ | |
| 547 | - public InetSocketAddress getHostAddress(int n) { | |
| 548 | - return ccm.addressOfNode(n); | |
| 549 | - } | |
| 550 | - | |
| 551 | - /** | |
| 552 | - * Returns an {@link AddressTranslater} to use when tests must manually create | |
| 553 | - * {@link Cluster} instances. | |
| 554 | - * <p/> | |
| 555 | - * This translator is necessary because hosts create with this class do not use standard ports. | |
| 556 | - * <p/> | |
| 557 | - * This method should not be called before the test has started, nor after the test is finished. | |
| 558 | - * | |
| 559 | - * @return an {@link AddressTranslater} to use when tests must manually create | |
| 560 | - * {@link Cluster} instances. | |
| 561 | - */ | |
| 562 | - public AddressTranslater getAddressTranslator() { | |
| 563 | - return ccm.addressTranslator(); | |
| 564 | - } | |
| 565 | - | |
| 566 | 790 | /** |
| 567 | 791 | * Registers the given {@link Closeable} to be closed at the end of the current test method. |
| 568 | 792 | * <p/> |
| @@ -583,22 +807,32 @@ | ||
| 583 | 807 | if (ccmTestConfig.createCcm()) { |
| 584 | 808 | if (ccmTestConfig.dirtiesContext()) { |
| 585 | 809 | ccm = ccmTestConfig.ccmBuilder().build(); |
| 810 | + ccmTestContext = new CCMTestContext(ccm, true); | |
| 586 | 811 | LOGGER.debug("Using dedicated {}", ccm); |
| 587 | 812 | } else { |
| 588 | - CCMBridge.Builder key = ccmTestConfig.ccmBuilder(); | |
| 589 | - ccm = CACHE.getIfPresent(key); | |
| 590 | - if (ccm != null) { | |
| 813 | + CCMBridge.Builder builder = ccmTestConfig.ccmBuilder(); | |
| 814 | + int weight = ccmTestConfig.weight(); | |
| 815 | + CCMTestContextKey key = new CCMTestContextKey(builder, weight); | |
| 816 | + CCMAccess ccm; | |
| 817 | + ccmTestContext = CACHE.getIfPresent(key); | |
| 818 | + if (ccmTestContext != null) { | |
| 819 | + ccmTestContext.refCount.incrementAndGet(); | |
| 820 | + ccm = ccmTestContext.ccm; | |
| 591 | 821 | LOGGER.debug("Reusing {}", ccm); |
| 592 | 822 | } else { |
| 593 | 823 | try { |
| 594 | - ccm = CACHE.get(ccmTestConfig.ccmBuilder()); | |
| 824 | + ccmTestContext = CACHE.get(key); | |
| 825 | + ccm = ccmTestContext.ccm; | |
| 595 | 826 | LOGGER.debug("Using newly-created {}", ccm); |
| 596 | 827 | } catch (ExecutionException e) { |
| 597 | - Throwables.propagate(e); | |
| 828 | + throw Throwables.propagate(e); | |
| 598 | 829 | } |
| 599 | 830 | } |
| 831 | + this.ccm = new ReadOnlyCCMBridge(ccm); | |
| 600 | 832 | } |
| 833 | + assert ccmTestContext != null; | |
| 601 | 834 | assert ccm != null; |
| 835 | + | |
| 602 | 836 | } |
| 603 | 837 | } |
| 604 | 838 | |
| @@ -608,7 +842,7 @@ | ||
| 608 | 842 | // add contact points only if the provided builder didn't do so |
| 609 | 843 | if (builder.getContactPoints().isEmpty()) |
| 610 | 844 | builder.addContactPointsWithPorts(getInitialContactPoints()); |
| 611 | - builder.withAddressTranslater(ccm.addressTranslator()); | |
| 845 | + builder.withPort(ccm.getBinaryPort()); | |
| 612 | 846 | cluster = register(builder.build()); |
| 613 | 847 | cluster.init(); |
| 614 | 848 | } |
| @@ -649,10 +883,12 @@ | ||
| 649 | 883 | } |
| 650 | 884 | |
| 651 | 885 | private void closeTestContext() { |
| 652 | - if (ccmTestConfig != null && ccm != null && ccmTestConfig.dirtiesContext()) { | |
| 653 | - ccm.close(); | |
| 886 | + if (ccmTestContext != null) { | |
| 887 | + ccmTestContext.refCount.decrementAndGet(); | |
| 888 | + ccmTestContext.maybeClose(); | |
| 654 | 889 | } |
| 655 | 890 | ccmTestConfig = null; |
| 891 | + ccmTestContext = null; | |
| 656 | 892 | ccm = null; |
| 657 | 893 | } |
| 658 | 894 |
modified driver-core/src/test/java/com/datastax/driver/core/ClusterInitTest.java +2 −2
| @@ -231,8 +231,8 @@ | ||
| 231 | 231 | .forcePeerInfo(1, 2, "release_version", "1.2.19") |
| 232 | 232 | .build(); |
| 233 | 233 | Cluster cluster = Cluster.builder() |
| 234 | - .addContactPointsWithPorts(scassandraCluster.address(1)) | |
| 235 | - .withAddressTranslater(scassandraCluster.addressTranslator()) | |
| 234 | + .addContactPoints(scassandraCluster.address(1).getAddress()) | |
| 235 | + .withPort(scassandraCluster.getBinaryPort()) | |
| 236 | 236 | .withNettyOptions(nonQuietClusterCloseOptions) |
| 237 | 237 | .build(); |
| 238 | 238 |
modified driver-core/src/test/java/com/datastax/driver/core/ControlConnectionTest.java +11 −11
| @@ -74,8 +74,8 @@ | ||
| 74 | 74 | |
| 75 | 75 | // We pass only the first host as contact point, so we know the control connection will be on this host |
| 76 | 76 | cluster = register(Cluster.builder() |
| 77 | - .addContactPointsWithPorts(getHostAddress(1)) | |
| 78 | - .withAddressTranslater(getAddressTranslator()) | |
| 77 | + .addContactPoints(ccm.addressOfNode(1).getAddress()) | |
| 78 | + .withPort(ccm.getBinaryPort()) | |
| 79 | 79 | .withReconnectionPolicy(reconnectionPolicy) |
| 80 | 80 | .withLoadBalancingPolicy(loadBalancingPolicy) |
| 81 | 81 | .build()); |
| @@ -101,11 +101,11 @@ | ||
| 101 | 101 | @CassandraVersion(major = 2.1) |
| 102 | 102 | public void should_parse_UDT_definitions_when_using_default_protocol_version() { |
| 103 | 103 | Cluster cluster; |
| 104 | - InetSocketAddress firstHost = getHostAddress(1); | |
| 104 | + InetSocketAddress firstHost = ccm.addressOfNode(1); | |
| 105 | 105 | // First driver instance: create UDT |
| 106 | 106 | cluster = register(Cluster.builder() |
| 107 | 107 | .addContactPointsWithPorts(firstHost) |
| 108 | - .withAddressTranslater(getAddressTranslator()) | |
| 108 | + .withPort(ccm.getBinaryPort()) | |
| 109 | 109 | .build()); |
| 110 | 110 | Session session = cluster.connect(); |
| 111 | 111 | session.execute("create keyspace ks WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1}"); |
| @@ -131,10 +131,10 @@ | ||
| 131 | 131 | @Test(groups = "long") |
| 132 | 132 | @CCMConfig(numberOfNodes = 3) |
| 133 | 133 | public void should_reestablish_if_control_node_decommissioned() throws InterruptedException { |
| 134 | - InetSocketAddress firstHost = getHostAddress(1); | |
| 134 | + InetSocketAddress firstHost = ccm.addressOfNode(1); | |
| 135 | 135 | Cluster cluster = register(Cluster.builder() |
| 136 | 136 | .addContactPointsWithPorts(firstHost) |
| 137 | - .withAddressTranslater(getAddressTranslator()) | |
| 137 | + .withPort(ccm.getBinaryPort()) | |
| 138 | 138 | .withQueryOptions(nonDebouncingQueryOptions()) |
| 139 | 139 | .build()); |
| 140 | 140 | cluster.init(); |
| @@ -144,7 +144,7 @@ | ||
| 144 | 144 | assertThat(controlHost).isEqualTo(firstHost.getAddress()); |
| 145 | 145 | |
| 146 | 146 | // Decommission the node. |
| 147 | - ccm.decommissionNode(1); | |
| 147 | + ccm.decommision(1); | |
| 148 | 148 | |
| 149 | 149 | // Ensure that the new control connection is not null and it's host is not equal to the decommissioned node. |
| 150 | 150 | Host newHost = cluster.manager.controlConnection.connectedHost(); |
| @@ -174,15 +174,15 @@ | ||
| 174 | 174 | scassandras.init(); |
| 175 | 175 | |
| 176 | 176 | try { |
| 177 | - Collection<InetSocketAddress> contactPoints = newArrayList(); | |
| 177 | + Collection<InetAddress> contactPoints = newArrayList(); | |
| 178 | 178 | for (int i = 1; i <= hostCount; i++) { |
| 179 | - contactPoints.add(scassandras.address(i)); | |
| 179 | + contactPoints.add(scassandras.address(i).getAddress()); | |
| 180 | 180 | } |
| 181 | 181 | final HashMultiset<InetAddress> occurrencesByHost = HashMultiset.create(hostCount); |
| 182 | 182 | for (int i = 0; i < iterations; i++) { |
| 183 | 183 | Cluster cluster = Cluster.builder() |
| 184 | - .addContactPointsWithPorts(contactPoints) | |
| 185 | - .withAddressTranslater(scassandras.addressTranslator()) | |
| 184 | + .addContactPoints(contactPoints) | |
| 185 | + .withPort(scassandras.getBinaryPort()) | |
| 186 | 186 | .withNettyOptions(nonQuietClusterCloseOptions) |
| 187 | 187 | .build(); |
| 188 | 188 |
added driver-core/src/test/java/com/datastax/driver/core/DseCCMClusterTest.java +71 −0
| @@ -0,0 +1,71 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (C) 2012-2015 DataStax Inc. | |
| 3 | + * | |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | + * you may not use this file except in compliance with the License. | |
| 6 | + * You may obtain a copy of the License at | |
| 7 | + * | |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | + * | |
| 10 | + * Unless required by applicable law or agreed to in writing, software | |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | + * See the License for the specific language governing permissions and | |
| 14 | + * limitations under the License. | |
| 15 | + */ | |
| 16 | +package com.datastax.driver.core; | |
| 17 | + | |
| 18 | +import org.testng.annotations.Test; | |
| 19 | + | |
| 20 | +/** | |
| 21 | + * A simple test to validate DSE setups. | |
| 22 | + * <p/> | |
| 23 | + * <h3>Running all tests against DSE</h3> | |
| 24 | + * <p/> | |
| 25 | + * To run tests globally against DSE, set the system property {@code dse} | |
| 26 | + * to {@code true}. | |
| 27 | + * <p/> | |
| 28 | + * When this flag is provided, it is assumed a DSE version is passed under | |
| 29 | + * the system property {@code cassandra.version}. | |
| 30 | + * A mapping for determining C* version from DSE version is described in {@link CCMBridge}. | |
| 31 | + * <p/> | |
| 32 | + * Example usages: | |
| 33 | + * <p/> | |
| 34 | + * DSE 4.8.3: | |
| 35 | + * <pre> | |
| 36 | + * -Ddse -Dcassandra.version=4.8.3 | |
| 37 | + * -Ddse=true -Dcassandra.version=4.8.3 | |
| 38 | + * </pre> | |
| 39 | + * <p/> | |
| 40 | + * Custom local install of DSE 5.0 (using {@code cassandra.directory} instead of {@code cassandra.version}): | |
| 41 | + * <pre> | |
| 42 | + * -Dcassandra.version=5.0 -Ddse -Dcassandra.directory=/path/to/dse | |
| 43 | + * </pre> | |
| 44 | + * <p/> | |
| 45 | + * <h3>Running a specific test against DSE</h3> | |
| 46 | + * <p/> | |
| 47 | + * Set the following properties on the test: | |
| 48 | + * <pre>{@code @CCMConfig(dse = true, version = "4.8.3")}</pre> | |
| 49 | + * | |
| 50 | + * <h3>Supplying DSE credentials</h3> | |
| 51 | + * | |
| 52 | + * Rather than adding system properties for DSE credentials, | |
| 53 | + * DSE tests rely on a recent change in CCM to support providing | |
| 54 | + * credentials via {@code $HOME/.ccm/.dse.ini}. | |
| 55 | + * | |
| 56 | + * The contents of this file need to be formed in this way: | |
| 57 | + * <pre> | |
| 58 | + * [dse_credentials] | |
| 59 | + * dse_username = myusername | |
| 60 | + * dse_password = mypassword | |
| 61 | + * </pre> | |
| 62 | + */ | |
| 63 | +@Test(enabled = false) | |
| 64 | +@CCMConfig(dse = true, version = "4.8.3") | |
| 65 | +public class DseCCMClusterTest extends CCMTestsSupport { | |
| 66 | + | |
| 67 | + @Test(groups = "short") | |
| 68 | + public void should_conenct_to_dse() throws InterruptedException { | |
| 69 | + } | |
| 70 | + | |
| 71 | +} |
modified driver-core/src/test/java/com/datastax/driver/core/EventDebouncerIntegrationTest.java +2 −2
| @@ -44,8 +44,8 @@ | ||
| 44 | 44 | public void should_wait_until_load_balancing_policy_is_fully_initialized() throws InterruptedException { |
| 45 | 45 | TestLoadBalancingPolicy policy = new TestLoadBalancingPolicy(); |
| 46 | 46 | final Cluster cluster = register(createClusterBuilderNoDebouncing() |
| 47 | - .addContactPointsWithPorts(getHostAddress(1)) | |
| 48 | - .withAddressTranslater(getAddressTranslator()) | |
| 47 | + .addContactPoints(ccm.addressOfNode(1).getAddress()) | |
| 48 | + .withPort(ccm.getBinaryPort()) | |
| 49 | 49 | .withLoadBalancingPolicy(policy).build()); |
| 50 | 50 | new Thread() { |
| 51 | 51 | @Override |
modified driver-core/src/test/java/com/datastax/driver/core/HeartbeatTest.java +4 −4
| @@ -57,8 +57,8 @@ | ||
| 57 | 57 | @Test(groups = "long") |
| 58 | 58 | public void should_send_heartbeat_when_connection_is_inactive() throws InterruptedException { |
| 59 | 59 | Cluster cluster = register(Cluster.builder() |
| 60 | - .addContactPointsWithPorts(getHostAddress(1)) | |
| 61 | - .withAddressTranslater(getAddressTranslator()) | |
| 60 | + .addContactPoints(ccm.addressOfNode(1).getAddress()) | |
| 61 | + .withPort(ccm.getBinaryPort()) | |
| 62 | 62 | .withPoolingOptions(new PoolingOptions() |
| 63 | 63 | .setHeartbeatIntervalSeconds(3)) |
| 64 | 64 | .build()); |
| @@ -113,8 +113,8 @@ | ||
| 113 | 113 | @Test(groups = "long") |
| 114 | 114 | public void should_not_send_heartbeat_when_disabled() throws InterruptedException { |
| 115 | 115 | Cluster cluster = register(Cluster.builder() |
| 116 | - .addContactPointsWithPorts(getHostAddress(1)) | |
| 117 | - .withAddressTranslater(getAddressTranslator()) | |
| 116 | + .addContactPoints(ccm.addressOfNode(1).getAddress()) | |
| 117 | + .withPort(ccm.getBinaryPort()) | |
| 118 | 118 | .withPoolingOptions(new PoolingOptions() |
| 119 | 119 | .setHeartbeatIntervalSeconds(0)) |
| 120 | 120 | .build()); |
modified driver-core/src/test/java/com/datastax/driver/core/HostConnectionPoolMultiTest.java +2 −2
| @@ -53,8 +53,8 @@ | ||
| 53 | 53 | PoolingOptions poolingOptions = new PoolingOptions().setConnectionsPerHost(LOCAL, core, max); |
| 54 | 54 | SocketOptions socketOptions = new SocketOptions().setReadTimeoutMillis(1000); |
| 55 | 55 | cluster = Cluster.builder() |
| 56 | - .addContactPointsWithPorts(scassandra.address(1)) | |
| 57 | - .withAddressTranslater(scassandra.addressTranslator()) | |
| 56 | + .addContactPoints(scassandra.address(1).getAddress()) | |
| 57 | + .withPort(scassandra.getBinaryPort()) | |
| 58 | 58 | .withQueryOptions(nonDebouncingQueryOptions()) |
| 59 | 59 | .withPoolingOptions(poolingOptions) |
| 60 | 60 | .withSocketOptions(socketOptions) |
modified driver-core/src/test/java/com/datastax/driver/core/LoadBalancingPolicyBootstrapTest.java +2 −2
| @@ -49,7 +49,7 @@ | ||
| 49 | 49 | |
| 50 | 50 | Cluster cluster = register(Cluster.builder() |
| 51 | 51 | .addContactPointsWithPorts(getInitialContactPoints()) |
| 52 | - .withAddressTranslater(ccm.addressTranslator()) | |
| 52 | + .withPort(ccm.getBinaryPort()) | |
| 53 | 53 | .withLoadBalancingPolicy(policy) |
| 54 | 54 | .build()); |
| 55 | 55 | |
| @@ -91,7 +91,7 @@ | ||
| 91 | 91 | HistoryPolicy policy = new HistoryPolicy(new RoundRobinPolicy()); |
| 92 | 92 | Cluster cluster = register(Cluster.builder() |
| 93 | 93 | .addContactPointsWithPorts(getInitialContactPoints()) |
| 94 | - .withAddressTranslater(ccm.addressTranslator()) | |
| 94 | + .withPort(ccm.getBinaryPort()) | |
| 95 | 95 | .withLoadBalancingPolicy(policy) |
| 96 | 96 | .build()); |
| 97 | 97 |
modified driver-core/src/test/java/com/datastax/driver/core/MetadataTest.java +3 −3
| @@ -55,8 +55,8 @@ | ||
| 55 | 55 | @CCMConfig(numberOfNodes = 3, dirtiesContext = true, createCluster = false) |
| 56 | 56 | public void should_update_metadata_on_topology_change() { |
| 57 | 57 | Cluster cluster = register(Cluster.builder() |
| 58 | - .addContactPointsWithPorts(getHostAddress(1)) | |
| 59 | - .withAddressTranslater(getAddressTranslator()) | |
| 58 | + .addContactPoints(ccm.addressOfNode(1).getAddress()) | |
| 59 | + .withPort(ccm.getBinaryPort()) | |
| 60 | 60 | .withQueryOptions(nonDebouncingQueryOptions()) |
| 61 | 61 | .build()); |
| 62 | 62 | Session session = cluster.connect(); |
| @@ -73,7 +73,7 @@ | ||
| 73 | 73 | Host host3 = TestUtils.findHost(cluster, 3); |
| 74 | 74 | Token host3Token = tokensForHost.get(host3); |
| 75 | 75 | |
| 76 | - ccm.decommissionNode(3); | |
| 76 | + ccm.decommision(3); | |
| 77 | 77 | ccm.remove(3); |
| 78 | 78 | |
| 79 | 79 | // Ensure that the token ranges were updated, there should only be 2 ranges now. |
modified driver-core/src/test/java/com/datastax/driver/core/MissingRpcAddressTest.java +4 −4
| @@ -42,8 +42,8 @@ | ||
| 42 | 42 | deleteNode2RpcAddressFromNode1(); |
| 43 | 43 | // Use only one contact point to make sure that the control connection is on node1 |
| 44 | 44 | Cluster cluster = register(Cluster.builder() |
| 45 | - .addContactPointsWithPorts(getHostAddress(1)) | |
| 46 | - .withAddressTranslater(getAddressTranslator()) | |
| 45 | + .addContactPoints(ccm.addressOfNode(1).getAddress()) | |
| 46 | + .withPort(ccm.getBinaryPort()) | |
| 47 | 47 | .build()); |
| 48 | 48 | cluster.connect(); |
| 49 | 49 | |
| @@ -54,10 +54,10 @@ | ||
| 54 | 54 | |
| 55 | 55 | // Artificially modify the system tables to simulate the missing rpc_address. |
| 56 | 56 | private void deleteNode2RpcAddressFromNode1() throws Exception { |
| 57 | - InetSocketAddress firstHost = getHostAddress(1); | |
| 57 | + InetSocketAddress firstHost = ccm.addressOfNode(1); | |
| 58 | 58 | Cluster cluster = register(Cluster.builder() |
| 59 | 59 | .addContactPointsWithPorts(singleton(firstHost)) |
| 60 | - .withAddressTranslater(getAddressTranslator()) | |
| 60 | + .withPort(ccm.getBinaryPort()) | |
| 61 | 61 | // ensure we will only connect to node1 |
| 62 | 62 | .withLoadBalancingPolicy(new WhiteListPolicy(Policies.defaultLoadBalancingPolicy(), |
| 63 | 63 | Lists.newArrayList(firstHost))) |
modified driver-core/src/test/java/com/datastax/driver/core/NettyOptionsTest.java +1 −1
| @@ -64,7 +64,7 @@ | ||
| 64 | 64 | }).when(nettyOptions).afterChannelInitialized(any(SocketChannel.class)); |
| 65 | 65 | cluster = Cluster.builder() |
| 66 | 66 | .addContactPointsWithPorts(ccm.addressOfNode(1)) |
| 67 | - .withAddressTranslater(ccm.addressTranslator()) | |
| 67 | + .withPort(ccm.getBinaryPort()) | |
| 68 | 68 | .withPoolingOptions(new PoolingOptions() |
| 69 | 69 | .setConnectionsPerHost(HostDistance.LOCAL, coreConnections, coreConnections) |
| 70 | 70 | ) |
modified driver-core/src/test/java/com/datastax/driver/core/NodeRefreshDebouncerTest.java +2 −2
| @@ -43,8 +43,8 @@ | ||
| 43 | 43 | int refreshNodeInterval = 30000; |
| 44 | 44 | QueryOptions queryOptions = new QueryOptions().setRefreshNodeIntervalMillis(refreshNodeInterval); |
| 45 | 45 | Cluster cluster = register(Cluster.builder() |
| 46 | - .addContactPointsWithPorts(getHostAddress(1)) | |
| 47 | - .withAddressTranslater(getAddressTranslator()) | |
| 46 | + .addContactPoints(ccm.addressOfNode(1).getAddress()) | |
| 47 | + .withPort(ccm.getBinaryPort()) | |
| 48 | 48 | .withQueryOptions(queryOptions) |
| 49 | 49 | .build()); |
| 50 | 50 | cluster.connect(); |
modified driver-core/src/test/java/com/datastax/driver/core/QueryOptionsTest.java +2 −2
| @@ -49,8 +49,8 @@ | ||
| 49 | 49 | queryOptions = new QueryOptions(); |
| 50 | 50 | loadBalancingPolicy = new SortingLoadBalancingPolicy(); |
| 51 | 51 | cluster = Cluster.builder() |
| 52 | - .addContactPointsWithPorts(scassandra.address(2)) | |
| 53 | - .withAddressTranslater(scassandra.addressTranslator()) | |
| 52 | + .addContactPoints(scassandra.address(2).getAddress()) | |
| 53 | + .withPort(scassandra.getBinaryPort()) | |
| 54 | 54 | .withLoadBalancingPolicy(loadBalancingPolicy) |
| 55 | 55 | .withQueryOptions(queryOptions) |
| 56 | 56 | .withNettyOptions(nonQuietClusterCloseOptions) |
modified driver-core/src/test/java/com/datastax/driver/core/RecommissionedNodeTest.java +8 −8
| @@ -51,8 +51,8 @@ | ||
| 51 | 51 | |
| 52 | 52 | // Now start the driver that will connect to node2 and node3, and consider node1 down |
| 53 | 53 | mainCluster = Cluster.builder() |
| 54 | - .addContactPointsWithPorts(mainCcm.addressOfNode(2)) | |
| 55 | - .withAddressTranslater(mainCcm.addressTranslator()) | |
| 54 | + .addContactPoints(mainCcm.addressOfNode(2).getAddress()) | |
| 55 | + .withPort(mainCcm.getBinaryPort()) | |
| 56 | 56 | .withQueryOptions(nonDebouncingQueryOptions()).build(); |
| 57 | 57 | mainCluster.connect(); |
| 58 | 58 | waitForCountUpHosts(mainCluster, 2); |
| @@ -80,8 +80,8 @@ | ||
| 80 | 80 | |
| 81 | 81 | // Start the driver, the control connection will be on node2 |
| 82 | 82 | mainCluster = Cluster.builder() |
| 83 | - .addContactPointsWithPorts(mainCcm.addressOfNode(2)) | |
| 84 | - .withAddressTranslater(mainCcm.addressTranslator()) | |
| 83 | + .addContactPoints(mainCcm.addressOfNode(2).getAddress()) | |
| 84 | + .withPort(mainCcm.getBinaryPort()) | |
| 85 | 85 | .withQueryOptions(nonDebouncingQueryOptions()).build(); |
| 86 | 86 | mainCluster.connect(); |
| 87 | 87 | waitForCountUpHosts(mainCluster, 1); |
| @@ -118,8 +118,8 @@ | ||
| 118 | 118 | |
| 119 | 119 | // Start the driver, it should only connect to node 2 |
| 120 | 120 | mainCluster = Cluster.builder() |
| 121 | - .addContactPointsWithPorts(mainCcm.addressOfNode(2)) | |
| 122 | - .withAddressTranslater(mainCcm.addressTranslator()) | |
| 121 | + .addContactPoints(mainCcm.addressOfNode(2).getAddress()) | |
| 122 | + .withPort(mainCcm.getBinaryPort()) | |
| 123 | 123 | .withQueryOptions(nonDebouncingQueryOptions()).build(); |
| 124 | 124 | |
| 125 | 125 | // When we first initialize the Cluster, all hosts are marked UP |
| @@ -154,8 +154,8 @@ | ||
| 154 | 154 | |
| 155 | 155 | // Start the driver, it should only connect to node 2 |
| 156 | 156 | mainCluster = Cluster.builder() |
| 157 | - .addContactPointsWithPorts(mainCcm.addressOfNode(2)) | |
| 158 | - .withAddressTranslater(mainCcm.addressTranslator()) | |
| 157 | + .addContactPoints(mainCcm.addressOfNode(2).getAddress()) | |
| 158 | + .withPort(mainCcm.getBinaryPort()) | |
| 159 | 159 | .withQueryOptions(nonDebouncingQueryOptions()).build(); |
| 160 | 160 | |
| 161 | 161 | // Create a session. This will try to open a pool to node 1 and find that it doesn't support protocol version. |
modified driver-core/src/test/java/com/datastax/driver/core/ReconnectionTest.java +5 −5
| @@ -51,7 +51,7 @@ | ||
| 51 | 51 | public void should_reconnect_after_full_connectivity_loss() throws InterruptedException { |
| 52 | 52 | Cluster cluster = register(Cluster.builder() |
| 53 | 53 | .addContactPointsWithPorts(ccm.addressOfNode(1)) |
| 54 | - .withAddressTranslater(ccm.addressTranslator()) | |
| 54 | + .withPort(ccm.getBinaryPort()) | |
| 55 | 55 | .withReconnectionPolicy(new ConstantReconnectionPolicy(reconnectionDelayMillis)) |
| 56 | 56 | .build()); |
| 57 | 57 | cluster.connect(); |
| @@ -90,7 +90,7 @@ | ||
| 90 | 90 | CountingAuthProvider authProvider = new CountingAuthProvider("cassandra", "cassandra"); |
| 91 | 91 | Cluster cluster = register(Cluster.builder() |
| 92 | 92 | .addContactPointsWithPorts(ccm.addressOfNode(1)) |
| 93 | - .withAddressTranslater(ccm.addressTranslator()) | |
| 93 | + .withPort(ccm.getBinaryPort()) | |
| 94 | 94 | // Start with the correct auth so that we can initialize the server |
| 95 | 95 | .withAuthProvider(authProvider) |
| 96 | 96 | .withReconnectionPolicy(reconnectionPolicy) |
| @@ -131,7 +131,7 @@ | ||
| 131 | 131 | |
| 132 | 132 | Cluster cluster = register(Cluster.builder() |
| 133 | 133 | .addContactPointsWithPorts(ccm.addressOfNode(1)) |
| 134 | - .withAddressTranslater(ccm.addressTranslator()) | |
| 134 | + .withPort(ccm.getBinaryPort()) | |
| 135 | 135 | .withReconnectionPolicy(reconnectionPolicy).build()); |
| 136 | 136 | cluster.connect(); |
| 137 | 137 | |
| @@ -159,7 +159,7 @@ | ||
| 159 | 159 | TogglabePolicy loadBalancingPolicy = new TogglabePolicy(new RoundRobinPolicy()); |
| 160 | 160 | Cluster cluster = register(Cluster.builder() |
| 161 | 161 | .addContactPointsWithPorts(ccm.addressOfNode(1)) |
| 162 | - .withAddressTranslater(ccm.addressTranslator()) | |
| 162 | + .withPort(ccm.getBinaryPort()) | |
| 163 | 163 | .withLoadBalancingPolicy(loadBalancingPolicy) |
| 164 | 164 | .withReconnectionPolicy(new ConstantReconnectionPolicy(reconnectionDelayMillis)) |
| 165 | 165 | .build()); |
| @@ -215,7 +215,7 @@ | ||
| 215 | 215 | SocketOptions socketOptions = spy(new SocketOptions()); |
| 216 | 216 | Cluster cluster = register(Cluster.builder() |
| 217 | 217 | .addContactPointsWithPorts(ccm.addressOfNode(1)) |
| 218 | - .withAddressTranslater(ccm.addressTranslator()) | |
| 218 | + .withPort(ccm.getBinaryPort()) | |
| 219 | 219 | .withReconnectionPolicy(new ConstantReconnectionPolicy(5000)) |
| 220 | 220 | .withLoadBalancingPolicy(loadBalancingPolicy) |
| 221 | 221 | .withSocketOptions(socketOptions) |
modified driver-core/src/test/java/com/datastax/driver/core/RefreshConnectedHostTest.java +1 −1
| @@ -43,7 +43,7 @@ | ||
| 43 | 43 | PoolingOptions poolingOptions = Mockito.spy(new PoolingOptions()); |
| 44 | 44 | cluster = register(Cluster.builder() |
| 45 | 45 | .addContactPointsWithPorts(ccm.addressOfNode(1)) |
| 46 | - .withAddressTranslater(ccm.addressTranslator()) | |
| 46 | + .withPort(ccm.getBinaryPort()) | |
| 47 | 47 | .withPoolingOptions(poolingOptions) |
| 48 | 48 | .withLoadBalancingPolicy(loadBalancingPolicy) |
| 49 | 49 | .withReconnectionPolicy(new ConstantReconnectionPolicy(1000)) |
modified driver-core/src/test/java/com/datastax/driver/core/SSLEncryptionTest.java +4 −2
| @@ -23,7 +23,9 @@ | ||
| 23 | 23 | |
| 24 | 24 | import static com.datastax.driver.core.Assertions.assertThat; |
| 25 | 25 | import static com.datastax.driver.core.CCMBridge.*; |
| 26 | +import static com.datastax.driver.core.CreateCCM.TestMode.PER_METHOD; | |
| 26 | 27 | |
| 28 | +@CreateCCM(PER_METHOD) | |
| 27 | 29 | @CCMConfig(auth = false) |
| 28 | 30 | public class SSLEncryptionTest extends SSLTestBase { |
| 29 | 31 | |
| @@ -73,7 +75,7 @@ | ||
| 73 | 75 | public void should_not_connect_without_ssl_but_node_uses_ssl() throws Exception { |
| 74 | 76 | Cluster cluster = register(Cluster.builder() |
| 75 | 77 | .addContactPointsWithPorts(this.getInitialContactPoints()) |
| 76 | - .withAddressTranslater(ccm.addressTranslator()) | |
| 78 | + .withPort(ccm.getBinaryPort()) | |
| 77 | 79 | .build()); |
| 78 | 80 | cluster.connect(); |
| 79 | 81 | } |
| @@ -92,7 +94,7 @@ | ||
| 92 | 94 | public void should_reconnect_with_ssl_on_node_up() throws Exception { |
| 93 | 95 | Cluster cluster = register(Cluster.builder() |
| 94 | 96 | .addContactPointsWithPorts(this.getInitialContactPoints()) |
| 95 | - .withAddressTranslater(ccm.addressTranslator()) | |
| 97 | + .withPort(ccm.getBinaryPort()) | |
| 96 | 98 | .withSSL(getSSLOptions(Optional.of(DEFAULT_CLIENT_KEYSTORE_PATH), Optional.of(DEFAULT_CLIENT_TRUSTSTORE_PATH))) |
| 97 | 99 | .build()); |
| 98 | 100 |
modified driver-core/src/test/java/com/datastax/driver/core/SSLTestBase.java +2 −2
| @@ -42,7 +42,7 @@ | ||
| 42 | 42 | protected void connectWithSSLOptions(SSLOptions sslOptions) throws Exception { |
| 43 | 43 | Cluster cluster = register(Cluster.builder() |
| 44 | 44 | .addContactPointsWithPorts(this.getInitialContactPoints()) |
| 45 | - .withAddressTranslater(ccm.addressTranslator()) | |
| 45 | + .withPort(ccm.getBinaryPort()) | |
| 46 | 46 | .withSSL(sslOptions) |
| 47 | 47 | .build()); |
| 48 | 48 | cluster.connect(); |
| @@ -60,7 +60,7 @@ | ||
| 60 | 60 | protected void connectWithSSL() throws Exception { |
| 61 | 61 | Cluster cluster = register(Cluster.builder() |
| 62 | 62 | .addContactPointsWithPorts(this.getInitialContactPoints()) |
| 63 | - .withAddressTranslater(ccm.addressTranslator()) | |
| 63 | + .withPort(ccm.getBinaryPort()) | |
| 64 | 64 | .withSSL() |
| 65 | 65 | .build()); |
| 66 | 66 | cluster.connect(); |
modified driver-core/src/test/java/com/datastax/driver/core/ScassandraCluster.java +4 −22
| @@ -17,7 +17,6 @@ | ||
| 17 | 17 | |
| 18 | 18 | import com.beust.jcommander.internal.Lists; |
| 19 | 19 | import com.beust.jcommander.internal.Maps; |
| 20 | -import com.datastax.driver.core.policies.AddressTranslater; | |
| 21 | 20 | import com.google.common.collect.ImmutableList; |
| 22 | 21 | import com.google.common.collect.ImmutableMap; |
| 23 | 22 | import com.google.common.collect.ImmutableSet; |
| @@ -115,6 +114,10 @@ | ||
| 115 | 114 | return -1; |
| 116 | 115 | } |
| 117 | 116 | |
| 117 | + public int getBinaryPort() { | |
| 118 | + return binaryPort; | |
| 119 | + } | |
| 120 | + | |
| 118 | 121 | public InetSocketAddress address(int node) { |
| 119 | 122 | return new InetSocketAddress(ipPrefix + node, binaryPort); |
| 120 | 123 | } |
| @@ -127,27 +130,6 @@ | ||
| 127 | 130 | return new InetSocketAddress(ipPrefix + ipSuffix, binaryPort); |
| 128 | 131 | } |
| 129 | 132 | |
| 130 | - /** | |
| 131 | - * Returns an {@link AddressTranslater} to use when tests must manually create | |
| 132 | - * {@link Cluster} instances. | |
| 133 | - * <p/> | |
| 134 | - * This translator is necessary because hosts create with this class do not use standard ports. | |
| 135 | - * <p/> | |
| 136 | - * This method should not be called before the test has started, nor after the test is finished. | |
| 137 | - * | |
| 138 | - * @return an {@link AddressTranslater} to use when tests must manually create | |
| 139 | - * {@link Cluster} instances. | |
| 140 | - */ | |
| 141 | - public AddressTranslater addressTranslator() { | |
| 142 | - return new AddressTranslater() { | |
| 143 | - @Override | |
| 144 | - public InetSocketAddress translate(InetSocketAddress address) { | |
| 145 | - return new InetSocketAddress(address.getAddress(), binaryPort); | |
| 146 | - } | |
| 147 | - }; | |
| 148 | - } | |
| 149 | - | |
| 150 | - | |
| 151 | 133 | public Host host(Cluster cluster, int dc, int node) { |
| 152 | 134 | InetAddress address = address(dc, node).getAddress(); |
| 153 | 135 | for (Host host : cluster.getMetadata().getAllHosts()) { |
modified driver-core/src/test/java/com/datastax/driver/core/SchemaChangesCCTest.java +2 −2
| @@ -57,14 +57,14 @@ | ||
| 57 | 57 | Cluster.builder() |
| 58 | 58 | .withLoadBalancingPolicy(lbPolicy) |
| 59 | 59 | .addContactPointsWithPorts(ccm.addressOfNode(1)) |
| 60 | - .withAddressTranslater(ccm.addressTranslator()) | |
| 60 | + .withPort(ccm.getBinaryPort()) | |
| 61 | 61 | .build()); |
| 62 | 62 | // Put cluster2 control connection on node 2 so it doesn't go down (to prevent noise for debugging). |
| 63 | 63 | Cluster cluster2 = register( |
| 64 | 64 | Cluster.builder() |
| 65 | 65 | .withLoadBalancingPolicy(lbPolicy) |
| 66 | 66 | .addContactPointsWithPorts(ccm.addressOfNode(2)) |
| 67 | - .withAddressTranslater(ccm.addressTranslator()) | |
| 67 | + .withPort(ccm.getBinaryPort()) | |
| 68 | 68 | .build()); |
| 69 | 69 | SchemaChangeListener listener = mock(SchemaChangeListener.class); |
| 70 | 70 |
modified driver-core/src/test/java/com/datastax/driver/core/SessionLeakTest.java +4 −4
| @@ -40,8 +40,8 @@ | ||
| 40 | 40 | channelMonitor = new SocketChannelMonitor(); |
| 41 | 41 | channelMonitor.reportAtFixedInterval(1, TimeUnit.SECONDS); |
| 42 | 42 | cluster = register(Cluster.builder() |
| 43 | - .addContactPointsWithPorts(getHostAddress(1)) | |
| 44 | - .withAddressTranslater(getAddressTranslator()) | |
| 43 | + .addContactPoints(ccm.addressOfNode(1).getAddress()) | |
| 44 | + .withPort(ccm.getBinaryPort()) | |
| 45 | 45 | .withNettyOptions(channelMonitor.nettyOptions()) |
| 46 | 46 | .withQueryOptions(nonDebouncingQueryOptions()) |
| 47 | 47 | .build()); |
| @@ -96,8 +96,8 @@ | ||
| 96 | 96 | channelMonitor = new SocketChannelMonitor(); |
| 97 | 97 | channelMonitor.reportAtFixedInterval(1, TimeUnit.SECONDS); |
| 98 | 98 | cluster = register(Cluster.builder() |
| 99 | - .addContactPointsWithPorts(getHostAddress(1)) | |
| 100 | - .withAddressTranslater(getAddressTranslator()) | |
| 99 | + .addContactPoints(ccm.addressOfNode(1).getAddress()) | |
| 100 | + .withPort(ccm.getBinaryPort()) | |
| 101 | 101 | .withNettyOptions(channelMonitor.nettyOptions()) |
| 102 | 102 | .build()); |
| 103 | 103 | cluster.init(); |
modified driver-core/src/test/java/com/datastax/driver/core/SpeculativeExecutionTest.java +4 −4
| @@ -50,8 +50,8 @@ | ||
| 50 | 50 | |
| 51 | 51 | loadBalancingPolicy = new SortingLoadBalancingPolicy(); |
| 52 | 52 | cluster = Cluster.builder() |
| 53 | - .addContactPointsWithPorts(scassandras.address(2)) | |
| 54 | - .withAddressTranslater(scassandras.addressTranslator()) | |
| 53 | + .addContactPoints(scassandras.address(2).getAddress()) | |
| 54 | + .withPort(scassandras.getBinaryPort()) | |
| 55 | 55 | .withLoadBalancingPolicy(loadBalancingPolicy) |
| 56 | 56 | .withSpeculativeExecutionPolicy(new ConstantSpeculativeExecutionPolicy(speculativeExecutionDelay, 1)) |
| 57 | 57 | .withQueryOptions(new QueryOptions().setDefaultIdempotence(true)) |
| @@ -201,8 +201,8 @@ | ||
| 201 | 201 | SpeculativeExecutionPolicy mockPolicy = mock(SpeculativeExecutionPolicy.class); |
| 202 | 202 | |
| 203 | 203 | Cluster cluster = Cluster.builder() |
| 204 | - .addContactPointsWithPorts(scassandras.address(2)) | |
| 205 | - .withAddressTranslater(scassandras.addressTranslator()) | |
| 204 | + .addContactPoints(scassandras.address(2).getAddress()) | |
| 205 | + .withPort(scassandras.getBinaryPort()) | |
| 206 | 206 | .withSpeculativeExecutionPolicy(mockPolicy) |
| 207 | 207 | .build(); |
| 208 | 208 |
modified driver-core/src/test/java/com/datastax/driver/core/StateListenerTest.java +1 −1
| @@ -51,7 +51,7 @@ | ||
| 51 | 51 | listener.waitForEvent(); |
| 52 | 52 | |
| 53 | 53 | listener.setExpectedEvent(REMOVE); |
| 54 | - ccm.decommissionNode(2); | |
| 54 | + ccm.decommision(2); | |
| 55 | 55 | listener.waitForEvent(); |
| 56 | 56 | } |
| 57 | 57 |
modified driver-core/src/test/java/com/datastax/driver/core/TestUtils.java +2 −2
| @@ -581,12 +581,12 @@ | ||
| 581 | 581 | /** |
| 582 | 582 | * @return a {@link Cluster} instance that connects only to the control host of the given cluster. |
| 583 | 583 | */ |
| 584 | - public static Cluster buildControlCluster(Cluster cluster, CCMBridge ccm) { | |
| 584 | + public static Cluster buildControlCluster(Cluster cluster, CCMAccess ccm) { | |
| 585 | 585 | Host controlHost = cluster.manager.controlConnection.connectedHost(); |
| 586 | 586 | List<InetSocketAddress> singleAddress = Collections.singletonList(controlHost.getSocketAddress()); |
| 587 | 587 | return Cluster.builder() |
| 588 | 588 | .addContactPointsWithPorts(singleAddress) |
| 589 | - .withAddressTranslater(ccm.addressTranslator()) | |
| 589 | + .withPort(ccm.getBinaryPort()) | |
| 590 | 590 | .withLoadBalancingPolicy(new WhiteListPolicy(new RoundRobinPolicy(), singleAddress)) |
| 591 | 591 | .build(); |
| 592 | 592 | } |
modified driver-core/src/test/java/com/datastax/driver/core/exceptions/ExceptionsScassandraTest.java +2 −2
| @@ -48,8 +48,8 @@ | ||
| 48 | 48 | @BeforeMethod(groups = "short") |
| 49 | 49 | public void beforeMethod() { |
| 50 | 50 | cluster = Cluster.builder() |
| 51 | - .addContactPointsWithPorts(scassandras.address(1)) | |
| 52 | - .withAddressTranslater(scassandras.addressTranslator()) | |
| 51 | + .addContactPoints(scassandras.address(1).getAddress()) | |
| 52 | + .withPort(scassandras.getBinaryPort()) | |
| 53 | 53 | .withRetryPolicy(FallthroughRetryPolicy.INSTANCE) |
| 54 | 54 | .build(); |
| 55 | 55 | session = cluster.connect(); |
modified driver-core/src/test/java/com/datastax/driver/core/exceptions/ExceptionsTest.java +4 −4
| @@ -66,8 +66,8 @@ | ||
| 66 | 66 | assertEquals(e.getKeyspace(), keyspace.toLowerCase()); |
| 67 | 67 | assertEquals(e.getTable(), null); |
| 68 | 68 | assertEquals(e.wasTableCreation(), false); |
| 69 | - assertEquals(e.getHost(), getHostAddress(1).getAddress()); | |
| 70 | - assertEquals(e.getAddress(), getHostAddress(1)); | |
| 69 | + assertEquals(e.getHost(), ccm.addressOfNode(1).getAddress()); | |
| 70 | + assertEquals(e.getAddress(), ccm.addressOfNode(1)); | |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | session.execute(cqlCommands[1]); |
| @@ -80,8 +80,8 @@ | ||
| 80 | 80 | assertEquals(e.getKeyspace(), keyspace.toLowerCase()); |
| 81 | 81 | assertEquals(e.getTable(), table.toLowerCase()); |
| 82 | 82 | assertEquals(e.wasTableCreation(), true); |
| 83 | - assertEquals(e.getHost(), getHostAddress(1).getAddress()); | |
| 84 | - assertEquals(e.getAddress(), getHostAddress(1)); | |
| 83 | + assertEquals(e.getHost(), ccm.addressOfNode(1).getAddress()); | |
| 84 | + assertEquals(e.getAddress(), ccm.addressOfNode(1)); | |
| 85 | 85 | } |
| 86 | 86 | } |
| 87 | 87 |
modified driver-core/src/test/java/com/datastax/driver/core/policies/AbstractRetryPolicyIntegrationTest.java +2 −2
| @@ -61,8 +61,8 @@ | ||
| 61 | 61 | scassandras.init(); |
| 62 | 62 | |
| 63 | 63 | cluster = Cluster.builder() |
| 64 | - .addContactPointsWithPorts(scassandras.address(1)) | |
| 65 | - .withAddressTranslater(scassandras.addressTranslator()) | |
| 64 | + .addContactPoints(scassandras.address(1).getAddress()) | |
| 65 | + .withPort(scassandras.getBinaryPort()) | |
| 66 | 66 | .withRetryPolicy(retryPolicy) |
| 67 | 67 | .withLoadBalancingPolicy(new SortingLoadBalancingPolicy()) |
| 68 | 68 | .withNettyOptions(nonQuietClusterCloseOptions) |
modified driver-core/src/test/java/com/datastax/driver/core/policies/CloseableLoadBalancingPolicyTest.java +1 −1
| @@ -41,7 +41,7 @@ | ||
| 41 | 41 | public Cluster.Builder createClusterBuilder() { |
| 42 | 42 | policy = new CloseMonitoringPolicy(Policies.defaultLoadBalancingPolicy()); |
| 43 | 43 | return Cluster.builder() |
| 44 | - .addContactPointsWithPorts(getHostAddress(1)) | |
| 44 | + .addContactPoints(ccm.addressOfNode(1).getAddress()) | |
| 45 | 45 | .withLoadBalancingPolicy(policy); |
| 46 | 46 | } |
| 47 | 47 |
modified driver-core/src/test/java/com/datastax/driver/core/policies/DCAwareRoundRobinPolicyTest.java +22 −22
| @@ -81,8 +81,8 @@ | ||
| 81 | 81 | // given: a 10 node 2 DC cluster. |
| 82 | 82 | ScassandraCluster sCluster = ScassandraCluster.builder().withNodes(5, 5).build(); |
| 83 | 83 | Cluster cluster = builder() |
| 84 | - .addContactPointsWithPorts(sCluster.address(1, 1)) | |
| 85 | - .withAddressTranslater(sCluster.addressTranslator()) | |
| 84 | + .addContactPoints(sCluster.address(1, 1).getAddress()) | |
| 85 | + .withPort(sCluster.getBinaryPort()) | |
| 86 | 86 | .withLoadBalancingPolicy(DCAwareRoundRobinPolicy.builder().withLocalDc(datacenter(1)).build()) |
| 87 | 87 | .build(); |
| 88 | 88 | try { |
| @@ -114,8 +114,8 @@ | ||
| 114 | 114 | // given: a 10 node 2 DC cluster with DC policy with 2 remote hosts. |
| 115 | 115 | ScassandraCluster sCluster = ScassandraCluster.builder().withNodes(5, 5).build(); |
| 116 | 116 | Cluster cluster = builder() |
| 117 | - .addContactPointsWithPorts(sCluster.address(1, 1)) | |
| 118 | - .withAddressTranslater(sCluster.addressTranslator()) | |
| 117 | + .addContactPoints(sCluster.address(1, 1).getAddress()) | |
| 118 | + .withPort(sCluster.getBinaryPort()) | |
| 119 | 119 | .withLoadBalancingPolicy(DCAwareRoundRobinPolicy.builder().withLocalDc(datacenter(1)).withUsedHostsPerRemoteDc(2).build()) |
| 120 | 120 | .build(); |
| 121 | 121 | |
| @@ -157,8 +157,8 @@ | ||
| 157 | 157 | // given: a 10 node 2 DC cluster with DC policy with 2 remote hosts. |
| 158 | 158 | ScassandraCluster sCluster = ScassandraCluster.builder().withNodes(5, 5).build(); |
| 159 | 159 | Cluster cluster = builder() |
| 160 | - .addContactPointsWithPorts(sCluster.address(1, 1)) | |
| 161 | - .withAddressTranslater(sCluster.addressTranslator()) | |
| 160 | + .addContactPoints(sCluster.address(1, 1).getAddress()) | |
| 161 | + .withPort(sCluster.getBinaryPort()) | |
| 162 | 162 | .withLoadBalancingPolicy(DCAwareRoundRobinPolicy.builder().withUsedHostsPerRemoteDc(2).build()) |
| 163 | 163 | .build(); |
| 164 | 164 | |
| @@ -201,8 +201,8 @@ | ||
| 201 | 201 | // a local consistency level. |
| 202 | 202 | ScassandraCluster sCluster = ScassandraCluster.builder().withNodes(2, 2).build(); |
| 203 | 203 | Cluster cluster = builder() |
| 204 | - .addContactPointsWithPorts(sCluster.address(1, 1)) | |
| 205 | - .withAddressTranslater(sCluster.addressTranslator()) | |
| 204 | + .addContactPoints(sCluster.address(1, 1).getAddress()) | |
| 205 | + .withPort(sCluster.getBinaryPort()) | |
| 206 | 206 | .withLoadBalancingPolicy(DCAwareRoundRobinPolicy.builder().withUsedHostsPerRemoteDc(2).build()) |
| 207 | 207 | .build(); |
| 208 | 208 | |
| @@ -247,8 +247,8 @@ | ||
| 247 | 247 | // a local consistency level. |
| 248 | 248 | ScassandraCluster sCluster = ScassandraCluster.builder().withNodes(2, 2).build(); |
| 249 | 249 | Cluster cluster = builder() |
| 250 | - .addContactPointsWithPorts(sCluster.address(1, 1)) | |
| 251 | - .withAddressTranslater(sCluster.addressTranslator()) | |
| 250 | + .addContactPoints(sCluster.address(1, 1).getAddress()) | |
| 251 | + .withPort(sCluster.getBinaryPort()) | |
| 252 | 252 | .withLoadBalancingPolicy(DCAwareRoundRobinPolicy.builder() |
| 253 | 253 | .allowRemoteDCsForLocalConsistencyLevel() |
| 254 | 254 | .withUsedHostsPerRemoteDc(2).build()) |
| @@ -293,8 +293,8 @@ | ||
| 293 | 293 | DCAwareRoundRobinPolicy.builder().withUsedHostsPerRemoteDc(2).build(), |
| 294 | 294 | Lists.newArrayList(datacenter(2))); |
| 295 | 295 | Cluster cluster = builder() |
| 296 | - .addContactPointsWithPorts(sCluster.address(1, 1)) | |
| 297 | - .withAddressTranslater(sCluster.addressTranslator()) | |
| 296 | + .addContactPoints(sCluster.address(1, 1).getAddress()) | |
| 297 | + .withPort(sCluster.getBinaryPort()) | |
| 298 | 298 | .withLoadBalancingPolicy(loadBalancingPolicy) |
| 299 | 299 | .build(); |
| 300 | 300 | |
| @@ -347,8 +347,8 @@ | ||
| 347 | 347 | DCAwareRoundRobinPolicy.builder().withUsedHostsPerRemoteDc(2).build(), |
| 348 | 348 | Lists.newArrayList(datacenter(1), datacenter(2))); |
| 349 | 349 | Cluster cluster = builder() |
| 350 | - .addContactPointsWithPorts(sCluster.address(1, 1)) | |
| 351 | - .withAddressTranslater(sCluster.addressTranslator()) | |
| 350 | + .addContactPoints(sCluster.address(1, 1).getAddress()) | |
| 351 | + .withPort(sCluster.getBinaryPort()) | |
| 352 | 352 | .withLoadBalancingPolicy(loadBalancingPolicy) |
| 353 | 353 | .build(); |
| 354 | 354 | |
| @@ -399,8 +399,8 @@ | ||
| 399 | 399 | DCAwareRoundRobinPolicy policy = spy(DCAwareRoundRobinPolicy.builder().build()); |
| 400 | 400 | ScassandraCluster sCluster = ScassandraCluster.builder().withNodes(2, 2).build(); |
| 401 | 401 | Cluster cluster = builder() |
| 402 | - .addContactPointsWithPorts(sCluster.address(1, 1)) | |
| 403 | - .withAddressTranslater(sCluster.addressTranslator()) | |
| 402 | + .addContactPoints(sCluster.address(1, 1).getAddress()) | |
| 403 | + .withPort(sCluster.getBinaryPort()) | |
| 404 | 404 | .withLoadBalancingPolicy(policy) |
| 405 | 405 | .build(); |
| 406 | 406 | |
| @@ -439,8 +439,8 @@ | ||
| 439 | 439 | DCAwareRoundRobinPolicy policy = spy(DCAwareRoundRobinPolicy.builder().build()); |
| 440 | 440 | ScassandraCluster sCluster = ScassandraCluster.builder().withNodes(2, 2).build(); |
| 441 | 441 | Cluster cluster = builder() |
| 442 | - .addContactPointsWithPorts(sCluster.address(1, 1), sCluster.address(2, 1)) | |
| 443 | - .withAddressTranslater(sCluster.addressTranslator()) | |
| 442 | + .addContactPoints(sCluster.address(1, 1).getAddress(), sCluster.address(2, 1).getAddress()) | |
| 443 | + .withPort(sCluster.getBinaryPort()) | |
| 444 | 444 | .withLoadBalancingPolicy(policy) |
| 445 | 445 | .build(); |
| 446 | 446 | |
| @@ -478,8 +478,8 @@ | ||
| 478 | 478 | ScassandraCluster sCluster = ScassandraCluster.builder().withNodes(2, 2).build(); |
| 479 | 479 | DCAwareRoundRobinPolicy policy = spy(DCAwareRoundRobinPolicy.builder().withLocalDc(datacenter(1)).build()); |
| 480 | 480 | Cluster cluster = builder() |
| 481 | - .addContactPointsWithPorts(sCluster.address(1, 1)) | |
| 482 | - .withAddressTranslater(sCluster.addressTranslator()) | |
| 481 | + .addContactPoints(sCluster.address(1, 1).getAddress()) | |
| 482 | + .withPort(sCluster.getBinaryPort()) | |
| 483 | 483 | .withLoadBalancingPolicy(policy) |
| 484 | 484 | .build(); |
| 485 | 485 | |
| @@ -518,8 +518,8 @@ | ||
| 518 | 518 | ScassandraCluster sCluster = ScassandraCluster.builder().withNodes(2, 2).build(); |
| 519 | 519 | DCAwareRoundRobinPolicy policy = spy(DCAwareRoundRobinPolicy.builder().withLocalDc(datacenter(3)).build()); |
| 520 | 520 | Cluster cluster = builder() |
| 521 | - .addContactPointsWithPorts(sCluster.address(1, 1), sCluster.address(2, 1)) | |
| 522 | - .withAddressTranslater(sCluster.addressTranslator()) | |
| 521 | + .addContactPoints(sCluster.address(1, 1).getAddress(), sCluster.address(2, 1).getAddress()) | |
| 522 | + .withPort(sCluster.getBinaryPort()) | |
| 523 | 523 | .withLoadBalancingPolicy(policy) |
| 524 | 524 | .build(); |
| 525 | 525 |
modified driver-core/src/test/java/com/datastax/driver/core/policies/DefaultRetryPolicyIntegrationTest.java +2 −2
| @@ -106,8 +106,8 @@ | ||
| 106 | 106 | Collections.singletonList(host1.getSocketAddress())); |
| 107 | 107 | |
| 108 | 108 | Cluster whiteListedCluster = Cluster.builder() |
| 109 | - .addContactPointsWithPorts(scassandras.address(1)) | |
| 110 | - .withAddressTranslater(scassandras.addressTranslator()) | |
| 109 | + .addContactPoints(scassandras.address(1).getAddress()) | |
| 110 | + .withPort(scassandras.getBinaryPort()) | |
| 111 | 111 | .withRetryPolicy(retryPolicy) |
| 112 | 112 | .withLoadBalancingPolicy(firstHostOnlyPolicy) |
| 113 | 113 | .build(); |
modified driver-core/src/test/java/com/datastax/driver/core/policies/DowngradingConsistencyRetryPolicyIntegrationTest.java +2 −2
| @@ -43,8 +43,8 @@ | ||
| 43 | 43 | @Test(groups = "long") |
| 44 | 44 | public void should_downgrade_if_not_enough_replicas_for_requested_CL() { |
| 45 | 45 | Cluster cluster = register(Cluster.builder() |
| 46 | - .addContactPointsWithPorts(getHostAddress(1)) | |
| 47 | - .withAddressTranslater(getAddressTranslator()) | |
| 46 | + .addContactPoints(ccm.addressOfNode(1).getAddress()) | |
| 47 | + .withPort(ccm.getBinaryPort()) | |
| 48 | 48 | .withRetryPolicy(Mockito.spy(DowngradingConsistencyRetryPolicy.INSTANCE)) |
| 49 | 49 | .build()); |
| 50 | 50 | Session session = cluster.connect(); |
modified driver-core/src/test/java/com/datastax/driver/core/policies/RoundRobinPolicyTest.java +6 −6
| @@ -59,8 +59,8 @@ | ||
| 59 | 59 | ScassandraCluster sCluster = ScassandraCluster.builder().withNodes(5).build(); |
| 60 | 60 | |
| 61 | 61 | Cluster cluster = Cluster.builder() |
| 62 | - .addContactPointsWithPorts(sCluster.address(1)) | |
| 63 | - .withAddressTranslater(sCluster.addressTranslator()) | |
| 62 | + .addContactPoints(sCluster.address(1).getAddress()) | |
| 63 | + .withPort(sCluster.getBinaryPort()) | |
| 64 | 64 | .withLoadBalancingPolicy(new RoundRobinPolicy()) |
| 65 | 65 | .withNettyOptions(nonQuietClusterCloseOptions) |
| 66 | 66 | .build(); |
| @@ -95,8 +95,8 @@ | ||
| 95 | 95 | ScassandraCluster sCluster = ScassandraCluster.builder().withNodes(2, 2, 2, 2, 2).build(); |
| 96 | 96 | |
| 97 | 97 | Cluster cluster = Cluster.builder() |
| 98 | - .addContactPointsWithPorts(sCluster.address(1)) | |
| 99 | - .withAddressTranslater(sCluster.addressTranslator()) | |
| 98 | + .addContactPoints(sCluster.address(1).getAddress()) | |
| 99 | + .withPort(sCluster.getBinaryPort()) | |
| 100 | 100 | .withLoadBalancingPolicy(new RoundRobinPolicy()) |
| 101 | 101 | .withNettyOptions(nonQuietClusterCloseOptions) |
| 102 | 102 | .build(); |
| @@ -134,8 +134,8 @@ | ||
| 134 | 134 | ScassandraCluster sCluster = ScassandraCluster.builder().withNodes(1, 1).build(); |
| 135 | 135 | |
| 136 | 136 | Cluster cluster = Cluster.builder() |
| 137 | - .addContactPointsWithPorts(sCluster.address(1)) | |
| 138 | - .withAddressTranslater(sCluster.addressTranslator()) | |
| 137 | + .addContactPoints(sCluster.address(1).getAddress()) | |
| 138 | + .withPort(sCluster.getBinaryPort()) | |
| 139 | 139 | .withLoadBalancingPolicy(new RoundRobinPolicy()) |
| 140 | 140 | .withNettyOptions(nonQuietClusterCloseOptions) |
| 141 | 141 | .build(); |
modified driver-core/src/test/java/com/datastax/driver/core/policies/TokenAwarePolicyTest.java +9 −9
| @@ -70,8 +70,8 @@ | ||
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | Cluster cluster = Cluster.builder() |
| 73 | - .addContactPointsWithPorts(sCluster.address(1)) | |
| 74 | - .withAddressTranslater(sCluster.addressTranslator()) | |
| 73 | + .addContactPoints(sCluster.address(1).getAddress()) | |
| 74 | + .withPort(sCluster.getBinaryPort()) | |
| 75 | 75 | .withNettyOptions(nonQuietClusterCloseOptions) |
| 76 | 76 | .withLoadBalancingPolicy(loadBalancingPolicy) |
| 77 | 77 | .build(); |
| @@ -137,8 +137,8 @@ | ||
| 137 | 137 | .withSimpleKeyspace("keyspace", 1) |
| 138 | 138 | .build(); |
| 139 | 139 | Cluster cluster = Cluster.builder() |
| 140 | - .addContactPointsWithPorts(sCluster.address(1)) | |
| 141 | - .withAddressTranslater(sCluster.addressTranslator()) | |
| 140 | + .addContactPoints(sCluster.address(1).getAddress()) | |
| 141 | + .withPort(sCluster.getBinaryPort()) | |
| 142 | 142 | .withNettyOptions(nonQuietClusterCloseOptions) |
| 143 | 143 | .withLoadBalancingPolicy(new TokenAwarePolicy(new RoundRobinPolicy())) |
| 144 | 144 | .build(); |
| @@ -182,8 +182,8 @@ | ||
| 182 | 182 | .withNetworkTopologyKeyspace("keyspace", ImmutableMap.of(1, 1, 2, 1)) |
| 183 | 183 | .build(); |
| 184 | 184 | Cluster cluster = Cluster.builder() |
| 185 | - .addContactPointsWithPorts(sCluster.address(1)) | |
| 186 | - .withAddressTranslater(sCluster.addressTranslator()) | |
| 185 | + .addContactPoints(sCluster.address(1).getAddress()) | |
| 186 | + .withPort(sCluster.getBinaryPort()) | |
| 187 | 187 | .withNettyOptions(nonQuietClusterCloseOptions) |
| 188 | 188 | .withLoadBalancingPolicy(new TokenAwarePolicy(DCAwareRoundRobinPolicy.builder() |
| 189 | 189 | .withLocalDc(ScassandraCluster.datacenter(2)) |
| @@ -230,8 +230,8 @@ | ||
| 230 | 230 | .withSimpleKeyspace("keyspace", 2) |
| 231 | 231 | .build(); |
| 232 | 232 | Cluster cluster = Cluster.builder() |
| 233 | - .addContactPointsWithPorts(sCluster.address(2)) | |
| 234 | - .withAddressTranslater(sCluster.addressTranslator()) | |
| 233 | + .addContactPoints(sCluster.address(2).getAddress()) | |
| 234 | + .withPort(sCluster.getBinaryPort()) | |
| 235 | 235 | .withNettyOptions(nonQuietClusterCloseOptions) |
| 236 | 236 | // Don't shuffle replicas just to keep test deterministic. |
| 237 | 237 | .withLoadBalancingPolicy(new TokenAwarePolicy(new RoundRobinPolicy(), false)) |
| @@ -322,7 +322,7 @@ | ||
| 322 | 322 | Cluster cluster = Cluster.builder() |
| 323 | 323 | .withLoadBalancingPolicy(new TokenAwarePolicy(new RoundRobinPolicy())) |
| 324 | 324 | .addContactPointsWithPorts(ccm.addressOfNode(1)) |
| 325 | - .withAddressTranslater(ccm.addressTranslator()) | |
| 325 | + .withPort(ccm.getBinaryPort()) | |
| 326 | 326 | .build(); |
| 327 | 327 | |
| 328 | 328 | try { |
modified driver-core/src/test/java/com/datastax/driver/core/policies/WhiteListPolicyTest.java +2 −2
| @@ -53,8 +53,8 @@ | ||
| 53 | 53 | List<InetSocketAddress> whiteList = Lists.newArrayList(sCluster.address(3), sCluster.address(5)); |
| 54 | 54 | |
| 55 | 55 | Cluster cluster = Cluster.builder() |
| 56 | - .addContactPointsWithPorts(sCluster.address(5)) | |
| 57 | - .withAddressTranslater(sCluster.addressTranslator()) | |
| 56 | + .addContactPoints(sCluster.address(5).getAddress()) | |
| 57 | + .withPort(sCluster.getBinaryPort()) | |
| 58 | 58 | .withLoadBalancingPolicy(new WhiteListPolicy(new RoundRobinPolicy(), whiteList)) |
| 59 | 59 | .withNettyOptions(nonQuietClusterCloseOptions) |
| 60 | 60 | .build(); |
modified driver-mapping/src/test/java/com/datastax/driver/mapping/UDTFieldMapperTest.java +4 −4
| @@ -40,7 +40,7 @@ | ||
| 40 | 40 | ccm = CCMBridge.builder().build(); |
| 41 | 41 | cluster = Cluster.builder() |
| 42 | 42 | .addContactPointsWithPorts(ccm.addressOfNode(1)) |
| 43 | - .withAddressTranslater(ccm.addressTranslator()) | |
| 43 | + .withPort(ccm.getBinaryPort()) | |
| 44 | 44 | .build(); |
| 45 | 45 | Session session1 = cluster.connect(); |
| 46 | 46 | session1.execute("create schema if not exists java_509 " + |
| @@ -56,7 +56,7 @@ | ||
| 56 | 56 | // Create entities with another connection |
| 57 | 57 | cluster = Cluster.builder() |
| 58 | 58 | .addContactPointsWithPorts(ccm.addressOfNode(1)) |
| 59 | - .withAddressTranslater(ccm.addressTranslator()) | |
| 59 | + .withPort(ccm.getBinaryPort()) | |
| 60 | 60 | .build(); |
| 61 | 61 | Session session2 = cluster.newSession(); |
| 62 | 62 | Mapper<MyHashWithKeyspace> hashMapper = new MappingManager(session2).mapper(MyHashWithKeyspace.class); |
| @@ -93,7 +93,7 @@ | ||
| 93 | 93 | ccm = CCMBridge.builder().build(); |
| 94 | 94 | cluster = Cluster.builder() |
| 95 | 95 | .addContactPointsWithPorts(ccm.addressOfNode(1)) |
| 96 | - .withAddressTranslater(ccm.addressTranslator()) | |
| 96 | + .withPort(ccm.getBinaryPort()) | |
| 97 | 97 | .build(); |
| 98 | 98 | Session session1 = cluster.connect(); |
| 99 | 99 | session1.execute("create schema if not exists java_509 " + |
| @@ -110,7 +110,7 @@ | ||
| 110 | 110 | // Create entities with another connection |
| 111 | 111 | cluster = Cluster.builder() |
| 112 | 112 | .addContactPointsWithPorts(ccm.addressOfNode(1)) |
| 113 | - .withAddressTranslater(ccm.addressTranslator()) | |
| 113 | + .withPort(ccm.getBinaryPort()) | |
| 114 | 114 | .build(); |
| 115 | 115 | Session session2 = cluster.newSession(); |
| 116 | 116 |