Elffuss BraidHub

kikocis/java-driver public

Move DSE configuration logic into CCMBridge

Motivation:

CCMBridge.Builder previously didn't not account for that fact that the
user could be running with DSE enabled by default.  In this case, there
needs to be a mechanism for disabling DSE for certain tests.

Modifications:

Update CCMConfig dse option to behave such that if never specified is
not set to false but rather null so CCMBridge.Builder can differentiate
between being expicitly set to false or unset.

Also adds version mappings for DSE 4.7.7-9, 4.8.4-11, and 5.0.1-4.

Result:

withoutDSE option added to indicate CCM configuration should not require
DSE.
Changesetb5a08ee3ce3d7b6eb34961341deb90eccef57216ef6d6defc94f1a05d9c2ee37
AuthorAndrew Tolbert <andrew.tolbert@datastax.com> · 2016-12-06 17:06 -06:00
CommitterAndrew Tolbert <andrew.tolbert@datastax.com> · 2016-12-14 17:44 -06:00
Parentseb74149ffde9

Browse the files at this changeset

5 files changed

modified driver-core/src/test/java/com/datastax/driver/core/CCMBridge.java +63 −14
@@ -86,11 +86,26 @@
8686 * {@link #getCassandraVersion()}. If C* version cannot be derived, the method makes a 'best guess'.
8787 */
8888 private static final Map<String, String> dseToCassandraVersions = ImmutableMap.<String, String>builder()
89- .put("5.0", "3.0")
89+ .put("5.0.4", "3.0.10")
90+ .put("5.0.3", "3.0.9")
91+ .put("5.0.2", "3.0.8")
92+ .put("5.0.1", "3.0.7")
93+ .put("5.0", "3.0.7")
94+ .put("4.8.11", "2.1.17")
95+ .put("4.8.10", "2.1.15")
96+ .put("4.8.9", "2.1.15")
97+ .put("4.8.8", "2.1.14")
98+ .put("4.8.7", "2.1.14")
99+ .put("4.8.6", "2.1.13")
100+ .put("4.8.5", "2.1.13")
101+ .put("4.8.4", "2.1.12")
90102 .put("4.8.3", "2.1.11")
91103 .put("4.8.2", "2.1.11")
92104 .put("4.8.1", "2.1.11")
93105 .put("4.8", "2.1.9")
106+ .put("4.7.9", "2.1.15")
107+ .put("4.7.8", "2.1.13")
108+ .put("4.7.7", "2.1.12")
94109 .put("4.7.6", "2.1.11")
95110 .put("4.7.5", "2.1.11")
96111 .put("4.7.4", "2.1.11")
@@ -698,7 +713,7 @@
698713
699714 int[] nodes = {1};
700715 private boolean start = true;
701- private boolean isDSE = isDSE();
716+ private Boolean isDSE = null;
702717 private String version = getCassandraVersion();
703718 private Set<String> createOptions = new LinkedHashSet<String>(getInstallArguments());
704719 private Set<String> jvmArgs = new LinkedHashSet<String>();
@@ -759,11 +774,18 @@
759774 * Sets this cluster to be a DSE cluster (defaults to {@link #isDSE()} if this is never called).
760775 */
761776 public Builder withDSE() {
762- this.createOptions.add("--dse");
763777 this.isDSE = true;
764778 return this;
765779 }
766780
781+ /**
782+ * Sets this cluster to be a non-DSE cluster (defaults to {@link #isDSE()} if this is never called).
783+ */
784+ public Builder withoutDSE() {
785+ this.isDSE = false;
786+ return this;
787+ }
788+
767789 /**
768790 * The Cassandra or DSE version to use (defaults to {@link #getCassandraVersion()} if this is never called).
769791 */
@@ -846,24 +868,38 @@
846868 public CCMBridge build() {
847869 // be careful NOT to alter internal state (hashCode/equals) during build!
848870 String clusterName = TestUtils.generateIdentifier("ccm_");
871+ boolean dse = isDSE == null ? isDSE() : isDSE;
872+
849873 Map<String, Object> cassandraConfiguration = randomizePorts(this.cassandraConfiguration);
850- Map<String, Object> dseConfiguration = randomizePorts(this.dseConfiguration);
851874 VersionNumber version = VersionNumber.parse(this.version);
852875 int storagePort = Integer.parseInt(cassandraConfiguration.get("storage_port").toString());
853876 int thriftPort = Integer.parseInt(cassandraConfiguration.get("rpc_port").toString());
854877 int binaryPort = Integer.parseInt(cassandraConfiguration.get("native_transport_port").toString());
855- final CCMBridge ccm = new CCMBridge(clusterName, isDSE, version, storagePort, thriftPort, binaryPort, joinJvmArgs());
878+ final CCMBridge ccm = new CCMBridge(clusterName, dse, version, storagePort, thriftPort, binaryPort, joinJvmArgs());
879+
856880 Runtime.getRuntime().addShutdownHook(new Thread() {
857881 @Override
858882 public void run() {
859883 ccm.close();
860884 }
861885 });
862- ccm.execute(buildCreateCommand(clusterName));
886+ ccm.execute(buildCreateCommand(clusterName, dse));
863887 updateNodeConf(ccm);
864888 ccm.updateConfig(cassandraConfiguration);
865- if (!dseConfiguration.isEmpty())
866- ccm.updateDSEConfig(dseConfiguration);
889+ if (dse) {
890+ Map<String, Object> dseConfiguration = Maps.newLinkedHashMap(this.dseConfiguration);
891+ /* TODO: Use version passed in if present, there is currently a conflation of C* and DSE versions
892+ * when it comes to this that don't want to disturb. No tests are currently using withVersion with
893+ * dse, so its not an issue at the moment. */
894+ if (VersionNumber.parse(CCMBridge.getDSEVersion()).getMajor() >= 5) {
895+ // randomize DSE specific ports if dse present and greater than 5.0
896+ dseConfiguration.put("lease_netty_server_port", RANDOM_PORT);
897+ dseConfiguration.put("internode_messaging_options.port", RANDOM_PORT);
898+ }
899+ dseConfiguration = randomizePorts(dseConfiguration);
900+ if (!dseConfiguration.isEmpty())
901+ ccm.updateDSEConfig(dseConfiguration);
902+ }
867903 for (Map.Entry<Integer, Workload[]> entry : workloads.entrySet()) {
868904 ccm.setWorkload(entry.getKey(), entry.getValue());
869905 }
@@ -895,7 +931,7 @@
895931 return allJvmArgs.toString();
896932 }
897933
898- private String buildCreateCommand(String clusterName) {
934+ private String buildCreateCommand(String clusterName, boolean dse) {
899935 StringBuilder result = new StringBuilder(CCM_COMMAND + " create");
900936 result.append(" ").append(clusterName);
901937 result.append(" -i ").append(TestUtils.IP_PREFIX);
@@ -909,7 +945,20 @@
909945 result.append(node);
910946 }
911947 }
912- result.append(" ").append(Joiner.on(" ").join(randomizePorts(createOptions)));
948+
949+ // If not DSE, remove --dse if in createOptions.
950+ Set<String> lCreateOptions = new LinkedHashSet<String>(createOptions);
951+ if (!dse) {
952+ Iterator<String> it = lCreateOptions.iterator();
953+ while (it.hasNext()) {
954+ String option = it.next();
955+ // remove any version previously set and
956+ // install-dir, which is incompatible
957+ if (option.equals("--dse"))
958+ it.remove();
959+ }
960+ }
961+ result.append(" ").append(Joiner.on(" ").join(randomizePorts(lCreateOptions)));
913962 return result.toString();
914963 }
915964
@@ -1000,14 +1049,14 @@
10001049 if (this == o) return true;
10011050 if (o == null || getClass() != o.getClass()) return false;
10021051 Builder builder = (Builder) o;
1003- if (isDSE != builder.isDSE) return false;
10041052 if (!Arrays.equals(nodes, builder.nodes)) return false;
1053+ if (isDSE != null ? !isDSE.equals(builder.isDSE) : builder.isDSE != null) return false;
1054+ if (!version.equals(builder.version)) return false;
10051055 if (!createOptions.equals(builder.createOptions)) return false;
10061056 if (!jvmArgs.equals(builder.jvmArgs)) return false;
10071057 if (!cassandraConfiguration.equals(builder.cassandraConfiguration)) return false;
10081058 if (!dseConfiguration.equals(builder.dseConfiguration)) return false;
1009- if (!workloads.equals(builder.workloads)) return false;
1010- return version.equals(builder.version);
1059+ return workloads.equals(builder.workloads);
10111060 }
10121061
10131062 @Override
@@ -1015,7 +1064,7 @@
10151064 // do not include cluster name and start, only
10161065 // properties relevant to the settings of the cluster
10171066 int result = Arrays.hashCode(nodes);
1018- result = 31 * result + (isDSE ? 1 : 0);
1067+ result = 31 * result + (isDSE != null ? isDSE.hashCode() : 0);
10191068 result = 31 * result + createOptions.hashCode();
10201069 result = 31 * result + jvmArgs.hashCode();
10211070 result = 31 * result + cassandraConfiguration.hashCode();
modified driver-core/src/test/java/com/datastax/driver/core/CCMTestsSupport.java +16 −4
@@ -271,12 +271,12 @@
271271 }
272272
273273 @SuppressWarnings("SimplifiableIfStatement")
274- private boolean dse() {
274+ private Boolean dse() {
275275 for (CCMConfig ann : annotations) {
276276 if (ann != null && ann.dse().length > 0)
277277 return ann.dse()[0];
278278 }
279- return false;
279+ return null;
280280 }
281281
282282 @SuppressWarnings("SimplifiableIfStatement")
@@ -430,8 +430,14 @@
430430 }
431431 if (version() != null)
432432 ccmBuilder.withVersion(version());
433- if (dse())
434- ccmBuilder.withDSE();
433+ Boolean dse = dse();
434+ if (dse != null) {
435+ if (dse) {
436+ ccmBuilder.withDSE();
437+ } else {
438+ ccmBuilder.withoutDSE();
439+ }
440+ }
435441 if (ssl())
436442 ccmBuilder.withSSL();
437443 if (auth())
@@ -913,6 +919,12 @@
913919 }
914920 LOGGER.debug("Using {}", ccm);
915921 }
922+
923+ // Check to ensure binary protocol is listening before proceeding.
924+ for (InetSocketAddress node : getContactPointsWithPorts()) {
925+ LOGGER.debug("Waiting for binary protocol to show up for {}", node);
926+ TestUtils.waitUntilPortIsUp(node);
927+ }
916928 }
917929
918930 protected void initTestCluster(Object testInstance) throws Exception {
modified driver-core/src/test/java/com/datastax/driver/core/HostMetadataIntegrationTest.java +5 −6
@@ -15,6 +15,7 @@
1515 */
1616 package com.datastax.driver.core;
1717
18+import com.datastax.driver.core.utils.DseVersion;
1819 import org.apache.log4j.Level;
1920 import org.apache.log4j.Logger;
2021 import org.testng.annotations.Test;
@@ -35,24 +36,22 @@
3536 * This test is disabled as running DSE with workloads is intensive and has unreliable results
3637 * when running CCM with multiple workloads.
3738 * <p/>
38- * FIXME: this test is currently disabled because nodes with specific workload
39- * do not seem to come up within the allocated time.
4039 *
4140 * @test_category host:metadata
42- * @jira_ticket JAVA1042
41+ * @jira_ticket JAVA-1042
4342 * @see HostMetadataIntegrationTest#should_parse_dse_workload_and_version_if_available()
4443 */
45- @Test(groups = "long", enabled = false)
44+ @Test(groups = "long")
45+ @DseVersion(major = 5.0)
4646 public void test_mixed_dse_workload() {
4747 CCMBridge.Builder builder = CCMBridge.builder()
4848 .withNodes(3)
4949 .withDSE()
50- .withVersion("4.8.3")
5150 .withWorkload(2, solr)
5251 .withWorkload(3, spark);
5352 CCMAccess ccm = CCMCache.get(builder);
5453
55- VersionNumber version = VersionNumber.parse("4.8.3");
54+ VersionNumber version = VersionNumber.parse(CCMBridge.getDSEVersion());
5655
5756 Cluster cluster = Cluster.builder()
5857 .addContactPoints(ccm.addressOfNode(1).getAddress())
modified driver-core/src/test/java/com/datastax/driver/core/ProtocolV1Test.java +1 −1
@@ -25,7 +25,7 @@
2525 /**
2626 * Tests targeting protocol v1 specifically.
2727 */
28-@CCMConfig(version = "1.2.19")
28+@CCMConfig(version = "1.2.19", dse = false)
2929 public class ProtocolV1Test extends CCMTestsSupport {
3030
3131 @Override
modified driver-core/src/test/java/com/datastax/driver/core/RecommissionedNodeTest.java +1 −0
@@ -157,6 +157,7 @@
157157 .withStoragePort(mainCcm.getStoragePort())
158158 .withThriftPort(mainCcm.getThriftPort())
159159 .withBinaryPort(mainCcm.getBinaryPort())
160+ .withoutDSE()
160161 .withVersion("1.2.19");
161162 otherCcm = CCMCache.get(otherCcmBuilder);
162163 otherCcm.waitForUp(1);