kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 34b058666d9d0f528dc8a423bf10f476c687421177224b850e05679709125227 |
|---|---|
| Author | olim7t <omichallat+github@gmail.com> · 2016-03-09 15:58 +01:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2016-03-09 22:30 +01:00 |
| Parents | 6cbc334fa86f |
3 files changed
modified changelog/README.md +1 −0
| @@ -36,6 +36,7 @@ | ||
| 36 | 36 | - [bug] JAVA-764: Retry with the normal consistency level (not the serial one) when a write times out on the Paxos phase. |
| 37 | 37 | - [bug] JAVA-727: Allow monotonic timestamp generators to drift in the future + use microsecond precision when possible. |
| 38 | 38 | - [improvement] JAVA-444: Add Java process information to UUIDs.makeNode() hash. |
| 39 | +- [improvement] JAVA-977: Preserve original cause when BuiltStatement value can't be serialized. | |
| 39 | 40 | |
| 40 | 41 | Merged from 2.0 branch: |
| 41 | 42 |
modified driver-core/src/main/java/com/datastax/driver/core/querybuilder/Utils.java +3 −1
| @@ -68,7 +68,9 @@ | ||
| 68 | 68 | serializedValues[i] = DataType.serializeValue(values.get(i), protocolVersion); |
| 69 | 69 | } catch (IllegalArgumentException e) { |
| 70 | 70 | // Catch and rethrow to provide a more helpful error message (one that include which value is bad) |
| 71 | - throw new IllegalArgumentException(String.format("Value %d of type %s does not correspond to any CQL3 type", i, values.get(i).getClass())); | |
| 71 | + throw new IllegalArgumentException( | |
| 72 | + String.format("Value %d of type %s does not correspond to any CQL3 type", | |
| 73 | + i, values.get(i).getClass()), e); | |
| 72 | 74 | } |
| 73 | 75 | } |
| 74 | 76 | return serializedValues; |
modified driver-core/src/test/java/com/datastax/driver/core/querybuilder/QueryBuilderTest.java +35 −15
| @@ -25,15 +25,20 @@ | ||
| 25 | 25 | import com.google.common.collect.Sets; |
| 26 | 26 | import org.testng.annotations.Test; |
| 27 | 27 | |
| 28 | +import java.io.PrintWriter; | |
| 29 | +import java.io.StringWriter; | |
| 28 | 30 | import java.math.BigDecimal; |
| 29 | 31 | import java.math.BigInteger; |
| 30 | 32 | import java.net.InetAddress; |
| 33 | +import java.nio.ByteBuffer; | |
| 31 | 34 | import java.util.*; |
| 32 | 35 | |
| 33 | 36 | import static com.datastax.driver.core.DataType.cint; |
| 34 | 37 | import static com.datastax.driver.core.querybuilder.QueryBuilder.*; |
| 35 | 38 | import static org.assertj.core.api.Assertions.assertThat; |
| 36 | -import static org.testng.Assert.*; | |
| 39 | +import static org.assertj.core.api.Assertions.fail; | |
| 40 | +import static org.testng.Assert.assertEquals; | |
| 41 | +import static org.testng.Assert.assertTrue; | |
| 37 | 42 | |
| 38 | 43 | public class QueryBuilderTest { |
| 39 | 44 | |
| @@ -140,35 +145,35 @@ | ||
| 140 | 145 | |
| 141 | 146 | try { |
| 142 | 147 | select().countAll().from("foo").orderBy(asc("a"), desc("b")).orderBy(asc("a"), desc("b")); |
| 143 | - fail(); | |
| 148 | + fail("Expected an IllegalStateException"); | |
| 144 | 149 | } catch (IllegalStateException e) { |
| 145 | 150 | assertEquals(e.getMessage(), "An ORDER BY clause has already been provided"); |
| 146 | 151 | } |
| 147 | 152 | |
| 148 | 153 | try { |
| 149 | 154 | select().column("a").all().from("foo"); |
| 150 | - fail(); | |
| 155 | + fail("Expected an IllegalStateException"); | |
| 151 | 156 | } catch (IllegalStateException e) { |
| 152 | 157 | assertEquals(e.getMessage(), "Some columns ([a]) have already been selected."); |
| 153 | 158 | } |
| 154 | 159 | |
| 155 | 160 | try { |
| 156 | 161 | select().column("a").countAll().from("foo"); |
| 157 | - fail(); | |
| 162 | + fail("Expected an IllegalStateException"); | |
| 158 | 163 | } catch (IllegalStateException e) { |
| 159 | 164 | assertEquals(e.getMessage(), "Some columns ([a]) have already been selected."); |
| 160 | 165 | } |
| 161 | 166 | |
| 162 | 167 | try { |
| 163 | 168 | select().all().from("foo").limit(-42); |
| 164 | - fail(); | |
| 169 | + fail("Expected an IllegalArgumentException"); | |
| 165 | 170 | } catch (IllegalArgumentException e) { |
| 166 | 171 | assertEquals(e.getMessage(), "Invalid LIMIT value, must be strictly positive"); |
| 167 | 172 | } |
| 168 | 173 | |
| 169 | 174 | try { |
| 170 | 175 | select().all().from("foo").limit(42).limit(42); |
| 171 | - fail(); | |
| 176 | + fail("Expected an IllegalStateException"); | |
| 172 | 177 | } catch (IllegalStateException e) { |
| 173 | 178 | assertEquals(e.getMessage(), "A LIMIT value has already been provided"); |
| 174 | 179 | } |
| @@ -244,7 +249,7 @@ | ||
| 244 | 249 | |
| 245 | 250 | try { |
| 246 | 251 | insertInto("foo").values(new String[]{"a", "b"}, new Object[]{1, 2, 3}); |
| 247 | - fail(); | |
| 252 | + fail("Expected an IllegalArgumentException"); | |
| 248 | 253 | } catch (IllegalArgumentException e) { |
| 249 | 254 | assertEquals(e.getMessage(), "Got 2 names but 3 values"); |
| 250 | 255 | } |
| @@ -327,7 +332,7 @@ | ||
| 327 | 332 | |
| 328 | 333 | try { |
| 329 | 334 | update("foo").using(ttl(-400)); |
| 330 | - fail(); | |
| 335 | + fail("Expected an IllegalArgumentException"); | |
| 331 | 336 | } catch (IllegalArgumentException e) { |
| 332 | 337 | assertEquals(e.getMessage(), "Invalid ttl, must be positive"); |
| 333 | 338 | } |
| @@ -381,14 +386,14 @@ | ||
| 381 | 386 | |
| 382 | 387 | try { |
| 383 | 388 | delete().column("a").all().from("foo"); |
| 384 | - fail(); | |
| 389 | + fail("Expected an IllegalStateException"); | |
| 385 | 390 | } catch (IllegalStateException e) { |
| 386 | 391 | assertEquals(e.getMessage(), "Some columns ([a]) have already been selected."); |
| 387 | 392 | } |
| 388 | 393 | |
| 389 | 394 | try { |
| 390 | 395 | delete().from("foo").using(timestamp(-1240003134L)); |
| 391 | - fail(); | |
| 396 | + fail("Expected an IllegalArgumentException"); | |
| 392 | 397 | } catch (IllegalArgumentException e) { |
| 393 | 398 | assertEquals(e.getMessage(), "Invalid timestamp, must be positive"); |
| 394 | 399 | } |
| @@ -895,7 +900,6 @@ | ||
| 895 | 900 | } |
| 896 | 901 | |
| 897 | 902 | @Test(groups = "unit") |
| 898 | - @CassandraVersion(major = 2.1) | |
| 899 | 903 | public void should_serialize_collections_of_serializable_elements() { |
| 900 | 904 | Set<UUID> set = Sets.newHashSet(UUID.randomUUID()); |
| 901 | 905 | List<Date> list = Lists.newArrayList(new Date()); |
| @@ -912,7 +916,6 @@ | ||
| 912 | 916 | } |
| 913 | 917 | |
| 914 | 918 | @Test(groups = "unit") |
| 915 | - @CassandraVersion(major = 2.1) | |
| 916 | 919 | public void should_not_attempt_to_serialize_function_calls_in_collections() { |
| 917 | 920 | BuiltStatement query = insertInto("foo").value("v", Sets.newHashSet(fcall("func", 1))); |
| 918 | 921 | assertThat(query.getQueryString()).isEqualTo("INSERT INTO foo (v) VALUES ({func(1)});"); |
| @@ -920,7 +923,6 @@ | ||
| 920 | 923 | } |
| 921 | 924 | |
| 922 | 925 | @Test(groups = "unit") |
| 923 | - @CassandraVersion(major = 2.1) | |
| 924 | 926 | public void should_not_attempt_to_serialize_bind_markers_in_collections() { |
| 925 | 927 | BuiltStatement query = insertInto("foo").value("v", Lists.newArrayList(1, 2, bindMarker())); |
| 926 | 928 | assertThat(query.getQueryString()).isEqualTo("INSERT INTO foo (v) VALUES ([1,2,?]);"); |
| @@ -928,7 +930,6 @@ | ||
| 928 | 930 | } |
| 929 | 931 | |
| 930 | 932 | @Test(groups = "unit") |
| 931 | - @CassandraVersion(major = 2.1) | |
| 932 | 933 | public void should_not_attempt_to_serialize_raw_values_in_collections() { |
| 933 | 934 | BuiltStatement query = insertInto("foo").value("v", ImmutableMap.of(1, raw("x"))); |
| 934 | 935 | assertThat(query.getQueryString()).isEqualTo("INSERT INTO foo (v) VALUES ({1:x});"); |
| @@ -936,7 +937,6 @@ | ||
| 936 | 937 | } |
| 937 | 938 | |
| 938 | 939 | @Test(groups = "unit") |
| 939 | - @CassandraVersion(major = 2.1) | |
| 940 | 940 | public void should_not_attempt_to_serialize_collections_containing_numbers() { |
| 941 | 941 | BuiltStatement query; |
| 942 | 942 | // lists |
| @@ -956,4 +956,24 @@ | ||
| 956 | 956 | assertThat(query.hasValues()).isFalse(); |
| 957 | 957 | } |
| 958 | 958 | |
| 959 | + @Test(groups = "unit") | |
| 960 | + public void should_include_original_cause_when_arguments_invalid() { | |
| 961 | + // Collection elements in protocol v2 must be at most 65535 bytes | |
| 962 | + ByteBuffer bb = ByteBuffer.allocate(65536); // too big | |
| 963 | + List<ByteBuffer> value = Lists.newArrayList(bb); | |
| 964 | + | |
| 965 | + BuiltStatement s = insertInto("foo").value("l", value); | |
| 966 | + try { | |
| 967 | + s.getValues(ProtocolVersion.V2); | |
| 968 | + fail("Expected an IllegalArgumentException"); | |
| 969 | + } catch (IllegalArgumentException e) { | |
| 970 | + StringWriter writer = new StringWriter(); | |
| 971 | + e.printStackTrace(new PrintWriter(writer)); | |
| 972 | + String stackTrace = writer.toString(); | |
| 973 | + assertThat(stackTrace).contains( | |
| 974 | + "Native protocol version 2 supports only elements with size up to 65535 bytes - " + | |
| 975 | + "but element size is 65536 bytes"); | |
| 976 | + } | |
| 977 | + } | |
| 978 | + | |
| 959 | 979 | } |