Elffuss BraidHub

kikocis/java-driver public

Merge branch '2.0' into 2.1 (doc and test changes only)
Changesetdb477ca76c88fcf2b55b3b65e8bef4bd809d112dfcd3b4e95f2b7181367ce8c4
Authorolim7t <omichallat+github@gmail.com> · 2015-07-11 21:11 +02:00
Committerolim7t <omichallat+github@gmail.com> · 2015-07-11 21:21 +02:00
Parentsa542c0877cae, cd5f31cb7f27

Browse the files at this changeset

31 files changed

modified README.md +3 −1
@@ -57,7 +57,9 @@
5757 - MAILING LIST: https://groups.google.com/a/lists.datastax.com/forum/#!forum/java-driver-user
5858 - IRC: #datastax-drivers on [irc.freenode.net](http://freenode.net)
5959 - TWITTER: Follow the latest news about DataStax Drivers - [@olim7t](http://twitter.com/olim7t), [@mfiguiere](http://twitter.com/mfiguiere)
60-- DOCS: http://www.datastax.com/documentation/developer/java-driver/2.1/index.html
60+- DOCS: the [user guide](http://docs.datastax.com/en/developer/java-driver/2.1/java-driver/whatsNew2.html)
61+ has introductory material. We are progressively migrating the doc
62+ [here](features/) with more technical details.
6163 - API: http://www.datastax.com/drivers/java/2.1
6264
6365 **Feeback requested:** help us focus our efforts, provide your input on the [Platform and Runtime Survey](http://goo.gl/forms/qwUE6qnL7U) (we kept it short).
modified driver-core/src/main/java/com/datastax/driver/core/PoolingOptions.java +4 −0
@@ -135,6 +135,8 @@
135135 *
136136 * @throws IllegalArgumentException if {@code distance == HostDistance.IGNORED},
137137 * or if {@code newCoreConnections} is greater than the maximum value for this distance.
138+ *
139+ * @see #setConnectionsPerHost(HostDistance, int, int)
138140 */
139141 public synchronized PoolingOptions setCoreConnectionsPerHost(HostDistance distance, int newCoreConnections) {
140142 if (distance == HostDistance.IGNORED)
@@ -178,6 +180,8 @@
178180 *
179181 * @throws IllegalArgumentException if {@code distance == HostDistance.IGNORED},
180182 * or if {@code newMaxConnections} is less than the core value for this distance.
183+ *
184+ * @see #setConnectionsPerHost(HostDistance, int, int)
181185 */
182186 public synchronized PoolingOptions setMaxConnectionsPerHost(HostDistance distance, int newMaxConnections) {
183187 if (distance == HostDistance.IGNORED)
modified driver-core/src/test/java/com/datastax/driver/core/AbstractPoliciesTest.java +1 −1
@@ -51,7 +51,7 @@
5151 }
5252
5353 public static void createMultiDCSchema(Session session, int dc1RF, int dc2RF) {
54- session.execute(String.format(CREATE_KEYSPACE_GENERIC_FORMAT, SIMPLE_KEYSPACE, "NetworkTopologyStrategy", String.format("'dc1' : %d, 'dc2' : %d", dc1RF, dc2RF)));
54+ session.execute(String.format(CREATE_KEYSPACE_GENERIC_FORMAT, SIMPLE_KEYSPACE, "NetworkTopologyStrategy", String.format("'datacenter1' : %d, 'datacenter2' : %d", dc1RF, dc2RF)));
5555 session.execute("USE " + SIMPLE_KEYSPACE);
5656 session.execute(String.format("CREATE TABLE %s (k int PRIMARY KEY, i int)", SIMPLE_TABLE));
5757 }
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 −102
@@ -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,37 +181,8 @@
190181 return f;
191182 }
192183
193- public static CCMBridge create(String name, String... options) {
194- // This leads to a confusing CCM error message so check explicitly:
195- checkArgument(!"current".equals(name.toLowerCase()),
196- "cluster can't be called \"current\"");
197- CCMBridge bridge = new CCMBridge();
198- bridge.execute(CCM_COMMAND + " create %s -b -i %s %s " + Joiner.on(" ").join(options), name, IP_PREFIX, CASSANDRA_VERSION);
199- return bridge;
200- }
201-
202- public static CCMBridge create(String name, int nbNodes, String... options) {
203- checkArgument(!"current".equals(name.toLowerCase()),
204- "cluster can't be called \"current\"");
205- CCMBridge bridge = new CCMBridge();
206- bridge.execute(CCM_COMMAND + " create %s -n %d -s -i %s -b %s " + Joiner.on(" ").join(options), name, nbNodes, IP_PREFIX, CASSANDRA_VERSION);
207- return bridge;
208- }
209-
210- public static CCMBridge createWithCustomVersion(String name, int nbNodes, String cassandraVersion) {
211- checkArgument(!"current".equals(name.toLowerCase()),
212- "cluster can't be called \"current\"");
213- CCMBridge bridge = new CCMBridge();
214- bridge.execute(CCM_COMMAND + " create %s -n %d -s -i %s -b -v %s ", name, nbNodes, IP_PREFIX, cassandraVersion);
215- return bridge;
216- }
217-
218- public static CCMBridge create(String name, int nbNodesDC1, int nbNodesDC2) {
219- checkArgument(!"current".equals(name.toLowerCase()),
220- "cluster can't be called \"current\"");
221- CCMBridge bridge = new CCMBridge();
222- bridge.execute(CCM_COMMAND + " create %s -n %d:%d -s -i %s -b %s", name, nbNodesDC1, nbNodesDC2, IP_PREFIX, CASSANDRA_VERSION);
223- return bridge;
184+ public static Builder builder(String clusterName) {
185+ return new Builder(clusterName);
224186 }
225187
226188 public static CCMBridge.CCMCluster buildCluster(int nbNodes, Cluster.Builder builder) {
@@ -248,9 +210,9 @@
248210 execute(CCM_COMMAND + " node%d start --wait-other-notice --wait-for-binary-proto", n);
249211 }
250212
251- public void start(int n, String option) {
252- logger.info("Starting: " + IP_PREFIX + n + " with " + option);
253- 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);
254216 }
255217
256218 public void stop(int n) {
@@ -259,7 +221,7 @@
259221 }
260222
261223 public void stop(String clusterName) {
262- logger.info("Stopping Cluster : "+clusterName);
224+ logger.info("Stopping Cluster : " + clusterName);
263225 execute(CCM_COMMAND + " stop "+clusterName);
264226 }
265227
@@ -309,10 +271,6 @@
309271 execute(CCM_COMMAND + " node%d decommission", n);
310272 }
311273
312- public void updateConfig(String name, String value) {
313- updateConfig(ImmutableMap.of(name, value));
314- }
315-
316274 public void updateConfig(Map<String, String> configs) {
317275 StringBuilder confStr = new StringBuilder();
318276 for (Map.Entry<String, String> entry : configs.entrySet()) {
@@ -321,10 +279,6 @@
321279 execute(CCM_COMMAND + " updateconf " + confStr);
322280 }
323281
324- public void populate(int n) {
325- execute(CCM_COMMAND + " populate -n %d -i %s", n, IP_PREFIX);
326- }
327-
328282 private void execute(String command, Object... args) {
329283
330284 String fullCommand = String.format(command, args) + " --config-dir=" + ccmDir;
@@ -332,6 +286,7 @@
332286 logger.debug("Executing: " + fullCommand);
333287 CommandLine cli = CommandLine.parse(fullCommand);
334288 Executor executor = new DefaultExecutor();
289+ executor.setWorkingDirectory(CASSANDRA_DIR);
335290
336291 LogOutputStream outStream = new LogOutputStream() {
337292 @Override protected void processLine(String line, int logLevel) {
@@ -381,33 +336,6 @@
381336 }
382337 }
383338
384- /**
385- * Enables SSL without client authentication. Does not apply to already started nodes.
386- */
387- public void enableSSL() {
388- enableSSL(false);
389- }
390-
391- /**
392- * Enables SSL. Does not apply to already started nodes.
393- * @param requireClientAuth Whether or not to require Clients used authentication.
394- */
395- public void enableSSL(boolean requireClientAuth) {
396- ImmutableMap.Builder<String, String> configs = ImmutableMap.builder();
397-
398- configs.put("client_encryption_options.enabled", "true");
399- configs.put("client_encryption_options.keystore", DEFAULT_SERVER_KEYSTORE_FILE.getAbsolutePath());
400- configs.put("client_encryption_options.keystore_password", DEFAULT_SERVER_KEYSTORE_PASSWORD);
401-
402- if (requireClientAuth) {
403- configs.put("client_encryption_options.require_client_auth", "true");
404- configs.put("client_encryption_options.truststore", DEFAULT_SERVER_TRUSTSTORE_FILE.getAbsolutePath());
405- configs.put("client_encryption_options.truststore_password", DEFAULT_SERVER_TRUSTSTORE_PASSWORD);
406- }
407-
408- updateConfig(configs.build());
409- }
410-
411339 private static void busyWaitForPort(InetAddress address, int port, boolean expectedConnectionState) {
412340 long maxAcceptableWaitTime = TimeUnit.SECONDS.toMillis(10);
413341 long waitQuantum = TimeUnit.MILLISECONDS.toMillis(500);
@@ -519,7 +447,7 @@
519447 if (!clusterInitialized){
520448 try {
521449 //launch ccm cluster
522- ccmBridge = CCMBridge.create("test-class");
450+ ccmBridge = CCMBridge.builder("test-class").withoutNodes().notStarted().build();
523451
524452 ports = new int[5];
525453 for (int i = 0; i < 5; i++) {
@@ -545,7 +473,7 @@
545473
546474 private void initKeyspace() {
547475 try {
548- Builder builder = Cluster.builder();
476+ Cluster.Builder builder = Cluster.builder();
549477
550478 builder = configure(builder);
551479
@@ -605,14 +533,16 @@
605533 if (nbNodes == 0)
606534 throw new IllegalArgumentException();
607535
608- return new CCMCluster(CCMBridge.create("test", nbNodes), builder, nbNodes);
536+ CCMBridge ccm = CCMBridge.builder("test").withNodes(nbNodes).build();
537+ return new CCMCluster(ccm, builder, nbNodes);
609538 }
610539
611540 public static CCMCluster create(int nbNodesDC1, int nbNodesDC2, Cluster.Builder builder) {
612541 if (nbNodesDC1 == 0)
613542 throw new IllegalArgumentException();
614543
615- return new CCMCluster(CCMBridge.create("test", nbNodesDC1, nbNodesDC2), builder, nbNodesDC1 + nbNodesDC2);
544+ CCMBridge ccm = CCMBridge.builder("test").withNodes(nbNodesDC1, nbNodesDC2).build();
545+ return new CCMCluster(ccm, builder, nbNodesDC1 + nbNodesDC2);
616546 }
617547
618548 public static CCMCluster create(CCMBridge cassandraCluster, Cluster.Builder builder, int totalNodes) {
@@ -628,7 +558,8 @@
628558
629559 try {
630560 Thread.sleep(1000);
631- } catch (Exception e) {
561+ } catch (InterruptedException e) {
562+ fail("Unexpected interruption");
632563 }
633564 this.cluster = builder.addContactPoints(contactPoints).build();
634565 this.session = cluster.connect();
@@ -659,4 +590,87 @@
659590 }
660591 }
661592 }
593+
594+ /** use {@link #builder(String)} to get an instance */
595+ public static class Builder {
596+ private final String clusterName;
597+ private Integer[] nodes = { 1 };
598+ private boolean start = true;
599+ private String cassandraVersion = CASSANDRA_VERSION;
600+ private String[] startOptions = new String[0];
601+ private Map<String, String> cassandraConfiguration = Maps.newHashMap();
602+
603+
604+ Builder(String clusterName) {
605+ this.clusterName = clusterName;
606+ }
607+
608+ /** Number of nodes for each DC. Defaults to [1] (1 DC with 1 node) */
609+ public Builder withNodes(Integer... nodes) {
610+ this.nodes = nodes;
611+ return this;
612+ }
613+
614+ public Builder withoutNodes() {
615+ return withNodes();
616+ }
617+
618+ public Builder withSSL(boolean requireClientAuth) {
619+ cassandraConfiguration.put("client_encryption_options.enabled", "true");
620+ cassandraConfiguration.put("client_encryption_options.keystore", DEFAULT_SERVER_KEYSTORE_FILE.getAbsolutePath());
621+ cassandraConfiguration.put("client_encryption_options.keystore_password", DEFAULT_SERVER_KEYSTORE_PASSWORD);
622+
623+ if (requireClientAuth) {
624+ cassandraConfiguration.put("client_encryption_options.require_client_auth", "true");
625+ cassandraConfiguration.put("client_encryption_options.truststore", DEFAULT_SERVER_TRUSTSTORE_FILE.getAbsolutePath());
626+ cassandraConfiguration.put("client_encryption_options.truststore_password", DEFAULT_SERVER_TRUSTSTORE_PASSWORD);
627+ }
628+ return this;
629+ }
630+
631+ /** Whether to start the cluster immediately (defaults to true if this is never called) */
632+ public Builder notStarted() {
633+ this.start = false;
634+ return this;
635+ }
636+
637+ /** Defaults to system property cassandra.version */
638+ public Builder withCassandraVersion(String cassandraVersion) {
639+ this.cassandraVersion = "-v " + cassandraVersion;
640+ return this;
641+ }
642+
643+ /** Free-form options that will be added at the end of the start command */
644+ public Builder withStartOptions(String... options) {
645+ this.startOptions = options;
646+ return this;
647+ }
648+
649+ /** Customizes entries in cassandra.yaml (can be called multiple times) */
650+ public Builder withCassandraConfiguration(String key, String value) {
651+ this.cassandraConfiguration.put(key, value);
652+ return this;
653+ }
654+
655+ public CCMBridge build() {
656+ CCMBridge ccm = new CCMBridge();
657+ ccm.execute(buildCreateCommand());
658+ ccm.updateConfig(cassandraConfiguration);
659+ if (start)
660+ ccm.start();
661+ return ccm;
662+ }
663+
664+ private String buildCreateCommand() {
665+ StringBuilder result = new StringBuilder(CCM_COMMAND + " create");
666+ result.append(" " + clusterName);
667+ result.append(" -i" + IP_PREFIX);
668+ result.append(" " + cassandraVersion);
669+ if (nodes.length > 0)
670+ result.append(" -n " + Joiner.on(":").join(nodes));
671+ if (startOptions.length > 0)
672+ result.append(" " + Joiner.on(" ").join(startOptions));
673+ return result.toString();
674+ }
675+ }
662676 }
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 +3 −3
@@ -56,7 +56,7 @@
5656 };
5757
5858 try {
59- ccm = CCMBridge.create("test", 2);
59+ ccm = CCMBridge.builder("test").withNodes(2).build();
6060 // We pass only the first host as contact point, so we know the control connection will be on this host
6161 cluster = Cluster.builder()
6262 .addContactPoint(CCMBridge.ipOfNode(1))
@@ -95,7 +95,7 @@
9595 Cluster cluster = null;
9696
9797 try {
98- ccm = CCMBridge.create("test", 1);
98+ ccm = CCMBridge.builder("test").build();
9999
100100 // First driver instance: create UDT
101101 cluster = Cluster.builder().addContactPoint(CCMBridge.ipOfNode(1)).build();
@@ -132,7 +132,7 @@
132132 Cluster cluster = null;
133133
134134 try {
135- ccm = CCMBridge.create("test", 3);
135+ ccm = CCMBridge.builder("test").withNodes(3).build();
136136
137137 cluster = Cluster.builder()
138138 .addContactPoint(CCMBridge.ipOfNode(1))
modified driver-core/src/test/java/com/datastax/driver/core/ExceptionsTest.java +7 −5
@@ -15,6 +15,8 @@
1515 */
1616 package com.datastax.driver.core;
1717
18+import java.util.Locale;
19+
1820 import com.datastax.driver.core.exceptions.*;
1921 import org.testng.annotations.Test;
2022
@@ -192,7 +194,7 @@
192194 c.session.execute("USE " + keyspace);
193195 c.session.execute(String.format(TestUtils.CREATE_TABLE_SIMPLE_FORMAT, table));
194196
195- c.session.execute(new SimpleStatement(String.format(TestUtils.INSERT_FORMAT, table, key, "foo", 42, 24.03f)).setConsistencyLevel(ConsistencyLevel.ALL));
197+ c.session.execute(new SimpleStatement(String.format(Locale.US, TestUtils.INSERT_FORMAT, table, key, "foo", 42, 24.03f)).setConsistencyLevel(ConsistencyLevel.ALL));
196198 c.session.execute(new SimpleStatement(String.format(TestUtils.SELECT_ALL_FORMAT, table)).setConsistencyLevel(ConsistencyLevel.ALL));
197199
198200 c.cassandraCluster.forceStop(2);
@@ -308,7 +310,7 @@
308310 c.session.execute("USE " + keyspace);
309311 c.session.execute(String.format(TestUtils.CREATE_TABLE_SIMPLE_FORMAT, table));
310312
311- c.session.execute(new SimpleStatement(String.format(TestUtils.INSERT_FORMAT, table, key, "foo", 42, 24.03f)).setConsistencyLevel(ConsistencyLevel.ALL));
313+ c.session.execute(new SimpleStatement(String.format(Locale.US, TestUtils.INSERT_FORMAT, table, key, "foo", 42, 24.03f)).setConsistencyLevel(ConsistencyLevel.ALL));
312314 c.session.execute(new SimpleStatement(String.format(TestUtils.SELECT_ALL_FORMAT, table)).setConsistencyLevel(ConsistencyLevel.ALL));
313315
314316 c.cassandraCluster.stop(2);
@@ -326,7 +328,7 @@
326328 }
327329
328330 try{
329- c.session.execute(new SimpleStatement(String.format(TestUtils.INSERT_FORMAT, table, key, "foo", 42, 24.03f)).setConsistencyLevel(ConsistencyLevel.ALL));
331+ c.session.execute(new SimpleStatement(String.format(Locale.US, TestUtils.INSERT_FORMAT, table, key, "foo", 42, 24.03f)).setConsistencyLevel(ConsistencyLevel.ALL));
330332 } catch (UnavailableException e) {
331333 String expectedError = String.format("Not enough replica available for query at consistency %s (%d required but only %d alive)", "ALL", 3, 2);
332334 assertEquals(e.getMessage(), expectedError);
@@ -361,12 +363,12 @@
361363 c.session.execute("USE " + keyspace);
362364 c.session.execute(String.format(TestUtils.CREATE_TABLE_SIMPLE_FORMAT, table));
363365
364- c.session.execute(new SimpleStatement(String.format(TestUtils.INSERT_FORMAT, table, key, "foo", 42, 24.03f)).setConsistencyLevel(ConsistencyLevel.ALL));
366+ c.session.execute(new SimpleStatement(String.format(Locale.US, TestUtils.INSERT_FORMAT, table, key, "foo", 42, 24.03f)).setConsistencyLevel(ConsistencyLevel.ALL));
365367 c.session.execute(new SimpleStatement(String.format(TestUtils.SELECT_ALL_FORMAT, table)).setConsistencyLevel(ConsistencyLevel.ALL));
366368
367369 c.cassandraCluster.forceStop(2);
368370 try{
369- c.session.execute(new SimpleStatement(String.format(TestUtils.INSERT_FORMAT, table, key, "foo", 42, 24.03f)).setConsistencyLevel(ConsistencyLevel.ALL));
371+ c.session.execute(new SimpleStatement(String.format(Locale.US, TestUtils.INSERT_FORMAT, table, key, "foo", 42, 24.03f)).setConsistencyLevel(ConsistencyLevel.ALL));
370372 } catch (WriteTimeoutException e) {
371373 assertEquals(e.getConsistencyLevel(), ConsistencyLevel.ALL);
372374 assertEquals(e.getReceivedAcknowledgements(), 2);
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
@@ -47,7 +47,7 @@
4747 @Test(groups = "short", dataProvider = "NettyOptionsTest")
4848 public void should_invoke_netty_options_hooks(int hosts, int coreConnections) throws Exception {
4949 //given
50- CCMBridge ccm = CCMBridge.create("test", hosts);
50+ CCMBridge ccm = CCMBridge.builder("test").withNodes(hosts).build();
5151 Cluster cluster = null;
5252 try {
5353 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
@@ -42,7 +42,7 @@
4242
4343 @BeforeClass(groups = "short")
4444 public void setup() {
45- ccm = CCMBridge.create("schemaChangesTest", 1);
45+ ccm = CCMBridge.builder("schemaChangesTest").withNodes(1).build();
4646
4747 cluster = Cluster.builder().addContactPoint(CCMBridge.ipOfNode(1)).build();
4848 cluster2 = Cluster.builder().addContactPoint(CCMBridge.ipOfNode(1)).build();
modified driver-core/src/test/java/com/datastax/driver/core/SessionLeakTest.java +2 −2
@@ -44,7 +44,7 @@
4444 public void connectionLeakTest() throws Exception {
4545 // Checking for JAVA-342
4646 CCMBridge ccmBridge;
47- ccmBridge = CCMBridge.create("test", 1);
47+ ccmBridge = CCMBridge.builder("test").withNodes(1).build();
4848 channelMonitor = new SocketChannelMonitor();
4949 channelMonitor.reportAtFixedInterval(1, TimeUnit.SECONDS);
5050 try {
@@ -107,7 +107,7 @@
107107 public void should_not_leak_session_when_wrong_keyspace() throws Exception {
108108 // Checking for JAVA-806
109109 CCMBridge ccmBridge;
110- ccmBridge = CCMBridge.create("test", 1);
110+ ccmBridge = CCMBridge.builder("test").withNodes(1).build();
111111 channelMonitor = new SocketChannelMonitor();
112112 channelMonitor.reportAtFixedInterval(1, TimeUnit.SECONDS);
113113 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/StateListenerTest.java +87 −51
@@ -15,76 +15,112 @@
1515 */
1616 package com.datastax.driver.core;
1717
18-import com.google.common.collect.Sets;
19-import org.testng.annotations.Test;
18+import java.util.concurrent.CountDownLatch;
19+
20+import static java.util.concurrent.TimeUnit.MINUTES;
2021
21-import java.util.Set;
22+import org.slf4j.Logger;
23+import org.slf4j.LoggerFactory;
24+import org.testng.annotations.Test;
2225
23-import static org.testng.Assert.assertEquals;
26+import static org.assertj.core.api.Assertions.assertThat;
2427
25-import static com.datastax.driver.core.TestUtils.*;
28+import static com.datastax.driver.core.StateListenerTest.TestListener.Event.*;
2629
27-/**
28- * Simple test of the Sessions methods against a one node cluster.
29- */
3030 public class StateListenerTest {
31+ private static final Logger logger = LoggerFactory.getLogger(StateListenerTest.class);
3132
3233 @Test(groups = "long")
33- public void listenerTest() throws Throwable {
34-
35- CCMBridge.CCMCluster c = CCMBridge.buildCluster(1, Cluster.builder());
36- Cluster cluster = c.cluster;
37-
34+ public void should_receive_events_when_node_states_change() throws InterruptedException {
35+ CCMBridge ccm = null;
36+ Cluster cluster = null;
3837 try {
39- CountingListener listener = new CountingListener();
38+ ccm = CCMBridge.builder("test").build();
39+ cluster = Cluster.builder()
40+ .addContactPoint(CCMBridge.ipOfNode(1))
41+ .build();
42+ cluster.init();
43+ TestListener listener = new TestListener();
4044 cluster.register(listener);
4145
42- c.cassandraCluster.bootstrapNode(2);
43- waitFor(CCMBridge.IP_PREFIX + '2', cluster);
44-
45- // We sleep slightly before checking the listener because the node is marked UP
46- // just before the listeners are called, and since waitFor is based on isUP,
47- // it can return *just* before the listener are called.
48- Thread.sleep(500);
49- assertEquals(listener.adds.size(), 1);
50-
51- c.cassandraCluster.forceStop(1);
52- waitForDown(CCMBridge.IP_PREFIX + '1', cluster);
53- Thread.sleep(500);
54- assertEquals(listener.downs.size(), 1);
55-
56- c.cassandraCluster.start(1);
57- waitFor(CCMBridge.IP_PREFIX + '1', cluster);
58- Thread.sleep(500);
59- assertEquals(listener.ups.size(), 1);
60-
61- c.cassandraCluster.decommissionNode(2);
62- waitForDecommission(CCMBridge.IP_PREFIX + '2', cluster);
63- Thread.sleep(500);
64- assertEquals(listener.removes.size(), 1);
65- } catch (Throwable e) {
66- c.errorOut();
67- throw e;
46+ listener.setExpectedEvent(ADD);
47+ ccm.bootstrapNode(2);
48+ listener.waitForEvent();
49+
50+ listener.setExpectedEvent(DOWN);
51+ ccm.forceStop(1);
52+ listener.waitForEvent();
53+
54+ listener.setExpectedEvent(UP);
55+ ccm.start(1);
56+ listener.waitForEvent();
57+
58+ listener.setExpectedEvent(REMOVE);
59+ ccm.decommissionNode(2);
60+ listener.waitForEvent();
61+
6862 } finally {
69- c.discard();
63+ if (cluster != null)
64+ cluster.close();
65+ if (ccm != null)
66+ ccm.remove();
7067 }
7168 }
7269
73- private static class CountingListener implements Host.StateListener {
70+ static class TestListener implements Host.StateListener {
71+ enum Event {ADD, UP, SUSPECTED, DOWN, REMOVE}
72+
73+ volatile CountDownLatch latch;
74+ volatile Event expectedEvent;
75+ volatile Event actualEvent;
7476
75- public Set<Host> adds = Sets.newHashSet();
76- public Set<Host> removes = Sets.newHashSet();
77- public Set<Host> ups = Sets.newHashSet();
78- public Set<Host> downs = Sets.newHashSet();
77+ void setExpectedEvent(Event expectedEvent) {
78+ logger.debug("Set expected event {}", expectedEvent);
79+ this.expectedEvent = expectedEvent;
80+ latch = new CountDownLatch(1);
81+ }
82+
83+ void waitForEvent() throws InterruptedException {
84+ assertThat(latch.await(2, MINUTES))
85+ .as("Timed out waiting for event " + expectedEvent)
86+ .isTrue();
87+ assertThat(actualEvent).isEqualTo(expectedEvent);
88+ }
89+
90+ private void reportActualEvent(Event event) {
91+ if (latch.getCount() == 0) {
92+ // TODO this actually happens because C* sends REMOVE/ADD/REMOVE on a remove
93+ logger.error("Was not waiting for an event but got {} (this should eventually be fixed by JAVA-657)", event);
94+ return;
95+ }
96+ logger.debug("Got event {}", event);
97+ actualEvent = event;
98+ latch.countDown();
99+ }
79100
80- public void onAdd(Host host) { adds.add(host); }
101+ @Override
102+ public void onAdd(Host host) {
103+ reportActualEvent(ADD);
104+ }
81105
82- public void onUp(Host host) { ups.add(host); }
106+ @Override
107+ public void onUp(Host host) {
108+ reportActualEvent(UP);
109+ }
83110
84- public void onSuspected(Host host) {}
111+ @Override
112+ public void onSuspected(Host host) {
113+ reportActualEvent(SUSPECTED);
114+ }
85115
86- public void onDown(Host host) { downs.add(host); }
116+ @Override
117+ public void onDown(Host host) {
118+ reportActualEvent(DOWN);
119+ }
87120
88- public void onRemove(Host host) { removes.add(host); }
121+ @Override
122+ public void onRemove(Host host) {
123+ reportActualEvent(REMOVE);
124+ }
89125 }
90126 }
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) {
added features/compression/README.md +88 −0
@@ -0,0 +1,88 @@
1+## Compression
2+
3+Cassandra's binary protocol supports optional compression of
4+transport-level requests and responses, for example:
5+
6+* a query with its serialized parameters;
7+* a [page](../paging/) from a result set, i.e. a list of serialized
8+ rows.
9+
10+It reduces network traffic at the cost of CPU overhead, therefore it
11+will likely be beneficial when you have larger payloads.
12+
13+Two algorithms are available:
14+[LZ4](https://github.com/jpountz/lz4-java) and
15+[Snappy](https://code.google.com/p/snappy/).
16+Both rely on third-party libraries, declared by the driver as *optional*
17+dependencies. So If you use a build tool like Maven, you'll need to
18+declare an explicit dependency to pull the appropriate library in your
19+application's classpath. Then you configure compression at driver
20+startup.
21+
22+### LZ4
23+
24+Maven dependency:
25+
26+```xml
27+<dependency>
28+ <groupId>net.jpountz.lz4</groupId>
29+ <artifactId>lz4</artifactId>
30+ <version>1.2.0</version>
31+</dependency>
32+```
33+
34+Always check the exact version of the library: go to the driver's
35+[parent POM][pom] (change the URL to match your driver version) and look
36+for the `lz4.version` property.
37+
38+Driver configuration:
39+
40+```java
41+cluster = Cluster.builder()
42+ .addContactPoint("127.0.0.1")
43+ .withCompression(ProtocolOptions.Compression.LZ4)
44+ .build();
45+```
46+
47+LZ4-java has three internal implementations (from fastest to slowest):
48+
49+* JNI;
50+* pure Java using sun.misc.Unsafe;
51+* pure Java using only "safe" classes.
52+
53+It will pick the best implementation depending on what's possible on
54+your platform. To find out which one was chosen, [enable INFO
55+logs](../logging/) on the category
56+`com.datastax.driver.core.FrameCompressor` and look for a log similar to
57+this:
58+
59+```
60+INFO com.datastax.driver.core.FrameCompressor - Using LZ4Factory:JNI
61+```
62+
63+### Snappy
64+
65+Maven dependency:
66+
67+```xml
68+<dependency>
69+ <groupId>org.xerial.snappy</groupId>
70+ <artifactId>snappy-java</artifactId>
71+ <version>1.0.5</version>
72+</dependency>
73+```
74+
75+Always check the exact version of the library: go to the driver's
76+[parent POM][pom] (change the URL to match your driver version) and look
77+for the `snappy.version` property.
78+
79+Driver configuration:
80+
81+```java
82+cluster = Cluster.builder()
83+ .addContactPoint("127.0.0.1")
84+ .withCompression(ProtocolOptions.Compression.SNAPPY)
85+ .build();
86+```
87+
88+[pom]: https://repo1.maven.org/maven2/com/datastax/cassandra/cassandra-driver-parent/2.1.7/cassandra-driver-parent-2.1.7.pom
modified features/pooling/README.md +22 −0
@@ -99,6 +99,27 @@
9999 its maximum capacity. In general, you shouldn't need to change its
100100 default value.
101101
102+#### Dynamic resizing
103+
104+If core != max, the pool will resize automatically to adjust to the
105+current activity on the host.
106+
107+When activity goes up and there are *n* connections with n < max, the driver
108+will add a connection when the number of concurrent requests is more than
109+(n - 1) * 128 + [PoolingOptions.setNewConnectionThreshold][nct]
110+(in layman's terms, when all but the last connection are full and the last
111+connection is above the threshold).
112+
113+When activity goes down, the driver will "trash" connections if the maximum
114+number of requests in a 10 second time period can be satisfied by less than
115+the number of connections opened. Trashed connections are kept open but do
116+not accept new requests. After a given timeout (defined by
117+[PoolingOptions.setIdleTimeoutSeconds][sits]), trashed connections are closed
118+and removed. If during that idle period activity increases again, those
119+connections will be resurrected back into the active pool and reused. The
120+main intent of that is to not constantly recreate connections if activity
121+changes quickly over an interval.
122+
102123 #### Simultaneous requests per connection
103124
104125 [PoolingOptions.setMaxRequestsPerConnection][mrpc] allows you to
@@ -228,6 +249,7 @@
228249 [lbp]:http://docs.datastax.com/en/drivers/java/2.1/com/datastax/driver/core/policies/LoadBalancingPolicy.html
229250 [nct]:http://docs.datastax.com/en/drivers/java/2.1/com/datastax/driver/core/PoolingOptions.html#setNewConnectionThreshold(com.datastax.driver.core.HostDistance,%20int)
230251 [mrpc]: http://docs.datastax.com/en/drivers/java/2.1/com/datastax/driver/core/PoolingOptions.html#setMaxRequestsPerConnection(com.datastax.driver.core.HostDistance,%20int)
252+[sits]: http://docs.datastax.com/en/drivers/java/2.1/com/datastax/driver/core/PoolingOptions.html#setIdleTimeoutSeconds(int)
231253 [rtm]:http://docs.datastax.com/en/drivers/java/2.1/com/datastax/driver/core/SocketOptions.html#getReadTimeoutMillis()
232254 [exec_async]:http://docs.datastax.com/en/drivers/java/2.1/com/datastax/driver/core/Session.html#executeAsync(com.datastax.driver.core.Statement)
233255 [ptm]:http://docs.datastax.com/en/drivers/java/2.1/com/datastax/driver/core/PoolingOptions.html#setPoolTimeoutMillis(int)