kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | db477ca76c88fcf2b55b3b65e8bef4bd809d112dfcd3b4e95f2b7181367ce8c4 |
|---|---|
| Author | olim7t <omichallat+github@gmail.com> · 2015-07-11 21:11 +02:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2015-07-11 21:21 +02:00 |
| Parents | a542c0877cae, cd5f31cb7f27 |
31 files changed
modified README.md +3 −1
| @@ -57,7 +57,9 @@ | ||
| 57 | 57 | - MAILING LIST: https://groups.google.com/a/lists.datastax.com/forum/#!forum/java-driver-user |
| 58 | 58 | - IRC: #datastax-drivers on [irc.freenode.net](http://freenode.net) |
| 59 | 59 | - 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. | |
| 61 | 63 | - API: http://www.datastax.com/drivers/java/2.1 |
| 62 | 64 | |
| 63 | 65 | **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 @@ | ||
| 135 | 135 | * |
| 136 | 136 | * @throws IllegalArgumentException if {@code distance == HostDistance.IGNORED}, |
| 137 | 137 | * or if {@code newCoreConnections} is greater than the maximum value for this distance. |
| 138 | + * | |
| 139 | + * @see #setConnectionsPerHost(HostDistance, int, int) | |
| 138 | 140 | */ |
| 139 | 141 | public synchronized PoolingOptions setCoreConnectionsPerHost(HostDistance distance, int newCoreConnections) { |
| 140 | 142 | if (distance == HostDistance.IGNORED) |
| @@ -178,6 +180,8 @@ | ||
| 178 | 180 | * |
| 179 | 181 | * @throws IllegalArgumentException if {@code distance == HostDistance.IGNORED}, |
| 180 | 182 | * or if {@code newMaxConnections} is less than the core value for this distance. |
| 183 | + * | |
| 184 | + * @see #setConnectionsPerHost(HostDistance, int, int) | |
| 181 | 185 | */ |
| 182 | 186 | public synchronized PoolingOptions setMaxConnectionsPerHost(HostDistance distance, int newMaxConnections) { |
| 183 | 187 | if (distance == HostDistance.IGNORED) |
modified driver-core/src/test/java/com/datastax/driver/core/AbstractPoliciesTest.java +1 −1
| @@ -51,7 +51,7 @@ | ||
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | 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))); | |
| 55 | 55 | session.execute("USE " + SIMPLE_KEYSPACE); |
| 56 | 56 | session.execute(String.format("CREATE TABLE %s (k int PRIMARY KEY, i int)", SIMPLE_TABLE)); |
| 57 | 57 | } |
modified driver-core/src/test/java/com/datastax/driver/core/AuthenticationTest.java +14 −25
| @@ -15,9 +15,6 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.net.InetAddress; | |
| 19 | -import java.net.InetSocketAddress; | |
| 20 | -import java.util.Map; | |
| 21 | 18 | import java.util.concurrent.TimeUnit; |
| 22 | 19 | |
| 23 | 20 | import org.slf4j.Logger; |
| @@ -36,17 +33,18 @@ | ||
| 36 | 33 | |
| 37 | 34 | private static final Logger logger = LoggerFactory.getLogger(AuthenticationTest.class); |
| 38 | 35 | |
| 39 | - private CCMBridge cassandraCluster; | |
| 36 | + private CCMBridge ccm; | |
| 40 | 37 | |
| 41 | 38 | /** |
| 42 | 39 | * creates a cluster and turns on password authentication before starting it. |
| 43 | 40 | */ |
| 44 | 41 | @BeforeClass (groups = "short") |
| 45 | 42 | 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"); | |
| 50 | 48 | |
| 51 | 49 | // Even though we've override the default user setup delay, still wait |
| 52 | 50 | // one second to make sure we don't race |
| @@ -55,51 +53,42 @@ | ||
| 55 | 53 | |
| 56 | 54 | @AfterClass (groups = "short") |
| 57 | 55 | public void shutdownCluster() { |
| 58 | - if (null != cassandraCluster) | |
| 59 | - cassandraCluster.stop(); | |
| 56 | + if (ccm != null) | |
| 57 | + ccm.stop(); | |
| 60 | 58 | } |
| 61 | 59 | |
| 62 | 60 | @Test(groups = "short") |
| 63 | - public void testAuthenticatedConnection() throws InterruptedException { | |
| 61 | + public void should_connect_with_credentials() throws InterruptedException { | |
| 64 | 62 | try { |
| 65 | 63 | Cluster.builder().addContactPoint(CCMBridge.IP_PREFIX + '1') |
| 66 | 64 | .withCredentials("cassandra", "cassandra") |
| 67 | 65 | .build() |
| 68 | 66 | .connect(); |
| 69 | 67 | } 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)); | |
| 74 | 69 | } |
| 75 | 70 | } |
| 76 | 71 | |
| 77 | 72 | @Test(groups = "short", expectedExceptions = AuthenticationException.class) |
| 78 | - public void testConnectionAttemptWithIncorrectCredentialsIsRefused() throws InterruptedException { | |
| 73 | + public void should_fail_to_connect_with_wrong_credentials() throws InterruptedException { | |
| 79 | 74 | try { |
| 80 | 75 | Cluster.builder().addContactPoint(CCMBridge.IP_PREFIX + '1') |
| 81 | 76 | .withCredentials("bogus", "bogus") |
| 82 | 77 | .build() |
| 83 | 78 | .connect(); |
| 84 | 79 | } 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)); | |
| 89 | 81 | } |
| 90 | 82 | } |
| 91 | 83 | |
| 92 | 84 | @Test(groups = "short", expectedExceptions = AuthenticationException.class) |
| 93 | - public void testConnectionAttemptWithoutCredentialsIsRefused() throws InterruptedException { | |
| 85 | + public void should_fail_to_connect_without_credentials() throws InterruptedException { | |
| 94 | 86 | try { |
| 95 | 87 | Cluster.builder().addContactPoint(CCMBridge.IP_PREFIX + '1') |
| 96 | 88 | .build() |
| 97 | 89 | .connect(); |
| 98 | 90 | } 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)); | |
| 103 | 92 | } |
| 104 | 93 | } |
| 105 | 94 | } |
modified driver-core/src/test/java/com/datastax/driver/core/CCMBridge.java +116 −102
| @@ -38,10 +38,8 @@ | ||
| 38 | 38 | import org.testng.annotations.AfterClass; |
| 39 | 39 | import org.testng.annotations.BeforeClass; |
| 40 | 40 | |
| 41 | -import static com.google.common.base.Preconditions.checkArgument; | |
| 42 | 41 | import static org.testng.Assert.fail; |
| 43 | 42 | |
| 44 | -import com.datastax.driver.core.Cluster.Builder; | |
| 45 | 43 | import com.datastax.driver.core.exceptions.AlreadyExistsException; |
| 46 | 44 | import com.datastax.driver.core.exceptions.DriverException; |
| 47 | 45 | import com.datastax.driver.core.exceptions.NoHostAvailableException; |
| @@ -56,6 +54,8 @@ | ||
| 56 | 54 | public static final String IP_PREFIX; |
| 57 | 55 | |
| 58 | 56 | private static final String CASSANDRA_VERSION_REGEXP = "\\d\\.\\d\\.\\d+(-\\w+)?"; |
| 57 | + static final File CASSANDRA_DIR; | |
| 58 | + static final String CASSANDRA_VERSION; | |
| 59 | 59 | |
| 60 | 60 | public static final String DEFAULT_CLIENT_TRUSTSTORE_PASSWORD = "cassandra1sfun"; |
| 61 | 61 | public static final String DEFAULT_CLIENT_TRUSTSTORE_PATH = "/client.truststore"; |
| @@ -89,6 +89,21 @@ | ||
| 89 | 89 | private static final String CCM_COMMAND; |
| 90 | 90 | |
| 91 | 91 | 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 | + | |
| 92 | 107 | // Inherit the current environment. |
| 93 | 108 | Map<String,String> envMap = Maps.newHashMap(new ProcessBuilder().environment()); |
| 94 | 109 | // If ccm.path is set, override the PATH variable with it. |
| @@ -122,33 +137,9 @@ | ||
| 122 | 137 | private static boolean isWindows() { |
| 123 | 138 | |
| 124 | 139 | 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"); | |
| 149 | 141 | } |
| 150 | 142 | |
| 151 | - private final Runtime runtime = Runtime.getRuntime(); | |
| 152 | 143 | private final File ccmDir; |
| 153 | 144 | |
| 154 | 145 | private CCMBridge() { |
| @@ -190,37 +181,8 @@ | ||
| 190 | 181 | return f; |
| 191 | 182 | } |
| 192 | 183 | |
| 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); | |
| 224 | 186 | } |
| 225 | 187 | |
| 226 | 188 | public static CCMBridge.CCMCluster buildCluster(int nbNodes, Cluster.Builder builder) { |
| @@ -248,9 +210,9 @@ | ||
| 248 | 210 | execute(CCM_COMMAND + " node%d start --wait-other-notice --wait-for-binary-proto", n); |
| 249 | 211 | } |
| 250 | 212 | |
| 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); | |
| 254 | 216 | } |
| 255 | 217 | |
| 256 | 218 | public void stop(int n) { |
| @@ -259,7 +221,7 @@ | ||
| 259 | 221 | } |
| 260 | 222 | |
| 261 | 223 | public void stop(String clusterName) { |
| 262 | - logger.info("Stopping Cluster : "+clusterName); | |
| 224 | + logger.info("Stopping Cluster : " + clusterName); | |
| 263 | 225 | execute(CCM_COMMAND + " stop "+clusterName); |
| 264 | 226 | } |
| 265 | 227 | |
| @@ -309,10 +271,6 @@ | ||
| 309 | 271 | execute(CCM_COMMAND + " node%d decommission", n); |
| 310 | 272 | } |
| 311 | 273 | |
| 312 | - public void updateConfig(String name, String value) { | |
| 313 | - updateConfig(ImmutableMap.of(name, value)); | |
| 314 | - } | |
| 315 | - | |
| 316 | 274 | public void updateConfig(Map<String, String> configs) { |
| 317 | 275 | StringBuilder confStr = new StringBuilder(); |
| 318 | 276 | for (Map.Entry<String, String> entry : configs.entrySet()) { |
| @@ -321,10 +279,6 @@ | ||
| 321 | 279 | execute(CCM_COMMAND + " updateconf " + confStr); |
| 322 | 280 | } |
| 323 | 281 | |
| 324 | - public void populate(int n) { | |
| 325 | - execute(CCM_COMMAND + " populate -n %d -i %s", n, IP_PREFIX); | |
| 326 | - } | |
| 327 | - | |
| 328 | 282 | private void execute(String command, Object... args) { |
| 329 | 283 | |
| 330 | 284 | String fullCommand = String.format(command, args) + " --config-dir=" + ccmDir; |
| @@ -332,6 +286,7 @@ | ||
| 332 | 286 | logger.debug("Executing: " + fullCommand); |
| 333 | 287 | CommandLine cli = CommandLine.parse(fullCommand); |
| 334 | 288 | Executor executor = new DefaultExecutor(); |
| 289 | + executor.setWorkingDirectory(CASSANDRA_DIR); | |
| 335 | 290 | |
| 336 | 291 | LogOutputStream outStream = new LogOutputStream() { |
| 337 | 292 | @Override protected void processLine(String line, int logLevel) { |
| @@ -381,33 +336,6 @@ | ||
| 381 | 336 | } |
| 382 | 337 | } |
| 383 | 338 | |
| 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 | - | |
| 411 | 339 | private static void busyWaitForPort(InetAddress address, int port, boolean expectedConnectionState) { |
| 412 | 340 | long maxAcceptableWaitTime = TimeUnit.SECONDS.toMillis(10); |
| 413 | 341 | long waitQuantum = TimeUnit.MILLISECONDS.toMillis(500); |
| @@ -519,7 +447,7 @@ | ||
| 519 | 447 | if (!clusterInitialized){ |
| 520 | 448 | try { |
| 521 | 449 | //launch ccm cluster |
| 522 | - ccmBridge = CCMBridge.create("test-class"); | |
| 450 | + ccmBridge = CCMBridge.builder("test-class").withoutNodes().notStarted().build(); | |
| 523 | 451 | |
| 524 | 452 | ports = new int[5]; |
| 525 | 453 | for (int i = 0; i < 5; i++) { |
| @@ -545,7 +473,7 @@ | ||
| 545 | 473 | |
| 546 | 474 | private void initKeyspace() { |
| 547 | 475 | try { |
| 548 | - Builder builder = Cluster.builder(); | |
| 476 | + Cluster.Builder builder = Cluster.builder(); | |
| 549 | 477 | |
| 550 | 478 | builder = configure(builder); |
| 551 | 479 | |
| @@ -605,14 +533,16 @@ | ||
| 605 | 533 | if (nbNodes == 0) |
| 606 | 534 | throw new IllegalArgumentException(); |
| 607 | 535 | |
| 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); | |
| 609 | 538 | } |
| 610 | 539 | |
| 611 | 540 | public static CCMCluster create(int nbNodesDC1, int nbNodesDC2, Cluster.Builder builder) { |
| 612 | 541 | if (nbNodesDC1 == 0) |
| 613 | 542 | throw new IllegalArgumentException(); |
| 614 | 543 | |
| 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); | |
| 616 | 546 | } |
| 617 | 547 | |
| 618 | 548 | public static CCMCluster create(CCMBridge cassandraCluster, Cluster.Builder builder, int totalNodes) { |
| @@ -628,7 +558,8 @@ | ||
| 628 | 558 | |
| 629 | 559 | try { |
| 630 | 560 | Thread.sleep(1000); |
| 631 | - } catch (Exception e) { | |
| 561 | + } catch (InterruptedException e) { | |
| 562 | + fail("Unexpected interruption"); | |
| 632 | 563 | } |
| 633 | 564 | this.cluster = builder.addContactPoints(contactPoints).build(); |
| 634 | 565 | this.session = cluster.connect(); |
| @@ -659,4 +590,87 @@ | ||
| 659 | 590 | } |
| 660 | 591 | } |
| 661 | 592 | } |
| 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 | + } | |
| 662 | 676 | } |
modified driver-core/src/test/java/com/datastax/driver/core/ClusterInitTest.java +16 −13
| @@ -15,15 +15,6 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 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 | - | |
| 27 | 18 | import java.net.InetAddress; |
| 28 | 19 | import java.net.InetSocketAddress; |
| 29 | 20 | import java.util.Collections; |
| @@ -31,10 +22,23 @@ | ||
| 31 | 22 | import java.util.concurrent.TimeUnit; |
| 32 | 23 | import java.util.concurrent.TimeoutException; |
| 33 | 24 | |
| 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 | + | |
| 34 | 40 | import static com.datastax.driver.core.FakeHost.Behavior.THROWING_CONNECT_TIMEOUTS; |
| 35 | 41 | import static com.datastax.driver.core.querybuilder.QueryBuilder.insertInto; |
| 36 | -import static org.assertj.core.api.Assertions.fail; | |
| 37 | -import static org.mockito.Mockito.*; | |
| 38 | 42 | |
| 39 | 43 | public class ClusterInitTest { |
| 40 | 44 | private static final Logger logger = LoggerFactory.getLogger(ClusterInitTest.class); |
| @@ -52,8 +56,7 @@ | ||
| 52 | 56 | try { |
| 53 | 57 | // Obtaining connect timeouts is not trivial: we create a 6-host cluster but only start one of them, |
| 54 | 58 | // then simulate the other 5. |
| 55 | - ccm = CCMBridge.create("test"); | |
| 56 | - ccm.populate(6); | |
| 59 | + ccm = CCMBridge.builder("test").withNodes(6).notStarted().build(); | |
| 57 | 60 | ccm.start(1); |
| 58 | 61 | |
| 59 | 62 | 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 @@ | ||
| 56 | 56 | }; |
| 57 | 57 | |
| 58 | 58 | try { |
| 59 | - ccm = CCMBridge.create("test", 2); | |
| 59 | + ccm = CCMBridge.builder("test").withNodes(2).build(); | |
| 60 | 60 | // We pass only the first host as contact point, so we know the control connection will be on this host |
| 61 | 61 | cluster = Cluster.builder() |
| 62 | 62 | .addContactPoint(CCMBridge.ipOfNode(1)) |
| @@ -95,7 +95,7 @@ | ||
| 95 | 95 | Cluster cluster = null; |
| 96 | 96 | |
| 97 | 97 | try { |
| 98 | - ccm = CCMBridge.create("test", 1); | |
| 98 | + ccm = CCMBridge.builder("test").build(); | |
| 99 | 99 | |
| 100 | 100 | // First driver instance: create UDT |
| 101 | 101 | cluster = Cluster.builder().addContactPoint(CCMBridge.ipOfNode(1)).build(); |
| @@ -132,7 +132,7 @@ | ||
| 132 | 132 | Cluster cluster = null; |
| 133 | 133 | |
| 134 | 134 | try { |
| 135 | - ccm = CCMBridge.create("test", 3); | |
| 135 | + ccm = CCMBridge.builder("test").withNodes(3).build(); | |
| 136 | 136 | |
| 137 | 137 | cluster = Cluster.builder() |
| 138 | 138 | .addContactPoint(CCMBridge.ipOfNode(1)) |
modified driver-core/src/test/java/com/datastax/driver/core/ExceptionsTest.java +7 −5
| @@ -15,6 +15,8 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | +import java.util.Locale; | |
| 19 | + | |
| 18 | 20 | import com.datastax.driver.core.exceptions.*; |
| 19 | 21 | import org.testng.annotations.Test; |
| 20 | 22 | |
| @@ -192,7 +194,7 @@ | ||
| 192 | 194 | c.session.execute("USE " + keyspace); |
| 193 | 195 | c.session.execute(String.format(TestUtils.CREATE_TABLE_SIMPLE_FORMAT, table)); |
| 194 | 196 | |
| 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)); | |
| 196 | 198 | c.session.execute(new SimpleStatement(String.format(TestUtils.SELECT_ALL_FORMAT, table)).setConsistencyLevel(ConsistencyLevel.ALL)); |
| 197 | 199 | |
| 198 | 200 | c.cassandraCluster.forceStop(2); |
| @@ -308,7 +310,7 @@ | ||
| 308 | 310 | c.session.execute("USE " + keyspace); |
| 309 | 311 | c.session.execute(String.format(TestUtils.CREATE_TABLE_SIMPLE_FORMAT, table)); |
| 310 | 312 | |
| 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)); | |
| 312 | 314 | c.session.execute(new SimpleStatement(String.format(TestUtils.SELECT_ALL_FORMAT, table)).setConsistencyLevel(ConsistencyLevel.ALL)); |
| 313 | 315 | |
| 314 | 316 | c.cassandraCluster.stop(2); |
| @@ -326,7 +328,7 @@ | ||
| 326 | 328 | } |
| 327 | 329 | |
| 328 | 330 | 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)); | |
| 330 | 332 | } catch (UnavailableException e) { |
| 331 | 333 | String expectedError = String.format("Not enough replica available for query at consistency %s (%d required but only %d alive)", "ALL", 3, 2); |
| 332 | 334 | assertEquals(e.getMessage(), expectedError); |
| @@ -361,12 +363,12 @@ | ||
| 361 | 363 | c.session.execute("USE " + keyspace); |
| 362 | 364 | c.session.execute(String.format(TestUtils.CREATE_TABLE_SIMPLE_FORMAT, table)); |
| 363 | 365 | |
| 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)); | |
| 365 | 367 | c.session.execute(new SimpleStatement(String.format(TestUtils.SELECT_ALL_FORMAT, table)).setConsistencyLevel(ConsistencyLevel.ALL)); |
| 366 | 368 | |
| 367 | 369 | c.cassandraCluster.forceStop(2); |
| 368 | 370 | 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)); | |
| 370 | 372 | } catch (WriteTimeoutException e) { |
| 371 | 373 | assertEquals(e.getConsistencyLevel(), ConsistencyLevel.ALL); |
| 372 | 374 | assertEquals(e.getReceivedAcknowledgements(), 2); |
modified driver-core/src/test/java/com/datastax/driver/core/HeartbeatTest.java +2 −2
| @@ -57,7 +57,7 @@ | ||
| 57 | 57 | CCMBridge ccm = null; |
| 58 | 58 | Cluster cluster = null; |
| 59 | 59 | try { |
| 60 | - ccm = CCMBridge.create("test", 1); | |
| 60 | + ccm = CCMBridge.builder("test").withNodes(1).build(); | |
| 61 | 61 | cluster = Cluster.builder().addContactPoint(CCMBridge.ipOfNode(1)) |
| 62 | 62 | .withPoolingOptions(new PoolingOptions() |
| 63 | 63 | .setHeartbeatIntervalSeconds(3)) |
| @@ -121,7 +121,7 @@ | ||
| 121 | 121 | CCMBridge ccm = null; |
| 122 | 122 | Cluster cluster = null; |
| 123 | 123 | try { |
| 124 | - ccm = CCMBridge.create("test", 1); | |
| 124 | + ccm = CCMBridge.builder("test").withNodes(1).build(); | |
| 125 | 125 | cluster = Cluster.builder().addContactPoint(CCMBridge.ipOfNode(1)) |
| 126 | 126 | .withPoolingOptions(new PoolingOptions() |
| 127 | 127 | .setHeartbeatIntervalSeconds(0)) |
modified driver-core/src/test/java/com/datastax/driver/core/LoadBalancingPolicyBootstrapTest.java +2 −2
| @@ -51,7 +51,7 @@ | ||
| 51 | 51 | CCMBridge ccm = null; |
| 52 | 52 | Cluster cluster = null; |
| 53 | 53 | try { |
| 54 | - ccm = CCMBridge.create("test", 2); | |
| 54 | + ccm = CCMBridge.builder("test").withNodes(2).build(); | |
| 55 | 55 | cluster = Cluster.builder() |
| 56 | 56 | .addContactPoints(CCMBridge.ipOfNode(1), CCMBridge.ipOfNode(2)) |
| 57 | 57 | .withLoadBalancingPolicy(policy) |
| @@ -86,7 +86,7 @@ | ||
| 86 | 86 | CCMBridge ccm = null; |
| 87 | 87 | Cluster cluster = null; |
| 88 | 88 | try { |
| 89 | - ccm = CCMBridge.create("test", 2); | |
| 89 | + ccm = CCMBridge.builder("test").withNodes(2).build(); | |
| 90 | 90 | |
| 91 | 91 | // In order to validate this behavior, we need to stop the first node that would be attempted to be |
| 92 | 92 | // established as the control connection. |
modified driver-core/src/test/java/com/datastax/driver/core/MetadataTest.java +1 −1
| @@ -54,7 +54,7 @@ | ||
| 54 | 54 | Cluster cluster = null; |
| 55 | 55 | |
| 56 | 56 | try { |
| 57 | - ccm = CCMBridge.create("test", 3); | |
| 57 | + ccm = CCMBridge.builder("test").withNodes(3).build(); | |
| 58 | 58 | |
| 59 | 59 | cluster = Cluster.builder() |
| 60 | 60 | .addContactPoint(CCMBridge.ipOfNode(1)) |
modified driver-core/src/test/java/com/datastax/driver/core/MissingRpcAddressTest.java +1 −1
| @@ -36,7 +36,7 @@ | ||
| 36 | 36 | |
| 37 | 37 | @Test(groups = "short") |
| 38 | 38 | public void testMissingRpcAddressAtStartup() throws Exception { |
| 39 | - CCMBridge ccm = CCMBridge.create("ccm", 2); | |
| 39 | + CCMBridge ccm = CCMBridge.builder("ccm").withNodes(2).build(); | |
| 40 | 40 | |
| 41 | 41 | Cluster cluster = null; |
| 42 | 42 | try { |
modified driver-core/src/test/java/com/datastax/driver/core/NettyOptionsTest.java +1 −1
| @@ -47,7 +47,7 @@ | ||
| 47 | 47 | @Test(groups = "short", dataProvider = "NettyOptionsTest") |
| 48 | 48 | public void should_invoke_netty_options_hooks(int hosts, int coreConnections) throws Exception { |
| 49 | 49 | //given |
| 50 | - CCMBridge ccm = CCMBridge.create("test", hosts); | |
| 50 | + CCMBridge ccm = CCMBridge.builder("test").withNodes(hosts).build(); | |
| 51 | 51 | Cluster cluster = null; |
| 52 | 52 | try { |
| 53 | 53 | 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 @@ | ||
| 44 | 44 | |
| 45 | 45 | @Test(groups = "long") |
| 46 | 46 | 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(); | |
| 48 | 48 | // node1 will be our "recommissioned" node, for now we just stop it so that it stays in the peers table. |
| 49 | 49 | mainCcm.stop(1); |
| 50 | 50 | mainCcm.waitForDown(1); |
| @@ -56,7 +56,7 @@ | ||
| 56 | 56 | // From that point, reconnections to node1 have been scheduled. |
| 57 | 57 | |
| 58 | 58 | // Start another ccm that will reuse node1's address |
| 59 | - otherCcm = CCMBridge.create("other", 1); | |
| 59 | + otherCcm = CCMBridge.builder("other").withNodes(1).build(); | |
| 60 | 60 | otherCcm.waitForUp(1); |
| 61 | 61 | |
| 62 | 62 | // Give the driver the time to notice the node is back up and try to connect to it. |
| @@ -67,7 +67,7 @@ | ||
| 67 | 67 | |
| 68 | 68 | @Test(groups = "long") |
| 69 | 69 | 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(); | |
| 71 | 71 | mainCcm.stop(1); |
| 72 | 72 | mainCcm.waitForDown(1); |
| 73 | 73 | |
| @@ -77,7 +77,7 @@ | ||
| 77 | 77 | waitForCountUpHosts(mainCluster, 1); |
| 78 | 78 | |
| 79 | 79 | // Start another ccm that will reuse node1's address |
| 80 | - otherCcm = CCMBridge.create("other", 1); | |
| 80 | + otherCcm = CCMBridge.builder("other").withNodes(1).build(); | |
| 81 | 81 | otherCcm.waitForUp(1); |
| 82 | 82 | |
| 83 | 83 | // Stop node2, the control connection gets defunct |
| @@ -91,11 +91,11 @@ | ||
| 91 | 91 | @Test(groups = "long") |
| 92 | 92 | public void should_ignore_recommissioned_node_on_session_init() throws Exception { |
| 93 | 93 | // Simulate the bug before starting the cluster |
| 94 | - mainCcm = CCMBridge.create("main", 2); | |
| 94 | + mainCcm = CCMBridge.builder("main").withNodes(2).build(); | |
| 95 | 95 | mainCcm.stop(1); |
| 96 | 96 | mainCcm.waitForDown(1); |
| 97 | 97 | |
| 98 | - otherCcm = CCMBridge.create("other", 1); | |
| 98 | + otherCcm = CCMBridge.builder("other").withNodes(1).build(); | |
| 99 | 99 | otherCcm.waitForUp(1); |
| 100 | 100 | |
| 101 | 101 | // Start the driver, it should only connect to node 2 |
| @@ -119,11 +119,11 @@ | ||
| 119 | 119 | @CassandraVersion(major=2.0) |
| 120 | 120 | public void should_ignore_node_that_does_not_support_protocol_version_on_session_init() throws Exception { |
| 121 | 121 | // Simulate the bug before starting the cluster |
| 122 | - mainCcm = CCMBridge.create("main", 2); | |
| 122 | + mainCcm = CCMBridge.builder("main").withNodes(2).build(); | |
| 123 | 123 | mainCcm.stop(1); |
| 124 | 124 | mainCcm.waitForDown(1); |
| 125 | 125 | |
| 126 | - otherCcm = CCMBridge.createWithCustomVersion("main", 1, "1.2.19"); | |
| 126 | + otherCcm = CCMBridge.builder("main").withNodes(1).withCassandraVersion("1.2.19").build(); | |
| 127 | 127 | otherCcm.waitForUp(1); |
| 128 | 128 | |
| 129 | 129 | // 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 @@ | ||
| 53 | 53 | CCMBridge ccm = null; |
| 54 | 54 | Cluster cluster = null; |
| 55 | 55 | try { |
| 56 | - ccm = CCMBridge.create("test", 2); | |
| 56 | + ccm = CCMBridge.builder("test").withNodes(2).build(); | |
| 57 | 57 | int reconnectionDelay = 1000; |
| 58 | 58 | cluster = Cluster.builder() |
| 59 | 59 | .addContactPoint(CCMBridge.ipOfNode(1)) |
| @@ -90,10 +90,10 @@ | ||
| 90 | 90 | CCMBridge ccm = null; |
| 91 | 91 | Cluster cluster = null; |
| 92 | 92 | 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(); | |
| 97 | 97 | ccm.start(1, "-Dcassandra.superuser_setup_delay_ms=0"); |
| 98 | 98 | |
| 99 | 99 | DynamicPlainTextAuthProvider authProvider = new DynamicPlainTextAuthProvider("cassandra", "cassandra"); |
| @@ -149,7 +149,7 @@ | ||
| 149 | 149 | CountingReconnectionPolicy reconnectionPolicy = new CountingReconnectionPolicy(new ConstantReconnectionPolicy(reconnectionDelayMillis)); |
| 150 | 150 | |
| 151 | 151 | try { |
| 152 | - ccm = CCMBridge.create("test", 2); | |
| 152 | + ccm = CCMBridge.builder("test").withNodes(2).build(); | |
| 153 | 153 | cluster = Cluster.builder() |
| 154 | 154 | .addContactPoint(CCMBridge.ipOfNode(1)) |
| 155 | 155 | .withReconnectionPolicy(reconnectionPolicy) |
| @@ -190,7 +190,7 @@ | ||
| 190 | 190 | TogglabePolicy loadBalancingPolicy = new TogglabePolicy(new RoundRobinPolicy()); |
| 191 | 191 | |
| 192 | 192 | try { |
| 193 | - ccm = CCMBridge.create("test", 1); | |
| 193 | + ccm = CCMBridge.builder("test").withNodes(1).build(); | |
| 194 | 194 | cluster = Cluster.builder() |
| 195 | 195 | .addContactPoint(CCMBridge.ipOfNode(1)) |
| 196 | 196 | .withLoadBalancingPolicy(loadBalancingPolicy) |
| @@ -256,7 +256,7 @@ | ||
| 256 | 256 | SocketOptions socketOptions = spy(new SocketOptions()); |
| 257 | 257 | |
| 258 | 258 | try { |
| 259 | - ccm = CCMBridge.create("test", 1); | |
| 259 | + ccm = CCMBridge.builder("test").withNodes(1).build(); | |
| 260 | 260 | cluster = Cluster.builder() |
| 261 | 261 | .addContactPoint(CCMBridge.ipOfNode(1)) |
| 262 | 262 | .withReconnectionPolicy(new ConstantReconnectionPolicy(5000)) |
modified driver-core/src/test/java/com/datastax/driver/core/RefreshConnectedHostTest.java +1 −2
| @@ -41,8 +41,7 @@ | ||
| 41 | 41 | LimitingLoadBalancingPolicy loadBalancingPolicy = new LimitingLoadBalancingPolicy(new RoundRobinPolicy(), 2, 1); |
| 42 | 42 | |
| 43 | 43 | // 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(); | |
| 46 | 45 | ccm.start(1); |
| 47 | 46 | ccm.start(2); |
| 48 | 47 | ccm.waitForUp(1); |
modified driver-core/src/test/java/com/datastax/driver/core/SSLTestBase.java +3 −10
| @@ -17,7 +17,6 @@ | ||
| 17 | 17 | |
| 18 | 18 | import java.security.KeyStore; |
| 19 | 19 | import java.security.SecureRandom; |
| 20 | -import java.util.concurrent.TimeUnit; | |
| 21 | 20 | |
| 22 | 21 | import com.google.common.base.Optional; |
| 23 | 22 | import javax.net.ssl.KeyManagerFactory; |
| @@ -25,15 +24,9 @@ | ||
| 25 | 24 | import javax.net.ssl.TrustManagerFactory; |
| 26 | 25 | import org.testng.annotations.AfterClass; |
| 27 | 26 | import org.testng.annotations.BeforeClass; |
| 28 | -import org.testng.annotations.Test; | |
| 29 | 27 | |
| 30 | -import com.datastax.driver.core.exceptions.NoHostAvailableException; | |
| 31 | - | |
| 32 | -import static com.datastax.driver.core.Assertions.assertThat; | |
| 33 | 28 | import static com.datastax.driver.core.CCMBridge.DEFAULT_CLIENT_KEYSTORE_PASSWORD; |
| 34 | -import static com.datastax.driver.core.CCMBridge.DEFAULT_CLIENT_KEYSTORE_PATH; | |
| 35 | 29 | import static com.datastax.driver.core.CCMBridge.DEFAULT_CLIENT_TRUSTSTORE_PASSWORD; |
| 36 | -import static com.datastax.driver.core.CCMBridge.DEFAULT_CLIENT_TRUSTSTORE_PATH; | |
| 37 | 30 | public abstract class SSLTestBase { |
| 38 | 31 | |
| 39 | 32 | private final boolean requireClientAuth; |
| @@ -46,9 +39,9 @@ | ||
| 46 | 39 | |
| 47 | 40 | @BeforeClass(groups={"short", "long"}) |
| 48 | 41 | 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(); | |
| 52 | 45 | } |
| 53 | 46 | |
| 54 | 47 | @AfterClass(groups={"short", "long"}) |
modified driver-core/src/test/java/com/datastax/driver/core/SchemaAgreementTest.java +1 −1
| @@ -41,7 +41,7 @@ | ||
| 41 | 41 | |
| 42 | 42 | @BeforeClass(groups = "short") |
| 43 | 43 | public void setup() { |
| 44 | - ccm = CCMBridge.create("schema_agreement", 2); | |
| 44 | + ccm = CCMBridge.builder("schema_agreement").withNodes(2).build(); | |
| 45 | 45 | cluster = Cluster.builder().addContactPoint(CCMBridge.ipOfNode(1)).build(); |
| 46 | 46 | session = cluster.connect(); |
| 47 | 47 | 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 @@ | ||
| 42 | 42 | |
| 43 | 43 | @BeforeClass(groups = "short") |
| 44 | 44 | public void setup() { |
| 45 | - ccm = CCMBridge.create("schemaChangesTest", 1); | |
| 45 | + ccm = CCMBridge.builder("schemaChangesTest").withNodes(1).build(); | |
| 46 | 46 | |
| 47 | 47 | cluster = Cluster.builder().addContactPoint(CCMBridge.ipOfNode(1)).build(); |
| 48 | 48 | 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 @@ | ||
| 44 | 44 | public void connectionLeakTest() throws Exception { |
| 45 | 45 | // Checking for JAVA-342 |
| 46 | 46 | CCMBridge ccmBridge; |
| 47 | - ccmBridge = CCMBridge.create("test", 1); | |
| 47 | + ccmBridge = CCMBridge.builder("test").withNodes(1).build(); | |
| 48 | 48 | channelMonitor = new SocketChannelMonitor(); |
| 49 | 49 | channelMonitor.reportAtFixedInterval(1, TimeUnit.SECONDS); |
| 50 | 50 | try { |
| @@ -107,7 +107,7 @@ | ||
| 107 | 107 | public void should_not_leak_session_when_wrong_keyspace() throws Exception { |
| 108 | 108 | // Checking for JAVA-806 |
| 109 | 109 | CCMBridge ccmBridge; |
| 110 | - ccmBridge = CCMBridge.create("test", 1); | |
| 110 | + ccmBridge = CCMBridge.builder("test").withNodes(1).build(); | |
| 111 | 111 | channelMonitor = new SocketChannelMonitor(); |
| 112 | 112 | channelMonitor.reportAtFixedInterval(1, TimeUnit.SECONDS); |
| 113 | 113 | try { |
modified driver-core/src/test/java/com/datastax/driver/core/SingleTokenIntegrationTest.java +4 −5
| @@ -34,11 +34,10 @@ | ||
| 34 | 34 | Cluster cluster = null; |
| 35 | 35 | |
| 36 | 36 | 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(); | |
| 42 | 41 | |
| 43 | 42 | cluster = Cluster.builder().addContactPoint(CCMBridge.ipOfNode(1)).build(); |
| 44 | 43 |
modified driver-core/src/test/java/com/datastax/driver/core/StateListenerTest.java +87 −51
| @@ -15,76 +15,112 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 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; | |
| 20 | 21 | |
| 21 | -import java.util.Set; | |
| 22 | +import org.slf4j.Logger; | |
| 23 | +import org.slf4j.LoggerFactory; | |
| 24 | +import org.testng.annotations.Test; | |
| 22 | 25 | |
| 23 | -import static org.testng.Assert.assertEquals; | |
| 26 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 24 | 27 | |
| 25 | -import static com.datastax.driver.core.TestUtils.*; | |
| 28 | +import static com.datastax.driver.core.StateListenerTest.TestListener.Event.*; | |
| 26 | 29 | |
| 27 | -/** | |
| 28 | - * Simple test of the Sessions methods against a one node cluster. | |
| 29 | - */ | |
| 30 | 30 | public class StateListenerTest { |
| 31 | + private static final Logger logger = LoggerFactory.getLogger(StateListenerTest.class); | |
| 31 | 32 | |
| 32 | 33 | @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; | |
| 38 | 37 | 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(); | |
| 40 | 44 | cluster.register(listener); |
| 41 | 45 | |
| 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 | + | |
| 68 | 62 | } finally { |
| 69 | - c.discard(); | |
| 63 | + if (cluster != null) | |
| 64 | + cluster.close(); | |
| 65 | + if (ccm != null) | |
| 66 | + ccm.remove(); | |
| 70 | 67 | } |
| 71 | 68 | } |
| 72 | 69 | |
| 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; | |
| 74 | 76 | |
| 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 | + } | |
| 79 | 100 | |
| 80 | - public void onAdd(Host host) { adds.add(host); } | |
| 101 | + @Override | |
| 102 | + public void onAdd(Host host) { | |
| 103 | + reportActualEvent(ADD); | |
| 104 | + } | |
| 81 | 105 | |
| 82 | - public void onUp(Host host) { ups.add(host); } | |
| 106 | + @Override | |
| 107 | + public void onUp(Host host) { | |
| 108 | + reportActualEvent(UP); | |
| 109 | + } | |
| 83 | 110 | |
| 84 | - public void onSuspected(Host host) {} | |
| 111 | + @Override | |
| 112 | + public void onSuspected(Host host) { | |
| 113 | + reportActualEvent(SUSPECTED); | |
| 114 | + } | |
| 85 | 115 | |
| 86 | - public void onDown(Host host) { downs.add(host); } | |
| 116 | + @Override | |
| 117 | + public void onDown(Host host) { | |
| 118 | + reportActualEvent(DOWN); | |
| 119 | + } | |
| 87 | 120 | |
| 88 | - public void onRemove(Host host) { removes.add(host); } | |
| 121 | + @Override | |
| 122 | + public void onRemove(Host host) { | |
| 123 | + reportActualEvent(REMOVE); | |
| 124 | + } | |
| 89 | 125 | } |
| 90 | 126 | } |
modified driver-core/src/test/java/com/datastax/driver/core/TimeoutStressTest.java +1 −1
| @@ -70,7 +70,7 @@ | ||
| 70 | 70 | |
| 71 | 71 | @BeforeClass(groups = "long") |
| 72 | 72 | public void beforeClass() throws Exception { |
| 73 | - ccmBridge = CCMBridge.create("test", 3); | |
| 73 | + ccmBridge = CCMBridge.builder("test").withNodes(3).build(); | |
| 74 | 74 | channelMonitor = new SocketChannelMonitor(); |
| 75 | 75 | nodes = Lists.newArrayList( |
| 76 | 76 | 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 @@ | ||
| 72 | 72 | |
| 73 | 73 | @BeforeClass(groups = "short") |
| 74 | 74 | public void setup() { |
| 75 | - ccm = CCMBridge.create("test", 3, ccmOptions); | |
| 75 | + ccm = CCMBridge.builder("test").withNodes(3).withStartOptions(ccmOptions).build(); | |
| 76 | 76 | |
| 77 | 77 | // Only connect to node 1, which makes it easier to query system tables in should_expose_tokens_per_host() |
| 78 | 78 | 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 @@ | ||
| 29 | 29 | CCMBridge ccm = null; |
| 30 | 30 | Cluster cluster = null; |
| 31 | 31 | try { |
| 32 | - ccm = CCMBridge.create("test", 1); | |
| 32 | + ccm = CCMBridge.builder("test").withNodes(1).build(); | |
| 33 | 33 | cluster = Cluster.builder() |
| 34 | 34 | .addContactPoint(CCMBridge.ipOfNode(1)) |
| 35 | 35 | .withLoadBalancingPolicy(policy) |
modified driver-core/src/test/java/com/datastax/driver/core/policies/DCAwareRoundRobinPolicyTest.java +1 −1
| @@ -36,7 +36,7 @@ | ||
| 36 | 36 | @BeforeClass(groups = "short") |
| 37 | 37 | public void createCcm() { |
| 38 | 38 | // 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(); | |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | @AfterClass(groups = "short") |
modified driver-core/src/test/java/com/datastax/driver/core/policies/DowngradingConsistencyRetryPolicyIntegrationTest.java +1 −1
| @@ -46,7 +46,7 @@ | ||
| 46 | 46 | Cluster cluster = null; |
| 47 | 47 | try { |
| 48 | 48 | // 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(); | |
| 50 | 50 | cluster = Cluster.builder() |
| 51 | 51 | .addContactPoint(CCMBridge.ipOfNode(1)) |
| 52 | 52 | .withRetryPolicy(Mockito.spy(DowngradingConsistencyRetryPolicy.INSTANCE)) |
modified driver-core/src/test/java/com/datastax/driver/core/policies/TokenAwarePolicyTest.java +1 −3
| @@ -16,9 +16,7 @@ | ||
| 16 | 16 | package com.datastax.driver.core.policies; |
| 17 | 17 | |
| 18 | 18 | import java.nio.ByteBuffer; |
| 19 | -import java.util.ArrayList; | |
| 20 | 19 | import java.util.List; |
| 21 | -import java.util.Set; | |
| 22 | 20 | |
| 23 | 21 | import static org.assertj.core.api.Assertions.assertThat; |
| 24 | 22 | import com.google.common.collect.Lists; |
| @@ -44,7 +42,7 @@ | ||
| 44 | 42 | CCMBridge ccm = null; |
| 45 | 43 | Cluster cluster = null; |
| 46 | 44 | try { |
| 47 | - ccm = CCMBridge.create("test", 3); | |
| 45 | + ccm = CCMBridge.builder("test").withNodes(3).build(); | |
| 48 | 46 | cluster = Cluster.builder() |
| 49 | 47 | .addContactPoint(CCMBridge.ipOfNode(1)) |
| 50 | 48 | .withLoadBalancingPolicy(loadBalancingPolicy) |
modified driver-examples/osgi/src/test/java/com/datastax/driver/osgi/CCMBridgeListener.java +1 −1
| @@ -33,7 +33,7 @@ | ||
| 33 | 33 | private CCMBridge ccm; |
| 34 | 34 | |
| 35 | 35 | @Override public void onStart(ITestContext context) { |
| 36 | - ccm = CCMBridge.create("test", 1); | |
| 36 | + ccm = CCMBridge.builder("test").withNodes(1).build(); | |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | @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 @@ | ||
| 99 | 99 | its maximum capacity. In general, you shouldn't need to change its |
| 100 | 100 | default value. |
| 101 | 101 | |
| 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 | + | |
| 102 | 123 | #### Simultaneous requests per connection |
| 103 | 124 | |
| 104 | 125 | [PoolingOptions.setMaxRequestsPerConnection][mrpc] allows you to |
| @@ -228,6 +249,7 @@ | ||
| 228 | 249 | [lbp]:http://docs.datastax.com/en/drivers/java/2.1/com/datastax/driver/core/policies/LoadBalancingPolicy.html |
| 229 | 250 | [nct]:http://docs.datastax.com/en/drivers/java/2.1/com/datastax/driver/core/PoolingOptions.html#setNewConnectionThreshold(com.datastax.driver.core.HostDistance,%20int) |
| 230 | 251 | [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) | |
| 231 | 253 | [rtm]:http://docs.datastax.com/en/drivers/java/2.1/com/datastax/driver/core/SocketOptions.html#getReadTimeoutMillis() |
| 232 | 254 | [exec_async]:http://docs.datastax.com/en/drivers/java/2.1/com/datastax/driver/core/Session.html#executeAsync(com.datastax.driver.core.Statement) |
| 233 | 255 | [ptm]:http://docs.datastax.com/en/drivers/java/2.1/com/datastax/driver/core/PoolingOptions.html#setPoolTimeoutMillis(int) |