From 81ae2a187d6def5abfb95cf9ab41ef43739b9404 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20B=C4=85czkowski?= Date: Sat, 9 Nov 2024 02:31:25 +0100 Subject: [PATCH 1/2] Add ScyllaVersion annotation Adds annotation that allows specifying a range of relevant Scylla versions for the tests. --- .../datastax/driver/core/TestListener.java | 58 +++++++++++++++++++ .../driver/core/utils/ScyllaVersion.java | 32 ++++++++++ 2 files changed, 90 insertions(+) create mode 100644 driver-core/src/test/java/com/datastax/driver/core/utils/ScyllaVersion.java diff --git a/driver-core/src/test/java/com/datastax/driver/core/TestListener.java b/driver-core/src/test/java/com/datastax/driver/core/TestListener.java index 210e4c9d929..2e8a8b8acf3 100644 --- a/driver-core/src/test/java/com/datastax/driver/core/TestListener.java +++ b/driver-core/src/test/java/com/datastax/driver/core/TestListener.java @@ -25,8 +25,10 @@ import com.datastax.driver.core.utils.DseVersion; import com.datastax.driver.core.utils.ScyllaOnly; import com.datastax.driver.core.utils.ScyllaSkip; +import com.datastax.driver.core.utils.ScyllaVersion; import java.lang.reflect.AnnotatedElement; import java.lang.reflect.Method; +import java.util.Objects; import java.util.concurrent.TimeUnit; import org.testng.IInvokedMethod; import org.testng.IInvokedMethodListener; @@ -144,6 +146,11 @@ private boolean scanAnnotatedElement(AnnotatedElement element) { dseVersionCheck(dseVersion); foundAnnotation = true; } + if (element.isAnnotationPresent(ScyllaVersion.class)) { + ScyllaVersion scyllaVersion = element.getAnnotation(ScyllaVersion.class); + scyllaVersionCheck(scyllaVersion); + foundAnnotation = true; + } return foundAnnotation; } @@ -172,6 +179,57 @@ private static void dseVersionCheck(DseVersion version) { } } + private static void scyllaVersionCheck(ScyllaVersion annotation) { + VersionNumber configuredVersion = CCMBridge.getGlobalScyllaVersion(); + if (configuredVersion == null) { + throw new SkipException( + "Skipping test because provided Scylla version is null and the test requires Scylla."); + } + boolean isEnterprise = String.valueOf(configuredVersion.getMajor()).matches("\\d{4}"); + + if (isEnterprise) { + if (!annotation.minEnterprise().isEmpty()) { + VersionNumber minVersion = + Objects.requireNonNull(VersionNumber.parse(annotation.minEnterprise())); + if (minVersion.compareTo(configuredVersion) > 0) { + throw new SkipException( + String.format( + "Version >= %s required, but found %s. Justification: %s", + minVersion, configuredVersion, annotation.description())); + } + } + if (!annotation.maxEnterprise().isEmpty()) { + VersionNumber maxVersion = + Objects.requireNonNull(VersionNumber.parse(annotation.maxEnterprise())); + if (maxVersion.compareTo(configuredVersion) <= 0) { + throw new SkipException( + String.format( + "Version < %s required, but found %s. Justification: %s", + maxVersion, configuredVersion, annotation.description())); + } + } + } else { + if (!annotation.minOSS().isEmpty()) { + VersionNumber minVersion = Objects.requireNonNull(VersionNumber.parse(annotation.minOSS())); + if (minVersion.compareTo(configuredVersion) > 0) { + throw new SkipException( + String.format( + "Version >= %s required, but found %s. Justification: %s", + minVersion, configuredVersion, annotation.description())); + } + } + if (!annotation.maxOSS().isEmpty()) { + VersionNumber maxVersion = Objects.requireNonNull(VersionNumber.parse(annotation.maxOSS())); + if (maxVersion.compareTo(configuredVersion) <= 0) { + throw new SkipException( + String.format( + "Version < %s required, but found %s. Justification: %s", + maxVersion, configuredVersion, annotation.description())); + } + } + } + } + private static void scyllaSkipCheck() { if (CCMBridge.getGlobalScyllaVersion() != null) { throw new SkipException("Skipping test because it is disabled for Scylla cluster."); diff --git a/driver-core/src/test/java/com/datastax/driver/core/utils/ScyllaVersion.java b/driver-core/src/test/java/com/datastax/driver/core/utils/ScyllaVersion.java new file mode 100644 index 00000000000..d59eea72e08 --- /dev/null +++ b/driver-core/src/test/java/com/datastax/driver/core/utils/ScyllaVersion.java @@ -0,0 +1,32 @@ +package com.datastax.driver.core.utils; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +/** + * Annotation for a Class or Method that defines a Scylla Version requirement. If the Scylla version + * in use does not meet the version requirement, the test is skipped. + */ +@Retention(RetentionPolicy.RUNTIME) +public @interface ScyllaVersion { + /** @return The minimum Enterprise version required to execute this test, i.e. "2020.1.13" */ + String minEnterprise() default ""; + + /** + * @return the maximum exclusive Enterprise version allowed to execute this test, i.e. "2021.1.12" + * means only tests < "2021.1.12" may execute this test. + */ + String maxEnterprise() default ""; + + /** @return The minimum OSS version required to execute this test, i.e. "4.5.6" */ + String minOSS() default ""; + + /** + * @return the maximum exclusive OSS version allowed to execute this test, i.e. "5.0.0" means only + * tests < "5.0.0" may execute this test. + */ + String maxOSS() default ""; + + /** @return The description returned if this version requirement is not met. */ + String description() default "Does not meet Scylla version requirement."; +} From 57c72f8df2398c5af54385246f908b42ce3aec5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20B=C4=85czkowski?= Date: Sat, 9 Nov 2024 02:37:01 +0100 Subject: [PATCH 2/2] Reenable TabletsIT --- .../src/test/java/com/datastax/driver/core/TabletsIT.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/driver-core/src/test/java/com/datastax/driver/core/TabletsIT.java b/driver-core/src/test/java/com/datastax/driver/core/TabletsIT.java index 4fda898a225..60d4a0da793 100644 --- a/driver-core/src/test/java/com/datastax/driver/core/TabletsIT.java +++ b/driver-core/src/test/java/com/datastax/driver/core/TabletsIT.java @@ -4,7 +4,7 @@ import com.datastax.driver.core.exceptions.SyntaxError; import com.datastax.driver.core.utils.ScyllaOnly; -import com.datastax.driver.core.utils.ScyllaSkip; +import com.datastax.driver.core.utils.ScyllaVersion; import java.nio.ByteBuffer; import java.util.Map; import org.testng.Assert; @@ -17,7 +17,7 @@ "--experimental-features=tablets" }) @ScyllaOnly -@ScyllaSkip // There is no released version with tablets-routing-v1 currently +@ScyllaVersion(minOSS = "6.0.0", minEnterprise = "2024.2", description = "Needs to support tablets") public class TabletsIT extends CCMTestsSupport { private static final int INITIAL_TABLETS = 32;