Elffuss BraidHub

kikocis/java-driver public

Extra tests for nested collections (JAVA-570, JAVA-612, JAVA-672).
Changeset1e0f61b0202a3145ca75c50a2c213fc4a7497aecebeea2440a75c8f629f81b65
AuthorAndrew Tolbert <andrew.tolbert@datastax.com> · 2015-03-03 14:47 -06:00
Committerolim7t <omichallat+github@gmail.com> · 2015-03-06 17:23 -08:00
Parents4d9e392bb521

Browse the files at this changeset

14 files changed

modified driver-core/src/test/java/com/datastax/driver/core/ControlConnectionTest.java +2 −2
@@ -12,6 +12,7 @@
1212 import com.datastax.driver.core.policies.LoadBalancingPolicy;
1313 import com.datastax.driver.core.policies.Policies;
1414 import com.datastax.driver.core.policies.ReconnectionPolicy;
15+import com.datastax.driver.core.utils.CassandraVersion;
1516
1617 public class ControlConnectionTest {
1718 @Test(groups = "short")
@@ -73,9 +74,8 @@
7374 * Therefore we use two different driver instances in this test.
7475 */
7576 @Test(groups = "short")
77+ @CassandraVersion(major=2.1)
7678 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-
7979 CCMBridge ccm = null;
8080 Cluster cluster = null;
8181
modified driver-core/src/test/java/com/datastax/driver/core/DataTypeIntegrationTest.java +106 −7
@@ -15,15 +15,10 @@
1515 */
1616 package com.datastax.driver.core;
1717
18-import java.util.Collection;
19-import java.util.List;
20-import java.util.Map;
18+import java.util.*;
2119 import java.util.concurrent.atomic.AtomicInteger;
2220
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.*;
2722 import org.slf4j.Logger;
2823 import org.slf4j.LoggerFactory;
2924 import org.testng.annotations.Test;
@@ -149,6 +144,7 @@
149144 tables.addAll(tablesWithCollectionsOfPrimitives());
150145 tables.addAll(tablesWithMapsOfPrimitives());
151146 tables.addAll(tablesWithNestedCollections());
147+ tables.addAll(tablesWithRandomlyGeneratedNestedCollections());
152148
153149 return ImmutableList.copyOf(tables);
154150 }
@@ -220,4 +216,107 @@
220216 }
221217 return tables;
222218 }
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+ }
223322 }
modified driver-core/src/test/java/com/datastax/driver/core/QueryTimestampTest.java +2 −4
@@ -11,18 +11,16 @@
1111 import com.datastax.driver.core.Cluster.Builder;
1212 import com.datastax.driver.core.Metrics.Errors;
1313 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;
1615
1716 /**
1817 * Tests the behavior of client-provided timestamps with protocol v3.
1918 */
19+@CassandraVersion(major=2.1)
2020 public class QueryTimestampTest extends CCMBridge.PerClassSingleNodeCluster {
2121
2222 @Override
2323 protected Collection<String> getTableDefinitions() {
24- versionCheck(2.1, 0, "This will only work with Cassandra 2.1.0");
25-
2624 return Lists.newArrayList("CREATE TABLE foo (k int PRIMARY KEY, v int)");
2725 }
2826
modified driver-core/src/test/java/com/datastax/driver/core/SingleConnectionPoolTest.java +3 −2
@@ -12,11 +12,12 @@
1212
1313 import static org.testng.Assert.fail;
1414
15+import com.datastax.driver.core.utils.CassandraVersion;
16+
17+@CassandraVersion(major=2.1)
1518 public class SingleConnectionPoolTest extends CCMBridge.PerClassSingleNodeCluster {
1619 @Override
1720 protected Collection<String> getTableDefinitions() {
18- TestUtils.versionCheck(2.1, 0, "This will only work with Cassandra 2.1.0+");
19-
2021 return Lists.newArrayList();
2122 }
2223
modified driver-core/src/test/java/com/datastax/driver/core/TupleTest.java +3 −3
@@ -25,15 +25,15 @@
2525 import static org.testng.Assert.assertEquals;
2626 import static org.testng.Assert.fail;
2727
28+import com.datastax.driver.core.utils.CassandraVersion;
29+
2830 import static com.datastax.driver.core.TestUtils.SIMPLE_KEYSPACE;
29-import static com.datastax.driver.core.TestUtils.versionCheck;
3031
32+@CassandraVersion(major=2.1)
3133 public class TupleTest extends CCMBridge.PerClassSingleNodeCluster {
3234
3335 @Override
3436 protected Collection<String> getTableDefinitions() {
35- versionCheck(2.1, 0, "This will only work with Cassandra 2.1.0");
36-
3737 return Arrays.asList("CREATE TABLE t (k int PRIMARY KEY, v frozen<tuple<int, text, float>>)");
3838 }
3939
modified driver-core/src/test/java/com/datastax/driver/core/UserTypesTest.java +3 −3
@@ -32,9 +32,11 @@
3232 import static org.testng.Assert.assertEquals;
3333
3434 import static com.datastax.driver.core.Metadata.quote;
35-import static com.datastax.driver.core.TestUtils.versionCheck;
3635 import static org.testng.Assert.assertNotEquals;
3736
37+import com.datastax.driver.core.utils.CassandraVersion;
38+
39+@CassandraVersion(major=2.1)
3840 public class UserTypesTest extends CCMBridge.PerClassSingleNodeCluster {
3941
4042 private final static List<DataType> DATA_TYPE_PRIMITIVES = new ArrayList<DataType>(DataType.allPrimitiveTypes());
@@ -43,8 +45,6 @@
4345
4446 @Override
4547 protected Collection<String> getTableDefinitions() {
46- versionCheck(2.1, 0, "This will only work with Cassandra 2.1.0");
47-
4848 String type1 = "CREATE TYPE phone (alias text, number text)";
4949 String type2 = "CREATE TYPE address (street text, \"ZIP\" int, phones set<frozen<phone>>)";
5050
modified driver-core/src/test/java/com/datastax/driver/core/querybuilder/QueryBuilderExecutionTest.java +3 −47
@@ -15,18 +15,12 @@
1515 */
1616 package com.datastax.driver.core.querybuilder;
1717
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+
2520 import org.testng.annotations.Test;
2621
2722 import com.datastax.driver.core.*;
2823
29-import static com.datastax.driver.core.Assertions.assertThat;
3024 import static com.datastax.driver.core.querybuilder.QueryBuilder.*;
3125
3226 import static org.testng.Assert.*;
@@ -38,9 +32,7 @@
3832 @Override
3933 protected Collection<String> getTableDefinitions() {
4034 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)");
4436 }
4537
4638 @Test(groups = "short")
@@ -110,40 +102,4 @@
110102 assertEquals("batchTest2", r2.getString("k"));
111103 assertEquals("val2", r2.getString("t"));
112104 }
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- }
149105 }
modified driver-core/src/test/java/com/datastax/driver/core/querybuilder/QueryBuilderTest.java +4 −0
@@ -755,6 +755,10 @@
755755 statement = update("foo").with(set("m", ImmutableMap.of(1, list, 2, list))).where(eq("k", 1));
756756 assertThat(statement.toString()).isEqualTo(query);
757757
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+
758762 query = "UPDATE foo SET l=[[1]]+l WHERE k=1;";
759763 statement = update("foo").with(prepend("l", ImmutableList.of(1))).where(eq("k", 1));
760764 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 @@
1111
1212 import com.datastax.driver.core.*;
1313 import com.datastax.driver.core.schemabuilder.TableOptions.CompactionOptions.DateTieredCompactionStrategyOptions.TimeStampResolution;
14+import com.datastax.driver.core.utils.CassandraVersion;
1415
1516 import static com.datastax.driver.core.schemabuilder.SchemaBuilder.dateTieredStrategy;
1617 import static com.datastax.driver.core.schemabuilder.SchemaBuilder.percentile;
@@ -25,9 +26,8 @@
2526 }
2627
2728 @Test(groups = "short")
29+ @CassandraVersion(major=2.1, minor=2)
2830 public void should_modify_table_metadata() {
29- TestUtils.versionCheck(2.1, 2, "This test requires Cassandra 2.1.2");
30-
3131 // Create a table
3232 session.execute(SchemaBuilder.createTable("ks", "TableMetadata")
3333 .addPartitionKey("a", DataType.cint())
@@ -122,9 +122,8 @@
122122 }
123123
124124 @Test(groups = "short")
125+ @CassandraVersion(major=2.1)
125126 public void should_create_a_table_and_a_udt() {
126- TestUtils.versionCheck(2.1, 0, "This test requires Cassandra 2.1.0");
127-
128127 // Create a UDT and a table
129128 session.execute(SchemaBuilder.createType("MyUDT")
130129 .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 @@
11 package com.datastax.driver.mapping;
22
3-import java.util.Collection;
4-import java.util.Map;
3+import java.util.*;
54
65 import com.google.common.collect.ImmutableMap;
76 import com.google.common.collect.Lists;
7+import com.google.common.collect.Sets;
88 import org.testng.annotations.Test;
99
1010 import com.datastax.driver.core.CCMBridge;
1111 import com.datastax.driver.core.ResultSet;
12+import com.datastax.driver.core.utils.CassandraVersion;
1213 import com.datastax.driver.mapping.annotations.*;
1314
1415 import static com.datastax.driver.core.Assertions.assertThat;
1516
17+@CassandraVersion(major=2.1, minor=3)
1618 public class MapperNestedCollectionsTest extends CCMBridge.PerClassSingleNodeCluster {
1719
1820 @Override
1921 protected Collection<String> getTableDefinitions() {
2022 return Lists.newArrayList(
21- "CREATE TYPE testType(i int)",
23+ "CREATE TYPE testType(i int, ls list<frozen<set<int>>>)",
2224 "CREATE TABLE testTable (k int primary key, "
2325 + "m1 map<text, frozen<map<int, int>>>, " // nested collection
2426 + "m2 map<text, frozen<map<int, frozen<testType>>>>)" // nested collection with UDT
@@ -32,7 +34,14 @@
3234 TestTable testTable = new TestTable();
3335 testTable.setK(1);
3436 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))));
3645
3746 mapper.save(testTable);
3847
@@ -65,13 +74,23 @@
6574 public static class TestType {
6675 private int i;
6776
77+ @Frozen("list<frozen<set<int>>>")
78+ private List<Set<Integer>> ls;
79+
6880 public TestType() {
81+ ls = Lists.newArrayList();
6982 }
7083
7184 public TestType(int i) {
85+ this();
7286 this.i = i;
7387 }
7488
89+ public TestType(int i, List<Set<Integer>> ls) {
90+ this(i);
91+ this.ls = ls;
92+ }
93+
7594 public int getI() {
7695 return i;
7796 }
@@ -80,20 +99,36 @@
8099 this.i = i;
81100 }
82101
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+
83110 @Override
84- public boolean equals(Object other) {
85- if (this == other)
111+ public boolean equals(Object o) {
112+ if (this == o)
86113 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;
92125 }
93126
94127 @Override
95128 public int hashCode() {
96- return i;
129+ int result = i;
130+ result = 31 * result + ls.hashCode();
131+ return result;
97132 }
98133 }
99134
modified driver-mapping/src/test/java/com/datastax/driver/mapping/UDTFieldMapperTest.java +2 −4
@@ -10,14 +10,14 @@
1010 import com.datastax.driver.core.Cluster;
1111 import com.datastax.driver.core.Session;
1212 import com.datastax.driver.core.TestUtils;
13+import com.datastax.driver.core.utils.CassandraVersion;
1314 import com.datastax.driver.mapping.annotations.*;
1415
16+@CassandraVersion(major=2.1)
1517 public class UDTFieldMapperTest {
1618
1719 @Test(groups = "short")
1820 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-
2121 CCMBridge ccm = null;
2222 Cluster cluster = null;
2323
@@ -65,8 +65,6 @@
6565
6666 @Test(groups = "short")
6767 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-
7068 CCMBridge ccm = null;
7169 Cluster cluster = null;
7270
modified pom.xml +1 −1
@@ -38,7 +38,7 @@
3838
3939 <properties>
4040 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
41- <cassandra.version>2.1.2</cassandra.version>
41+ <cassandra.version>2.1.3</cassandra.version>
4242 </properties>
4343
4444 <dependencies>