kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | a2da54e3138595d0331dad493f83dce884219722813337238b1d940dc29bcadd |
|---|---|
| Author | Andrew Tolbert <andrew.tolbert@datastax.com> · 2015-02-04 19:55 -06:00 |
| Committer | Andrew Tolbert <andrew.tolbert@datastax.com> · 2015-02-13 07:25 -06:00 |
| Parents | 9c550af6c9cb |
8 files changed
modified driver-core/src/test/java/com/datastax/driver/core/BatchStatementTest.java +4 −5
| @@ -20,12 +20,12 @@ | ||
| 20 | 20 | |
| 21 | 21 | import org.testng.annotations.Test; |
| 22 | 22 | |
| 23 | -import com.datastax.driver.core.exceptions.UnsupportedFeatureException; | |
| 24 | - | |
| 25 | -import static com.datastax.driver.core.TestUtils.versionCheck; | |
| 26 | 23 | import static org.testng.Assert.assertEquals; |
| 27 | 24 | import static org.testng.Assert.assertTrue; |
| 28 | 25 | |
| 26 | +import com.datastax.driver.core.exceptions.UnsupportedFeatureException; | |
| 27 | +import com.datastax.driver.core.utils.CassandraVersion; | |
| 28 | + | |
| 29 | 29 | public class BatchStatementTest extends CCMBridge.PerClassSingleNodeCluster { |
| 30 | 30 | |
| 31 | 31 | @Override |
| @@ -80,9 +80,8 @@ | ||
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | @Test(groups = "short") |
| 83 | + @CassandraVersion(major=2.0, minor=9, description="This will only work with C* 2.0.9 (CASSANDRA-7337)") | |
| 83 | 84 | public void casBatchTest() throws Throwable { |
| 84 | - versionCheck(2.0, 9, "This will only work with C* 2.0.9 (CASSANDRA-7337)"); | |
| 85 | - | |
| 86 | 85 | try { |
| 87 | 86 | PreparedStatement st = session.prepare("INSERT INTO test (k, v) VALUES (?, ?) IF NOT EXISTS"); |
| 88 | 87 |
modified driver-core/src/test/java/com/datastax/driver/core/ConditionalUpdateTest.java +3 −0
| @@ -6,9 +6,12 @@ | ||
| 6 | 6 | import org.testng.annotations.Test; |
| 7 | 7 | import static org.testng.Assert.*; |
| 8 | 8 | |
| 9 | +import com.datastax.driver.core.utils.CassandraVersion; | |
| 10 | + | |
| 9 | 11 | /** |
| 10 | 12 | * Test {@link ResultSet#wasApplied()} for conditional updates. |
| 11 | 13 | */ |
| 14 | +@CassandraVersion(major=2.0, description="Conditional Updates requires 2.0+.") | |
| 12 | 15 | public class ConditionalUpdateTest extends CCMBridge.PerClassSingleNodeCluster { |
| 13 | 16 | |
| 14 | 17 | @Override |
modified driver-core/src/test/java/com/datastax/driver/core/DataTypeTest.java +2 −2
| @@ -26,7 +26,7 @@ | ||
| 26 | 26 | import static org.testng.Assert.*; |
| 27 | 27 | |
| 28 | 28 | import com.datastax.driver.core.exceptions.InvalidTypeException; |
| 29 | - | |
| 29 | +import com.datastax.driver.core.utils.CassandraVersion; | |
| 30 | 30 | |
| 31 | 31 | /** |
| 32 | 32 | * Tests DataType class to ensure data sent in is the same as data received |
| @@ -517,8 +517,8 @@ | ||
| 517 | 517 | } |
| 518 | 518 | |
| 519 | 519 | @Test(groups = "short") |
| 520 | + @CassandraVersion(major=2.0, minor=0, description="This feature requires protocol v2") | |
| 520 | 521 | public void primitiveInsertWithValueTest() throws Throwable { |
| 521 | - TestUtils.versionCheck(2.0, 0, "This feature requires protocol v2"); | |
| 522 | 522 | for (DataType dt : DataType.allPrimitiveTypes()) { |
| 523 | 523 | if (exclude(dt)) |
| 524 | 524 | continue; |
modified driver-core/src/test/java/com/datastax/driver/core/LargeDataTest.java +4 −2
| @@ -23,6 +23,8 @@ | ||
| 23 | 23 | |
| 24 | 24 | import com.datastax.driver.core.querybuilder.Batch; |
| 25 | 25 | import com.datastax.driver.core.querybuilder.Insert; |
| 26 | +import com.datastax.driver.core.utils.CassandraVersion; | |
| 27 | + | |
| 26 | 28 | import static com.datastax.driver.core.TestUtils.CREATE_KEYSPACE_SIMPLE_FORMAT; |
| 27 | 29 | import static com.datastax.driver.core.querybuilder.QueryBuilder.*; |
| 28 | 30 | |
| @@ -180,8 +182,8 @@ | ||
| 180 | 182 | * @throws Throwable |
| 181 | 183 | */ |
| 182 | 184 | @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.") | |
| 183 | 186 | public void wideRows() throws Throwable { |
| 184 | - TestUtils.versionCheck(2, 0, "< 2.0 is skipped as 1.2 does not handle reading wide rows well."); | |
| 185 | 187 | Cluster.Builder builder = Cluster.builder(); |
| 186 | 188 | CCMBridge.CCMCluster c = CCMBridge.buildCluster(1, builder); |
| 187 | 189 | |
| @@ -204,8 +206,8 @@ | ||
| 204 | 206 | * @throws Throwable |
| 205 | 207 | */ |
| 206 | 208 | @Test(groups = "short") |
| 209 | + @CassandraVersion(major=2.0, minor=0, description="< 2.0 is skipped as 1.2 does not handle large batches well.") | |
| 207 | 210 | public void wideBatchRows() throws Throwable { |
| 208 | - TestUtils.versionCheck(2, 0, "< 2.0 is skipped as 1.2 does not handle large batches well."); | |
| 209 | 211 | Cluster.Builder builder = Cluster.builder(); |
| 210 | 212 | CCMBridge.CCMCluster c = CCMBridge.buildCluster(1, builder); |
| 211 | 213 |
modified driver-core/src/test/java/com/datastax/driver/core/TestListener.java +32 −4
| @@ -15,12 +15,16 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 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; | |
| 21 | 23 | import java.util.concurrent.TimeUnit; |
| 22 | 24 | |
| 23 | -public class TestListener extends TestListenerAdapter { | |
| 25 | +import com.datastax.driver.core.utils.CassandraVersion; | |
| 26 | + | |
| 27 | +public class TestListener extends TestListenerAdapter implements IInvokedMethodListener { | |
| 24 | 28 | |
| 25 | 29 | private long start_time = System.nanoTime(); |
| 26 | 30 | private int test_index = 0; |
| @@ -78,4 +82,28 @@ | ||
| 78 | 82 | + ':' + (minutes < 10 ? "0" : "") + minutes |
| 79 | 83 | + ':' + (seconds< 10 ? "0" : "") + seconds); |
| 80 | 84 | } |
| 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 | + } | |
| 81 | 109 | } |
modified driver-core/src/test/java/com/datastax/driver/core/TestUtils.java +1 −1
| @@ -374,7 +374,7 @@ | ||
| 374 | 374 | int minor = Integer.parseInt(versionArray[2]); |
| 375 | 375 | |
| 376 | 376 | if (major < majorCheck || (major == majorCheck && minor < minorCheck)) { |
| 377 | - throw new SkipException(skipString); | |
| 377 | + throw new SkipException("Version >= " + majorCheck + "." + minorCheck + " required. Description: " + skipString); | |
| 378 | 378 | } |
| 379 | 379 | } |
| 380 | 380 |
modified driver-core/src/test/java/com/datastax/driver/core/querybuilder/QueryBuilderITest.java +4 −1
| @@ -25,6 +25,8 @@ | ||
| 25 | 25 | |
| 26 | 26 | import com.datastax.driver.core.*; |
| 27 | 27 | import com.datastax.driver.core.exceptions.SyntaxError; |
| 28 | +import com.datastax.driver.core.utils.CassandraVersion; | |
| 29 | + | |
| 28 | 30 | import static com.datastax.driver.core.querybuilder.QueryBuilder.*; |
| 29 | 31 | |
| 30 | 32 | public class QueryBuilderITest extends CCMBridge.PerClassSingleNodeCluster { |
| @@ -206,7 +208,8 @@ | ||
| 206 | 208 | } |
| 207 | 209 | |
| 208 | 210 | @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 { | |
| 210 | 213 | session.execute("INSERT INTO ks.test_int (k, a, b) VALUES (1, 1, 1)"); |
| 211 | 214 | |
| 212 | 215 | 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 | +} |