|
25 | 25 | import com.datastax.driver.core.utils.DseVersion;
|
26 | 26 | import com.datastax.driver.core.utils.ScyllaOnly;
|
27 | 27 | import com.datastax.driver.core.utils.ScyllaSkip;
|
| 28 | +import com.datastax.driver.core.utils.ScyllaVersion; |
28 | 29 | import java.lang.reflect.AnnotatedElement;
|
29 | 30 | import java.lang.reflect.Method;
|
| 31 | +import java.util.Objects; |
30 | 32 | import java.util.concurrent.TimeUnit;
|
31 | 33 | import org.testng.IInvokedMethod;
|
32 | 34 | import org.testng.IInvokedMethodListener;
|
@@ -144,6 +146,11 @@ private boolean scanAnnotatedElement(AnnotatedElement element) {
|
144 | 146 | dseVersionCheck(dseVersion);
|
145 | 147 | foundAnnotation = true;
|
146 | 148 | }
|
| 149 | + if (element.isAnnotationPresent(ScyllaVersion.class)) { |
| 150 | + ScyllaVersion scyllaVersion = element.getAnnotation(ScyllaVersion.class); |
| 151 | + scyllaVersionCheck(scyllaVersion); |
| 152 | + foundAnnotation = true; |
| 153 | + } |
147 | 154 | return foundAnnotation;
|
148 | 155 | }
|
149 | 156 |
|
@@ -172,6 +179,57 @@ private static void dseVersionCheck(DseVersion version) {
|
172 | 179 | }
|
173 | 180 | }
|
174 | 181 |
|
| 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 | + |
175 | 233 | private static void scyllaSkipCheck() {
|
176 | 234 | if (CCMBridge.getGlobalScyllaVersion() != null) {
|
177 | 235 | throw new SkipException("Skipping test because it is disabled for Scylla cluster.");
|
|
0 commit comments