Elffuss BraidHub

kikocis/java-driver public

Remove ambiguity in Cassandra and DSE versions

Motivation:

Originally CCMBridge was developed targeting running Apache Cassandra
clusters using CCM.  Over time this has changed to also work with
DataStax Enterprise.  There are some cases where there was ambiguity
with regards to whether the DSE or Cassandra version was used.  This
attempts to fix this.

Also, there were some places where the globally configured Cassandra/DSE
version was used (passed in via -Dcassandra.version) instead of a
locally configured one for a particular test.  This commit also fixes
this.

In Addition, TestUtils.getDesiredProtocolVersion was made available to
determine the ProtocolVersion to use based on the globally configured
Cassandra version.   This functionality has been moved to CCMAccess, so
one can get the ProtocolVersion tied to the version of Cassandra used
scoped to the test.

Finally, update default cassandra.version used in tests to 3.10.

Modifications:

Break out CCMAccess.getVersion() into two methods,
CCMAccess.getCassandraVersion() and CCMAccess.getDSEVersion().  If DSE
is not configured getDSEVersion() returns null, if it is configured
getCassandraVersion() returns the mapped version of Cassandra from DSE.

Move TestUtils.getDesiredProtocolVersion to CCMAccess.

Rename CCMBridge.CASSANDRA_VERSION to CCMBridge.INPUT_CASSANDRA_VERSION.
Add CCMBridge.CASSANDRA_VERSION_NUMBER and CCMBridge.DSE_VERSION_NUMBER.

Rename CCMBridge.getCassandraVersion() and getDSEVersion() to
CCMBridge.getGlobalCassandraVersion() and
CCMBridge.getGlobalDSEVersion().  These methods return VersionNumber
instead of String.

Result:

Ambiguity removed between Cassandra and DSE versions.  Annotations that
call out CCM remain unchanged.
Changesetb19c57544376af25ffbc8a81ea5da22d8b04113ba30ad918d51e4f70b181fe6b
AuthorAndrew Tolbert <andrew.tolbert@datastax.com> · 2017-02-13 14:19 -06:00
CommitterAndrew Tolbert <andrew.tolbert@datastax.com> · 2017-02-17 11:09 -06:00
Parents3faae1558f54

Browse the files at this changeset

27 files changed

modified driver-core/src/test/java/com/datastax/driver/core/AggregateMetadataTest.java +2 −2
@@ -185,7 +185,7 @@
185185 @Test(groups = "short")
186186 @CassandraVersion("2.2.0")
187187 public void should_parse_and_format_aggregate_with_composite_type_literal_initcond() {
188- VersionNumber ver = VersionNumber.parse(CCMBridge.getCassandraVersion());
188+ VersionNumber ver = ccm().getCassandraVersion();
189189 if (ver.getMajor() == 3) {
190190 if ((ver.getMinor() >= 1 && ver.getMinor() < 4) || (ver.getMinor() == 0 && ver.getPatch() < 4)) {
191191 throw new SkipException("Requires C* 2.2.X, 3.0.4+ or 3.4.X+");
@@ -206,7 +206,7 @@
206206 @Test(groups = "short")
207207 @CassandraVersion("3.4")
208208 public void should_parse_and_format_aggregate_with_composite_type_hex_initcond() {
209- VersionNumber ver = VersionNumber.parse(CCMBridge.getCassandraVersion());
209+ VersionNumber ver = ccm().getCassandraVersion();
210210 if ((ver.getMinor() >= 1 && ver.getMinor() < 4)) {
211211 throw new SkipException("Requires 3.0.4+ or 3.4.X+");
212212 }
modified driver-core/src/test/java/com/datastax/driver/core/AuthenticationTest.java +1 −1
@@ -41,7 +41,7 @@
4141 public void sleepIf12() {
4242 // For C* 1.2, sleep before attempting to connect as there is a small delay between
4343 // user being created.
44- if (ccm().getVersion().getMajor() < 2) {
44+ if (ccm().getCassandraVersion().getMajor() < 2) {
4545 Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS);
4646 }
4747 }
modified driver-core/src/test/java/com/datastax/driver/core/CCMAccess.java +26 −3
@@ -32,13 +32,21 @@
3232 String getClusterName();
3333
3434 /**
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.
3637 * <p/>
37- * By default the version is equal to {@link CCMBridge#getCassandraVersion()}.
3838 *
3939 * @return The version of this CCM cluster.
4040 */
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();
4250
4351 /**
4452 * @return The config directory for this CCM cluster.
@@ -236,4 +244,19 @@
236244 */
237245 void waitForDown(int node);
238246
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);
239262 }
modified driver-core/src/test/java/com/datastax/driver/core/CCMBridge.java +151 −165
@@ -40,11 +40,11 @@
4040
4141 private static final Logger logger = LoggerFactory.getLogger(CCMBridge.class);
4242
43- private static final String CASSANDRA_VERSION;
43+ private static final VersionNumber GLOBAL_CASSANDRA_VERSION_NUMBER;
4444
45- private static final Set<String> CASSANDRA_INSTALL_ARGS;
45+ private static final VersionNumber GLOBAL_DSE_VERSION_NUMBER;
4646
47- private static final boolean IS_DSE;
47+ private static final Set<String> CASSANDRA_INSTALL_ARGS;
4848
4949 public static final String DEFAULT_CLIENT_TRUSTSTORE_PASSWORD = "cassandra1sfun";
5050 public static final String DEFAULT_CLIENT_TRUSTSTORE_PATH = "/client.truststore";
@@ -81,8 +81,8 @@
8181 private static final Map<String, String> ENVIRONMENT_MAP;
8282
8383 /**
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'.
8686 */
8787 private static final Map<String, String> dseToCassandraVersions = ImmutableMap.<String, String>builder()
8888 .put("5.0.4", "3.0.10")
@@ -144,14 +144,14 @@
144144 private static final String CCM_COMMAND;
145145
146146 static {
147- CASSANDRA_VERSION = System.getProperty("cassandra.version");
147+ String inputCassandraVersion = System.getProperty("cassandra.version");
148148 String installDirectory = System.getProperty("cassandra.directory");
149149 String branch = System.getProperty("cassandra.branch");
150150
151151 String dseProperty = System.getProperty("dse");
152152 // If -Ddse, if the value is empty interpret it as enabled,
153153 // 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));
155155
156156 ImmutableSet.Builder<String> installArgs = ImmutableSet.builder();
157157 if (installDirectory != null && !installDirectory.trim().isEmpty()) {
@@ -159,10 +159,10 @@
159159 } else if (branch != null && !branch.trim().isEmpty()) {
160160 installArgs.add("-v git:" + branch.trim().replaceAll("\"", ""));
161161 } else {
162- installArgs.add("-v " + CASSANDRA_VERSION);
162+ installArgs.add("-v " + inputCassandraVersion);
163163 }
164164
165- if (IS_DSE) {
165+ if (isDse) {
166166 installArgs.add("--dse");
167167 }
168168
@@ -193,12 +193,57 @@
193193 }
194194 ENVIRONMENT_MAP = ImmutableMap.copyOf(envMap);
195195
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);
197199 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);
199201 } else {
202+ GLOBAL_CASSANDRA_VERSION_NUMBER = VersionNumber.parse(inputCassandraVersion);
203+ GLOBAL_DSE_VERSION_NUMBER = null;
200204 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");
202247 }
203248 }
204249
@@ -215,7 +260,9 @@
215260
216261 private final String clusterName;
217262
218- private final VersionNumber version;
263+ private final VersionNumber cassandraVersion;
264+
265+ private final VersionNumber dseVersion;
219266
220267 private final int storagePort;
221268
@@ -237,106 +284,20 @@
237284
238285 private final int[] nodes;
239286
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) {
241289 this.clusterName = clusterName;
242- this.version = version;
290+ this.cassandraVersion = cassandraVersion;
291+ this.dseVersion = dseVersion;
243292 this.storagePort = storagePort;
244293 this.thriftPort = thriftPort;
245294 this.binaryPort = binaryPort;
246- this.isDSE = isDSE;
295+ this.isDSE = dseVersion != null;
247296 this.jvmArgs = jvmArgs;
248297 this.nodes = nodes;
249298 this.ccmDir = Files.createTempDir();
250299 }
251300
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-
340301 public static Builder builder() {
341302 return new Builder();
342303 }
@@ -352,8 +313,13 @@
352313 }
353314
354315 @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;
357323 }
358324
359325 @Override
@@ -435,7 +401,7 @@
435401 private String getStartWaitArguments() {
436402 // make a small exception for C* 1.2 as it has a bug where it starts listening on the binary
437403 // interface slightly before it joins the cluster.
438- if (getCassandraVersion().startsWith("1.")) {
404+ if (this.cassandraVersion.getMajor() == 1) {
439405 return " --wait-other-notice";
440406 } else {
441407 return " --no-wait";
@@ -450,7 +416,7 @@
450416 logger.debug("Starting: {} - free memory: {} MB", this, TestUtils.getFreeMemoryMB());
451417 try {
452418 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) {
454420 cmd += " --quiet-windows";
455421 }
456422 execute(cmd);
@@ -524,7 +490,7 @@
524490 logger.debug(String.format("Starting: node %s (%s%s:%s) in %s", n, TestUtils.IP_PREFIX, n, binaryPort, this));
525491 try {
526492 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) {
528494 cmd += " --quiet-windows";
529495 }
530496 execute(cmd, n);
@@ -582,7 +548,7 @@
582548 logger.debug(String.format("Decommissioning: node %s (%s%s:%s) from %s", n, TestUtils.IP_PREFIX, n, binaryPort, this));
583549 // Special case for C* 3.12+, DSE 5.1+, force decommission (see CASSANDRA-12510)
584550 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) {
586552 cmd += " --force";
587553 }
588554 execute(cmd, n);
@@ -724,6 +690,26 @@
724690 TestUtils.waitUntilPortIsDown(addressOfNode(node));
725691 }
726692
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+
727713 /**
728714 * <p>
729715 * Extracts a keystore from the classpath into a temporary file.
@@ -782,9 +768,9 @@
782768
783769 int[] nodes = {1};
784770 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>();
788774 private Set<String> jvmArgs = new LinkedHashSet<String>();
789775 private final Map<String, Object> cassandraConfiguration = Maps.newLinkedHashMap();
790776 private final Map<String, Object> dseConfiguration = Maps.newLinkedHashMap();
@@ -840,41 +826,24 @@
840826 }
841827
842828 /**
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.
852830 */
853- public Builder withoutDSE() {
854- this.isDSE = false;
831+ public Builder withVersion(VersionNumber version) {
832+ this.version = version;
855833 return this;
856834 }
857835
858836 /**
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.
860838 */
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;
872841 return this;
873842 }
874843
875844 /**
876845 * 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).
878847 */
879848 public Builder withCreateOptions(String... createOptions) {
880849 Collections.addAll(this.createOptions, createOptions);
@@ -937,20 +906,36 @@
937906 public CCMBridge build() {
938907 // be careful NOT to alter internal state (hashCode/equals) during build!
939908 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+ }
941927
942928 Map<String, Object> cassandraConfiguration = randomizePorts(this.cassandraConfiguration);
943- VersionNumber version = VersionNumber.parse(this.version);
944929 int storagePort = Integer.parseInt(cassandraConfiguration.get("storage_port").toString());
945930 int thriftPort = Integer.parseInt(cassandraConfiguration.get("rpc_port").toString());
946931 int binaryPort = Integer.parseInt(cassandraConfiguration.get("native_transport_port").toString());
947- if (!isThriftSupported(dse, version)) {
932+ if (!isThriftSupported(cassandraVersion)) {
948933 // remove thrift configuration
949934 cassandraConfiguration.remove("start_rpc");
950935 cassandraConfiguration.remove("rpc_port");
951936 cassandraConfiguration.remove("thrift_prepared_statements_cache_size_mb");
952937 }
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);
954939
955940 Runtime.getRuntime().addShutdownHook(new Thread() {
956941 @Override
@@ -958,12 +943,12 @@
958943 ccm.close();
959944 }
960945 });
961- ccm.execute(buildCreateCommand(clusterName, dse));
946+ ccm.execute(buildCreateCommand(clusterName, versionConfigured, cassandraVersion, dseVersion));
962947 updateNodeConf(ccm);
963948 ccm.updateConfig(cassandraConfiguration);
964- if (dse) {
949+ if (dseVersion != null) {
965950 Map<String, Object> dseConfiguration = Maps.newLinkedHashMap(this.dseConfiguration);
966- if (dse && version.getMajor() >= 5) {
951+ if (dseVersion.getMajor() >= 5) {
967952 // randomize DSE specific ports if dse present and greater than 5.0
968953 dseConfiguration.put("lease_netty_server_port", RANDOM_PORT);
969954 dseConfiguration.put("internode_messaging_options.port", RANDOM_PORT);
@@ -980,8 +965,8 @@
980965 return ccm;
981966 }
982967
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;
985970 }
986971
987972 public int weight() {
@@ -1007,7 +992,7 @@
1007992 return allJvmArgs.toString();
1008993 }
1009994
1010- private String buildCreateCommand(String clusterName, boolean dse) {
995+ private String buildCreateCommand(String clusterName, boolean versionConfigured, VersionNumber cassandraVersion, VersionNumber dseVersion) {
1011996 StringBuilder result = new StringBuilder(CCM_COMMAND + " create");
1012997 result.append(" ").append(clusterName);
1013998 result.append(" -i ").append(TestUtils.IP_PREFIX);
@@ -1022,16 +1007,18 @@
10221007 }
10231008 }
10241009
1025- // If not DSE, remove --dse if in createOptions.
10261010 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());
10351022 }
10361023 }
10371024 result.append(" ").append(Joiner.on(" ").join(randomizePorts(lCreateOptions)));
@@ -1120,14 +1107,15 @@
11201107 @Override
11211108 @SuppressWarnings("SimplifiableIfStatement")
11221109 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.
11251111 if (this == o) return true;
11261112 if (o == null || getClass() != o.getClass()) return false;
1113+
11271114 Builder builder = (Builder) o;
1115+
1116+ if (dse != builder.dse) return false;
11281117 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;
11311119 if (!createOptions.equals(builder.createOptions)) return false;
11321120 if (!jvmArgs.equals(builder.jvmArgs)) return false;
11331121 if (!cassandraConfiguration.equals(builder.cassandraConfiguration)) return false;
@@ -1137,19 +1125,17 @@
11371125
11381126 @Override
11391127 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.
11421129 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);
11441132 result = 31 * result + createOptions.hashCode();
11451133 result = 31 * result + jvmArgs.hashCode();
11461134 result = 31 * result + cassandraConfiguration.hashCode();
11471135 result = 31 * result + dseConfiguration.hashCode();
11481136 result = 31 * result + workloads.hashCode();
1149- result = 31 * result + version.hashCode();
11501137 return result;
11511138 }
1152-
11531139 }
11541140
11551141 }
modified driver-core/src/test/java/com/datastax/driver/core/CCMCache.java +17 −2
@@ -49,8 +49,13 @@
4949 }
5050
5151 @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();
5459 }
5560
5661 @Override
@@ -215,6 +220,16 @@
215220 ccm.waitForDown(node);
216221 }
217222
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+
218233 @Override
219234 public String toString() {
220235 return ccm.toString();
modified driver-core/src/test/java/com/datastax/driver/core/CCMTestsSupport.java +38 −17
@@ -78,13 +78,18 @@
7878 }
7979
8080 @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();
8388 }
8489
8590 @Override
86- public VersionNumber getVersion() {
87- return delegate.getVersion();
91+ public InetSocketAddress addressOfNode(int n) {
92+ return delegate.addressOfNode(n);
8893 }
8994
9095 @Override
@@ -237,6 +242,16 @@
237242 throw new UnsupportedOperationException("This CCM cluster is read-only");
238243 }
239244
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+
240255 @Override
241256 public String toString() {
242257 return delegate.toString();
@@ -318,9 +333,15 @@
318333 }
319334
320335 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+ }
324345 for (String aConf : conf) {
325346 String[] tokens = aConf.split(":");
326347 if (tokens.length != 2)
@@ -331,7 +352,7 @@
331352 // cannot be met.
332353 if (configVersionRequirements.containsKey(key)) {
333354 VersionNumber requirement = configVersionRequirements.get(key);
334- if (version.compareTo(requirement) < 0) {
355+ if (version != null && version.compareTo(requirement) < 0) {
335356 LOGGER.debug("Skipping inclusion of '{}' in cassandra.yaml since it requires >= C* {} and {} " +
336357 "was detected.", aConf, requirement, version);
337358 continue;
@@ -428,16 +449,16 @@
428449 if (ccmBuilder == null) {
429450 ccmBuilder = CCMBridge.builder().withNodes(numberOfNodes()).notStarted();
430451 }
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);
440457 }
458+
459+ Boolean dse = dse();
460+ if (dse != null)
461+ ccmBuilder.withDSE(dse);
441462 if (ssl())
442463 ccmBuilder.withSSL();
443464 if (auth())
modified driver-core/src/test/java/com/datastax/driver/core/DataTypeClassNameParserTest.java +1 −1
@@ -25,7 +25,7 @@
2525
2626 public class DataTypeClassNameParserTest {
2727
28- private ProtocolVersion protocolVersion = TestUtils.getDesiredProtocolVersion();
28+ private ProtocolVersion protocolVersion = ProtocolVersion.NEWEST_SUPPORTED;
2929 private CodecRegistry codecRegistry = new CodecRegistry();
3030
3131 @Test(groups = "unit")
modified driver-core/src/test/java/com/datastax/driver/core/DataTypeIntegrationTest.java +22 −16
@@ -39,13 +39,19 @@
3939 public class DataTypeIntegrationTest extends CCMTestsSupport {
4040 private static final Logger logger = LoggerFactory.getLogger(DataTypeIntegrationTest.class);
4141
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;
4447
4548 enum StatementType {RAW_STRING, SIMPLE_WITH_PARAM, PREPARED}
4649
4750 @Override
4851 public void onTestContextInitialized() {
52+ ProtocolVersion protocolVersion = ccm().getProtocolVersion();
53+ samples = PrimitiveTypeSamples.samples(protocolVersion);
54+ tables = allTables();
4955 Host host = cluster().getMetadata().getAllHosts().iterator().next();
5056 cassandraVersion = host.getCassandraVersion().nextStable();
5157 List<String> statements = Lists.newArrayList();
@@ -188,7 +194,7 @@
188194 }
189195 }
190196
191- private static List<TestTable> allTables() {
197+ private List<TestTable> allTables() {
192198 List<TestTable> tables = Lists.newArrayList();
193199
194200 tables.addAll(tablesWithPrimitives());
@@ -201,18 +207,18 @@
201207 return ImmutableList.copyOf(tables);
202208 }
203209
204- private static List<TestTable> tablesWithPrimitives() {
210+ private List<TestTable> tablesWithPrimitives() {
205211 List<TestTable> tables = Lists.newArrayList();
206- for (Map.Entry<DataType, Object> entry : PrimitiveTypeSamples.ALL.entrySet())
212+ for (Map.Entry<DataType, Object> entry : samples.entrySet())
207213 tables.add(new TestTable(entry.getKey(), entry.getValue(), "1.2.0"));
208214 return tables;
209215 }
210216
211- private static List<TestTable> tablesWithPrimitivesNull() {
217+ private List<TestTable> tablesWithPrimitivesNull() {
212218 List<TestTable> tables = Lists.newArrayList();
213219 // Create a test table for each primitive type testing with null values. If the
214220 // 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())) {
216222 Object expectedPrimitiveValue = null;
217223 switch (dataType.getName()) {
218224 case BIGINT:
@@ -247,9 +253,9 @@
247253
248254 }
249255
250- private static List<TestTable> tablesWithCollectionsOfPrimitives() {
256+ private List<TestTable> tablesWithCollectionsOfPrimitives() {
251257 List<TestTable> tables = Lists.newArrayList();
252- for (Map.Entry<DataType, Object> entry : PrimitiveTypeSamples.ALL.entrySet()) {
258+ for (Map.Entry<DataType, Object> entry : samples.entrySet()) {
253259
254260 DataType elementType = entry.getKey();
255261 Object elementSample = entry.getValue();
@@ -260,12 +266,12 @@
260266 return tables;
261267 }
262268
263- private static List<TestTable> tablesWithMapsOfPrimitives() {
269+ private List<TestTable> tablesWithMapsOfPrimitives() {
264270 List<TestTable> tables = Lists.newArrayList();
265- for (Map.Entry<DataType, Object> keyEntry : PrimitiveTypeSamples.ALL.entrySet()) {
271+ for (Map.Entry<DataType, Object> keyEntry : samples.entrySet()) {
266272 DataType keyType = keyEntry.getKey();
267273 Object keySample = keyEntry.getValue();
268- for (Map.Entry<DataType, Object> valueEntry : PrimitiveTypeSamples.ALL.entrySet()) {
274+ for (Map.Entry<DataType, Object> valueEntry : samples.entrySet()) {
269275 DataType valueType = valueEntry.getKey();
270276 Object valueSample = valueEntry.getValue();
271277
@@ -277,7 +283,7 @@
277283 return tables;
278284 }
279285
280- private static Collection<? extends TestTable> tablesWithNestedCollections() {
286+ private Collection<? extends TestTable> tablesWithNestedCollections() {
281287 List<TestTable> tables = Lists.newArrayList();
282288
283289 // To avoid combinatorial explosion, only use int as the primitive type, and two levels of nesting.
@@ -308,7 +314,7 @@
308314 return tables;
309315 }
310316
311- private static Collection<? extends TestTable> tablesWithRandomlyGeneratedNestedCollections() {
317+ private Collection<? extends TestTable> tablesWithRandomlyGeneratedNestedCollections() {
312318 List<TestTable> tables = Lists.newArrayList();
313319
314320 DataType nestedListType = buildNestedType(DataType.Name.LIST, 5);
@@ -324,7 +330,7 @@
324330 /**
325331 * Populate a nested collection based on the given type and it's arguments.
326332 */
327- public static Object nestedObject(DataType type) {
333+ public Object nestedObject(DataType type) {
328334
329335 int typeIdx = type.getTypeArguments().size() > 1 ? 1 : 0;
330336 DataType argument = type.getTypeArguments().get(typeIdx);
@@ -374,7 +380,7 @@
374380 * @return a DataType that is a nested collection with the given baseType with the
375381 * given depth.
376382 */
377- public static DataType buildNestedType(DataType.Name baseType, int depth) {
383+ public DataType buildNestedType(DataType.Name baseType, int depth) {
378384 Random r = new Random();
379385 DataType t = null;
380386
modified driver-core/src/test/java/com/datastax/driver/core/DataTypeTest.java +1 −1
@@ -37,7 +37,7 @@
3737
3838 CodecRegistry codecRegistry = new CodecRegistry();
3939
40- ProtocolVersion protocolVersion = TestUtils.getDesiredProtocolVersion();
40+ ProtocolVersion protocolVersion = ProtocolVersion.NEWEST_SUPPORTED;
4141
4242 static boolean exclude(DataType t) {
4343 return t.getName() == DataType.Name.COUNTER;
modified driver-core/src/test/java/com/datastax/driver/core/GettableDataIntegrationTest.java +1 −1
@@ -45,7 +45,7 @@
4545
4646 @Override
4747 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;
4949 // only add tuples / nested collections at > 2.1.3.
5050 execute("CREATE TABLE codec_mapping (k int PRIMARY KEY, "
5151 + "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 @@
1515 */
1616 package com.datastax.driver.core;
1717
18-import com.datastax.driver.core.utils.DseVersion;
1918 import org.apache.log4j.Level;
2019 import org.apache.log4j.Logger;
2120 import org.testng.annotations.Test;
@@ -23,52 +22,10 @@
2322 import java.net.InetAddress;
2423
2524 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;
2825 import static com.datastax.driver.core.TestUtils.nonQuietClusterCloseOptions;
2926
3027 public class HostMetadataIntegrationTest {
3128
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-
7229 /**
7330 * Validates that {@link Host#getDseVersion()} and {@link Host#getDseWorkload()} return values defined in
7431 * 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 @@
7575 + "\"MixedCaseColumn\" list<text>,"
7676 +
7777 // 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
7979 ?
8080 ", map_full frozen<map<text, int>>,"
8181 + "set_full frozen<set<text>>,"
@@ -106,7 +106,7 @@
106106 @CassandraVersion(value = "2.1", description = "index names with quoted identifiers and collection indexes not supported until 2.1")
107107 public void should_create_metadata_for_values_index_on_mixed_case_column() {
108108 // 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 ?
110110 String.format("CREATE INDEX \"MixedCaseIndex\" ON %s.indexing (values(\"MixedCaseColumn\"));", keyspace) :
111111 String.format("CREATE INDEX \"MixedCaseIndex\" ON %s.indexing (\"MixedCaseColumn\");", keyspace);
112112 session().execute(createValuesIndex);
@@ -116,7 +116,7 @@
116116 .hasName("MixedCaseIndex")
117117 .hasParent((TableMetadata) column.getParent())
118118 .isNotCustomIndex()
119- .hasTarget(ccm().getVersion().getMajor() > 2 ? "values(\"MixedCaseColumn\")" : "\"MixedCaseColumn\"")
119+ .hasTarget(ccm().getCassandraVersion().getMajor() > 2 ? "values(\"MixedCaseColumn\")" : "\"MixedCaseColumn\"")
120120 .hasKind(COMPOSITES)
121121 .asCqlQuery(createValuesIndex);
122122 assertThat((TableMetadata) column.getParent()).hasIndex(index);
@@ -126,7 +126,7 @@
126126 @CassandraVersion("2.1.0")
127127 public void should_create_metadata_for_index_on_map_values() {
128128 // 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 ?
130130 String.format("CREATE INDEX map_values_index ON %s.indexing (values(map_values));", keyspace) :
131131 String.format("CREATE INDEX map_values_index ON %s.indexing (map_values);", keyspace);
132132 session().execute(createValuesIndex);
@@ -136,7 +136,7 @@
136136 .hasName("map_values_index")
137137 .hasParent((TableMetadata) column.getParent())
138138 .isNotCustomIndex()
139- .hasTarget(ccm().getVersion().getMajor() > 2 ? "values(map_values)" : "map_values")
139+ .hasTarget(ccm().getCassandraVersion().getMajor() > 2 ? "values(map_values)" : "map_values")
140140 .hasKind(COMPOSITES)
141141 .asCqlQuery(createValuesIndex);
142142 assertThat((TableMetadata) column.getParent()).hasIndex(index);
modified driver-core/src/test/java/com/datastax/driver/core/PreparedStatementTest.java +9 −6
@@ -48,7 +48,8 @@
4848 private static final String SIMPLE_TABLE = "test";
4949 private static final String SIMPLE_TABLE2 = "test2";
5050
51- private final Collection<DataType> primitiveTypes = DataType.allPrimitiveTypes(TestUtils.getDesiredProtocolVersion());
51+ private ProtocolVersion protocolVersion;
52+ private Collection<DataType> primitiveTypes;
5253
5354 private boolean exclude(DataType t) {
5455 return t.getName() == DataType.Name.COUNTER;
@@ -56,6 +57,8 @@
5657
5758 @Override
5859 public void onTestContextInitialized() {
60+ protocolVersion = ccm().getProtocolVersion();
61+ primitiveTypes = DataType.allPrimitiveTypes(protocolVersion);
5962 execute(createTestFixtures());
6063 }
6164
@@ -340,7 +343,7 @@
340343 toPrepare.setConsistencyLevel(ConsistencyLevel.QUORUM);
341344 toPrepare.setSerialConsistencyLevel(ConsistencyLevel.LOCAL_SERIAL);
342345 toPrepare.setRetryPolicy(FallthroughRetryPolicy.INSTANCE);
343- if (TestUtils.getDesiredProtocolVersion().compareTo(V4) >= 0)
346+ if (protocolVersion.compareTo(V4) >= 0)
344347 toPrepare.setOutgoingPayload(ImmutableMap.of("foo", Bytes.fromHexString("0xcafebabe")));
345348 toPrepare.setIdempotent(true);
346349 toPrepare.enableTracing();
@@ -349,7 +352,7 @@
349352 assertThat(prepared.getConsistencyLevel()).isEqualTo(ConsistencyLevel.QUORUM);
350353 assertThat(prepared.getSerialConsistencyLevel()).isEqualTo(ConsistencyLevel.LOCAL_SERIAL);
351354 assertThat(prepared.getRetryPolicy()).isEqualTo(FallthroughRetryPolicy.INSTANCE);
352- if (TestUtils.getDesiredProtocolVersion().compareTo(V4) >= 0)
355+ if (protocolVersion.compareTo(V4) >= 0)
353356 assertThat(prepared.getOutgoingPayload()).isEqualTo(ImmutableMap.of("foo", Bytes.fromHexString("0xcafebabe")));
354357 assertThat(prepared.isIdempotent()).isTrue();
355358 assertThat(prepared.isTracing()).isTrue();
@@ -358,7 +361,7 @@
358361 assertThat(bs.getConsistencyLevel()).isEqualTo(ConsistencyLevel.QUORUM);
359362 assertThat(bs.getSerialConsistencyLevel()).isEqualTo(ConsistencyLevel.LOCAL_SERIAL);
360363 assertThat(bs.getRetryPolicy()).isEqualTo(FallthroughRetryPolicy.INSTANCE);
361- if (TestUtils.getDesiredProtocolVersion().compareTo(V4) >= 0)
364+ if (protocolVersion.compareTo(V4) >= 0)
362365 assertThat(bs.getOutgoingPayload()).isEqualTo(ImmutableMap.of("foo", Bytes.fromHexString("0xcafebabe")));
363366 assertThat(bs.isIdempotent()).isTrue();
364367 assertThat(bs.isTracing()).isTrue();
@@ -460,7 +463,7 @@
460463 Cluster cluster = register(Cluster.builder()
461464 .addContactPoints(getContactPoints())
462465 .withPort(ccm().getBinaryPort())
463- .withProtocolVersion(TestUtils.getDesiredProtocolVersion(ProtocolVersion.V3))
466+ .withProtocolVersion(ccm().getProtocolVersion(ProtocolVersion.V3))
464467 .build());
465468 Session session = cluster.connect();
466469 try {
@@ -490,7 +493,7 @@
490493 Cluster cluster = register(Cluster.builder()
491494 .addContactPoints(getContactPoints())
492495 .withPort(ccm().getBinaryPort())
493- .withProtocolVersion(TestUtils.getDesiredProtocolVersion(ProtocolVersion.V3))
496+ .withProtocolVersion(ccm().getProtocolVersion(ProtocolVersion.V3))
494497 .build());
495498 Session session = cluster.connect();
496499 try {
modified driver-core/src/test/java/com/datastax/driver/core/PrimitiveTypeSamples.java +2 −4
@@ -36,11 +36,9 @@
3636 */
3737 public class PrimitiveTypeSamples {
3838
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) {
4240 try {
43- final Collection<DataType> primitiveTypes = DataType.allPrimitiveTypes(TestUtils.getDesiredProtocolVersion());
41+ final Collection<DataType> primitiveTypes = DataType.allPrimitiveTypes(protocolVersion);
4442 ImmutableMap<DataType, Object> data = ImmutableMap.<DataType, Object>builder()
4543 .put(DataType.ascii(), "ascii")
4644 .put(DataType.bigint(), Long.MAX_VALUE)
modified driver-core/src/test/java/com/datastax/driver/core/QueryLoggerTest.java +44 −40
@@ -49,41 +49,9 @@
4949 */
5050 public class QueryLoggerTest extends CCMTestsSupport {
5151
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;
8755
8856 private Logger normal = Logger.getLogger(NORMAL_LOGGER.getName());
8957 private Logger slow = Logger.getLogger(SLOW_LOGGER.getName());
@@ -98,6 +66,47 @@
9866 private Level originalSlow;
9967 private Level originalError;
10068
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+
101110 @BeforeMethod(groups = {"short", "unit"})
102111 public void startCapturingLogs() {
103112 originalNormal = normal.getLevel();
@@ -1064,9 +1073,4 @@
10641073 .contains("param1:'foo'");
10651074 }
10661075
1067- @Override
1068- public void onTestContextInitialized() {
1069- execute("CREATE TABLE test (pk int PRIMARY KEY, " + definitions + ")");
1070- }
1071-
10721076 }
modified driver-core/src/test/java/com/datastax/driver/core/RecommissionedNodeTest.java +1 −2
@@ -157,8 +157,7 @@
157157 .withStoragePort(mainCcm.getStoragePort())
158158 .withThriftPort(mainCcm.getThriftPort())
159159 .withBinaryPort(mainCcm.getBinaryPort())
160- .withoutDSE()
161- .withVersion("1.2.19");
160+ .withVersion(VersionNumber.parse("1.2.19"));
162161 otherCcm = CCMCache.get(otherCcmBuilder);
163162 otherCcm.waitForUp(1);
164163
modified driver-core/src/test/java/com/datastax/driver/core/ReconnectionTest.java +2 −2
@@ -83,7 +83,7 @@
8383 public void should_keep_reconnecting_on_authentication_error() throws InterruptedException {
8484 // For C* 1.2, sleep before attempting to connect as there is a small delay between
8585 // user being created.
86- if (ccm().getVersion().getMajor() < 2) {
86+ if (ccm().getCassandraVersion().getMajor() < 2) {
8787 Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS);
8888 }
8989 CountingReconnectionPolicy reconnectionPolicy = new CountingReconnectionPolicy(new ConstantReconnectionPolicy(reconnectionDelayMillis));
@@ -223,7 +223,7 @@
223223 .withReconnectionPolicy(new ConstantReconnectionPolicy(5000))
224224 .withLoadBalancingPolicy(loadBalancingPolicy)
225225 .withSocketOptions(socketOptions)
226- .withProtocolVersion(TestUtils.getDesiredProtocolVersion())
226+ .withProtocolVersion(ccm().getProtocolVersion())
227227 .build());
228228 // Create two sessions to have multiple pools
229229 cluster.connect();
modified driver-core/src/test/java/com/datastax/driver/core/SchemaRefreshDebouncerTest.java +1 −1
@@ -189,7 +189,7 @@
189189 */
190190 @Test(groups = "short")
191191 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)
193193 throw new SkipException("Disabled in Cassandra 2.2+ because of CASSANDRA-9996");
194194
195195 String keyspace = TestUtils.generateIdentifier("ks_");
modified driver-core/src/test/java/com/datastax/driver/core/SimpleStatementIntegrationTest.java +2 −2
@@ -100,7 +100,7 @@
100100 @Test(groups = "short", expectedExceptions = UnsupportedFeatureException.class)
101101 @CassandraVersion("2.0.0")
102102 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) {
104104 throw new SkipException("Skipping since Cassandra 3.0+ does not support protocol v2");
105105 }
106106 useNamedValuesWithProtocol(ProtocolVersion.V2);
@@ -109,7 +109,7 @@
109109 @Test(groups = "short", expectedExceptions = UnsupportedFeatureException.class)
110110 @CassandraVersion("2.0.0")
111111 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) {
113113 throw new SkipException("Skipping since Cassandra 3.0+ does not support protocol v1");
114114 }
115115 useNamedValuesWithProtocol(ProtocolVersion.V1);
modified driver-core/src/test/java/com/datastax/driver/core/StatementIdempotenceTest.java +1 −1
@@ -41,7 +41,7 @@
4141 when(cluster.getConfiguration()).thenReturn(configuration);
4242 when(configuration.getCodecRegistry()).thenReturn(codecRegistry);
4343 when(configuration.getProtocolOptions()).thenReturn(protocolOptions);
44- when(protocolOptions.getProtocolVersion()).thenReturn(TestUtils.getDesiredProtocolVersion());
44+ when(protocolOptions.getProtocolVersion()).thenReturn(ProtocolVersion.NEWEST_SUPPORTED);
4545 }
4646
4747 @Test(groups = "unit")
modified driver-core/src/test/java/com/datastax/driver/core/TestListener.java +4 −3
@@ -119,12 +119,13 @@
119119 }
120120
121121 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());
123123 }
124124
125125 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());
128129 } else {
129130 throw new SkipException("Skipping test because not configured for DataStax Enterprise cluster.");
130131 }
modified driver-core/src/test/java/com/datastax/driver/core/TestUtils.java +2 −29
@@ -735,33 +735,6 @@
735735 return connectionSuccessful;
736736 }
737737
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-
765738 /**
766739 * @return a {@link Cluster} instance that connects only to the control host of the given cluster.
767740 */
@@ -838,7 +811,7 @@
838811
839812 /**
840813 * Helper for generating a DynamicCompositeType {@link ByteBuffer} from the given parameters.
841- *
814+ * <p/>
842815 * Any of params given as an Integer will be considered with a field name of 'i', any as String will
843816 * be considered with a field name of 's'.
844817 *
@@ -881,7 +854,7 @@
881854
882855 /**
883856 * Helper for generating a Composite {@link ByteBuffer} from the given parameters.
884- *
857+ * <p/>
885858 * Expects Integer and String types for parameters.
886859 *
887860 * @param params params to serialize.
modified driver-core/src/test/java/com/datastax/driver/core/TupleTest.java +12 −11
@@ -30,10 +30,13 @@
3030 @CassandraVersion("2.1.0")
3131 public class TupleTest extends CCMTestsSupport {
3232
33- ProtocolVersion protocolVersion = TestUtils.getDesiredProtocolVersion();
33+ private ProtocolVersion protocolVersion;
34+ private Map<DataType, Object> samples;
3435
3536 @Override
3637 public void onTestContextInitialized() {
38+ protocolVersion = ccm().getProtocolVersion();
39+ samples = PrimitiveTypeSamples.samples(protocolVersion);
3740 execute("CREATE TABLE t (k int PRIMARY KEY, v frozen<tuple<int, text, float>>)");
3841 }
3942
@@ -202,8 +205,7 @@
202205 */
203206 @Test(groups = "short")
204207 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());
207209 session().execute("CREATE KEYSPACE test_tuple_subtypes " +
208210 "WITH replication = { 'class' : 'SimpleStrategy', 'replication_factor': '1'}");
209211 session().execute("USE test_tuple_subtypes");
@@ -226,8 +228,8 @@
226228 for (int j = 0; j < i; ++j) {
227229 dataTypes.add(DATA_TYPE_PRIMITIVES.get(j));
228230 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)));
231233 }
232234
233235 // complete portion of the arrays needed for trailing nulls
@@ -261,8 +263,7 @@
261263 */
262264 @Test(groups = "short")
263265 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());
266267 session().execute("CREATE KEYSPACE test_tuple_non_primitive_subtypes " +
267268 "WITH replication = { 'class' : 'SimpleStrategy', 'replication_factor': '1'}");
268269 session().execute("USE test_tuple_non_primitive_subtypes");
@@ -296,7 +297,7 @@
296297 ArrayList<Object> createdValues = new ArrayList<Object>();
297298
298299 dataTypes.add(DataType.list(datatype));
299- createdValues.add(Collections.singletonList(PrimitiveTypeSamples.ALL.get(datatype)));
300+ createdValues.add(Collections.singletonList(samples.get(datatype)));
300301
301302 TupleType t = new TupleType(dataTypes, protocolVersion, cluster().getConfiguration().getCodecRegistry());
302303 TupleValue createdTuple = t.newValue(createdValues.toArray());
@@ -319,7 +320,7 @@
319320 ArrayList<Object> createdValues = new ArrayList<Object>();
320321
321322 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))));
323324
324325 TupleType t = new TupleType(dataTypes, protocolVersion, cluster().getConfiguration().getCodecRegistry());
325326 TupleValue createdTuple = t.newValue(createdValues.toArray());
@@ -342,7 +343,7 @@
342343 ArrayList<Object> createdValues = new ArrayList<Object>();
343344
344345 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));
346347
347348 dataTypes.add(DataType.map(datatype, datatype));
348349 createdValues.add(hm);
@@ -370,7 +371,7 @@
370371 */
371372 @Test(groups = "short")
372373 public void detachedTupleTypeTest() {
373- TupleType detachedType = TupleType.of(TestUtils.getDesiredProtocolVersion(), CodecRegistry.DEFAULT_INSTANCE,
374+ TupleType detachedType = TupleType.of(protocolVersion, CodecRegistry.DEFAULT_INSTANCE,
374375 DataType.cint(), DataType.text(), DataType.cfloat());
375376 TupleValue detachedValue = detachedType.newValue(1, "hello", 2.0f);
376377
modified driver-core/src/test/java/com/datastax/driver/core/TypeCodecAssert.java +1 −1
@@ -24,7 +24,7 @@
2424 @SuppressWarnings("unused")
2525 public class TypeCodecAssert<T> extends AbstractAssert<TypeCodecAssert<T>, TypeCodec<T>> {
2626
27- private ProtocolVersion version = TestUtils.getDesiredProtocolVersion();
27+ private ProtocolVersion version = ProtocolVersion.NEWEST_SUPPORTED;
2828
2929 protected TypeCodecAssert(TypeCodec<T> actual) {
3030 super(actual, TypeCodecAssert.class);
modified driver-core/src/test/java/com/datastax/driver/core/UserTypesTest.java +9 −7
@@ -39,11 +39,8 @@
3939 @CassandraVersion("2.1.0")
4040 public class UserTypesTest extends CCMTestsSupport {
4141
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;
4744
4845 private final static List<DataType.Name> DATA_TYPE_NON_PRIMITIVE_NAMES =
4946 new ArrayList<DataType.Name>(EnumSet.of(DataType.Name.LIST, DataType.Name.SET, DataType.Name.MAP, DataType.Name.TUPLE));
@@ -57,6 +54,10 @@
5754
5855 @Override
5956 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);
6061 String type1 = "CREATE TYPE phone (alias text, number text)";
6162 String type2 = "CREATE TYPE \"\"\"User Address\"\"\" (street text, \"ZIP\"\"\" int, phones set<frozen<phone>>)";
6263 String table = "CREATE TABLE user (id int PRIMARY KEY, addr frozen<\"\"\"User Address\"\"\">)";
@@ -229,10 +230,11 @@
229230 UserType alldatatypesDef = cluster().getMetadata().getKeyspace("testPrimitiveDatatypes").getUserType("alldatatypes");
230231 UDTValue alldatatypes = alldatatypesDef.newValue();
231232
233+
232234 for (int i = 0; i < DATA_TYPE_PRIMITIVES.size(); i++) {
233235 DataType dataType = DATA_TYPE_PRIMITIVES.get(i);
234236 String index = Character.toString((char) (startIndex + i));
235- Object sampleData = PrimitiveTypeSamples.ALL.get(dataType);
237+ Object sampleData = samples.get(dataType);
236238
237239 switch (dataType.getName()) {
238240 case ASCII:
@@ -360,7 +362,7 @@
360362 DataType dataType = DATA_TYPE_PRIMITIVES.get(j);
361363
362364 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);
364366 switch (name) {
365367 case LIST:
366368 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 @@
9393 // Delegate javax.security.cert to the parent classloader. javax.security.cert.X509Certificate is used in
9494 // io.netty.util.internal.EmptyArrays, but not directly by the driver.
9595 bootDelegationPackage("javax.security.cert"),
96- systemProperty("cassandra.version").value(CCMBridge.getCassandraVersion()),
96+ systemProperty("cassandra.version").value(CCMBridge.getGlobalCassandraVersion().toString()),
9797 systemProperty("cassandra.contactpoints").value(TestUtils.IP_PREFIX + 1),
9898 systemProperty("logback.configurationFile").value("file:" + PathUtils.getBaseDir() + "/src/test/resources/logback.xml"),
9999 mavenBundle("org.slf4j", "slf4j-api", "1.7.5"),
modified pom.xml +1 −1
@@ -46,7 +46,7 @@
4646
4747 <properties>
4848 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
49- <cassandra.version>3.8</cassandra.version>
49+ <cassandra.version>3.10</cassandra.version>
5050 <java.version>1.6</java.version>
5151 <log4j.version>1.2.17</log4j.version>
5252 <slf4j-log4j12.version>1.7.6</slf4j-log4j12.version>