kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 1e0f61b0202a3145ca75c50a2c213fc4a7497aecebeea2440a75c8f629f81b65 |
|---|---|
| Author | Andrew Tolbert <andrew.tolbert@datastax.com> · 2015-03-03 14:47 -06:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2015-03-06 17:23 -08:00 |
| Parents | 4d9e392bb521 |
14 files changed
modified driver-core/src/test/java/com/datastax/driver/core/ControlConnectionTest.java +2 −2
| @@ -12,6 +12,7 @@ | ||
| 12 | 12 | import com.datastax.driver.core.policies.LoadBalancingPolicy; |
| 13 | 13 | import com.datastax.driver.core.policies.Policies; |
| 14 | 14 | import com.datastax.driver.core.policies.ReconnectionPolicy; |
| 15 | +import com.datastax.driver.core.utils.CassandraVersion; | |
| 15 | 16 | |
| 16 | 17 | public class ControlConnectionTest { |
| 17 | 18 | @Test(groups = "short") |
| @@ -73,9 +74,8 @@ | ||
| 73 | 74 | * Therefore we use two different driver instances in this test. |
| 74 | 75 | */ |
| 75 | 76 | @Test(groups = "short") |
| 77 | + @CassandraVersion(major=2.1) | |
| 76 | 78 | public void should_parse_UDT_definitions_when_using_default_protocol_version() { |
| 77 | - TestUtils.versionCheck(2.1, 0, "This will only work with C* 2.1.0"); | |
| 78 | - | |
| 79 | 79 | CCMBridge ccm = null; |
| 80 | 80 | Cluster cluster = null; |
| 81 | 81 |
modified driver-core/src/test/java/com/datastax/driver/core/DataTypeIntegrationTest.java +106 −7
| @@ -15,15 +15,10 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.util.Collection; | |
| 19 | -import java.util.List; | |
| 20 | -import java.util.Map; | |
| 18 | +import java.util.*; | |
| 21 | 19 | import java.util.concurrent.atomic.AtomicInteger; |
| 22 | 20 | |
| 23 | -import com.google.common.collect.ImmutableList; | |
| 24 | -import com.google.common.collect.ImmutableMap; | |
| 25 | -import com.google.common.collect.Lists; | |
| 26 | -import com.google.common.collect.Sets; | |
| 21 | +import com.google.common.collect.*; | |
| 27 | 22 | import org.slf4j.Logger; |
| 28 | 23 | import org.slf4j.LoggerFactory; |
| 29 | 24 | import org.testng.annotations.Test; |
| @@ -149,6 +144,7 @@ | ||
| 149 | 144 | tables.addAll(tablesWithCollectionsOfPrimitives()); |
| 150 | 145 | tables.addAll(tablesWithMapsOfPrimitives()); |
| 151 | 146 | tables.addAll(tablesWithNestedCollections()); |
| 147 | + tables.addAll(tablesWithRandomlyGeneratedNestedCollections()); | |
| 152 | 148 | |
| 153 | 149 | return ImmutableList.copyOf(tables); |
| 154 | 150 | } |
| @@ -220,4 +216,107 @@ | ||
| 220 | 216 | } |
| 221 | 217 | return tables; |
| 222 | 218 | } |
| 219 | + | |
| 220 | + private static Collection<? extends TestTable> tablesWithRandomlyGeneratedNestedCollections() { | |
| 221 | + List<TestTable> tables = Lists.newArrayList(); | |
| 222 | + | |
| 223 | + DataType nestedListType = buildNestedType(DataType.Name.LIST, 5); | |
| 224 | + DataType nestedSetType = buildNestedType(DataType.Name.SET, 5); | |
| 225 | + DataType nestedMapType = buildNestedType(DataType.Name.MAP, 5); | |
| 226 | + | |
| 227 | + tables.add(new TestTable(nestedListType, nestedObject(nestedListType), "2.1.3")); | |
| 228 | + tables.add(new TestTable(nestedSetType, nestedObject(nestedSetType), "2.1.3")); | |
| 229 | + tables.add(new TestTable(nestedMapType, nestedObject(nestedMapType), "2.1.3")); | |
| 230 | + return tables; | |
| 231 | + } | |
| 232 | + | |
| 233 | + /** | |
| 234 | + * Populate a nested collection based on the given type and it's arguments. | |
| 235 | + */ | |
| 236 | + public static Object nestedObject(DataType type) { | |
| 237 | + | |
| 238 | + int typeIdx = type.getTypeArguments().size() > 1 ? 1 : 0; | |
| 239 | + DataType argument = type.getTypeArguments().get(typeIdx); | |
| 240 | + boolean isAtBottom = !argument.isCollection(); | |
| 241 | + | |
| 242 | + if(isAtBottom) { | |
| 243 | + switch(type.getName()) { | |
| 244 | + case LIST: | |
| 245 | + return Lists.newArrayList(1, 2, 3); | |
| 246 | + case SET: | |
| 247 | + return Sets.newHashSet(1, 2, 3); | |
| 248 | + case MAP: | |
| 249 | + Map<Integer, Integer> map = Maps.newHashMap(); | |
| 250 | + map.put(1, 2); | |
| 251 | + map.put(3, 4); | |
| 252 | + map.put(5, 6); | |
| 253 | + return map; | |
| 254 | + } | |
| 255 | + } | |
| 256 | + else { | |
| 257 | + switch(type.getName()) { | |
| 258 | + case LIST: | |
| 259 | + List<Object> l = Lists.newArrayListWithExpectedSize(2); | |
| 260 | + for(int i = 0; i < 5; i++) { | |
| 261 | + l.add(nestedObject(argument)); | |
| 262 | + } | |
| 263 | + return l; | |
| 264 | + case SET: | |
| 265 | + Set<Object> s = Sets.newHashSet(); | |
| 266 | + for(int i = 0; i < 5; i++) { | |
| 267 | + s.add(nestedObject(argument)); | |
| 268 | + } | |
| 269 | + return s; | |
| 270 | + case MAP: | |
| 271 | + Map<Integer, Object> map = Maps.newHashMap(); | |
| 272 | + for(int i = 0; i < 5; i++) { | |
| 273 | + map.put(i, nestedObject(argument)); | |
| 274 | + } | |
| 275 | + return map; | |
| 276 | + } | |
| 277 | + } | |
| 278 | + return null; | |
| 279 | + } | |
| 280 | + | |
| 281 | + /** | |
| 282 | + * @param baseType The base type to use, one of SET, MAP, LIST. | |
| 283 | + * @param depth How many subcollections to generate. | |
| 284 | + * @return a DataType that is a nested collection with the given baseType with the | |
| 285 | + * given depth. | |
| 286 | + */ | |
| 287 | + public static DataType buildNestedType(DataType.Name baseType, int depth) { | |
| 288 | + Random r = new Random(); | |
| 289 | + DataType t = null; | |
| 290 | + | |
| 291 | + for (int i = 1; i <= depth; i++) { | |
| 292 | + int chooser = r.nextInt(3); | |
| 293 | + if(t == null) { | |
| 294 | + if(chooser == 0) { | |
| 295 | + t = DataType.frozenList(DataType.cint()); | |
| 296 | + } else if(chooser == 1) { | |
| 297 | + t = DataType.frozenSet(DataType.cint()); | |
| 298 | + } else { | |
| 299 | + t = DataType.frozenMap(DataType.cint(), DataType.cint()); | |
| 300 | + } | |
| 301 | + } else if(i == depth) { | |
| 302 | + switch(baseType) { | |
| 303 | + case LIST: | |
| 304 | + return DataType.list(t); | |
| 305 | + case SET: | |
| 306 | + return DataType.set(t); | |
| 307 | + case MAP: | |
| 308 | + return DataType.map(DataType.cint(), t); | |
| 309 | + } | |
| 310 | + } else { | |
| 311 | + if(chooser == 0) { | |
| 312 | + t = DataType.frozenList(t); | |
| 313 | + } else if(chooser == 1) { | |
| 314 | + t = DataType.frozenSet(t); | |
| 315 | + } else { | |
| 316 | + t = DataType.frozenMap(DataType.cint(), t); | |
| 317 | + } | |
| 318 | + } | |
| 319 | + } | |
| 320 | + return null; | |
| 321 | + } | |
| 223 | 322 | } |
modified driver-core/src/test/java/com/datastax/driver/core/QueryTimestampTest.java +2 −4
| @@ -11,18 +11,16 @@ | ||
| 11 | 11 | import com.datastax.driver.core.Cluster.Builder; |
| 12 | 12 | import com.datastax.driver.core.Metrics.Errors; |
| 13 | 13 | import com.datastax.driver.core.policies.DowngradingConsistencyRetryPolicy; |
| 14 | - | |
| 15 | -import static com.datastax.driver.core.TestUtils.versionCheck; | |
| 14 | +import com.datastax.driver.core.utils.CassandraVersion; | |
| 16 | 15 | |
| 17 | 16 | /** |
| 18 | 17 | * Tests the behavior of client-provided timestamps with protocol v3. |
| 19 | 18 | */ |
| 19 | +@CassandraVersion(major=2.1) | |
| 20 | 20 | public class QueryTimestampTest extends CCMBridge.PerClassSingleNodeCluster { |
| 21 | 21 | |
| 22 | 22 | @Override |
| 23 | 23 | protected Collection<String> getTableDefinitions() { |
| 24 | - versionCheck(2.1, 0, "This will only work with Cassandra 2.1.0"); | |
| 25 | - | |
| 26 | 24 | return Lists.newArrayList("CREATE TABLE foo (k int PRIMARY KEY, v int)"); |
| 27 | 25 | } |
| 28 | 26 |
modified driver-core/src/test/java/com/datastax/driver/core/SingleConnectionPoolTest.java +3 −2
| @@ -12,11 +12,12 @@ | ||
| 12 | 12 | |
| 13 | 13 | import static org.testng.Assert.fail; |
| 14 | 14 | |
| 15 | +import com.datastax.driver.core.utils.CassandraVersion; | |
| 16 | + | |
| 17 | +@CassandraVersion(major=2.1) | |
| 15 | 18 | public class SingleConnectionPoolTest extends CCMBridge.PerClassSingleNodeCluster { |
| 16 | 19 | @Override |
| 17 | 20 | protected Collection<String> getTableDefinitions() { |
| 18 | - TestUtils.versionCheck(2.1, 0, "This will only work with Cassandra 2.1.0+"); | |
| 19 | - | |
| 20 | 21 | return Lists.newArrayList(); |
| 21 | 22 | } |
| 22 | 23 |
modified driver-core/src/test/java/com/datastax/driver/core/TupleTest.java +3 −3
| @@ -25,15 +25,15 @@ | ||
| 25 | 25 | import static org.testng.Assert.assertEquals; |
| 26 | 26 | import static org.testng.Assert.fail; |
| 27 | 27 | |
| 28 | +import com.datastax.driver.core.utils.CassandraVersion; | |
| 29 | + | |
| 28 | 30 | import static com.datastax.driver.core.TestUtils.SIMPLE_KEYSPACE; |
| 29 | -import static com.datastax.driver.core.TestUtils.versionCheck; | |
| 30 | 31 | |
| 32 | +@CassandraVersion(major=2.1) | |
| 31 | 33 | public class TupleTest extends CCMBridge.PerClassSingleNodeCluster { |
| 32 | 34 | |
| 33 | 35 | @Override |
| 34 | 36 | protected Collection<String> getTableDefinitions() { |
| 35 | - versionCheck(2.1, 0, "This will only work with Cassandra 2.1.0"); | |
| 36 | - | |
| 37 | 37 | return Arrays.asList("CREATE TABLE t (k int PRIMARY KEY, v frozen<tuple<int, text, float>>)"); |
| 38 | 38 | } |
| 39 | 39 |
modified driver-core/src/test/java/com/datastax/driver/core/UserTypesTest.java +3 −3
| @@ -32,9 +32,11 @@ | ||
| 32 | 32 | import static org.testng.Assert.assertEquals; |
| 33 | 33 | |
| 34 | 34 | import static com.datastax.driver.core.Metadata.quote; |
| 35 | -import static com.datastax.driver.core.TestUtils.versionCheck; | |
| 36 | 35 | import static org.testng.Assert.assertNotEquals; |
| 37 | 36 | |
| 37 | +import com.datastax.driver.core.utils.CassandraVersion; | |
| 38 | + | |
| 39 | +@CassandraVersion(major=2.1) | |
| 38 | 40 | public class UserTypesTest extends CCMBridge.PerClassSingleNodeCluster { |
| 39 | 41 | |
| 40 | 42 | private final static List<DataType> DATA_TYPE_PRIMITIVES = new ArrayList<DataType>(DataType.allPrimitiveTypes()); |
| @@ -43,8 +45,6 @@ | ||
| 43 | 45 | |
| 44 | 46 | @Override |
| 45 | 47 | protected Collection<String> getTableDefinitions() { |
| 46 | - versionCheck(2.1, 0, "This will only work with Cassandra 2.1.0"); | |
| 47 | - | |
| 48 | 48 | String type1 = "CREATE TYPE phone (alias text, number text)"; |
| 49 | 49 | String type2 = "CREATE TYPE address (street text, \"ZIP\" int, phones set<frozen<phone>>)"; |
| 50 | 50 |
modified driver-core/src/test/java/com/datastax/driver/core/querybuilder/QueryBuilderExecutionTest.java +3 −47
| @@ -15,18 +15,12 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core.querybuilder; |
| 17 | 17 | |
| 18 | -import java.net.InetAddress; | |
| 19 | -import java.util.Arrays; | |
| 20 | -import java.util.Collection; | |
| 21 | -import java.util.Date; | |
| 22 | -import java.util.List; | |
| 23 | - | |
| 24 | -import com.google.common.collect.ImmutableList; | |
| 18 | +import java.util.*; | |
| 19 | + | |
| 25 | 20 | import org.testng.annotations.Test; |
| 26 | 21 | |
| 27 | 22 | import com.datastax.driver.core.*; |
| 28 | 23 | |
| 29 | -import static com.datastax.driver.core.Assertions.assertThat; | |
| 30 | 24 | import static com.datastax.driver.core.querybuilder.QueryBuilder.*; |
| 31 | 25 | |
| 32 | 26 | import static org.testng.Assert.*; |
| @@ -38,9 +32,7 @@ | ||
| 38 | 32 | @Override |
| 39 | 33 | protected Collection<String> getTableDefinitions() { |
| 40 | 34 | return Arrays.asList(String.format(TestUtils.CREATE_TABLE_SIMPLE_FORMAT, TABLE1), |
| 41 | - "CREATE TABLE dateTest (t timestamp PRIMARY KEY)", | |
| 42 | - "CREATE TYPE udt (i int, a inet)", | |
| 43 | - "CREATE TABLE udtTest(k int PRIMARY KEY, t frozen<udt>, l list<frozen<udt>>)"); | |
| 35 | + "CREATE TABLE dateTest (t timestamp PRIMARY KEY)"); | |
| 44 | 36 | } |
| 45 | 37 | |
| 46 | 38 | @Test(groups = "short") |
| @@ -110,40 +102,4 @@ | ||
| 110 | 102 | assertEquals("batchTest2", r2.getString("k")); |
| 111 | 103 | assertEquals("val2", r2.getString("t")); |
| 112 | 104 | } |
| 113 | - | |
| 114 | - @Test(groups = "short") | |
| 115 | - public void insertUdtTest() throws Exception { | |
| 116 | - UserType udtType = cluster.getMetadata().getKeyspace("ks").getUserType("udt"); | |
| 117 | - UDTValue udtValue = udtType.newValue().setInt("i", 2).setInet("a", InetAddress.getByName("localhost")); | |
| 118 | - | |
| 119 | - Statement insert = insertInto("udtTest").value("k", 1).value("t", udtValue); | |
| 120 | - assertEquals(insert.toString(), "INSERT INTO udtTest(k,t) VALUES (1,{i:2, a:'127.0.0.1'});"); | |
| 121 | - | |
| 122 | - session.execute(insert); | |
| 123 | - | |
| 124 | - List<Row> rows = session.execute(select().from("udtTest").where(eq("k", 1))).all(); | |
| 125 | - | |
| 126 | - assertEquals(rows.size(), 1); | |
| 127 | - | |
| 128 | - Row r1 = rows.get(0); | |
| 129 | - assertEquals("127.0.0.1", r1.getUDTValue("t").getInet("a").getHostAddress()); | |
| 130 | - } | |
| 131 | - | |
| 132 | - @Test(groups = "short") | |
| 133 | - public void should_handle_collections_of_UDT() throws Exception { | |
| 134 | - UserType udtType = cluster.getMetadata().getKeyspace("ks").getUserType("udt"); | |
| 135 | - UDTValue udtValue = udtType.newValue().setInt("i", 2).setInet("a", InetAddress.getByName("localhost")); | |
| 136 | - | |
| 137 | - Statement insert = insertInto("udtTest").value("k", 1).value("l", ImmutableList.of(udtValue)); | |
| 138 | - assertThat(insert.toString()).isEqualTo("INSERT INTO udtTest(k,l) VALUES (1,[{i:2, a:'127.0.0.1'}]);"); | |
| 139 | - | |
| 140 | - session.execute(insert); | |
| 141 | - | |
| 142 | - List<Row> rows = session.execute(select().from("udtTest").where(eq("k", 1))).all(); | |
| 143 | - | |
| 144 | - assertThat(rows.size()).isEqualTo(1); | |
| 145 | - | |
| 146 | - Row r1 = rows.get(0); | |
| 147 | - assertThat(r1.getList("l", UDTValue.class).get(0).getInet("a").getHostAddress()).isEqualTo("127.0.0.1"); | |
| 148 | - } | |
| 149 | 105 | } |
modified driver-core/src/test/java/com/datastax/driver/core/querybuilder/QueryBuilderTest.java +4 −0
| @@ -755,6 +755,10 @@ | ||
| 755 | 755 | statement = update("foo").with(set("m", ImmutableMap.of(1, list, 2, list))).where(eq("k", 1)); |
| 756 | 756 | assertThat(statement.toString()).isEqualTo(query); |
| 757 | 757 | |
| 758 | + query = "UPDATE foo SET m=m+{1:[[1],[2]],2:[[1],[2]]} WHERE k=1;"; | |
| 759 | + statement = update("foo").with(putAll("m", ImmutableMap.of(1, list, 2, list))).where(eq("k", 1)); | |
| 760 | + assertThat(statement.toString()).isEqualTo(query); | |
| 761 | + | |
| 758 | 762 | query = "UPDATE foo SET l=[[1]]+l WHERE k=1;"; |
| 759 | 763 | statement = update("foo").with(prepend("l", ImmutableList.of(1))).where(eq("k", 1)); |
| 760 | 764 | assertThat(statement.toString()).isEqualTo(query); |
added driver-core/src/test/java/com/datastax/driver/core/querybuilder/QueryBuilderUDTExecutionTest.java +83 −0
| @@ -0,0 +1,83 @@ | ||
| 1 | +package com.datastax.driver.core.querybuilder; | |
| 2 | + | |
| 3 | +import java.net.InetAddress; | |
| 4 | +import java.util.Arrays; | |
| 5 | +import java.util.Collection; | |
| 6 | +import java.util.List; | |
| 7 | +import java.util.Map; | |
| 8 | + | |
| 9 | +import com.google.common.collect.ImmutableList; | |
| 10 | +import com.google.common.collect.Maps; | |
| 11 | +import org.testng.annotations.Test; | |
| 12 | + | |
| 13 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 14 | +import static org.testng.Assert.assertEquals; | |
| 15 | + | |
| 16 | +import com.datastax.driver.core.*; | |
| 17 | +import com.datastax.driver.core.utils.CassandraVersion; | |
| 18 | + | |
| 19 | +import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; | |
| 20 | +import static com.datastax.driver.core.querybuilder.QueryBuilder.insertInto; | |
| 21 | +import static com.datastax.driver.core.querybuilder.QueryBuilder.putAll; | |
| 22 | +import static com.datastax.driver.core.querybuilder.QueryBuilder.select; | |
| 23 | +import static com.datastax.driver.core.querybuilder.QueryBuilder.update; | |
| 24 | + | |
| 25 | +@CassandraVersion(major=2.1, minor=3) | |
| 26 | +public class QueryBuilderUDTExecutionTest extends CCMBridge.PerClassSingleNodeCluster { | |
| 27 | + | |
| 28 | + @Override | |
| 29 | + protected Collection<String> getTableDefinitions() { | |
| 30 | + return Arrays.asList("CREATE TYPE udt (i int, a inet)", | |
| 31 | + "CREATE TABLE udtTest(k int PRIMARY KEY, t frozen<udt>, l list<frozen<udt>>, m map<int, frozen<udt>>)"); | |
| 32 | + } | |
| 33 | + | |
| 34 | + @Test(groups = "short") | |
| 35 | + public void insertUdtTest() throws Exception { | |
| 36 | + UserType udtType = cluster.getMetadata().getKeyspace("ks").getUserType("udt"); | |
| 37 | + UDTValue udtValue = udtType.newValue().setInt("i", 2).setInet("a", InetAddress.getByName("localhost")); | |
| 38 | + | |
| 39 | + Statement insert = insertInto("udtTest").value("k", 1).value("t", udtValue); | |
| 40 | + assertEquals(insert.toString(), "INSERT INTO udtTest(k,t) VALUES (1,{i:2, a:'127.0.0.1'});"); | |
| 41 | + | |
| 42 | + session.execute(insert); | |
| 43 | + | |
| 44 | + List<Row> rows = session.execute(select().from("udtTest").where(eq("k", 1))).all(); | |
| 45 | + | |
| 46 | + assertEquals(rows.size(), 1); | |
| 47 | + | |
| 48 | + Row r1 = rows.get(0); | |
| 49 | + assertEquals("127.0.0.1", r1.getUDTValue("t").getInet("a").getHostAddress()); | |
| 50 | + } | |
| 51 | + | |
| 52 | + @Test(groups = "short") | |
| 53 | + public void should_handle_collections_of_UDT() throws Exception { | |
| 54 | + UserType udtType = cluster.getMetadata().getKeyspace("ks").getUserType("udt"); | |
| 55 | + UDTValue udtValue = udtType.newValue().setInt("i", 2).setInet("a", InetAddress.getByName("localhost")); | |
| 56 | + UDTValue udtValue2 = udtType.newValue().setInt("i", 3).setInet("a", InetAddress.getByName("localhost")); | |
| 57 | + | |
| 58 | + Statement insert = insertInto("udtTest").value("k", 1).value("l", ImmutableList.of(udtValue)); | |
| 59 | + assertThat(insert.toString()).isEqualTo("INSERT INTO udtTest(k,l) VALUES (1,[{i:2, a:'127.0.0.1'}]);"); | |
| 60 | + | |
| 61 | + session.execute(insert); | |
| 62 | + | |
| 63 | + List<Row> rows = session.execute(select().from("udtTest").where(eq("k", 1))).all(); | |
| 64 | + | |
| 65 | + assertThat(rows.size()).isEqualTo(1); | |
| 66 | + | |
| 67 | + Row r1 = rows.get(0); | |
| 68 | + assertThat(r1.getList("l", UDTValue.class).get(0).getInet("a").getHostAddress()).isEqualTo("127.0.0.1"); | |
| 69 | + | |
| 70 | + Map<Integer, UDTValue> map = Maps.newHashMap(); | |
| 71 | + map.put(0, udtValue); | |
| 72 | + map.put(2, udtValue2); | |
| 73 | + Statement updateMap = update("udtTest").with(putAll("m", map)).where(eq("k", 1)); | |
| 74 | + assertThat(updateMap.toString()) | |
| 75 | + .isEqualTo("UPDATE udtTest SET m=m+{0:{i:2, a:'127.0.0.1'},2:{i:3, a:'127.0.0.1'}} WHERE k=1;"); | |
| 76 | + | |
| 77 | + session.execute(updateMap); | |
| 78 | + | |
| 79 | + rows = session.execute(select().from("udtTest").where(eq("k", 1))).all(); | |
| 80 | + r1 = rows.get(0); | |
| 81 | + assertThat(r1.getMap("m", Integer.class, UDTValue.class)).isEqualTo(map); | |
| 82 | + } | |
| 83 | +} |
modified driver-core/src/test/java/com/datastax/driver/core/schemabuilder/SchemaBuilderIT.java +3 −4
| @@ -11,6 +11,7 @@ | ||
| 11 | 11 | |
| 12 | 12 | import com.datastax.driver.core.*; |
| 13 | 13 | import com.datastax.driver.core.schemabuilder.TableOptions.CompactionOptions.DateTieredCompactionStrategyOptions.TimeStampResolution; |
| 14 | +import com.datastax.driver.core.utils.CassandraVersion; | |
| 14 | 15 | |
| 15 | 16 | import static com.datastax.driver.core.schemabuilder.SchemaBuilder.dateTieredStrategy; |
| 16 | 17 | import static com.datastax.driver.core.schemabuilder.SchemaBuilder.percentile; |
| @@ -25,9 +26,8 @@ | ||
| 25 | 26 | } |
| 26 | 27 | |
| 27 | 28 | @Test(groups = "short") |
| 29 | + @CassandraVersion(major=2.1, minor=2) | |
| 28 | 30 | public void should_modify_table_metadata() { |
| 29 | - TestUtils.versionCheck(2.1, 2, "This test requires Cassandra 2.1.2"); | |
| 30 | - | |
| 31 | 31 | // Create a table |
| 32 | 32 | session.execute(SchemaBuilder.createTable("ks", "TableMetadata") |
| 33 | 33 | .addPartitionKey("a", DataType.cint()) |
| @@ -122,9 +122,8 @@ | ||
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | @Test(groups = "short") |
| 125 | + @CassandraVersion(major=2.1) | |
| 125 | 126 | public void should_create_a_table_and_a_udt() { |
| 126 | - TestUtils.versionCheck(2.1, 0, "This test requires Cassandra 2.1.0"); | |
| 127 | - | |
| 128 | 127 | // Create a UDT and a table |
| 129 | 128 | session.execute(SchemaBuilder.createType("MyUDT") |
| 130 | 129 | .ifNotExists() |
added driver-mapping/src/test/java/com/datastax/driver/mapping/MapperInvalidCollectionTypesTest.java +105 −0
| @@ -0,0 +1,105 @@ | ||
| 1 | +package com.datastax.driver.mapping; | |
| 2 | + | |
| 3 | +import java.util.*; | |
| 4 | + | |
| 5 | +import org.testng.annotations.Test; | |
| 6 | + | |
| 7 | +import com.datastax.driver.core.CCMBridge; | |
| 8 | +import com.datastax.driver.mapping.annotations.PartitionKey; | |
| 9 | +import com.datastax.driver.mapping.annotations.Table; | |
| 10 | + | |
| 11 | +public class MapperInvalidCollectionTypesTest extends CCMBridge.PerClassSingleNodeCluster { | |
| 12 | + protected Collection<String> getTableDefinitions() { | |
| 13 | + return Arrays.asList( | |
| 14 | + "CREATE TABLE table_list (id int PRIMARY KEY, l list<int>)", | |
| 15 | + "CREATE TABLE table_set (id int PRIMARY KEY, s set<int>)", | |
| 16 | + "CREATE TABLE table_map (id int PRIMARY KEY, m map<int, int>)"); | |
| 17 | + } | |
| 18 | + | |
| 19 | + @Table(keyspace="ks", name="table_list") | |
| 20 | + public class InvalidList { | |
| 21 | + @PartitionKey | |
| 22 | + private int id; | |
| 23 | + | |
| 24 | + private ArrayList<Integer> l; | |
| 25 | + | |
| 26 | + public int getId() { | |
| 27 | + return id; | |
| 28 | + } | |
| 29 | + | |
| 30 | + public void setId(int id) { | |
| 31 | + this.id = id; | |
| 32 | + } | |
| 33 | + | |
| 34 | + public ArrayList<Integer> getL() { | |
| 35 | + return l; | |
| 36 | + } | |
| 37 | + | |
| 38 | + public void setL(ArrayList<Integer> l) { | |
| 39 | + this.l = l; | |
| 40 | + } | |
| 41 | + } | |
| 42 | + | |
| 43 | + @Table(keyspace="ks", name="table_set") | |
| 44 | + public class InvalidSet { | |
| 45 | + @PartitionKey | |
| 46 | + private int id; | |
| 47 | + | |
| 48 | + private HashSet<Integer> s; | |
| 49 | + | |
| 50 | + public int getId() { | |
| 51 | + return id; | |
| 52 | + } | |
| 53 | + | |
| 54 | + public void setId(int id) { | |
| 55 | + this.id = id; | |
| 56 | + } | |
| 57 | + | |
| 58 | + public HashSet<Integer> getS() { | |
| 59 | + return s; | |
| 60 | + } | |
| 61 | + | |
| 62 | + public void setS(HashSet<Integer> s) { | |
| 63 | + this.s = s; | |
| 64 | + } | |
| 65 | + } | |
| 66 | + | |
| 67 | + @Table(keyspace="ks", name="table_map") | |
| 68 | + public class InvalidMap { | |
| 69 | + @PartitionKey | |
| 70 | + private int id; | |
| 71 | + | |
| 72 | + private TreeMap<Integer, Integer> m; | |
| 73 | + | |
| 74 | + public TreeMap<Integer, Integer> getM() { | |
| 75 | + return m; | |
| 76 | + } | |
| 77 | + | |
| 78 | + public void setM(TreeMap<Integer, Integer> m) { | |
| 79 | + this.m = m; | |
| 80 | + } | |
| 81 | + | |
| 82 | + public int getId() { | |
| 83 | + return id; | |
| 84 | + } | |
| 85 | + | |
| 86 | + public void setId(int id) { | |
| 87 | + this.id = id; | |
| 88 | + } | |
| 89 | + } | |
| 90 | + | |
| 91 | + @Test(groups="short", expectedExceptions = IllegalArgumentException.class) | |
| 92 | + public void list_type_is_enforced() { | |
| 93 | + new MappingManager(session).mapper(InvalidList.class); | |
| 94 | + } | |
| 95 | + | |
| 96 | + @Test(groups="short", expectedExceptions = IllegalArgumentException.class) | |
| 97 | + public void map_type_is_enforced() { | |
| 98 | + new MappingManager(session).mapper(InvalidMap.class); | |
| 99 | + } | |
| 100 | + | |
| 101 | + @Test(groups="short", expectedExceptions = IllegalArgumentException.class) | |
| 102 | + public void set_type_is_enforced() { | |
| 103 | + new MappingManager(session).mapper(InvalidSet.class); | |
| 104 | + } | |
| 105 | +} |
modified driver-mapping/src/test/java/com/datastax/driver/mapping/MapperNestedCollectionsTest.java +47 −12
| @@ -1,24 +1,26 @@ | ||
| 1 | 1 | package com.datastax.driver.mapping; |
| 2 | 2 | |
| 3 | -import java.util.Collection; | |
| 4 | -import java.util.Map; | |
| 3 | +import java.util.*; | |
| 5 | 4 | |
| 6 | 5 | import com.google.common.collect.ImmutableMap; |
| 7 | 6 | import com.google.common.collect.Lists; |
| 7 | +import com.google.common.collect.Sets; | |
| 8 | 8 | import org.testng.annotations.Test; |
| 9 | 9 | |
| 10 | 10 | import com.datastax.driver.core.CCMBridge; |
| 11 | 11 | import com.datastax.driver.core.ResultSet; |
| 12 | +import com.datastax.driver.core.utils.CassandraVersion; | |
| 12 | 13 | import com.datastax.driver.mapping.annotations.*; |
| 13 | 14 | |
| 14 | 15 | import static com.datastax.driver.core.Assertions.assertThat; |
| 15 | 16 | |
| 17 | +@CassandraVersion(major=2.1, minor=3) | |
| 16 | 18 | public class MapperNestedCollectionsTest extends CCMBridge.PerClassSingleNodeCluster { |
| 17 | 19 | |
| 18 | 20 | @Override |
| 19 | 21 | protected Collection<String> getTableDefinitions() { |
| 20 | 22 | return Lists.newArrayList( |
| 21 | - "CREATE TYPE testType(i int)", | |
| 23 | + "CREATE TYPE testType(i int, ls list<frozen<set<int>>>)", | |
| 22 | 24 | "CREATE TABLE testTable (k int primary key, " |
| 23 | 25 | + "m1 map<text, frozen<map<int, int>>>, " // nested collection |
| 24 | 26 | + "m2 map<text, frozen<map<int, frozen<testType>>>>)" // nested collection with UDT |
| @@ -32,7 +34,14 @@ | ||
| 32 | 34 | TestTable testTable = new TestTable(); |
| 33 | 35 | testTable.setK(1); |
| 34 | 36 | testTable.setM1(ImmutableMap.<String, Map<Integer, Integer>>of("bar", ImmutableMap.of(1, 2))); |
| 35 | - testTable.setM2(ImmutableMap.<String, Map<Integer, TestType>>of("bar", ImmutableMap.of(1, new TestType(2)))); | |
| 37 | + | |
| 38 | + Set<Integer> s1 = Sets.newHashSet(1,2,3); | |
| 39 | + Set<Integer> s2 = Sets.newHashSet(4,5,6); | |
| 40 | + List<Set<Integer>> ls = new ArrayList<Set<Integer>>(); | |
| 41 | + ls.add(s1); | |
| 42 | + ls.add(s2); | |
| 43 | + | |
| 44 | + testTable.setM2(ImmutableMap.<String, Map<Integer, TestType>>of("bar", ImmutableMap.of(1, new TestType(2, ls)))); | |
| 36 | 45 | |
| 37 | 46 | mapper.save(testTable); |
| 38 | 47 | |
| @@ -65,13 +74,23 @@ | ||
| 65 | 74 | public static class TestType { |
| 66 | 75 | private int i; |
| 67 | 76 | |
| 77 | + @Frozen("list<frozen<set<int>>>") | |
| 78 | + private List<Set<Integer>> ls; | |
| 79 | + | |
| 68 | 80 | public TestType() { |
| 81 | + ls = Lists.newArrayList(); | |
| 69 | 82 | } |
| 70 | 83 | |
| 71 | 84 | public TestType(int i) { |
| 85 | + this(); | |
| 72 | 86 | this.i = i; |
| 73 | 87 | } |
| 74 | 88 | |
| 89 | + public TestType(int i, List<Set<Integer>> ls) { | |
| 90 | + this(i); | |
| 91 | + this.ls = ls; | |
| 92 | + } | |
| 93 | + | |
| 75 | 94 | public int getI() { |
| 76 | 95 | return i; |
| 77 | 96 | } |
| @@ -80,20 +99,36 @@ | ||
| 80 | 99 | this.i = i; |
| 81 | 100 | } |
| 82 | 101 | |
| 102 | + public List<Set<Integer>> getLs() { | |
| 103 | + return ls; | |
| 104 | + } | |
| 105 | + | |
| 106 | + public void setLs(List<Set<Integer>> ls) { | |
| 107 | + this.ls = ls; | |
| 108 | + } | |
| 109 | + | |
| 83 | 110 | @Override |
| 84 | - public boolean equals(Object other) { | |
| 85 | - if (this == other) | |
| 111 | + public boolean equals(Object o) { | |
| 112 | + if (this == o) | |
| 86 | 113 | return true; |
| 87 | - if (other instanceof TestType) { | |
| 88 | - TestType that = (TestType)other; | |
| 89 | - return this.i == that.i; | |
| 90 | - } | |
| 91 | - return false; | |
| 114 | + if (!(o instanceof TestType)) | |
| 115 | + return false; | |
| 116 | + | |
| 117 | + TestType testType = (TestType)o; | |
| 118 | + | |
| 119 | + if (i != testType.i) | |
| 120 | + return false; | |
| 121 | + if (!ls.equals(testType.ls)) | |
| 122 | + return false; | |
| 123 | + | |
| 124 | + return true; | |
| 92 | 125 | } |
| 93 | 126 | |
| 94 | 127 | @Override |
| 95 | 128 | public int hashCode() { |
| 96 | - return i; | |
| 129 | + int result = i; | |
| 130 | + result = 31 * result + ls.hashCode(); | |
| 131 | + return result; | |
| 97 | 132 | } |
| 98 | 133 | } |
| 99 | 134 |
modified driver-mapping/src/test/java/com/datastax/driver/mapping/UDTFieldMapperTest.java +2 −4
| @@ -10,14 +10,14 @@ | ||
| 10 | 10 | import com.datastax.driver.core.Cluster; |
| 11 | 11 | import com.datastax.driver.core.Session; |
| 12 | 12 | import com.datastax.driver.core.TestUtils; |
| 13 | +import com.datastax.driver.core.utils.CassandraVersion; | |
| 13 | 14 | import com.datastax.driver.mapping.annotations.*; |
| 14 | 15 | |
| 16 | +@CassandraVersion(major=2.1) | |
| 15 | 17 | public class UDTFieldMapperTest { |
| 16 | 18 | |
| 17 | 19 | @Test(groups = "short") |
| 18 | 20 | public void udt_and_tables_with_ks_created_in_another_session_should_be_mapped() { |
| 19 | - TestUtils.versionCheck(2.1, 0, "This will only work with C* 2.1.0"); | |
| 20 | - | |
| 21 | 21 | CCMBridge ccm = null; |
| 22 | 22 | Cluster cluster = null; |
| 23 | 23 | |
| @@ -65,8 +65,6 @@ | ||
| 65 | 65 | |
| 66 | 66 | @Test(groups = "short") |
| 67 | 67 | public void udt_and_tables_without_ks_created_in_another_session_should_be_mapped() { |
| 68 | - TestUtils.versionCheck(2.1, 0, "This will only work with C* 2.1.0"); | |
| 69 | - | |
| 70 | 68 | CCMBridge ccm = null; |
| 71 | 69 | Cluster cluster = null; |
| 72 | 70 |
modified pom.xml +1 −1
| @@ -38,7 +38,7 @@ | ||
| 38 | 38 | |
| 39 | 39 | <properties> |
| 40 | 40 | <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> |
| 41 | - <cassandra.version>2.1.2</cassandra.version> | |
| 41 | + <cassandra.version>2.1.3</cassandra.version> | |
| 42 | 42 | </properties> |
| 43 | 43 | |
| 44 | 44 | <dependencies> |