kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | b19c57544376af25ffbc8a81ea5da22d8b04113ba30ad918d51e4f70b181fe6b |
|---|---|
| Author | Andrew Tolbert <andrew.tolbert@datastax.com> · 2017-02-13 14:19 -06:00 |
| Committer | Andrew Tolbert <andrew.tolbert@datastax.com> · 2017-02-17 11:09 -06:00 |
| Parents | 3faae1558f54 |
27 files changed
modified driver-core/src/test/java/com/datastax/driver/core/AggregateMetadataTest.java +2 −2
| @@ -185,7 +185,7 @@ | ||
| 185 | 185 | @Test(groups = "short") |
| 186 | 186 | @CassandraVersion("2.2.0") |
| 187 | 187 | public void should_parse_and_format_aggregate_with_composite_type_literal_initcond() { |
| 188 | - VersionNumber ver = VersionNumber.parse(CCMBridge.getCassandraVersion()); | |
| 188 | + VersionNumber ver = ccm().getCassandraVersion(); | |
| 189 | 189 | if (ver.getMajor() == 3) { |
| 190 | 190 | if ((ver.getMinor() >= 1 && ver.getMinor() < 4) || (ver.getMinor() == 0 && ver.getPatch() < 4)) { |
| 191 | 191 | throw new SkipException("Requires C* 2.2.X, 3.0.4+ or 3.4.X+"); |
| @@ -206,7 +206,7 @@ | ||
| 206 | 206 | @Test(groups = "short") |
| 207 | 207 | @CassandraVersion("3.4") |
| 208 | 208 | public void should_parse_and_format_aggregate_with_composite_type_hex_initcond() { |
| 209 | - VersionNumber ver = VersionNumber.parse(CCMBridge.getCassandraVersion()); | |
| 209 | + VersionNumber ver = ccm().getCassandraVersion(); | |
| 210 | 210 | if ((ver.getMinor() >= 1 && ver.getMinor() < 4)) { |
| 211 | 211 | throw new SkipException("Requires 3.0.4+ or 3.4.X+"); |
| 212 | 212 | } |
modified driver-core/src/test/java/com/datastax/driver/core/AuthenticationTest.java +1 −1
| @@ -41,7 +41,7 @@ | ||
| 41 | 41 | public void sleepIf12() { |
| 42 | 42 | // For C* 1.2, sleep before attempting to connect as there is a small delay between |
| 43 | 43 | // user being created. |
| 44 | - if (ccm().getVersion().getMajor() < 2) { | |
| 44 | + if (ccm().getCassandraVersion().getMajor() < 2) { | |
| 45 | 45 | Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS); |
| 46 | 46 | } |
| 47 | 47 | } |
modified driver-core/src/test/java/com/datastax/driver/core/CCMAccess.java +26 −3
| @@ -32,13 +32,21 @@ | ||
| 32 | 32 | String getClusterName(); |
| 33 | 33 | |
| 34 | 34 | /** |
| 35 | - * Returns the Cassandra version of this CCM cluster. | |
| 35 | + * Returns the Cassandra version of this CCM cluster. If {@link #getDSEVersion()} is non-null it is assumed | |
| 36 | + * that this value is only used for representing the compatible Cassandra version for that DSE version. | |
| 36 | 37 | * <p/> |
| 37 | - * By default the version is equal to {@link CCMBridge#getCassandraVersion()}. | |
| 38 | 38 | * |
| 39 | 39 | * @return The version of this CCM cluster. |
| 40 | 40 | */ |
| 41 | - VersionNumber getVersion(); | |
| 41 | + VersionNumber getCassandraVersion(); | |
| 42 | + | |
| 43 | + /** | |
| 44 | + * Returns the DSE version of this CCM cluster if this is a DSE cluster, otherwise null. | |
| 45 | + * <p/> | |
| 46 | + * | |
| 47 | + * @return The version of this CCM cluster. | |
| 48 | + */ | |
| 49 | + VersionNumber getDSEVersion(); | |
| 42 | 50 | |
| 43 | 51 | /** |
| 44 | 52 | * @return The config directory for this CCM cluster. |
| @@ -236,4 +244,19 @@ | ||
| 236 | 244 | */ |
| 237 | 245 | void waitForDown(int node); |
| 238 | 246 | |
| 247 | + /** | |
| 248 | + * @return The target protocolVersion to use when connecting to this CCM cluster. | |
| 249 | + * <p/> | |
| 250 | + * This should be based on the highest protocol version that both the cluster and driver support. | |
| 251 | + * <p/> | |
| 252 | + * For example, C* 2.0.17 should return {@link ProtocolVersion#V2} since C* supports up to V2 and the driver | |
| 253 | + * supports that version. | |
| 254 | + */ | |
| 255 | + ProtocolVersion getProtocolVersion(); | |
| 256 | + | |
| 257 | + /** | |
| 258 | + * @param maximumAllowed The maximum protocol version to use. | |
| 259 | + * @return The target protocolVersion or maximumAllowed if {@link #getProtocolVersion} is greater. | |
| 260 | + */ | |
| 261 | + ProtocolVersion getProtocolVersion(ProtocolVersion maximumAllowed); | |
| 239 | 262 | } |
modified driver-core/src/test/java/com/datastax/driver/core/CCMBridge.java +151 −165
| @@ -40,11 +40,11 @@ | ||
| 40 | 40 | |
| 41 | 41 | private static final Logger logger = LoggerFactory.getLogger(CCMBridge.class); |
| 42 | 42 | |
| 43 | - private static final String CASSANDRA_VERSION; | |
| 43 | + private static final VersionNumber GLOBAL_CASSANDRA_VERSION_NUMBER; | |
| 44 | 44 | |
| 45 | - private static final Set<String> CASSANDRA_INSTALL_ARGS; | |
| 45 | + private static final VersionNumber GLOBAL_DSE_VERSION_NUMBER; | |
| 46 | 46 | |
| 47 | - private static final boolean IS_DSE; | |
| 47 | + private static final Set<String> CASSANDRA_INSTALL_ARGS; | |
| 48 | 48 | |
| 49 | 49 | public static final String DEFAULT_CLIENT_TRUSTSTORE_PASSWORD = "cassandra1sfun"; |
| 50 | 50 | public static final String DEFAULT_CLIENT_TRUSTSTORE_PATH = "/client.truststore"; |
| @@ -81,8 +81,8 @@ | ||
| 81 | 81 | private static final Map<String, String> ENVIRONMENT_MAP; |
| 82 | 82 | |
| 83 | 83 | /** |
| 84 | - * A mapping of full DSE versions to their C* counterpart. This is not meant to be comprehensive. Used by | |
| 85 | - * {@link #getCassandraVersion()}. If C* version cannot be derived, the method makes a 'best guess'. | |
| 84 | + * A mapping of full DSE versions to their C* counterpart. This is not meant to be comprehensive. | |
| 85 | + * If C* version cannot be derived, the method makes a 'best guess'. | |
| 86 | 86 | */ |
| 87 | 87 | private static final Map<String, String> dseToCassandraVersions = ImmutableMap.<String, String>builder() |
| 88 | 88 | .put("5.0.4", "3.0.10") |
| @@ -144,14 +144,14 @@ | ||
| 144 | 144 | private static final String CCM_COMMAND; |
| 145 | 145 | |
| 146 | 146 | static { |
| 147 | - CASSANDRA_VERSION = System.getProperty("cassandra.version"); | |
| 147 | + String inputCassandraVersion = System.getProperty("cassandra.version"); | |
| 148 | 148 | String installDirectory = System.getProperty("cassandra.directory"); |
| 149 | 149 | String branch = System.getProperty("cassandra.branch"); |
| 150 | 150 | |
| 151 | 151 | String dseProperty = System.getProperty("dse"); |
| 152 | 152 | // If -Ddse, if the value is empty interpret it as enabled, |
| 153 | 153 | // otherwise if there is a value, parse as boolean. |
| 154 | - IS_DSE = dseProperty != null && (dseProperty.isEmpty() || Boolean.parseBoolean(dseProperty)); | |
| 154 | + boolean isDse = dseProperty != null && (dseProperty.isEmpty() || Boolean.parseBoolean(dseProperty)); | |
| 155 | 155 | |
| 156 | 156 | ImmutableSet.Builder<String> installArgs = ImmutableSet.builder(); |
| 157 | 157 | if (installDirectory != null && !installDirectory.trim().isEmpty()) { |
| @@ -159,10 +159,10 @@ | ||
| 159 | 159 | } else if (branch != null && !branch.trim().isEmpty()) { |
| 160 | 160 | installArgs.add("-v git:" + branch.trim().replaceAll("\"", "")); |
| 161 | 161 | } else { |
| 162 | - installArgs.add("-v " + CASSANDRA_VERSION); | |
| 162 | + installArgs.add("-v " + inputCassandraVersion); | |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | - if (IS_DSE) { | |
| 165 | + if (isDse) { | |
| 166 | 166 | installArgs.add("--dse"); |
| 167 | 167 | } |
| 168 | 168 | |
| @@ -193,12 +193,57 @@ | ||
| 193 | 193 | } |
| 194 | 194 | ENVIRONMENT_MAP = ImmutableMap.copyOf(envMap); |
| 195 | 195 | |
| 196 | - if (CCMBridge.isDSE()) { | |
| 196 | + if (isDse) { | |
| 197 | + GLOBAL_DSE_VERSION_NUMBER = VersionNumber.parse(inputCassandraVersion); | |
| 198 | + GLOBAL_CASSANDRA_VERSION_NUMBER = CCMBridge.getCassandraVersion(GLOBAL_DSE_VERSION_NUMBER); | |
| 197 | 199 | logger.info("Tests requiring CCM will by default use DSE version {} (C* {}, install arguments: {})", |
| 198 | - CCMBridge.getDSEVersion(), CCMBridge.getCassandraVersion(), CCMBridge.getInstallArguments()); | |
| 200 | + GLOBAL_DSE_VERSION_NUMBER, GLOBAL_CASSANDRA_VERSION_NUMBER, CASSANDRA_INSTALL_ARGS); | |
| 199 | 201 | } else { |
| 202 | + GLOBAL_CASSANDRA_VERSION_NUMBER = VersionNumber.parse(inputCassandraVersion); | |
| 203 | + GLOBAL_DSE_VERSION_NUMBER = null; | |
| 200 | 204 | logger.info("Tests requiring CCM will by default use Cassandra version {} (install arguments: {})", |
| 201 | - CCMBridge.getCassandraVersion(), CCMBridge.getInstallArguments()); | |
| 205 | + GLOBAL_CASSANDRA_VERSION_NUMBER, CASSANDRA_INSTALL_ARGS); | |
| 206 | + } | |
| 207 | + } | |
| 208 | + | |
| 209 | + /** | |
| 210 | + * @return {@link VersionNumber} configured for Cassandra based on system properties. | |
| 211 | + */ | |
| 212 | + public static VersionNumber getGlobalCassandraVersion() { | |
| 213 | + return GLOBAL_CASSANDRA_VERSION_NUMBER; | |
| 214 | + } | |
| 215 | + | |
| 216 | + /** | |
| 217 | + * @return {@link VersionNumber} configured for DSE based on system properties. | |
| 218 | + */ | |
| 219 | + public static VersionNumber getGlobalDSEVersion() { | |
| 220 | + return GLOBAL_DSE_VERSION_NUMBER; | |
| 221 | + } | |
| 222 | + | |
| 223 | + /** | |
| 224 | + * @return The mapped cassandra version to the given dseVersion. | |
| 225 | + * If the DSE version can't be derived the following logic is used: | |
| 226 | + * <ol> | |
| 227 | + * <li>If <= 3.X, use C* 1.2</li> | |
| 228 | + * <li>If 4.X, use 2.1 for >= 4.7, 2.0 otherwise.</li> | |
| 229 | + * <li>Otherwise 3.0</li> | |
| 230 | + * </ol> | |
| 231 | + */ | |
| 232 | + public static VersionNumber getCassandraVersion(VersionNumber dseVersion) { | |
| 233 | + String cassandraVersion = dseToCassandraVersions.get(dseVersion.toString()); | |
| 234 | + if (cassandraVersion != null) { | |
| 235 | + return VersionNumber.parse(cassandraVersion); | |
| 236 | + } else if (dseVersion.getMajor() <= 3) { | |
| 237 | + return VersionNumber.parse("1.2"); | |
| 238 | + } else if (dseVersion.getMajor() == 4) { | |
| 239 | + if (dseVersion.getMinor() >= 7) { | |
| 240 | + return VersionNumber.parse("2.1"); | |
| 241 | + } else { | |
| 242 | + return VersionNumber.parse("2.0"); | |
| 243 | + } | |
| 244 | + } else { | |
| 245 | + // Fallback on 3.0 by default. | |
| 246 | + return VersionNumber.parse("3.0"); | |
| 202 | 247 | } |
| 203 | 248 | } |
| 204 | 249 | |
| @@ -215,7 +260,9 @@ | ||
| 215 | 260 | |
| 216 | 261 | private final String clusterName; |
| 217 | 262 | |
| 218 | - private final VersionNumber version; | |
| 263 | + private final VersionNumber cassandraVersion; | |
| 264 | + | |
| 265 | + private final VersionNumber dseVersion; | |
| 219 | 266 | |
| 220 | 267 | private final int storagePort; |
| 221 | 268 | |
| @@ -237,106 +284,20 @@ | ||
| 237 | 284 | |
| 238 | 285 | private final int[] nodes; |
| 239 | 286 | |
| 240 | - private CCMBridge(String clusterName, boolean isDSE, VersionNumber version, int storagePort, int thriftPort, int binaryPort, String jvmArgs, int[] nodes) { | |
| 287 | + private CCMBridge(String clusterName, VersionNumber cassandraVersion, VersionNumber dseVersion, | |
| 288 | + int storagePort, int thriftPort, int binaryPort, String jvmArgs, int[] nodes) { | |
| 241 | 289 | this.clusterName = clusterName; |
| 242 | - this.version = version; | |
| 290 | + this.cassandraVersion = cassandraVersion; | |
| 291 | + this.dseVersion = dseVersion; | |
| 243 | 292 | this.storagePort = storagePort; |
| 244 | 293 | this.thriftPort = thriftPort; |
| 245 | 294 | this.binaryPort = binaryPort; |
| 246 | - this.isDSE = isDSE; | |
| 295 | + this.isDSE = dseVersion != null; | |
| 247 | 296 | this.jvmArgs = jvmArgs; |
| 248 | 297 | this.nodes = nodes; |
| 249 | 298 | this.ccmDir = Files.createTempDir(); |
| 250 | 299 | } |
| 251 | 300 | |
| 252 | - /** | |
| 253 | - * @return The configured cassandra version. If -Ddse=true was used, this value is derived from the | |
| 254 | - * DSE version provided. If the DSE version can't be derived the following logic is used: | |
| 255 | - * <ol> | |
| 256 | - * <li>If <= 3.X, use C* 1.2</li> | |
| 257 | - * <li>If 4.X, use 2.1 for >= 4.7, 2.0 otherwise.</li> | |
| 258 | - * <li>Otherwise 3.0</li> | |
| 259 | - * </ol> | |
| 260 | - */ | |
| 261 | - public static String getCassandraVersion() { | |
| 262 | - if (isDSE()) { | |
| 263 | - String cassandraVersion = dseToCassandraVersions.get(CASSANDRA_VERSION); | |
| 264 | - if (cassandraVersion != null) { | |
| 265 | - return cassandraVersion; | |
| 266 | - } else if (CASSANDRA_VERSION.startsWith("3.") || CASSANDRA_VERSION.compareTo("3") <= 0) { | |
| 267 | - return "1.2"; | |
| 268 | - } else if (CASSANDRA_VERSION.startsWith("4.")) { | |
| 269 | - if (CASSANDRA_VERSION.compareTo("4.7") >= 0) { | |
| 270 | - return "2.1"; | |
| 271 | - } else { | |
| 272 | - return "2.0"; | |
| 273 | - } | |
| 274 | - } else { | |
| 275 | - // Fallback on 3.0 by default. | |
| 276 | - return "3.0"; | |
| 277 | - } | |
| 278 | - | |
| 279 | - } else { | |
| 280 | - return CASSANDRA_VERSION; | |
| 281 | - } | |
| 282 | - } | |
| 283 | - | |
| 284 | - /** | |
| 285 | - * @return {@link VersionNumber} representation of {@link CCMBridge#getCassandraVersion()} | |
| 286 | - */ | |
| 287 | - public static VersionNumber getCassandraVersionNumber() { | |
| 288 | - return VersionNumber.parse(getCassandraVersion()); | |
| 289 | - } | |
| 290 | - | |
| 291 | - /** | |
| 292 | - * @param compareVersion The given version to compare with. | |
| 293 | - * @return Whether or not the configured cassandra version is greater than or equal to the given version. | |
| 294 | - */ | |
| 295 | - public static boolean isCassandraVersionAtLeast(String compareVersion) { | |
| 296 | - return getCassandraVersionNumber().compareTo(VersionNumber.parse(compareVersion)) >= 0; | |
| 297 | - } | |
| 298 | - | |
| 299 | - /** | |
| 300 | - * @return The configured DSE version if '-Ddse=true' specified, otherwise null. | |
| 301 | - */ | |
| 302 | - public static String getDSEVersion() { | |
| 303 | - if (isDSE()) { | |
| 304 | - return CASSANDRA_VERSION; | |
| 305 | - } else { | |
| 306 | - return null; | |
| 307 | - } | |
| 308 | - } | |
| 309 | - | |
| 310 | - /** | |
| 311 | - * @return {@link VersionNumber} representation of {@link CCMBridge#getDSEVersion()} | |
| 312 | - */ | |
| 313 | - public static VersionNumber getDSEVersionNumber() { | |
| 314 | - return VersionNumber.parse(getDSEVersion()); | |
| 315 | - } | |
| 316 | - | |
| 317 | - /** | |
| 318 | - * @param compareVersion The given version to compare with. | |
| 319 | - * @return Whether or not the configured dse version is greater than or equal to the given version. | |
| 320 | - */ | |
| 321 | - public static boolean isDSEVersionAtLeast(String compareVersion) { | |
| 322 | - VersionNumber dseVersion = getDSEVersionNumber(); | |
| 323 | - return dseVersion != null && dseVersion.compareTo(VersionNumber.parse(compareVersion)) >= 0; | |
| 324 | - } | |
| 325 | - | |
| 326 | - /** | |
| 327 | - * @return Whether or not DSE was configured via '-Ddse=true'. | |
| 328 | - */ | |
| 329 | - public static boolean isDSE() { | |
| 330 | - return IS_DSE; | |
| 331 | - } | |
| 332 | - | |
| 333 | - /** | |
| 334 | - * @return The install arguments to pass to CCM when creating the cluster. | |
| 335 | - */ | |
| 336 | - public static Set<String> getInstallArguments() { | |
| 337 | - return CASSANDRA_INSTALL_ARGS; | |
| 338 | - } | |
| 339 | - | |
| 340 | 301 | public static Builder builder() { |
| 341 | 302 | return new Builder(); |
| 342 | 303 | } |
| @@ -352,8 +313,13 @@ | ||
| 352 | 313 | } |
| 353 | 314 | |
| 354 | 315 | @Override |
| 355 | - public VersionNumber getVersion() { | |
| 356 | - return version; | |
| 316 | + public VersionNumber getCassandraVersion() { | |
| 317 | + return cassandraVersion; | |
| 318 | + } | |
| 319 | + | |
| 320 | + @Override | |
| 321 | + public VersionNumber getDSEVersion() { | |
| 322 | + return dseVersion; | |
| 357 | 323 | } |
| 358 | 324 | |
| 359 | 325 | @Override |
| @@ -435,7 +401,7 @@ | ||
| 435 | 401 | private String getStartWaitArguments() { |
| 436 | 402 | // make a small exception for C* 1.2 as it has a bug where it starts listening on the binary |
| 437 | 403 | // interface slightly before it joins the cluster. |
| 438 | - if (getCassandraVersion().startsWith("1.")) { | |
| 404 | + if (this.cassandraVersion.getMajor() == 1) { | |
| 439 | 405 | return " --wait-other-notice"; |
| 440 | 406 | } else { |
| 441 | 407 | return " --no-wait"; |
| @@ -450,7 +416,7 @@ | ||
| 450 | 416 | logger.debug("Starting: {} - free memory: {} MB", this, TestUtils.getFreeMemoryMB()); |
| 451 | 417 | try { |
| 452 | 418 | String cmd = CCM_COMMAND + " start " + jvmArgs + getStartWaitArguments(); |
| 453 | - if (isWindows() && this.version.compareTo(VersionNumber.parse("2.2.4")) >= 0) { | |
| 419 | + if (isWindows() && this.cassandraVersion.compareTo(VersionNumber.parse("2.2.4")) >= 0) { | |
| 454 | 420 | cmd += " --quiet-windows"; |
| 455 | 421 | } |
| 456 | 422 | execute(cmd); |
| @@ -524,7 +490,7 @@ | ||
| 524 | 490 | logger.debug(String.format("Starting: node %s (%s%s:%s) in %s", n, TestUtils.IP_PREFIX, n, binaryPort, this)); |
| 525 | 491 | try { |
| 526 | 492 | String cmd = CCM_COMMAND + " node%d start " + jvmArgs + getStartWaitArguments(); |
| 527 | - if (isWindows() && this.version.compareTo(VersionNumber.parse("2.2.4")) >= 0) { | |
| 493 | + if (isWindows() && this.cassandraVersion.compareTo(VersionNumber.parse("2.2.4")) >= 0) { | |
| 528 | 494 | cmd += " --quiet-windows"; |
| 529 | 495 | } |
| 530 | 496 | execute(cmd, n); |
| @@ -582,7 +548,7 @@ | ||
| 582 | 548 | logger.debug(String.format("Decommissioning: node %s (%s%s:%s) from %s", n, TestUtils.IP_PREFIX, n, binaryPort, this)); |
| 583 | 549 | // Special case for C* 3.12+, DSE 5.1+, force decommission (see CASSANDRA-12510) |
| 584 | 550 | String cmd = CCM_COMMAND + " node%d decommission"; |
| 585 | - if ((!isDSE() && isCassandraVersionAtLeast("3.12")) || (isDSE() && isDSEVersionAtLeast("5.1"))) { | |
| 551 | + if (this.cassandraVersion.compareTo(VersionNumber.parse("3.12")) >= 0) { | |
| 586 | 552 | cmd += " --force"; |
| 587 | 553 | } |
| 588 | 554 | execute(cmd, n); |
| @@ -724,6 +690,26 @@ | ||
| 724 | 690 | TestUtils.waitUntilPortIsDown(addressOfNode(node)); |
| 725 | 691 | } |
| 726 | 692 | |
| 693 | + @Override | |
| 694 | + public ProtocolVersion getProtocolVersion() { | |
| 695 | + VersionNumber version = getCassandraVersion(); | |
| 696 | + if (version.compareTo(VersionNumber.parse("2.0")) < 0) { | |
| 697 | + return ProtocolVersion.V1; | |
| 698 | + } else if (version.compareTo(VersionNumber.parse("2.1")) < 0) { | |
| 699 | + return ProtocolVersion.V2; | |
| 700 | + } else if (version.compareTo(VersionNumber.parse("2.2")) < 0) { | |
| 701 | + return ProtocolVersion.V3; | |
| 702 | + } else { | |
| 703 | + return ProtocolVersion.V4; | |
| 704 | + } | |
| 705 | + } | |
| 706 | + | |
| 707 | + @Override | |
| 708 | + public ProtocolVersion getProtocolVersion(ProtocolVersion maximumAllowed) { | |
| 709 | + ProtocolVersion versionToUse = getProtocolVersion(); | |
| 710 | + return versionToUse.compareTo(maximumAllowed) > 0 ? maximumAllowed : versionToUse; | |
| 711 | + } | |
| 712 | + | |
| 727 | 713 | /** |
| 728 | 714 | * <p> |
| 729 | 715 | * Extracts a keystore from the classpath into a temporary file. |
| @@ -782,9 +768,9 @@ | ||
| 782 | 768 | |
| 783 | 769 | int[] nodes = {1}; |
| 784 | 770 | private boolean start = true; |
| 785 | - private Boolean isDSE = null; | |
| 786 | - private String version = getCassandraVersion(); | |
| 787 | - private Set<String> createOptions = new LinkedHashSet<String>(getInstallArguments()); | |
| 771 | + private boolean dse = false; | |
| 772 | + private VersionNumber version = null; | |
| 773 | + private Set<String> createOptions = new LinkedHashSet<String>(); | |
| 788 | 774 | private Set<String> jvmArgs = new LinkedHashSet<String>(); |
| 789 | 775 | private final Map<String, Object> cassandraConfiguration = Maps.newLinkedHashMap(); |
| 790 | 776 | private final Map<String, Object> dseConfiguration = Maps.newLinkedHashMap(); |
| @@ -840,41 +826,24 @@ | ||
| 840 | 826 | } |
| 841 | 827 | |
| 842 | 828 | /** |
| 843 | - * Sets this cluster to be a DSE cluster (defaults to {@link #isDSE()} if this is never called). | |
| 844 | - */ | |
| 845 | - public Builder withDSE() { | |
| 846 | - this.isDSE = true; | |
| 847 | - return this; | |
| 848 | - } | |
| 849 | - | |
| 850 | - /** | |
| 851 | - * Sets this cluster to be a non-DSE cluster (defaults to {@link #isDSE()} if this is never called). | |
| 829 | + * The Cassandra or DSE version to use. If not specified the globally configured version is used instead. | |
| 852 | 830 | */ |
| 853 | - public Builder withoutDSE() { | |
| 854 | - this.isDSE = false; | |
| 831 | + public Builder withVersion(VersionNumber version) { | |
| 832 | + this.version = version; | |
| 855 | 833 | return this; |
| 856 | 834 | } |
| 857 | 835 | |
| 858 | 836 | /** |
| 859 | - * The Cassandra or DSE version to use (defaults to {@link #getCassandraVersion()} if this is never called). | |
| 837 | + * Indicates whether or not this cluster is meant to be a DSE cluster. | |
| 860 | 838 | */ |
| 861 | - public Builder withVersion(String version) { | |
| 862 | - Iterator<String> it = createOptions.iterator(); | |
| 863 | - while (it.hasNext()) { | |
| 864 | - String option = it.next(); | |
| 865 | - // remove any version previously set and | |
| 866 | - // install-dir, which is incompatible | |
| 867 | - if (option.startsWith("-v ") || option.startsWith("--install-dir")) | |
| 868 | - it.remove(); | |
| 869 | - } | |
| 870 | - this.createOptions.add("-v " + version); | |
| 871 | - this.version = version; | |
| 839 | + public Builder withDSE(boolean dse) { | |
| 840 | + this.dse = dse; | |
| 872 | 841 | return this; |
| 873 | 842 | } |
| 874 | 843 | |
| 875 | 844 | /** |
| 876 | 845 | * Free-form options that will be added at the end of the {@code ccm create} command |
| 877 | - * (defaults to {@link #getInstallArguments()} if this is never called). | |
| 846 | + * (defaults to {@link #CASSANDRA_INSTALL_ARGS} if this is never called). | |
| 878 | 847 | */ |
| 879 | 848 | public Builder withCreateOptions(String... createOptions) { |
| 880 | 849 | Collections.addAll(this.createOptions, createOptions); |
| @@ -937,20 +906,36 @@ | ||
| 937 | 906 | public CCMBridge build() { |
| 938 | 907 | // be careful NOT to alter internal state (hashCode/equals) during build! |
| 939 | 908 | String clusterName = TestUtils.generateIdentifier("ccm_"); |
| 940 | - boolean dse = isDSE == null ? isDSE() : isDSE; | |
| 909 | + | |
| 910 | + | |
| 911 | + VersionNumber dseVersion; | |
| 912 | + VersionNumber cassandraVersion; | |
| 913 | + boolean versionConfigured = this.version != null; | |
| 914 | + // No version was explicitly provided, fallback on global config. | |
| 915 | + if (!versionConfigured) { | |
| 916 | + dseVersion = GLOBAL_DSE_VERSION_NUMBER; | |
| 917 | + cassandraVersion = GLOBAL_CASSANDRA_VERSION_NUMBER; | |
| 918 | + } else if (dse) { | |
| 919 | + // given version is the DSE version, base cassandra version on DSE version. | |
| 920 | + dseVersion = this.version; | |
| 921 | + cassandraVersion = getCassandraVersion(dseVersion); | |
| 922 | + } else { | |
| 923 | + // given version is cassandra version. | |
| 924 | + dseVersion = null; | |
| 925 | + cassandraVersion = this.version; | |
| 926 | + } | |
| 941 | 927 | |
| 942 | 928 | Map<String, Object> cassandraConfiguration = randomizePorts(this.cassandraConfiguration); |
| 943 | - VersionNumber version = VersionNumber.parse(this.version); | |
| 944 | 929 | int storagePort = Integer.parseInt(cassandraConfiguration.get("storage_port").toString()); |
| 945 | 930 | int thriftPort = Integer.parseInt(cassandraConfiguration.get("rpc_port").toString()); |
| 946 | 931 | int binaryPort = Integer.parseInt(cassandraConfiguration.get("native_transport_port").toString()); |
| 947 | - if (!isThriftSupported(dse, version)) { | |
| 932 | + if (!isThriftSupported(cassandraVersion)) { | |
| 948 | 933 | // remove thrift configuration |
| 949 | 934 | cassandraConfiguration.remove("start_rpc"); |
| 950 | 935 | cassandraConfiguration.remove("rpc_port"); |
| 951 | 936 | cassandraConfiguration.remove("thrift_prepared_statements_cache_size_mb"); |
| 952 | 937 | } |
| 953 | - final CCMBridge ccm = new CCMBridge(clusterName, dse, version, storagePort, thriftPort, binaryPort, joinJvmArgs(), nodes); | |
| 938 | + final CCMBridge ccm = new CCMBridge(clusterName, cassandraVersion, dseVersion, storagePort, thriftPort, binaryPort, joinJvmArgs(), nodes); | |
| 954 | 939 | |
| 955 | 940 | Runtime.getRuntime().addShutdownHook(new Thread() { |
| 956 | 941 | @Override |
| @@ -958,12 +943,12 @@ | ||
| 958 | 943 | ccm.close(); |
| 959 | 944 | } |
| 960 | 945 | }); |
| 961 | - ccm.execute(buildCreateCommand(clusterName, dse)); | |
| 946 | + ccm.execute(buildCreateCommand(clusterName, versionConfigured, cassandraVersion, dseVersion)); | |
| 962 | 947 | updateNodeConf(ccm); |
| 963 | 948 | ccm.updateConfig(cassandraConfiguration); |
| 964 | - if (dse) { | |
| 949 | + if (dseVersion != null) { | |
| 965 | 950 | Map<String, Object> dseConfiguration = Maps.newLinkedHashMap(this.dseConfiguration); |
| 966 | - if (dse && version.getMajor() >= 5) { | |
| 951 | + if (dseVersion.getMajor() >= 5) { | |
| 967 | 952 | // randomize DSE specific ports if dse present and greater than 5.0 |
| 968 | 953 | dseConfiguration.put("lease_netty_server_port", RANDOM_PORT); |
| 969 | 954 | dseConfiguration.put("internode_messaging_options.port", RANDOM_PORT); |
| @@ -980,8 +965,8 @@ | ||
| 980 | 965 | return ccm; |
| 981 | 966 | } |
| 982 | 967 | |
| 983 | - private static boolean isThriftSupported(boolean dse, VersionNumber version) { | |
| 984 | - return dse || version.compareTo(VersionNumber.parse("4.0")) < 0; | |
| 968 | + private static boolean isThriftSupported(VersionNumber cassandraVersion) { | |
| 969 | + return cassandraVersion.compareTo(VersionNumber.parse("4.0")) < 0; | |
| 985 | 970 | } |
| 986 | 971 | |
| 987 | 972 | public int weight() { |
| @@ -1007,7 +992,7 @@ | ||
| 1007 | 992 | return allJvmArgs.toString(); |
| 1008 | 993 | } |
| 1009 | 994 | |
| 1010 | - private String buildCreateCommand(String clusterName, boolean dse) { | |
| 995 | + private String buildCreateCommand(String clusterName, boolean versionConfigured, VersionNumber cassandraVersion, VersionNumber dseVersion) { | |
| 1011 | 996 | StringBuilder result = new StringBuilder(CCM_COMMAND + " create"); |
| 1012 | 997 | result.append(" ").append(clusterName); |
| 1013 | 998 | result.append(" -i ").append(TestUtils.IP_PREFIX); |
| @@ -1022,16 +1007,18 @@ | ||
| 1022 | 1007 | } |
| 1023 | 1008 | } |
| 1024 | 1009 | |
| 1025 | - // If not DSE, remove --dse if in createOptions. | |
| 1026 | 1010 | Set<String> lCreateOptions = new LinkedHashSet<String>(createOptions); |
| 1027 | - if (!dse) { | |
| 1028 | - Iterator<String> it = lCreateOptions.iterator(); | |
| 1029 | - while (it.hasNext()) { | |
| 1030 | - String option = it.next(); | |
| 1031 | - // remove any version previously set and | |
| 1032 | - // install-dir, which is incompatible | |
| 1033 | - if (option.equals("--dse")) | |
| 1034 | - it.remove(); | |
| 1011 | + if (!versionConfigured) { | |
| 1012 | + // If no version was provided, use the default install ags. | |
| 1013 | + lCreateOptions.addAll(CASSANDRA_INSTALL_ARGS); | |
| 1014 | + } else { | |
| 1015 | + if (dseVersion != null) { | |
| 1016 | + lCreateOptions.add("--dse"); | |
| 1017 | + lCreateOptions.add("-v"); | |
| 1018 | + lCreateOptions.add(dseVersion.toString()); | |
| 1019 | + } else { | |
| 1020 | + lCreateOptions.add("-v"); | |
| 1021 | + lCreateOptions.add(cassandraVersion.toString()); | |
| 1035 | 1022 | } |
| 1036 | 1023 | } |
| 1037 | 1024 | result.append(" ").append(Joiner.on(" ").join(randomizePorts(lCreateOptions))); |
| @@ -1120,14 +1107,15 @@ | ||
| 1120 | 1107 | @Override |
| 1121 | 1108 | @SuppressWarnings("SimplifiableIfStatement") |
| 1122 | 1109 | public boolean equals(Object o) { |
| 1123 | - // do not include cluster name and start, only | |
| 1124 | - // properties relevant to the settings of the cluster | |
| 1110 | + // do not include start as it is not relevant to the settings of the cluster. | |
| 1125 | 1111 | if (this == o) return true; |
| 1126 | 1112 | if (o == null || getClass() != o.getClass()) return false; |
| 1113 | + | |
| 1127 | 1114 | Builder builder = (Builder) o; |
| 1115 | + | |
| 1116 | + if (dse != builder.dse) return false; | |
| 1128 | 1117 | if (!Arrays.equals(nodes, builder.nodes)) return false; |
| 1129 | - if (isDSE != null ? !isDSE.equals(builder.isDSE) : builder.isDSE != null) return false; | |
| 1130 | - if (!version.equals(builder.version)) return false; | |
| 1118 | + if (version != null ? !version.equals(builder.version) : builder.version != null) return false; | |
| 1131 | 1119 | if (!createOptions.equals(builder.createOptions)) return false; |
| 1132 | 1120 | if (!jvmArgs.equals(builder.jvmArgs)) return false; |
| 1133 | 1121 | if (!cassandraConfiguration.equals(builder.cassandraConfiguration)) return false; |
| @@ -1137,19 +1125,17 @@ | ||
| 1137 | 1125 | |
| 1138 | 1126 | @Override |
| 1139 | 1127 | public int hashCode() { |
| 1140 | - // do not include cluster name and start, only | |
| 1141 | - // properties relevant to the settings of the cluster | |
| 1128 | + // do not include start as it is not relevant to the settings of the cluster. | |
| 1142 | 1129 | int result = Arrays.hashCode(nodes); |
| 1143 | - result = 31 * result + (isDSE != null ? isDSE.hashCode() : 0); | |
| 1130 | + result = 31 * result + (dse ? 1 : 0); | |
| 1131 | + result = 31 * result + (version != null ? version.hashCode() : 0); | |
| 1144 | 1132 | result = 31 * result + createOptions.hashCode(); |
| 1145 | 1133 | result = 31 * result + jvmArgs.hashCode(); |
| 1146 | 1134 | result = 31 * result + cassandraConfiguration.hashCode(); |
| 1147 | 1135 | result = 31 * result + dseConfiguration.hashCode(); |
| 1148 | 1136 | result = 31 * result + workloads.hashCode(); |
| 1149 | - result = 31 * result + version.hashCode(); | |
| 1150 | 1137 | return result; |
| 1151 | 1138 | } |
| 1152 | - | |
| 1153 | 1139 | } |
| 1154 | 1140 | |
| 1155 | 1141 | } |
modified driver-core/src/test/java/com/datastax/driver/core/CCMCache.java +17 −2
| @@ -49,8 +49,13 @@ | ||
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | @Override |
| 52 | - public VersionNumber getVersion() { | |
| 53 | - return ccm.getVersion(); | |
| 52 | + public VersionNumber getCassandraVersion() { | |
| 53 | + return ccm.getCassandraVersion(); | |
| 54 | + } | |
| 55 | + | |
| 56 | + @Override | |
| 57 | + public VersionNumber getDSEVersion() { | |
| 58 | + return ccm.getDSEVersion(); | |
| 54 | 59 | } |
| 55 | 60 | |
| 56 | 61 | @Override |
| @@ -215,6 +220,16 @@ | ||
| 215 | 220 | ccm.waitForDown(node); |
| 216 | 221 | } |
| 217 | 222 | |
| 223 | + @Override | |
| 224 | + public ProtocolVersion getProtocolVersion() { | |
| 225 | + return ccm.getProtocolVersion(); | |
| 226 | + } | |
| 227 | + | |
| 228 | + @Override | |
| 229 | + public ProtocolVersion getProtocolVersion(ProtocolVersion maximumAllowed) { | |
| 230 | + return ccm.getProtocolVersion(maximumAllowed); | |
| 231 | + } | |
| 232 | + | |
| 218 | 233 | @Override |
| 219 | 234 | public String toString() { |
| 220 | 235 | return ccm.toString(); |
modified driver-core/src/test/java/com/datastax/driver/core/CCMTestsSupport.java +38 −17
| @@ -78,13 +78,18 @@ | ||
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | @Override |
| 81 | - public InetSocketAddress addressOfNode(int n) { | |
| 82 | - return delegate.addressOfNode(n); | |
| 81 | + public VersionNumber getCassandraVersion() { | |
| 82 | + return delegate.getCassandraVersion(); | |
| 83 | + } | |
| 84 | + | |
| 85 | + @Override | |
| 86 | + public VersionNumber getDSEVersion() { | |
| 87 | + return delegate.getDSEVersion(); | |
| 83 | 88 | } |
| 84 | 89 | |
| 85 | 90 | @Override |
| 86 | - public VersionNumber getVersion() { | |
| 87 | - return delegate.getVersion(); | |
| 91 | + public InetSocketAddress addressOfNode(int n) { | |
| 92 | + return delegate.addressOfNode(n); | |
| 88 | 93 | } |
| 89 | 94 | |
| 90 | 95 | @Override |
| @@ -237,6 +242,16 @@ | ||
| 237 | 242 | throw new UnsupportedOperationException("This CCM cluster is read-only"); |
| 238 | 243 | } |
| 239 | 244 | |
| 245 | + @Override | |
| 246 | + public ProtocolVersion getProtocolVersion() { | |
| 247 | + return delegate.getProtocolVersion(); | |
| 248 | + } | |
| 249 | + | |
| 250 | + @Override | |
| 251 | + public ProtocolVersion getProtocolVersion(ProtocolVersion maximumAllowed) { | |
| 252 | + return delegate.getProtocolVersion(maximumAllowed); | |
| 253 | + } | |
| 254 | + | |
| 240 | 255 | @Override |
| 241 | 256 | public String toString() { |
| 242 | 257 | return delegate.toString(); |
| @@ -318,9 +333,15 @@ | ||
| 318 | 333 | } |
| 319 | 334 | |
| 320 | 335 | private void addConfigOptions(String[] conf, Map<String, Object> config) { |
| 321 | - String versionStr = version(); | |
| 322 | - VersionNumber version = VersionNumber.parse(versionStr != null ? | |
| 323 | - versionStr : CCMBridge.getCassandraVersion()); | |
| 336 | + VersionNumber version = VersionNumber.parse(version()); | |
| 337 | + if (version == null) { | |
| 338 | + version = CCMBridge.getGlobalCassandraVersion(); | |
| 339 | + } else { | |
| 340 | + Boolean dse = dse(); | |
| 341 | + if (dse != null && dse) { | |
| 342 | + version = CCMBridge.getCassandraVersion(version); | |
| 343 | + } | |
| 344 | + } | |
| 324 | 345 | for (String aConf : conf) { |
| 325 | 346 | String[] tokens = aConf.split(":"); |
| 326 | 347 | if (tokens.length != 2) |
| @@ -331,7 +352,7 @@ | ||
| 331 | 352 | // cannot be met. |
| 332 | 353 | if (configVersionRequirements.containsKey(key)) { |
| 333 | 354 | VersionNumber requirement = configVersionRequirements.get(key); |
| 334 | - if (version.compareTo(requirement) < 0) { | |
| 355 | + if (version != null && version.compareTo(requirement) < 0) { | |
| 335 | 356 | LOGGER.debug("Skipping inclusion of '{}' in cassandra.yaml since it requires >= C* {} and {} " + |
| 336 | 357 | "was detected.", aConf, requirement, version); |
| 337 | 358 | continue; |
| @@ -428,16 +449,16 @@ | ||
| 428 | 449 | if (ccmBuilder == null) { |
| 429 | 450 | ccmBuilder = CCMBridge.builder().withNodes(numberOfNodes()).notStarted(); |
| 430 | 451 | } |
| 431 | - if (version() != null) | |
| 432 | - ccmBuilder.withVersion(version()); | |
| 433 | - Boolean dse = dse(); | |
| 434 | - if (dse != null) { | |
| 435 | - if (dse) { | |
| 436 | - ccmBuilder.withDSE(); | |
| 437 | - } else { | |
| 438 | - ccmBuilder.withoutDSE(); | |
| 439 | - } | |
| 452 | + | |
| 453 | + String versionStr = version(); | |
| 454 | + if (versionStr != null) { | |
| 455 | + VersionNumber version = VersionNumber.parse(versionStr); | |
| 456 | + ccmBuilder.withVersion(version); | |
| 440 | 457 | } |
| 458 | + | |
| 459 | + Boolean dse = dse(); | |
| 460 | + if (dse != null) | |
| 461 | + ccmBuilder.withDSE(dse); | |
| 441 | 462 | if (ssl()) |
| 442 | 463 | ccmBuilder.withSSL(); |
| 443 | 464 | if (auth()) |
modified driver-core/src/test/java/com/datastax/driver/core/DataTypeClassNameParserTest.java +1 −1
| @@ -25,7 +25,7 @@ | ||
| 25 | 25 | |
| 26 | 26 | public class DataTypeClassNameParserTest { |
| 27 | 27 | |
| 28 | - private ProtocolVersion protocolVersion = TestUtils.getDesiredProtocolVersion(); | |
| 28 | + private ProtocolVersion protocolVersion = ProtocolVersion.NEWEST_SUPPORTED; | |
| 29 | 29 | private CodecRegistry codecRegistry = new CodecRegistry(); |
| 30 | 30 | |
| 31 | 31 | @Test(groups = "unit") |
modified driver-core/src/test/java/com/datastax/driver/core/DataTypeIntegrationTest.java +22 −16
| @@ -39,13 +39,19 @@ | ||
| 39 | 39 | public class DataTypeIntegrationTest extends CCMTestsSupport { |
| 40 | 40 | private static final Logger logger = LoggerFactory.getLogger(DataTypeIntegrationTest.class); |
| 41 | 41 | |
| 42 | - List<TestTable> tables = allTables(); | |
| 43 | - VersionNumber cassandraVersion; | |
| 42 | + private Map<DataType, Object> samples; | |
| 43 | + | |
| 44 | + private List<TestTable> tables; | |
| 45 | + | |
| 46 | + private VersionNumber cassandraVersion; | |
| 44 | 47 | |
| 45 | 48 | enum StatementType {RAW_STRING, SIMPLE_WITH_PARAM, PREPARED} |
| 46 | 49 | |
| 47 | 50 | @Override |
| 48 | 51 | public void onTestContextInitialized() { |
| 52 | + ProtocolVersion protocolVersion = ccm().getProtocolVersion(); | |
| 53 | + samples = PrimitiveTypeSamples.samples(protocolVersion); | |
| 54 | + tables = allTables(); | |
| 49 | 55 | Host host = cluster().getMetadata().getAllHosts().iterator().next(); |
| 50 | 56 | cassandraVersion = host.getCassandraVersion().nextStable(); |
| 51 | 57 | List<String> statements = Lists.newArrayList(); |
| @@ -188,7 +194,7 @@ | ||
| 188 | 194 | } |
| 189 | 195 | } |
| 190 | 196 | |
| 191 | - private static List<TestTable> allTables() { | |
| 197 | + private List<TestTable> allTables() { | |
| 192 | 198 | List<TestTable> tables = Lists.newArrayList(); |
| 193 | 199 | |
| 194 | 200 | tables.addAll(tablesWithPrimitives()); |
| @@ -201,18 +207,18 @@ | ||
| 201 | 207 | return ImmutableList.copyOf(tables); |
| 202 | 208 | } |
| 203 | 209 | |
| 204 | - private static List<TestTable> tablesWithPrimitives() { | |
| 210 | + private List<TestTable> tablesWithPrimitives() { | |
| 205 | 211 | List<TestTable> tables = Lists.newArrayList(); |
| 206 | - for (Map.Entry<DataType, Object> entry : PrimitiveTypeSamples.ALL.entrySet()) | |
| 212 | + for (Map.Entry<DataType, Object> entry : samples.entrySet()) | |
| 207 | 213 | tables.add(new TestTable(entry.getKey(), entry.getValue(), "1.2.0")); |
| 208 | 214 | return tables; |
| 209 | 215 | } |
| 210 | 216 | |
| 211 | - private static List<TestTable> tablesWithPrimitivesNull() { | |
| 217 | + private List<TestTable> tablesWithPrimitivesNull() { | |
| 212 | 218 | List<TestTable> tables = Lists.newArrayList(); |
| 213 | 219 | // Create a test table for each primitive type testing with null values. If the |
| 214 | 220 | // type maps to a java primitive type it's value will by the default value instead of null. |
| 215 | - for (DataType dataType : DataType.allPrimitiveTypes(TestUtils.getDesiredProtocolVersion())) { | |
| 221 | + for (DataType dataType : DataType.allPrimitiveTypes(ccm().getProtocolVersion())) { | |
| 216 | 222 | Object expectedPrimitiveValue = null; |
| 217 | 223 | switch (dataType.getName()) { |
| 218 | 224 | case BIGINT: |
| @@ -247,9 +253,9 @@ | ||
| 247 | 253 | |
| 248 | 254 | } |
| 249 | 255 | |
| 250 | - private static List<TestTable> tablesWithCollectionsOfPrimitives() { | |
| 256 | + private List<TestTable> tablesWithCollectionsOfPrimitives() { | |
| 251 | 257 | List<TestTable> tables = Lists.newArrayList(); |
| 252 | - for (Map.Entry<DataType, Object> entry : PrimitiveTypeSamples.ALL.entrySet()) { | |
| 258 | + for (Map.Entry<DataType, Object> entry : samples.entrySet()) { | |
| 253 | 259 | |
| 254 | 260 | DataType elementType = entry.getKey(); |
| 255 | 261 | Object elementSample = entry.getValue(); |
| @@ -260,12 +266,12 @@ | ||
| 260 | 266 | return tables; |
| 261 | 267 | } |
| 262 | 268 | |
| 263 | - private static List<TestTable> tablesWithMapsOfPrimitives() { | |
| 269 | + private List<TestTable> tablesWithMapsOfPrimitives() { | |
| 264 | 270 | List<TestTable> tables = Lists.newArrayList(); |
| 265 | - for (Map.Entry<DataType, Object> keyEntry : PrimitiveTypeSamples.ALL.entrySet()) { | |
| 271 | + for (Map.Entry<DataType, Object> keyEntry : samples.entrySet()) { | |
| 266 | 272 | DataType keyType = keyEntry.getKey(); |
| 267 | 273 | Object keySample = keyEntry.getValue(); |
| 268 | - for (Map.Entry<DataType, Object> valueEntry : PrimitiveTypeSamples.ALL.entrySet()) { | |
| 274 | + for (Map.Entry<DataType, Object> valueEntry : samples.entrySet()) { | |
| 269 | 275 | DataType valueType = valueEntry.getKey(); |
| 270 | 276 | Object valueSample = valueEntry.getValue(); |
| 271 | 277 | |
| @@ -277,7 +283,7 @@ | ||
| 277 | 283 | return tables; |
| 278 | 284 | } |
| 279 | 285 | |
| 280 | - private static Collection<? extends TestTable> tablesWithNestedCollections() { | |
| 286 | + private Collection<? extends TestTable> tablesWithNestedCollections() { | |
| 281 | 287 | List<TestTable> tables = Lists.newArrayList(); |
| 282 | 288 | |
| 283 | 289 | // To avoid combinatorial explosion, only use int as the primitive type, and two levels of nesting. |
| @@ -308,7 +314,7 @@ | ||
| 308 | 314 | return tables; |
| 309 | 315 | } |
| 310 | 316 | |
| 311 | - private static Collection<? extends TestTable> tablesWithRandomlyGeneratedNestedCollections() { | |
| 317 | + private Collection<? extends TestTable> tablesWithRandomlyGeneratedNestedCollections() { | |
| 312 | 318 | List<TestTable> tables = Lists.newArrayList(); |
| 313 | 319 | |
| 314 | 320 | DataType nestedListType = buildNestedType(DataType.Name.LIST, 5); |
| @@ -324,7 +330,7 @@ | ||
| 324 | 330 | /** |
| 325 | 331 | * Populate a nested collection based on the given type and it's arguments. |
| 326 | 332 | */ |
| 327 | - public static Object nestedObject(DataType type) { | |
| 333 | + public Object nestedObject(DataType type) { | |
| 328 | 334 | |
| 329 | 335 | int typeIdx = type.getTypeArguments().size() > 1 ? 1 : 0; |
| 330 | 336 | DataType argument = type.getTypeArguments().get(typeIdx); |
| @@ -374,7 +380,7 @@ | ||
| 374 | 380 | * @return a DataType that is a nested collection with the given baseType with the |
| 375 | 381 | * given depth. |
| 376 | 382 | */ |
| 377 | - public static DataType buildNestedType(DataType.Name baseType, int depth) { | |
| 383 | + public DataType buildNestedType(DataType.Name baseType, int depth) { | |
| 378 | 384 | Random r = new Random(); |
| 379 | 385 | DataType t = null; |
| 380 | 386 |
modified driver-core/src/test/java/com/datastax/driver/core/DataTypeTest.java +1 −1
| @@ -37,7 +37,7 @@ | ||
| 37 | 37 | |
| 38 | 38 | CodecRegistry codecRegistry = new CodecRegistry(); |
| 39 | 39 | |
| 40 | - ProtocolVersion protocolVersion = TestUtils.getDesiredProtocolVersion(); | |
| 40 | + ProtocolVersion protocolVersion = ProtocolVersion.NEWEST_SUPPORTED; | |
| 41 | 41 | |
| 42 | 42 | static boolean exclude(DataType t) { |
| 43 | 43 | return t.getName() == DataType.Name.COUNTER; |
modified driver-core/src/test/java/com/datastax/driver/core/GettableDataIntegrationTest.java +1 −1
| @@ -45,7 +45,7 @@ | ||
| 45 | 45 | |
| 46 | 46 | @Override |
| 47 | 47 | public void onTestContextInitialized() { |
| 48 | - is21 = ccm().getVersion().compareTo(VersionNumber.parse("2.1.3")) > 0; | |
| 48 | + is21 = ccm().getCassandraVersion().compareTo(VersionNumber.parse("2.1.3")) > 0; | |
| 49 | 49 | // only add tuples / nested collections at > 2.1.3. |
| 50 | 50 | execute("CREATE TABLE codec_mapping (k int PRIMARY KEY, " |
| 51 | 51 | + "v int, l list<int>, m map<int,int>" + |
modified driver-core/src/test/java/com/datastax/driver/core/HostMetadataIntegrationTest.java +0 −43
| @@ -15,7 +15,6 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import com.datastax.driver.core.utils.DseVersion; | |
| 19 | 18 | import org.apache.log4j.Level; |
| 20 | 19 | import org.apache.log4j.Logger; |
| 21 | 20 | import org.testng.annotations.Test; |
| @@ -23,52 +22,10 @@ | ||
| 23 | 22 | import java.net.InetAddress; |
| 24 | 23 | |
| 25 | 24 | import static com.datastax.driver.core.Assertions.assertThat; |
| 26 | -import static com.datastax.driver.core.CCMAccess.Workload.solr; | |
| 27 | -import static com.datastax.driver.core.CCMAccess.Workload.spark; | |
| 28 | 25 | import static com.datastax.driver.core.TestUtils.nonQuietClusterCloseOptions; |
| 29 | 26 | |
| 30 | 27 | public class HostMetadataIntegrationTest { |
| 31 | 28 | |
| 32 | - /** | |
| 33 | - * Validates that when given a DSE cluster that the workload and dse versions are properly | |
| 34 | - * parsed and set on the respective {@link Host} instances. | |
| 35 | - * <p/> | |
| 36 | - * This test is disabled as running DSE with workloads is intensive and has unreliable results | |
| 37 | - * when running CCM with multiple workloads. | |
| 38 | - * <p/> | |
| 39 | - * | |
| 40 | - * @test_category host:metadata | |
| 41 | - * @jira_ticket JAVA-1042 | |
| 42 | - * @see HostMetadataIntegrationTest#should_parse_dse_workload_and_version_if_available() | |
| 43 | - */ | |
| 44 | - @Test(groups = "long") | |
| 45 | - @DseVersion("5.0.0") | |
| 46 | - public void test_mixed_dse_workload() { | |
| 47 | - CCMBridge.Builder builder = CCMBridge.builder() | |
| 48 | - .withNodes(3) | |
| 49 | - .withDSE() | |
| 50 | - .withWorkload(2, solr) | |
| 51 | - .withWorkload(3, spark); | |
| 52 | - CCMAccess ccm = CCMCache.get(builder); | |
| 53 | - | |
| 54 | - VersionNumber version = VersionNumber.parse(CCMBridge.getDSEVersion()); | |
| 55 | - | |
| 56 | - Cluster cluster = Cluster.builder() | |
| 57 | - .addContactPoints(ccm.addressOfNode(1).getAddress()) | |
| 58 | - .withPort(ccm.getBinaryPort()) | |
| 59 | - .build(); | |
| 60 | - try { | |
| 61 | - cluster.connect(); | |
| 62 | - | |
| 63 | - assertThat(cluster).host(1).hasWorkload("Cassandra").hasDseVersion(version); | |
| 64 | - assertThat(cluster).host(2).hasWorkload("Search").hasDseVersion(version); | |
| 65 | - assertThat(cluster).host(3).hasWorkload("Analytics").hasDseVersion(version); | |
| 66 | - } finally { | |
| 67 | - cluster.close(); | |
| 68 | - ccm.close(); | |
| 69 | - } | |
| 70 | - } | |
| 71 | - | |
| 72 | 29 | /** |
| 73 | 30 | * Validates that {@link Host#getDseVersion()} and {@link Host#getDseWorkload()} return values defined in |
| 74 | 31 | * the <code>dse_version</code> and <code>workload</code> columns if they are present in <code>system.local</code> |
modified driver-core/src/test/java/com/datastax/driver/core/IndexMetadataTest.java +5 −5
| @@ -75,7 +75,7 @@ | ||
| 75 | 75 | + "\"MixedCaseColumn\" list<text>," |
| 76 | 76 | + |
| 77 | 77 | // Frozen collections was introduced only in C* 2.1.3 |
| 78 | - (ccm().getVersion().compareTo(VersionNumber.parse("2.1.3")) >= 0 | |
| 78 | + (ccm().getCassandraVersion().compareTo(VersionNumber.parse("2.1.3")) >= 0 | |
| 79 | 79 | ? |
| 80 | 80 | ", map_full frozen<map<text, int>>," |
| 81 | 81 | + "set_full frozen<set<text>>," |
| @@ -106,7 +106,7 @@ | ||
| 106 | 106 | @CassandraVersion(value = "2.1", description = "index names with quoted identifiers and collection indexes not supported until 2.1") |
| 107 | 107 | public void should_create_metadata_for_values_index_on_mixed_case_column() { |
| 108 | 108 | // 3.0 assumes the 'values' keyword if index on a collection |
| 109 | - String createValuesIndex = ccm().getVersion().getMajor() > 2 ? | |
| 109 | + String createValuesIndex = ccm().getCassandraVersion().getMajor() > 2 ? | |
| 110 | 110 | String.format("CREATE INDEX \"MixedCaseIndex\" ON %s.indexing (values(\"MixedCaseColumn\"));", keyspace) : |
| 111 | 111 | String.format("CREATE INDEX \"MixedCaseIndex\" ON %s.indexing (\"MixedCaseColumn\");", keyspace); |
| 112 | 112 | session().execute(createValuesIndex); |
| @@ -116,7 +116,7 @@ | ||
| 116 | 116 | .hasName("MixedCaseIndex") |
| 117 | 117 | .hasParent((TableMetadata) column.getParent()) |
| 118 | 118 | .isNotCustomIndex() |
| 119 | - .hasTarget(ccm().getVersion().getMajor() > 2 ? "values(\"MixedCaseColumn\")" : "\"MixedCaseColumn\"") | |
| 119 | + .hasTarget(ccm().getCassandraVersion().getMajor() > 2 ? "values(\"MixedCaseColumn\")" : "\"MixedCaseColumn\"") | |
| 120 | 120 | .hasKind(COMPOSITES) |
| 121 | 121 | .asCqlQuery(createValuesIndex); |
| 122 | 122 | assertThat((TableMetadata) column.getParent()).hasIndex(index); |
| @@ -126,7 +126,7 @@ | ||
| 126 | 126 | @CassandraVersion("2.1.0") |
| 127 | 127 | public void should_create_metadata_for_index_on_map_values() { |
| 128 | 128 | // 3.0 assumes the 'values' keyword if index on a collection |
| 129 | - String createValuesIndex = ccm().getVersion().getMajor() > 2 ? | |
| 129 | + String createValuesIndex = ccm().getCassandraVersion().getMajor() > 2 ? | |
| 130 | 130 | String.format("CREATE INDEX map_values_index ON %s.indexing (values(map_values));", keyspace) : |
| 131 | 131 | String.format("CREATE INDEX map_values_index ON %s.indexing (map_values);", keyspace); |
| 132 | 132 | session().execute(createValuesIndex); |
| @@ -136,7 +136,7 @@ | ||
| 136 | 136 | .hasName("map_values_index") |
| 137 | 137 | .hasParent((TableMetadata) column.getParent()) |
| 138 | 138 | .isNotCustomIndex() |
| 139 | - .hasTarget(ccm().getVersion().getMajor() > 2 ? "values(map_values)" : "map_values") | |
| 139 | + .hasTarget(ccm().getCassandraVersion().getMajor() > 2 ? "values(map_values)" : "map_values") | |
| 140 | 140 | .hasKind(COMPOSITES) |
| 141 | 141 | .asCqlQuery(createValuesIndex); |
| 142 | 142 | assertThat((TableMetadata) column.getParent()).hasIndex(index); |
modified driver-core/src/test/java/com/datastax/driver/core/PreparedStatementTest.java +9 −6
| @@ -48,7 +48,8 @@ | ||
| 48 | 48 | private static final String SIMPLE_TABLE = "test"; |
| 49 | 49 | private static final String SIMPLE_TABLE2 = "test2"; |
| 50 | 50 | |
| 51 | - private final Collection<DataType> primitiveTypes = DataType.allPrimitiveTypes(TestUtils.getDesiredProtocolVersion()); | |
| 51 | + private ProtocolVersion protocolVersion; | |
| 52 | + private Collection<DataType> primitiveTypes; | |
| 52 | 53 | |
| 53 | 54 | private boolean exclude(DataType t) { |
| 54 | 55 | return t.getName() == DataType.Name.COUNTER; |
| @@ -56,6 +57,8 @@ | ||
| 56 | 57 | |
| 57 | 58 | @Override |
| 58 | 59 | public void onTestContextInitialized() { |
| 60 | + protocolVersion = ccm().getProtocolVersion(); | |
| 61 | + primitiveTypes = DataType.allPrimitiveTypes(protocolVersion); | |
| 59 | 62 | execute(createTestFixtures()); |
| 60 | 63 | } |
| 61 | 64 | |
| @@ -340,7 +343,7 @@ | ||
| 340 | 343 | toPrepare.setConsistencyLevel(ConsistencyLevel.QUORUM); |
| 341 | 344 | toPrepare.setSerialConsistencyLevel(ConsistencyLevel.LOCAL_SERIAL); |
| 342 | 345 | toPrepare.setRetryPolicy(FallthroughRetryPolicy.INSTANCE); |
| 343 | - if (TestUtils.getDesiredProtocolVersion().compareTo(V4) >= 0) | |
| 346 | + if (protocolVersion.compareTo(V4) >= 0) | |
| 344 | 347 | toPrepare.setOutgoingPayload(ImmutableMap.of("foo", Bytes.fromHexString("0xcafebabe"))); |
| 345 | 348 | toPrepare.setIdempotent(true); |
| 346 | 349 | toPrepare.enableTracing(); |
| @@ -349,7 +352,7 @@ | ||
| 349 | 352 | assertThat(prepared.getConsistencyLevel()).isEqualTo(ConsistencyLevel.QUORUM); |
| 350 | 353 | assertThat(prepared.getSerialConsistencyLevel()).isEqualTo(ConsistencyLevel.LOCAL_SERIAL); |
| 351 | 354 | assertThat(prepared.getRetryPolicy()).isEqualTo(FallthroughRetryPolicy.INSTANCE); |
| 352 | - if (TestUtils.getDesiredProtocolVersion().compareTo(V4) >= 0) | |
| 355 | + if (protocolVersion.compareTo(V4) >= 0) | |
| 353 | 356 | assertThat(prepared.getOutgoingPayload()).isEqualTo(ImmutableMap.of("foo", Bytes.fromHexString("0xcafebabe"))); |
| 354 | 357 | assertThat(prepared.isIdempotent()).isTrue(); |
| 355 | 358 | assertThat(prepared.isTracing()).isTrue(); |
| @@ -358,7 +361,7 @@ | ||
| 358 | 361 | assertThat(bs.getConsistencyLevel()).isEqualTo(ConsistencyLevel.QUORUM); |
| 359 | 362 | assertThat(bs.getSerialConsistencyLevel()).isEqualTo(ConsistencyLevel.LOCAL_SERIAL); |
| 360 | 363 | assertThat(bs.getRetryPolicy()).isEqualTo(FallthroughRetryPolicy.INSTANCE); |
| 361 | - if (TestUtils.getDesiredProtocolVersion().compareTo(V4) >= 0) | |
| 364 | + if (protocolVersion.compareTo(V4) >= 0) | |
| 362 | 365 | assertThat(bs.getOutgoingPayload()).isEqualTo(ImmutableMap.of("foo", Bytes.fromHexString("0xcafebabe"))); |
| 363 | 366 | assertThat(bs.isIdempotent()).isTrue(); |
| 364 | 367 | assertThat(bs.isTracing()).isTrue(); |
| @@ -460,7 +463,7 @@ | ||
| 460 | 463 | Cluster cluster = register(Cluster.builder() |
| 461 | 464 | .addContactPoints(getContactPoints()) |
| 462 | 465 | .withPort(ccm().getBinaryPort()) |
| 463 | - .withProtocolVersion(TestUtils.getDesiredProtocolVersion(ProtocolVersion.V3)) | |
| 466 | + .withProtocolVersion(ccm().getProtocolVersion(ProtocolVersion.V3)) | |
| 464 | 467 | .build()); |
| 465 | 468 | Session session = cluster.connect(); |
| 466 | 469 | try { |
| @@ -490,7 +493,7 @@ | ||
| 490 | 493 | Cluster cluster = register(Cluster.builder() |
| 491 | 494 | .addContactPoints(getContactPoints()) |
| 492 | 495 | .withPort(ccm().getBinaryPort()) |
| 493 | - .withProtocolVersion(TestUtils.getDesiredProtocolVersion(ProtocolVersion.V3)) | |
| 496 | + .withProtocolVersion(ccm().getProtocolVersion(ProtocolVersion.V3)) | |
| 494 | 497 | .build()); |
| 495 | 498 | Session session = cluster.connect(); |
| 496 | 499 | try { |
modified driver-core/src/test/java/com/datastax/driver/core/PrimitiveTypeSamples.java +2 −4
| @@ -36,11 +36,9 @@ | ||
| 36 | 36 | */ |
| 37 | 37 | public class PrimitiveTypeSamples { |
| 38 | 38 | |
| 39 | - public static final Map<DataType, Object> ALL = generateAll(); | |
| 40 | - | |
| 41 | - private static Map<DataType, Object> generateAll() { | |
| 39 | + static Map<DataType, Object> samples(ProtocolVersion protocolVersion) { | |
| 42 | 40 | try { |
| 43 | - final Collection<DataType> primitiveTypes = DataType.allPrimitiveTypes(TestUtils.getDesiredProtocolVersion()); | |
| 41 | + final Collection<DataType> primitiveTypes = DataType.allPrimitiveTypes(protocolVersion); | |
| 44 | 42 | ImmutableMap<DataType, Object> data = ImmutableMap.<DataType, Object>builder() |
| 45 | 43 | .put(DataType.ascii(), "ascii") |
| 46 | 44 | .put(DataType.bigint(), Long.MAX_VALUE) |
modified driver-core/src/test/java/com/datastax/driver/core/QueryLoggerTest.java +44 −40
| @@ -49,41 +49,9 @@ | ||
| 49 | 49 | */ |
| 50 | 50 | public class QueryLoggerTest extends CCMTestsSupport { |
| 51 | 51 | |
| 52 | - private static final List<DataType> dataTypes = new ArrayList<DataType>( | |
| 53 | - Sets.filter(DataType.allPrimitiveTypes(TestUtils.getDesiredProtocolVersion()), new Predicate<DataType>() { | |
| 54 | - @Override | |
| 55 | - public boolean apply(DataType type) { | |
| 56 | - return type != DataType.counter(); | |
| 57 | - } | |
| 58 | - })); | |
| 59 | - | |
| 60 | - private static final List<Object> values = Lists.transform(dataTypes, new Function<DataType, Object>() { | |
| 61 | - @Override | |
| 62 | - public Object apply(DataType type) { | |
| 63 | - return getFixedValue(type); | |
| 64 | - } | |
| 65 | - } | |
| 66 | - ); | |
| 67 | - | |
| 68 | - private static final String definitions = Joiner.on(", ").join( | |
| 69 | - Lists.transform(dataTypes, new Function<DataType, String>() { | |
| 70 | - @Override | |
| 71 | - public String apply(DataType type) { | |
| 72 | - return "c_" + type + " " + type; | |
| 73 | - } | |
| 74 | - } | |
| 75 | - ) | |
| 76 | - ); | |
| 77 | - | |
| 78 | - private static final String assignments = Joiner.on(", ").join( | |
| 79 | - Lists.transform(dataTypes, new Function<DataType, String>() { | |
| 80 | - @Override | |
| 81 | - public String apply(DataType type) { | |
| 82 | - return "c_" + type + " = ?"; | |
| 83 | - } | |
| 84 | - } | |
| 85 | - ) | |
| 86 | - ); | |
| 52 | + private List<DataType> dataTypes; | |
| 53 | + private List<Object> values; | |
| 54 | + private String assignments; | |
| 87 | 55 | |
| 88 | 56 | private Logger normal = Logger.getLogger(NORMAL_LOGGER.getName()); |
| 89 | 57 | private Logger slow = Logger.getLogger(SLOW_LOGGER.getName()); |
| @@ -98,6 +66,47 @@ | ||
| 98 | 66 | private Level originalSlow; |
| 99 | 67 | private Level originalError; |
| 100 | 68 | |
| 69 | + @Override | |
| 70 | + public void onTestContextInitialized() { | |
| 71 | + dataTypes = new ArrayList<DataType>( | |
| 72 | + Sets.filter(DataType.allPrimitiveTypes(ccm().getProtocolVersion()), new Predicate<DataType>() { | |
| 73 | + @Override | |
| 74 | + public boolean apply(DataType type) { | |
| 75 | + return type != DataType.counter(); | |
| 76 | + } | |
| 77 | + })); | |
| 78 | + | |
| 79 | + values = Lists.transform(dataTypes, new Function<DataType, Object>() { | |
| 80 | + @Override | |
| 81 | + public Object apply(DataType type) { | |
| 82 | + return getFixedValue(type); | |
| 83 | + } | |
| 84 | + } | |
| 85 | + ); | |
| 86 | + | |
| 87 | + String definitions = Joiner.on(", ").join( | |
| 88 | + Lists.transform(dataTypes, new Function<DataType, String>() { | |
| 89 | + @Override | |
| 90 | + public String apply(DataType type) { | |
| 91 | + return "c_" + type + " " + type; | |
| 92 | + } | |
| 93 | + } | |
| 94 | + ) | |
| 95 | + ); | |
| 96 | + | |
| 97 | + assignments = Joiner.on(", ").join( | |
| 98 | + Lists.transform(dataTypes, new Function<DataType, String>() { | |
| 99 | + @Override | |
| 100 | + public String apply(DataType type) { | |
| 101 | + return "c_" + type + " = ?"; | |
| 102 | + } | |
| 103 | + } | |
| 104 | + ) | |
| 105 | + ); | |
| 106 | + | |
| 107 | + execute("CREATE TABLE test (pk int PRIMARY KEY, " + definitions + ")"); | |
| 108 | + } | |
| 109 | + | |
| 101 | 110 | @BeforeMethod(groups = {"short", "unit"}) |
| 102 | 111 | public void startCapturingLogs() { |
| 103 | 112 | originalNormal = normal.getLevel(); |
| @@ -1064,9 +1073,4 @@ | ||
| 1064 | 1073 | .contains("param1:'foo'"); |
| 1065 | 1074 | } |
| 1066 | 1075 | |
| 1067 | - @Override | |
| 1068 | - public void onTestContextInitialized() { | |
| 1069 | - execute("CREATE TABLE test (pk int PRIMARY KEY, " + definitions + ")"); | |
| 1070 | - } | |
| 1071 | - | |
| 1072 | 1076 | } |
modified driver-core/src/test/java/com/datastax/driver/core/RecommissionedNodeTest.java +1 −2
| @@ -157,8 +157,7 @@ | ||
| 157 | 157 | .withStoragePort(mainCcm.getStoragePort()) |
| 158 | 158 | .withThriftPort(mainCcm.getThriftPort()) |
| 159 | 159 | .withBinaryPort(mainCcm.getBinaryPort()) |
| 160 | - .withoutDSE() | |
| 161 | - .withVersion("1.2.19"); | |
| 160 | + .withVersion(VersionNumber.parse("1.2.19")); | |
| 162 | 161 | otherCcm = CCMCache.get(otherCcmBuilder); |
| 163 | 162 | otherCcm.waitForUp(1); |
| 164 | 163 |
modified driver-core/src/test/java/com/datastax/driver/core/ReconnectionTest.java +2 −2
| @@ -83,7 +83,7 @@ | ||
| 83 | 83 | public void should_keep_reconnecting_on_authentication_error() throws InterruptedException { |
| 84 | 84 | // For C* 1.2, sleep before attempting to connect as there is a small delay between |
| 85 | 85 | // user being created. |
| 86 | - if (ccm().getVersion().getMajor() < 2) { | |
| 86 | + if (ccm().getCassandraVersion().getMajor() < 2) { | |
| 87 | 87 | Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS); |
| 88 | 88 | } |
| 89 | 89 | CountingReconnectionPolicy reconnectionPolicy = new CountingReconnectionPolicy(new ConstantReconnectionPolicy(reconnectionDelayMillis)); |
| @@ -223,7 +223,7 @@ | ||
| 223 | 223 | .withReconnectionPolicy(new ConstantReconnectionPolicy(5000)) |
| 224 | 224 | .withLoadBalancingPolicy(loadBalancingPolicy) |
| 225 | 225 | .withSocketOptions(socketOptions) |
| 226 | - .withProtocolVersion(TestUtils.getDesiredProtocolVersion()) | |
| 226 | + .withProtocolVersion(ccm().getProtocolVersion()) | |
| 227 | 227 | .build()); |
| 228 | 228 | // Create two sessions to have multiple pools |
| 229 | 229 | cluster.connect(); |
modified driver-core/src/test/java/com/datastax/driver/core/SchemaRefreshDebouncerTest.java +1 −1
| @@ -189,7 +189,7 @@ | ||
| 189 | 189 | */ |
| 190 | 190 | @Test(groups = "short") |
| 191 | 191 | public void should_debounce_and_coalesce_multiple_alter_events_on_same_table_into_refresh_table() throws Exception { |
| 192 | - if (ccm().getVersion().getMajor() > 2 || ccm().getVersion().getMajor() == 2 && ccm().getVersion().getMinor() > 1) | |
| 192 | + if (ccm().getCassandraVersion().compareTo(VersionNumber.parse("2.2")) >= 0) | |
| 193 | 193 | throw new SkipException("Disabled in Cassandra 2.2+ because of CASSANDRA-9996"); |
| 194 | 194 | |
| 195 | 195 | String keyspace = TestUtils.generateIdentifier("ks_"); |
modified driver-core/src/test/java/com/datastax/driver/core/SimpleStatementIntegrationTest.java +2 −2
| @@ -100,7 +100,7 @@ | ||
| 100 | 100 | @Test(groups = "short", expectedExceptions = UnsupportedFeatureException.class) |
| 101 | 101 | @CassandraVersion("2.0.0") |
| 102 | 102 | public void should_fail_if_query_with_named_values_if_protocol_is_V2() { |
| 103 | - if (ccm().getVersion().getMajor() >= 3) { | |
| 103 | + if (ccm().getCassandraVersion().getMajor() >= 3) { | |
| 104 | 104 | throw new SkipException("Skipping since Cassandra 3.0+ does not support protocol v2"); |
| 105 | 105 | } |
| 106 | 106 | useNamedValuesWithProtocol(ProtocolVersion.V2); |
| @@ -109,7 +109,7 @@ | ||
| 109 | 109 | @Test(groups = "short", expectedExceptions = UnsupportedFeatureException.class) |
| 110 | 110 | @CassandraVersion("2.0.0") |
| 111 | 111 | public void should_fail_if_query_with_named_values_if_protocol_is_V1() { |
| 112 | - if (ccm().getVersion().getMajor() >= 3) { | |
| 112 | + if (ccm().getCassandraVersion().getMajor() >= 3) { | |
| 113 | 113 | throw new SkipException("Skipping since Cassandra 3.0+ does not support protocol v1"); |
| 114 | 114 | } |
| 115 | 115 | useNamedValuesWithProtocol(ProtocolVersion.V1); |
modified driver-core/src/test/java/com/datastax/driver/core/StatementIdempotenceTest.java +1 −1
| @@ -41,7 +41,7 @@ | ||
| 41 | 41 | when(cluster.getConfiguration()).thenReturn(configuration); |
| 42 | 42 | when(configuration.getCodecRegistry()).thenReturn(codecRegistry); |
| 43 | 43 | when(configuration.getProtocolOptions()).thenReturn(protocolOptions); |
| 44 | - when(protocolOptions.getProtocolVersion()).thenReturn(TestUtils.getDesiredProtocolVersion()); | |
| 44 | + when(protocolOptions.getProtocolVersion()).thenReturn(ProtocolVersion.NEWEST_SUPPORTED); | |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | @Test(groups = "unit") |
modified driver-core/src/test/java/com/datastax/driver/core/TestListener.java +4 −3
| @@ -119,12 +119,13 @@ | ||
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | private static void cassandraVersionCheck(CassandraVersion version) { |
| 122 | - versionCheck(CCMBridge.getCassandraVersionNumber(), VersionNumber.parse(version.value()), version.description()); | |
| 122 | + versionCheck(CCMBridge.getGlobalCassandraVersion(), VersionNumber.parse(version.value()), version.description()); | |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | private static void dseVersionCheck(DseVersion version) { |
| 126 | - if (CCMBridge.isDSE()) { | |
| 127 | - versionCheck(CCMBridge.getDSEVersionNumber(), VersionNumber.parse(version.value()), version.description()); | |
| 126 | + VersionNumber dseVersion = CCMBridge.getGlobalDSEVersion(); | |
| 127 | + if (dseVersion != null) { | |
| 128 | + versionCheck(CCMBridge.getGlobalDSEVersion(), VersionNumber.parse(version.value()), version.description()); | |
| 128 | 129 | } else { |
| 129 | 130 | throw new SkipException("Skipping test because not configured for DataStax Enterprise cluster."); |
| 130 | 131 | } |
modified driver-core/src/test/java/com/datastax/driver/core/TestUtils.java +2 −29
| @@ -735,33 +735,6 @@ | ||
| 735 | 735 | return connectionSuccessful; |
| 736 | 736 | } |
| 737 | 737 | |
| 738 | - /** | |
| 739 | - * @return The desired target protocol version based on the 'cassandra.version' System property. | |
| 740 | - */ | |
| 741 | - public static ProtocolVersion getDesiredProtocolVersion() { | |
| 742 | - String version = CCMBridge.getCassandraVersion(); | |
| 743 | - String[] versionArray = version.split("\\.|-"); | |
| 744 | - double major = Double.parseDouble(versionArray[0] + "." + versionArray[1]); | |
| 745 | - if (major < 2.0) { | |
| 746 | - return ProtocolVersion.V1; | |
| 747 | - } else if (major < 2.1) { | |
| 748 | - return ProtocolVersion.V2; | |
| 749 | - } else if (major < 2.2) { | |
| 750 | - return ProtocolVersion.V3; | |
| 751 | - } else { | |
| 752 | - return ProtocolVersion.V4; | |
| 753 | - } | |
| 754 | - } | |
| 755 | - | |
| 756 | - /** | |
| 757 | - * @param maximumAllowed The maximum protocol version to use. | |
| 758 | - * @return The desired protocolVersion or maximumAllowed if {@link #getDesiredProtocolVersion} is greater. | |
| 759 | - */ | |
| 760 | - public static ProtocolVersion getDesiredProtocolVersion(ProtocolVersion maximumAllowed) { | |
| 761 | - ProtocolVersion versionToUse = getDesiredProtocolVersion(); | |
| 762 | - return versionToUse.compareTo(maximumAllowed) > 0 ? maximumAllowed : versionToUse; | |
| 763 | - } | |
| 764 | - | |
| 765 | 738 | /** |
| 766 | 739 | * @return a {@link Cluster} instance that connects only to the control host of the given cluster. |
| 767 | 740 | */ |
| @@ -838,7 +811,7 @@ | ||
| 838 | 811 | |
| 839 | 812 | /** |
| 840 | 813 | * Helper for generating a DynamicCompositeType {@link ByteBuffer} from the given parameters. |
| 841 | - * | |
| 814 | + * <p/> | |
| 842 | 815 | * Any of params given as an Integer will be considered with a field name of 'i', any as String will |
| 843 | 816 | * be considered with a field name of 's'. |
| 844 | 817 | * |
| @@ -881,7 +854,7 @@ | ||
| 881 | 854 | |
| 882 | 855 | /** |
| 883 | 856 | * Helper for generating a Composite {@link ByteBuffer} from the given parameters. |
| 884 | - * | |
| 857 | + * <p/> | |
| 885 | 858 | * Expects Integer and String types for parameters. |
| 886 | 859 | * |
| 887 | 860 | * @param params params to serialize. |
modified driver-core/src/test/java/com/datastax/driver/core/TupleTest.java +12 −11
| @@ -30,10 +30,13 @@ | ||
| 30 | 30 | @CassandraVersion("2.1.0") |
| 31 | 31 | public class TupleTest extends CCMTestsSupport { |
| 32 | 32 | |
| 33 | - ProtocolVersion protocolVersion = TestUtils.getDesiredProtocolVersion(); | |
| 33 | + private ProtocolVersion protocolVersion; | |
| 34 | + private Map<DataType, Object> samples; | |
| 34 | 35 | |
| 35 | 36 | @Override |
| 36 | 37 | public void onTestContextInitialized() { |
| 38 | + protocolVersion = ccm().getProtocolVersion(); | |
| 39 | + samples = PrimitiveTypeSamples.samples(protocolVersion); | |
| 37 | 40 | execute("CREATE TABLE t (k int PRIMARY KEY, v frozen<tuple<int, text, float>>)"); |
| 38 | 41 | } |
| 39 | 42 | |
| @@ -202,8 +205,7 @@ | ||
| 202 | 205 | */ |
| 203 | 206 | @Test(groups = "short") |
| 204 | 207 | public void tupleSubtypesTest() throws Exception { |
| 205 | - | |
| 206 | - List<DataType> DATA_TYPE_PRIMITIVES = Lists.newArrayList(PrimitiveTypeSamples.ALL.keySet()); | |
| 208 | + List<DataType> DATA_TYPE_PRIMITIVES = Lists.newArrayList(samples.keySet()); | |
| 207 | 209 | session().execute("CREATE KEYSPACE test_tuple_subtypes " + |
| 208 | 210 | "WITH replication = { 'class' : 'SimpleStrategy', 'replication_factor': '1'}"); |
| 209 | 211 | session().execute("USE test_tuple_subtypes"); |
| @@ -226,8 +228,8 @@ | ||
| 226 | 228 | for (int j = 0; j < i; ++j) { |
| 227 | 229 | dataTypes.add(DATA_TYPE_PRIMITIVES.get(j)); |
| 228 | 230 | completeDataTypes.add(DATA_TYPE_PRIMITIVES.get(j)); |
| 229 | - createdValues.add(PrimitiveTypeSamples.ALL.get(DATA_TYPE_PRIMITIVES.get(j))); | |
| 230 | - completeValues.add(PrimitiveTypeSamples.ALL.get(DATA_TYPE_PRIMITIVES.get(j))); | |
| 231 | + createdValues.add(samples.get(DATA_TYPE_PRIMITIVES.get(j))); | |
| 232 | + completeValues.add(samples.get(DATA_TYPE_PRIMITIVES.get(j))); | |
| 231 | 233 | } |
| 232 | 234 | |
| 233 | 235 | // complete portion of the arrays needed for trailing nulls |
| @@ -261,8 +263,7 @@ | ||
| 261 | 263 | */ |
| 262 | 264 | @Test(groups = "short") |
| 263 | 265 | public void tupleNonPrimitiveSubTypesTest() throws Exception { |
| 264 | - | |
| 265 | - List<DataType> DATA_TYPE_PRIMITIVES = Lists.newArrayList(PrimitiveTypeSamples.ALL.keySet()); | |
| 266 | + List<DataType> DATA_TYPE_PRIMITIVES = Lists.newArrayList(samples.keySet()); | |
| 266 | 267 | session().execute("CREATE KEYSPACE test_tuple_non_primitive_subtypes " + |
| 267 | 268 | "WITH replication = { 'class' : 'SimpleStrategy', 'replication_factor': '1'}"); |
| 268 | 269 | session().execute("USE test_tuple_non_primitive_subtypes"); |
| @@ -296,7 +297,7 @@ | ||
| 296 | 297 | ArrayList<Object> createdValues = new ArrayList<Object>(); |
| 297 | 298 | |
| 298 | 299 | dataTypes.add(DataType.list(datatype)); |
| 299 | - createdValues.add(Collections.singletonList(PrimitiveTypeSamples.ALL.get(datatype))); | |
| 300 | + createdValues.add(Collections.singletonList(samples.get(datatype))); | |
| 300 | 301 | |
| 301 | 302 | TupleType t = new TupleType(dataTypes, protocolVersion, cluster().getConfiguration().getCodecRegistry()); |
| 302 | 303 | TupleValue createdTuple = t.newValue(createdValues.toArray()); |
| @@ -319,7 +320,7 @@ | ||
| 319 | 320 | ArrayList<Object> createdValues = new ArrayList<Object>(); |
| 320 | 321 | |
| 321 | 322 | dataTypes.add(DataType.set(datatype)); |
| 322 | - createdValues.add(new HashSet<Object>(Collections.singletonList(PrimitiveTypeSamples.ALL.get(datatype)))); | |
| 323 | + createdValues.add(new HashSet<Object>(Collections.singletonList(samples.get(datatype)))); | |
| 323 | 324 | |
| 324 | 325 | TupleType t = new TupleType(dataTypes, protocolVersion, cluster().getConfiguration().getCodecRegistry()); |
| 325 | 326 | TupleValue createdTuple = t.newValue(createdValues.toArray()); |
| @@ -342,7 +343,7 @@ | ||
| 342 | 343 | ArrayList<Object> createdValues = new ArrayList<Object>(); |
| 343 | 344 | |
| 344 | 345 | HashMap<Object, Object> hm = new HashMap<Object, Object>(); |
| 345 | - hm.put(PrimitiveTypeSamples.ALL.get(datatype), PrimitiveTypeSamples.ALL.get(datatype)); | |
| 346 | + hm.put(samples.get(datatype), samples.get(datatype)); | |
| 346 | 347 | |
| 347 | 348 | dataTypes.add(DataType.map(datatype, datatype)); |
| 348 | 349 | createdValues.add(hm); |
| @@ -370,7 +371,7 @@ | ||
| 370 | 371 | */ |
| 371 | 372 | @Test(groups = "short") |
| 372 | 373 | public void detachedTupleTypeTest() { |
| 373 | - TupleType detachedType = TupleType.of(TestUtils.getDesiredProtocolVersion(), CodecRegistry.DEFAULT_INSTANCE, | |
| 374 | + TupleType detachedType = TupleType.of(protocolVersion, CodecRegistry.DEFAULT_INSTANCE, | |
| 374 | 375 | DataType.cint(), DataType.text(), DataType.cfloat()); |
| 375 | 376 | TupleValue detachedValue = detachedType.newValue(1, "hello", 2.0f); |
| 376 | 377 |
modified driver-core/src/test/java/com/datastax/driver/core/TypeCodecAssert.java +1 −1
| @@ -24,7 +24,7 @@ | ||
| 24 | 24 | @SuppressWarnings("unused") |
| 25 | 25 | public class TypeCodecAssert<T> extends AbstractAssert<TypeCodecAssert<T>, TypeCodec<T>> { |
| 26 | 26 | |
| 27 | - private ProtocolVersion version = TestUtils.getDesiredProtocolVersion(); | |
| 27 | + private ProtocolVersion version = ProtocolVersion.NEWEST_SUPPORTED; | |
| 28 | 28 | |
| 29 | 29 | protected TypeCodecAssert(TypeCodec<T> actual) { |
| 30 | 30 | super(actual, TypeCodecAssert.class); |
modified driver-core/src/test/java/com/datastax/driver/core/UserTypesTest.java +9 −7
| @@ -39,11 +39,8 @@ | ||
| 39 | 39 | @CassandraVersion("2.1.0") |
| 40 | 40 | public class UserTypesTest extends CCMTestsSupport { |
| 41 | 41 | |
| 42 | - private final static List<DataType> DATA_TYPE_PRIMITIVES = new ArrayList<DataType>(DataType.allPrimitiveTypes(TestUtils.getDesiredProtocolVersion())); | |
| 43 | - | |
| 44 | - static { | |
| 45 | - DATA_TYPE_PRIMITIVES.remove(DataType.counter()); | |
| 46 | - } | |
| 42 | + private List<DataType> DATA_TYPE_PRIMITIVES; | |
| 43 | + private Map<DataType, Object> samples; | |
| 47 | 44 | |
| 48 | 45 | private final static List<DataType.Name> DATA_TYPE_NON_PRIMITIVE_NAMES = |
| 49 | 46 | new ArrayList<DataType.Name>(EnumSet.of(DataType.Name.LIST, DataType.Name.SET, DataType.Name.MAP, DataType.Name.TUPLE)); |
| @@ -57,6 +54,10 @@ | ||
| 57 | 54 | |
| 58 | 55 | @Override |
| 59 | 56 | public void onTestContextInitialized() { |
| 57 | + ProtocolVersion protocolVersion = ccm().getProtocolVersion(); | |
| 58 | + DATA_TYPE_PRIMITIVES = new ArrayList<DataType>(DataType.allPrimitiveTypes(protocolVersion)); | |
| 59 | + DATA_TYPE_PRIMITIVES.remove(DataType.counter()); | |
| 60 | + samples = PrimitiveTypeSamples.samples(protocolVersion); | |
| 60 | 61 | String type1 = "CREATE TYPE phone (alias text, number text)"; |
| 61 | 62 | String type2 = "CREATE TYPE \"\"\"User Address\"\"\" (street text, \"ZIP\"\"\" int, phones set<frozen<phone>>)"; |
| 62 | 63 | String table = "CREATE TABLE user (id int PRIMARY KEY, addr frozen<\"\"\"User Address\"\"\">)"; |
| @@ -229,10 +230,11 @@ | ||
| 229 | 230 | UserType alldatatypesDef = cluster().getMetadata().getKeyspace("testPrimitiveDatatypes").getUserType("alldatatypes"); |
| 230 | 231 | UDTValue alldatatypes = alldatatypesDef.newValue(); |
| 231 | 232 | |
| 233 | + | |
| 232 | 234 | for (int i = 0; i < DATA_TYPE_PRIMITIVES.size(); i++) { |
| 233 | 235 | DataType dataType = DATA_TYPE_PRIMITIVES.get(i); |
| 234 | 236 | String index = Character.toString((char) (startIndex + i)); |
| 235 | - Object sampleData = PrimitiveTypeSamples.ALL.get(dataType); | |
| 237 | + Object sampleData = samples.get(dataType); | |
| 236 | 238 | |
| 237 | 239 | switch (dataType.getName()) { |
| 238 | 240 | case ASCII: |
| @@ -360,7 +362,7 @@ | ||
| 360 | 362 | DataType dataType = DATA_TYPE_PRIMITIVES.get(j); |
| 361 | 363 | |
| 362 | 364 | String index = Character.toString((char) (startIndex + i)) + "_" + Character.toString((char) (startIndex + j)); |
| 363 | - Object sampleElement = PrimitiveTypeSamples.ALL.get(dataType); | |
| 365 | + Object sampleElement = samples.get(dataType); | |
| 364 | 366 | switch (name) { |
| 365 | 367 | case LIST: |
| 366 | 368 | alldatatypes.setList(index, Lists.newArrayList(sampleElement)); |
modified driver-tests/osgi/src/test/java/com/datastax/driver/osgi/BundleOptions.java +1 −1
| @@ -93,7 +93,7 @@ | ||
| 93 | 93 | // Delegate javax.security.cert to the parent classloader. javax.security.cert.X509Certificate is used in |
| 94 | 94 | // io.netty.util.internal.EmptyArrays, but not directly by the driver. |
| 95 | 95 | bootDelegationPackage("javax.security.cert"), |
| 96 | - systemProperty("cassandra.version").value(CCMBridge.getCassandraVersion()), | |
| 96 | + systemProperty("cassandra.version").value(CCMBridge.getGlobalCassandraVersion().toString()), | |
| 97 | 97 | systemProperty("cassandra.contactpoints").value(TestUtils.IP_PREFIX + 1), |
| 98 | 98 | systemProperty("logback.configurationFile").value("file:" + PathUtils.getBaseDir() + "/src/test/resources/logback.xml"), |
| 99 | 99 | mavenBundle("org.slf4j", "slf4j-api", "1.7.5"), |
modified pom.xml +1 −1
| @@ -46,7 +46,7 @@ | ||
| 46 | 46 | |
| 47 | 47 | <properties> |
| 48 | 48 | <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> |
| 49 | - <cassandra.version>3.8</cassandra.version> | |
| 49 | + <cassandra.version>3.10</cassandra.version> | |
| 50 | 50 | <java.version>1.6</java.version> |
| 51 | 51 | <log4j.version>1.2.17</log4j.version> |
| 52 | 52 | <slf4j-log4j12.version>1.7.6</slf4j-log4j12.version> |