Elffuss BraidHub

kikocis/java-driver public

Merge pull request #573 from datastax/2.1-test-fixes

Fixes for CCM tests [2.1]
Changeset446aa287b841361baefe105f672198a0a66d3d98e3c270b33cb756a08be0f6a7
AuthorAlexandre Dutra <adutra@users.noreply.github.com> · 2016-01-16 16:23 +01:00
CommitterAlexandre Dutra <adutra@users.noreply.github.com> · 2016-01-16 16:23 +01:00
Parents5ce316cb6b8b, b4e947eab72f

Browse the files at this changeset

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 @@
1515 */
1616 package com.datastax.driver.core;
1717
18-import com.datastax.driver.core.policies.AddressTranslater;
1918 import com.google.common.base.Joiner;
2019 import com.google.common.base.Throwables;
2120 import com.google.common.collect.ImmutableMap;
21+import com.google.common.collect.ImmutableSet;
2222 import com.google.common.collect.Maps;
2323 import com.google.common.io.ByteStreams;
2424 import com.google.common.io.Closer;
@@ -35,13 +35,13 @@
3535 import static com.datastax.driver.core.TestUtils.executeNoFail;
3636 import static com.datastax.driver.core.TestUtils.findAvailablePort;
3737
38-public class CCMBridge implements Closeable {
38+public class CCMBridge implements CCMAccess {
3939
4040 private static final Logger logger = LoggerFactory.getLogger(CCMBridge.class);
4141
4242 private static final String CASSANDRA_VERSION;
4343
44- private static final String CASSANDRA_INSTALL_ARGS;
44+ private static final Set<String> CASSANDRA_INSTALL_ARGS;
4545
4646 private static final boolean IS_DSE;
4747
@@ -133,23 +133,20 @@
133133 // otherwise if there is a value, parse as boolean.
134134 IS_DSE = dseProperty != null && (dseProperty.isEmpty() || Boolean.parseBoolean(dseProperty));
135135
136- StringBuilder installArgs = new StringBuilder();
136+ ImmutableSet.Builder<String> installArgs = ImmutableSet.builder();
137137 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());
140139 } 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("\"", ""));
143141 } else {
144- installArgs.append("-v ");
145- installArgs.append(CASSANDRA_VERSION);
142+ installArgs.add("-v " + CASSANDRA_VERSION);
146143 }
147144
148145 if (IS_DSE) {
149- installArgs.append(" --dse");
146+ installArgs.add("--dse");
150147 }
151148
152- CASSANDRA_INSTALL_ARGS = installArgs.toString();
149+ CASSANDRA_INSTALL_ARGS = installArgs.build();
153150
154151 // Inherit the current environment.
155152 Map<String, String> envMap = Maps.newHashMap(new ProcessBuilder().environment());
@@ -177,10 +174,10 @@
177174 ENVIRONMENT_MAP = ImmutableMap.copyOf(envMap);
178175
179176 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: {})",
181178 CCMBridge.getDSEVersion(), CCMBridge.getCassandraVersion(), CCMBridge.getInstallArguments());
182179 } 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: {})",
184181 CCMBridge.getCassandraVersion(), CCMBridge.getInstallArguments());
185182 }
186183 }
@@ -212,13 +209,11 @@
212209
213210 private final String jvmArgs;
214211
215- private final int initialNumberOfNodes;
216-
217212 private boolean keepLogs = false;
218213
219214 private boolean closed = false;
220215
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) {
222217 this.clusterName = clusterName;
223218 this.version = version;
224219 this.storagePort = storagePort;
@@ -226,7 +221,6 @@
226221 this.binaryPort = binaryPort;
227222 this.isDSE = isDSE;
228223 this.jvmArgs = jvmArgs;
229- this.initialNumberOfNodes = initialNumberOfNodes;
230224 this.ccmDir = Files.createTempDir();
231225 }
232226
@@ -283,7 +277,7 @@
283277 /**
284278 * @return The install arguments to pass to CCM when creating the cluster.
285279 */
286- public static String getInstallArguments() {
280+ public static Set<String> getInstallArguments() {
287281 return CASSANDRA_INSTALL_ARGS;
288282 }
289283
@@ -291,87 +285,57 @@
291285 return new Builder();
292286 }
293287
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;
305291 }
306292
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);
323296 }
324297
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
332299 public VersionNumber getVersion() {
333300 return version;
334301 }
335302
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
347304 public File getCcmDir() {
348305 return ccmDir;
349306 }
350307
308+ @Override
351309 public File getClusterDir() {
352310 return new File(ccmDir, clusterName);
353311 }
354312
313+ @Override
355314 public File getNodeDir(int n) {
356315 return new File(getClusterDir(), "node" + n);
357316 }
358317
318+ @Override
359319 public File getNodeConfDir(int n) {
360320 return new File(getNodeDir(n), "conf");
361321 }
362322
323+ @Override
363324 public int getStoragePort() {
364325 return storagePort;
365326 }
366327
328+ @Override
367329 public int getThriftPort() {
368330 return thriftPort;
369331 }
370332
333+ @Override
371334 public int getBinaryPort() {
372335 return binaryPort;
373336 }
374337
338+ @Override
375339 public void setKeepLogs(boolean keepLogs) {
376340 this.keepLogs = keepLogs;
377341 }
@@ -407,11 +371,13 @@
407371 logger.debug("Closed: " + this);
408372 }
409373
374+ @Override
410375 public void start() {
411376 logger.debug("Starting: " + this);
412377 execute(CCM_COMMAND + " start --wait-other-notice --wait-for-binary-proto" + jvmArgs);
413378 }
414379
380+ @Override
415381 public synchronized void stop() {
416382 if (closed)
417383 return;
@@ -420,6 +386,7 @@
420386 closed = true;
421387 }
422388
389+ @Override
423390 public synchronized void forceStop() {
424391 if (closed)
425392 return;
@@ -428,36 +395,43 @@
428395 closed = true;
429396 }
430397
398+ @Override
431399 public void start(int n) {
432400 logger.debug(String.format("Starting: node %s (%s%s:%s) in %s", n, TestUtils.IP_PREFIX, n, binaryPort, this));
433401 execute(CCM_COMMAND + " node%d start --wait-other-notice --wait-for-binary-proto" + jvmArgs, n);
434402 }
435403
404+ @Override
436405 public void stop(int n) {
437406 logger.debug(String.format("Stopping: node %s (%s%s:%s) in %s", n, TestUtils.IP_PREFIX, n, binaryPort, this));
438407 execute(CCM_COMMAND + " node%d stop", n);
439408 }
440409
410+ @Override
441411 public void forceStop(int n) {
442412 logger.debug(String.format("Force stopping: node %s (%s%s:%s) in %s", n, TestUtils.IP_PREFIX, n, binaryPort, this));
443413 execute(CCM_COMMAND + " node%d stop --not-gently", n);
444414 }
445415
416+ @Override
446417 public synchronized void remove() {
447418 stop();
448419 logger.debug("Removing: " + this);
449420 execute(CCM_COMMAND + " remove");
450421 }
451422
423+ @Override
452424 public void remove(int n) {
453425 logger.debug(String.format("Removing: node %s (%s%s:%s) from %s", n, TestUtils.IP_PREFIX, n, binaryPort, this));
454426 execute(CCM_COMMAND + " node%d remove", n);
455427 }
456428
429+ @Override
457430 public void add(int n) {
458431 add(1, n);
459432 }
460433
434+ @Override
461435 public void add(int dc, int n) {
462436 logger.debug(String.format("Adding: node %s (%s%s:%s) to %s", n, TestUtils.IP_PREFIX, n, binaryPort, this));
463437 String thriftItf = TestUtils.ipOfNode(n) + ":" + thriftPort;
@@ -468,11 +442,13 @@
468442 n, dc, TestUtils.IP_PREFIX, n, thriftItf, storageItf, binaryItf, TestUtils.findAvailablePort(), remoteLogItf);
469443 }
470444
471- public void decommissionNode(int n) {
445+ @Override
446+ public void decommision(int n) {
472447 logger.debug(String.format("Decommissioning: node %s (%s%s:%s) from %s", n, TestUtils.IP_PREFIX, n, binaryPort, this));
473448 execute(CCM_COMMAND + " node%d decommission", n);
474449 }
475450
451+ @Override
476452 public void updateConfig(Map<String, Object> configs) {
477453 StringBuilder confStr = new StringBuilder();
478454 for (Map.Entry<String, Object> entry : configs.entrySet()) {
@@ -485,6 +461,7 @@
485461 execute(CCM_COMMAND + " updateconf " + confStr);
486462 }
487463
464+ @Override
488465 public void updateDSEConfig(Map<String, Object> configs) {
489466 StringBuilder confStr = new StringBuilder();
490467 for (Map.Entry<String, Object> entry : configs.entrySet()) {
@@ -497,10 +474,12 @@
497474 execute(CCM_COMMAND + " updatedseconf " + confStr);
498475 }
499476
477+ @Override
500478 public void updateNodeConfig(int n, String key, Object value) {
501479 updateNodeConfig(n, ImmutableMap.<String, Object>builder().put(key, value).build());
502480 }
503481
482+ @Override
504483 public void updateNodeConfig(int n, Map<String, Object> configs) {
505484 StringBuilder confStr = new StringBuilder();
506485 for (Map.Entry<String, Object> entry : configs.entrySet()) {
@@ -513,6 +492,7 @@
513492 execute(CCM_COMMAND + " node%s updateconf %s", n, confStr);
514493 }
515494
495+ @Override
516496 public void setWorkload(int node, String workload) {
517497 execute(CCM_COMMAND + " node%d setworkload %s", node, workload);
518498 }
@@ -619,6 +599,12 @@
619599 return "CCM cluster " + clusterName;
620600 }
621601
602+ @Override
603+ protected void finalize() throws Throwable {
604+ close();
605+ super.finalize();
606+ }
607+
622608 /**
623609 * use {@link #builder()} to get an instance
624610 */
@@ -628,8 +614,8 @@
628614 int[] nodes = {1};
629615 private boolean start = true;
630616 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());
633619 private Set<String> jvmArgs = new LinkedHashSet<String>();
634620 private final Map<String, Object> cassandraConfiguration = Maps.newHashMap();
635621 private final Map<String, Object> dseConfiguration = Maps.newHashMap();
@@ -687,6 +673,7 @@
687673 * Sets this cluster to be a DSE cluster (defaults to {@link #isDSE()} if this is never called).
688674 */
689675 public Builder withDSE() {
676+ this.createOptions.add("--dse");
690677 this.isDSE = true;
691678 return this;
692679 }
@@ -696,8 +683,17 @@
696683 *
697684 * Defaults to {@link #getCassandraVersion()}.
698685 */
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;
701697 return this;
702698 }
703699
@@ -752,15 +748,11 @@
752748
753749 public CCMBridge build() {
754750 // be careful NOT to alter internal state (hashCode/equals) during build!
755- int initialNumberOfNodes = 0;
756- for (int nodesPerDc : nodes) {
757- initialNumberOfNodes += nodesPerDc;
758- }
759751 int storagePort = this.storagePort == -1 ? findAvailablePort() : this.storagePort;
760752 int thriftPort = this.thriftPort == -1 ? findAvailablePort() : this.thriftPort;
761753 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());
764756 Runtime.getRuntime().addShutdownHook(new Thread() {
765757 @Override
766758 public void run() {
@@ -795,10 +787,6 @@
795787 result.append(" ").append(clusterName);
796788 result.append(" -i ").append(TestUtils.IP_PREFIX);
797789 result.append(" ");
798- if (cassandraVersion != null)
799- result.append("-v ").append(cassandraVersion);
800- else
801- result.append(CASSANDRA_INSTALL_ARGS);
802790 if (nodes.length > 0) {
803791 result.append(" -n ");
804792 for (int i = 0; i < nodes.length; i++) {
@@ -808,8 +796,7 @@
808796 result.append(node);
809797 }
810798 }
811- if (!createOptions.isEmpty())
812- result.append(" ").append(Joiner.on(" ").join(createOptions));
799+ result.append(" ").append(Joiner.on(" ").join(createOptions));
813800 return result.toString();
814801 }
815802
@@ -879,7 +866,7 @@
879866 if (!jvmArgs.equals(builder.jvmArgs)) return false;
880867 if (!dseConfiguration.equals(builder.dseConfiguration)) return false;
881868 if (!cassandraConfiguration.equals(builder.cassandraConfiguration)) return false;
882- return cassandraVersion.equals(builder.cassandraVersion);
869+ return version.equals(builder.version);
883870 }
884871
885872 @Override
@@ -895,7 +882,7 @@
895882 result = 31 * result + thriftPort;
896883 result = 31 * result + binaryPort;
897884 result = 31 * result + storagePort;
898- result = 31 * result + cassandraVersion.hashCode();
885+ result = 31 * result + version.hashCode();
899886 return result;
900887 }
901888 }
modified driver-core/src/test/java/com/datastax/driver/core/CCMConfig.java +7 −0
@@ -43,6 +43,10 @@
4343 /**
4444 * The C* or DSE version to use; defaults to the version defined by
4545 * 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}.
4650 *
4751 * @return The C* or DSE version to use
4852 * @see CCMBridge#getCassandraVersion()
@@ -51,6 +55,9 @@
5155
5256 /**
5357 * 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}.
5461 *
5562 * @return {@code true} to launch a DSE instance, {@code false} to launch an OSS C* instance (default).
5663 */
modified driver-core/src/test/java/com/datastax/driver/core/CCMTestsSupport.java +295 −59
@@ -16,17 +16,19 @@
1616 package com.datastax.driver.core;
1717
1818 import com.datastax.driver.core.CreateCCM.TestMode;
19-import com.datastax.driver.core.policies.AddressTranslater;
2019 import com.google.common.base.Throwables;
2120 import com.google.common.cache.*;
2221 import com.google.common.collect.Lists;
2322 import com.google.common.io.Closer;
23+import com.google.common.util.concurrent.MoreExecutors;
24+import com.google.common.util.concurrent.ThreadFactoryBuilder;
2425 import org.slf4j.Logger;
2526 import org.slf4j.LoggerFactory;
2627 import org.testng.ITestResult;
2728 import org.testng.annotations.*;
2829
2930 import java.io.Closeable;
31+import java.io.File;
3032 import java.io.IOException;
3133 import java.lang.annotation.Annotation;
3234 import java.lang.reflect.Constructor;
@@ -35,8 +37,7 @@
3537 import java.lang.reflect.ParameterizedType;
3638 import java.net.InetSocketAddress;
3739 import java.util.*;
38-import java.util.concurrent.Callable;
39-import java.util.concurrent.ExecutionException;
40+import java.util.concurrent.*;
4041 import java.util.concurrent.atomic.AtomicInteger;
4142
4243 import static com.datastax.driver.core.CreateCCM.TestMode.PER_CLASS;
@@ -52,6 +53,166 @@
5253
5354 private static final List<String> TEST_GROUPS = Lists.newArrayList("isolated", "short", "long", "stress", "duration");
5455
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+
55216 private static class CCMTestConfig {
56217
57218 private final List<CCMConfig> annotations;
@@ -109,6 +270,7 @@
109270 @SuppressWarnings("SimplifiableIfStatement")
110271 private Map<String, Object> config() {
111272 Map<String, Object> config = new HashMap<String, Object>();
273+ config.put("start_rpc", false);
112274 for (int i = annotations.size() - 1; i == 0; i--) {
113275 CCMConfig ann = annotations.get(i);
114276 addConfigOptions(ann.config(), config);
@@ -202,8 +364,7 @@
202364
203365 private CCMBridge.Builder ccmBuilder() {
204366 if (ccmBuilder == null) {
205- ccmBuilder = CCMBridge.builder()
206- .withNodes(numberOfNodes());
367+ ccmBuilder = CCMBridge.builder().withNodes(numberOfNodes());
207368 if (version() != null)
208369 ccmBuilder.withVersion(version());
209370 if (dse())
@@ -283,31 +444,115 @@
283444 }
284445 }
285446
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+ }
286527 }
287528
288- private static class CCMTestContextLoader extends CacheLoader<CCMBridge.Builder, CCMBridge> {
529+ private static class CCMTestContextLoader extends CacheLoader<CCMTestContextKey, CCMTestContext> {
289530
290531 @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());
293534 }
294535
295536 }
296537
297- private static class CCMTestContextWeigher implements Weigher<CCMBridge.Builder, CCMBridge> {
538+ private static class CCMTestContextWeigher implements Weigher<CCMTestContextKey, CCMTestContext> {
539+
298540 @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;
301543 }
544+
302545 }
303546
304- private static class CCMTestContextRemovalListener implements RemovalListener<CCMBridge.Builder, CCMBridge> {
547+ private static class CCMTestContextRemovalListener implements RemovalListener<CCMTestContextKey, CCMTestContext> {
305548
306549 @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();
311556 }
312557 }
313558
@@ -316,7 +561,11 @@
316561 /**
317562 * A LoadingCache that stores running CCM clusters.
318563 */
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()));
320569
321570 static {
322571 long maximumWeight;
@@ -326,24 +575,29 @@
326575 if (freeMemoryMB < 1000)
327576 LOGGER.warn("Available memory below 1GB: {}MB, CCM clusters might fail to start", freeMemoryMB);
328577 // 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));
331582 } else {
332583 maximumWeight = Integer.parseInt(numberOfNodes);
333584 }
334585 LOGGER.info("Maximum number of running CCM nodes: {}", maximumWeight);
335586 CACHE = CacheBuilder.newBuilder()
336- .initialCapacity(1)
587+ .initialCapacity(3)
337588 .maximumWeight(maximumWeight)
338589 .weigher(new CCMTestContextWeigher())
339590 .removalListener(new CCMTestContextRemovalListener())
340591 .build(new CCMTestContextLoader());
341592 }
593+
342594 private TestMode testMode;
343595
344596 private CCMTestConfig ccmTestConfig;
345597
346- protected CCMBridge ccm;
598+ private CCMTestContext ccmTestContext;
599+
600+ protected CCMAccess ccm;
347601
348602 protected Cluster cluster;
349603
@@ -533,36 +787,6 @@
533787 return contactPoints;
534788 }
535789
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-
566790 /**
567791 * Registers the given {@link Closeable} to be closed at the end of the current test method.
568792 * <p/>
@@ -583,22 +807,32 @@
583807 if (ccmTestConfig.createCcm()) {
584808 if (ccmTestConfig.dirtiesContext()) {
585809 ccm = ccmTestConfig.ccmBuilder().build();
810+ ccmTestContext = new CCMTestContext(ccm, true);
586811 LOGGER.debug("Using dedicated {}", ccm);
587812 } 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;
591821 LOGGER.debug("Reusing {}", ccm);
592822 } else {
593823 try {
594- ccm = CACHE.get(ccmTestConfig.ccmBuilder());
824+ ccmTestContext = CACHE.get(key);
825+ ccm = ccmTestContext.ccm;
595826 LOGGER.debug("Using newly-created {}", ccm);
596827 } catch (ExecutionException e) {
597- Throwables.propagate(e);
828+ throw Throwables.propagate(e);
598829 }
599830 }
831+ this.ccm = new ReadOnlyCCMBridge(ccm);
600832 }
833+ assert ccmTestContext != null;
601834 assert ccm != null;
835+
602836 }
603837 }
604838
@@ -608,7 +842,7 @@
608842 // add contact points only if the provided builder didn't do so
609843 if (builder.getContactPoints().isEmpty())
610844 builder.addContactPointsWithPorts(getInitialContactPoints());
611- builder.withAddressTranslater(ccm.addressTranslator());
845+ builder.withPort(ccm.getBinaryPort());
612846 cluster = register(builder.build());
613847 cluster.init();
614848 }
@@ -649,10 +883,12 @@
649883 }
650884
651885 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();
654889 }
655890 ccmTestConfig = null;
891+ ccmTestContext = null;
656892 ccm = null;
657893 }
658894
modified driver-core/src/test/java/com/datastax/driver/core/ClusterInitTest.java +2 −2
@@ -231,8 +231,8 @@
231231 .forcePeerInfo(1, 2, "release_version", "1.2.19")
232232 .build();
233233 Cluster cluster = Cluster.builder()
234- .addContactPointsWithPorts(scassandraCluster.address(1))
235- .withAddressTranslater(scassandraCluster.addressTranslator())
234+ .addContactPoints(scassandraCluster.address(1).getAddress())
235+ .withPort(scassandraCluster.getBinaryPort())
236236 .withNettyOptions(nonQuietClusterCloseOptions)
237237 .build();
238238
modified driver-core/src/test/java/com/datastax/driver/core/ControlConnectionTest.java +11 −11
@@ -74,8 +74,8 @@
7474
7575 // We pass only the first host as contact point, so we know the control connection will be on this host
7676 cluster = register(Cluster.builder()
77- .addContactPointsWithPorts(getHostAddress(1))
78- .withAddressTranslater(getAddressTranslator())
77+ .addContactPoints(ccm.addressOfNode(1).getAddress())
78+ .withPort(ccm.getBinaryPort())
7979 .withReconnectionPolicy(reconnectionPolicy)
8080 .withLoadBalancingPolicy(loadBalancingPolicy)
8181 .build());
@@ -101,11 +101,11 @@
101101 @CassandraVersion(major = 2.1)
102102 public void should_parse_UDT_definitions_when_using_default_protocol_version() {
103103 Cluster cluster;
104- InetSocketAddress firstHost = getHostAddress(1);
104+ InetSocketAddress firstHost = ccm.addressOfNode(1);
105105 // First driver instance: create UDT
106106 cluster = register(Cluster.builder()
107107 .addContactPointsWithPorts(firstHost)
108- .withAddressTranslater(getAddressTranslator())
108+ .withPort(ccm.getBinaryPort())
109109 .build());
110110 Session session = cluster.connect();
111111 session.execute("create keyspace ks WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1}");
@@ -131,10 +131,10 @@
131131 @Test(groups = "long")
132132 @CCMConfig(numberOfNodes = 3)
133133 public void should_reestablish_if_control_node_decommissioned() throws InterruptedException {
134- InetSocketAddress firstHost = getHostAddress(1);
134+ InetSocketAddress firstHost = ccm.addressOfNode(1);
135135 Cluster cluster = register(Cluster.builder()
136136 .addContactPointsWithPorts(firstHost)
137- .withAddressTranslater(getAddressTranslator())
137+ .withPort(ccm.getBinaryPort())
138138 .withQueryOptions(nonDebouncingQueryOptions())
139139 .build());
140140 cluster.init();
@@ -144,7 +144,7 @@
144144 assertThat(controlHost).isEqualTo(firstHost.getAddress());
145145
146146 // Decommission the node.
147- ccm.decommissionNode(1);
147+ ccm.decommision(1);
148148
149149 // Ensure that the new control connection is not null and it's host is not equal to the decommissioned node.
150150 Host newHost = cluster.manager.controlConnection.connectedHost();
@@ -174,15 +174,15 @@
174174 scassandras.init();
175175
176176 try {
177- Collection<InetSocketAddress> contactPoints = newArrayList();
177+ Collection<InetAddress> contactPoints = newArrayList();
178178 for (int i = 1; i <= hostCount; i++) {
179- contactPoints.add(scassandras.address(i));
179+ contactPoints.add(scassandras.address(i).getAddress());
180180 }
181181 final HashMultiset<InetAddress> occurrencesByHost = HashMultiset.create(hostCount);
182182 for (int i = 0; i < iterations; i++) {
183183 Cluster cluster = Cluster.builder()
184- .addContactPointsWithPorts(contactPoints)
185- .withAddressTranslater(scassandras.addressTranslator())
184+ .addContactPoints(contactPoints)
185+ .withPort(scassandras.getBinaryPort())
186186 .withNettyOptions(nonQuietClusterCloseOptions)
187187 .build();
188188
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 @@
4444 public void should_wait_until_load_balancing_policy_is_fully_initialized() throws InterruptedException {
4545 TestLoadBalancingPolicy policy = new TestLoadBalancingPolicy();
4646 final Cluster cluster = register(createClusterBuilderNoDebouncing()
47- .addContactPointsWithPorts(getHostAddress(1))
48- .withAddressTranslater(getAddressTranslator())
47+ .addContactPoints(ccm.addressOfNode(1).getAddress())
48+ .withPort(ccm.getBinaryPort())
4949 .withLoadBalancingPolicy(policy).build());
5050 new Thread() {
5151 @Override
modified driver-core/src/test/java/com/datastax/driver/core/HeartbeatTest.java +4 −4
@@ -57,8 +57,8 @@
5757 @Test(groups = "long")
5858 public void should_send_heartbeat_when_connection_is_inactive() throws InterruptedException {
5959 Cluster cluster = register(Cluster.builder()
60- .addContactPointsWithPorts(getHostAddress(1))
61- .withAddressTranslater(getAddressTranslator())
60+ .addContactPoints(ccm.addressOfNode(1).getAddress())
61+ .withPort(ccm.getBinaryPort())
6262 .withPoolingOptions(new PoolingOptions()
6363 .setHeartbeatIntervalSeconds(3))
6464 .build());
@@ -113,8 +113,8 @@
113113 @Test(groups = "long")
114114 public void should_not_send_heartbeat_when_disabled() throws InterruptedException {
115115 Cluster cluster = register(Cluster.builder()
116- .addContactPointsWithPorts(getHostAddress(1))
117- .withAddressTranslater(getAddressTranslator())
116+ .addContactPoints(ccm.addressOfNode(1).getAddress())
117+ .withPort(ccm.getBinaryPort())
118118 .withPoolingOptions(new PoolingOptions()
119119 .setHeartbeatIntervalSeconds(0))
120120 .build());
modified driver-core/src/test/java/com/datastax/driver/core/HostConnectionPoolMultiTest.java +2 −2
@@ -53,8 +53,8 @@
5353 PoolingOptions poolingOptions = new PoolingOptions().setConnectionsPerHost(LOCAL, core, max);
5454 SocketOptions socketOptions = new SocketOptions().setReadTimeoutMillis(1000);
5555 cluster = Cluster.builder()
56- .addContactPointsWithPorts(scassandra.address(1))
57- .withAddressTranslater(scassandra.addressTranslator())
56+ .addContactPoints(scassandra.address(1).getAddress())
57+ .withPort(scassandra.getBinaryPort())
5858 .withQueryOptions(nonDebouncingQueryOptions())
5959 .withPoolingOptions(poolingOptions)
6060 .withSocketOptions(socketOptions)
modified driver-core/src/test/java/com/datastax/driver/core/LoadBalancingPolicyBootstrapTest.java +2 −2
@@ -49,7 +49,7 @@
4949
5050 Cluster cluster = register(Cluster.builder()
5151 .addContactPointsWithPorts(getInitialContactPoints())
52- .withAddressTranslater(ccm.addressTranslator())
52+ .withPort(ccm.getBinaryPort())
5353 .withLoadBalancingPolicy(policy)
5454 .build());
5555
@@ -91,7 +91,7 @@
9191 HistoryPolicy policy = new HistoryPolicy(new RoundRobinPolicy());
9292 Cluster cluster = register(Cluster.builder()
9393 .addContactPointsWithPorts(getInitialContactPoints())
94- .withAddressTranslater(ccm.addressTranslator())
94+ .withPort(ccm.getBinaryPort())
9595 .withLoadBalancingPolicy(policy)
9696 .build());
9797
modified driver-core/src/test/java/com/datastax/driver/core/MetadataTest.java +3 −3
@@ -55,8 +55,8 @@
5555 @CCMConfig(numberOfNodes = 3, dirtiesContext = true, createCluster = false)
5656 public void should_update_metadata_on_topology_change() {
5757 Cluster cluster = register(Cluster.builder()
58- .addContactPointsWithPorts(getHostAddress(1))
59- .withAddressTranslater(getAddressTranslator())
58+ .addContactPoints(ccm.addressOfNode(1).getAddress())
59+ .withPort(ccm.getBinaryPort())
6060 .withQueryOptions(nonDebouncingQueryOptions())
6161 .build());
6262 Session session = cluster.connect();
@@ -73,7 +73,7 @@
7373 Host host3 = TestUtils.findHost(cluster, 3);
7474 Token host3Token = tokensForHost.get(host3);
7575
76- ccm.decommissionNode(3);
76+ ccm.decommision(3);
7777 ccm.remove(3);
7878
7979 // 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 @@
4242 deleteNode2RpcAddressFromNode1();
4343 // Use only one contact point to make sure that the control connection is on node1
4444 Cluster cluster = register(Cluster.builder()
45- .addContactPointsWithPorts(getHostAddress(1))
46- .withAddressTranslater(getAddressTranslator())
45+ .addContactPoints(ccm.addressOfNode(1).getAddress())
46+ .withPort(ccm.getBinaryPort())
4747 .build());
4848 cluster.connect();
4949
@@ -54,10 +54,10 @@
5454
5555 // Artificially modify the system tables to simulate the missing rpc_address.
5656 private void deleteNode2RpcAddressFromNode1() throws Exception {
57- InetSocketAddress firstHost = getHostAddress(1);
57+ InetSocketAddress firstHost = ccm.addressOfNode(1);
5858 Cluster cluster = register(Cluster.builder()
5959 .addContactPointsWithPorts(singleton(firstHost))
60- .withAddressTranslater(getAddressTranslator())
60+ .withPort(ccm.getBinaryPort())
6161 // ensure we will only connect to node1
6262 .withLoadBalancingPolicy(new WhiteListPolicy(Policies.defaultLoadBalancingPolicy(),
6363 Lists.newArrayList(firstHost)))
modified driver-core/src/test/java/com/datastax/driver/core/NettyOptionsTest.java +1 −1
@@ -64,7 +64,7 @@
6464 }).when(nettyOptions).afterChannelInitialized(any(SocketChannel.class));
6565 cluster = Cluster.builder()
6666 .addContactPointsWithPorts(ccm.addressOfNode(1))
67- .withAddressTranslater(ccm.addressTranslator())
67+ .withPort(ccm.getBinaryPort())
6868 .withPoolingOptions(new PoolingOptions()
6969 .setConnectionsPerHost(HostDistance.LOCAL, coreConnections, coreConnections)
7070 )
modified driver-core/src/test/java/com/datastax/driver/core/NodeRefreshDebouncerTest.java +2 −2
@@ -43,8 +43,8 @@
4343 int refreshNodeInterval = 30000;
4444 QueryOptions queryOptions = new QueryOptions().setRefreshNodeIntervalMillis(refreshNodeInterval);
4545 Cluster cluster = register(Cluster.builder()
46- .addContactPointsWithPorts(getHostAddress(1))
47- .withAddressTranslater(getAddressTranslator())
46+ .addContactPoints(ccm.addressOfNode(1).getAddress())
47+ .withPort(ccm.getBinaryPort())
4848 .withQueryOptions(queryOptions)
4949 .build());
5050 cluster.connect();
modified driver-core/src/test/java/com/datastax/driver/core/QueryOptionsTest.java +2 −2
@@ -49,8 +49,8 @@
4949 queryOptions = new QueryOptions();
5050 loadBalancingPolicy = new SortingLoadBalancingPolicy();
5151 cluster = Cluster.builder()
52- .addContactPointsWithPorts(scassandra.address(2))
53- .withAddressTranslater(scassandra.addressTranslator())
52+ .addContactPoints(scassandra.address(2).getAddress())
53+ .withPort(scassandra.getBinaryPort())
5454 .withLoadBalancingPolicy(loadBalancingPolicy)
5555 .withQueryOptions(queryOptions)
5656 .withNettyOptions(nonQuietClusterCloseOptions)
modified driver-core/src/test/java/com/datastax/driver/core/RecommissionedNodeTest.java +8 −8
@@ -51,8 +51,8 @@
5151
5252 // Now start the driver that will connect to node2 and node3, and consider node1 down
5353 mainCluster = Cluster.builder()
54- .addContactPointsWithPorts(mainCcm.addressOfNode(2))
55- .withAddressTranslater(mainCcm.addressTranslator())
54+ .addContactPoints(mainCcm.addressOfNode(2).getAddress())
55+ .withPort(mainCcm.getBinaryPort())
5656 .withQueryOptions(nonDebouncingQueryOptions()).build();
5757 mainCluster.connect();
5858 waitForCountUpHosts(mainCluster, 2);
@@ -80,8 +80,8 @@
8080
8181 // Start the driver, the control connection will be on node2
8282 mainCluster = Cluster.builder()
83- .addContactPointsWithPorts(mainCcm.addressOfNode(2))
84- .withAddressTranslater(mainCcm.addressTranslator())
83+ .addContactPoints(mainCcm.addressOfNode(2).getAddress())
84+ .withPort(mainCcm.getBinaryPort())
8585 .withQueryOptions(nonDebouncingQueryOptions()).build();
8686 mainCluster.connect();
8787 waitForCountUpHosts(mainCluster, 1);
@@ -118,8 +118,8 @@
118118
119119 // Start the driver, it should only connect to node 2
120120 mainCluster = Cluster.builder()
121- .addContactPointsWithPorts(mainCcm.addressOfNode(2))
122- .withAddressTranslater(mainCcm.addressTranslator())
121+ .addContactPoints(mainCcm.addressOfNode(2).getAddress())
122+ .withPort(mainCcm.getBinaryPort())
123123 .withQueryOptions(nonDebouncingQueryOptions()).build();
124124
125125 // When we first initialize the Cluster, all hosts are marked UP
@@ -154,8 +154,8 @@
154154
155155 // Start the driver, it should only connect to node 2
156156 mainCluster = Cluster.builder()
157- .addContactPointsWithPorts(mainCcm.addressOfNode(2))
158- .withAddressTranslater(mainCcm.addressTranslator())
157+ .addContactPoints(mainCcm.addressOfNode(2).getAddress())
158+ .withPort(mainCcm.getBinaryPort())
159159 .withQueryOptions(nonDebouncingQueryOptions()).build();
160160
161161 // 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 @@
5151 public void should_reconnect_after_full_connectivity_loss() throws InterruptedException {
5252 Cluster cluster = register(Cluster.builder()
5353 .addContactPointsWithPorts(ccm.addressOfNode(1))
54- .withAddressTranslater(ccm.addressTranslator())
54+ .withPort(ccm.getBinaryPort())
5555 .withReconnectionPolicy(new ConstantReconnectionPolicy(reconnectionDelayMillis))
5656 .build());
5757 cluster.connect();
@@ -90,7 +90,7 @@
9090 CountingAuthProvider authProvider = new CountingAuthProvider("cassandra", "cassandra");
9191 Cluster cluster = register(Cluster.builder()
9292 .addContactPointsWithPorts(ccm.addressOfNode(1))
93- .withAddressTranslater(ccm.addressTranslator())
93+ .withPort(ccm.getBinaryPort())
9494 // Start with the correct auth so that we can initialize the server
9595 .withAuthProvider(authProvider)
9696 .withReconnectionPolicy(reconnectionPolicy)
@@ -131,7 +131,7 @@
131131
132132 Cluster cluster = register(Cluster.builder()
133133 .addContactPointsWithPorts(ccm.addressOfNode(1))
134- .withAddressTranslater(ccm.addressTranslator())
134+ .withPort(ccm.getBinaryPort())
135135 .withReconnectionPolicy(reconnectionPolicy).build());
136136 cluster.connect();
137137
@@ -159,7 +159,7 @@
159159 TogglabePolicy loadBalancingPolicy = new TogglabePolicy(new RoundRobinPolicy());
160160 Cluster cluster = register(Cluster.builder()
161161 .addContactPointsWithPorts(ccm.addressOfNode(1))
162- .withAddressTranslater(ccm.addressTranslator())
162+ .withPort(ccm.getBinaryPort())
163163 .withLoadBalancingPolicy(loadBalancingPolicy)
164164 .withReconnectionPolicy(new ConstantReconnectionPolicy(reconnectionDelayMillis))
165165 .build());
@@ -215,7 +215,7 @@
215215 SocketOptions socketOptions = spy(new SocketOptions());
216216 Cluster cluster = register(Cluster.builder()
217217 .addContactPointsWithPorts(ccm.addressOfNode(1))
218- .withAddressTranslater(ccm.addressTranslator())
218+ .withPort(ccm.getBinaryPort())
219219 .withReconnectionPolicy(new ConstantReconnectionPolicy(5000))
220220 .withLoadBalancingPolicy(loadBalancingPolicy)
221221 .withSocketOptions(socketOptions)
modified driver-core/src/test/java/com/datastax/driver/core/RefreshConnectedHostTest.java +1 −1
@@ -43,7 +43,7 @@
4343 PoolingOptions poolingOptions = Mockito.spy(new PoolingOptions());
4444 cluster = register(Cluster.builder()
4545 .addContactPointsWithPorts(ccm.addressOfNode(1))
46- .withAddressTranslater(ccm.addressTranslator())
46+ .withPort(ccm.getBinaryPort())
4747 .withPoolingOptions(poolingOptions)
4848 .withLoadBalancingPolicy(loadBalancingPolicy)
4949 .withReconnectionPolicy(new ConstantReconnectionPolicy(1000))
modified driver-core/src/test/java/com/datastax/driver/core/SSLEncryptionTest.java +4 −2
@@ -23,7 +23,9 @@
2323
2424 import static com.datastax.driver.core.Assertions.assertThat;
2525 import static com.datastax.driver.core.CCMBridge.*;
26+import static com.datastax.driver.core.CreateCCM.TestMode.PER_METHOD;
2627
28+@CreateCCM(PER_METHOD)
2729 @CCMConfig(auth = false)
2830 public class SSLEncryptionTest extends SSLTestBase {
2931
@@ -73,7 +75,7 @@
7375 public void should_not_connect_without_ssl_but_node_uses_ssl() throws Exception {
7476 Cluster cluster = register(Cluster.builder()
7577 .addContactPointsWithPorts(this.getInitialContactPoints())
76- .withAddressTranslater(ccm.addressTranslator())
78+ .withPort(ccm.getBinaryPort())
7779 .build());
7880 cluster.connect();
7981 }
@@ -92,7 +94,7 @@
9294 public void should_reconnect_with_ssl_on_node_up() throws Exception {
9395 Cluster cluster = register(Cluster.builder()
9496 .addContactPointsWithPorts(this.getInitialContactPoints())
95- .withAddressTranslater(ccm.addressTranslator())
97+ .withPort(ccm.getBinaryPort())
9698 .withSSL(getSSLOptions(Optional.of(DEFAULT_CLIENT_KEYSTORE_PATH), Optional.of(DEFAULT_CLIENT_TRUSTSTORE_PATH)))
9799 .build());
98100
modified driver-core/src/test/java/com/datastax/driver/core/SSLTestBase.java +2 −2
@@ -42,7 +42,7 @@
4242 protected void connectWithSSLOptions(SSLOptions sslOptions) throws Exception {
4343 Cluster cluster = register(Cluster.builder()
4444 .addContactPointsWithPorts(this.getInitialContactPoints())
45- .withAddressTranslater(ccm.addressTranslator())
45+ .withPort(ccm.getBinaryPort())
4646 .withSSL(sslOptions)
4747 .build());
4848 cluster.connect();
@@ -60,7 +60,7 @@
6060 protected void connectWithSSL() throws Exception {
6161 Cluster cluster = register(Cluster.builder()
6262 .addContactPointsWithPorts(this.getInitialContactPoints())
63- .withAddressTranslater(ccm.addressTranslator())
63+ .withPort(ccm.getBinaryPort())
6464 .withSSL()
6565 .build());
6666 cluster.connect();
modified driver-core/src/test/java/com/datastax/driver/core/ScassandraCluster.java +4 −22
@@ -17,7 +17,6 @@
1717
1818 import com.beust.jcommander.internal.Lists;
1919 import com.beust.jcommander.internal.Maps;
20-import com.datastax.driver.core.policies.AddressTranslater;
2120 import com.google.common.collect.ImmutableList;
2221 import com.google.common.collect.ImmutableMap;
2322 import com.google.common.collect.ImmutableSet;
@@ -115,6 +114,10 @@
115114 return -1;
116115 }
117116
117+ public int getBinaryPort() {
118+ return binaryPort;
119+ }
120+
118121 public InetSocketAddress address(int node) {
119122 return new InetSocketAddress(ipPrefix + node, binaryPort);
120123 }
@@ -127,27 +130,6 @@
127130 return new InetSocketAddress(ipPrefix + ipSuffix, binaryPort);
128131 }
129132
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-
151133 public Host host(Cluster cluster, int dc, int node) {
152134 InetAddress address = address(dc, node).getAddress();
153135 for (Host host : cluster.getMetadata().getAllHosts()) {
modified driver-core/src/test/java/com/datastax/driver/core/SchemaChangesCCTest.java +2 −2
@@ -57,14 +57,14 @@
5757 Cluster.builder()
5858 .withLoadBalancingPolicy(lbPolicy)
5959 .addContactPointsWithPorts(ccm.addressOfNode(1))
60- .withAddressTranslater(ccm.addressTranslator())
60+ .withPort(ccm.getBinaryPort())
6161 .build());
6262 // Put cluster2 control connection on node 2 so it doesn't go down (to prevent noise for debugging).
6363 Cluster cluster2 = register(
6464 Cluster.builder()
6565 .withLoadBalancingPolicy(lbPolicy)
6666 .addContactPointsWithPorts(ccm.addressOfNode(2))
67- .withAddressTranslater(ccm.addressTranslator())
67+ .withPort(ccm.getBinaryPort())
6868 .build());
6969 SchemaChangeListener listener = mock(SchemaChangeListener.class);
7070
modified driver-core/src/test/java/com/datastax/driver/core/SessionLeakTest.java +4 −4
@@ -40,8 +40,8 @@
4040 channelMonitor = new SocketChannelMonitor();
4141 channelMonitor.reportAtFixedInterval(1, TimeUnit.SECONDS);
4242 cluster = register(Cluster.builder()
43- .addContactPointsWithPorts(getHostAddress(1))
44- .withAddressTranslater(getAddressTranslator())
43+ .addContactPoints(ccm.addressOfNode(1).getAddress())
44+ .withPort(ccm.getBinaryPort())
4545 .withNettyOptions(channelMonitor.nettyOptions())
4646 .withQueryOptions(nonDebouncingQueryOptions())
4747 .build());
@@ -96,8 +96,8 @@
9696 channelMonitor = new SocketChannelMonitor();
9797 channelMonitor.reportAtFixedInterval(1, TimeUnit.SECONDS);
9898 cluster = register(Cluster.builder()
99- .addContactPointsWithPorts(getHostAddress(1))
100- .withAddressTranslater(getAddressTranslator())
99+ .addContactPoints(ccm.addressOfNode(1).getAddress())
100+ .withPort(ccm.getBinaryPort())
101101 .withNettyOptions(channelMonitor.nettyOptions())
102102 .build());
103103 cluster.init();
modified driver-core/src/test/java/com/datastax/driver/core/SpeculativeExecutionTest.java +4 −4
@@ -50,8 +50,8 @@
5050
5151 loadBalancingPolicy = new SortingLoadBalancingPolicy();
5252 cluster = Cluster.builder()
53- .addContactPointsWithPorts(scassandras.address(2))
54- .withAddressTranslater(scassandras.addressTranslator())
53+ .addContactPoints(scassandras.address(2).getAddress())
54+ .withPort(scassandras.getBinaryPort())
5555 .withLoadBalancingPolicy(loadBalancingPolicy)
5656 .withSpeculativeExecutionPolicy(new ConstantSpeculativeExecutionPolicy(speculativeExecutionDelay, 1))
5757 .withQueryOptions(new QueryOptions().setDefaultIdempotence(true))
@@ -201,8 +201,8 @@
201201 SpeculativeExecutionPolicy mockPolicy = mock(SpeculativeExecutionPolicy.class);
202202
203203 Cluster cluster = Cluster.builder()
204- .addContactPointsWithPorts(scassandras.address(2))
205- .withAddressTranslater(scassandras.addressTranslator())
204+ .addContactPoints(scassandras.address(2).getAddress())
205+ .withPort(scassandras.getBinaryPort())
206206 .withSpeculativeExecutionPolicy(mockPolicy)
207207 .build();
208208
modified driver-core/src/test/java/com/datastax/driver/core/StateListenerTest.java +1 −1
@@ -51,7 +51,7 @@
5151 listener.waitForEvent();
5252
5353 listener.setExpectedEvent(REMOVE);
54- ccm.decommissionNode(2);
54+ ccm.decommision(2);
5555 listener.waitForEvent();
5656 }
5757
modified driver-core/src/test/java/com/datastax/driver/core/TestUtils.java +2 −2
@@ -581,12 +581,12 @@
581581 /**
582582 * @return a {@link Cluster} instance that connects only to the control host of the given cluster.
583583 */
584- public static Cluster buildControlCluster(Cluster cluster, CCMBridge ccm) {
584+ public static Cluster buildControlCluster(Cluster cluster, CCMAccess ccm) {
585585 Host controlHost = cluster.manager.controlConnection.connectedHost();
586586 List<InetSocketAddress> singleAddress = Collections.singletonList(controlHost.getSocketAddress());
587587 return Cluster.builder()
588588 .addContactPointsWithPorts(singleAddress)
589- .withAddressTranslater(ccm.addressTranslator())
589+ .withPort(ccm.getBinaryPort())
590590 .withLoadBalancingPolicy(new WhiteListPolicy(new RoundRobinPolicy(), singleAddress))
591591 .build();
592592 }
modified driver-core/src/test/java/com/datastax/driver/core/exceptions/ExceptionsScassandraTest.java +2 −2
@@ -48,8 +48,8 @@
4848 @BeforeMethod(groups = "short")
4949 public void beforeMethod() {
5050 cluster = Cluster.builder()
51- .addContactPointsWithPorts(scassandras.address(1))
52- .withAddressTranslater(scassandras.addressTranslator())
51+ .addContactPoints(scassandras.address(1).getAddress())
52+ .withPort(scassandras.getBinaryPort())
5353 .withRetryPolicy(FallthroughRetryPolicy.INSTANCE)
5454 .build();
5555 session = cluster.connect();
modified driver-core/src/test/java/com/datastax/driver/core/exceptions/ExceptionsTest.java +4 −4
@@ -66,8 +66,8 @@
6666 assertEquals(e.getKeyspace(), keyspace.toLowerCase());
6767 assertEquals(e.getTable(), null);
6868 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));
7171 }
7272
7373 session.execute(cqlCommands[1]);
@@ -80,8 +80,8 @@
8080 assertEquals(e.getKeyspace(), keyspace.toLowerCase());
8181 assertEquals(e.getTable(), table.toLowerCase());
8282 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));
8585 }
8686 }
8787
modified driver-core/src/test/java/com/datastax/driver/core/policies/AbstractRetryPolicyIntegrationTest.java +2 −2
@@ -61,8 +61,8 @@
6161 scassandras.init();
6262
6363 cluster = Cluster.builder()
64- .addContactPointsWithPorts(scassandras.address(1))
65- .withAddressTranslater(scassandras.addressTranslator())
64+ .addContactPoints(scassandras.address(1).getAddress())
65+ .withPort(scassandras.getBinaryPort())
6666 .withRetryPolicy(retryPolicy)
6767 .withLoadBalancingPolicy(new SortingLoadBalancingPolicy())
6868 .withNettyOptions(nonQuietClusterCloseOptions)
modified driver-core/src/test/java/com/datastax/driver/core/policies/CloseableLoadBalancingPolicyTest.java +1 −1
@@ -41,7 +41,7 @@
4141 public Cluster.Builder createClusterBuilder() {
4242 policy = new CloseMonitoringPolicy(Policies.defaultLoadBalancingPolicy());
4343 return Cluster.builder()
44- .addContactPointsWithPorts(getHostAddress(1))
44+ .addContactPoints(ccm.addressOfNode(1).getAddress())
4545 .withLoadBalancingPolicy(policy);
4646 }
4747
modified driver-core/src/test/java/com/datastax/driver/core/policies/DCAwareRoundRobinPolicyTest.java +22 −22
@@ -81,8 +81,8 @@
8181 // given: a 10 node 2 DC cluster.
8282 ScassandraCluster sCluster = ScassandraCluster.builder().withNodes(5, 5).build();
8383 Cluster cluster = builder()
84- .addContactPointsWithPorts(sCluster.address(1, 1))
85- .withAddressTranslater(sCluster.addressTranslator())
84+ .addContactPoints(sCluster.address(1, 1).getAddress())
85+ .withPort(sCluster.getBinaryPort())
8686 .withLoadBalancingPolicy(DCAwareRoundRobinPolicy.builder().withLocalDc(datacenter(1)).build())
8787 .build();
8888 try {
@@ -114,8 +114,8 @@
114114 // given: a 10 node 2 DC cluster with DC policy with 2 remote hosts.
115115 ScassandraCluster sCluster = ScassandraCluster.builder().withNodes(5, 5).build();
116116 Cluster cluster = builder()
117- .addContactPointsWithPorts(sCluster.address(1, 1))
118- .withAddressTranslater(sCluster.addressTranslator())
117+ .addContactPoints(sCluster.address(1, 1).getAddress())
118+ .withPort(sCluster.getBinaryPort())
119119 .withLoadBalancingPolicy(DCAwareRoundRobinPolicy.builder().withLocalDc(datacenter(1)).withUsedHostsPerRemoteDc(2).build())
120120 .build();
121121
@@ -157,8 +157,8 @@
157157 // given: a 10 node 2 DC cluster with DC policy with 2 remote hosts.
158158 ScassandraCluster sCluster = ScassandraCluster.builder().withNodes(5, 5).build();
159159 Cluster cluster = builder()
160- .addContactPointsWithPorts(sCluster.address(1, 1))
161- .withAddressTranslater(sCluster.addressTranslator())
160+ .addContactPoints(sCluster.address(1, 1).getAddress())
161+ .withPort(sCluster.getBinaryPort())
162162 .withLoadBalancingPolicy(DCAwareRoundRobinPolicy.builder().withUsedHostsPerRemoteDc(2).build())
163163 .build();
164164
@@ -201,8 +201,8 @@
201201 // a local consistency level.
202202 ScassandraCluster sCluster = ScassandraCluster.builder().withNodes(2, 2).build();
203203 Cluster cluster = builder()
204- .addContactPointsWithPorts(sCluster.address(1, 1))
205- .withAddressTranslater(sCluster.addressTranslator())
204+ .addContactPoints(sCluster.address(1, 1).getAddress())
205+ .withPort(sCluster.getBinaryPort())
206206 .withLoadBalancingPolicy(DCAwareRoundRobinPolicy.builder().withUsedHostsPerRemoteDc(2).build())
207207 .build();
208208
@@ -247,8 +247,8 @@
247247 // a local consistency level.
248248 ScassandraCluster sCluster = ScassandraCluster.builder().withNodes(2, 2).build();
249249 Cluster cluster = builder()
250- .addContactPointsWithPorts(sCluster.address(1, 1))
251- .withAddressTranslater(sCluster.addressTranslator())
250+ .addContactPoints(sCluster.address(1, 1).getAddress())
251+ .withPort(sCluster.getBinaryPort())
252252 .withLoadBalancingPolicy(DCAwareRoundRobinPolicy.builder()
253253 .allowRemoteDCsForLocalConsistencyLevel()
254254 .withUsedHostsPerRemoteDc(2).build())
@@ -293,8 +293,8 @@
293293 DCAwareRoundRobinPolicy.builder().withUsedHostsPerRemoteDc(2).build(),
294294 Lists.newArrayList(datacenter(2)));
295295 Cluster cluster = builder()
296- .addContactPointsWithPorts(sCluster.address(1, 1))
297- .withAddressTranslater(sCluster.addressTranslator())
296+ .addContactPoints(sCluster.address(1, 1).getAddress())
297+ .withPort(sCluster.getBinaryPort())
298298 .withLoadBalancingPolicy(loadBalancingPolicy)
299299 .build();
300300
@@ -347,8 +347,8 @@
347347 DCAwareRoundRobinPolicy.builder().withUsedHostsPerRemoteDc(2).build(),
348348 Lists.newArrayList(datacenter(1), datacenter(2)));
349349 Cluster cluster = builder()
350- .addContactPointsWithPorts(sCluster.address(1, 1))
351- .withAddressTranslater(sCluster.addressTranslator())
350+ .addContactPoints(sCluster.address(1, 1).getAddress())
351+ .withPort(sCluster.getBinaryPort())
352352 .withLoadBalancingPolicy(loadBalancingPolicy)
353353 .build();
354354
@@ -399,8 +399,8 @@
399399 DCAwareRoundRobinPolicy policy = spy(DCAwareRoundRobinPolicy.builder().build());
400400 ScassandraCluster sCluster = ScassandraCluster.builder().withNodes(2, 2).build();
401401 Cluster cluster = builder()
402- .addContactPointsWithPorts(sCluster.address(1, 1))
403- .withAddressTranslater(sCluster.addressTranslator())
402+ .addContactPoints(sCluster.address(1, 1).getAddress())
403+ .withPort(sCluster.getBinaryPort())
404404 .withLoadBalancingPolicy(policy)
405405 .build();
406406
@@ -439,8 +439,8 @@
439439 DCAwareRoundRobinPolicy policy = spy(DCAwareRoundRobinPolicy.builder().build());
440440 ScassandraCluster sCluster = ScassandraCluster.builder().withNodes(2, 2).build();
441441 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())
444444 .withLoadBalancingPolicy(policy)
445445 .build();
446446
@@ -478,8 +478,8 @@
478478 ScassandraCluster sCluster = ScassandraCluster.builder().withNodes(2, 2).build();
479479 DCAwareRoundRobinPolicy policy = spy(DCAwareRoundRobinPolicy.builder().withLocalDc(datacenter(1)).build());
480480 Cluster cluster = builder()
481- .addContactPointsWithPorts(sCluster.address(1, 1))
482- .withAddressTranslater(sCluster.addressTranslator())
481+ .addContactPoints(sCluster.address(1, 1).getAddress())
482+ .withPort(sCluster.getBinaryPort())
483483 .withLoadBalancingPolicy(policy)
484484 .build();
485485
@@ -518,8 +518,8 @@
518518 ScassandraCluster sCluster = ScassandraCluster.builder().withNodes(2, 2).build();
519519 DCAwareRoundRobinPolicy policy = spy(DCAwareRoundRobinPolicy.builder().withLocalDc(datacenter(3)).build());
520520 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())
523523 .withLoadBalancingPolicy(policy)
524524 .build();
525525
modified driver-core/src/test/java/com/datastax/driver/core/policies/DefaultRetryPolicyIntegrationTest.java +2 −2
@@ -106,8 +106,8 @@
106106 Collections.singletonList(host1.getSocketAddress()));
107107
108108 Cluster whiteListedCluster = Cluster.builder()
109- .addContactPointsWithPorts(scassandras.address(1))
110- .withAddressTranslater(scassandras.addressTranslator())
109+ .addContactPoints(scassandras.address(1).getAddress())
110+ .withPort(scassandras.getBinaryPort())
111111 .withRetryPolicy(retryPolicy)
112112 .withLoadBalancingPolicy(firstHostOnlyPolicy)
113113 .build();
modified driver-core/src/test/java/com/datastax/driver/core/policies/DowngradingConsistencyRetryPolicyIntegrationTest.java +2 −2
@@ -43,8 +43,8 @@
4343 @Test(groups = "long")
4444 public void should_downgrade_if_not_enough_replicas_for_requested_CL() {
4545 Cluster cluster = register(Cluster.builder()
46- .addContactPointsWithPorts(getHostAddress(1))
47- .withAddressTranslater(getAddressTranslator())
46+ .addContactPoints(ccm.addressOfNode(1).getAddress())
47+ .withPort(ccm.getBinaryPort())
4848 .withRetryPolicy(Mockito.spy(DowngradingConsistencyRetryPolicy.INSTANCE))
4949 .build());
5050 Session session = cluster.connect();
modified driver-core/src/test/java/com/datastax/driver/core/policies/RoundRobinPolicyTest.java +6 −6
@@ -59,8 +59,8 @@
5959 ScassandraCluster sCluster = ScassandraCluster.builder().withNodes(5).build();
6060
6161 Cluster cluster = Cluster.builder()
62- .addContactPointsWithPorts(sCluster.address(1))
63- .withAddressTranslater(sCluster.addressTranslator())
62+ .addContactPoints(sCluster.address(1).getAddress())
63+ .withPort(sCluster.getBinaryPort())
6464 .withLoadBalancingPolicy(new RoundRobinPolicy())
6565 .withNettyOptions(nonQuietClusterCloseOptions)
6666 .build();
@@ -95,8 +95,8 @@
9595 ScassandraCluster sCluster = ScassandraCluster.builder().withNodes(2, 2, 2, 2, 2).build();
9696
9797 Cluster cluster = Cluster.builder()
98- .addContactPointsWithPorts(sCluster.address(1))
99- .withAddressTranslater(sCluster.addressTranslator())
98+ .addContactPoints(sCluster.address(1).getAddress())
99+ .withPort(sCluster.getBinaryPort())
100100 .withLoadBalancingPolicy(new RoundRobinPolicy())
101101 .withNettyOptions(nonQuietClusterCloseOptions)
102102 .build();
@@ -134,8 +134,8 @@
134134 ScassandraCluster sCluster = ScassandraCluster.builder().withNodes(1, 1).build();
135135
136136 Cluster cluster = Cluster.builder()
137- .addContactPointsWithPorts(sCluster.address(1))
138- .withAddressTranslater(sCluster.addressTranslator())
137+ .addContactPoints(sCluster.address(1).getAddress())
138+ .withPort(sCluster.getBinaryPort())
139139 .withLoadBalancingPolicy(new RoundRobinPolicy())
140140 .withNettyOptions(nonQuietClusterCloseOptions)
141141 .build();
modified driver-core/src/test/java/com/datastax/driver/core/policies/TokenAwarePolicyTest.java +9 −9
@@ -70,8 +70,8 @@
7070 }
7171
7272 Cluster cluster = Cluster.builder()
73- .addContactPointsWithPorts(sCluster.address(1))
74- .withAddressTranslater(sCluster.addressTranslator())
73+ .addContactPoints(sCluster.address(1).getAddress())
74+ .withPort(sCluster.getBinaryPort())
7575 .withNettyOptions(nonQuietClusterCloseOptions)
7676 .withLoadBalancingPolicy(loadBalancingPolicy)
7777 .build();
@@ -137,8 +137,8 @@
137137 .withSimpleKeyspace("keyspace", 1)
138138 .build();
139139 Cluster cluster = Cluster.builder()
140- .addContactPointsWithPorts(sCluster.address(1))
141- .withAddressTranslater(sCluster.addressTranslator())
140+ .addContactPoints(sCluster.address(1).getAddress())
141+ .withPort(sCluster.getBinaryPort())
142142 .withNettyOptions(nonQuietClusterCloseOptions)
143143 .withLoadBalancingPolicy(new TokenAwarePolicy(new RoundRobinPolicy()))
144144 .build();
@@ -182,8 +182,8 @@
182182 .withNetworkTopologyKeyspace("keyspace", ImmutableMap.of(1, 1, 2, 1))
183183 .build();
184184 Cluster cluster = Cluster.builder()
185- .addContactPointsWithPorts(sCluster.address(1))
186- .withAddressTranslater(sCluster.addressTranslator())
185+ .addContactPoints(sCluster.address(1).getAddress())
186+ .withPort(sCluster.getBinaryPort())
187187 .withNettyOptions(nonQuietClusterCloseOptions)
188188 .withLoadBalancingPolicy(new TokenAwarePolicy(DCAwareRoundRobinPolicy.builder()
189189 .withLocalDc(ScassandraCluster.datacenter(2))
@@ -230,8 +230,8 @@
230230 .withSimpleKeyspace("keyspace", 2)
231231 .build();
232232 Cluster cluster = Cluster.builder()
233- .addContactPointsWithPorts(sCluster.address(2))
234- .withAddressTranslater(sCluster.addressTranslator())
233+ .addContactPoints(sCluster.address(2).getAddress())
234+ .withPort(sCluster.getBinaryPort())
235235 .withNettyOptions(nonQuietClusterCloseOptions)
236236 // Don't shuffle replicas just to keep test deterministic.
237237 .withLoadBalancingPolicy(new TokenAwarePolicy(new RoundRobinPolicy(), false))
@@ -322,7 +322,7 @@
322322 Cluster cluster = Cluster.builder()
323323 .withLoadBalancingPolicy(new TokenAwarePolicy(new RoundRobinPolicy()))
324324 .addContactPointsWithPorts(ccm.addressOfNode(1))
325- .withAddressTranslater(ccm.addressTranslator())
325+ .withPort(ccm.getBinaryPort())
326326 .build();
327327
328328 try {
modified driver-core/src/test/java/com/datastax/driver/core/policies/WhiteListPolicyTest.java +2 −2
@@ -53,8 +53,8 @@
5353 List<InetSocketAddress> whiteList = Lists.newArrayList(sCluster.address(3), sCluster.address(5));
5454
5555 Cluster cluster = Cluster.builder()
56- .addContactPointsWithPorts(sCluster.address(5))
57- .withAddressTranslater(sCluster.addressTranslator())
56+ .addContactPoints(sCluster.address(5).getAddress())
57+ .withPort(sCluster.getBinaryPort())
5858 .withLoadBalancingPolicy(new WhiteListPolicy(new RoundRobinPolicy(), whiteList))
5959 .withNettyOptions(nonQuietClusterCloseOptions)
6060 .build();
modified driver-mapping/src/test/java/com/datastax/driver/mapping/UDTFieldMapperTest.java +4 −4
@@ -40,7 +40,7 @@
4040 ccm = CCMBridge.builder().build();
4141 cluster = Cluster.builder()
4242 .addContactPointsWithPorts(ccm.addressOfNode(1))
43- .withAddressTranslater(ccm.addressTranslator())
43+ .withPort(ccm.getBinaryPort())
4444 .build();
4545 Session session1 = cluster.connect();
4646 session1.execute("create schema if not exists java_509 " +
@@ -56,7 +56,7 @@
5656 // Create entities with another connection
5757 cluster = Cluster.builder()
5858 .addContactPointsWithPorts(ccm.addressOfNode(1))
59- .withAddressTranslater(ccm.addressTranslator())
59+ .withPort(ccm.getBinaryPort())
6060 .build();
6161 Session session2 = cluster.newSession();
6262 Mapper<MyHashWithKeyspace> hashMapper = new MappingManager(session2).mapper(MyHashWithKeyspace.class);
@@ -93,7 +93,7 @@
9393 ccm = CCMBridge.builder().build();
9494 cluster = Cluster.builder()
9595 .addContactPointsWithPorts(ccm.addressOfNode(1))
96- .withAddressTranslater(ccm.addressTranslator())
96+ .withPort(ccm.getBinaryPort())
9797 .build();
9898 Session session1 = cluster.connect();
9999 session1.execute("create schema if not exists java_509 " +
@@ -110,7 +110,7 @@
110110 // Create entities with another connection
111111 cluster = Cluster.builder()
112112 .addContactPointsWithPorts(ccm.addressOfNode(1))
113- .withAddressTranslater(ccm.addressTranslator())
113+ .withPort(ccm.getBinaryPort())
114114 .build();
115115 Session session2 = cluster.newSession();
116116