Skip to content

Commit 6abba76

Browse files
committed
Update ProtocolVersionRenegotiationTest to use global config
Since we run a test matrix in CI we can get full coverage of how the driver behaves when connecting to different C* versions collectively. This is quicker / more reliable than creating a different version cluster each time.
1 parent 26ca703 commit 6abba76

2 files changed

Lines changed: 33 additions & 16 deletions

File tree

driver-core/src/test/java/com/datastax/driver/core/ProtocolBetaVersionTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package com.datastax.driver.core;
1717

18+
import com.datastax.driver.core.utils.CassandraVersion;
1819
import org.testng.annotations.Test;
1920

2021
import static com.datastax.driver.core.ProtocolVersion.V4;
@@ -26,7 +27,7 @@
2627
* Tests for the new USE_BETA flag introduced in protocol v5
2728
* and Cassandra 3.10.
2829
*/
29-
@CCMConfig(version = "3.10")
30+
@CassandraVersion("3.10")
3031
public class ProtocolBetaVersionTest extends CCMTestsSupport {
3132

3233
/**

driver-core/src/test/java/com/datastax/driver/core/ProtocolVersionRenegotiationTest.java

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,42 +16,53 @@
1616
package com.datastax.driver.core;
1717

1818
import com.datastax.driver.core.exceptions.UnsupportedProtocolVersionException;
19+
import com.datastax.driver.core.utils.CassandraVersion;
20+
import org.testng.SkipException;
21+
import org.testng.annotations.BeforeMethod;
1922
import org.testng.annotations.Test;
2023

2124
import static com.datastax.driver.core.ProtocolVersion.*;
2225
import static org.assertj.core.api.Assertions.assertThat;
2326

24-
@CreateCCM(CreateCCM.TestMode.PER_METHOD)
2527
public class ProtocolVersionRenegotiationTest extends CCMTestsSupport {
2628

29+
private ProtocolVersion protocolVersion;
30+
31+
@BeforeMethod(groups = "short")
32+
public void setUp() {
33+
protocolVersion = ccm().getProtocolVersion();
34+
}
35+
2736
/**
2837
* @jira_ticket JAVA-1367
2938
*/
3039
@Test(groups = "short")
31-
@CCMConfig(version = "2.1.16", createCluster = false)
3240
public void should_succeed_when_version_provided_and_matches() throws Exception {
33-
Cluster cluster = connectWithVersion(V3);
34-
assertThat(actualProtocolVersion(cluster)).isEqualTo(V3);
41+
Cluster cluster = connectWithVersion(protocolVersion);
42+
assertThat(actualProtocolVersion(cluster)).isEqualTo(protocolVersion);
3543
}
3644

3745
/**
3846
* @jira_ticket JAVA-1367
3947
*/
4048
@Test(groups = "short")
41-
@CCMConfig(version = "3.6", createCluster = false)
42-
public void should_fail_when_version_provided_and_too_low_3_6() throws Exception {
49+
@CassandraVersion("3.0")
50+
public void should_fail_when_version_provided_and_too_low_less_than_3_8() throws Exception {
51+
if (ccm().getCassandraVersion().compareTo(VersionNumber.parse("3.8")) >= 0) {
52+
throw new SkipException("CASSANDRA-11464 (3.8+) uses the attempted protocol version");
53+
}
4354
UnsupportedProtocolVersionException e = connectWithUnsupportedVersion(V1);
4455
assertThat(e.getUnsupportedVersion()).isEqualTo(V1);
4556
// pre-CASSANDRA-11464: server replies with its own version
46-
assertThat(e.getServerVersion()).isEqualTo(V4);
57+
assertThat(e.getServerVersion()).isEqualTo(protocolVersion);
4758
}
4859

4960
/**
5061
* @jira_ticket JAVA-1367
5162
*/
5263
@Test(groups = "short")
53-
@CCMConfig(version = "3.10", createCluster = false)
54-
public void should_fail_when_version_provided_and_too_low_3_10() throws Exception {
64+
@CassandraVersion("3.8")
65+
public void should_fail_when_version_provided_and_too_low_3_8_plus() throws Exception {
5566
UnsupportedProtocolVersionException e = connectWithUnsupportedVersion(V1);
5667
assertThat(e.getUnsupportedVersion()).isEqualTo(V1);
5768
// post-CASSANDRA-11464: server replies with client's version
@@ -62,24 +73,26 @@ public void should_fail_when_version_provided_and_too_low_3_10() throws Exceptio
6273
* @jira_ticket JAVA-1367
6374
*/
6475
@Test(groups = "short")
65-
@CCMConfig(version = "1.2.19", createCluster = false)
6676
public void should_fail_when_version_provided_and_too_high() throws Exception {
77+
if (ccm().getCassandraVersion().compareTo(VersionNumber.parse("2.2")) >= 0) {
78+
throw new SkipException("Server supports protocol V4");
79+
}
6780
UnsupportedProtocolVersionException e = connectWithUnsupportedVersion(V4);
6881
assertThat(e.getUnsupportedVersion()).isEqualTo(V4);
6982
// pre-CASSANDRA-11464: server replies with its own version
70-
assertThat(e.getServerVersion()).isEqualTo(V1);
83+
assertThat(e.getServerVersion()).isEqualTo(protocolVersion);
7184
}
7285

7386
/**
7487
* @jira_ticket JAVA-1367
7588
*/
7689
@Test(groups = "short")
77-
@CCMConfig(version = "2.1.16", createCluster = false)
7890
public void should_fail_when_beta_allowed_and_too_high() throws Exception {
91+
if (ccm().getCassandraVersion().compareTo(VersionNumber.parse("3.10")) >= 0) {
92+
throw new SkipException("Server supports protocol protocol V5 beta");
93+
}
7994
UnsupportedProtocolVersionException e = connectWithUnsupportedBetaVersion();
8095
assertThat(e.getUnsupportedVersion()).isEqualTo(V5);
81-
// pre-CASSANDRA-11464: server replies with its own version
82-
assertThat(e.getServerVersion()).isEqualTo(V3);
8396
}
8497

8598
/**
@@ -88,8 +101,11 @@ public void should_fail_when_beta_allowed_and_too_high() throws Exception {
88101
@Test(groups = "short")
89102
@CCMConfig(version = "2.1.16", createCluster = false)
90103
public void should_negotiate_when_no_version_provided() throws Exception {
104+
if (protocolVersion.compareTo(ProtocolVersion.NEWEST_SUPPORTED) >= 0) {
105+
throw new SkipException("Server supports newest protocol version driver supports");
106+
}
91107
Cluster cluster = connectWithoutVersion();
92-
assertThat(actualProtocolVersion(cluster)).isEqualTo(V3);
108+
assertThat(actualProtocolVersion(cluster)).isEqualTo(protocolVersion);
93109
}
94110

95111
private UnsupportedProtocolVersionException connectWithUnsupportedVersion(ProtocolVersion version) {

0 commit comments

Comments
 (0)