Elffuss BraidHub

kikocis/java-driver public

Refactor CCMBridge constructors to builder pattern (JAVA-789)
Changeset44457cdc3b144f2fad8934ebba385b65790ad1ae3fa526287a4a9f4873782c37
Authorolim7t <omichallat+github@gmail.com> · 2015-07-03 15:16 +02:00
Committerolim7t <omichallat+github@gmail.com> · 2015-07-03 19:21 +02:00
Parents1c8ac384bf5a

Browse the files at this changeset

24 files changed

modified driver-core/src/test/java/com/datastax/driver/core/AuthenticationTest.java +14 −25
@@ -15,9 +15,6 @@
1515 */
1616 package com.datastax.driver.core;
1717
18-import java.net.InetAddress;
19-import java.net.InetSocketAddress;
20-import java.util.Map;
2118 import java.util.concurrent.TimeUnit;
2219
2320 import org.slf4j.Logger;
@@ -36,17 +33,18 @@
3633
3734 private static final Logger logger = LoggerFactory.getLogger(AuthenticationTest.class);
3835
39- private CCMBridge cassandraCluster;
36+ private CCMBridge ccm;
4037
4138 /**
4239 * creates a cluster and turns on password authentication before starting it.
4340 */
4441 @BeforeClass (groups = "short")
4542 public void setupClusterWithAuthentication() throws InterruptedException {
46- cassandraCluster = CCMBridge.create("test");
47- cassandraCluster.populate(1);
48- cassandraCluster.updateConfig("authenticator", "PasswordAuthenticator");
49- cassandraCluster.start(1, "-Dcassandra.superuser_setup_delay_ms=0");
43+ ccm = CCMBridge.builder("test")
44+ .withCassandraConfiguration("authenticator", "PasswordAuthenticator")
45+ .notStarted()
46+ .build();
47+ ccm.start(1, "-Dcassandra.superuser_setup_delay_ms=0");
5048
5149 // Even though we've override the default user setup delay, still wait
5250 // one second to make sure we don't race
@@ -55,51 +53,42 @@
5553
5654 @AfterClass (groups = "short")
5755 public void shutdownCluster() {
58- if (null != cassandraCluster)
59- cassandraCluster.stop();
56+ if (ccm != null)
57+ ccm.stop();
6058 }
6159
6260 @Test(groups = "short")
63- public void testAuthenticatedConnection() throws InterruptedException {
61+ public void should_connect_with_credentials() throws InterruptedException {
6462 try {
6563 Cluster.builder().addContactPoint(CCMBridge.IP_PREFIX + '1')
6664 .withCredentials("cassandra", "cassandra")
6765 .build()
6866 .connect();
6967 } catch (NoHostAvailableException e) {
70-
71- for (Map.Entry<InetSocketAddress, Throwable> entry : e.getErrors().entrySet())
72- logger.error("Error connecting to " + entry.getKey(), entry.getValue());
73- throw new RuntimeException(e);
68+ logger.error(e.getCustomMessage(1, true, true));
7469 }
7570 }
7671
7772 @Test(groups = "short", expectedExceptions = AuthenticationException.class)
78- public void testConnectionAttemptWithIncorrectCredentialsIsRefused() throws InterruptedException {
73+ public void should_fail_to_connect_with_wrong_credentials() throws InterruptedException {
7974 try {
8075 Cluster.builder().addContactPoint(CCMBridge.IP_PREFIX + '1')
8176 .withCredentials("bogus", "bogus")
8277 .build()
8378 .connect();
8479 } catch (NoHostAvailableException e) {
85-
86- for (Map.Entry<InetSocketAddress, Throwable> entry : e.getErrors().entrySet())
87- logger.info("Error connecting to " + entry.getKey() + ": " + entry.getValue());
88- throw new RuntimeException(e);
80+ logger.error(e.getCustomMessage(1, true, true));
8981 }
9082 }
9183
9284 @Test(groups = "short", expectedExceptions = AuthenticationException.class)
93- public void testConnectionAttemptWithoutCredentialsIsRefused() throws InterruptedException {
85+ public void should_fail_to_connect_without_credentials() throws InterruptedException {
9486 try {
9587 Cluster.builder().addContactPoint(CCMBridge.IP_PREFIX + '1')
9688 .build()
9789 .connect();
9890 } catch (NoHostAvailableException e) {
99-
100- for (Map.Entry<InetSocketAddress, Throwable> entry : e.getErrors().entrySet())
101- logger.info("Error connecting to " + entry.getKey() + ": " + entry.getValue());
102- throw new RuntimeException(e);
91+ logger.error(e.getCustomMessage(1, true, true));
10392 }
10493 }
10594 }
modified driver-core/src/test/java/com/datastax/driver/core/CCMBridge.java +116 −93
@@ -38,10 +38,8 @@
3838 import org.testng.annotations.AfterClass;
3939 import org.testng.annotations.BeforeClass;
4040
41-import static com.google.common.base.Preconditions.checkArgument;
4241 import static org.testng.Assert.fail;
4342
44-import com.datastax.driver.core.Cluster.Builder;
4543 import com.datastax.driver.core.exceptions.AlreadyExistsException;
4644 import com.datastax.driver.core.exceptions.DriverException;
4745 import com.datastax.driver.core.exceptions.NoHostAvailableException;
@@ -56,6 +54,8 @@
5654 public static final String IP_PREFIX;
5755
5856 private static final String CASSANDRA_VERSION_REGEXP = "\\d\\.\\d\\.\\d+(-\\w+)?";
57+ static final File CASSANDRA_DIR;
58+ static final String CASSANDRA_VERSION;
5959
6060 public static final String DEFAULT_CLIENT_TRUSTSTORE_PASSWORD = "cassandra1sfun";
6161 public static final String DEFAULT_CLIENT_TRUSTSTORE_PATH = "/client.truststore";
@@ -89,6 +89,21 @@
8989 private static final String CCM_COMMAND;
9090
9191 static {
92+ String version = System.getProperty("cassandra.version");
93+ if (version.matches(CASSANDRA_VERSION_REGEXP)) {
94+ CASSANDRA_DIR = null;
95+ CASSANDRA_VERSION = "-v " + version;
96+ } else {
97+ CASSANDRA_DIR = new File(version);
98+ CASSANDRA_VERSION = "";
99+ }
100+
101+ String ip_prefix = System.getProperty("ipprefix");
102+ if (ip_prefix == null || ip_prefix.isEmpty()) {
103+ ip_prefix = "127.0.1.";
104+ }
105+ IP_PREFIX = ip_prefix;
106+
92107 // Inherit the current environment.
93108 Map<String,String> envMap = Maps.newHashMap(new ProcessBuilder().environment());
94109 // If ccm.path is set, override the PATH variable with it.
@@ -122,33 +137,9 @@
122137 private static boolean isWindows() {
123138
124139 String osName = System.getProperty("os.name");
125- if (osName == null) {
126- return false;
127- }
128- return osName.startsWith("Windows");
129- }
130-
131- static final File CASSANDRA_DIR;
132- static final String CASSANDRA_VERSION;
133-
134- static {
135- String version = System.getProperty("cassandra.version");
136- if (version.matches(CASSANDRA_VERSION_REGEXP)) {
137- CASSANDRA_DIR = null;
138- CASSANDRA_VERSION = "-v " + version;
139- } else {
140- CASSANDRA_DIR = new File(version);
141- CASSANDRA_VERSION = "";
142- }
143-
144- String ip_prefix = System.getProperty("ipprefix");
145- if (ip_prefix == null || ip_prefix.isEmpty()) {
146- ip_prefix = "127.0.1.";
147- }
148- IP_PREFIX = ip_prefix;
140+ return osName != null && osName.startsWith("Windows");
149141 }
150142
151- private final Runtime runtime = Runtime.getRuntime();
152143 private final File ccmDir;
153144
154145 private CCMBridge() {
@@ -190,28 +181,8 @@
190181 return f;
191182 }
192183
193- public static CCMBridge create(String name, String... options) {
194- CCMBridge bridge = new CCMBridge();
195- bridge.execute(CCM_COMMAND + " create %s -b -i %s %s " + Joiner.on(" ").join(options), name, IP_PREFIX, CASSANDRA_VERSION);
196- return bridge;
197- }
198-
199- public static CCMBridge create(String name, int nbNodes, String... options) {
200- CCMBridge bridge = new CCMBridge();
201- bridge.execute(CCM_COMMAND + " create %s -n %d -s -i %s -b %s " + Joiner.on(" ").join(options), name, nbNodes, IP_PREFIX, CASSANDRA_VERSION);
202- return bridge;
203- }
204-
205- public static CCMBridge createWithCustomVersion(String name, int nbNodes, String cassandraVersion) {
206- CCMBridge bridge = new CCMBridge();
207- bridge.execute(CCM_COMMAND + " create %s -n %d -s -i %s -b -v %s ", name, nbNodes, IP_PREFIX, cassandraVersion);
208- return bridge;
209- }
210-
211- public static CCMBridge create(String name, int nbNodesDC1, int nbNodesDC2) {
212- CCMBridge bridge = new CCMBridge();
213- bridge.execute(CCM_COMMAND + " create %s -n %d:%d -s -i %s -b %s", name, nbNodesDC1, nbNodesDC2, IP_PREFIX, CASSANDRA_VERSION);
214- return bridge;
184+ public static Builder builder(String clusterName) {
185+ return new Builder(clusterName);
215186 }
216187
217188 public static CCMBridge.CCMCluster buildCluster(int nbNodes, Cluster.Builder builder) {
@@ -239,9 +210,9 @@
239210 execute(CCM_COMMAND + " node%d start --wait-other-notice --wait-for-binary-proto", n);
240211 }
241212
242- public void start(int n, String option) {
243- logger.info("Starting: " + IP_PREFIX + n + " with " + option);
244- execute(CCM_COMMAND + " node%d start --wait-other-notice --wait-for-binary-proto --jvm_arg=%s", n, option);
213+ public void start(int n, String jvmArg) {
214+ logger.info("Starting: " + IP_PREFIX + n + " with " + jvmArg);
215+ execute(CCM_COMMAND + " node%d start --wait-other-notice --wait-for-binary-proto --jvm_arg=%s", n, jvmArg);
245216 }
246217
247218 public void stop(int n) {
@@ -250,7 +221,7 @@
250221 }
251222
252223 public void stop(String clusterName) {
253- logger.info("Stopping Cluster : "+clusterName);
224+ logger.info("Stopping Cluster : " + clusterName);
254225 execute(CCM_COMMAND + " stop "+clusterName);
255226 }
256227
@@ -300,10 +271,6 @@
300271 execute(CCM_COMMAND + " node%d decommission", n);
301272 }
302273
303- public void updateConfig(String name, String value) {
304- updateConfig(ImmutableMap.of(name, value));
305- }
306-
307274 public void updateConfig(Map<String, String> configs) {
308275 StringBuilder confStr = new StringBuilder();
309276 for (Map.Entry<String, String> entry : configs.entrySet()) {
@@ -312,10 +279,6 @@
312279 execute(CCM_COMMAND + " updateconf " + confStr);
313280 }
314281
315- public void populate(int n) {
316- execute(CCM_COMMAND + " populate -n %d -i %s", n, IP_PREFIX);
317- }
318-
319282 private void execute(String command, Object... args) {
320283
321284 String fullCommand = String.format(command, args) + " --config-dir=" + ccmDir;
@@ -323,6 +286,7 @@
323286 logger.debug("Executing: " + fullCommand);
324287 CommandLine cli = CommandLine.parse(fullCommand);
325288 Executor executor = new DefaultExecutor();
289+ executor.setWorkingDirectory(CASSANDRA_DIR);
326290
327291 LogOutputStream outStream = new LogOutputStream() {
328292 @Override protected void processLine(String line, int logLevel) {
@@ -372,33 +336,6 @@
372336 }
373337 }
374338
375- /**
376- * Enables SSL without client authentication. Does not apply to already started nodes.
377- */
378- public void enableSSL() {
379- enableSSL(false);
380- }
381-
382- /**
383- * Enables SSL. Does not apply to already started nodes.
384- * @param requireClientAuth Whether or not to require Clients used authentication.
385- */
386- public void enableSSL(boolean requireClientAuth) {
387- ImmutableMap.Builder<String, String> configs = ImmutableMap.builder();
388-
389- configs.put("client_encryption_options.enabled", "true");
390- configs.put("client_encryption_options.keystore", DEFAULT_SERVER_KEYSTORE_FILE.getAbsolutePath());
391- configs.put("client_encryption_options.keystore_password", DEFAULT_SERVER_KEYSTORE_PASSWORD);
392-
393- if (requireClientAuth) {
394- configs.put("client_encryption_options.require_client_auth", "true");
395- configs.put("client_encryption_options.truststore", DEFAULT_SERVER_TRUSTSTORE_FILE.getAbsolutePath());
396- configs.put("client_encryption_options.truststore_password", DEFAULT_SERVER_TRUSTSTORE_PASSWORD);
397- }
398-
399- updateConfig(configs.build());
400- }
401-
402339 private static void busyWaitForPort(InetAddress address, int port, boolean expectedConnectionState) {
403340 long maxAcceptableWaitTime = TimeUnit.SECONDS.toMillis(10);
404341 long waitQuantum = TimeUnit.MILLISECONDS.toMillis(500);
@@ -508,7 +445,7 @@
508445 if (!clusterInitialized){
509446 try {
510447 //launch ccm cluster
511- ccmBridge = CCMBridge.create("test-class");
448+ ccmBridge = CCMBridge.builder("test-class").withoutNodes().notStarted().build();
512449
513450 ports = new int[5];
514451 for (int i = 0; i < 5; i++) {
@@ -534,7 +471,7 @@
534471
535472 private void initKeyspace() {
536473 try {
537- Builder builder = Cluster.builder();
474+ Cluster.Builder builder = Cluster.builder();
538475
539476 builder = configure(builder);
540477
@@ -594,14 +531,16 @@
594531 if (nbNodes == 0)
595532 throw new IllegalArgumentException();
596533
597- return new CCMCluster(CCMBridge.create("test", nbNodes), builder, nbNodes);
534+ CCMBridge ccm = CCMBridge.builder("test").withNodes(nbNodes).build();
535+ return new CCMCluster(ccm, builder, nbNodes);
598536 }
599537
600538 public static CCMCluster create(int nbNodesDC1, int nbNodesDC2, Cluster.Builder builder) {
601539 if (nbNodesDC1 == 0)
602540 throw new IllegalArgumentException();
603541
604- return new CCMCluster(CCMBridge.create("test", nbNodesDC1, nbNodesDC2), builder, nbNodesDC1 + nbNodesDC2);
542+ CCMBridge ccm = CCMBridge.builder("test").withNodes(nbNodesDC1, nbNodesDC2).build();
543+ return new CCMCluster(ccm, builder, nbNodesDC1 + nbNodesDC2);
605544 }
606545
607546 public static CCMCluster create(CCMBridge cassandraCluster, Cluster.Builder builder, int totalNodes) {
@@ -617,7 +556,8 @@
617556
618557 try {
619558 Thread.sleep(1000);
620- } catch (Exception e) {
559+ } catch (InterruptedException e) {
560+ fail("Unexpected interruption");
621561 }
622562 this.cluster = builder.addContactPoints(contactPoints).build();
623563 this.session = cluster.connect();
@@ -648,4 +588,87 @@
648588 }
649589 }
650590 }
591+
592+ /** use {@link #builder(String)} to get an instance */
593+ public static class Builder {
594+ private final String clusterName;
595+ private Integer[] nodes = { 1 };
596+ private boolean start = true;
597+ private String cassandraVersion = CASSANDRA_VERSION;
598+ private String[] startOptions = new String[0];
599+ private Map<String, String> cassandraConfiguration = Maps.newHashMap();
600+
601+
602+ Builder(String clusterName) {
603+ this.clusterName = clusterName;
604+ }
605+
606+ /** Number of nodes for each DC. Defaults to [1] (1 DC with 1 node) */
607+ public Builder withNodes(Integer... nodes) {
608+ this.nodes = nodes;
609+ return this;
610+ }
611+
612+ public Builder withoutNodes() {
613+ return withNodes();
614+ }
615+
616+ public Builder withSSL(boolean requireClientAuth) {
617+ cassandraConfiguration.put("client_encryption_options.enabled", "true");
618+ cassandraConfiguration.put("client_encryption_options.keystore", DEFAULT_SERVER_KEYSTORE_FILE.getAbsolutePath());
619+ cassandraConfiguration.put("client_encryption_options.keystore_password", DEFAULT_SERVER_KEYSTORE_PASSWORD);
620+
621+ if (requireClientAuth) {
622+ cassandraConfiguration.put("client_encryption_options.require_client_auth", "true");
623+ cassandraConfiguration.put("client_encryption_options.truststore", DEFAULT_SERVER_TRUSTSTORE_FILE.getAbsolutePath());
624+ cassandraConfiguration.put("client_encryption_options.truststore_password", DEFAULT_SERVER_TRUSTSTORE_PASSWORD);
625+ }
626+ return this;
627+ }
628+
629+ /** Whether to start the cluster immediately (defaults to true if this is never called) */
630+ public Builder notStarted() {
631+ this.start = false;
632+ return this;
633+ }
634+
635+ /** Defaults to system property cassandra.version */
636+ public Builder withCassandraVersion(String cassandraVersion) {
637+ this.cassandraVersion = "-v " + cassandraVersion;
638+ return this;
639+ }
640+
641+ /** Free-form options that will be added at the end of the start command */
642+ public Builder withStartOptions(String... options) {
643+ this.startOptions = options;
644+ return this;
645+ }
646+
647+ /** Customizes entries in cassandra.yaml (can be called multiple times) */
648+ public Builder withCassandraConfiguration(String key, String value) {
649+ this.cassandraConfiguration.put(key, value);
650+ return this;
651+ }
652+
653+ public CCMBridge build() {
654+ CCMBridge ccm = new CCMBridge();
655+ ccm.execute(buildCreateCommand());
656+ ccm.updateConfig(cassandraConfiguration);
657+ if (start)
658+ ccm.start();
659+ return ccm;
660+ }
661+
662+ private String buildCreateCommand() {
663+ StringBuilder result = new StringBuilder(CCM_COMMAND + " create");
664+ result.append(" " + clusterName);
665+ result.append(" -i" + IP_PREFIX);
666+ result.append(" " + cassandraVersion);
667+ if (nodes.length > 0)
668+ result.append(" -n " + Joiner.on(":").join(nodes));
669+ if (startOptions.length > 0)
670+ result.append(" " + Joiner.on(" ").join(startOptions));
671+ return result.toString();
672+ }
673+ }
651674 }
modified driver-core/src/test/java/com/datastax/driver/core/ClusterInitTest.java +16 −13
@@ -15,15 +15,6 @@
1515 */
1616 package com.datastax.driver.core;
1717
18-import com.datastax.driver.core.exceptions.NoHostAvailableException;
19-import com.datastax.driver.core.policies.ConstantReconnectionPolicy;
20-import com.datastax.driver.core.querybuilder.Insert;
21-import com.datastax.driver.core.utils.UUIDs;
22-import com.google.common.collect.Lists;
23-import org.slf4j.Logger;
24-import org.slf4j.LoggerFactory;
25-import org.testng.annotations.Test;
26-
2718 import java.net.InetAddress;
2819 import java.net.InetSocketAddress;
2920 import java.util.Collections;
@@ -31,10 +22,23 @@
3122 import java.util.concurrent.TimeUnit;
3223 import java.util.concurrent.TimeoutException;
3324
25+import com.google.common.collect.Lists;
26+import org.slf4j.Logger;
27+import org.slf4j.LoggerFactory;
28+import org.testng.annotations.Test;
29+
30+import static org.assertj.core.api.Assertions.fail;
31+import static org.mockito.Mockito.spy;
32+import static org.mockito.Mockito.times;
33+import static org.mockito.Mockito.verify;
34+
35+import com.datastax.driver.core.exceptions.NoHostAvailableException;
36+import com.datastax.driver.core.policies.ConstantReconnectionPolicy;
37+import com.datastax.driver.core.querybuilder.Insert;
38+import com.datastax.driver.core.utils.UUIDs;
39+
3440 import static com.datastax.driver.core.FakeHost.Behavior.THROWING_CONNECT_TIMEOUTS;
3541 import static com.datastax.driver.core.querybuilder.QueryBuilder.insertInto;
36-import static org.assertj.core.api.Assertions.fail;
37-import static org.mockito.Mockito.*;
3842
3943 public class ClusterInitTest {
4044 private static final Logger logger = LoggerFactory.getLogger(ClusterInitTest.class);
@@ -52,8 +56,7 @@
5256 try {
5357 // Obtaining connect timeouts is not trivial: we create a 6-host cluster but only start one of them,
5458 // then simulate the other 5.
55- ccm = CCMBridge.create("test");
56- ccm.populate(6);
59+ ccm = CCMBridge.builder("test").withNodes(6).notStarted().build();
5760 ccm.start(1);
5861
5962 for (int i = 0; i < 5; i++) {
modified driver-core/src/test/java/com/datastax/driver/core/ControlConnectionTest.java +2 −2
@@ -55,7 +55,7 @@
5555 };
5656
5757 try {
58- ccm = CCMBridge.create("test", 2);
58+ ccm = CCMBridge.builder("test").withNodes(2).build();
5959 // We pass only the first host as contact point, so we know the control connection will be on this host
6060 cluster = Cluster.builder()
6161 .addContactPoint(CCMBridge.ipOfNode(1))
@@ -96,7 +96,7 @@
9696 Cluster cluster = null;
9797
9898 try {
99- ccm = CCMBridge.create("test", 3);
99+ ccm = CCMBridge.builder("test").withNodes(3).build();
100100
101101 cluster = Cluster.builder()
102102 .addContactPoint(CCMBridge.ipOfNode(1))
modified driver-core/src/test/java/com/datastax/driver/core/HeartbeatTest.java +2 −2
@@ -57,7 +57,7 @@
5757 CCMBridge ccm = null;
5858 Cluster cluster = null;
5959 try {
60- ccm = CCMBridge.create("test", 1);
60+ ccm = CCMBridge.builder("test").withNodes(1).build();
6161 cluster = Cluster.builder().addContactPoint(CCMBridge.ipOfNode(1))
6262 .withPoolingOptions(new PoolingOptions()
6363 .setHeartbeatIntervalSeconds(3))
@@ -121,7 +121,7 @@
121121 CCMBridge ccm = null;
122122 Cluster cluster = null;
123123 try {
124- ccm = CCMBridge.create("test", 1);
124+ ccm = CCMBridge.builder("test").withNodes(1).build();
125125 cluster = Cluster.builder().addContactPoint(CCMBridge.ipOfNode(1))
126126 .withPoolingOptions(new PoolingOptions()
127127 .setHeartbeatIntervalSeconds(0))
modified driver-core/src/test/java/com/datastax/driver/core/LoadBalancingPolicyBootstrapTest.java +2 −2
@@ -51,7 +51,7 @@
5151 CCMBridge ccm = null;
5252 Cluster cluster = null;
5353 try {
54- ccm = CCMBridge.create("test", 2);
54+ ccm = CCMBridge.builder("test").withNodes(2).build();
5555 cluster = Cluster.builder()
5656 .addContactPoints(CCMBridge.ipOfNode(1), CCMBridge.ipOfNode(2))
5757 .withLoadBalancingPolicy(policy)
@@ -86,7 +86,7 @@
8686 CCMBridge ccm = null;
8787 Cluster cluster = null;
8888 try {
89- ccm = CCMBridge.create("test", 2);
89+ ccm = CCMBridge.builder("test").withNodes(2).build();
9090
9191 // In order to validate this behavior, we need to stop the first node that would be attempted to be
9292 // established as the control connection.
modified driver-core/src/test/java/com/datastax/driver/core/MetadataTest.java +1 −1
@@ -54,7 +54,7 @@
5454 Cluster cluster = null;
5555
5656 try {
57- ccm = CCMBridge.create("test", 3);
57+ ccm = CCMBridge.builder("test").withNodes(3).build();
5858
5959 cluster = Cluster.builder()
6060 .addContactPoint(CCMBridge.ipOfNode(1))
modified driver-core/src/test/java/com/datastax/driver/core/MissingRpcAddressTest.java +1 −1
@@ -36,7 +36,7 @@
3636
3737 @Test(groups = "short")
3838 public void testMissingRpcAddressAtStartup() throws Exception {
39- CCMBridge ccm = CCMBridge.create("ccm", 2);
39+ CCMBridge ccm = CCMBridge.builder("ccm").withNodes(2).build();
4040
4141 Cluster cluster = null;
4242 try {
modified driver-core/src/test/java/com/datastax/driver/core/NettyOptionsTest.java +1 −1
@@ -48,7 +48,7 @@
4848 public void should_invoke_netty_options_hooks(int hosts, int coreConnections) throws Exception {
4949 //given
5050 int expectedNumberOfCalls = coreConnections * hosts + 1;
51- CCMBridge ccm = CCMBridge.createWithCustomVersion("test", hosts, "2.0.10");
51+ CCMBridge ccm = CCMBridge.builder("test").withNodes(hosts).withCassandraVersion("2.0.10").build();
5252 Cluster cluster = null;
5353 try {
5454 NettyOptions nettyOptions = mock(NettyOptions.class, CALLS_REAL_METHODS.get());
modified driver-core/src/test/java/com/datastax/driver/core/RecommissionedNodeTest.java +8 −8
@@ -44,7 +44,7 @@
4444
4545 @Test(groups = "long")
4646 public void should_ignore_recommissioned_node_on_reconnection_attempt() throws Exception {
47- mainCcm = CCMBridge.create("main", 3);
47+ mainCcm = CCMBridge.builder("main").withNodes(3).build();
4848 // node1 will be our "recommissioned" node, for now we just stop it so that it stays in the peers table.
4949 mainCcm.stop(1);
5050 mainCcm.waitForDown(1);
@@ -56,7 +56,7 @@
5656 // From that point, reconnections to node1 have been scheduled.
5757
5858 // Start another ccm that will reuse node1's address
59- otherCcm = CCMBridge.create("other", 1);
59+ otherCcm = CCMBridge.builder("other").withNodes(1).build();
6060 otherCcm.waitForUp(1);
6161
6262 // Give the driver the time to notice the node is back up and try to connect to it.
@@ -67,7 +67,7 @@
6767
6868 @Test(groups = "long")
6969 public void should_ignore_recommissioned_node_on_control_connection_reconnect() throws Exception {
70- mainCcm = CCMBridge.create("main", 2);
70+ mainCcm = CCMBridge.builder("main").withNodes(2).build();
7171 mainCcm.stop(1);
7272 mainCcm.waitForDown(1);
7373
@@ -77,7 +77,7 @@
7777 waitForCountUpHosts(mainCluster, 1);
7878
7979 // Start another ccm that will reuse node1's address
80- otherCcm = CCMBridge.create("other", 1);
80+ otherCcm = CCMBridge.builder("other").withNodes(1).build();
8181 otherCcm.waitForUp(1);
8282
8383 // Stop node2, the control connection gets defunct
@@ -91,11 +91,11 @@
9191 @Test(groups = "long")
9292 public void should_ignore_recommissioned_node_on_session_init() throws Exception {
9393 // Simulate the bug before starting the cluster
94- mainCcm = CCMBridge.create("main", 2);
94+ mainCcm = CCMBridge.builder("main").withNodes(2).build();
9595 mainCcm.stop(1);
9696 mainCcm.waitForDown(1);
9797
98- otherCcm = CCMBridge.create("other", 1);
98+ otherCcm = CCMBridge.builder("other").withNodes(1).build();
9999 otherCcm.waitForUp(1);
100100
101101 // Start the driver, it should only connect to node 2
@@ -119,11 +119,11 @@
119119 @CassandraVersion(major=2.0)
120120 public void should_ignore_node_that_does_not_support_protocol_version_on_session_init() throws Exception {
121121 // Simulate the bug before starting the cluster
122- mainCcm = CCMBridge.create("main", 2);
122+ mainCcm = CCMBridge.builder("main").withNodes(2).build();
123123 mainCcm.stop(1);
124124 mainCcm.waitForDown(1);
125125
126- otherCcm = CCMBridge.createWithCustomVersion("main", 1, "1.2.19");
126+ otherCcm = CCMBridge.builder("main").withNodes(1).withCassandraVersion("1.2.19").build();
127127 otherCcm.waitForUp(1);
128128
129129 // Start the driver, it should only connect to node 2
modified driver-core/src/test/java/com/datastax/driver/core/ReconnectionTest.java +8 −8
@@ -53,7 +53,7 @@
5353 CCMBridge ccm = null;
5454 Cluster cluster = null;
5555 try {
56- ccm = CCMBridge.create("test", 2);
56+ ccm = CCMBridge.builder("test").withNodes(2).build();
5757 int reconnectionDelay = 1000;
5858 cluster = Cluster.builder()
5959 .addContactPoint(CCMBridge.ipOfNode(1))
@@ -90,10 +90,10 @@
9090 CCMBridge ccm = null;
9191 Cluster cluster = null;
9292 try {
93- ccm = CCMBridge.create("test");
94- ccm.populate(1);
95- // Configure password authentication on the server (default: cassandra / cassandra)
96- ccm.updateConfig("authenticator", "PasswordAuthenticator");
93+ ccm = CCMBridge.builder("test")
94+ .withCassandraConfiguration("authenticator", "PasswordAuthenticator") // default credentials: cassandra / cassandra
95+ .notStarted()
96+ .build();
9797 ccm.start(1, "-Dcassandra.superuser_setup_delay_ms=0");
9898
9999 DynamicPlainTextAuthProvider authProvider = new DynamicPlainTextAuthProvider("cassandra", "cassandra");
@@ -149,7 +149,7 @@
149149 CountingReconnectionPolicy reconnectionPolicy = new CountingReconnectionPolicy(new ConstantReconnectionPolicy(reconnectionDelayMillis));
150150
151151 try {
152- ccm = CCMBridge.create("test", 2);
152+ ccm = CCMBridge.builder("test").withNodes(2).build();
153153 cluster = Cluster.builder()
154154 .addContactPoint(CCMBridge.ipOfNode(1))
155155 .withReconnectionPolicy(reconnectionPolicy)
@@ -190,7 +190,7 @@
190190 TogglabePolicy loadBalancingPolicy = new TogglabePolicy(new RoundRobinPolicy());
191191
192192 try {
193- ccm = CCMBridge.create("test", 1);
193+ ccm = CCMBridge.builder("test").withNodes(1).build();
194194 cluster = Cluster.builder()
195195 .addContactPoint(CCMBridge.ipOfNode(1))
196196 .withLoadBalancingPolicy(loadBalancingPolicy)
@@ -256,7 +256,7 @@
256256 SocketOptions socketOptions = spy(new SocketOptions());
257257
258258 try {
259- ccm = CCMBridge.create("test", 1);
259+ ccm = CCMBridge.builder("test").withNodes(1).build();
260260 cluster = Cluster.builder()
261261 .addContactPoint(CCMBridge.ipOfNode(1))
262262 .withReconnectionPolicy(new ConstantReconnectionPolicy(5000))
modified driver-core/src/test/java/com/datastax/driver/core/RefreshConnectedHostTest.java +1 −2
@@ -41,8 +41,7 @@
4141 LimitingLoadBalancingPolicy loadBalancingPolicy = new LimitingLoadBalancingPolicy(new RoundRobinPolicy(), 2, 1);
4242
4343 // Setup a 3-host cluster, start only two hosts so that we know in advance which ones the policy will use
44- ccm = CCMBridge.create("test");
45- ccm.populate(3);
44+ ccm = CCMBridge.builder("test").withNodes(3).notStarted().build();
4645 ccm.start(1);
4746 ccm.start(2);
4847 ccm.waitForUp(1);
modified driver-core/src/test/java/com/datastax/driver/core/SSLTestBase.java +3 −10
@@ -17,7 +17,6 @@
1717
1818 import java.security.KeyStore;
1919 import java.security.SecureRandom;
20-import java.util.concurrent.TimeUnit;
2120
2221 import com.google.common.base.Optional;
2322 import javax.net.ssl.KeyManagerFactory;
@@ -25,15 +24,9 @@
2524 import javax.net.ssl.TrustManagerFactory;
2625 import org.testng.annotations.AfterClass;
2726 import org.testng.annotations.BeforeClass;
28-import org.testng.annotations.Test;
2927
30-import com.datastax.driver.core.exceptions.NoHostAvailableException;
31-
32-import static com.datastax.driver.core.Assertions.assertThat;
3328 import static com.datastax.driver.core.CCMBridge.DEFAULT_CLIENT_KEYSTORE_PASSWORD;
34-import static com.datastax.driver.core.CCMBridge.DEFAULT_CLIENT_KEYSTORE_PATH;
3529 import static com.datastax.driver.core.CCMBridge.DEFAULT_CLIENT_TRUSTSTORE_PASSWORD;
36-import static com.datastax.driver.core.CCMBridge.DEFAULT_CLIENT_TRUSTSTORE_PATH;
3730 public abstract class SSLTestBase {
3831
3932 private final boolean requireClientAuth;
@@ -46,9 +39,9 @@
4639
4740 @BeforeClass(groups={"short", "long"})
4841 public void beforeClass() {
49- ccm = CCMBridge.create("test");
50- ccm.enableSSL(requireClientAuth);
51- ccm.bootstrapNode(1);
42+ ccm = CCMBridge.builder("test")
43+ .withSSL(requireClientAuth)
44+ .build();
5245 }
5346
5447 @AfterClass(groups={"short", "long"})
modified driver-core/src/test/java/com/datastax/driver/core/SchemaAgreementTest.java +1 −1
@@ -41,7 +41,7 @@
4141
4242 @BeforeClass(groups = "short")
4343 public void setup() {
44- ccm = CCMBridge.create("schema_agreement", 2);
44+ ccm = CCMBridge.builder("schema_agreement").withNodes(2).build();
4545 cluster = Cluster.builder().addContactPoint(CCMBridge.ipOfNode(1)).build();
4646 session = cluster.connect();
4747 session.execute("create keyspace test with replication = {'class': 'SimpleStrategy', 'replication_factor': 1}");
modified driver-core/src/test/java/com/datastax/driver/core/SchemaChangesTest.java +1 −1
@@ -41,7 +41,7 @@
4141
4242 @BeforeClass(groups = "short")
4343 public void setup() {
44- ccm = CCMBridge.create("schemaChangesTest", 1);
44+ ccm = CCMBridge.builder("schemaChangesTest").withNodes(1).build();
4545
4646 cluster = Cluster.builder().addContactPoint(CCMBridge.ipOfNode(1)).build();
4747 cluster2 = Cluster.builder().addContactPoint(CCMBridge.ipOfNode(1)).build();
modified driver-core/src/test/java/com/datastax/driver/core/SessionLeakTest.java +2 −6
@@ -27,13 +27,9 @@
2727 import static org.testng.Assert.assertEquals;
2828 import static java.util.concurrent.TimeUnit.MINUTES;
2929
30-import com.google.common.collect.Lists;
31-import org.testng.annotations.Test;
32-
3330 import static org.assertj.core.api.Assertions.fail;
3431
3532 import com.datastax.driver.core.exceptions.InvalidQueryException;
36-import com.datastax.driver.core.utils.SocketChannelMonitor;
3733
3834 import static com.datastax.driver.core.Assertions.assertThat;
3935
@@ -50,7 +46,7 @@
5046 public void connectionLeakTest() throws Exception {
5147 // Checking for JAVA-342
5248 CCMBridge ccmBridge;
53- ccmBridge = CCMBridge.create("test", 1);
49+ ccmBridge = CCMBridge.builder("test").withNodes(1).build();
5450 channelMonitor = new SocketChannelMonitor();
5551 channelMonitor.reportAtFixedInterval(1, TimeUnit.SECONDS);
5652 try {
@@ -113,7 +109,7 @@
113109 public void should_not_leak_session_when_wrong_keyspace() throws Exception {
114110 // Checking for JAVA-806
115111 CCMBridge ccmBridge;
116- ccmBridge = CCMBridge.create("test", 1);
112+ ccmBridge = CCMBridge.builder("test").withNodes(1).build();
117113 channelMonitor = new SocketChannelMonitor();
118114 channelMonitor.reportAtFixedInterval(1, TimeUnit.SECONDS);
119115 try {
modified driver-core/src/test/java/com/datastax/driver/core/SingleTokenIntegrationTest.java +4 −5
@@ -34,11 +34,10 @@
3434 Cluster cluster = null;
3535
3636 try {
37- ccm = CCMBridge.create("test");
38- // force the initial token to a non-min value to validate that the single range will always be ]minToken, minToken]
39- ccm.updateConfig("initial_token", "1");
40- ccm.bootstrapNode(1);
41- ccm.start();
37+ ccm = CCMBridge.builder("test")
38+ // force the initial token to a non-min value to validate that the single range will always be ]minToken, minToken]
39+ .withCassandraConfiguration("initial_token", "1")
40+ .build();
4241
4342 cluster = Cluster.builder().addContactPoint(CCMBridge.ipOfNode(1)).build();
4443
modified driver-core/src/test/java/com/datastax/driver/core/TimeoutStressTest.java +1 −1
@@ -70,7 +70,7 @@
7070
7171 @BeforeClass(groups = "long")
7272 public void beforeClass() throws Exception {
73- ccmBridge = CCMBridge.create("test", 3);
73+ ccmBridge = CCMBridge.builder("test").withNodes(3).build();
7474 channelMonitor = new SocketChannelMonitor();
7575 nodes = Lists.newArrayList(
7676 new InetSocketAddress(CCMBridge.IP_PREFIX + '1', 9042),
modified driver-core/src/test/java/com/datastax/driver/core/TokenIntegrationTest.java +1 −1
@@ -72,7 +72,7 @@
7272
7373 @BeforeClass(groups = "short")
7474 public void setup() {
75- ccm = CCMBridge.create("test", 3, ccmOptions);
75+ ccm = CCMBridge.builder("test").withNodes(3).withStartOptions(ccmOptions).build();
7676
7777 // Only connect to node 1, which makes it easier to query system tables in should_expose_tokens_per_host()
7878 LoadBalancingPolicy lbp = new WhiteListPolicy(new RoundRobinPolicy(),
modified driver-core/src/test/java/com/datastax/driver/core/policies/CloseableLoadBalancingPolicyTest.java +1 −1
@@ -29,7 +29,7 @@
2929 CCMBridge ccm = null;
3030 Cluster cluster = null;
3131 try {
32- ccm = CCMBridge.create("test", 1);
32+ ccm = CCMBridge.builder("test").withNodes(1).build();
3333 cluster = Cluster.builder()
3434 .addContactPoint(CCMBridge.ipOfNode(1))
3535 .withLoadBalancingPolicy(policy)
modified driver-core/src/test/java/com/datastax/driver/core/policies/DCAwareRoundRobinPolicyTest.java +1 −1
@@ -36,7 +36,7 @@
3636 @BeforeClass(groups = "short")
3737 public void createCcm() {
3838 // Two-DC cluster with one host in each DC
39- ccm = CCMBridge.create("test", 1, 1);
39+ ccm = CCMBridge.builder("test").withNodes(1, 1).build();
4040 }
4141
4242 @AfterClass(groups = "short")
modified driver-core/src/test/java/com/datastax/driver/core/policies/DowngradingConsistencyRetryPolicyIntegrationTest.java +1 −1
@@ -46,7 +46,7 @@
4646 Cluster cluster = null;
4747 try {
4848 // 3-node cluster, keyspace with RF = 3
49- ccm = CCMBridge.create(this.getClass().getName(), 3);
49+ ccm = CCMBridge.builder(this.getClass().getName()).withNodes(3).build();
5050 cluster = Cluster.builder()
5151 .addContactPoint(CCMBridge.ipOfNode(1))
5252 .withRetryPolicy(Mockito.spy(DowngradingConsistencyRetryPolicy.INSTANCE))
modified driver-core/src/test/java/com/datastax/driver/core/policies/TokenAwarePolicyTest.java +1 −3
@@ -16,9 +16,7 @@
1616 package com.datastax.driver.core.policies;
1717
1818 import java.nio.ByteBuffer;
19-import java.util.ArrayList;
2019 import java.util.List;
21-import java.util.Set;
2220
2321 import static org.assertj.core.api.Assertions.assertThat;
2422 import com.google.common.collect.Lists;
@@ -44,7 +42,7 @@
4442 CCMBridge ccm = null;
4543 Cluster cluster = null;
4644 try {
47- ccm = CCMBridge.create("test", 3);
45+ ccm = CCMBridge.builder("test").withNodes(3).build();
4846 cluster = Cluster.builder()
4947 .addContactPoint(CCMBridge.ipOfNode(1))
5048 .withLoadBalancingPolicy(loadBalancingPolicy)
modified driver-examples/osgi/src/test/java/com/datastax/driver/osgi/CCMBridgeListener.java +1 −1
@@ -33,7 +33,7 @@
3333 private CCMBridge ccm;
3434
3535 @Override public void onStart(ITestContext context) {
36- ccm = CCMBridge.create("test", 1);
36+ ccm = CCMBridge.builder("test").withNodes(1).build();
3737 }
3838
3939 @Override public void onFinish(ITestContext context) {