Skip to content

Commit c044358

Browse files
authored
3.x: Reenable TabletsIT (#364)
* Add ScyllaVersion annotation Adds annotation that allows specifying a range of relevant Scylla versions for the tests. * Reenable TabletsIT
1 parent c2d7fb3 commit c044358

File tree

3 files changed

+92
-2
lines changed

3 files changed

+92
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import com.datastax.driver.core.exceptions.SyntaxError;
66
import com.datastax.driver.core.utils.ScyllaOnly;
7-
import com.datastax.driver.core.utils.ScyllaSkip;
7+
import com.datastax.driver.core.utils.ScyllaVersion;
88
import java.nio.ByteBuffer;
99
import java.util.Map;
1010
import org.testng.Assert;
@@ -17,7 +17,7 @@
1717
"--experimental-features=tablets"
1818
})
1919
@ScyllaOnly
20-
@ScyllaSkip // There is no released version with tablets-routing-v1 currently
20+
@ScyllaVersion(minOSS = "6.0.0", minEnterprise = "2024.2", description = "Needs to support tablets")
2121
public class TabletsIT extends CCMTestsSupport {
2222

2323
private static final int INITIAL_TABLETS = 32;

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

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@
2525
import com.datastax.driver.core.utils.DseVersion;
2626
import com.datastax.driver.core.utils.ScyllaOnly;
2727
import com.datastax.driver.core.utils.ScyllaSkip;
28+
import com.datastax.driver.core.utils.ScyllaVersion;
2829
import java.lang.reflect.AnnotatedElement;
2930
import java.lang.reflect.Method;
31+
import java.util.Objects;
3032
import java.util.concurrent.TimeUnit;
3133
import org.testng.IInvokedMethod;
3234
import org.testng.IInvokedMethodListener;
@@ -144,6 +146,11 @@ private boolean scanAnnotatedElement(AnnotatedElement element) {
144146
dseVersionCheck(dseVersion);
145147
foundAnnotation = true;
146148
}
149+
if (element.isAnnotationPresent(ScyllaVersion.class)) {
150+
ScyllaVersion scyllaVersion = element.getAnnotation(ScyllaVersion.class);
151+
scyllaVersionCheck(scyllaVersion);
152+
foundAnnotation = true;
153+
}
147154
return foundAnnotation;
148155
}
149156

@@ -172,6 +179,57 @@ private static void dseVersionCheck(DseVersion version) {
172179
}
173180
}
174181

182+
private static void scyllaVersionCheck(ScyllaVersion annotation) {
183+
VersionNumber configuredVersion = CCMBridge.getGlobalScyllaVersion();
184+
if (configuredVersion == null) {
185+
throw new SkipException(
186+
"Skipping test because provided Scylla version is null and the test requires Scylla.");
187+
}
188+
boolean isEnterprise = String.valueOf(configuredVersion.getMajor()).matches("\\d{4}");
189+
190+
if (isEnterprise) {
191+
if (!annotation.minEnterprise().isEmpty()) {
192+
VersionNumber minVersion =
193+
Objects.requireNonNull(VersionNumber.parse(annotation.minEnterprise()));
194+
if (minVersion.compareTo(configuredVersion) > 0) {
195+
throw new SkipException(
196+
String.format(
197+
"Version >= %s required, but found %s. Justification: %s",
198+
minVersion, configuredVersion, annotation.description()));
199+
}
200+
}
201+
if (!annotation.maxEnterprise().isEmpty()) {
202+
VersionNumber maxVersion =
203+
Objects.requireNonNull(VersionNumber.parse(annotation.maxEnterprise()));
204+
if (maxVersion.compareTo(configuredVersion) <= 0) {
205+
throw new SkipException(
206+
String.format(
207+
"Version < %s required, but found %s. Justification: %s",
208+
maxVersion, configuredVersion, annotation.description()));
209+
}
210+
}
211+
} else {
212+
if (!annotation.minOSS().isEmpty()) {
213+
VersionNumber minVersion = Objects.requireNonNull(VersionNumber.parse(annotation.minOSS()));
214+
if (minVersion.compareTo(configuredVersion) > 0) {
215+
throw new SkipException(
216+
String.format(
217+
"Version >= %s required, but found %s. Justification: %s",
218+
minVersion, configuredVersion, annotation.description()));
219+
}
220+
}
221+
if (!annotation.maxOSS().isEmpty()) {
222+
VersionNumber maxVersion = Objects.requireNonNull(VersionNumber.parse(annotation.maxOSS()));
223+
if (maxVersion.compareTo(configuredVersion) <= 0) {
224+
throw new SkipException(
225+
String.format(
226+
"Version < %s required, but found %s. Justification: %s",
227+
maxVersion, configuredVersion, annotation.description()));
228+
}
229+
}
230+
}
231+
}
232+
175233
private static void scyllaSkipCheck() {
176234
if (CCMBridge.getGlobalScyllaVersion() != null) {
177235
throw new SkipException("Skipping test because it is disabled for Scylla cluster.");
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.datastax.driver.core.utils;
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 ScyllaVersion {
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+
}

0 commit comments

Comments
 (0)