Elffuss BraidHub

kikocis/java-driver public

Add 'CassandraVersion' annotation for skipping test based on version.

Presence of a @CassandraVersion annotation on a Test Class or Method
will cause validation against cassandra.version and skip tests if they
do not meet the criteria.
Changeseta2da54e3138595d0331dad493f83dce884219722813337238b1d940dc29bcadd
AuthorAndrew Tolbert <andrew.tolbert@datastax.com> · 2015-02-04 19:55 -06:00
CommitterAndrew Tolbert <andrew.tolbert@datastax.com> · 2015-02-13 07:25 -06:00
Parents9c550af6c9cb

Browse the files at this changeset

8 files changed

modified driver-core/src/test/java/com/datastax/driver/core/BatchStatementTest.java +4 −5
@@ -20,12 +20,12 @@
2020
2121 import org.testng.annotations.Test;
2222
23-import com.datastax.driver.core.exceptions.UnsupportedFeatureException;
24-
25-import static com.datastax.driver.core.TestUtils.versionCheck;
2623 import static org.testng.Assert.assertEquals;
2724 import static org.testng.Assert.assertTrue;
2825
26+import com.datastax.driver.core.exceptions.UnsupportedFeatureException;
27+import com.datastax.driver.core.utils.CassandraVersion;
28+
2929 public class BatchStatementTest extends CCMBridge.PerClassSingleNodeCluster {
3030
3131 @Override
@@ -80,9 +80,8 @@
8080 }
8181
8282 @Test(groups = "short")
83+ @CassandraVersion(major=2.0, minor=9, description="This will only work with C* 2.0.9 (CASSANDRA-7337)")
8384 public void casBatchTest() throws Throwable {
84- versionCheck(2.0, 9, "This will only work with C* 2.0.9 (CASSANDRA-7337)");
85-
8685 try {
8786 PreparedStatement st = session.prepare("INSERT INTO test (k, v) VALUES (?, ?) IF NOT EXISTS");
8887
modified driver-core/src/test/java/com/datastax/driver/core/ConditionalUpdateTest.java +3 −0
@@ -6,9 +6,12 @@
66 import org.testng.annotations.Test;
77 import static org.testng.Assert.*;
88
9+import com.datastax.driver.core.utils.CassandraVersion;
10+
911 /**
1012 * Test {@link ResultSet#wasApplied()} for conditional updates.
1113 */
14+@CassandraVersion(major=2.0, description="Conditional Updates requires 2.0+.")
1215 public class ConditionalUpdateTest extends CCMBridge.PerClassSingleNodeCluster {
1316
1417 @Override
modified driver-core/src/test/java/com/datastax/driver/core/DataTypeTest.java +2 −2
@@ -26,7 +26,7 @@
2626 import static org.testng.Assert.*;
2727
2828 import com.datastax.driver.core.exceptions.InvalidTypeException;
29-
29+import com.datastax.driver.core.utils.CassandraVersion;
3030
3131 /**
3232 * Tests DataType class to ensure data sent in is the same as data received
@@ -517,8 +517,8 @@
517517 }
518518
519519 @Test(groups = "short")
520+ @CassandraVersion(major=2.0, minor=0, description="This feature requires protocol v2")
520521 public void primitiveInsertWithValueTest() throws Throwable {
521- TestUtils.versionCheck(2.0, 0, "This feature requires protocol v2");
522522 for (DataType dt : DataType.allPrimitiveTypes()) {
523523 if (exclude(dt))
524524 continue;
modified driver-core/src/test/java/com/datastax/driver/core/LargeDataTest.java +4 −2
@@ -23,6 +23,8 @@
2323
2424 import com.datastax.driver.core.querybuilder.Batch;
2525 import com.datastax.driver.core.querybuilder.Insert;
26+import com.datastax.driver.core.utils.CassandraVersion;
27+
2628 import static com.datastax.driver.core.TestUtils.CREATE_KEYSPACE_SIMPLE_FORMAT;
2729 import static com.datastax.driver.core.querybuilder.QueryBuilder.*;
2830
@@ -180,8 +182,8 @@
180182 * @throws Throwable
181183 */
182184 @Test(groups = "long")
185+ @CassandraVersion(major=2.0, minor=0, description="< 2.0 is skipped as 1.2 does not handle reading wide rows well.")
183186 public void wideRows() throws Throwable {
184- TestUtils.versionCheck(2, 0, "< 2.0 is skipped as 1.2 does not handle reading wide rows well.");
185187 Cluster.Builder builder = Cluster.builder();
186188 CCMBridge.CCMCluster c = CCMBridge.buildCluster(1, builder);
187189
@@ -204,8 +206,8 @@
204206 * @throws Throwable
205207 */
206208 @Test(groups = "short")
209+ @CassandraVersion(major=2.0, minor=0, description="< 2.0 is skipped as 1.2 does not handle large batches well.")
207210 public void wideBatchRows() throws Throwable {
208- TestUtils.versionCheck(2, 0, "< 2.0 is skipped as 1.2 does not handle large batches well.");
209211 Cluster.Builder builder = Cluster.builder();
210212 CCMBridge.CCMCluster c = CCMBridge.buildCluster(1, builder);
211213
modified driver-core/src/test/java/com/datastax/driver/core/TestListener.java +32 −4
@@ -15,12 +15,16 @@
1515 */
1616 package com.datastax.driver.core;
1717
18-import org.testng.ITestResult;
19-import org.testng.TestListenerAdapter;
20-
18+import org.testng.*;
19+import org.testng.internal.ConstructorOrMethod;
20+
21+import java.lang.annotation.Annotation;
22+import java.lang.reflect.Method;
2123 import java.util.concurrent.TimeUnit;
2224
23-public class TestListener extends TestListenerAdapter {
25+import com.datastax.driver.core.utils.CassandraVersion;
26+
27+public class TestListener extends TestListenerAdapter implements IInvokedMethodListener {
2428
2529 private long start_time = System.nanoTime();
2630 private int test_index = 0;
@@ -78,4 +82,28 @@
7882 + ':' + (minutes < 10 ? "0" : "") + minutes
7983 + ':' + (seconds< 10 ? "0" : "") + seconds);
8084 }
85+
86+ @Override public void beforeInvocation(IInvokedMethod testMethod, ITestResult testResult) {
87+ // Check to see if the class or method is annotated with 'CassandraVersion', if so ensure the
88+ // version we are testing with meets the requirement, if not a SkipException is thrown
89+ // and this test is skipped.
90+ ITestNGMethod testNgMethod = testResult.getMethod();
91+ ConstructorOrMethod constructorOrMethod = testNgMethod.getConstructorOrMethod();
92+
93+ Class<?> clazz = testNgMethod.getInstance().getClass();
94+ if(clazz != null && clazz.isAnnotationPresent(CassandraVersion.class)) {
95+ CassandraVersion cassandraVersion = clazz.getAnnotation(CassandraVersion.class);
96+ TestUtils.versionCheck(cassandraVersion.major(), cassandraVersion.minor(), cassandraVersion.description());
97+ }
98+
99+ Method method = constructorOrMethod.getMethod();
100+ if(method != null && method.isAnnotationPresent(CassandraVersion.class)) {
101+ CassandraVersion cassandraVersion = method.getAnnotation(CassandraVersion.class);
102+ TestUtils.versionCheck(cassandraVersion.major(), cassandraVersion.minor(), cassandraVersion.description());
103+ }
104+ }
105+
106+ @Override public void afterInvocation(IInvokedMethod testMethod, ITestResult testResult) {
107+ // Do nothing
108+ }
81109 }
modified driver-core/src/test/java/com/datastax/driver/core/TestUtils.java +1 −1
@@ -374,7 +374,7 @@
374374 int minor = Integer.parseInt(versionArray[2]);
375375
376376 if (major < majorCheck || (major == majorCheck && minor < minorCheck)) {
377- throw new SkipException(skipString);
377+ throw new SkipException("Version >= " + majorCheck + "." + minorCheck + " required. Description: " + skipString);
378378 }
379379 }
380380
modified driver-core/src/test/java/com/datastax/driver/core/querybuilder/QueryBuilderITest.java +4 −1
@@ -25,6 +25,8 @@
2525
2626 import com.datastax.driver.core.*;
2727 import com.datastax.driver.core.exceptions.SyntaxError;
28+import com.datastax.driver.core.utils.CassandraVersion;
29+
2830 import static com.datastax.driver.core.querybuilder.QueryBuilder.*;
2931
3032 public class QueryBuilderITest extends CCMBridge.PerClassSingleNodeCluster {
@@ -206,7 +208,8 @@
206208 }
207209
208210 @Test(groups = "short")
209- public void conditionalDeletesTest() throws Exception {
211+ @CassandraVersion(major=2.0, minor=7, description="DELETE..IF EXISTS only supported in 2.0.7+ (CASSANDRA-5708)")
212+ public void conditionalDeletesTest() throws Exception {
210213 session.execute("INSERT INTO ks.test_int (k, a, b) VALUES (1, 1, 1)");
211214
212215 Statement delete;
added driver-core/src/test/java/com/datastax/driver/core/utils/CassandraVersion.java +28 −0
@@ -0,0 +1,28 @@
1+package com.datastax.driver.core.utils;
2+
3+import java.lang.annotation.Retention;
4+import java.lang.annotation.RetentionPolicy;
5+
6+/**
7+ * <p>Annotation for a Class or Method that defines a Cassandra Version requirement. If the cassandra verison in used
8+ * does not meet the version requirement, the test is skipped.</p>
9+ *
10+ * @see {@link com.datastax.driver.core.TestListener#beforeInvocation(org.testng.IInvokedMethod, org.testng.ITestResult)} for usage.
11+ */
12+@Retention(RetentionPolicy.RUNTIME)
13+public @interface CassandraVersion {
14+ /**
15+ * @return The major version required to execute this test, i.e. "2.0"
16+ */
17+ public double major();
18+
19+ /**
20+ * @return The minor version required to execute this test, i.e. "0"
21+ */
22+ public int minor() default 0;
23+
24+ /**
25+ * @return The description returned if this version requirement is not met.
26+ */
27+ public String description() default "Does not meet minimum version requirement.";
28+}