Skip to content

Commit 2a4c52a

Browse files
Bouncheckavelanarius
authored andcommitted
Add ScyllaRequirement annotation and apply it
Adds new annotation. Allows for both OSS and Enterprise version requirements. Annotates some tests with it.
1 parent c30f3d7 commit 2a4c52a

File tree

7 files changed

+163
-6
lines changed

7 files changed

+163
-6
lines changed

integration-tests/src/test/java/com/datastax/oss/driver/core/cql/PreparedStatementIT.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import com.datastax.oss.driver.api.core.type.DataTypes;
4343
import com.datastax.oss.driver.api.testinfra.CassandraRequirement;
4444
import com.datastax.oss.driver.api.testinfra.CassandraSkip;
45+
import com.datastax.oss.driver.api.testinfra.ScyllaRequirement;
4546
import com.datastax.oss.driver.api.testinfra.ScyllaSkip;
4647
import com.datastax.oss.driver.api.testinfra.ccm.CcmRule;
4748
import com.datastax.oss.driver.api.testinfra.session.SessionRule;
@@ -477,6 +478,10 @@ public void should_infer_routing_information_when_partition_key_is_bound() {
477478

478479
@Test
479480
@CassandraSkip // Functionality only available in Scylla
481+
@ScyllaRequirement(
482+
minEnterprise = "2021.0.0",
483+
minOSS = "4.3.rc0",
484+
description = "Requires LWT_ADD_METADATA_MARK extension")
480485
public void scylla_should_recognize_prepared_lwt_query() {
481486
CqlSession session = sessionRule.session();
482487
PreparedStatement statementNonLWT =

integration-tests/src/test/java/com/datastax/oss/driver/core/loadbalancing/LWTLoadBalancingIT.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import com.datastax.oss.driver.api.core.metadata.Node;
3333
import com.datastax.oss.driver.api.core.metadata.TokenMap;
3434
import com.datastax.oss.driver.api.core.type.codec.TypeCodecs;
35+
import com.datastax.oss.driver.api.testinfra.ScyllaRequirement;
3536
import com.datastax.oss.driver.api.testinfra.ccm.CcmBridge;
3637
import com.datastax.oss.driver.api.testinfra.ccm.CustomCcmRule;
3738
import com.datastax.oss.driver.api.testinfra.session.SessionRule;
@@ -45,6 +46,10 @@
4546
import org.junit.rules.RuleChain;
4647
import org.junit.rules.TestRule;
4748

49+
@ScyllaRequirement(
50+
minEnterprise = "2021.0.0",
51+
minOSS = "4.3.rc0",
52+
description = "Requires LWT_ADD_METADATA_MARK extension")
4853
public class LWTLoadBalancingIT {
4954
private static final CustomCcmRule CCM_RULE = CustomCcmRule.builder().withNodes(3).build();
5055

@@ -89,6 +94,7 @@ public void should_use_only_one_node_when_lwt_detected() {
8994
// Sanity check for the previous test - non-LWT queries should
9095
// not always be sent to same node
9196
public void should_not_use_only_one_node_when_non_lwt() {
97+
assumeTrue(CcmBridge.SCYLLA_ENABLEMENT);
9298
CqlSession session = SESSION_RULE.session();
9399
int pk = 1234;
94100
PreparedStatement statement = session.prepare("INSERT INTO foo (pk, ck, v) VALUES (?, ?, ?)");

osgi-tests/src/test/java/com/datastax/oss/driver/internal/osgi/support/CcmPaxExam.java

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import com.datastax.oss.driver.api.core.Version;
2121
import com.datastax.oss.driver.api.testinfra.CassandraRequirement;
2222
import com.datastax.oss.driver.api.testinfra.DseRequirement;
23+
import com.datastax.oss.driver.api.testinfra.ScyllaRequirement;
24+
import com.datastax.oss.driver.api.testinfra.ccm.CcmBridge;
2325
import java.util.Objects;
2426
import java.util.Optional;
2527
import org.junit.AssumptionViolatedException;
@@ -83,6 +85,53 @@ public void run(RunNotifier notifier) {
8385
}
8486
}
8587
}
88+
ScyllaRequirement scyllaRequirement = description.getAnnotation(ScyllaRequirement.class);
89+
if (scyllaRequirement != null) {
90+
Optional<Version> scyllaVersionOption = CCM_BRIDGE.getScyllaVersion();
91+
if (!scyllaVersionOption.isPresent()) {
92+
notifier.fireTestAssumptionFailed(
93+
new Failure(
94+
description,
95+
new AssumptionViolatedException("Test Requires Scylla but it is not configured.")));
96+
return;
97+
}
98+
Version scyllaVersion = scyllaVersionOption.get();
99+
if (CcmBridge.SCYLLA_ENTERPRISE) {
100+
if (!scyllaRequirement.minEnterprise().isEmpty()) {
101+
Version minVersion =
102+
Objects.requireNonNull(Version.parse(scyllaRequirement.minEnterprise()));
103+
if (minVersion.compareTo(scyllaVersion) > 0) {
104+
fireRequirementsNotMet(
105+
notifier, description, scyllaRequirement.minEnterprise(), false, false);
106+
return;
107+
}
108+
}
109+
if (!scyllaRequirement.maxEnterprise().isEmpty()) {
110+
Version maxVersion =
111+
Objects.requireNonNull(Version.parse(scyllaRequirement.maxEnterprise()));
112+
if (maxVersion.compareTo(scyllaVersion) <= 0) {
113+
fireRequirementsNotMet(
114+
notifier, description, scyllaRequirement.maxEnterprise(), true, false);
115+
return;
116+
}
117+
}
118+
} else {
119+
if (!scyllaRequirement.minOSS().isEmpty()) {
120+
Version minVersion = Objects.requireNonNull(Version.parse(scyllaRequirement.minOSS()));
121+
if (minVersion.compareTo(scyllaVersion) > 0) {
122+
fireRequirementsNotMet(notifier, description, scyllaRequirement.minOSS(), false, false);
123+
return;
124+
}
125+
}
126+
if (!scyllaRequirement.maxOSS().isEmpty()) {
127+
Version maxVersion = Objects.requireNonNull(Version.parse(scyllaRequirement.maxOSS()));
128+
if (maxVersion.compareTo(CcmBridge.VERSION) <= 0) {
129+
fireRequirementsNotMet(notifier, description, scyllaRequirement.maxOSS(), true, false);
130+
return;
131+
}
132+
}
133+
}
134+
}
86135
super.run(notifier);
87136
}
88137

@@ -97,9 +146,13 @@ private void fireRequirementsNotMet(
97146
String.format(
98147
"Test requires %s %s %s but %s is configured. Description: %s",
99148
lessThan ? "less than" : "at least",
100-
dse ? "DSE" : "C*",
149+
dse ? "DSE" : (CcmBridge.SCYLLA_ENABLEMENT ? "SCYLLA" : "C*"),
101150
requirement,
102-
dse ? CCM_BRIDGE.getDseVersion().orElse(null) : CCM_BRIDGE.getCassandraVersion(),
151+
dse
152+
? CCM_BRIDGE.getDseVersion().orElse(null)
153+
: (CcmBridge.SCYLLA_ENABLEMENT
154+
? CCM_BRIDGE.getScyllaVersion().orElse(null)
155+
: CCM_BRIDGE.getCassandraVersion()),
103156
description));
104157
notifier.fireTestAssumptionFailed(new Failure(description, e));
105158
}

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
<version>${netty.version}</version>
105105
</dependency>
106106
<dependency>
107-
<!-- Only for integration tests, use the shaded JAR for production code -->
107+
<!-- Only for integration tests, use the shaded JAR for production code. -->
108108
<groupId>com.google.guava</groupId>
109109
<artifactId>guava</artifactId>
110110
<version>25.1-jre</version>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.datastax.oss.driver.api.testinfra;
2+
3+
import java.lang.annotation.Retention;
4+
import java.lang.annotation.RetentionPolicy;
5+
6+
/**
7+
* Annotation for a Class or Method that defines a Scylla Version requirement. If the Scylla version
8+
* in use does not meet the version requirement, the test is skipped.
9+
*/
10+
@Retention(RetentionPolicy.RUNTIME)
11+
public @interface ScyllaRequirement {
12+
/** @return The minimum Enterprise version required to execute this test, i.e. "2020.1.13" */
13+
String minEnterprise() default "";
14+
15+
/**
16+
* @return the maximum exclusive Enterprise version allowed to execute this test, i.e. "2021.1.12"
17+
* means only tests &lt; "2021.1.12" may execute this test.
18+
*/
19+
String maxEnterprise() default "";
20+
21+
/** @return The minimum OSS version required to execute this test, i.e. "4.5.6" */
22+
String minOSS() default "";
23+
24+
/**
25+
* @return the maximum exclusive OSS version allowed to execute this test, i.e. "5.0.0" means only
26+
* tests &lt; "5.0.0" may execute this test.
27+
*/
28+
String maxOSS() default "";
29+
30+
/** @return The description returned if this version requirement is not met. */
31+
String description() default "Does not meet Scylla version requirement.";
32+
}

test-infra/src/main/java/com/datastax/oss/driver/api/testinfra/ccm/BaseCcmRule.java

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.datastax.oss.driver.api.core.ProtocolVersion;
2626
import com.datastax.oss.driver.api.core.Version;
2727
import com.datastax.oss.driver.api.testinfra.*;
28+
import java.util.Objects;
2829
import java.util.Optional;
2930
import org.junit.AssumptionViolatedException;
3031
import org.junit.runner.Description;
@@ -69,9 +70,13 @@ public void evaluate() {
6970
String.format(
7071
"Test requires %s %s %s but %s is configured. Description: %s",
7172
lessThan ? "less than" : "at least",
72-
dse ? "DSE" : "C*",
73+
dse ? "DSE" : (CcmBridge.SCYLLA_ENABLEMENT ? "SCYLLA" : "C*"),
7374
requirement,
74-
dse ? ccmBridge.getDseVersion().orElse(null) : ccmBridge.getCassandraVersion(),
75+
dse
76+
? ccmBridge.getDseVersion().orElse(null)
77+
: (CcmBridge.SCYLLA_ENABLEMENT
78+
? ccmBridge.getScyllaVersion().orElse(null)
79+
: ccmBridge.getCassandraVersion()),
7580
description));
7681
}
7782
};
@@ -163,6 +168,51 @@ public void evaluate() {
163168
}
164169
}
165170
}
171+
172+
ScyllaRequirement scyllaRequirement = description.getAnnotation(ScyllaRequirement.class);
173+
if (scyllaRequirement != null) {
174+
Optional<Version> scyllaVersionOption = ccmBridge.getScyllaVersion();
175+
if (!scyllaVersionOption.isPresent()) {
176+
return new Statement() {
177+
@Override
178+
public void evaluate() {
179+
throw new AssumptionViolatedException(
180+
"Test has Scylla version requirement, but CCMBridge is not configured for Scylla.");
181+
}
182+
};
183+
}
184+
Version scyllaVersion = scyllaVersionOption.get();
185+
if (CcmBridge.SCYLLA_ENTERPRISE) {
186+
if (!scyllaRequirement.minEnterprise().isEmpty()) {
187+
Version minVersion =
188+
Objects.requireNonNull(Version.parse(scyllaRequirement.minEnterprise()));
189+
if (minVersion.compareTo(scyllaVersion) > 0) {
190+
return buildErrorStatement(minVersion, scyllaRequirement.description(), false, false);
191+
}
192+
}
193+
if (!scyllaRequirement.maxEnterprise().isEmpty()) {
194+
Version maxVersion =
195+
Objects.requireNonNull(Version.parse(scyllaRequirement.maxEnterprise()));
196+
if (maxVersion.compareTo(scyllaVersion) <= 0) {
197+
return buildErrorStatement(maxVersion, scyllaRequirement.description(), true, false);
198+
}
199+
}
200+
} else {
201+
if (!scyllaRequirement.minOSS().isEmpty()) {
202+
Version minVersion = Objects.requireNonNull(Version.parse(scyllaRequirement.minOSS()));
203+
if (minVersion.compareTo(scyllaVersion) > 0) {
204+
return buildErrorStatement(minVersion, scyllaRequirement.description(), false, false);
205+
}
206+
}
207+
if (!scyllaRequirement.maxOSS().isEmpty()) {
208+
Version maxVersion = Objects.requireNonNull(Version.parse(scyllaRequirement.maxOSS()));
209+
if (maxVersion.compareTo(CcmBridge.VERSION) <= 0) {
210+
return buildErrorStatement(maxVersion, scyllaRequirement.description(), true, false);
211+
}
212+
}
213+
}
214+
}
215+
166216
return super.apply(base, description);
167217
}
168218

test-infra/src/main/java/com/datastax/oss/driver/api/testinfra/ccm/CcmBridge.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ public class CcmBridge implements AutoCloseable {
7070

7171
public static final Boolean SCYLLA_ENABLEMENT = Boolean.getBoolean("ccm.scylla");
7272

73+
public static final Boolean SCYLLA_ENTERPRISE =
74+
String.valueOf(VERSION.getMajor()).matches("\\d{4}");
75+
7376
public static final String CLUSTER_NAME = "ccm_1";
7477

7578
public static final String DEFAULT_CLIENT_TRUSTSTORE_PASSWORD = "fakePasswordForTests";
@@ -126,7 +129,7 @@ public class CcmBridge implements AutoCloseable {
126129
LOG.info("CCM Bridge configured with DSE version {}", VERSION);
127130
} else if (SCYLLA_ENABLEMENT) {
128131
LOG.info("CCM Bridge configured with Scylla version {}", VERSION);
129-
if (String.valueOf(VERSION.getMajor()).matches("\\d{4}")) {
132+
if (SCYLLA_ENTERPRISE) {
130133
envMap.put("SCYLLA_PRODUCT", "enterprise");
131134
}
132135
} else {
@@ -207,6 +210,14 @@ private static boolean isWindows() {
207210
return System.getProperty("os.name", "").toLowerCase(Locale.US).contains("win");
208211
}
209212

213+
public Optional<Version> getScyllaVersion() {
214+
return SCYLLA_ENABLEMENT ? Optional.of(VERSION) : Optional.empty();
215+
}
216+
217+
public Optional<String> getScyllaUnparsedVersion() {
218+
return SCYLLA_ENABLEMENT ? Optional.of(System.getProperty("ccm.version")) : Optional.empty();
219+
}
220+
210221
public Optional<Version> getDseVersion() {
211222
return DSE_ENABLEMENT ? Optional.of(VERSION) : Optional.empty();
212223
}

0 commit comments

Comments
 (0)