kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 9737075342ee5fbba847829b1c898cfda9f0e85646dd59c17757ce435da36652 |
|---|---|
| Author | olim7t <omichallat+github@gmail.com> · 2015-12-09 18:45 +01:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2015-12-09 18:45 +01:00 |
| Parents | c200baed5144 |
More than 300 files changed
modified driver-core/src/test/java/com/datastax/driver/core/TokenIntegrationTest.java +64 −60
| @@ -15,9 +15,11 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.net.InetSocketAddress; | |
| 19 | -import java.util.*; | |
| 20 | - | |
| 18 | +import com.datastax.driver.core.exceptions.InvalidTypeException; | |
| 19 | +import com.datastax.driver.core.policies.LoadBalancingPolicy; | |
| 20 | +import com.datastax.driver.core.policies.RoundRobinPolicy; | |
| 21 | +import com.datastax.driver.core.policies.WhiteListPolicy; | |
| 22 | +import com.datastax.driver.core.utils.CassandraVersion; | |
| 21 | 23 | import com.google.common.base.Function; |
| 22 | 24 | import com.google.common.collect.Iterables; |
| 23 | 25 | import com.google.common.collect.Lists; |
| @@ -25,30 +27,29 @@ | ||
| 25 | 27 | import org.testng.annotations.BeforeClass; |
| 26 | 28 | import org.testng.annotations.Test; |
| 27 | 29 | |
| 28 | -import com.datastax.driver.core.exceptions.InvalidTypeException; | |
| 29 | -import com.datastax.driver.core.policies.LoadBalancingPolicy; | |
| 30 | -import com.datastax.driver.core.policies.RoundRobinPolicy; | |
| 31 | -import com.datastax.driver.core.policies.WhiteListPolicy; | |
| 32 | -import com.datastax.driver.core.utils.CassandraVersion; | |
| 30 | +import java.net.InetSocketAddress; | |
| 31 | +import java.util.HashSet; | |
| 32 | +import java.util.List; | |
| 33 | +import java.util.Set; | |
| 33 | 34 | |
| 34 | 35 | import static com.datastax.driver.core.Assertions.assertThat; |
| 35 | 36 | |
| 36 | 37 | /** |
| 37 | 38 | * This class uses subclasses for each type of partitioner. |
| 38 | - * | |
| 39 | + * <p/> | |
| 39 | 40 | * There's normally a way to parametrize a TestNG class with @Factory and @DataProvider, |
| 40 | 41 | * but it doesn't seem to work with multiple methods. |
| 41 | 42 | */ |
| 42 | 43 | public abstract class TokenIntegrationTest { |
| 43 | 44 | |
| 44 | 45 | List<String> schema = Lists.newArrayList( |
| 45 | - "CREATE KEYSPACE test WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1}", | |
| 46 | - "CREATE KEYSPACE test2 WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 2}", | |
| 47 | - "USE test", | |
| 48 | - "CREATE TABLE foo(i int primary key)", | |
| 49 | - "INSERT INTO foo (i) VALUES (1)", | |
| 50 | - "INSERT INTO foo (i) VALUES (2)", | |
| 51 | - "INSERT INTO foo (i) VALUES (3)" | |
| 46 | + "CREATE KEYSPACE test WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1}", | |
| 47 | + "CREATE KEYSPACE test2 WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 2}", | |
| 48 | + "USE test", | |
| 49 | + "CREATE TABLE foo(i int primary key)", | |
| 50 | + "INSERT INTO foo (i) VALUES (1)", | |
| 51 | + "INSERT INTO foo (i) VALUES (2)", | |
| 52 | + "INSERT INTO foo (i) VALUES (3)" | |
| 52 | 53 | ); |
| 53 | 54 | |
| 54 | 55 | private final String ccmOptions; |
| @@ -76,17 +77,17 @@ | ||
| 76 | 77 | |
| 77 | 78 | // Only connect to node 1, which makes it easier to query system tables in should_expose_tokens_per_host() |
| 78 | 79 | LoadBalancingPolicy lbp = new WhiteListPolicy(new RoundRobinPolicy(), |
| 79 | - Lists.newArrayList(new InetSocketAddress(CCMBridge.ipOfNode(1), 9042))); | |
| 80 | + Lists.newArrayList(new InetSocketAddress(CCMBridge.ipOfNode(1), 9042))); | |
| 80 | 81 | |
| 81 | 82 | cluster = Cluster.builder() |
| 82 | - .addContactPoints(CCMBridge.ipOfNode(1)) | |
| 83 | - .withLoadBalancingPolicy(lbp) | |
| 84 | - .withQueryOptions(new QueryOptions() | |
| 85 | - .setRefreshNodeIntervalMillis(0) | |
| 86 | - .setRefreshNodeListIntervalMillis(0) | |
| 87 | - .setRefreshSchemaIntervalMillis(0) | |
| 88 | - ) | |
| 89 | - .build(); | |
| 83 | + .addContactPoints(CCMBridge.ipOfNode(1)) | |
| 84 | + .withLoadBalancingPolicy(lbp) | |
| 85 | + .withQueryOptions(new QueryOptions() | |
| 86 | + .setRefreshNodeIntervalMillis(0) | |
| 87 | + .setRefreshNodeListIntervalMillis(0) | |
| 88 | + .setRefreshSchemaIntervalMillis(0) | |
| 89 | + ) | |
| 90 | + .build(); | |
| 90 | 91 | cluster.init(); |
| 91 | 92 | session = cluster.connect(); |
| 92 | 93 | |
| @@ -94,7 +95,7 @@ | ||
| 94 | 95 | session.execute(statement); |
| 95 | 96 | } |
| 96 | 97 | |
| 97 | - @AfterClass(groups = "short", alwaysRun=true) | |
| 98 | + @AfterClass(groups = "short", alwaysRun = true) | |
| 98 | 99 | public void teardown() { |
| 99 | 100 | if (cluster != null) |
| 100 | 101 | cluster.close(); |
| @@ -135,8 +136,8 @@ | ||
| 135 | 136 | if (row.getInt("i") == testKey) { |
| 136 | 137 | // We should find our test key exactly once |
| 137 | 138 | assertThat(foundRange) |
| 138 | - .describedAs("found the same key in two ranges: " + foundRange + " and " + range) | |
| 139 | - .isNull(); | |
| 139 | + .describedAs("found the same key in two ranges: " + foundRange + " and " + range) | |
| 140 | + .isNull(); | |
| 140 | 141 | foundRange = range; |
| 141 | 142 | // That range should be managed by the replica |
| 142 | 143 | assertThat(metadata.getReplicas("test", range)).contains(replica); |
| @@ -160,16 +161,16 @@ | ||
| 160 | 161 | * Validates that a {@link Token} can be retrieved and parsed by executing 'select token(name)' and |
| 161 | 162 | * then used to find data matching that token. |
| 162 | 163 | * </p> |
| 163 | - * | |
| 164 | - * <p> | |
| 164 | + * <p/> | |
| 165 | + * <p/> | |
| 165 | 166 | * This test does the following: |
| 166 | - * | |
| 167 | + * <p/> | |
| 167 | 168 | * <ol> |
| 168 | - * <li>Retrieve the token for the key with value '1', get it by index, and ensure if is of the expected token type.</li> | |
| 169 | - * <li>Retrieve the token for the partition key with getPartitionKeyToken</li> | |
| 170 | - * <li>Select data by token with a BoundStatement.</li> | |
| 171 | - * <li>Select data by token using setToken by index.</li> | |
| 172 | - * <li>Select data by token with setPartitionKeyToken.</li> | |
| 169 | + * <li>Retrieve the token for the key with value '1', get it by index, and ensure if is of the expected token type.</li> | |
| 170 | + * <li>Retrieve the token for the partition key with getPartitionKeyToken</li> | |
| 171 | + * <li>Select data by token with a BoundStatement.</li> | |
| 172 | + * <li>Select data by token using setToken by index.</li> | |
| 173 | + * <li>Select data by token with setPartitionKeyToken.</li> | |
| 173 | 174 | * </ol> |
| 174 | 175 | * |
| 175 | 176 | * @test_category token |
| @@ -185,7 +186,7 @@ | ||
| 185 | 186 | assertThat(token.getType()).isEqualTo(expectedTokenType); |
| 186 | 187 | |
| 187 | 188 | assertThat( |
| 188 | - row.getPartitionKeyToken() | |
| 189 | + row.getPartitionKeyToken() | |
| 189 | 190 | ).isEqualTo(token); |
| 190 | 191 | |
| 191 | 192 | PreparedStatement pst = session.prepare("SELECT * FROM test.foo WHERE token(i) = ?"); |
| @@ -204,17 +205,17 @@ | ||
| 204 | 205 | * Validates that a {@link Token} can be retrieved and parsed by using bind variables and |
| 205 | 206 | * aliasing. |
| 206 | 207 | * </p> |
| 207 | - * | |
| 208 | - * <p> | |
| 208 | + * <p/> | |
| 209 | + * <p/> | |
| 209 | 210 | * This test does the following: |
| 210 | - * | |
| 211 | + * <p/> | |
| 211 | 212 | * <ol> |
| 212 | - * <li>Retrieve the token by alias for the key '1', and ensure it matches the token by index.</li> | |
| 213 | - * <li>Select data by token using setToken by name.</li> | |
| 213 | + * <li>Retrieve the token by alias for the key '1', and ensure it matches the token by index.</li> | |
| 214 | + * <li>Select data by token using setToken by name.</li> | |
| 214 | 215 | * </ol> |
| 215 | 216 | */ |
| 216 | 217 | @Test(groups = "short") |
| 217 | - @CassandraVersion(major=2) | |
| 218 | + @CassandraVersion(major = 2) | |
| 218 | 219 | public void should_get_token_from_row_and_set_token_in_query_with_binding_and_aliasing() { |
| 219 | 220 | Row row = session.execute("SELECT token(i) AS t FROM test.foo WHERE i = 1").one(); |
| 220 | 221 | Token token = row.getToken("t"); |
| @@ -249,7 +250,7 @@ | ||
| 249 | 250 | * Ensures that @{link TokenRange}s are exposed at a per host level, the ranges are complete, |
| 250 | 251 | * the entire ring is represented, and that ranges do not overlap. |
| 251 | 252 | * </p> |
| 252 | - * | |
| 253 | + * <p/> | |
| 253 | 254 | * <p> |
| 254 | 255 | * Also ensures that ranges from another replica are present when a Host is a replica for |
| 255 | 256 | * another node. |
| @@ -275,7 +276,7 @@ | ||
| 275 | 276 | Host host = TestUtils.findHost(cluster, i); |
| 276 | 277 | Set<TokenRange> hostRanges = cluster.getMetadata().getTokenRanges(keyspace, host); |
| 277 | 278 | // Special case: When using vnodes the tokens are not evenly assigned to each replica. |
| 278 | - if(!useVnodes) { | |
| 279 | + if (!useVnodes) { | |
| 279 | 280 | assertThat(hostRanges).hasSize(replicationFactor * numTokens); |
| 280 | 281 | } |
| 281 | 282 | allRangesWithReplicas.addAll(hostRanges); |
| @@ -286,7 +287,7 @@ | ||
| 286 | 287 | |
| 287 | 288 | // Once we ignore duplicates, the number of ranges should match the number of nodes. |
| 288 | 289 | Set<TokenRange> allRanges = new HashSet<TokenRange>(allRangesWithReplicas); |
| 289 | - assertThat(allRanges).hasSize(3*numTokens); | |
| 290 | + assertThat(allRanges).hasSize(3 * numTokens); | |
| 290 | 291 | |
| 291 | 292 | // And the ranges should cover the whole ring and no ranges intersect. |
| 292 | 293 | assertThat(cluster).hasValidTokenRanges(keyspace); |
| @@ -296,7 +297,7 @@ | ||
| 296 | 297 | * <p> |
| 297 | 298 | * Ensures that Tokens are exposed for each Host and that the match those in the system tables. |
| 298 | 299 | * </p> |
| 299 | - * | |
| 300 | + * <p/> | |
| 300 | 301 | * <p> |
| 301 | 302 | * Also validates that tokens are not present for multiple hosts. |
| 302 | 303 | * </p> |
| @@ -315,12 +316,13 @@ | ||
| 315 | 316 | // constructed in the first place, but there's not much else we can do. |
| 316 | 317 | // Note that this relies on all queries going to node 1, which is why we use a WhiteList LBP in setup(). |
| 317 | 318 | Row row = (host.listenAddress == null) |
| 318 | - ? session.execute("select tokens from system.local").one() | |
| 319 | - : session.execute("select tokens from system.peers where peer = '" + host.listenAddress.getHostAddress() + "'").one(); | |
| 319 | + ? session.execute("select tokens from system.local").one() | |
| 320 | + : session.execute("select tokens from system.peers where peer = '" + host.listenAddress.getHostAddress() + "'").one(); | |
| 320 | 321 | Set<String> tokenStrings = row.getSet("tokens", String.class); |
| 321 | 322 | assertThat(tokenStrings).hasSize(numTokens); |
| 322 | 323 | Iterable<Token> tokensFromSystemTable = Iterables.transform(tokenStrings, new Function<String, Token>() { |
| 323 | - @Override public Token apply(String input) { | |
| 324 | + @Override | |
| 325 | + public Token apply(String input) { | |
| 324 | 326 | return tokenFactory().fromString(input); |
| 325 | 327 | } |
| 326 | 328 | }); |
| @@ -348,11 +350,12 @@ | ||
| 348 | 350 | assertOnlyOneWrapped(ranges); |
| 349 | 351 | |
| 350 | 352 | Iterable<TokenRange> splitRanges = Iterables.concat(Iterables.transform(ranges, |
| 351 | - new Function<TokenRange, Iterable<TokenRange>>() { | |
| 352 | - @Override public Iterable<TokenRange> apply(TokenRange input) { | |
| 353 | - return input.splitEvenly(10); | |
| 354 | - } | |
| 355 | - }) | |
| 353 | + new Function<TokenRange, Iterable<TokenRange>>() { | |
| 354 | + @Override | |
| 355 | + public Iterable<TokenRange> apply(TokenRange input) { | |
| 356 | + return input.splitEvenly(10); | |
| 357 | + } | |
| 358 | + }) | |
| 356 | 359 | ); |
| 357 | 360 | |
| 358 | 361 | assertOnlyOneWrapped(splitRanges); |
| @@ -360,16 +363,17 @@ | ||
| 360 | 363 | |
| 361 | 364 | /** |
| 362 | 365 | * Asserts that given the input {@link TokenRange}s that at most one of them wraps the token ring. |
| 366 | + * | |
| 363 | 367 | * @param ranges Ranges to validate against. |
| 364 | 368 | */ |
| 365 | 369 | protected void assertOnlyOneWrapped(Iterable<TokenRange> ranges) { |
| 366 | 370 | TokenRange wrappedRange = null; |
| 367 | 371 | |
| 368 | - for(TokenRange range : ranges) { | |
| 369 | - if(range.isWrappedAround()) { | |
| 372 | + for (TokenRange range : ranges) { | |
| 373 | + if (range.isWrappedAround()) { | |
| 370 | 374 | assertThat(wrappedRange) |
| 371 | - .as("Found a wrapped around TokenRange (%s) when one already exists (%s).", range, wrappedRange) | |
| 372 | - .isNull(); | |
| 375 | + .as("Found a wrapped around TokenRange (%s) when one already exists (%s).", range, wrappedRange) | |
| 376 | + .isNull(); | |
| 373 | 377 | wrappedRange = range; |
| 374 | 378 | |
| 375 | 379 | assertThat(range).isWrappedAround(); // this also checks the unwrapped ranges |
| @@ -390,7 +394,7 @@ | ||
| 390 | 394 | Token end = metadata.newToken(range.getEnd().toString()); |
| 391 | 395 | |
| 392 | 396 | assertThat(metadata.newTokenRange(start, end)) |
| 393 | - .isEqualTo(range); | |
| 397 | + .isEqualTo(range); | |
| 394 | 398 | } |
| 395 | 399 | |
| 396 | 400 | protected abstract Token.Factory tokenFactory(); |
modified driver-core/src/test/java/com/datastax/driver/core/TokenRangeAssert.java +14 −14
| @@ -15,11 +15,11 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | +import org.assertj.core.api.AbstractAssert; | |
| 19 | + | |
| 18 | 20 | import java.util.Iterator; |
| 19 | 21 | import java.util.List; |
| 20 | 22 | |
| 21 | -import org.assertj.core.api.AbstractAssert; | |
| 22 | - | |
| 23 | 23 | import static com.datastax.driver.core.Assertions.assertThat; |
| 24 | 24 | |
| 25 | 25 | public class TokenRangeAssert extends AbstractAssert<TokenRangeAssert, TokenRange> { |
| @@ -54,8 +54,8 @@ | ||
| 54 | 54 | |
| 55 | 55 | List<TokenRange> unwrapped = actual.unwrap(); |
| 56 | 56 | assertThat(unwrapped.size()) |
| 57 | - .as("%s should unwrap to two ranges, but unwrapped to %s", actual, unwrapped) | |
| 58 | - .isEqualTo(2); | |
| 57 | + .as("%s should unwrap to two ranges, but unwrapped to %s", actual, unwrapped) | |
| 58 | + .isEqualTo(2); | |
| 59 | 59 | |
| 60 | 60 | Iterator<TokenRange> unwrappedIt = unwrapped.iterator(); |
| 61 | 61 | TokenRange firstRange = unwrappedIt.next(); |
| @@ -80,22 +80,22 @@ | ||
| 80 | 80 | |
| 81 | 81 | public TokenRangeAssert intersects(TokenRange that) { |
| 82 | 82 | assertThat(actual.intersects(that)) |
| 83 | - .as("%s should intersect %s", actual, that) | |
| 84 | - .isTrue(); | |
| 83 | + .as("%s should intersect %s", actual, that) | |
| 84 | + .isTrue(); | |
| 85 | 85 | assertThat(that.intersects(actual)) |
| 86 | - .as("%s should intersect %s", that, actual) | |
| 87 | - .isTrue(); | |
| 86 | + .as("%s should intersect %s", that, actual) | |
| 87 | + .isTrue(); | |
| 88 | 88 | return this; |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | - public TokenRangeAssert doesNotIntersect(TokenRange ... that) { | |
| 92 | - for(TokenRange thatRange : that) { | |
| 91 | + public TokenRangeAssert doesNotIntersect(TokenRange... that) { | |
| 92 | + for (TokenRange thatRange : that) { | |
| 93 | 93 | assertThat(actual.intersects(thatRange)) |
| 94 | - .as("%s should not intersect %s", actual, thatRange) | |
| 95 | - .isFalse(); | |
| 94 | + .as("%s should not intersect %s", actual, thatRange) | |
| 95 | + .isFalse(); | |
| 96 | 96 | assertThat(thatRange.intersects(actual)) |
| 97 | - .as("%s should not intersect %s", thatRange, actual) | |
| 98 | - .isFalse(); | |
| 97 | + .as("%s should not intersect %s", thatRange, actual) | |
| 98 | + .isFalse(); | |
| 99 | 99 | } |
| 100 | 100 | return this; |
| 101 | 101 | } |
modified driver-core/src/test/java/com/datastax/driver/core/TokenRangeTest.java +50 −51
| @@ -15,14 +15,13 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.util.List; | |
| 19 | - | |
| 20 | 18 | import com.google.common.collect.ImmutableList; |
| 21 | 19 | import org.testng.annotations.Test; |
| 22 | 20 | |
| 23 | -import static org.testng.Assert.fail; | |
| 21 | +import java.util.List; | |
| 24 | 22 | |
| 25 | 23 | import static com.datastax.driver.core.Assertions.assertThat; |
| 24 | +import static org.testng.Assert.fail; | |
| 26 | 25 | |
| 27 | 26 | public class TokenRangeTest { |
| 28 | 27 | // The tests in this class don't depend on the kind of factory used, so use Murmur3 everywhere |
| @@ -33,74 +32,74 @@ | ||
| 33 | 32 | public void should_check_intersection() { |
| 34 | 33 | // NB - to make the test more visual, we use watch face numbers |
| 35 | 34 | assertThat(tokenRange(3, 9)) |
| 36 | - .doesNotIntersect(tokenRange(11, 1)) | |
| 37 | - .doesNotIntersect(tokenRange(1, 2)) | |
| 38 | - .doesNotIntersect(tokenRange(11, 3)) | |
| 39 | - .doesNotIntersect(tokenRange(2, 3)) | |
| 40 | - .doesNotIntersect(tokenRange(3, 3)) | |
| 41 | - .intersects(tokenRange(2, 6)) | |
| 42 | - .intersects(tokenRange(2, 10)) | |
| 43 | - .intersects(tokenRange(6, 10)) | |
| 44 | - .intersects(tokenRange(4, 8)) | |
| 45 | - .intersects(tokenRange(3, 9)) | |
| 46 | - .doesNotIntersect(tokenRange(9, 10)) | |
| 47 | - .doesNotIntersect(tokenRange(10, 11)) | |
| 35 | + .doesNotIntersect(tokenRange(11, 1)) | |
| 36 | + .doesNotIntersect(tokenRange(1, 2)) | |
| 37 | + .doesNotIntersect(tokenRange(11, 3)) | |
| 38 | + .doesNotIntersect(tokenRange(2, 3)) | |
| 39 | + .doesNotIntersect(tokenRange(3, 3)) | |
| 40 | + .intersects(tokenRange(2, 6)) | |
| 41 | + .intersects(tokenRange(2, 10)) | |
| 42 | + .intersects(tokenRange(6, 10)) | |
| 43 | + .intersects(tokenRange(4, 8)) | |
| 44 | + .intersects(tokenRange(3, 9)) | |
| 45 | + .doesNotIntersect(tokenRange(9, 10)) | |
| 46 | + .doesNotIntersect(tokenRange(10, 11)) | |
| 48 | 47 | ; |
| 49 | 48 | assertThat(tokenRange(9, 3)) |
| 50 | - .doesNotIntersect(tokenRange(5, 7)) | |
| 51 | - .doesNotIntersect(tokenRange(7, 8)) | |
| 52 | - .doesNotIntersect(tokenRange(5, 9)) | |
| 53 | - .doesNotIntersect(tokenRange(8, 9)) | |
| 54 | - .doesNotIntersect(tokenRange(9, 9)) | |
| 55 | - .intersects(tokenRange(8, 2)) | |
| 56 | - .intersects(tokenRange(8, 4)) | |
| 57 | - .intersects(tokenRange(2, 4)) | |
| 58 | - .intersects(tokenRange(10, 2)) | |
| 59 | - .intersects(tokenRange(9, 3)) | |
| 60 | - .doesNotIntersect(tokenRange(3, 4)) | |
| 61 | - .doesNotIntersect(tokenRange(4, 5)) | |
| 49 | + .doesNotIntersect(tokenRange(5, 7)) | |
| 50 | + .doesNotIntersect(tokenRange(7, 8)) | |
| 51 | + .doesNotIntersect(tokenRange(5, 9)) | |
| 52 | + .doesNotIntersect(tokenRange(8, 9)) | |
| 53 | + .doesNotIntersect(tokenRange(9, 9)) | |
| 54 | + .intersects(tokenRange(8, 2)) | |
| 55 | + .intersects(tokenRange(8, 4)) | |
| 56 | + .intersects(tokenRange(2, 4)) | |
| 57 | + .intersects(tokenRange(10, 2)) | |
| 58 | + .intersects(tokenRange(9, 3)) | |
| 59 | + .doesNotIntersect(tokenRange(3, 4)) | |
| 60 | + .doesNotIntersect(tokenRange(4, 5)) | |
| 62 | 61 | ; |
| 63 | 62 | assertThat(tokenRange(3, 3)).doesNotIntersect(tokenRange(3, 3)); |
| 64 | 63 | |
| 65 | 64 | // Reminder: minToken serves as both lower and upper bound |
| 66 | 65 | assertThat(tokenRange(minToken, 5)) |
| 67 | - .doesNotIntersect(tokenRange(6, 7)) | |
| 68 | - .doesNotIntersect(tokenRange(6, minToken)) | |
| 69 | - .intersects(tokenRange(6, 4)) | |
| 70 | - .intersects(tokenRange(2, 4)) | |
| 71 | - .intersects(tokenRange(minToken, 4)) | |
| 72 | - .intersects(tokenRange(minToken, 5)) | |
| 66 | + .doesNotIntersect(tokenRange(6, 7)) | |
| 67 | + .doesNotIntersect(tokenRange(6, minToken)) | |
| 68 | + .intersects(tokenRange(6, 4)) | |
| 69 | + .intersects(tokenRange(2, 4)) | |
| 70 | + .intersects(tokenRange(minToken, 4)) | |
| 71 | + .intersects(tokenRange(minToken, 5)) | |
| 73 | 72 | ; |
| 74 | 73 | |
| 75 | 74 | assertThat(tokenRange(5, minToken)) |
| 76 | - .doesNotIntersect(tokenRange(3, 4)) | |
| 77 | - .doesNotIntersect(tokenRange(minToken, 4)) | |
| 78 | - .intersects(tokenRange(6, 7)) | |
| 79 | - .intersects(tokenRange(4, 1)) | |
| 80 | - .intersects(tokenRange(6, minToken)) | |
| 81 | - .intersects(tokenRange(5, minToken)) | |
| 75 | + .doesNotIntersect(tokenRange(3, 4)) | |
| 76 | + .doesNotIntersect(tokenRange(minToken, 4)) | |
| 77 | + .intersects(tokenRange(6, 7)) | |
| 78 | + .intersects(tokenRange(4, 1)) | |
| 79 | + .intersects(tokenRange(6, minToken)) | |
| 80 | + .intersects(tokenRange(5, minToken)) | |
| 82 | 81 | ; |
| 83 | 82 | |
| 84 | 83 | assertThat(tokenRange(minToken, minToken)) |
| 85 | - .intersects(tokenRange(3, 4)) | |
| 86 | - .intersects(tokenRange(3, minToken)) | |
| 87 | - .intersects(tokenRange(minToken, 3)) | |
| 88 | - .doesNotIntersect(tokenRange(3, 3)) | |
| 84 | + .intersects(tokenRange(3, 4)) | |
| 85 | + .intersects(tokenRange(3, minToken)) | |
| 86 | + .intersects(tokenRange(minToken, 3)) | |
| 87 | + .doesNotIntersect(tokenRange(3, 3)) | |
| 89 | 88 | ; |
| 90 | 89 | } |
| 91 | 90 | |
| 92 | 91 | @Test(groups = "unit") |
| 93 | 92 | public void should_compute_intersection() { |
| 94 | 93 | assertThat(tokenRange(3, 9).intersectWith(tokenRange(2, 4))) |
| 95 | - .isEqualTo(ImmutableList.of(tokenRange(3, 4))); | |
| 94 | + .isEqualTo(ImmutableList.of(tokenRange(3, 4))); | |
| 96 | 95 | assertThat(tokenRange(3, 9).intersectWith(tokenRange(3, 5))) |
| 97 | - .isEqualTo(ImmutableList.of(tokenRange(3, 5))); | |
| 96 | + .isEqualTo(ImmutableList.of(tokenRange(3, 5))); | |
| 98 | 97 | assertThat(tokenRange(3, 9).intersectWith(tokenRange(4, 6))) |
| 99 | - .isEqualTo(ImmutableList.of(tokenRange(4, 6))); | |
| 98 | + .isEqualTo(ImmutableList.of(tokenRange(4, 6))); | |
| 100 | 99 | assertThat(tokenRange(3, 9).intersectWith(tokenRange(7, 9))) |
| 101 | - .isEqualTo(ImmutableList.of(tokenRange(7, 9))); | |
| 100 | + .isEqualTo(ImmutableList.of(tokenRange(7, 9))); | |
| 102 | 101 | assertThat(tokenRange(3, 9).intersectWith(tokenRange(8, 10))) |
| 103 | - .isEqualTo(ImmutableList.of(tokenRange(8, 9))); | |
| 102 | + .isEqualTo(ImmutableList.of(tokenRange(8, 9))); | |
| 104 | 103 | } |
| 105 | 104 | |
| 106 | 105 | @Test(groups = "unit") |
| @@ -108,14 +107,14 @@ | ||
| 108 | 107 | // If a range wraps the ring like 10, -10 does this will produce two separate |
| 109 | 108 | // intersected ranges. |
| 110 | 109 | assertThat(tokenRange(10, -10).intersectWith(tokenRange(-20, 20))) |
| 111 | - .isEqualTo(ImmutableList.of(tokenRange(10, 20), tokenRange(-20, -10))); | |
| 110 | + .isEqualTo(ImmutableList.of(tokenRange(10, 20), tokenRange(-20, -10))); | |
| 112 | 111 | assertThat(tokenRange(-20, 20).intersectWith(tokenRange(10, -10))) |
| 113 | - .isEqualTo(ImmutableList.of(tokenRange(10, 20), tokenRange(-20, -10))); | |
| 112 | + .isEqualTo(ImmutableList.of(tokenRange(10, 20), tokenRange(-20, -10))); | |
| 114 | 113 | |
| 115 | 114 | // If both ranges wrap the ring, they should be merged together wrapping across |
| 116 | 115 | // the range. |
| 117 | 116 | assertThat(tokenRange(10, -30).intersectWith(tokenRange(20, -20))) |
| 118 | - .isEqualTo(ImmutableList.of(tokenRange(20, -30))); | |
| 117 | + .isEqualTo(ImmutableList.of(tokenRange(20, -30))); | |
| 119 | 118 | } |
| 120 | 119 | |
| 121 | 120 | @Test(groups = "unit", expectedExceptions = IllegalArgumentException.class) |
modified driver-core/src/test/java/com/datastax/driver/core/TracingTest.java +8 −8
| @@ -15,19 +15,19 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.util.Collection; | |
| 19 | -import java.util.Collections; | |
| 20 | -import java.util.List; | |
| 21 | -import java.util.UUID; | |
| 22 | - | |
| 23 | 18 | import com.datastax.driver.core.policies.DowngradingConsistencyRetryPolicy; |
| 24 | 19 | import com.datastax.driver.core.utils.CassandraVersion; |
| 25 | 20 | import org.testng.annotations.BeforeClass; |
| 26 | 21 | import org.testng.annotations.Test; |
| 27 | 22 | |
| 23 | +import java.util.Collection; | |
| 24 | +import java.util.Collections; | |
| 25 | +import java.util.List; | |
| 26 | +import java.util.UUID; | |
| 27 | + | |
| 28 | 28 | import static org.assertj.core.api.Assertions.assertThat; |
| 29 | 29 | |
| 30 | -@CassandraVersion(major=2.0) | |
| 30 | +@CassandraVersion(major = 2.0) | |
| 31 | 31 | public class TracingTest extends CCMBridge.PerClassSingleNodeCluster { |
| 32 | 32 | |
| 33 | 33 | @Override |
| @@ -73,12 +73,12 @@ | ||
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | assertThat(result.getExecutionInfo().getQueryTrace().getEvents()).isNotNull() |
| 76 | - .isNotEmpty(); | |
| 76 | + .isNotEmpty(); | |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | /** |
| 80 | 80 | * Validates that if a query gets retried, the second internal query will still have tracing enabled. |
| 81 | - * | |
| 81 | + * <p/> | |
| 82 | 82 | * To force a retry, we use the downgrading policy with an impossible CL. |
| 83 | 83 | * |
| 84 | 84 | * @test_category tracing |
modified driver-core/src/test/java/com/datastax/driver/core/TupleTest.java +21 −16
| @@ -15,20 +15,19 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.nio.ByteBuffer; | |
| 19 | -import java.util.*; | |
| 20 | - | |
| 21 | 18 | import com.beust.jcommander.internal.Lists; |
| 19 | +import com.datastax.driver.core.utils.CassandraVersion; | |
| 22 | 20 | import com.google.common.base.Joiner; |
| 23 | 21 | import org.testng.annotations.Test; |
| 24 | 22 | |
| 23 | +import java.nio.ByteBuffer; | |
| 24 | +import java.util.*; | |
| 25 | + | |
| 25 | 26 | import static org.assertj.core.api.Assertions.assertThat; |
| 26 | 27 | import static org.testng.Assert.assertEquals; |
| 27 | 28 | import static org.testng.Assert.fail; |
| 28 | 29 | |
| 29 | -import com.datastax.driver.core.utils.CassandraVersion; | |
| 30 | - | |
| 31 | -@CassandraVersion(major=2.1) | |
| 30 | +@CassandraVersion(major = 2.1) | |
| 32 | 31 | public class TupleTest extends CCMBridge.PerClassSingleNodeCluster { |
| 33 | 32 | |
| 34 | 33 | ProtocolVersion protocolVersion = TestUtils.getDesiredProtocolVersion(); |
| @@ -92,13 +91,14 @@ | ||
| 92 | 91 | /** |
| 93 | 92 | * Basic test of tuple functionality. |
| 94 | 93 | * Original code found in python-driver:integration.standard.test_types.py:test_tuple_type |
| 94 | + * | |
| 95 | 95 | * @throws Exception |
| 96 | 96 | */ |
| 97 | 97 | @Test(groups = "short") |
| 98 | 98 | public void tupleTypeTest() throws Exception { |
| 99 | 99 | try { |
| 100 | 100 | session.execute("CREATE KEYSPACE test_tuple_type " + |
| 101 | - "WITH replication = { 'class' : 'SimpleStrategy', 'replication_factor': '1'}"); | |
| 101 | + "WITH replication = { 'class' : 'SimpleStrategy', 'replication_factor': '1'}"); | |
| 102 | 102 | session.execute("USE test_tuple_type"); |
| 103 | 103 | session.execute("CREATE TABLE mytable (a int PRIMARY KEY, b frozen<tuple<ascii, int, boolean>>)"); |
| 104 | 104 | |
| @@ -114,7 +114,8 @@ | ||
| 114 | 114 | try { |
| 115 | 115 | TupleValue partial = t.newValue("bar", 456); |
| 116 | 116 | fail(); |
| 117 | - } catch (IllegalArgumentException e) {} | |
| 117 | + } catch (IllegalArgumentException e) { | |
| 118 | + } | |
| 118 | 119 | |
| 119 | 120 | // test incomplete tuples with new TupleType |
| 120 | 121 | TupleType t1 = cluster.getMetadata().newTupleType(DataType.ascii(), DataType.cint()); |
| @@ -128,7 +129,8 @@ | ||
| 128 | 129 | try { |
| 129 | 130 | TupleValue subpartial = t.newValue("zoo"); |
| 130 | 131 | fail(); |
| 131 | - } catch (IllegalArgumentException e) {} | |
| 132 | + } catch (IllegalArgumentException e) { | |
| 133 | + } | |
| 132 | 134 | |
| 133 | 135 | // test single value tuples with new TupleType |
| 134 | 136 | TupleType t2 = cluster.getMetadata().newTupleType(DataType.ascii()); |
| @@ -166,7 +168,7 @@ | ||
| 166 | 168 | public void tupleTestTypeVaryingLengths() throws Exception { |
| 167 | 169 | try { |
| 168 | 170 | session.execute("CREATE KEYSPACE test_tuple_type_varying_lengths " + |
| 169 | - "WITH replication = { 'class' : 'SimpleStrategy', 'replication_factor': '1'}"); | |
| 171 | + "WITH replication = { 'class' : 'SimpleStrategy', 'replication_factor': '1'}"); | |
| 170 | 172 | session.execute("USE test_tuple_type_varying_lengths"); |
| 171 | 173 | |
| 172 | 174 | // programmatically create the table with tuples of said sizes |
| @@ -221,7 +223,7 @@ | ||
| 221 | 223 | |
| 222 | 224 | try { |
| 223 | 225 | session.execute("CREATE KEYSPACE test_tuple_subtypes " + |
| 224 | - "WITH replication = { 'class' : 'SimpleStrategy', 'replication_factor': '1'}"); | |
| 226 | + "WITH replication = { 'class' : 'SimpleStrategy', 'replication_factor': '1'}"); | |
| 225 | 227 | session.execute("USE test_tuple_subtypes"); |
| 226 | 228 | |
| 227 | 229 | // programmatically create the table with a tuple of all datatypes |
| @@ -287,7 +289,7 @@ | ||
| 287 | 289 | |
| 288 | 290 | try { |
| 289 | 291 | session.execute("CREATE KEYSPACE test_tuple_non_primitive_subtypes " + |
| 290 | - "WITH replication = { 'class' : 'SimpleStrategy', 'replication_factor': '1'}"); | |
| 292 | + "WITH replication = { 'class' : 'SimpleStrategy', 'replication_factor': '1'}"); | |
| 291 | 293 | session.execute("USE test_tuple_non_primitive_subtypes"); |
| 292 | 294 | |
| 293 | 295 | ArrayList<String> values = new ArrayList<String>(); |
| @@ -398,7 +400,7 @@ | ||
| 398 | 400 | @Test(groups = "short") |
| 399 | 401 | public void detachedTupleTypeTest() { |
| 400 | 402 | TupleType detachedType = TupleType.of(TestUtils.getDesiredProtocolVersion(), CodecRegistry.DEFAULT_INSTANCE, |
| 401 | - DataType.cint(), DataType.text(), DataType.cfloat()); | |
| 403 | + DataType.cint(), DataType.text(), DataType.cfloat()); | |
| 402 | 404 | TupleValue detachedValue = detachedType.newValue(1, "hello", 2.0f); |
| 403 | 405 | |
| 404 | 406 | TupleType attachedType = cluster.getMetadata().newTupleType(DataType.cint(), DataType.text(), DataType.cfloat()); |
| @@ -409,6 +411,7 @@ | ||
| 409 | 411 | |
| 410 | 412 | /** |
| 411 | 413 | * Helper method for creating nested tuple schema |
| 414 | + * | |
| 412 | 415 | * @param depth |
| 413 | 416 | * @return |
| 414 | 417 | */ |
| @@ -421,6 +424,7 @@ | ||
| 421 | 424 | |
| 422 | 425 | /** |
| 423 | 426 | * Helper method for creating nested tuples |
| 427 | + * | |
| 424 | 428 | * @param depth |
| 425 | 429 | * @return |
| 426 | 430 | */ |
| @@ -456,9 +460,9 @@ | ||
| 456 | 460 | "v_2 %s, " + |
| 457 | 461 | "v_3 %s, " + |
| 458 | 462 | "v_64 %s)", nestedTuplesSchemaHelper(1), |
| 459 | - nestedTuplesSchemaHelper(2), | |
| 460 | - nestedTuplesSchemaHelper(3), | |
| 461 | - nestedTuplesSchemaHelper(64))); | |
| 463 | + nestedTuplesSchemaHelper(2), | |
| 464 | + nestedTuplesSchemaHelper(3), | |
| 465 | + nestedTuplesSchemaHelper(64))); | |
| 462 | 466 | |
| 463 | 467 | for (int i : Arrays.asList(1, 2, 3, 64)) { |
| 464 | 468 | // create tuple |
| @@ -482,6 +486,7 @@ | ||
| 482 | 486 | /** |
| 483 | 487 | * Test for inserting null Tuple values into UDT's |
| 484 | 488 | * Original code found in python-driver:integration.standard.test_types.py:test_tuples_with_nulls |
| 489 | + * | |
| 485 | 490 | * @throws Exception |
| 486 | 491 | */ |
| 487 | 492 | @Test(groups = "short") |
modified driver-core/src/test/java/com/datastax/driver/core/TypeCodecAssert.java +3 −3
| @@ -67,14 +67,14 @@ | ||
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | public TypeCodecAssert withProtocolVersion(ProtocolVersion version) { |
| 70 | - if(version == null) fail("ProtocolVersion cannot be null"); | |
| 70 | + if (version == null) fail("ProtocolVersion cannot be null"); | |
| 71 | 71 | this.version = version; |
| 72 | 72 | return this; |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | @SuppressWarnings("unchecked") |
| 76 | 76 | public TypeCodecAssert canSerialize(Object value) { |
| 77 | - if(version == null) fail("ProtocolVersion cannot be null"); | |
| 77 | + if (version == null) fail("ProtocolVersion cannot be null"); | |
| 78 | 78 | try { |
| 79 | 79 | assertThat(actual.deserialize(actual.serialize(value, version), version)).isEqualTo(value); |
| 80 | 80 | } catch (Exception e) { |
| @@ -85,7 +85,7 @@ | ||
| 85 | 85 | |
| 86 | 86 | @SuppressWarnings("unchecked") |
| 87 | 87 | public TypeCodecAssert cannotSerialize(Object value) { |
| 88 | - if(version == null) fail("ProtocolVersion cannot be null"); | |
| 88 | + if (version == null) fail("ProtocolVersion cannot be null"); | |
| 89 | 89 | try { |
| 90 | 90 | actual.serialize(value, version); |
| 91 | 91 | fail("Should not have been able to serialize " + value + " with " + actual); |
modified driver-core/src/test/java/com/datastax/driver/core/TypeCodecCollectionsIntegrationTest.java +51 −55
| @@ -15,6 +15,13 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.querybuilder.BuiltStatement; | |
| 19 | +import com.datastax.driver.core.utils.CassandraVersion; | |
| 20 | +import com.google.common.collect.ImmutableMap; | |
| 21 | +import com.google.common.reflect.TypeToken; | |
| 22 | +import org.testng.annotations.BeforeMethod; | |
| 23 | +import org.testng.annotations.Test; | |
| 24 | + | |
| 18 | 25 | import java.math.BigDecimal; |
| 19 | 26 | import java.math.BigInteger; |
| 20 | 27 | import java.util.Collection; |
| @@ -22,24 +29,12 @@ | ||
| 22 | 29 | import java.util.Map; |
| 23 | 30 | import java.util.Set; |
| 24 | 31 | |
| 25 | -import com.google.common.collect.ImmutableMap; | |
| 26 | -import com.google.common.reflect.TypeToken; | |
| 27 | -import org.testng.annotations.BeforeMethod; | |
| 28 | -import org.testng.annotations.Test; | |
| 29 | - | |
| 32 | +import static com.datastax.driver.core.querybuilder.QueryBuilder.*; | |
| 30 | 33 | import static com.google.common.collect.Lists.newArrayList; |
| 31 | 34 | import static com.google.common.collect.Sets.newHashSet; |
| 32 | 35 | import static org.assertj.core.api.Assertions.assertThat; |
| 33 | 36 | |
| 34 | -import com.datastax.driver.core.querybuilder.BuiltStatement; | |
| 35 | -import com.datastax.driver.core.utils.CassandraVersion; | |
| 36 | - | |
| 37 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.bindMarker; | |
| 38 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; | |
| 39 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.insertInto; | |
| 40 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.select; | |
| 41 | - | |
| 42 | -@CassandraVersion(major=2.0) | |
| 37 | +@CassandraVersion(major = 2.0) | |
| 43 | 38 | public class TypeCodecCollectionsIntegrationTest extends CCMBridge.PerClassSingleNodeCluster { |
| 44 | 39 | |
| 45 | 40 | private final String insertQuery = "INSERT INTO \"myTable2\" (c_int, l_int, l_bigint, s_float, s_double, m_varint, m_decimal) VALUES (?, ?, ?, ?, ?, ?, ?)"; |
| @@ -60,30 +55,30 @@ | ||
| 60 | 55 | @Override |
| 61 | 56 | protected Collection<String> getTableDefinitions() { |
| 62 | 57 | return newArrayList( |
| 63 | - "CREATE TABLE IF NOT EXISTS \"myTable2\" (" | |
| 64 | - + "c_int int PRIMARY KEY, " | |
| 65 | - + "l_int list<int>, " | |
| 66 | - + "l_bigint list<bigint>, " | |
| 67 | - + "s_float set<float>, " | |
| 68 | - + "s_double set<double>, " | |
| 69 | - + "m_varint map<int,varint>, " | |
| 70 | - + "m_decimal map<int,decimal>" | |
| 71 | - + ")"); | |
| 58 | + "CREATE TABLE IF NOT EXISTS \"myTable2\" (" | |
| 59 | + + "c_int int PRIMARY KEY, " | |
| 60 | + + "l_int list<int>, " | |
| 61 | + + "l_bigint list<bigint>, " | |
| 62 | + + "s_float set<float>, " | |
| 63 | + + "s_double set<double>, " | |
| 64 | + + "m_varint map<int,varint>, " | |
| 65 | + + "m_decimal map<int,decimal>" | |
| 66 | + + ")"); | |
| 72 | 67 | } |
| 73 | 68 | |
| 74 | 69 | @BeforeMethod(groups = "short") |
| 75 | 70 | public void createBuiltStatements() throws Exception { |
| 76 | 71 | insertStmt = insertInto("\"myTable2\"") |
| 77 | - .value("c_int", bindMarker()) | |
| 78 | - .value("l_int", bindMarker()) | |
| 79 | - .value("l_bigint", bindMarker()) | |
| 80 | - .value("s_float", bindMarker()) | |
| 81 | - .value("s_double", bindMarker()) | |
| 82 | - .value("m_varint", bindMarker()) | |
| 83 | - .value("m_decimal", bindMarker()); | |
| 72 | + .value("c_int", bindMarker()) | |
| 73 | + .value("l_int", bindMarker()) | |
| 74 | + .value("l_bigint", bindMarker()) | |
| 75 | + .value("s_float", bindMarker()) | |
| 76 | + .value("s_double", bindMarker()) | |
| 77 | + .value("m_varint", bindMarker()) | |
| 78 | + .value("m_decimal", bindMarker()); | |
| 84 | 79 | selectStmt = select("c_int", "l_int", "l_bigint", "s_float", "s_double", "m_varint", "m_decimal") |
| 85 | - .from("\"myTable2\"") | |
| 86 | - .where(eq("c_int", bindMarker())); | |
| 80 | + .from("\"myTable2\"") | |
| 81 | + .where(eq("c_int", bindMarker())); | |
| 87 | 82 | } |
| 88 | 83 | |
| 89 | 84 | @Test(groups = "short") |
| @@ -106,17 +101,17 @@ | ||
| 106 | 101 | @Test(groups = "short") |
| 107 | 102 | public void should_use_collection_codecs_with_prepared_statements_2() { |
| 108 | 103 | session.execute(session.prepare(insertQuery).bind() |
| 109 | - .setInt(0, n_int) | |
| 110 | - .setList(1, l_int) | |
| 111 | - .setList(2, l_bigint, Long.class) // variant with element type explicitly set | |
| 112 | - .setSet(3, s_float) | |
| 113 | - .setSet(4, s_double, TypeToken.of(Double.class)) // variant with element type explicitly set | |
| 114 | - .setMap(5, m_varint) | |
| 115 | - .setMap(6, m_decimal, Integer.class, BigDecimal.class) // variant with element type explicitly set | |
| 104 | + .setInt(0, n_int) | |
| 105 | + .setList(1, l_int) | |
| 106 | + .setList(2, l_bigint, Long.class) // variant with element type explicitly set | |
| 107 | + .setSet(3, s_float) | |
| 108 | + .setSet(4, s_double, TypeToken.of(Double.class)) // variant with element type explicitly set | |
| 109 | + .setMap(5, m_varint) | |
| 110 | + .setMap(6, m_decimal, Integer.class, BigDecimal.class) // variant with element type explicitly set | |
| 116 | 111 | ); |
| 117 | 112 | PreparedStatement ps = session.prepare(selectQuery); |
| 118 | 113 | ResultSet rows = session.execute(ps.bind() |
| 119 | - .setInt(0, n_int) | |
| 114 | + .setInt(0, n_int) | |
| 120 | 115 | ); |
| 121 | 116 | Row row = rows.one(); |
| 122 | 117 | assertRow(row); |
| @@ -125,13 +120,13 @@ | ||
| 125 | 120 | @Test(groups = "short") |
| 126 | 121 | public void should_use_collection_codecs_with_prepared_statements_3() { |
| 127 | 122 | session.execute(session.prepare(insertQuery).bind() |
| 128 | - .setInt(0, n_int) | |
| 129 | - .set(1, l_int, TypeTokens.listOf(Integer.class)) | |
| 130 | - .set(2, l_bigint, TypeTokens.listOf(Long.class)) | |
| 131 | - .set(3, s_float, TypeTokens.setOf(Float.class)) | |
| 132 | - .set(4, s_double, TypeTokens.setOf(Double.class)) | |
| 133 | - .set(5, m_varint, TypeTokens.mapOf(Integer.class, BigInteger.class)) | |
| 134 | - .set(6, m_decimal, TypeTokens.mapOf(Integer.class, BigDecimal.class)) | |
| 123 | + .setInt(0, n_int) | |
| 124 | + .set(1, l_int, TypeTokens.listOf(Integer.class)) | |
| 125 | + .set(2, l_bigint, TypeTokens.listOf(Long.class)) | |
| 126 | + .set(3, s_float, TypeTokens.setOf(Float.class)) | |
| 127 | + .set(4, s_double, TypeTokens.setOf(Double.class)) | |
| 128 | + .set(5, m_varint, TypeTokens.mapOf(Integer.class, BigInteger.class)) | |
| 129 | + .set(6, m_decimal, TypeTokens.mapOf(Integer.class, BigDecimal.class)) | |
| 135 | 130 | ); |
| 136 | 131 | PreparedStatement ps = session.prepare(selectQuery); |
| 137 | 132 | ResultSet rows = session.execute(ps.bind() |
| @@ -144,21 +139,22 @@ | ||
| 144 | 139 | @Test(groups = "short") |
| 145 | 140 | public void should_use_collection_codecs_with_built_statements() { |
| 146 | 141 | session.execute(session.prepare(insertStmt).bind() |
| 147 | - .setInt(0, n_int) | |
| 148 | - .set(1, l_int, TypeTokens.listOf(Integer.class)) | |
| 149 | - .set(2, l_bigint, TypeTokens.listOf(Long.class)) | |
| 150 | - .set(3, s_float, TypeTokens.setOf(Float.class)) | |
| 151 | - .set(4, s_double, TypeTokens.setOf(Double.class)) | |
| 152 | - .set(5, m_varint, TypeTokens.mapOf(Integer.class, BigInteger.class)) | |
| 153 | - .set(6, m_decimal, TypeTokens.mapOf(Integer.class, BigDecimal.class)) | |
| 142 | + .setInt(0, n_int) | |
| 143 | + .set(1, l_int, TypeTokens.listOf(Integer.class)) | |
| 144 | + .set(2, l_bigint, TypeTokens.listOf(Long.class)) | |
| 145 | + .set(3, s_float, TypeTokens.setOf(Float.class)) | |
| 146 | + .set(4, s_double, TypeTokens.setOf(Double.class)) | |
| 147 | + .set(5, m_varint, TypeTokens.mapOf(Integer.class, BigInteger.class)) | |
| 148 | + .set(6, m_decimal, TypeTokens.mapOf(Integer.class, BigDecimal.class)) | |
| 154 | 149 | ); |
| 155 | 150 | PreparedStatement ps = session.prepare(selectStmt); |
| 156 | 151 | ResultSet rows = session.execute(ps.bind() |
| 157 | - .setInt(0, n_int) | |
| 152 | + .setInt(0, n_int) | |
| 158 | 153 | ); |
| 159 | 154 | Row row = rows.one(); |
| 160 | 155 | assertRow(row); |
| 161 | 156 | } |
| 157 | + | |
| 162 | 158 | private void assertRow(Row row) { |
| 163 | 159 | assertThat(row.getInt(0)).isEqualTo(n_int); |
| 164 | 160 | assertThat(row.getList(1, Integer.class)).isEqualTo(l_int); |
modified driver-core/src/test/java/com/datastax/driver/core/TypeCodecEncapsulationIntegrationTest.java +104 −85
| @@ -15,29 +15,24 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.math.BigDecimal; | |
| 19 | -import java.math.BigInteger; | |
| 20 | -import java.nio.ByteBuffer; | |
| 21 | -import java.util.Collection; | |
| 22 | - | |
| 18 | +import com.datastax.driver.core.exceptions.InvalidTypeException; | |
| 19 | +import com.datastax.driver.core.querybuilder.BuiltStatement; | |
| 20 | +import com.datastax.driver.core.utils.CassandraVersion; | |
| 23 | 21 | import com.google.common.base.Objects; |
| 24 | 22 | import com.google.common.reflect.TypeParameter; |
| 25 | 23 | import com.google.common.reflect.TypeToken; |
| 26 | 24 | import org.testng.annotations.BeforeMethod; |
| 27 | 25 | import org.testng.annotations.Test; |
| 28 | 26 | |
| 27 | +import java.math.BigDecimal; | |
| 28 | +import java.math.BigInteger; | |
| 29 | +import java.nio.ByteBuffer; | |
| 30 | +import java.util.Collection; | |
| 31 | + | |
| 32 | +import static com.datastax.driver.core.querybuilder.QueryBuilder.*; | |
| 29 | 33 | import static com.google.common.collect.Lists.newArrayList; |
| 30 | 34 | import static org.assertj.core.api.Assertions.assertThat; |
| 31 | 35 | |
| 32 | -import com.datastax.driver.core.exceptions.InvalidTypeException; | |
| 33 | -import com.datastax.driver.core.querybuilder.BuiltStatement; | |
| 34 | -import com.datastax.driver.core.utils.CassandraVersion; | |
| 35 | - | |
| 36 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.bindMarker; | |
| 37 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; | |
| 38 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.insertInto; | |
| 39 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.select; | |
| 40 | - | |
| 41 | 36 | public class TypeCodecEncapsulationIntegrationTest extends CCMBridge.PerClassSingleNodeCluster { |
| 42 | 37 | |
| 43 | 38 | private final String insertQuery = "INSERT INTO \"myTable\" (c_int, c_bigint, c_float, c_double, c_varint, c_decimal) VALUES (?, ?, ?, ?, ?, ?)"; |
| @@ -57,58 +52,58 @@ | ||
| 57 | 52 | @Override |
| 58 | 53 | protected Collection<String> getTableDefinitions() { |
| 59 | 54 | return newArrayList( |
| 60 | - "CREATE TABLE \"myTable\" (" | |
| 61 | - + "c_int int, " | |
| 62 | - + "c_bigint bigint, " | |
| 63 | - + "c_float float, " | |
| 64 | - + "c_double double, " | |
| 65 | - + "c_varint varint, " | |
| 66 | - + "c_decimal decimal, " | |
| 67 | - + "PRIMARY KEY (c_int, c_bigint)" | |
| 68 | - + ")" | |
| 55 | + "CREATE TABLE \"myTable\" (" | |
| 56 | + + "c_int int, " | |
| 57 | + + "c_bigint bigint, " | |
| 58 | + + "c_float float, " | |
| 59 | + + "c_double double, " | |
| 60 | + + "c_varint varint, " | |
| 61 | + + "c_decimal decimal, " | |
| 62 | + + "PRIMARY KEY (c_int, c_bigint)" | |
| 63 | + + ")" | |
| 69 | 64 | ); |
| 70 | 65 | } |
| 71 | 66 | |
| 72 | 67 | @Override |
| 73 | 68 | protected Cluster.Builder configure(Cluster.Builder builder) { |
| 74 | 69 | return builder.withCodecRegistry( |
| 75 | - new CodecRegistry() | |
| 76 | - .register( | |
| 77 | - new NumberBoxCodec<Integer>(TypeCodec.cint()), | |
| 78 | - new NumberBoxCodec<Long>(TypeCodec.bigint()), | |
| 79 | - new NumberBoxCodec<Float>(TypeCodec.cfloat()), | |
| 80 | - new NumberBoxCodec<Double>(TypeCodec.cdouble()), | |
| 81 | - new NumberBoxCodec<BigInteger>(TypeCodec.varint()), | |
| 82 | - new NumberBoxCodec<BigDecimal>(TypeCodec.decimal()) | |
| 83 | - ) | |
| 70 | + new CodecRegistry() | |
| 71 | + .register( | |
| 72 | + new NumberBoxCodec<Integer>(TypeCodec.cint()), | |
| 73 | + new NumberBoxCodec<Long>(TypeCodec.bigint()), | |
| 74 | + new NumberBoxCodec<Float>(TypeCodec.cfloat()), | |
| 75 | + new NumberBoxCodec<Double>(TypeCodec.cdouble()), | |
| 76 | + new NumberBoxCodec<BigInteger>(TypeCodec.varint()), | |
| 77 | + new NumberBoxCodec<BigDecimal>(TypeCodec.decimal()) | |
| 78 | + ) | |
| 84 | 79 | ); |
| 85 | 80 | } |
| 86 | 81 | |
| 87 | 82 | @BeforeMethod(groups = "short") |
| 88 | 83 | public void createBuiltStatements() throws Exception { |
| 89 | 84 | insertStmt = insertInto("\"myTable\"") |
| 90 | - .value("c_int", bindMarker()) | |
| 91 | - .value("c_bigint", bindMarker()) | |
| 92 | - .value("c_float", bindMarker()) | |
| 93 | - .value("c_double", bindMarker()) | |
| 94 | - .value("c_varint", bindMarker()) | |
| 95 | - .value("c_decimal", bindMarker()); | |
| 85 | + .value("c_int", bindMarker()) | |
| 86 | + .value("c_bigint", bindMarker()) | |
| 87 | + .value("c_float", bindMarker()) | |
| 88 | + .value("c_double", bindMarker()) | |
| 89 | + .value("c_varint", bindMarker()) | |
| 90 | + .value("c_decimal", bindMarker()); | |
| 96 | 91 | selectStmt = select("c_int", "c_bigint", "c_float", "c_double", "c_varint", "c_decimal") |
| 97 | - .from("\"myTable\"") | |
| 98 | - .where(eq("c_int", bindMarker())) | |
| 99 | - .and(eq("c_bigint", bindMarker())); | |
| 92 | + .from("\"myTable\"") | |
| 93 | + .where(eq("c_int", bindMarker())) | |
| 94 | + .and(eq("c_bigint", bindMarker())); | |
| 100 | 95 | } |
| 101 | 96 | |
| 102 | 97 | @Test(groups = "short") |
| 103 | - @CassandraVersion(major=2.0) | |
| 98 | + @CassandraVersion(major = 2.0) | |
| 104 | 99 | public void should_use_custom_codecs_with_simple_statements() { |
| 105 | 100 | session.execute(insertQuery, |
| 106 | - n_int, | |
| 107 | - new NumberBox<Long>(n_bigint), | |
| 108 | - new NumberBox<Float>(n_float), | |
| 109 | - new NumberBox<Double>(n_double), | |
| 110 | - new NumberBox<BigInteger>(n_varint), | |
| 111 | - new NumberBox<BigDecimal>(n_decimal)); | |
| 101 | + n_int, | |
| 102 | + new NumberBox<Long>(n_bigint), | |
| 103 | + new NumberBox<Float>(n_float), | |
| 104 | + new NumberBox<Double>(n_double), | |
| 105 | + new NumberBox<BigInteger>(n_varint), | |
| 106 | + new NumberBox<BigDecimal>(n_decimal)); | |
| 112 | 107 | ResultSet rows = session.execute(selectQuery, n_int, new NumberBox<Long>(n_bigint)); |
| 113 | 108 | Row row = rows.one(); |
| 114 | 109 | assertRow(row); |
| @@ -117,12 +112,12 @@ | ||
| 117 | 112 | @Test(groups = "short") |
| 118 | 113 | public void should_use_custom_codecs_with_prepared_statements_1() { |
| 119 | 114 | session.execute(session.prepare(insertQuery).bind( |
| 120 | - n_int, | |
| 121 | - new NumberBox<Long>(n_bigint), | |
| 122 | - new NumberBox<Float>(n_float), | |
| 123 | - new NumberBox<Double>(n_double), | |
| 124 | - new NumberBox<BigInteger>(n_varint), | |
| 125 | - new NumberBox<BigDecimal>(n_decimal))); | |
| 115 | + n_int, | |
| 116 | + new NumberBox<Long>(n_bigint), | |
| 117 | + new NumberBox<Float>(n_float), | |
| 118 | + new NumberBox<Double>(n_double), | |
| 119 | + new NumberBox<BigInteger>(n_varint), | |
| 120 | + new NumberBox<BigDecimal>(n_decimal))); | |
| 126 | 121 | PreparedStatement ps = session.prepare(selectQuery); |
| 127 | 122 | ResultSet rows = session.execute(ps.bind(n_int, new NumberBox<Long>(n_bigint))); |
| 128 | 123 | Row row = rows.one(); |
| @@ -132,17 +127,25 @@ | ||
| 132 | 127 | @Test(groups = "short") |
| 133 | 128 | public void should_use_custom_codecs_with_prepared_statements_2() { |
| 134 | 129 | session.execute(session.prepare(insertQuery).bind() |
| 135 | - .set(0, new NumberBox<Integer>(n_int), new TypeToken<NumberBox<Integer>>() {}) | |
| 136 | - .set(1, new NumberBox<Long>(n_bigint), new TypeToken<NumberBox<Long>>() {}) | |
| 137 | - .set(2, new NumberBox<Float>(n_float), new TypeToken<NumberBox<Float>>() {}) | |
| 138 | - .set(3, new NumberBox<Double>(n_double), new TypeToken<NumberBox<Double>>() {}) | |
| 139 | - .set(4, new NumberBox<BigInteger>(n_varint), new TypeToken<NumberBox<BigInteger>>() {}) | |
| 140 | - .set(5, new NumberBox<BigDecimal>(n_decimal), new TypeToken<NumberBox<BigDecimal>>() {}) | |
| 130 | + .set(0, new NumberBox<Integer>(n_int), new TypeToken<NumberBox<Integer>>() { | |
| 131 | + }) | |
| 132 | + .set(1, new NumberBox<Long>(n_bigint), new TypeToken<NumberBox<Long>>() { | |
| 133 | + }) | |
| 134 | + .set(2, new NumberBox<Float>(n_float), new TypeToken<NumberBox<Float>>() { | |
| 135 | + }) | |
| 136 | + .set(3, new NumberBox<Double>(n_double), new TypeToken<NumberBox<Double>>() { | |
| 137 | + }) | |
| 138 | + .set(4, new NumberBox<BigInteger>(n_varint), new TypeToken<NumberBox<BigInteger>>() { | |
| 139 | + }) | |
| 140 | + .set(5, new NumberBox<BigDecimal>(n_decimal), new TypeToken<NumberBox<BigDecimal>>() { | |
| 141 | + }) | |
| 141 | 142 | ); |
| 142 | 143 | PreparedStatement ps = session.prepare(selectQuery); |
| 143 | 144 | ResultSet rows = session.execute(ps.bind() |
| 144 | - .set(0, new NumberBox<Integer>(n_int), new TypeToken<NumberBox<Integer>>() {}) | |
| 145 | - .set(1, new NumberBox<Long>(n_bigint), new TypeToken<NumberBox<Long>>() {}) | |
| 145 | + .set(0, new NumberBox<Integer>(n_int), new TypeToken<NumberBox<Integer>>() { | |
| 146 | + }) | |
| 147 | + .set(1, new NumberBox<Long>(n_bigint), new TypeToken<NumberBox<Long>>() { | |
| 148 | + }) | |
| 146 | 149 | ); |
| 147 | 150 | Row row = rows.one(); |
| 148 | 151 | assertRow(row); |
| @@ -151,12 +154,12 @@ | ||
| 151 | 154 | @Test(groups = "short") |
| 152 | 155 | public void should_use_custom_codecs_with_built_statements_1() { |
| 153 | 156 | session.execute(session.prepare(insertStmt).bind( |
| 154 | - n_int, | |
| 155 | - new NumberBox<Long>(n_bigint), | |
| 156 | - new NumberBox<Float>(n_float), | |
| 157 | - new NumberBox<Double>(n_double), | |
| 158 | - new NumberBox<BigInteger>(n_varint), | |
| 159 | - new NumberBox<BigDecimal>(n_decimal))); | |
| 157 | + n_int, | |
| 158 | + new NumberBox<Long>(n_bigint), | |
| 159 | + new NumberBox<Float>(n_float), | |
| 160 | + new NumberBox<Double>(n_double), | |
| 161 | + new NumberBox<BigInteger>(n_varint), | |
| 162 | + new NumberBox<BigDecimal>(n_decimal))); | |
| 160 | 163 | PreparedStatement ps = session.prepare(selectStmt); |
| 161 | 164 | ResultSet rows = session.execute(ps.bind(n_int, new NumberBox<Long>(n_bigint))); |
| 162 | 165 | Row row = rows.one(); |
| @@ -166,17 +169,25 @@ | ||
| 166 | 169 | @Test(groups = "short") |
| 167 | 170 | public void should_use_custom_codecs_with_built_statements_2() { |
| 168 | 171 | session.execute(session.prepare(insertStmt).bind() |
| 169 | - .set(0, new NumberBox<Integer>(n_int), new TypeToken<NumberBox<Integer>>() {}) | |
| 170 | - .set(1, new NumberBox<Long>(n_bigint), new TypeToken<NumberBox<Long>>() {}) | |
| 171 | - .set(2, new NumberBox<Float>(n_float), new TypeToken<NumberBox<Float>>() {}) | |
| 172 | - .set(3, new NumberBox<Double>(n_double), new TypeToken<NumberBox<Double>>() {}) | |
| 173 | - .set(4, new NumberBox<BigInteger>(n_varint), new TypeToken<NumberBox<BigInteger>>() {}) | |
| 174 | - .set(5, new NumberBox<BigDecimal>(n_decimal), new TypeToken<NumberBox<BigDecimal>>() {}) | |
| 172 | + .set(0, new NumberBox<Integer>(n_int), new TypeToken<NumberBox<Integer>>() { | |
| 173 | + }) | |
| 174 | + .set(1, new NumberBox<Long>(n_bigint), new TypeToken<NumberBox<Long>>() { | |
| 175 | + }) | |
| 176 | + .set(2, new NumberBox<Float>(n_float), new TypeToken<NumberBox<Float>>() { | |
| 177 | + }) | |
| 178 | + .set(3, new NumberBox<Double>(n_double), new TypeToken<NumberBox<Double>>() { | |
| 179 | + }) | |
| 180 | + .set(4, new NumberBox<BigInteger>(n_varint), new TypeToken<NumberBox<BigInteger>>() { | |
| 181 | + }) | |
| 182 | + .set(5, new NumberBox<BigDecimal>(n_decimal), new TypeToken<NumberBox<BigDecimal>>() { | |
| 183 | + }) | |
| 175 | 184 | ); |
| 176 | 185 | PreparedStatement ps = session.prepare(selectStmt); |
| 177 | 186 | ResultSet rows = session.execute(ps.bind() |
| 178 | - .set(0, new NumberBox<Integer>(n_int), new TypeToken<NumberBox<Integer>>() {}) | |
| 179 | - .set(1, new NumberBox<Long>(n_bigint), new TypeToken<NumberBox<Long>>() {}) | |
| 187 | + .set(0, new NumberBox<Integer>(n_int), new TypeToken<NumberBox<Integer>>() { | |
| 188 | + }) | |
| 189 | + .set(1, new NumberBox<Long>(n_bigint), new TypeToken<NumberBox<Long>>() { | |
| 190 | + }) | |
| 180 | 191 | ); |
| 181 | 192 | Row row = rows.one(); |
| 182 | 193 | assertRow(row); |
| @@ -208,12 +219,18 @@ | ||
| 208 | 219 | assertThat(row.get(5, BigDecimal.class)).isEqualTo(n_decimal); |
| 209 | 220 | // with get + type, but enforcing NumberBox types |
| 210 | 221 | // we get the NumberBox codecs instead |
| 211 | - assertThat(row.get(0, new TypeToken<NumberBox<Integer>>() {})).isEqualTo(new NumberBox<Integer>(n_int)); | |
| 212 | - assertThat(row.get(1, new TypeToken<NumberBox<Long>>() {})).isEqualTo(new NumberBox<Long>(n_bigint)); | |
| 213 | - assertThat(row.get(2, new TypeToken<NumberBox<Float>>() {})).isEqualTo(new NumberBox<Float>(n_float)); | |
| 214 | - assertThat(row.get(3, new TypeToken<NumberBox<Double>>() {})).isEqualTo(new NumberBox<Double>(n_double)); | |
| 215 | - assertThat(row.get(4, new TypeToken<NumberBox<BigInteger>>() {})).isEqualTo(new NumberBox<BigInteger>(n_varint)); | |
| 216 | - assertThat(row.get(5, new TypeToken<NumberBox<BigDecimal>>() {})).isEqualTo(new NumberBox<BigDecimal>(n_decimal)); | |
| 222 | + assertThat(row.get(0, new TypeToken<NumberBox<Integer>>() { | |
| 223 | + })).isEqualTo(new NumberBox<Integer>(n_int)); | |
| 224 | + assertThat(row.get(1, new TypeToken<NumberBox<Long>>() { | |
| 225 | + })).isEqualTo(new NumberBox<Long>(n_bigint)); | |
| 226 | + assertThat(row.get(2, new TypeToken<NumberBox<Float>>() { | |
| 227 | + })).isEqualTo(new NumberBox<Float>(n_float)); | |
| 228 | + assertThat(row.get(3, new TypeToken<NumberBox<Double>>() { | |
| 229 | + })).isEqualTo(new NumberBox<Double>(n_double)); | |
| 230 | + assertThat(row.get(4, new TypeToken<NumberBox<BigInteger>>() { | |
| 231 | + })).isEqualTo(new NumberBox<BigInteger>(n_varint)); | |
| 232 | + assertThat(row.get(5, new TypeToken<NumberBox<BigDecimal>>() { | |
| 233 | + })).isEqualTo(new NumberBox<BigDecimal>(n_decimal)); | |
| 217 | 234 | } |
| 218 | 235 | |
| 219 | 236 | private class NumberBoxCodec<T extends Number> extends TypeCodec<NumberBox<T>> { |
| @@ -221,12 +238,14 @@ | ||
| 221 | 238 | private final TypeCodec<T> numberCodec; |
| 222 | 239 | |
| 223 | 240 | protected NumberBoxCodec(TypeCodec<T> numberCodec) { |
| 224 | - super(numberCodec.getCqlType(), new TypeToken<NumberBox<T>>(){}.where(new TypeParameter<T>(){}, numberCodec.getJavaType())); | |
| 241 | + super(numberCodec.getCqlType(), new TypeToken<NumberBox<T>>() { | |
| 242 | + }.where(new TypeParameter<T>() { | |
| 243 | + }, numberCodec.getJavaType())); | |
| 225 | 244 | this.numberCodec = numberCodec; |
| 226 | 245 | } |
| 227 | 246 | |
| 228 | 247 | public boolean accepts(Object value) { |
| 229 | - return value instanceof NumberBox && numberCodec.accepts(((NumberBox)value).getNumber()); | |
| 248 | + return value instanceof NumberBox && numberCodec.accepts(((NumberBox) value).getNumber()); | |
| 230 | 249 | } |
| 231 | 250 | |
| 232 | 251 | @Override |
| @@ -269,7 +288,7 @@ | ||
| 269 | 288 | return true; |
| 270 | 289 | if (o == null || getClass() != o.getClass()) |
| 271 | 290 | return false; |
| 272 | - NumberBox numberBox = (NumberBox)o; | |
| 291 | + NumberBox numberBox = (NumberBox) o; | |
| 273 | 292 | return Objects.equal(number, numberBox.number); |
| 274 | 293 | } |
| 275 | 294 |
modified driver-core/src/test/java/com/datastax/driver/core/TypeCodecNestedCollectionsIntegrationTest.java +31 −34
| @@ -15,9 +15,9 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.nio.ByteBuffer; | |
| 19 | -import java.util.*; | |
| 20 | - | |
| 18 | +import com.datastax.driver.core.exceptions.InvalidTypeException; | |
| 19 | +import com.datastax.driver.core.querybuilder.BuiltStatement; | |
| 20 | +import com.datastax.driver.core.utils.CassandraVersion; | |
| 21 | 21 | import com.google.common.base.Objects; |
| 22 | 22 | import com.google.common.collect.ImmutableMap; |
| 23 | 23 | import com.google.common.reflect.TypeToken; |
| @@ -25,23 +25,18 @@ | ||
| 25 | 25 | import org.testng.annotations.BeforeMethod; |
| 26 | 26 | import org.testng.annotations.Test; |
| 27 | 27 | |
| 28 | +import java.nio.ByteBuffer; | |
| 29 | +import java.util.*; | |
| 30 | + | |
| 31 | +import static com.datastax.driver.core.querybuilder.QueryBuilder.*; | |
| 28 | 32 | import static com.google.common.collect.Lists.newArrayList; |
| 29 | 33 | import static org.assertj.core.api.Assertions.assertThat; |
| 30 | 34 | |
| 31 | -import com.datastax.driver.core.exceptions.InvalidTypeException; | |
| 32 | -import com.datastax.driver.core.querybuilder.BuiltStatement; | |
| 33 | -import com.datastax.driver.core.utils.CassandraVersion; | |
| 34 | - | |
| 35 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.bindMarker; | |
| 36 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; | |
| 37 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.insertInto; | |
| 38 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.select; | |
| 39 | - | |
| 40 | 35 | /** |
| 41 | 36 | * Validates that nested collections are properly encoded, |
| 42 | 37 | * even if some inner type requires a custom codec. |
| 43 | 38 | */ |
| 44 | -@CassandraVersion(major=2.1) | |
| 39 | +@CassandraVersion(major = 2.1) | |
| 45 | 40 | public class TypeCodecNestedCollectionsIntegrationTest extends CCMBridge.PerClassSingleNodeCluster { |
| 46 | 41 | |
| 47 | 42 | private final String insertQuery = "INSERT INTO \"myTable\" (pk, v) VALUES (?, ?)"; |
| @@ -54,23 +49,25 @@ | ||
| 54 | 49 | private int pk = 42; |
| 55 | 50 | private List<Set<Map<MyInt, String>>> v; |
| 56 | 51 | |
| 57 | - private TypeToken<List<Set<Map<MyInt, String>>>> listType = new TypeToken<List<Set<Map<MyInt, String>>>>(){}; | |
| 58 | - private TypeToken<Set<Map<MyInt, String>>> elementsType = new TypeToken<Set<Map<MyInt, String>>>(){}; | |
| 52 | + private TypeToken<List<Set<Map<MyInt, String>>>> listType = new TypeToken<List<Set<Map<MyInt, String>>>>() { | |
| 53 | + }; | |
| 54 | + private TypeToken<Set<Map<MyInt, String>>> elementsType = new TypeToken<Set<Map<MyInt, String>>>() { | |
| 55 | + }; | |
| 59 | 56 | |
| 60 | 57 | @Override |
| 61 | 58 | protected Collection<String> getTableDefinitions() { |
| 62 | 59 | return newArrayList( |
| 63 | - "CREATE TABLE IF NOT EXISTS \"myTable\" (" | |
| 64 | - + "pk int PRIMARY KEY, " | |
| 65 | - + "v frozen<list<frozen<set<frozen<map<int,text>>>>>>" | |
| 66 | - + ")" | |
| 60 | + "CREATE TABLE IF NOT EXISTS \"myTable\" (" | |
| 61 | + + "pk int PRIMARY KEY, " | |
| 62 | + + "v frozen<list<frozen<set<frozen<map<int,text>>>>>>" | |
| 63 | + + ")" | |
| 67 | 64 | ); |
| 68 | 65 | } |
| 69 | 66 | |
| 70 | 67 | @Override |
| 71 | 68 | protected Cluster.Builder configure(Cluster.Builder builder) { |
| 72 | 69 | return builder.withCodecRegistry( |
| 73 | - new CodecRegistry().register(new MyIntCodec()) // global User <-> varchar codec | |
| 70 | + new CodecRegistry().register(new MyIntCodec()) // global User <-> varchar codec | |
| 74 | 71 | ); |
| 75 | 72 | } |
| 76 | 73 | |
| @@ -86,11 +83,11 @@ | ||
| 86 | 83 | @BeforeMethod(groups = "short") |
| 87 | 84 | public void createBuiltStatements() throws Exception { |
| 88 | 85 | insertStmt = insertInto("\"myTable\"") |
| 89 | - .value("pk", bindMarker()) | |
| 90 | - .value("v", bindMarker()); | |
| 86 | + .value("pk", bindMarker()) | |
| 87 | + .value("v", bindMarker()); | |
| 91 | 88 | selectStmt = select("pk", "v") |
| 92 | - .from("\"myTable\"") | |
| 93 | - .where(eq("pk", bindMarker())); | |
| 89 | + .from("\"myTable\"") | |
| 90 | + .where(eq("pk", bindMarker())); | |
| 94 | 91 | } |
| 95 | 92 | |
| 96 | 93 | @Test(groups = "short") |
| @@ -113,12 +110,12 @@ | ||
| 113 | 110 | @Test(groups = "short") |
| 114 | 111 | public void should_work_with_prepared_statements_2() { |
| 115 | 112 | session.execute(session.prepare(insertQuery).bind() |
| 116 | - .setInt(0, pk) | |
| 117 | - .setList(1, v, elementsType) // variant with element type explicitly set | |
| 113 | + .setInt(0, pk) | |
| 114 | + .setList(1, v, elementsType) // variant with element type explicitly set | |
| 118 | 115 | ); |
| 119 | 116 | PreparedStatement ps = session.prepare(selectQuery); |
| 120 | 117 | ResultSet rows = session.execute(ps.bind() |
| 121 | - .setInt(0, pk) | |
| 118 | + .setInt(0, pk) | |
| 122 | 119 | ); |
| 123 | 120 | Row row = rows.one(); |
| 124 | 121 | assertRow(row); |
| @@ -127,12 +124,12 @@ | ||
| 127 | 124 | @Test(groups = "short") |
| 128 | 125 | public void should_work_with_prepared_statements_3() { |
| 129 | 126 | session.execute(session.prepare(insertQuery).bind() |
| 130 | - .setInt(0, pk) | |
| 131 | - .set(1, v, listType) | |
| 127 | + .setInt(0, pk) | |
| 128 | + .set(1, v, listType) | |
| 132 | 129 | ); |
| 133 | 130 | PreparedStatement ps = session.prepare(selectQuery); |
| 134 | 131 | ResultSet rows = session.execute(ps.bind() |
| 135 | - .setInt(0, pk) | |
| 132 | + .setInt(0, pk) | |
| 136 | 133 | ); |
| 137 | 134 | Row row = rows.one(); |
| 138 | 135 | assertRow(row); |
| @@ -141,12 +138,12 @@ | ||
| 141 | 138 | @Test(groups = "short") |
| 142 | 139 | public void should_work_with_built_statements() { |
| 143 | 140 | session.execute(session.prepare(insertStmt).bind() |
| 144 | - .setInt(0, pk) | |
| 145 | - .set(1, v, listType) | |
| 141 | + .setInt(0, pk) | |
| 142 | + .set(1, v, listType) | |
| 146 | 143 | ); |
| 147 | 144 | PreparedStatement ps = session.prepare(selectStmt); |
| 148 | 145 | ResultSet rows = session.execute(ps.bind() |
| 149 | - .setInt(0, pk) | |
| 146 | + .setInt(0, pk) | |
| 150 | 147 | ); |
| 151 | 148 | Row row = rows.one(); |
| 152 | 149 | assertRow(row); |
| @@ -171,7 +168,7 @@ | ||
| 171 | 168 | return true; |
| 172 | 169 | if (o == null || getClass() != o.getClass()) |
| 173 | 170 | return false; |
| 174 | - MyInt myInt = (MyInt)o; | |
| 171 | + MyInt myInt = (MyInt) o; | |
| 175 | 172 | return Objects.equal(i, myInt.i); |
| 176 | 173 | } |
| 177 | 174 |
modified driver-core/src/test/java/com/datastax/driver/core/TypeCodecNestedUDTAndTupleIntegrationTest.java +17 −19
| @@ -15,15 +15,13 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.util.*; | |
| 19 | - | |
| 18 | +import com.datastax.driver.core.utils.CassandraVersion; | |
| 20 | 19 | import com.google.common.collect.Lists; |
| 21 | -import com.google.common.collect.Sets; | |
| 22 | 20 | import org.testng.annotations.Test; |
| 23 | 21 | |
| 24 | -import static org.assertj.core.api.Assertions.assertThat; | |
| 22 | +import java.util.Collection; | |
| 25 | 23 | |
| 26 | -import com.datastax.driver.core.utils.CassandraVersion; | |
| 24 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 27 | 25 | |
| 28 | 26 | /** |
| 29 | 27 | * This tests that the CodecRegistry is able to create codecs on the fly |
| @@ -39,20 +37,20 @@ | ||
| 39 | 37 | @Override |
| 40 | 38 | protected Collection<String> getTableDefinitions() { |
| 41 | 39 | return Lists.newArrayList( |
| 42 | - "CREATE TYPE IF NOT EXISTS \"udt3\" (f3 text)", | |
| 43 | - "CREATE TYPE IF NOT EXISTS \"udt2\" (f2 frozen<udt3>)", | |
| 44 | - "CREATE TYPE IF NOT EXISTS \"udt1\" (f1 frozen<udt2>)", | |
| 45 | - "CREATE TABLE IF NOT EXISTS \"t1\" (pk int PRIMARY KEY, " | |
| 46 | - + "c1 frozen<udt1>, " | |
| 47 | - + "c2 frozen<tuple<tuple<tuple<text>>>>, " | |
| 48 | - + "c3 frozen<tuple<tuple<tuple<udt1>>>>" | |
| 49 | - + ")", | |
| 50 | - // it's important to insert values using CQL literals | |
| 51 | - // so that the CodecRegistry will not be required until | |
| 52 | - // we receive a ResultSet | |
| 53 | - "INSERT INTO t1 (pk, c1) VALUES (1, {f1:{f2:{f3:'foo'}}})", | |
| 54 | - "INSERT INTO t1 (pk, c2) VALUES (2, ((('foo'))))", | |
| 55 | - "INSERT INTO t1 (pk, c3) VALUES (3, ((({f1:{f2:{f3:'foo'}}}))))" | |
| 40 | + "CREATE TYPE IF NOT EXISTS \"udt3\" (f3 text)", | |
| 41 | + "CREATE TYPE IF NOT EXISTS \"udt2\" (f2 frozen<udt3>)", | |
| 42 | + "CREATE TYPE IF NOT EXISTS \"udt1\" (f1 frozen<udt2>)", | |
| 43 | + "CREATE TABLE IF NOT EXISTS \"t1\" (pk int PRIMARY KEY, " | |
| 44 | + + "c1 frozen<udt1>, " | |
| 45 | + + "c2 frozen<tuple<tuple<tuple<text>>>>, " | |
| 46 | + + "c3 frozen<tuple<tuple<tuple<udt1>>>>" | |
| 47 | + + ")", | |
| 48 | + // it's important to insert values using CQL literals | |
| 49 | + // so that the CodecRegistry will not be required until | |
| 50 | + // we receive a ResultSet | |
| 51 | + "INSERT INTO t1 (pk, c1) VALUES (1, {f1:{f2:{f3:'foo'}}})", | |
| 52 | + "INSERT INTO t1 (pk, c2) VALUES (2, ((('foo'))))", | |
| 53 | + "INSERT INTO t1 (pk, c3) VALUES (3, ((({f1:{f2:{f3:'foo'}}}))))" | |
| 56 | 54 | ); |
| 57 | 55 | } |
| 58 | 56 |
modified driver-core/src/test/java/com/datastax/driver/core/TypeCodecNumbersIntegrationTest.java +30 −31
| @@ -15,18 +15,17 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.utils.CassandraVersion; | |
| 19 | +import org.testng.annotations.Test; | |
| 20 | + | |
| 18 | 21 | import java.math.BigDecimal; |
| 19 | 22 | import java.math.BigInteger; |
| 20 | 23 | import java.util.Collection; |
| 21 | 24 | |
| 22 | -import org.testng.annotations.Test; | |
| 23 | - | |
| 24 | 25 | import static com.google.common.collect.Lists.newArrayList; |
| 25 | 26 | import static org.assertj.core.api.Assertions.assertThat; |
| 26 | 27 | |
| 27 | -import com.datastax.driver.core.utils.CassandraVersion; | |
| 28 | - | |
| 29 | -public class TypeCodecNumbersIntegrationTest extends CCMBridge.PerClassSingleNodeCluster{ | |
| 28 | +public class TypeCodecNumbersIntegrationTest extends CCMBridge.PerClassSingleNodeCluster { | |
| 30 | 29 | |
| 31 | 30 | private final String insertQuery = "INSERT INTO \"myTable\" (c_int, c_bigint, c_float, c_double, c_varint, c_decimal) VALUES (?, ?, ?, ?, ?, ?)"; |
| 32 | 31 | |
| @@ -43,20 +42,20 @@ | ||
| 43 | 42 | @Override |
| 44 | 43 | protected Collection<String> getTableDefinitions() { |
| 45 | 44 | return newArrayList( |
| 46 | - "CREATE TABLE \"myTable\" (" | |
| 47 | - + "c_int int, " | |
| 48 | - + "c_bigint bigint, " | |
| 49 | - + "c_float float, " | |
| 50 | - + "c_double double, " | |
| 51 | - + "c_varint varint, " | |
| 52 | - + "c_decimal decimal, " | |
| 53 | - + "PRIMARY KEY (c_int, c_bigint)" | |
| 54 | - + ")" | |
| 45 | + "CREATE TABLE \"myTable\" (" | |
| 46 | + + "c_int int, " | |
| 47 | + + "c_bigint bigint, " | |
| 48 | + + "c_float float, " | |
| 49 | + + "c_double double, " | |
| 50 | + + "c_varint varint, " | |
| 51 | + + "c_decimal decimal, " | |
| 52 | + + "PRIMARY KEY (c_int, c_bigint)" | |
| 53 | + + ")" | |
| 55 | 54 | ); |
| 56 | 55 | } |
| 57 | 56 | |
| 58 | 57 | @Test(groups = "short") |
| 59 | - @CassandraVersion(major=2.0) | |
| 58 | + @CassandraVersion(major = 2.0) | |
| 60 | 59 | public void should_use_defaut_codecs_with_simple_statements() { |
| 61 | 60 | session.execute(insertQuery, n_int, n_bigint, n_float, n_double, n_varint, n_decimal); |
| 62 | 61 | ResultSet rows = session.execute(selectQuery, n_int, n_bigint); |
| @@ -76,17 +75,17 @@ | ||
| 76 | 75 | @Test(groups = "short") |
| 77 | 76 | public void should_use_default_codecs_with_prepared_statements_2() { |
| 78 | 77 | session.execute(session.prepare(insertQuery).bind() |
| 79 | - .setInt(0, n_int) | |
| 80 | - .setLong(1, n_bigint) | |
| 81 | - .setFloat(2, n_float) | |
| 82 | - .setDouble(3, n_double) | |
| 83 | - .setVarint(4, n_varint) | |
| 84 | - .setDecimal(5, n_decimal) | |
| 78 | + .setInt(0, n_int) | |
| 79 | + .setLong(1, n_bigint) | |
| 80 | + .setFloat(2, n_float) | |
| 81 | + .setDouble(3, n_double) | |
| 82 | + .setVarint(4, n_varint) | |
| 83 | + .setDecimal(5, n_decimal) | |
| 85 | 84 | ); |
| 86 | 85 | PreparedStatement ps = session.prepare(selectQuery); |
| 87 | 86 | ResultSet rows = session.execute(ps.bind() |
| 88 | - .setInt(0, n_int) | |
| 89 | - .setLong(1, n_bigint) | |
| 87 | + .setInt(0, n_int) | |
| 88 | + .setLong(1, n_bigint) | |
| 90 | 89 | ); |
| 91 | 90 | Row row = rows.one(); |
| 92 | 91 | assertRow(row); |
| @@ -95,17 +94,17 @@ | ||
| 95 | 94 | @Test(groups = "short") |
| 96 | 95 | public void should_use_default_codecs_with_prepared_statements_3() { |
| 97 | 96 | session.execute(session.prepare(insertQuery).bind() |
| 98 | - .set(0, n_int, Integer.class) | |
| 99 | - .set(1, n_bigint, Long.class) | |
| 100 | - .set(2, n_float, Float.class) | |
| 101 | - .set(3, n_double, Double.class) | |
| 102 | - .set(4, n_varint, BigInteger.class) | |
| 103 | - .set(5, n_decimal, BigDecimal.class) | |
| 97 | + .set(0, n_int, Integer.class) | |
| 98 | + .set(1, n_bigint, Long.class) | |
| 99 | + .set(2, n_float, Float.class) | |
| 100 | + .set(3, n_double, Double.class) | |
| 101 | + .set(4, n_varint, BigInteger.class) | |
| 102 | + .set(5, n_decimal, BigDecimal.class) | |
| 104 | 103 | ); |
| 105 | 104 | PreparedStatement ps = session.prepare(selectQuery); |
| 106 | 105 | ResultSet rows = session.execute(ps.bind() |
| 107 | - .setInt(0, n_int) | |
| 108 | - .setLong(1, n_bigint) | |
| 106 | + .setInt(0, n_int) | |
| 107 | + .setLong(1, n_bigint) | |
| 109 | 108 | ); |
| 110 | 109 | Row row = rows.one(); |
| 111 | 110 | assertRow(row); |
modified driver-core/src/test/java/com/datastax/driver/core/TypeCodecOverlappingJavaTypeIntegrationTest.java +22 −21
| @@ -15,18 +15,17 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.exceptions.InvalidTypeException; | |
| 19 | +import com.google.common.reflect.TypeToken; | |
| 20 | +import org.testng.annotations.Test; | |
| 21 | + | |
| 18 | 22 | import java.nio.ByteBuffer; |
| 19 | 23 | import java.util.Collection; |
| 20 | 24 | import java.util.List; |
| 21 | 25 | |
| 22 | -import com.google.common.reflect.TypeToken; | |
| 23 | -import org.testng.annotations.Test; | |
| 24 | - | |
| 25 | 26 | import static com.google.common.collect.Lists.newArrayList; |
| 26 | 27 | import static org.assertj.core.api.Assertions.assertThat; |
| 27 | 28 | |
| 28 | -import com.datastax.driver.core.exceptions.InvalidTypeException; | |
| 29 | - | |
| 30 | 29 | /** |
| 31 | 30 | * Test an edge case where the user register 2 codecs for the same Java type (here, String). |
| 32 | 31 | * SimpleStatements become almost unusable in these cases, but we are adding tests |
| @@ -41,18 +40,18 @@ | ||
| 41 | 40 | @Override |
| 42 | 41 | protected Collection<String> getTableDefinitions() { |
| 43 | 42 | return newArrayList( |
| 44 | - "CREATE TABLE \"myTable\" (" | |
| 45 | - + "c_int int PRIMARY KEY, " | |
| 46 | - + "l_int list<int>, " | |
| 47 | - + "c_text text " | |
| 48 | - + ")" | |
| 43 | + "CREATE TABLE \"myTable\" (" | |
| 44 | + + "c_int int PRIMARY KEY, " | |
| 45 | + + "l_int list<int>, " | |
| 46 | + + "c_text text " | |
| 47 | + + ")" | |
| 49 | 48 | ); |
| 50 | 49 | } |
| 51 | 50 | |
| 52 | 51 | @Override |
| 53 | 52 | protected Cluster.Builder configure(Cluster.Builder builder) { |
| 54 | 53 | return builder.withCodecRegistry( |
| 55 | - new CodecRegistry().register(new IntToStringCodec()) | |
| 54 | + new CodecRegistry().register(new IntToStringCodec()) | |
| 56 | 55 | ); |
| 57 | 56 | } |
| 58 | 57 | |
| @@ -60,16 +59,16 @@ | ||
| 60 | 59 | public void should_use_custom_codecs_with_prepared_statements() { |
| 61 | 60 | PreparedStatement ps = session.prepare(insertQuery); |
| 62 | 61 | session.execute( |
| 63 | - ps.bind() | |
| 64 | - .setInt(0, 42) | |
| 65 | - .setList(1, newArrayList(42)) | |
| 66 | - .setString(2, "42") // here we have the CQL type so VarcharCodec will be used even if IntToStringCodec accepts it | |
| 62 | + ps.bind() | |
| 63 | + .setInt(0, 42) | |
| 64 | + .setList(1, newArrayList(42)) | |
| 65 | + .setString(2, "42") // here we have the CQL type so VarcharCodec will be used even if IntToStringCodec accepts it | |
| 67 | 66 | ); |
| 68 | 67 | session.execute( |
| 69 | - ps.bind() | |
| 70 | - .setString(0, "42") | |
| 71 | - .setList(1, newArrayList("42"), String.class) | |
| 72 | - .setString(2, "42") // here we have the CQL type so VarcharCodec will be used even if IntToStringCodec accepts it | |
| 68 | + ps.bind() | |
| 69 | + .setString(0, "42") | |
| 70 | + .setList(1, newArrayList("42"), String.class) | |
| 71 | + .setString(2, "42") // here we have the CQL type so VarcharCodec will be used even if IntToStringCodec accepts it | |
| 73 | 72 | ); |
| 74 | 73 | ps = session.prepare(selectQuery); |
| 75 | 74 | assertRow(session.execute(ps.bind().setInt(0, 42)).one()); |
| @@ -85,8 +84,10 @@ | ||
| 85 | 84 | assertThat(row.getList(1, Integer.class)).isEqualTo(newArrayList(42)); |
| 86 | 85 | assertThat(row.getList(1, String.class)).isEqualTo(newArrayList("42")); |
| 87 | 86 | assertThat(row.getObject(1)).isEqualTo(newArrayList(42)); // uses the default codec |
| 88 | - assertThat(row.get(1, new TypeToken<List<Integer>>() {})).isEqualTo(newArrayList(42)); | |
| 89 | - assertThat(row.get(1, new TypeToken<List<String>>() {})).isEqualTo(newArrayList("42")); | |
| 87 | + assertThat(row.get(1, new TypeToken<List<Integer>>() { | |
| 88 | + })).isEqualTo(newArrayList(42)); | |
| 89 | + assertThat(row.get(1, new TypeToken<List<String>>() { | |
| 90 | + })).isEqualTo(newArrayList("42")); | |
| 90 | 91 | } |
| 91 | 92 | |
| 92 | 93 | private class IntToStringCodec extends TypeCodec<String> { |
modified driver-core/src/test/java/com/datastax/driver/core/TypeCodecTest.java +56 −55
| @@ -15,9 +15,9 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.nio.ByteBuffer; | |
| 19 | -import java.util.*; | |
| 20 | - | |
| 18 | +import com.datastax.driver.core.UserType.Field; | |
| 19 | +import com.datastax.driver.core.exceptions.CodecNotFoundException; | |
| 20 | +import com.datastax.driver.core.exceptions.InvalidTypeException; | |
| 21 | 21 | import com.google.common.base.Function; |
| 22 | 22 | import com.google.common.base.Joiner; |
| 23 | 23 | import com.google.common.base.Strings; |
| @@ -25,17 +25,14 @@ | ||
| 25 | 25 | import com.google.common.reflect.TypeToken; |
| 26 | 26 | import org.testng.annotations.Test; |
| 27 | 27 | |
| 28 | -import static com.google.common.collect.Lists.newArrayList; | |
| 29 | -import static org.testng.Assert.fail; | |
| 30 | - | |
| 31 | -import com.datastax.driver.core.UserType.Field; | |
| 32 | -import com.datastax.driver.core.exceptions.CodecNotFoundException; | |
| 33 | -import com.datastax.driver.core.exceptions.InvalidTypeException; | |
| 28 | +import java.nio.ByteBuffer; | |
| 29 | +import java.util.*; | |
| 34 | 30 | |
| 35 | 31 | import static com.datastax.driver.core.Assertions.assertThat; |
| 36 | -import static com.datastax.driver.core.TypeTokens.listOf; | |
| 37 | 32 | import static com.datastax.driver.core.DataType.*; |
| 38 | 33 | import static com.datastax.driver.core.ProtocolVersion.V3; |
| 34 | +import static com.google.common.collect.Lists.newArrayList; | |
| 35 | +import static org.testng.Assert.fail; | |
| 39 | 36 | |
| 40 | 37 | public class TypeCodecTest { |
| 41 | 38 | |
| @@ -71,7 +68,7 @@ | ||
| 71 | 68 | assertThat(codec).isNotNull().accepts(cqlType); |
| 72 | 69 | } |
| 73 | 70 | |
| 74 | - @Test(groups = "unit", expectedExceptions = { IllegalArgumentException.class }) | |
| 71 | + @Test(groups = "unit", expectedExceptions = {IllegalArgumentException.class}) | |
| 75 | 72 | public void collectionTooLargeTest() throws Exception { |
| 76 | 73 | DataType cqlType = DataType.list(DataType.cint()); |
| 77 | 74 | List<Integer> list = Collections.nCopies(65536, 1); |
| @@ -79,7 +76,7 @@ | ||
| 79 | 76 | codec.serialize(list, ProtocolVersion.V2); |
| 80 | 77 | } |
| 81 | 78 | |
| 82 | - @Test(groups = "unit", expectedExceptions = { IllegalArgumentException.class }) | |
| 79 | + @Test(groups = "unit", expectedExceptions = {IllegalArgumentException.class}) | |
| 83 | 80 | public void collectionElementTooLargeTest() throws Exception { |
| 84 | 81 | DataType cqlType = DataType.list(DataType.text()); |
| 85 | 82 | List<String> list = newArrayList(Strings.repeat("a", 65536)); |
| @@ -103,57 +100,57 @@ | ||
| 103 | 100 | String ascii = "The quick brown fox jumps over the lazy dog!"; |
| 104 | 101 | String utf8 = "Dès Noël, où un zéphyr haï me vêt de glaçons würmiens, je dîne d’exquis rôtis de bœuf au kir à l’aÿ d’âge mûr & cætera!"; |
| 105 | 102 | assertThat(asciiCodec) |
| 106 | - .accepts(String.class) | |
| 107 | - .accepts(ascii()) | |
| 108 | - .doesNotAccept(varchar()) | |
| 109 | - .doesNotAccept(text()) | |
| 110 | - .accepts(ascii) | |
| 111 | - .canSerialize(ascii) | |
| 112 | - .cannotSerialize(utf8); | |
| 103 | + .accepts(String.class) | |
| 104 | + .accepts(ascii()) | |
| 105 | + .doesNotAccept(varchar()) | |
| 106 | + .doesNotAccept(text()) | |
| 107 | + .accepts(ascii) | |
| 108 | + .canSerialize(ascii) | |
| 109 | + .cannotSerialize(utf8); | |
| 113 | 110 | assertThat(utf8Codec) |
| 114 | - .accepts(String.class) | |
| 115 | - .doesNotAccept(ascii()) | |
| 116 | - .accepts(varchar()) | |
| 117 | - .accepts(text()) | |
| 118 | - .accepts(ascii) | |
| 119 | - .accepts(utf8) | |
| 120 | - .canSerialize(ascii) | |
| 121 | - .canSerialize(utf8); | |
| 111 | + .accepts(String.class) | |
| 112 | + .doesNotAccept(ascii()) | |
| 113 | + .accepts(varchar()) | |
| 114 | + .accepts(text()) | |
| 115 | + .accepts(ascii) | |
| 116 | + .accepts(utf8) | |
| 117 | + .canSerialize(ascii) | |
| 118 | + .canSerialize(utf8); | |
| 122 | 119 | } |
| 123 | 120 | |
| 124 | 121 | @Test(groups = "unit") |
| 125 | 122 | public void test_varchar_vs_text() { |
| 126 | 123 | assertThat(TypeCodec.varchar()) |
| 127 | - .accepts(String.class) | |
| 128 | - .accepts(varchar()) | |
| 129 | - .accepts(text()); | |
| 124 | + .accepts(String.class) | |
| 125 | + .accepts(varchar()) | |
| 126 | + .accepts(text()); | |
| 130 | 127 | assertThat(TypeCodec.list(TypeCodec.varchar())) |
| 131 | - .accepts(list(varchar())) | |
| 132 | - .accepts(list(text())); | |
| 128 | + .accepts(list(varchar())) | |
| 129 | + .accepts(list(text())); | |
| 133 | 130 | assertThat(TypeCodec.set(TypeCodec.varchar())) |
| 134 | - .accepts(set(varchar())) | |
| 135 | - .accepts(set(text())); | |
| 131 | + .accepts(set(varchar())) | |
| 132 | + .accepts(set(text())); | |
| 136 | 133 | assertThat(TypeCodec.map(TypeCodec.varchar(), TypeCodec.varchar())) |
| 137 | - .accepts(map(varchar(), varchar())) | |
| 138 | - .accepts(map(varchar(), text())) | |
| 139 | - .accepts(map(text(), varchar())) | |
| 140 | - .accepts(map(text(), text())); | |
| 134 | + .accepts(map(varchar(), varchar())) | |
| 135 | + .accepts(map(varchar(), text())) | |
| 136 | + .accepts(map(text(), varchar())) | |
| 137 | + .accepts(map(text(), text())); | |
| 141 | 138 | TupleType t1 = new TupleType(newArrayList(varchar(), varchar()), V3, new CodecRegistry()); |
| 142 | 139 | TupleType t2 = new TupleType(newArrayList(text(), varchar()), V3, new CodecRegistry()); |
| 143 | 140 | TupleType t3 = new TupleType(newArrayList(varchar(), text()), V3, new CodecRegistry()); |
| 144 | 141 | TupleType t4 = new TupleType(newArrayList(text(), text()), V3, new CodecRegistry()); |
| 145 | 142 | assertThat(TypeCodec.tuple(t1)) |
| 146 | - .accepts(t2) | |
| 147 | - .accepts(t3) | |
| 148 | - .accepts(t4); | |
| 143 | + .accepts(t2) | |
| 144 | + .accepts(t3) | |
| 145 | + .accepts(t4); | |
| 149 | 146 | UserType u1 = new UserType("ks", "table", newArrayList(new Field("f1", varchar()), new Field("f2", varchar())), V3, new CodecRegistry()); |
| 150 | 147 | UserType u2 = new UserType("ks", "table", newArrayList(new Field("f1", text()), new Field("f2", varchar())), V3, new CodecRegistry()); |
| 151 | 148 | UserType u3 = new UserType("ks", "table", newArrayList(new Field("f1", varchar()), new Field("f2", text())), V3, new CodecRegistry()); |
| 152 | 149 | UserType u4 = new UserType("ks", "table", newArrayList(new Field("f1", text()), new Field("f2", text())), V3, new CodecRegistry()); |
| 153 | 150 | assertThat(TypeCodec.userType(u1)) |
| 154 | - .accepts(u2) | |
| 155 | - .accepts(u3) | |
| 156 | - .accepts(u4); | |
| 151 | + .accepts(u2) | |
| 152 | + .accepts(u3) | |
| 153 | + .accepts(u4); | |
| 157 | 154 | } |
| 158 | 155 | |
| 159 | 156 | @Test(groups = "unit") |
| @@ -170,12 +167,14 @@ | ||
| 170 | 167 | //ok |
| 171 | 168 | } |
| 172 | 169 | TypeCodec<List<A>> expected = TypeCodec.list(aCodec); |
| 173 | - TypeCodec<List<A>> actual = codecRegistry.codecFor(list(cint()), new TypeToken<List<A>>(){}); | |
| 170 | + TypeCodec<List<A>> actual = codecRegistry.codecFor(list(cint()), new TypeToken<List<A>>() { | |
| 171 | + }); | |
| 174 | 172 | assertThat(actual.getCqlType()).isEqualTo(expected.getCqlType()); |
| 175 | 173 | assertThat(actual.getJavaType()).isEqualTo(expected.getJavaType()); |
| 176 | 174 | // cannot work: List<B> is not assignable to List<A> |
| 177 | 175 | try { |
| 178 | - codecRegistry.codecFor(list(cint()), new TypeToken<List<B>>(){}); | |
| 176 | + codecRegistry.codecFor(list(cint()), new TypeToken<List<B>>() { | |
| 177 | + }); | |
| 179 | 178 | fail(); |
| 180 | 179 | } catch (CodecNotFoundException e) { |
| 181 | 180 | //ok |
| @@ -191,13 +190,15 @@ | ||
| 191 | 190 | } |
| 192 | 191 | assertThat(codecRegistry.codecFor(cint(), B.class)).isNotNull().isSameAs(bCodec); |
| 193 | 192 | try { |
| 194 | - codecRegistry.codecFor(list(cint()), new TypeToken<List<A>>(){}); | |
| 193 | + codecRegistry.codecFor(list(cint()), new TypeToken<List<A>>() { | |
| 194 | + }); | |
| 195 | 195 | fail(); |
| 196 | 196 | } catch (CodecNotFoundException e) { |
| 197 | 197 | // ok |
| 198 | 198 | } |
| 199 | 199 | TypeCodec<List<B>> expectedB = TypeCodec.list(bCodec); |
| 200 | - TypeCodec<List<B>> actualB = codecRegistry.codecFor(list(cint()), new TypeToken<List<B>>(){}); | |
| 200 | + TypeCodec<List<B>> actualB = codecRegistry.codecFor(list(cint()), new TypeToken<List<B>>() { | |
| 201 | + }); | |
| 201 | 202 | assertThat(actualB.getCqlType()).isEqualTo(expectedB.getCqlType()); |
| 202 | 203 | assertThat(actualB.getJavaType()).isEqualTo(expectedB.getJavaType()); |
| 203 | 204 | } |
| @@ -218,9 +219,9 @@ | ||
| 218 | 219 | public void should_deserialize_empty_buffer_as_udt_with_null_values() { |
| 219 | 220 | CodecRegistry codecRegistry = new CodecRegistry(); |
| 220 | 221 | UserType udt = new UserType("ks", "t", Arrays.asList( |
| 221 | - new UserType.Field("t", DataType.text()), | |
| 222 | - new UserType.Field("i", DataType.cint()), | |
| 223 | - new UserType.Field("l", DataType.list(DataType.text())) | |
| 222 | + new UserType.Field("t", DataType.text()), | |
| 223 | + new UserType.Field("i", DataType.cint()), | |
| 224 | + new UserType.Field("l", DataType.list(DataType.text())) | |
| 224 | 225 | ), ProtocolVersion.NEWEST_SUPPORTED, codecRegistry); |
| 225 | 226 | UDTValue expected = udt.newValue(); |
| 226 | 227 | expected.setString("t", null); |
| @@ -245,9 +246,9 @@ | ||
| 245 | 246 | TypeCodec<UUID> codec = codecRegistry.codecFor(DataType.timeuuid(), type4UUID); |
| 246 | 247 | // Should resolve the TimeUUIDCodec, but not serialize/format a type4 uuid with it. |
| 247 | 248 | assertThat(codec).isSameAs(TypeCodec.timeUUID()) |
| 248 | - .accepts(UUID.class) | |
| 249 | - .cannotSerialize(type4UUID) | |
| 250 | - .cannotFormat(type4UUID); | |
| 249 | + .accepts(UUID.class) | |
| 250 | + .cannotSerialize(type4UUID) | |
| 251 | + .cannotFormat(type4UUID); | |
| 251 | 252 | } |
| 252 | 253 | |
| 253 | 254 | |
| @@ -294,7 +295,7 @@ | ||
| 294 | 295 | throw new UnsupportedOperationException(); |
| 295 | 296 | } |
| 296 | 297 | } |
| 297 | - | |
| 298 | + | |
| 298 | 299 | class A { |
| 299 | 300 | |
| 300 | 301 | int i = 0; |
modified driver-core/src/test/java/com/datastax/driver/core/TypeCodecTupleIntegrationTest.java +17 −19
| @@ -15,18 +15,16 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.util.Collection; | |
| 19 | -import java.util.Collections; | |
| 20 | -import java.util.UUID; | |
| 21 | - | |
| 18 | +import com.datastax.driver.core.utils.CassandraVersion; | |
| 22 | 19 | import com.google.common.collect.Lists; |
| 23 | 20 | import org.testng.annotations.Test; |
| 24 | 21 | |
| 25 | -import static org.assertj.core.api.Assertions.assertThat; | |
| 26 | - | |
| 27 | -import com.datastax.driver.core.utils.CassandraVersion; | |
| 22 | +import java.util.Collection; | |
| 23 | +import java.util.Collections; | |
| 24 | +import java.util.UUID; | |
| 28 | 25 | |
| 29 | 26 | import static com.datastax.driver.core.DataType.cfloat; |
| 27 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 30 | 28 | |
| 31 | 29 | @CassandraVersion(major = 2.1) |
| 32 | 30 | public class TypeCodecTupleIntegrationTest extends CCMBridge.PerClassSingleNodeCluster { |
| @@ -46,7 +44,7 @@ | ||
| 46 | 44 | @Override |
| 47 | 45 | protected Collection<String> getTableDefinitions() { |
| 48 | 46 | return Lists.newArrayList( |
| 49 | - "CREATE TABLE IF NOT EXISTS \"users\" (id uuid PRIMARY KEY, name text, location frozen<tuple<float,float>>)" | |
| 47 | + "CREATE TABLE IF NOT EXISTS \"users\" (id uuid PRIMARY KEY, name text, location frozen<tuple<float,float>>)" | |
| 50 | 48 | ); |
| 51 | 49 | } |
| 52 | 50 | |
| @@ -96,15 +94,15 @@ | ||
| 96 | 94 | public void should_handle_tuples_with_custom_codecs() { |
| 97 | 95 | CodecRegistry codecRegistry = new CodecRegistry(); |
| 98 | 96 | Cluster cluster = Cluster.builder() |
| 99 | - .addContactPointsWithPorts(Collections.singleton(hostAddress)) | |
| 100 | - .withCodecRegistry(codecRegistry) | |
| 101 | - .build(); | |
| 97 | + .addContactPointsWithPorts(Collections.singleton(hostAddress)) | |
| 98 | + .withCodecRegistry(codecRegistry) | |
| 99 | + .build(); | |
| 102 | 100 | |
| 103 | 101 | try { |
| 104 | 102 | Session session = cluster.connect(keyspace); |
| 105 | 103 | setUpTupleTypes(cluster); |
| 106 | 104 | codecRegistry |
| 107 | - .register(new LocationCodec(TypeCodec.tuple(locationType))) | |
| 105 | + .register(new LocationCodec(TypeCodec.tuple(locationType))) | |
| 108 | 106 | ; |
| 109 | 107 | session.execute(insertQuery, uuid, "John Doe", locationValue); |
| 110 | 108 | ResultSet rows = session.execute(selectQuery, uuid); |
| @@ -132,15 +130,15 @@ | ||
| 132 | 130 | public void should_handle_partial_tuples_with_custom_codecs() { |
| 133 | 131 | CodecRegistry codecRegistry = new CodecRegistry(); |
| 134 | 132 | Cluster cluster = Cluster.builder() |
| 135 | - .addContactPointsWithPorts(Collections.singleton(hostAddress)) | |
| 136 | - .withCodecRegistry(codecRegistry) | |
| 137 | - .build(); | |
| 133 | + .addContactPointsWithPorts(Collections.singleton(hostAddress)) | |
| 134 | + .withCodecRegistry(codecRegistry) | |
| 135 | + .build(); | |
| 138 | 136 | |
| 139 | 137 | try { |
| 140 | 138 | Session session = cluster.connect(keyspace); |
| 141 | 139 | setUpTupleTypes(cluster); |
| 142 | 140 | codecRegistry |
| 143 | - .register(new LocationCodec(TypeCodec.tuple(locationType))) | |
| 141 | + .register(new LocationCodec(TypeCodec.tuple(locationType))) | |
| 144 | 142 | ; |
| 145 | 143 | session.execute(insertQuery, uuid, "John Doe", partialLocationValueInserted); |
| 146 | 144 | ResultSet rows = session.execute(selectQuery, uuid); |
| @@ -191,8 +189,8 @@ | ||
| 191 | 189 | private void setUpTupleTypes(Cluster cluster) { |
| 192 | 190 | locationType = cluster.getMetadata().newTupleType(cfloat(), cfloat()); |
| 193 | 191 | locationValue = locationType.newValue() |
| 194 | - .setFloat(0, 37.387224f) | |
| 195 | - .setFloat(1, -121.9733837f); | |
| 192 | + .setFloat(0, 37.387224f) | |
| 193 | + .setFloat(1, -121.9733837f); | |
| 196 | 194 | // insert a tuple of a different dimension |
| 197 | 195 | partialLocationValueInserted = cluster.getMetadata().newTupleType(cfloat()).newValue().setFloat(0, 37.387224f); |
| 198 | 196 | // retrieve the partial tuple with null missing values |
| @@ -239,7 +237,7 @@ | ||
| 239 | 237 | if (o == null || getClass() != o.getClass()) |
| 240 | 238 | return false; |
| 241 | 239 | |
| 242 | - Location location = (Location)o; | |
| 240 | + Location location = (Location) o; | |
| 243 | 241 | |
| 244 | 242 | return Float.compare(location.latitude, latitude) == 0 && Float.compare(location.longitude, longitude) == 0; |
| 245 | 243 |
modified driver-core/src/test/java/com/datastax/driver/core/TypeCodecUDTIntegrationTest.java +20 −21
| @@ -15,15 +15,14 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.util.*; | |
| 19 | - | |
| 18 | +import com.datastax.driver.core.utils.CassandraVersion; | |
| 20 | 19 | import com.google.common.collect.Lists; |
| 21 | 20 | import com.google.common.collect.Sets; |
| 22 | 21 | import org.testng.annotations.Test; |
| 23 | 22 | |
| 24 | -import static org.assertj.core.api.Assertions.assertThat; | |
| 23 | +import java.util.*; | |
| 25 | 24 | |
| 26 | -import com.datastax.driver.core.utils.CassandraVersion; | |
| 25 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 27 | 26 | |
| 28 | 27 | @CassandraVersion(major = 2.1) |
| 29 | 28 | public class TypeCodecUDTIntegrationTest extends CCMBridge.PerClassSingleNodeCluster { |
| @@ -45,9 +44,9 @@ | ||
| 45 | 44 | @Override |
| 46 | 45 | protected Collection<String> getTableDefinitions() { |
| 47 | 46 | return Lists.newArrayList( |
| 48 | - "CREATE TYPE IF NOT EXISTS \"phone\" (number text, tags set<text>)", | |
| 49 | - "CREATE TYPE IF NOT EXISTS \"address\" (street text, zipcode int, phones list<frozen<phone>>)", | |
| 50 | - "CREATE TABLE IF NOT EXISTS \"users\" (id uuid PRIMARY KEY, name text, address frozen<address>)" | |
| 47 | + "CREATE TYPE IF NOT EXISTS \"phone\" (number text, tags set<text>)", | |
| 48 | + "CREATE TYPE IF NOT EXISTS \"address\" (street text, zipcode int, phones list<frozen<phone>>)", | |
| 49 | + "CREATE TABLE IF NOT EXISTS \"users\" (id uuid PRIMARY KEY, name text, address frozen<address>)" | |
| 51 | 50 | ); |
| 52 | 51 | } |
| 53 | 52 | |
| @@ -76,9 +75,9 @@ | ||
| 76 | 75 | public void should_handle_udts_with_custom_codecs() { |
| 77 | 76 | CodecRegistry codecRegistry = new CodecRegistry(); |
| 78 | 77 | Cluster cluster = Cluster.builder() |
| 79 | - .addContactPointsWithPorts(Collections.singleton(hostAddress)) | |
| 80 | - .withCodecRegistry(codecRegistry) | |
| 81 | - .build(); | |
| 78 | + .addContactPointsWithPorts(Collections.singleton(hostAddress)) | |
| 79 | + .withCodecRegistry(codecRegistry) | |
| 80 | + .build(); | |
| 82 | 81 | |
| 83 | 82 | try { |
| 84 | 83 | Session session = cluster.connect(keyspace); |
| @@ -86,8 +85,8 @@ | ||
| 86 | 85 | TypeCodec<UDTValue> addressTypeCodec = TypeCodec.userType(addressType); |
| 87 | 86 | TypeCodec<UDTValue> phoneTypeCodec = TypeCodec.userType(phoneType); |
| 88 | 87 | codecRegistry |
| 89 | - .register(new AddressCodec(addressTypeCodec, Address.class)) | |
| 90 | - .register(new PhoneCodec(phoneTypeCodec, Phone.class)) | |
| 88 | + .register(new AddressCodec(addressTypeCodec, Address.class)) | |
| 89 | + .register(new PhoneCodec(phoneTypeCodec, Phone.class)) | |
| 91 | 90 | ; |
| 92 | 91 | session.execute(insertQuery, uuid, "John Doe", address); |
| 93 | 92 | ResultSet rows = session.execute(selectQuery, uuid); |
| @@ -127,15 +126,15 @@ | ||
| 127 | 126 | addressType = cluster.getMetadata().getKeyspace(keyspace).getUserType("address"); |
| 128 | 127 | phoneType = cluster.getMetadata().getKeyspace(keyspace).getUserType("phone"); |
| 129 | 128 | UDTValue phone1Value = phoneType.newValue() |
| 130 | - .setString("number", phone1.number) | |
| 131 | - .setSet("tags", phone1.tags); | |
| 129 | + .setString("number", phone1.number) | |
| 130 | + .setSet("tags", phone1.tags); | |
| 132 | 131 | UDTValue phone2Value = phoneType.newValue() |
| 133 | - .setString("number", phone2.number) | |
| 134 | - .setSet("tags", phone2.tags); | |
| 132 | + .setString("number", phone2.number) | |
| 133 | + .setSet("tags", phone2.tags); | |
| 135 | 134 | addressValue = addressType.newValue() |
| 136 | - .setString("street", address.street) | |
| 137 | - .setInt(1, address.zipcode) | |
| 138 | - .setList("phones", Lists.newArrayList(phone1Value, phone2Value)); | |
| 135 | + .setString("street", address.street) | |
| 136 | + .setInt(1, address.zipcode) | |
| 137 | + .setList("phones", Lists.newArrayList(phone1Value, phone2Value)); | |
| 139 | 138 | } |
| 140 | 139 | |
| 141 | 140 | static class AddressCodec extends MappingCodec<Address, UDTValue> { |
| @@ -198,7 +197,7 @@ | ||
| 198 | 197 | return true; |
| 199 | 198 | if (o == null || getClass() != o.getClass()) |
| 200 | 199 | return false; |
| 201 | - Address address = (Address)o; | |
| 200 | + Address address = (Address) o; | |
| 202 | 201 | return zipcode == address.zipcode && street.equals(address.street) && phones.equals(address.phones); |
| 203 | 202 | } |
| 204 | 203 | |
| @@ -228,7 +227,7 @@ | ||
| 228 | 227 | return true; |
| 229 | 228 | if (o == null || getClass() != o.getClass()) |
| 230 | 229 | return false; |
| 231 | - Phone phone = (Phone)o; | |
| 230 | + Phone phone = (Phone) o; | |
| 232 | 231 | return number.equals(phone.number) && tags.equals(phone.tags); |
| 233 | 232 | } |
| 234 | 233 |
modified driver-core/src/test/java/com/datastax/driver/core/UnresolvedUserTypeTest.java +13 −17
| @@ -15,20 +15,16 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.util.Collection; | |
| 19 | -import java.util.Collections; | |
| 20 | -import java.util.concurrent.ExecutionException; | |
| 21 | - | |
| 18 | +import com.datastax.driver.core.utils.CassandraVersion; | |
| 22 | 19 | import com.google.common.collect.Lists; |
| 23 | 20 | import org.testng.annotations.Test; |
| 24 | 21 | |
| 25 | -import com.datastax.driver.core.utils.CassandraVersion; | |
| 22 | +import java.util.Collection; | |
| 23 | +import java.util.Collections; | |
| 24 | +import java.util.concurrent.ExecutionException; | |
| 26 | 25 | |
| 27 | 26 | import static com.datastax.driver.core.Assertions.assertThat; |
| 28 | -import static com.datastax.driver.core.DataType.cint; | |
| 29 | -import static com.datastax.driver.core.DataType.list; | |
| 30 | -import static com.datastax.driver.core.DataType.map; | |
| 31 | -import static com.datastax.driver.core.DataType.set; | |
| 27 | +import static com.datastax.driver.core.DataType.*; | |
| 32 | 28 | |
| 33 | 29 | @CassandraVersion(major = 3.0) |
| 34 | 30 | public class UnresolvedUserTypeTest extends CCMBridge.PerClassSingleNodeCluster { |
| @@ -52,14 +48,14 @@ | ||
| 52 | 48 | |
| 53 | 49 | Topological sort order should be : GH,FE,D,CB,A |
| 54 | 50 | */ |
| 55 | - String.format("CREATE TYPE %s.h (f1 int)", keyspace), | |
| 56 | - String.format("CREATE TYPE %s.g (f1 int)", keyspace), | |
| 57 | - String.format("CREATE TYPE %s.\"F\" (f1 frozen<h>)", keyspace), | |
| 58 | - String.format("CREATE TYPE %s.\"E\" (f1 frozen<list<g>>)", keyspace), | |
| 59 | - String.format("CREATE TYPE %s.\"D\" (f1 frozen<tuple<\"F\",g,h>>)", keyspace), | |
| 60 | - String.format("CREATE TYPE %s.\"C\" (f1 frozen<map<\"E\",\"D\">>)", keyspace), | |
| 61 | - String.format("CREATE TYPE %s.\"B\" (f1 frozen<set<\"D\">>)", keyspace), | |
| 62 | - String.format("CREATE TYPE %s.\"A\" (f1 frozen<\"C\">)", keyspace) | |
| 51 | + String.format("CREATE TYPE %s.h (f1 int)", keyspace), | |
| 52 | + String.format("CREATE TYPE %s.g (f1 int)", keyspace), | |
| 53 | + String.format("CREATE TYPE %s.\"F\" (f1 frozen<h>)", keyspace), | |
| 54 | + String.format("CREATE TYPE %s.\"E\" (f1 frozen<list<g>>)", keyspace), | |
| 55 | + String.format("CREATE TYPE %s.\"D\" (f1 frozen<tuple<\"F\",g,h>>)", keyspace), | |
| 56 | + String.format("CREATE TYPE %s.\"C\" (f1 frozen<map<\"E\",\"D\">>)", keyspace), | |
| 57 | + String.format("CREATE TYPE %s.\"B\" (f1 frozen<set<\"D\">>)", keyspace), | |
| 58 | + String.format("CREATE TYPE %s.\"A\" (f1 frozen<\"C\">)", keyspace) | |
| 63 | 59 | ); |
| 64 | 60 | } |
| 65 | 61 |
modified driver-core/src/test/java/com/datastax/driver/core/UserTypesTest.java +28 −23
| @@ -15,34 +15,33 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.lang.Exception; | |
| 19 | -import java.math.BigDecimal; | |
| 20 | -import java.math.BigInteger; | |
| 21 | -import java.net.InetAddress; | |
| 22 | -import java.nio.ByteBuffer; | |
| 23 | -import java.util.*; | |
| 24 | - | |
| 18 | +import com.datastax.driver.core.utils.CassandraVersion; | |
| 19 | +import com.google.common.base.Joiner; | |
| 25 | 20 | import com.google.common.collect.ImmutableMap; |
| 26 | 21 | import com.google.common.collect.ImmutableSet; |
| 27 | -import com.google.common.base.Joiner; | |
| 28 | - | |
| 29 | 22 | import com.google.common.collect.Lists; |
| 30 | 23 | import com.google.common.collect.Sets; |
| 31 | 24 | import org.testng.annotations.Test; |
| 32 | -import static org.testng.Assert.assertEquals; | |
| 25 | + | |
| 26 | +import java.math.BigDecimal; | |
| 27 | +import java.math.BigInteger; | |
| 28 | +import java.net.InetAddress; | |
| 29 | +import java.nio.ByteBuffer; | |
| 30 | +import java.util.*; | |
| 33 | 31 | |
| 34 | 32 | import static com.datastax.driver.core.Metadata.quote; |
| 33 | +import static org.testng.Assert.assertEquals; | |
| 35 | 34 | import static org.testng.Assert.assertNotEquals; |
| 36 | 35 | |
| 37 | -import com.datastax.driver.core.utils.CassandraVersion; | |
| 38 | - | |
| 39 | -@CassandraVersion(major=2.1) | |
| 36 | +@CassandraVersion(major = 2.1) | |
| 40 | 37 | public class UserTypesTest extends CCMBridge.PerClassSingleNodeCluster { |
| 41 | 38 | |
| 42 | 39 | private final static List<DataType> DATA_TYPE_PRIMITIVES = new ArrayList<DataType>(DataType.allPrimitiveTypes(TestUtils.getDesiredProtocolVersion())); |
| 40 | + | |
| 43 | 41 | static { |
| 44 | 42 | DATA_TYPE_PRIMITIVES.remove(DataType.counter()); |
| 45 | 43 | } |
| 44 | + | |
| 46 | 45 | private final static List<DataType.Name> DATA_TYPE_NON_PRIMITIVE_NAMES = |
| 47 | 46 | new ArrayList<DataType.Name>(EnumSet.of(DataType.Name.LIST, DataType.Name.SET, DataType.Name.MAP, DataType.Name.TUPLE)); |
| 48 | 47 | |
| @@ -92,6 +91,7 @@ | ||
| 92 | 91 | |
| 93 | 92 | /** |
| 94 | 93 | * Run simpleWriteReadTest with unprepared requests. |
| 94 | + * | |
| 95 | 95 | * @throws Exception |
| 96 | 96 | */ |
| 97 | 97 | @Test(groups = "short") |
| @@ -122,6 +122,7 @@ | ||
| 122 | 122 | |
| 123 | 123 | /** |
| 124 | 124 | * Test for ensuring udts are defined in a particular keyspace. |
| 125 | + * | |
| 125 | 126 | * @throws Exception |
| 126 | 127 | */ |
| 127 | 128 | @Test(groups = "short") |
| @@ -166,6 +167,7 @@ | ||
| 166 | 167 | /** |
| 167 | 168 | * Test for ensuring extra-lengthy udts are handled correctly. |
| 168 | 169 | * Original code found in python-driver:integration.standard.test_udts.py:test_udt_sizes |
| 170 | + * | |
| 169 | 171 | * @throws Exception |
| 170 | 172 | */ |
| 171 | 173 | @Test(groups = "short") |
| @@ -219,6 +221,7 @@ | ||
| 219 | 221 | /** |
| 220 | 222 | * Test for inserting various types of DATA_TYPE_PRIMITIVES into UDT's. |
| 221 | 223 | * Original code found in python-driver:integration.standard.test_udts.py:test_primitive_datatypes |
| 224 | + * | |
| 222 | 225 | * @throws Exception |
| 223 | 226 | */ |
| 224 | 227 | @Test(groups = "short") |
| @@ -290,7 +293,7 @@ | ||
| 290 | 293 | alldatatypes.setTimestamp(index, ((Date) sampleData)); |
| 291 | 294 | break; |
| 292 | 295 | case DATE: |
| 293 | - alldatatypes.setDate(index, ((LocalDate)sampleData)); | |
| 296 | + alldatatypes.setDate(index, ((LocalDate) sampleData)); | |
| 294 | 297 | break; |
| 295 | 298 | case TIME: |
| 296 | 299 | alldatatypes.setTime(index, ((Long) sampleData)); |
| @@ -332,6 +335,7 @@ | ||
| 332 | 335 | /** |
| 333 | 336 | * Test for inserting various types of DATA_TYPE_NON_PRIMITIVE into UDT's |
| 334 | 337 | * Original code found in python-driver:integration.standard.test_udts.py:test_nonprimitive_datatypes |
| 338 | + * | |
| 335 | 339 | * @throws Exception |
| 336 | 340 | */ |
| 337 | 341 | @Test(groups = "short") |
| @@ -351,17 +355,15 @@ | ||
| 351 | 355 | for (int i = 0; i < DATA_TYPE_NON_PRIMITIVE_NAMES.size(); i++) |
| 352 | 356 | for (int j = 0; j < DATA_TYPE_PRIMITIVES.size(); j++) { |
| 353 | 357 | String typeString; |
| 354 | - if(DATA_TYPE_NON_PRIMITIVE_NAMES.get(i) == DataType.Name.MAP) { | |
| 358 | + if (DATA_TYPE_NON_PRIMITIVE_NAMES.get(i) == DataType.Name.MAP) { | |
| 355 | 359 | typeString = (String.format("%s_%s %s<%s, %s>", Character.toString((char) (startIndex + i)), |
| 356 | 360 | Character.toString((char) (startIndex + j)), DATA_TYPE_NON_PRIMITIVE_NAMES.get(i), |
| 357 | 361 | DATA_TYPE_PRIMITIVES.get(j).getName(), DATA_TYPE_PRIMITIVES.get(j).getName())); |
| 358 | - } | |
| 359 | - else if (DATA_TYPE_NON_PRIMITIVE_NAMES.get(i) == DataType.Name.TUPLE) { | |
| 362 | + } else if (DATA_TYPE_NON_PRIMITIVE_NAMES.get(i) == DataType.Name.TUPLE) { | |
| 360 | 363 | typeString = (String.format("%s_%s frozen<%s<%s>>", Character.toString((char) (startIndex + i)), |
| 361 | - Character.toString((char) (startIndex + j)), DATA_TYPE_NON_PRIMITIVE_NAMES.get(i), | |
| 362 | - DATA_TYPE_PRIMITIVES.get(j).getName())); | |
| 363 | - } | |
| 364 | - else { | |
| 364 | + Character.toString((char) (startIndex + j)), DATA_TYPE_NON_PRIMITIVE_NAMES.get(i), | |
| 365 | + DATA_TYPE_PRIMITIVES.get(j).getName())); | |
| 366 | + } else { | |
| 365 | 367 | typeString = (String.format("%s_%s %s<%s>", Character.toString((char) (startIndex + i)), |
| 366 | 368 | Character.toString((char) (startIndex + j)), DATA_TYPE_NON_PRIMITIVE_NAMES.get(i), |
| 367 | 369 | DATA_TYPE_PRIMITIVES.get(j).getName())); |
| @@ -383,7 +385,7 @@ | ||
| 383 | 385 | |
| 384 | 386 | String index = Character.toString((char) (startIndex + i)) + "_" + Character.toString((char) (startIndex + j)); |
| 385 | 387 | Object sampleElement = PrimitiveTypeSamples.ALL.get(dataType); |
| 386 | - switch(name) { | |
| 388 | + switch (name) { | |
| 387 | 389 | case LIST: |
| 388 | 390 | alldatatypes.setList(index, Lists.newArrayList(sampleElement)); |
| 389 | 391 | break; |
| @@ -420,6 +422,7 @@ | ||
| 420 | 422 | /** |
| 421 | 423 | * Test for ensuring nested UDT's are handled correctly. |
| 422 | 424 | * Original code found in python-driver:integration.standard.test_udts.py:test_nested_registered_udts |
| 425 | + * | |
| 423 | 426 | * @throws Exception |
| 424 | 427 | */ |
| 425 | 428 | @Test(groups = "short") |
| @@ -436,7 +439,7 @@ | ||
| 436 | 439 | session.execute("CREATE TYPE depth_0 (age int, name text)"); |
| 437 | 440 | |
| 438 | 441 | for (int i = 1; i <= MAX_NESTING_DEPTH; i++) { |
| 439 | - session.execute(String.format("CREATE TYPE depth_%s (value frozen<depth_%s>)", String.valueOf(i), String.valueOf(i-1))); | |
| 442 | + session.execute(String.format("CREATE TYPE depth_%s (value frozen<depth_%s>)", String.valueOf(i), String.valueOf(i - 1))); | |
| 440 | 443 | } |
| 441 | 444 | |
| 442 | 445 | session.execute(String.format("CREATE TABLE mytable (a int PRIMARY KEY, b frozen<depth_0>, c frozen<depth_1>, d frozen<depth_2>, e frozen<depth_3>," + |
| @@ -484,6 +487,7 @@ | ||
| 484 | 487 | /** |
| 485 | 488 | * Test for inserting null values into UDT's |
| 486 | 489 | * Original code found in python-driver:integration.standard.test_udts.py:test_udts_with_nulls |
| 490 | + * | |
| 487 | 491 | * @throws Exception |
| 488 | 492 | */ |
| 489 | 493 | @Test(groups = "short") |
| @@ -537,6 +541,7 @@ | ||
| 537 | 541 | |
| 538 | 542 | /** |
| 539 | 543 | * Test for inserting null values into collections of UDT's |
| 544 | + * | |
| 540 | 545 | * @throws Exception |
| 541 | 546 | */ |
| 542 | 547 | @Test(groups = "short") |
modified driver-core/src/test/java/com/datastax/driver/core/VersionNumberTest.java +8 −7
| @@ -16,6 +16,7 @@ | ||
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | 18 | import org.testng.annotations.Test; |
| 19 | + | |
| 19 | 20 | import static org.testng.Assert.assertEquals; |
| 20 | 21 | |
| 21 | 22 | public class VersionNumberTest { |
| @@ -23,13 +24,13 @@ | ||
| 23 | 24 | @Test(groups = "unit") |
| 24 | 25 | public void versionNumberTest() { |
| 25 | 26 | |
| 26 | - String[] versions = new String[] { | |
| 27 | - "1.2.0", | |
| 28 | - "2.0.0", | |
| 29 | - "2.0.0-beta1", | |
| 30 | - "2.0.0-beta1-SNAPSHOT", | |
| 31 | - "2.0.0-beta1-SNAPSHOT+abc01", | |
| 32 | - "2.0.0.22" // DSE | |
| 27 | + String[] versions = new String[]{ | |
| 28 | + "1.2.0", | |
| 29 | + "2.0.0", | |
| 30 | + "2.0.0-beta1", | |
| 31 | + "2.0.0-beta1-SNAPSHOT", | |
| 32 | + "2.0.0-beta1-SNAPSHOT+abc01", | |
| 33 | + "2.0.0.22" // DSE | |
| 33 | 34 | }; |
| 34 | 35 | |
| 35 | 36 | VersionNumber[] numbers = new VersionNumber[versions.length]; |
modified driver-core/src/test/java/com/datastax/driver/core/WarningsTest.java +6 −7
| @@ -15,16 +15,15 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.util.Collection; | |
| 19 | -import java.util.List; | |
| 20 | - | |
| 18 | +import com.datastax.driver.core.utils.CassandraVersion; | |
| 21 | 19 | import com.google.common.base.Strings; |
| 22 | 20 | import com.google.common.collect.Lists; |
| 23 | 21 | import org.testng.annotations.Test; |
| 24 | 22 | |
| 25 | -import static org.assertj.core.api.Assertions.assertThat; | |
| 23 | +import java.util.Collection; | |
| 24 | +import java.util.List; | |
| 26 | 25 | |
| 27 | -import com.datastax.driver.core.utils.CassandraVersion; | |
| 26 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 28 | 27 | |
| 29 | 28 | public class WarningsTest extends CCMBridge.PerClassSingleNodeCluster { |
| 30 | 29 | |
| @@ -36,7 +35,7 @@ | ||
| 36 | 35 | @Override |
| 37 | 36 | protected Collection<String> getTableDefinitions() { |
| 38 | 37 | return Lists.newArrayList( |
| 39 | - "CREATE TABLE foo(k int primary key, v text)" | |
| 38 | + "CREATE TABLE foo(k int primary key, v text)" | |
| 40 | 39 | ); |
| 41 | 40 | } |
| 42 | 41 | |
| @@ -44,7 +43,7 @@ | ||
| 44 | 43 | @Test(groups = "short") |
| 45 | 44 | public void should_expose_warnings_on_execution_info() { |
| 46 | 45 | ResultSet rs = session.execute(String.format("BEGIN UNLOGGED BATCH INSERT INTO foo (k, v) VALUES (1, '%s') APPLY BATCH", |
| 47 | - Strings.repeat("1", BATCH_SIZE_WARN_THRESHOLD_IN_BYTES))); | |
| 46 | + Strings.repeat("1", BATCH_SIZE_WARN_THRESHOLD_IN_BYTES))); | |
| 48 | 47 | |
| 49 | 48 | List<String> warnings = rs.getExecutionInfo().getWarnings(); |
| 50 | 49 | assertThat(warnings).hasSize(1); |
modified driver-core/src/test/java/com/datastax/driver/core/exceptions/ExceptionsScassandraTest.java +15 −19
| @@ -15,25 +15,21 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core.exceptions; |
| 17 | 17 | |
| 18 | -import java.util.List; | |
| 19 | -import java.util.Map; | |
| 20 | - | |
| 18 | +import com.datastax.driver.core.*; | |
| 19 | +import com.datastax.driver.core.policies.FallthroughRetryPolicy; | |
| 21 | 20 | import com.google.common.collect.ImmutableList; |
| 22 | 21 | import com.google.common.collect.ImmutableMap; |
| 23 | 22 | import org.scassandra.Scassandra; |
| 24 | 23 | import org.scassandra.http.client.PrimingRequest; |
| 25 | 24 | import org.testng.annotations.*; |
| 26 | 25 | |
| 27 | -import static org.assertj.core.api.Assertions.assertThat; | |
| 28 | -import static org.assertj.core.api.Assertions.fail; | |
| 29 | -import static org.scassandra.http.client.PrimingRequest.Result.read_request_timeout; | |
| 30 | -import static org.scassandra.http.client.PrimingRequest.Result.unavailable; | |
| 31 | -import static org.scassandra.http.client.PrimingRequest.Result.write_request_timeout; | |
| 32 | - | |
| 33 | -import com.datastax.driver.core.*; | |
| 34 | -import com.datastax.driver.core.policies.FallthroughRetryPolicy; | |
| 26 | +import java.util.List; | |
| 27 | +import java.util.Map; | |
| 35 | 28 | |
| 36 | 29 | import static com.datastax.driver.core.ConsistencyLevel.LOCAL_ONE; |
| 30 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 31 | +import static org.assertj.core.api.Assertions.fail; | |
| 32 | +import static org.scassandra.http.client.PrimingRequest.Result.*; | |
| 37 | 33 | |
| 38 | 34 | public class ExceptionsScassandraTest { |
| 39 | 35 | |
| @@ -52,14 +48,14 @@ | ||
| 52 | 48 | @BeforeMethod(groups = "short") |
| 53 | 49 | public void beforeMethod() { |
| 54 | 50 | cluster = Cluster.builder() |
| 55 | - .addContactPoint(CCMBridge.ipOfNode(1)) | |
| 56 | - .withRetryPolicy(FallthroughRetryPolicy.INSTANCE) | |
| 57 | - .build(); | |
| 51 | + .addContactPoint(CCMBridge.ipOfNode(1)) | |
| 52 | + .withRetryPolicy(FallthroughRetryPolicy.INSTANCE) | |
| 53 | + .build(); | |
| 58 | 54 | session = cluster.connect(); |
| 59 | 55 | host1 = TestUtils.findHost(cluster, 1); |
| 60 | 56 | errors = cluster.getMetrics().getErrorMetrics(); |
| 61 | 57 | |
| 62 | - for(Scassandra node : scassandras.nodes()) { | |
| 58 | + for (Scassandra node : scassandras.nodes()) { | |
| 63 | 59 | node.primingClient().clearAllPrimes(); |
| 64 | 60 | node.activityClient().clearAllRecordedActivity(); |
| 65 | 61 | } |
| @@ -116,9 +112,9 @@ | ||
| 116 | 112 | |
| 117 | 113 | protected void simulateError(int hostNumber, PrimingRequest.Result result) { |
| 118 | 114 | scassandras.node(hostNumber).primingClient().prime(PrimingRequest.queryBuilder() |
| 119 | - .withQuery("mock query") | |
| 120 | - .withResult(result) | |
| 121 | - .build()); | |
| 115 | + .withQuery("mock query") | |
| 116 | + .withResult(result) | |
| 117 | + .build()); | |
| 122 | 118 | } |
| 123 | 119 | |
| 124 | 120 | private static List<Map<String, ?>> row(String key, String value) { |
| @@ -135,7 +131,7 @@ | ||
| 135 | 131 | |
| 136 | 132 | @AfterMethod(groups = "short") |
| 137 | 133 | public void afterMethod() { |
| 138 | - for(Scassandra node : scassandras.nodes()) { | |
| 134 | + for (Scassandra node : scassandras.nodes()) { | |
| 139 | 135 | node.primingClient().clearAllPrimes(); |
| 140 | 136 | } |
| 141 | 137 | if (cluster != null) |
modified driver-core/src/test/java/com/datastax/driver/core/exceptions/ExceptionsTest.java +17 −18
| @@ -15,22 +15,21 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core.exceptions; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.CCMBridge; | |
| 19 | +import com.datastax.driver.core.Cluster; | |
| 20 | +import com.datastax.driver.core.TestUtils; | |
| 21 | +import com.datastax.driver.core.WriteType; | |
| 22 | +import org.testng.annotations.Test; | |
| 23 | + | |
| 18 | 24 | import java.net.InetAddress; |
| 19 | 25 | import java.net.InetSocketAddress; |
| 20 | -import java.util.Locale; | |
| 21 | - | |
| 22 | -import org.testng.annotations.Test; | |
| 23 | 26 | |
| 27 | +import static com.datastax.driver.core.CCMBridge.ipOfNode; | |
| 28 | +import static com.datastax.driver.core.ConsistencyLevel.LOCAL_QUORUM; | |
| 24 | 29 | import static org.assertj.core.api.Assertions.assertThat; |
| 25 | 30 | import static org.testng.Assert.assertEquals; |
| 26 | 31 | import static org.testng.Assert.assertTrue; |
| 27 | 32 | |
| 28 | -import com.datastax.driver.core.*; | |
| 29 | - | |
| 30 | -import static com.datastax.driver.core.CCMBridge.ipOfNode; | |
| 31 | -import static com.datastax.driver.core.ConsistencyLevel.LOCAL_QUORUM; | |
| 32 | -import static com.datastax.driver.core.TestUtils.waitForDownWithWait; | |
| 33 | - | |
| 34 | 33 | /** |
| 35 | 34 | * Tests Exception classes with separate clusters per test, when applicable |
| 36 | 35 | */ |
| @@ -53,9 +52,9 @@ | ||
| 53 | 52 | String table = "TestTable"; |
| 54 | 53 | |
| 55 | 54 | String[] cqlCommands = new String[]{ |
| 56 | - String.format(TestUtils.CREATE_KEYSPACE_SIMPLE_FORMAT, keyspace, 1), | |
| 57 | - "USE " + keyspace, | |
| 58 | - String.format("CREATE TABLE %s (k text PRIMARY KEY, t text, i int, f float)", table) | |
| 55 | + String.format(TestUtils.CREATE_KEYSPACE_SIMPLE_FORMAT, keyspace, 1), | |
| 56 | + "USE " + keyspace, | |
| 57 | + String.format("CREATE TABLE %s (k text PRIMARY KEY, t text, i int, f float)", table) | |
| 59 | 58 | }; |
| 60 | 59 | |
| 61 | 60 | // Create the schema once |
| @@ -185,7 +184,7 @@ | ||
| 185 | 184 | public void should_create_proper_invalid_query_exception() { |
| 186 | 185 | InvalidQueryException e = new InvalidQueryException("Bad, really bad"); |
| 187 | 186 | assertThat(e.getMessage()).isEqualTo("Bad, really bad"); |
| 188 | - e = (InvalidQueryException)e.copy(); | |
| 187 | + e = (InvalidQueryException) e.copy(); | |
| 189 | 188 | assertThat(e.getMessage()).isEqualTo("Bad, really bad"); |
| 190 | 189 | } |
| 191 | 190 | |
| @@ -193,7 +192,7 @@ | ||
| 193 | 192 | public void should_create_proper_trace_retrieval_exception() { |
| 194 | 193 | TraceRetrievalException e = new TraceRetrievalException("Couldn't find any trace of it"); |
| 195 | 194 | assertThat(e.getMessage()).isEqualTo("Couldn't find any trace of it"); |
| 196 | - e = (TraceRetrievalException)e.copy(); | |
| 195 | + e = (TraceRetrievalException) e.copy(); | |
| 197 | 196 | assertThat(e.getMessage()).isEqualTo("Couldn't find any trace of it"); |
| 198 | 197 | } |
| 199 | 198 | |
| @@ -210,7 +209,7 @@ | ||
| 210 | 209 | assertThat(e.getMessage()).isEqualTo("Bad, really bad"); |
| 211 | 210 | assertThat(e.getAddress()).isEqualTo(address1); |
| 212 | 211 | assertThat(e.getHost()).isEqualTo(address1.getAddress()); |
| 213 | - InvalidQueryException e1 = (InvalidQueryException)e.copy(); | |
| 212 | + InvalidQueryException e1 = (InvalidQueryException) e.copy(); | |
| 214 | 213 | assertThat(e1.getMessage()).isEqualTo("Bad, really bad"); |
| 215 | 214 | } |
| 216 | 215 | |
| @@ -232,7 +231,7 @@ | ||
| 232 | 231 | assertThat(e.getMessage()).isEqualTo("Missing ) at EOF"); |
| 233 | 232 | assertThat(e.getAddress()).isEqualTo(address1); |
| 234 | 233 | assertThat(e.getHost()).isEqualTo(address1.getAddress()); |
| 235 | - e = (SyntaxError)e.copy(); | |
| 234 | + e = (SyntaxError) e.copy(); | |
| 236 | 235 | assertThat(e.getMessage()).isEqualTo("Missing ) at EOF"); |
| 237 | 236 | assertThat(e.getAddress()).isEqualTo(address1); |
| 238 | 237 | assertThat(e.getHost()).isEqualTo(address1.getAddress()); |
| @@ -244,7 +243,7 @@ | ||
| 244 | 243 | assertThat(e.getMessage()).isEqualTo("I'm running headless now"); |
| 245 | 244 | assertThat(e.getAddress()).isEqualTo(address1); |
| 246 | 245 | assertThat(e.getHost()).isEqualTo(address1.getAddress()); |
| 247 | - e = (TruncateException)e.copy(); | |
| 246 | + e = (TruncateException) e.copy(); | |
| 248 | 247 | assertThat(e.getMessage()).isEqualTo("I'm running headless now"); |
| 249 | 248 | assertThat(e.getAddress()).isEqualTo(address1); |
| 250 | 249 | assertThat(e.getHost()).isEqualTo(address1.getAddress()); |
| @@ -256,7 +255,7 @@ | ||
| 256 | 255 | assertThat(e.getMessage()).isEqualTo("You talking to me?"); |
| 257 | 256 | assertThat(e.getAddress()).isEqualTo(address1); |
| 258 | 257 | assertThat(e.getHost()).isEqualTo(address1.getAddress()); |
| 259 | - e = (UnauthorizedException)e.copy(); | |
| 258 | + e = (UnauthorizedException) e.copy(); | |
| 260 | 259 | assertThat(e.getMessage()).isEqualTo("You talking to me?"); |
| 261 | 260 | assertThat(e.getAddress()).isEqualTo(address1); |
| 262 | 261 | assertThat(e.getHost()).isEqualTo(address1.getAddress()); |
modified driver-core/src/test/java/com/datastax/driver/core/exceptions/FunctionExecutionExceptionTest.java +6 −7
| @@ -15,13 +15,12 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core.exceptions; |
| 17 | 17 | |
| 18 | -import java.util.Collection; | |
| 19 | - | |
| 18 | +import com.datastax.driver.core.CCMBridge; | |
| 19 | +import com.datastax.driver.core.utils.CassandraVersion; | |
| 20 | 20 | import com.google.common.collect.Lists; |
| 21 | 21 | import org.testng.annotations.Test; |
| 22 | 22 | |
| 23 | -import com.datastax.driver.core.CCMBridge; | |
| 24 | -import com.datastax.driver.core.utils.CassandraVersion; | |
| 23 | +import java.util.Collection; | |
| 25 | 24 | |
| 26 | 25 | @CassandraVersion(major = 2.2) |
| 27 | 26 | public class FunctionExecutionExceptionTest extends CCMBridge.PerClassSingleNodeCluster { |
| @@ -29,9 +28,9 @@ | ||
| 29 | 28 | @Override |
| 30 | 29 | protected Collection<String> getTableDefinitions() { |
| 31 | 30 | return Lists.newArrayList( |
| 32 | - "CREATE TABLE foo (k int primary key, i int, l list<int>)", | |
| 33 | - "INSERT INTO foo (k, i, l) VALUES (1, 1, [1])", | |
| 34 | - "CREATE FUNCTION element_at(l list<int>, i int) RETURNS NULL ON NULL INPUT RETURNS int LANGUAGE java AS 'return (Integer) l.get(i);'" | |
| 31 | + "CREATE TABLE foo (k int primary key, i int, l list<int>)", | |
| 32 | + "INSERT INTO foo (k, i, l) VALUES (1, 1, [1])", | |
| 33 | + "CREATE FUNCTION element_at(l list<int>, i int) RETURNS NULL ON NULL INPUT RETURNS int LANGUAGE java AS 'return (Integer) l.get(i);'" | |
| 35 | 34 | ); |
| 36 | 35 | } |
| 37 | 36 |
modified driver-core/src/test/java/com/datastax/driver/core/exceptions/NoHostAvailableExceptionTest.java +14 −13
| @@ -15,13 +15,13 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core.exceptions; |
| 17 | 17 | |
| 18 | +import com.beust.jcommander.internal.Maps; | |
| 19 | +import org.testng.annotations.Test; | |
| 20 | + | |
| 18 | 21 | import java.io.PrintWriter; |
| 19 | 22 | import java.net.InetSocketAddress; |
| 20 | 23 | import java.util.Map; |
| 21 | 24 | |
| 22 | -import com.beust.jcommander.internal.Maps; | |
| 23 | -import org.testng.annotations.Test; | |
| 24 | - | |
| 25 | 25 | import static org.assertj.core.api.Assertions.assertThat; |
| 26 | 26 | |
| 27 | 27 | public class NoHostAvailableExceptionTest { |
| @@ -30,9 +30,9 @@ | ||
| 30 | 30 | NoHostAvailableException e = new NoHostAvailableException(buildMockErrors(3)); |
| 31 | 31 | String message = e.getMessage(); |
| 32 | 32 | assertThat(message).startsWith("All host(s) tried for query failed"); |
| 33 | - assertThat(message).contains( "/127.0.0.1:9042 (com.datastax.driver.core.exceptions.NoHostAvailableExceptionTest$MockError: mock error 1)"); | |
| 34 | - assertThat(message).contains( "/127.0.0.2:9042 (com.datastax.driver.core.exceptions.NoHostAvailableExceptionTest$MockError: mock error 2)"); | |
| 35 | - assertThat(message).contains( "/127.0.0.3:9042 (com.datastax.driver.core.exceptions.NoHostAvailableExceptionTest$MockError: mock error 3)"); | |
| 33 | + assertThat(message).contains("/127.0.0.1:9042 (com.datastax.driver.core.exceptions.NoHostAvailableExceptionTest$MockError: mock error 1)"); | |
| 34 | + assertThat(message).contains("/127.0.0.2:9042 (com.datastax.driver.core.exceptions.NoHostAvailableExceptionTest$MockError: mock error 2)"); | |
| 35 | + assertThat(message).contains("/127.0.0.3:9042 (com.datastax.driver.core.exceptions.NoHostAvailableExceptionTest$MockError: mock error 3)"); | |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | @Test(groups = "unit") |
| @@ -40,9 +40,9 @@ | ||
| 40 | 40 | NoHostAvailableException e = new NoHostAvailableException(buildMockErrors(4)); |
| 41 | 41 | String message = e.getMessage(); |
| 42 | 42 | assertThat(message).startsWith("All host(s) tried for query failed"); |
| 43 | - assertThat(message).contains( "/127.0.0.1:9042 (com.datastax.driver.core.exceptions.NoHostAvailableExceptionTest$MockError: mock error 1)"); | |
| 44 | - assertThat(message).contains( "/127.0.0.2:9042 (com.datastax.driver.core.exceptions.NoHostAvailableExceptionTest$MockError: mock error 2)"); | |
| 45 | - assertThat(message).contains( "/127.0.0.3:9042 (com.datastax.driver.core.exceptions.NoHostAvailableExceptionTest$MockError: mock error 3)"); | |
| 43 | + assertThat(message).contains("/127.0.0.1:9042 (com.datastax.driver.core.exceptions.NoHostAvailableExceptionTest$MockError: mock error 1)"); | |
| 44 | + assertThat(message).contains("/127.0.0.2:9042 (com.datastax.driver.core.exceptions.NoHostAvailableExceptionTest$MockError: mock error 2)"); | |
| 45 | + assertThat(message).contains("/127.0.0.3:9042 (com.datastax.driver.core.exceptions.NoHostAvailableExceptionTest$MockError: mock error 3)"); | |
| 46 | 46 | assertThat(message).contains("only showing errors of first 3 hosts, use getErrors() for more details"); |
| 47 | 47 | } |
| 48 | 48 | |
| @@ -51,9 +51,9 @@ | ||
| 51 | 51 | NoHostAvailableException e = new NoHostAvailableException(buildMockErrors(3)); |
| 52 | 52 | String message = e.getCustomMessage(3, true, false); |
| 53 | 53 | assertThat(message).startsWith("All host(s) tried for query failed (tried:\n"); |
| 54 | - assertThat(message).contains( "/127.0.0.1:9042 (com.datastax.driver.core.exceptions.NoHostAvailableExceptionTest$MockError: mock error 1)\n"); | |
| 55 | - assertThat(message).contains( "/127.0.0.2:9042 (com.datastax.driver.core.exceptions.NoHostAvailableExceptionTest$MockError: mock error 2)\n"); | |
| 56 | - assertThat(message).contains( "/127.0.0.3:9042 (com.datastax.driver.core.exceptions.NoHostAvailableExceptionTest$MockError: mock error 3)\n"); | |
| 54 | + assertThat(message).contains("/127.0.0.1:9042 (com.datastax.driver.core.exceptions.NoHostAvailableExceptionTest$MockError: mock error 1)\n"); | |
| 55 | + assertThat(message).contains("/127.0.0.2:9042 (com.datastax.driver.core.exceptions.NoHostAvailableExceptionTest$MockError: mock error 2)\n"); | |
| 56 | + assertThat(message).contains("/127.0.0.3:9042 (com.datastax.driver.core.exceptions.NoHostAvailableExceptionTest$MockError: mock error 3)\n"); | |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | @Test(groups = "unit") |
| @@ -82,7 +82,8 @@ | ||
| 82 | 82 | this.i = i; |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | - @Override public void printStackTrace(PrintWriter writer) { | |
| 85 | + @Override | |
| 86 | + public void printStackTrace(PrintWriter writer) { | |
| 86 | 87 | writer.printf("mock stack trace %d", i); |
| 87 | 88 | } |
| 88 | 89 | } |
modified driver-core/src/test/java/com/datastax/driver/core/policies/AbstractRetryPolicyIntegrationTest.java +28 −32
| @@ -15,9 +15,8 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core.policies; |
| 17 | 17 | |
| 18 | -import java.util.List; | |
| 19 | -import java.util.Map; | |
| 20 | - | |
| 18 | +import com.datastax.driver.core.*; | |
| 19 | +import com.datastax.driver.core.exceptions.DriverException; | |
| 21 | 20 | import com.google.common.collect.ImmutableList; |
| 22 | 21 | import com.google.common.collect.ImmutableMap; |
| 23 | 22 | import org.mockito.Mockito; |
| @@ -26,23 +25,20 @@ | ||
| 26 | 25 | import org.testng.annotations.AfterMethod; |
| 27 | 26 | import org.testng.annotations.BeforeMethod; |
| 28 | 27 | |
| 29 | -import static org.assertj.core.api.Assertions.assertThat; | |
| 30 | -import static org.mockito.Matchers.any; | |
| 31 | -import static org.mockito.Matchers.anyBoolean; | |
| 32 | -import static org.mockito.Matchers.anyInt; | |
| 33 | -import static org.mockito.Mockito.times; | |
| 34 | - | |
| 35 | -import com.datastax.driver.core.*; | |
| 36 | -import com.datastax.driver.core.exceptions.DriverException; | |
| 28 | +import java.util.List; | |
| 29 | +import java.util.Map; | |
| 37 | 30 | |
| 38 | 31 | import static com.datastax.driver.core.TestUtils.nonQuietClusterCloseOptions; |
| 32 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 33 | +import static org.mockito.Matchers.*; | |
| 34 | +import static org.mockito.Mockito.times; | |
| 39 | 35 | |
| 40 | 36 | /** |
| 41 | 37 | * Base class for retry policy integration tests. |
| 42 | - * | |
| 38 | + * <p/> | |
| 43 | 39 | * We use SCassandra to easily simulate specific errors (unavailable, read timeout...) on nodes, |
| 44 | 40 | * and SortingLoadBalancingPolicy to get a predictable order of the query plan (always host1, host2, host3). |
| 45 | - * | |
| 41 | + * <p/> | |
| 46 | 42 | * Note that SCassandra only allows a limited number of test cases, for instance it always returns errors |
| 47 | 43 | * with receivedResponses = 0. If that becomes more finely tuneable in the future, we'll be able to add more |
| 48 | 44 | * tests in child classes. |
| @@ -73,17 +69,17 @@ | ||
| 73 | 69 | scassandras.init(); |
| 74 | 70 | |
| 75 | 71 | cluster = Cluster.builder() |
| 76 | - .addContactPoint(CCMBridge.ipOfNode(1)) | |
| 77 | - .withRetryPolicy(retryPolicy) | |
| 78 | - .withLoadBalancingPolicy(new SortingLoadBalancingPolicy()) | |
| 79 | - // Scassandra does not support V3 nor V4 yet, and V4 may cause the server to crash | |
| 80 | - .withProtocolVersion(ProtocolVersion.V2) | |
| 81 | - .withPoolingOptions(new PoolingOptions() | |
| 82 | - .setCoreConnectionsPerHost(HostDistance.LOCAL, 1) | |
| 83 | - .setMaxConnectionsPerHost(HostDistance.LOCAL, 1) | |
| 84 | - .setHeartbeatIntervalSeconds(0)) | |
| 85 | - .withNettyOptions(nonQuietClusterCloseOptions) | |
| 86 | - .build(); | |
| 72 | + .addContactPoint(CCMBridge.ipOfNode(1)) | |
| 73 | + .withRetryPolicy(retryPolicy) | |
| 74 | + .withLoadBalancingPolicy(new SortingLoadBalancingPolicy()) | |
| 75 | + // Scassandra does not support V3 nor V4 yet, and V4 may cause the server to crash | |
| 76 | + .withProtocolVersion(ProtocolVersion.V2) | |
| 77 | + .withPoolingOptions(new PoolingOptions() | |
| 78 | + .setCoreConnectionsPerHost(HostDistance.LOCAL, 1) | |
| 79 | + .setMaxConnectionsPerHost(HostDistance.LOCAL, 1) | |
| 80 | + .setHeartbeatIntervalSeconds(0)) | |
| 81 | + .withNettyOptions(nonQuietClusterCloseOptions) | |
| 82 | + .build(); | |
| 87 | 83 | |
| 88 | 84 | session = cluster.connect(); |
| 89 | 85 | |
| @@ -95,16 +91,16 @@ | ||
| 95 | 91 | |
| 96 | 92 | Mockito.reset(retryPolicy); |
| 97 | 93 | |
| 98 | - for(Scassandra node : scassandras.nodes()) { | |
| 94 | + for (Scassandra node : scassandras.nodes()) { | |
| 99 | 95 | node.activityClient().clearAllRecordedActivity(); |
| 100 | 96 | } |
| 101 | 97 | } |
| 102 | 98 | |
| 103 | 99 | protected void simulateError(int hostNumber, PrimingRequest.Result result) { |
| 104 | 100 | scassandras.node(hostNumber).primingClient().prime(PrimingRequest.queryBuilder() |
| 105 | - .withQuery("mock query") | |
| 106 | - .withResult(result) | |
| 107 | - .build()); | |
| 101 | + .withQuery("mock query") | |
| 102 | + .withResult(result) | |
| 103 | + .build()); | |
| 108 | 104 | } |
| 109 | 105 | |
| 110 | 106 | protected void simulateNormalResponse(int hostNumber) { |
| @@ -128,23 +124,23 @@ | ||
| 128 | 124 | |
| 129 | 125 | protected void assertOnReadTimeoutWasCalled(int times) { |
| 130 | 126 | Mockito.verify(retryPolicy, times(times)).onReadTimeout( |
| 131 | - any(Statement.class), any(ConsistencyLevel.class), anyInt(), anyInt(), anyBoolean(), anyInt()); | |
| 127 | + any(Statement.class), any(ConsistencyLevel.class), anyInt(), anyInt(), anyBoolean(), anyInt()); | |
| 132 | 128 | |
| 133 | 129 | } |
| 134 | 130 | |
| 135 | 131 | protected void assertOnWriteTimeoutWasCalled(int times) { |
| 136 | 132 | Mockito.verify(retryPolicy, times(times)).onWriteTimeout( |
| 137 | - any(Statement.class), any(ConsistencyLevel.class), any(WriteType.class), anyInt(), anyInt(), anyInt()); | |
| 133 | + any(Statement.class), any(ConsistencyLevel.class), any(WriteType.class), anyInt(), anyInt(), anyInt()); | |
| 138 | 134 | } |
| 139 | 135 | |
| 140 | 136 | protected void assertOnUnavailableWasCalled(int times) { |
| 141 | 137 | Mockito.verify(retryPolicy, times(times)).onUnavailable( |
| 142 | - any(Statement.class), any(ConsistencyLevel.class), anyInt(), anyInt(), anyInt()); | |
| 138 | + any(Statement.class), any(ConsistencyLevel.class), anyInt(), anyInt(), anyInt()); | |
| 143 | 139 | } |
| 144 | 140 | |
| 145 | 141 | protected void assertOnRequestErrorWasCalled(int times, Class<? extends DriverException> expected) { |
| 146 | 142 | Mockito.verify(retryPolicy, times(times)).onRequestError( |
| 147 | - any(Statement.class), any(ConsistencyLevel.class), any(expected), anyInt()); | |
| 143 | + any(Statement.class), any(ConsistencyLevel.class), any(expected), anyInt()); | |
| 148 | 144 | } |
| 149 | 145 | |
| 150 | 146 | protected void assertQueried(int hostNumber, int times) { |
modified driver-core/src/test/java/com/datastax/driver/core/policies/CloseableLoadBalancingPolicyTest.java +5 −6
| @@ -15,13 +15,12 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core.policies; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.CCMBridge; | |
| 19 | +import com.datastax.driver.core.Cluster; | |
| 18 | 20 | import org.testng.annotations.Test; |
| 19 | 21 | |
| 20 | 22 | import static org.assertj.core.api.Assertions.assertThat; |
| 21 | 23 | |
| 22 | -import com.datastax.driver.core.CCMBridge; | |
| 23 | -import com.datastax.driver.core.Cluster; | |
| 24 | - | |
| 25 | 24 | public class CloseableLoadBalancingPolicyTest { |
| 26 | 25 | @Test(groups = "short") |
| 27 | 26 | public void should_be_invoked_at_shutdown() { |
| @@ -31,9 +30,9 @@ | ||
| 31 | 30 | try { |
| 32 | 31 | ccm = CCMBridge.builder("test").withNodes(1).build(); |
| 33 | 32 | cluster = Cluster.builder() |
| 34 | - .addContactPoint(CCMBridge.ipOfNode(1)) | |
| 35 | - .withLoadBalancingPolicy(policy) | |
| 36 | - .build(); | |
| 33 | + .addContactPoint(CCMBridge.ipOfNode(1)) | |
| 34 | + .withLoadBalancingPolicy(policy) | |
| 35 | + .build(); | |
| 37 | 36 | cluster.connect(); |
| 38 | 37 | } finally { |
| 39 | 38 | if (cluster != null) |
modified driver-core/src/test/java/com/datastax/driver/core/policies/CustomRetryPolicyIntegrationTest.java +9 −11
| @@ -15,19 +15,17 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core.policies; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.*; | |
| 19 | +import com.datastax.driver.core.exceptions.*; | |
| 18 | 20 | import org.scassandra.http.client.PrimingRequest; |
| 19 | 21 | import org.testng.annotations.DataProvider; |
| 20 | 22 | import org.testng.annotations.Test; |
| 21 | 23 | |
| 24 | +import static com.datastax.driver.core.Assertions.assertThat; | |
| 22 | 25 | import static org.assertj.core.api.Fail.fail; |
| 23 | 26 | import static org.scassandra.http.client.PrimingRequest.Result.*; |
| 24 | 27 | import static org.scassandra.http.client.PrimingRequest.then; |
| 25 | 28 | |
| 26 | -import com.datastax.driver.core.*; | |
| 27 | -import com.datastax.driver.core.exceptions.*; | |
| 28 | - | |
| 29 | -import static com.datastax.driver.core.Assertions.assertThat; | |
| 30 | - | |
| 31 | 29 | /** |
| 32 | 30 | * Integration test with a custom implementation, to test retry and ignore decisions. |
| 33 | 31 | */ |
| @@ -76,7 +74,7 @@ | ||
| 76 | 74 | cluster.getConfiguration().getSocketOptions().setReadTimeoutMillis(1); |
| 77 | 75 | try { |
| 78 | 76 | scassandras |
| 79 | - .node(1).primingClient().prime(PrimingRequest.queryBuilder() | |
| 77 | + .node(1).primingClient().prime(PrimingRequest.queryBuilder() | |
| 80 | 78 | .withQuery("mock query") |
| 81 | 79 | .withThen(then().withFixedDelay(1000L).withRows(row("result", "result1"))) |
| 82 | 80 | .build()); |
| @@ -85,7 +83,7 @@ | ||
| 85 | 83 | fail("expected an OperationTimedOutException"); |
| 86 | 84 | } catch (OperationTimedOutException e) { |
| 87 | 85 | assertThat(e.getMessage()).isEqualTo( |
| 88 | - String.format("[%s] Timed out waiting for server response", host1.getAddress()) | |
| 86 | + String.format("[%s] Timed out waiting for server response", host1.getAddress()) | |
| 89 | 87 | ); |
| 90 | 88 | } |
| 91 | 89 | assertOnRequestErrorWasCalled(1, OperationTimedOutException.class); |
| @@ -103,8 +101,8 @@ | ||
| 103 | 101 | @DataProvider |
| 104 | 102 | public static Object[][] serverSideErrors() { |
| 105 | 103 | return new Object[][]{ |
| 106 | - {server_error, ServerError.class}, | |
| 107 | - {overloaded, OverloadedException.class} | |
| 104 | + {server_error, ServerError.class}, | |
| 105 | + {overloaded, OverloadedException.class} | |
| 108 | 106 | }; |
| 109 | 107 | } |
| 110 | 108 | |
| @@ -145,8 +143,8 @@ | ||
| 145 | 143 | @Override |
| 146 | 144 | public RetryDecision onUnavailable(Statement statement, ConsistencyLevel cl, int requiredReplica, int aliveReplica, int nbRetry) { |
| 147 | 145 | return (nbRetry == 0) |
| 148 | - ? RetryDecision.retry(cl) | |
| 149 | - : RetryDecision.rethrow(); | |
| 146 | + ? RetryDecision.retry(cl) | |
| 147 | + : RetryDecision.rethrow(); | |
| 150 | 148 | } |
| 151 | 149 | |
| 152 | 150 | @Override |
modified driver-core/src/test/java/com/datastax/driver/core/policies/DCAwareRoundRobinPolicyTest.java +57 −67
| @@ -15,8 +15,8 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core.policies; |
| 17 | 17 | |
| 18 | -import java.util.Collection; | |
| 19 | - | |
| 18 | +import com.datastax.driver.core.*; | |
| 19 | +import com.datastax.driver.core.exceptions.NoHostAvailableException; | |
| 20 | 20 | import com.google.common.collect.Lists; |
| 21 | 21 | import org.apache.log4j.Level; |
| 22 | 22 | import org.apache.log4j.Logger; |
| @@ -27,26 +27,16 @@ | ||
| 27 | 27 | import org.testng.annotations.BeforeMethod; |
| 28 | 28 | import org.testng.annotations.Test; |
| 29 | 29 | |
| 30 | -import static com.google.common.collect.Lists.newArrayList; | |
| 31 | -import static org.mockito.Matchers.any; | |
| 32 | -import static org.mockito.Mockito.spy; | |
| 33 | -import static org.mockito.MockitoAnnotations.initMocks; | |
| 34 | - | |
| 35 | -import com.datastax.driver.core.Cluster; | |
| 36 | -import com.datastax.driver.core.ConsistencyLevel; | |
| 37 | -import com.datastax.driver.core.DataProviders; | |
| 38 | -import com.datastax.driver.core.Host; | |
| 39 | -import com.datastax.driver.core.MemoryAppender; | |
| 40 | -import com.datastax.driver.core.QueryTracker; | |
| 41 | -import com.datastax.driver.core.ScassandraCluster; | |
| 42 | -import com.datastax.driver.core.Session; | |
| 43 | -import com.datastax.driver.core.SocketOptions; | |
| 44 | -import com.datastax.driver.core.exceptions.NoHostAvailableException; | |
| 30 | +import java.util.Collection; | |
| 45 | 31 | |
| 46 | 32 | import static com.datastax.driver.core.Assertions.assertThat; |
| 47 | 33 | import static com.datastax.driver.core.ScassandraCluster.datacenter; |
| 48 | 34 | import static com.datastax.driver.core.TestUtils.findHost; |
| 49 | 35 | import static com.datastax.driver.core.TestUtils.nonQuietClusterCloseOptions; |
| 36 | +import static com.google.common.collect.Lists.newArrayList; | |
| 37 | +import static org.mockito.Matchers.any; | |
| 38 | +import static org.mockito.Mockito.spy; | |
| 39 | +import static org.mockito.MockitoAnnotations.initMocks; | |
| 50 | 40 | |
| 51 | 41 | public class DCAwareRoundRobinPolicyTest { |
| 52 | 42 | |
| @@ -74,8 +64,8 @@ | ||
| 74 | 64 | |
| 75 | 65 | private Cluster.Builder builder() { |
| 76 | 66 | return Cluster.builder() |
| 77 | - // Close cluster immediately to speed up tests. | |
| 78 | - .withNettyOptions(nonQuietClusterCloseOptions); | |
| 67 | + // Close cluster immediately to speed up tests. | |
| 68 | + .withNettyOptions(nonQuietClusterCloseOptions); | |
| 79 | 69 | } |
| 80 | 70 | |
| 81 | 71 | /** |
| @@ -89,9 +79,9 @@ | ||
| 89 | 79 | // given: a 10 node 2 DC cluster. |
| 90 | 80 | ScassandraCluster sCluster = ScassandraCluster.builder().withNodes(5, 5).build(); |
| 91 | 81 | Cluster cluster = builder() |
| 92 | - .addContactPoint(sCluster.address(1, 1)) | |
| 93 | - .withLoadBalancingPolicy(DCAwareRoundRobinPolicy.builder().withLocalDc(datacenter(1)).build()) | |
| 94 | - .build(); | |
| 82 | + .addContactPoint(sCluster.address(1, 1)) | |
| 83 | + .withLoadBalancingPolicy(DCAwareRoundRobinPolicy.builder().withLocalDc(datacenter(1)).build()) | |
| 84 | + .build(); | |
| 95 | 85 | try { |
| 96 | 86 | sCluster.init(); |
| 97 | 87 | |
| @@ -101,7 +91,7 @@ | ||
| 101 | 91 | |
| 102 | 92 | // then: each node in local DC should get an equal (10) number of requests. |
| 103 | 93 | // then: no node in the remote DC should get a request. |
| 104 | - for(int i = 1; i <= 5; i++) { | |
| 94 | + for (int i = 1; i <= 5; i++) { | |
| 105 | 95 | queryTracker.assertQueried(sCluster, 1, i, 10); |
| 106 | 96 | queryTracker.assertQueried(sCluster, 2, i, 0); |
| 107 | 97 | } |
| @@ -116,14 +106,14 @@ | ||
| 116 | 106 | * |
| 117 | 107 | * @test_category load_balancing:dc_aware |
| 118 | 108 | */ |
| 119 | - @Test(groups="short") | |
| 109 | + @Test(groups = "short") | |
| 120 | 110 | public void should_not_use_remote_hosts_if_some_nodes_are_up_in_local_dc() { |
| 121 | 111 | // given: a 10 node 2 DC cluster with DC policy with 2 remote hosts. |
| 122 | 112 | ScassandraCluster sCluster = ScassandraCluster.builder().withNodes(5, 5).build(); |
| 123 | 113 | Cluster cluster = builder() |
| 124 | - .addContactPoint(sCluster.address(1, 1)) | |
| 125 | - .withLoadBalancingPolicy(DCAwareRoundRobinPolicy.builder().withLocalDc(datacenter(1)).withUsedHostsPerRemoteDc(2).build()) | |
| 126 | - .build(); | |
| 114 | + .addContactPoint(sCluster.address(1, 1)) | |
| 115 | + .withLoadBalancingPolicy(DCAwareRoundRobinPolicy.builder().withLocalDc(datacenter(1)).withUsedHostsPerRemoteDc(2).build()) | |
| 116 | + .build(); | |
| 127 | 117 | |
| 128 | 118 | try { |
| 129 | 119 | sCluster.init(); |
| @@ -142,7 +132,7 @@ | ||
| 142 | 132 | queryTracker.assertQueried(sCluster, 1, 4, 25); |
| 143 | 133 | |
| 144 | 134 | // then: no nodes in the remote DC should have been queried. |
| 145 | - for(int i = 1; i <= 5; i++) { | |
| 135 | + for (int i = 1; i <= 5; i++) { | |
| 146 | 136 | queryTracker.assertQueried(sCluster, 2, i, 0); |
| 147 | 137 | } |
| 148 | 138 | } finally { |
| @@ -158,14 +148,14 @@ | ||
| 158 | 148 | * |
| 159 | 149 | * @test_category load_balancing:dc_aware |
| 160 | 150 | */ |
| 161 | - @Test(groups="short") | |
| 151 | + @Test(groups = "short") | |
| 162 | 152 | public void should_round_robin_on_remote_hosts_when_no_up_nodes_in_local_dc() { |
| 163 | 153 | // given: a 10 node 2 DC cluster with DC policy with 2 remote hosts. |
| 164 | 154 | ScassandraCluster sCluster = ScassandraCluster.builder().withNodes(5, 5).build(); |
| 165 | 155 | Cluster cluster = builder() |
| 166 | - .addContactPoint(sCluster.address(1, 1)) | |
| 167 | - .withLoadBalancingPolicy(DCAwareRoundRobinPolicy.builder().withUsedHostsPerRemoteDc(2).build()) | |
| 168 | - .build(); | |
| 156 | + .addContactPoint(sCluster.address(1, 1)) | |
| 157 | + .withLoadBalancingPolicy(DCAwareRoundRobinPolicy.builder().withUsedHostsPerRemoteDc(2).build()) | |
| 158 | + .build(); | |
| 169 | 159 | |
| 170 | 160 | try { |
| 171 | 161 | sCluster.init(); |
| @@ -200,15 +190,15 @@ | ||
| 200 | 190 | * |
| 201 | 191 | * @test_category load_balancing:dc_aware |
| 202 | 192 | */ |
| 203 | - @Test(groups="short", dataProvider="consistencyLevels", dataProviderClass = DataProviders.class) | |
| 193 | + @Test(groups = "short", dataProvider = "consistencyLevels", dataProviderClass = DataProviders.class) | |
| 204 | 194 | public void should_only_use_remote_hosts_when_using_non_dc_local_cl(ConsistencyLevel cl) { |
| 205 | 195 | // given: a 4 node 2 DC Cluster with a LB policy that specifies to not allow remote dcs for |
| 206 | 196 | // a local consistency level. |
| 207 | 197 | ScassandraCluster sCluster = ScassandraCluster.builder().withNodes(2, 2).build(); |
| 208 | 198 | Cluster cluster = builder() |
| 209 | - .addContactPoint(sCluster.address(1, 1)) | |
| 210 | - .withLoadBalancingPolicy(DCAwareRoundRobinPolicy.builder().withUsedHostsPerRemoteDc(2).build()) | |
| 211 | - .build(); | |
| 199 | + .addContactPoint(sCluster.address(1, 1)) | |
| 200 | + .withLoadBalancingPolicy(DCAwareRoundRobinPolicy.builder().withUsedHostsPerRemoteDc(2).build()) | |
| 201 | + .build(); | |
| 212 | 202 | |
| 213 | 203 | try { |
| 214 | 204 | sCluster.init(); |
| @@ -245,17 +235,17 @@ | ||
| 245 | 235 | * |
| 246 | 236 | * @test_category load_balancing:dc_aware |
| 247 | 237 | */ |
| 248 | - @Test(groups="short", dataProvider="consistencyLevels", dataProviderClass = DataProviders.class) | |
| 238 | + @Test(groups = "short", dataProvider = "consistencyLevels", dataProviderClass = DataProviders.class) | |
| 249 | 239 | public void should_use_remote_hosts_for_local_cl_when_allowed(ConsistencyLevel cl) { |
| 250 | 240 | // given: a 4 node 2 DC Cluster with a LB policy that specifies to allow remote dcs for |
| 251 | 241 | // a local consistency level. |
| 252 | 242 | ScassandraCluster sCluster = ScassandraCluster.builder().withNodes(2, 2).build(); |
| 253 | 243 | Cluster cluster = builder() |
| 254 | - .addContactPoint(sCluster.address(1, 1)) | |
| 255 | - .withLoadBalancingPolicy(DCAwareRoundRobinPolicy.builder() | |
| 256 | - .allowRemoteDCsForLocalConsistencyLevel() | |
| 257 | - .withUsedHostsPerRemoteDc(2).build()) | |
| 258 | - .build(); | |
| 244 | + .addContactPoint(sCluster.address(1, 1)) | |
| 245 | + .withLoadBalancingPolicy(DCAwareRoundRobinPolicy.builder() | |
| 246 | + .allowRemoteDCsForLocalConsistencyLevel() | |
| 247 | + .withUsedHostsPerRemoteDc(2).build()) | |
| 248 | + .build(); | |
| 259 | 249 | |
| 260 | 250 | try { |
| 261 | 251 | sCluster.init(); |
| @@ -291,14 +281,14 @@ | ||
| 291 | 281 | @Test(groups = "short") |
| 292 | 282 | public void should_not_send_requests_to_blacklisted_dc_using_host_filter_policy() { |
| 293 | 283 | // given: a 6 node 3 DC cluster with a DCAwareRoundRobinPolicy that is filtering hosts in DC2. |
| 294 | - ScassandraCluster sCluster = ScassandraCluster.builder().withNodes(2,2,2).build(); | |
| 284 | + ScassandraCluster sCluster = ScassandraCluster.builder().withNodes(2, 2, 2).build(); | |
| 295 | 285 | LoadBalancingPolicy loadBalancingPolicy = HostFilterPolicy.fromDCBlackList( |
| 296 | - DCAwareRoundRobinPolicy.builder().withUsedHostsPerRemoteDc(2).build(), | |
| 297 | - Lists.newArrayList(datacenter(2))); | |
| 286 | + DCAwareRoundRobinPolicy.builder().withUsedHostsPerRemoteDc(2).build(), | |
| 287 | + Lists.newArrayList(datacenter(2))); | |
| 298 | 288 | Cluster cluster = builder() |
| 299 | - .addContactPoint(sCluster.address(1, 1)) | |
| 300 | - .withLoadBalancingPolicy(loadBalancingPolicy) | |
| 301 | - .build(); | |
| 289 | + .addContactPoint(sCluster.address(1, 1)) | |
| 290 | + .withLoadBalancingPolicy(loadBalancingPolicy) | |
| 291 | + .build(); | |
| 302 | 292 | |
| 303 | 293 | try { |
| 304 | 294 | sCluster.init(); |
| @@ -344,14 +334,14 @@ | ||
| 344 | 334 | @Test(groups = "short") |
| 345 | 335 | public void should_send_requests_to_whitelisted_dcs_using_host_filter_policy() { |
| 346 | 336 | // given: a 6 node 3 DC cluster with a DCAwareRoundRobinPolicy that is whitelisting hosts in DC1 and DC2. |
| 347 | - ScassandraCluster sCluster = ScassandraCluster.builder().withNodes(2,2,2).build(); | |
| 337 | + ScassandraCluster sCluster = ScassandraCluster.builder().withNodes(2, 2, 2).build(); | |
| 348 | 338 | LoadBalancingPolicy loadBalancingPolicy = HostFilterPolicy.fromDCWhiteList( |
| 349 | - DCAwareRoundRobinPolicy.builder().withUsedHostsPerRemoteDc(2).build(), | |
| 350 | - Lists.newArrayList(datacenter(1), datacenter(2))); | |
| 339 | + DCAwareRoundRobinPolicy.builder().withUsedHostsPerRemoteDc(2).build(), | |
| 340 | + Lists.newArrayList(datacenter(1), datacenter(2))); | |
| 351 | 341 | Cluster cluster = builder() |
| 352 | - .addContactPoint(sCluster.address(1, 1)) | |
| 353 | - .withLoadBalancingPolicy(loadBalancingPolicy) | |
| 354 | - .build(); | |
| 342 | + .addContactPoint(sCluster.address(1, 1)) | |
| 343 | + .withLoadBalancingPolicy(loadBalancingPolicy) | |
| 344 | + .build(); | |
| 355 | 345 | |
| 356 | 346 | try { |
| 357 | 347 | sCluster.init(); |
| @@ -394,15 +384,15 @@ | ||
| 394 | 384 | * |
| 395 | 385 | * @test_category load_balancing:dc_aware |
| 396 | 386 | */ |
| 397 | - @Test(groups="short") | |
| 387 | + @Test(groups = "short") | |
| 398 | 388 | public void should_use_local_dc_from_contact_points_when_not_explicitly_specified() { |
| 399 | 389 | // given: a 4 node 2 DC cluster without a local DC specified. |
| 400 | 390 | DCAwareRoundRobinPolicy policy = spy(DCAwareRoundRobinPolicy.builder().build()); |
| 401 | 391 | ScassandraCluster sCluster = ScassandraCluster.builder().withNodes(2, 2).build(); |
| 402 | 392 | Cluster cluster = builder() |
| 403 | - .addContactPoint(sCluster.address(1, 1)) | |
| 404 | - .withLoadBalancingPolicy(policy) | |
| 405 | - .build(); | |
| 393 | + .addContactPoint(sCluster.address(1, 1)) | |
| 394 | + .withLoadBalancingPolicy(policy) | |
| 395 | + .build(); | |
| 406 | 396 | |
| 407 | 397 | try { |
| 408 | 398 | sCluster.init(); |
| @@ -439,9 +429,9 @@ | ||
| 439 | 429 | DCAwareRoundRobinPolicy policy = spy(DCAwareRoundRobinPolicy.builder().build()); |
| 440 | 430 | ScassandraCluster sCluster = ScassandraCluster.builder().withNodes(2, 2).build(); |
| 441 | 431 | Cluster cluster = builder() |
| 442 | - .addContactPoints(sCluster.address(1, 1), sCluster.address(2, 1)) | |
| 443 | - .withLoadBalancingPolicy(policy) | |
| 444 | - .build(); | |
| 432 | + .addContactPoints(sCluster.address(1, 1), sCluster.address(2, 1)) | |
| 433 | + .withLoadBalancingPolicy(policy) | |
| 434 | + .build(); | |
| 445 | 435 | |
| 446 | 436 | try { |
| 447 | 437 | sCluster.init(); |
| @@ -477,9 +467,9 @@ | ||
| 477 | 467 | ScassandraCluster sCluster = ScassandraCluster.builder().withNodes(2, 2).build(); |
| 478 | 468 | DCAwareRoundRobinPolicy policy = spy(DCAwareRoundRobinPolicy.builder().withLocalDc(datacenter(1)).build()); |
| 479 | 469 | Cluster cluster = builder() |
| 480 | - .addContactPoints(sCluster.address(1, 1)) | |
| 481 | - .withLoadBalancingPolicy(policy) | |
| 482 | - .build(); | |
| 470 | + .addContactPoints(sCluster.address(1, 1)) | |
| 471 | + .withLoadBalancingPolicy(policy) | |
| 472 | + .build(); | |
| 483 | 473 | |
| 484 | 474 | try { |
| 485 | 475 | sCluster.init(); |
| @@ -516,9 +506,9 @@ | ||
| 516 | 506 | ScassandraCluster sCluster = ScassandraCluster.builder().withNodes(2, 2).build(); |
| 517 | 507 | DCAwareRoundRobinPolicy policy = spy(DCAwareRoundRobinPolicy.builder().withLocalDc(datacenter(3)).build()); |
| 518 | 508 | Cluster cluster = builder() |
| 519 | - .addContactPoints(sCluster.address(1, 1), sCluster.address(2, 1)) | |
| 520 | - .withLoadBalancingPolicy(policy) | |
| 521 | - .build(); | |
| 509 | + .addContactPoints(sCluster.address(1, 1), sCluster.address(2, 1)) | |
| 510 | + .withLoadBalancingPolicy(policy) | |
| 511 | + .build(); | |
| 522 | 512 | |
| 523 | 513 | try { |
| 524 | 514 | sCluster.init(); |
modified driver-core/src/test/java/com/datastax/driver/core/policies/DefaultRetryPolicyIntegrationTest.java +23 −24
| @@ -17,20 +17,19 @@ | ||
| 17 | 17 | |
| 18 | 18 | import com.datastax.driver.core.*; |
| 19 | 19 | import com.datastax.driver.core.exceptions.*; |
| 20 | - | |
| 21 | 20 | import org.assertj.core.api.Fail; |
| 22 | 21 | import org.scassandra.Scassandra; |
| 23 | 22 | import org.scassandra.http.client.PrimingRequest; |
| 24 | 23 | import org.testng.annotations.DataProvider; |
| 25 | 24 | import org.testng.annotations.Test; |
| 26 | 25 | |
| 26 | +import java.util.Collections; | |
| 27 | + | |
| 27 | 28 | import static org.assertj.core.api.Assertions.assertThat; |
| 28 | 29 | import static org.assertj.core.api.Assertions.fail; |
| 29 | 30 | import static org.scassandra.http.client.PrimingRequest.Result.*; |
| 30 | 31 | import static org.scassandra.http.client.PrimingRequest.then; |
| 31 | 32 | |
| 32 | -import java.util.Collections; | |
| 33 | - | |
| 34 | 33 | public class DefaultRetryPolicyIntegrationTest extends AbstractRetryPolicyIntegrationTest { |
| 35 | 34 | public DefaultRetryPolicyIntegrationTest() { |
| 36 | 35 | super(DefaultRetryPolicy.INSTANCE); |
| @@ -115,7 +114,7 @@ | ||
| 115 | 114 | |
| 116 | 115 | Cluster whiteListedCluster = Cluster.builder() |
| 117 | 116 | .addContactPoint(CCMBridge.ipOfNode(1)) |
| 118 | - // Scassandra does not support V3 nor V4 yet, and V4 may cause the server to crash | |
| 117 | + // Scassandra does not support V3 nor V4 yet, and V4 may cause the server to crash | |
| 119 | 118 | .withProtocolVersion(ProtocolVersion.V2) |
| 120 | 119 | .withRetryPolicy(retryPolicy) |
| 121 | 120 | .withLoadBalancingPolicy(firstHostOnlyPolicy) |
| @@ -124,7 +123,7 @@ | ||
| 124 | 123 | try { |
| 125 | 124 | Session whiteListedSession = whiteListedCluster.connect(); |
| 126 | 125 | // Clear all activity as result of connect. |
| 127 | - for(Scassandra node : scassandras.nodes()) { | |
| 126 | + for (Scassandra node : scassandras.nodes()) { | |
| 128 | 127 | node.activityClient().clearAllRecordedActivity(); |
| 129 | 128 | } |
| 130 | 129 | |
| @@ -133,7 +132,7 @@ | ||
| 133 | 132 | try { |
| 134 | 133 | query(whiteListedSession); |
| 135 | 134 | fail("expected an NoHostAvailableException"); |
| 136 | - } catch(NoHostAvailableException e) { | |
| 135 | + } catch (NoHostAvailableException e) { | |
| 137 | 136 | // ok |
| 138 | 137 | Throwable error = e.getErrors().get(host1.getSocketAddress()); |
| 139 | 138 | assertThat(error).isNotNull(); |
| @@ -157,17 +156,17 @@ | ||
| 157 | 156 | cluster.getConfiguration().getSocketOptions().setReadTimeoutMillis(1); |
| 158 | 157 | try { |
| 159 | 158 | scassandras |
| 160 | - .node(1).primingClient().prime(PrimingRequest.queryBuilder() | |
| 159 | + .node(1).primingClient().prime(PrimingRequest.queryBuilder() | |
| 161 | 160 | .withQuery("mock query") |
| 162 | 161 | .withThen(then().withFixedDelay(1000L).withRows(row("result", "result1"))) |
| 163 | 162 | .build()); |
| 164 | 163 | scassandras |
| 165 | - .node(2).primingClient().prime(PrimingRequest.queryBuilder() | |
| 164 | + .node(2).primingClient().prime(PrimingRequest.queryBuilder() | |
| 166 | 165 | .withQuery("mock query") |
| 167 | 166 | .withThen(then().withFixedDelay(1000L).withRows(row("result", "result2"))) |
| 168 | 167 | .build()); |
| 169 | 168 | scassandras |
| 170 | - .node(3).primingClient().prime(PrimingRequest.queryBuilder() | |
| 169 | + .node(3).primingClient().prime(PrimingRequest.queryBuilder() | |
| 171 | 170 | .withQuery("mock query") |
| 172 | 171 | .withThen(then().withFixedDelay(1000L).withRows(row("result", "result3"))) |
| 173 | 172 | .build()); |
| @@ -176,17 +175,17 @@ | ||
| 176 | 175 | fail("expected a NoHostAvailableException"); |
| 177 | 176 | } catch (NoHostAvailableException e) { |
| 178 | 177 | assertThat(e.getErrors().keySet()).hasSize(3).containsOnlyOnce( |
| 179 | - host1.getSocketAddress(), | |
| 180 | - host2.getSocketAddress(), | |
| 181 | - host3.getSocketAddress()); | |
| 178 | + host1.getSocketAddress(), | |
| 179 | + host2.getSocketAddress(), | |
| 180 | + host3.getSocketAddress()); | |
| 182 | 181 | assertThat(e.getErrors().values()) |
| 183 | - .hasOnlyElementsOfType(OperationTimedOutException.class) | |
| 184 | - .extractingResultOf("getMessage") | |
| 185 | - .containsOnlyOnce( | |
| 186 | - String.format("[%s] Timed out waiting for server response", host1.getAddress()), | |
| 187 | - String.format("[%s] Timed out waiting for server response", host2.getAddress()), | |
| 188 | - String.format("[%s] Timed out waiting for server response", host3.getAddress()) | |
| 189 | - ); | |
| 182 | + .hasOnlyElementsOfType(OperationTimedOutException.class) | |
| 183 | + .extractingResultOf("getMessage") | |
| 184 | + .containsOnlyOnce( | |
| 185 | + String.format("[%s] Timed out waiting for server response", host1.getAddress()), | |
| 186 | + String.format("[%s] Timed out waiting for server response", host2.getAddress()), | |
| 187 | + String.format("[%s] Timed out waiting for server response", host3.getAddress()) | |
| 188 | + ); | |
| 190 | 189 | } |
| 191 | 190 | assertOnRequestErrorWasCalled(3, OperationTimedOutException.class); |
| 192 | 191 | assertThat(errors.getRetries().getCount()).isEqualTo(3); |
| @@ -203,8 +202,8 @@ | ||
| 203 | 202 | @DataProvider |
| 204 | 203 | public static Object[][] serverSideErrors() { |
| 205 | 204 | return new Object[][]{ |
| 206 | - {server_error, ServerError.class}, | |
| 207 | - {overloaded, OverloadedException.class} | |
| 205 | + {server_error, ServerError.class}, | |
| 206 | + {overloaded, OverloadedException.class} | |
| 208 | 207 | }; |
| 209 | 208 | } |
| 210 | 209 | |
| @@ -218,9 +217,9 @@ | ||
| 218 | 217 | Fail.fail("expected a NoHostAvailableException"); |
| 219 | 218 | } catch (NoHostAvailableException e) { |
| 220 | 219 | assertThat(e.getErrors().keySet()).hasSize(3).containsOnlyOnce( |
| 221 | - host1.getSocketAddress(), | |
| 222 | - host2.getSocketAddress(), | |
| 223 | - host3.getSocketAddress()); | |
| 220 | + host1.getSocketAddress(), | |
| 221 | + host2.getSocketAddress(), | |
| 222 | + host3.getSocketAddress()); | |
| 224 | 223 | assertThat(e.getErrors().values()).hasOnlyElementsOfType(exception); |
| 225 | 224 | } |
| 226 | 225 | assertOnRequestErrorWasCalled(3, exception); |
modified driver-core/src/test/java/com/datastax/driver/core/policies/DelegatingLoadBalancingPolicy.java +4 −4
| @@ -15,17 +15,17 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core.policies; |
| 17 | 17 | |
| 18 | -import java.util.Collection; | |
| 19 | -import java.util.Iterator; | |
| 20 | - | |
| 21 | 18 | import com.datastax.driver.core.Cluster; |
| 22 | 19 | import com.datastax.driver.core.Host; |
| 23 | 20 | import com.datastax.driver.core.HostDistance; |
| 24 | 21 | import com.datastax.driver.core.Statement; |
| 25 | 22 | |
| 23 | +import java.util.Collection; | |
| 24 | +import java.util.Iterator; | |
| 25 | + | |
| 26 | 26 | /** |
| 27 | 27 | * Base class for tests that want to wrap a policy to add some instrumentation. |
| 28 | - * | |
| 28 | + * <p/> | |
| 29 | 29 | * NB: this is currently only used in tests, but could be provided as a convenience in the production code. |
| 30 | 30 | */ |
| 31 | 31 | public abstract class DelegatingLoadBalancingPolicy implements ChainableLoadBalancingPolicy { |
modified driver-core/src/test/java/com/datastax/driver/core/policies/DelegatingSpeculativeExecutionPolicy.java +1 −1
| @@ -20,7 +20,7 @@ | ||
| 20 | 20 | |
| 21 | 21 | /** |
| 22 | 22 | * Base class for tests that want to wrap a policy to add some instrumentation. |
| 23 | - * | |
| 23 | + * <p/> | |
| 24 | 24 | * NB: this is currently only used in tests, but could be provided as a convenience in the production code. |
| 25 | 25 | */ |
| 26 | 26 | public abstract class DelegatingSpeculativeExecutionPolicy implements SpeculativeExecutionPolicy { |
modified driver-core/src/test/java/com/datastax/driver/core/policies/DowngradingConsistencyRetryPolicyIntegrationTest.java +7 −12
| @@ -15,24 +15,19 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core.policies; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.*; | |
| 18 | 19 | import com.google.common.base.Objects; |
| 19 | 20 | import org.mockito.Mockito; |
| 20 | 21 | import org.mockito.verification.VerificationMode; |
| 21 | 22 | import org.testng.annotations.Test; |
| 22 | 23 | |
| 24 | +import static com.datastax.driver.core.ConsistencyLevel.*; | |
| 23 | 25 | import static org.assertj.core.api.Assertions.assertThat; |
| 24 | 26 | import static org.mockito.Matchers.any; |
| 25 | 27 | import static org.mockito.Matchers.anyInt; |
| 26 | 28 | import static org.mockito.Mockito.never; |
| 27 | 29 | import static org.mockito.Mockito.times; |
| 28 | 30 | |
| 29 | -import com.datastax.driver.core.*; | |
| 30 | - | |
| 31 | -import static com.datastax.driver.core.ConsistencyLevel.ALL; | |
| 32 | -import static com.datastax.driver.core.ConsistencyLevel.ONE; | |
| 33 | -import static com.datastax.driver.core.ConsistencyLevel.QUORUM; | |
| 34 | -import static com.datastax.driver.core.ConsistencyLevel.TWO; | |
| 35 | - | |
| 36 | 31 | /** |
| 37 | 32 | * Note: we can't extend {@link AbstractRetryPolicyIntegrationTest} here, because SCassandra doesn't allow custom values for |
| 38 | 33 | * receivedResponses in primed responses. |
| @@ -48,9 +43,9 @@ | ||
| 48 | 43 | // 3-node cluster, keyspace with RF = 3 |
| 49 | 44 | ccm = CCMBridge.builder(this.getClass().getName()).withNodes(3).build(); |
| 50 | 45 | cluster = Cluster.builder() |
| 51 | - .addContactPoint(CCMBridge.ipOfNode(1)) | |
| 52 | - .withRetryPolicy(Mockito.spy(DowngradingConsistencyRetryPolicy.INSTANCE)) | |
| 53 | - .build(); | |
| 46 | + .addContactPoint(CCMBridge.ipOfNode(1)) | |
| 47 | + .withRetryPolicy(Mockito.spy(DowngradingConsistencyRetryPolicy.INSTANCE)) | |
| 48 | + .build(); | |
| 54 | 49 | Session session = cluster.connect(); |
| 55 | 50 | |
| 56 | 51 | session.execute("CREATE KEYSPACE test WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 3}"); |
| @@ -91,7 +86,7 @@ | ||
| 91 | 86 | Mockito.reset(retryPolicy); |
| 92 | 87 | |
| 93 | 88 | Statement s = new SimpleStatement("SELECT * FROM test.foo WHERE k = 0") |
| 94 | - .setConsistencyLevel(requested); | |
| 89 | + .setConsistencyLevel(requested); | |
| 95 | 90 | |
| 96 | 91 | ResultSet rs = session.execute(s); |
| 97 | 92 | |
| @@ -104,6 +99,6 @@ | ||
| 104 | 99 | // If the level was downgraded the policy should have been invoked |
| 105 | 100 | VerificationMode expectedCallsToPolicy = (expected == requested) ? never() : times(1); |
| 106 | 101 | Mockito.verify(retryPolicy, expectedCallsToPolicy).onUnavailable( |
| 107 | - any(Statement.class), any(ConsistencyLevel.class), anyInt(), anyInt(), anyInt()); | |
| 102 | + any(Statement.class), any(ConsistencyLevel.class), anyInt(), anyInt(), anyInt()); | |
| 108 | 103 | } |
| 109 | 104 | } |
modified driver-core/src/test/java/com/datastax/driver/core/policies/EC2MultiRegionAddressTranslatorTest.java +5 −5
| @@ -55,7 +55,7 @@ | ||
| 55 | 55 | InetSocketAddress expectedAddress = new InetSocketAddress("54.32.55.66", 9042); |
| 56 | 56 | |
| 57 | 57 | InitialDirContext mock = mock(InitialDirContext.class); |
| 58 | - when(mock.getAttributes("5.2.0.192.in-addr.arpa", new String[] { "PTR" })) | |
| 58 | + when(mock.getAttributes("5.2.0.192.in-addr.arpa", new String[]{"PTR"})) | |
| 59 | 59 | .thenReturn(new BasicAttributes("PTR", expectedAddress.getHostName())); |
| 60 | 60 | EC2MultiRegionAddressTranslator translator = new EC2MultiRegionAddressTranslator(mock); |
| 61 | 61 | |
| @@ -79,9 +79,9 @@ | ||
| 79 | 79 | public void should_build_reversed_domain_name_for_ip_v4() throws Exception { |
| 80 | 80 | InetAddress address = InetAddress.getByName("192.0.2.5"); |
| 81 | 81 | assertThat( |
| 82 | - EC2MultiRegionAddressTranslator.reverse(address) | |
| 82 | + EC2MultiRegionAddressTranslator.reverse(address) | |
| 83 | 83 | ).isEqualTo( |
| 84 | - "5.2.0.192.in-addr.arpa" | |
| 84 | + "5.2.0.192.in-addr.arpa" | |
| 85 | 85 | ); |
| 86 | 86 | } |
| 87 | 87 | |
| @@ -89,9 +89,9 @@ | ||
| 89 | 89 | public void should_build_reversed_domain_name_for_ip_v6() throws Exception { |
| 90 | 90 | InetAddress address = InetAddress.getByName("2001:db8::567:89ab"); |
| 91 | 91 | assertThat( |
| 92 | - EC2MultiRegionAddressTranslator.reverse(address) | |
| 92 | + EC2MultiRegionAddressTranslator.reverse(address) | |
| 93 | 93 | ).isEqualTo( |
| 94 | - "b.a.9.8.7.6.5.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa" | |
| 94 | + "b.a.9.8.7.6.5.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa" | |
| 95 | 95 | ); |
| 96 | 96 | } |
| 97 | 97 | } |
| No newline at the end of the file |
modified driver-core/src/test/java/com/datastax/driver/core/policies/FallthroughRetryPolicyIntegrationTest.java +6 −7
| @@ -15,6 +15,8 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core.policies; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.SocketOptions; | |
| 19 | +import com.datastax.driver.core.exceptions.*; | |
| 18 | 20 | import org.assertj.core.api.Fail; |
| 19 | 21 | import org.scassandra.http.client.PrimingRequest; |
| 20 | 22 | import org.testng.annotations.DataProvider; |
| @@ -25,9 +27,6 @@ | ||
| 25 | 27 | import static org.scassandra.http.client.PrimingRequest.Result.*; |
| 26 | 28 | import static org.scassandra.http.client.PrimingRequest.then; |
| 27 | 29 | |
| 28 | -import com.datastax.driver.core.SocketOptions; | |
| 29 | -import com.datastax.driver.core.exceptions.*; | |
| 30 | - | |
| 31 | 30 | public class FallthroughRetryPolicyIntegrationTest extends AbstractRetryPolicyIntegrationTest { |
| 32 | 31 | public FallthroughRetryPolicyIntegrationTest() { |
| 33 | 32 | super(FallthroughRetryPolicy.INSTANCE); |
| @@ -86,7 +85,7 @@ | ||
| 86 | 85 | cluster.getConfiguration().getSocketOptions().setReadTimeoutMillis(1); |
| 87 | 86 | try { |
| 88 | 87 | scassandras |
| 89 | - .node(1).primingClient().prime(PrimingRequest.queryBuilder() | |
| 88 | + .node(1).primingClient().prime(PrimingRequest.queryBuilder() | |
| 90 | 89 | .withQuery("mock query") |
| 91 | 90 | .withThen(then().withFixedDelay(1000L).withRows(row("result", "result1"))) |
| 92 | 91 | .build()); |
| @@ -95,7 +94,7 @@ | ||
| 95 | 94 | Fail.fail("expected an OperationTimedOutException"); |
| 96 | 95 | } catch (OperationTimedOutException e) { |
| 97 | 96 | assertThat(e.getMessage()).isEqualTo( |
| 98 | - String.format("[%s] Timed out waiting for server response", host1.getAddress()) | |
| 97 | + String.format("[%s] Timed out waiting for server response", host1.getAddress()) | |
| 99 | 98 | ); |
| 100 | 99 | } |
| 101 | 100 | assertOnRequestErrorWasCalled(1, OperationTimedOutException.class); |
| @@ -113,8 +112,8 @@ | ||
| 113 | 112 | @DataProvider |
| 114 | 113 | public static Object[][] serverSideErrors() { |
| 115 | 114 | return new Object[][]{ |
| 116 | - {server_error, ServerError.class}, | |
| 117 | - {overloaded, OverloadedException.class} | |
| 115 | + {server_error, ServerError.class}, | |
| 116 | + {overloaded, OverloadedException.class} | |
| 118 | 117 | }; |
| 119 | 118 | } |
| 120 | 119 |
modified driver-core/src/test/java/com/datastax/driver/core/policies/HostFilterPolicyTest.java +11 −12
| @@ -15,9 +15,10 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core.policies; |
| 17 | 17 | |
| 18 | -import java.net.InetSocketAddress; | |
| 19 | -import java.util.Collection; | |
| 20 | - | |
| 18 | +import com.datastax.driver.core.Cluster; | |
| 19 | +import com.datastax.driver.core.Host; | |
| 20 | +import com.datastax.driver.core.HostDistance; | |
| 21 | +import com.datastax.driver.core.Statement; | |
| 21 | 22 | import com.google.common.base.Predicate; |
| 22 | 23 | import com.google.common.base.Predicates; |
| 23 | 24 | import com.google.common.collect.Iterators; |
| @@ -29,14 +30,12 @@ | ||
| 29 | 30 | import org.testng.annotations.BeforeMethod; |
| 30 | 31 | import org.testng.annotations.Test; |
| 31 | 32 | |
| 33 | +import java.net.InetSocketAddress; | |
| 34 | +import java.util.Collection; | |
| 35 | + | |
| 32 | 36 | import static org.assertj.core.api.Assertions.assertThat; |
| 33 | 37 | import static org.mockito.Mockito.*; |
| 34 | 38 | |
| 35 | -import com.datastax.driver.core.Cluster; | |
| 36 | -import com.datastax.driver.core.Host; | |
| 37 | -import com.datastax.driver.core.HostDistance; | |
| 38 | -import com.datastax.driver.core.Statement; | |
| 39 | - | |
| 40 | 39 | public class HostFilterPolicyTest { |
| 41 | 40 | @Mock |
| 42 | 41 | Cluster cluster; |
| @@ -130,12 +129,12 @@ | ||
| 130 | 129 | @Test(groups = "unit") |
| 131 | 130 | public void should_return_query_plan_of_wrapped_policy() { |
| 132 | 131 | when(wrappedPolicy.newQueryPlan(any(String.class), any(Statement.class))) |
| 133 | - .thenReturn(Iterators.forArray(host1, host2, host3)); | |
| 132 | + .thenReturn(Iterators.forArray(host1, host2, host3)); | |
| 134 | 133 | |
| 135 | 134 | HostFilterPolicy policy = new HostFilterPolicy(wrappedPolicy, null); |
| 136 | 135 | |
| 137 | 136 | assertThat(policy.newQueryPlan("keyspace", mock(Statement.class))) |
| 138 | - .containsExactly(host1, host2, host3); | |
| 137 | + .containsExactly(host1, host2, host3); | |
| 139 | 138 | } |
| 140 | 139 | |
| 141 | 140 | @Test(groups = "unit") |
| @@ -145,7 +144,7 @@ | ||
| 145 | 144 | when(host3.getDatacenter()).thenReturn(null); |
| 146 | 145 | |
| 147 | 146 | HostFilterPolicy policy = HostFilterPolicy.fromDCBlackList(wrappedPolicy, |
| 148 | - Lists.newArrayList("dc2")); | |
| 147 | + Lists.newArrayList("dc2")); | |
| 149 | 148 | |
| 150 | 149 | assertThat(policy.distance(host1)).isSameAs(HostDistance.LOCAL); |
| 151 | 150 | assertThat(policy.distance(host2)).isSameAs(HostDistance.IGNORED); |
| @@ -159,7 +158,7 @@ | ||
| 159 | 158 | when(host3.getDatacenter()).thenReturn(null); |
| 160 | 159 | |
| 161 | 160 | HostFilterPolicy policy = HostFilterPolicy.fromDCWhiteList(wrappedPolicy, |
| 162 | - Lists.newArrayList("dc1")); | |
| 161 | + Lists.newArrayList("dc1")); | |
| 163 | 162 | |
| 164 | 163 | assertThat(policy.distance(host1)).isSameAs(HostDistance.LOCAL); |
| 165 | 164 | assertThat(policy.distance(host2)).isSameAs(HostDistance.IGNORED); |
modified driver-core/src/test/java/com/datastax/driver/core/policies/IdempotenceAwareRetryPolicyIntegrationTest.java +12 −15
| @@ -15,6 +15,8 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core.policies; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.*; | |
| 19 | +import com.datastax.driver.core.exceptions.*; | |
| 18 | 20 | import org.scassandra.http.client.PrimingRequest; |
| 19 | 21 | import org.testng.annotations.BeforeMethod; |
| 20 | 22 | import org.testng.annotations.DataProvider; |
| @@ -22,14 +24,9 @@ | ||
| 22 | 24 | |
| 23 | 25 | import static org.assertj.core.api.Assertions.assertThat; |
| 24 | 26 | import static org.assertj.core.api.Assertions.fail; |
| 25 | -import static org.scassandra.http.client.PrimingRequest.Result.overloaded; | |
| 26 | -import static org.scassandra.http.client.PrimingRequest.Result.server_error; | |
| 27 | -import static org.scassandra.http.client.PrimingRequest.Result.write_request_timeout; | |
| 27 | +import static org.scassandra.http.client.PrimingRequest.Result.*; | |
| 28 | 28 | import static org.scassandra.http.client.PrimingRequest.then; |
| 29 | 29 | |
| 30 | -import com.datastax.driver.core.*; | |
| 31 | -import com.datastax.driver.core.exceptions.*; | |
| 32 | - | |
| 33 | 30 | /** |
| 34 | 31 | * Integration test with an IdempotenceAwareRetryPolicy. |
| 35 | 32 | */ |
| @@ -40,7 +37,7 @@ | ||
| 40 | 37 | } |
| 41 | 38 | |
| 42 | 39 | @BeforeMethod(groups = "short") |
| 43 | - public void setUpDefaultIdempotence(){ | |
| 40 | + public void setUpDefaultIdempotence() { | |
| 44 | 41 | cluster.getConfiguration().getQueryOptions().setDefaultIdempotence(false); |
| 45 | 42 | } |
| 46 | 43 | |
| @@ -78,7 +75,7 @@ | ||
| 78 | 75 | cluster.getConfiguration().getSocketOptions().setReadTimeoutMillis(1); |
| 79 | 76 | try { |
| 80 | 77 | scassandras |
| 81 | - .node(1).primingClient().prime(PrimingRequest.queryBuilder() | |
| 78 | + .node(1).primingClient().prime(PrimingRequest.queryBuilder() | |
| 82 | 79 | .withQuery("mock query") |
| 83 | 80 | .withThen(then().withFixedDelay(1000L).withRows(row("result", "result1"))) |
| 84 | 81 | .build()); |
| @@ -87,7 +84,7 @@ | ||
| 87 | 84 | fail("expected an OperationTimedOutException"); |
| 88 | 85 | } catch (OperationTimedOutException e) { |
| 89 | 86 | assertThat(e.getMessage()).isEqualTo( |
| 90 | - String.format("[%s] Timed out waiting for server response", host1.getAddress()) | |
| 87 | + String.format("[%s] Timed out waiting for server response", host1.getAddress()) | |
| 91 | 88 | ); |
| 92 | 89 | } |
| 93 | 90 | assertOnRequestErrorWasCalled(1, OperationTimedOutException.class); |
| @@ -107,7 +104,7 @@ | ||
| 107 | 104 | cluster.getConfiguration().getSocketOptions().setReadTimeoutMillis(1); |
| 108 | 105 | try { |
| 109 | 106 | scassandras |
| 110 | - .node(1).primingClient().prime(PrimingRequest.queryBuilder() | |
| 107 | + .node(1).primingClient().prime(PrimingRequest.queryBuilder() | |
| 111 | 108 | .withQuery("mock query") |
| 112 | 109 | .withThen(then().withFixedDelay(1000L).withRows(row("result", "result1"))) |
| 113 | 110 | .build()); |
| @@ -127,8 +124,8 @@ | ||
| 127 | 124 | @DataProvider |
| 128 | 125 | public static Object[][] serverSideErrors() { |
| 129 | 126 | return new Object[][]{ |
| 130 | - {server_error, ServerError.class}, | |
| 131 | - {overloaded, OverloadedException.class} | |
| 127 | + {server_error, ServerError.class}, | |
| 128 | + {overloaded, OverloadedException.class} | |
| 132 | 129 | }; |
| 133 | 130 | } |
| 134 | 131 | |
| @@ -161,9 +158,9 @@ | ||
| 161 | 158 | fail("expected a NoHostAvailableException"); |
| 162 | 159 | } catch (NoHostAvailableException e) { |
| 163 | 160 | assertThat(e.getErrors().keySet()).hasSize(3).containsOnly( |
| 164 | - host1.getSocketAddress(), | |
| 165 | - host2.getSocketAddress(), | |
| 166 | - host3.getSocketAddress()); | |
| 161 | + host1.getSocketAddress(), | |
| 162 | + host2.getSocketAddress(), | |
| 163 | + host3.getSocketAddress()); | |
| 167 | 164 | assertThat(e.getErrors().values()).hasOnlyElementsOfType(exception); |
| 168 | 165 | } |
| 169 | 166 | assertOnRequestErrorWasCalled(3, exception); |
modified driver-core/src/test/java/com/datastax/driver/core/policies/LatencyAwarePolicyTest.java +26 −26
| @@ -15,23 +15,21 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core.policies; |
| 17 | 17 | |
| 18 | -import java.util.concurrent.CountDownLatch; | |
| 19 | - | |
| 20 | -import static java.util.concurrent.TimeUnit.SECONDS; | |
| 21 | - | |
| 18 | +import com.datastax.driver.core.*; | |
| 22 | 19 | import com.datastax.driver.core.exceptions.NoHostAvailableException; |
| 20 | +import com.datastax.driver.core.exceptions.ReadTimeoutException; | |
| 21 | +import com.datastax.driver.core.exceptions.UnavailableException; | |
| 23 | 22 | import org.testng.annotations.Test; |
| 24 | 23 | |
| 24 | +import java.util.concurrent.CountDownLatch; | |
| 25 | + | |
| 26 | +import static java.util.concurrent.TimeUnit.SECONDS; | |
| 25 | 27 | import static org.assertj.core.api.Assertions.assertThat; |
| 26 | 28 | import static org.assertj.core.api.Assertions.fail; |
| 27 | 29 | import static org.scassandra.http.client.PrimingRequest.Result.read_request_timeout; |
| 28 | 30 | import static org.scassandra.http.client.PrimingRequest.Result.unavailable; |
| 29 | 31 | import static org.scassandra.http.client.PrimingRequest.queryBuilder; |
| 30 | 32 | |
| 31 | -import com.datastax.driver.core.*; | |
| 32 | -import com.datastax.driver.core.exceptions.ReadTimeoutException; | |
| 33 | -import com.datastax.driver.core.exceptions.UnavailableException; | |
| 34 | - | |
| 35 | 33 | public class LatencyAwarePolicyTest extends ScassandraTestBase { |
| 36 | 34 | |
| 37 | 35 | /** |
| @@ -55,10 +53,12 @@ | ||
| 55 | 53 | } |
| 56 | 54 | |
| 57 | 55 | @Override |
| 58 | - public void onRegister(Cluster cluster) {} | |
| 56 | + public void onRegister(Cluster cluster) { | |
| 57 | + } | |
| 59 | 58 | |
| 60 | 59 | @Override |
| 61 | - public void onUnregister(Cluster cluster) {} | |
| 60 | + public void onUnregister(Cluster cluster) { | |
| 61 | + } | |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | @Test(groups = "short") |
| @@ -66,13 +66,13 @@ | ||
| 66 | 66 | // given |
| 67 | 67 | String query = "SELECT foo FROM bar"; |
| 68 | 68 | primingClient.prime( |
| 69 | - queryBuilder() | |
| 70 | - .withQuery(query) | |
| 71 | - .build() | |
| 69 | + queryBuilder() | |
| 70 | + .withQuery(query) | |
| 71 | + .build() | |
| 72 | 72 | ); |
| 73 | 73 | LatencyAwarePolicy latencyAwarePolicy = LatencyAwarePolicy.builder(new RoundRobinPolicy()) |
| 74 | - .withMininumMeasurements(1) | |
| 75 | - .build(); | |
| 74 | + .withMininumMeasurements(1) | |
| 75 | + .build(); | |
| 76 | 76 | Cluster.Builder builder = super.createClusterBuilder(); |
| 77 | 77 | builder.withLoadBalancingPolicy(latencyAwarePolicy); |
| 78 | 78 | Cluster cluster = builder.build(); |
| @@ -104,14 +104,14 @@ | ||
| 104 | 104 | // given |
| 105 | 105 | String query = "SELECT foo FROM bar"; |
| 106 | 106 | primingClient.prime( |
| 107 | - queryBuilder() | |
| 108 | - .withQuery(query) | |
| 109 | - .withResult(unavailable) | |
| 110 | - .build() | |
| 107 | + queryBuilder() | |
| 108 | + .withQuery(query) | |
| 109 | + .withResult(unavailable) | |
| 110 | + .build() | |
| 111 | 111 | ); |
| 112 | 112 | LatencyAwarePolicy latencyAwarePolicy = LatencyAwarePolicy.builder(new RoundRobinPolicy()) |
| 113 | - .withMininumMeasurements(1) | |
| 114 | - .build(); | |
| 113 | + .withMininumMeasurements(1) | |
| 114 | + .build(); | |
| 115 | 115 | Cluster.Builder builder = super.createClusterBuilder(); |
| 116 | 116 | builder.withLoadBalancingPolicy(latencyAwarePolicy); |
| 117 | 117 | Cluster cluster = builder.build(); |
| @@ -144,14 +144,14 @@ | ||
| 144 | 144 | } |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | - @Test(groups= "short") | |
| 147 | + @Test(groups = "short") | |
| 148 | 148 | public void should_consider_latency_when_read_timeout() throws Exception { |
| 149 | 149 | String query = "SELECT foo FROM bar"; |
| 150 | 150 | primingClient.prime( |
| 151 | - queryBuilder() | |
| 152 | - .withQuery(query) | |
| 153 | - .withResult(read_request_timeout) | |
| 154 | - .build() | |
| 151 | + queryBuilder() | |
| 152 | + .withQuery(query) | |
| 153 | + .withResult(read_request_timeout) | |
| 154 | + .build() | |
| 155 | 155 | ); |
| 156 | 156 | |
| 157 | 157 | LatencyAwarePolicy latencyAwarePolicy = LatencyAwarePolicy.builder(new RoundRobinPolicy()) |
modified driver-core/src/test/java/com/datastax/driver/core/policies/LimitingLoadBalancingPolicy.java +12 −13
| @@ -15,27 +15,26 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core.policies; |
| 17 | 17 | |
| 18 | -import java.util.*; | |
| 19 | -import java.util.concurrent.ConcurrentHashMap; | |
| 20 | -import java.util.concurrent.locks.Lock; | |
| 21 | -import java.util.concurrent.locks.ReentrantLock; | |
| 22 | - | |
| 23 | -import com.google.common.collect.Sets; | |
| 24 | - | |
| 25 | 18 | import com.datastax.driver.core.Cluster; |
| 26 | 19 | import com.datastax.driver.core.Host; |
| 27 | 20 | import com.datastax.driver.core.HostDistance; |
| 28 | 21 | import com.datastax.driver.core.Statement; |
| 22 | +import com.google.common.collect.Sets; | |
| 23 | + | |
| 24 | +import java.util.*; | |
| 25 | +import java.util.concurrent.ConcurrentHashMap; | |
| 26 | +import java.util.concurrent.locks.Lock; | |
| 27 | +import java.util.concurrent.locks.ReentrantLock; | |
| 29 | 28 | |
| 30 | 29 | /** |
| 31 | 30 | * Sample load balancing policy that limits the number of nodes the driver connects to. |
| 32 | - * | |
| 31 | + * <p/> | |
| 33 | 32 | * If more nodes are available, they are marked as IGNORED. When one of the "chosen" nodes |
| 34 | 33 | * goes down, the policy picks one of the ignored nodes to replace it. |
| 35 | - * <p> | |
| 34 | + * <p/> | |
| 36 | 35 | * This kind of policy can be used to alleviate the load on a cluster that has a lot of |
| 37 | 36 | * clients. |
| 38 | - * <p> | |
| 37 | + * <p/> | |
| 39 | 38 | * For simplicity, this policy does not distinguish LOCAL and REMOTE nodes. |
| 40 | 39 | */ |
| 41 | 40 | public class LimitingLoadBalancingPolicy extends DelegatingLoadBalancingPolicy { |
| @@ -48,8 +47,8 @@ | ||
| 48 | 47 | private volatile Cluster cluster; |
| 49 | 48 | |
| 50 | 49 | /** |
| 51 | - * @param delegate the underlying policy that will be fed with the chosen nodes | |
| 52 | - * @param maxHosts the maximum number of chosen nodes | |
| 50 | + * @param delegate the underlying policy that will be fed with the chosen nodes | |
| 51 | + * @param maxHosts the maximum number of chosen nodes | |
| 53 | 52 | * @param threshold how many chosen nodes we accept to lose before we start picking new ones |
| 54 | 53 | */ |
| 55 | 54 | public LimitingLoadBalancingPolicy(LoadBalancingPolicy delegate, int maxHosts, int threshold) { |
| @@ -63,7 +62,7 @@ | ||
| 63 | 62 | this.cluster = cluster; |
| 64 | 63 | |
| 65 | 64 | Iterator<Host> hostIt = hosts.iterator(); |
| 66 | - while(hostIt.hasNext() && chosenHosts.size() <= maxHosts - threshold) { | |
| 65 | + while (hostIt.hasNext() && chosenHosts.size() <= maxHosts - threshold) { | |
| 67 | 66 | chosenHosts.add(hostIt.next()); |
| 68 | 67 | } |
| 69 | 68 |
modified driver-core/src/test/java/com/datastax/driver/core/policies/LoggingRetryPolicyIntegrationTest.java +13 −15
| @@ -15,20 +15,16 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core.policies; |
| 17 | 17 | |
| 18 | -import org.apache.log4j.Level; | |
| 19 | -import org.apache.log4j.Logger; | |
| 20 | -import org.slf4j.helpers.MessageFormatter; | |
| 21 | -import org.testng.annotations.*; | |
| 22 | - | |
| 23 | -import static org.apache.log4j.Level.INFO; | |
| 24 | -import static org.scassandra.http.client.PrimingRequest.Result.read_request_timeout; | |
| 25 | -import static org.scassandra.http.client.PrimingRequest.Result.server_error; | |
| 26 | -import static org.scassandra.http.client.PrimingRequest.Result.unavailable; | |
| 27 | -import static org.scassandra.http.client.PrimingRequest.Result.write_request_timeout; | |
| 28 | - | |
| 29 | 18 | import com.datastax.driver.core.*; |
| 30 | 19 | import com.datastax.driver.core.exceptions.DriverException; |
| 31 | 20 | import com.datastax.driver.core.exceptions.ServerError; |
| 21 | +import org.apache.log4j.Level; | |
| 22 | +import org.apache.log4j.Logger; | |
| 23 | +import org.slf4j.helpers.MessageFormatter; | |
| 24 | +import org.testng.annotations.AfterMethod; | |
| 25 | +import org.testng.annotations.BeforeClass; | |
| 26 | +import org.testng.annotations.BeforeMethod; | |
| 27 | +import org.testng.annotations.Test; | |
| 32 | 28 | |
| 33 | 29 | import static com.datastax.driver.core.Assertions.assertThat; |
| 34 | 30 | import static com.datastax.driver.core.ConsistencyLevel.LOCAL_ONE; |
| @@ -36,6 +32,8 @@ | ||
| 36 | 32 | import static com.datastax.driver.core.policies.LoggingRetryPolicy.*; |
| 37 | 33 | import static com.datastax.driver.core.policies.RetryPolicy.RetryDecision.ignore; |
| 38 | 34 | import static com.datastax.driver.core.policies.RetryPolicy.RetryDecision.tryNextHost; |
| 35 | +import static org.apache.log4j.Level.INFO; | |
| 36 | +import static org.scassandra.http.client.PrimingRequest.Result.*; | |
| 39 | 37 | |
| 40 | 38 | /** |
| 41 | 39 | * Integration tests with LoggingRetryPolicy. |
| @@ -51,24 +49,24 @@ | ||
| 51 | 49 | private Level originalLevel; |
| 52 | 50 | private ConsistencyLevel defaultCL; |
| 53 | 51 | |
| 54 | - @BeforeClass(groups = { "short", "unit" }) | |
| 52 | + @BeforeClass(groups = {"short", "unit"}) | |
| 55 | 53 | public void setUpRetryPolicy() { |
| 56 | 54 | setRetryPolicy(new LoggingRetryPolicy(new CustomRetryPolicy())); |
| 57 | 55 | } |
| 58 | 56 | |
| 59 | - @BeforeMethod(groups = { "short", "unit" }) | |
| 57 | + @BeforeMethod(groups = {"short", "unit"}) | |
| 60 | 58 | public void storeDefaultCL() { |
| 61 | 59 | defaultCL = cluster.getConfiguration().getQueryOptions().getConsistencyLevel(); |
| 62 | 60 | } |
| 63 | 61 | |
| 64 | - @BeforeMethod(groups = { "short", "unit" }) | |
| 62 | + @BeforeMethod(groups = {"short", "unit"}) | |
| 65 | 63 | public void startCapturingLogs() { |
| 66 | 64 | originalLevel = logger.getLevel(); |
| 67 | 65 | logger.setLevel(INFO); |
| 68 | 66 | logger.addAppender(appender = new MemoryAppender()); |
| 69 | 67 | } |
| 70 | 68 | |
| 71 | - @AfterMethod(groups = { "short", "unit" }) | |
| 69 | + @AfterMethod(groups = {"short", "unit"}) | |
| 72 | 70 | public void stopCapturingLogs() { |
| 73 | 71 | logger.setLevel(originalLevel); |
| 74 | 72 | logger.removeAppender(appender); |
modified driver-core/src/test/java/com/datastax/driver/core/policies/RetryDecisionTest.java +15 −19
| @@ -15,16 +15,12 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core.policies; |
| 17 | 17 | |
| 18 | -import org.testng.annotations.Test; | |
| 19 | - | |
| 20 | -import static org.assertj.core.api.Assertions.assertThat; | |
| 21 | - | |
| 22 | 18 | import com.datastax.driver.core.policies.RetryPolicy.RetryDecision; |
| 19 | +import org.testng.annotations.Test; | |
| 23 | 20 | |
| 24 | 21 | import static com.datastax.driver.core.ConsistencyLevel.ONE; |
| 25 | -import static com.datastax.driver.core.policies.RetryPolicy.RetryDecision.Type.IGNORE; | |
| 26 | -import static com.datastax.driver.core.policies.RetryPolicy.RetryDecision.Type.RETHROW; | |
| 27 | -import static com.datastax.driver.core.policies.RetryPolicy.RetryDecision.Type.RETRY; | |
| 22 | +import static com.datastax.driver.core.policies.RetryPolicy.RetryDecision.Type.*; | |
| 23 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 28 | 24 | |
| 29 | 25 | public class RetryDecisionTest { |
| 30 | 26 | |
| @@ -32,34 +28,34 @@ | ||
| 32 | 28 | public void should_expose_decision_properties() throws Throwable { |
| 33 | 29 | RetryDecision retryAtOne = RetryDecision.retry(ONE); |
| 34 | 30 | assertThat(retryAtOne.getType()) |
| 35 | - .isEqualTo(RETRY); | |
| 31 | + .isEqualTo(RETRY); | |
| 36 | 32 | assertThat(retryAtOne.getRetryConsistencyLevel()) |
| 37 | - .isEqualTo(ONE); | |
| 33 | + .isEqualTo(ONE); | |
| 38 | 34 | assertThat(retryAtOne.isRetryCurrent()) |
| 39 | - .isTrue(); | |
| 35 | + .isTrue(); | |
| 40 | 36 | assertThat(retryAtOne.toString()) |
| 41 | - .isEqualTo("Retry at ONE on same host."); | |
| 37 | + .isEqualTo("Retry at ONE on same host."); | |
| 42 | 38 | |
| 43 | 39 | RetryDecision tryNextAtOne = RetryDecision.tryNextHost(ONE); |
| 44 | 40 | assertThat(tryNextAtOne.getType()) |
| 45 | - .isEqualTo(RETRY); | |
| 41 | + .isEqualTo(RETRY); | |
| 46 | 42 | assertThat(tryNextAtOne.getRetryConsistencyLevel()) |
| 47 | - .isEqualTo(ONE); | |
| 43 | + .isEqualTo(ONE); | |
| 48 | 44 | assertThat(tryNextAtOne.isRetryCurrent()) |
| 49 | - .isFalse(); | |
| 45 | + .isFalse(); | |
| 50 | 46 | assertThat(tryNextAtOne.toString()) |
| 51 | - .isEqualTo("Retry at ONE on next host."); | |
| 47 | + .isEqualTo("Retry at ONE on next host."); | |
| 52 | 48 | |
| 53 | 49 | RetryDecision rethrow = RetryDecision.rethrow(); |
| 54 | 50 | assertThat(rethrow.getType()) |
| 55 | - .isEqualTo(RETHROW); | |
| 51 | + .isEqualTo(RETHROW); | |
| 56 | 52 | assertThat(rethrow.toString()) |
| 57 | - .isEqualTo("Rethrow"); | |
| 53 | + .isEqualTo("Rethrow"); | |
| 58 | 54 | |
| 59 | 55 | RetryDecision ignore = RetryDecision.ignore(); |
| 60 | 56 | assertThat(ignore.getType()) |
| 61 | - .isEqualTo(IGNORE); | |
| 57 | + .isEqualTo(IGNORE); | |
| 62 | 58 | assertThat(ignore.toString()) |
| 63 | - .isEqualTo("Ignore"); | |
| 59 | + .isEqualTo("Ignore"); | |
| 64 | 60 | } |
| 65 | 61 | } |
modified driver-core/src/test/java/com/datastax/driver/core/policies/RoundRobinPolicyTest.java +21 −28
| @@ -15,20 +15,13 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core.policies; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.*; | |
| 18 | 19 | import org.apache.log4j.Level; |
| 19 | 20 | import org.apache.log4j.Logger; |
| 20 | 21 | import org.testng.annotations.AfterMethod; |
| 21 | 22 | import org.testng.annotations.BeforeMethod; |
| 22 | 23 | import org.testng.annotations.Test; |
| 23 | 24 | |
| 24 | -import com.datastax.driver.core.Cluster; | |
| 25 | -import com.datastax.driver.core.ConsistencyLevel; | |
| 26 | -import com.datastax.driver.core.DataProviders; | |
| 27 | -import com.datastax.driver.core.MemoryAppender; | |
| 28 | -import com.datastax.driver.core.QueryTracker; | |
| 29 | -import com.datastax.driver.core.ScassandraCluster; | |
| 30 | -import com.datastax.driver.core.Session; | |
| 31 | - | |
| 32 | 25 | import static com.datastax.driver.core.Assertions.assertThat; |
| 33 | 26 | import static com.datastax.driver.core.TestUtils.nonQuietClusterCloseOptions; |
| 34 | 27 | |
| @@ -58,16 +51,16 @@ | ||
| 58 | 51 | * |
| 59 | 52 | * @test_category load_balancing:round_robin |
| 60 | 53 | */ |
| 61 | - @Test(groups="short") | |
| 54 | + @Test(groups = "short") | |
| 62 | 55 | public void should_round_robin_within_single_datacenter() { |
| 63 | 56 | // given: a 5 node cluster using RoundRobinPolicy. |
| 64 | 57 | ScassandraCluster sCluster = ScassandraCluster.builder().withNodes(5).build(); |
| 65 | 58 | |
| 66 | 59 | Cluster cluster = Cluster.builder() |
| 67 | - .addContactPoint(sCluster.address(1)) | |
| 68 | - .withLoadBalancingPolicy(new RoundRobinPolicy()) | |
| 69 | - .withNettyOptions(nonQuietClusterCloseOptions) | |
| 70 | - .build(); | |
| 60 | + .addContactPoint(sCluster.address(1)) | |
| 61 | + .withLoadBalancingPolicy(new RoundRobinPolicy()) | |
| 62 | + .withNettyOptions(nonQuietClusterCloseOptions) | |
| 63 | + .build(); | |
| 71 | 64 | |
| 72 | 65 | try { |
| 73 | 66 | sCluster.init(); |
| @@ -77,7 +70,7 @@ | ||
| 77 | 70 | queryTracker.query(session, 50); |
| 78 | 71 | |
| 79 | 72 | // then: all nodes should be queried equally. |
| 80 | - for(int i = 1; i <= 5; i++) { | |
| 73 | + for (int i = 1; i <= 5; i++) { | |
| 81 | 74 | queryTracker.assertQueried(sCluster, 1, i, 10); |
| 82 | 75 | } |
| 83 | 76 | } finally { |
| @@ -93,16 +86,16 @@ | ||
| 93 | 86 | * |
| 94 | 87 | * @test_category load_balancing:round_robin |
| 95 | 88 | */ |
| 96 | - @Test(groups="short") | |
| 89 | + @Test(groups = "short") | |
| 97 | 90 | public void should_round_robin_irrespective_of_topology() { |
| 98 | 91 | // given: a 10 node, 5 DC cluster using RoundRobinPolicy. |
| 99 | - ScassandraCluster sCluster = ScassandraCluster.builder().withNodes(2,2,2,2,2).build(); | |
| 92 | + ScassandraCluster sCluster = ScassandraCluster.builder().withNodes(2, 2, 2, 2, 2).build(); | |
| 100 | 93 | |
| 101 | 94 | Cluster cluster = Cluster.builder() |
| 102 | - .addContactPoint(sCluster.address(1)) | |
| 103 | - .withLoadBalancingPolicy(new RoundRobinPolicy()) | |
| 104 | - .withNettyOptions(nonQuietClusterCloseOptions) | |
| 105 | - .build(); | |
| 95 | + .addContactPoint(sCluster.address(1)) | |
| 96 | + .withLoadBalancingPolicy(new RoundRobinPolicy()) | |
| 97 | + .withNettyOptions(nonQuietClusterCloseOptions) | |
| 98 | + .build(); | |
| 106 | 99 | |
| 107 | 100 | try { |
| 108 | 101 | sCluster.init(); |
| @@ -112,7 +105,7 @@ | ||
| 112 | 105 | queryTracker.query(session, 50); |
| 113 | 106 | |
| 114 | 107 | // then: all nodes should be queried equally. |
| 115 | - for(int dc = 1; dc <= 5; dc++) { | |
| 108 | + for (int dc = 1; dc <= 5; dc++) { | |
| 116 | 109 | for (int i = 1; i <= 2; i++) { |
| 117 | 110 | queryTracker.assertQueried(sCluster, dc, i, 5); |
| 118 | 111 | } |
| @@ -131,16 +124,16 @@ | ||
| 131 | 124 | * |
| 132 | 125 | * @test_category load_balancing:round_robin |
| 133 | 126 | */ |
| 134 | - @Test(groups="short", dataProvider="consistencyLevels", dataProviderClass=DataProviders.class) | |
| 127 | + @Test(groups = "short", dataProvider = "consistencyLevels", dataProviderClass = DataProviders.class) | |
| 135 | 128 | public void should_warn_if_using_dc_local_consistency_level(ConsistencyLevel cl) { |
| 136 | 129 | // given: a 2 node, 2 DC cluster using RoundRobinPolicy. |
| 137 | - ScassandraCluster sCluster = ScassandraCluster.builder().withNodes(1,1).build(); | |
| 130 | + ScassandraCluster sCluster = ScassandraCluster.builder().withNodes(1, 1).build(); | |
| 138 | 131 | |
| 139 | 132 | Cluster cluster = Cluster.builder() |
| 140 | - .addContactPoint(sCluster.address(1)) | |
| 141 | - .withLoadBalancingPolicy(new RoundRobinPolicy()) | |
| 142 | - .withNettyOptions(nonQuietClusterCloseOptions) | |
| 143 | - .build(); | |
| 133 | + .addContactPoint(sCluster.address(1)) | |
| 134 | + .withLoadBalancingPolicy(new RoundRobinPolicy()) | |
| 135 | + .withNettyOptions(nonQuietClusterCloseOptions) | |
| 136 | + .build(); | |
| 144 | 137 | |
| 145 | 138 | String expectedLogMessage = "Detected request at Consistency Level " + cl + " but the non-DC aware RoundRobinPolicy is in use."; |
| 146 | 139 | |
| @@ -156,7 +149,7 @@ | ||
| 156 | 149 | queryTracker.assertQueried(sCluster, 2, 1, 25); |
| 157 | 150 | |
| 158 | 151 | // Should get a warning if using a local DC cl. |
| 159 | - if(cl.isDCLocal()) { | |
| 152 | + if (cl.isDCLocal()) { | |
| 160 | 153 | assertThat(logs.get()).containsOnlyOnce(expectedLogMessage); |
| 161 | 154 | } else { |
| 162 | 155 | assertThat(logs.get()).doesNotContain(expectedLogMessage); |
modified driver-core/src/test/java/com/datastax/driver/core/policies/TokenAwarePolicyTest.java +61 −65
| @@ -15,22 +15,18 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core.policies; |
| 17 | 17 | |
| 18 | -import java.nio.ByteBuffer; | |
| 19 | -import java.util.List; | |
| 20 | - | |
| 18 | +import com.datastax.driver.core.*; | |
| 21 | 19 | import com.google.common.collect.ImmutableMap; |
| 22 | 20 | import com.google.common.collect.Lists; |
| 23 | 21 | import org.testng.annotations.BeforeMethod; |
| 24 | 22 | import org.testng.annotations.DataProvider; |
| 25 | 23 | import org.testng.annotations.Test; |
| 26 | 24 | |
| 27 | -import com.datastax.driver.core.*; | |
| 25 | +import java.nio.ByteBuffer; | |
| 26 | +import java.util.List; | |
| 28 | 27 | |
| 29 | 28 | import static com.datastax.driver.core.Assertions.assertThat; |
| 30 | -import static com.datastax.driver.core.TestUtils.CREATE_KEYSPACE_SIMPLE_FORMAT; | |
| 31 | -import static com.datastax.driver.core.TestUtils.SIMPLE_KEYSPACE; | |
| 32 | -import static com.datastax.driver.core.TestUtils.getDesiredProtocolVersion; | |
| 33 | -import static com.datastax.driver.core.TestUtils.nonQuietClusterCloseOptions; | |
| 29 | +import static com.datastax.driver.core.TestUtils.*; | |
| 34 | 30 | |
| 35 | 31 | public class TokenAwarePolicyTest { |
| 36 | 32 | |
| @@ -41,12 +37,12 @@ | ||
| 41 | 37 | queryTracker = new QueryTracker(); |
| 42 | 38 | } |
| 43 | 39 | |
| 44 | - @DataProvider(name="shuffleProvider") | |
| 45 | - public Object[][] shuffleProvider () { | |
| 46 | - return new Object[][] { | |
| 47 | - { true }, | |
| 48 | - { false }, | |
| 49 | - { null } | |
| 40 | + @DataProvider(name = "shuffleProvider") | |
| 41 | + public Object[][] shuffleProvider() { | |
| 42 | + return new Object[][]{ | |
| 43 | + {true}, | |
| 44 | + {false}, | |
| 45 | + {null} | |
| 50 | 46 | }; |
| 51 | 47 | } |
| 52 | 48 | |
| @@ -57,16 +53,16 @@ | ||
| 57 | 53 | * |
| 58 | 54 | * @test_category load_balancing:token_aware |
| 59 | 55 | */ |
| 60 | - @Test(groups="short", dataProvider="shuffleProvider") | |
| 56 | + @Test(groups = "short", dataProvider = "shuffleProvider") | |
| 61 | 57 | public void should_shuffle_replicas_based_on_configuration(Boolean shuffleReplicas) { |
| 62 | 58 | // given: an 8 node cluster using TokenAwarePolicy and some shuffle replica configuration with a keyspace with replication factor of 3. |
| 63 | 59 | ScassandraCluster sCluster = ScassandraCluster.builder() |
| 64 | - .withNodes(8) | |
| 65 | - .withSimpleKeyspace("keyspace", 3) | |
| 66 | - .build(); | |
| 60 | + .withNodes(8) | |
| 61 | + .withSimpleKeyspace("keyspace", 3) | |
| 62 | + .build(); | |
| 67 | 63 | |
| 68 | 64 | LoadBalancingPolicy loadBalancingPolicy; |
| 69 | - if(shuffleReplicas == null) { | |
| 65 | + if (shuffleReplicas == null) { | |
| 70 | 66 | loadBalancingPolicy = new TokenAwarePolicy(new RoundRobinPolicy()); |
| 71 | 67 | shuffleReplicas = true; |
| 72 | 68 | } else { |
| @@ -74,9 +70,9 @@ | ||
| 74 | 70 | } |
| 75 | 71 | |
| 76 | 72 | Cluster cluster = Cluster.builder().addContactPoints(sCluster.address(1)) |
| 77 | - .withNettyOptions(nonQuietClusterCloseOptions) | |
| 78 | - .withLoadBalancingPolicy(loadBalancingPolicy) | |
| 79 | - .build(); | |
| 73 | + .withNettyOptions(nonQuietClusterCloseOptions) | |
| 74 | + .withLoadBalancingPolicy(loadBalancingPolicy) | |
| 75 | + .build(); | |
| 80 | 76 | |
| 81 | 77 | try { |
| 82 | 78 | sCluster.init(); |
| @@ -91,9 +87,9 @@ | ||
| 91 | 87 | // then: The replicas resolved from the cluster metadata must match node 6 and its replicas. |
| 92 | 88 | List<Host> replicas = Lists.newArrayList(cluster.getMetadata().getReplicas("keyspace", routingKey)); |
| 93 | 89 | assertThat(replicas).containsExactly( |
| 94 | - sCluster.host(cluster, 1, 6), | |
| 95 | - sCluster.host(cluster, 1, 7), | |
| 96 | - sCluster.host(cluster, 1, 8)); | |
| 90 | + sCluster.host(cluster, 1, 6), | |
| 91 | + sCluster.host(cluster, 1, 7), | |
| 92 | + sCluster.host(cluster, 1, 8)); | |
| 97 | 93 | |
| 98 | 94 | // then: generating a query plan on a statement using that routing key should properly prioritize node 6 and its replicas. |
| 99 | 95 | // Actual query does not matter, only the keyspace and routing key will be used |
| @@ -102,16 +98,16 @@ | ||
| 102 | 98 | statement.setKeyspace("keyspace"); |
| 103 | 99 | |
| 104 | 100 | boolean shuffledAtLeastOnce = false; |
| 105 | - for(int i = 0; i < 1024; i++) { | |
| 101 | + for (int i = 0; i < 1024; i++) { | |
| 106 | 102 | List<Host> queryPlan = Lists.newArrayList(loadBalancingPolicy.newQueryPlan(null, statement)); |
| 107 | 103 | assertThat(queryPlan).containsOnlyElementsOf(cluster.getMetadata().getAllHosts()); |
| 108 | 104 | |
| 109 | 105 | List<Host> firstThree = queryPlan.subList(0, 3); |
| 110 | 106 | // then: if shuffle replicas was used or using default, the first three hosts returned should be 6,7,8 in any order. |
| 111 | 107 | // if shuffle replicas was not used, the first three hosts returned should be 6,7,8 in that order. |
| 112 | - if(shuffleReplicas) { | |
| 108 | + if (shuffleReplicas) { | |
| 113 | 109 | assertThat(firstThree).containsOnlyElementsOf(replicas); |
| 114 | - if(!firstThree.equals(replicas)) { | |
| 110 | + if (!firstThree.equals(replicas)) { | |
| 115 | 111 | shuffledAtLeastOnce = true; |
| 116 | 112 | } |
| 117 | 113 | } else { |
| @@ -134,17 +130,17 @@ | ||
| 134 | 130 | * |
| 135 | 131 | * @test_category load_balancing:token_aware |
| 136 | 132 | */ |
| 137 | - @Test(groups="short") | |
| 133 | + @Test(groups = "short") | |
| 138 | 134 | public void should_choose_proper_host_based_on_routing_key() { |
| 139 | 135 | // given: A 3 node cluster using TokenAwarePolicy with a replication factor of 1. |
| 140 | 136 | ScassandraCluster sCluster = ScassandraCluster.builder() |
| 141 | - .withNodes(3) | |
| 142 | - .withSimpleKeyspace("keyspace", 1) | |
| 143 | - .build(); | |
| 137 | + .withNodes(3) | |
| 138 | + .withSimpleKeyspace("keyspace", 1) | |
| 139 | + .build(); | |
| 144 | 140 | Cluster cluster = Cluster.builder().addContactPoints(sCluster.address(1)) |
| 145 | - .withNettyOptions(nonQuietClusterCloseOptions) | |
| 146 | - .withLoadBalancingPolicy(new TokenAwarePolicy(new RoundRobinPolicy())) | |
| 147 | - .build(); | |
| 141 | + .withNettyOptions(nonQuietClusterCloseOptions) | |
| 142 | + .withLoadBalancingPolicy(new TokenAwarePolicy(new RoundRobinPolicy())) | |
| 143 | + .build(); | |
| 148 | 144 | |
| 149 | 145 | // when: A query is made with a routing key |
| 150 | 146 | try { |
| @@ -155,8 +151,8 @@ | ||
| 155 | 151 | // Encodes into murmur hash '4557949199137838892' which should belong be owned by node 3. |
| 156 | 152 | ByteBuffer routingKey = TypeCodec.varchar().serialize("should_choose_proper_host_based_on_routing_key", ProtocolVersion.NEWEST_SUPPORTED); |
| 157 | 153 | SimpleStatement statement = new SimpleStatement("select * from table where k=5") |
| 158 | - .setRoutingKey(routingKey) | |
| 159 | - .setKeyspace("keyspace"); | |
| 154 | + .setRoutingKey(routingKey) | |
| 155 | + .setKeyspace("keyspace"); | |
| 160 | 156 | |
| 161 | 157 | queryTracker.query(session, 10, statement); |
| 162 | 158 | |
| @@ -177,20 +173,20 @@ | ||
| 177 | 173 | * |
| 178 | 174 | * @test_category load_balancing:token_aware |
| 179 | 175 | */ |
| 180 | - @Test(groups="short") | |
| 176 | + @Test(groups = "short") | |
| 181 | 177 | public void should_choose_host_in_local_dc_when_using_network_topology_strategy_and_dc_aware() { |
| 182 | 178 | // given: A 6 node, 2 DC cluster with RF 1:1, using TokenAwarePolicy wrapping DCAwareRoundRobinPolicy with remote hosts. |
| 183 | 179 | ScassandraCluster sCluster = ScassandraCluster.builder() |
| 184 | - .withNodes(3, 3) | |
| 185 | - .withNetworkTopologyKeyspace("keyspace", ImmutableMap.of(1, 1, 2, 1)) | |
| 186 | - .build(); | |
| 187 | - Cluster cluster = Cluster.builder().addContactPoints(sCluster.address(2,1)) | |
| 188 | - .withNettyOptions(nonQuietClusterCloseOptions) | |
| 189 | - .withLoadBalancingPolicy(new TokenAwarePolicy(DCAwareRoundRobinPolicy.builder() | |
| 190 | - .withLocalDc(ScassandraCluster.datacenter(2)) | |
| 191 | - .withUsedHostsPerRemoteDc(3) | |
| 192 | - .build())) | |
| 193 | - .build(); | |
| 180 | + .withNodes(3, 3) | |
| 181 | + .withNetworkTopologyKeyspace("keyspace", ImmutableMap.of(1, 1, 2, 1)) | |
| 182 | + .build(); | |
| 183 | + Cluster cluster = Cluster.builder().addContactPoints(sCluster.address(2, 1)) | |
| 184 | + .withNettyOptions(nonQuietClusterCloseOptions) | |
| 185 | + .withLoadBalancingPolicy(new TokenAwarePolicy(DCAwareRoundRobinPolicy.builder() | |
| 186 | + .withLocalDc(ScassandraCluster.datacenter(2)) | |
| 187 | + .withUsedHostsPerRemoteDc(3) | |
| 188 | + .build())) | |
| 189 | + .build(); | |
| 194 | 190 | |
| 195 | 191 | // when: A query is made with a routing key |
| 196 | 192 | try { |
| @@ -201,8 +197,8 @@ | ||
| 201 | 197 | // Encodes into murmur hash '-8124212968526248339' which should belong to 1:1 in DC1 and 2:1 in DC2. |
| 202 | 198 | ByteBuffer routingKey = TypeCodec.varchar().serialize("should_choose_host_in_local_dc_when_using_network_topology_strategy_and_dc_aware", ProtocolVersion.NEWEST_SUPPORTED); |
| 203 | 199 | SimpleStatement statement = new SimpleStatement("select * from table where k=5") |
| 204 | - .setRoutingKey(routingKey) | |
| 205 | - .setKeyspace("keyspace"); | |
| 200 | + .setRoutingKey(routingKey) | |
| 201 | + .setKeyspace("keyspace"); | |
| 206 | 202 | |
| 207 | 203 | queryTracker.query(session, 10, statement); |
| 208 | 204 | |
| @@ -222,18 +218,18 @@ | ||
| 222 | 218 | * |
| 223 | 219 | * @test_category load_balancing:token_aware |
| 224 | 220 | */ |
| 225 | - @Test(groups="short") | |
| 221 | + @Test(groups = "short") | |
| 226 | 222 | public void should_use_other_nodes_when_replicas_having_token_are_down() { |
| 227 | 223 | // given: A 4 node cluster using TokenAwarePolicy with a replication factor of 2. |
| 228 | 224 | ScassandraCluster sCluster = ScassandraCluster.builder() |
| 229 | - .withNodes(4) | |
| 230 | - .withSimpleKeyspace("keyspace", 2) | |
| 231 | - .build(); | |
| 225 | + .withNodes(4) | |
| 226 | + .withSimpleKeyspace("keyspace", 2) | |
| 227 | + .build(); | |
| 232 | 228 | Cluster cluster = Cluster.builder().addContactPoints(sCluster.address(2)) |
| 233 | - .withNettyOptions(nonQuietClusterCloseOptions) | |
| 234 | - // Don't shuffle replicas just to keep test deterministic. | |
| 235 | - .withLoadBalancingPolicy(new TokenAwarePolicy(new RoundRobinPolicy(), false)) | |
| 236 | - .build(); | |
| 229 | + .withNettyOptions(nonQuietClusterCloseOptions) | |
| 230 | + // Don't shuffle replicas just to keep test deterministic. | |
| 231 | + .withLoadBalancingPolicy(new TokenAwarePolicy(new RoundRobinPolicy(), false)) | |
| 232 | + .build(); | |
| 237 | 233 | |
| 238 | 234 | try { |
| 239 | 235 | sCluster.init(); |
| @@ -244,8 +240,8 @@ | ||
| 244 | 240 | // Encodes into murmur hash '6444339665561646341' which should belong to node 4. |
| 245 | 241 | ByteBuffer routingKey = TypeCodec.varchar().serialize("should_use_other_nodes_when_replicas_having_token_are_down", ProtocolVersion.NEWEST_SUPPORTED); |
| 246 | 242 | SimpleStatement statement = new SimpleStatement("select * from table where k=5") |
| 247 | - .setRoutingKey(routingKey) | |
| 248 | - .setKeyspace("keyspace"); | |
| 243 | + .setRoutingKey(routingKey) | |
| 244 | + .setKeyspace("keyspace"); | |
| 249 | 245 | |
| 250 | 246 | queryTracker.query(session, 10, statement); |
| 251 | 247 | |
| @@ -318,9 +314,9 @@ | ||
| 318 | 314 | CCMBridge ccm = CCMBridge.builder("TokenAwarePolicyTest").withNodes(3).notStarted().build(); |
| 319 | 315 | |
| 320 | 316 | Cluster cluster = Cluster.builder() |
| 321 | - .withLoadBalancingPolicy(new TokenAwarePolicy(new RoundRobinPolicy())) | |
| 322 | - .addContactPoint(CCMBridge.ipOfNode(1)) | |
| 323 | - .build(); | |
| 317 | + .withLoadBalancingPolicy(new TokenAwarePolicy(new RoundRobinPolicy())) | |
| 318 | + .addContactPoint(CCMBridge.ipOfNode(1)) | |
| 319 | + .build(); | |
| 324 | 320 | |
| 325 | 321 | try { |
| 326 | 322 | ccm.start(); |
| @@ -336,11 +332,11 @@ | ||
| 336 | 332 | BoundStatement insertBs = insertPs.bind(1, 2, 3); |
| 337 | 333 | |
| 338 | 334 | PreparedStatement selectPs = session.prepare("SELECT * FROM " + table + " WHERE k1=? and k2=?"); |
| 339 | - BoundStatement selectBs = selectPs.bind(1,2); | |
| 335 | + BoundStatement selectBs = selectPs.bind(1, 2); | |
| 340 | 336 | |
| 341 | 337 | // when: executing a prepared statement with a composite partition key. |
| 342 | 338 | // then: should query the correct node (1) in for both insert and select queries. |
| 343 | - for(int i = 0; i < 10; i++) { | |
| 339 | + for (int i = 0; i < 10; i++) { | |
| 344 | 340 | ResultSet rs = session.execute(insertBs); |
| 345 | 341 | assertThat(rs.getExecutionInfo().getQueriedHost()).isEqualTo(TestUtils.findHost(cluster, 1)); |
| 346 | 342 |
modified driver-core/src/test/java/com/datastax/driver/core/policies/WhiteListPolicyTest.java +20 −25
| @@ -15,20 +15,15 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core.policies; |
| 17 | 17 | |
| 18 | -import java.net.InetAddress; | |
| 19 | -import java.net.InetSocketAddress; | |
| 20 | -import java.util.List; | |
| 21 | - | |
| 18 | +import com.datastax.driver.core.*; | |
| 19 | +import com.datastax.driver.core.exceptions.NoHostAvailableException; | |
| 22 | 20 | import com.google.common.collect.Lists; |
| 23 | 21 | import org.testng.annotations.BeforeMethod; |
| 24 | 22 | import org.testng.annotations.Test; |
| 25 | 23 | |
| 26 | -import com.datastax.driver.core.Cluster; | |
| 27 | -import com.datastax.driver.core.ConsistencyLevel; | |
| 28 | -import com.datastax.driver.core.QueryTracker; | |
| 29 | -import com.datastax.driver.core.ScassandraCluster; | |
| 30 | -import com.datastax.driver.core.Session; | |
| 31 | -import com.datastax.driver.core.exceptions.NoHostAvailableException; | |
| 24 | +import java.net.InetAddress; | |
| 25 | +import java.net.InetSocketAddress; | |
| 26 | +import java.util.List; | |
| 32 | 27 | |
| 33 | 28 | import static com.datastax.driver.core.TestUtils.nonQuietClusterCloseOptions; |
| 34 | 29 | |
| @@ -46,25 +41,25 @@ | ||
| 46 | 41 | * <p/> |
| 47 | 42 | * Ensures that: |
| 48 | 43 | * <ol> |
| 49 | - * <li>Only addresses provided in the whitelist are every used for querying.</li> | |
| 50 | - * <li>If no nodes present in the whitelist are available, queries fail with a {@link NoHostAvailableException}</li> | |
| 44 | + * <li>Only addresses provided in the whitelist are every used for querying.</li> | |
| 45 | + * <li>If no nodes present in the whitelist are available, queries fail with a {@link NoHostAvailableException}</li> | |
| 51 | 46 | * </ol> |
| 52 | 47 | * |
| 53 | 48 | * @test_category load_balancing:white_list |
| 54 | 49 | */ |
| 55 | - @Test(groups="short") | |
| 50 | + @Test(groups = "short") | |
| 56 | 51 | public void should_only_query_hosts_in_white_list() throws Exception { |
| 57 | 52 | // given: a 5 node cluster with a WhiteListPolicy targeting nodes 3 and 5. |
| 58 | 53 | ScassandraCluster sCluster = ScassandraCluster.builder().withNodes(5).build(); |
| 59 | 54 | List<InetSocketAddress> whiteList = Lists.newArrayList( |
| 60 | - new InetSocketAddress(InetAddress.getByName(sCluster.address(3)), 9042), | |
| 61 | - new InetSocketAddress(InetAddress.getByName(sCluster.address(5)), 9042)); | |
| 55 | + new InetSocketAddress(InetAddress.getByName(sCluster.address(3)), 9042), | |
| 56 | + new InetSocketAddress(InetAddress.getByName(sCluster.address(5)), 9042)); | |
| 62 | 57 | |
| 63 | 58 | Cluster cluster = Cluster.builder() |
| 64 | - .addContactPoint(sCluster.address(5)) | |
| 65 | - .withLoadBalancingPolicy(new WhiteListPolicy(new RoundRobinPolicy(), whiteList)) | |
| 66 | - .withNettyOptions(nonQuietClusterCloseOptions) | |
| 67 | - .build(); | |
| 59 | + .addContactPoint(sCluster.address(5)) | |
| 60 | + .withLoadBalancingPolicy(new WhiteListPolicy(new RoundRobinPolicy(), whiteList)) | |
| 61 | + .withNettyOptions(nonQuietClusterCloseOptions) | |
| 62 | + .build(); | |
| 68 | 63 | |
| 69 | 64 | try { |
| 70 | 65 | sCluster.init(); |
| @@ -106,7 +101,7 @@ | ||
| 106 | 101 | * |
| 107 | 102 | * @test_category load_balancing:white_list |
| 108 | 103 | */ |
| 109 | - @Test(groups="short", expectedExceptions = {IllegalArgumentException.class}) | |
| 104 | + @Test(groups = "short", expectedExceptions = {IllegalArgumentException.class}) | |
| 110 | 105 | public void should_require_contact_point_in_white_list() throws Exception { |
| 111 | 106 | // given: a 5 node cluster with a WhiteListPolicy targeting node2. |
| 112 | 107 | ScassandraCluster sCluster = ScassandraCluster.builder().withNodes(5).build(); |
| @@ -114,12 +109,12 @@ | ||
| 114 | 109 | // when: using a Cluster instance with none of the contact points in the declared |
| 115 | 110 | // WhiteListPolicy. |
| 116 | 111 | List<InetSocketAddress> whiteList = Lists.newArrayList( |
| 117 | - new InetSocketAddress(InetAddress.getByName(sCluster.address(2)), 9042)); | |
| 112 | + new InetSocketAddress(InetAddress.getByName(sCluster.address(2)), 9042)); | |
| 118 | 113 | Cluster cluster = Cluster.builder() |
| 119 | - .addContactPoint(sCluster.address(3)) | |
| 120 | - .withLoadBalancingPolicy(new WhiteListPolicy(new RoundRobinPolicy(), whiteList)) | |
| 121 | - .withNettyOptions(nonQuietClusterCloseOptions) | |
| 122 | - .build(); | |
| 114 | + .addContactPoint(sCluster.address(3)) | |
| 115 | + .withLoadBalancingPolicy(new WhiteListPolicy(new RoundRobinPolicy(), whiteList)) | |
| 116 | + .withNettyOptions(nonQuietClusterCloseOptions) | |
| 117 | + .build(); | |
| 123 | 118 | |
| 124 | 119 | try { |
| 125 | 120 | sCluster.init(); |
modified driver-core/src/test/java/com/datastax/driver/core/querybuilder/QueryBuilder21ExecutionTest.java +12 −16
| @@ -15,24 +15,20 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core.querybuilder; |
| 17 | 17 | |
| 18 | -import java.util.Arrays; | |
| 19 | -import java.util.Collection; | |
| 20 | - | |
| 21 | -import org.testng.annotations.Test; | |
| 22 | - | |
| 23 | 18 | import com.datastax.driver.core.CCMBridge; |
| 24 | 19 | import com.datastax.driver.core.PreparedStatement; |
| 25 | 20 | import com.datastax.driver.core.ResultSet; |
| 26 | 21 | import com.datastax.driver.core.Row; |
| 27 | 22 | import com.datastax.driver.core.utils.CassandraVersion; |
| 23 | +import org.testng.annotations.Test; | |
| 24 | + | |
| 25 | +import java.util.Arrays; | |
| 26 | +import java.util.Collection; | |
| 28 | 27 | |
| 29 | 28 | import static com.datastax.driver.core.Assertions.assertThat; |
| 30 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.bindMarker; | |
| 31 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.contains; | |
| 32 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.containsKey; | |
| 33 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.select; | |
| 34 | - | |
| 35 | -@CassandraVersion(major=2.1) | |
| 29 | +import static com.datastax.driver.core.querybuilder.QueryBuilder.*; | |
| 30 | + | |
| 31 | +@CassandraVersion(major = 2.1) | |
| 36 | 32 | public class QueryBuilder21ExecutionTest extends CCMBridge.PerClassSingleNodeCluster { |
| 37 | 33 | |
| 38 | 34 | @Override |
| @@ -53,7 +49,7 @@ | ||
| 53 | 49 | ); |
| 54 | 50 | } |
| 55 | 51 | |
| 56 | - @Test(groups="short") | |
| 52 | + @Test(groups = "short") | |
| 57 | 53 | public void should_handle_contains_on_set_with_index() { |
| 58 | 54 | PreparedStatement byCategory = session.prepare(select("id", "description", "categories") |
| 59 | 55 | .from("products") |
| @@ -62,12 +58,12 @@ | ||
| 62 | 58 | ResultSet results = session.execute(byCategory.bind().setString("category", "hdtv")); |
| 63 | 59 | |
| 64 | 60 | assertThat(results.getAvailableWithoutFetching()).isEqualTo(2); |
| 65 | - for(Row row : results) { | |
| 61 | + for (Row row : results) { | |
| 66 | 62 | assertThat(row.getSet("categories", String.class)).contains("hdtv"); |
| 67 | 63 | } |
| 68 | 64 | } |
| 69 | 65 | |
| 70 | - @Test(groups="short") | |
| 66 | + @Test(groups = "short") | |
| 71 | 67 | public void should_handle_contains_on_list_with_index() { |
| 72 | 68 | PreparedStatement byBuyer = session.prepare(select("id", "description", "buyers") |
| 73 | 69 | .from("products") |
| @@ -81,7 +77,7 @@ | ||
| 81 | 77 | assertThat(row.getList("buyers", Integer.class)).contains(4); |
| 82 | 78 | } |
| 83 | 79 | |
| 84 | - @Test(groups="short") | |
| 80 | + @Test(groups = "short") | |
| 85 | 81 | public void should_handle_contains_on_map_with_index() { |
| 86 | 82 | PreparedStatement byFeatures = session.prepare(select("id", "description", "features_values") |
| 87 | 83 | .from("products") |
| @@ -96,7 +92,7 @@ | ||
| 96 | 92 | } |
| 97 | 93 | |
| 98 | 94 | |
| 99 | - @Test(groups="short") | |
| 95 | + @Test(groups = "short") | |
| 100 | 96 | public void should_handle_contains_key_on_map_with_index() { |
| 101 | 97 | PreparedStatement byFeatures = session.prepare(select("id", "description", "features_keys") |
| 102 | 98 | .from("products") |
modified driver-core/src/test/java/com/datastax/driver/core/querybuilder/QueryBuilderExecutionTest.java +8 −12
| @@ -15,19 +15,15 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core.querybuilder; |
| 17 | 17 | |
| 18 | -import java.util.*; | |
| 19 | - | |
| 18 | +import com.datastax.driver.core.*; | |
| 20 | 19 | import org.testng.annotations.Test; |
| 21 | 20 | |
| 22 | -import static org.assertj.core.api.Assertions.assertThat; | |
| 23 | -import static org.assertj.core.data.MapEntry.entry; | |
| 24 | -import static org.testng.Assert.assertEquals; | |
| 25 | -import static org.testng.Assert.assertFalse; | |
| 26 | -import static org.testng.Assert.assertTrue; | |
| 27 | - | |
| 28 | -import com.datastax.driver.core.*; | |
| 21 | +import java.util.*; | |
| 29 | 22 | |
| 30 | 23 | import static com.datastax.driver.core.querybuilder.QueryBuilder.*; |
| 24 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 25 | +import static org.assertj.core.data.MapEntry.entry; | |
| 26 | +import static org.testng.Assert.*; | |
| 31 | 27 | |
| 32 | 28 | public class QueryBuilderExecutionTest extends CCMBridge.PerClassSingleNodeCluster { |
| 33 | 29 | |
| @@ -36,9 +32,9 @@ | ||
| 36 | 32 | @Override |
| 37 | 33 | protected Collection<String> getTableDefinitions() { |
| 38 | 34 | return Arrays.asList( |
| 39 | - String.format("CREATE TABLE %s (k text PRIMARY KEY, t text, i int, f float)", TABLE1), | |
| 40 | - "CREATE TABLE dateTest (t timestamp PRIMARY KEY)", | |
| 41 | - "CREATE TABLE test_coll (k int PRIMARY KEY, a list<int>, b map<int,text>, c set<text>)"); | |
| 35 | + String.format("CREATE TABLE %s (k text PRIMARY KEY, t text, i int, f float)", TABLE1), | |
| 36 | + "CREATE TABLE dateTest (t timestamp PRIMARY KEY)", | |
| 37 | + "CREATE TABLE test_coll (k int PRIMARY KEY, a list<int>, b map<int,text>, c set<text>)"); | |
| 42 | 38 | } |
| 43 | 39 | |
| 44 | 40 | @Test(groups = "short") |
modified driver-core/src/test/java/com/datastax/driver/core/querybuilder/QueryBuilderITest.java +21 −19
| @@ -15,19 +15,17 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core.querybuilder; |
| 17 | 17 | |
| 18 | -import java.util.Arrays; | |
| 19 | -import java.util.Collection; | |
| 20 | -import java.util.TreeSet; | |
| 21 | - | |
| 22 | -import org.testng.annotations.Test; | |
| 23 | - | |
| 24 | -import static org.testng.Assert.*; | |
| 25 | - | |
| 26 | 18 | import com.datastax.driver.core.*; |
| 27 | 19 | import com.datastax.driver.core.exceptions.SyntaxError; |
| 28 | 20 | import com.datastax.driver.core.utils.CassandraVersion; |
| 21 | +import org.testng.annotations.Test; | |
| 22 | + | |
| 23 | +import java.util.Arrays; | |
| 24 | +import java.util.Collection; | |
| 25 | +import java.util.TreeSet; | |
| 29 | 26 | |
| 30 | 27 | import static com.datastax.driver.core.querybuilder.QueryBuilder.*; |
| 28 | +import static org.testng.Assert.*; | |
| 31 | 29 | |
| 32 | 30 | public class QueryBuilderITest extends CCMBridge.PerClassSingleNodeCluster { |
| 33 | 31 | |
| @@ -37,15 +35,15 @@ | ||
| 37 | 35 | @Override |
| 38 | 36 | protected Collection<String> getTableDefinitions() { |
| 39 | 37 | return Arrays.asList(String.format("CREATE TABLE %s (k text PRIMARY KEY, a int, b int)", TABLE_TEXT), |
| 40 | - String.format("CREATE TABLE %s (k int PRIMARY KEY, a int, b int)", TABLE_INT)); | |
| 38 | + String.format("CREATE TABLE %s (k int PRIMARY KEY, a int, b int)", TABLE_INT)); | |
| 41 | 39 | } |
| 42 | 40 | |
| 43 | 41 | @Override |
| 44 | 42 | protected Cluster.Builder configure(Cluster.Builder builder) { |
| 45 | 43 | return builder.withQueryOptions(new QueryOptions() |
| 46 | - .setRefreshNodeIntervalMillis(0) | |
| 47 | - .setRefreshNodeListIntervalMillis(0) | |
| 48 | - .setRefreshSchemaIntervalMillis(0) | |
| 44 | + .setRefreshNodeIntervalMillis(0) | |
| 45 | + .setRefreshNodeListIntervalMillis(0) | |
| 46 | + .setRefreshSchemaIntervalMillis(0) | |
| 49 | 47 | ); |
| 50 | 48 | } |
| 51 | 49 | |
| @@ -147,7 +145,11 @@ | ||
| 147 | 145 | assertEquals(insert.toString(), query); |
| 148 | 146 | |
| 149 | 147 | query = "INSERT INTO foo (a,b) VALUES ({'2''} space','3','4'},3.4) USING TTL 24 AND TIMESTAMP 42;"; |
| 150 | - insert = insertInto("foo").values(new String[]{ "a", "b"}, new Object[]{ new TreeSet<String>(){{ add("2'} space"); add("3"); add("4"); }}, 3.4 }).using(ttl(24)).and(timestamp(42)); | |
| 148 | + insert = insertInto("foo").values(new String[]{"a", "b"}, new Object[]{new TreeSet<String>() {{ | |
| 149 | + add("2'} space"); | |
| 150 | + add("3"); | |
| 151 | + add("4"); | |
| 152 | + }}, 3.4}).using(ttl(24)).and(timestamp(42)); | |
| 151 | 153 | assertEquals(insert.toString(), query); |
| 152 | 154 | } |
| 153 | 155 | |
| @@ -215,16 +217,16 @@ | ||
| 215 | 217 | } |
| 216 | 218 | |
| 217 | 219 | @Test(groups = "short") |
| 218 | - @CassandraVersion(major=2.0, minor=7, description="DELETE..IF EXISTS only supported in 2.0.7+ (CASSANDRA-5708)") | |
| 220 | + @CassandraVersion(major = 2.0, minor = 7, description = "DELETE..IF EXISTS only supported in 2.0.7+ (CASSANDRA-5708)") | |
| 219 | 221 | public void conditionalDeletesTest() throws Exception { |
| 220 | - session.execute(String.format("INSERT INTO %s.test_int (k, a, b) VALUES (1, 1, 1)",keyspace)); | |
| 222 | + session.execute(String.format("INSERT INTO %s.test_int (k, a, b) VALUES (1, 1, 1)", keyspace)); | |
| 221 | 223 | |
| 222 | 224 | Statement delete; |
| 223 | 225 | Row row; |
| 224 | 226 | delete = delete().from(keyspace, TABLE_INT).where(eq("k", 2)).ifExists(); |
| 225 | 227 | row = session.execute(delete).one(); |
| 226 | 228 | assertFalse(row.getBool("[applied]")); |
| 227 | - | |
| 229 | + | |
| 228 | 230 | delete = delete().from(keyspace, TABLE_INT).where(eq("k", 1)).ifExists(); |
| 229 | 231 | row = session.execute(delete).one(); |
| 230 | 232 | assertTrue(row.getBool("[applied]")); |
| @@ -234,16 +236,16 @@ | ||
| 234 | 236 | delete = delete().from(keyspace, TABLE_INT).where(eq("k", 1)).onlyIf(eq("a", 1)).and(eq("b", 2)); |
| 235 | 237 | row = session.execute(delete).one(); |
| 236 | 238 | assertFalse(row.getBool("[applied]")); |
| 237 | - | |
| 239 | + | |
| 238 | 240 | delete = delete().from(keyspace, TABLE_INT).where(eq("k", 1)).onlyIf(eq("a", 1)).and(eq("b", 1)); |
| 239 | 241 | row = session.execute(delete).one(); |
| 240 | 242 | assertTrue(row.getBool("[applied]")); |
| 241 | 243 | } |
| 242 | 244 | |
| 243 | 245 | @Test(groups = "short") |
| 244 | - @CassandraVersion(major=2.0, minor=13, description="Allow IF EXISTS for UPDATE statements (CASSANDRA-8610)") | |
| 246 | + @CassandraVersion(major = 2.0, minor = 13, description = "Allow IF EXISTS for UPDATE statements (CASSANDRA-8610)") | |
| 245 | 247 | public void conditionalUpdatesTest() throws Exception { |
| 246 | - session.execute(String.format("INSERT INTO %s.test_int (k, a, b) VALUES (1, 1, 1)",keyspace)); | |
| 248 | + session.execute(String.format("INSERT INTO %s.test_int (k, a, b) VALUES (1, 1, 1)", keyspace)); | |
| 247 | 249 | |
| 248 | 250 | Statement update; |
| 249 | 251 | Row row; |
modified driver-core/src/test/java/com/datastax/driver/core/querybuilder/QueryBuilderRoutingKeyTest.java +9 −11
| @@ -15,19 +15,17 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core.querybuilder; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.*; | |
| 19 | +import org.testng.annotations.Test; | |
| 20 | + | |
| 18 | 21 | import java.nio.ByteBuffer; |
| 19 | 22 | import java.util.Arrays; |
| 20 | 23 | import java.util.Collection; |
| 21 | 24 | |
| 22 | -import org.testng.annotations.Test; | |
| 23 | - | |
| 25 | +import static com.datastax.driver.core.querybuilder.QueryBuilder.*; | |
| 24 | 26 | import static org.testng.Assert.assertEquals; |
| 25 | 27 | import static org.testng.Assert.assertNotNull; |
| 26 | 28 | |
| 27 | -import com.datastax.driver.core.*; | |
| 28 | - | |
| 29 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.*; | |
| 30 | - | |
| 31 | 29 | public class QueryBuilderRoutingKeyTest extends CCMBridge.PerClassSingleNodeCluster { |
| 32 | 30 | |
| 33 | 31 | private static final String TABLE_TEXT = "test_text"; |
| @@ -36,15 +34,15 @@ | ||
| 36 | 34 | @Override |
| 37 | 35 | protected Collection<String> getTableDefinitions() { |
| 38 | 36 | return Arrays.asList(String.format("CREATE TABLE %s (k text PRIMARY KEY, a int, b int)", TABLE_TEXT), |
| 39 | - String.format("CREATE TABLE %s (k int PRIMARY KEY, a int, b int)", TABLE_INT)); | |
| 37 | + String.format("CREATE TABLE %s (k int PRIMARY KEY, a int, b int)", TABLE_INT)); | |
| 40 | 38 | } |
| 41 | 39 | |
| 42 | 40 | @Override |
| 43 | 41 | protected Cluster.Builder configure(Cluster.Builder builder) { |
| 44 | 42 | return builder.withQueryOptions(new QueryOptions() |
| 45 | - .setRefreshNodeIntervalMillis(0) | |
| 46 | - .setRefreshNodeListIntervalMillis(0) | |
| 47 | - .setRefreshSchemaIntervalMillis(0) | |
| 43 | + .setRefreshNodeIntervalMillis(0) | |
| 44 | + .setRefreshNodeListIntervalMillis(0) | |
| 45 | + .setRefreshSchemaIntervalMillis(0) | |
| 48 | 46 | ); |
| 49 | 47 | } |
| 50 | 48 | |
| @@ -115,7 +113,7 @@ | ||
| 115 | 113 | batch_query += String.format("UPDATE %s.test_int USING TTL 400;", keyspace); |
| 116 | 114 | batch_query += "APPLY BATCH;"; |
| 117 | 115 | batch = batch() |
| 118 | - .add(insertInto(table).values(new String[]{ "k", "a" }, new Object[]{ 42, 1 })) | |
| 116 | + .add(insertInto(table).values(new String[]{"k", "a"}, new Object[]{42, 1})) | |
| 119 | 117 | .add(update(table).using(ttl(400))); |
| 120 | 118 | assertEquals(batch.getRoutingKey(protocolVersion, codecRegistry), bb); |
| 121 | 119 | assertEquals(batch.toString(), batch_query); |
modified driver-core/src/test/java/com/datastax/driver/core/querybuilder/QueryBuilderTest.java +108 −112
| @@ -15,29 +15,25 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core.querybuilder; |
| 17 | 17 | |
| 18 | -import java.math.BigDecimal; | |
| 19 | -import java.math.BigInteger; | |
| 20 | -import java.net.InetAddress; | |
| 21 | -import java.util.*; | |
| 22 | - | |
| 18 | +import com.datastax.driver.core.*; | |
| 19 | +import com.datastax.driver.core.exceptions.CodecNotFoundException; | |
| 20 | +import com.datastax.driver.core.exceptions.InvalidQueryException; | |
| 21 | +import com.datastax.driver.core.utils.Bytes; | |
| 22 | +import com.datastax.driver.core.utils.CassandraVersion; | |
| 23 | 23 | import com.google.common.collect.ImmutableList; |
| 24 | 24 | import com.google.common.collect.ImmutableMap; |
| 25 | 25 | import com.google.common.collect.Lists; |
| 26 | 26 | import com.google.common.collect.Sets; |
| 27 | 27 | import org.testng.annotations.Test; |
| 28 | 28 | |
| 29 | -import static org.assertj.core.api.Assertions.assertThat; | |
| 30 | -import static org.testng.Assert.assertEquals; | |
| 31 | -import static org.testng.Assert.assertTrue; | |
| 32 | -import static org.testng.Assert.fail; | |
| 33 | - | |
| 34 | -import com.datastax.driver.core.*; | |
| 35 | -import com.datastax.driver.core.exceptions.CodecNotFoundException; | |
| 36 | -import com.datastax.driver.core.exceptions.InvalidQueryException; | |
| 37 | -import com.datastax.driver.core.utils.Bytes; | |
| 38 | -import com.datastax.driver.core.utils.CassandraVersion; | |
| 29 | +import java.math.BigDecimal; | |
| 30 | +import java.math.BigInteger; | |
| 31 | +import java.net.InetAddress; | |
| 32 | +import java.util.*; | |
| 39 | 33 | |
| 40 | 34 | import static com.datastax.driver.core.querybuilder.QueryBuilder.*; |
| 35 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 36 | +import static org.testng.Assert.*; | |
| 41 | 37 | |
| 42 | 38 | public class QueryBuilderTest { |
| 43 | 39 | |
| @@ -57,10 +53,10 @@ | ||
| 57 | 53 | |
| 58 | 54 | query = "SELECT a,b,\"C\" FROM foo WHERE a IN ('127.0.0.1','127.0.0.3') AND \"C\"='foo' ORDER BY a ASC,b DESC LIMIT 42;"; |
| 59 | 55 | select = select("a", "b", quote("C")).from("foo") |
| 60 | - .where(in("a", InetAddress.getByName("127.0.0.1"), InetAddress.getByName("127.0.0.3"))) | |
| 61 | - .and(eq(quote("C"), "foo")) | |
| 62 | - .orderBy(asc("a"), desc("b")) | |
| 63 | - .limit(42); | |
| 56 | + .where(in("a", InetAddress.getByName("127.0.0.1"), InetAddress.getByName("127.0.0.3"))) | |
| 57 | + .and(eq(quote("C"), "foo")) | |
| 58 | + .orderBy(asc("a"), desc("b")) | |
| 59 | + .limit(42); | |
| 64 | 60 | assertEquals(select.toString(), query); |
| 65 | 61 | |
| 66 | 62 | query = "SELECT writetime(a),ttl(a) FROM foo ALLOW FILTERING;"; |
| @@ -178,7 +174,7 @@ | ||
| 178 | 174 | } |
| 179 | 175 | |
| 180 | 176 | @Test(groups = "unit") |
| 181 | - @SuppressWarnings({ "serial", "deprecation" }) | |
| 177 | + @SuppressWarnings({"serial", "deprecation"}) | |
| 182 | 178 | public void insertTest() throws Exception { |
| 183 | 179 | |
| 184 | 180 | String query; |
| @@ -186,67 +182,67 @@ | ||
| 186 | 182 | |
| 187 | 183 | query = "INSERT INTO foo (a,b,\"C\",d) VALUES (123,'127.0.0.1','foo''bar',{'x':3,'y':2}) USING TIMESTAMP 42 AND TTL 24;"; |
| 188 | 184 | insert = insertInto("foo") |
| 189 | - .value("a", 123) | |
| 190 | - .value("b", InetAddress.getByName("127.0.0.1")) | |
| 191 | - .value(quote("C"), "foo'bar") | |
| 192 | - .value("d", new TreeMap<String, Integer>() {{ | |
| 193 | - put("x", 3); | |
| 194 | - put("y", 2); | |
| 195 | - }}) | |
| 196 | - .using(timestamp(42)).and(ttl(24)); | |
| 185 | + .value("a", 123) | |
| 186 | + .value("b", InetAddress.getByName("127.0.0.1")) | |
| 187 | + .value(quote("C"), "foo'bar") | |
| 188 | + .value("d", new TreeMap<String, Integer>() {{ | |
| 189 | + put("x", 3); | |
| 190 | + put("y", 2); | |
| 191 | + }}) | |
| 192 | + .using(timestamp(42)).and(ttl(24)); | |
| 197 | 193 | assertEquals(insert.toString(), query); |
| 198 | 194 | |
| 199 | 195 | query = "INSERT INTO foo (a,b) VALUES (2,null);"; |
| 200 | 196 | insert = insertInto("foo") |
| 201 | - .value("a", 2) | |
| 202 | - .value("b", null); | |
| 197 | + .value("a", 2) | |
| 198 | + .value("b", null); | |
| 203 | 199 | assertEquals(insert.toString(), query); |
| 204 | 200 | |
| 205 | 201 | query = "INSERT INTO foo (a,b) VALUES ({2,3,4},3.4) USING TTL 24 AND TIMESTAMP 42;"; |
| 206 | - insert = insertInto("foo").values(new String[]{ "a", "b" }, new Object[]{ new TreeSet<Integer>() {{ | |
| 202 | + insert = insertInto("foo").values(new String[]{"a", "b"}, new Object[]{new TreeSet<Integer>() {{ | |
| 207 | 203 | add(2); |
| 208 | 204 | add(3); |
| 209 | 205 | add(4); |
| 210 | - }}, 3.4 }).using(ttl(24)).and(timestamp(42)); | |
| 206 | + }}, 3.4}).using(ttl(24)).and(timestamp(42)); | |
| 211 | 207 | assertEquals(insert.toString(), query); |
| 212 | 208 | |
| 213 | 209 | query = "INSERT INTO foo.bar (a,b) VALUES ({2,3,4},3.4) USING TTL ? AND TIMESTAMP ?;"; |
| 214 | 210 | insert = insertInto("foo", "bar") |
| 215 | - .values(new String[]{ "a", "b" }, new Object[]{ new TreeSet<Integer>() {{ | |
| 216 | - add(2); | |
| 217 | - add(3); | |
| 218 | - add(4); | |
| 219 | - }}, 3.4 }) | |
| 220 | - .using(ttl(bindMarker())) | |
| 221 | - .and(timestamp(bindMarker())); | |
| 211 | + .values(new String[]{"a", "b"}, new Object[]{new TreeSet<Integer>() {{ | |
| 212 | + add(2); | |
| 213 | + add(3); | |
| 214 | + add(4); | |
| 215 | + }}, 3.4}) | |
| 216 | + .using(ttl(bindMarker())) | |
| 217 | + .and(timestamp(bindMarker())); | |
| 222 | 218 | assertEquals(insert.toString(), query); |
| 223 | 219 | |
| 224 | 220 | // commutative result of TIMESTAMP |
| 225 | 221 | query = "INSERT INTO foo.bar (a,b,c) VALUES ({2,3,4},3.4,123) USING TIMESTAMP 42;"; |
| 226 | 222 | insert = insertInto("foo", "bar") |
| 227 | - .using(timestamp(42)) | |
| 228 | - .values(new String[]{ "a", "b" }, new Object[]{ new TreeSet<Integer>() {{ | |
| 229 | - add(2); | |
| 230 | - add(3); | |
| 231 | - add(4); | |
| 232 | - }}, 3.4 }) | |
| 233 | - .value("c", 123); | |
| 223 | + .using(timestamp(42)) | |
| 224 | + .values(new String[]{"a", "b"}, new Object[]{new TreeSet<Integer>() {{ | |
| 225 | + add(2); | |
| 226 | + add(3); | |
| 227 | + add(4); | |
| 228 | + }}, 3.4}) | |
| 229 | + .value("c", 123); | |
| 234 | 230 | assertEquals(insert.toString(), query); |
| 235 | 231 | |
| 236 | 232 | // commutative result of value() and values() |
| 237 | 233 | query = "INSERT INTO foo (c,a,b) VALUES (123,{2,3,4},3.4) USING TIMESTAMP 42;"; |
| 238 | 234 | insert = insertInto("foo") |
| 239 | - .using(timestamp(42)) | |
| 240 | - .value("c", 123) | |
| 241 | - .values(new String[]{ "a", "b" }, new Object[]{ new TreeSet<Integer>() {{ | |
| 242 | - add(2); | |
| 243 | - add(3); | |
| 244 | - add(4); | |
| 245 | - }}, 3.4 }); | |
| 235 | + .using(timestamp(42)) | |
| 236 | + .value("c", 123) | |
| 237 | + .values(new String[]{"a", "b"}, new Object[]{new TreeSet<Integer>() {{ | |
| 238 | + add(2); | |
| 239 | + add(3); | |
| 240 | + add(4); | |
| 241 | + }}, 3.4}); | |
| 246 | 242 | assertEquals(insert.toString(), query); |
| 247 | 243 | |
| 248 | 244 | try { |
| 249 | - insertInto("foo").values(new String[]{ "a", "b"}, new Object[]{ 1, 2, 3 }); | |
| 245 | + insertInto("foo").values(new String[]{"a", "b"}, new Object[]{1, 2, 3}); | |
| 250 | 246 | fail(); |
| 251 | 247 | } catch (IllegalArgumentException e) { |
| 252 | 248 | assertEquals(e.getMessage(), "Got 2 names but 3 values"); |
| @@ -298,11 +294,11 @@ | ||
| 298 | 294 | add(3); |
| 299 | 295 | add(4); |
| 300 | 296 | }})) |
| 301 | - .and(put("c", "k", "v")) | |
| 302 | - .and(putAll("d", new TreeMap<String, Integer>() {{ | |
| 303 | - put("x", 3); | |
| 304 | - put("y", 2); | |
| 305 | - }})); | |
| 297 | + .and(put("c", "k", "v")) | |
| 298 | + .and(putAll("d", new TreeMap<String, Integer>() {{ | |
| 299 | + put("x", 3); | |
| 300 | + put("y", 2); | |
| 301 | + }})); | |
| 306 | 302 | assertEquals(update.toString(), query); |
| 307 | 303 | |
| 308 | 304 | query = "UPDATE foo USING TTL 400;"; |
| @@ -341,7 +337,7 @@ | ||
| 341 | 337 | update = update("foo").with(set("x", 3)).where(eq("k", 2)).ifExists(); |
| 342 | 338 | assertThat(update.toString()).isEqualTo("UPDATE foo SET x=3 WHERE k=2 IF EXISTS;"); |
| 343 | 339 | } |
| 344 | - | |
| 340 | + | |
| 345 | 341 | @Test(groups = "unit") |
| 346 | 342 | public void deleteTest() throws Exception { |
| 347 | 343 | |
| @@ -418,14 +414,14 @@ | ||
| 418 | 414 | query += "DELETE a[3],b['foo'],c FROM foo WHERE k=1;"; |
| 419 | 415 | query += "APPLY BATCH;"; |
| 420 | 416 | batch = batch() |
| 421 | - .add(insertInto("foo").values(new String[]{ "a", "b" }, new Object[]{ new TreeSet<Integer>() {{ | |
| 422 | - add(2); | |
| 423 | - add(3); | |
| 424 | - add(4); | |
| 425 | - }}, 3.4 })) | |
| 426 | - .add(update("foo").with(setIdx("a", 2, "foo")).and(prependAll("b", Arrays.asList(3, 2, 1))).and(remove("c", "a")).where(eq("k", 2))) | |
| 427 | - .add(delete().listElt("a", 3).mapElt("b", "foo").column("c").from("foo").where(eq("k", 1))) | |
| 428 | - .using(timestamp(42)); | |
| 417 | + .add(insertInto("foo").values(new String[]{"a", "b"}, new Object[]{new TreeSet<Integer>() {{ | |
| 418 | + add(2); | |
| 419 | + add(3); | |
| 420 | + add(4); | |
| 421 | + }}, 3.4})) | |
| 422 | + .add(update("foo").with(setIdx("a", 2, "foo")).and(prependAll("b", Arrays.asList(3, 2, 1))).and(remove("c", "a")).where(eq("k", 2))) | |
| 423 | + .add(delete().listElt("a", 3).mapElt("b", "foo").column("c").from("foo").where(eq("k", 1))) | |
| 424 | + .using(timestamp(42)); | |
| 429 | 425 | assertEquals(batch.toString(), query); |
| 430 | 426 | |
| 431 | 427 | // Test passing batch(statement) |
| @@ -450,10 +446,10 @@ | ||
| 450 | 446 | query += "UPDATE foo SET c=c+3;"; |
| 451 | 447 | query += "APPLY BATCH;"; |
| 452 | 448 | batch = batch() |
| 453 | - .add(update("foo").with(incr("a", 1))) | |
| 454 | - .add(update("foo").with(incr("b", 2))) | |
| 455 | - .add(update("foo").with(incr("c", 3))) | |
| 456 | - .using(timestamp(42)); | |
| 449 | + .add(update("foo").with(incr("a", 1))) | |
| 450 | + .add(update("foo").with(incr("b", 2))) | |
| 451 | + .add(update("foo").with(incr("c", 3))) | |
| 452 | + .using(timestamp(42)); | |
| 457 | 453 | assertEquals(batch.toString(), query); |
| 458 | 454 | |
| 459 | 455 | // Test single increments |
| @@ -463,10 +459,10 @@ | ||
| 463 | 459 | query += "UPDATE foo SET c=c+1;"; |
| 464 | 460 | query += "APPLY BATCH;"; |
| 465 | 461 | batch = batch() |
| 466 | - .add(update("foo").with(incr("a"))) | |
| 467 | - .add(update("foo").with(incr("b"))) | |
| 468 | - .add(update("foo").with(incr("c"))) | |
| 469 | - .using(timestamp(42)); | |
| 462 | + .add(update("foo").with(incr("a"))) | |
| 463 | + .add(update("foo").with(incr("b"))) | |
| 464 | + .add(update("foo").with(incr("c"))) | |
| 465 | + .using(timestamp(42)); | |
| 470 | 466 | assertEquals(batch.toString(), query); |
| 471 | 467 | |
| 472 | 468 | // Test value decrements |
| @@ -476,10 +472,10 @@ | ||
| 476 | 472 | query += "UPDATE foo SET c=c-3;"; |
| 477 | 473 | query += "APPLY BATCH;"; |
| 478 | 474 | batch = batch() |
| 479 | - .add(update("foo").with(decr("a", 1))) | |
| 480 | - .add(update("foo").with(decr("b", 2))) | |
| 481 | - .add(update("foo").with(decr("c", 3))) | |
| 482 | - .using(timestamp(42)); | |
| 475 | + .add(update("foo").with(decr("a", 1))) | |
| 476 | + .add(update("foo").with(decr("b", 2))) | |
| 477 | + .add(update("foo").with(decr("c", 3))) | |
| 478 | + .using(timestamp(42)); | |
| 483 | 479 | assertEquals(batch.toString(), query); |
| 484 | 480 | |
| 485 | 481 | // Test single decrements |
| @@ -489,10 +485,10 @@ | ||
| 489 | 485 | query += "UPDATE foo SET c=c-1;"; |
| 490 | 486 | query += "APPLY BATCH;"; |
| 491 | 487 | batch = batch() |
| 492 | - .add(update("foo").with(decr("a"))) | |
| 493 | - .add(update("foo").with(decr("b"))) | |
| 494 | - .add(update("foo").with(decr("c"))) | |
| 495 | - .using(timestamp(42)); | |
| 488 | + .add(update("foo").with(decr("a"))) | |
| 489 | + .add(update("foo").with(decr("b"))) | |
| 490 | + .add(update("foo").with(decr("c"))) | |
| 491 | + .using(timestamp(42)); | |
| 496 | 492 | assertEquals(batch.toString(), query); |
| 497 | 493 | |
| 498 | 494 | // Test negative decrements and negative increments |
| @@ -502,20 +498,20 @@ | ||
| 502 | 498 | query += "UPDATE foo SET c=c-3;"; |
| 503 | 499 | query += "APPLY BATCH;"; |
| 504 | 500 | batch = batch() |
| 505 | - .add(update("foo").with(decr("a", -1))) | |
| 506 | - .add(update("foo").with(incr("b", -2))) | |
| 507 | - .add(update("foo").with(decr("c", 3))) | |
| 508 | - .using(timestamp(42)); | |
| 501 | + .add(update("foo").with(decr("a", -1))) | |
| 502 | + .add(update("foo").with(incr("b", -2))) | |
| 503 | + .add(update("foo").with(decr("c", 3))) | |
| 504 | + .using(timestamp(42)); | |
| 509 | 505 | assertEquals(batch.toString(), query); |
| 510 | 506 | } |
| 511 | 507 | |
| 512 | - @Test(groups = "unit", expectedExceptions = { IllegalArgumentException.class }) | |
| 508 | + @Test(groups = "unit", expectedExceptions = {IllegalArgumentException.class}) | |
| 513 | 509 | public void batchMixedCounterTest() throws Exception { |
| 514 | 510 | batch() |
| 515 | - .add(update("foo").with(incr("a", 1))) | |
| 516 | - .add(update("foo").with(set("b", 2))) | |
| 517 | - .add(update("foo").with(incr("c", 3))) | |
| 518 | - .using(timestamp(42)); | |
| 511 | + .add(update("foo").with(incr("a", 1))) | |
| 512 | + .add(update("foo").with(set("b", 2))) | |
| 513 | + .add(update("foo").with(incr("c", 3))) | |
| 514 | + .using(timestamp(42)); | |
| 519 | 515 | } |
| 520 | 516 | |
| 521 | 517 | @Test(groups = "unit") |
| @@ -525,8 +521,8 @@ | ||
| 525 | 521 | |
| 526 | 522 | query = "INSERT INTO test (k,c) VALUES (0,?);"; |
| 527 | 523 | insert = insertInto("test") |
| 528 | - .value("k", 0) | |
| 529 | - .value("c", bindMarker()); | |
| 524 | + .value("k", 0) | |
| 525 | + .value("c", bindMarker()); | |
| 530 | 526 | assertEquals(insert.toString(), query); |
| 531 | 527 | } |
| 532 | 528 | |
| @@ -625,11 +621,11 @@ | ||
| 625 | 621 | assertEquals(insert.toString(), query); |
| 626 | 622 | |
| 627 | 623 | query = "INSERT INTO foo (a,b) VALUES ({'2''} space','3','4'},3.4) USING TTL 24 AND TIMESTAMP 42;"; |
| 628 | - insert = insertInto("foo").values(new String[]{ "a", "b" }, new Object[]{ new TreeSet<String>() {{ | |
| 624 | + insert = insertInto("foo").values(new String[]{"a", "b"}, new Object[]{new TreeSet<String>() {{ | |
| 629 | 625 | add("2'} space"); |
| 630 | 626 | add("3"); |
| 631 | 627 | add("4"); |
| 632 | - }}, 3.4 }).using(ttl(24)).and(timestamp(42)); | |
| 628 | + }}, 3.4}).using(ttl(24)).and(timestamp(42)); | |
| 633 | 629 | assertEquals(insert.toString(), query); |
| 634 | 630 | } |
| 635 | 631 | |
| @@ -684,7 +680,7 @@ | ||
| 684 | 680 | |
| 685 | 681 | query = "DELETE a,b FROM foo WHERE a IN ('b','c''); --comment');"; |
| 686 | 682 | delete = delete("a", "b").from("foo") |
| 687 | - .where(in("a", "b", "c'); --comment")); | |
| 683 | + .where(in("a", "b", "c'); --comment")); | |
| 688 | 684 | assertEquals(delete.toString(), query); |
| 689 | 685 | |
| 690 | 686 | query = "DELETE FROM foo WHERE \"k=1 OR k\">42;"; |
| @@ -713,7 +709,7 @@ | ||
| 713 | 709 | public void rejectUnknownValueTest() throws Exception { |
| 714 | 710 | try { |
| 715 | 711 | RegularStatement s = update("foo").with(set("a", new byte[13])).where(eq("k", 2)) |
| 716 | - .setForceNoValues(true); | |
| 712 | + .setForceNoValues(true); | |
| 717 | 713 | s.getQueryString(); |
| 718 | 714 | fail("should have failed to inline a byte[]"); |
| 719 | 715 | } catch (CodecNotFoundException e) { |
| @@ -730,22 +726,22 @@ | ||
| 730 | 726 | @Test(groups = "unit") |
| 731 | 727 | public void quotingTest() { |
| 732 | 728 | assertEquals(select().from("Metrics", "epochs").toString(), |
| 733 | - "SELECT * FROM Metrics.epochs;"); | |
| 729 | + "SELECT * FROM Metrics.epochs;"); | |
| 734 | 730 | assertEquals(select().from("Metrics", quote("epochs")).toString(), |
| 735 | - "SELECT * FROM Metrics.\"epochs\";"); | |
| 731 | + "SELECT * FROM Metrics.\"epochs\";"); | |
| 736 | 732 | assertEquals(select().from(quote("Metrics"), "epochs").toString(), |
| 737 | - "SELECT * FROM \"Metrics\".epochs;"); | |
| 733 | + "SELECT * FROM \"Metrics\".epochs;"); | |
| 738 | 734 | assertEquals(select().from(quote("Metrics"), quote("epochs")).toString(), |
| 739 | - "SELECT * FROM \"Metrics\".\"epochs\";"); | |
| 735 | + "SELECT * FROM \"Metrics\".\"epochs\";"); | |
| 740 | 736 | |
| 741 | 737 | assertEquals(insertInto("Metrics", "epochs").toString(), |
| 742 | - "INSERT INTO Metrics.epochs () VALUES ();"); | |
| 738 | + "INSERT INTO Metrics.epochs () VALUES ();"); | |
| 743 | 739 | assertEquals(insertInto("Metrics", quote("epochs")).toString(), |
| 744 | - "INSERT INTO Metrics.\"epochs\" () VALUES ();"); | |
| 740 | + "INSERT INTO Metrics.\"epochs\" () VALUES ();"); | |
| 745 | 741 | assertEquals(insertInto(quote("Metrics"), "epochs").toString(), |
| 746 | - "INSERT INTO \"Metrics\".epochs () VALUES ();"); | |
| 742 | + "INSERT INTO \"Metrics\".epochs () VALUES ();"); | |
| 747 | 743 | assertEquals(insertInto(quote("Metrics"), quote("epochs")).toString(), |
| 748 | - "INSERT INTO \"Metrics\".\"epochs\" () VALUES ();"); | |
| 744 | + "INSERT INTO \"Metrics\".\"epochs\" () VALUES ();"); | |
| 749 | 745 | } |
| 750 | 746 | |
| 751 | 747 | @Test(groups = "unit") |
| @@ -759,7 +755,7 @@ | ||
| 759 | 755 | |
| 760 | 756 | query = "SELECT * FROM foo WHERE k=4 AND (c1,c2)>=('a',2) AND (c1,c2)<('b',0);"; |
| 761 | 757 | select = select().all().from("foo").where(eq("k", 4)).and(gte(Arrays.asList("c1", "c2"), Arrays.<Object>asList("a", 2))) |
| 762 | - .and(lt(Arrays.asList("c1", "c2"), Arrays.<Object>asList("b", 0))); | |
| 758 | + .and(lt(Arrays.asList("c1", "c2"), Arrays.<Object>asList("b", 0))); | |
| 763 | 759 | assertEquals(select.toString(), query); |
| 764 | 760 | |
| 765 | 761 | query = "SELECT * FROM foo WHERE k=4 AND (c1,c2)<=('a',2);"; |
| @@ -779,8 +775,8 @@ | ||
| 779 | 775 | |
| 780 | 776 | // If the excessive count results from successive DSL calls, we don't check it on the fly so this statement works: |
| 781 | 777 | BuiltStatement statement = select().all().from("foo") |
| 782 | - .where(eq("bar", "a")) | |
| 783 | - .and(in("baz", values.toArray())); | |
| 778 | + .where(eq("bar", "a")) | |
| 779 | + .and(in("baz", values.toArray())); | |
| 784 | 780 | |
| 785 | 781 | // But we still want to check it client-side, to fail fast instead of sending a bad query to Cassandra. |
| 786 | 782 | // getValues() is called on any RegularStatement before we send it (see SessionManager.makeRequestMessage). |
| @@ -866,12 +862,12 @@ | ||
| 866 | 862 | assertThat(select.getValues(ProtocolVersion.NEWEST_SUPPORTED, CodecRegistry.DEFAULT_INSTANCE)).isNull(); |
| 867 | 863 | } |
| 868 | 864 | |
| 869 | - @Test(groups = "unit", expectedExceptions = { IllegalStateException.class }) | |
| 865 | + @Test(groups = "unit", expectedExceptions = {IllegalStateException.class}) | |
| 870 | 866 | public void should_throw_ISE_if_getObject_called_on_statement_without_values() { |
| 871 | 867 | select().from("test").where(eq("foo", 42)).getObject(0); // integers are appended to the CQL string |
| 872 | 868 | } |
| 873 | 869 | |
| 874 | - @Test(groups = "unit", expectedExceptions = { IndexOutOfBoundsException.class }) | |
| 870 | + @Test(groups = "unit", expectedExceptions = {IndexOutOfBoundsException.class}) | |
| 875 | 871 | public void should_throw_IOOBE_if_getObject_called_with_wrong_index() { |
| 876 | 872 | select().from("test").where(eq("foo", new Object())).getObject(1); |
| 877 | 873 | } |
modified driver-core/src/test/java/com/datastax/driver/core/querybuilder/QueryBuilderTupleExecutionTest.java +11 −16
| @@ -15,33 +15,28 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core.querybuilder; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.CCMBridge; | |
| 19 | +import com.datastax.driver.core.TupleType; | |
| 20 | +import com.datastax.driver.core.TupleValue; | |
| 21 | +import com.datastax.driver.core.utils.CassandraVersion; | |
| 22 | +import com.google.common.collect.ImmutableList; | |
| 23 | +import org.testng.annotations.Test; | |
| 24 | + | |
| 18 | 25 | import java.util.Collection; |
| 19 | 26 | import java.util.Collections; |
| 20 | 27 | import java.util.List; |
| 21 | 28 | |
| 22 | -import com.google.common.collect.ImmutableList; | |
| 23 | -import org.testng.annotations.Test; | |
| 24 | - | |
| 29 | +import static com.datastax.driver.core.DataType.cint; | |
| 30 | +import static com.datastax.driver.core.querybuilder.QueryBuilder.*; | |
| 25 | 31 | import static org.assertj.core.api.Assertions.assertThat; |
| 26 | 32 | import static org.testng.Assert.assertEquals; |
| 27 | 33 | |
| 28 | -import com.datastax.driver.core.CCMBridge; | |
| 29 | -import com.datastax.driver.core.TupleType; | |
| 30 | -import com.datastax.driver.core.TupleValue; | |
| 31 | -import com.datastax.driver.core.utils.CassandraVersion; | |
| 32 | - | |
| 33 | -import static com.datastax.driver.core.DataType.cint; | |
| 34 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; | |
| 35 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.insertInto; | |
| 36 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.set; | |
| 37 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.update; | |
| 38 | - | |
| 39 | -@CassandraVersion(major=2.1, minor=3) | |
| 34 | +@CassandraVersion(major = 2.1, minor = 3) | |
| 40 | 35 | public class QueryBuilderTupleExecutionTest extends CCMBridge.PerClassSingleNodeCluster { |
| 41 | 36 | |
| 42 | 37 | @Override |
| 43 | 38 | protected Collection<String> getTableDefinitions() { |
| 44 | - return Collections.emptyList(); | |
| 39 | + return Collections.emptyList(); | |
| 45 | 40 | } |
| 46 | 41 | |
| 47 | 42 | @Test(groups = "short") |
modified driver-core/src/test/java/com/datastax/driver/core/querybuilder/QueryBuilderUDTExecutionTest.java +10 −12
| @@ -15,30 +15,28 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core.querybuilder; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.*; | |
| 19 | +import com.datastax.driver.core.utils.CassandraVersion; | |
| 20 | +import com.google.common.collect.ImmutableList; | |
| 21 | +import com.google.common.collect.Maps; | |
| 22 | +import org.testng.annotations.Test; | |
| 23 | + | |
| 18 | 24 | import java.net.InetAddress; |
| 19 | 25 | import java.util.Arrays; |
| 20 | 26 | import java.util.Collection; |
| 21 | 27 | import java.util.List; |
| 22 | 28 | import java.util.Map; |
| 23 | 29 | |
| 24 | -import com.google.common.collect.ImmutableList; | |
| 25 | -import com.google.common.collect.Maps; | |
| 26 | -import org.testng.annotations.Test; | |
| 27 | - | |
| 30 | +import static com.datastax.driver.core.querybuilder.QueryBuilder.*; | |
| 28 | 31 | import static org.assertj.core.api.Assertions.assertThat; |
| 29 | 32 | import static org.testng.Assert.assertEquals; |
| 30 | 33 | |
| 31 | -import com.datastax.driver.core.*; | |
| 32 | -import com.datastax.driver.core.utils.CassandraVersion; | |
| 33 | - | |
| 34 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.*; | |
| 35 | - | |
| 36 | -@CassandraVersion(major=2.1, minor=3) | |
| 34 | +@CassandraVersion(major = 2.1, minor = 3) | |
| 37 | 35 | public class QueryBuilderUDTExecutionTest extends CCMBridge.PerClassSingleNodeCluster { |
| 38 | 36 | |
| 39 | 37 | @Override |
| 40 | 38 | protected Collection<String> getTableDefinitions() { |
| 41 | - return Arrays.asList("CREATE TYPE udt (i int, a inet)", | |
| 39 | + return Arrays.asList("CREATE TYPE udt (i int, a inet)", | |
| 42 | 40 | "CREATE TABLE udtTest(k int PRIMARY KEY, t frozen<udt>, l list<frozen<udt>>, m map<int, frozen<udt>>)"); |
| 43 | 41 | } |
| 44 | 42 | |
| @@ -83,7 +81,7 @@ | ||
| 83 | 81 | map.put(2, udtValue2); |
| 84 | 82 | Statement updateMap = update("udtTest").with(putAll("m", map)).where(eq("k", 1)); |
| 85 | 83 | assertThat(updateMap.toString()) |
| 86 | - .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;"); | |
| 84 | + .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;"); | |
| 87 | 85 | |
| 88 | 86 | session.execute(updateMap); |
| 89 | 87 |
modified driver-core/src/test/java/com/datastax/driver/core/schemabuilder/AlterTest.java +50 −52
| @@ -15,13 +15,11 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core.schemabuilder; |
| 17 | 17 | |
| 18 | -import org.testng.annotations.Test; | |
| 19 | - | |
| 20 | -import static org.assertj.core.api.Assertions.assertThat; | |
| 21 | - | |
| 22 | 18 | import com.datastax.driver.core.DataType; |
| 19 | +import org.testng.annotations.Test; | |
| 23 | 20 | |
| 24 | 21 | import static com.datastax.driver.core.schemabuilder.SchemaBuilder.*; |
| 22 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 25 | 23 | |
| 26 | 24 | public class AlterTest { |
| 27 | 25 | |
| @@ -94,96 +92,96 @@ | ||
| 94 | 92 | // Note that this does not necessarily represent a valid configuration, the goal is just to test all options |
| 95 | 93 | // (some of which might be specific to C* 2.0 or 2.1) |
| 96 | 94 | SchemaStatement statement = alterTable("test").withOptions() |
| 97 | - .bloomFilterFPChance(0.01) | |
| 98 | - .caching(Caching.ROWS_ONLY) | |
| 99 | - .comment("This is a comment") | |
| 100 | - .compactionOptions(leveledStrategy().ssTableSizeInMB(160)) | |
| 101 | - .compressionOptions(lz4()) | |
| 102 | - .dcLocalReadRepairChance(0.21) | |
| 103 | - .defaultTimeToLive(100) | |
| 104 | - .gcGraceSeconds(9999) | |
| 105 | - .indexInterval(256) | |
| 106 | - .minIndexInterval(64) | |
| 107 | - .maxIndexInterval(512) | |
| 108 | - .memtableFlushPeriodInMillis(12) | |
| 109 | - .populateIOCacheOnFlush(true) | |
| 110 | - .replicateOnWrite(true) | |
| 111 | - .readRepairChance(0.42) | |
| 112 | - .speculativeRetry(always()); | |
| 95 | + .bloomFilterFPChance(0.01) | |
| 96 | + .caching(Caching.ROWS_ONLY) | |
| 97 | + .comment("This is a comment") | |
| 98 | + .compactionOptions(leveledStrategy().ssTableSizeInMB(160)) | |
| 99 | + .compressionOptions(lz4()) | |
| 100 | + .dcLocalReadRepairChance(0.21) | |
| 101 | + .defaultTimeToLive(100) | |
| 102 | + .gcGraceSeconds(9999) | |
| 103 | + .indexInterval(256) | |
| 104 | + .minIndexInterval(64) | |
| 105 | + .maxIndexInterval(512) | |
| 106 | + .memtableFlushPeriodInMillis(12) | |
| 107 | + .populateIOCacheOnFlush(true) | |
| 108 | + .replicateOnWrite(true) | |
| 109 | + .readRepairChance(0.42) | |
| 110 | + .speculativeRetry(always()); | |
| 113 | 111 | |
| 114 | 112 | SchemaStatement statementWith21Caching = alterTable("test").withOptions() |
| 115 | - .caching(KeyCaching.NONE, rows(100)); | |
| 113 | + .caching(KeyCaching.NONE, rows(100)); | |
| 116 | 114 | |
| 117 | 115 | //Then |
| 118 | 116 | assertThat(statement.getQueryString()).isEqualTo("\n\tALTER TABLE test\n\t" + |
| 119 | - "WITH caching = 'rows_only' " + | |
| 120 | - "AND bloom_filter_fp_chance = 0.01 " + | |
| 121 | - "AND comment = 'This is a comment' " + | |
| 122 | - "AND compression = {'sstable_compression' : 'LZ4Compressor'} " + | |
| 123 | - "AND compaction = {'class' : 'LeveledCompactionStrategy', 'sstable_size_in_mb' : 160} " + | |
| 124 | - "AND dclocal_read_repair_chance = 0.21 " + | |
| 125 | - "AND default_time_to_live = 100 " + | |
| 126 | - "AND gc_grace_seconds = 9999 " + | |
| 127 | - "AND index_interval = 256 " + | |
| 128 | - "AND min_index_interval = 64 " + | |
| 129 | - "AND max_index_interval = 512 " + | |
| 130 | - "AND memtable_flush_period_in_ms = 12 " + | |
| 131 | - "AND populate_io_cache_on_flush = true " + | |
| 132 | - "AND read_repair_chance = 0.42 " + | |
| 133 | - "AND replicate_on_write = true " + | |
| 134 | - "AND speculative_retry = 'ALWAYS'"); | |
| 117 | + "WITH caching = 'rows_only' " + | |
| 118 | + "AND bloom_filter_fp_chance = 0.01 " + | |
| 119 | + "AND comment = 'This is a comment' " + | |
| 120 | + "AND compression = {'sstable_compression' : 'LZ4Compressor'} " + | |
| 121 | + "AND compaction = {'class' : 'LeveledCompactionStrategy', 'sstable_size_in_mb' : 160} " + | |
| 122 | + "AND dclocal_read_repair_chance = 0.21 " + | |
| 123 | + "AND default_time_to_live = 100 " + | |
| 124 | + "AND gc_grace_seconds = 9999 " + | |
| 125 | + "AND index_interval = 256 " + | |
| 126 | + "AND min_index_interval = 64 " + | |
| 127 | + "AND max_index_interval = 512 " + | |
| 128 | + "AND memtable_flush_period_in_ms = 12 " + | |
| 129 | + "AND populate_io_cache_on_flush = true " + | |
| 130 | + "AND read_repair_chance = 0.42 " + | |
| 131 | + "AND replicate_on_write = true " + | |
| 132 | + "AND speculative_retry = 'ALWAYS'"); | |
| 135 | 133 | |
| 136 | 134 | assertThat(statementWith21Caching.getQueryString()).isEqualTo("\n\tALTER TABLE test\n\t" + |
| 137 | - "WITH caching = {'keys' : 'none', 'rows_per_partition' : 100}"); | |
| 135 | + "WITH caching = {'keys' : 'none', 'rows_per_partition' : 100}"); | |
| 138 | 136 | } |
| 139 | 137 | |
| 140 | 138 | @Test(groups = "unit", expectedExceptions = IllegalArgumentException.class, |
| 141 | - expectedExceptionsMessageRegExp = "The keyspace name 'add' is not allowed because it is a reserved keyword") | |
| 139 | + expectedExceptionsMessageRegExp = "The keyspace name 'add' is not allowed because it is a reserved keyword") | |
| 142 | 140 | public void should_fail_if_keyspace_name_is_a_reserved_keyword() throws Exception { |
| 143 | 141 | alterTable("add", "test") |
| 144 | - .addColumn("test").type(DataType.ascii()); | |
| 142 | + .addColumn("test").type(DataType.ascii()); | |
| 145 | 143 | } |
| 146 | 144 | |
| 147 | 145 | @Test(groups = "unit", expectedExceptions = IllegalArgumentException.class, |
| 148 | - expectedExceptionsMessageRegExp = "The table name 'add' is not allowed because it is a reserved keyword") | |
| 146 | + expectedExceptionsMessageRegExp = "The table name 'add' is not allowed because it is a reserved keyword") | |
| 149 | 147 | public void should_fail_if_table_name_is_a_reserved_keyword() throws Exception { |
| 150 | 148 | alterTable("add") |
| 151 | - .addColumn("test").type(DataType.ascii()); | |
| 149 | + .addColumn("test").type(DataType.ascii()); | |
| 152 | 150 | } |
| 153 | 151 | |
| 154 | 152 | @Test(groups = "unit", expectedExceptions = IllegalArgumentException.class, |
| 155 | - expectedExceptionsMessageRegExp = "The new column name 'add' is not allowed because it is a reserved keyword") | |
| 153 | + expectedExceptionsMessageRegExp = "The new column name 'add' is not allowed because it is a reserved keyword") | |
| 156 | 154 | public void should_fail_if_added_column_is_a_reserved_keyword() throws Exception { |
| 157 | 155 | alterTable("test") |
| 158 | - .addColumn("add").type(DataType.ascii()).getQueryString(); | |
| 156 | + .addColumn("add").type(DataType.ascii()).getQueryString(); | |
| 159 | 157 | } |
| 160 | 158 | |
| 161 | 159 | @Test(groups = "unit", expectedExceptions = IllegalArgumentException.class, |
| 162 | - expectedExceptionsMessageRegExp = "The altered column name 'add' is not allowed because it is a reserved keyword") | |
| 160 | + expectedExceptionsMessageRegExp = "The altered column name 'add' is not allowed because it is a reserved keyword") | |
| 163 | 161 | public void should_fail_if_altered_column_is_a_reserved_keyword() throws Exception { |
| 164 | 162 | alterTable("test") |
| 165 | - .alterColumn("add").type(DataType.ascii()).getQueryString(); | |
| 163 | + .alterColumn("add").type(DataType.ascii()).getQueryString(); | |
| 166 | 164 | } |
| 167 | 165 | |
| 168 | 166 | @Test(groups = "unit", expectedExceptions = IllegalArgumentException.class, |
| 169 | - expectedExceptionsMessageRegExp = "The renamed column name 'add' is not allowed because it is a reserved keyword") | |
| 167 | + expectedExceptionsMessageRegExp = "The renamed column name 'add' is not allowed because it is a reserved keyword") | |
| 170 | 168 | public void should_fail_if_renamed_column_is_a_reserved_keyword() throws Exception { |
| 171 | 169 | alterTable("test") |
| 172 | - .renameColumn("add"); | |
| 170 | + .renameColumn("add"); | |
| 173 | 171 | } |
| 174 | 172 | |
| 175 | 173 | @Test(groups = "unit", expectedExceptions = IllegalArgumentException.class, |
| 176 | - expectedExceptionsMessageRegExp = "The new column name 'add' is not allowed because it is a reserved keyword") | |
| 174 | + expectedExceptionsMessageRegExp = "The new column name 'add' is not allowed because it is a reserved keyword") | |
| 177 | 175 | public void should_fail_if_new_renamed_column_is_a_reserved_keyword() throws Exception { |
| 178 | 176 | alterTable("test") |
| 179 | - .renameColumn("col").to("add"); | |
| 177 | + .renameColumn("col").to("add"); | |
| 180 | 178 | } |
| 181 | 179 | |
| 182 | 180 | @Test(groups = "unit", expectedExceptions = IllegalArgumentException.class, |
| 183 | - expectedExceptionsMessageRegExp = "The dropped column name 'add' is not allowed because it is a reserved keyword") | |
| 181 | + expectedExceptionsMessageRegExp = "The dropped column name 'add' is not allowed because it is a reserved keyword") | |
| 184 | 182 | public void should_fail_if_drop_column_is_a_reserved_keyword() throws Exception { |
| 185 | 183 | alterTable("test") |
| 186 | - .dropColumn("add").getQueryString(); | |
| 184 | + .dropColumn("add").getQueryString(); | |
| 187 | 185 | } |
| 188 | 186 | |
| 189 | 187 | @Test(groups = "unit") |
modified driver-core/src/test/java/com/datastax/driver/core/schemabuilder/CompactionOptionsTest.java +74 −77
| @@ -17,12 +17,9 @@ | ||
| 17 | 17 | |
| 18 | 18 | import org.testng.annotations.Test; |
| 19 | 19 | |
| 20 | -import static org.assertj.core.api.Assertions.assertThat; | |
| 21 | - | |
| 22 | -import static com.datastax.driver.core.schemabuilder.SchemaBuilder.dateTieredStrategy; | |
| 23 | -import static com.datastax.driver.core.schemabuilder.SchemaBuilder.leveledStrategy; | |
| 24 | -import static com.datastax.driver.core.schemabuilder.SchemaBuilder.sizedTieredStategy; | |
| 20 | +import static com.datastax.driver.core.schemabuilder.SchemaBuilder.*; | |
| 25 | 21 | import static com.datastax.driver.core.schemabuilder.TableOptions.CompactionOptions.DateTieredCompactionStrategyOptions.TimeStampResolution; |
| 22 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 26 | 23 | |
| 27 | 24 | public class CompactionOptionsTest { |
| 28 | 25 | |
| @@ -30,128 +27,128 @@ | ||
| 30 | 27 | public void should_create_sized_tiered_compaction_options() throws Exception { |
| 31 | 28 | //When |
| 32 | 29 | final String built = sizedTieredStategy() |
| 33 | - .bucketLow(0.5) | |
| 34 | - .bucketHigh(1.2) | |
| 35 | - .coldReadsRatioToOmit(0.89) | |
| 36 | - .enabled(true) | |
| 37 | - .minThreshold(2) | |
| 38 | - .maxThreshold(4) | |
| 39 | - .minSSTableSizeInBytes(5000000L) | |
| 40 | - .tombstoneCompactionIntervalInDay(3) | |
| 41 | - .tombstoneThreshold(0.7) | |
| 42 | - .uncheckedTombstoneCompaction(true) | |
| 43 | - .build(); | |
| 30 | + .bucketLow(0.5) | |
| 31 | + .bucketHigh(1.2) | |
| 32 | + .coldReadsRatioToOmit(0.89) | |
| 33 | + .enabled(true) | |
| 34 | + .minThreshold(2) | |
| 35 | + .maxThreshold(4) | |
| 36 | + .minSSTableSizeInBytes(5000000L) | |
| 37 | + .tombstoneCompactionIntervalInDay(3) | |
| 38 | + .tombstoneThreshold(0.7) | |
| 39 | + .uncheckedTombstoneCompaction(true) | |
| 40 | + .build(); | |
| 44 | 41 | |
| 45 | 42 | //Then |
| 46 | 43 | assertThat(built).isEqualTo("{'class' : 'SizeTieredCompactionStrategy', " + |
| 47 | - "'enabled' : true, " + | |
| 48 | - "'tombstone_compaction_interval' : 3, " + | |
| 49 | - "'tombstone_threshold' : 0.7, " + | |
| 50 | - "'unchecked_tombstone_compaction' : true, " + | |
| 51 | - "'bucket_high' : 1.2, " + | |
| 52 | - "'bucket_low' : 0.5, " + | |
| 53 | - "'cold_reads_to_omit' : 0.89, " + | |
| 54 | - "'min_threshold' : 2, " + | |
| 55 | - "'max_threshold' : 4, " + | |
| 56 | - "'min_sstable_size' : 5000000}"); | |
| 44 | + "'enabled' : true, " + | |
| 45 | + "'tombstone_compaction_interval' : 3, " + | |
| 46 | + "'tombstone_threshold' : 0.7, " + | |
| 47 | + "'unchecked_tombstone_compaction' : true, " + | |
| 48 | + "'bucket_high' : 1.2, " + | |
| 49 | + "'bucket_low' : 0.5, " + | |
| 50 | + "'cold_reads_to_omit' : 0.89, " + | |
| 51 | + "'min_threshold' : 2, " + | |
| 52 | + "'max_threshold' : 4, " + | |
| 53 | + "'min_sstable_size' : 5000000}"); | |
| 57 | 54 | } |
| 58 | 55 | |
| 59 | 56 | @Test(groups = "unit") |
| 60 | 57 | public void should_create_leveled_compaction_option() throws Exception { |
| 61 | 58 | //When |
| 62 | 59 | final String built = leveledStrategy() |
| 63 | - .enabled(true) | |
| 64 | - .ssTableSizeInMB(160) | |
| 65 | - .tombstoneCompactionIntervalInDay(3) | |
| 66 | - .tombstoneThreshold(0.7) | |
| 67 | - .uncheckedTombstoneCompaction(true) | |
| 68 | - .build(); | |
| 60 | + .enabled(true) | |
| 61 | + .ssTableSizeInMB(160) | |
| 62 | + .tombstoneCompactionIntervalInDay(3) | |
| 63 | + .tombstoneThreshold(0.7) | |
| 64 | + .uncheckedTombstoneCompaction(true) | |
| 65 | + .build(); | |
| 69 | 66 | |
| 70 | 67 | //Then |
| 71 | 68 | assertThat(built).isEqualTo("{'class' : 'LeveledCompactionStrategy', " + |
| 72 | - "'enabled' : true, " + | |
| 73 | - "'tombstone_compaction_interval' : 3, " + | |
| 74 | - "'tombstone_threshold' : 0.7, " + | |
| 75 | - "'unchecked_tombstone_compaction' : true, " + | |
| 76 | - "'sstable_size_in_mb' : 160}"); | |
| 69 | + "'enabled' : true, " + | |
| 70 | + "'tombstone_compaction_interval' : 3, " + | |
| 71 | + "'tombstone_threshold' : 0.7, " + | |
| 72 | + "'unchecked_tombstone_compaction' : true, " + | |
| 73 | + "'sstable_size_in_mb' : 160}"); | |
| 77 | 74 | } |
| 78 | 75 | |
| 79 | 76 | @Test(groups = "unit") |
| 80 | 77 | public void should_create_date_tiered_compaction_option() throws Exception { |
| 81 | 78 | //When |
| 82 | 79 | String built = dateTieredStrategy() |
| 83 | - .baseTimeSeconds(7200) | |
| 84 | - .enabled(true) | |
| 85 | - .maxSSTableAgeDays(400) | |
| 86 | - .minThreshold(2) | |
| 87 | - .maxThreshold(4) | |
| 88 | - .timestampResolution(TimeStampResolution.MICROSECONDS) | |
| 89 | - .tombstoneCompactionIntervalInDay(3) | |
| 90 | - .tombstoneThreshold(0.7) | |
| 91 | - .uncheckedTombstoneCompaction(true) | |
| 92 | - .build(); | |
| 80 | + .baseTimeSeconds(7200) | |
| 81 | + .enabled(true) | |
| 82 | + .maxSSTableAgeDays(400) | |
| 83 | + .minThreshold(2) | |
| 84 | + .maxThreshold(4) | |
| 85 | + .timestampResolution(TimeStampResolution.MICROSECONDS) | |
| 86 | + .tombstoneCompactionIntervalInDay(3) | |
| 87 | + .tombstoneThreshold(0.7) | |
| 88 | + .uncheckedTombstoneCompaction(true) | |
| 89 | + .build(); | |
| 93 | 90 | |
| 94 | 91 | //Then |
| 95 | 92 | assertThat(built).isEqualTo("{'class' : 'DateTieredCompactionStrategy', " + |
| 96 | - "'enabled' : true, " + | |
| 97 | - "'tombstone_compaction_interval' : 3, " + | |
| 98 | - "'tombstone_threshold' : 0.7, " + | |
| 99 | - "'unchecked_tombstone_compaction' : true, " + | |
| 100 | - "'base_time_seconds' : 7200, " + | |
| 101 | - "'max_sstable_age_days' : 400, " + | |
| 102 | - "'min_threshold' : 2, " + | |
| 103 | - "'max_threshold' : 4, " + | |
| 104 | - "'timestamp_resolution' : 'MICROSECONDS'}"); | |
| 93 | + "'enabled' : true, " + | |
| 94 | + "'tombstone_compaction_interval' : 3, " + | |
| 95 | + "'tombstone_threshold' : 0.7, " + | |
| 96 | + "'unchecked_tombstone_compaction' : true, " + | |
| 97 | + "'base_time_seconds' : 7200, " + | |
| 98 | + "'max_sstable_age_days' : 400, " + | |
| 99 | + "'min_threshold' : 2, " + | |
| 100 | + "'max_threshold' : 4, " + | |
| 101 | + "'timestamp_resolution' : 'MICROSECONDS'}"); | |
| 105 | 102 | } |
| 106 | 103 | |
| 107 | 104 | @Test(groups = "unit") |
| 108 | 105 | public void should_handle_freeform_options() { |
| 109 | 106 | //When |
| 110 | 107 | String built = dateTieredStrategy() |
| 111 | - .freeformOption("foo", "bar") | |
| 112 | - .freeformOption("baz", 1) | |
| 113 | - .build(); | |
| 108 | + .freeformOption("foo", "bar") | |
| 109 | + .freeformOption("baz", 1) | |
| 110 | + .build(); | |
| 114 | 111 | |
| 115 | 112 | //Then |
| 116 | 113 | assertThat(built).isEqualTo("{'class' : 'DateTieredCompactionStrategy', " + |
| 117 | - "'foo' : 'bar', " + | |
| 118 | - "'baz' : 1}"); | |
| 114 | + "'foo' : 'bar', " + | |
| 115 | + "'baz' : 1}"); | |
| 119 | 116 | |
| 120 | 117 | } |
| 121 | 118 | |
| 122 | 119 | @Test(groups = "unit", expectedExceptions = IllegalArgumentException.class) |
| 123 | 120 | public void should_throw_exception_if_cold_read_ratio_out_of_range() throws Exception { |
| 124 | 121 | sizedTieredStategy() |
| 125 | - .bucketLow(0.5) | |
| 126 | - .bucketHigh(1.2) | |
| 127 | - .coldReadsRatioToOmit(1.89) | |
| 128 | - .build(); | |
| 122 | + .bucketLow(0.5) | |
| 123 | + .bucketHigh(1.2) | |
| 124 | + .coldReadsRatioToOmit(1.89) | |
| 125 | + .build(); | |
| 129 | 126 | } |
| 130 | 127 | |
| 131 | 128 | @Test(groups = "unit", expectedExceptions = IllegalArgumentException.class) |
| 132 | 129 | public void should_throw_exception_if_cold_read_ratio_negative() throws Exception { |
| 133 | 130 | sizedTieredStategy() |
| 134 | - .bucketLow(0.5) | |
| 135 | - .bucketHigh(1.2) | |
| 136 | - .coldReadsRatioToOmit(-1.0) | |
| 137 | - .build(); | |
| 131 | + .bucketLow(0.5) | |
| 132 | + .bucketHigh(1.2) | |
| 133 | + .coldReadsRatioToOmit(-1.0) | |
| 134 | + .build(); | |
| 138 | 135 | } |
| 139 | 136 | |
| 140 | 137 | @Test(groups = "unit", expectedExceptions = IllegalArgumentException.class) |
| 141 | 138 | public void should_throw_exception_if_tombstone_threshold_out_of_range() throws Exception { |
| 142 | 139 | sizedTieredStategy() |
| 143 | - .bucketLow(0.5) | |
| 144 | - .bucketHigh(1.2) | |
| 145 | - .tombstoneThreshold(1.89) | |
| 146 | - .build(); | |
| 140 | + .bucketLow(0.5) | |
| 141 | + .bucketHigh(1.2) | |
| 142 | + .tombstoneThreshold(1.89) | |
| 143 | + .build(); | |
| 147 | 144 | } |
| 148 | 145 | |
| 149 | 146 | @Test(groups = "unit", expectedExceptions = IllegalArgumentException.class) |
| 150 | 147 | public void should_throw_exception_if_tombstone_threshold_negative() throws Exception { |
| 151 | 148 | sizedTieredStategy() |
| 152 | - .bucketLow(0.5) | |
| 153 | - .bucketHigh(1.2) | |
| 154 | - .coldReadsRatioToOmit(-1.0) | |
| 155 | - .build(); | |
| 149 | + .bucketLow(0.5) | |
| 150 | + .bucketHigh(1.2) | |
| 151 | + .coldReadsRatioToOmit(-1.0) | |
| 152 | + .build(); | |
| 156 | 153 | } |
| 157 | 154 | } |
modified driver-core/src/test/java/com/datastax/driver/core/schemabuilder/CompressionOptionsTest.java +1 −5
| @@ -17,13 +17,9 @@ | ||
| 17 | 17 | |
| 18 | 18 | import org.testng.annotations.Test; |
| 19 | 19 | |
| 20 | +import static com.datastax.driver.core.schemabuilder.SchemaBuilder.*; | |
| 20 | 21 | import static org.assertj.core.api.Assertions.assertThat; |
| 21 | 22 | |
| 22 | -import static com.datastax.driver.core.schemabuilder.SchemaBuilder.deflate; | |
| 23 | -import static com.datastax.driver.core.schemabuilder.SchemaBuilder.lz4; | |
| 24 | -import static com.datastax.driver.core.schemabuilder.SchemaBuilder.noCompression; | |
| 25 | -import static com.datastax.driver.core.schemabuilder.SchemaBuilder.snappy; | |
| 26 | - | |
| 27 | 23 | public class CompressionOptionsTest { |
| 28 | 24 | |
| 29 | 25 | @Test(groups = "unit") |
modified driver-core/src/test/java/com/datastax/driver/core/schemabuilder/CreateIndexTest.java +1 −2
| @@ -17,9 +17,8 @@ | ||
| 17 | 17 | |
| 18 | 18 | import org.testng.annotations.Test; |
| 19 | 19 | |
| 20 | -import static org.assertj.core.api.Assertions.assertThat; | |
| 21 | - | |
| 22 | 20 | import static com.datastax.driver.core.schemabuilder.SchemaBuilder.createIndex; |
| 21 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 23 | 22 | |
| 24 | 23 | public class CreateIndexTest { |
| 25 | 24 |
modified driver-core/src/test/java/com/datastax/driver/core/schemabuilder/CreateTest.java +283 −285
| @@ -15,13 +15,11 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core.schemabuilder; |
| 17 | 17 | |
| 18 | -import org.testng.annotations.Test; | |
| 19 | - | |
| 20 | -import static org.assertj.core.api.Assertions.assertThat; | |
| 21 | - | |
| 22 | 18 | import com.datastax.driver.core.DataType; |
| 19 | +import org.testng.annotations.Test; | |
| 23 | 20 | |
| 24 | 21 | import static com.datastax.driver.core.schemabuilder.SchemaBuilder.*; |
| 22 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 25 | 23 | |
| 26 | 24 | /** |
| 27 | 25 | * Note: some addColumn variants are covered in {@link CreateTypeTest}. |
| @@ -32,26 +30,26 @@ | ||
| 32 | 30 | public void should_create_simple_table() throws Exception { |
| 33 | 31 | //When |
| 34 | 32 | SchemaStatement statement = createTable("test") |
| 35 | - .addPartitionKey("id", DataType.bigint()) | |
| 36 | - .addColumn("name", DataType.text()); | |
| 33 | + .addPartitionKey("id", DataType.bigint()) | |
| 34 | + .addColumn("name", DataType.text()); | |
| 37 | 35 | |
| 38 | 36 | //Then |
| 39 | 37 | assertThat(statement.getQueryString()).isEqualTo("\n\tCREATE TABLE test(\n\t\t" + |
| 40 | - "id bigint,\n\t\t" + | |
| 41 | - "name text,\n\t\t" + | |
| 42 | - "PRIMARY KEY(id))"); | |
| 38 | + "id bigint,\n\t\t" + | |
| 39 | + "name text,\n\t\t" + | |
| 40 | + "PRIMARY KEY(id))"); | |
| 43 | 41 | } |
| 44 | 42 | |
| 45 | 43 | @Test(groups = "unit") |
| 46 | 44 | public void should_create_table_with_udt_partition_key() throws Exception { |
| 47 | 45 | //When |
| 48 | 46 | SchemaStatement statement = createTable("test") |
| 49 | - .addUDTPartitionKey("u", frozen("user")); | |
| 47 | + .addUDTPartitionKey("u", frozen("user")); | |
| 50 | 48 | |
| 51 | 49 | //Then |
| 52 | 50 | assertThat(statement.getQueryString()).isEqualTo("\n\tCREATE TABLE test(\n\t\t" + |
| 53 | - "u frozen<user>,\n\t\t" + | |
| 54 | - "PRIMARY KEY(u))" | |
| 51 | + "u frozen<user>,\n\t\t" + | |
| 52 | + "PRIMARY KEY(u))" | |
| 55 | 53 | ); |
| 56 | 54 | } |
| 57 | 55 | |
| @@ -64,547 +62,547 @@ | ||
| 64 | 62 | public void should_create_simple_table_if_not_exists() throws Exception { |
| 65 | 63 | //When |
| 66 | 64 | SchemaStatement statement = createTable("test") |
| 67 | - .ifNotExists() | |
| 68 | - .addPartitionKey("id", DataType.bigint()) | |
| 69 | - .addColumn("name", DataType.text()); | |
| 65 | + .ifNotExists() | |
| 66 | + .addPartitionKey("id", DataType.bigint()) | |
| 67 | + .addColumn("name", DataType.text()); | |
| 70 | 68 | //Then |
| 71 | 69 | assertThat(statement.getQueryString()).isEqualTo("\n\tCREATE TABLE IF NOT EXISTS test(\n\t\t" + |
| 72 | - "id bigint,\n\t\t" + | |
| 73 | - "name text,\n\t\t" + | |
| 74 | - "PRIMARY KEY(id))"); | |
| 70 | + "id bigint,\n\t\t" + | |
| 71 | + "name text,\n\t\t" + | |
| 72 | + "PRIMARY KEY(id))"); | |
| 75 | 73 | } |
| 76 | 74 | |
| 77 | 75 | @Test(groups = "unit") |
| 78 | 76 | public void should_create_simple_table_with_keyspace() throws Exception { |
| 79 | 77 | //When |
| 80 | 78 | SchemaStatement statement = createTable("ks", "test") |
| 81 | - .addPartitionKey("id", DataType.bigint()) | |
| 82 | - .addColumn("name", DataType.text()); | |
| 79 | + .addPartitionKey("id", DataType.bigint()) | |
| 80 | + .addColumn("name", DataType.text()); | |
| 83 | 81 | //Then |
| 84 | 82 | assertThat(statement.getQueryString()).isEqualTo("\n\tCREATE TABLE ks.test(\n\t\t" + |
| 85 | - "id bigint,\n\t\t" + | |
| 86 | - "name text,\n\t\t" + | |
| 87 | - "PRIMARY KEY(id))"); | |
| 83 | + "id bigint,\n\t\t" + | |
| 84 | + "name text,\n\t\t" + | |
| 85 | + "PRIMARY KEY(id))"); | |
| 88 | 86 | } |
| 89 | 87 | |
| 90 | 88 | @Test(groups = "unit") |
| 91 | 89 | public void should_create_simple_table_with_list() throws Exception { |
| 92 | 90 | //When |
| 93 | 91 | SchemaStatement statement = createTable("test") |
| 94 | - .addPartitionKey("id", DataType.bigint()) | |
| 95 | - .addColumn("friends", DataType.list(DataType.text())); | |
| 92 | + .addPartitionKey("id", DataType.bigint()) | |
| 93 | + .addColumn("friends", DataType.list(DataType.text())); | |
| 96 | 94 | |
| 97 | 95 | //Then |
| 98 | 96 | assertThat(statement.getQueryString()).isEqualTo("\n\tCREATE TABLE test(\n\t\t" + |
| 99 | - "id bigint,\n\t\t" + | |
| 100 | - "friends list<text>,\n\t\t" + | |
| 101 | - "PRIMARY KEY(id))"); | |
| 97 | + "id bigint,\n\t\t" + | |
| 98 | + "friends list<text>,\n\t\t" + | |
| 99 | + "PRIMARY KEY(id))"); | |
| 102 | 100 | } |
| 103 | 101 | |
| 104 | 102 | @Test(groups = "unit") |
| 105 | 103 | public void should_create_simple_table_with_set() throws Exception { |
| 106 | 104 | //When |
| 107 | 105 | SchemaStatement statement = createTable("test") |
| 108 | - .addPartitionKey("id", DataType.bigint()) | |
| 109 | - .addColumn("friends", DataType.set(DataType.text())); | |
| 106 | + .addPartitionKey("id", DataType.bigint()) | |
| 107 | + .addColumn("friends", DataType.set(DataType.text())); | |
| 110 | 108 | |
| 111 | 109 | //Then |
| 112 | 110 | assertThat(statement.getQueryString()).isEqualTo("\n\tCREATE TABLE test(\n\t\t" + |
| 113 | - "id bigint,\n\t\t" + | |
| 114 | - "friends set<text>,\n\t\t" + | |
| 115 | - "PRIMARY KEY(id))"); | |
| 111 | + "id bigint,\n\t\t" + | |
| 112 | + "friends set<text>,\n\t\t" + | |
| 113 | + "PRIMARY KEY(id))"); | |
| 116 | 114 | } |
| 117 | 115 | |
| 118 | 116 | @Test(groups = "unit") |
| 119 | 117 | public void should_create_simple_table_with_map() throws Exception { |
| 120 | 118 | //When |
| 121 | 119 | SchemaStatement statement = createTable("test") |
| 122 | - .addPartitionKey("id", DataType.bigint()) | |
| 123 | - .addColumn("friends", DataType.map(DataType.cint(), DataType.text())); | |
| 120 | + .addPartitionKey("id", DataType.bigint()) | |
| 121 | + .addColumn("friends", DataType.map(DataType.cint(), DataType.text())); | |
| 124 | 122 | |
| 125 | 123 | //Then |
| 126 | 124 | assertThat(statement.getQueryString()).isEqualTo("\n\tCREATE TABLE test(\n\t\t" + |
| 127 | - "id bigint,\n\t\t" + | |
| 128 | - "friends map<int, text>,\n\t\t" + | |
| 129 | - "PRIMARY KEY(id))"); | |
| 125 | + "id bigint,\n\t\t" + | |
| 126 | + "friends map<int, text>,\n\t\t" + | |
| 127 | + "PRIMARY KEY(id))"); | |
| 130 | 128 | } |
| 131 | 129 | |
| 132 | 130 | @Test(groups = "unit") |
| 133 | 131 | public void should_create_table_with_clustering_keys() throws Exception { |
| 134 | 132 | //When |
| 135 | 133 | SchemaStatement statement = createTable("test") |
| 136 | - .addPartitionKey("id", DataType.bigint()) | |
| 137 | - .addClusteringColumn("col1", DataType.uuid()) | |
| 138 | - .addClusteringColumn("col2", DataType.uuid()) | |
| 139 | - .addColumn("name", DataType.text()); | |
| 134 | + .addPartitionKey("id", DataType.bigint()) | |
| 135 | + .addClusteringColumn("col1", DataType.uuid()) | |
| 136 | + .addClusteringColumn("col2", DataType.uuid()) | |
| 137 | + .addColumn("name", DataType.text()); | |
| 140 | 138 | |
| 141 | 139 | //Then |
| 142 | 140 | assertThat(statement.getQueryString()).isEqualTo("\n\tCREATE TABLE test(\n\t\t" + |
| 143 | - "id bigint,\n\t\t" + | |
| 144 | - "col1 uuid,\n\t\t" + | |
| 145 | - "col2 uuid,\n\t\t" + | |
| 146 | - "name text,\n\t\t" + | |
| 147 | - "PRIMARY KEY(id, col1, col2))"); | |
| 141 | + "id bigint,\n\t\t" + | |
| 142 | + "col1 uuid,\n\t\t" + | |
| 143 | + "col2 uuid,\n\t\t" + | |
| 144 | + "name text,\n\t\t" + | |
| 145 | + "PRIMARY KEY(id, col1, col2))"); | |
| 148 | 146 | } |
| 149 | 147 | |
| 150 | 148 | @Test(groups = "unit") |
| 151 | 149 | public void should_create_table_with_udt_clustering_keys() throws Exception { |
| 152 | 150 | //When |
| 153 | 151 | SchemaStatement statement = createTable("test") |
| 154 | - .addPartitionKey("id", DataType.bigint()) | |
| 155 | - .addClusteringColumn("col1", DataType.uuid()) | |
| 156 | - .addUDTClusteringColumn("col2", frozen("address")) | |
| 157 | - .addColumn("name", DataType.text()); | |
| 152 | + .addPartitionKey("id", DataType.bigint()) | |
| 153 | + .addClusteringColumn("col1", DataType.uuid()) | |
| 154 | + .addUDTClusteringColumn("col2", frozen("address")) | |
| 155 | + .addColumn("name", DataType.text()); | |
| 158 | 156 | |
| 159 | 157 | //Then |
| 160 | 158 | assertThat(statement.getQueryString()).isEqualTo("\n\tCREATE TABLE test(\n\t\t" + |
| 161 | - "id bigint,\n\t\t" + | |
| 162 | - "col1 uuid,\n\t\t" + | |
| 163 | - "col2 frozen<address>,\n\t\t" + | |
| 164 | - "name text,\n\t\t" + | |
| 165 | - "PRIMARY KEY(id, col1, col2))"); | |
| 159 | + "id bigint,\n\t\t" + | |
| 160 | + "col1 uuid,\n\t\t" + | |
| 161 | + "col2 frozen<address>,\n\t\t" + | |
| 162 | + "name text,\n\t\t" + | |
| 163 | + "PRIMARY KEY(id, col1, col2))"); | |
| 166 | 164 | } |
| 167 | 165 | |
| 168 | 166 | @Test(groups = "unit") |
| 169 | 167 | public void should_create_table_with_composite_partition_key() throws Exception { |
| 170 | 168 | //When |
| 171 | 169 | SchemaStatement statement = createTable("test") |
| 172 | - .addPartitionKey("id1", DataType.bigint()) | |
| 173 | - .addPartitionKey("id2", DataType.text()) | |
| 174 | - .addColumn("name", DataType.text()); | |
| 170 | + .addPartitionKey("id1", DataType.bigint()) | |
| 171 | + .addPartitionKey("id2", DataType.text()) | |
| 172 | + .addColumn("name", DataType.text()); | |
| 175 | 173 | |
| 176 | 174 | //Then |
| 177 | 175 | assertThat(statement.getQueryString()).isEqualTo("\n\tCREATE TABLE test(\n\t\t" + |
| 178 | - "id1 bigint,\n\t\t" + | |
| 179 | - "id2 text,\n\t\t" + | |
| 180 | - "name text,\n\t\t" + | |
| 181 | - "PRIMARY KEY((id1, id2)))"); | |
| 176 | + "id1 bigint,\n\t\t" + | |
| 177 | + "id2 text,\n\t\t" + | |
| 178 | + "name text,\n\t\t" + | |
| 179 | + "PRIMARY KEY((id1, id2)))"); | |
| 182 | 180 | } |
| 183 | 181 | |
| 184 | 182 | @Test(groups = "unit") |
| 185 | 183 | public void should_create_table_with_composite_partition_key_and_clustering_keys() throws Exception { |
| 186 | 184 | //When |
| 187 | 185 | SchemaStatement statement = createTable("test") |
| 188 | - .addPartitionKey("id1", DataType.bigint()) | |
| 189 | - .addPartitionKey("id2", DataType.text()) | |
| 190 | - .addClusteringColumn("col1", DataType.uuid()) | |
| 191 | - .addClusteringColumn("col2", DataType.uuid()) | |
| 192 | - .addColumn("name", DataType.text()); | |
| 186 | + .addPartitionKey("id1", DataType.bigint()) | |
| 187 | + .addPartitionKey("id2", DataType.text()) | |
| 188 | + .addClusteringColumn("col1", DataType.uuid()) | |
| 189 | + .addClusteringColumn("col2", DataType.uuid()) | |
| 190 | + .addColumn("name", DataType.text()); | |
| 193 | 191 | |
| 194 | 192 | //Then |
| 195 | 193 | assertThat(statement.getQueryString()).isEqualTo("\n\tCREATE TABLE test(\n\t\t" + |
| 196 | - "id1 bigint,\n\t\t" + | |
| 197 | - "id2 text,\n\t\t" + | |
| 198 | - "col1 uuid,\n\t\t" + | |
| 199 | - "col2 uuid,\n\t\t" + | |
| 200 | - "name text,\n\t\t" + | |
| 201 | - "PRIMARY KEY((id1, id2), col1, col2))"); | |
| 194 | + "id1 bigint,\n\t\t" + | |
| 195 | + "id2 text,\n\t\t" + | |
| 196 | + "col1 uuid,\n\t\t" + | |
| 197 | + "col2 uuid,\n\t\t" + | |
| 198 | + "name text,\n\t\t" + | |
| 199 | + "PRIMARY KEY((id1, id2), col1, col2))"); | |
| 202 | 200 | } |
| 203 | 201 | |
| 204 | 202 | @Test(groups = "unit") |
| 205 | 203 | public void should_create_table_with_static_column() throws Exception { |
| 206 | 204 | //When |
| 207 | 205 | SchemaStatement statement = createTable("test") |
| 208 | - .addPartitionKey("id", DataType.bigint()) | |
| 209 | - .addClusteringColumn("col", DataType.uuid()) | |
| 210 | - .addStaticColumn("bucket", DataType.cint()) | |
| 211 | - .addColumn("name", DataType.text()); | |
| 206 | + .addPartitionKey("id", DataType.bigint()) | |
| 207 | + .addClusteringColumn("col", DataType.uuid()) | |
| 208 | + .addStaticColumn("bucket", DataType.cint()) | |
| 209 | + .addColumn("name", DataType.text()); | |
| 212 | 210 | |
| 213 | 211 | //Then |
| 214 | 212 | assertThat(statement.getQueryString()).isEqualTo("\n\tCREATE TABLE test(\n\t\t" + |
| 215 | - "id bigint,\n\t\t" + | |
| 216 | - "col uuid,\n\t\t" + | |
| 217 | - "bucket int static,\n\t\t" + | |
| 218 | - "name text,\n\t\t" + | |
| 219 | - "PRIMARY KEY(id, col))"); | |
| 213 | + "id bigint,\n\t\t" + | |
| 214 | + "col uuid,\n\t\t" + | |
| 215 | + "bucket int static,\n\t\t" + | |
| 216 | + "name text,\n\t\t" + | |
| 217 | + "PRIMARY KEY(id, col))"); | |
| 220 | 218 | } |
| 221 | 219 | |
| 222 | 220 | @Test(groups = "unit") |
| 223 | 221 | public void should_create_table_with_udt_static_column() throws Exception { |
| 224 | 222 | //When |
| 225 | 223 | SchemaStatement statement = createTable("test") |
| 226 | - .addPartitionKey("id", DataType.bigint()) | |
| 227 | - .addClusteringColumn("col", DataType.uuid()) | |
| 228 | - .addUDTStaticColumn("bucket", frozen("address")) | |
| 229 | - .addColumn("name", DataType.text()); | |
| 224 | + .addPartitionKey("id", DataType.bigint()) | |
| 225 | + .addClusteringColumn("col", DataType.uuid()) | |
| 226 | + .addUDTStaticColumn("bucket", frozen("address")) | |
| 227 | + .addColumn("name", DataType.text()); | |
| 230 | 228 | |
| 231 | 229 | //Then |
| 232 | 230 | assertThat(statement.getQueryString()).isEqualTo("\n\tCREATE TABLE test(\n\t\t" + |
| 233 | - "id bigint,\n\t\t" + | |
| 234 | - "col uuid,\n\t\t" + | |
| 235 | - "bucket frozen<address> static,\n\t\t" + | |
| 236 | - "name text,\n\t\t" + | |
| 237 | - "PRIMARY KEY(id, col))"); | |
| 231 | + "id bigint,\n\t\t" + | |
| 232 | + "col uuid,\n\t\t" + | |
| 233 | + "bucket frozen<address> static,\n\t\t" + | |
| 234 | + "name text,\n\t\t" + | |
| 235 | + "PRIMARY KEY(id, col))"); | |
| 238 | 236 | } |
| 239 | 237 | |
| 240 | 238 | @Test(groups = "unit") |
| 241 | 239 | public void should_create_table_with_clustering_order() throws Exception { |
| 242 | 240 | //When |
| 243 | 241 | SchemaStatement statement = createTable("test") |
| 244 | - .addPartitionKey("id", DataType.bigint()) | |
| 245 | - .addClusteringColumn("col1", DataType.uuid()) | |
| 246 | - .addClusteringColumn("col2", DataType.uuid()) | |
| 247 | - .addColumn("name", DataType.text()) | |
| 248 | - .withOptions() | |
| 249 | - .clusteringOrder("col1", Direction.ASC) | |
| 250 | - .clusteringOrder("col2", Direction.DESC); | |
| 242 | + .addPartitionKey("id", DataType.bigint()) | |
| 243 | + .addClusteringColumn("col1", DataType.uuid()) | |
| 244 | + .addClusteringColumn("col2", DataType.uuid()) | |
| 245 | + .addColumn("name", DataType.text()) | |
| 246 | + .withOptions() | |
| 247 | + .clusteringOrder("col1", Direction.ASC) | |
| 248 | + .clusteringOrder("col2", Direction.DESC); | |
| 251 | 249 | |
| 252 | 250 | //Then |
| 253 | 251 | assertThat(statement.getQueryString()).isEqualTo("\n\tCREATE TABLE test(\n\t\t" + |
| 254 | - "id bigint,\n\t\t" + | |
| 255 | - "col1 uuid,\n\t\t" + | |
| 256 | - "col2 uuid,\n\t\t" + | |
| 257 | - "name text,\n\t\t" + | |
| 258 | - "PRIMARY KEY(id, col1, col2))\n\t" + | |
| 259 | - "WITH CLUSTERING ORDER BY(col1 ASC, col2 DESC)"); | |
| 252 | + "id bigint,\n\t\t" + | |
| 253 | + "col1 uuid,\n\t\t" + | |
| 254 | + "col2 uuid,\n\t\t" + | |
| 255 | + "name text,\n\t\t" + | |
| 256 | + "PRIMARY KEY(id, col1, col2))\n\t" + | |
| 257 | + "WITH CLUSTERING ORDER BY(col1 ASC, col2 DESC)"); | |
| 260 | 258 | } |
| 261 | 259 | |
| 262 | 260 | @Test(groups = "unit", expectedExceptions = IllegalArgumentException.class) |
| 263 | 261 | public void should_fail_when_blank_clustering_order_column_provided() throws Exception { |
| 264 | 262 | createTable("test") |
| 265 | - .addPartitionKey("id", DataType.bigint()) | |
| 266 | - .addClusteringColumn("col1", DataType.uuid()) | |
| 267 | - .addClusteringColumn("col2", DataType.uuid()) | |
| 268 | - .addColumn("name", DataType.text()) | |
| 269 | - .withOptions().clusteringOrder("", Direction.DESC); | |
| 263 | + .addPartitionKey("id", DataType.bigint()) | |
| 264 | + .addClusteringColumn("col1", DataType.uuid()) | |
| 265 | + .addClusteringColumn("col2", DataType.uuid()) | |
| 266 | + .addColumn("name", DataType.text()) | |
| 267 | + .withOptions().clusteringOrder("", Direction.DESC); | |
| 270 | 268 | } |
| 271 | 269 | |
| 272 | 270 | @Test(groups = "unit", expectedExceptions = IllegalArgumentException.class) |
| 273 | 271 | public void should_fail_when_clustering_order_column_does_not_match_declared_clustering_keys() throws Exception { |
| 274 | 272 | createTable("test") |
| 275 | - .addPartitionKey("id", DataType.bigint()) | |
| 276 | - .addClusteringColumn("col1", DataType.uuid()) | |
| 277 | - .addClusteringColumn("col2", DataType.uuid()) | |
| 278 | - .addColumn("name", DataType.text()) | |
| 279 | - .withOptions().clusteringOrder("col3", Direction.ASC); | |
| 273 | + .addPartitionKey("id", DataType.bigint()) | |
| 274 | + .addClusteringColumn("col1", DataType.uuid()) | |
| 275 | + .addClusteringColumn("col2", DataType.uuid()) | |
| 276 | + .addColumn("name", DataType.text()) | |
| 277 | + .withOptions().clusteringOrder("col3", Direction.ASC); | |
| 280 | 278 | } |
| 281 | 279 | |
| 282 | 280 | @Test(groups = "unit") |
| 283 | 281 | public void should_create_table_with_compact_storage() throws Exception { |
| 284 | 282 | //When |
| 285 | 283 | SchemaStatement statement = createTable("test") |
| 286 | - .addPartitionKey("id", DataType.bigint()) | |
| 287 | - .addClusteringColumn("col1", DataType.uuid()) | |
| 288 | - .addClusteringColumn("col2", DataType.uuid()) | |
| 289 | - .addColumn("name", DataType.text()) | |
| 290 | - .withOptions() | |
| 291 | - .compactStorage(); | |
| 284 | + .addPartitionKey("id", DataType.bigint()) | |
| 285 | + .addClusteringColumn("col1", DataType.uuid()) | |
| 286 | + .addClusteringColumn("col2", DataType.uuid()) | |
| 287 | + .addColumn("name", DataType.text()) | |
| 288 | + .withOptions() | |
| 289 | + .compactStorage(); | |
| 292 | 290 | |
| 293 | 291 | //Then |
| 294 | 292 | assertThat(statement.getQueryString()).isEqualTo("\n\tCREATE TABLE test(\n\t\t" + |
| 295 | - "id bigint,\n\t\t" + | |
| 296 | - "col1 uuid,\n\t\t" + | |
| 297 | - "col2 uuid,\n\t\t" + | |
| 298 | - "name text,\n\t\t" + | |
| 299 | - "PRIMARY KEY(id, col1, col2))\n\t" + | |
| 300 | - "WITH COMPACT STORAGE"); | |
| 293 | + "id bigint,\n\t\t" + | |
| 294 | + "col1 uuid,\n\t\t" + | |
| 295 | + "col2 uuid,\n\t\t" + | |
| 296 | + "name text,\n\t\t" + | |
| 297 | + "PRIMARY KEY(id, col1, col2))\n\t" + | |
| 298 | + "WITH COMPACT STORAGE"); | |
| 301 | 299 | } |
| 302 | 300 | |
| 303 | 301 | @Test(groups = "unit") |
| 304 | 302 | public void should_create_table_with_all_options() throws Exception { |
| 305 | 303 | //When |
| 306 | 304 | SchemaStatement statement = createTable("test") |
| 307 | - .addPartitionKey("id", DataType.bigint()) | |
| 308 | - .addClusteringColumn("col1", DataType.uuid()) | |
| 309 | - .addClusteringColumn("col2", DataType.uuid()) | |
| 310 | - .addColumn("name", DataType.text()) | |
| 311 | - .withOptions() | |
| 312 | - .clusteringOrder("col1", Direction.ASC) | |
| 313 | - .clusteringOrder("col2", Direction.DESC) | |
| 314 | - .compactStorage() | |
| 315 | - .bloomFilterFPChance(0.01) | |
| 316 | - .caching(Caching.ROWS_ONLY) | |
| 317 | - .comment("This is a comment") | |
| 318 | - .compactionOptions(leveledStrategy().ssTableSizeInMB(160)) | |
| 319 | - .compressionOptions(lz4()) | |
| 320 | - .dcLocalReadRepairChance(0.21) | |
| 321 | - .defaultTimeToLive(100) | |
| 322 | - .gcGraceSeconds(9999) | |
| 323 | - .minIndexInterval(64) | |
| 324 | - .maxIndexInterval(512) | |
| 325 | - .memtableFlushPeriodInMillis(12) | |
| 326 | - .populateIOCacheOnFlush(true) | |
| 327 | - .readRepairChance(0.05) | |
| 328 | - .replicateOnWrite(true) | |
| 329 | - .speculativeRetry(always()); | |
| 305 | + .addPartitionKey("id", DataType.bigint()) | |
| 306 | + .addClusteringColumn("col1", DataType.uuid()) | |
| 307 | + .addClusteringColumn("col2", DataType.uuid()) | |
| 308 | + .addColumn("name", DataType.text()) | |
| 309 | + .withOptions() | |
| 310 | + .clusteringOrder("col1", Direction.ASC) | |
| 311 | + .clusteringOrder("col2", Direction.DESC) | |
| 312 | + .compactStorage() | |
| 313 | + .bloomFilterFPChance(0.01) | |
| 314 | + .caching(Caching.ROWS_ONLY) | |
| 315 | + .comment("This is a comment") | |
| 316 | + .compactionOptions(leveledStrategy().ssTableSizeInMB(160)) | |
| 317 | + .compressionOptions(lz4()) | |
| 318 | + .dcLocalReadRepairChance(0.21) | |
| 319 | + .defaultTimeToLive(100) | |
| 320 | + .gcGraceSeconds(9999) | |
| 321 | + .minIndexInterval(64) | |
| 322 | + .maxIndexInterval(512) | |
| 323 | + .memtableFlushPeriodInMillis(12) | |
| 324 | + .populateIOCacheOnFlush(true) | |
| 325 | + .readRepairChance(0.05) | |
| 326 | + .replicateOnWrite(true) | |
| 327 | + .speculativeRetry(always()); | |
| 330 | 328 | |
| 331 | 329 | //Then |
| 332 | 330 | assertThat(statement.getQueryString()).isEqualTo("\n\tCREATE TABLE test(\n\t\t" + |
| 333 | - "id bigint,\n\t\t" + | |
| 334 | - "col1 uuid,\n\t\t" + | |
| 335 | - "col2 uuid,\n\t\t" + | |
| 336 | - "name text,\n\t\tPRIMARY KEY(id, col1, col2))\n\t" + | |
| 337 | - "WITH caching = 'rows_only' " + | |
| 338 | - "AND bloom_filter_fp_chance = 0.01 " + | |
| 339 | - "AND comment = 'This is a comment' " + | |
| 340 | - "AND compression = {'sstable_compression' : 'LZ4Compressor'} " + | |
| 341 | - "AND compaction = {'class' : 'LeveledCompactionStrategy', 'sstable_size_in_mb' : 160} " + | |
| 342 | - "AND dclocal_read_repair_chance = 0.21 " + | |
| 343 | - "AND default_time_to_live = 100 " + | |
| 344 | - "AND gc_grace_seconds = 9999 " + | |
| 345 | - "AND min_index_interval = 64 " + | |
| 346 | - "AND max_index_interval = 512 " + | |
| 347 | - "AND memtable_flush_period_in_ms = 12 " + | |
| 348 | - "AND populate_io_cache_on_flush = true " + | |
| 349 | - "AND read_repair_chance = 0.05 " + | |
| 350 | - "AND replicate_on_write = true " + | |
| 351 | - "AND speculative_retry = 'ALWAYS' AND CLUSTERING ORDER BY(col1 ASC, col2 DESC) AND COMPACT STORAGE"); | |
| 331 | + "id bigint,\n\t\t" + | |
| 332 | + "col1 uuid,\n\t\t" + | |
| 333 | + "col2 uuid,\n\t\t" + | |
| 334 | + "name text,\n\t\tPRIMARY KEY(id, col1, col2))\n\t" + | |
| 335 | + "WITH caching = 'rows_only' " + | |
| 336 | + "AND bloom_filter_fp_chance = 0.01 " + | |
| 337 | + "AND comment = 'This is a comment' " + | |
| 338 | + "AND compression = {'sstable_compression' : 'LZ4Compressor'} " + | |
| 339 | + "AND compaction = {'class' : 'LeveledCompactionStrategy', 'sstable_size_in_mb' : 160} " + | |
| 340 | + "AND dclocal_read_repair_chance = 0.21 " + | |
| 341 | + "AND default_time_to_live = 100 " + | |
| 342 | + "AND gc_grace_seconds = 9999 " + | |
| 343 | + "AND min_index_interval = 64 " + | |
| 344 | + "AND max_index_interval = 512 " + | |
| 345 | + "AND memtable_flush_period_in_ms = 12 " + | |
| 346 | + "AND populate_io_cache_on_flush = true " + | |
| 347 | + "AND read_repair_chance = 0.05 " + | |
| 348 | + "AND replicate_on_write = true " + | |
| 349 | + "AND speculative_retry = 'ALWAYS' AND CLUSTERING ORDER BY(col1 ASC, col2 DESC) AND COMPACT STORAGE"); | |
| 352 | 350 | } |
| 353 | 351 | |
| 354 | 352 | @Test(groups = "unit") |
| 355 | 353 | public void should_build_table_with_new_caching_options() throws Exception { |
| 356 | 354 | //When |
| 357 | 355 | SchemaStatement statement = createTable("test") |
| 358 | - .addPartitionKey("id", DataType.bigint()) | |
| 359 | - .addColumn("name", DataType.text()) | |
| 360 | - .withOptions() | |
| 361 | - .caching(KeyCaching.ALL, rows(100)); | |
| 356 | + .addPartitionKey("id", DataType.bigint()) | |
| 357 | + .addColumn("name", DataType.text()) | |
| 358 | + .withOptions() | |
| 359 | + .caching(KeyCaching.ALL, rows(100)); | |
| 362 | 360 | |
| 363 | 361 | //Then |
| 364 | 362 | assertThat(statement.getQueryString()).isEqualTo("\n\tCREATE TABLE test(\n\t\t" + |
| 365 | - "id bigint,\n\t\t" + | |
| 366 | - "name text,\n\t\tPRIMARY KEY(id))\n\t" + | |
| 367 | - "WITH caching = {'keys' : 'all', 'rows_per_partition' : 100}"); | |
| 363 | + "id bigint,\n\t\t" + | |
| 364 | + "name text,\n\t\tPRIMARY KEY(id))\n\t" + | |
| 365 | + "WITH caching = {'keys' : 'all', 'rows_per_partition' : 100}"); | |
| 368 | 366 | |
| 369 | 367 | //When |
| 370 | 368 | statement = createTable("test") |
| 371 | - .addPartitionKey("id", DataType.bigint()) | |
| 372 | - .addColumn("name", DataType.text()) | |
| 373 | - .withOptions() | |
| 374 | - .caching(KeyCaching.ALL, allRows()); | |
| 369 | + .addPartitionKey("id", DataType.bigint()) | |
| 370 | + .addColumn("name", DataType.text()) | |
| 371 | + .withOptions() | |
| 372 | + .caching(KeyCaching.ALL, allRows()); | |
| 375 | 373 | |
| 376 | 374 | //Then |
| 377 | 375 | assertThat(statement.getQueryString()).isEqualTo("\n\tCREATE TABLE test(\n\t\t" + |
| 378 | - "id bigint,\n\t\t" + | |
| 379 | - "name text,\n\t\tPRIMARY KEY(id))\n\t" + | |
| 380 | - "WITH caching = {'keys' : 'all', 'rows_per_partition' : 'all'}"); | |
| 376 | + "id bigint,\n\t\t" + | |
| 377 | + "name text,\n\t\tPRIMARY KEY(id))\n\t" + | |
| 378 | + "WITH caching = {'keys' : 'all', 'rows_per_partition' : 'all'}"); | |
| 381 | 379 | } |
| 382 | 380 | |
| 383 | 381 | @Test(groups = "unit") |
| 384 | 382 | public void should_build_table_with_custom_option() throws Exception { |
| 385 | 383 | //When |
| 386 | 384 | SchemaStatement statement = createTable("test") |
| 387 | - .addPartitionKey("id", DataType.bigint()) | |
| 388 | - .addColumn("name", DataType.text()) | |
| 389 | - .withOptions() | |
| 390 | - .freeformOption("key1", "value1") | |
| 391 | - .freeformOption("key2", 1.0); | |
| 385 | + .addPartitionKey("id", DataType.bigint()) | |
| 386 | + .addColumn("name", DataType.text()) | |
| 387 | + .withOptions() | |
| 388 | + .freeformOption("key1", "value1") | |
| 389 | + .freeformOption("key2", 1.0); | |
| 392 | 390 | |
| 393 | 391 | //Then |
| 394 | 392 | assertThat(statement.getQueryString()).isEqualTo("\n\tCREATE TABLE test(\n\t\t" + |
| 395 | - "id bigint,\n\t\t" + | |
| 396 | - "name text,\n\t\tPRIMARY KEY(id))\n\t" + | |
| 397 | - "WITH key1 = 'value1' " + | |
| 398 | - "AND key2 = 1.0"); | |
| 393 | + "id bigint,\n\t\t" + | |
| 394 | + "name text,\n\t\tPRIMARY KEY(id))\n\t" + | |
| 395 | + "WITH key1 = 'value1' " + | |
| 396 | + "AND key2 = 1.0"); | |
| 399 | 397 | } |
| 400 | 398 | |
| 401 | 399 | @Test(groups = "unit", expectedExceptions = IllegalStateException.class) |
| 402 | 400 | public void should_fail_when_both_caching_versions() throws Exception { |
| 403 | 401 | createTable("test") |
| 404 | - .addPartitionKey("id", DataType.bigint()) | |
| 405 | - .addColumn("name", DataType.text()) | |
| 406 | - .withOptions() | |
| 407 | - .caching(Caching.KEYS_ONLY) | |
| 408 | - .caching(KeyCaching.ALL, allRows()).getQueryString(); | |
| 402 | + .addPartitionKey("id", DataType.bigint()) | |
| 403 | + .addColumn("name", DataType.text()) | |
| 404 | + .withOptions() | |
| 405 | + .caching(Caching.KEYS_ONLY) | |
| 406 | + .caching(KeyCaching.ALL, allRows()).getQueryString(); | |
| 409 | 407 | } |
| 410 | 408 | |
| 411 | 409 | @Test(groups = "unit", expectedExceptions = IllegalArgumentException.class) |
| 412 | 410 | public void should_fail_when_negative_rows_per_partition() throws Exception { |
| 413 | 411 | createTable("test") |
| 414 | - .addPartitionKey("id", DataType.bigint()) | |
| 415 | - .addColumn("name", DataType.text()) | |
| 416 | - .withOptions() | |
| 417 | - .caching(KeyCaching.ALL, rows(-3)); | |
| 412 | + .addPartitionKey("id", DataType.bigint()) | |
| 413 | + .addColumn("name", DataType.text()) | |
| 414 | + .withOptions() | |
| 415 | + .caching(KeyCaching.ALL, rows(-3)); | |
| 418 | 416 | } |
| 419 | 417 | |
| 420 | 418 | @Test(groups = "unit", expectedExceptions = IllegalArgumentException.class) |
| 421 | 419 | public void should_fail_when_read_repair_chance_out_of_bound() throws Exception { |
| 422 | 420 | createTable("test") |
| 423 | - .addPartitionKey("id", DataType.bigint()) | |
| 424 | - .addColumn("name", DataType.text()) | |
| 425 | - .withOptions() | |
| 426 | - .readRepairChance(1.3); | |
| 421 | + .addPartitionKey("id", DataType.bigint()) | |
| 422 | + .addColumn("name", DataType.text()) | |
| 423 | + .withOptions() | |
| 424 | + .readRepairChance(1.3); | |
| 427 | 425 | } |
| 428 | 426 | |
| 429 | 427 | @Test(groups = "unit", expectedExceptions = IllegalArgumentException.class) |
| 430 | 428 | public void should_fail_when_read_repair_chance_negative() throws Exception { |
| 431 | 429 | createTable("test") |
| 432 | - .addPartitionKey("id", DataType.bigint()) | |
| 433 | - .addColumn("name", DataType.text()) | |
| 434 | - .withOptions() | |
| 435 | - .readRepairChance(-1.3); | |
| 430 | + .addPartitionKey("id", DataType.bigint()) | |
| 431 | + .addColumn("name", DataType.text()) | |
| 432 | + .withOptions() | |
| 433 | + .readRepairChance(-1.3); | |
| 436 | 434 | } |
| 437 | 435 | |
| 438 | 436 | @Test(groups = "unit") |
| 439 | 437 | public void should_create_table_with_speculative_retry_none() throws Exception { |
| 440 | 438 | //When |
| 441 | 439 | SchemaStatement statement = createTable("test") |
| 442 | - .addPartitionKey("id", DataType.bigint()) | |
| 443 | - .addColumn("name", DataType.text()) | |
| 444 | - .withOptions() | |
| 445 | - .speculativeRetry(noSpeculativeRetry()); | |
| 440 | + .addPartitionKey("id", DataType.bigint()) | |
| 441 | + .addColumn("name", DataType.text()) | |
| 442 | + .withOptions() | |
| 443 | + .speculativeRetry(noSpeculativeRetry()); | |
| 446 | 444 | |
| 447 | 445 | //Then |
| 448 | 446 | assertThat(statement.getQueryString()).isEqualTo("\n\tCREATE TABLE test(\n\t\t" + |
| 449 | - "id bigint,\n\t\t" + | |
| 450 | - "name text,\n\t\t" + | |
| 451 | - "PRIMARY KEY(id))\n\t" + | |
| 452 | - "WITH speculative_retry = 'NONE'"); | |
| 447 | + "id bigint,\n\t\t" + | |
| 448 | + "name text,\n\t\t" + | |
| 449 | + "PRIMARY KEY(id))\n\t" + | |
| 450 | + "WITH speculative_retry = 'NONE'"); | |
| 453 | 451 | } |
| 454 | 452 | |
| 455 | 453 | @Test(groups = "unit") |
| 456 | 454 | public void should_create_table_with_speculative_retry_in_percentile() throws Exception { |
| 457 | 455 | //When |
| 458 | 456 | SchemaStatement statement = createTable("test") |
| 459 | - .addPartitionKey("id", DataType.bigint()) | |
| 460 | - .addColumn("name", DataType.text()) | |
| 461 | - .withOptions() | |
| 462 | - .speculativeRetry(percentile(95)); | |
| 457 | + .addPartitionKey("id", DataType.bigint()) | |
| 458 | + .addColumn("name", DataType.text()) | |
| 459 | + .withOptions() | |
| 460 | + .speculativeRetry(percentile(95)); | |
| 463 | 461 | |
| 464 | 462 | //Then |
| 465 | 463 | assertThat(statement.getQueryString()).isEqualTo("\n\tCREATE TABLE test(\n\t\t" + |
| 466 | - "id bigint,\n\t\t" + | |
| 467 | - "name text,\n\t\t" + | |
| 468 | - "PRIMARY KEY(id))\n\t" + | |
| 469 | - "WITH speculative_retry = '95percentile'"); | |
| 464 | + "id bigint,\n\t\t" + | |
| 465 | + "name text,\n\t\t" + | |
| 466 | + "PRIMARY KEY(id))\n\t" + | |
| 467 | + "WITH speculative_retry = '95percentile'"); | |
| 470 | 468 | } |
| 471 | 469 | |
| 472 | 470 | @Test(groups = "unit") |
| 473 | 471 | public void should_create_table_with_speculative_retry_in_milli_secs() throws Exception { |
| 474 | 472 | //When |
| 475 | 473 | SchemaStatement statement = createTable("test") |
| 476 | - .addPartitionKey("id", DataType.bigint()) | |
| 477 | - .addColumn("name", DataType.text()) | |
| 478 | - .withOptions() | |
| 479 | - .speculativeRetry(millisecs(12)); | |
| 474 | + .addPartitionKey("id", DataType.bigint()) | |
| 475 | + .addColumn("name", DataType.text()) | |
| 476 | + .withOptions() | |
| 477 | + .speculativeRetry(millisecs(12)); | |
| 480 | 478 | |
| 481 | 479 | //Then |
| 482 | 480 | assertThat(statement.getQueryString()).isEqualTo("\n\tCREATE TABLE test(\n\t\t" + |
| 483 | - "id bigint,\n\t\t" + | |
| 484 | - "name text,\n\t\t" + | |
| 485 | - "PRIMARY KEY(id))\n\t" + | |
| 486 | - "WITH speculative_retry = '12ms'"); | |
| 481 | + "id bigint,\n\t\t" + | |
| 482 | + "name text,\n\t\t" + | |
| 483 | + "PRIMARY KEY(id))\n\t" + | |
| 484 | + "WITH speculative_retry = '12ms'"); | |
| 487 | 485 | } |
| 488 | 486 | |
| 489 | 487 | @Test(groups = "unit", expectedExceptions = IllegalStateException.class, |
| 490 | - expectedExceptionsMessageRegExp = "The '\\[pk\\]' columns can not be declared as partition keys and clustering keys at the same time") | |
| 488 | + expectedExceptionsMessageRegExp = "The '\\[pk\\]' columns can not be declared as partition keys and clustering keys at the same time") | |
| 491 | 489 | public void should_fail_if_same_partition_and_clustering_column() throws Exception { |
| 492 | 490 | createTable("test") |
| 493 | - .addPartitionKey("pk", DataType.bigint()) | |
| 494 | - .addClusteringColumn("pk", DataType.bigint()).getQueryString(); | |
| 491 | + .addPartitionKey("pk", DataType.bigint()) | |
| 492 | + .addClusteringColumn("pk", DataType.bigint()).getQueryString(); | |
| 495 | 493 | } |
| 496 | 494 | |
| 497 | 495 | @Test(groups = "unit", expectedExceptions = IllegalStateException.class, |
| 498 | - expectedExceptionsMessageRegExp = "The '\\[pk\\]' columns can not be declared as partition keys and simple columns at the same time") | |
| 496 | + expectedExceptionsMessageRegExp = "The '\\[pk\\]' columns can not be declared as partition keys and simple columns at the same time") | |
| 499 | 497 | public void should_fail_if_same_partition_and_simple_column() throws Exception { |
| 500 | 498 | createTable("test") |
| 501 | - .addPartitionKey("pk", DataType.bigint()) | |
| 502 | - .addColumn("pk", DataType.text()).getQueryString(); | |
| 499 | + .addPartitionKey("pk", DataType.bigint()) | |
| 500 | + .addColumn("pk", DataType.text()).getQueryString(); | |
| 503 | 501 | } |
| 504 | 502 | |
| 505 | 503 | @Test(groups = "unit", expectedExceptions = IllegalStateException.class, |
| 506 | - expectedExceptionsMessageRegExp = "The '\\[cluster\\]' columns can not be declared as clustering keys and simple columns at the same time") | |
| 504 | + expectedExceptionsMessageRegExp = "The '\\[cluster\\]' columns can not be declared as clustering keys and simple columns at the same time") | |
| 507 | 505 | public void should_fail_if_same_clustering_and_simple_column() throws Exception { |
| 508 | 506 | createTable("test") |
| 509 | - .addPartitionKey("pk", DataType.bigint()) | |
| 510 | - .addClusteringColumn("cluster", DataType.bigint()) | |
| 511 | - .addColumn("cluster", DataType.text()).getQueryString(); | |
| 507 | + .addPartitionKey("pk", DataType.bigint()) | |
| 508 | + .addClusteringColumn("cluster", DataType.bigint()) | |
| 509 | + .addColumn("cluster", DataType.text()).getQueryString(); | |
| 512 | 510 | } |
| 513 | 511 | |
| 514 | 512 | @Test(groups = "unit", expectedExceptions = IllegalStateException.class, |
| 515 | - expectedExceptionsMessageRegExp = "The '\\[pk\\]' columns can not be declared as partition keys and static columns at the same time") | |
| 513 | + expectedExceptionsMessageRegExp = "The '\\[pk\\]' columns can not be declared as partition keys and static columns at the same time") | |
| 516 | 514 | public void should_fail_if_same_partition_and_static_column() throws Exception { |
| 517 | 515 | createTable("test") |
| 518 | - .addPartitionKey("pk", DataType.bigint()) | |
| 519 | - .addStaticColumn("pk", DataType.text()).getQueryString(); | |
| 516 | + .addPartitionKey("pk", DataType.bigint()) | |
| 517 | + .addStaticColumn("pk", DataType.text()).getQueryString(); | |
| 520 | 518 | } |
| 521 | 519 | |
| 522 | 520 | @Test(groups = "unit", expectedExceptions = IllegalStateException.class, |
| 523 | - expectedExceptionsMessageRegExp = "The '\\[cluster\\]' columns can not be declared as clustering keys and static columns at the same time") | |
| 521 | + expectedExceptionsMessageRegExp = "The '\\[cluster\\]' columns can not be declared as clustering keys and static columns at the same time") | |
| 524 | 522 | public void should_fail_if_same_clustering_and_static_column() throws Exception { |
| 525 | 523 | createTable("test") |
| 526 | - .addPartitionKey("pk", DataType.bigint()) | |
| 527 | - .addClusteringColumn("cluster", DataType.bigint()) | |
| 528 | - .addStaticColumn("cluster", DataType.text()).getQueryString(); | |
| 524 | + .addPartitionKey("pk", DataType.bigint()) | |
| 525 | + .addClusteringColumn("cluster", DataType.bigint()) | |
| 526 | + .addStaticColumn("cluster", DataType.text()).getQueryString(); | |
| 529 | 527 | } |
| 530 | 528 | |
| 531 | 529 | @Test(groups = "unit", expectedExceptions = IllegalStateException.class, |
| 532 | - expectedExceptionsMessageRegExp = "The '\\[col\\]' columns can not be declared as simple columns and static columns at the same time") | |
| 530 | + expectedExceptionsMessageRegExp = "The '\\[col\\]' columns can not be declared as simple columns and static columns at the same time") | |
| 533 | 531 | public void should_fail_if_same_simple_and_static_column() throws Exception { |
| 534 | 532 | createTable("test") |
| 535 | - .addPartitionKey("pk", DataType.bigint()) | |
| 536 | - .addClusteringColumn("cluster", DataType.uuid()) | |
| 537 | - .addColumn("col", DataType.bigint()) | |
| 538 | - .addStaticColumn("col", DataType.text()).getQueryString(); | |
| 533 | + .addPartitionKey("pk", DataType.bigint()) | |
| 534 | + .addClusteringColumn("cluster", DataType.uuid()) | |
| 535 | + .addColumn("col", DataType.bigint()) | |
| 536 | + .addStaticColumn("col", DataType.text()).getQueryString(); | |
| 539 | 537 | } |
| 540 | 538 | |
| 541 | 539 | @Test(groups = "unit", expectedExceptions = IllegalStateException.class, |
| 542 | - expectedExceptionsMessageRegExp = "The table 'test' cannot declare static columns '\\[stat\\]' without clustering columns") | |
| 540 | + expectedExceptionsMessageRegExp = "The table 'test' cannot declare static columns '\\[stat\\]' without clustering columns") | |
| 543 | 541 | public void should_fail_if_static_column_in_non_clustered_table() throws Exception { |
| 544 | 542 | createTable("test") |
| 545 | - .addPartitionKey("pk", DataType.bigint()) | |
| 546 | - .addStaticColumn("stat", DataType.text()).getQueryString(); | |
| 543 | + .addPartitionKey("pk", DataType.bigint()) | |
| 544 | + .addStaticColumn("stat", DataType.text()).getQueryString(); | |
| 547 | 545 | } |
| 548 | 546 | |
| 549 | 547 | @Test(groups = "unit", expectedExceptions = IllegalArgumentException.class, |
| 550 | - expectedExceptionsMessageRegExp = "The keyspace name 'add' is not allowed because it is a reserved keyword") | |
| 548 | + expectedExceptionsMessageRegExp = "The keyspace name 'add' is not allowed because it is a reserved keyword") | |
| 551 | 549 | public void should_fail_if_keyspace_name_is_a_reserved_keyword() throws Exception { |
| 552 | 550 | createTable("add", "test") |
| 553 | - .addPartitionKey("pk", DataType.bigint()) | |
| 554 | - .addColumn("col", DataType.text()).getQueryString(); | |
| 551 | + .addPartitionKey("pk", DataType.bigint()) | |
| 552 | + .addColumn("col", DataType.text()).getQueryString(); | |
| 555 | 553 | } |
| 556 | 554 | |
| 557 | 555 | @Test(groups = "unit", expectedExceptions = IllegalArgumentException.class, |
| 558 | - expectedExceptionsMessageRegExp = "The table name 'add' is not allowed because it is a reserved keyword") | |
| 556 | + expectedExceptionsMessageRegExp = "The table name 'add' is not allowed because it is a reserved keyword") | |
| 559 | 557 | public void should_fail_if_table_name_is_a_reserved_keyword() throws Exception { |
| 560 | 558 | createTable("add") |
| 561 | - .addPartitionKey("pk", DataType.bigint()) | |
| 562 | - .addColumn("col", DataType.text()).getQueryString(); | |
| 559 | + .addPartitionKey("pk", DataType.bigint()) | |
| 560 | + .addColumn("col", DataType.text()).getQueryString(); | |
| 563 | 561 | } |
| 564 | 562 | |
| 565 | 563 | @Test(groups = "unit", expectedExceptions = IllegalArgumentException.class, |
| 566 | - expectedExceptionsMessageRegExp = "The partition key name 'add' is not allowed because it is a reserved keyword") | |
| 564 | + expectedExceptionsMessageRegExp = "The partition key name 'add' is not allowed because it is a reserved keyword") | |
| 567 | 565 | public void should_fail_if_partition_key_is_a_reserved_keyword() throws Exception { |
| 568 | 566 | createTable("test") |
| 569 | - .addPartitionKey("add", DataType.bigint()) | |
| 570 | - .addColumn("col", DataType.text()).getQueryString(); | |
| 567 | + .addPartitionKey("add", DataType.bigint()) | |
| 568 | + .addColumn("col", DataType.text()).getQueryString(); | |
| 571 | 569 | } |
| 572 | 570 | |
| 573 | 571 | @Test(groups = "unit", expectedExceptions = IllegalArgumentException.class, |
| 574 | - expectedExceptionsMessageRegExp = "The clustering column name 'add' is not allowed because it is a reserved keyword") | |
| 572 | + expectedExceptionsMessageRegExp = "The clustering column name 'add' is not allowed because it is a reserved keyword") | |
| 575 | 573 | public void should_fail_if_clustering_key_is_a_reserved_keyword() throws Exception { |
| 576 | 574 | createTable("test") |
| 577 | - .addPartitionKey("pk", DataType.bigint()) | |
| 578 | - .addClusteringColumn("add", DataType.uuid()) | |
| 579 | - .addColumn("col", DataType.text()).getQueryString(); | |
| 575 | + .addPartitionKey("pk", DataType.bigint()) | |
| 576 | + .addClusteringColumn("add", DataType.uuid()) | |
| 577 | + .addColumn("col", DataType.text()).getQueryString(); | |
| 580 | 578 | } |
| 581 | 579 | |
| 582 | 580 | @Test(groups = "unit", expectedExceptions = IllegalArgumentException.class, |
| 583 | - expectedExceptionsMessageRegExp = "The column name 'add' is not allowed because it is a reserved keyword") | |
| 581 | + expectedExceptionsMessageRegExp = "The column name 'add' is not allowed because it is a reserved keyword") | |
| 584 | 582 | public void should_fail_if_simple_column_is_a_reserved_keyword() throws Exception { |
| 585 | 583 | createTable("test") |
| 586 | - .addPartitionKey("pk", DataType.bigint()) | |
| 587 | - .addClusteringColumn("cluster", DataType.uuid()) | |
| 588 | - .addColumn("add", DataType.text()).getQueryString(); | |
| 584 | + .addPartitionKey("pk", DataType.bigint()) | |
| 585 | + .addClusteringColumn("cluster", DataType.uuid()) | |
| 586 | + .addColumn("add", DataType.text()).getQueryString(); | |
| 589 | 587 | } |
| 590 | 588 | |
| 591 | 589 | @Test(groups = "unit", expectedExceptions = IllegalArgumentException.class, |
| 592 | - expectedExceptionsMessageRegExp = "The static column name 'add' is not allowed because it is a reserved keyword") | |
| 590 | + expectedExceptionsMessageRegExp = "The static column name 'add' is not allowed because it is a reserved keyword") | |
| 593 | 591 | public void should_fail_if_static_column_is_a_reserved_keyword() throws Exception { |
| 594 | 592 | createTable("test") |
| 595 | - .addPartitionKey("pk", DataType.bigint()) | |
| 596 | - .addClusteringColumn("cluster", DataType.uuid()) | |
| 597 | - .addStaticColumn("add", DataType.text()) | |
| 598 | - .addColumn("col", DataType.text()).getQueryString(); | |
| 593 | + .addPartitionKey("pk", DataType.bigint()) | |
| 594 | + .addClusteringColumn("cluster", DataType.uuid()) | |
| 595 | + .addStaticColumn("add", DataType.text()) | |
| 596 | + .addColumn("col", DataType.text()).getQueryString(); | |
| 599 | 597 | } |
| 600 | 598 | |
| 601 | 599 | @Test(groups = "unit", expectedExceptions = IllegalStateException.class, |
| 602 | - expectedExceptionsMessageRegExp = "Cannot create table 'test' with compact storage and static columns '\\[stat\\]'") | |
| 600 | + expectedExceptionsMessageRegExp = "Cannot create table 'test' with compact storage and static columns '\\[stat\\]'") | |
| 603 | 601 | public void should_fail_creating_table_with_static_columns_and_compact_storage() throws Exception { |
| 604 | 602 | createTable("test") |
| 605 | - .addPartitionKey("pk", DataType.bigint()) | |
| 606 | - .addClusteringColumn("cluster", DataType.uuid()) | |
| 607 | - .addStaticColumn("stat", DataType.text()) | |
| 608 | - .withOptions().compactStorage().getQueryString(); | |
| 603 | + .addPartitionKey("pk", DataType.bigint()) | |
| 604 | + .addClusteringColumn("cluster", DataType.uuid()) | |
| 605 | + .addStaticColumn("stat", DataType.text()) | |
| 606 | + .withOptions().compactStorage().getQueryString(); | |
| 609 | 607 | } |
| 610 | 608 | } |
modified driver-core/src/test/java/com/datastax/driver/core/schemabuilder/CreateTypeTest.java +39 −43
| @@ -15,133 +15,129 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core.schemabuilder; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.DataType; | |
| 18 | 19 | import org.testng.annotations.Test; |
| 19 | 20 | |
| 21 | +import static com.datastax.driver.core.schemabuilder.SchemaBuilder.*; | |
| 20 | 22 | import static org.assertj.core.api.Assertions.assertThat; |
| 21 | 23 | |
| 22 | -import com.datastax.driver.core.DataType; | |
| 23 | - | |
| 24 | -import static com.datastax.driver.core.schemabuilder.SchemaBuilder.createType; | |
| 25 | -import static com.datastax.driver.core.schemabuilder.SchemaBuilder.frozen; | |
| 26 | -import static com.datastax.driver.core.schemabuilder.SchemaBuilder.udtLiteral; | |
| 27 | - | |
| 28 | 24 | public class CreateTypeTest { |
| 29 | 25 | |
| 30 | 26 | @Test(groups = "unit") |
| 31 | 27 | public void should_create_UDT() throws Exception { |
| 32 | 28 | //When |
| 33 | 29 | SchemaStatement statement = createType("ks", "myType") |
| 34 | - .addColumn("col1", DataType.text()) | |
| 35 | - .addColumn("col2", DataType.bigint()); | |
| 30 | + .addColumn("col1", DataType.text()) | |
| 31 | + .addColumn("col2", DataType.bigint()); | |
| 36 | 32 | |
| 37 | 33 | //Then |
| 38 | 34 | assertThat(statement.getQueryString()).isEqualTo("\n\tCREATE TYPE ks.myType(\n\t\t" + |
| 39 | - "col1 text,\n\t\t" + | |
| 40 | - "col2 bigint)"); | |
| 35 | + "col1 text,\n\t\t" + | |
| 36 | + "col2 bigint)"); | |
| 41 | 37 | } |
| 42 | 38 | |
| 43 | 39 | @Test(groups = "unit") |
| 44 | 40 | public void should_create_UDT_if_not_exists() throws Exception { |
| 45 | 41 | //When |
| 46 | 42 | SchemaStatement statement = createType("myType") |
| 47 | - .ifNotExists() | |
| 48 | - .addColumn("col1", DataType.text()) | |
| 49 | - .addColumn("col2", DataType.bigint()); | |
| 43 | + .ifNotExists() | |
| 44 | + .addColumn("col1", DataType.text()) | |
| 45 | + .addColumn("col2", DataType.bigint()); | |
| 50 | 46 | |
| 51 | 47 | //Then |
| 52 | 48 | assertThat(statement.getQueryString()).isEqualTo("\n\tCREATE TYPE IF NOT EXISTS myType(\n\t\t" + |
| 53 | - "col1 text,\n\t\t" + | |
| 54 | - "col2 bigint)"); | |
| 49 | + "col1 text,\n\t\t" + | |
| 50 | + "col2 bigint)"); | |
| 55 | 51 | } |
| 56 | 52 | |
| 57 | 53 | @Test(groups = "unit") |
| 58 | 54 | public void should_create_simple_UDT_column() throws Exception { |
| 59 | 55 | //When |
| 60 | 56 | SchemaStatement statement = createType("ks", "myType") |
| 61 | - .addColumn("col1", DataType.text()) | |
| 62 | - .addUDTColumn("my_udt", frozen("address")); | |
| 57 | + .addColumn("col1", DataType.text()) | |
| 58 | + .addUDTColumn("my_udt", frozen("address")); | |
| 63 | 59 | |
| 64 | 60 | //Then |
| 65 | 61 | assertThat(statement.getQueryString()).isEqualTo("\n\tCREATE TYPE ks.myType(\n\t\t" + |
| 66 | - "col1 text,\n\t\t" + | |
| 67 | - "my_udt frozen<address>)"); | |
| 62 | + "col1 text,\n\t\t" + | |
| 63 | + "my_udt frozen<address>)"); | |
| 68 | 64 | } |
| 69 | 65 | |
| 70 | 66 | @Test(groups = "unit") |
| 71 | 67 | public void should_create_list_UDT_column() throws Exception { |
| 72 | 68 | //When |
| 73 | 69 | SchemaStatement statement = createType("ks", "myType") |
| 74 | - .addColumn("col1", DataType.text()) | |
| 75 | - .addUDTListColumn("my_udt", frozen("address")); | |
| 70 | + .addColumn("col1", DataType.text()) | |
| 71 | + .addUDTListColumn("my_udt", frozen("address")); | |
| 76 | 72 | |
| 77 | 73 | //Then |
| 78 | 74 | assertThat(statement.getQueryString()).isEqualTo("\n\tCREATE TYPE ks.myType(\n\t\t" + |
| 79 | - "col1 text,\n\t\t" + | |
| 80 | - "my_udt list<frozen<address>>)"); | |
| 75 | + "col1 text,\n\t\t" + | |
| 76 | + "my_udt list<frozen<address>>)"); | |
| 81 | 77 | } |
| 82 | 78 | |
| 83 | 79 | @Test(groups = "unit") |
| 84 | 80 | public void should_create_set_UDT_column() throws Exception { |
| 85 | 81 | //When |
| 86 | 82 | SchemaStatement statement = createType("ks", "myType") |
| 87 | - .addColumn("col1", DataType.text()) | |
| 88 | - .addUDTSetColumn("my_udt", frozen("address")); | |
| 83 | + .addColumn("col1", DataType.text()) | |
| 84 | + .addUDTSetColumn("my_udt", frozen("address")); | |
| 89 | 85 | |
| 90 | 86 | //Then |
| 91 | 87 | assertThat(statement.getQueryString()).isEqualTo("\n\tCREATE TYPE ks.myType(\n\t\t" + |
| 92 | - "col1 text,\n\t\t" + | |
| 93 | - "my_udt set<frozen<address>>)"); | |
| 88 | + "col1 text,\n\t\t" + | |
| 89 | + "my_udt set<frozen<address>>)"); | |
| 94 | 90 | } |
| 95 | 91 | |
| 96 | 92 | @Test(groups = "unit") |
| 97 | 93 | public void should_create_key_UDT_map_column() throws Exception { |
| 98 | 94 | //When |
| 99 | 95 | SchemaStatement statement = createType("ks", "myType") |
| 100 | - .addColumn("col1", DataType.text()) | |
| 101 | - .addUDTMapColumn("my_udt", frozen("address"), DataType.text()); | |
| 96 | + .addColumn("col1", DataType.text()) | |
| 97 | + .addUDTMapColumn("my_udt", frozen("address"), DataType.text()); | |
| 102 | 98 | |
| 103 | 99 | //Then |
| 104 | 100 | assertThat(statement.getQueryString()).isEqualTo("\n\tCREATE TYPE ks.myType(\n\t\t" + |
| 105 | - "col1 text,\n\t\t" + | |
| 106 | - "my_udt map<frozen<address>, text>)"); | |
| 101 | + "col1 text,\n\t\t" + | |
| 102 | + "my_udt map<frozen<address>, text>)"); | |
| 107 | 103 | } |
| 108 | 104 | |
| 109 | 105 | @Test(groups = "unit") |
| 110 | 106 | public void should_create_value_UDT_map_column() throws Exception { |
| 111 | 107 | //When |
| 112 | 108 | SchemaStatement statement = createType("ks", "myType") |
| 113 | - .addColumn("col1", DataType.text()) | |
| 114 | - .addUDTMapColumn("my_udt", DataType.cint(), frozen("address")); | |
| 109 | + .addColumn("col1", DataType.text()) | |
| 110 | + .addUDTMapColumn("my_udt", DataType.cint(), frozen("address")); | |
| 115 | 111 | |
| 116 | 112 | //Then |
| 117 | 113 | assertThat(statement.getQueryString()).isEqualTo("\n\tCREATE TYPE ks.myType(\n\t\t" + |
| 118 | - "col1 text,\n\t\t" + | |
| 119 | - "my_udt map<int, frozen<address>>)"); | |
| 114 | + "col1 text,\n\t\t" + | |
| 115 | + "my_udt map<int, frozen<address>>)"); | |
| 120 | 116 | } |
| 121 | 117 | |
| 122 | 118 | @Test(groups = "unit") |
| 123 | 119 | public void should_create_key_value_UDT_map_column() throws Exception { |
| 124 | 120 | //When |
| 125 | 121 | SchemaStatement statement = createType("ks", "myType") |
| 126 | - .addColumn("col1", DataType.text()) | |
| 127 | - .addUDTMapColumn("my_udt", frozen("coords"), frozen("address")); | |
| 122 | + .addColumn("col1", DataType.text()) | |
| 123 | + .addUDTMapColumn("my_udt", frozen("coords"), frozen("address")); | |
| 128 | 124 | |
| 129 | 125 | //Then |
| 130 | 126 | assertThat(statement.getQueryString()).isEqualTo("\n\tCREATE TYPE ks.myType(\n\t\t" + |
| 131 | - "col1 text,\n\t\t" + | |
| 132 | - "my_udt map<frozen<coords>, frozen<address>>)"); | |
| 127 | + "col1 text,\n\t\t" + | |
| 128 | + "my_udt map<frozen<coords>, frozen<address>>)"); | |
| 133 | 129 | } |
| 134 | 130 | |
| 135 | 131 | @Test(groups = "unit") |
| 136 | 132 | public void should_create_column_with_manual_type() throws Exception { |
| 137 | 133 | //When |
| 138 | 134 | SchemaStatement statement = createType("ks", "myType") |
| 139 | - .addColumn("col1", DataType.text()) | |
| 140 | - .addUDTColumn("my_udt", udtLiteral("frozen<address>")); | |
| 135 | + .addColumn("col1", DataType.text()) | |
| 136 | + .addUDTColumn("my_udt", udtLiteral("frozen<address>")); | |
| 141 | 137 | |
| 142 | 138 | //Then |
| 143 | 139 | assertThat(statement.getQueryString()).isEqualTo("\n\tCREATE TYPE ks.myType(\n\t\t" + |
| 144 | - "col1 text,\n\t\t" + | |
| 145 | - "my_udt frozen<address>)"); | |
| 140 | + "col1 text,\n\t\t" + | |
| 141 | + "my_udt frozen<address>)"); | |
| 146 | 142 | } |
| 147 | 143 | } |
| No newline at the end of the file |
modified driver-core/src/test/java/com/datastax/driver/core/schemabuilder/DropTest.java +3 −6
| @@ -17,12 +17,9 @@ | ||
| 17 | 17 | |
| 18 | 18 | import org.testng.annotations.Test; |
| 19 | 19 | |
| 20 | +import static com.datastax.driver.core.schemabuilder.SchemaBuilder.*; | |
| 20 | 21 | import static org.assertj.core.api.Assertions.assertThat; |
| 21 | 22 | |
| 22 | -import static com.datastax.driver.core.schemabuilder.SchemaBuilder.dropIndex; | |
| 23 | -import static com.datastax.driver.core.schemabuilder.SchemaBuilder.dropTable; | |
| 24 | -import static com.datastax.driver.core.schemabuilder.SchemaBuilder.dropType; | |
| 25 | - | |
| 26 | 23 | public class DropTest { |
| 27 | 24 | |
| 28 | 25 | @Test(groups = "unit") |
| @@ -107,13 +104,13 @@ | ||
| 107 | 104 | } |
| 108 | 105 | |
| 109 | 106 | @Test(groups = "unit", expectedExceptions = IllegalArgumentException.class, |
| 110 | - expectedExceptionsMessageRegExp = "The keyspace name 'add' is not allowed because it is a reserved keyword") | |
| 107 | + expectedExceptionsMessageRegExp = "The keyspace name 'add' is not allowed because it is a reserved keyword") | |
| 111 | 108 | public void should_fail_if_keyspace_name_is_a_reserved_keyword() throws Exception { |
| 112 | 109 | dropTable("add", "test").getQueryString(); |
| 113 | 110 | } |
| 114 | 111 | |
| 115 | 112 | @Test(groups = "unit", expectedExceptions = IllegalArgumentException.class, |
| 116 | - expectedExceptionsMessageRegExp = "The table name 'add' is not allowed because it is a reserved keyword") | |
| 113 | + expectedExceptionsMessageRegExp = "The table name 'add' is not allowed because it is a reserved keyword") | |
| 117 | 114 | public void should_fail_if_table_name_is_a_reserved_keyword() throws Exception { |
| 118 | 115 | dropTable("add").getQueryString(); |
| 119 | 116 | } |
modified driver-core/src/test/java/com/datastax/driver/core/schemabuilder/SchemaBuilderIT.java +124 −126
| @@ -15,25 +15,23 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core.schemabuilder; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.CCMBridge; | |
| 19 | +import com.datastax.driver.core.DataType; | |
| 20 | +import com.datastax.driver.core.ResultSet; | |
| 21 | +import com.datastax.driver.core.Row; | |
| 22 | +import com.datastax.driver.core.schemabuilder.TableOptions.CompactionOptions.DateTieredCompactionStrategyOptions.TimeStampResolution; | |
| 23 | +import com.datastax.driver.core.utils.CassandraVersion; | |
| 24 | +import org.testng.annotations.Test; | |
| 25 | + | |
| 18 | 26 | import java.util.ArrayList; |
| 19 | 27 | import java.util.Collection; |
| 20 | 28 | import java.util.Iterator; |
| 21 | 29 | |
| 22 | -import org.testng.annotations.Test; | |
| 23 | - | |
| 30 | +import static com.datastax.driver.core.schemabuilder.SchemaBuilder.*; | |
| 24 | 31 | import static org.assertj.core.api.Assertions.assertThat; |
| 25 | 32 | import static org.assertj.core.api.Assertions.fail; |
| 26 | 33 | |
| 27 | -import com.datastax.driver.core.*; | |
| 28 | -import com.datastax.driver.core.schemabuilder.TableOptions.CompactionOptions.DateTieredCompactionStrategyOptions.TimeStampResolution; | |
| 29 | -import com.datastax.driver.core.utils.CassandraVersion; | |
| 30 | - | |
| 31 | -import static com.datastax.driver.core.schemabuilder.SchemaBuilder.dateTieredStrategy; | |
| 32 | -import static com.datastax.driver.core.schemabuilder.SchemaBuilder.percentile; | |
| 33 | -import static com.datastax.driver.core.schemabuilder.SchemaBuilder.rows; | |
| 34 | -import static com.datastax.driver.core.schemabuilder.SchemaBuilder.snappy; | |
| 35 | - | |
| 36 | -public class SchemaBuilderIT extends CCMBridge.PerClassSingleNodeCluster{ | |
| 34 | +public class SchemaBuilderIT extends CCMBridge.PerClassSingleNodeCluster { | |
| 37 | 35 | |
| 38 | 36 | @Override |
| 39 | 37 | protected Collection<String> getTableDefinitions() { |
| @@ -41,73 +39,73 @@ | ||
| 41 | 39 | } |
| 42 | 40 | |
| 43 | 41 | @Test(groups = "short") |
| 44 | - @CassandraVersion(major=2.1, minor=2) | |
| 42 | + @CassandraVersion(major = 2.1, minor = 2) | |
| 45 | 43 | public void should_modify_table_metadata() { |
| 46 | 44 | // Create a table |
| 47 | 45 | session.execute(SchemaBuilder.createTable("ks", "TableMetadata") |
| 48 | - .addPartitionKey("a", DataType.cint()) | |
| 49 | - .addPartitionKey("b", DataType.cint()) | |
| 50 | - .addClusteringColumn("c", DataType.cint()) | |
| 51 | - .addClusteringColumn("d", DataType.cint()) | |
| 52 | - .withOptions() | |
| 53 | - .compactStorage() | |
| 46 | + .addPartitionKey("a", DataType.cint()) | |
| 47 | + .addPartitionKey("b", DataType.cint()) | |
| 48 | + .addClusteringColumn("c", DataType.cint()) | |
| 49 | + .addClusteringColumn("d", DataType.cint()) | |
| 50 | + .withOptions() | |
| 51 | + .compactStorage() | |
| 54 | 52 | ); |
| 55 | 53 | |
| 56 | 54 | // Modify the table metadata |
| 57 | 55 | session.execute(SchemaBuilder.alterTable("TableMetadata") |
| 58 | - .withOptions() | |
| 59 | - .defaultTimeToLive(1337) | |
| 60 | - .bloomFilterFPChance(0.42) | |
| 61 | - .caching(SchemaBuilder.KeyCaching.ALL, rows(1)) | |
| 62 | - .gcGraceSeconds(1234567890) | |
| 63 | - .minIndexInterval(6) | |
| 64 | - .indexInterval(7) | |
| 65 | - .maxIndexInterval(8) | |
| 66 | - .comment("Useful comment") | |
| 67 | - .readRepairChance(0.123456) | |
| 68 | - .speculativeRetry(percentile(50)) | |
| 69 | - .dcLocalReadRepairChance(0.84) | |
| 70 | - .memtableFlushPeriodInMillis(1234567890) | |
| 71 | - .compactionOptions(dateTieredStrategy() | |
| 72 | - .baseTimeSeconds(1) | |
| 73 | - .minThreshold(2) | |
| 74 | - .maxThreshold(3) | |
| 75 | - .maxSSTableAgeDays(4) | |
| 76 | - .timestampResolution(TimeStampResolution.MILLISECONDS)) | |
| 77 | - .compressionOptions(snappy())); | |
| 56 | + .withOptions() | |
| 57 | + .defaultTimeToLive(1337) | |
| 58 | + .bloomFilterFPChance(0.42) | |
| 59 | + .caching(SchemaBuilder.KeyCaching.ALL, rows(1)) | |
| 60 | + .gcGraceSeconds(1234567890) | |
| 61 | + .minIndexInterval(6) | |
| 62 | + .indexInterval(7) | |
| 63 | + .maxIndexInterval(8) | |
| 64 | + .comment("Useful comment") | |
| 65 | + .readRepairChance(0.123456) | |
| 66 | + .speculativeRetry(percentile(50)) | |
| 67 | + .dcLocalReadRepairChance(0.84) | |
| 68 | + .memtableFlushPeriodInMillis(1234567890) | |
| 69 | + .compactionOptions(dateTieredStrategy() | |
| 70 | + .baseTimeSeconds(1) | |
| 71 | + .minThreshold(2) | |
| 72 | + .maxThreshold(3) | |
| 73 | + .maxSSTableAgeDays(4) | |
| 74 | + .timestampResolution(TimeStampResolution.MILLISECONDS)) | |
| 75 | + .compressionOptions(snappy())); | |
| 78 | 76 | |
| 79 | 77 | // Retrieve the metadata from Cassandra |
| 80 | 78 | ResultSet rows = session.execute("SELECT " |
| 81 | - + "bloom_filter_fp_chance, " | |
| 82 | - + "caching, " | |
| 83 | - + "cf_id, " | |
| 84 | - + "column_aliases, " | |
| 85 | - + "comment, " | |
| 86 | - + "compaction_strategy_class, " | |
| 87 | - + "compaction_strategy_options, " | |
| 88 | - + "comparator, " | |
| 89 | - + "compression_parameters, " | |
| 90 | - + "default_time_to_live, " | |
| 91 | - + "default_validator, " | |
| 92 | - + "dropped_columns, " | |
| 93 | - + "gc_grace_seconds, " | |
| 94 | - + "index_interval, " | |
| 95 | - + "is_dense, " | |
| 96 | - + "key_aliases, " | |
| 97 | - + "key_validator, " | |
| 98 | - + "local_read_repair_chance, " | |
| 99 | - + "max_compaction_threshold, " | |
| 100 | - + "max_index_interval, " | |
| 101 | - + "memtable_flush_period_in_ms, " | |
| 102 | - + "min_compaction_threshold, " | |
| 103 | - + "min_index_interval, " | |
| 104 | - + "read_repair_chance, " | |
| 105 | - + "speculative_retry, " | |
| 106 | - + "subcomparator, " | |
| 107 | - + "type, " | |
| 108 | - + "value_alias " | |
| 109 | - + "FROM system.schema_columnfamilies " | |
| 110 | - + "WHERE keyspace_name='ks' AND columnfamily_name='tablemetadata'"); | |
| 79 | + + "bloom_filter_fp_chance, " | |
| 80 | + + "caching, " | |
| 81 | + + "cf_id, " | |
| 82 | + + "column_aliases, " | |
| 83 | + + "comment, " | |
| 84 | + + "compaction_strategy_class, " | |
| 85 | + + "compaction_strategy_options, " | |
| 86 | + + "comparator, " | |
| 87 | + + "compression_parameters, " | |
| 88 | + + "default_time_to_live, " | |
| 89 | + + "default_validator, " | |
| 90 | + + "dropped_columns, " | |
| 91 | + + "gc_grace_seconds, " | |
| 92 | + + "index_interval, " | |
| 93 | + + "is_dense, " | |
| 94 | + + "key_aliases, " | |
| 95 | + + "key_validator, " | |
| 96 | + + "local_read_repair_chance, " | |
| 97 | + + "max_compaction_threshold, " | |
| 98 | + + "max_index_interval, " | |
| 99 | + + "memtable_flush_period_in_ms, " | |
| 100 | + + "min_compaction_threshold, " | |
| 101 | + + "min_index_interval, " | |
| 102 | + + "read_repair_chance, " | |
| 103 | + + "speculative_retry, " | |
| 104 | + + "subcomparator, " | |
| 105 | + + "type, " | |
| 106 | + + "value_alias " | |
| 107 | + + "FROM system.schema_columnfamilies " | |
| 108 | + + "WHERE keyspace_name='ks' AND columnfamily_name='tablemetadata'"); | |
| 111 | 109 | for (Row row : rows) { |
| 112 | 110 | // There should be only one row |
| 113 | 111 | // Verify that every property we modified is correctly set |
| @@ -117,11 +115,11 @@ | ||
| 117 | 115 | assertThat(row.getString("column_aliases")).isEqualTo("[\"c\",\"d\"]"); |
| 118 | 116 | assertThat(row.getString("comment")).isEqualTo("Useful comment"); |
| 119 | 117 | assertThat(row.getString("compaction_strategy_class")) |
| 120 | - .isEqualTo("org.apache.cassandra.db.compaction.DateTieredCompactionStrategy"); | |
| 118 | + .isEqualTo("org.apache.cassandra.db.compaction.DateTieredCompactionStrategy"); | |
| 121 | 119 | assertThat(row.getString("compaction_strategy_options")).isEqualTo( |
| 122 | - "{\"base_time_seconds\":\"1\",\"timestamp_resolution\":\"MILLISECONDS\",\"max_sstable_age_days\":\"4\",\"min_threshold\":\"2\",\"max_threshold\":\"3\"}"); | |
| 120 | + "{\"base_time_seconds\":\"1\",\"timestamp_resolution\":\"MILLISECONDS\",\"max_sstable_age_days\":\"4\",\"min_threshold\":\"2\",\"max_threshold\":\"3\"}"); | |
| 123 | 121 | assertThat(row.getString("compression_parameters")) |
| 124 | - .isEqualTo("{\"sstable_compression\":\"org.apache.cassandra.io.compress.SnappyCompressor\"}"); | |
| 122 | + .isEqualTo("{\"sstable_compression\":\"org.apache.cassandra.io.compress.SnappyCompressor\"}"); | |
| 125 | 123 | assertThat(row.getInt("default_time_to_live")).isEqualTo(1337); |
| 126 | 124 | assertThat(row.getInt("gc_grace_seconds")).isEqualTo(1234567890); |
| 127 | 125 | assertThat(row.getInt("min_index_interval")).isEqualTo(6); |
| @@ -137,34 +135,34 @@ | ||
| 137 | 135 | } |
| 138 | 136 | |
| 139 | 137 | @Test(groups = "short") |
| 140 | - @CassandraVersion(major=2.1) | |
| 138 | + @CassandraVersion(major = 2.1) | |
| 141 | 139 | public void should_create_a_table_and_a_udt() { |
| 142 | 140 | // Create a UDT and a table |
| 143 | 141 | session.execute(SchemaBuilder.createType("MyUDT") |
| 144 | - .ifNotExists() | |
| 145 | - .addColumn("x", DataType.cint()) | |
| 142 | + .ifNotExists() | |
| 143 | + .addColumn("x", DataType.cint()) | |
| 146 | 144 | ); |
| 147 | 145 | UDTType myUDT = UDTType.frozen("MyUDT"); |
| 148 | 146 | session.execute(SchemaBuilder.createTable("ks", "CreateTable") |
| 149 | - .ifNotExists() | |
| 150 | - .addPartitionKey("a", DataType.cint()) | |
| 151 | - .addUDTPartitionKey("b", myUDT) | |
| 152 | - .addClusteringColumn("c", DataType.ascii()) | |
| 153 | - .addUDTClusteringColumn("d", myUDT) | |
| 154 | - .addUDTColumn("e", myUDT) | |
| 155 | - .addStaticColumn("f", DataType.bigint()) | |
| 156 | - .addUDTStaticColumn("g", myUDT) | |
| 157 | - .addUDTListColumn("h", myUDT) | |
| 158 | - .addUDTMapColumn("i", DataType.cboolean(), myUDT) | |
| 159 | - .addUDTMapColumn("j", myUDT, DataType.cboolean()) | |
| 160 | - .addUDTSetColumn("k", myUDT) | |
| 147 | + .ifNotExists() | |
| 148 | + .addPartitionKey("a", DataType.cint()) | |
| 149 | + .addUDTPartitionKey("b", myUDT) | |
| 150 | + .addClusteringColumn("c", DataType.ascii()) | |
| 151 | + .addUDTClusteringColumn("d", myUDT) | |
| 152 | + .addUDTColumn("e", myUDT) | |
| 153 | + .addStaticColumn("f", DataType.bigint()) | |
| 154 | + .addUDTStaticColumn("g", myUDT) | |
| 155 | + .addUDTListColumn("h", myUDT) | |
| 156 | + .addUDTMapColumn("i", DataType.cboolean(), myUDT) | |
| 157 | + .addUDTMapColumn("j", myUDT, DataType.cboolean()) | |
| 158 | + .addUDTSetColumn("k", myUDT) | |
| 161 | 159 | ); |
| 162 | 160 | |
| 163 | 161 | // Check columns a to k |
| 164 | 162 | ResultSet rows = session.execute( |
| 165 | - "SELECT column_name, type, validator " | |
| 166 | - + "FROM system.schema_columns " | |
| 167 | - + "WHERE keyspace_name='ks' AND columnfamily_name='createtable'"); | |
| 163 | + "SELECT column_name, type, validator " | |
| 164 | + + "FROM system.schema_columns " | |
| 165 | + + "WHERE keyspace_name='ks' AND columnfamily_name='createtable'"); | |
| 168 | 166 | Iterator<Row> iterator = rows.iterator(); |
| 169 | 167 | verifyNextColumnDefinition(iterator, "a", "partition_key", "org.apache.cassandra.db.marshal.Int32Type"); |
| 170 | 168 | verifyNextColumnDefinition(iterator, "b", "partition_key", "org.apache.cassandra.db.marshal.UserType"); |
| @@ -174,37 +172,37 @@ | ||
| 174 | 172 | verifyNextColumnDefinition(iterator, "f", "static", "org.apache.cassandra.db.marshal.LongType"); |
| 175 | 173 | verifyNextColumnDefinition(iterator, "g", "static", "org.apache.cassandra.db.marshal.UserType"); |
| 176 | 174 | verifyNextColumnDefinition(iterator, "h", "regular", "org.apache.cassandra.db.marshal.ListType" |
| 177 | - , "org.apache.cassandra.db.marshal.UserType"); | |
| 175 | + , "org.apache.cassandra.db.marshal.UserType"); | |
| 178 | 176 | verifyNextColumnDefinition(iterator, "i", "regular", "org.apache.cassandra.db.marshal.MapType" |
| 179 | - , "org.apache.cassandra.db.marshal.BooleanType", "org.apache.cassandra.db.marshal.UserType"); | |
| 177 | + , "org.apache.cassandra.db.marshal.BooleanType", "org.apache.cassandra.db.marshal.UserType"); | |
| 180 | 178 | verifyNextColumnDefinition(iterator, "j", "regular", "org.apache.cassandra.db.marshal.MapType" |
| 181 | - , "org.apache.cassandra.db.marshal.UserType", "org.apache.cassandra.db.marshal.BooleanType"); | |
| 179 | + , "org.apache.cassandra.db.marshal.UserType", "org.apache.cassandra.db.marshal.BooleanType"); | |
| 182 | 180 | verifyNextColumnDefinition(iterator, "k", "regular", "org.apache.cassandra.db.marshal.SetType" |
| 183 | - , "org.apache.cassandra.db.marshal.UserType"); | |
| 181 | + , "org.apache.cassandra.db.marshal.UserType"); | |
| 184 | 182 | } |
| 185 | 183 | |
| 186 | 184 | @Test(groups = "short") |
| 187 | 185 | public void should_add_and_drop_a_column() { |
| 188 | 186 | // Create a table, add a column to it with an alter table statement and delete that column |
| 189 | 187 | session.execute(SchemaBuilder.createTable("ks", "DropColumn") |
| 190 | - .ifNotExists() | |
| 191 | - .addPartitionKey("a", DataType.cint()) | |
| 188 | + .ifNotExists() | |
| 189 | + .addPartitionKey("a", DataType.cint()) | |
| 192 | 190 | ); |
| 193 | 191 | |
| 194 | 192 | // Add and then drop a column |
| 195 | 193 | session.execute(SchemaBuilder.alterTable("ks", "DropColumn") |
| 196 | - .addColumn("b") | |
| 197 | - .type(DataType.cint()) | |
| 194 | + .addColumn("b") | |
| 195 | + .type(DataType.cint()) | |
| 198 | 196 | ); |
| 199 | 197 | session.execute(SchemaBuilder.alterTable("ks", "DropColumn") |
| 200 | - .dropColumn("b") | |
| 198 | + .dropColumn("b") | |
| 201 | 199 | ); |
| 202 | 200 | |
| 203 | 201 | // Check that only column a exist |
| 204 | 202 | ResultSet rows = session.execute( |
| 205 | - "SELECT column_name, type, validator " | |
| 206 | - + "FROM system.schema_columns " | |
| 207 | - + "WHERE keyspace_name='ks' AND columnfamily_name='dropcolumn'"); | |
| 203 | + "SELECT column_name, type, validator " | |
| 204 | + + "FROM system.schema_columns " | |
| 205 | + + "WHERE keyspace_name='ks' AND columnfamily_name='dropcolumn'"); | |
| 208 | 206 | Iterator<Row> iterator = rows.iterator(); |
| 209 | 207 | verifyNextColumnDefinition(iterator, "a", "partition_key", "org.apache.cassandra.db.marshal.Int32Type"); |
| 210 | 208 | assertThat(iterator.hasNext()).isFalse(); |
| @@ -224,7 +222,7 @@ | ||
| 224 | 222 | public void should_drop_a_table() { |
| 225 | 223 | // Create a table |
| 226 | 224 | session.execute(SchemaBuilder.createTable("ks", "DropTable") |
| 227 | - .addPartitionKey("a", DataType.cint()) | |
| 225 | + .addPartitionKey("a", DataType.cint()) | |
| 228 | 226 | ); |
| 229 | 227 | |
| 230 | 228 | // Drop the table |
| @@ -232,9 +230,9 @@ | ||
| 232 | 230 | session.execute(SchemaBuilder.dropTable("DropTable").ifExists()); |
| 233 | 231 | |
| 234 | 232 | ResultSet rows = session.execute( |
| 235 | - "SELECT columnfamily_name " | |
| 236 | - + "FROM system.schema_columnfamilies " | |
| 237 | - + "WHERE keyspace_name='ks' AND columnfamily_name='droptable'"); | |
| 233 | + "SELECT columnfamily_name " | |
| 234 | + + "FROM system.schema_columnfamilies " | |
| 235 | + + "WHERE keyspace_name='ks' AND columnfamily_name='droptable'"); | |
| 238 | 236 | if (rows.iterator().hasNext()) { |
| 239 | 237 | fail("This table should have been deleted"); |
| 240 | 238 | } |
| @@ -244,28 +242,28 @@ | ||
| 244 | 242 | public void should_create_an_index() { |
| 245 | 243 | // Create a table |
| 246 | 244 | session.execute(SchemaBuilder.createTable("ks", "CreateIndex") |
| 247 | - .addPartitionKey("a", DataType.cint()) | |
| 248 | - .addClusteringColumn("b", DataType.cint()) | |
| 249 | - .addColumn("c", DataType.map(DataType.cint(), DataType.cint())) | |
| 245 | + .addPartitionKey("a", DataType.cint()) | |
| 246 | + .addClusteringColumn("b", DataType.cint()) | |
| 247 | + .addColumn("c", DataType.map(DataType.cint(), DataType.cint())) | |
| 250 | 248 | ); |
| 251 | 249 | |
| 252 | 250 | // Create an index on a regular column of the table |
| 253 | 251 | session.execute(SchemaBuilder.createIndex("ks_Index") |
| 254 | - .onTable("ks", "CreateIndex") | |
| 255 | - .andColumn("b") | |
| 252 | + .onTable("ks", "CreateIndex") | |
| 253 | + .andColumn("b") | |
| 256 | 254 | ); |
| 257 | 255 | session.execute(SchemaBuilder.createIndex("ks_IndexOnMap") |
| 258 | - .onTable("ks", "CreateIndex") | |
| 259 | - .andKeysOfColumn("c") | |
| 256 | + .onTable("ks", "CreateIndex") | |
| 257 | + .andKeysOfColumn("c") | |
| 260 | 258 | ); |
| 261 | 259 | |
| 262 | 260 | // Verify that the indexes exist on the right columns |
| 263 | 261 | ResultSet rows = session.execute( |
| 264 | - "SELECT column_name, index_name, index_options, index_type, component_index " | |
| 265 | - + "FROM system.schema_columns " | |
| 266 | - + "WHERE keyspace_name='ks' " | |
| 267 | - + "AND columnfamily_name='createindex' " | |
| 268 | - + "AND column_name IN ('b', 'c')"); | |
| 262 | + "SELECT column_name, index_name, index_options, index_type, component_index " | |
| 263 | + + "FROM system.schema_columns " | |
| 264 | + + "WHERE keyspace_name='ks' " | |
| 265 | + + "AND columnfamily_name='createindex' " | |
| 266 | + + "AND column_name IN ('b', 'c')"); | |
| 269 | 267 | Iterator<Row> iterator = rows.iterator(); |
| 270 | 268 | verifyNextIndexDefinition(iterator, "ks_Index", "{}", "COMPOSITES", 0); |
| 271 | 269 | verifyNextIndexDefinition(iterator, "ks_IndexOnMap", "{\"index_keys\":\"\"}", "COMPOSITES", 1); |
| @@ -285,8 +283,8 @@ | ||
| 285 | 283 | public void should_drop_an_index() { |
| 286 | 284 | // Create a table |
| 287 | 285 | session.execute(SchemaBuilder.createTable("ks", "DropIndex") |
| 288 | - .addPartitionKey("a", DataType.cint()) | |
| 289 | - .addClusteringColumn("b", DataType.cint()) | |
| 286 | + .addPartitionKey("a", DataType.cint()) | |
| 287 | + .addClusteringColumn("b", DataType.cint()) | |
| 290 | 288 | ); |
| 291 | 289 | |
| 292 | 290 | // Create an index |
| @@ -294,8 +292,8 @@ | ||
| 294 | 292 | // but a lowercase index name at deletion |
| 295 | 293 | // See : https://issues.apache.org/jira/browse/CASSANDRA-8365 |
| 296 | 294 | session.execute(SchemaBuilder.createIndex("ks_index") |
| 297 | - .onTable("ks", "DropIndex") | |
| 298 | - .andColumn("b") | |
| 295 | + .onTable("ks", "DropIndex") | |
| 296 | + .andColumn("b") | |
| 299 | 297 | ); |
| 300 | 298 | |
| 301 | 299 | // Verify that the PK index and the secondary indexes both exist |
| @@ -310,10 +308,10 @@ | ||
| 310 | 308 | |
| 311 | 309 | private int numberOfIndexedColumns(String keyspace, String table) { |
| 312 | 310 | ResultSet columns = session.execute( |
| 313 | - "SELECT * " | |
| 314 | - + "FROM system.schema_columns " | |
| 315 | - + "WHERE keyspace_name='ks' " | |
| 316 | - + "AND columnfamily_name='dropindex' "); | |
| 311 | + "SELECT * " | |
| 312 | + + "FROM system.schema_columns " | |
| 313 | + + "WHERE keyspace_name='ks' " | |
| 314 | + + "AND columnfamily_name='dropindex' "); | |
| 317 | 315 | int count = 0; |
| 318 | 316 | for (Row column : columns) { |
| 319 | 317 | if (column.getString("index_name") != null) |
modified driver-core/src/test/java/com/datastax/driver/core/utils/SocketChannelMonitor.java +14 −11
| @@ -28,9 +28,10 @@ | ||
| 28 | 28 | import org.slf4j.LoggerFactory; |
| 29 | 29 | |
| 30 | 30 | import java.net.InetSocketAddress; |
| 31 | -import java.net.Socket; | |
| 32 | -import java.net.SocketAddress; | |
| 33 | -import java.util.*; | |
| 31 | +import java.util.Collection; | |
| 32 | +import java.util.Collections; | |
| 33 | +import java.util.Comparator; | |
| 34 | +import java.util.List; | |
| 34 | 35 | import java.util.concurrent.Executors; |
| 35 | 36 | import java.util.concurrent.ScheduledExecutorService; |
| 36 | 37 | import java.util.concurrent.TimeUnit; |
| @@ -70,7 +71,7 @@ | ||
| 70 | 71 | public void run() { |
| 71 | 72 | try { |
| 72 | 73 | report(); |
| 73 | - } catch(Exception e) { | |
| 74 | + } catch (Exception e) { | |
| 74 | 75 | logger.error("Error countered.", e); |
| 75 | 76 | } |
| 76 | 77 | } |
| @@ -85,7 +86,7 @@ | ||
| 85 | 86 | |
| 86 | 87 | /** |
| 87 | 88 | * @return A custom {@link NettyOptions} instance that hooks into afterChannelInitialized added channels may be |
| 88 | - * monitored. | |
| 89 | + * monitored. | |
| 89 | 90 | */ |
| 90 | 91 | public NettyOptions nettyOptions() { |
| 91 | 92 | return nettyOptions; |
| @@ -100,6 +101,7 @@ | ||
| 100 | 101 | |
| 101 | 102 | /** |
| 102 | 103 | * Schedules a {@link #report()} to be called every configured interval. |
| 104 | + * | |
| 103 | 105 | * @param interval how often to report. |
| 104 | 106 | * @param timeUnit at what time precision to report at. |
| 105 | 107 | */ |
| @@ -115,17 +117,17 @@ | ||
| 115 | 117 | } |
| 116 | 118 | |
| 117 | 119 | /** |
| 118 | - * <p> | |
| 120 | + * <p/> | |
| 119 | 121 | * Report for all sockets matching the given predicate. The report format reflects the number of open, closed, |
| 120 | 122 | * live and total sockets created. This is logged at DEBUG if enabled. |
| 121 | - * | |
| 122 | - * <p> | |
| 123 | + * <p/> | |
| 124 | + * <p/> | |
| 123 | 125 | * If TRACE is enabled, each individual socket will be logged as well. |
| 124 | 126 | * |
| 125 | 127 | * @param channelFilter used to determine which sockets to report on. |
| 126 | 128 | */ |
| 127 | 129 | public void report(Predicate<SocketChannel> channelFilter) { |
| 128 | - if(logger.isDebugEnabled()) { | |
| 130 | + if (logger.isDebugEnabled()) { | |
| 129 | 131 | Iterable<SocketChannel> channels = matchingChannels(channelFilter); |
| 130 | 132 | Iterable<SocketChannel> open = Iterables.filter(channels, openChannels); |
| 131 | 133 | Iterable<SocketChannel> closed = Iterables.filter(channels, Predicates.not(openChannels)); |
| @@ -137,7 +139,7 @@ | ||
| 137 | 139 | Iterables.size(channels), |
| 138 | 140 | channelsCreated.get()); |
| 139 | 141 | |
| 140 | - if(logger.isTraceEnabled()) { | |
| 142 | + if (logger.isTraceEnabled()) { | |
| 141 | 143 | logger.trace("Open channels {}.", open); |
| 142 | 144 | logger.trace("Closed channels {}.", closed); |
| 143 | 145 | } |
| @@ -149,7 +151,8 @@ | ||
| 149 | 151 | public int compare(SocketChannel t0, SocketChannel t1) { |
| 150 | 152 | // Should not be null as these are filtered previously in matchingChannels. |
| 151 | 153 | assert t0 != null && t0.remoteAddress() != null; |
| 152 | - assert t1 != null && t1.remoteAddress() != null;; | |
| 154 | + assert t1 != null && t1.remoteAddress() != null; | |
| 155 | + ; | |
| 153 | 156 | return t0.remoteAddress().toString().compareTo(t1.remoteAddress().toString()); |
| 154 | 157 | } |
| 155 | 158 | }; |
modified driver-core/src/test/java/com/datastax/driver/core/utils/UUIDsTest.java +9 −7
| @@ -15,18 +15,20 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core.utils; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.ProtocolVersion; | |
| 19 | +import com.datastax.driver.core.TypeCodec; | |
| 20 | +import org.testng.annotations.Test; | |
| 21 | + | |
| 18 | 22 | import java.nio.ByteBuffer; |
| 19 | -import java.util.*; | |
| 23 | +import java.util.HashSet; | |
| 24 | +import java.util.Random; | |
| 25 | +import java.util.Set; | |
| 26 | +import java.util.UUID; | |
| 20 | 27 | import java.util.concurrent.ConcurrentSkipListSet; |
| 21 | 28 | |
| 22 | -import org.testng.annotations.Test; | |
| 23 | - | |
| 24 | 29 | import static org.testng.Assert.assertEquals; |
| 25 | 30 | import static org.testng.Assert.assertTrue; |
| 26 | 31 | |
| 27 | -import com.datastax.driver.core.ProtocolVersion; | |
| 28 | -import com.datastax.driver.core.TypeCodec; | |
| 29 | - | |
| 30 | 32 | public class UUIDsTest { |
| 31 | 33 | |
| 32 | 34 | @Test(groups = "unit") |
| @@ -102,7 +104,7 @@ | ||
| 102 | 104 | int nbPerTstamp = 10; |
| 103 | 105 | |
| 104 | 106 | for (int i = 0; i < nbTstamp; i++) { |
| 105 | - long tstamp = (long)random.nextInt(); | |
| 107 | + long tstamp = (long) random.nextInt(); | |
| 106 | 108 | for (int j = 0; j < nbPerTstamp; j++) { |
| 107 | 109 | assertWithin(new UUID(UUIDs.makeMSB(UUIDs.fromUnixTimestamp(tstamp)), random.nextLong()), UUIDs.startOf(tstamp), UUIDs.endOf(tstamp)); |
| 108 | 110 | } |
modified driver-dse/src/main/java/com/datastax/driver/auth/DseAuthProvider.java +15 −18
| @@ -22,27 +22,27 @@ | ||
| 22 | 22 | import java.net.InetSocketAddress; |
| 23 | 23 | |
| 24 | 24 | /** |
| 25 | - * AuthProvider which supplies authenticator instances for clients to connect t | |
| 26 | - * DSE clusters secured with Kerberos | |
| 27 | - * | |
| 25 | + * AuthProvider which supplies authenticator instances for clients to connect t | |
| 26 | + * DSE clusters secured with Kerberos | |
| 27 | + * <p/> | |
| 28 | 28 | * The SASL protocol name defaults to "dse"; should you need to change that |
| 29 | 29 | * it can be overridden using the <code>dse.sasl.protocol</code> system property. |
| 30 | - * <p> | |
| 30 | + * <p/> | |
| 31 | 31 | * Keytab and ticket cache settings are specified using a standard JAAS |
| 32 | 32 | * configuration file. The location of the file can be set using the |
| 33 | 33 | * <code>java.security.auth.login.config</code> system property or by adding a |
| 34 | 34 | * <code>login.config.url.n</code> entry in the <code>java.security</code> properties |
| 35 | 35 | * file. |
| 36 | - * <p> | |
| 37 | - * See the following documents for further details on the | |
| 36 | + * <p/> | |
| 37 | + * See the following documents for further details on the | |
| 38 | 38 | * <a href="https://docs.oracle.com/javase/6/docs/technotes/guides/security/jgss/tutorials/LoginConfigFile.html">JAAS Login Configuration File</a> and the |
| 39 | 39 | * <a href="http://docs.oracle.com/javase/6/docs/technotes/guides/security/jaas/tutorials/GeneralAcnOnly.html">JAAS Authentication Tutorial</a> |
| 40 | 40 | * for more on JAAS in general. |
| 41 | - * | |
| 41 | + * <p/> | |
| 42 | 42 | * <h1>Authentication using ticket cache</h1> |
| 43 | 43 | * Run <code>kinit</code> to obtain a ticket and populate the cache before |
| 44 | 44 | * connecting. JAAS config: |
| 45 | - | |
| 45 | + * <p/> | |
| 46 | 46 | * <pre> |
| 47 | 47 | * DseClient { |
| 48 | 48 | * com.sun.security.auth.module.Krb5LoginModule required |
| @@ -50,13 +50,13 @@ | ||
| 50 | 50 | * renewTGT=true; |
| 51 | 51 | * }; |
| 52 | 52 | * </pre> |
| 53 | - * | |
| 54 | - * | |
| 53 | + * <p/> | |
| 54 | + * <p/> | |
| 55 | 55 | * <h1>Authentication using a keytab file</h1> |
| 56 | 56 | * To enable authentication using a keytab file, specify its location on disk. |
| 57 | 57 | * If your keytab contains more than one principal key, you should also specify |
| 58 | 58 | * which one to select. |
| 59 | - * | |
| 59 | + * <p/> | |
| 60 | 60 | * <pre> |
| 61 | 61 | * DseClient { |
| 62 | 62 | * com.sun.security.auth.module.Krb5LoginModule required |
| @@ -65,23 +65,20 @@ | ||
| 65 | 65 | * principal="user@MYDOMAIN.COM"; |
| 66 | 66 | * }; |
| 67 | 67 | * </pre> |
| 68 | - * | |
| 68 | + * <p/> | |
| 69 | 69 | * To connect to clusters using internal authentication, use the standard method for |
| 70 | 70 | * setting credentials. eg: |
| 71 | - * | |
| 71 | + * <p/> | |
| 72 | 72 | * <pre> |
| 73 | 73 | * Cluster cluster = Cluster.builder() |
| 74 | 74 | * .addContactPoint(hostname) |
| 75 | 75 | * .withCredentials("username", "password") |
| 76 | 76 | * .build(); |
| 77 | 77 | * </pre> |
| 78 | - * | |
| 79 | 78 | */ |
| 80 | -public class DseAuthProvider implements AuthProvider | |
| 81 | -{ | |
| 79 | +public class DseAuthProvider implements AuthProvider { | |
| 82 | 80 | @Override |
| 83 | - public Authenticator newAuthenticator(InetSocketAddress host, String authenticator) throws AuthenticationException | |
| 84 | - { | |
| 81 | + public Authenticator newAuthenticator(InetSocketAddress host, String authenticator) throws AuthenticationException { | |
| 85 | 82 | return new KerberosAuthenticator(host); |
| 86 | 83 | } |
| 87 | 84 | } |
modified driver-dse/src/main/java/com/datastax/driver/auth/KerberosAuthenticator.java +9 −18
| @@ -30,8 +30,7 @@ | ||
| 30 | 30 | * PrivilegedSaslClient which performs the priviledged actions on behalf |
| 31 | 31 | * of the logged in user. |
| 32 | 32 | */ |
| 33 | -public class KerberosAuthenticator implements Authenticator | |
| 34 | -{ | |
| 33 | +public class KerberosAuthenticator implements Authenticator { | |
| 35 | 34 | private static final Logger logger = LoggerFactory.getLogger(KerberosAuthenticator.class); |
| 36 | 35 | |
| 37 | 36 | public static final String JAAS_CONFIG_ENTRY = "DseClient"; |
| @@ -41,8 +40,7 @@ | ||
| 41 | 40 | |
| 42 | 41 | private final PrivilegedSaslClient saslClient; |
| 43 | 42 | |
| 44 | - public KerberosAuthenticator(InetSocketAddress host) | |
| 45 | - { | |
| 43 | + public KerberosAuthenticator(InetSocketAddress host) { | |
| 46 | 44 | saslClient = new PrivilegedSaslClient(loginSubject(), |
| 47 | 45 | SUPPORTED_MECHANISMS, |
| 48 | 46 | null, |
| @@ -52,32 +50,26 @@ | ||
| 52 | 50 | null); |
| 53 | 51 | } |
| 54 | 52 | |
| 55 | - private Subject loginSubject() | |
| 56 | - { | |
| 53 | + private Subject loginSubject() { | |
| 57 | 54 | Subject subject = new Subject(); |
| 58 | - try | |
| 59 | - { | |
| 55 | + try { | |
| 60 | 56 | LoginContext login = new LoginContext(JAAS_CONFIG_ENTRY, subject); |
| 61 | 57 | login.login(); |
| 62 | 58 | return subject; |
| 63 | - } catch (LoginException e) | |
| 64 | - { | |
| 59 | + } catch (LoginException e) { | |
| 65 | 60 | throw new RuntimeException(e); |
| 66 | 61 | } |
| 67 | 62 | } |
| 68 | 63 | |
| 69 | 64 | @Override |
| 70 | - public byte[] initialResponse() | |
| 71 | - { | |
| 65 | + public byte[] initialResponse() { | |
| 72 | 66 | return saslClient.getInitialResponse(); |
| 73 | 67 | } |
| 74 | 68 | |
| 75 | 69 | @Override |
| 76 | - public byte[] evaluateChallenge(byte[] challenge) | |
| 77 | - { | |
| 70 | + public byte[] evaluateChallenge(byte[] challenge) { | |
| 78 | 71 | byte[] response = saslClient.evaluateChallenge(challenge); |
| 79 | - if (response == null) | |
| 80 | - { | |
| 72 | + if (response == null) { | |
| 81 | 73 | // If we generate a null response, then authentication has completed (if |
| 82 | 74 | // not, warn), and return without sending a response back to the server. |
| 83 | 75 | logger.trace("Response to server is null: authentication should now be complete."); |
| @@ -91,8 +83,7 @@ | ||
| 91 | 83 | } |
| 92 | 84 | |
| 93 | 85 | @Override |
| 94 | - public void onAuthenticationSuccess(byte[] token) | |
| 95 | - { | |
| 86 | + public void onAuthenticationSuccess(byte[] token) { | |
| 96 | 87 | // no-op |
| 97 | 88 | } |
| 98 | 89 | } |
modified driver-dse/src/main/java/com/datastax/driver/auth/PrivilegedSaslClient.java +25 −43
| @@ -32,14 +32,12 @@ | ||
| 32 | 32 | * the authentication protocol as {@code PrivilegedAction}s with the |
| 33 | 33 | * assumed identity of the {@code Subject} supplied in the constructor. |
| 34 | 34 | */ |
| 35 | -public class PrivilegedSaslClient | |
| 36 | -{ | |
| 35 | +public class PrivilegedSaslClient { | |
| 37 | 36 | private static final Logger logger = LoggerFactory.getLogger(PrivilegedSaslClient.class); |
| 38 | 37 | |
| 39 | - public static final Map<String, String> DEFAULT_PROPERTIES = new HashMap<String, String>() | |
| 40 | - {{ | |
| 41 | - put(Sasl.SERVER_AUTH, "true"); | |
| 42 | - put(Sasl.QOP, "auth"); | |
| 38 | + public static final Map<String, String> DEFAULT_PROPERTIES = new HashMap<String, String>() {{ | |
| 39 | + put(Sasl.SERVER_AUTH, "true"); | |
| 40 | + put(Sasl.QOP, "auth"); | |
| 43 | 41 | }}; |
| 44 | 42 | private static final byte[] EMPTY_BYTE_ARRAY = new byte[0]; |
| 45 | 43 | |
| @@ -60,17 +58,13 @@ | ||
| 60 | 58 | final String protocol, |
| 61 | 59 | final String hostname, |
| 62 | 60 | final Map<String, String> properties, |
| 63 | - final CallbackHandler callbackHandler) | |
| 64 | - { | |
| 61 | + final CallbackHandler callbackHandler) { | |
| 65 | 62 | logger.trace("Initalising SASL client"); |
| 66 | 63 | this.clientIdentity = clientIdentity; |
| 67 | - saslClient = Subject.doAs(this.clientIdentity, new PrivilegedAction<SaslClient>() | |
| 68 | - { | |
| 64 | + saslClient = Subject.doAs(this.clientIdentity, new PrivilegedAction<SaslClient>() { | |
| 69 | 65 | @Override |
| 70 | - public javax.security.sasl.SaslClient run() | |
| 71 | - { | |
| 72 | - try | |
| 73 | - { | |
| 66 | + public javax.security.sasl.SaslClient run() { | |
| 67 | + try { | |
| 74 | 68 | return Sasl.createSaslClient( |
| 75 | 69 | mechanisms, |
| 76 | 70 | authzId, |
| @@ -78,8 +72,7 @@ | ||
| 78 | 72 | hostname, |
| 79 | 73 | properties, |
| 80 | 74 | callbackHandler); |
| 81 | - } catch (Exception e) | |
| 82 | - { | |
| 75 | + } catch (Exception e) { | |
| 83 | 76 | logger.error("Error initialising SASL client", e); |
| 84 | 77 | throw new RuntimeException(e); |
| 85 | 78 | } |
| @@ -91,24 +84,19 @@ | ||
| 91 | 84 | |
| 92 | 85 | /** |
| 93 | 86 | * Generate an initial token to start the SASL handshake with server. |
| 87 | + * | |
| 94 | 88 | * @return SaslTokenRequestMessage message to be sent to server. |
| 95 | 89 | */ |
| 96 | - public byte[] getInitialResponse() | |
| 97 | - { | |
| 90 | + public byte[] getInitialResponse() { | |
| 98 | 91 | logger.trace("Initialising SASL handshake from client"); |
| 99 | 92 | byte[] initialResponse = null; |
| 100 | - if (saslClient.hasInitialResponse()) | |
| 101 | - { | |
| 102 | - initialResponse = Subject.doAs(clientIdentity, new PrivilegedAction<byte[]>() | |
| 103 | - { | |
| 93 | + if (saslClient.hasInitialResponse()) { | |
| 94 | + initialResponse = Subject.doAs(clientIdentity, new PrivilegedAction<byte[]>() { | |
| 104 | 95 | @Override |
| 105 | - public byte[] run() | |
| 106 | - { | |
| 107 | - try | |
| 108 | - { | |
| 96 | + public byte[] run() { | |
| 97 | + try { | |
| 109 | 98 | return saslClient.evaluateChallenge(EMPTY_BYTE_ARRAY); |
| 110 | - } catch (Exception e) | |
| 111 | - { | |
| 99 | + } catch (Exception e) { | |
| 112 | 100 | throw new RuntimeException(e); |
| 113 | 101 | } |
| 114 | 102 | } |
| @@ -119,30 +107,24 @@ | ||
| 119 | 107 | |
| 120 | 108 | /** |
| 121 | 109 | * Respond to server's SASL token |
| 110 | + * | |
| 122 | 111 | * @param challenge contains server's SASL token |
| 123 | 112 | * @return client's response SASL token, which will be null if authentication is complete |
| 124 | 113 | */ |
| 125 | - public byte[] evaluateChallenge(final byte[] challenge) | |
| 126 | - { | |
| 114 | + public byte[] evaluateChallenge(final byte[] challenge) { | |
| 127 | 115 | logger.trace("Evaluating SASL server token"); |
| 128 | - if (saslClient.isComplete()) | |
| 129 | - { | |
| 116 | + if (saslClient.isComplete()) { | |
| 130 | 117 | return null; |
| 131 | 118 | } |
| 132 | - byte[] retval = Subject.doAs(clientIdentity, new PrivilegedAction<byte[]>() | |
| 133 | - { | |
| 119 | + byte[] retval = Subject.doAs(clientIdentity, new PrivilegedAction<byte[]>() { | |
| 134 | 120 | @Override |
| 135 | - public byte[] run() | |
| 136 | - { | |
| 137 | - try | |
| 138 | - { | |
| 121 | + public byte[] run() { | |
| 122 | + try { | |
| 139 | 123 | logger.trace("SASL client evaluating challenge"); |
| 140 | 124 | byte[] retval = saslClient.evaluateChallenge(challenge); |
| 141 | 125 | logger.trace("SASL client is complete = " + saslClient.isComplete()); |
| 142 | 126 | return retval; |
| 143 | - } | |
| 144 | - catch (SaslException e) | |
| 145 | - { | |
| 127 | + } catch (SaslException e) { | |
| 146 | 128 | logger.error("Failed to generate response to SASL server's token:", e); |
| 147 | 129 | throw new RuntimeException(e); |
| 148 | 130 | } |
| @@ -153,10 +135,10 @@ | ||
| 153 | 135 | |
| 154 | 136 | /** |
| 155 | 137 | * Is the SASL negotiation with the server complete |
| 138 | + * | |
| 156 | 139 | * @return true iff SASL authentication has successfully completed |
| 157 | 140 | */ |
| 158 | - public boolean isComplete() | |
| 159 | - { | |
| 141 | + public boolean isComplete() { | |
| 160 | 142 | return saslClient.isComplete(); |
| 161 | 143 | } |
| 162 | 144 | } |
modified driver-examples/osgi/src/main/java/com/datastax/driver/osgi/api/MailboxMessage.java +7 −6
| @@ -46,13 +46,14 @@ | ||
| 46 | 46 | return body; |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | - @Override public boolean equals(Object that) { | |
| 50 | - if(that instanceof MailboxMessage) { | |
| 51 | - MailboxMessage thatM = (MailboxMessage)that; | |
| 49 | + @Override | |
| 50 | + public boolean equals(Object that) { | |
| 51 | + if (that instanceof MailboxMessage) { | |
| 52 | + MailboxMessage thatM = (MailboxMessage) that; | |
| 52 | 53 | return recipient.equals(thatM.getRecipient()) && |
| 53 | - date.equals(thatM.getDate()) && | |
| 54 | - sender.equals(thatM.getSender()) && | |
| 55 | - body.equals(thatM.getBody()); | |
| 54 | + date.equals(thatM.getDate()) && | |
| 55 | + sender.equals(thatM.getSender()) && | |
| 56 | + body.equals(thatM.getBody()); | |
| 56 | 57 | } else { |
| 57 | 58 | return false; |
| 58 | 59 | } |
modified driver-examples/osgi/src/main/java/com/datastax/driver/osgi/api/MailboxService.java +3 −0
| @@ -22,6 +22,7 @@ | ||
| 22 | 22 | |
| 23 | 23 | /** |
| 24 | 24 | * Retrieve all messages for a given recipient. |
| 25 | + * | |
| 25 | 26 | * @param recipient User whose mailbox is being read. |
| 26 | 27 | * @return All messages in the mailbox. |
| 27 | 28 | */ |
| @@ -29,6 +30,7 @@ | ||
| 29 | 30 | |
| 30 | 31 | /** |
| 31 | 32 | * Stores the given message in the appropriate mailbox. |
| 33 | + * | |
| 32 | 34 | * @param message Message to send. |
| 33 | 35 | * @return UUID generated for the message. |
| 34 | 36 | */ |
| @@ -36,6 +38,7 @@ | ||
| 36 | 38 | |
| 37 | 39 | /** |
| 38 | 40 | * Deletes all mail for the given recipient. |
| 41 | + * | |
| 39 | 42 | * @param recipient User whose mailbox will be cleared. |
| 40 | 43 | */ |
| 41 | 44 | public void clearMailbox(String recipient) throws MailboxException; |
modified driver-examples/osgi/src/main/java/com/datastax/driver/osgi/impl/Activator.java +11 −10
| @@ -15,28 +15,28 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.osgi.impl; |
| 17 | 17 | |
| 18 | -import java.util.Hashtable; | |
| 19 | - | |
| 20 | -import org.osgi.framework.BundleActivator; | |
| 21 | -import org.osgi.framework.BundleContext; | |
| 22 | - | |
| 23 | 18 | import com.datastax.driver.core.Cluster; |
| 24 | 19 | import com.datastax.driver.core.Session; |
| 25 | 20 | import com.datastax.driver.osgi.api.MailboxService; |
| 21 | +import org.osgi.framework.BundleActivator; | |
| 22 | +import org.osgi.framework.BundleContext; | |
| 23 | + | |
| 24 | +import java.util.Hashtable; | |
| 26 | 25 | |
| 27 | 26 | public class Activator implements BundleActivator { |
| 28 | 27 | |
| 29 | 28 | private Cluster cluster; |
| 30 | 29 | |
| 31 | - @Override public void start(BundleContext context) throws Exception { | |
| 30 | + @Override | |
| 31 | + public void start(BundleContext context) throws Exception { | |
| 32 | 32 | String contactPointsStr = context.getProperty("cassandra.contactpoints"); |
| 33 | - if(contactPointsStr == null) { | |
| 33 | + if (contactPointsStr == null) { | |
| 34 | 34 | contactPointsStr = "127.0.0.1"; |
| 35 | 35 | } |
| 36 | 36 | String[] contactPoints = contactPointsStr.split(","); |
| 37 | 37 | |
| 38 | 38 | String keyspace = context.getProperty("cassandra.keyspace"); |
| 39 | - if(keyspace == null) { | |
| 39 | + if (keyspace == null) { | |
| 40 | 40 | keyspace = "mailbox"; |
| 41 | 41 | } |
| 42 | 42 | |
| @@ -49,8 +49,9 @@ | ||
| 49 | 49 | context.registerService(MailboxService.class.getName(), mailbox, new Hashtable<String, String>()); |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | - @Override public void stop(BundleContext context) throws Exception { | |
| 53 | - if(cluster != null) { | |
| 52 | + @Override | |
| 53 | + public void stop(BundleContext context) throws Exception { | |
| 54 | + if (cluster != null) { | |
| 54 | 55 | cluster.close(); |
| 55 | 56 | } |
| 56 | 57 | } |
modified driver-examples/osgi/src/main/java/com/datastax/driver/osgi/impl/MailboxImpl.java +32 −29
| @@ -15,11 +15,6 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.osgi.impl; |
| 17 | 17 | |
| 18 | -import java.util.ArrayList; | |
| 19 | -import java.util.Collection; | |
| 20 | -import java.util.Date; | |
| 21 | -import java.util.UUID; | |
| 22 | - | |
| 23 | 18 | import com.datastax.driver.core.*; |
| 24 | 19 | import com.datastax.driver.core.exceptions.InvalidQueryException; |
| 25 | 20 | import com.datastax.driver.core.utils.UUIDs; |
| @@ -27,6 +22,11 @@ | ||
| 27 | 22 | import com.datastax.driver.osgi.api.MailboxMessage; |
| 28 | 23 | import com.datastax.driver.osgi.api.MailboxService; |
| 29 | 24 | |
| 25 | +import java.util.ArrayList; | |
| 26 | +import java.util.Collection; | |
| 27 | +import java.util.Date; | |
| 28 | +import java.util.UUID; | |
| 29 | + | |
| 30 | 30 | import static com.datastax.driver.core.querybuilder.QueryBuilder.*; |
| 31 | 31 | |
| 32 | 32 | public class MailboxImpl implements MailboxService { |
| @@ -51,7 +51,7 @@ | ||
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | public synchronized void init() { |
| 54 | - if(initialized) | |
| 54 | + if (initialized) | |
| 55 | 55 | return; |
| 56 | 56 | |
| 57 | 57 | // Create the schema if it does not exist. |
| @@ -59,53 +59,55 @@ | ||
| 59 | 59 | session.execute("USE " + keyspace); |
| 60 | 60 | } catch (InvalidQueryException e) { |
| 61 | 61 | session.execute("CREATE KEYSPACE " + keyspace + |
| 62 | - " with replication = {'class': 'SimpleStrategy', 'replication_factor' : 1}"); | |
| 62 | + " with replication = {'class': 'SimpleStrategy', 'replication_factor' : 1}"); | |
| 63 | 63 | |
| 64 | 64 | session.execute("CREATE TABLE " + keyspace + "." + TABLE + " (" + |
| 65 | - "recipient text," + | |
| 66 | - "time timeuuid," + | |
| 67 | - "sender text," + | |
| 68 | - "body text," + | |
| 69 | - "PRIMARY KEY (recipient, time))"); | |
| 65 | + "recipient text," + | |
| 66 | + "time timeuuid," + | |
| 67 | + "sender text," + | |
| 68 | + "body text," + | |
| 69 | + "PRIMARY KEY (recipient, time))"); | |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | retrieveStatement = session.prepare(select() |
| 73 | - .from(keyspace, TABLE) | |
| 74 | - .where(eq("recipient", bindMarker()))); | |
| 73 | + .from(keyspace, TABLE) | |
| 74 | + .where(eq("recipient", bindMarker()))); | |
| 75 | 75 | |
| 76 | 76 | insertStatement = session.prepare(insertInto(keyspace, TABLE) |
| 77 | - .value("recipient", bindMarker()) | |
| 78 | - .value("time", bindMarker()) | |
| 79 | - .value("sender", bindMarker()) | |
| 80 | - .value("body", bindMarker())); | |
| 77 | + .value("recipient", bindMarker()) | |
| 78 | + .value("time", bindMarker()) | |
| 79 | + .value("sender", bindMarker()) | |
| 80 | + .value("body", bindMarker())); | |
| 81 | 81 | |
| 82 | 82 | deleteStatement = session.prepare(delete().from(keyspace, TABLE) |
| 83 | - .where(eq("recipient", bindMarker()))); | |
| 83 | + .where(eq("recipient", bindMarker()))); | |
| 84 | 84 | |
| 85 | 85 | initialized = true; |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | - @Override public Collection<MailboxMessage> getMessages(String recipient) throws MailboxException { | |
| 88 | + @Override | |
| 89 | + public Collection<MailboxMessage> getMessages(String recipient) throws MailboxException { | |
| 89 | 90 | try { |
| 90 | 91 | BoundStatement statement = new BoundStatement(retrieveStatement); |
| 91 | 92 | statement.setString(0, recipient); |
| 92 | 93 | ResultSet result = session.execute(statement); |
| 93 | 94 | |
| 94 | 95 | Collection<MailboxMessage> messages = new ArrayList<MailboxMessage>(); |
| 95 | - for(Row input : result) { | |
| 96 | + for (Row input : result) { | |
| 96 | 97 | Date date = new Date(UUIDs.unixTimestamp(input.getUUID("time"))); |
| 97 | 98 | messages.add(new MailboxMessage(input.getString("recipient"), |
| 98 | - date, | |
| 99 | - input.getString("sender"), | |
| 100 | - input.getString("body"))); | |
| 99 | + date, | |
| 100 | + input.getString("sender"), | |
| 101 | + input.getString("body"))); | |
| 101 | 102 | } |
| 102 | 103 | return messages; |
| 103 | - } catch(Exception e) { | |
| 104 | + } catch (Exception e) { | |
| 104 | 105 | throw new MailboxException(e); |
| 105 | 106 | } |
| 106 | 107 | } |
| 107 | 108 | |
| 108 | - @Override public UUID sendMessage(MailboxMessage message) throws MailboxException { | |
| 109 | + @Override | |
| 110 | + public UUID sendMessage(MailboxMessage message) throws MailboxException { | |
| 109 | 111 | try { |
| 110 | 112 | UUID time = UUIDs.startOf(message.getDate().getTime()); |
| 111 | 113 | |
| @@ -117,17 +119,18 @@ | ||
| 117 | 119 | |
| 118 | 120 | session.execute(statement); |
| 119 | 121 | return time; |
| 120 | - } catch(Exception e) { | |
| 122 | + } catch (Exception e) { | |
| 121 | 123 | throw new MailboxException(e); |
| 122 | 124 | } |
| 123 | 125 | } |
| 124 | 126 | |
| 125 | - @Override public void clearMailbox(String recipient) throws MailboxException { | |
| 127 | + @Override | |
| 128 | + public void clearMailbox(String recipient) throws MailboxException { | |
| 126 | 129 | try { |
| 127 | 130 | BoundStatement statement = new BoundStatement(deleteStatement); |
| 128 | 131 | statement.setString(0, recipient); |
| 129 | 132 | session.execute(statement); |
| 130 | - } catch(Exception e) { | |
| 133 | + } catch (Exception e) { | |
| 131 | 134 | throw new MailboxException(e); |
| 132 | 135 | } |
| 133 | 136 | } |
modified driver-examples/osgi/src/test/java/com/datastax/driver/osgi/BundleOptions.java +23 −28
| @@ -15,22 +15,15 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.osgi; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.CCMBridge; | |
| 18 | 19 | import org.ops4j.pax.exam.Option; |
| 19 | 20 | import org.ops4j.pax.exam.options.CompositeOption; |
| 20 | 21 | import org.ops4j.pax.exam.options.MavenArtifactProvisionOption; |
| 21 | 22 | import org.ops4j.pax.exam.options.UrlProvisionOption; |
| 22 | 23 | import org.ops4j.pax.exam.util.PathUtils; |
| 23 | 24 | |
| 24 | -import static org.ops4j.pax.exam.CoreOptions.bootDelegationPackage; | |
| 25 | -import static org.ops4j.pax.exam.CoreOptions.bundle; | |
| 26 | -import static org.ops4j.pax.exam.CoreOptions.mavenBundle; | |
| 27 | -import static org.ops4j.pax.exam.CoreOptions.options; | |
| 28 | -import static org.ops4j.pax.exam.CoreOptions.systemPackages; | |
| 29 | -import static org.ops4j.pax.exam.CoreOptions.systemProperty; | |
| 30 | - | |
| 31 | -import com.datastax.driver.core.CCMBridge; | |
| 32 | - | |
| 33 | 25 | import static com.datastax.driver.osgi.VersionProvider.projectVersion; |
| 26 | +import static org.ops4j.pax.exam.CoreOptions.*; | |
| 34 | 27 | |
| 35 | 28 | public class BundleOptions { |
| 36 | 29 | |
| @@ -40,7 +33,7 @@ | ||
| 40 | 33 | |
| 41 | 34 | public static UrlProvisionOption driverBundle(boolean useShaded) { |
| 42 | 35 | String classifier = useShaded ? "-shaded" : ""; |
| 43 | - return bundle("reference:file:" + PathUtils.getBaseDir() + "/../../driver-core/target/cassandra-driver-core-" + projectVersion() + classifier + ".jar"); | |
| 36 | + return bundle("reference:file:" + PathUtils.getBaseDir() + "/../../driver-core/target/cassandra-driver-core-" + projectVersion() + classifier + ".jar"); | |
| 44 | 37 | } |
| 45 | 38 | |
| 46 | 39 | public static MavenArtifactProvisionOption guavaBundle() { |
| @@ -51,13 +44,14 @@ | ||
| 51 | 44 | final String nettyVersion = "4.0.33.Final"; |
| 52 | 45 | return new CompositeOption() { |
| 53 | 46 | |
| 54 | - @Override public Option[] getOptions() { | |
| 47 | + @Override | |
| 48 | + public Option[] getOptions() { | |
| 55 | 49 | return options( |
| 56 | - mavenBundle("io.netty", "netty-buffer", nettyVersion), | |
| 57 | - mavenBundle("io.netty", "netty-codec", nettyVersion), | |
| 58 | - mavenBundle("io.netty", "netty-common", nettyVersion), | |
| 59 | - mavenBundle("io.netty", "netty-handler", nettyVersion), | |
| 60 | - mavenBundle("io.netty", "netty-transport", nettyVersion) | |
| 50 | + mavenBundle("io.netty", "netty-buffer", nettyVersion), | |
| 51 | + mavenBundle("io.netty", "netty-codec", nettyVersion), | |
| 52 | + mavenBundle("io.netty", "netty-common", nettyVersion), | |
| 53 | + mavenBundle("io.netty", "netty-handler", nettyVersion), | |
| 54 | + mavenBundle("io.netty", "netty-transport", nettyVersion) | |
| 61 | 55 | ); |
| 62 | 56 | } |
| 63 | 57 | }; |
| @@ -70,19 +64,20 @@ | ||
| 70 | 64 | public static CompositeOption defaultOptions() { |
| 71 | 65 | return new CompositeOption() { |
| 72 | 66 | |
| 73 | - @Override public Option[] getOptions() { | |
| 67 | + @Override | |
| 68 | + public Option[] getOptions() { | |
| 74 | 69 | return options( |
| 75 | - // Delegate javax.security.cert to the parent classloader. javax.security.cert.X509Certificate is used in | |
| 76 | - // io.netty.util.internal.EmptyArrays, but not directly by the driver. | |
| 77 | - bootDelegationPackage("javax.security.cert"), | |
| 78 | - systemProperty("cassandra.contactpoints").value(CCMBridge.IP_PREFIX + 1), | |
| 79 | - systemProperty("logback.configurationFile").value("file:" + PathUtils.getBaseDir() + "/src/test/resources/logback.xml"), | |
| 80 | - mavenBundle("org.slf4j", "slf4j-api", "1.7.5"), | |
| 81 | - mavenBundle("ch.qos.logback", "logback-classic", "1.1.3"), | |
| 82 | - mavenBundle("ch.qos.logback", "logback-core", "1.1.3"), | |
| 83 | - mavenBundle("io.dropwizard.metrics", "metrics-core", "3.1.2"), | |
| 84 | - systemPackages("org.testng", "org.junit", "org.junit.runner", "org.junit.runner.manipulation", | |
| 85 | - "org.junit.runner.notification", "com.jcabi.manifests") | |
| 70 | + // Delegate javax.security.cert to the parent classloader. javax.security.cert.X509Certificate is used in | |
| 71 | + // io.netty.util.internal.EmptyArrays, but not directly by the driver. | |
| 72 | + bootDelegationPackage("javax.security.cert"), | |
| 73 | + systemProperty("cassandra.contactpoints").value(CCMBridge.IP_PREFIX + 1), | |
| 74 | + systemProperty("logback.configurationFile").value("file:" + PathUtils.getBaseDir() + "/src/test/resources/logback.xml"), | |
| 75 | + mavenBundle("org.slf4j", "slf4j-api", "1.7.5"), | |
| 76 | + mavenBundle("ch.qos.logback", "logback-classic", "1.1.3"), | |
| 77 | + mavenBundle("ch.qos.logback", "logback-core", "1.1.3"), | |
| 78 | + mavenBundle("io.dropwizard.metrics", "metrics-core", "3.1.2"), | |
| 79 | + systemPackages("org.testng", "org.junit", "org.junit.runner", "org.junit.runner.manipulation", | |
| 80 | + "org.junit.runner.notification", "com.jcabi.manifests") | |
| 86 | 81 | ); |
| 87 | 82 | } |
| 88 | 83 | }; |
modified driver-examples/osgi/src/test/java/com/datastax/driver/osgi/CCMBridgeListener.java +22 −11
| @@ -15,16 +15,15 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.osgi; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.CCMBridge; | |
| 18 | 19 | import org.testng.ITestContext; |
| 19 | 20 | import org.testng.ITestListener; |
| 20 | 21 | import org.testng.ITestResult; |
| 21 | 22 | |
| 22 | -import com.datastax.driver.core.CCMBridge; | |
| 23 | - | |
| 24 | 23 | /** |
| 25 | 24 | * A listener that fires up a single node CCM instance on test class start and tears it |
| 26 | 25 | * down on test class end. |
| 27 | - * | |
| 26 | + * <p/> | |
| 28 | 27 | * This is needed for tests that use Pax-Exam since it runs some methods in the OSGi container |
| 29 | 28 | * which we do not want. |
| 30 | 29 | */ |
| @@ -32,23 +31,35 @@ | ||
| 32 | 31 | |
| 33 | 32 | private CCMBridge ccm; |
| 34 | 33 | |
| 35 | - @Override public void onStart(ITestContext context) { | |
| 34 | + @Override | |
| 35 | + public void onStart(ITestContext context) { | |
| 36 | 36 | ccm = CCMBridge.builder("test").withNodes(1).build(); |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | - @Override public void onFinish(ITestContext context) { | |
| 40 | - if(ccm != null) { | |
| 39 | + @Override | |
| 40 | + public void onFinish(ITestContext context) { | |
| 41 | + if (ccm != null) { | |
| 41 | 42 | ccm.remove(); |
| 42 | 43 | } |
| 43 | 44 | } |
| 44 | 45 | |
| 45 | - @Override public void onTestStart(ITestResult result) {} | |
| 46 | + @Override | |
| 47 | + public void onTestStart(ITestResult result) { | |
| 48 | + } | |
| 46 | 49 | |
| 47 | - @Override public void onTestSuccess(ITestResult result) {} | |
| 50 | + @Override | |
| 51 | + public void onTestSuccess(ITestResult result) { | |
| 52 | + } | |
| 48 | 53 | |
| 49 | - @Override public void onTestFailure(ITestResult result) {} | |
| 54 | + @Override | |
| 55 | + public void onTestFailure(ITestResult result) { | |
| 56 | + } | |
| 50 | 57 | |
| 51 | - @Override public void onTestSkipped(ITestResult result) {} | |
| 58 | + @Override | |
| 59 | + public void onTestSkipped(ITestResult result) { | |
| 60 | + } | |
| 52 | 61 | |
| 53 | - @Override public void onTestFailedButWithinSuccessPercentage(ITestResult result) {} | |
| 62 | + @Override | |
| 63 | + public void onTestFailedButWithinSuccessPercentage(ITestResult result) { | |
| 64 | + } | |
| 54 | 65 | } |
modified driver-examples/osgi/src/test/java/com/datastax/driver/osgi/GuavaSanityCheckNegativeIT.java +21 −27
| @@ -15,54 +15,49 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.osgi; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.Cluster; | |
| 18 | 19 | import org.ops4j.pax.exam.Configuration; |
| 19 | 20 | import org.ops4j.pax.exam.Option; |
| 20 | 21 | import org.ops4j.pax.exam.testng.listener.PaxExam; |
| 21 | 22 | import org.testng.annotations.Listeners; |
| 22 | 23 | import org.testng.annotations.Test; |
| 23 | 24 | |
| 25 | +import static com.datastax.driver.osgi.BundleOptions.*; | |
| 24 | 26 | import static org.ops4j.pax.exam.CoreOptions.options; |
| 25 | 27 | import static org.testng.Assert.assertTrue; |
| 26 | 28 | import static org.testng.Assert.fail; |
| 27 | 29 | |
| 28 | -import com.datastax.driver.core.Cluster; | |
| 29 | - | |
| 30 | -import static com.datastax.driver.osgi.BundleOptions.defaultOptions; | |
| 31 | -import static com.datastax.driver.osgi.BundleOptions.driverBundle; | |
| 32 | -import static com.datastax.driver.osgi.BundleOptions.guavaBundle; | |
| 33 | -import static com.datastax.driver.osgi.BundleOptions.nettyBundles; | |
| 34 | - | |
| 35 | 30 | @Listeners({PaxExam.class}) |
| 36 | -@Test(groups="short") | |
| 31 | +@Test(groups = "short") | |
| 37 | 32 | public class GuavaSanityCheckNegativeIT { |
| 38 | 33 | |
| 39 | 34 | @Configuration |
| 40 | 35 | public Option[] guava14_0_1Config() { |
| 41 | 36 | return options( |
| 42 | - driverBundle(), | |
| 43 | - nettyBundles(), | |
| 44 | - guavaBundle().version("14.0.1"), | |
| 45 | - defaultOptions() | |
| 37 | + driverBundle(), | |
| 38 | + nettyBundles(), | |
| 39 | + guavaBundle().version("14.0.1"), | |
| 40 | + defaultOptions() | |
| 46 | 41 | ); |
| 47 | 42 | } |
| 48 | 43 | |
| 49 | 44 | @Configuration |
| 50 | 45 | public Option[] guava15Config() { |
| 51 | 46 | return options( |
| 52 | - driverBundle(), | |
| 53 | - nettyBundles(), | |
| 54 | - guavaBundle().version("15.0"), | |
| 55 | - defaultOptions() | |
| 47 | + driverBundle(), | |
| 48 | + nettyBundles(), | |
| 49 | + guavaBundle().version("15.0"), | |
| 50 | + defaultOptions() | |
| 56 | 51 | ); |
| 57 | 52 | } |
| 58 | 53 | |
| 59 | 54 | @Configuration |
| 60 | 55 | public Option[] guava16Config() { |
| 61 | 56 | return options( |
| 62 | - driverBundle(), | |
| 63 | - nettyBundles(), | |
| 64 | - guavaBundle().version("16.0"), | |
| 65 | - defaultOptions() | |
| 57 | + driverBundle(), | |
| 58 | + nettyBundles(), | |
| 59 | + guavaBundle().version("16.0"), | |
| 60 | + defaultOptions() | |
| 66 | 61 | ); |
| 67 | 62 | } |
| 68 | 63 | |
| @@ -73,12 +68,12 @@ | ||
| 73 | 68 | * is raised as the cause of an {@link ExceptionInInitializerError} since the failure |
| 74 | 69 | * occurs at static initialization. |
| 75 | 70 | * </p> |
| 76 | - * | |
| 71 | + * <p/> | |
| 77 | 72 | * The following configurations are tried (defined via methods with the @Configuration annotation): |
| 78 | 73 | * <ol> |
| 79 | - * <li>With Guava 14.0.1</li> | |
| 80 | - * <li>With Guava 15.0</li> | |
| 81 | - * <li>With Guava 16.0</li> | |
| 74 | + * <li>With Guava 14.0.1</li> | |
| 75 | + * <li>With Guava 15.0</li> | |
| 76 | + * <li>With Guava 16.0</li> | |
| 82 | 77 | * </ol> |
| 83 | 78 | * |
| 84 | 79 | * @test_category packaging |
| @@ -90,11 +85,10 @@ | ||
| 90 | 85 | try { |
| 91 | 86 | Cluster.builder(); |
| 92 | 87 | fail("Expected an IllegalStateException for Guava version incompatibility"); |
| 93 | - } | |
| 94 | - catch(ExceptionInInitializerError e) { | |
| 88 | + } catch (ExceptionInInitializerError e) { | |
| 95 | 89 | try { |
| 96 | 90 | throw e.getCause(); |
| 97 | - } catch(IllegalStateException ise) { | |
| 91 | + } catch (IllegalStateException ise) { | |
| 98 | 92 | assertTrue(ise.getMessage().contains("Detected Guava issue #1635")); |
| 99 | 93 | } |
| 100 | 94 | } |
modified driver-examples/osgi/src/test/java/com/datastax/driver/osgi/MailboxServiceIT.java +37 −38
| @@ -15,71 +15,70 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.osgi; |
| 17 | 17 | |
| 18 | -import java.util.ArrayList; | |
| 19 | -import java.util.Collection; | |
| 20 | -import java.util.GregorianCalendar; | |
| 21 | - | |
| 22 | -import javax.inject.Inject; | |
| 18 | +import com.datastax.driver.osgi.api.MailboxException; | |
| 19 | +import com.datastax.driver.osgi.api.MailboxMessage; | |
| 20 | +import com.datastax.driver.osgi.api.MailboxService; | |
| 23 | 21 | import org.ops4j.pax.exam.Configuration; |
| 24 | 22 | import org.ops4j.pax.exam.Option; |
| 25 | 23 | import org.ops4j.pax.exam.testng.listener.PaxExam; |
| 26 | 24 | import org.testng.annotations.Listeners; |
| 27 | 25 | import org.testng.annotations.Test; |
| 28 | 26 | |
| 29 | -import static org.ops4j.pax.exam.CoreOptions.options; | |
| 30 | -import static org.testng.Assert.assertEquals; | |
| 31 | - | |
| 32 | -import com.datastax.driver.osgi.api.MailboxException; | |
| 33 | -import com.datastax.driver.osgi.api.MailboxMessage; | |
| 34 | -import com.datastax.driver.osgi.api.MailboxService; | |
| 27 | +import javax.inject.Inject; | |
| 28 | +import java.util.ArrayList; | |
| 29 | +import java.util.Collection; | |
| 30 | +import java.util.GregorianCalendar; | |
| 35 | 31 | |
| 36 | 32 | import static com.datastax.driver.osgi.BundleOptions.*; |
| 33 | +import static org.ops4j.pax.exam.CoreOptions.options; | |
| 34 | +import static org.testng.Assert.assertEquals; | |
| 37 | 35 | |
| 38 | 36 | @Listeners({CCMBridgeListener.class, PaxExam.class}) |
| 39 | -@Test(groups="short") | |
| 37 | +@Test(groups = "short") | |
| 40 | 38 | public class MailboxServiceIT { |
| 41 | - @Inject MailboxService service; | |
| 39 | + @Inject | |
| 40 | + MailboxService service; | |
| 42 | 41 | |
| 43 | 42 | @Configuration |
| 44 | 43 | public Option[] shadedConfig() { |
| 45 | 44 | return options( |
| 46 | - driverBundle(true), | |
| 47 | - mailboxBundle(), | |
| 48 | - guavaBundle(), | |
| 49 | - defaultOptions() | |
| 45 | + driverBundle(true), | |
| 46 | + mailboxBundle(), | |
| 47 | + guavaBundle(), | |
| 48 | + defaultOptions() | |
| 50 | 49 | ); |
| 51 | 50 | } |
| 52 | 51 | |
| 53 | 52 | @Configuration |
| 54 | 53 | public Option[] defaultConfig() { |
| 55 | 54 | return options( |
| 56 | - driverBundle(), | |
| 57 | - mailboxBundle(), | |
| 58 | - guavaBundle(), | |
| 59 | - nettyBundles(), | |
| 60 | - defaultOptions() | |
| 55 | + driverBundle(), | |
| 56 | + mailboxBundle(), | |
| 57 | + guavaBundle(), | |
| 58 | + nettyBundles(), | |
| 59 | + defaultOptions() | |
| 61 | 60 | ); |
| 62 | 61 | } |
| 63 | 62 | |
| 64 | 63 | @Configuration |
| 65 | 64 | public Option[] guava17Config() { |
| 66 | 65 | return options( |
| 67 | - driverBundle(), | |
| 68 | - mailboxBundle(), | |
| 69 | - nettyBundles(), | |
| 70 | - guavaBundle().version("17.0"), | |
| 71 | - defaultOptions() | |
| 66 | + driverBundle(), | |
| 67 | + mailboxBundle(), | |
| 68 | + nettyBundles(), | |
| 69 | + guavaBundle().version("17.0"), | |
| 70 | + defaultOptions() | |
| 72 | 71 | ); |
| 73 | 72 | } |
| 74 | 73 | |
| 75 | 74 | @Configuration |
| 76 | 75 | public Option[] guava18Config() { |
| 77 | 76 | return options( |
| 78 | - driverBundle(), | |
| 79 | - mailboxBundle(), | |
| 80 | - nettyBundles(), | |
| 81 | - guavaBundle().version("18.0"), | |
| 82 | - defaultOptions() | |
| 77 | + driverBundle(), | |
| 78 | + mailboxBundle(), | |
| 79 | + nettyBundles(), | |
| 80 | + guavaBundle().version("18.0"), | |
| 81 | + defaultOptions() | |
| 83 | 82 | ); |
| 84 | 83 | } |
| 85 | 84 | |
| @@ -88,14 +87,14 @@ | ||
| 88 | 87 | * Exercises a 'mailbox' service provided by an OSGi bundle that depends on the driver. Ensures that |
| 89 | 88 | * queries can be made through the service with the current given configuration. |
| 90 | 89 | * </p> |
| 91 | - * | |
| 90 | + * <p/> | |
| 92 | 91 | * The following configurations are tried (defined via methods with the @Configuration annotation): |
| 93 | 92 | * <ol> |
| 94 | - * <li>Default bundle (Driver with all of it's dependencies)</li> | |
| 95 | - * <li>Shaded bundle (Driver with netty shaded)</li> | |
| 96 | - * <li>With Guava 16.0.1</li> | |
| 97 | - * <li>With Guava 17</li> | |
| 98 | - * <li>With Guava 18</li> | |
| 93 | + * <li>Default bundle (Driver with all of it's dependencies)</li> | |
| 94 | + * <li>Shaded bundle (Driver with netty shaded)</li> | |
| 95 | + * <li>With Guava 16.0.1</li> | |
| 96 | + * <li>With Guava 17</li> | |
| 97 | + * <li>With Guava 18</li> | |
| 99 | 98 | * </ol> |
| 100 | 99 | * |
| 101 | 100 | * @test_category packaging |
modified driver-examples/osgi/src/test/java/com/datastax/driver/osgi/VersionProvider.java +5 −4
| @@ -15,15 +15,15 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.osgi; |
| 17 | 17 | |
| 18 | +import com.jcabi.manifests.Manifests; | |
| 19 | + | |
| 18 | 20 | import java.util.regex.Matcher; |
| 19 | 21 | import java.util.regex.Pattern; |
| 20 | 22 | |
| 21 | -import com.jcabi.manifests.Manifests; | |
| 22 | - | |
| 23 | 23 | /** |
| 24 | 24 | * Attempts to resolve the project version from the Bundle manifest. If not present, will throw RuntimeException |
| 25 | 25 | * on initialization. If this happens, try building with 'mvn compile' to generate the Bundle manifest. |
| 26 | - * | |
| 26 | + * <p/> | |
| 27 | 27 | * In IntelliJ you can have compile run after make by right clicking on 'compile' in the 'Maven Projects' tool window. |
| 28 | 28 | */ |
| 29 | 29 | public class VersionProvider { |
| @@ -31,12 +31,13 @@ | ||
| 31 | 31 | private static final Pattern versionPattern = Pattern.compile(("(\\d+.\\d+\\.\\d+)(.*)")); |
| 32 | 32 | |
| 33 | 33 | private static final String PROJECT_VERSION; |
| 34 | + | |
| 34 | 35 | static { |
| 35 | 36 | String bundleName = Manifests.read("Bundle-SymbolicName"); |
| 36 | 37 | if (bundleName.equals("com.datastax.driver.osgi")) { |
| 37 | 38 | String bundleVersion = Manifests.read("Bundle-Version"); |
| 38 | 39 | Matcher matcher = versionPattern.matcher(bundleVersion); |
| 39 | - if(matcher.matches()) { | |
| 40 | + if (matcher.matches()) { | |
| 40 | 41 | String majorVersion = matcher.group(1); |
| 41 | 42 | // Replace all instances of '.' after the main version with '-' to properly |
| 42 | 43 | // resolve the correct version. |
modified driver-examples/stress/src/main/java/com/datastax/driver/stress/AsynchronousConsumer.java +6 −8
| @@ -15,17 +15,15 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.stress; |
| 17 | 17 | |
| 18 | -import java.util.Iterator; | |
| 19 | -import java.util.concurrent.CountDownLatch; | |
| 20 | -import java.util.concurrent.ExecutorService; | |
| 21 | -import java.util.concurrent.Executors; | |
| 22 | - | |
| 23 | -import com.google.common.util.concurrent.FutureCallback; | |
| 24 | -import com.google.common.util.concurrent.Futures; | |
| 25 | - | |
| 26 | 18 | import com.datastax.driver.core.ResultSet; |
| 27 | 19 | import com.datastax.driver.core.ResultSetFuture; |
| 28 | 20 | import com.datastax.driver.core.Session; |
| 21 | +import com.google.common.util.concurrent.FutureCallback; | |
| 22 | +import com.google.common.util.concurrent.Futures; | |
| 23 | + | |
| 24 | +import java.util.concurrent.CountDownLatch; | |
| 25 | +import java.util.concurrent.ExecutorService; | |
| 26 | +import java.util.concurrent.Executors; | |
| 29 | 27 | |
| 30 | 28 | import static com.google.common.util.concurrent.Uninterruptibles.awaitUninterruptibly; |
| 31 | 29 |
modified driver-examples/stress/src/main/java/com/datastax/driver/stress/BlockingConsumer.java +1 −4
| @@ -15,12 +15,9 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.stress; |
| 17 | 17 | |
| 18 | -import java.util.Iterator; | |
| 19 | - | |
| 20 | -import com.google.common.util.concurrent.Uninterruptibles; | |
| 21 | - | |
| 22 | 18 | import com.datastax.driver.core.Session; |
| 23 | 19 | import com.datastax.driver.core.exceptions.DriverException; |
| 20 | +import com.google.common.util.concurrent.Uninterruptibles; | |
| 24 | 21 | |
| 25 | 22 | public class BlockingConsumer implements Consumer { |
| 26 | 23 |
modified driver-examples/stress/src/main/java/com/datastax/driver/stress/Consumer.java +1 −0
| @@ -18,5 +18,6 @@ | ||
| 18 | 18 | public interface Consumer { |
| 19 | 19 | |
| 20 | 20 | public void start(); |
| 21 | + | |
| 21 | 22 | public void join(); |
| 22 | 23 | } |
modified driver-examples/stress/src/main/java/com/datastax/driver/stress/Generators.java +14 −15
| @@ -15,16 +15,15 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.stress; |
| 17 | 17 | |
| 18 | -import java.nio.ByteBuffer; | |
| 19 | -import java.util.Random; | |
| 20 | - | |
| 21 | 18 | import com.datastax.driver.core.*; |
| 22 | -import com.datastax.driver.core.exceptions.*; | |
| 19 | +import com.datastax.driver.core.exceptions.QueryValidationException; | |
| 23 | 20 | import com.datastax.driver.core.utils.Bytes; |
| 24 | - | |
| 25 | 21 | import joptsimple.OptionParser; |
| 26 | 22 | import joptsimple.OptionSet; |
| 27 | 23 | |
| 24 | +import java.nio.ByteBuffer; | |
| 25 | +import java.util.Random; | |
| 26 | + | |
| 28 | 27 | public class Generators { |
| 29 | 28 | private static ThreadLocal<Random> random = new ThreadLocal<Random>() { |
| 30 | 29 | protected Random initialValue() { |
| @@ -69,7 +68,7 @@ | ||
| 69 | 68 | |
| 70 | 69 | public OptionParser addOptions(OptionParser parser) { |
| 71 | 70 | String msg = "Simple insertion of CQL3 rows (using prepared statements unless the --no-prepare option is used). " |
| 72 | - + "The inserted rows have a fixed set of columns but no clustering columns."; | |
| 71 | + + "The inserted rows have a fixed set of columns but no clustering columns."; | |
| 73 | 72 | parser.formatHelpWith(Stress.Help.formatFor(name(), msg)); |
| 74 | 73 | |
| 75 | 74 | parser.accepts("no-prepare", "Do no use prepared statement"); |
| @@ -91,7 +90,7 @@ | ||
| 91 | 90 | |
| 92 | 91 | StringBuilder sb = new StringBuilder(); |
| 93 | 92 | sb.append("CREATE TABLE standard1 (key bigint PRIMARY KEY"); |
| 94 | - for (int i = 0; i < (Integer)options.valueOf("columns-per-row"); ++i) | |
| 93 | + for (int i = 0; i < (Integer) options.valueOf("columns-per-row"); ++i) | |
| 95 | 94 | sb.append(", C").append(i).append(" blob"); |
| 96 | 95 | sb.append(')'); |
| 97 | 96 | |
| @@ -104,13 +103,13 @@ | ||
| 104 | 103 | public QueryGenerator create(int id, int iterations, OptionSet options, Session session) { |
| 105 | 104 | |
| 106 | 105 | return options.has("no-prepare") |
| 107 | - ? createRegular(id, iterations, options, session) | |
| 108 | - : createPrepared(id, iterations, options, session); | |
| 106 | + ? createRegular(id, iterations, options, session) | |
| 107 | + : createPrepared(id, iterations, options, session); | |
| 109 | 108 | } |
| 110 | 109 | |
| 111 | 110 | public QueryGenerator createRegular(int id, int iterations, OptionSet options, final Session session) { |
| 112 | - final int valueSize = (Integer)options.valueOf("value-size"); | |
| 113 | - final int columnsPerRow = (Integer)options.valueOf("columns-per-row"); | |
| 111 | + final int valueSize = (Integer) options.valueOf("value-size"); | |
| 112 | + final int columnsPerRow = (Integer) options.valueOf("columns-per-row"); | |
| 114 | 113 | final long prefix = (long) id << 32; |
| 115 | 114 | |
| 116 | 115 | return new AbstractGenerator(iterations) { |
| @@ -130,8 +129,8 @@ | ||
| 130 | 129 | } |
| 131 | 130 | |
| 132 | 131 | public QueryGenerator createPrepared(int id, int iterations, OptionSet options, Session session) { |
| 133 | - final int valueSize = (Integer)options.valueOf("value-size"); | |
| 134 | - final int columnsPerRow = (Integer)options.valueOf("columns-per-row"); | |
| 132 | + final int valueSize = (Integer) options.valueOf("value-size"); | |
| 133 | + final int columnsPerRow = (Integer) options.valueOf("columns-per-row"); | |
| 135 | 134 | final long prefix = (long) id << 32; |
| 136 | 135 | |
| 137 | 136 | StringBuilder sb = new StringBuilder(); |
| @@ -184,8 +183,8 @@ | ||
| 184 | 183 | |
| 185 | 184 | public QueryGenerator create(int id, int iterations, OptionSet options, Session session) { |
| 186 | 185 | return options.has("no-prepare") |
| 187 | - ? createRegular(id, iterations, session) | |
| 188 | - : createPrepared(id, iterations, session); | |
| 186 | + ? createRegular(id, iterations, session) | |
| 187 | + : createPrepared(id, iterations, session); | |
| 189 | 188 | } |
| 190 | 189 | |
| 191 | 190 | public QueryGenerator createRegular(long id, int iterations, final Session session) { |
modified driver-examples/stress/src/main/java/com/datastax/driver/stress/QueryGenerator.java +5 −3
| @@ -15,13 +15,12 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.stress; |
| 17 | 17 | |
| 18 | -import java.util.Iterator; | |
| 19 | - | |
| 20 | 18 | import com.datastax.driver.core.*; |
| 21 | - | |
| 22 | 19 | import joptsimple.OptionParser; |
| 23 | 20 | import joptsimple.OptionSet; |
| 24 | 21 | |
| 22 | +import java.util.Iterator; | |
| 23 | + | |
| 25 | 24 | public abstract class QueryGenerator implements Iterator<QueryGenerator.Request> { |
| 26 | 25 | |
| 27 | 26 | protected final int iterations; |
| @@ -38,8 +37,11 @@ | ||
| 38 | 37 | |
| 39 | 38 | public interface Builder { |
| 40 | 39 | public String name(); |
| 40 | + | |
| 41 | 41 | public OptionParser addOptions(OptionParser parser); |
| 42 | + | |
| 42 | 43 | public void prepare(OptionSet options, Session session); |
| 44 | + | |
| 43 | 45 | public QueryGenerator create(int id, int iterations, OptionSet options, Session session); |
| 44 | 46 | } |
| 45 | 47 |
modified driver-examples/stress/src/main/java/com/datastax/driver/stress/Reporter.java +23 −17
| @@ -15,15 +15,21 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.stress; |
| 17 | 17 | |
| 18 | -import java.io.*; | |
| 19 | -import java.util.concurrent.*; | |
| 20 | -import java.util.concurrent.atomic.AtomicInteger; | |
| 21 | - | |
| 22 | 18 | import com.yammer.metrics.Metrics; |
| 23 | -import com.yammer.metrics.core.*; | |
| 24 | -import com.yammer.metrics.reporting.*; | |
| 19 | +import com.yammer.metrics.core.Meter; | |
| 20 | +import com.yammer.metrics.core.Timer; | |
| 21 | +import com.yammer.metrics.core.TimerContext; | |
| 25 | 22 | import com.yammer.metrics.stats.Snapshot; |
| 26 | 23 | |
| 24 | +import java.io.File; | |
| 25 | +import java.io.FileOutputStream; | |
| 26 | +import java.io.IOException; | |
| 27 | +import java.io.PrintStream; | |
| 28 | +import java.util.concurrent.Executors; | |
| 29 | +import java.util.concurrent.ScheduledExecutorService; | |
| 30 | +import java.util.concurrent.TimeUnit; | |
| 31 | +import java.util.concurrent.atomic.AtomicInteger; | |
| 32 | + | |
| 27 | 33 | public class Reporter implements Runnable { |
| 28 | 34 | |
| 29 | 35 | private Meter requests; |
| @@ -67,8 +73,8 @@ | ||
| 67 | 73 | this.iterations = iterations; |
| 68 | 74 | |
| 69 | 75 | // Middle = exclude first and last 10% (note: if requests is -1, we'll end up with negative bounds, which will always exclude. It's fine if we never stop anyway) |
| 70 | - this.middleLowBound = (int)(0.1 * iterations); | |
| 71 | - this.middleHighBound = (int)(0.9 * iterations); | |
| 76 | + this.middleLowBound = (int) (0.1 * iterations); | |
| 77 | + this.middleHighBound = (int) (0.9 * iterations); | |
| 72 | 78 | } |
| 73 | 79 | |
| 74 | 80 | private static String formatHeader(String[] args) { |
| @@ -162,14 +168,14 @@ | ||
| 162 | 168 | |
| 163 | 169 | private void reportToCSV(Report report) { |
| 164 | 170 | csv.println(new StringBuilder() |
| 165 | - .append(report.elapsed).append(',') | |
| 166 | - .append(report.totalOps).append(',') | |
| 167 | - .append(report.intervalRate).append(',') | |
| 168 | - .append(report.meanRate).append(',') | |
| 169 | - .append(report.meanLatency).append(',') | |
| 170 | - .append(report.latency95th).append(',') | |
| 171 | - .append(report.latency99th).append(',') | |
| 172 | - .append(report.stdDev)); | |
| 171 | + .append(report.elapsed).append(',') | |
| 172 | + .append(report.totalOps).append(',') | |
| 173 | + .append(report.intervalRate).append(',') | |
| 174 | + .append(report.meanRate).append(',') | |
| 175 | + .append(report.meanLatency).append(',') | |
| 176 | + .append(report.latency95th).append(',') | |
| 177 | + .append(report.latency99th).append(',') | |
| 178 | + .append(report.stdDev)); | |
| 173 | 179 | } |
| 174 | 180 | |
| 175 | 181 | private void stopCSV(Report lastReport) { |
| @@ -197,7 +203,7 @@ | ||
| 197 | 203 | |
| 198 | 204 | private void printReportToConsole(Report report) { |
| 199 | 205 | long delay = report.timestamp - lastConsoleTimestamp; |
| 200 | - double intervalRate = (((double)(report.totalOps - lastConsoleOpCount)) / delay) * 1000; | |
| 206 | + double intervalRate = (((double) (report.totalOps - lastConsoleOpCount)) / delay) * 1000; | |
| 201 | 207 | |
| 202 | 208 | String msg = String.format(" %8d | %12d | %13.2f | %12.2f | %17.3f | %17.3f | %17.3f | %9.3f", |
| 203 | 209 | report.elapsed, report.totalOps, intervalRate, report.meanRate, report.meanLatency, report.latency95th, report.latency99th, report.stdDev); |
modified driver-examples/stress/src/main/java/com/datastax/driver/stress/Stress.java +27 −26
| @@ -15,32 +15,33 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.stress; |
| 17 | 17 | |
| 18 | -import java.io.IOException; | |
| 19 | -import java.util.*; | |
| 20 | - | |
| 21 | 18 | import com.datastax.driver.core.*; |
| 22 | -import com.datastax.driver.core.exceptions.*; | |
| 23 | - | |
| 19 | +import com.datastax.driver.core.exceptions.NoHostAvailableException; | |
| 20 | +import joptsimple.*; | |
| 24 | 21 | import org.apache.log4j.PropertyConfigurator; |
| 25 | 22 | |
| 26 | -import joptsimple.*; | |
| 23 | +import java.io.IOException; | |
| 24 | +import java.util.HashMap; | |
| 25 | +import java.util.List; | |
| 26 | +import java.util.Map; | |
| 27 | 27 | |
| 28 | 28 | /** |
| 29 | 29 | * A simple stress tool to demonstrate the use of the driver. |
| 30 | - * | |
| 30 | + * <p/> | |
| 31 | 31 | * Sample usage: |
| 32 | - * stress insert -n 100000 | |
| 33 | - * stress read -n 10000 | |
| 32 | + * stress insert -n 100000 | |
| 33 | + * stress read -n 10000 | |
| 34 | 34 | */ |
| 35 | 35 | public class Stress { |
| 36 | 36 | |
| 37 | 37 | private static final Map<String, QueryGenerator.Builder> generators = new HashMap<String, QueryGenerator.Builder>(); |
| 38 | + | |
| 38 | 39 | static { |
| 39 | 40 | PropertyConfigurator.configure(System.getProperty("log4j.configuration", "./conf/log4j.properties")); |
| 40 | 41 | |
| 41 | - QueryGenerator.Builder[] gs = new QueryGenerator.Builder[] { | |
| 42 | - Generators.INSERTER, | |
| 43 | - Generators.READER | |
| 42 | + QueryGenerator.Builder[] gs = new QueryGenerator.Builder[]{ | |
| 43 | + Generators.INSERTER, | |
| 44 | + Generators.READER | |
| 44 | 45 | }; |
| 45 | 46 | |
| 46 | 47 | for (QueryGenerator.Builder b : gs) |
| @@ -60,7 +61,7 @@ | ||
| 60 | 61 | accepts("connections-per-host", "The number of connections per hosts (default: based on the number of threads)").withRequiredArg().ofType(Integer.class); |
| 61 | 62 | }}; |
| 62 | 63 | String msg = "Where <generator> can be one of " + generators.keySet() + '\n' |
| 63 | - + "You can get more help on a particular generator with: stress <generator> -h"; | |
| 64 | + + "You can get more help on a particular generator with: stress <generator> -h"; | |
| 64 | 65 | parser.formatHelpWith(Help.formatFor("<generator>", msg)); |
| 65 | 66 | return parser; |
| 66 | 67 | } |
| @@ -175,7 +176,7 @@ | ||
| 175 | 176 | public static Help formatFor(String generator, String header) { |
| 176 | 177 | // It's a pain in the ass to get the real console width in JAVA so hardcode it. But it's the 21th |
| 177 | 178 | // century, we're not stuck at 80 characters anymore. |
| 178 | - int width = 120; | |
| 179 | + int width = 120; | |
| 179 | 180 | return new Help(new BuiltinHelpFormatter(width, 4), generator, header); |
| 180 | 181 | } |
| 181 | 182 | |
| @@ -195,19 +196,19 @@ | ||
| 195 | 196 | Stresser stresser = Stresser.forCommandLineArguments(args); |
| 196 | 197 | OptionSet options = stresser.getOptions(); |
| 197 | 198 | |
| 198 | - int requests = options.has("n") ? (Integer)options.valueOf("n") : -1; | |
| 199 | - int concurrency = (Integer)options.valueOf("t"); | |
| 199 | + int requests = options.has("n") ? (Integer) options.valueOf("n") : -1; | |
| 200 | + int concurrency = (Integer) options.valueOf("t"); | |
| 200 | 201 | |
| 201 | - String reportFileName = (String)options.valueOf("report-file"); | |
| 202 | + String reportFileName = (String) options.valueOf("report-file"); | |
| 202 | 203 | |
| 203 | 204 | boolean async = options.has("async"); |
| 204 | 205 | |
| 205 | - int iterations = (requests == -1 ? -1 : requests / concurrency); | |
| 206 | + int iterations = (requests == -1 ? -1 : requests / concurrency); | |
| 206 | 207 | |
| 207 | 208 | final int maxRequestsPerConnection = 128; |
| 208 | 209 | int maxConnections = options.has("connections-per-host") |
| 209 | - ? (Integer)options.valueOf("connections-per-host") | |
| 210 | - : concurrency / maxRequestsPerConnection + 1; | |
| 210 | + ? (Integer) options.valueOf("connections-per-host") | |
| 211 | + : concurrency / maxRequestsPerConnection + 1; | |
| 211 | 212 | |
| 212 | 213 | PoolingOptions pools = new PoolingOptions(); |
| 213 | 214 | pools.setNewConnectionThreshold(HostDistance.LOCAL, concurrency); |
| @@ -226,10 +227,10 @@ | ||
| 226 | 227 | try { |
| 227 | 228 | // Create session to hosts |
| 228 | 229 | Cluster cluster = new Cluster.Builder() |
| 229 | - .addContactPoints(String.valueOf(options.valueOf("ip"))) | |
| 230 | - .withPoolingOptions(pools) | |
| 231 | - .withSocketOptions(new SocketOptions().setTcpNoDelay(true)) | |
| 232 | - .build(); | |
| 230 | + .addContactPoints(String.valueOf(options.valueOf("ip"))) | |
| 231 | + .withPoolingOptions(pools) | |
| 232 | + .withSocketOptions(new SocketOptions().setTcpNoDelay(true)) | |
| 233 | + .build(); | |
| 233 | 234 | |
| 234 | 235 | if (options.has("compression")) |
| 235 | 236 | cluster.getConfiguration().getProtocolOptions().setCompression(ProtocolOptions.Compression.SNAPPY); |
| @@ -242,13 +243,13 @@ | ||
| 242 | 243 | System.out.println("Preparing test..."); |
| 243 | 244 | stresser.prepare(session); |
| 244 | 245 | |
| 245 | - Reporter reporter = new Reporter((Integer)options.valueOf("print-delay"), reportFileName, args, requests); | |
| 246 | + Reporter reporter = new Reporter((Integer) options.valueOf("print-delay"), reportFileName, args, requests); | |
| 246 | 247 | |
| 247 | 248 | Consumer[] consumers = new Consumer[concurrency]; |
| 248 | 249 | for (int i = 0; i < concurrency; i++) { |
| 249 | 250 | QueryGenerator generator = stresser.newGenerator(i, session, iterations); |
| 250 | 251 | consumers[i] = async ? new AsynchronousConsumer(session, generator, reporter) : |
| 251 | - new BlockingConsumer(session, generator, reporter); | |
| 252 | + new BlockingConsumer(session, generator, reporter); | |
| 252 | 253 | } |
| 253 | 254 | |
| 254 | 255 | System.out.println("Starting to stress test..."); |
modified driver-extras/src/main/java/com/datastax/driver/extras/codecs/MappingCodec.java +5 −6
| @@ -15,26 +15,25 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.extras.codecs; |
| 17 | 17 | |
| 18 | -import java.nio.ByteBuffer; | |
| 19 | - | |
| 20 | -import com.google.common.reflect.TypeToken; | |
| 21 | - | |
| 22 | 18 | import com.datastax.driver.core.ProtocolVersion; |
| 23 | 19 | import com.datastax.driver.core.TypeCodec; |
| 24 | 20 | import com.datastax.driver.core.exceptions.InvalidTypeException; |
| 21 | +import com.google.common.reflect.TypeToken; | |
| 22 | + | |
| 23 | +import java.nio.ByteBuffer; | |
| 25 | 24 | |
| 26 | 25 | /** |
| 27 | 26 | * An abstract {@link TypeCodec} that maps a Java Pojo to another Java object |
| 28 | 27 | * that can in turn be serialized into a CQL type. |
| 29 | 28 | * This can serve as a base for libraries dealing with Pojo mappings. |
| 30 | - * <p> | |
| 29 | + * <p/> | |
| 31 | 30 | * This codec can be seen as a convenience base class for libraries |
| 32 | 31 | * dealing with Pojo-to-Pojo mappings, but it comes |
| 33 | 32 | * with a performance penalty: each Java object is serialized |
| 34 | 33 | * in two steps: first to an intermediate object, and then to a {@link ByteBuffer}, |
| 35 | 34 | * which means that each serialization actually incurs in two potentially |
| 36 | 35 | * expensive operations being carried. |
| 37 | - * <p> | |
| 36 | + * <p/> | |
| 38 | 37 | * If such operations are really expensive, and your mapping library is capable |
| 39 | 38 | * of serializing objects directly to {@link ByteBuffer}s, |
| 40 | 39 | * consider writing your own codec instead of using this one. |
modified driver-extras/src/main/java/com/datastax/driver/extras/codecs/ParsingCodec.java +5 −6
| @@ -15,25 +15,24 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.extras.codecs; |
| 17 | 17 | |
| 18 | -import java.nio.ByteBuffer; | |
| 19 | - | |
| 20 | -import com.google.common.reflect.TypeToken; | |
| 21 | - | |
| 22 | 18 | import com.datastax.driver.core.ProtocolVersion; |
| 23 | 19 | import com.datastax.driver.core.TypeCodec; |
| 24 | 20 | import com.datastax.driver.core.exceptions.InvalidTypeException; |
| 21 | +import com.google.common.reflect.TypeToken; | |
| 22 | + | |
| 23 | +import java.nio.ByteBuffer; | |
| 25 | 24 | |
| 26 | 25 | /** |
| 27 | 26 | * An abstract {@link TypeCodec} that stores JAVA objects as serialized strings. |
| 28 | 27 | * This can serve as a base for codecs dealing with XML or JSON formats. |
| 29 | - * <p> | |
| 28 | + * <p/> | |
| 30 | 29 | * This codec can be seen as a convenience base class to help |
| 31 | 30 | * implementing Java-to-XML or Java-to-JSON mappings, but it comes |
| 32 | 31 | * with a performance penalty: each Java object is serialized |
| 33 | 32 | * in two steps: first to a String, and then to a {@link ByteBuffer}, |
| 34 | 33 | * which means that each serialization actually incurs in two potentially |
| 35 | 34 | * expensive operations being carried. |
| 36 | - * <p> | |
| 35 | + * <p/> | |
| 37 | 36 | * If you are using an XML or JSON library that supports writing Java objects |
| 38 | 37 | * directly to {@link ByteBuffer}s, consider writing your own codec instead of |
| 39 | 38 | * using this one. |
modified driver-extras/src/main/java/com/datastax/driver/extras/codecs/arrays/AbstractArrayCodec.java +8 −9
| @@ -15,16 +15,15 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.extras.codecs.arrays; |
| 17 | 17 | |
| 18 | -import java.lang.reflect.Array; | |
| 19 | - | |
| 20 | -import static com.google.common.base.Preconditions.checkArgument; | |
| 21 | - | |
| 22 | 18 | import com.datastax.driver.core.DataType; |
| 23 | 19 | import com.datastax.driver.core.ParseUtils; |
| 24 | 20 | import com.datastax.driver.core.TypeCodec; |
| 25 | 21 | import com.datastax.driver.core.exceptions.InvalidTypeException; |
| 26 | 22 | |
| 23 | +import java.lang.reflect.Array; | |
| 24 | + | |
| 27 | 25 | import static com.datastax.driver.core.ParseUtils.skipSpaces; |
| 26 | +import static com.google.common.base.Preconditions.checkArgument; | |
| 28 | 27 | |
| 29 | 28 | /** |
| 30 | 29 | * Base class for all codecs dealing with Java arrays. |
| @@ -35,7 +34,7 @@ | ||
| 35 | 34 | public abstract class AbstractArrayCodec<T> extends TypeCodec<T> { |
| 36 | 35 | |
| 37 | 36 | /** |
| 38 | - * @param cqlType The CQL type. Must be a list type. | |
| 37 | + * @param cqlType The CQL type. Must be a list type. | |
| 39 | 38 | * @param javaClass The Java type. Must be an array class. |
| 40 | 39 | */ |
| 41 | 40 | public AbstractArrayCodec(DataType.CollectionType cqlType, Class<T> javaClass) { |
| @@ -80,7 +79,7 @@ | ||
| 80 | 79 | // second pass: parse elements |
| 81 | 80 | T array = newInstance(length); |
| 82 | 81 | int i = 0; |
| 83 | - for( ; idx < value.length(); i++) { | |
| 82 | + for (; idx < value.length(); i++) { | |
| 84 | 83 | int n = skipLiteral(value, idx); |
| 85 | 84 | parseElement(value.substring(idx, n), array, i); |
| 86 | 85 | idx = skipSpaces(value, n); |
| @@ -105,8 +104,8 @@ | ||
| 105 | 104 | * Format the {@code index}th element of {@code array} to {@code output}. |
| 106 | 105 | * |
| 107 | 106 | * @param output The StringBuilder to write to. |
| 108 | - * @param array The array to read from. | |
| 109 | - * @param index The element index. | |
| 107 | + * @param array The array to read from. | |
| 108 | + * @param index The element index. | |
| 110 | 109 | */ |
| 111 | 110 | protected abstract void formatElement(StringBuilder output, T array, int index); |
| 112 | 111 | |
| @@ -121,7 +120,7 @@ | ||
| 121 | 120 | |
| 122 | 121 | private int getArrayLength(String value, int idx) { |
| 123 | 122 | int length = 1; |
| 124 | - for( ; idx < value.length(); length++) { | |
| 123 | + for (; idx < value.length(); length++) { | |
| 125 | 124 | idx = skipLiteral(value, idx); |
| 126 | 125 | idx = skipSpaces(value, idx); |
| 127 | 126 | if (value.charAt(idx) == ']') |
modified driver-extras/src/main/java/com/datastax/driver/extras/codecs/arrays/AbstractPrimitiveArrayCodec.java +16 −14
| @@ -15,16 +15,16 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.extras.codecs.arrays; |
| 17 | 17 | |
| 18 | -import java.lang.reflect.Array; | |
| 19 | -import java.nio.ByteBuffer; | |
| 20 | - | |
| 21 | -import static com.google.common.base.Preconditions.checkArgument; | |
| 22 | - | |
| 23 | 18 | import com.datastax.driver.core.CodecUtils; |
| 24 | 19 | import com.datastax.driver.core.DataType; |
| 25 | 20 | import com.datastax.driver.core.ProtocolVersion; |
| 26 | 21 | import com.datastax.driver.core.exceptions.InvalidTypeException; |
| 27 | 22 | |
| 23 | +import java.lang.reflect.Array; | |
| 24 | +import java.nio.ByteBuffer; | |
| 25 | + | |
| 26 | +import static com.google.common.base.Preconditions.checkArgument; | |
| 27 | + | |
| 28 | 28 | /** |
| 29 | 29 | * Base class for all codecs dealing with Java primitive arrays. |
| 30 | 30 | * This class provides a more efficient implementation of {@link #serialize(Object, ProtocolVersion)} |
| @@ -35,7 +35,7 @@ | ||
| 35 | 35 | public abstract class AbstractPrimitiveArrayCodec<T> extends AbstractArrayCodec<T> { |
| 36 | 36 | |
| 37 | 37 | /** |
| 38 | - * @param cqlType The CQL type. Must be a list type. | |
| 38 | + * @param cqlType The CQL type. Must be a list type. | |
| 39 | 39 | * @param javaClass The Java type. Must be an array class. |
| 40 | 40 | */ |
| 41 | 41 | public AbstractPrimitiveArrayCodec(DataType.CollectionType cqlType, Class<T> javaClass) { |
| @@ -51,8 +51,8 @@ | ||
| 51 | 51 | // native method |
| 52 | 52 | int length = Array.getLength(array); |
| 53 | 53 | checkArgument(isProtocolV3OrAbove || length < 65536, |
| 54 | - "Native protocol version %d supports up to 65535 elements in any collection - but collection contains %d elements", | |
| 55 | - protocolVersion.toInt(), length); | |
| 54 | + "Native protocol version %d supports up to 65535 elements in any collection - but collection contains %d elements", | |
| 55 | + protocolVersion.toInt(), length); | |
| 56 | 56 | /* |
| 57 | 57 | * Encoding of lists in the native protocol: |
| 58 | 58 | * [size of list] [size of element 1][element1] [size of element 2][element2]... |
| @@ -101,18 +101,20 @@ | ||
| 101 | 101 | |
| 102 | 102 | /** |
| 103 | 103 | * Write the {@code index}th element of {@code array} to {@code output}. |
| 104 | - * @param output The ByteBuffer to write to. | |
| 105 | - * @param array The array to read from. | |
| 106 | - * @param index The element index. | |
| 104 | + * | |
| 105 | + * @param output The ByteBuffer to write to. | |
| 106 | + * @param array The array to read from. | |
| 107 | + * @param index The element index. | |
| 107 | 108 | * @param protocolVersion The protocol version to use. |
| 108 | 109 | */ |
| 109 | 110 | protected abstract void serializeElement(ByteBuffer output, T array, int index, ProtocolVersion protocolVersion); |
| 110 | 111 | |
| 111 | 112 | /** |
| 112 | 113 | * Read the {@code index}th element of {@code array} from {@code input}. |
| 113 | - * @param input The ByteBuffer to read from. | |
| 114 | - * @param array The array to write to. | |
| 115 | - * @param index The element index. | |
| 114 | + * | |
| 115 | + * @param input The ByteBuffer to read from. | |
| 116 | + * @param array The array to write to. | |
| 117 | + * @param index The element index. | |
| 116 | 118 | * @param protocolVersion The protocol version to use. |
| 117 | 119 | */ |
| 118 | 120 | protected abstract void deserializeElement(ByteBuffer input, T array, int index, ProtocolVersion protocolVersion); |
modified driver-extras/src/main/java/com/datastax/driver/extras/codecs/arrays/DoubleArrayCodec.java +3 −3
| @@ -15,14 +15,14 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.extras.codecs.arrays; |
| 17 | 17 | |
| 18 | -import java.nio.ByteBuffer; | |
| 19 | - | |
| 20 | 18 | import com.datastax.driver.core.DataType; |
| 21 | 19 | import com.datastax.driver.core.ProtocolVersion; |
| 22 | 20 | |
| 21 | +import java.nio.ByteBuffer; | |
| 22 | + | |
| 23 | 23 | /** |
| 24 | 24 | * A codec that maps the CQL type {@code list<double>} to the Java type {@code double[]}. |
| 25 | - * <p> | |
| 25 | + * <p/> | |
| 26 | 26 | * Note that this codec is designed for performance and converts CQL lists |
| 27 | 27 | * <em>directly</em> to {@code double[]}, thus avoiding any unnecessary |
| 28 | 28 | * boxing and unboxing of Java primitive {@code double} values; |
modified driver-extras/src/main/java/com/datastax/driver/extras/codecs/arrays/FloatArrayCodec.java +3 −3
| @@ -15,14 +15,14 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.extras.codecs.arrays; |
| 17 | 17 | |
| 18 | -import java.nio.ByteBuffer; | |
| 19 | - | |
| 20 | 18 | import com.datastax.driver.core.DataType; |
| 21 | 19 | import com.datastax.driver.core.ProtocolVersion; |
| 22 | 20 | |
| 21 | +import java.nio.ByteBuffer; | |
| 22 | + | |
| 23 | 23 | /** |
| 24 | 24 | * A codec that maps the CQL type {@code list<float>} to the Java type {@code float[]}. |
| 25 | - * <p> | |
| 25 | + * <p/> | |
| 26 | 26 | * Note that this codec is designed for performance and converts CQL lists |
| 27 | 27 | * <em>directly</em> to {@code float[]}, thus avoiding any unnecessary |
| 28 | 28 | * boxing and unboxing of Java primitive {@code float} values; |
modified driver-extras/src/main/java/com/datastax/driver/extras/codecs/arrays/IntArrayCodec.java +3 −3
| @@ -15,14 +15,14 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.extras.codecs.arrays; |
| 17 | 17 | |
| 18 | -import java.nio.ByteBuffer; | |
| 19 | - | |
| 20 | 18 | import com.datastax.driver.core.DataType; |
| 21 | 19 | import com.datastax.driver.core.ProtocolVersion; |
| 22 | 20 | |
| 21 | +import java.nio.ByteBuffer; | |
| 22 | + | |
| 23 | 23 | /** |
| 24 | 24 | * A codec that maps the CQL type {@code list<int>} to the Java type {@code int[]}. |
| 25 | - * <p> | |
| 25 | + * <p/> | |
| 26 | 26 | * Note that this codec is designed for performance and converts CQL lists |
| 27 | 27 | * <em>directly</em> to {@code int[]}, thus avoiding any unnecessary |
| 28 | 28 | * boxing and unboxing of Java primitive {@code int} values; |
modified driver-extras/src/main/java/com/datastax/driver/extras/codecs/arrays/LongArrayCodec.java +3 −3
| @@ -15,14 +15,14 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.extras.codecs.arrays; |
| 17 | 17 | |
| 18 | -import java.nio.ByteBuffer; | |
| 19 | - | |
| 20 | 18 | import com.datastax.driver.core.DataType; |
| 21 | 19 | import com.datastax.driver.core.ProtocolVersion; |
| 22 | 20 | |
| 21 | +import java.nio.ByteBuffer; | |
| 22 | + | |
| 23 | 23 | /** |
| 24 | 24 | * A codec that maps the CQL type {@code list<long>} to the Java type {@code long[]}. |
| 25 | - * <p> | |
| 25 | + * <p/> | |
| 26 | 26 | * Note that this codec is designed for performance and converts CQL lists |
| 27 | 27 | * <em>directly</em> to {@code long[]}, thus avoiding any unnecessary |
| 28 | 28 | * boxing and unboxing of Java primitive {@code long} values; |
modified driver-extras/src/main/java/com/datastax/driver/extras/codecs/arrays/ObjectArrayCodec.java +8 −8
| @@ -15,21 +15,21 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.extras.codecs.arrays; |
| 17 | 17 | |
| 18 | -import java.lang.reflect.Array; | |
| 19 | -import java.nio.BufferUnderflowException; | |
| 20 | -import java.nio.ByteBuffer; | |
| 21 | - | |
| 22 | 18 | import com.datastax.driver.core.CodecUtils; |
| 23 | 19 | import com.datastax.driver.core.DataType; |
| 24 | 20 | import com.datastax.driver.core.ProtocolVersion; |
| 25 | 21 | import com.datastax.driver.core.TypeCodec; |
| 26 | 22 | import com.datastax.driver.core.exceptions.InvalidTypeException; |
| 27 | 23 | |
| 24 | +import java.lang.reflect.Array; | |
| 25 | +import java.nio.BufferUnderflowException; | |
| 26 | +import java.nio.ByteBuffer; | |
| 27 | + | |
| 28 | 28 | /** |
| 29 | 29 | * Codec dealing with Java object arrays. |
| 30 | 30 | * Serialization and deserialization of elements in the array is |
| 31 | 31 | * delegated to the provided element codec. |
| 32 | - * <p> | |
| 32 | + * <p/> | |
| 33 | 33 | * For example, to create a codec that maps {@code list<text>} to {@code String[]}, |
| 34 | 34 | * declare the following: |
| 35 | 35 | * <pre>{@code |
| @@ -65,8 +65,8 @@ | ||
| 65 | 65 | bb = eltCodec.serialize(elt, protocolVersion); |
| 66 | 66 | } catch (ClassCastException e) { |
| 67 | 67 | throw new InvalidTypeException( |
| 68 | - String.format("Invalid type for %s element, expecting %s but got %s", | |
| 69 | - cqlType, eltCodec.getJavaType(), elt.getClass()), e); | |
| 68 | + String.format("Invalid type for %s element, expecting %s but got %s", | |
| 69 | + cqlType, eltCodec.getJavaType(), elt.getClass()), e); | |
| 70 | 70 | } |
| 71 | 71 | bbs[i++] = bb; |
| 72 | 72 | } |
| @@ -104,6 +104,6 @@ | ||
| 104 | 104 | @Override |
| 105 | 105 | @SuppressWarnings("unchecked") |
| 106 | 106 | protected E[] newInstance(int size) { |
| 107 | - return (E[])Array.newInstance(getJavaType().getRawType().getComponentType(), size); | |
| 107 | + return (E[]) Array.newInstance(getJavaType().getRawType().getComponentType(), size); | |
| 108 | 108 | } |
| 109 | 109 | } |
modified driver-extras/src/main/java/com/datastax/driver/extras/codecs/date/SimpleDateCodec.java +8 −16
| @@ -15,34 +15,26 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.extras.codecs.date; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.*; | |
| 19 | +import com.datastax.driver.core.exceptions.InvalidTypeException; | |
| 20 | + | |
| 18 | 21 | import java.nio.ByteBuffer; |
| 19 | 22 | import java.text.ParseException; |
| 20 | 23 | import java.util.Date; |
| 21 | 24 | |
| 25 | +import static com.datastax.driver.core.CodecUtils.*; | |
| 26 | +import static com.datastax.driver.core.ParseUtils.*; | |
| 22 | 27 | import static java.util.concurrent.TimeUnit.MILLISECONDS; |
| 23 | 28 | |
| 24 | -import com.datastax.driver.core.*; | |
| 25 | -import com.datastax.driver.core.exceptions.InvalidTypeException; | |
| 26 | - | |
| 27 | -import static com.datastax.driver.core.CodecUtils.fromCqlDateToDaysSinceEpoch; | |
| 28 | -import static com.datastax.driver.core.CodecUtils.fromDaysSinceEpochToCqlDate; | |
| 29 | -import static com.datastax.driver.core.CodecUtils.fromSignedToUnsignedInt; | |
| 30 | -import static com.datastax.driver.core.CodecUtils.fromUnsignedToSignedInt; | |
| 31 | -import static com.datastax.driver.core.ParseUtils.isLongLiteral; | |
| 32 | -import static com.datastax.driver.core.ParseUtils.isQuoted; | |
| 33 | -import static com.datastax.driver.core.ParseUtils.parseDate; | |
| 34 | -import static com.datastax.driver.core.ParseUtils.quote; | |
| 35 | -import static com.datastax.driver.core.ParseUtils.unquote; | |
| 36 | - | |
| 37 | 29 | /** |
| 38 | 30 | * A {@link TypeCodec} that maps CQL dates to Java primitive ints, |
| 39 | 31 | * representing the number of days since the Epoch. |
| 40 | - * <p> | |
| 32 | + * <p/> | |
| 41 | 33 | * This codec can serve as a replacement for the driver's built-in |
| 42 | 34 | * {@link TypeCodec#date() date} codec, |
| 43 | 35 | * when application code prefers to deal with raw days than with |
| 44 | 36 | * {@link LocalDate} instances. |
| 45 | - * <p> | |
| 37 | + * <p/> | |
| 46 | 38 | * <strong>Important</strong>: this codec cannot work with {@link SimpleStatement}s! |
| 47 | 39 | * If you try to insert CQL date values as {@code int}s in a {@link SimpleStatement}, |
| 48 | 40 | * the insertion would succeed but the values wouldn't be properly encoded. |
| @@ -96,7 +88,7 @@ | ||
| 96 | 88 | |
| 97 | 89 | try { |
| 98 | 90 | Date date = parseDate(value, pattern); |
| 99 | - return (int)MILLISECONDS.toDays(date.getTime()); | |
| 91 | + return (int) MILLISECONDS.toDays(date.getTime()); | |
| 100 | 92 | } catch (ParseException e) { |
| 101 | 93 | throw new InvalidTypeException(String.format("Cannot parse date value from \"%s\"", value), e); |
| 102 | 94 | } |
modified driver-extras/src/main/java/com/datastax/driver/extras/codecs/date/SimpleTimestampCodec.java +5 −6
| @@ -15,22 +15,21 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.extras.codecs.date; |
| 17 | 17 | |
| 18 | -import java.nio.ByteBuffer; | |
| 19 | -import java.text.ParseException; | |
| 20 | - | |
| 21 | -import static java.lang.Long.parseLong; | |
| 22 | - | |
| 23 | 18 | import com.datastax.driver.core.DataType; |
| 24 | 19 | import com.datastax.driver.core.ProtocolVersion; |
| 25 | 20 | import com.datastax.driver.core.TypeCodec; |
| 26 | 21 | import com.datastax.driver.core.exceptions.InvalidTypeException; |
| 27 | 22 | |
| 23 | +import java.nio.ByteBuffer; | |
| 24 | +import java.text.ParseException; | |
| 25 | + | |
| 28 | 26 | import static com.datastax.driver.core.ParseUtils.*; |
| 27 | +import static java.lang.Long.parseLong; | |
| 29 | 28 | |
| 30 | 29 | /** |
| 31 | 30 | * A {@link TypeCodec} that maps CQL timestamps to Java primitive longs, |
| 32 | 31 | * representing the number of milliseconds since the Epoch. |
| 33 | - * <p> | |
| 32 | + * <p/> | |
| 34 | 33 | * This codec can serve as a replacement for the driver's built-in |
| 35 | 34 | * {@link TypeCodec#timestamp() timestamp} codec, |
| 36 | 35 | * when application code prefers to deal with raw milliseconds than with |
modified driver-extras/src/main/java/com/datastax/driver/extras/codecs/enums/EnumNameCodec.java +1 −1
| @@ -21,7 +21,7 @@ | ||
| 21 | 21 | /** |
| 22 | 22 | * A codec that serializes {@link Enum} instances as CQL {@code varchar}s |
| 23 | 23 | * representing their programmatic names as returned by {@link Enum#name()}. |
| 24 | - * <p> | |
| 24 | + * <p/> | |
| 25 | 25 | * <strong>Note that this codec relies on the enum constant names; |
| 26 | 26 | * it is therefore vital that enum names never change.</strong> |
| 27 | 27 | * |
modified driver-extras/src/main/java/com/datastax/driver/extras/codecs/enums/EnumOrdinalCodec.java +3 −3
| @@ -15,16 +15,16 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.extras.codecs.enums; |
| 17 | 17 | |
| 18 | -import java.nio.ByteBuffer; | |
| 19 | - | |
| 20 | 18 | import com.datastax.driver.core.ProtocolVersion; |
| 21 | 19 | import com.datastax.driver.core.TypeCodec; |
| 22 | 20 | import com.datastax.driver.core.exceptions.InvalidTypeException; |
| 23 | 21 | |
| 22 | +import java.nio.ByteBuffer; | |
| 23 | + | |
| 24 | 24 | /** |
| 25 | 25 | * A codec that serializes {@link Enum} instances as CQL {@code int}s |
| 26 | 26 | * representing their ordinal values as returned by {@link Enum#ordinal()}. |
| 27 | - * <p> | |
| 27 | + * <p/> | |
| 28 | 28 | * <strong>Note that this codec relies on the enum constants declaration order; |
| 29 | 29 | * it is therefore vital that this order remains immutable.</strong> |
| 30 | 30 | * |
modified driver-extras/src/main/java/com/datastax/driver/extras/codecs/guava/OptionalCodec.java +9 −8
| @@ -15,16 +15,15 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.extras.codecs.guava; |
| 17 | 17 | |
| 18 | -import java.util.Collection; | |
| 19 | -import java.util.Map; | |
| 20 | - | |
| 18 | +import com.datastax.driver.core.TypeCodec; | |
| 19 | +import com.datastax.driver.extras.codecs.MappingCodec; | |
| 21 | 20 | import com.google.common.base.Optional; |
| 22 | 21 | import com.google.common.base.Predicate; |
| 23 | 22 | import com.google.common.reflect.TypeParameter; |
| 24 | 23 | import com.google.common.reflect.TypeToken; |
| 25 | 24 | |
| 26 | -import com.datastax.driver.core.TypeCodec; | |
| 27 | -import com.datastax.driver.extras.codecs.MappingCodec; | |
| 25 | +import java.util.Collection; | |
| 26 | +import java.util.Map; | |
| 28 | 27 | |
| 29 | 28 | /** |
| 30 | 29 | * A codec that wraps other codecs around Guava's {@link Optional} API. |
| @@ -40,14 +39,16 @@ | ||
| 40 | 39 | @Override |
| 41 | 40 | public boolean apply(T input) { |
| 42 | 41 | return input == null |
| 43 | - || input instanceof Collection && ((Collection)input).isEmpty() | |
| 44 | - || input instanceof Map && ((Map)input).isEmpty(); | |
| 42 | + || input instanceof Collection && ((Collection) input).isEmpty() | |
| 43 | + || input instanceof Map && ((Map) input).isEmpty(); | |
| 45 | 44 | } |
| 46 | 45 | }); |
| 47 | 46 | } |
| 48 | 47 | |
| 49 | 48 | public OptionalCodec(TypeCodec<T> codec, Predicate<T> isAbsent) { |
| 50 | - super(codec, new TypeToken<Optional<T>>(){}.where(new TypeParameter<T>(){}, codec.getJavaType())); | |
| 49 | + super(codec, new TypeToken<Optional<T>>() { | |
| 50 | + }.where(new TypeParameter<T>() { | |
| 51 | + }, codec.getJavaType())); | |
| 51 | 52 | this.isAbsent = isAbsent; |
| 52 | 53 | } |
| 53 | 54 |
modified driver-extras/src/main/java/com/datastax/driver/extras/codecs/jdk8/InstantCodec.java +30 −38
| @@ -15,30 +15,22 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.extras.codecs.jdk8; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.DataType; | |
| 19 | +import com.datastax.driver.core.ProtocolVersion; | |
| 20 | +import com.datastax.driver.core.TypeCodec; | |
| 21 | +import com.datastax.driver.core.exceptions.InvalidTypeException; | |
| 22 | + | |
| 18 | 23 | import java.nio.ByteBuffer; |
| 19 | 24 | import java.time.Instant; |
| 20 | 25 | import java.time.format.DateTimeFormatter; |
| 21 | 26 | import java.time.format.DateTimeFormatterBuilder; |
| 22 | 27 | import java.time.format.DateTimeParseException; |
| 23 | -import java.util.Date; | |
| 24 | 28 | |
| 29 | +import static com.datastax.driver.core.ParseUtils.*; | |
| 25 | 30 | import static java.lang.Long.parseLong; |
| 26 | 31 | import static java.time.Instant.ofEpochMilli; |
| 27 | 32 | import static java.time.ZoneOffset.UTC; |
| 28 | -import static java.time.temporal.ChronoField.HOUR_OF_DAY; | |
| 29 | -import static java.time.temporal.ChronoField.MINUTE_OF_HOUR; | |
| 30 | -import static java.time.temporal.ChronoField.NANO_OF_SECOND; | |
| 31 | -import static java.time.temporal.ChronoField.SECOND_OF_MINUTE; | |
| 32 | - | |
| 33 | -import com.datastax.driver.core.DataType; | |
| 34 | -import com.datastax.driver.core.ProtocolVersion; | |
| 35 | -import com.datastax.driver.core.TypeCodec; | |
| 36 | -import com.datastax.driver.core.exceptions.InvalidTypeException; | |
| 37 | - | |
| 38 | -import static com.datastax.driver.core.ParseUtils.isLongLiteral; | |
| 39 | -import static com.datastax.driver.core.ParseUtils.isQuoted; | |
| 40 | -import static com.datastax.driver.core.ParseUtils.quote; | |
| 41 | -import static com.datastax.driver.core.ParseUtils.unquote; | |
| 33 | +import static java.time.temporal.ChronoField.*; | |
| 42 | 34 | |
| 43 | 35 | /** |
| 44 | 36 | * <p> |
| @@ -46,7 +38,7 @@ | ||
| 46 | 38 | * allowing the setting and retrieval of {@code timestamp} |
| 47 | 39 | * columns as {@link Instant} instances. |
| 48 | 40 | * </p> |
| 49 | - * | |
| 41 | + * <p/> | |
| 50 | 42 | * <p> |
| 51 | 43 | * Since C* <code>timestamp</code> columns do not preserve timezones |
| 52 | 44 | * any attached timezone information will be lost. |
| @@ -65,30 +57,30 @@ | ||
| 65 | 57 | * the ISO formats accepted in CQL. |
| 66 | 58 | */ |
| 67 | 59 | private static final DateTimeFormatter PARSER = new DateTimeFormatterBuilder() |
| 68 | - .parseCaseSensitive() | |
| 69 | - .parseStrict() | |
| 70 | - .append(DateTimeFormatter.ISO_LOCAL_DATE) | |
| 71 | - .optionalStart() | |
| 72 | - .appendLiteral('T') | |
| 73 | - .appendValue(HOUR_OF_DAY, 2) | |
| 74 | - .appendLiteral(':') | |
| 75 | - .appendValue(MINUTE_OF_HOUR, 2) | |
| 76 | - .optionalEnd() | |
| 77 | - .optionalStart() | |
| 78 | - .appendLiteral(':') | |
| 79 | - .appendValue(SECOND_OF_MINUTE, 2) | |
| 80 | - .optionalEnd() | |
| 81 | - .optionalStart() | |
| 82 | - .appendFraction(NANO_OF_SECOND, 0, 9, true) | |
| 83 | - .optionalEnd() | |
| 84 | - .optionalStart() | |
| 85 | - .appendZoneId() | |
| 86 | - .optionalEnd() | |
| 87 | - .toFormatter() | |
| 88 | - .withZone(UTC); | |
| 60 | + .parseCaseSensitive() | |
| 61 | + .parseStrict() | |
| 62 | + .append(DateTimeFormatter.ISO_LOCAL_DATE) | |
| 63 | + .optionalStart() | |
| 64 | + .appendLiteral('T') | |
| 65 | + .appendValue(HOUR_OF_DAY, 2) | |
| 66 | + .appendLiteral(':') | |
| 67 | + .appendValue(MINUTE_OF_HOUR, 2) | |
| 68 | + .optionalEnd() | |
| 69 | + .optionalStart() | |
| 70 | + .appendLiteral(':') | |
| 71 | + .appendValue(SECOND_OF_MINUTE, 2) | |
| 72 | + .optionalEnd() | |
| 73 | + .optionalStart() | |
| 74 | + .appendFraction(NANO_OF_SECOND, 0, 9, true) | |
| 75 | + .optionalEnd() | |
| 76 | + .optionalStart() | |
| 77 | + .appendZoneId() | |
| 78 | + .optionalEnd() | |
| 79 | + .toFormatter() | |
| 80 | + .withZone(UTC); | |
| 89 | 81 | |
| 90 | 82 | private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSxxx") |
| 91 | - .withZone(UTC); | |
| 83 | + .withZone(UTC); | |
| 92 | 84 | |
| 93 | 85 | |
| 94 | 86 | private InstantCodec() { |
modified driver-extras/src/main/java/com/datastax/driver/extras/codecs/jdk8/LocalDateCodec.java +7 −11
| @@ -15,24 +15,20 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.extras.codecs.jdk8; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.DataType; | |
| 19 | +import com.datastax.driver.core.ProtocolVersion; | |
| 20 | +import com.datastax.driver.core.TypeCodec; | |
| 21 | +import com.datastax.driver.core.exceptions.InvalidTypeException; | |
| 22 | + | |
| 18 | 23 | import java.nio.ByteBuffer; |
| 19 | 24 | import java.time.LocalDate; |
| 20 | 25 | import java.time.temporal.ChronoUnit; |
| 21 | 26 | |
| 27 | +import static com.datastax.driver.core.CodecUtils.*; | |
| 28 | +import static com.datastax.driver.core.ParseUtils.*; | |
| 22 | 29 | import static java.lang.Long.parseLong; |
| 23 | 30 | import static java.time.format.DateTimeFormatter.ISO_LOCAL_DATE; |
| 24 | 31 | |
| 25 | -import com.datastax.driver.core.*; | |
| 26 | -import com.datastax.driver.core.exceptions.InvalidTypeException; | |
| 27 | - | |
| 28 | -import static com.datastax.driver.core.CodecUtils.fromCqlDateToDaysSinceEpoch; | |
| 29 | -import static com.datastax.driver.core.CodecUtils.fromSignedToUnsignedInt; | |
| 30 | -import static com.datastax.driver.core.CodecUtils.fromUnsignedToSignedInt; | |
| 31 | -import static com.datastax.driver.core.ParseUtils.isLongLiteral; | |
| 32 | -import static com.datastax.driver.core.ParseUtils.isQuoted; | |
| 33 | -import static com.datastax.driver.core.ParseUtils.quote; | |
| 34 | -import static com.datastax.driver.core.ParseUtils.unquote; | |
| 35 | - | |
| 36 | 32 | /** |
| 37 | 33 | * {@link TypeCodec} that maps |
| 38 | 34 | * {@link java.time.LocalDate} to CQL {@code date}. |
modified driver-extras/src/main/java/com/datastax/driver/extras/codecs/jdk8/LocalTimeCodec.java +4 −4
| @@ -15,16 +15,16 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.extras.codecs.jdk8; |
| 17 | 17 | |
| 18 | -import java.nio.ByteBuffer; | |
| 19 | -import java.time.LocalTime; | |
| 20 | -import java.time.format.DateTimeFormatter; | |
| 21 | - | |
| 22 | 18 | import com.datastax.driver.core.DataType; |
| 23 | 19 | import com.datastax.driver.core.ParseUtils; |
| 24 | 20 | import com.datastax.driver.core.ProtocolVersion; |
| 25 | 21 | import com.datastax.driver.core.TypeCodec; |
| 26 | 22 | import com.datastax.driver.core.exceptions.InvalidTypeException; |
| 27 | 23 | |
| 24 | +import java.nio.ByteBuffer; | |
| 25 | +import java.time.LocalTime; | |
| 26 | +import java.time.format.DateTimeFormatter; | |
| 27 | + | |
| 28 | 28 | import static com.datastax.driver.core.ParseUtils.quote; |
| 29 | 29 | |
| 30 | 30 | /** |
modified driver-extras/src/main/java/com/datastax/driver/extras/codecs/jdk8/OptionalCodec.java +10 −9
| @@ -15,17 +15,16 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.extras.codecs.jdk8; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.TypeCodec; | |
| 19 | +import com.datastax.driver.extras.codecs.MappingCodec; | |
| 20 | +import com.google.common.reflect.TypeParameter; | |
| 21 | +import com.google.common.reflect.TypeToken; | |
| 22 | + | |
| 18 | 23 | import java.util.Collection; |
| 19 | 24 | import java.util.Map; |
| 20 | 25 | import java.util.Optional; |
| 21 | 26 | import java.util.function.Predicate; |
| 22 | 27 | |
| 23 | -import com.google.common.reflect.TypeParameter; | |
| 24 | -import com.google.common.reflect.TypeToken; | |
| 25 | - | |
| 26 | -import com.datastax.driver.core.TypeCodec; | |
| 27 | -import com.datastax.driver.extras.codecs.MappingCodec; | |
| 28 | - | |
| 29 | 28 | /** |
| 30 | 29 | * A codec that wraps other codecs around JDK 8's {@link Optional} API. |
| 31 | 30 | * |
| @@ -40,15 +39,17 @@ | ||
| 40 | 39 | @Override |
| 41 | 40 | public boolean test(T input) { |
| 42 | 41 | return input == null |
| 43 | - || input instanceof Collection && ((Collection)input).isEmpty() | |
| 44 | - || input instanceof Map && ((Map)input).isEmpty(); | |
| 42 | + || input instanceof Collection && ((Collection) input).isEmpty() | |
| 43 | + || input instanceof Map && ((Map) input).isEmpty(); | |
| 45 | 44 | |
| 46 | 45 | } |
| 47 | 46 | }); |
| 48 | 47 | } |
| 49 | 48 | |
| 50 | 49 | public OptionalCodec(TypeCodec<T> codec, Predicate<T> isAbsent) { |
| 51 | - super(codec, new TypeToken<Optional<T>>(){}.where(new TypeParameter<T>(){}, codec.getJavaType())); | |
| 50 | + super(codec, new TypeToken<Optional<T>>() { | |
| 51 | + }.where(new TypeParameter<T>() { | |
| 52 | + }, codec.getJavaType())); | |
| 52 | 53 | this.isAbsent = isAbsent; |
| 53 | 54 | } |
| 54 | 55 |
modified driver-extras/src/main/java/com/datastax/driver/extras/codecs/jdk8/ZonedDateTimeCodec.java +44 −49
| @@ -15,6 +15,9 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.extras.codecs.jdk8; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.*; | |
| 19 | +import com.datastax.driver.core.exceptions.InvalidTypeException; | |
| 20 | + | |
| 18 | 21 | import java.nio.ByteBuffer; |
| 19 | 22 | import java.time.Instant; |
| 20 | 23 | import java.time.ZoneId; |
| @@ -25,27 +28,19 @@ | ||
| 25 | 28 | import java.time.format.DateTimeParseException; |
| 26 | 29 | import java.util.List; |
| 27 | 30 | |
| 28 | -import static java.time.temporal.ChronoField.HOUR_OF_DAY; | |
| 29 | -import static java.time.temporal.ChronoField.MINUTE_OF_HOUR; | |
| 30 | -import static java.time.temporal.ChronoField.NANO_OF_SECOND; | |
| 31 | -import static java.time.temporal.ChronoField.SECOND_OF_MINUTE; | |
| 32 | - | |
| 33 | -import static com.google.common.base.Preconditions.checkArgument; | |
| 34 | - | |
| 35 | -import com.datastax.driver.core.*; | |
| 36 | -import com.datastax.driver.core.exceptions.InvalidTypeException; | |
| 37 | - | |
| 38 | 31 | import static com.datastax.driver.core.ParseUtils.isLongLiteral; |
| 39 | 32 | import static com.datastax.driver.core.ParseUtils.quote; |
| 33 | +import static com.google.common.base.Preconditions.checkArgument; | |
| 34 | +import static java.time.temporal.ChronoField.*; | |
| 40 | 35 | |
| 41 | 36 | /** |
| 42 | - * <p> | |
| 37 | + * <p/> | |
| 43 | 38 | * {@link TypeCodec} that maps |
| 44 | 39 | * {@link ZonedDateTime} to CQL {@code tuple<timestamp,varchar>}, |
| 45 | 40 | * providing a pattern for maintaining timezone information in |
| 46 | 41 | * Cassandra. |
| 47 | - * | |
| 48 | - * <p> | |
| 42 | + * <p/> | |
| 43 | + * <p/> | |
| 49 | 44 | * Since Cassandra's <code>timestamp</code> type preserves only |
| 50 | 45 | * milliseconds since epoch, any timezone information |
| 51 | 46 | * would normally be lost. By using a |
| @@ -64,27 +59,27 @@ | ||
| 64 | 59 | * the ISO formats accepted in CQL. |
| 65 | 60 | */ |
| 66 | 61 | private static final DateTimeFormatter FORMATTER = new DateTimeFormatterBuilder() |
| 67 | - .parseCaseSensitive() | |
| 68 | - .parseStrict() | |
| 69 | - .append(DateTimeFormatter.ISO_LOCAL_DATE) | |
| 70 | - .optionalStart() | |
| 71 | - .appendLiteral('T') | |
| 72 | - .appendValue(HOUR_OF_DAY, 2) | |
| 73 | - .appendLiteral(':') | |
| 74 | - .appendValue(MINUTE_OF_HOUR, 2) | |
| 75 | - .optionalEnd() | |
| 76 | - .optionalStart() | |
| 77 | - .appendLiteral(':') | |
| 78 | - .appendValue(SECOND_OF_MINUTE, 2) | |
| 79 | - .optionalEnd() | |
| 80 | - .optionalStart() | |
| 81 | - .appendFraction(NANO_OF_SECOND, 0, 9, true) | |
| 82 | - .optionalEnd() | |
| 83 | - .optionalStart() | |
| 84 | - .appendZoneOrOffsetId() | |
| 85 | - .optionalEnd() | |
| 86 | - .toFormatter() | |
| 87 | - .withZone(ZoneOffset.UTC); | |
| 62 | + .parseCaseSensitive() | |
| 63 | + .parseStrict() | |
| 64 | + .append(DateTimeFormatter.ISO_LOCAL_DATE) | |
| 65 | + .optionalStart() | |
| 66 | + .appendLiteral('T') | |
| 67 | + .appendValue(HOUR_OF_DAY, 2) | |
| 68 | + .appendLiteral(':') | |
| 69 | + .appendValue(MINUTE_OF_HOUR, 2) | |
| 70 | + .optionalEnd() | |
| 71 | + .optionalStart() | |
| 72 | + .appendLiteral(':') | |
| 73 | + .appendValue(SECOND_OF_MINUTE, 2) | |
| 74 | + .optionalEnd() | |
| 75 | + .optionalStart() | |
| 76 | + .appendFraction(NANO_OF_SECOND, 0, 9, true) | |
| 77 | + .optionalEnd() | |
| 78 | + .optionalStart() | |
| 79 | + .appendZoneOrOffsetId() | |
| 80 | + .optionalEnd() | |
| 81 | + .toFormatter() | |
| 82 | + .withZone(ZoneOffset.UTC); | |
| 88 | 83 | |
| 89 | 84 | private static final DateTimeFormatter ZONE_FORMATTER = DateTimeFormatter.ofPattern("xxx"); |
| 90 | 85 | |
| @@ -92,9 +87,9 @@ | ||
| 92 | 87 | super(tupleType, ZonedDateTime.class); |
| 93 | 88 | List<DataType> types = tupleType.getComponentTypes(); |
| 94 | 89 | checkArgument( |
| 95 | - types.size() == 2 && types.get(0).equals(DataType.timestamp()) && types.get(1).equals(DataType.varchar()), | |
| 96 | - "Expected tuple<timestamp,varchar>, got %s", | |
| 97 | - tupleType); | |
| 90 | + types.size() == 2 && types.get(0).equals(DataType.timestamp()) && types.get(1).equals(DataType.varchar()), | |
| 91 | + "Expected tuple<timestamp,varchar>, got %s", | |
| 92 | + tupleType); | |
| 98 | 93 | } |
| 99 | 94 | |
| 100 | 95 | @Override |
| @@ -104,43 +99,43 @@ | ||
| 104 | 99 | |
| 105 | 100 | @Override |
| 106 | 101 | protected ByteBuffer serializeField(ZonedDateTime source, int index, ProtocolVersion protocolVersion) { |
| 107 | - if(index == 0) { | |
| 102 | + if (index == 0) { | |
| 108 | 103 | long millis = source.toInstant().toEpochMilli(); |
| 109 | 104 | return bigint().serializeNoBoxing(millis, protocolVersion); |
| 110 | 105 | } |
| 111 | - if(index == 1) { | |
| 106 | + if (index == 1) { | |
| 112 | 107 | return varchar().serialize(ZONE_FORMATTER.format(source.getOffset()), protocolVersion); |
| 113 | 108 | } |
| 114 | - throw new IndexOutOfBoundsException("Tuple index out of bounds. "+ index); | |
| 109 | + throw new IndexOutOfBoundsException("Tuple index out of bounds. " + index); | |
| 115 | 110 | } |
| 116 | 111 | |
| 117 | 112 | @Override |
| 118 | 113 | protected ZonedDateTime deserializeAndSetField(ByteBuffer input, ZonedDateTime target, int index, ProtocolVersion protocolVersion) { |
| 119 | - if(index == 0) { | |
| 114 | + if (index == 0) { | |
| 120 | 115 | long millis = bigint().deserializeNoBoxing(input, protocolVersion); |
| 121 | 116 | return Instant.ofEpochMilli(millis).atZone(ZoneOffset.UTC); |
| 122 | 117 | } |
| 123 | - if(index == 1) { | |
| 118 | + if (index == 1) { | |
| 124 | 119 | String zoneId = varchar().deserialize(input, protocolVersion); |
| 125 | 120 | return target.withZoneSameInstant(ZoneId.of(zoneId)); |
| 126 | 121 | } |
| 127 | - throw new IndexOutOfBoundsException("Tuple index out of bounds. "+ index); | |
| 122 | + throw new IndexOutOfBoundsException("Tuple index out of bounds. " + index); | |
| 128 | 123 | } |
| 129 | 124 | |
| 130 | 125 | @Override |
| 131 | 126 | protected String formatField(ZonedDateTime value, int index) { |
| 132 | - if(index == 0) { | |
| 127 | + if (index == 0) { | |
| 133 | 128 | return quote(FORMATTER.format(value)); |
| 134 | 129 | } |
| 135 | - if(index == 1) { | |
| 130 | + if (index == 1) { | |
| 136 | 131 | return quote(ZONE_FORMATTER.format(value.getOffset())); |
| 137 | 132 | } |
| 138 | - throw new IndexOutOfBoundsException("Tuple index out of bounds. "+ index); | |
| 133 | + throw new IndexOutOfBoundsException("Tuple index out of bounds. " + index); | |
| 139 | 134 | } |
| 140 | 135 | |
| 141 | 136 | @Override |
| 142 | 137 | protected ZonedDateTime parseAndSetField(String input, ZonedDateTime target, int index) { |
| 143 | - if(index == 0) { | |
| 138 | + if (index == 0) { | |
| 144 | 139 | // strip enclosing single quotes, if any |
| 145 | 140 | if (ParseUtils.isQuoted(input)) |
| 146 | 141 | input = ParseUtils.unquote(input); |
| @@ -158,10 +153,10 @@ | ||
| 158 | 153 | throw new InvalidTypeException(String.format("Cannot parse timestamp value from \"%s\"", target)); |
| 159 | 154 | } |
| 160 | 155 | } |
| 161 | - if(index == 1) { | |
| 156 | + if (index == 1) { | |
| 162 | 157 | String zoneId = varchar().parse(input); |
| 163 | 158 | return target.withZoneSameInstant(ZoneId.of(zoneId)); |
| 164 | 159 | } |
| 165 | - throw new IndexOutOfBoundsException("Tuple index out of bounds. "+ index); | |
| 160 | + throw new IndexOutOfBoundsException("Tuple index out of bounds. " + index); | |
| 166 | 161 | } |
| 167 | 162 | } |
modified driver-extras/src/main/java/com/datastax/driver/extras/codecs/jdk8/package-info.java +2 −3
| @@ -19,11 +19,10 @@ | ||
| 19 | 19 | * {@link com.datastax.driver.core.TypeCodec TypeCodec} instances useful for |
| 20 | 20 | * serializing between CQL types and Java 8 types, such as the ones from the |
| 21 | 21 | * {@link java.time} API and {@link java.util.Optional}. |
| 22 | - * | |
| 23 | - * <p> | |
| 22 | + * <p/> | |
| 23 | + * <p/> | |
| 24 | 24 | * Note that, while the driver remains globally compatible with older JDKs, |
| 25 | 25 | * classes in this package require the presence of a Java 8 or higher |
| 26 | 26 | * at runtime. |
| 27 | - * | |
| 28 | 27 | */ |
| 29 | 28 | package com.datastax.driver.extras.codecs.jdk8; |
modified driver-extras/src/main/java/com/datastax/driver/extras/codecs/joda/DateTimeCodec.java +31 −33
| @@ -15,9 +15,8 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.extras.codecs.joda; |
| 17 | 17 | |
| 18 | -import java.nio.ByteBuffer; | |
| 19 | -import java.util.List; | |
| 20 | - | |
| 18 | +import com.datastax.driver.core.*; | |
| 19 | +import com.datastax.driver.core.exceptions.InvalidTypeException; | |
| 21 | 20 | import org.joda.time.DateTime; |
| 22 | 21 | import org.joda.time.DateTimeZone; |
| 23 | 22 | import org.joda.time.format.DateTimeFormat; |
| @@ -25,23 +24,22 @@ | ||
| 25 | 24 | import org.joda.time.format.DateTimeFormatterBuilder; |
| 26 | 25 | import org.joda.time.format.ISODateTimeFormat; |
| 27 | 26 | |
| 28 | -import static com.google.common.base.Preconditions.checkArgument; | |
| 29 | -import static org.joda.time.DateTimeZone.UTC; | |
| 30 | - | |
| 31 | -import com.datastax.driver.core.*; | |
| 32 | -import com.datastax.driver.core.exceptions.InvalidTypeException; | |
| 27 | +import java.nio.ByteBuffer; | |
| 28 | +import java.util.List; | |
| 33 | 29 | |
| 34 | 30 | import static com.datastax.driver.core.ParseUtils.isLongLiteral; |
| 35 | 31 | import static com.datastax.driver.core.ParseUtils.quote; |
| 32 | +import static com.google.common.base.Preconditions.checkArgument; | |
| 33 | +import static org.joda.time.DateTimeZone.UTC; | |
| 36 | 34 | |
| 37 | 35 | /** |
| 38 | - * <p> | |
| 36 | + * <p/> | |
| 39 | 37 | * {@link TypeCodec} that maps |
| 40 | 38 | * {@link DateTime} to CQL {@code tuple<timestamp,varchar>}, |
| 41 | 39 | * providing a pattern for maintaining timezone information in |
| 42 | 40 | * Cassandra. |
| 43 | - * | |
| 44 | - * <p> | |
| 41 | + * <p/> | |
| 42 | + * <p/> | |
| 45 | 43 | * Since Cassandra's <code>timestamp</code> type preserves only |
| 46 | 44 | * milliseconds since epoch, any timezone information |
| 47 | 45 | * would normally be lost. By using a |
| @@ -60,13 +58,13 @@ | ||
| 60 | 58 | * the ISO formats accepted in CQL. |
| 61 | 59 | */ |
| 62 | 60 | private static final DateTimeFormatter FORMATTER = new DateTimeFormatterBuilder() |
| 63 | - .append(ISODateTimeFormat.dateOptionalTimeParser().getParser()) | |
| 64 | - .appendOptional( | |
| 65 | - new DateTimeFormatterBuilder() | |
| 66 | - .appendTimeZoneOffset("Z", true, 2, 4) | |
| 67 | - .toParser()) | |
| 68 | - .toFormatter() | |
| 69 | - .withZoneUTC(); | |
| 61 | + .append(ISODateTimeFormat.dateOptionalTimeParser().getParser()) | |
| 62 | + .appendOptional( | |
| 63 | + new DateTimeFormatterBuilder() | |
| 64 | + .appendTimeZoneOffset("Z", true, 2, 4) | |
| 65 | + .toParser()) | |
| 66 | + .toFormatter() | |
| 67 | + .withZoneUTC(); | |
| 70 | 68 | |
| 71 | 69 | private static final DateTimeFormatter ZONE_FORMATTER = DateTimeFormat.forPattern("ZZ"); |
| 72 | 70 | |
| @@ -74,9 +72,9 @@ | ||
| 74 | 72 | super(tupleType, DateTime.class); |
| 75 | 73 | List<DataType> types = tupleType.getComponentTypes(); |
| 76 | 74 | checkArgument( |
| 77 | - types.size() == 2 && types.get(0).equals(DataType.timestamp()) && types.get(1).equals(DataType.varchar()), | |
| 78 | - "Expected tuple<timestamp,varchar>, got %s", | |
| 79 | - tupleType); | |
| 75 | + types.size() == 2 && types.get(0).equals(DataType.timestamp()) && types.get(1).equals(DataType.varchar()), | |
| 76 | + "Expected tuple<timestamp,varchar>, got %s", | |
| 77 | + tupleType); | |
| 80 | 78 | } |
| 81 | 79 | |
| 82 | 80 | @Override |
| @@ -86,43 +84,43 @@ | ||
| 86 | 84 | |
| 87 | 85 | @Override |
| 88 | 86 | protected ByteBuffer serializeField(DateTime source, int index, ProtocolVersion protocolVersion) { |
| 89 | - if(index == 0) { | |
| 87 | + if (index == 0) { | |
| 90 | 88 | long millis = source.getMillis(); |
| 91 | 89 | return bigint().serializeNoBoxing(millis, protocolVersion); |
| 92 | 90 | } |
| 93 | - if(index == 1) { | |
| 91 | + if (index == 1) { | |
| 94 | 92 | return varchar().serialize(ZONE_FORMATTER.print(source), protocolVersion); |
| 95 | 93 | } |
| 96 | - throw new IndexOutOfBoundsException("Tuple index out of bounds. "+ index); | |
| 94 | + throw new IndexOutOfBoundsException("Tuple index out of bounds. " + index); | |
| 97 | 95 | } |
| 98 | 96 | |
| 99 | 97 | @Override |
| 100 | 98 | protected DateTime deserializeAndSetField(ByteBuffer input, DateTime target, int index, ProtocolVersion protocolVersion) { |
| 101 | - if(index == 0) { | |
| 99 | + if (index == 0) { | |
| 102 | 100 | long millis = bigint().deserializeNoBoxing(input, protocolVersion); |
| 103 | 101 | return new DateTime(millis); |
| 104 | 102 | } |
| 105 | - if(index == 1) { | |
| 103 | + if (index == 1) { | |
| 106 | 104 | String zoneId = varchar().deserialize(input, protocolVersion); |
| 107 | 105 | return target.withZone(DateTimeZone.forID(zoneId)); |
| 108 | 106 | } |
| 109 | - throw new IndexOutOfBoundsException("Tuple index out of bounds. "+ index); | |
| 107 | + throw new IndexOutOfBoundsException("Tuple index out of bounds. " + index); | |
| 110 | 108 | } |
| 111 | 109 | |
| 112 | 110 | @Override |
| 113 | 111 | protected String formatField(DateTime value, int index) { |
| 114 | - if(index == 0) { | |
| 112 | + if (index == 0) { | |
| 115 | 113 | return quote(value.withZone(UTC).toString()); |
| 116 | 114 | } |
| 117 | - if(index == 1) { | |
| 115 | + if (index == 1) { | |
| 118 | 116 | return quote(ZONE_FORMATTER.print(value)); |
| 119 | 117 | } |
| 120 | - throw new IndexOutOfBoundsException("Tuple index out of bounds. "+ index); | |
| 118 | + throw new IndexOutOfBoundsException("Tuple index out of bounds. " + index); | |
| 121 | 119 | } |
| 122 | 120 | |
| 123 | 121 | @Override |
| 124 | 122 | protected DateTime parseAndSetField(String input, DateTime target, int index) { |
| 125 | - if(index == 0) { | |
| 123 | + if (index == 0) { | |
| 126 | 124 | // strip enclosing single quotes, if any |
| 127 | 125 | if (ParseUtils.isQuoted(input)) |
| 128 | 126 | input = ParseUtils.unquote(input); |
| @@ -140,11 +138,11 @@ | ||
| 140 | 138 | throw new InvalidTypeException(String.format("Cannot parse timestamp value from \"%s\"", target)); |
| 141 | 139 | } |
| 142 | 140 | } |
| 143 | - if(index == 1) { | |
| 141 | + if (index == 1) { | |
| 144 | 142 | String zoneId = varchar().parse(input); |
| 145 | 143 | return target.withZone(DateTimeZone.forID(zoneId)); |
| 146 | 144 | } |
| 147 | - throw new IndexOutOfBoundsException("Tuple index out of bounds. "+ index); | |
| 145 | + throw new IndexOutOfBoundsException("Tuple index out of bounds. " + index); | |
| 148 | 146 | } |
| 149 | 147 | |
| 150 | 148 | } |
modified driver-extras/src/main/java/com/datastax/driver/extras/codecs/joda/InstantCodec.java +14 −19
| @@ -15,25 +15,20 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.extras.codecs.joda; |
| 17 | 17 | |
| 18 | -import java.nio.ByteBuffer; | |
| 19 | - | |
| 20 | -import static java.lang.Long.parseLong; | |
| 21 | - | |
| 18 | +import com.datastax.driver.core.DataType; | |
| 19 | +import com.datastax.driver.core.ProtocolVersion; | |
| 20 | +import com.datastax.driver.core.TypeCodec; | |
| 21 | +import com.datastax.driver.core.exceptions.InvalidTypeException; | |
| 22 | 22 | import org.joda.time.Instant; |
| 23 | 23 | import org.joda.time.format.DateTimeFormat; |
| 24 | 24 | import org.joda.time.format.DateTimeFormatter; |
| 25 | 25 | import org.joda.time.format.DateTimeFormatterBuilder; |
| 26 | 26 | import org.joda.time.format.ISODateTimeFormat; |
| 27 | 27 | |
| 28 | -import com.datastax.driver.core.DataType; | |
| 29 | -import com.datastax.driver.core.ProtocolVersion; | |
| 30 | -import com.datastax.driver.core.TypeCodec; | |
| 31 | -import com.datastax.driver.core.exceptions.InvalidTypeException; | |
| 28 | +import java.nio.ByteBuffer; | |
| 32 | 29 | |
| 33 | -import static com.datastax.driver.core.ParseUtils.isLongLiteral; | |
| 34 | -import static com.datastax.driver.core.ParseUtils.isQuoted; | |
| 35 | -import static com.datastax.driver.core.ParseUtils.quote; | |
| 36 | -import static com.datastax.driver.core.ParseUtils.unquote; | |
| 30 | +import static com.datastax.driver.core.ParseUtils.*; | |
| 31 | +import static java.lang.Long.parseLong; | |
| 37 | 32 | |
| 38 | 33 | /** |
| 39 | 34 | * {@link TypeCodec} that maps {@link Instant} to CQL {@code timestamp}. |
| @@ -51,13 +46,13 @@ | ||
| 51 | 46 | * the ISO formats accepted in CQL. |
| 52 | 47 | */ |
| 53 | 48 | private static final DateTimeFormatter PARSER = new DateTimeFormatterBuilder() |
| 54 | - .append(ISODateTimeFormat.dateOptionalTimeParser().getParser()) | |
| 55 | - .appendOptional( | |
| 56 | - new DateTimeFormatterBuilder() | |
| 57 | - .appendTimeZoneOffset("Z", true, 2, 4) | |
| 58 | - .toParser()) | |
| 59 | - .toFormatter() | |
| 60 | - .withZoneUTC(); | |
| 49 | + .append(ISODateTimeFormat.dateOptionalTimeParser().getParser()) | |
| 50 | + .appendOptional( | |
| 51 | + new DateTimeFormatterBuilder() | |
| 52 | + .appendTimeZoneOffset("Z", true, 2, 4) | |
| 53 | + .toParser()) | |
| 54 | + .toFormatter() | |
| 55 | + .withZoneUTC(); | |
| 61 | 56 | |
| 62 | 57 | private static final DateTimeFormatter FORMATTER = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZZ").withZoneUTC(); |
| 63 | 58 |
modified driver-extras/src/main/java/com/datastax/driver/extras/codecs/joda/LocalDateCodec.java +9 −15
| @@ -15,27 +15,21 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.extras.codecs.joda; |
| 17 | 17 | |
| 18 | -import java.nio.ByteBuffer; | |
| 19 | - | |
| 20 | -import static java.lang.Long.parseLong; | |
| 21 | - | |
| 18 | +import com.datastax.driver.core.DataType; | |
| 19 | +import com.datastax.driver.core.ProtocolVersion; | |
| 20 | +import com.datastax.driver.core.TypeCodec; | |
| 21 | +import com.datastax.driver.core.exceptions.InvalidTypeException; | |
| 22 | 22 | import org.joda.time.Days; |
| 23 | 23 | import org.joda.time.LocalDate; |
| 24 | 24 | import org.joda.time.format.DateTimeFormat; |
| 25 | 25 | import org.joda.time.format.DateTimeFormatter; |
| 26 | 26 | |
| 27 | -import static org.joda.time.Days.daysBetween; | |
| 28 | - | |
| 29 | -import com.datastax.driver.core.*; | |
| 30 | -import com.datastax.driver.core.exceptions.InvalidTypeException; | |
| 27 | +import java.nio.ByteBuffer; | |
| 31 | 28 | |
| 32 | -import static com.datastax.driver.core.CodecUtils.fromCqlDateToDaysSinceEpoch; | |
| 33 | -import static com.datastax.driver.core.CodecUtils.fromSignedToUnsignedInt; | |
| 34 | -import static com.datastax.driver.core.CodecUtils.fromUnsignedToSignedInt; | |
| 35 | -import static com.datastax.driver.core.ParseUtils.isLongLiteral; | |
| 36 | -import static com.datastax.driver.core.ParseUtils.isQuoted; | |
| 37 | -import static com.datastax.driver.core.ParseUtils.quote; | |
| 38 | -import static com.datastax.driver.core.ParseUtils.unquote; | |
| 29 | +import static com.datastax.driver.core.CodecUtils.*; | |
| 30 | +import static com.datastax.driver.core.ParseUtils.*; | |
| 31 | +import static java.lang.Long.parseLong; | |
| 32 | +import static org.joda.time.Days.daysBetween; | |
| 39 | 33 | |
| 40 | 34 | /** |
| 41 | 35 | * {@link TypeCodec} that maps |
modified driver-extras/src/main/java/com/datastax/driver/extras/codecs/joda/LocalTimeCodec.java +9 −11
| @@ -15,27 +15,25 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.extras.codecs.joda; |
| 17 | 17 | |
| 18 | -import java.nio.ByteBuffer; | |
| 19 | - | |
| 20 | -import static java.util.concurrent.TimeUnit.MILLISECONDS; | |
| 21 | -import static java.util.concurrent.TimeUnit.NANOSECONDS; | |
| 22 | - | |
| 23 | -import org.joda.time.LocalTime; | |
| 24 | -import org.joda.time.format.DateTimeFormat; | |
| 25 | -import org.joda.time.format.DateTimeFormatter; | |
| 26 | - | |
| 27 | 18 | import com.datastax.driver.core.DataType; |
| 28 | 19 | import com.datastax.driver.core.ParseUtils; |
| 29 | 20 | import com.datastax.driver.core.ProtocolVersion; |
| 30 | 21 | import com.datastax.driver.core.TypeCodec; |
| 31 | 22 | import com.datastax.driver.core.exceptions.InvalidTypeException; |
| 23 | +import org.joda.time.LocalTime; | |
| 24 | +import org.joda.time.format.DateTimeFormat; | |
| 25 | +import org.joda.time.format.DateTimeFormatter; | |
| 26 | + | |
| 27 | +import java.nio.ByteBuffer; | |
| 32 | 28 | |
| 33 | 29 | import static com.datastax.driver.core.ParseUtils.quote; |
| 30 | +import static java.util.concurrent.TimeUnit.MILLISECONDS; | |
| 31 | +import static java.util.concurrent.TimeUnit.NANOSECONDS; | |
| 34 | 32 | |
| 35 | 33 | /** |
| 36 | 34 | * {@link TypeCodec} that maps {@link LocalTime} to CQL {@code time} (long representing nanoseconds since midnight). |
| 37 | - * | |
| 38 | - * <p> | |
| 35 | + * <p/> | |
| 36 | + * <p/> | |
| 39 | 37 | * IMPORTANT: {@link LocalTime} has millisecond precision; nanoseconds below one millisecond will be lost |
| 40 | 38 | * during deserialization. |
| 41 | 39 | */ |
modified driver-extras/src/main/java/com/datastax/driver/extras/codecs/joda/package-info.java +3 −4
| @@ -18,12 +18,12 @@ | ||
| 18 | 18 | * This package contains a collection of convenience |
| 19 | 19 | * {@link com.datastax.driver.core.TypeCodec TypeCodec} instances useful for |
| 20 | 20 | * serializing between CQL types and Joda Time types such as {@link org.joda.time.DateTime}. |
| 21 | - * | |
| 22 | - * <p> | |
| 21 | + * <p/> | |
| 22 | + * <p/> | |
| 23 | 23 | * Note that classes in this package require the presence of |
| 24 | 24 | * <a href="http://www.joda.org/joda-time/">Joda Time library</a> at runtime. |
| 25 | 25 | * If you use Maven, this can be done by declaring the following dependency in your project: |
| 26 | - * | |
| 26 | + * <p/> | |
| 27 | 27 | * <pre>{@code |
| 28 | 28 | * <dependency> |
| 29 | 29 | * <groupId>joda-time</groupId> |
| @@ -31,6 +31,5 @@ | ||
| 31 | 31 | * <version>2.9.1</version> |
| 32 | 32 | * </dependency> |
| 33 | 33 | * }</pre> |
| 34 | - * | |
| 35 | 34 | */ |
| 36 | 35 | package com.datastax.driver.extras.codecs.joda; |
modified driver-extras/src/main/java/com/datastax/driver/extras/codecs/json/JacksonJsonCodec.java +15 −16
| @@ -15,34 +15,33 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.extras.codecs.json; |
| 17 | 17 | |
| 18 | -import java.io.IOException; | |
| 19 | -import java.nio.ByteBuffer; | |
| 20 | - | |
| 21 | -import com.fasterxml.jackson.core.JsonProcessingException; | |
| 22 | -import com.fasterxml.jackson.databind.JavaType; | |
| 23 | -import com.fasterxml.jackson.databind.ObjectMapper; | |
| 24 | -import com.fasterxml.jackson.databind.type.TypeFactory; | |
| 25 | - | |
| 26 | 18 | import com.datastax.driver.core.DataType; |
| 27 | 19 | import com.datastax.driver.core.ParseUtils; |
| 28 | 20 | import com.datastax.driver.core.ProtocolVersion; |
| 29 | 21 | import com.datastax.driver.core.TypeCodec; |
| 30 | 22 | import com.datastax.driver.core.exceptions.InvalidTypeException; |
| 31 | 23 | import com.datastax.driver.core.utils.Bytes; |
| 24 | +import com.fasterxml.jackson.core.JsonProcessingException; | |
| 25 | +import com.fasterxml.jackson.databind.JavaType; | |
| 26 | +import com.fasterxml.jackson.databind.ObjectMapper; | |
| 27 | +import com.fasterxml.jackson.databind.type.TypeFactory; | |
| 28 | + | |
| 29 | +import java.io.IOException; | |
| 30 | +import java.nio.ByteBuffer; | |
| 32 | 31 | |
| 33 | 32 | /** |
| 34 | 33 | * A JSON codec that uses the <a href="http://wiki.fasterxml.com/JacksonHome">Jackson</a> |
| 35 | 34 | * library to perform serialization and deserialization of JSON objects. |
| 36 | - * | |
| 37 | - * <p> | |
| 35 | + * <p/> | |
| 36 | + * <p/> | |
| 38 | 37 | * This codec maps a single Java object to a single JSON structure at a time; |
| 39 | 38 | * mapping of arrays or collections to root-level JSON arrays is not supported, |
| 40 | 39 | * but such a codec can be easily crafted after this one. |
| 41 | - * | |
| 42 | - * <p> | |
| 40 | + * <p/> | |
| 41 | + * <p/> | |
| 43 | 42 | * Note that this codec requires the presence of Jackson library at runtime. |
| 44 | 43 | * If you use Maven, this can be done by declaring the following dependency in your project: |
| 45 | - * | |
| 44 | + * <p/> | |
| 46 | 45 | * <pre>{@code |
| 47 | 46 | * <dependency> |
| 48 | 47 | * <groupId>com.fasterxml.jackson.core</groupId> |
| @@ -50,7 +49,6 @@ | ||
| 50 | 49 | * <version>2.6.3</version> |
| 51 | 50 | * </dependency> |
| 52 | 51 | * }</pre> |
| 53 | - * | |
| 54 | 52 | */ |
| 55 | 53 | public class JacksonJsonCodec<T> extends TypeCodec<T> { |
| 56 | 54 | |
| @@ -77,7 +75,7 @@ | ||
| 77 | 75 | if (bytes == null) |
| 78 | 76 | return null; |
| 79 | 77 | try { |
| 80 | - return (T)objectMapper.readValue(Bytes.getArray(bytes), toJacksonJavaType()); | |
| 78 | + return (T) objectMapper.readValue(Bytes.getArray(bytes), toJacksonJavaType()); | |
| 81 | 79 | } catch (IOException e) { |
| 82 | 80 | throw new InvalidTypeException(e.getMessage(), e); |
| 83 | 81 | } |
| @@ -105,7 +103,7 @@ | ||
| 105 | 103 | throw new InvalidTypeException("JSON strings must be enclosed by single quotes"); |
| 106 | 104 | String json = ParseUtils.unquote(value); |
| 107 | 105 | try { |
| 108 | - return (T)objectMapper.readValue(json, toJacksonJavaType()); | |
| 106 | + return (T) objectMapper.readValue(json, toJacksonJavaType()); | |
| 109 | 107 | } catch (IOException e) { |
| 110 | 108 | throw new InvalidTypeException(e.getMessage(), e); |
| 111 | 109 | } |
| @@ -114,6 +112,7 @@ | ||
| 114 | 112 | /** |
| 115 | 113 | * This method acts as a bridge between Guava's {@link com.google.common.reflect.TypeToken TypeToken} API, which is used |
| 116 | 114 | * by the driver, and Jackson's {@link JavaType} API. |
| 115 | + * | |
| 117 | 116 | * @return A {@link JavaType} instance corresponding to the codec's {@link #getJavaType() Java type}. |
| 118 | 117 | */ |
| 119 | 118 | protected JavaType toJacksonJavaType() { |
modified driver-extras/src/main/java/com/datastax/driver/extras/codecs/json/Jsr353JsonCodec.java +13 −15
| @@ -15,12 +15,6 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.extras.codecs.json; |
| 17 | 17 | |
| 18 | -import java.io.*; | |
| 19 | -import java.nio.ByteBuffer; | |
| 20 | -import java.util.Map; | |
| 21 | - | |
| 22 | -import javax.json.*; | |
| 23 | - | |
| 24 | 18 | import com.datastax.driver.core.DataType; |
| 25 | 19 | import com.datastax.driver.core.ParseUtils; |
| 26 | 20 | import com.datastax.driver.core.ProtocolVersion; |
| @@ -28,26 +22,31 @@ | ||
| 28 | 22 | import com.datastax.driver.core.exceptions.InvalidTypeException; |
| 29 | 23 | import com.datastax.driver.core.utils.Bytes; |
| 30 | 24 | |
| 25 | +import javax.json.*; | |
| 26 | +import java.io.*; | |
| 27 | +import java.nio.ByteBuffer; | |
| 28 | +import java.util.Map; | |
| 29 | + | |
| 31 | 30 | /** |
| 32 | 31 | * A JSON codec that uses the |
| 33 | 32 | * <a href="https://jcp.org/en/jsr/detail?id=353">Java API for JSON processing</a> |
| 34 | 33 | * to perform serialization and deserialization of JSON structures. |
| 35 | - * <p> | |
| 34 | + * <p/> | |
| 36 | 35 | * More specifically, this codec maps an arbitrary {@link JsonStructure} to |
| 37 | 36 | * a CQL {@code varchar} column. |
| 38 | - * <p> | |
| 37 | + * <p/> | |
| 39 | 38 | * This codec handles the Java type {@link JsonStructure}. |
| 40 | 39 | * It is therefore required that values are set and retrieved using that exact Java type; |
| 41 | 40 | * users should manually downcast to either {@link JsonObject} or {@link JsonArray}, |
| 42 | 41 | * as in the example below: |
| 43 | 42 | * <pre>{@code |
| 44 | - * | |
| 43 | + * <p/> | |
| 45 | 44 | * // setting values |
| 46 | 45 | * JsonObject myObject = ... |
| 47 | 46 | * PreparedStatement ps = ... |
| 48 | 47 | * // set values using JsonStructure as target Java type |
| 49 | 48 | * BoundStatement bs = ps.bind().set(1, myObject, JsonStructure.class); |
| 50 | - * | |
| 49 | + * <p/> | |
| 51 | 50 | * // retrieving values |
| 52 | 51 | * Row row = session.execute(bs).one(); |
| 53 | 52 | * // use JsonStructure as target Java type to retrieve values |
| @@ -57,27 +56,26 @@ | ||
| 57 | 56 | * ... |
| 58 | 57 | * } |
| 59 | 58 | * }</pre> |
| 60 | - * | |
| 61 | - * <p> | |
| 59 | + * <p/> | |
| 60 | + * <p/> | |
| 62 | 61 | * Note that at runtime, this codec requires the presence of both JSR-353 API |
| 63 | 62 | * and a JSR-353-compatible runtime library, such as |
| 64 | 63 | * <a href="https://jsonp.java.net/download.html">JSR-353's reference implementation</a>. |
| 65 | 64 | * If you use Maven, this can be done by declaring the following dependencies in your project: |
| 66 | - * | |
| 65 | + * <p/> | |
| 67 | 66 | * <pre>{@code |
| 68 | 67 | * <dependency> |
| 69 | 68 | * <groupId>javax.json</groupId> |
| 70 | 69 | * <artifactId>javax.json-api</artifactId> |
| 71 | 70 | * <version>1.0</version> |
| 72 | 71 | * </dependency> |
| 73 | - * | |
| 72 | + * <p/> | |
| 74 | 73 | * <dependency> |
| 75 | 74 | * <groupId>org.glassfish</groupId> |
| 76 | 75 | * <artifactId>javax.json</artifactId> |
| 77 | 76 | * <version>1.0.4</version> |
| 78 | 77 | * </dependency> |
| 79 | 78 | * }</pre> |
| 80 | - * | |
| 81 | 79 | */ |
| 82 | 80 | public class Jsr353JsonCodec extends TypeCodec<JsonStructure> { |
| 83 | 81 |
modified driver-extras/src/main/java/com/datastax/driver/extras/codecs/package-info.java +33 −33
| @@ -16,40 +16,40 @@ | ||
| 16 | 16 | |
| 17 | 17 | /** |
| 18 | 18 | * This package and its subpackages contain several convenience {@link com.datastax.driver.core.TypeCodec TypeCodec}s. |
| 19 | - * | |
| 19 | + * <p/> | |
| 20 | 20 | * <table summary="Supported Mappings"> |
| 21 | - * <tr> | |
| 22 | - * <th>Package</th> | |
| 23 | - * <th>Description</th> | |
| 24 | - * </tr> | |
| 25 | - * <tr> | |
| 26 | - * <td>{@link com.datastax.driver.extras.codecs.arrays}</td> | |
| 27 | - * <td>codecs mapping CQL lists to Java arrays.</td> | |
| 28 | - * </tr> | |
| 29 | - * <tr> | |
| 30 | - * <td>{@link com.datastax.driver.extras.codecs.date}</td> | |
| 31 | - * <td>codecs mapping CQL temporal types to Java primitive types.</td> | |
| 32 | - * </tr> | |
| 33 | - * <tr> | |
| 34 | - * <td>{@link com.datastax.driver.extras.codecs.enums}</td> | |
| 35 | - * <td>codecs mapping CQL types to Java enums.</td> | |
| 36 | - * </tr> | |
| 37 | - * <tr> | |
| 38 | - * <td>{@link com.datastax.driver.extras.codecs.guava}</td> | |
| 39 | - * <td>codecs mapping CQL types to Guava-specific Java types.</td> | |
| 40 | - * </tr> | |
| 41 | - * <tr> | |
| 42 | - * <td>{@link com.datastax.driver.extras.codecs.jdk8}</td> | |
| 43 | - * <td>codecs mapping CQL types to Java 8 types, including {@code java.time} API and {@code java.util.Optional}.</td> | |
| 44 | - * </tr> | |
| 45 | - * <tr> | |
| 46 | - * <td>{@link com.datastax.driver.extras.codecs.joda}</td> | |
| 47 | - * <td>codecs mapping CQL types to Joda Time types.</td> | |
| 48 | - * </tr> | |
| 49 | - * <tr> | |
| 50 | - * <td>{@link com.datastax.driver.extras.codecs.json}</td> | |
| 51 | - * <td>codecs mapping CQL varchars to JSON structures.</td> | |
| 52 | - * </tr> | |
| 21 | + * <tr> | |
| 22 | + * <th>Package</th> | |
| 23 | + * <th>Description</th> | |
| 24 | + * </tr> | |
| 25 | + * <tr> | |
| 26 | + * <td>{@link com.datastax.driver.extras.codecs.arrays}</td> | |
| 27 | + * <td>codecs mapping CQL lists to Java arrays.</td> | |
| 28 | + * </tr> | |
| 29 | + * <tr> | |
| 30 | + * <td>{@link com.datastax.driver.extras.codecs.date}</td> | |
| 31 | + * <td>codecs mapping CQL temporal types to Java primitive types.</td> | |
| 32 | + * </tr> | |
| 33 | + * <tr> | |
| 34 | + * <td>{@link com.datastax.driver.extras.codecs.enums}</td> | |
| 35 | + * <td>codecs mapping CQL types to Java enums.</td> | |
| 36 | + * </tr> | |
| 37 | + * <tr> | |
| 38 | + * <td>{@link com.datastax.driver.extras.codecs.guava}</td> | |
| 39 | + * <td>codecs mapping CQL types to Guava-specific Java types.</td> | |
| 40 | + * </tr> | |
| 41 | + * <tr> | |
| 42 | + * <td>{@link com.datastax.driver.extras.codecs.jdk8}</td> | |
| 43 | + * <td>codecs mapping CQL types to Java 8 types, including {@code java.time} API and {@code java.util.Optional}.</td> | |
| 44 | + * </tr> | |
| 45 | + * <tr> | |
| 46 | + * <td>{@link com.datastax.driver.extras.codecs.joda}</td> | |
| 47 | + * <td>codecs mapping CQL types to Joda Time types.</td> | |
| 48 | + * </tr> | |
| 49 | + * <tr> | |
| 50 | + * <td>{@link com.datastax.driver.extras.codecs.json}</td> | |
| 51 | + * <td>codecs mapping CQL varchars to JSON structures.</td> | |
| 52 | + * </tr> | |
| 53 | 53 | * </table> |
| 54 | 54 | */ |
| 55 | 55 | package com.datastax.driver.extras.codecs; |
modified driver-extras/src/test/java/com/datastax/driver/extras/codecs/arrays/ArrayCodecsTest.java +50 −51
| @@ -15,82 +15,81 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.extras.codecs.arrays; |
| 17 | 17 | |
| 18 | -import java.util.Collection; | |
| 19 | -import java.util.List; | |
| 20 | - | |
| 21 | -import com.google.common.collect.Lists; | |
| 22 | -import com.google.common.primitives.Primitives; | |
| 23 | -import org.testng.annotations.DataProvider; | |
| 24 | -import org.testng.annotations.Test; | |
| 25 | - | |
| 26 | -import static org.assertj.core.api.Assertions.assertThat; | |
| 27 | - | |
| 28 | 18 | import com.datastax.driver.core.*; |
| 29 | 19 | import com.datastax.driver.mapping.Mapper; |
| 30 | 20 | import com.datastax.driver.mapping.MappingManager; |
| 31 | 21 | import com.datastax.driver.mapping.annotations.Column; |
| 32 | 22 | import com.datastax.driver.mapping.annotations.PartitionKey; |
| 33 | 23 | import com.datastax.driver.mapping.annotations.Table; |
| 24 | +import com.google.common.collect.Lists; | |
| 25 | +import com.google.common.primitives.Primitives; | |
| 26 | +import org.testng.annotations.DataProvider; | |
| 27 | +import org.testng.annotations.Test; | |
| 28 | + | |
| 29 | +import java.util.Collection; | |
| 30 | +import java.util.List; | |
| 31 | + | |
| 32 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 34 | 33 | |
| 35 | 34 | public class ArrayCodecsTest extends CCMBridge.PerClassSingleNodeCluster { |
| 36 | 35 | |
| 37 | 36 | private static final ObjectArrayCodec<String> stringArrayCodec = new ObjectArrayCodec<String>( |
| 38 | - DataType.list(DataType.varchar()), | |
| 39 | - String[].class, | |
| 40 | - TypeCodec.varchar()); | |
| 37 | + DataType.list(DataType.varchar()), | |
| 38 | + String[].class, | |
| 39 | + TypeCodec.varchar()); | |
| 41 | 40 | |
| 42 | 41 | @Override |
| 43 | 42 | protected Collection<String> getTableDefinitions() { |
| 44 | 43 | return Lists.newArrayList( |
| 45 | - "CREATE TABLE lists (" | |
| 46 | - + "pk int PRIMARY KEY, " | |
| 47 | - + "l_int list<int>, " | |
| 48 | - + "l_bigint list<bigint>, " | |
| 49 | - + "l_float list<float>, " | |
| 50 | - + "l_double list<double>, " | |
| 51 | - + "l_string list<text> " | |
| 52 | - + ")", | |
| 53 | - "INSERT INTO lists (pk, l_int, l_bigint, l_float, l_double, l_string) VALUES (1, " | |
| 54 | - + "[1, 2, 3], " | |
| 55 | - + "[4, 5, 6], " | |
| 56 | - + "[1.0, 2.0, 3.0], " | |
| 57 | - + "[4.0, 5.0, 6.0], " | |
| 58 | - + "['a', 'b', 'c'] " | |
| 59 | - + ")" | |
| 44 | + "CREATE TABLE lists (" | |
| 45 | + + "pk int PRIMARY KEY, " | |
| 46 | + + "l_int list<int>, " | |
| 47 | + + "l_bigint list<bigint>, " | |
| 48 | + + "l_float list<float>, " | |
| 49 | + + "l_double list<double>, " | |
| 50 | + + "l_string list<text> " | |
| 51 | + + ")", | |
| 52 | + "INSERT INTO lists (pk, l_int, l_bigint, l_float, l_double, l_string) VALUES (1, " | |
| 53 | + + "[1, 2, 3], " | |
| 54 | + + "[4, 5, 6], " | |
| 55 | + + "[1.0, 2.0, 3.0], " | |
| 56 | + + "[4.0, 5.0, 6.0], " | |
| 57 | + + "['a', 'b', 'c'] " | |
| 58 | + + ")" | |
| 60 | 59 | ); |
| 61 | 60 | } |
| 62 | 61 | |
| 63 | 62 | @Override |
| 64 | 63 | protected Cluster.Builder configure(Cluster.Builder builder) { |
| 65 | 64 | return builder.withCodecRegistry( |
| 66 | - new CodecRegistry() | |
| 67 | - .register(IntArrayCodec.instance) | |
| 68 | - .register(LongArrayCodec.instance) | |
| 69 | - .register(FloatArrayCodec.instance) | |
| 70 | - .register(DoubleArrayCodec.instance) | |
| 71 | - .register(stringArrayCodec) | |
| 65 | + new CodecRegistry() | |
| 66 | + .register(IntArrayCodec.instance) | |
| 67 | + .register(LongArrayCodec.instance) | |
| 68 | + .register(FloatArrayCodec.instance) | |
| 69 | + .register(DoubleArrayCodec.instance) | |
| 70 | + .register(stringArrayCodec) | |
| 72 | 71 | ); |
| 73 | 72 | } |
| 74 | 73 | |
| 75 | 74 | @DataProvider(name = "ArrayCodecsTest-serializing") |
| 76 | 75 | public static Object[][] parametersForSerializationTests() { |
| 77 | 76 | return new Object[][]{ |
| 78 | - { "l_int", int[].class, new int[]{ 1, 2, 3 } }, | |
| 79 | - { "l_bigint", long[].class, new long[]{ 4, 5, 6 } }, | |
| 80 | - { "l_float", float[].class, new float[]{ 1, 2, 3 } }, | |
| 81 | - { "l_double", double[].class, new double[]{ 4, 5, 6 } }, | |
| 82 | - { "l_string", String[].class, new String[]{ "a", "b", "c" } } | |
| 77 | + {"l_int", int[].class, new int[]{1, 2, 3}}, | |
| 78 | + {"l_bigint", long[].class, new long[]{4, 5, 6}}, | |
| 79 | + {"l_float", float[].class, new float[]{1, 2, 3}}, | |
| 80 | + {"l_double", double[].class, new double[]{4, 5, 6}}, | |
| 81 | + {"l_string", String[].class, new String[]{"a", "b", "c"}} | |
| 83 | 82 | }; |
| 84 | 83 | } |
| 85 | 84 | |
| 86 | 85 | @DataProvider(name = "ArrayCodecsTest-formatting") |
| 87 | 86 | public static Object[][] parametersForFormattingTests() { |
| 88 | 87 | return new Object[][]{ |
| 89 | - { new IntArrayCodec(), new int[]{ 1, 2, 3 }, new int[0], "[1,2,3]" }, | |
| 90 | - { new LongArrayCodec(), new long[]{ 4, 5, 6 }, new long[0], "[4,5,6]" }, | |
| 91 | - { new FloatArrayCodec(), new float[]{ 1, 2, 3 }, new float[0], "[1.0,2.0,3.0]" }, | |
| 92 | - { new DoubleArrayCodec(), new double[]{ 4, 5, 6 }, new double[0], "[4.0,5.0,6.0]" }, | |
| 93 | - { stringArrayCodec, new String[]{ "a", "b", "c" }, new String[0], "['a','b','c']" } | |
| 88 | + {new IntArrayCodec(), new int[]{1, 2, 3}, new int[0], "[1,2,3]"}, | |
| 89 | + {new LongArrayCodec(), new long[]{4, 5, 6}, new long[0], "[4,5,6]"}, | |
| 90 | + {new FloatArrayCodec(), new float[]{1, 2, 3}, new float[0], "[1.0,2.0,3.0]"}, | |
| 91 | + {new DoubleArrayCodec(), new double[]{4, 5, 6}, new double[0], "[4.0,5.0,6.0]"}, | |
| 92 | + {stringArrayCodec, new String[]{"a", "b", "c"}, new String[0], "['a','b','c']"} | |
| 94 | 93 | }; |
| 95 | 94 | } |
| 96 | 95 | |
| @@ -105,8 +104,8 @@ | ||
| 105 | 104 | public <A> void should_set_list_column_with_array(String columnName, Class<A> arrayClass, A expected) { |
| 106 | 105 | PreparedStatement ps = session.prepare(String.format("INSERT INTO lists (pk, %s) VALUES (?, ?)", columnName)); |
| 107 | 106 | BoundStatement bs = ps.bind() |
| 108 | - .setInt(0, 2) | |
| 109 | - .set(columnName, expected, arrayClass); | |
| 107 | + .setInt(0, 2) | |
| 108 | + .set(columnName, expected, arrayClass); | |
| 110 | 109 | session.execute(bs); |
| 111 | 110 | Row row = session.execute(String.format("SELECT %s FROM lists WHERE pk = 2", columnName)).one(); |
| 112 | 111 | List<?> list = row.getList(columnName, Primitives.wrap(arrayClass.getComponentType())); |
| @@ -166,11 +165,11 @@ | ||
| 166 | 165 | |
| 167 | 166 | public Mapped() { |
| 168 | 167 | pk = 42; |
| 169 | - strings = new String[]{ "a", "b", "c" }; | |
| 170 | - ints = new int[]{ 1, 2, 3 }; | |
| 171 | - longs = new long[]{ 4, 5, 6 }; | |
| 172 | - floats = new float[]{ 1, 2, 3 }; | |
| 173 | - doubles = new double[]{ 4, 5, 6 }; | |
| 168 | + strings = new String[]{"a", "b", "c"}; | |
| 169 | + ints = new int[]{1, 2, 3}; | |
| 170 | + longs = new long[]{4, 5, 6}; | |
| 171 | + floats = new float[]{1, 2, 3}; | |
| 172 | + doubles = new double[]{4, 5, 6}; | |
| 174 | 173 | } |
| 175 | 174 | |
| 176 | 175 | public int getPk() { |
modified driver-extras/src/test/java/com/datastax/driver/extras/codecs/date/SimpleDateCodecTest.java +18 −19
| @@ -15,44 +15,43 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.extras.codecs.date; |
| 17 | 17 | |
| 18 | -import java.text.ParseException; | |
| 19 | - | |
| 20 | -import static java.util.concurrent.TimeUnit.MILLISECONDS; | |
| 21 | - | |
| 22 | 18 | import org.testng.annotations.DataProvider; |
| 23 | 19 | import org.testng.annotations.Test; |
| 24 | 20 | |
| 21 | +import java.text.ParseException; | |
| 22 | + | |
| 25 | 23 | import static com.datastax.driver.core.Assertions.assertThat; |
| 26 | 24 | import static com.datastax.driver.core.CodecUtils.fromCqlDateToDaysSinceEpoch; |
| 27 | 25 | import static com.datastax.driver.core.ParseUtils.parseDate; |
| 28 | 26 | import static com.datastax.driver.core.ProtocolVersion.V4; |
| 27 | +import static java.util.concurrent.TimeUnit.MILLISECONDS; | |
| 29 | 28 | |
| 30 | 29 | public class SimpleDateCodecTest { |
| 31 | 30 | |
| 32 | 31 | @DataProvider(name = "SimpleDateCodecTest.parse") |
| 33 | 32 | public Object[][] parseParameters() throws ParseException { |
| 34 | - int _2014_01_01 = (int)MILLISECONDS.toDays(parseDate("2014-01-01", "yyyy-MM-dd").getTime()); | |
| 33 | + int _2014_01_01 = (int) MILLISECONDS.toDays(parseDate("2014-01-01", "yyyy-MM-dd").getTime()); | |
| 35 | 34 | return new Object[][]{ |
| 36 | - { null , null }, | |
| 37 | - { "" , null }, | |
| 38 | - { "NULL" , null }, | |
| 39 | - { "0" , fromCqlDateToDaysSinceEpoch(0) }, | |
| 40 | - { "'2147483648'" , 0 }, | |
| 41 | - // SimpleDateFormat is unable to parse year -5877641 | |
| 42 | - //{ "'-5877641-06-23'" , fromCqlDateToDaysSinceEpoch(0) }, | |
| 43 | - { "'1970-01-01'" , 0 }, | |
| 44 | - { "'2014-01-01'" , _2014_01_01 } | |
| 35 | + {null, null}, | |
| 36 | + {"", null}, | |
| 37 | + {"NULL", null}, | |
| 38 | + {"0", fromCqlDateToDaysSinceEpoch(0)}, | |
| 39 | + {"'2147483648'", 0}, | |
| 40 | + // SimpleDateFormat is unable to parse year -5877641 | |
| 41 | + //{ "'-5877641-06-23'" , fromCqlDateToDaysSinceEpoch(0) }, | |
| 42 | + {"'1970-01-01'", 0}, | |
| 43 | + {"'2014-01-01'", _2014_01_01} | |
| 45 | 44 | }; |
| 46 | 45 | } |
| 47 | 46 | |
| 48 | 47 | @DataProvider(name = "SimpleDateCodecTest.format") |
| 49 | 48 | public Object[][] formatParameters() throws ParseException { |
| 50 | - int _2014_01_01 = (int)MILLISECONDS.toDays(parseDate("2014-01-01", "yyyy-MM-dd").getTime()); | |
| 49 | + int _2014_01_01 = (int) MILLISECONDS.toDays(parseDate("2014-01-01", "yyyy-MM-dd").getTime()); | |
| 51 | 50 | return new Object[][]{ |
| 52 | - { null , "NULL" }, | |
| 53 | - { fromCqlDateToDaysSinceEpoch(0), "'0'" }, | |
| 54 | - { 0 , "'2147483648'" }, | |
| 55 | - { _2014_01_01 , "'2147499719'" } | |
| 51 | + {null, "NULL"}, | |
| 52 | + {fromCqlDateToDaysSinceEpoch(0), "'0'"}, | |
| 53 | + {0, "'2147483648'"}, | |
| 54 | + {_2014_01_01, "'2147499719'"} | |
| 56 | 55 | }; |
| 57 | 56 | } |
| 58 | 57 |
modified driver-extras/src/test/java/com/datastax/driver/extras/codecs/date/SimpleDateCodecsTest.java +22 −24
| @@ -15,23 +15,21 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.extras.codecs.date; |
| 17 | 17 | |
| 18 | -import java.util.*; | |
| 19 | - | |
| 20 | -import com.google.common.collect.ImmutableMap; | |
| 21 | -import org.testng.annotations.BeforeClass; | |
| 22 | -import org.testng.annotations.Test; | |
| 23 | - | |
| 24 | -import static com.google.common.collect.Lists.newArrayList; | |
| 25 | -import static org.assertj.core.api.Assertions.assertThat; | |
| 26 | - | |
| 27 | 18 | import com.datastax.driver.core.*; |
| 28 | -import com.datastax.driver.core.LocalDate; | |
| 29 | 19 | import com.datastax.driver.core.utils.CassandraVersion; |
| 30 | 20 | import com.datastax.driver.mapping.Mapper; |
| 31 | 21 | import com.datastax.driver.mapping.MappingManager; |
| 32 | 22 | import com.datastax.driver.mapping.annotations.Column; |
| 33 | 23 | import com.datastax.driver.mapping.annotations.PartitionKey; |
| 34 | 24 | import com.datastax.driver.mapping.annotations.Table; |
| 25 | +import com.google.common.collect.ImmutableMap; | |
| 26 | +import org.testng.annotations.BeforeClass; | |
| 27 | +import org.testng.annotations.Test; | |
| 28 | + | |
| 29 | +import java.util.*; | |
| 30 | + | |
| 31 | +import static com.google.common.collect.Lists.newArrayList; | |
| 32 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 35 | 33 | |
| 36 | 34 | @CassandraVersion(major = 2.2) |
| 37 | 35 | public class SimpleDateCodecsTest extends CCMBridge.PerClassSingleNodeCluster { |
| @@ -39,21 +37,21 @@ | ||
| 39 | 37 | @Override |
| 40 | 38 | protected Collection<String> getTableDefinitions() { |
| 41 | 39 | return Collections.singletonList( |
| 42 | - "CREATE TABLE IF NOT EXISTS foo (" | |
| 43 | - + "c1 text PRIMARY KEY, " | |
| 44 | - + "cdate date, " | |
| 45 | - + "ctimestamp timestamp, " | |
| 46 | - + "cdates frozen<list<date>>, " | |
| 47 | - + "ctimestamps frozen<map<text,timestamp>> " | |
| 48 | - + ")"); | |
| 40 | + "CREATE TABLE IF NOT EXISTS foo (" | |
| 41 | + + "c1 text PRIMARY KEY, " | |
| 42 | + + "cdate date, " | |
| 43 | + + "ctimestamp timestamp, " | |
| 44 | + + "cdates frozen<list<date>>, " | |
| 45 | + + "ctimestamps frozen<map<text,timestamp>> " | |
| 46 | + + ")"); | |
| 49 | 47 | } |
| 50 | 48 | |
| 51 | 49 | @BeforeClass(groups = "short") |
| 52 | 50 | public void registerCodecs() throws Exception { |
| 53 | 51 | CodecRegistry codecRegistry = cluster.getConfiguration().getCodecRegistry(); |
| 54 | 52 | codecRegistry |
| 55 | - .register(SimpleDateCodec.instance) | |
| 56 | - .register(SimpleTimestampCodec.instance); | |
| 53 | + .register(SimpleDateCodec.instance) | |
| 54 | + .register(SimpleTimestampCodec.instance); | |
| 57 | 55 | } |
| 58 | 56 | |
| 59 | 57 | |
| @@ -67,7 +65,7 @@ | ||
| 67 | 65 | * @expected_result properly maps. |
| 68 | 66 | * @since 2.2.0 |
| 69 | 67 | */ |
| 70 | - @Test(groups="short") | |
| 68 | + @Test(groups = "short") | |
| 71 | 69 | public void should_map_date_to_days_since_epoch() { |
| 72 | 70 | // given |
| 73 | 71 | int days = 12345; |
| @@ -96,7 +94,7 @@ | ||
| 96 | 94 | * @expected_result properly maps. |
| 97 | 95 | * @since 2.2.0 |
| 98 | 96 | */ |
| 99 | - @Test(groups="short") | |
| 97 | + @Test(groups = "short") | |
| 100 | 98 | public void should_map_timestamp_to_millis_since_epoch() { |
| 101 | 99 | // given |
| 102 | 100 | long millis = new Date().getTime(); |
| @@ -142,17 +140,17 @@ | ||
| 142 | 140 | private int days; |
| 143 | 141 | |
| 144 | 142 | @Column(name = "ctimestamps") |
| 145 | - private Map<String,Long> mapOfMillis; | |
| 143 | + private Map<String, Long> mapOfMillis; | |
| 146 | 144 | |
| 147 | 145 | @Column(name = "cdates") |
| 148 | 146 | private List<Integer> listOfDays; |
| 149 | 147 | |
| 150 | - public Mapped(){ | |
| 148 | + public Mapped() { | |
| 151 | 149 | c1 = "mapper"; |
| 152 | 150 | millis = 123456; |
| 153 | 151 | days = 123; |
| 154 | 152 | mapOfMillis = ImmutableMap.of("foo", 123456L); |
| 155 | - listOfDays = newArrayList(123,456); | |
| 153 | + listOfDays = newArrayList(123, 456); | |
| 156 | 154 | } |
| 157 | 155 | |
| 158 | 156 | public String getC1() { |
modified driver-extras/src/test/java/com/datastax/driver/extras/codecs/date/SimpleTimestampCodecTest.java +15 −15
| @@ -15,11 +15,11 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.extras.codecs.date; |
| 17 | 17 | |
| 18 | -import java.text.ParseException; | |
| 19 | - | |
| 20 | 18 | import org.testng.annotations.DataProvider; |
| 21 | 19 | import org.testng.annotations.Test; |
| 22 | 20 | |
| 21 | +import java.text.ParseException; | |
| 22 | + | |
| 23 | 23 | import static com.datastax.driver.core.Assertions.assertThat; |
| 24 | 24 | import static com.datastax.driver.core.ParseUtils.parseDate; |
| 25 | 25 | import static com.datastax.driver.core.ProtocolVersion.V4; |
| @@ -29,25 +29,25 @@ | ||
| 29 | 29 | @DataProvider(name = "SimpleTimestampCodecTest.parse") |
| 30 | 30 | public Object[][] parseParameters() throws ParseException { |
| 31 | 31 | return new Object[][]{ |
| 32 | - { null , null }, | |
| 33 | - { "" , null }, | |
| 34 | - { "NULL" , null }, | |
| 35 | - { "0" , 0L }, | |
| 36 | - { "'2010-06-30T01:20'" , parseDate("2010-06-30T01:20:00.000Z").getTime() }, | |
| 37 | - { "'2010-06-30T01:20Z'" , parseDate("2010-06-30T01:20:00.000Z").getTime() }, | |
| 38 | - { "'2010-06-30T01:20:47'" , parseDate("2010-06-30T01:20:47.000Z").getTime() }, | |
| 39 | - { "'2010-06-30T01:20:47+01:00'" , parseDate("2010-06-30T00:20:47.000Z").getTime() }, | |
| 40 | - { "'2010-06-30T01:20:47.999'" , parseDate("2010-06-30T01:20:47.999Z").getTime() }, | |
| 41 | - { "'2010-06-30T01:20:47.999+01:00'" , parseDate("2010-06-30T00:20:47.999Z").getTime() } | |
| 32 | + {null, null}, | |
| 33 | + {"", null}, | |
| 34 | + {"NULL", null}, | |
| 35 | + {"0", 0L}, | |
| 36 | + {"'2010-06-30T01:20'", parseDate("2010-06-30T01:20:00.000Z").getTime()}, | |
| 37 | + {"'2010-06-30T01:20Z'", parseDate("2010-06-30T01:20:00.000Z").getTime()}, | |
| 38 | + {"'2010-06-30T01:20:47'", parseDate("2010-06-30T01:20:47.000Z").getTime()}, | |
| 39 | + {"'2010-06-30T01:20:47+01:00'", parseDate("2010-06-30T00:20:47.000Z").getTime()}, | |
| 40 | + {"'2010-06-30T01:20:47.999'", parseDate("2010-06-30T01:20:47.999Z").getTime()}, | |
| 41 | + {"'2010-06-30T01:20:47.999+01:00'", parseDate("2010-06-30T00:20:47.999Z").getTime()} | |
| 42 | 42 | }; |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | @DataProvider(name = "SimpleTimestampCodecTest.format") |
| 46 | 46 | public Object[][] formatParameters() throws ParseException { |
| 47 | 47 | return new Object[][]{ |
| 48 | - { null , "NULL" }, | |
| 49 | - { 0L , "'0'" }, | |
| 50 | - { 123456L, "'123456'" } | |
| 48 | + {null, "NULL"}, | |
| 49 | + {0L, "'0'"}, | |
| 50 | + {123456L, "'123456'"} | |
| 51 | 51 | }; |
| 52 | 52 | } |
| 53 | 53 |
modified driver-extras/src/test/java/com/datastax/driver/extras/codecs/enums/EnumCodecsTest.java +60 −53
| @@ -15,25 +15,20 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.extras.codecs.enums; |
| 17 | 17 | |
| 18 | -import java.util.Collection; | |
| 19 | -import java.util.List; | |
| 20 | -import java.util.Map; | |
| 21 | -import java.util.Set; | |
| 22 | - | |
| 23 | -import com.google.common.collect.ImmutableMap; | |
| 24 | -import com.google.common.reflect.TypeToken; | |
| 25 | -import org.testng.annotations.BeforeMethod; | |
| 26 | -import org.testng.annotations.Test; | |
| 27 | - | |
| 28 | -import static com.google.common.collect.Lists.newArrayList; | |
| 29 | -import static com.google.common.collect.Sets.newHashSet; | |
| 30 | -import static org.assertj.core.api.Assertions.assertThat; | |
| 31 | - | |
| 32 | 18 | import com.datastax.driver.core.*; |
| 33 | 19 | import com.datastax.driver.core.utils.CassandraVersion; |
| 34 | 20 | import com.datastax.driver.mapping.Mapper; |
| 35 | 21 | import com.datastax.driver.mapping.MappingManager; |
| 36 | 22 | import com.datastax.driver.mapping.annotations.*; |
| 23 | +import com.google.common.collect.ImmutableMap; | |
| 24 | +import com.google.common.reflect.TypeToken; | |
| 25 | +import org.testng.annotations.BeforeMethod; | |
| 26 | +import org.testng.annotations.Test; | |
| 27 | + | |
| 28 | +import java.util.Collection; | |
| 29 | +import java.util.List; | |
| 30 | +import java.util.Map; | |
| 31 | +import java.util.Set; | |
| 37 | 32 | |
| 38 | 33 | import static com.datastax.driver.core.DataType.cint; |
| 39 | 34 | import static com.datastax.driver.core.DataType.text; |
| @@ -41,13 +36,16 @@ | ||
| 41 | 36 | import static com.datastax.driver.extras.codecs.enums.EnumCodecsTest.Bar.BAR_2; |
| 42 | 37 | import static com.datastax.driver.extras.codecs.enums.EnumCodecsTest.Foo.FOO_1; |
| 43 | 38 | import static com.datastax.driver.extras.codecs.enums.EnumCodecsTest.Foo.FOO_2; |
| 39 | +import static com.google.common.collect.Lists.newArrayList; | |
| 40 | +import static com.google.common.collect.Sets.newHashSet; | |
| 41 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 44 | 42 | |
| 45 | 43 | /** |
| 46 | 44 | * A test that validates that Enums are correctly mapped to varchars (with EnumNameCodec) |
| 47 | 45 | * and ints (with EnumOrdinalCodec). |
| 48 | 46 | * It also validates that both codecs may coexist in the same CodecRegistry. |
| 49 | 47 | */ |
| 50 | -@CassandraVersion(major=2.1) | |
| 48 | +@CassandraVersion(major = 2.1) | |
| 51 | 49 | public class EnumCodecsTest extends CCMBridge.PerClassSingleNodeCluster { |
| 52 | 50 | |
| 53 | 51 | private final String insertQuery = "INSERT INTO t1 (pk, foo, foos, bar, bars, foobars, tup, udt) VALUES (?, ?, ?, ?, ?, ?, ?, ?)"; |
| @@ -65,41 +63,41 @@ | ||
| 65 | 63 | @Override |
| 66 | 64 | protected Collection<String> getTableDefinitions() { |
| 67 | 65 | return newArrayList( |
| 68 | - "CREATE TYPE IF NOT EXISTS udt1 (" | |
| 69 | - + "foo int," | |
| 70 | - + "bar text)", | |
| 71 | - "CREATE TABLE IF NOT EXISTS t1 (" | |
| 72 | - + "pk int, " | |
| 73 | - + "foo int, " | |
| 74 | - + "foos list<int>, " | |
| 75 | - + "bar text, " | |
| 76 | - + "bars set<text>, " | |
| 77 | - + "foobars map<int,text>, " | |
| 78 | - + "tup frozen<tuple<int,varchar>>, " | |
| 79 | - + "udt frozen<udt1>," | |
| 80 | - + "primary key (pk, foo))" | |
| 66 | + "CREATE TYPE IF NOT EXISTS udt1 (" | |
| 67 | + + "foo int," | |
| 68 | + + "bar text)", | |
| 69 | + "CREATE TABLE IF NOT EXISTS t1 (" | |
| 70 | + + "pk int, " | |
| 71 | + + "foo int, " | |
| 72 | + + "foos list<int>, " | |
| 73 | + + "bar text, " | |
| 74 | + + "bars set<text>, " | |
| 75 | + + "foobars map<int,text>, " | |
| 76 | + + "tup frozen<tuple<int,varchar>>, " | |
| 77 | + + "udt frozen<udt1>," | |
| 78 | + + "primary key (pk, foo))" | |
| 81 | 79 | ); |
| 82 | 80 | } |
| 83 | 81 | |
| 84 | 82 | @Override |
| 85 | 83 | protected Cluster.Builder configure(Cluster.Builder builder) { |
| 86 | 84 | return builder.withCodecRegistry( |
| 87 | - new CodecRegistry() | |
| 88 | - .register(new EnumOrdinalCodec<Foo>(Foo.class)) | |
| 89 | - .register(new EnumNameCodec<Bar>(Bar.class)) | |
| 85 | + new CodecRegistry() | |
| 86 | + .register(new EnumOrdinalCodec<Foo>(Foo.class)) | |
| 87 | + .register(new EnumNameCodec<Bar>(Bar.class)) | |
| 90 | 88 | ); |
| 91 | 89 | } |
| 92 | 90 | |
| 93 | - @BeforeMethod(groups="short") | |
| 91 | + @BeforeMethod(groups = "short") | |
| 94 | 92 | public void before() { |
| 95 | 93 | TupleType tup = cluster.getMetadata().newTupleType(cint(), text()); |
| 96 | 94 | tupleValue = tup.newValue() |
| 97 | - .set(0, FOO_1, Foo.class) | |
| 98 | - .set(1, BAR_1, Bar.class); | |
| 95 | + .set(0, FOO_1, Foo.class) | |
| 96 | + .set(1, BAR_1, Bar.class); | |
| 99 | 97 | UserType udt = cluster.getMetadata().getKeyspace(keyspace).getUserType("udt1"); |
| 100 | 98 | udtValue = udt.newValue() |
| 101 | - .set("foo", FOO_1, Foo.class) | |
| 102 | - .set("bar", BAR_1, Bar.class); | |
| 99 | + .set("foo", FOO_1, Foo.class) | |
| 100 | + .set("bar", BAR_1, Bar.class); | |
| 103 | 101 | } |
| 104 | 102 | |
| 105 | 103 | @Test(groups = "short") |
| @@ -122,18 +120,19 @@ | ||
| 122 | 120 | @Test(groups = "short") |
| 123 | 121 | public void should_use_enum_codecs_with_prepared_statements_2() { |
| 124 | 122 | session.execute(session.prepare(insertQuery).bind() |
| 125 | - .setInt(0, pk) | |
| 126 | - .set(1, FOO_1, Foo.class) | |
| 127 | - .setList(2, foos, Foo.class) | |
| 128 | - .set(3, BAR_1, Bar.class) | |
| 129 | - .set(4, bars, new TypeToken<Set<Bar>>(){}) | |
| 130 | - .setMap(5, foobars, Foo.class, Bar.class) | |
| 131 | - .setTupleValue(6, tupleValue) | |
| 132 | - .setUDTValue(7, udtValue) | |
| 123 | + .setInt(0, pk) | |
| 124 | + .set(1, FOO_1, Foo.class) | |
| 125 | + .setList(2, foos, Foo.class) | |
| 126 | + .set(3, BAR_1, Bar.class) | |
| 127 | + .set(4, bars, new TypeToken<Set<Bar>>() { | |
| 128 | + }) | |
| 129 | + .setMap(5, foobars, Foo.class, Bar.class) | |
| 130 | + .setTupleValue(6, tupleValue) | |
| 131 | + .setUDTValue(7, udtValue) | |
| 133 | 132 | ); |
| 134 | 133 | PreparedStatement ps = session.prepare(selectQuery); |
| 135 | 134 | ResultSet rows = session.execute(ps.bind() |
| 136 | - .setInt(0, pk) | |
| 135 | + .setInt(0, pk) | |
| 137 | 136 | ); |
| 138 | 137 | Row row = rows.one(); |
| 139 | 138 | assertRow(row); |
| @@ -200,8 +199,10 @@ | ||
| 200 | 199 | assertThat(row.getObject(2)).isEqualTo(newArrayList(FOO_1.ordinal(), FOO_2.ordinal())); // uses the built-in ListCodec(IntCodec) because CQL type is list<int> |
| 201 | 200 | assertThat(row.getList(2, Integer.class)).isEqualTo(newArrayList(FOO_1.ordinal(), FOO_2.ordinal())); |
| 202 | 201 | assertThat(row.getList("foos", Foo.class)).isEqualTo(newArrayList(FOO_1, FOO_2)); |
| 203 | - assertThat(row.get(2, new TypeToken<List<Integer>>(){})).isEqualTo(newArrayList(FOO_1.ordinal(), FOO_2.ordinal())); | |
| 204 | - assertThat(row.get("foos", new TypeToken<List<Foo>>(){})).isEqualTo(newArrayList(FOO_1, FOO_2)); | |
| 202 | + assertThat(row.get(2, new TypeToken<List<Integer>>() { | |
| 203 | + })).isEqualTo(newArrayList(FOO_1.ordinal(), FOO_2.ordinal())); | |
| 204 | + assertThat(row.get("foos", new TypeToken<List<Foo>>() { | |
| 205 | + })).isEqualTo(newArrayList(FOO_1, FOO_2)); | |
| 205 | 206 | |
| 206 | 207 | assertThat(row.getObject(3)).isEqualTo(BAR_1.name()); // uses the built-in VarcharCodec because CQL type is varchar |
| 207 | 208 | assertThat(row.getString("bar")).isEqualTo(BAR_1.name()); // forces VarcharCodec |
| @@ -211,8 +212,10 @@ | ||
| 211 | 212 | assertThat(row.getObject(4)).isEqualTo(newHashSet(BAR_1.name(), BAR_2.name())); // uses the built-in SetCodec(VarcharCodec) because CQL type is set<varchar> |
| 212 | 213 | assertThat(row.getSet(4, String.class)).isEqualTo(newHashSet(BAR_1.name(), BAR_2.name())); |
| 213 | 214 | assertThat(row.getSet("bars", Bar.class)).isEqualTo(newHashSet(BAR_1, BAR_2)); |
| 214 | - assertThat(row.get(4, new TypeToken<Set<String>>(){})).isEqualTo(newHashSet(BAR_1.name(), BAR_2.name())); | |
| 215 | - assertThat(row.get("bars", new TypeToken<Set<Bar>>(){})).isEqualTo(newHashSet(BAR_1, BAR_2)); | |
| 215 | + assertThat(row.get(4, new TypeToken<Set<String>>() { | |
| 216 | + })).isEqualTo(newHashSet(BAR_1.name(), BAR_2.name())); | |
| 217 | + assertThat(row.get("bars", new TypeToken<Set<Bar>>() { | |
| 218 | + })).isEqualTo(newHashSet(BAR_1, BAR_2)); | |
| 216 | 219 | |
| 217 | 220 | // uses default built-in codec MapCodec(IntCodec, VarcharCodec) because CQL type is map<int, varchar> |
| 218 | 221 | assertThat(row.getObject(5)).isEqualTo(ImmutableMap.of(FOO_1.ordinal(), BAR_1.name(), FOO_2.ordinal(), BAR_2.name())); |
| @@ -224,10 +227,14 @@ | ||
| 224 | 227 | assertThat(row.getMap(5, Foo.class, Bar.class)).isEqualTo(ImmutableMap.of(FOO_1, BAR_1, FOO_2, BAR_2)); |
| 225 | 228 | |
| 226 | 229 | // get + TypeToken with combinations of built-in or EnumX codecs |
| 227 | - assertThat(row.get("foobars", new TypeToken<Map<Integer, String>>(){})).isEqualTo(ImmutableMap.of(FOO_1.ordinal(), BAR_1.name(), FOO_2.ordinal(), BAR_2.name())); | |
| 228 | - assertThat(row.get("foobars", new TypeToken<Map<Foo, String>>(){})).isEqualTo(ImmutableMap.of(FOO_1, BAR_1.name(), FOO_2, BAR_2.name())); | |
| 229 | - assertThat(row.get("foobars", new TypeToken<Map<Integer, Bar>>(){})).isEqualTo(ImmutableMap.of(FOO_1.ordinal(), BAR_1, FOO_2.ordinal(), BAR_2)); | |
| 230 | - assertThat(row.get("foobars", new TypeToken<Map<Foo, Bar>>(){})).isEqualTo(ImmutableMap.of(FOO_1, BAR_1, FOO_2, BAR_2)); | |
| 230 | + assertThat(row.get("foobars", new TypeToken<Map<Integer, String>>() { | |
| 231 | + })).isEqualTo(ImmutableMap.of(FOO_1.ordinal(), BAR_1.name(), FOO_2.ordinal(), BAR_2.name())); | |
| 232 | + assertThat(row.get("foobars", new TypeToken<Map<Foo, String>>() { | |
| 233 | + })).isEqualTo(ImmutableMap.of(FOO_1, BAR_1.name(), FOO_2, BAR_2.name())); | |
| 234 | + assertThat(row.get("foobars", new TypeToken<Map<Integer, Bar>>() { | |
| 235 | + })).isEqualTo(ImmutableMap.of(FOO_1.ordinal(), BAR_1, FOO_2.ordinal(), BAR_2)); | |
| 236 | + assertThat(row.get("foobars", new TypeToken<Map<Foo, Bar>>() { | |
| 237 | + })).isEqualTo(ImmutableMap.of(FOO_1, BAR_1, FOO_2, BAR_2)); | |
| 231 | 238 | |
| 232 | 239 | assertThat(row.getTupleValue(6).getInt(0)).isEqualTo(FOO_1.ordinal()); |
| 233 | 240 | assertThat(row.get(6, TupleValue.class).get(0, Foo.class)).isEqualTo(FOO_1); |
modified driver-extras/src/test/java/com/datastax/driver/extras/codecs/guava/OptionalCodecTest.java +17 −25
| @@ -15,31 +15,23 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.extras.codecs.guava; |
| 17 | 17 | |
| 18 | -import java.math.BigDecimal; | |
| 19 | -import java.util.Collection; | |
| 20 | -import java.util.Collections; | |
| 21 | -import java.util.List; | |
| 22 | - | |
| 18 | +import com.datastax.driver.core.*; | |
| 19 | +import com.datastax.driver.core.CCMBridge.PerClassSingleNodeCluster; | |
| 20 | +import com.datastax.driver.core.querybuilder.BuiltStatement; | |
| 21 | +import com.datastax.driver.core.utils.CassandraVersion; | |
| 23 | 22 | import com.google.common.base.Optional; |
| 24 | 23 | import com.google.common.collect.Lists; |
| 25 | 24 | import org.testng.annotations.BeforeMethod; |
| 26 | 25 | import org.testng.annotations.Test; |
| 27 | 26 | |
| 28 | -import static org.assertj.core.api.Assertions.assertThat; | |
| 29 | - | |
| 30 | -import com.datastax.driver.core.*; | |
| 31 | -import com.datastax.driver.core.CCMBridge.PerClassSingleNodeCluster; | |
| 32 | -import com.datastax.driver.core.querybuilder.BuiltStatement; | |
| 33 | -import com.datastax.driver.core.utils.CassandraVersion; | |
| 27 | +import java.math.BigDecimal; | |
| 28 | +import java.util.Collection; | |
| 29 | +import java.util.Collections; | |
| 30 | +import java.util.List; | |
| 34 | 31 | |
| 35 | -import static com.datastax.driver.core.TypeCodec.bigint; | |
| 36 | -import static com.datastax.driver.core.TypeCodec.decimal; | |
| 37 | -import static com.datastax.driver.core.TypeCodec.list; | |
| 38 | -import static com.datastax.driver.core.TypeCodec.varchar; | |
| 39 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.bindMarker; | |
| 40 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; | |
| 41 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.insertInto; | |
| 42 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.select; | |
| 32 | +import static com.datastax.driver.core.TypeCodec.*; | |
| 33 | +import static com.datastax.driver.core.querybuilder.QueryBuilder.*; | |
| 34 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 43 | 35 | |
| 44 | 36 | public class OptionalCodecTest extends PerClassSingleNodeCluster { |
| 45 | 37 | |
| @@ -79,8 +71,8 @@ | ||
| 79 | 71 | * @jira_ticket JAVA-846 |
| 80 | 72 | * @since 2.2.0 |
| 81 | 73 | */ |
| 82 | - @Test(groups="short") | |
| 83 | - @CassandraVersion(major=2.2) | |
| 74 | + @Test(groups = "short") | |
| 75 | + @CassandraVersion(major = 2.2) | |
| 84 | 76 | public void should_map_unset_value_to_absent() { |
| 85 | 77 | PreparedStatement insertPrep = session.prepare(this.insertStmt); |
| 86 | 78 | PreparedStatement selectPrep = session.prepare(this.selectStmt); |
| @@ -109,7 +101,7 @@ | ||
| 109 | 101 | * @jira_ticket JAVA-846 |
| 110 | 102 | * @since 2.2.0 |
| 111 | 103 | */ |
| 112 | - @Test(groups="short") | |
| 104 | + @Test(groups = "short") | |
| 113 | 105 | public void should_map_absent_null_value_to_absent() { |
| 114 | 106 | PreparedStatement insertPrep = session.prepare(this.insertStmt); |
| 115 | 107 | PreparedStatement selectPrep = session.prepare(this.selectStmt); |
| @@ -141,7 +133,7 @@ | ||
| 141 | 133 | * @jira_ticket JAVA-846 |
| 142 | 134 | * @since 2.2.0 |
| 143 | 135 | */ |
| 144 | - @Test(groups="short") | |
| 136 | + @Test(groups = "short") | |
| 145 | 137 | public void should_map_some_back_to_itself() { |
| 146 | 138 | PreparedStatement insertPrep = session.prepare(this.insertStmt); |
| 147 | 139 | PreparedStatement selectPrep = session.prepare(this.selectStmt); |
| @@ -169,7 +161,7 @@ | ||
| 169 | 161 | assertThat(returnData.get()).isEqualTo(data); |
| 170 | 162 | } |
| 171 | 163 | |
| 172 | - @Test(groups="short") | |
| 164 | + @Test(groups = "short") | |
| 173 | 165 | public void should_map_a_primitive_type_to_absent() { |
| 174 | 166 | OptionalCodec<Long> optionalLongCodec = new OptionalCodec<Long>(bigint()); |
| 175 | 167 | cluster.getConfiguration().getCodecRegistry().register(optionalLongCodec); |
| @@ -193,7 +185,7 @@ | ||
| 193 | 185 | assertThat(row.get("c4", Long.class)).isNull(); |
| 194 | 186 | } |
| 195 | 187 | |
| 196 | - @Test(groups="short") | |
| 188 | + @Test(groups = "short") | |
| 197 | 189 | public void should_map_a_nullable_type_to_absent() { |
| 198 | 190 | OptionalCodec<BigDecimal> optionalDecimalCodec = new OptionalCodec<BigDecimal>(decimal()); |
| 199 | 191 | cluster.getConfiguration().getCodecRegistry().register(optionalDecimalCodec); |
modified driver-extras/src/test/java/com/datastax/driver/extras/codecs/jdk8/InstantCodecTest.java +18 −20
| @@ -15,43 +15,41 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.extras.codecs.jdk8; |
| 17 | 17 | |
| 18 | -import java.time.Instant; | |
| 19 | -import java.time.ZonedDateTime; | |
| 20 | - | |
| 18 | +import com.datastax.driver.core.Assertions; | |
| 21 | 19 | import org.testng.annotations.DataProvider; |
| 22 | 20 | import org.testng.annotations.Test; |
| 23 | 21 | |
| 24 | -import static org.assertj.core.api.Assertions.assertThat; | |
| 25 | - | |
| 26 | -import com.datastax.driver.core.Assertions; | |
| 22 | +import java.time.Instant; | |
| 23 | +import java.time.ZonedDateTime; | |
| 27 | 24 | |
| 28 | 25 | import static com.datastax.driver.core.ProtocolVersion.V4; |
| 26 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 29 | 27 | |
| 30 | 28 | public class InstantCodecTest { |
| 31 | 29 | |
| 32 | 30 | @DataProvider(name = "InstantCodecTest.parse") |
| 33 | 31 | public Object[][] parseParameters() { |
| 34 | 32 | return new Object[][]{ |
| 35 | - { null , null }, | |
| 36 | - { "" , null }, | |
| 37 | - { "NULL" , null }, | |
| 38 | - { "0" , Instant.ofEpochMilli(0) }, | |
| 39 | - { "1277860847999" , Instant.ofEpochMilli(1277860847999L) }, | |
| 40 | - { "'2010-06-30T01:20'" , Instant.parse("2010-06-30T01:20:00.000Z") }, | |
| 41 | - { "'2010-06-30T01:20Z'" , Instant.parse("2010-06-30T01:20:00.000Z") }, | |
| 42 | - { "'2010-06-30T01:20:47'" , Instant.parse("2010-06-30T01:20:47.000Z") }, | |
| 43 | - { "'2010-06-30T01:20:47+01:00'" , Instant.parse("2010-06-30T00:20:47.000Z") }, | |
| 44 | - { "'2010-06-30T01:20:47.999'" , Instant.parse("2010-06-30T01:20:47.999Z") }, | |
| 45 | - { "'2010-06-30T01:20:47.999+01:00'" , Instant.parse("2010-06-30T00:20:47.999Z") } | |
| 33 | + {null, null}, | |
| 34 | + {"", null}, | |
| 35 | + {"NULL", null}, | |
| 36 | + {"0", Instant.ofEpochMilli(0)}, | |
| 37 | + {"1277860847999", Instant.ofEpochMilli(1277860847999L)}, | |
| 38 | + {"'2010-06-30T01:20'", Instant.parse("2010-06-30T01:20:00.000Z")}, | |
| 39 | + {"'2010-06-30T01:20Z'", Instant.parse("2010-06-30T01:20:00.000Z")}, | |
| 40 | + {"'2010-06-30T01:20:47'", Instant.parse("2010-06-30T01:20:47.000Z")}, | |
| 41 | + {"'2010-06-30T01:20:47+01:00'", Instant.parse("2010-06-30T00:20:47.000Z")}, | |
| 42 | + {"'2010-06-30T01:20:47.999'", Instant.parse("2010-06-30T01:20:47.999Z")}, | |
| 43 | + {"'2010-06-30T01:20:47.999+01:00'", Instant.parse("2010-06-30T00:20:47.999Z")} | |
| 46 | 44 | }; |
| 47 | 45 | } |
| 48 | 46 | |
| 49 | 47 | @DataProvider(name = "InstantCodecTest.format") |
| 50 | 48 | public Object[][] formatParameters() { |
| 51 | 49 | return new Object[][]{ |
| 52 | - { null , "NULL" }, | |
| 53 | - { Instant.ofEpochMilli(0) , "'1970-01-01T00:00:00.000+00:00'" }, | |
| 54 | - { ZonedDateTime.parse("2010-06-30T02:20:47.999+01:00").toInstant(), "'2010-06-30T01:20:47.999+00:00'" } | |
| 50 | + {null, "NULL"}, | |
| 51 | + {Instant.ofEpochMilli(0), "'1970-01-01T00:00:00.000+00:00'"}, | |
| 52 | + {ZonedDateTime.parse("2010-06-30T02:20:47.999+01:00").toInstant(), "'2010-06-30T01:20:47.999+00:00'"} | |
| 55 | 53 | }; |
| 56 | 54 | } |
| 57 | 55 |
modified driver-extras/src/test/java/com/datastax/driver/extras/codecs/jdk8/Jdk8TimeCodecsTest.java +32 −34
| @@ -15,20 +15,6 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.extras.codecs.jdk8; |
| 17 | 17 | |
| 18 | -import java.time.Instant; | |
| 19 | -import java.time.LocalDate; | |
| 20 | -import java.time.LocalTime; | |
| 21 | -import java.time.ZonedDateTime; | |
| 22 | -import java.util.*; | |
| 23 | - | |
| 24 | -import com.google.common.collect.ImmutableMap; | |
| 25 | -import org.testng.annotations.BeforeClass; | |
| 26 | -import org.testng.annotations.Test; | |
| 27 | - | |
| 28 | -import static com.google.common.collect.Lists.newArrayList; | |
| 29 | -import static com.google.common.collect.Sets.newHashSet; | |
| 30 | -import static org.assertj.core.api.Assertions.assertThat; | |
| 31 | - | |
| 32 | 18 | import com.datastax.driver.core.*; |
| 33 | 19 | import com.datastax.driver.core.utils.CassandraVersion; |
| 34 | 20 | import com.datastax.driver.mapping.Mapper; |
| @@ -36,27 +22,39 @@ | ||
| 36 | 22 | import com.datastax.driver.mapping.annotations.Column; |
| 37 | 23 | import com.datastax.driver.mapping.annotations.PartitionKey; |
| 38 | 24 | import com.datastax.driver.mapping.annotations.Table; |
| 25 | +import com.google.common.collect.ImmutableMap; | |
| 26 | +import org.testng.annotations.BeforeClass; | |
| 27 | +import org.testng.annotations.Test; | |
| 28 | + | |
| 29 | +import java.time.Instant; | |
| 30 | +import java.time.LocalDate; | |
| 31 | +import java.time.LocalTime; | |
| 32 | +import java.time.ZonedDateTime; | |
| 33 | +import java.util.*; | |
| 39 | 34 | |
| 40 | 35 | import static com.datastax.driver.core.DataType.timestamp; |
| 41 | 36 | import static com.datastax.driver.core.DataType.varchar; |
| 37 | +import static com.google.common.collect.Lists.newArrayList; | |
| 38 | +import static com.google.common.collect.Sets.newHashSet; | |
| 39 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 42 | 40 | |
| 43 | -@CassandraVersion(major=2.2) | |
| 41 | +@CassandraVersion(major = 2.2) | |
| 44 | 42 | public class Jdk8TimeCodecsTest extends CCMBridge.PerClassSingleNodeCluster { |
| 45 | 43 | |
| 46 | 44 | @Override |
| 47 | 45 | protected Collection<String> getTableDefinitions() { |
| 48 | 46 | return Collections.singletonList( |
| 49 | 47 | "CREATE TABLE IF NOT EXISTS foo (" |
| 50 | - + "c1 text PRIMARY KEY, " | |
| 51 | - + "cdate date, " | |
| 52 | - + "ctime time, " | |
| 53 | - + "ctimestamp timestamp, " | |
| 54 | - + "ctuple tuple<timestamp,varchar>, " | |
| 55 | - + "cdates frozen<list<date>>, " | |
| 56 | - + "ctimes frozen<set<time>>, " | |
| 57 | - + "ctimestamps frozen<map<text,timestamp>>, " | |
| 58 | - + "ctuples frozen<map<tuple<timestamp,varchar>,varchar>>" | |
| 59 | - + ")"); | |
| 48 | + + "c1 text PRIMARY KEY, " | |
| 49 | + + "cdate date, " | |
| 50 | + + "ctime time, " | |
| 51 | + + "ctimestamp timestamp, " | |
| 52 | + + "ctuple tuple<timestamp,varchar>, " | |
| 53 | + + "cdates frozen<list<date>>, " | |
| 54 | + + "ctimes frozen<set<time>>, " | |
| 55 | + + "ctimestamps frozen<map<text,timestamp>>, " | |
| 56 | + + "ctuples frozen<map<tuple<timestamp,varchar>,varchar>>" | |
| 57 | + + ")"); | |
| 60 | 58 | } |
| 61 | 59 | |
| 62 | 60 | @BeforeClass(groups = "short") |
| @@ -64,10 +62,10 @@ | ||
| 64 | 62 | TupleType dateWithTimeZoneType = cluster.getMetadata().newTupleType(timestamp(), varchar()); |
| 65 | 63 | CodecRegistry codecRegistry = cluster.getConfiguration().getCodecRegistry(); |
| 66 | 64 | codecRegistry |
| 67 | - .register(LocalTimeCodec.instance) | |
| 68 | - .register(LocalDateCodec.instance) | |
| 69 | - .register(InstantCodec.instance) | |
| 70 | - .register(new ZonedDateTimeCodec(dateWithTimeZoneType)); | |
| 65 | + .register(LocalTimeCodec.instance) | |
| 66 | + .register(LocalDateCodec.instance) | |
| 67 | + .register(InstantCodec.instance) | |
| 68 | + .register(new ZonedDateTimeCodec(dateWithTimeZoneType)); | |
| 71 | 69 | } |
| 72 | 70 | |
| 73 | 71 | /** |
| @@ -81,7 +79,7 @@ | ||
| 81 | 79 | * @jira_ticket JAVA-606 |
| 82 | 80 | * @since 2.2.0 |
| 83 | 81 | */ |
| 84 | - @Test(groups="short") | |
| 82 | + @Test(groups = "short") | |
| 85 | 83 | public void should_map_time_to_localtime() { |
| 86 | 84 | // given |
| 87 | 85 | LocalTime time = LocalTime.of(12, 16, 34, 999); |
| @@ -106,7 +104,7 @@ | ||
| 106 | 104 | * @jira_ticket JAVA-606 |
| 107 | 105 | * @since 2.2.0 |
| 108 | 106 | */ |
| 109 | - @Test(groups="short") | |
| 107 | + @Test(groups = "short") | |
| 110 | 108 | public void should_map_date_to_localdate() { |
| 111 | 109 | // given |
| 112 | 110 | LocalDate localDate = LocalDate.of(2015, 1, 1); |
| @@ -132,7 +130,7 @@ | ||
| 132 | 130 | * @jira_ticket JAVA-606 |
| 133 | 131 | * @since 2.2.0 |
| 134 | 132 | */ |
| 135 | - @Test(groups="short") | |
| 133 | + @Test(groups = "short") | |
| 136 | 134 | public void should_map_timestamp_to_instant() { |
| 137 | 135 | // given |
| 138 | 136 | Instant instant = Instant.parse("2010-06-30T01:20:30Z"); |
| @@ -157,7 +155,7 @@ | ||
| 157 | 155 | * @jira_ticket JAVA-606 |
| 158 | 156 | * @since 2.2.0 |
| 159 | 157 | */ |
| 160 | - @Test(groups="short") | |
| 158 | + @Test(groups = "short") | |
| 161 | 159 | public void should_map_tuple_to_zoneddatetime() { |
| 162 | 160 | // given |
| 163 | 161 | ZonedDateTime expected = ZonedDateTime.parse("2010-06-30T01:20+05:30"); |
| @@ -176,7 +174,7 @@ | ||
| 176 | 174 | assertThat(actual.getZone()).isEqualTo(expected.getZone()); |
| 177 | 175 | } |
| 178 | 176 | |
| 179 | - @Test(groups="short") | |
| 177 | + @Test(groups = "short") | |
| 180 | 178 | public void should_use_mapper_to_store_and_retrieve_values_with_custom_jdk8_codecs() { |
| 181 | 179 | // given |
| 182 | 180 | MappingManager manager = new MappingManager(session); |
modified driver-extras/src/test/java/com/datastax/driver/extras/codecs/jdk8/LocalDateCodecTest.java +14 −16
| @@ -15,16 +15,14 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.extras.codecs.jdk8; |
| 17 | 17 | |
| 18 | -import java.time.LocalDate; | |
| 19 | - | |
| 18 | +import com.datastax.driver.core.Assertions; | |
| 20 | 19 | import org.testng.annotations.DataProvider; |
| 21 | 20 | import org.testng.annotations.Test; |
| 22 | 21 | |
| 23 | -import static org.assertj.core.api.Assertions.assertThat; | |
| 24 | - | |
| 25 | -import com.datastax.driver.core.Assertions; | |
| 22 | +import java.time.LocalDate; | |
| 26 | 23 | |
| 27 | 24 | import static com.datastax.driver.core.ProtocolVersion.V4; |
| 25 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 28 | 26 | |
| 29 | 27 | public class LocalDateCodecTest { |
| 30 | 28 | |
| @@ -34,23 +32,23 @@ | ||
| 34 | 32 | @DataProvider(name = "LocalDateCodecTest.parse") |
| 35 | 33 | public Object[][] parseParameters() { |
| 36 | 34 | return new Object[][]{ |
| 37 | - { null , null }, | |
| 38 | - { "" , null }, | |
| 39 | - { "NULL" , null }, | |
| 40 | - { "0" , MIN }, | |
| 41 | - { "'2147483648'" , EPOCH }, | |
| 42 | - { "'-5877641-06-23'" , MIN }, | |
| 43 | - { "'1970-01-01'" , EPOCH }, | |
| 44 | - { "'2014-01-01'" , LocalDate.parse("2014-01-01") } | |
| 35 | + {null, null}, | |
| 36 | + {"", null}, | |
| 37 | + {"NULL", null}, | |
| 38 | + {"0", MIN}, | |
| 39 | + {"'2147483648'", EPOCH}, | |
| 40 | + {"'-5877641-06-23'", MIN}, | |
| 41 | + {"'1970-01-01'", EPOCH}, | |
| 42 | + {"'2014-01-01'", LocalDate.parse("2014-01-01")} | |
| 45 | 43 | }; |
| 46 | 44 | } |
| 47 | 45 | |
| 48 | 46 | @DataProvider(name = "LocalDateCodecTest.format") |
| 49 | 47 | public Object[][] formatParameters() { |
| 50 | 48 | return new Object[][]{ |
| 51 | - { null , "NULL" }, | |
| 52 | - { LocalDate.ofEpochDay(0) , "'1970-01-01'" }, | |
| 53 | - { LocalDate.parse("2010-06-30"), "'2010-06-30'" } | |
| 49 | + {null, "NULL"}, | |
| 50 | + {LocalDate.ofEpochDay(0), "'1970-01-01'"}, | |
| 51 | + {LocalDate.parse("2010-06-30"), "'2010-06-30'"} | |
| 54 | 52 | }; |
| 55 | 53 | } |
| 56 | 54 |
modified driver-extras/src/test/java/com/datastax/driver/extras/codecs/jdk8/LocalTimeCodecTest.java +14 −16
| @@ -15,17 +15,15 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.extras.codecs.jdk8; |
| 17 | 17 | |
| 18 | -import java.time.LocalTime; | |
| 19 | - | |
| 18 | +import com.datastax.driver.core.Assertions; | |
| 20 | 19 | import org.testng.annotations.DataProvider; |
| 21 | 20 | import org.testng.annotations.Test; |
| 22 | 21 | |
| 23 | -import static org.assertj.core.api.Assertions.assertThat; | |
| 24 | - | |
| 25 | -import com.datastax.driver.core.Assertions; | |
| 22 | +import java.time.LocalTime; | |
| 26 | 23 | |
| 27 | 24 | import static com.datastax.driver.core.ParseUtils.quote; |
| 28 | 25 | import static com.datastax.driver.core.ProtocolVersion.V4; |
| 26 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 29 | 27 | |
| 30 | 28 | public class LocalTimeCodecTest { |
| 31 | 29 | |
| @@ -34,23 +32,23 @@ | ||
| 34 | 32 | LocalTime time = LocalTime.parse("13:25:47.123456789"); |
| 35 | 33 | String nanosOfDay = quote(Long.toString(time.toNanoOfDay())); |
| 36 | 34 | return new Object[][]{ |
| 37 | - { null , null }, | |
| 38 | - { "" , null }, | |
| 39 | - { "NULL" , null }, | |
| 40 | - { nanosOfDay , LocalTime.parse("13:25:47.123456789") }, | |
| 41 | - { "'13:25:47'" , LocalTime.parse("13:25:47") }, | |
| 42 | - { "'13:25:47.123'" , LocalTime.parse("13:25:47.123") }, | |
| 43 | - { "'13:25:47.123456'" , LocalTime.parse("13:25:47.123456") }, | |
| 44 | - { "'13:25:47.123456789'", LocalTime.parse("13:25:47.123456789") } | |
| 35 | + {null, null}, | |
| 36 | + {"", null}, | |
| 37 | + {"NULL", null}, | |
| 38 | + {nanosOfDay, LocalTime.parse("13:25:47.123456789")}, | |
| 39 | + {"'13:25:47'", LocalTime.parse("13:25:47")}, | |
| 40 | + {"'13:25:47.123'", LocalTime.parse("13:25:47.123")}, | |
| 41 | + {"'13:25:47.123456'", LocalTime.parse("13:25:47.123456")}, | |
| 42 | + {"'13:25:47.123456789'", LocalTime.parse("13:25:47.123456789")} | |
| 45 | 43 | }; |
| 46 | 44 | } |
| 47 | 45 | |
| 48 | 46 | @DataProvider(name = "LocalTimeCodecTest.format") |
| 49 | 47 | public Object[][] formatParameters() { |
| 50 | 48 | return new Object[][]{ |
| 51 | - { null , "NULL" }, | |
| 52 | - { LocalTime.NOON , "'12:00:00.000'" }, | |
| 53 | - { LocalTime.parse("02:20:47.999999"), "'02:20:47.999'" } | |
| 49 | + {null, "NULL"}, | |
| 50 | + {LocalTime.NOON, "'12:00:00.000'"}, | |
| 51 | + {LocalTime.parse("02:20:47.999999"), "'02:20:47.999'"} | |
| 54 | 52 | }; |
| 55 | 53 | } |
| 56 | 54 |
modified driver-extras/src/test/java/com/datastax/driver/extras/codecs/jdk8/OptionalCodecTest.java +16 −24
| @@ -15,32 +15,24 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.extras.codecs.jdk8; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.*; | |
| 19 | +import com.datastax.driver.core.CCMBridge.PerClassSingleNodeCluster; | |
| 20 | +import com.datastax.driver.core.querybuilder.BuiltStatement; | |
| 21 | +import com.datastax.driver.core.utils.CassandraVersion; | |
| 22 | +import com.google.common.collect.Lists; | |
| 23 | +import org.testng.annotations.BeforeMethod; | |
| 24 | +import org.testng.annotations.Test; | |
| 25 | + | |
| 18 | 26 | import java.math.BigDecimal; |
| 19 | 27 | import java.util.Collection; |
| 20 | 28 | import java.util.Collections; |
| 21 | 29 | import java.util.List; |
| 22 | 30 | import java.util.Optional; |
| 23 | 31 | |
| 24 | -import com.google.common.collect.Lists; | |
| 25 | -import org.testng.annotations.BeforeMethod; | |
| 26 | -import org.testng.annotations.Test; | |
| 27 | - | |
| 32 | +import static com.datastax.driver.core.TypeCodec.*; | |
| 33 | +import static com.datastax.driver.core.querybuilder.QueryBuilder.*; | |
| 28 | 34 | import static org.assertj.core.api.Assertions.assertThat; |
| 29 | 35 | |
| 30 | -import com.datastax.driver.core.*; | |
| 31 | -import com.datastax.driver.core.CCMBridge.PerClassSingleNodeCluster; | |
| 32 | -import com.datastax.driver.core.querybuilder.BuiltStatement; | |
| 33 | -import com.datastax.driver.core.utils.CassandraVersion; | |
| 34 | - | |
| 35 | -import static com.datastax.driver.core.TypeCodec.bigint; | |
| 36 | -import static com.datastax.driver.core.TypeCodec.decimal; | |
| 37 | -import static com.datastax.driver.core.TypeCodec.list; | |
| 38 | -import static com.datastax.driver.core.TypeCodec.varchar; | |
| 39 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.bindMarker; | |
| 40 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; | |
| 41 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.insertInto; | |
| 42 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.select; | |
| 43 | - | |
| 44 | 36 | public class OptionalCodecTest extends PerClassSingleNodeCluster { |
| 45 | 37 | |
| 46 | 38 | private final OptionalCodec<List<String>> optionalCodec = new OptionalCodec<List<String>>(list(varchar())); |
| @@ -79,8 +71,8 @@ | ||
| 79 | 71 | * @jira_ticket JAVA-606 |
| 80 | 72 | * @since 2.2.0 |
| 81 | 73 | */ |
| 82 | - @Test(groups="short") | |
| 83 | - @CassandraVersion(major=2.2) | |
| 74 | + @Test(groups = "short") | |
| 75 | + @CassandraVersion(major = 2.2) | |
| 84 | 76 | public void should_map_unset_value_to_empty() { |
| 85 | 77 | PreparedStatement insertPrep = session.prepare(this.insertStmt); |
| 86 | 78 | PreparedStatement selectPrep = session.prepare(this.selectStmt); |
| @@ -109,7 +101,7 @@ | ||
| 109 | 101 | * @jira_ticket JAVA-606 |
| 110 | 102 | * @since 2.2.0 |
| 111 | 103 | */ |
| 112 | - @Test(groups="short") | |
| 104 | + @Test(groups = "short") | |
| 113 | 105 | public void should_map_absent_null_value_to_empty() { |
| 114 | 106 | PreparedStatement insertPrep = session.prepare(this.insertStmt); |
| 115 | 107 | PreparedStatement selectPrep = session.prepare(this.selectStmt); |
| @@ -141,7 +133,7 @@ | ||
| 141 | 133 | * @jira_ticket JAVA-606 |
| 142 | 134 | * @since 2.2.0 |
| 143 | 135 | */ |
| 144 | - @Test(groups="short") | |
| 136 | + @Test(groups = "short") | |
| 145 | 137 | public void should_map_some_back_to_itself() { |
| 146 | 138 | PreparedStatement insertPrep = session.prepare(this.insertStmt); |
| 147 | 139 | PreparedStatement selectPrep = session.prepare(this.selectStmt); |
| @@ -169,7 +161,7 @@ | ||
| 169 | 161 | assertThat(returnData.get()).isEqualTo(data); |
| 170 | 162 | } |
| 171 | 163 | |
| 172 | - @Test(groups="short") | |
| 164 | + @Test(groups = "short") | |
| 173 | 165 | public void should_map_a_primitive_type_to_empty() { |
| 174 | 166 | OptionalCodec<Long> optionalLongCodec = new OptionalCodec<Long>(bigint()); |
| 175 | 167 | cluster.getConfiguration().getCodecRegistry().register(optionalLongCodec); |
| @@ -193,7 +185,7 @@ | ||
| 193 | 185 | assertThat(row.get("c4", Long.class)).isNull(); |
| 194 | 186 | } |
| 195 | 187 | |
| 196 | - @Test(groups="short") | |
| 188 | + @Test(groups = "short") | |
| 197 | 189 | public void should_map_a_nullable_type_to_empty() { |
| 198 | 190 | OptionalCodec<BigDecimal> optionalDecimalCodec = new OptionalCodec<BigDecimal>(decimal()); |
| 199 | 191 | cluster.getConfiguration().getCodecRegistry().register(optionalDecimalCodec); |
modified driver-extras/src/test/java/com/datastax/driver/extras/codecs/jdk8/ZonedDateTimeCodecTest.java +20 −23
| @@ -15,29 +15,26 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.extras.codecs.jdk8; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.Assertions; | |
| 19 | +import com.datastax.driver.core.TupleType; | |
| 20 | +import org.testng.annotations.DataProvider; | |
| 21 | +import org.testng.annotations.Test; | |
| 22 | + | |
| 18 | 23 | import java.time.ZoneOffset; |
| 19 | 24 | import java.time.ZonedDateTime; |
| 20 | 25 | |
| 26 | +import static com.datastax.driver.core.DataType.timestamp; | |
| 27 | +import static com.datastax.driver.core.DataType.varchar; | |
| 28 | +import static com.datastax.driver.core.ProtocolVersion.V4; | |
| 29 | +import static com.google.common.collect.Lists.newArrayList; | |
| 21 | 30 | import static java.time.Instant.ofEpochMilli; |
| 22 | 31 | import static java.time.Instant.parse; |
| 23 | 32 | import static java.time.ZoneOffset.UTC; |
| 24 | 33 | import static java.time.ZonedDateTime.ofInstant; |
| 25 | - | |
| 26 | -import org.testng.annotations.DataProvider; | |
| 27 | -import org.testng.annotations.Test; | |
| 28 | - | |
| 29 | -import static com.google.common.collect.Lists.newArrayList; | |
| 30 | 34 | import static org.assertj.core.api.Assertions.assertThat; |
| 31 | 35 | import static org.mockito.Mockito.mock; |
| 32 | 36 | import static org.mockito.Mockito.when; |
| 33 | 37 | |
| 34 | -import com.datastax.driver.core.Assertions; | |
| 35 | -import com.datastax.driver.core.TupleType; | |
| 36 | - | |
| 37 | -import static com.datastax.driver.core.DataType.timestamp; | |
| 38 | -import static com.datastax.driver.core.DataType.varchar; | |
| 39 | -import static com.datastax.driver.core.ProtocolVersion.V4; | |
| 40 | - | |
| 41 | 38 | public class ZonedDateTimeCodecTest { |
| 42 | 39 | |
| 43 | 40 | private final TupleType tupleType = mock(TupleType.class); |
| @@ -45,23 +42,23 @@ | ||
| 45 | 42 | @DataProvider(name = "ZonedDateTimeCodecTest.parse") |
| 46 | 43 | public Object[][] parseParameters() { |
| 47 | 44 | return new Object[][]{ |
| 48 | - { null , null }, | |
| 49 | - { "" , null }, | |
| 50 | - { "NULL" , null }, | |
| 51 | - { "(0 ,'+01:00')" , ofInstant(ofEpochMilli(0) , ZoneOffset.of("+01:00")) }, | |
| 52 | - { "(1277860847999 ,'+01:00')" , ofInstant(parse("2010-06-30T01:20:47.999Z"), ZoneOffset.of("+01:00")) }, | |
| 53 | - { "('2010-06-30T01:20Z' ,'+01:00')" , ofInstant(parse("2010-06-30T01:20:00.000Z"), ZoneOffset.of("+01:00")) }, | |
| 54 | - { "('2010-06-30T01:20:47Z' ,'+01:00')" , ofInstant(parse("2010-06-30T01:20:47.000Z"), ZoneOffset.of("+01:00")) }, | |
| 55 | - { "('2010-06-30T01:20:47.999Z','+01:00')" , ofInstant(parse("2010-06-30T01:20:47.999Z"), ZoneOffset.of("+01:00")) } | |
| 45 | + {null, null}, | |
| 46 | + {"", null}, | |
| 47 | + {"NULL", null}, | |
| 48 | + {"(0 ,'+01:00')", ofInstant(ofEpochMilli(0), ZoneOffset.of("+01:00"))}, | |
| 49 | + {"(1277860847999 ,'+01:00')", ofInstant(parse("2010-06-30T01:20:47.999Z"), ZoneOffset.of("+01:00"))}, | |
| 50 | + {"('2010-06-30T01:20Z' ,'+01:00')", ofInstant(parse("2010-06-30T01:20:00.000Z"), ZoneOffset.of("+01:00"))}, | |
| 51 | + {"('2010-06-30T01:20:47Z' ,'+01:00')", ofInstant(parse("2010-06-30T01:20:47.000Z"), ZoneOffset.of("+01:00"))}, | |
| 52 | + {"('2010-06-30T01:20:47.999Z','+01:00')", ofInstant(parse("2010-06-30T01:20:47.999Z"), ZoneOffset.of("+01:00"))} | |
| 56 | 53 | }; |
| 57 | 54 | } |
| 58 | 55 | |
| 59 | 56 | @DataProvider(name = "ZonedDateTimeCodecTest.format") |
| 60 | 57 | public Object[][] formatParameters() { |
| 61 | 58 | return new Object[][]{ |
| 62 | - { null , "NULL" }, | |
| 63 | - { ofInstant(ofEpochMilli(0), UTC) , "('1970-01-01T00:00:00Z','+00:00')" }, | |
| 64 | - { ZonedDateTime.parse("2010-06-30T01:20:47.999+01:00"), "('2010-06-30T00:20:47.999Z','+01:00')" } | |
| 59 | + {null, "NULL"}, | |
| 60 | + {ofInstant(ofEpochMilli(0), UTC), "('1970-01-01T00:00:00Z','+00:00')"}, | |
| 61 | + {ZonedDateTime.parse("2010-06-30T01:20:47.999+01:00"), "('2010-06-30T00:20:47.999Z','+01:00')"} | |
| 65 | 62 | }; |
| 66 | 63 | } |
| 67 | 64 |
modified driver-extras/src/test/java/com/datastax/driver/extras/codecs/joda/DateTimeCodecTest.java +16 −19
| @@ -15,11 +15,15 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.extras.codecs.joda; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.Assertions; | |
| 19 | +import com.datastax.driver.core.TupleType; | |
| 18 | 20 | import org.joda.time.DateTime; |
| 19 | -import org.joda.time.DateTimeZone; | |
| 20 | 21 | import org.testng.annotations.DataProvider; |
| 21 | 22 | import org.testng.annotations.Test; |
| 22 | 23 | |
| 24 | +import static com.datastax.driver.core.DataType.timestamp; | |
| 25 | +import static com.datastax.driver.core.DataType.varchar; | |
| 26 | +import static com.datastax.driver.core.ProtocolVersion.V4; | |
| 23 | 27 | import static com.google.common.collect.Lists.newArrayList; |
| 24 | 28 | import static org.assertj.core.api.Assertions.assertThat; |
| 25 | 29 | import static org.joda.time.DateTimeZone.UTC; |
| @@ -27,13 +31,6 @@ | ||
| 27 | 31 | import static org.mockito.Mockito.mock; |
| 28 | 32 | import static org.mockito.Mockito.when; |
| 29 | 33 | |
| 30 | -import com.datastax.driver.core.Assertions; | |
| 31 | -import com.datastax.driver.core.TupleType; | |
| 32 | - | |
| 33 | -import static com.datastax.driver.core.DataType.timestamp; | |
| 34 | -import static com.datastax.driver.core.DataType.varchar; | |
| 35 | -import static com.datastax.driver.core.ProtocolVersion.V4; | |
| 36 | - | |
| 37 | 34 | public class DateTimeCodecTest { |
| 38 | 35 | |
| 39 | 36 | private final TupleType tupleType = mock(TupleType.class); |
| @@ -41,23 +38,23 @@ | ||
| 41 | 38 | @DataProvider(name = "DateTimeCodecTest.parse") |
| 42 | 39 | public Object[][] parseParameters() { |
| 43 | 40 | return new Object[][]{ |
| 44 | - { null , null }, | |
| 45 | - { "" , null }, | |
| 46 | - { "NULL" , null }, | |
| 47 | - { "(0 ,'UTC')" , new DateTime(0, forID("UTC")) }, | |
| 48 | - { "(1277860847999 ,'+01:00')" , new DateTime("2010-06-30T02:20:47.999+01:00", forID("+01:00")) }, | |
| 49 | - { "('2010-06-30T01:20Z' ,'+01:00')" , new DateTime("2010-06-30T02:20:00.000+01:00", forID("+01:00")) }, | |
| 50 | - { "('2010-06-30T01:20:47Z' ,'+01:00')" , new DateTime("2010-06-30T02:20:47.000+01:00", forID("+01:00")) }, | |
| 51 | - { "('2010-06-30T01:20:47.999Z','+01:00')" , new DateTime("2010-06-30T02:20:47.999+01:00", forID("+01:00")) } | |
| 41 | + {null, null}, | |
| 42 | + {"", null}, | |
| 43 | + {"NULL", null}, | |
| 44 | + {"(0 ,'UTC')", new DateTime(0, forID("UTC"))}, | |
| 45 | + {"(1277860847999 ,'+01:00')", new DateTime("2010-06-30T02:20:47.999+01:00", forID("+01:00"))}, | |
| 46 | + {"('2010-06-30T01:20Z' ,'+01:00')", new DateTime("2010-06-30T02:20:00.000+01:00", forID("+01:00"))}, | |
| 47 | + {"('2010-06-30T01:20:47Z' ,'+01:00')", new DateTime("2010-06-30T02:20:47.000+01:00", forID("+01:00"))}, | |
| 48 | + {"('2010-06-30T01:20:47.999Z','+01:00')", new DateTime("2010-06-30T02:20:47.999+01:00", forID("+01:00"))} | |
| 52 | 49 | }; |
| 53 | 50 | } |
| 54 | 51 | |
| 55 | 52 | @DataProvider(name = "DateTimeCodecTest.format") |
| 56 | 53 | public Object[][] formatParameters() { |
| 57 | 54 | return new Object[][]{ |
| 58 | - { null , "NULL" }, | |
| 59 | - { new DateTime(0).withZone(UTC) , "('1970-01-01T00:00:00.000Z','+00:00')" }, | |
| 60 | - { new DateTime("2010-06-30T01:20:47.999+01:00", forID("+01:00")), "('2010-06-30T00:20:47.999Z','+01:00')" } | |
| 55 | + {null, "NULL"}, | |
| 56 | + {new DateTime(0).withZone(UTC), "('1970-01-01T00:00:00.000Z','+00:00')"}, | |
| 57 | + {new DateTime("2010-06-30T01:20:47.999+01:00", forID("+01:00")), "('2010-06-30T00:20:47.999Z','+01:00')"} | |
| 61 | 58 | }; |
| 62 | 59 | } |
| 63 | 60 |
modified driver-extras/src/test/java/com/datastax/driver/extras/codecs/joda/InstantCodecTest.java +17 −19
| @@ -15,43 +15,41 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.extras.codecs.joda; |
| 17 | 17 | |
| 18 | -import java.text.ParseException; | |
| 19 | - | |
| 18 | +import com.datastax.driver.core.Assertions; | |
| 20 | 19 | import org.joda.time.Instant; |
| 21 | 20 | import org.testng.annotations.DataProvider; |
| 22 | 21 | import org.testng.annotations.Test; |
| 23 | 22 | |
| 24 | -import static org.assertj.core.api.Assertions.assertThat; | |
| 25 | - | |
| 26 | -import com.datastax.driver.core.Assertions; | |
| 23 | +import java.text.ParseException; | |
| 27 | 24 | |
| 28 | 25 | import static com.datastax.driver.core.ProtocolVersion.V4; |
| 26 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 29 | 27 | |
| 30 | 28 | public class InstantCodecTest { |
| 31 | 29 | |
| 32 | 30 | @DataProvider(name = "InstantCodecTest.parse") |
| 33 | 31 | public Object[][] parseParameters() { |
| 34 | 32 | return new Object[][]{ |
| 35 | - { null , null }, | |
| 36 | - { "" , null }, | |
| 37 | - { "NULL" , null }, | |
| 38 | - { "0" , new Instant(0) }, | |
| 39 | - { "1277860847999" , new Instant(1277860847999L) }, | |
| 40 | - { "'2010-06-30T01:20'" , Instant.parse("2010-06-30T01:20:00.000Z") }, | |
| 41 | - { "'2010-06-30T01:20Z'" , Instant.parse("2010-06-30T01:20:00.000Z") }, | |
| 42 | - { "'2010-06-30T01:20:47'" , Instant.parse("2010-06-30T01:20:47.000Z") }, | |
| 43 | - { "'2010-06-30T01:20:47+01:00'" , Instant.parse("2010-06-30T00:20:47.000Z") }, | |
| 44 | - { "'2010-06-30T01:20:47.999'" , Instant.parse("2010-06-30T01:20:47.999Z") }, | |
| 45 | - { "'2010-06-30T01:20:47.999+01:00'" , Instant.parse("2010-06-30T00:20:47.999Z") } | |
| 33 | + {null, null}, | |
| 34 | + {"", null}, | |
| 35 | + {"NULL", null}, | |
| 36 | + {"0", new Instant(0)}, | |
| 37 | + {"1277860847999", new Instant(1277860847999L)}, | |
| 38 | + {"'2010-06-30T01:20'", Instant.parse("2010-06-30T01:20:00.000Z")}, | |
| 39 | + {"'2010-06-30T01:20Z'", Instant.parse("2010-06-30T01:20:00.000Z")}, | |
| 40 | + {"'2010-06-30T01:20:47'", Instant.parse("2010-06-30T01:20:47.000Z")}, | |
| 41 | + {"'2010-06-30T01:20:47+01:00'", Instant.parse("2010-06-30T00:20:47.000Z")}, | |
| 42 | + {"'2010-06-30T01:20:47.999'", Instant.parse("2010-06-30T01:20:47.999Z")}, | |
| 43 | + {"'2010-06-30T01:20:47.999+01:00'", Instant.parse("2010-06-30T00:20:47.999Z")} | |
| 46 | 44 | }; |
| 47 | 45 | } |
| 48 | 46 | |
| 49 | 47 | @DataProvider(name = "InstantCodecTest.format") |
| 50 | 48 | public Object[][] formatParameters() throws ParseException { |
| 51 | 49 | return new Object[][]{ |
| 52 | - { null , "NULL" }, | |
| 53 | - { new Instant(0) , "'1970-01-01T00:00:00.000+00:00'" }, | |
| 54 | - { Instant.parse("2010-06-30T02:20:47.999+01:00").toInstant(), "'2010-06-30T01:20:47.999+00:00'" } | |
| 50 | + {null, "NULL"}, | |
| 51 | + {new Instant(0), "'1970-01-01T00:00:00.000+00:00'"}, | |
| 52 | + {Instant.parse("2010-06-30T02:20:47.999+01:00").toInstant(), "'2010-06-30T01:20:47.999+00:00'"} | |
| 55 | 53 | }; |
| 56 | 54 | } |
| 57 | 55 |
modified driver-extras/src/test/java/com/datastax/driver/extras/codecs/joda/JodaTimeCodecsTest.java +34 −37
| @@ -15,11 +15,13 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.extras.codecs.joda; |
| 17 | 17 | |
| 18 | -import java.util.*; | |
| 19 | - | |
| 20 | -import static java.util.concurrent.TimeUnit.MILLISECONDS; | |
| 21 | -import static java.util.concurrent.TimeUnit.NANOSECONDS; | |
| 22 | - | |
| 18 | +import com.datastax.driver.core.*; | |
| 19 | +import com.datastax.driver.core.utils.CassandraVersion; | |
| 20 | +import com.datastax.driver.mapping.Mapper; | |
| 21 | +import com.datastax.driver.mapping.MappingManager; | |
| 22 | +import com.datastax.driver.mapping.annotations.Column; | |
| 23 | +import com.datastax.driver.mapping.annotations.PartitionKey; | |
| 24 | +import com.datastax.driver.mapping.annotations.Table; | |
| 23 | 25 | import com.google.common.collect.ImmutableMap; |
| 24 | 26 | import org.joda.time.DateTime; |
| 25 | 27 | import org.joda.time.Instant; |
| @@ -28,38 +30,33 @@ | ||
| 28 | 30 | import org.testng.annotations.BeforeClass; |
| 29 | 31 | import org.testng.annotations.Test; |
| 30 | 32 | |
| 31 | -import static com.google.common.collect.Lists.newArrayList; | |
| 32 | -import static com.google.common.collect.Sets.newHashSet; | |
| 33 | -import static org.assertj.core.api.Assertions.assertThat; | |
| 34 | - | |
| 35 | -import com.datastax.driver.core.*; | |
| 36 | -import com.datastax.driver.core.utils.CassandraVersion; | |
| 37 | -import com.datastax.driver.mapping.Mapper; | |
| 38 | -import com.datastax.driver.mapping.MappingManager; | |
| 39 | -import com.datastax.driver.mapping.annotations.Column; | |
| 40 | -import com.datastax.driver.mapping.annotations.PartitionKey; | |
| 41 | -import com.datastax.driver.mapping.annotations.Table; | |
| 33 | +import java.util.*; | |
| 42 | 34 | |
| 43 | 35 | import static com.datastax.driver.core.DataType.timestamp; |
| 44 | 36 | import static com.datastax.driver.core.DataType.varchar; |
| 37 | +import static com.google.common.collect.Lists.newArrayList; | |
| 38 | +import static com.google.common.collect.Sets.newHashSet; | |
| 39 | +import static java.util.concurrent.TimeUnit.MILLISECONDS; | |
| 40 | +import static java.util.concurrent.TimeUnit.NANOSECONDS; | |
| 41 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 45 | 42 | |
| 46 | -@CassandraVersion(major=2.2) | |
| 43 | +@CassandraVersion(major = 2.2) | |
| 47 | 44 | public class JodaTimeCodecsTest extends CCMBridge.PerClassSingleNodeCluster { |
| 48 | 45 | |
| 49 | 46 | @Override |
| 50 | 47 | protected Collection<String> getTableDefinitions() { |
| 51 | 48 | return Collections.singletonList( |
| 52 | - "CREATE TABLE IF NOT EXISTS foo (" | |
| 53 | - + "c1 text PRIMARY KEY, " | |
| 54 | - + "cdate date, " | |
| 55 | - + "ctime time, " | |
| 56 | - + "ctimestamp timestamp, " | |
| 57 | - + "ctuple tuple<timestamp,varchar>, " | |
| 58 | - + "cdates frozen<list<date>>, " | |
| 59 | - + "ctimes frozen<set<time>>, " | |
| 60 | - + "ctimestamps frozen<map<text,timestamp>>, " | |
| 61 | - + "ctuples frozen<map<tuple<timestamp,varchar>,varchar>>" | |
| 62 | - + ")"); | |
| 49 | + "CREATE TABLE IF NOT EXISTS foo (" | |
| 50 | + + "c1 text PRIMARY KEY, " | |
| 51 | + + "cdate date, " | |
| 52 | + + "ctime time, " | |
| 53 | + + "ctimestamp timestamp, " | |
| 54 | + + "ctuple tuple<timestamp,varchar>, " | |
| 55 | + + "cdates frozen<list<date>>, " | |
| 56 | + + "ctimes frozen<set<time>>, " | |
| 57 | + + "ctimestamps frozen<map<text,timestamp>>, " | |
| 58 | + + "ctuples frozen<map<tuple<timestamp,varchar>,varchar>>" | |
| 59 | + + ")"); | |
| 63 | 60 | } |
| 64 | 61 | |
| 65 | 62 | @BeforeClass(groups = "short") |
| @@ -67,10 +64,10 @@ | ||
| 67 | 64 | TupleType dateWithTimeZoneType = cluster.getMetadata().newTupleType(timestamp(), varchar()); |
| 68 | 65 | CodecRegistry codecRegistry = cluster.getConfiguration().getCodecRegistry(); |
| 69 | 66 | codecRegistry |
| 70 | - .register(LocalTimeCodec.instance) | |
| 71 | - .register(LocalDateCodec.instance) | |
| 72 | - .register(InstantCodec.instance) | |
| 73 | - .register(new DateTimeCodec(dateWithTimeZoneType)); | |
| 67 | + .register(LocalTimeCodec.instance) | |
| 68 | + .register(LocalDateCodec.instance) | |
| 69 | + .register(InstantCodec.instance) | |
| 70 | + .register(new DateTimeCodec(dateWithTimeZoneType)); | |
| 74 | 71 | } |
| 75 | 72 | |
| 76 | 73 | /** |
| @@ -84,7 +81,7 @@ | ||
| 84 | 81 | * @jira_ticket JAVA-846 |
| 85 | 82 | * @since 2.2.0 |
| 86 | 83 | */ |
| 87 | - @Test(groups="short") | |
| 84 | + @Test(groups = "short") | |
| 88 | 85 | public void should_map_time_to_localtime() { |
| 89 | 86 | // given |
| 90 | 87 | LocalTime time = new LocalTime(12, 16, 34, 999); |
| @@ -109,7 +106,7 @@ | ||
| 109 | 106 | * @jira_ticket JAVA-846 |
| 110 | 107 | * @since 2.2.0 |
| 111 | 108 | */ |
| 112 | - @Test(groups="short") | |
| 109 | + @Test(groups = "short") | |
| 113 | 110 | public void should_map_date_to_localdate() { |
| 114 | 111 | // given |
| 115 | 112 | LocalDate localDate = new LocalDate(2015, 1, 1); |
| @@ -135,7 +132,7 @@ | ||
| 135 | 132 | * @jira_ticket JAVA-846 |
| 136 | 133 | * @since 2.2.0 |
| 137 | 134 | */ |
| 138 | - @Test(groups="short") | |
| 135 | + @Test(groups = "short") | |
| 139 | 136 | public void should_map_timestamp_to_instant() { |
| 140 | 137 | // given |
| 141 | 138 | Instant instant = Instant.parse("2010-06-30T01:20+05:00"); |
| @@ -160,7 +157,7 @@ | ||
| 160 | 157 | * @jira_ticket JAVA-846 |
| 161 | 158 | * @since 2.2.0 |
| 162 | 159 | */ |
| 163 | - @Test(groups="short") | |
| 160 | + @Test(groups = "short") | |
| 164 | 161 | public void should_map_tuple_to_datetime() { |
| 165 | 162 | // given |
| 166 | 163 | DateTime expected = DateTime.parse("2010-06-30T01:20+05:30"); |
| @@ -178,7 +175,7 @@ | ||
| 178 | 175 | assertThat(row.get("ctuple", DateTime.class).getZone()).isEqualTo(expected.getZone()); |
| 179 | 176 | } |
| 180 | 177 | |
| 181 | - @Test(groups="short") | |
| 178 | + @Test(groups = "short") | |
| 182 | 179 | public void should_use_mapper_to_store_and_retrieve_values_with_custom_joda_codecs() { |
| 183 | 180 | // given |
| 184 | 181 | MappingManager manager = new MappingManager(session); |
modified driver-extras/src/test/java/com/datastax/driver/extras/codecs/joda/LocalDateCodecTest.java +13 −15
| @@ -15,15 +15,13 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.extras.codecs.joda; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.Assertions; | |
| 18 | 19 | import org.joda.time.LocalDate; |
| 19 | 20 | import org.testng.annotations.DataProvider; |
| 20 | 21 | import org.testng.annotations.Test; |
| 21 | 22 | |
| 22 | -import static org.assertj.core.api.Assertions.assertThat; | |
| 23 | - | |
| 24 | -import com.datastax.driver.core.Assertions; | |
| 25 | - | |
| 26 | 23 | import static com.datastax.driver.core.ProtocolVersion.V4; |
| 24 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 27 | 25 | |
| 28 | 26 | public class LocalDateCodecTest { |
| 29 | 27 | |
| @@ -33,23 +31,23 @@ | ||
| 33 | 31 | @DataProvider(name = "LocalDateCodecTest") |
| 34 | 32 | public Object[][] parseParameters() { |
| 35 | 33 | return new Object[][]{ |
| 36 | - { null , null }, | |
| 37 | - { "" , null }, | |
| 38 | - { "NULL" , null }, | |
| 39 | - { "0" , MIN }, | |
| 40 | - { "'2147483648'" , EPOCH }, | |
| 41 | - { "'-5877641-06-23'" , MIN }, | |
| 42 | - { "'1970-01-01'" , EPOCH }, | |
| 43 | - { "'2014-01-01'" , LocalDate.parse("2014-01-01") } | |
| 34 | + {null, null}, | |
| 35 | + {"", null}, | |
| 36 | + {"NULL", null}, | |
| 37 | + {"0", MIN}, | |
| 38 | + {"'2147483648'", EPOCH}, | |
| 39 | + {"'-5877641-06-23'", MIN}, | |
| 40 | + {"'1970-01-01'", EPOCH}, | |
| 41 | + {"'2014-01-01'", LocalDate.parse("2014-01-01")} | |
| 44 | 42 | }; |
| 45 | 43 | } |
| 46 | 44 | |
| 47 | 45 | @DataProvider(name = "LocalDateCodecTest.format") |
| 48 | 46 | public Object[][] formatParameters() { |
| 49 | 47 | return new Object[][]{ |
| 50 | - { null , "NULL" }, | |
| 51 | - { EPOCH , "'1970-01-01'" }, | |
| 52 | - { LocalDate.parse("2010-06-30"), "'2010-06-30'" } | |
| 48 | + {null, "NULL"}, | |
| 49 | + {EPOCH, "'1970-01-01'"}, | |
| 50 | + {LocalDate.parse("2010-06-30"), "'2010-06-30'"} | |
| 53 | 51 | }; |
| 54 | 52 | } |
| 55 | 53 |
modified driver-extras/src/test/java/com/datastax/driver/extras/codecs/joda/LocalTimeCodecTest.java +14 −17
| @@ -15,18 +15,15 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.extras.codecs.joda; |
| 17 | 17 | |
| 18 | -import static java.util.concurrent.TimeUnit.MILLISECONDS; | |
| 19 | - | |
| 18 | +import com.datastax.driver.core.Assertions; | |
| 20 | 19 | import org.joda.time.LocalTime; |
| 21 | 20 | import org.testng.annotations.DataProvider; |
| 22 | 21 | import org.testng.annotations.Test; |
| 23 | 22 | |
| 24 | -import static org.assertj.core.api.Assertions.assertThat; | |
| 25 | - | |
| 26 | -import com.datastax.driver.core.Assertions; | |
| 27 | - | |
| 28 | 23 | import static com.datastax.driver.core.ParseUtils.quote; |
| 29 | 24 | import static com.datastax.driver.core.ProtocolVersion.V4; |
| 25 | +import static java.util.concurrent.TimeUnit.MILLISECONDS; | |
| 26 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 30 | 27 | |
| 31 | 28 | public class LocalTimeCodecTest { |
| 32 | 29 | |
| @@ -35,23 +32,23 @@ | ||
| 35 | 32 | LocalTime time = LocalTime.parse("13:25:47.123456789"); |
| 36 | 33 | String nanosOfDay = quote(Long.toString(MILLISECONDS.toNanos(time.getMillisOfDay()))); |
| 37 | 34 | return new Object[][]{ |
| 38 | - { null , null }, | |
| 39 | - { "" , null }, | |
| 40 | - { "NULL" , null }, | |
| 41 | - { nanosOfDay , LocalTime.parse("13:25:47.123456789") }, | |
| 42 | - { "'13:25:47'" , LocalTime.parse("13:25:47") }, | |
| 43 | - { "'13:25:47.123'" , LocalTime.parse("13:25:47.123") }, | |
| 44 | - { "'13:25:47.123456'" , LocalTime.parse("13:25:47.123456") }, | |
| 45 | - { "'13:25:47.123456789'", LocalTime.parse("13:25:47.123456789") } | |
| 35 | + {null, null}, | |
| 36 | + {"", null}, | |
| 37 | + {"NULL", null}, | |
| 38 | + {nanosOfDay, LocalTime.parse("13:25:47.123456789")}, | |
| 39 | + {"'13:25:47'", LocalTime.parse("13:25:47")}, | |
| 40 | + {"'13:25:47.123'", LocalTime.parse("13:25:47.123")}, | |
| 41 | + {"'13:25:47.123456'", LocalTime.parse("13:25:47.123456")}, | |
| 42 | + {"'13:25:47.123456789'", LocalTime.parse("13:25:47.123456789")} | |
| 46 | 43 | }; |
| 47 | 44 | } |
| 48 | 45 | |
| 49 | 46 | @DataProvider(name = "LocalTimeCodecTest.format") |
| 50 | 47 | public Object[][] formatParameters() { |
| 51 | 48 | return new Object[][]{ |
| 52 | - { null , "NULL" }, | |
| 53 | - { LocalTime.parse("12:00") , "'12:00:00.000'" }, | |
| 54 | - { LocalTime.parse("02:20:47.999999"), "'02:20:47.999'" } | |
| 49 | + {null, "NULL"}, | |
| 50 | + {LocalTime.parse("12:00"), "'12:00:00.000'"}, | |
| 51 | + {LocalTime.parse("02:20:47.999999"), "'02:20:47.999'"} | |
| 55 | 52 | }; |
| 56 | 53 | } |
| 57 | 54 |
modified driver-extras/src/test/java/com/datastax/driver/extras/codecs/json/JacksonJsonCodecTest.java +37 −42
| @@ -15,37 +15,32 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.extras.codecs.json; |
| 17 | 17 | |
| 18 | -import java.util.ArrayList; | |
| 19 | -import java.util.Collection; | |
| 20 | - | |
| 18 | +import com.datastax.driver.core.*; | |
| 19 | +import com.datastax.driver.core.querybuilder.BuiltStatement; | |
| 20 | +import com.datastax.driver.core.utils.CassandraVersion; | |
| 21 | 21 | import com.fasterxml.jackson.annotation.JsonCreator; |
| 22 | 22 | import com.fasterxml.jackson.annotation.JsonProperty; |
| 23 | 23 | import com.google.common.base.Objects; |
| 24 | 24 | import com.google.common.collect.Lists; |
| 25 | 25 | import org.testng.annotations.Test; |
| 26 | 26 | |
| 27 | -import static org.assertj.core.api.Assertions.assertThat; | |
| 28 | - | |
| 29 | -import com.datastax.driver.core.*; | |
| 30 | -import com.datastax.driver.core.querybuilder.BuiltStatement; | |
| 31 | -import com.datastax.driver.core.utils.CassandraVersion; | |
| 27 | +import java.util.ArrayList; | |
| 28 | +import java.util.Collection; | |
| 32 | 29 | |
| 33 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.bindMarker; | |
| 34 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; | |
| 35 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.insertInto; | |
| 36 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.select; | |
| 30 | +import static com.datastax.driver.core.querybuilder.QueryBuilder.*; | |
| 31 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 37 | 32 | |
| 38 | 33 | public class JacksonJsonCodecTest extends CCMBridge.PerClassSingleNodeCluster { |
| 39 | 34 | |
| 40 | 35 | private static final JacksonJsonCodec<User> jsonCodec = new JacksonJsonCodec<User>(User.class); |
| 41 | 36 | |
| 42 | - private static final User alice = new User(1, "Alice"); | |
| 43 | - private static final User bob = new User(2, "Bob"); | |
| 37 | + private static final User alice = new User(1, "Alice"); | |
| 38 | + private static final User bob = new User(2, "Bob"); | |
| 44 | 39 | private static final User charlie = new User(3, "Charlie"); |
| 45 | 40 | |
| 46 | - private static final String bobJson = "{\"id\":2,\"name\":\"Bob\"}"; | |
| 41 | + private static final String bobJson = "{\"id\":2,\"name\":\"Bob\"}"; | |
| 47 | 42 | private static final String charlieJson = "{\"id\":3,\"name\":\"Charlie\"}"; |
| 48 | - private static final String aliceJson = "{\"id\":1,\"name\":\"Alice\"}"; | |
| 43 | + private static final String aliceJson = "{\"id\":1,\"name\":\"Alice\"}"; | |
| 49 | 44 | |
| 50 | 45 | private static final ArrayList<User> bobAndCharlie = Lists.newArrayList(bob, charlie); |
| 51 | 46 | |
| @@ -57,14 +52,14 @@ | ||
| 57 | 52 | @Override |
| 58 | 53 | protected Collection<String> getTableDefinitions() { |
| 59 | 54 | return Lists.newArrayList( |
| 60 | - "CREATE TABLE t1 (c1 text, c2 text, c3 list<text>, PRIMARY KEY (c1, c2))" | |
| 55 | + "CREATE TABLE t1 (c1 text, c2 text, c3 list<text>, PRIMARY KEY (c1, c2))" | |
| 61 | 56 | ); |
| 62 | 57 | } |
| 63 | 58 | |
| 64 | 59 | @Override |
| 65 | 60 | protected Cluster.Builder configure(Cluster.Builder builder) { |
| 66 | 61 | return builder.withCodecRegistry( |
| 67 | - new CodecRegistry().register(jsonCodec) // global User <-> varchar codec | |
| 62 | + new CodecRegistry().register(jsonCodec) // global User <-> varchar codec | |
| 68 | 63 | ); |
| 69 | 64 | } |
| 70 | 65 | |
| @@ -87,7 +82,7 @@ | ||
| 87 | 82 | } |
| 88 | 83 | |
| 89 | 84 | @Test(groups = "short") |
| 90 | - @CassandraVersion(major=2.0) | |
| 85 | + @CassandraVersion(major = 2.0) | |
| 91 | 86 | public void should_use_custom_codec_with_simple_statements() { |
| 92 | 87 | session.execute(insertQuery, notAJsonString, alice, bobAndCharlie); |
| 93 | 88 | ResultSet rows = session.execute(selectQuery, notAJsonString, alice); |
| @@ -98,13 +93,13 @@ | ||
| 98 | 93 | @Test(groups = "short") |
| 99 | 94 | public void should_use_custom_codec_with_built_statements_1() { |
| 100 | 95 | BuiltStatement insertStmt = insertInto("t1") |
| 101 | - .value("c1", bindMarker()) | |
| 102 | - .value("c2", bindMarker()) | |
| 103 | - .value("c3", bindMarker()); | |
| 96 | + .value("c1", bindMarker()) | |
| 97 | + .value("c2", bindMarker()) | |
| 98 | + .value("c3", bindMarker()); | |
| 104 | 99 | BuiltStatement selectStmt = select("c1", "c2", "c3") |
| 105 | - .from("t1") | |
| 106 | - .where(eq("c1", bindMarker())) | |
| 107 | - .and(eq("c2", bindMarker())); | |
| 100 | + .from("t1") | |
| 101 | + .where(eq("c1", bindMarker())) | |
| 102 | + .and(eq("c2", bindMarker())); | |
| 108 | 103 | session.execute(session.prepare(insertStmt).bind(notAJsonString, alice, bobAndCharlie)); |
| 109 | 104 | ResultSet rows = session.execute(session.prepare(selectStmt).bind(notAJsonString, alice)); |
| 110 | 105 | Row row = rows.one(); |
| @@ -114,14 +109,14 @@ | ||
| 114 | 109 | @Test(groups = "short") |
| 115 | 110 | public void should_use_custom_codec_with_built_statements_2() { |
| 116 | 111 | BuiltStatement insertStmt = insertInto("t1") |
| 117 | - .value("c1", notAJsonString) | |
| 118 | - .value("c2", alice) | |
| 119 | - .value("c3", bobAndCharlie); | |
| 112 | + .value("c1", notAJsonString) | |
| 113 | + .value("c2", alice) | |
| 114 | + .value("c3", bobAndCharlie); | |
| 120 | 115 | BuiltStatement selectStmt = |
| 121 | - select("c1", "c2", "c3") | |
| 122 | - .from("t1") | |
| 123 | - .where(eq("c1", notAJsonString)) | |
| 124 | - .and(eq("c2", alice)); | |
| 116 | + select("c1", "c2", "c3") | |
| 117 | + .from("t1") | |
| 118 | + .where(eq("c1", notAJsonString)) | |
| 119 | + .and(eq("c2", alice)); | |
| 125 | 120 | session.execute(insertStmt); |
| 126 | 121 | ResultSet rows = session.execute(selectStmt); |
| 127 | 122 | Row row = rows.one(); |
| @@ -143,17 +138,17 @@ | ||
| 143 | 138 | @Test(groups = "short") |
| 144 | 139 | public void should_use_custom_codec_with_prepared_statements_2() { |
| 145 | 140 | session.execute(session.prepare(insertQuery).bind() |
| 146 | - .setString(0, notAJsonString) | |
| 147 | - .set(1, alice, User.class) | |
| 148 | - .setList(2, bobAndCharlie, User.class) | |
| 141 | + .setString(0, notAJsonString) | |
| 142 | + .set(1, alice, User.class) | |
| 143 | + .setList(2, bobAndCharlie, User.class) | |
| 149 | 144 | ); |
| 150 | 145 | PreparedStatement ps = session.prepare(selectQuery); |
| 151 | 146 | ResultSet rows = session.execute(ps.bind() |
| 152 | - .setString(0, notAJsonString) | |
| 153 | - // this set() method conveys information about the java type of alice | |
| 154 | - // so the registry will look for a codec accepting varchar <-> User | |
| 155 | - // and will find jsonCodec because it is the only matching one | |
| 156 | - .set(1, alice, User.class) | |
| 147 | + .setString(0, notAJsonString) | |
| 148 | + // this set() method conveys information about the java type of alice | |
| 149 | + // so the registry will look for a codec accepting varchar <-> User | |
| 150 | + // and will find jsonCodec because it is the only matching one | |
| 151 | + .set(1, alice, User.class) | |
| 157 | 152 | ); |
| 158 | 153 | Row row = rows.one(); |
| 159 | 154 | assertRow(row); |
| @@ -209,9 +204,9 @@ | ||
| 209 | 204 | return true; |
| 210 | 205 | if (o == null || getClass() != o.getClass()) |
| 211 | 206 | return false; |
| 212 | - User user = (User)o; | |
| 207 | + User user = (User) o; | |
| 213 | 208 | return Objects.equal(id, user.id) && |
| 214 | - Objects.equal(name, user.name); | |
| 209 | + Objects.equal(name, user.name); | |
| 215 | 210 | } |
| 216 | 211 | |
| 217 | 212 | @Override |
modified driver-extras/src/test/java/com/datastax/driver/extras/codecs/json/Jsr353JsonCodecTest.java +32 −37
| @@ -15,32 +15,27 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.extras.codecs.json; |
| 17 | 17 | |
| 18 | -import java.io.IOException; | |
| 19 | -import java.io.StringWriter; | |
| 20 | -import java.util.Collection; | |
| 21 | - | |
| 18 | +import com.datastax.driver.core.*; | |
| 19 | +import com.datastax.driver.core.querybuilder.BuiltStatement; | |
| 20 | +import com.datastax.driver.core.utils.CassandraVersion; | |
| 22 | 21 | import com.google.common.collect.Lists; |
| 23 | -import javax.json.*; | |
| 24 | 22 | import org.testng.annotations.DataProvider; |
| 25 | 23 | import org.testng.annotations.Test; |
| 26 | 24 | |
| 27 | -import static org.assertj.core.api.Assertions.assertThat; | |
| 28 | - | |
| 29 | -import com.datastax.driver.core.*; | |
| 30 | -import com.datastax.driver.core.querybuilder.BuiltStatement; | |
| 31 | -import com.datastax.driver.core.utils.CassandraVersion; | |
| 25 | +import javax.json.*; | |
| 26 | +import java.io.IOException; | |
| 27 | +import java.io.StringWriter; | |
| 28 | +import java.util.Collection; | |
| 32 | 29 | |
| 33 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.bindMarker; | |
| 34 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; | |
| 35 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.insertInto; | |
| 36 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.select; | |
| 30 | +import static com.datastax.driver.core.querybuilder.QueryBuilder.*; | |
| 31 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 37 | 32 | |
| 38 | 33 | public class Jsr353JsonCodecTest extends CCMBridge.PerClassSingleNodeCluster { |
| 39 | 34 | |
| 40 | 35 | private static final Jsr353JsonCodec jsonCodec = new Jsr353JsonCodec(); |
| 41 | 36 | |
| 42 | - private static final JsonObject alice = Json.createObjectBuilder().add("id", 1).add("name", "Alice") .build(); | |
| 43 | - private static final JsonObject bob = Json.createObjectBuilder().add("id", 2).add("name", "Bob") .build(); | |
| 37 | + private static final JsonObject alice = Json.createObjectBuilder().add("id", 1).add("name", "Alice").build(); | |
| 38 | + private static final JsonObject bob = Json.createObjectBuilder().add("id", 2).add("name", "Bob").build(); | |
| 44 | 39 | private static final JsonObject charlie = Json.createObjectBuilder().add("id", 3).add("name", "Charlie").build(); |
| 45 | 40 | |
| 46 | 41 | private static final JsonArray bobAndCharlie = Json.createArrayBuilder().add(bob).add(charlie).build(); |
| @@ -53,22 +48,22 @@ | ||
| 53 | 48 | @Override |
| 54 | 49 | protected Collection<String> getTableDefinitions() { |
| 55 | 50 | return Lists.newArrayList( |
| 56 | - "CREATE TABLE t1 (c1 text, c2 text, PRIMARY KEY (c1, c2))" | |
| 51 | + "CREATE TABLE t1 (c1 text, c2 text, PRIMARY KEY (c1, c2))" | |
| 57 | 52 | ); |
| 58 | 53 | } |
| 59 | 54 | |
| 60 | 55 | @Override |
| 61 | 56 | protected Cluster.Builder configure(Cluster.Builder builder) { |
| 62 | 57 | return builder.withCodecRegistry( |
| 63 | - new CodecRegistry().register(jsonCodec) // global User <-> varchar codec | |
| 58 | + new CodecRegistry().register(jsonCodec) // global User <-> varchar codec | |
| 64 | 59 | ); |
| 65 | 60 | } |
| 66 | 61 | |
| 67 | 62 | @DataProvider(name = "Jsr353JsonCodecTest") |
| 68 | 63 | public static Object[][] parameters() { |
| 69 | - return new Object[][] { | |
| 70 | - { alice }, | |
| 71 | - { bobAndCharlie } | |
| 64 | + return new Object[][]{ | |
| 65 | + {alice}, | |
| 66 | + {bobAndCharlie} | |
| 72 | 67 | }; |
| 73 | 68 | } |
| 74 | 69 | |
| @@ -89,7 +84,7 @@ | ||
| 89 | 84 | } |
| 90 | 85 | |
| 91 | 86 | @Test(groups = "short", dataProvider = "Jsr353JsonCodecTest") |
| 92 | - @CassandraVersion(major=2.0) | |
| 87 | + @CassandraVersion(major = 2.0) | |
| 93 | 88 | public void should_use_custom_codec_with_simple_statements(JsonStructure object) throws IOException { |
| 94 | 89 | session.execute(insertQuery, notAJsonString, object); |
| 95 | 90 | ResultSet rows = session.execute(selectQuery, notAJsonString, object); |
| @@ -100,12 +95,12 @@ | ||
| 100 | 95 | @Test(groups = "short", dataProvider = "Jsr353JsonCodecTest") |
| 101 | 96 | public void should_use_custom_codec_with_built_statements_1(JsonStructure object) throws IOException { |
| 102 | 97 | BuiltStatement insertStmt = insertInto("t1") |
| 103 | - .value("c1", bindMarker()) | |
| 104 | - .value("c2", bindMarker()); | |
| 98 | + .value("c1", bindMarker()) | |
| 99 | + .value("c2", bindMarker()); | |
| 105 | 100 | BuiltStatement selectStmt = select("c1", "c2") |
| 106 | - .from("t1") | |
| 107 | - .where(eq("c1", bindMarker())) | |
| 108 | - .and(eq("c2", bindMarker())); | |
| 101 | + .from("t1") | |
| 102 | + .where(eq("c1", bindMarker())) | |
| 103 | + .and(eq("c2", bindMarker())); | |
| 109 | 104 | session.execute(session.prepare(insertStmt).bind(notAJsonString, object)); |
| 110 | 105 | ResultSet rows = session.execute(session.prepare(selectStmt).bind(notAJsonString, object)); |
| 111 | 106 | Row row = rows.one(); |
| @@ -115,13 +110,13 @@ | ||
| 115 | 110 | @Test(groups = "short", dataProvider = "Jsr353JsonCodecTest") |
| 116 | 111 | public void should_use_custom_codec_with_built_statements_2(JsonStructure object) throws IOException { |
| 117 | 112 | BuiltStatement insertStmt = insertInto("t1") |
| 118 | - .value("c1", notAJsonString) | |
| 119 | - .value("c2", object); | |
| 113 | + .value("c1", notAJsonString) | |
| 114 | + .value("c2", object); | |
| 120 | 115 | BuiltStatement selectStmt = |
| 121 | - select("c1", "c2") | |
| 122 | - .from("t1") | |
| 123 | - .where(eq("c1", notAJsonString)) | |
| 124 | - .and(eq("c2", object)); | |
| 116 | + select("c1", "c2") | |
| 117 | + .from("t1") | |
| 118 | + .where(eq("c1", notAJsonString)) | |
| 119 | + .and(eq("c2", object)); | |
| 125 | 120 | session.execute(insertStmt); |
| 126 | 121 | ResultSet rows = session.execute(selectStmt); |
| 127 | 122 | Row row = rows.one(); |
| @@ -140,13 +135,13 @@ | ||
| 140 | 135 | @Test(groups = "short", dataProvider = "Jsr353JsonCodecTest") |
| 141 | 136 | public void should_use_custom_codec_with_prepared_statements_2(JsonStructure object) throws IOException { |
| 142 | 137 | session.execute(session.prepare(insertQuery).bind() |
| 143 | - .setString(0, notAJsonString) | |
| 144 | - .set(1, object, JsonStructure.class) | |
| 138 | + .setString(0, notAJsonString) | |
| 139 | + .set(1, object, JsonStructure.class) | |
| 145 | 140 | ); |
| 146 | 141 | PreparedStatement ps = session.prepare(selectQuery); |
| 147 | 142 | ResultSet rows = session.execute(ps.bind() |
| 148 | - .setString(0, notAJsonString) | |
| 149 | - .set(1, object, JsonStructure.class) | |
| 143 | + .setString(0, notAJsonString) | |
| 144 | + .set(1, object, JsonStructure.class) | |
| 150 | 145 | ); |
| 151 | 146 | Row row = rows.one(); |
| 152 | 147 | assertRow(row, object); |
modified driver-mapping/src/main/java/com/datastax/driver/mapping/AccessorInvocationHandler.java +3 −1
| @@ -17,7 +17,8 @@ | ||
| 17 | 17 | |
| 18 | 18 | import java.lang.reflect.InvocationHandler; |
| 19 | 19 | import java.lang.reflect.Method; |
| 20 | -import java.util.*; | |
| 20 | +import java.util.HashMap; | |
| 21 | +import java.util.Map; | |
| 21 | 22 | |
| 22 | 23 | class AccessorInvocationHandler<T> implements InvocationHandler { |
| 23 | 24 | |
| @@ -26,6 +27,7 @@ | ||
| 26 | 27 | private static final Method TO_STRING; |
| 27 | 28 | private static final Method EQUALS; |
| 28 | 29 | private static final Method HASH_CODE; |
| 30 | + | |
| 29 | 31 | static { |
| 30 | 32 | try { |
| 31 | 33 | TO_STRING = Object.class.getMethod("toString"); |
modified driver-mapping/src/main/java/com/datastax/driver/mapping/AccessorMapper.java +3 −3
| @@ -15,12 +15,12 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.mapping; |
| 17 | 17 | |
| 18 | -import java.util.*; | |
| 19 | - | |
| 18 | +import com.datastax.driver.core.PreparedStatement; | |
| 20 | 19 | import com.google.common.util.concurrent.Futures; |
| 21 | 20 | import com.google.common.util.concurrent.ListenableFuture; |
| 22 | 21 | |
| 23 | -import com.datastax.driver.core.*; | |
| 22 | +import java.util.ArrayList; | |
| 23 | +import java.util.List; | |
| 24 | 24 | |
| 25 | 25 | abstract class AccessorMapper<T> { |
| 26 | 26 |
modified driver-mapping/src/main/java/com/datastax/driver/mapping/AccessorReflectionMapper.java +2 −2
| @@ -16,7 +16,7 @@ | ||
| 16 | 16 | package com.datastax.driver.mapping; |
| 17 | 17 | |
| 18 | 18 | import java.lang.reflect.Proxy; |
| 19 | -import java.util.*; | |
| 19 | +import java.util.List; | |
| 20 | 20 | |
| 21 | 21 | class AccessorReflectionMapper<T> extends AccessorMapper<T> { |
| 22 | 22 | |
| @@ -28,7 +28,7 @@ | ||
| 28 | 28 | @SuppressWarnings({"unchecked", "rawtypes"}) |
| 29 | 29 | private AccessorReflectionMapper(Class<T> daoClass, List<MethodMapper> methods) { |
| 30 | 30 | super(daoClass, methods); |
| 31 | - this.proxyClasses = (Class<T>[])new Class[]{ daoClass }; | |
| 31 | + this.proxyClasses = (Class<T>[]) new Class[]{daoClass}; | |
| 32 | 32 | this.handler = new AccessorInvocationHandler<T>(this); |
| 33 | 33 | } |
| 34 | 34 |
modified driver-mapping/src/main/java/com/datastax/driver/mapping/AnnotationChecks.java +10 −11
| @@ -15,12 +15,11 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.mapping; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.mapping.annotations.Computed; | |
| 19 | +import com.datastax.driver.mapping.annotations.Table; | |
| 20 | + | |
| 18 | 21 | import java.lang.annotation.Annotation; |
| 19 | -import java.lang.reflect.*; | |
| 20 | 22 | import java.lang.reflect.Field; |
| 21 | -import java.util.*; | |
| 22 | - | |
| 23 | -import com.datastax.driver.mapping.annotations.*; | |
| 24 | 23 | |
| 25 | 24 | /** |
| 26 | 25 | * Various checks on mapping annotations. |
| @@ -38,7 +37,7 @@ | ||
| 38 | 37 | T instance = annotatedClass.getAnnotation(annotation); |
| 39 | 38 | if (instance == null) |
| 40 | 39 | throw new IllegalArgumentException(String.format("@%s annotation was not found on type %s", |
| 41 | - annotation.getSimpleName(), annotatedClass.getName())); | |
| 40 | + annotation.getSimpleName(), annotatedClass.getName())); | |
| 42 | 41 | |
| 43 | 42 | // Check that no other mapping annotations are present |
| 44 | 43 | validateAnnotations(annotatedClass, annotation); |
| @@ -51,8 +50,8 @@ | ||
| 51 | 50 | Class<? extends Annotation> invalid = validateAnnotations(clazz.getAnnotations(), allowed); |
| 52 | 51 | if (invalid != null) |
| 53 | 52 | throw new IllegalArgumentException(String.format("Cannot have both @%s and @%s on type %s", |
| 54 | - allowed.getSimpleName(), invalid.getSimpleName(), | |
| 55 | - clazz.getName())); | |
| 53 | + allowed.getSimpleName(), invalid.getSimpleName(), | |
| 54 | + clazz.getName())); | |
| 56 | 55 | } |
| 57 | 56 | |
| 58 | 57 | /** |
| @@ -62,9 +61,9 @@ | ||
| 62 | 61 | Class<? extends Annotation> invalid = validateAnnotations(field.getAnnotations(), allowed); |
| 63 | 62 | if (invalid != null) |
| 64 | 63 | throw new IllegalArgumentException(String.format("Annotation @%s is not allowed on field %s of %s %s", |
| 65 | - invalid.getSimpleName(), | |
| 66 | - field.getName(), classDescription, | |
| 67 | - field.getDeclaringClass().getName())); | |
| 64 | + invalid.getSimpleName(), | |
| 65 | + field.getName(), classDescription, | |
| 66 | + field.getDeclaringClass().getName())); | |
| 68 | 67 | |
| 69 | 68 | checkValidComputed(field); |
| 70 | 69 | } |
| @@ -88,7 +87,7 @@ | ||
| 88 | 87 | |
| 89 | 88 | static void checkValidComputed(Field field) { |
| 90 | 89 | Computed computed = field.getAnnotation(Computed.class); |
| 91 | - if (computed != null && computed.value().isEmpty()){ | |
| 90 | + if (computed != null && computed.value().isEmpty()) { | |
| 92 | 91 | throw new IllegalArgumentException(String.format("Field %s: attribute 'value' of annotation @Computed is mandatory for computed fields", field.getName())); |
| 93 | 92 | } |
| 94 | 93 | } |
modified driver-mapping/src/main/java/com/datastax/driver/mapping/AnnotationParser.java +32 −32
| @@ -15,21 +15,20 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.mapping; |
| 17 | 17 | |
| 18 | -import java.lang.annotation.Annotation; | |
| 19 | -import java.lang.reflect.Field; | |
| 20 | -import java.lang.reflect.*; | |
| 21 | -import java.util.*; | |
| 22 | -import java.util.concurrent.atomic.AtomicInteger; | |
| 23 | - | |
| 24 | -import com.google.common.base.Strings; | |
| 25 | -import com.google.common.collect.Maps; | |
| 26 | -import com.google.common.reflect.TypeToken; | |
| 27 | - | |
| 28 | 18 | import com.datastax.driver.core.ConsistencyLevel; |
| 29 | 19 | import com.datastax.driver.core.TypeCodec; |
| 30 | 20 | import com.datastax.driver.core.UserType; |
| 31 | 21 | import com.datastax.driver.mapping.MethodMapper.ParamMapper; |
| 32 | 22 | import com.datastax.driver.mapping.annotations.*; |
| 23 | +import com.google.common.base.Strings; | |
| 24 | +import com.google.common.collect.Maps; | |
| 25 | +import com.google.common.reflect.TypeToken; | |
| 26 | + | |
| 27 | +import java.lang.annotation.Annotation; | |
| 28 | +import java.lang.reflect.Field; | |
| 29 | +import java.lang.reflect.*; | |
| 30 | +import java.util.*; | |
| 31 | +import java.util.concurrent.atomic.AtomicInteger; | |
| 33 | 32 | |
| 34 | 33 | /** |
| 35 | 34 | * Static metods that facilitates parsing class annotations into the corresponding {@link EntityMapper}. |
| @@ -42,7 +41,8 @@ | ||
| 42 | 41 | } |
| 43 | 42 | }; |
| 44 | 43 | |
| 45 | - private AnnotationParser() {} | |
| 44 | + private AnnotationParser() { | |
| 45 | + } | |
| 46 | 46 | |
| 47 | 47 | public static <T> EntityMapper<T> parseEntity(Class<T> entityClass, EntityMapper.Factory factory, MappingManager mappingManager) { |
| 48 | 48 | Table table = AnnotationChecks.getTypeAnnotation(Table.class, entityClass); |
| @@ -57,9 +57,9 @@ | ||
| 57 | 57 | ksName = mappingManager.getSession().getLoggedKeyspace(); |
| 58 | 58 | if (Strings.isNullOrEmpty(ksName)) |
| 59 | 59 | throw new IllegalArgumentException(String.format( |
| 60 | - "Error creating mapper for class %s, the @%s annotation declares no default keyspace, and the session is not currently logged to any keyspace", | |
| 61 | - entityClass.getSimpleName(), | |
| 62 | - Table.class.getSimpleName() | |
| 60 | + "Error creating mapper for class %s, the @%s annotation declares no default keyspace, and the session is not currently logged to any keyspace", | |
| 61 | + entityClass.getSimpleName(), | |
| 62 | + Table.class.getSimpleName() | |
| 63 | 63 | )); |
| 64 | 64 | } |
| 65 | 65 | |
| @@ -70,15 +70,15 @@ | ||
| 70 | 70 | List<Field> rgs = new ArrayList<Field>(); |
| 71 | 71 | |
| 72 | 72 | for (Field field : entityClass.getDeclaredFields()) { |
| 73 | - if(field.isSynthetic() || (field.getModifiers() & Modifier.STATIC) == Modifier.STATIC) | |
| 73 | + if (field.isSynthetic() || (field.getModifiers() & Modifier.STATIC) == Modifier.STATIC) | |
| 74 | 74 | continue; |
| 75 | 75 | |
| 76 | 76 | if (mappingManager.isCassandraV1 && field.getAnnotation(Computed.class) != null) |
| 77 | 77 | throw new UnsupportedOperationException("Computed fields are not supported with native protocol v1"); |
| 78 | 78 | |
| 79 | 79 | AnnotationChecks.validateAnnotations(field, "entity", |
| 80 | - Column.class, ClusteringColumn.class, Frozen.class, FrozenKey.class, | |
| 81 | - FrozenValue.class, PartitionKey.class, Transient.class, Computed.class); | |
| 80 | + Column.class, ClusteringColumn.class, Frozen.class, FrozenKey.class, | |
| 81 | + FrozenValue.class, PartitionKey.class, Transient.class, Computed.class); | |
| 82 | 82 | |
| 83 | 83 | if (field.getAnnotation(Transient.class) != null) |
| 84 | 84 | continue; |
| @@ -105,8 +105,8 @@ | ||
| 105 | 105 | validateOrder(ccs, "@ClusteringColumn"); |
| 106 | 106 | |
| 107 | 107 | mapper.addColumns(createColumnMappers(pks, factory, mapper.entityClass, mappingManager, columnCounter), |
| 108 | - createColumnMappers(ccs, factory, mapper.entityClass, mappingManager, columnCounter), | |
| 109 | - createColumnMappers(rgs, factory, mapper.entityClass, mappingManager, columnCounter)); | |
| 108 | + createColumnMappers(ccs, factory, mapper.entityClass, mappingManager, columnCounter), | |
| 109 | + createColumnMappers(rgs, factory, mapper.entityClass, mappingManager, columnCounter)); | |
| 110 | 110 | return mapper; |
| 111 | 111 | } |
| 112 | 112 | |
| @@ -130,9 +130,9 @@ | ||
| 130 | 130 | ksName = mappingManager.getSession().getLoggedKeyspace(); |
| 131 | 131 | if (Strings.isNullOrEmpty(ksName)) |
| 132 | 132 | throw new IllegalArgumentException(String.format( |
| 133 | - "Error creating UDT codec for class %s, the @%s annotation declares no default keyspace, and the session is not currently logged to any keyspace", | |
| 134 | - udtClass.getSimpleName(), | |
| 135 | - UDT.class.getSimpleName() | |
| 133 | + "Error creating UDT codec for class %s, the @%s annotation declares no default keyspace, and the session is not currently logged to any keyspace", | |
| 134 | + udtClass.getSimpleName(), | |
| 135 | + UDT.class.getSimpleName() | |
| 136 | 136 | )); |
| 137 | 137 | } |
| 138 | 138 | |
| @@ -141,12 +141,12 @@ | ||
| 141 | 141 | List<Field> columns = new ArrayList<Field>(); |
| 142 | 142 | |
| 143 | 143 | for (Field field : udtClass.getDeclaredFields()) { |
| 144 | - if(field.isSynthetic() || (field.getModifiers() & Modifier.STATIC) == Modifier.STATIC) | |
| 144 | + if (field.isSynthetic() || (field.getModifiers() & Modifier.STATIC) == Modifier.STATIC) | |
| 145 | 145 | continue; |
| 146 | 146 | |
| 147 | 147 | AnnotationChecks.validateAnnotations(field, "UDT", |
| 148 | - com.datastax.driver.mapping.annotations.Field.class, Frozen.class, FrozenKey.class, | |
| 149 | - FrozenValue.class, Transient.class); | |
| 148 | + com.datastax.driver.mapping.annotations.Field.class, Frozen.class, FrozenKey.class, | |
| 149 | + FrozenValue.class, Transient.class); | |
| 150 | 150 | |
| 151 | 151 | if (field.getAnnotation(Transient.class) != null) |
| 152 | 152 | continue; |
| @@ -182,7 +182,7 @@ | ||
| 182 | 182 | int pos = position(field); |
| 183 | 183 | if (pos != i) |
| 184 | 184 | throw new IllegalArgumentException(String.format("Invalid ordering value %d for annotation %s of column %s, was expecting %d", |
| 185 | - pos, annotation, field.getName(), i)); | |
| 185 | + pos, annotation, field.getName(), i)); | |
| 186 | 186 | } |
| 187 | 187 | } |
| 188 | 188 | |
| @@ -220,7 +220,7 @@ | ||
| 220 | 220 | Column column = field.getAnnotation(Column.class); |
| 221 | 221 | Computed computedField = field.getAnnotation(Computed.class); |
| 222 | 222 | if (column != null && !column.name().isEmpty()) { |
| 223 | - if (computedField != null){ | |
| 223 | + if (computedField != null) { | |
| 224 | 224 | throw new IllegalArgumentException("Cannot use @Column and @Computed on the same field"); |
| 225 | 225 | } |
| 226 | 226 | return column.caseSensitive() ? column.name() : column.name().toLowerCase(); |
| @@ -251,12 +251,12 @@ | ||
| 251 | 251 | |
| 252 | 252 | try { |
| 253 | 253 | @SuppressWarnings("unchecked") |
| 254 | - TypeCodec<Object> instance = (TypeCodec<Object>)codecClass.newInstance(); | |
| 254 | + TypeCodec<Object> instance = (TypeCodec<Object>) codecClass.newInstance(); | |
| 255 | 255 | return instance; |
| 256 | 256 | } catch (Exception e) { |
| 257 | 257 | throw new IllegalArgumentException(String.format( |
| 258 | - "Cannot create an instance of custom codec %s for field %s", | |
| 259 | - codecClass, field | |
| 258 | + "Cannot create an instance of custom codec %s for field %s", | |
| 259 | + codecClass, field | |
| 260 | 260 | ), e); |
| 261 | 261 | } |
| 262 | 262 | } |
| @@ -296,7 +296,7 @@ | ||
| 296 | 296 | Class<? extends TypeCodec<?>> codecClass = null; |
| 297 | 297 | for (Annotation a : paramAnnotations[i]) { |
| 298 | 298 | if (a.annotationType().equals(Param.class)) { |
| 299 | - Param param = (Param)a; | |
| 299 | + Param param = (Param) a; | |
| 300 | 300 | paramName = param.value(); |
| 301 | 301 | if (paramName.isEmpty()) |
| 302 | 302 | paramName = null; |
| @@ -332,7 +332,7 @@ | ||
| 332 | 332 | return factory.create(accClass, methods); |
| 333 | 333 | } |
| 334 | 334 | |
| 335 | - @SuppressWarnings({ "unchecked", "rawtypes" }) | |
| 335 | + @SuppressWarnings({"unchecked", "rawtypes"}) | |
| 336 | 336 | private static ParamMapper newParamMapper(String className, String methodName, int idx, String paramName, Class<? extends TypeCodec<?>> codecClass, Type paramType, Annotation[] paramAnnotations, MappingManager mappingManager) { |
| 337 | 337 | if (paramType instanceof Class) { |
| 338 | 338 | Class<?> paramClass = (Class<?>) paramType; |
modified driver-mapping/src/main/java/com/datastax/driver/mapping/ColumnMapper.java +15 −12
| @@ -15,22 +15,25 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.mapping; |
| 17 | 17 | |
| 18 | -import java.lang.reflect.Field; | |
| 19 | -import java.util.concurrent.atomic.AtomicInteger; | |
| 20 | - | |
| 21 | -import com.google.common.reflect.TypeToken; | |
| 22 | - | |
| 23 | 18 | import com.datastax.driver.core.Metadata; |
| 24 | 19 | import com.datastax.driver.core.TypeCodec; |
| 20 | +import com.google.common.reflect.TypeToken; | |
| 21 | + | |
| 22 | +import java.lang.reflect.Field; | |
| 23 | +import java.util.concurrent.atomic.AtomicInteger; | |
| 25 | 24 | |
| 26 | 25 | abstract class ColumnMapper<T> { |
| 27 | 26 | |
| 28 | - public enum Kind {PARTITION_KEY, CLUSTERING_COLUMN, REGULAR, COMPUTED}; | |
| 27 | + public enum Kind {PARTITION_KEY, CLUSTERING_COLUMN, REGULAR, COMPUTED} | |
| 28 | + | |
| 29 | + ; | |
| 29 | 30 | |
| 30 | 31 | private final String columnName; |
| 31 | 32 | private final String alias; |
| 32 | 33 | protected final String fieldName; |
| 33 | - /** The type of the Java field in the mapped class */ | |
| 34 | + /** | |
| 35 | + * The type of the Java field in the mapped class | |
| 36 | + */ | |
| 34 | 37 | protected final TypeToken<Object> fieldType; |
| 35 | 38 | protected final Kind kind; |
| 36 | 39 | protected final int position; |
| @@ -40,10 +43,10 @@ | ||
| 40 | 43 | protected ColumnMapper(Field field, int position, AtomicInteger columnCounter) { |
| 41 | 44 | this.columnName = AnnotationParser.columnName(field); |
| 42 | 45 | this.alias = (columnCounter != null) |
| 43 | - ? AnnotationParser.newAlias(field, columnCounter.incrementAndGet()) | |
| 44 | - : null; | |
| 46 | + ? AnnotationParser.newAlias(field, columnCounter.incrementAndGet()) | |
| 47 | + : null; | |
| 45 | 48 | this.fieldName = field.getName(); |
| 46 | - this.fieldType = (TypeToken<Object>)TypeToken.of(field.getGenericType()); | |
| 49 | + this.fieldType = (TypeToken<Object>) TypeToken.of(field.getGenericType()); | |
| 47 | 50 | this.kind = AnnotationParser.kind(field); |
| 48 | 51 | this.position = position; |
| 49 | 52 | this.customCodec = AnnotationParser.customCodec(field); |
| @@ -55,8 +58,8 @@ | ||
| 55 | 58 | |
| 56 | 59 | public String getColumnName() { |
| 57 | 60 | return kind == Kind.COMPUTED |
| 58 | - ? columnName | |
| 59 | - : Metadata.quote(columnName); | |
| 61 | + ? columnName | |
| 62 | + : Metadata.quote(columnName); | |
| 60 | 63 | } |
| 61 | 64 | |
| 62 | 65 | public String getAlias() { |
modified driver-mapping/src/main/java/com/datastax/driver/mapping/EntityMapper.java +5 −2
| @@ -15,11 +15,13 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.mapping; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.ConsistencyLevel; | |
| 19 | + | |
| 18 | 20 | import java.lang.reflect.Field; |
| 19 | -import java.util.*; | |
| 21 | +import java.util.ArrayList; | |
| 22 | +import java.util.List; | |
| 20 | 23 | import java.util.concurrent.atomic.AtomicInteger; |
| 21 | 24 | |
| 22 | -import com.datastax.driver.core.ConsistencyLevel; | |
| 23 | 25 | import static com.datastax.driver.core.querybuilder.QueryBuilder.quote; |
| 24 | 26 | |
| 25 | 27 | abstract class EntityMapper<T> { |
| @@ -84,6 +86,7 @@ | ||
| 84 | 86 | |
| 85 | 87 | interface Factory { |
| 86 | 88 | public <T> EntityMapper<T> create(Class<T> entityClass, String keyspace, String table, ConsistencyLevel writeConsistency, ConsistencyLevel readConsistency); |
| 89 | + | |
| 87 | 90 | public <T> ColumnMapper<T> createColumnMapper(Class<T> componentClass, Field field, int position, MappingManager mappingManager, AtomicInteger columnCounter); |
| 88 | 91 | } |
| 89 | 92 | } |
modified driver-mapping/src/main/java/com/datastax/driver/mapping/MappedUDTCodec.java +2 −6
| @@ -15,15 +15,11 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.mapping; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.*; | |
| 19 | + | |
| 18 | 20 | import java.nio.ByteBuffer; |
| 19 | -import java.util.List; | |
| 20 | 21 | import java.util.Map; |
| 21 | 22 | |
| 22 | -import com.google.common.collect.Lists; | |
| 23 | - | |
| 24 | -import com.datastax.driver.core.*; | |
| 25 | -import com.datastax.driver.core.exceptions.InvalidTypeException; | |
| 26 | - | |
| 27 | 23 | /** |
| 28 | 24 | * Serializes a class annotated with {@code @UDT} to the corresponding CQL user-defined type. |
| 29 | 25 | */ |
modified driver-mapping/src/main/java/com/datastax/driver/mapping/Mapper.java +69 −59
| @@ -15,8 +15,13 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.mapping; |
| 17 | 17 | |
| 18 | -import java.util.*; | |
| 19 | - | |
| 18 | +import com.datastax.driver.core.*; | |
| 19 | +import com.datastax.driver.core.querybuilder.Delete; | |
| 20 | +import com.datastax.driver.core.querybuilder.Insert; | |
| 21 | +import com.datastax.driver.core.querybuilder.QueryBuilder; | |
| 22 | +import com.datastax.driver.mapping.Mapper.Option.SaveNullFields; | |
| 23 | +import com.datastax.driver.mapping.annotations.Accessor; | |
| 24 | +import com.datastax.driver.mapping.annotations.Computed; | |
| 20 | 25 | import com.google.common.base.Function; |
| 21 | 26 | import com.google.common.base.Functions; |
| 22 | 27 | import com.google.common.base.Objects; |
| @@ -26,21 +31,14 @@ | ||
| 26 | 31 | import org.slf4j.Logger; |
| 27 | 32 | import org.slf4j.LoggerFactory; |
| 28 | 33 | |
| 29 | -import static com.google.common.base.Preconditions.checkArgument; | |
| 30 | - | |
| 31 | -import com.datastax.driver.core.*; | |
| 32 | -import com.datastax.driver.core.querybuilder.Delete; | |
| 33 | -import com.datastax.driver.core.querybuilder.Insert; | |
| 34 | -import com.datastax.driver.core.querybuilder.QueryBuilder; | |
| 35 | -import com.datastax.driver.mapping.Mapper.Option.SaveNullFields; | |
| 36 | -import com.datastax.driver.mapping.annotations.Accessor; | |
| 37 | -import com.datastax.driver.mapping.annotations.Computed; | |
| 34 | +import java.util.*; | |
| 38 | 35 | |
| 39 | 36 | import static com.datastax.driver.mapping.Mapper.Option.Type.SAVE_NULL_FIELDS; |
| 37 | +import static com.google.common.base.Preconditions.checkArgument; | |
| 40 | 38 | |
| 41 | 39 | /** |
| 42 | 40 | * An object handling the mapping of a particular class. |
| 43 | - * <p> | |
| 41 | + * <p/> | |
| 44 | 42 | * A {@code Mapper} object is obtained from a {@code MappingManager} using the |
| 45 | 43 | * {@link MappingManager#mapper} method. |
| 46 | 44 | */ |
| @@ -148,7 +146,7 @@ | ||
| 148 | 146 | |
| 149 | 147 | /** |
| 150 | 148 | * Creates a query that can be used to save the provided entity. |
| 151 | - * <p> | |
| 149 | + * <p/> | |
| 152 | 150 | * This method is useful if you want to setup a number of options (tracing, |
| 153 | 151 | * conistency level, ...) of the returned statement before executing it manually |
| 154 | 152 | * or need access to the {@code ResultSet} object after execution (to get the |
| @@ -164,7 +162,7 @@ | ||
| 164 | 162 | |
| 165 | 163 | /** |
| 166 | 164 | * Creates a query that can be used to save the provided entity. |
| 167 | - * <p> | |
| 165 | + * <p/> | |
| 168 | 166 | * This method is useful if you want to setup a number of options (tracing, |
| 169 | 167 | * conistency level, ...) of the returned statement before executing it manually |
| 170 | 168 | * or need access to the {@code ResultSet} object after execution (to get the |
| @@ -217,7 +215,7 @@ | ||
| 217 | 215 | } |
| 218 | 216 | |
| 219 | 217 | private static boolean shouldSaveNullFields(EnumMap<Option.Type, Option> options) { |
| 220 | - SaveNullFields option = (SaveNullFields)options.get(SAVE_NULL_FIELDS); | |
| 218 | + SaveNullFields option = (SaveNullFields) options.get(SAVE_NULL_FIELDS); | |
| 221 | 219 | return option == null || option.saveNullFields; |
| 222 | 220 | } |
| 223 | 221 | |
| @@ -231,7 +229,7 @@ | ||
| 231 | 229 | |
| 232 | 230 | /** |
| 233 | 231 | * Save an entity mapped by this mapper. |
| 234 | - * <p> | |
| 232 | + * <p/> | |
| 235 | 233 | * This method is basically equivalent to: {@code getManager().getSession().execute(saveQuery(entity))}. |
| 236 | 234 | * |
| 237 | 235 | * @param entity the entity to save. |
| @@ -260,7 +258,7 @@ | ||
| 260 | 258 | |
| 261 | 259 | /** |
| 262 | 260 | * Save an entity mapped by this mapper asynchronously. |
| 263 | - * <p> | |
| 261 | + * <p/> | |
| 264 | 262 | * This method is basically equivalent to: {@code getManager().getSession().executeAsync(saveQuery(entity))}. |
| 265 | 263 | * |
| 266 | 264 | * @param entity the entity to save. |
| @@ -272,7 +270,7 @@ | ||
| 272 | 270 | |
| 273 | 271 | /** |
| 274 | 272 | * Save an entity mapped by this mapper asynchronously using special options for save. |
| 275 | - * <p> | |
| 273 | + * <p/> | |
| 276 | 274 | * This method is basically equivalent to: {@code getManager().getSession().executeAsync(saveQuery(entity, options))}. |
| 277 | 275 | * |
| 278 | 276 | * @param entity the entity to save. |
| @@ -285,14 +283,14 @@ | ||
| 285 | 283 | |
| 286 | 284 | /** |
| 287 | 285 | * Creates a query to fetch entity given its PRIMARY KEY. |
| 288 | - * <p> | |
| 286 | + * <p/> | |
| 289 | 287 | * The values provided must correspond to the columns composing the PRIMARY |
| 290 | 288 | * KEY (in the order of said primary key). |
| 291 | - * <p> | |
| 289 | + * <p/> | |
| 292 | 290 | * This method is useful if you want to setup a number of options (tracing, |
| 293 | 291 | * conistency level, ...) of the returned statement before executing it manually, |
| 294 | 292 | * but in other cases, calling {@link #get} or {@link #getAsync} is shorter. |
| 295 | - * <p> | |
| 293 | + * <p/> | |
| 296 | 294 | * This method allows you to provide a suite of {@link Option} to include in |
| 297 | 295 | * the GET query. Options currently supported for GET are : |
| 298 | 296 | * <ul> |
| @@ -315,7 +313,7 @@ | ||
| 315 | 313 | |
| 316 | 314 | for (Object o : objects) { |
| 317 | 315 | if (o instanceof Option) { |
| 318 | - Option option = (Option)o; | |
| 316 | + Option option = (Option) o; | |
| 319 | 317 | options.put(option.type, option); |
| 320 | 318 | } else { |
| 321 | 319 | pks.add(o); |
| @@ -354,7 +352,7 @@ | ||
| 354 | 352 | |
| 355 | 353 | /** |
| 356 | 354 | * Fetch an entity based on its primary key. |
| 357 | - * <p> | |
| 355 | + * <p/> | |
| 358 | 356 | * This method is basically equivalent to: {@code map(getManager().getSession().execute(getQuery(objects))).one()}. |
| 359 | 357 | * |
| 360 | 358 | * @param objects the primary key of the entity to fetch, or more precisely |
| @@ -371,7 +369,7 @@ | ||
| 371 | 369 | |
| 372 | 370 | /** |
| 373 | 371 | * Fetch an entity based on its primary key asynchronously. |
| 374 | - * <p> | |
| 372 | + * <p/> | |
| 375 | 373 | * This method is basically equivalent to mapping the result of: {@code getManager().getSession().executeAsync(getQuery(objects))}. |
| 376 | 374 | * |
| 377 | 375 | * @param objects the primary key of the entity to fetch, or more precisely |
| @@ -389,19 +387,19 @@ | ||
| 389 | 387 | |
| 390 | 388 | /** |
| 391 | 389 | * Creates a query that can be used to delete the provided entity. |
| 392 | - * <p> | |
| 390 | + * <p/> | |
| 393 | 391 | * This method is a shortcut that extract the PRIMARY KEY from the |
| 394 | 392 | * provided entity and call {@link #deleteQuery(Object...)} with it. |
| 395 | 393 | * This method allows you to provide a suite of {@link Option} to include in |
| 396 | 394 | * the DELETE query. Note : currently, only {@link com.datastax.driver.mapping.Mapper.Option.Timestamp} |
| 397 | 395 | * is supported for DELETE queries. |
| 398 | - * <p> | |
| 396 | + * <p/> | |
| 399 | 397 | * This method is useful if you want to setup a number of options (tracing, |
| 400 | 398 | * conistency level, ...) of the returned statement before executing it manually |
| 401 | 399 | * or need access to the {@code ResultSet} object after execution (to get the |
| 402 | 400 | * trace, the execution info, ...), but in other cases, calling {@link #delete} |
| 403 | 401 | * or {@link #deleteAsync} is shorter. |
| 404 | - * <p> | |
| 402 | + * <p/> | |
| 405 | 403 | * This method allows you to provide a suite of {@link Option} to include in |
| 406 | 404 | * the DELETE query. Options currently supported for DELETE are : |
| 407 | 405 | * <ul> |
| @@ -426,10 +424,10 @@ | ||
| 426 | 424 | |
| 427 | 425 | /** |
| 428 | 426 | * Creates a query that can be used to delete the provided entity. |
| 429 | - * <p> | |
| 427 | + * <p/> | |
| 430 | 428 | * This method is a shortcut that extract the PRIMARY KEY from the |
| 431 | 429 | * provided entity and call {@link #deleteQuery(Object...)} with it. |
| 432 | - * <p> | |
| 430 | + * <p/> | |
| 433 | 431 | * This method is useful if you want to setup a number of options (tracing, |
| 434 | 432 | * conistency level, ...) of the returned statement before executing it manually |
| 435 | 433 | * or need access to the {@code ResultSet} object after execution (to get the |
| @@ -450,13 +448,13 @@ | ||
| 450 | 448 | |
| 451 | 449 | /** |
| 452 | 450 | * Creates a query that can be used to delete an entity given its PRIMARY KEY. |
| 453 | - * <p> | |
| 451 | + * <p/> | |
| 454 | 452 | * The values provided must correspond to the columns composing the PRIMARY |
| 455 | 453 | * KEY (in the order of said primary key). The values can also contain, after |
| 456 | 454 | * specifying the primary keys columns, a suite of {@link Option} to include in |
| 457 | 455 | * the DELETE query. Note : currently, only {@link com.datastax.driver.mapping.Mapper.Option.Timestamp} |
| 458 | 456 | * is supported for DELETE queries. |
| 459 | - * <p> | |
| 457 | + * <p/> | |
| 460 | 458 | * This method is useful if you want to setup a number of options (tracing, |
| 461 | 459 | * conistency level, ...) of the returned statement before executing it manually |
| 462 | 460 | * or need access to the {@code ResultSet} object after execution (to get the |
| @@ -486,7 +484,7 @@ | ||
| 486 | 484 | |
| 487 | 485 | for (Object o : objects) { |
| 488 | 486 | if (o instanceof Option) { |
| 489 | - Option option = (Option)o; | |
| 487 | + Option option = (Option) o; | |
| 490 | 488 | options.put(option.type, option); |
| 491 | 489 | } else { |
| 492 | 490 | pks.add(o); |
| @@ -526,7 +524,7 @@ | ||
| 526 | 524 | |
| 527 | 525 | /** |
| 528 | 526 | * Deletes an entity mapped by this mapper. |
| 529 | - * <p> | |
| 527 | + * <p/> | |
| 530 | 528 | * This method is basically equivalent to: {@code getManager().getSession().execute(deleteQuery(entity))}. |
| 531 | 529 | * |
| 532 | 530 | * @param entity the entity to delete. |
| @@ -537,7 +535,7 @@ | ||
| 537 | 535 | |
| 538 | 536 | /** |
| 539 | 537 | * Deletes an entity mapped by this mapper using provided options. |
| 540 | - * <p> | |
| 538 | + * <p/> | |
| 541 | 539 | * This method is basically equivalent to: {@code getManager().getSession().execute(deleteQuery(entity, options))}. |
| 542 | 540 | * |
| 543 | 541 | * @param entity the entity to delete. |
| @@ -549,7 +547,7 @@ | ||
| 549 | 547 | |
| 550 | 548 | /** |
| 551 | 549 | * Deletes an entity mapped by this mapper asynchronously. |
| 552 | - * <p> | |
| 550 | + * <p/> | |
| 553 | 551 | * This method is basically equivalent to: {@code getManager().getSession().executeAsync(deleteQuery(entity))}. |
| 554 | 552 | * |
| 555 | 553 | * @param entity the entity to delete. |
| @@ -561,7 +559,7 @@ | ||
| 561 | 559 | |
| 562 | 560 | /** |
| 563 | 561 | * Deletes an entity mapped by this mapper asynchronously using provided options. |
| 564 | - * <p> | |
| 562 | + * <p/> | |
| 565 | 563 | * This method is basically equivalent to: {@code getManager().getSession().executeAsync(deleteQuery(entity, options))}. |
| 566 | 564 | * |
| 567 | 565 | * @param entity the entity to delete. |
| @@ -574,7 +572,7 @@ | ||
| 574 | 572 | |
| 575 | 573 | /** |
| 576 | 574 | * Deletes an entity based on its primary key. |
| 577 | - * <p> | |
| 575 | + * <p/> | |
| 578 | 576 | * This method is basically equivalent to: {@code getManager().getSession().execute(deleteQuery(objects))}. |
| 579 | 577 | * |
| 580 | 578 | * @param objects the primary key of the entity to delete, or more precisely |
| @@ -591,7 +589,7 @@ | ||
| 591 | 589 | |
| 592 | 590 | /** |
| 593 | 591 | * Deletes an entity based on its primary key asynchronously. |
| 594 | - * <p> | |
| 592 | + * <p/> | |
| 595 | 593 | * This method is basically equivalent to: {@code getManager().getSession().executeAsync(deleteQuery(objects))}. |
| 596 | 594 | * |
| 597 | 595 | * @param objects the primary key of the entity to delete, or more precisely |
| @@ -608,7 +606,7 @@ | ||
| 608 | 606 | |
| 609 | 607 | /** |
| 610 | 608 | * Maps the rows from a {@code ResultSet} into the class this is a mapper of. |
| 611 | - * <p> | |
| 609 | + * <p/> | |
| 612 | 610 | * Use this method to map a result set that was not generated by the mapper (e.g. a result set coming from a |
| 613 | 611 | * manual query or an {@link Accessor method}. |
| 614 | 612 | * It expects that the result set contains all column mapped in the target class, |
| @@ -619,7 +617,6 @@ | ||
| 619 | 617 | * will encapsulate {@code resultSet} and so consuming results from this |
| 620 | 618 | * returned mapped result set will consume results from {@code resultSet} |
| 621 | 619 | * and vice-versa. |
| 622 | - * | |
| 623 | 620 | * @see #mapAliased(ResultSet) |
| 624 | 621 | */ |
| 625 | 622 | public Result<T> map(ResultSet resultSet) { |
| @@ -628,7 +625,7 @@ | ||
| 628 | 625 | |
| 629 | 626 | /** |
| 630 | 627 | * Maps the rows from a {@code ResultSet} into the class this is a mapper of. |
| 631 | - * <p> | |
| 628 | + * <p/> | |
| 632 | 629 | * Use this method to map a result set coming from the execution of the {@code Statement} returned by |
| 633 | 630 | * {@link #getQuery(Object...)}. {@link Computed} fields will be filled in the mapped object. |
| 634 | 631 | * |
| @@ -637,13 +634,12 @@ | ||
| 637 | 634 | * will encapsulate {@code resultSet} and so consuming results from this |
| 638 | 635 | * returned mapped result set will consume results from {@code resultSet} |
| 639 | 636 | * and vice-versa. |
| 640 | - * | |
| 641 | 637 | * @see #map(ResultSet) |
| 642 | 638 | */ |
| 643 | 639 | public Result<T> mapAliased(ResultSet resultSet) { |
| 644 | 640 | return (manager.isCassandraV1) |
| 645 | - ? map(resultSet) // no aliases | |
| 646 | - : new Result<T>(resultSet, mapper, protocolVersion, true); | |
| 641 | + ? map(resultSet) // no aliases | |
| 642 | + : new Result<T>(resultSet, mapper, protocolVersion, true); | |
| 647 | 643 | } |
| 648 | 644 | |
| 649 | 645 | /** |
| @@ -719,20 +715,20 @@ | ||
| 719 | 715 | |
| 720 | 716 | /** |
| 721 | 717 | * An option for a mapper operation. |
| 722 | - * <p> | |
| 718 | + * <p/> | |
| 723 | 719 | * Options can be passed to individual operations: |
| 724 | 720 | * <pre> |
| 725 | 721 | * mapper.save(myObject, Option.ttl(3600)); |
| 726 | 722 | * </pre> |
| 727 | - * | |
| 723 | + * <p/> | |
| 728 | 724 | * The mapper can also have defaults, that will apply to all operations that do not |
| 729 | 725 | * override these particular option: |
| 730 | 726 | * <pre> |
| 731 | 727 | * mapper.setDefaultSaveOptions(Option.ttl(3600)); |
| 732 | 728 | * mapper.save(myObject); |
| 733 | 729 | * </pre> |
| 734 | - * | |
| 735 | - * <p> | |
| 730 | + * <p/> | |
| 731 | + * <p/> | |
| 736 | 732 | * See the static methods in this class for available options. |
| 737 | 733 | */ |
| 738 | 734 | public static abstract class Option { |
| @@ -748,7 +744,7 @@ | ||
| 748 | 744 | /** |
| 749 | 745 | * Creates a new Option object to add time-to-live to a mapper operation. This is |
| 750 | 746 | * only valid for save operations. |
| 751 | - * <p> | |
| 747 | + * <p/> | |
| 752 | 748 | * Note that this option is only available if using {@link ProtocolVersion#V2} or above. |
| 753 | 749 | * |
| 754 | 750 | * @param ttl the TTL (in seconds). |
| @@ -761,7 +757,7 @@ | ||
| 761 | 757 | /** |
| 762 | 758 | * Creates a new Option object to add a timestamp to a mapper operation. This is |
| 763 | 759 | * only valid for save and delete operations. |
| 764 | - * <p> | |
| 760 | + * <p/> | |
| 765 | 761 | * Note that this option is only available if using {@link ProtocolVersion#V2} or above. |
| 766 | 762 | * |
| 767 | 763 | * @param timestamp the timestamp (in microseconds). |
| @@ -774,7 +770,7 @@ | ||
| 774 | 770 | /** |
| 775 | 771 | * Creates a new Option object to add a consistency level value to a mapper operation. This |
| 776 | 772 | * is valid for save, delete and get operations. |
| 777 | - * <p> | |
| 773 | + * <p/> | |
| 778 | 774 | * Note that the consistency level can also be defined at the mapper level, as a parameter |
| 779 | 775 | * of the {@link com.datastax.driver.mapping.annotations.Table} annotation (this is redundant |
| 780 | 776 | * for backward compatibility). This option, whether defined on a specific call or as the |
| @@ -801,17 +797,17 @@ | ||
| 801 | 797 | /** |
| 802 | 798 | * Creates a new Option object to specify whether null entity fields should be included in |
| 803 | 799 | * insert queries. This option is valid only for save operations. |
| 804 | - * | |
| 800 | + * <p/> | |
| 805 | 801 | * If this option is not specified, it defaults to {@code true} (null fields are saved). |
| 806 | 802 | * |
| 807 | 803 | * @param enabled whether to include null fields in queries. |
| 808 | 804 | * @return the option. |
| 809 | 805 | */ |
| 810 | - public static Option saveNullFields(boolean enabled){ | |
| 806 | + public static Option saveNullFields(boolean enabled) { | |
| 811 | 807 | return new SaveNullFields(enabled); |
| 812 | 808 | } |
| 813 | 809 | |
| 814 | - public Type getType(){ | |
| 810 | + public Type getType() { | |
| 815 | 811 | return this.type; |
| 816 | 812 | } |
| 817 | 813 | |
| @@ -837,19 +833,23 @@ | ||
| 837 | 833 | void appendTo(Insert.Options usings) { |
| 838 | 834 | usings.and(QueryBuilder.ttl(QueryBuilder.bindMarker())); |
| 839 | 835 | } |
| 836 | + | |
| 840 | 837 | @Override |
| 841 | 838 | void appendTo(Delete.Options usings) { |
| 842 | 839 | throw new UnsupportedOperationException("shouldn't be called"); |
| 843 | 840 | } |
| 841 | + | |
| 844 | 842 | @Override |
| 845 | 843 | void addToPreparedStatement(BoundStatement bs, int i) { |
| 846 | 844 | bs.setInt(i, this.ttlValue); |
| 847 | 845 | } |
| 846 | + | |
| 848 | 847 | @Override |
| 849 | 848 | void checkValidFor(QueryType qt, MappingManager manager) { |
| 850 | 849 | checkArgument(!manager.isCassandraV1, "TTL option requires native protocol v2 or above"); |
| 851 | 850 | checkArgument(qt == QueryType.SAVE, "TTL option is only allowed in save queries"); |
| 852 | 851 | } |
| 852 | + | |
| 853 | 853 | @Override |
| 854 | 854 | boolean isIncludedInQuery() { |
| 855 | 855 | return true; |
| @@ -864,23 +864,28 @@ | ||
| 864 | 864 | super(Type.TIMESTAMP); |
| 865 | 865 | this.tsValue = value; |
| 866 | 866 | } |
| 867 | + | |
| 867 | 868 | @Override |
| 868 | 869 | void appendTo(Insert.Options usings) { |
| 869 | 870 | usings.and(QueryBuilder.timestamp(QueryBuilder.bindMarker())); |
| 870 | 871 | } |
| 872 | + | |
| 871 | 873 | @Override |
| 872 | 874 | void appendTo(Delete.Options usings) { |
| 873 | 875 | usings.and(QueryBuilder.timestamp(QueryBuilder.bindMarker())); |
| 874 | 876 | } |
| 877 | + | |
| 875 | 878 | @Override |
| 876 | 879 | void checkValidFor(QueryType qt, MappingManager manager) { |
| 877 | 880 | checkArgument(!manager.isCassandraV1, "Timestamp option requires native protocol v2 or above"); |
| 878 | 881 | checkArgument(qt == QueryType.SAVE || qt == QueryType.DEL, "Timestamp option is only allowed in save and delete queries"); |
| 879 | 882 | } |
| 883 | + | |
| 880 | 884 | @Override |
| 881 | 885 | void addToPreparedStatement(BoundStatement bs, int i) { |
| 882 | 886 | bs.setLong(i, this.tsValue); |
| 883 | 887 | } |
| 888 | + | |
| 884 | 889 | @Override |
| 885 | 890 | boolean isIncludedInQuery() { |
| 886 | 891 | return true; |
| @@ -895,10 +900,12 @@ | ||
| 895 | 900 | super(Type.CL); |
| 896 | 901 | this.cl = cl; |
| 897 | 902 | } |
| 903 | + | |
| 898 | 904 | @Override |
| 899 | 905 | void appendTo(Insert.Options usings) { |
| 900 | 906 | throw new UnsupportedOperationException("shouldn't be called"); |
| 901 | 907 | } |
| 908 | + | |
| 902 | 909 | @Override |
| 903 | 910 | void appendTo(Delete.Options usings) { |
| 904 | 911 | throw new UnsupportedOperationException("shouldn't be called"); |
| @@ -908,10 +915,11 @@ | ||
| 908 | 915 | void addToPreparedStatement(BoundStatement bs, int i) { |
| 909 | 916 | bs.setConsistencyLevel(cl); |
| 910 | 917 | } |
| 918 | + | |
| 911 | 919 | @Override |
| 912 | 920 | void checkValidFor(QueryType qt, MappingManager manager) { |
| 913 | 921 | checkArgument(qt == QueryType.SAVE || qt == QueryType.DEL || qt == QueryType.GET, |
| 914 | - "Consistency level option is only allowed in save, delete and get queries"); | |
| 922 | + "Consistency level option is only allowed in save, delete and get queries"); | |
| 915 | 923 | } |
| 916 | 924 | |
| 917 | 925 | @Override |
| @@ -928,10 +936,12 @@ | ||
| 928 | 936 | super(Type.TRACING); |
| 929 | 937 | this.tracing = tracing; |
| 930 | 938 | } |
| 939 | + | |
| 931 | 940 | @Override |
| 932 | 941 | void appendTo(Insert.Options usings) { |
| 933 | 942 | throw new UnsupportedOperationException("shouldn't be called"); |
| 934 | 943 | } |
| 944 | + | |
| 935 | 945 | @Override |
| 936 | 946 | void appendTo(Delete.Options usings) { |
| 937 | 947 | throw new UnsupportedOperationException("shouldn't be called"); |
| @@ -946,7 +956,7 @@ | ||
| 946 | 956 | @Override |
| 947 | 957 | void checkValidFor(QueryType qt, MappingManager manager) { |
| 948 | 958 | checkArgument(qt == QueryType.SAVE || qt == QueryType.DEL || qt == QueryType.GET, |
| 949 | - "Tracing option is only allowed in save, delete and get queries"); | |
| 959 | + "Tracing option is only allowed in save, delete and get queries"); | |
| 950 | 960 | } |
| 951 | 961 | |
| 952 | 962 | @Override |
| @@ -1015,10 +1025,10 @@ | ||
| 1015 | 1025 | if (this == other) |
| 1016 | 1026 | return true; |
| 1017 | 1027 | if (other instanceof MapperQueryKey) { |
| 1018 | - MapperQueryKey that = (MapperQueryKey)other; | |
| 1028 | + MapperQueryKey that = (MapperQueryKey) other; | |
| 1019 | 1029 | return this.queryType.equals(that.queryType) |
| 1020 | - && this.optionTypes.equals(that.optionTypes) | |
| 1021 | - && this.columns.equals(that.columns); | |
| 1030 | + && this.optionTypes.equals(that.optionTypes) | |
| 1031 | + && this.columns.equals(that.columns); | |
| 1022 | 1032 | } |
| 1023 | 1033 | return false; |
| 1024 | 1034 | } |
modified driver-mapping/src/main/java/com/datastax/driver/mapping/MappingManager.java +23 −24
| @@ -15,10 +15,6 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.mapping; |
| 17 | 17 | |
| 18 | -import java.util.Collections; | |
| 19 | -import java.util.HashMap; | |
| 20 | -import java.util.Map; | |
| 21 | - | |
| 22 | 18 | import com.datastax.driver.core.ProtocolVersion; |
| 23 | 19 | import com.datastax.driver.core.Session; |
| 24 | 20 | import com.datastax.driver.core.TypeCodec; |
| @@ -26,6 +22,10 @@ | ||
| 26 | 22 | import com.datastax.driver.mapping.annotations.Table; |
| 27 | 23 | import com.datastax.driver.mapping.annotations.UDT; |
| 28 | 24 | |
| 25 | +import java.util.Collections; | |
| 26 | +import java.util.HashMap; | |
| 27 | +import java.util.Map; | |
| 28 | + | |
| 29 | 29 | /** |
| 30 | 30 | * Mapping manager from which to obtain entity mappers. |
| 31 | 31 | */ |
| @@ -40,7 +40,7 @@ | ||
| 40 | 40 | |
| 41 | 41 | /** |
| 42 | 42 | * Creates a new {@code MappingManager} using the provided {@code Session}. |
| 43 | - * <p> | |
| 43 | + * <p/> | |
| 44 | 44 | * Note that this constructor forces the initialization of the session (see |
| 45 | 45 | * {@link #MappingManager(Session, ProtocolVersion)} if that is a problem for you). |
| 46 | 46 | * |
| @@ -57,15 +57,14 @@ | ||
| 57 | 57 | |
| 58 | 58 | /** |
| 59 | 59 | * Creates a new {@code MappingManager} using the provided {@code Session}. |
| 60 | - * <p> | |
| 60 | + * <p/> | |
| 61 | 61 | * This constructor is only provided for backward compatibility: before 2.1.7, {@code MappingManager} could be |
| 62 | 62 | * built from an uninitialized session; since 2.1.7, the mapper needs to know the active protocol version to |
| 63 | 63 | * adapt its internal requests, so {@link #MappingManager(Session)} will now initialize the session if needed. |
| 64 | 64 | * If you rely on the session not being initialized, use this constructor and provide the version manually. |
| 65 | 65 | * |
| 66 | - * @param session the {@code Session} to use. | |
| 66 | + * @param session the {@code Session} to use. | |
| 67 | 67 | * @param protocolVersion the protocol version that will be used with this session. |
| 68 | - * | |
| 69 | 68 | * @since 2.1.7 |
| 70 | 69 | */ |
| 71 | 70 | public MappingManager(Session session, ProtocolVersion protocolVersion) { |
| @@ -79,10 +78,10 @@ | ||
| 79 | 78 | |
| 80 | 79 | /** |
| 81 | 80 | * The underlying {@code Session} used by this manager. |
| 82 | - * <p> | |
| 81 | + * <p/> | |
| 83 | 82 | * Note that you can get obtain the {@code Cluster} object corresponding |
| 84 | 83 | * to that session using {@code getSession().getCluster()}. |
| 85 | - * <p> | |
| 84 | + * <p/> | |
| 86 | 85 | * It is inadvisable to close the returned Session while this manager and |
| 87 | 86 | * its mappers are in use. |
| 88 | 87 | * |
| @@ -95,15 +94,15 @@ | ||
| 95 | 94 | /** |
| 96 | 95 | * Creates a {@code Mapper} for the provided class (that must be annotated by a |
| 97 | 96 | * {@link Table} annotation). |
| 98 | - * <p> | |
| 97 | + * <p/> | |
| 99 | 98 | * The {@code MappingManager} only ever keeps one Mapper for each class, and so calling this |
| 100 | 99 | * method multiple times on the same class will always return the same object. |
| 101 | - * <p> | |
| 100 | + * <p/> | |
| 102 | 101 | * If the type of any field in the class is an {@link UDT}-annotated classes, a codec for that |
| 103 | 102 | * class will automatically be created and registered with the underlying {@code Cluster}. |
| 104 | 103 | * This works recursively with UDTs nested in other UDTs or in collections. |
| 105 | 104 | * |
| 106 | - * @param <T> the type of the class to map. | |
| 105 | + * @param <T> the type of the class to map. | |
| 107 | 106 | * @param klass the (annotated) class for which to return the mapper. |
| 108 | 107 | * @return the {@code Mapper} object for class {@code klass}. |
| 109 | 108 | */ |
| @@ -114,15 +113,15 @@ | ||
| 114 | 113 | /** |
| 115 | 114 | * Creates a {@code TypeCodec} for the provided class (that must be annotated by |
| 116 | 115 | * a {@link UDT} annotation). |
| 117 | - * <p> | |
| 116 | + * <p/> | |
| 118 | 117 | * This method also registers the codec against the underlying {@code Cluster}. |
| 119 | 118 | * In addition, the codecs for any nested UDTs will also be created and registered. |
| 120 | - * <p> | |
| 119 | + * <p/> | |
| 121 | 120 | * You don't need to call this method explicitly if you already call {@link #mapper(Class)} |
| 122 | 121 | * for a class that references this UDT class (creating a mapper will automatically |
| 123 | 122 | * process all UDTs that it uses). |
| 124 | 123 | * |
| 125 | - * @param <T> the type of the class to map. | |
| 124 | + * @param <T> the type of the class to map. | |
| 126 | 125 | * @param klass the (annotated) class for which to return the codec. |
| 127 | 126 | * @return the codec that maps the provided class to the corresponding user-defined type. |
| 128 | 127 | */ |
| @@ -133,11 +132,11 @@ | ||
| 133 | 132 | /** |
| 134 | 133 | * Creates an accessor object based on the provided interface (that must be annotated by |
| 135 | 134 | * a {@link Accessor} annotation). |
| 136 | - * <p> | |
| 135 | + * <p/> | |
| 137 | 136 | * The {@code MappingManager} only ever keep one Accessor for each class, and so calling this |
| 138 | 137 | * method multiple time on the same class will always return the same object. |
| 139 | 138 | * |
| 140 | - * @param <T> the type of the accessor class. | |
| 139 | + * @param <T> the type of the accessor class. | |
| 141 | 140 | * @param klass the (annotated) class for which to create an accessor object. |
| 142 | 141 | * @return the accessor object for class {@code klass}. |
| 143 | 142 | */ |
| @@ -147,10 +146,10 @@ | ||
| 147 | 146 | |
| 148 | 147 | @SuppressWarnings("unchecked") |
| 149 | 148 | private <T> Mapper<T> getMapper(Class<T> klass) { |
| 150 | - Mapper<T> mapper = (Mapper<T>)mappers.get(klass); | |
| 149 | + Mapper<T> mapper = (Mapper<T>) mappers.get(klass); | |
| 151 | 150 | if (mapper == null) { |
| 152 | 151 | synchronized (mappers) { |
| 153 | - mapper = (Mapper<T>)mappers.get(klass); | |
| 152 | + mapper = (Mapper<T>) mappers.get(klass); | |
| 154 | 153 | if (mapper == null) { |
| 155 | 154 | EntityMapper<T> entityMapper = AnnotationParser.parseEntity(klass, ReflectionMapper.factory(), this); |
| 156 | 155 | mapper = new Mapper<T>(this, klass, entityMapper); |
| @@ -165,10 +164,10 @@ | ||
| 165 | 164 | |
| 166 | 165 | @SuppressWarnings("unchecked") |
| 167 | 166 | <T> TypeCodec<T> getUDTCodec(Class<T> mappedClass) { |
| 168 | - MappedUDTCodec<T> codec = (MappedUDTCodec<T>)udtCodecs.get(mappedClass); | |
| 167 | + MappedUDTCodec<T> codec = (MappedUDTCodec<T>) udtCodecs.get(mappedClass); | |
| 169 | 168 | if (codec == null) { |
| 170 | 169 | synchronized (udtCodecs) { |
| 171 | - codec = (MappedUDTCodec<T>)udtCodecs.get(mappedClass); | |
| 170 | + codec = (MappedUDTCodec<T>) udtCodecs.get(mappedClass); | |
| 172 | 171 | if (codec == null) { |
| 173 | 172 | codec = AnnotationParser.parseUDT(mappedClass, ReflectionMapper.factory(), this); |
| 174 | 173 | session.getCluster().getConfiguration().getCodecRegistry().register(codec); |
| @@ -184,10 +183,10 @@ | ||
| 184 | 183 | |
| 185 | 184 | @SuppressWarnings("unchecked") |
| 186 | 185 | private <T> T getAccessor(Class<T> klass) { |
| 187 | - T accessor = (T)accessors.get(klass); | |
| 186 | + T accessor = (T) accessors.get(klass); | |
| 188 | 187 | if (accessor == null) { |
| 189 | 188 | synchronized (accessors) { |
| 190 | - accessor = (T)accessors.get(klass); | |
| 189 | + accessor = (T) accessors.get(klass); | |
| 191 | 190 | if (accessor == null) { |
| 192 | 191 | AccessorMapper<T> mapper = AnnotationParser.parseAccessor(klass, AccessorReflectionMapper.factory(), this); |
| 193 | 192 | mapper.prepare(this); |
modified driver-mapping/src/main/java/com/datastax/driver/mapping/MethodMapper.java +20 −21
| @@ -15,17 +15,16 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.mapping; |
| 17 | 17 | |
| 18 | -import java.lang.reflect.Method; | |
| 19 | -import java.lang.reflect.ParameterizedType; | |
| 20 | -import java.lang.reflect.Type; | |
| 21 | -import java.util.Set; | |
| 22 | - | |
| 18 | +import com.datastax.driver.core.*; | |
| 23 | 19 | import com.google.common.collect.Sets; |
| 24 | 20 | import com.google.common.reflect.TypeToken; |
| 25 | 21 | import com.google.common.util.concurrent.Futures; |
| 26 | 22 | import com.google.common.util.concurrent.ListenableFuture; |
| 27 | 23 | |
| 28 | -import com.datastax.driver.core.*; | |
| 24 | +import java.lang.reflect.Method; | |
| 25 | +import java.lang.reflect.ParameterizedType; | |
| 26 | +import java.lang.reflect.Type; | |
| 27 | +import java.util.Set; | |
| 29 | 28 | |
| 30 | 29 | // TODO: we probably should make that an abstract class and move some bit in a "ReflexionMethodMapper" |
| 31 | 30 | // subclass for consistency with the rest, but we can see to that later |
| @@ -78,8 +77,8 @@ | ||
| 78 | 77 | |
| 79 | 78 | if (ListenableFuture.class.isAssignableFrom(returnType)) { |
| 80 | 79 | this.async = true; |
| 81 | - Type k = ((ParameterizedType)method.getGenericReturnType()).getActualTypeArguments()[0]; | |
| 82 | - if (k instanceof Class && ResultSet.class.isAssignableFrom((Class<?>)k)) | |
| 80 | + Type k = ((ParameterizedType) method.getGenericReturnType()).getActualTypeArguments()[0]; | |
| 81 | + if (k instanceof Class && ResultSet.class.isAssignableFrom((Class<?>) k)) | |
| 83 | 82 | return; |
| 84 | 83 | |
| 85 | 84 | mapType(manager, returnType, k); |
| @@ -101,13 +100,13 @@ | ||
| 101 | 100 | |
| 102 | 101 | if (method.getParameterTypes().length < names.size()) |
| 103 | 102 | throw new IllegalArgumentException(String.format("Not enough arguments for method %s, " |
| 104 | - + "found %d but it should be at least the number of unique bind parameter names in the @Query (%d)", | |
| 105 | - method.getName(), method.getParameterTypes().length, names.size())); | |
| 103 | + + "found %d but it should be at least the number of unique bind parameter names in the @Query (%d)", | |
| 104 | + method.getName(), method.getParameterTypes().length, names.size())); | |
| 106 | 105 | |
| 107 | 106 | if (method.getParameterTypes().length > variables.size()) |
| 108 | 107 | throw new IllegalArgumentException(String.format("Too many arguments for method %s, " |
| 109 | - + "found %d but it should be at most the number of bind parameters in the @Query (%d)", | |
| 110 | - method.getName(), method.getParameterTypes().length, variables.size())); | |
| 108 | + + "found %d but it should be at most the number of bind parameters in the @Query (%d)", | |
| 109 | + method.getName(), method.getParameterTypes().length, variables.size())); | |
| 111 | 110 | |
| 112 | 111 | // TODO could go further, e.g. check that the types match, inspect @Param annotations to check that all names are bound... |
| 113 | 112 | } |
| @@ -116,9 +115,9 @@ | ||
| 116 | 115 | private void mapType(MappingManager manager, Class<?> fullReturnType, Type type) { |
| 117 | 116 | |
| 118 | 117 | if (type instanceof ParameterizedType) { |
| 119 | - ParameterizedType pt = (ParameterizedType)type; | |
| 118 | + ParameterizedType pt = (ParameterizedType) type; | |
| 120 | 119 | Type raw = pt.getRawType(); |
| 121 | - if (raw instanceof Class && Result.class.isAssignableFrom((Class)raw)) { | |
| 120 | + if (raw instanceof Class && Result.class.isAssignableFrom((Class) raw)) { | |
| 122 | 121 | type = pt.getActualTypeArguments()[0]; |
| 123 | 122 | } else { |
| 124 | 123 | mapOne = true; |
| @@ -131,7 +130,7 @@ | ||
| 131 | 130 | throw new RuntimeException(String.format("Cannot map return of method %s to unsupported type %s", method, type)); |
| 132 | 131 | |
| 133 | 132 | try { |
| 134 | - this.returnMapper = (Mapper<?>)manager.mapper((Class<?>)type); | |
| 133 | + this.returnMapper = (Mapper<?>) manager.mapper((Class<?>) type); | |
| 135 | 134 | } catch (Exception e) { |
| 136 | 135 | throw new RuntimeException("Cannot map return to class " + fullReturnType, e); |
| 137 | 136 | } |
| @@ -162,8 +161,8 @@ | ||
| 162 | 161 | return future; |
| 163 | 162 | |
| 164 | 163 | return mapOne |
| 165 | - ? Futures.transform(future, returnMapper.mapOneFunctionWithoutAliases) | |
| 166 | - : Futures.transform(future, returnMapper.mapAllFunctionWithoutAliases); | |
| 164 | + ? Futures.transform(future, returnMapper.mapOneFunctionWithoutAliases) | |
| 165 | + : Futures.transform(future, returnMapper.mapAllFunctionWithoutAliases); | |
| 167 | 166 | } else { |
| 168 | 167 | ResultSet rs = session.execute(bs); |
| 169 | 168 | if (returnMapper == null) |
| @@ -185,13 +184,13 @@ | ||
| 185 | 184 | public ParamMapper(String paramName, int paramIdx, TypeToken<?> paramType, Class<? extends TypeCodec<?>> codecClass) { |
| 186 | 185 | this.paramName = paramName; |
| 187 | 186 | this.paramIdx = paramIdx; |
| 188 | - this.paramType = (TypeToken<Object>)paramType; | |
| 187 | + this.paramType = (TypeToken<Object>) paramType; | |
| 189 | 188 | try { |
| 190 | - this.codec = (codecClass == null) ? null : (TypeCodec<Object>)codecClass.newInstance(); | |
| 189 | + this.codec = (codecClass == null) ? null : (TypeCodec<Object>) codecClass.newInstance(); | |
| 191 | 190 | } catch (Exception e) { |
| 192 | 191 | throw new IllegalArgumentException(String.format( |
| 193 | - "Cannot create instance of codec %s for parameter %s", | |
| 194 | - codecClass, (paramName == null) ? paramIdx : paramName | |
| 192 | + "Cannot create instance of codec %s for parameter %s", | |
| 193 | + codecClass, (paramName == null) ? paramIdx : paramName | |
| 195 | 194 | ), e); |
| 196 | 195 | } |
| 197 | 196 | } |
modified driver-mapping/src/main/java/com/datastax/driver/mapping/QueryType.java +21 −22
| @@ -15,17 +15,16 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.mapping; |
| 17 | 17 | |
| 18 | -import java.util.ArrayList; | |
| 19 | -import java.util.Collection; | |
| 20 | -import java.util.List; | |
| 21 | -import java.util.Set; | |
| 22 | - | |
| 23 | -import com.google.common.base.Objects; | |
| 24 | - | |
| 25 | 18 | import com.datastax.driver.core.TableMetadata; |
| 26 | 19 | import com.datastax.driver.core.querybuilder.Delete; |
| 27 | 20 | import com.datastax.driver.core.querybuilder.Insert; |
| 28 | 21 | import com.datastax.driver.core.querybuilder.Select; |
| 22 | +import com.google.common.base.Objects; | |
| 23 | + | |
| 24 | +import java.util.ArrayList; | |
| 25 | +import java.util.Collection; | |
| 26 | +import java.util.List; | |
| 27 | +import java.util.Set; | |
| 29 | 28 | |
| 30 | 29 | import static com.datastax.driver.core.querybuilder.QueryBuilder.*; |
| 31 | 30 | |
| @@ -61,12 +60,12 @@ | ||
| 61 | 60 | switch (kind) { |
| 62 | 61 | case SAVE: { |
| 63 | 62 | Insert insert = table == null |
| 64 | - ? insertInto(mapper.getKeyspace(), mapper.getTable()) | |
| 65 | - : insertInto(table); | |
| 63 | + ? insertInto(mapper.getKeyspace(), mapper.getTable()) | |
| 64 | + : insertInto(table); | |
| 66 | 65 | for (ColumnMapper<?> cm : columns) |
| 67 | 66 | if (cm.kind != ColumnMapper.Kind.COMPUTED) |
| 68 | 67 | insert.value(cm.getColumnName(), bindMarker()); |
| 69 | - | |
| 68 | + | |
| 70 | 69 | Insert.Options usings = insert.using(); |
| 71 | 70 | for (Mapper.Option opt : options) { |
| 72 | 71 | opt.checkValidFor(QueryType.SAVE, manager); |
| @@ -79,8 +78,8 @@ | ||
| 79 | 78 | Select.Selection selection = select(); |
| 80 | 79 | for (ColumnMapper cm : mapper.allColumns()) { |
| 81 | 80 | Select.SelectionOrAlias column = (cm.kind == ColumnMapper.Kind.COMPUTED) |
| 82 | - ? ((Select.SelectionOrAlias)selection).raw(cm.getColumnName()) | |
| 83 | - : selection.column(cm.getColumnName()); | |
| 81 | + ? ((Select.SelectionOrAlias) selection).raw(cm.getColumnName()) | |
| 82 | + : selection.column(cm.getColumnName()); | |
| 84 | 83 | |
| 85 | 84 | if (cm.getAlias() == null) { |
| 86 | 85 | selection = column; |
| @@ -97,15 +96,15 @@ | ||
| 97 | 96 | Select.Where where = select.where(); |
| 98 | 97 | for (int i = 0; i < mapper.primaryKeySize(); i++) |
| 99 | 98 | where.and(eq(mapper.getPrimaryKeyColumn(i).getColumnName(), bindMarker())); |
| 100 | - | |
| 99 | + | |
| 101 | 100 | for (Mapper.Option opt : options) |
| 102 | 101 | opt.checkValidFor(QueryType.GET, manager); |
| 103 | 102 | return select.toString(); |
| 104 | 103 | } |
| 105 | 104 | case DEL: { |
| 106 | 105 | Delete delete = table == null |
| 107 | - ? delete().all().from(mapper.getKeyspace(), mapper.getTable()) | |
| 108 | - : delete().all().from(table); | |
| 106 | + ? delete().all().from(mapper.getKeyspace(), mapper.getTable()) | |
| 107 | + : delete().all().from(table); | |
| 109 | 108 | Delete.Where where = delete.where(); |
| 110 | 109 | for (int i = 0; i < mapper.primaryKeySize(); i++) |
| 111 | 110 | where.and(eq(mapper.getPrimaryKeyColumn(i).getColumnName(), bindMarker())); |
| @@ -120,8 +119,8 @@ | ||
| 120 | 119 | case SLICE: |
| 121 | 120 | case REVERSED_SLICE: { |
| 122 | 121 | Select select = table == null |
| 123 | - ? select().all().from(mapper.getKeyspace(), mapper.getTable()) | |
| 124 | - : select().all().from(table); | |
| 122 | + ? select().all().from(mapper.getKeyspace(), mapper.getTable()) | |
| 123 | + : select().all().from(table); | |
| 125 | 124 | Select.Where where = select.where(); |
| 126 | 125 | for (int i = 0; i < mapper.partitionKeys.size(); i++) |
| 127 | 126 | where.and(eq(mapper.partitionKeys.get(i).getColumnName(), bindMarker())); |
| @@ -174,12 +173,12 @@ | ||
| 174 | 173 | if (obj == null || this.getClass() != obj.getClass()) |
| 175 | 174 | return false; |
| 176 | 175 | |
| 177 | - QueryType that = (QueryType)obj; | |
| 176 | + QueryType that = (QueryType) obj; | |
| 178 | 177 | return kind == that.kind |
| 179 | - && startBoundSize == that.startBoundSize | |
| 180 | - && startInclusive == that.startInclusive | |
| 181 | - && endBoundSize == that.endBoundSize | |
| 182 | - && endInclusive == that.endInclusive; | |
| 178 | + && startBoundSize == that.startBoundSize | |
| 179 | + && startInclusive == that.startInclusive | |
| 180 | + && endBoundSize == that.endBoundSize | |
| 181 | + && endInclusive == that.endInclusive; | |
| 183 | 182 | } |
| 184 | 183 | |
| 185 | 184 | @Override |
modified driver-mapping/src/main/java/com/datastax/driver/mapping/ReflectionMapper.java +3 −3
| @@ -15,14 +15,14 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.mapping; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.ConsistencyLevel; | |
| 19 | + | |
| 18 | 20 | import java.beans.IntrospectionException; |
| 19 | 21 | import java.beans.PropertyDescriptor; |
| 20 | 22 | import java.lang.reflect.Field; |
| 21 | 23 | import java.lang.reflect.Method; |
| 22 | 24 | import java.util.concurrent.atomic.AtomicInteger; |
| 23 | 25 | |
| 24 | -import com.datastax.driver.core.ConsistencyLevel; | |
| 25 | - | |
| 26 | 26 | /** |
| 27 | 27 | * An {@link EntityMapper} implementation that use reflection to read and write fields |
| 28 | 28 | * of an entity. |
| @@ -88,7 +88,7 @@ | ||
| 88 | 88 | return new ReflectionMapper<T>(entityClass, keyspace, table, writeConsistency, readConsistency); |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | - @SuppressWarnings({ "unchecked", "rawtypes" }) | |
| 91 | + @SuppressWarnings({"unchecked", "rawtypes"}) | |
| 92 | 92 | public <T> ColumnMapper<T> createColumnMapper(Class<T> entityClass, Field field, int position, MappingManager mappingManager, AtomicInteger columnCounter) { |
| 93 | 93 | String fieldName = field.getName(); |
| 94 | 94 | try { |
modified driver-mapping/src/main/java/com/datastax/driver/mapping/ReflectionUtils.java +3 −3
| @@ -26,8 +26,8 @@ | ||
| 26 | 26 | /** |
| 27 | 27 | * Gets a type argument from a parameterized type. |
| 28 | 28 | * |
| 29 | - * @param pt the parameterized type. | |
| 30 | - * @param arg the index of the argument to retrieve. | |
| 29 | + * @param pt the parameterized type. | |
| 30 | + * @param arg the index of the argument to retrieve. | |
| 31 | 31 | * @param name the name of the element (field or method argument). |
| 32 | 32 | * @return the type argument. |
| 33 | 33 | */ |
| @@ -35,6 +35,6 @@ | ||
| 35 | 35 | Type ft = pt.getActualTypeArguments()[arg]; |
| 36 | 36 | if (!(ft instanceof Class)) |
| 37 | 37 | throw new IllegalArgumentException(String.format("Cannot map parameter of class %s for %s", pt, name)); |
| 38 | - return (Class<?>)ft; | |
| 38 | + return (Class<?>) ft; | |
| 39 | 39 | } |
| 40 | 40 | } |
modified driver-mapping/src/main/java/com/datastax/driver/mapping/Result.java +9 −9
| @@ -15,10 +15,10 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.mapping; |
| 17 | 17 | |
| 18 | -import java.util.*; | |
| 19 | - | |
| 20 | 18 | import com.datastax.driver.core.*; |
| 21 | 19 | |
| 20 | +import java.util.*; | |
| 21 | + | |
| 22 | 22 | /** |
| 23 | 23 | * A {@code ResultSet} mapped to an entity class. |
| 24 | 24 | */ |
| @@ -64,10 +64,10 @@ | ||
| 64 | 64 | private static boolean shouldSetValue(Object value) { |
| 65 | 65 | if (value == null) |
| 66 | 66 | return false; |
| 67 | - if(value instanceof Collection) | |
| 68 | - return !((Collection)value).isEmpty(); | |
| 69 | - if(value instanceof Map) | |
| 70 | - return !((Map)value).isEmpty(); | |
| 67 | + if (value instanceof Collection) | |
| 68 | + return !((Collection) value).isEmpty(); | |
| 69 | + if (value instanceof Map) | |
| 70 | + return !((Map) value).isEmpty(); | |
| 71 | 71 | return true; |
| 72 | 72 | } |
| 73 | 73 | |
| @@ -109,11 +109,11 @@ | ||
| 109 | 109 | |
| 110 | 110 | /** |
| 111 | 111 | * An iterator over the entities of this mapped result set. |
| 112 | - * | |
| 112 | + * <p/> | |
| 113 | 113 | * The {@link Iterator#next} method is equivalent to calling {@link #one}. |
| 114 | 114 | * So this iterator will consume results and after a full iteration, the |
| 115 | 115 | * mapped result set (and underlying {@code ResultSet}) will be empty. |
| 116 | - * | |
| 116 | + * <p/> | |
| 117 | 117 | * The returned iterator does not support the {@link Iterator#remove} method. |
| 118 | 118 | * |
| 119 | 119 | * @return an iterator that will consume and return the remaining rows of |
| @@ -139,7 +139,7 @@ | ||
| 139 | 139 | |
| 140 | 140 | /** |
| 141 | 141 | * Returns information on the execution of this query. |
| 142 | - * <p> | |
| 142 | + * <p/> | |
| 143 | 143 | * The returned object includes basic information such as the queried hosts, |
| 144 | 144 | * but also the Cassandra query trace if tracing was enabled for the query. |
| 145 | 145 | * |
modified driver-mapping/src/main/java/com/datastax/driver/mapping/TypeMappings.java +8 −9
| @@ -15,6 +15,9 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.mapping; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.mapping.annotations.UDT; | |
| 19 | +import com.google.common.collect.Sets; | |
| 20 | + | |
| 18 | 21 | import java.lang.reflect.ParameterizedType; |
| 19 | 22 | import java.lang.reflect.Type; |
| 20 | 23 | import java.util.Collections; |
| @@ -22,10 +25,6 @@ | ||
| 22 | 25 | import java.util.Map; |
| 23 | 26 | import java.util.Set; |
| 24 | 27 | |
| 25 | -import com.google.common.collect.Sets; | |
| 26 | - | |
| 27 | -import com.datastax.driver.mapping.annotations.UDT; | |
| 28 | - | |
| 29 | 28 | /** |
| 30 | 29 | * Utility methods to determine which CQL type we expect for a given Java field type. |
| 31 | 30 | */ |
| @@ -58,16 +57,16 @@ | ||
| 58 | 57 | static Set<Class<?>> findUDTs(Type type) { |
| 59 | 58 | Set<Class<?>> udts = findUDTs(type, null); |
| 60 | 59 | return (udts == null) |
| 61 | - ? Collections.<Class<?>>emptySet() | |
| 62 | - : udts; | |
| 60 | + ? Collections.<Class<?>>emptySet() | |
| 61 | + : udts; | |
| 63 | 62 | } |
| 64 | 63 | |
| 65 | 64 | private static Set<Class<?>> findUDTs(Type type, Set<Class<?>> udts) { |
| 66 | 65 | if (type instanceof ParameterizedType) { |
| 67 | - ParameterizedType pt = (ParameterizedType)type; | |
| 66 | + ParameterizedType pt = (ParameterizedType) type; | |
| 68 | 67 | Type raw = pt.getRawType(); |
| 69 | 68 | if ((raw instanceof Class)) { |
| 70 | - Class<?> klass = (Class<?>)raw; | |
| 69 | + Class<?> klass = (Class<?>) raw; | |
| 71 | 70 | if (mapsToCollection(klass)) { |
| 72 | 71 | Type[] childTypes = pt.getActualTypeArguments(); |
| 73 | 72 | udts = findUDTs(childTypes[0], udts); |
| @@ -77,7 +76,7 @@ | ||
| 77 | 76 | } |
| 78 | 77 | } |
| 79 | 78 | } else if (type instanceof Class) { |
| 80 | - Class<?> klass = (Class<?>)type; | |
| 79 | + Class<?> klass = (Class<?>) type; | |
| 81 | 80 | if (isMappedUDT(klass)) { |
| 82 | 81 | if (udts == null) |
| 83 | 82 | udts = Sets.newHashSet(); |
modified driver-mapping/src/main/java/com/datastax/driver/mapping/annotations/Accessor.java +3 −2
| @@ -23,10 +23,11 @@ | ||
| 23 | 23 | /** |
| 24 | 24 | * An accessor is an interface that defines a set of method to read and write |
| 25 | 25 | * from Cassandra. |
| 26 | - * <p> | |
| 26 | + * <p/> | |
| 27 | 27 | * Each method declaration of an interface with the annotation {@link Accessor} must |
| 28 | 28 | * have a {@link Query} annotation that defines the query the method executes. |
| 29 | 29 | */ |
| 30 | 30 | @Target(ElementType.TYPE) |
| 31 | 31 | @Retention(RetentionPolicy.RUNTIME) |
| 32 | -public @interface Accessor {} | |
| 32 | +public @interface Accessor { | |
| 33 | +} |
modified driver-mapping/src/main/java/com/datastax/driver/mapping/annotations/ClusteringColumn.java +1 −1
| @@ -22,7 +22,7 @@ | ||
| 22 | 22 | |
| 23 | 23 | /** |
| 24 | 24 | * Annotation for fields that map to a CQL clustering column. |
| 25 | - * <p> | |
| 25 | + * <p/> | |
| 26 | 26 | * If the mapped table has multiple clustering columns, it is mandatory |
| 27 | 27 | * to specify the ordinal parameter to avoid ordering ambiguity. |
| 28 | 28 | */ |
modified driver-mapping/src/main/java/com/datastax/driver/mapping/annotations/Column.java +3 −3
| @@ -15,17 +15,17 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.mapping.annotations; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.TypeCodec; | |
| 19 | + | |
| 18 | 20 | import java.lang.annotation.ElementType; |
| 19 | 21 | import java.lang.annotation.Retention; |
| 20 | 22 | import java.lang.annotation.RetentionPolicy; |
| 21 | 23 | import java.lang.annotation.Target; |
| 22 | 24 | |
| 23 | -import com.datastax.driver.core.TypeCodec; | |
| 24 | - | |
| 25 | 25 | /** |
| 26 | 26 | * Annotation that allows to specify the name of the CQL column to which the |
| 27 | 27 | * field should be mapped. |
| 28 | - * <p> | |
| 28 | + * <p/> | |
| 29 | 29 | * Note that this annotation is generally optional in the sense that any field |
| 30 | 30 | * of a class annotated by {@link Table} will be mapped by default to a column |
| 31 | 31 | * having the same name than this field unless that field has the |
modified driver-mapping/src/main/java/com/datastax/driver/mapping/annotations/Computed.java +5 −4
| @@ -16,8 +16,9 @@ | ||
| 16 | 16 | package com.datastax.driver.mapping.annotations; |
| 17 | 17 | |
| 18 | 18 | |
| 19 | -import java.lang.annotation.ElementType; | |
| 20 | 19 | import com.datastax.driver.mapping.Mapper; |
| 20 | + | |
| 21 | +import java.lang.annotation.ElementType; | |
| 21 | 22 | import java.lang.annotation.Retention; |
| 22 | 23 | import java.lang.annotation.RetentionPolicy; |
| 23 | 24 | import java.lang.annotation.Target; |
| @@ -25,10 +26,10 @@ | ||
| 25 | 26 | /** |
| 26 | 27 | * Annotates a "computed" field, which gets filled from a CQL expression in the SELECT query |
| 27 | 28 | * used to retrieve an entity. |
| 28 | - * <p> | |
| 29 | + * <p/> | |
| 29 | 30 | * Note that such fields are only filled by default mapper operations ({@link Mapper#get(Object...)}), |
| 30 | 31 | * they will be ignored in accessor queries and save operations. |
| 31 | - * <p> | |
| 32 | + * <p/> | |
| 32 | 33 | * As opposed to other mapper annotation, this one doesn't handle case sensitivity. If your expression |
| 33 | 34 | * contains case-sensitive names, you'll need to quote them explicitly: |
| 34 | 35 | * <pre> |
| @@ -40,7 +41,7 @@ | ||
| 40 | 41 | public @interface Computed { |
| 41 | 42 | /** |
| 42 | 43 | * The formula used to compute the field. |
| 43 | - * <p> | |
| 44 | + * <p/> | |
| 44 | 45 | * This is a CQL expression like you would use directly in a query, for instance |
| 45 | 46 | * "writetime(v)". |
| 46 | 47 | * |
modified driver-mapping/src/main/java/com/datastax/driver/mapping/annotations/Field.java +3 −3
| @@ -15,17 +15,17 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.mapping.annotations; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.TypeCodec; | |
| 19 | + | |
| 18 | 20 | import java.lang.annotation.ElementType; |
| 19 | 21 | import java.lang.annotation.Retention; |
| 20 | 22 | import java.lang.annotation.RetentionPolicy; |
| 21 | 23 | import java.lang.annotation.Target; |
| 22 | 24 | |
| 23 | -import com.datastax.driver.core.TypeCodec; | |
| 24 | - | |
| 25 | 25 | /** |
| 26 | 26 | * Annotation that allows to specify the name of the CQL UDT field to which the |
| 27 | 27 | * Java field should be mapped. |
| 28 | - * <p> | |
| 28 | + * <p/> | |
| 29 | 29 | * Note that this annotation is generally optional in the sense that any field |
| 30 | 30 | * of a class annotated by {@link UDT} will be mapped by default to a UDT field |
| 31 | 31 | * having the same name than this Java field unless that Java field has the |
modified driver-mapping/src/main/java/com/datastax/driver/mapping/annotations/Frozen.java +5 −5
| @@ -15,17 +15,17 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.mapping.annotations; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.DataType; | |
| 19 | + | |
| 18 | 20 | import java.lang.annotation.ElementType; |
| 19 | 21 | import java.lang.annotation.Retention; |
| 20 | 22 | import java.lang.annotation.RetentionPolicy; |
| 21 | 23 | import java.lang.annotation.Target; |
| 22 | 24 | |
| 23 | -import com.datastax.driver.core.DataType; | |
| 24 | - | |
| 25 | 25 | /** |
| 26 | 26 | * Specifies that the field decorated with this annotation maps to a CQL type that is {@link DataType#isFrozen() frozen}, |
| 27 | 27 | * or contains frozen subtypes. |
| 28 | - * <p> | |
| 28 | + * <p/> | |
| 29 | 29 | * This annotation is purely informational at this stage, the validity of the declaration is not checked. |
| 30 | 30 | * But will become useful when a schema generation feature is added to the mapper. Therefore it is a good idea to keep |
| 31 | 31 | * frozen declarations up-to-date. |
| @@ -42,7 +42,7 @@ | ||
| 42 | 42 | /** |
| 43 | 43 | * Contains the full CQL type of the target column. As a convenience, this can be left out when only the top-level |
| 44 | 44 | * type is frozen. |
| 45 | - * <p> | |
| 45 | + * <p/> | |
| 46 | 46 | * Examples: |
| 47 | 47 | * <pre> |
| 48 | 48 | * // Will map to frozen<user> |
| @@ -52,7 +52,7 @@ | ||
| 52 | 52 | * @Frozen("map<text, map<text, frozen<user>>>") |
| 53 | 53 | * private Map<String, Map<String, User>> m; |
| 54 | 54 | * </pre> |
| 55 | - * <p> | |
| 55 | + * <p/> | |
| 56 | 56 | * Also consider the {@link FrozenKey @FrozenKey} and {@link FrozenValue @FrozenValue} shortcuts for simple collections. |
| 57 | 57 | * |
| 58 | 58 | * @return the full CQL type of the target column. |
modified driver-mapping/src/main/java/com/datastax/driver/mapping/annotations/FrozenKey.java +5 −2
| @@ -15,11 +15,14 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.mapping.annotations; |
| 17 | 17 | |
| 18 | -import java.lang.annotation.*; | |
| 18 | +import java.lang.annotation.ElementType; | |
| 19 | +import java.lang.annotation.Retention; | |
| 20 | +import java.lang.annotation.RetentionPolicy; | |
| 21 | +import java.lang.annotation.Target; | |
| 19 | 22 | |
| 20 | 23 | /** |
| 21 | 24 | * Shorthand to specify that the key type of a MAP field is frozen. |
| 22 | - * <p> | |
| 25 | + * <p/> | |
| 23 | 26 | * This is equivalent to {@code @Frozen("map<frozen<foo>, bar>")}. |
| 24 | 27 | * |
| 25 | 28 | * @see Frozen |
modified driver-mapping/src/main/java/com/datastax/driver/mapping/annotations/FrozenValue.java +5 −2
| @@ -15,11 +15,14 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.mapping.annotations; |
| 17 | 17 | |
| 18 | -import java.lang.annotation.*; | |
| 18 | +import java.lang.annotation.ElementType; | |
| 19 | +import java.lang.annotation.Retention; | |
| 20 | +import java.lang.annotation.RetentionPolicy; | |
| 21 | +import java.lang.annotation.Target; | |
| 19 | 22 | |
| 20 | 23 | /** |
| 21 | 24 | * Shorthand to specify that the value type of a collection field is frozen. |
| 22 | - * <p> | |
| 25 | + * <p/> | |
| 23 | 26 | * This is equivalent to any of the following: |
| 24 | 27 | * <ul> |
| 25 | 28 | * <li>{@code @Frozen("list<frozen<foo>>")}</li> |
modified driver-mapping/src/main/java/com/datastax/driver/mapping/annotations/Param.java +2 −2
| @@ -15,13 +15,13 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.mapping.annotations; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.TypeCodec; | |
| 19 | + | |
| 18 | 20 | import java.lang.annotation.ElementType; |
| 19 | 21 | import java.lang.annotation.Retention; |
| 20 | 22 | import java.lang.annotation.RetentionPolicy; |
| 21 | 23 | import java.lang.annotation.Target; |
| 22 | 24 | |
| 23 | -import com.datastax.driver.core.TypeCodec; | |
| 24 | - | |
| 25 | 25 | /** |
| 26 | 26 | * Provides a name for a parameter of a method in an {@link Accessor} interface that |
| 27 | 27 | * can be used to reference to that parameter in method {@link Query}. |
modified driver-mapping/src/main/java/com/datastax/driver/mapping/annotations/PartitionKey.java +1 −1
| @@ -23,7 +23,7 @@ | ||
| 23 | 23 | /** |
| 24 | 24 | * Annotation for fields that map to a CQL partition key (or one of it's |
| 25 | 25 | * component if the partition key is composite). |
| 26 | - * <p> | |
| 26 | + * <p/> | |
| 27 | 27 | * If the partition key of the mapped table is composite, it is mandatory |
| 28 | 28 | * to specify the ordinal parameter to avoid ordering ambiguity. |
| 29 | 29 | */ |
modified driver-mapping/src/main/java/com/datastax/driver/mapping/annotations/Query.java +1 −1
| @@ -28,7 +28,7 @@ | ||
| 28 | 28 | public @interface Query { |
| 29 | 29 | /** |
| 30 | 30 | * The CQL query to use. |
| 31 | - * <p> | |
| 31 | + * <p/> | |
| 32 | 32 | * In that query string, the parameter of the annotated method can be referenced using |
| 33 | 33 | * name bind markers. For instance, the first parameter can be refered by {@code :arg0}, |
| 34 | 34 | * the second one by {@code :arg1}, ... Alternatively, if a parameter of the annonated |
modified driver-mapping/src/main/java/com/datastax/driver/mapping/annotations/QueryParameters.java +3 −3
| @@ -15,17 +15,17 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.mapping.annotations; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.Configuration; | |
| 19 | + | |
| 18 | 20 | import java.lang.annotation.ElementType; |
| 19 | 21 | import java.lang.annotation.Retention; |
| 20 | 22 | import java.lang.annotation.RetentionPolicy; |
| 21 | 23 | import java.lang.annotation.Target; |
| 22 | 24 | |
| 23 | -import com.datastax.driver.core.Configuration; | |
| 24 | - | |
| 25 | 25 | /** |
| 26 | 26 | * Query parameters to use in the (generated) implementation of a method of an {@link Accessor} |
| 27 | 27 | * interface. |
| 28 | - * <p> | |
| 28 | + * <p/> | |
| 29 | 29 | * All the parameters of this annotation are optional, and when not provided default to whatever |
| 30 | 30 | * default the {@code Cluster} instance used underneath are (those set in |
| 31 | 31 | * {@link Configuration#getQueryOptions}). |
modified driver-mapping/src/main/java/com/datastax/driver/mapping/annotations/Table.java +4 −2
| @@ -15,13 +15,13 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.mapping.annotations; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.mapping.Mapper; | |
| 19 | + | |
| 18 | 20 | import java.lang.annotation.ElementType; |
| 19 | 21 | import java.lang.annotation.Retention; |
| 20 | 22 | import java.lang.annotation.RetentionPolicy; |
| 21 | 23 | import java.lang.annotation.Target; |
| 22 | 24 | |
| 23 | -import com.datastax.driver.mapping.Mapper; | |
| 24 | - | |
| 25 | 25 | /** |
| 26 | 26 | * Defines to which table a class must be mapped to. |
| 27 | 27 | */ |
| @@ -34,6 +34,7 @@ | ||
| 34 | 34 | * @return the name of the keyspace. |
| 35 | 35 | */ |
| 36 | 36 | String keyspace() default ""; |
| 37 | + | |
| 37 | 38 | /** |
| 38 | 39 | * The name of the table. |
| 39 | 40 | * |
| @@ -47,6 +48,7 @@ | ||
| 47 | 48 | * @return whether the keyspace name is a case sensitive one. |
| 48 | 49 | */ |
| 49 | 50 | boolean caseSensitiveKeyspace() default false; |
| 51 | + | |
| 50 | 52 | /** |
| 51 | 53 | * Whether the table name is a case sensitive one. |
| 52 | 54 | * |
modified driver-mapping/src/main/java/com/datastax/driver/mapping/annotations/Transient.java +1 −1
| @@ -23,7 +23,7 @@ | ||
| 23 | 23 | /** |
| 24 | 24 | * Whenever this annotation is added on a field, the field will not be mapped |
| 25 | 25 | * to any column (neither during reads nor writes). |
| 26 | - * <p> | |
| 26 | + * <p/> | |
| 27 | 27 | * Please note that it is thus illegal to have a field that has both the |
| 28 | 28 | * {@code Transcient} annotation and one of the {@link Column}, {@link PartitionKey} |
| 29 | 29 | * or {@link ClusteringColumn} annotation. |
modified driver-mapping/src/main/java/com/datastax/driver/mapping/annotations/UDT.java +2 −0
| @@ -32,6 +32,7 @@ | ||
| 32 | 32 | * @return the name of the keyspace. |
| 33 | 33 | */ |
| 34 | 34 | String keyspace() default ""; |
| 35 | + | |
| 35 | 36 | /** |
| 36 | 37 | * The name of the type. |
| 37 | 38 | * |
| @@ -45,6 +46,7 @@ | ||
| 45 | 46 | * @return whether the keyspace name is a case sensitive one. |
| 46 | 47 | */ |
| 47 | 48 | boolean caseSensitiveKeyspace() default false; |
| 49 | + | |
| 48 | 50 | /** |
| 49 | 51 | * Whether the type name is a case sensitive one. |
| 50 | 52 | * |
modified driver-mapping/src/test/java/com/datastax/driver/mapping/MapperAccessorParamsTest.java +31 −20
| @@ -15,26 +15,25 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.mapping; |
| 17 | 17 | |
| 18 | -import java.util.Collection; | |
| 19 | - | |
| 20 | -import com.google.common.collect.Lists; | |
| 21 | -import org.testng.annotations.Test; | |
| 22 | - | |
| 23 | -import static org.assertj.core.api.Assertions.assertThat; | |
| 24 | - | |
| 25 | 18 | import com.datastax.driver.core.CCMBridge; |
| 26 | 19 | import com.datastax.driver.core.Row; |
| 27 | 20 | import com.datastax.driver.core.utils.CassandraVersion; |
| 28 | 21 | import com.datastax.driver.mapping.annotations.*; |
| 22 | +import com.google.common.collect.Lists; | |
| 23 | +import org.testng.annotations.Test; | |
| 24 | + | |
| 25 | +import java.util.Collection; | |
| 26 | + | |
| 27 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 29 | 28 | |
| 30 | 29 | public class MapperAccessorParamsTest extends CCMBridge.PerClassSingleNodeCluster { |
| 31 | 30 | @Override |
| 32 | 31 | protected Collection<String> getTableDefinitions() { |
| 33 | 32 | return Lists.newArrayList( |
| 34 | - "CREATE TABLE user ( key int primary key, gender int, home_phone text, work_phone text)", | |
| 35 | - "CREATE INDEX on user(gender)", | |
| 36 | - "CREATE TABLE user_str ( key int primary key, gender text)", | |
| 37 | - "CREATE INDEX on user_str(gender)" | |
| 33 | + "CREATE TABLE user ( key int primary key, gender int, home_phone text, work_phone text)", | |
| 34 | + "CREATE INDEX on user(gender)", | |
| 35 | + "CREATE TABLE user_str ( key int primary key, gender text)", | |
| 36 | + "CREATE INDEX on user_str(gender)" | |
| 38 | 37 | ); |
| 39 | 38 | } |
| 40 | 39 | |
| @@ -42,7 +41,7 @@ | ||
| 42 | 41 | @CassandraVersion(major = 2.0, description = "Uses named parameters") |
| 43 | 42 | public void should_allow_less_parameters_than_bind_markers_if_there_are_repeated_names() { |
| 44 | 43 | UserPhoneAccessor accessor = new MappingManager(session) |
| 45 | - .createAccessor(UserPhoneAccessor.class); | |
| 44 | + .createAccessor(UserPhoneAccessor.class); | |
| 46 | 45 | |
| 47 | 46 | session.execute("delete from user where key = 0"); |
| 48 | 47 | accessor.updatePhones_positional("1111", "2222", 0); |
| @@ -68,13 +67,13 @@ | ||
| 68 | 67 | @Test(groups = "short", expectedExceptions = RuntimeException.class) |
| 69 | 68 | public void should_fail_if_not_enough_parameters() { |
| 70 | 69 | new MappingManager(session) |
| 71 | - .createAccessor(UserPhoneAccessor_NotEnoughParams.class); | |
| 70 | + .createAccessor(UserPhoneAccessor_NotEnoughParams.class); | |
| 72 | 71 | } |
| 73 | 72 | |
| 74 | 73 | @Test(groups = "short", expectedExceptions = RuntimeException.class) |
| 75 | 74 | public void should_fail_if_too_many_parameters() { |
| 76 | 75 | new MappingManager(session) |
| 77 | - .createAccessor(UserPhoneAccessor_TooManyParams.class); | |
| 76 | + .createAccessor(UserPhoneAccessor_TooManyParams.class); | |
| 78 | 77 | } |
| 79 | 78 | |
| 80 | 79 | private void assertPhonesEqual(int key, String home, String work) { |
| @@ -87,26 +86,38 @@ | ||
| 87 | 86 | MALE, FEMALE |
| 88 | 87 | } |
| 89 | 88 | |
| 90 | - /** Tests various ways to match method parameters to query bind markers. */ | |
| 89 | + /** | |
| 90 | + * Tests various ways to match method parameters to query bind markers. | |
| 91 | + */ | |
| 91 | 92 | @Accessor |
| 92 | 93 | public interface UserPhoneAccessor { |
| 93 | - /** Standard positional markers */ | |
| 94 | + /** | |
| 95 | + * Standard positional markers | |
| 96 | + */ | |
| 94 | 97 | @Query("update user set home_phone = ?, work_phone = ? where key = ?") |
| 95 | 98 | void updatePhones_positional(String homePhone, String workPhone, int key); |
| 96 | 99 | |
| 97 | - /** Standard named markers */ | |
| 100 | + /** | |
| 101 | + * Standard named markers | |
| 102 | + */ | |
| 98 | 103 | @Query("update user set home_phone = :home, work_phone = :work where key = :key") |
| 99 | 104 | void updatePhones_named(@Param("key") int key, @Param("home") String homePhone, @Param("work") String workPhone); |
| 100 | 105 | |
| 101 | - /** Named markers with no @Param. Should fallback to positional matching */ | |
| 106 | + /** | |
| 107 | + * Named markers with no @Param. Should fallback to positional matching | |
| 108 | + */ | |
| 102 | 109 | @Query("update user set home_phone = :home, work_phone = :work where key = :key") |
| 103 | 110 | void updatePhones_fallback(String homePhone, String workPhone, int key); |
| 104 | 111 | |
| 105 | - /** Named markers with repeated names */ | |
| 112 | + /** | |
| 113 | + * Named markers with repeated names | |
| 114 | + */ | |
| 106 | 115 | @Query("update user set home_phone = :phone, work_phone = :phone where key = :key") |
| 107 | 116 | void updateBothPhones(@Param("key") int key, @Param("phone") String uniquePhone); |
| 108 | 117 | |
| 109 | - /** Named markers with repeated names, but no @Param. Should fallback to positional matching */ | |
| 118 | + /** | |
| 119 | + * Named markers with repeated names, but no @Param. Should fallback to positional matching | |
| 120 | + */ | |
| 110 | 121 | @Query("update user set home_phone = :phone, work_phone = :phone where key = :key") |
| 111 | 122 | void updatePhones_fallback2(String homePhone, String workPhone, int key); |
| 112 | 123 | } |
modified driver-mapping/src/test/java/com/datastax/driver/mapping/MapperAccessorTest.java +12 −13
| @@ -15,13 +15,6 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.mapping; |
| 17 | 17 | |
| 18 | -import java.util.Collection; | |
| 19 | - | |
| 20 | -import com.google.common.collect.Lists; | |
| 21 | -import org.testng.annotations.Test; | |
| 22 | - | |
| 23 | -import static org.assertj.core.api.Assertions.assertThat; | |
| 24 | - | |
| 25 | 18 | import com.datastax.driver.core.CCMBridge; |
| 26 | 19 | import com.datastax.driver.core.ResultSet; |
| 27 | 20 | import com.datastax.driver.core.Row; |
| @@ -29,6 +22,12 @@ | ||
| 29 | 22 | import com.datastax.driver.mapping.annotations.Accessor; |
| 30 | 23 | import com.datastax.driver.mapping.annotations.Param; |
| 31 | 24 | import com.datastax.driver.mapping.annotations.Query; |
| 25 | +import com.google.common.collect.Lists; | |
| 26 | +import org.testng.annotations.Test; | |
| 27 | + | |
| 28 | +import java.util.Collection; | |
| 29 | + | |
| 30 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 32 | 31 | |
| 33 | 32 | public class MapperAccessorTest extends CCMBridge.PerClassSingleNodeCluster { |
| 34 | 33 | |
| @@ -40,26 +39,26 @@ | ||
| 40 | 39 | @Test(groups = "short") |
| 41 | 40 | public void should_implement_toString() { |
| 42 | 41 | SystemAccessor accessor = new MappingManager(session) |
| 43 | - .createAccessor(SystemAccessor.class); | |
| 42 | + .createAccessor(SystemAccessor.class); | |
| 44 | 43 | |
| 45 | 44 | assertThat(accessor.toString()) |
| 46 | - .isEqualTo("SystemAccessor implementation generated by the Cassandra driver mapper"); | |
| 45 | + .isEqualTo("SystemAccessor implementation generated by the Cassandra driver mapper"); | |
| 47 | 46 | } |
| 48 | 47 | |
| 49 | 48 | @Test(groups = "short") |
| 50 | 49 | public void should_implement_equals_and_hashCode() { |
| 51 | 50 | SystemAccessor accessor = new MappingManager(session) |
| 52 | - .createAccessor(SystemAccessor.class); | |
| 51 | + .createAccessor(SystemAccessor.class); | |
| 53 | 52 | |
| 54 | 53 | assertThat(accessor).isNotEqualTo(new Object()); |
| 55 | 54 | assertThat(accessor.hashCode()).isEqualTo(System.identityHashCode(accessor)); |
| 56 | 55 | } |
| 57 | 56 | |
| 58 | 57 | @Test(groups = "short") |
| 59 | - @CassandraVersion(major=2.0) | |
| 58 | + @CassandraVersion(major = 2.0) | |
| 60 | 59 | public void should_allow_null_argument_in_accessor_when_set_by_name() { |
| 61 | 60 | FooAccessor accessor = new MappingManager(session) |
| 62 | - .createAccessor(FooAccessor.class); | |
| 61 | + .createAccessor(FooAccessor.class); | |
| 63 | 62 | |
| 64 | 63 | accessor.insert(1, null); |
| 65 | 64 | Row row = session.execute("select * from foo where k = 1").one(); |
| @@ -70,7 +69,7 @@ | ||
| 70 | 69 | @Test(groups = "short") |
| 71 | 70 | public void should_allow_null_argument_in_accessor_when_set_by_index() { |
| 72 | 71 | FooBindMarkerAccessor accessor = new MappingManager(session) |
| 73 | - .createAccessor(FooBindMarkerAccessor.class); | |
| 72 | + .createAccessor(FooBindMarkerAccessor.class); | |
| 74 | 73 | |
| 75 | 74 | accessor.insert(1, null); |
| 76 | 75 |
modified driver-mapping/src/test/java/com/datastax/driver/mapping/MapperCompositeKeyTest.java +6 −5
| @@ -15,13 +15,14 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.mapping; |
| 17 | 17 | |
| 18 | -import java.util.Arrays; | |
| 19 | -import java.util.Collection; | |
| 20 | - | |
| 21 | -import com.datastax.driver.mapping.annotations.*; | |
| 18 | +import com.datastax.driver.core.CCMBridge; | |
| 19 | +import com.datastax.driver.mapping.annotations.ClusteringColumn; | |
| 20 | +import com.datastax.driver.mapping.annotations.PartitionKey; | |
| 21 | +import com.datastax.driver.mapping.annotations.Table; | |
| 22 | 22 | import org.testng.annotations.Test; |
| 23 | 23 | |
| 24 | -import com.datastax.driver.core.CCMBridge; | |
| 24 | +import java.util.Arrays; | |
| 25 | +import java.util.Collection; | |
| 25 | 26 | |
| 26 | 27 | /** |
| 27 | 28 | * Tests for the mapper with composite partition keys and multiple clustering columns. |
modified driver-mapping/src/test/java/com/datastax/driver/mapping/MapperComputedFieldsTest.java +13 −15
| @@ -15,23 +15,21 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.mapping; |
| 17 | 17 | |
| 18 | -import java.util.Collection; | |
| 19 | - | |
| 20 | -import com.google.common.collect.Lists; | |
| 21 | -import org.testng.SkipException; | |
| 22 | -import org.testng.annotations.BeforeMethod; | |
| 23 | -import org.testng.annotations.Test; | |
| 24 | - | |
| 25 | -import static com.datastax.driver.core.ProtocolVersion.V1; | |
| 26 | -import static org.assertj.core.api.Assertions.fail; | |
| 27 | - | |
| 28 | 18 | import com.datastax.driver.core.*; |
| 29 | 19 | import com.datastax.driver.core.exceptions.CodecNotFoundException; |
| 30 | 20 | import com.datastax.driver.core.exceptions.InvalidQueryException; |
| 31 | 21 | import com.datastax.driver.core.utils.CassandraVersion; |
| 32 | 22 | import com.datastax.driver.mapping.annotations.*; |
| 23 | +import com.google.common.collect.Lists; | |
| 24 | +import org.testng.SkipException; | |
| 25 | +import org.testng.annotations.BeforeMethod; | |
| 26 | +import org.testng.annotations.Test; | |
| 27 | + | |
| 28 | +import java.util.Collection; | |
| 33 | 29 | |
| 34 | 30 | import static com.datastax.driver.core.Assertions.assertThat; |
| 31 | +import static com.datastax.driver.core.ProtocolVersion.V1; | |
| 32 | +import static org.assertj.core.api.Assertions.fail; | |
| 35 | 33 | |
| 36 | 34 | /** |
| 37 | 35 | * Tests to ensure validity of {@link com.datastax.driver.mapping.annotations.Computed} |
| @@ -43,8 +41,8 @@ | ||
| 43 | 41 | @Override |
| 44 | 42 | protected Collection<String> getTableDefinitions() { |
| 45 | 43 | return Lists.newArrayList( |
| 46 | - "CREATE TABLE user (login text primary key, name text)", | |
| 47 | - "INSERT INTO user (login, name) VALUES ('testlogin', 'test name')"); | |
| 44 | + "CREATE TABLE user (login text primary key, name text)", | |
| 45 | + "INSERT INTO user (login, name) VALUES ('testlogin', 'test name')"); | |
| 48 | 46 | } |
| 49 | 47 | |
| 50 | 48 | ProtocolVersion protocolVersion; |
| @@ -59,7 +57,7 @@ | ||
| 59 | 57 | userMapper = mappingManager.mapper(User.class); |
| 60 | 58 | } |
| 61 | 59 | |
| 62 | - @Test(groups = "short", expectedExceptions = { UnsupportedOperationException.class }) | |
| 60 | + @Test(groups = "short", expectedExceptions = {UnsupportedOperationException.class}) | |
| 63 | 61 | void should_get_unsupported_operation_exception_on_v1() { |
| 64 | 62 | if (protocolVersion.compareTo(V1) > 0) |
| 65 | 63 | throw new SkipException("Skipped when protocol version > V1"); |
| @@ -96,9 +94,9 @@ | ||
| 96 | 94 | @Test(groups = "short") |
| 97 | 95 | @CassandraVersion(major = 2.0) |
| 98 | 96 | void should_add_aliases_for_fields_in_select_queries() { |
| 99 | - BoundStatement bs = (BoundStatement)userMapper.getQuery("test"); | |
| 97 | + BoundStatement bs = (BoundStatement) userMapper.getQuery("test"); | |
| 100 | 98 | assertThat(bs.preparedStatement().getQueryString()) |
| 101 | - .contains("SELECT", "\"login\" AS col1", "\"name\" AS col2", "writetime(\"name\") AS col3"); | |
| 99 | + .contains("SELECT", "\"login\" AS col1", "\"name\" AS col2", "writetime(\"name\") AS col3"); | |
| 102 | 100 | } |
| 103 | 101 | |
| 104 | 102 | @Test(groups = "short") |
modified driver-mapping/src/test/java/com/datastax/driver/mapping/MapperCustomCodecTest.java +36 −35
| @@ -15,10 +15,10 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.mapping; |
| 17 | 17 | |
| 18 | -import java.nio.ByteBuffer; | |
| 19 | -import java.util.Collection; | |
| 20 | -import java.util.Map; | |
| 21 | - | |
| 18 | +import com.datastax.driver.core.*; | |
| 19 | +import com.datastax.driver.core.exceptions.InvalidTypeException; | |
| 20 | +import com.datastax.driver.core.utils.CassandraVersion; | |
| 21 | +import com.datastax.driver.mapping.annotations.*; | |
| 22 | 22 | import com.google.common.base.Optional; |
| 23 | 23 | import com.google.common.base.Predicate; |
| 24 | 24 | import com.google.common.collect.ImmutableMap; |
| @@ -27,40 +27,39 @@ | ||
| 27 | 27 | import com.google.common.reflect.TypeToken; |
| 28 | 28 | import org.testng.annotations.Test; |
| 29 | 29 | |
| 30 | +import java.nio.ByteBuffer; | |
| 31 | +import java.util.Collection; | |
| 32 | +import java.util.Map; | |
| 33 | + | |
| 30 | 34 | import static org.assertj.core.api.Assertions.assertThat; |
| 31 | 35 | import static org.assertj.core.api.Assertions.fail; |
| 32 | 36 | |
| 33 | -import com.datastax.driver.core.*; | |
| 34 | -import com.datastax.driver.core.exceptions.InvalidTypeException; | |
| 35 | -import com.datastax.driver.core.utils.CassandraVersion; | |
| 36 | -import com.datastax.driver.mapping.annotations.*; | |
| 37 | - | |
| 38 | -@CassandraVersion(major=2.1) | |
| 37 | +@CassandraVersion(major = 2.1) | |
| 39 | 38 | public class MapperCustomCodecTest extends CCMBridge.PerClassSingleNodeCluster { |
| 40 | 39 | |
| 41 | 40 | @Override |
| 42 | 41 | protected Collection<String> getTableDefinitions() { |
| 43 | 42 | return Lists.newArrayList( |
| 44 | - // Columns mapped to custom types | |
| 45 | - "CREATE TABLE data1 (i int PRIMARY KEY, l bigint)", | |
| 46 | - "INSERT INTO data1 (i, l) VALUES (1, 11)", | |
| 47 | - | |
| 48 | - // UDT fields mapped to custom types | |
| 49 | - "CREATE TYPE holder(i int, l bigint)", | |
| 50 | - "CREATE TABLE data2(i int primary key, data frozen<holder>)", | |
| 51 | - "INSERT INTO data2 (i, data) values (1, {i: 1, l: 11})", | |
| 52 | - | |
| 53 | - // nested UDT | |
| 54 | - // both UDT fields and non-UDT elements in the collection are mapped to custom types | |
| 55 | - "CREATE TABLE data3(i int primary key, data map<int, frozen<holder>>)", | |
| 56 | - "INSERT INTO data3 (i, data) values (1, {1: {i: 1, l: 11}})" | |
| 43 | + // Columns mapped to custom types | |
| 44 | + "CREATE TABLE data1 (i int PRIMARY KEY, l bigint)", | |
| 45 | + "INSERT INTO data1 (i, l) VALUES (1, 11)", | |
| 46 | + | |
| 47 | + // UDT fields mapped to custom types | |
| 48 | + "CREATE TYPE holder(i int, l bigint)", | |
| 49 | + "CREATE TABLE data2(i int primary key, data frozen<holder>)", | |
| 50 | + "INSERT INTO data2 (i, data) values (1, {i: 1, l: 11})", | |
| 51 | + | |
| 52 | + // nested UDT | |
| 53 | + // both UDT fields and non-UDT elements in the collection are mapped to custom types | |
| 54 | + "CREATE TABLE data3(i int primary key, data map<int, frozen<holder>>)", | |
| 55 | + "INSERT INTO data3 (i, data) values (1, {1: {i: 1, l: 11}})" | |
| 57 | 56 | ); |
| 58 | 57 | } |
| 59 | 58 | |
| 60 | 59 | @Override |
| 61 | 60 | protected Cluster.Builder configure(Cluster.Builder builder) { |
| 62 | 61 | return builder.withCodecRegistry(new CodecRegistry() |
| 63 | - .register(new CustomInt.Codec())); | |
| 62 | + .register(new CustomInt.Codec())); | |
| 64 | 63 | } |
| 65 | 64 | |
| 66 | 65 | @Test(groups = "short") |
| @@ -150,12 +149,12 @@ | ||
| 150 | 149 | mapper.delete(2); |
| 151 | 150 | } |
| 152 | 151 | |
| 153 | - @Test(groups="short", expectedExceptions = IllegalArgumentException.class) | |
| 152 | + @Test(groups = "short", expectedExceptions = IllegalArgumentException.class) | |
| 154 | 153 | public void should_fail_when_invalid_codec_with_no_default_ctor_provided() { |
| 155 | 154 | new MappingManager(session).mapper(Data1InvalidCodecNoDefaultConstructor.class); |
| 156 | 155 | } |
| 157 | 156 | |
| 158 | - @Test(groups="short", expectedExceptions = InvalidTypeException.class) | |
| 157 | + @Test(groups = "short", expectedExceptions = InvalidTypeException.class) | |
| 159 | 158 | public void should_fail_when_invalid_codec_type_mapping() { |
| 160 | 159 | Mapper<Data1InvalidCodecTypeMapping> mapper = new MappingManager(session).mapper(Data1InvalidCodecTypeMapping.class); |
| 161 | 160 | |
| @@ -174,12 +173,12 @@ | ||
| 174 | 173 | mapper.save(data12); |
| 175 | 174 | } |
| 176 | 175 | |
| 177 | - @Test(groups="short", expectedExceptions = IllegalArgumentException.class) | |
| 176 | + @Test(groups = "short", expectedExceptions = IllegalArgumentException.class) | |
| 178 | 177 | public void should_fail_when_invalid_codec_with_no_default_ctor_provided_in_accessor() { |
| 179 | 178 | new MappingManager(session).createAccessor(Data1AccessorNoDefaultConstructor.class); |
| 180 | 179 | } |
| 181 | 180 | |
| 182 | - @Test(groups="short", expectedExceptions = InvalidTypeException.class) | |
| 181 | + @Test(groups = "short", expectedExceptions = InvalidTypeException.class) | |
| 183 | 182 | public void should_fail_when_invalid_codec_type_mapping_in_accessor() { |
| 184 | 183 | Data1AccessorInvalidCodecTypeMapping accessor = new MappingManager(session).createAccessor(Data1AccessorInvalidCodecTypeMapping.class); |
| 185 | 184 | |
| @@ -194,7 +193,7 @@ | ||
| 194 | 193 | accessor.setL(1, Optional.of(2L)); |
| 195 | 194 | } |
| 196 | 195 | |
| 197 | - @Test(groups="short") | |
| 196 | + @Test(groups = "short") | |
| 198 | 197 | public void should_be_able_to_use_parameterized_type() { |
| 199 | 198 | Mapper<Data1ParameterizedType> mapper = new MappingManager(session).mapper(Data1ParameterizedType.class); |
| 200 | 199 | |
| @@ -454,7 +453,7 @@ | ||
| 454 | 453 | @Override |
| 455 | 454 | public boolean equals(Object other) { |
| 456 | 455 | if (other instanceof CustomInt) { |
| 457 | - CustomInt that = (CustomInt)other; | |
| 456 | + CustomInt that = (CustomInt) other; | |
| 458 | 457 | return this.value == that.value; |
| 459 | 458 | } |
| 460 | 459 | return false; |
| @@ -503,7 +502,7 @@ | ||
| 503 | 502 | @Override |
| 504 | 503 | public boolean equals(Object other) { |
| 505 | 504 | if (other instanceof CustomLong) { |
| 506 | - CustomLong that = (CustomLong)other; | |
| 505 | + CustomLong that = (CustomLong) other; | |
| 507 | 506 | return this.value == that.value; |
| 508 | 507 | } |
| 509 | 508 | return false; |
| @@ -511,7 +510,7 @@ | ||
| 511 | 510 | |
| 512 | 511 | @Override |
| 513 | 512 | public int hashCode() { |
| 514 | - return (int)(value ^ (value >>> 32)); | |
| 513 | + return (int) (value ^ (value >>> 32)); | |
| 515 | 514 | } |
| 516 | 515 | |
| 517 | 516 | public static class Codec extends TypeCodec<CustomLong> { |
| @@ -568,13 +567,15 @@ | ||
| 568 | 567 | private final Predicate<T> isAbsent; |
| 569 | 568 | |
| 570 | 569 | public OptionalCodec(TypeCodec<T> codec) { |
| 571 | - super(codec, new TypeToken<Optional<T>>(){}.where(new TypeParameter<T>(){}, codec.getJavaType())); | |
| 570 | + super(codec, new TypeToken<Optional<T>>() { | |
| 571 | + }.where(new TypeParameter<T>() { | |
| 572 | + }, codec.getJavaType())); | |
| 572 | 573 | this.isAbsent = new Predicate<T>() { |
| 573 | 574 | @Override |
| 574 | 575 | public boolean apply(T input) { |
| 575 | 576 | return input == null |
| 576 | - || input instanceof Collection && ((Collection)input).isEmpty() | |
| 577 | - || input instanceof Map && ((Map)input).isEmpty(); | |
| 577 | + || input instanceof Collection && ((Collection) input).isEmpty() | |
| 578 | + || input instanceof Map && ((Map) input).isEmpty(); | |
| 578 | 579 | } |
| 579 | 580 | }; |
| 580 | 581 | } |
modified driver-mapping/src/test/java/com/datastax/driver/mapping/MapperDefaultKeyspaceTest.java +25 −24
| @@ -15,36 +15,35 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.mapping; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.CCMBridge; | |
| 19 | +import com.datastax.driver.core.Session; | |
| 20 | +import com.datastax.driver.core.utils.CassandraVersion; | |
| 21 | +import com.datastax.driver.core.utils.UUIDs; | |
| 22 | +import com.datastax.driver.mapping.annotations.*; | |
| 23 | +import com.google.common.base.Objects; | |
| 24 | +import org.testng.annotations.Test; | |
| 25 | + | |
| 18 | 26 | import java.util.Arrays; |
| 19 | 27 | import java.util.Collection; |
| 20 | 28 | import java.util.UUID; |
| 21 | 29 | |
| 22 | -import com.google.common.base.Objects; | |
| 23 | -import org.testng.annotations.Test; | |
| 24 | - | |
| 25 | 30 | import static org.testng.Assert.assertEquals; |
| 26 | 31 | import static org.testng.Assert.assertNull; |
| 27 | 32 | |
| 28 | -import com.datastax.driver.core.CCMBridge; | |
| 29 | -import com.datastax.driver.core.Session; | |
| 30 | -import com.datastax.driver.core.utils.CassandraVersion; | |
| 31 | -import com.datastax.driver.core.utils.UUIDs; | |
| 32 | -import com.datastax.driver.mapping.annotations.*; | |
| 33 | - | |
| 34 | 33 | /** |
| 35 | 34 | * Tests usage of mapping annotations without specifying a keyspace. |
| 36 | 35 | */ |
| 37 | -@CassandraVersion(major=2.1) | |
| 36 | +@CassandraVersion(major = 2.1) | |
| 38 | 37 | public class MapperDefaultKeyspaceTest extends CCMBridge.PerClassSingleNodeCluster { |
| 39 | 38 | |
| 40 | 39 | private static final String KEYSPACE = "mapper_default_keyspace_test_ks"; |
| 41 | 40 | |
| 42 | 41 | protected Collection<String> getTableDefinitions() { |
| 43 | 42 | return Arrays.asList( |
| 44 | - String.format("CREATE KEYSPACE IF NOT EXISTS %s WITH replication = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 }", KEYSPACE), | |
| 45 | - String.format("CREATE TYPE IF NOT EXISTS %s.group_name (name text)", KEYSPACE), | |
| 46 | - String.format("CREATE TABLE IF NOT EXISTS %s.groups (group_id uuid PRIMARY KEY, name text)", KEYSPACE), | |
| 47 | - String.format("CREATE TABLE IF NOT EXISTS %s.groups2 (group_id uuid PRIMARY KEY, name frozen<group_name>)", KEYSPACE)); | |
| 43 | + String.format("CREATE KEYSPACE IF NOT EXISTS %s WITH replication = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 }", KEYSPACE), | |
| 44 | + String.format("CREATE TYPE IF NOT EXISTS %s.group_name (name text)", KEYSPACE), | |
| 45 | + String.format("CREATE TABLE IF NOT EXISTS %s.groups (group_id uuid PRIMARY KEY, name text)", KEYSPACE), | |
| 46 | + String.format("CREATE TABLE IF NOT EXISTS %s.groups2 (group_id uuid PRIMARY KEY, name frozen<group_name>)", KEYSPACE)); | |
| 48 | 47 | } |
| 49 | 48 | |
| 50 | 49 | @Test(groups = "short") |
| @@ -92,8 +91,8 @@ | ||
| 92 | 91 | } |
| 93 | 92 | |
| 94 | 93 | @Test(groups = "short", |
| 95 | - expectedExceptions = IllegalArgumentException.class, | |
| 96 | - expectedExceptionsMessageRegExp = "Error creating mapper for class Group, the @Table annotation declares no default keyspace, and the session is not currently logged to any keyspace") | |
| 94 | + expectedExceptions = IllegalArgumentException.class, | |
| 95 | + expectedExceptionsMessageRegExp = "Error creating mapper for class Group, the @Table annotation declares no default keyspace, and the session is not currently logged to any keyspace") | |
| 97 | 96 | public void should_throw_a_meaningful_error_message_when_no_default_table_keyspace_and_session_not_logged() { |
| 98 | 97 | Session session2 = cluster.connect(); |
| 99 | 98 | MappingManager manager = new MappingManager(session2); |
| @@ -101,8 +100,8 @@ | ||
| 101 | 100 | } |
| 102 | 101 | |
| 103 | 102 | @Test(groups = "short", |
| 104 | - expectedExceptions = IllegalArgumentException.class, | |
| 105 | - expectedExceptionsMessageRegExp = "Error creating UDT codec for class GroupName, the @UDT annotation declares no default keyspace, and the session is not currently logged to any keyspace") | |
| 103 | + expectedExceptions = IllegalArgumentException.class, | |
| 104 | + expectedExceptionsMessageRegExp = "Error creating UDT codec for class GroupName, the @UDT annotation declares no default keyspace, and the session is not currently logged to any keyspace") | |
| 106 | 105 | public void should_throw_a_meaningful_error_message_when_no_default_udt_keyspace_and_session_not_logged() { |
| 107 | 106 | Session session2 = cluster.connect(); |
| 108 | 107 | MappingManager manager = new MappingManager(session2); |
| @@ -123,7 +122,8 @@ | ||
| 123 | 122 | |
| 124 | 123 | private String name; |
| 125 | 124 | |
| 126 | - public Group() {} | |
| 125 | + public Group() { | |
| 126 | + } | |
| 127 | 127 | |
| 128 | 128 | public Group(String name) { |
| 129 | 129 | this.name = name; |
| @@ -151,9 +151,9 @@ | ||
| 151 | 151 | if (other == null || other.getClass() != this.getClass()) |
| 152 | 152 | return false; |
| 153 | 153 | |
| 154 | - Group that = (Group)other; | |
| 154 | + Group that = (Group) other; | |
| 155 | 155 | return Objects.equal(groupId, that.groupId) |
| 156 | - && Objects.equal(name, that.name); | |
| 156 | + && Objects.equal(name, that.name); | |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | @Override |
| @@ -172,7 +172,8 @@ | ||
| 172 | 172 | @Frozen |
| 173 | 173 | private GroupName name; |
| 174 | 174 | |
| 175 | - public Group2() {} | |
| 175 | + public Group2() { | |
| 176 | + } | |
| 176 | 177 | |
| 177 | 178 | public Group2(GroupName name) { |
| 178 | 179 | this.name = name; |
| @@ -200,9 +201,9 @@ | ||
| 200 | 201 | if (other == null || other.getClass() != this.getClass()) |
| 201 | 202 | return false; |
| 202 | 203 | |
| 203 | - Group that = (Group)other; | |
| 204 | + Group that = (Group) other; | |
| 204 | 205 | return Objects.equal(groupId, that.groupId) |
| 205 | - && Objects.equal(name, that.name); | |
| 206 | + && Objects.equal(name, that.name); | |
| 206 | 207 | } |
| 207 | 208 | |
| 208 | 209 | @Override |
modified driver-mapping/src/test/java/com/datastax/driver/mapping/MapperMaterializedViewTest.java +63 −63
| @@ -15,68 +15,67 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.mapping; |
| 17 | 17 | |
| 18 | -import java.util.Collection; | |
| 19 | -import java.util.Iterator; | |
| 20 | - | |
| 21 | -import org.testng.annotations.BeforeMethod; | |
| 22 | -import org.testng.annotations.Test; | |
| 23 | - | |
| 24 | -import static com.google.common.collect.Lists.newArrayList; | |
| 25 | -import static org.assertj.core.api.Assertions.assertThat; | |
| 26 | - | |
| 27 | 18 | import com.datastax.driver.core.CCMBridge; |
| 28 | 19 | import com.datastax.driver.core.utils.CassandraVersion; |
| 29 | 20 | import com.datastax.driver.mapping.annotations.Accessor; |
| 30 | 21 | import com.datastax.driver.mapping.annotations.Param; |
| 31 | 22 | import com.datastax.driver.mapping.annotations.Query; |
| 32 | 23 | import com.datastax.driver.mapping.annotations.Table; |
| 24 | +import org.testng.annotations.BeforeMethod; | |
| 25 | +import org.testng.annotations.Test; | |
| 26 | + | |
| 27 | +import java.util.Collection; | |
| 28 | +import java.util.Iterator; | |
| 29 | + | |
| 30 | +import static com.google.common.collect.Lists.newArrayList; | |
| 31 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 33 | 32 | |
| 34 | -@CassandraVersion(major=3.0) | |
| 35 | -public class MapperMaterializedViewTest extends CCMBridge.PerClassSingleNodeCluster{ | |
| 33 | +@CassandraVersion(major = 3.0) | |
| 34 | +public class MapperMaterializedViewTest extends CCMBridge.PerClassSingleNodeCluster { | |
| 36 | 35 | |
| 37 | 36 | @Override |
| 38 | 37 | protected Collection<String> getTableDefinitions() { |
| 39 | 38 | // Example schema taken from: http://www.datastax.com/dev/blog/new-in-cassandra-3-0-materialized-views |
| 40 | 39 | return newArrayList( |
| 41 | - "CREATE TABLE scores (user TEXT, game TEXT, year INT, month INT, day INT, score INT, PRIMARY KEY(user, game, year, month, day))", | |
| 42 | - "CREATE MATERIALIZED VIEW alltimehigh AS\n" | |
| 43 | - + " SELECT * FROM scores\n" | |
| 44 | - + " WHERE game IS NOT NULL AND score IS NOT NULL AND user IS NOT NULL AND year IS NOT NULL AND month IS NOT NULL AND day IS NOT NULL\n" | |
| 45 | - + " PRIMARY KEY (game, score, user, year, month, day)\n" | |
| 46 | - + " WITH CLUSTERING ORDER BY (score desc)", | |
| 47 | - "CREATE MATERIALIZED VIEW dailyhigh AS\n" | |
| 48 | - + " SELECT * FROM scores\n" | |
| 49 | - + " WHERE game IS NOT NULL AND year IS NOT NULL AND month IS NOT NULL AND day IS NOT NULL AND score IS NOT NULL AND user IS NOT NULL\n" | |
| 50 | - + " PRIMARY KEY ((game, year, month, day), score, user)\n" | |
| 51 | - + " WITH CLUSTERING ORDER BY (score DESC)", | |
| 52 | - "CREATE MATERIALIZED VIEW monthlyhigh AS\n" | |
| 53 | - + " SELECT * FROM scores\n" | |
| 54 | - + " WHERE game IS NOT NULL AND year IS NOT NULL AND month IS NOT NULL AND score IS NOT NULL AND user IS NOT NULL AND day IS NOT NULL\n" | |
| 55 | - + " PRIMARY KEY ((game, year, month), score, user, day)\n" | |
| 56 | - + " WITH CLUSTERING ORDER BY (score DESC)", | |
| 57 | - "CREATE MATERIALIZED VIEW filtereduserhigh AS\n" | |
| 58 | - + " SELECT * FROM scores\n" | |
| 59 | - + " WHERE user in ('jbellis', 'pcmanus') AND game IS NOT NULL AND score IS NOT NULL AND year is NOT NULL AND day is not NULL and month IS NOT NULL\n" | |
| 60 | - + " PRIMARY KEY (game, score, user, year, month, day)\n" | |
| 61 | - + " WITH CLUSTERING ORDER BY (score DESC)", | |
| 62 | - "INSERT INTO scores (user, game, year, month, day, score) VALUES ('pcmanus', 'Coup', 2015, 5, 1, 4000)", | |
| 63 | - "INSERT INTO scores (user, game, year, month, day, score) VALUES ('jbellis', 'Coup', 2015, 5, 3, 1750)", | |
| 64 | - "INSERT INTO scores (user, game, year, month, day, score) VALUES ('yukim', 'Coup', 2015, 5, 3, 2250)", | |
| 65 | - "INSERT INTO scores (user, game, year, month, day, score) VALUES ('tjake', 'Coup', 2015, 5, 3, 500)", | |
| 66 | - "INSERT INTO scores (user, game, year, month, day, score) VALUES ('iamaleksey', 'Coup', 2015, 6, 1, 2500)", | |
| 67 | - "INSERT INTO scores (user, game, year, month, day, score) VALUES ('tjake', 'Coup', 2015, 6, 2, 1000)", | |
| 68 | - "INSERT INTO scores (user, game, year, month, day, score) VALUES ('pcmanus', 'Coup', 2015, 6, 2, 2000)", | |
| 69 | - "INSERT INTO scores (user, game, year, month, day, score) VALUES ('jmckenzie', 'Coup', 2015, 6, 9, 2700)", | |
| 70 | - "INSERT INTO scores (user, game, year, month, day, score) VALUES ('jbellis', 'Coup', 2015, 6, 20, 3500)", | |
| 71 | - "INSERT INTO scores (user, game, year, month, day, score) VALUES ('jbellis', 'Checkers', 2015, 6, 20, 1200)", | |
| 72 | - "INSERT INTO scores (user, game, year, month, day, score) VALUES ('jbellis', 'Chess', 2015, 6, 21, 3500)", | |
| 73 | - "INSERT INTO scores (user, game, year, month, day, score) VALUES ('pcmanus', 'Chess', 2015, 1, 25, 3200)" | |
| 40 | + "CREATE TABLE scores (user TEXT, game TEXT, year INT, month INT, day INT, score INT, PRIMARY KEY(user, game, year, month, day))", | |
| 41 | + "CREATE MATERIALIZED VIEW alltimehigh AS\n" | |
| 42 | + + " SELECT * FROM scores\n" | |
| 43 | + + " WHERE game IS NOT NULL AND score IS NOT NULL AND user IS NOT NULL AND year IS NOT NULL AND month IS NOT NULL AND day IS NOT NULL\n" | |
| 44 | + + " PRIMARY KEY (game, score, user, year, month, day)\n" | |
| 45 | + + " WITH CLUSTERING ORDER BY (score desc)", | |
| 46 | + "CREATE MATERIALIZED VIEW dailyhigh AS\n" | |
| 47 | + + " SELECT * FROM scores\n" | |
| 48 | + + " WHERE game IS NOT NULL AND year IS NOT NULL AND month IS NOT NULL AND day IS NOT NULL AND score IS NOT NULL AND user IS NOT NULL\n" | |
| 49 | + + " PRIMARY KEY ((game, year, month, day), score, user)\n" | |
| 50 | + + " WITH CLUSTERING ORDER BY (score DESC)", | |
| 51 | + "CREATE MATERIALIZED VIEW monthlyhigh AS\n" | |
| 52 | + + " SELECT * FROM scores\n" | |
| 53 | + + " WHERE game IS NOT NULL AND year IS NOT NULL AND month IS NOT NULL AND score IS NOT NULL AND user IS NOT NULL AND day IS NOT NULL\n" | |
| 54 | + + " PRIMARY KEY ((game, year, month), score, user, day)\n" | |
| 55 | + + " WITH CLUSTERING ORDER BY (score DESC)", | |
| 56 | + "CREATE MATERIALIZED VIEW filtereduserhigh AS\n" | |
| 57 | + + " SELECT * FROM scores\n" | |
| 58 | + + " WHERE user in ('jbellis', 'pcmanus') AND game IS NOT NULL AND score IS NOT NULL AND year is NOT NULL AND day is not NULL and month IS NOT NULL\n" | |
| 59 | + + " PRIMARY KEY (game, score, user, year, month, day)\n" | |
| 60 | + + " WITH CLUSTERING ORDER BY (score DESC)", | |
| 61 | + "INSERT INTO scores (user, game, year, month, day, score) VALUES ('pcmanus', 'Coup', 2015, 5, 1, 4000)", | |
| 62 | + "INSERT INTO scores (user, game, year, month, day, score) VALUES ('jbellis', 'Coup', 2015, 5, 3, 1750)", | |
| 63 | + "INSERT INTO scores (user, game, year, month, day, score) VALUES ('yukim', 'Coup', 2015, 5, 3, 2250)", | |
| 64 | + "INSERT INTO scores (user, game, year, month, day, score) VALUES ('tjake', 'Coup', 2015, 5, 3, 500)", | |
| 65 | + "INSERT INTO scores (user, game, year, month, day, score) VALUES ('iamaleksey', 'Coup', 2015, 6, 1, 2500)", | |
| 66 | + "INSERT INTO scores (user, game, year, month, day, score) VALUES ('tjake', 'Coup', 2015, 6, 2, 1000)", | |
| 67 | + "INSERT INTO scores (user, game, year, month, day, score) VALUES ('pcmanus', 'Coup', 2015, 6, 2, 2000)", | |
| 68 | + "INSERT INTO scores (user, game, year, month, day, score) VALUES ('jmckenzie', 'Coup', 2015, 6, 9, 2700)", | |
| 69 | + "INSERT INTO scores (user, game, year, month, day, score) VALUES ('jbellis', 'Coup', 2015, 6, 20, 3500)", | |
| 70 | + "INSERT INTO scores (user, game, year, month, day, score) VALUES ('jbellis', 'Checkers', 2015, 6, 20, 1200)", | |
| 71 | + "INSERT INTO scores (user, game, year, month, day, score) VALUES ('jbellis', 'Chess', 2015, 6, 21, 3500)", | |
| 72 | + "INSERT INTO scores (user, game, year, month, day, score) VALUES ('pcmanus', 'Chess', 2015, 1, 25, 3200)" | |
| 74 | 73 | ); |
| 75 | 74 | } |
| 76 | 75 | |
| 77 | 76 | private ScoreAccessor accessor; |
| 78 | 77 | |
| 79 | - @BeforeMethod(groups="short") | |
| 78 | + @BeforeMethod(groups = "short") | |
| 80 | 79 | public void setUp() { |
| 81 | 80 | accessor = new MappingManager(session).createAccessor(ScoreAccessor.class); |
| 82 | 81 | } |
| @@ -85,9 +84,9 @@ | ||
| 85 | 84 | * Validates that an accessor properly maps a single entity over a result from a materialized |
| 86 | 85 | * view. |
| 87 | 86 | * |
| 88 | - * @test_category materialized_view,mapper | |
| 87 | + * @test_category materialized_view, mapper | |
| 89 | 88 | */ |
| 90 | - @Test(groups="short") | |
| 89 | + @Test(groups = "short") | |
| 91 | 90 | public void should_access_single_entity() { |
| 92 | 91 | Score score = accessor.allTimeHigh("Coup"); |
| 93 | 92 | |
| @@ -98,9 +97,9 @@ | ||
| 98 | 97 | * Validates that an accessor properly maps to a Result from a materialized |
| 99 | 98 | * view. |
| 100 | 99 | * |
| 101 | - * @test_category materialized_view,mapper | |
| 100 | + * @test_category materialized_view, mapper | |
| 102 | 101 | */ |
| 103 | - @Test(groups="short") | |
| 102 | + @Test(groups = "short") | |
| 104 | 103 | public void should_access_mapped_result() { |
| 105 | 104 | Result<Score> scores = accessor.dailyHigh("Coup", 2015, 6, 2); |
| 106 | 105 | |
| @@ -114,9 +113,9 @@ | ||
| 114 | 113 | * Validates that an accessor properly maps to a Result from a materialized |
| 115 | 114 | * view given a range criteria query. |
| 116 | 115 | * |
| 117 | - * @test_category materialized_view,mapper | |
| 116 | + * @test_category materialized_view, mapper | |
| 118 | 117 | */ |
| 119 | - @Test(groups="short") | |
| 118 | + @Test(groups = "short") | |
| 120 | 119 | public void should_access_mapped_result_range() { |
| 121 | 120 | Result<Score> scores = accessor.monthlyHighRange("Coup", 2015, 6, 2500, 3500); |
| 122 | 121 | |
| @@ -131,9 +130,9 @@ | ||
| 131 | 130 | * Validates that an accessor properly maps to a Result from a materialized |
| 132 | 131 | * view that is filtered on a primary key. |
| 133 | 132 | * |
| 134 | - * @test_category materialized_view,mapper | |
| 133 | + * @test_category materialized_view, mapper | |
| 135 | 134 | */ |
| 136 | - @Test(groups="short") | |
| 135 | + @Test(groups = "short") | |
| 137 | 136 | public void should_access_filtered_user_high() { |
| 138 | 137 | Result<Score> scores = accessor.filteredUserHigh("Chess"); |
| 139 | 138 | |
| @@ -158,7 +157,7 @@ | ||
| 158 | 157 | Result<Score> filteredUserHigh(String game); |
| 159 | 158 | } |
| 160 | 159 | |
| 161 | - @Table(name="scores") | |
| 160 | + @Table(name = "scores") | |
| 162 | 161 | public static class Score { |
| 163 | 162 | String user; |
| 164 | 163 | |
| @@ -172,7 +171,8 @@ | ||
| 172 | 171 | |
| 173 | 172 | int score; |
| 174 | 173 | |
| 175 | - public Score() {} | |
| 174 | + public Score() { | |
| 175 | + } | |
| 176 | 176 | |
| 177 | 177 | public Score(String user, String game, int year, int month, int day, int score) { |
| 178 | 178 | this.user = user; |
| @@ -234,13 +234,13 @@ | ||
| 234 | 234 | @Override |
| 235 | 235 | public String toString() { |
| 236 | 236 | return "Score{" + |
| 237 | - "user='" + user + '\'' + | |
| 238 | - ", game='" + game + '\'' + | |
| 239 | - ", year=" + year + | |
| 240 | - ", month=" + month + | |
| 241 | - ", day=" + day + | |
| 242 | - ", score=" + score + | |
| 243 | - '}'; | |
| 237 | + "user='" + user + '\'' + | |
| 238 | + ", game='" + game + '\'' + | |
| 239 | + ", year=" + year + | |
| 240 | + ", month=" + month + | |
| 241 | + ", day=" + day + | |
| 242 | + ", score=" + score + | |
| 243 | + '}'; | |
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | @Override |
| @@ -250,7 +250,7 @@ | ||
| 250 | 250 | if (!(o instanceof Score)) |
| 251 | 251 | return false; |
| 252 | 252 | |
| 253 | - Score score1 = (Score)o; | |
| 253 | + Score score1 = (Score) o; | |
| 254 | 254 | |
| 255 | 255 | if (year != score1.year) |
| 256 | 256 | return false; |
modified driver-mapping/src/test/java/com/datastax/driver/mapping/MapperNestedCollectionsTest.java +13 −14
| @@ -15,30 +15,29 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.mapping; |
| 17 | 17 | |
| 18 | -import java.util.*; | |
| 19 | - | |
| 18 | +import com.datastax.driver.core.CCMBridge; | |
| 19 | +import com.datastax.driver.core.ResultSet; | |
| 20 | +import com.datastax.driver.core.utils.CassandraVersion; | |
| 21 | +import com.datastax.driver.mapping.annotations.*; | |
| 20 | 22 | import com.google.common.collect.ImmutableMap; |
| 21 | 23 | import com.google.common.collect.Lists; |
| 22 | 24 | import com.google.common.collect.Sets; |
| 23 | 25 | import org.testng.annotations.Test; |
| 24 | 26 | |
| 25 | -import com.datastax.driver.core.CCMBridge; | |
| 26 | -import com.datastax.driver.core.ResultSet; | |
| 27 | -import com.datastax.driver.core.utils.CassandraVersion; | |
| 28 | -import com.datastax.driver.mapping.annotations.*; | |
| 27 | +import java.util.*; | |
| 29 | 28 | |
| 30 | 29 | import static com.datastax.driver.core.Assertions.assertThat; |
| 31 | 30 | |
| 32 | -@CassandraVersion(major=2.1, minor=3) | |
| 31 | +@CassandraVersion(major = 2.1, minor = 3) | |
| 33 | 32 | public class MapperNestedCollectionsTest extends CCMBridge.PerClassSingleNodeCluster { |
| 34 | 33 | |
| 35 | 34 | @Override |
| 36 | 35 | protected Collection<String> getTableDefinitions() { |
| 37 | 36 | return Lists.newArrayList( |
| 38 | - "CREATE TYPE testType(i int, ls list<frozen<set<int>>>)", | |
| 39 | - "CREATE TABLE testTable (k int primary key, " | |
| 40 | - + "m1 map<text, frozen<map<int, int>>>, " // nested collection | |
| 41 | - + "m2 map<text, frozen<map<int, frozen<testType>>>>)" // nested collection with UDT | |
| 37 | + "CREATE TYPE testType(i int, ls list<frozen<set<int>>>)", | |
| 38 | + "CREATE TABLE testTable (k int primary key, " | |
| 39 | + + "m1 map<text, frozen<map<int, int>>>, " // nested collection | |
| 40 | + + "m2 map<text, frozen<map<int, frozen<testType>>>>)" // nested collection with UDT | |
| 42 | 41 | ); |
| 43 | 42 | } |
| 44 | 43 | |
| @@ -50,8 +49,8 @@ | ||
| 50 | 49 | testTable.setK(1); |
| 51 | 50 | testTable.setM1(ImmutableMap.<String, Map<Integer, Integer>>of("bar", ImmutableMap.of(1, 2))); |
| 52 | 51 | |
| 53 | - Set<Integer> s1 = Sets.newHashSet(1,2,3); | |
| 54 | - Set<Integer> s2 = Sets.newHashSet(4,5,6); | |
| 52 | + Set<Integer> s1 = Sets.newHashSet(1, 2, 3); | |
| 53 | + Set<Integer> s2 = Sets.newHashSet(4, 5, 6); | |
| 55 | 54 | List<Set<Integer>> ls = new ArrayList<Set<Integer>>(); |
| 56 | 55 | ls.add(s1); |
| 57 | 56 | ls.add(s2); |
| @@ -129,7 +128,7 @@ | ||
| 129 | 128 | if (!(o instanceof TestType)) |
| 130 | 129 | return false; |
| 131 | 130 | |
| 132 | - TestType testType = (TestType)o; | |
| 131 | + TestType testType = (TestType) o; | |
| 133 | 132 | |
| 134 | 133 | if (i != testType.i) |
| 135 | 134 | return false; |
modified driver-mapping/src/test/java/com/datastax/driver/mapping/MapperOptionTest.java +25 −25
| @@ -15,27 +15,25 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.mapping; |
| 17 | 17 | |
| 18 | -import java.util.Collection; | |
| 19 | -import java.util.concurrent.ExecutionException; | |
| 20 | - | |
| 21 | -import com.google.common.collect.Lists; | |
| 22 | -import org.testng.SkipException; | |
| 23 | -import org.testng.annotations.BeforeMethod; | |
| 24 | -import org.testng.annotations.Test; | |
| 25 | - | |
| 26 | -import static com.datastax.driver.core.ConsistencyLevel.*; | |
| 27 | -import static org.assertj.core.api.Assertions.assertThat; | |
| 28 | -import static org.assertj.core.api.Assertions.fail; | |
| 29 | - | |
| 30 | 18 | import com.datastax.driver.core.*; |
| 31 | 19 | import com.datastax.driver.core.exceptions.NoHostAvailableException; |
| 32 | 20 | import com.datastax.driver.core.exceptions.UnavailableException; |
| 33 | 21 | import com.datastax.driver.core.utils.CassandraVersion; |
| 34 | 22 | import com.datastax.driver.mapping.annotations.PartitionKey; |
| 35 | 23 | import com.datastax.driver.mapping.annotations.Table; |
| 24 | +import com.google.common.collect.Lists; | |
| 25 | +import org.testng.SkipException; | |
| 26 | +import org.testng.annotations.BeforeMethod; | |
| 27 | +import org.testng.annotations.Test; | |
| 36 | 28 | |
| 29 | +import java.util.Collection; | |
| 30 | +import java.util.concurrent.ExecutionException; | |
| 31 | + | |
| 32 | +import static com.datastax.driver.core.ConsistencyLevel.*; | |
| 37 | 33 | import static com.datastax.driver.core.ProtocolVersion.V1; |
| 38 | 34 | import static com.datastax.driver.mapping.Mapper.Option; |
| 35 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 36 | +import static org.assertj.core.api.Assertions.fail; | |
| 39 | 37 | |
| 40 | 38 | public class MapperOptionTest extends CCMBridge.PerClassSingleNodeCluster { |
| 41 | 39 | |
| @@ -69,7 +67,7 @@ | ||
| 69 | 67 | User todelete = new User(45, "todelete"); |
| 70 | 68 | mapper.save(todelete); |
| 71 | 69 | Option opt = Option.timestamp(35); |
| 72 | - BoundStatement bs = (BoundStatement)mapper.deleteQuery(45, opt, Option.consistencyLevel(QUORUM)); | |
| 70 | + BoundStatement bs = (BoundStatement) mapper.deleteQuery(45, opt, Option.consistencyLevel(QUORUM)); | |
| 73 | 71 | assertThat(bs.preparedStatement().getQueryString()).contains("USING TIMESTAMP"); |
| 74 | 72 | assertThat(bs.getConsistencyLevel()).isEqualTo(QUORUM); |
| 75 | 73 | } |
| @@ -80,7 +78,7 @@ | ||
| 80 | 78 | User user = new User(45, "toget"); |
| 81 | 79 | mapper.save(user); |
| 82 | 80 | |
| 83 | - BoundStatement bs = (BoundStatement)mapper.getQuery(45, Option.tracing(true), Option.consistencyLevel(ALL)); | |
| 81 | + BoundStatement bs = (BoundStatement) mapper.getQuery(45, Option.tracing(true), Option.consistencyLevel(ALL)); | |
| 84 | 82 | assertThat(bs.isTracing()).isTrue(); |
| 85 | 83 | assertThat(bs.getConsistencyLevel()).isEqualTo(ALL); |
| 86 | 84 | |
| @@ -107,32 +105,32 @@ | ||
| 107 | 105 | @CassandraVersion(major = 2.0) |
| 108 | 106 | void should_use_default_options() { |
| 109 | 107 | mapper.setDefaultSaveOptions(Option.timestamp(644746L), Option.ttl(76324)); |
| 110 | - BoundStatement bs = (BoundStatement)mapper.saveQuery(new User(46, "rjhrgce")); | |
| 108 | + BoundStatement bs = (BoundStatement) mapper.saveQuery(new User(46, "rjhrgce")); | |
| 111 | 109 | assertThat(bs.preparedStatement().getQueryString()).contains("TIMESTAMP").contains("TTL"); |
| 112 | 110 | |
| 113 | 111 | mapper.resetDefaultSaveOptions(); |
| 114 | - bs = (BoundStatement)mapper.saveQuery(new User(47, "rjhrgce")); | |
| 112 | + bs = (BoundStatement) mapper.saveQuery(new User(47, "rjhrgce")); | |
| 115 | 113 | assertThat(bs.preparedStatement().getQueryString()).doesNotContain("TIMESTAMP").doesNotContain("TTL"); |
| 116 | 114 | |
| 117 | 115 | mapper.setDefaultDeleteOptions(Option.timestamp(3245L), Option.tracing(true)); |
| 118 | - bs = (BoundStatement)mapper.deleteQuery(47); | |
| 116 | + bs = (BoundStatement) mapper.deleteQuery(47); | |
| 119 | 117 | assertThat(bs.preparedStatement().getQueryString()).contains("TIMESTAMP"); |
| 120 | 118 | assertThat(bs.isTracing()).isTrue(); |
| 121 | 119 | |
| 122 | 120 | mapper.resetDefaultDeleteOptions(); |
| 123 | - bs = (BoundStatement)mapper.deleteQuery(47); | |
| 121 | + bs = (BoundStatement) mapper.deleteQuery(47); | |
| 124 | 122 | assertThat(bs.preparedStatement().getQueryString()).doesNotContain("TIMESTAMP"); |
| 125 | 123 | assertThat(bs.isTracing()).isFalse(); |
| 126 | 124 | |
| 127 | - bs = (BoundStatement)mapper.saveQuery(new User(46, "rjhrgce"), Option.timestamp(23), Option.consistencyLevel(ConsistencyLevel.ANY)); | |
| 125 | + bs = (BoundStatement) mapper.saveQuery(new User(46, "rjhrgce"), Option.timestamp(23), Option.consistencyLevel(ConsistencyLevel.ANY)); | |
| 128 | 126 | assertThat(bs.getConsistencyLevel()).isEqualTo(ConsistencyLevel.ANY); |
| 129 | 127 | |
| 130 | 128 | mapper.setDefaultGetOptions(Option.tracing(true)); |
| 131 | - bs = (BoundStatement)mapper.getQuery(46); | |
| 129 | + bs = (BoundStatement) mapper.getQuery(46); | |
| 132 | 130 | assertThat(bs.isTracing()).isTrue(); |
| 133 | 131 | |
| 134 | 132 | mapper.resetDefaultGetOptions(); |
| 135 | - bs = (BoundStatement)mapper.getQuery(46); | |
| 133 | + bs = (BoundStatement) mapper.getQuery(46); | |
| 136 | 134 | assertThat(bs.isTracing()).isFalse(); |
| 137 | 135 | } |
| 138 | 136 | |
| @@ -170,7 +168,9 @@ | ||
| 170 | 168 | assertThat(savedTimestamp).isEqualTo(explicitTimestamp); |
| 171 | 169 | } |
| 172 | 170 | |
| 173 | - /** Cover all versions of save() to check that methods that call each other properly propagate the options */ | |
| 171 | + /** | |
| 172 | + * Cover all versions of save() to check that methods that call each other properly propagate the options | |
| 173 | + */ | |
| 174 | 174 | @Test(groups = "short") |
| 175 | 175 | @CassandraVersion(major = 2.0) |
| 176 | 176 | void should_use_save_options_for_all_variants() throws ExecutionException, InterruptedException { |
| @@ -328,12 +328,12 @@ | ||
| 328 | 328 | assertThat(statement.getConsistencyLevel()).isEqualTo(TWO); |
| 329 | 329 | } |
| 330 | 330 | |
| 331 | - @Test(groups="short", expectedExceptions = IllegalArgumentException.class) | |
| 331 | + @Test(groups = "short", expectedExceptions = IllegalArgumentException.class) | |
| 332 | 332 | void should_fail_if_option_does_not_apply_to_query() { |
| 333 | 333 | mapper.get(42, Option.ttl(1)); |
| 334 | 334 | } |
| 335 | 335 | |
| 336 | - @Test(groups="short", expectedExceptions = IllegalArgumentException.class) | |
| 336 | + @Test(groups = "short", expectedExceptions = IllegalArgumentException.class) | |
| 337 | 337 | void should_fail_when_using_ttl_with_protocol_v1() { |
| 338 | 338 | if (protocolVersion.compareTo(V1) > 0) |
| 339 | 339 | throw new SkipException("Skipped when protocol version > V1"); |
| @@ -341,7 +341,7 @@ | ||
| 341 | 341 | mapper.saveQuery(new User(42, "helloworld"), Option.ttl(15)); |
| 342 | 342 | } |
| 343 | 343 | |
| 344 | - @Test(groups="short", expectedExceptions = IllegalArgumentException.class) | |
| 344 | + @Test(groups = "short", expectedExceptions = IllegalArgumentException.class) | |
| 345 | 345 | void should_fail_when_using_timestamp_with_protocol_v1() { |
| 346 | 346 | if (protocolVersion.compareTo(V1) > 0) |
| 347 | 347 | throw new SkipException("Skipped when protocol version > V1"); |
modified driver-mapping/src/test/java/com/datastax/driver/mapping/MapperPrimitiveTypes22Test.java +6 −6
| @@ -29,16 +29,16 @@ | ||
| 29 | 29 | |
| 30 | 30 | import static org.testng.Assert.assertEquals; |
| 31 | 31 | |
| 32 | -@CassandraVersion(major=2.2) | |
| 32 | +@CassandraVersion(major = 2.2) | |
| 33 | 33 | public class MapperPrimitiveTypes22Test extends CCMBridge.PerClassSingleNodeCluster { |
| 34 | 34 | |
| 35 | 35 | protected Collection<String> getTableDefinitions() { |
| 36 | 36 | return Arrays.asList("CREATE TABLE primitiveTypes22 (" |
| 37 | - + "byteBufferCol blob primary key," | |
| 38 | - + "localDateCol date," | |
| 39 | - + "timeCol time, timeWrapperCol time," | |
| 40 | - + "byteCol tinyint, byteWrapperCol tinyint," | |
| 41 | - + "shortCol smallint, shortWrapperCol smallint)"); | |
| 37 | + + "byteBufferCol blob primary key," | |
| 38 | + + "localDateCol date," | |
| 39 | + + "timeCol time, timeWrapperCol time," | |
| 40 | + + "byteCol tinyint, byteWrapperCol tinyint," | |
| 41 | + + "shortCol smallint, shortWrapperCol smallint)"); | |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | @Test(groups = "short") |
modified driver-mapping/src/test/java/com/datastax/driver/mapping/MapperPrimitiveTypesTest.java +13 −13
| @@ -40,19 +40,19 @@ | ||
| 40 | 40 | |
| 41 | 41 | protected Collection<String> getTableDefinitions() { |
| 42 | 42 | return Arrays.asList("CREATE TABLE primitiveTypes (" |
| 43 | - + "byteBufferCol blob primary key," | |
| 44 | - + "intCol int, intWrapperCol int," | |
| 45 | - + "longCol bigint, longWrapperCol bigint," | |
| 46 | - + "floatCol float, floatWrapperCol float," | |
| 47 | - + "doubleCol double, doubleWrapperCol double," | |
| 48 | - + "booleanCol boolean, booleanWrapperCol boolean," | |
| 49 | - + "bigDecimalCol decimal," | |
| 50 | - + "bigIntegerCol varint," | |
| 51 | - + "stringCol text," | |
| 52 | - + "inetCol inet," | |
| 53 | - + "dateCol timestamp," | |
| 54 | - + "uuidCol uuid," | |
| 55 | - + "timeUuidCol timeuuid)"); | |
| 43 | + + "byteBufferCol blob primary key," | |
| 44 | + + "intCol int, intWrapperCol int," | |
| 45 | + + "longCol bigint, longWrapperCol bigint," | |
| 46 | + + "floatCol float, floatWrapperCol float," | |
| 47 | + + "doubleCol double, doubleWrapperCol double," | |
| 48 | + + "booleanCol boolean, booleanWrapperCol boolean," | |
| 49 | + + "bigDecimalCol decimal," | |
| 50 | + + "bigIntegerCol varint," | |
| 51 | + + "stringCol text," | |
| 52 | + + "inetCol inet," | |
| 53 | + + "dateCol timestamp," | |
| 54 | + + "uuidCol uuid," | |
| 55 | + + "timeUuidCol timeuuid)"); | |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | @Test(groups = "short") |
modified driver-mapping/src/test/java/com/datastax/driver/mapping/MapperSaveNullFieldsTest.java +13 −14
| @@ -15,19 +15,18 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.mapping; |
| 17 | 17 | |
| 18 | -import java.util.Collection; | |
| 19 | - | |
| 20 | -import com.google.common.collect.Lists; | |
| 21 | -import org.testng.annotations.BeforeMethod; | |
| 22 | -import org.testng.annotations.Test; | |
| 23 | - | |
| 24 | -import static org.assertj.core.api.Assertions.assertThat; | |
| 25 | - | |
| 26 | 18 | import com.datastax.driver.core.BoundStatement; |
| 27 | 19 | import com.datastax.driver.core.CCMBridge; |
| 28 | 20 | import com.datastax.driver.mapping.Mapper.Option; |
| 29 | 21 | import com.datastax.driver.mapping.annotations.PartitionKey; |
| 30 | 22 | import com.datastax.driver.mapping.annotations.Table; |
| 23 | +import com.google.common.collect.Lists; | |
| 24 | +import org.testng.annotations.BeforeMethod; | |
| 25 | +import org.testng.annotations.Test; | |
| 26 | + | |
| 27 | +import java.util.Collection; | |
| 28 | + | |
| 29 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 31 | 30 | |
| 32 | 31 | public class MapperSaveNullFieldsTest extends CCMBridge.PerClassSingleNodeCluster { |
| 33 | 32 | |
| @@ -75,7 +74,7 @@ | ||
| 75 | 74 | private void should_save_null_fields(boolean nullName, boolean nullPhone, boolean saveExpected, Option... options) { |
| 76 | 75 | // Start with clean data |
| 77 | 76 | session.execute("insert into user(login, name, phone) " |
| 78 | - + "values ('test_login', 'previous_name', 'previous_phone')"); | |
| 77 | + + "values ('test_login', 'previous_name', 'previous_phone')"); | |
| 79 | 78 | |
| 80 | 79 | String newName = nullName ? null : "new_name"; |
| 81 | 80 | String newPhone = nullPhone ? null : "new_phone"; |
| @@ -83,7 +82,7 @@ | ||
| 83 | 82 | User newUser = new User("test_login", newName, newPhone); |
| 84 | 83 | |
| 85 | 84 | // Check if null fields are included in generated statement: |
| 86 | - BoundStatement bs = (BoundStatement)mapper.saveQuery(newUser, options); | |
| 85 | + BoundStatement bs = (BoundStatement) mapper.saveQuery(newUser, options); | |
| 87 | 86 | String queryString = bs.preparedStatement().getQueryString(); |
| 88 | 87 | if (nullName && !saveExpected) |
| 89 | 88 | assertThat(queryString).as(description).doesNotContain("\"name\""); |
| @@ -99,11 +98,11 @@ | ||
| 99 | 98 | mapper.save(newUser, options); |
| 100 | 99 | User savedUser = mapper.get("test_login"); |
| 101 | 100 | String expectedName = nullName |
| 102 | - ? (saveExpected ? null : "previous_name") | |
| 103 | - : "new_name"; | |
| 101 | + ? (saveExpected ? null : "previous_name") | |
| 102 | + : "new_name"; | |
| 104 | 103 | String expectedPhone = nullPhone |
| 105 | - ? (saveExpected ? null : "previous_phone") | |
| 106 | - : "new_phone"; | |
| 104 | + ? (saveExpected ? null : "previous_phone") | |
| 105 | + : "new_phone"; | |
| 107 | 106 | assertThat(savedUser.getName()).as(description).isEqualTo(expectedName); |
| 108 | 107 | assertThat(savedUser.getPhone()).as(description).isEqualTo(expectedPhone); |
| 109 | 108 | } |
modified driver-mapping/src/test/java/com/datastax/driver/mapping/MapperTest.java +31 −31
| @@ -15,22 +15,20 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.mapping; |
| 17 | 17 | |
| 18 | -import java.net.InetAddress; | |
| 19 | - | |
| 18 | +import com.datastax.driver.core.*; | |
| 20 | 19 | import com.datastax.driver.core.utils.CassandraVersion; |
| 21 | -import com.datastax.driver.mapping.annotations.Table; | |
| 22 | -import java.util.*; | |
| 23 | - | |
| 20 | +import com.datastax.driver.core.utils.UUIDs; | |
| 21 | +import com.datastax.driver.mapping.annotations.*; | |
| 24 | 22 | import com.google.common.base.Objects; |
| 25 | 23 | import com.google.common.util.concurrent.ListenableFuture; |
| 26 | 24 | import org.testng.annotations.Test; |
| 27 | 25 | |
| 28 | -import static org.assertj.core.api.Assertions.assertThat; | |
| 29 | -import static org.testng.Assert.*; | |
| 26 | +import java.net.InetAddress; | |
| 27 | +import java.util.*; | |
| 30 | 28 | |
| 31 | -import com.datastax.driver.mapping.annotations.*; | |
| 32 | -import com.datastax.driver.core.*; | |
| 33 | -import com.datastax.driver.core.utils.UUIDs; | |
| 29 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 30 | +import static org.testng.Assert.assertEquals; | |
| 31 | +import static org.testng.Assert.assertTrue; | |
| 34 | 32 | |
| 35 | 33 | /** |
| 36 | 34 | * Basic tests for the mapping module. |
| @@ -42,7 +40,7 @@ | ||
| 42 | 40 | // We'll allow to generate those create statement from the annotated entities later, but it's currently |
| 43 | 41 | // a TODO |
| 44 | 42 | return Arrays.asList("CREATE TABLE users (user_id uuid PRIMARY KEY, name text, email text, year int, gender text)", |
| 45 | - "CREATE TABLE posts (user_id uuid, post_id timeuuid, title text, content text, device inet, tags set<text>, PRIMARY KEY(user_id, post_id))"); | |
| 43 | + "CREATE TABLE posts (user_id uuid, post_id timeuuid, title text, content text, device inet, tags set<text>, PRIMARY KEY(user_id, post_id))"); | |
| 46 | 44 | } |
| 47 | 45 | |
| 48 | 46 | /* |
| @@ -58,8 +56,8 @@ | ||
| 58 | 56 | */ |
| 59 | 57 | @SuppressWarnings("unused") |
| 60 | 58 | @Table(name = "users", |
| 61 | - readConsistency="QUORUM", | |
| 62 | - writeConsistency="QUORUM") | |
| 59 | + readConsistency = "QUORUM", | |
| 60 | + writeConsistency = "QUORUM") | |
| 63 | 61 | public static class User { |
| 64 | 62 | |
| 65 | 63 | // Dummy constant to test that static fields are properly ignored |
| @@ -74,7 +72,8 @@ | ||
| 74 | 72 | @Column // not strictly required, but we want to check that the annotation works without a name |
| 75 | 73 | private int year; |
| 76 | 74 | |
| 77 | - public User() {} | |
| 75 | + public User() { | |
| 76 | + } | |
| 78 | 77 | |
| 79 | 78 | public User(String name, String email) { |
| 80 | 79 | this.userId = UUIDs.random(); |
| @@ -119,11 +118,11 @@ | ||
| 119 | 118 | if (other == null || other.getClass() != this.getClass()) |
| 120 | 119 | return false; |
| 121 | 120 | |
| 122 | - User that = (User)other; | |
| 121 | + User that = (User) other; | |
| 123 | 122 | return Objects.equal(userId, that.userId) |
| 124 | - && Objects.equal(name, that.name) | |
| 125 | - && Objects.equal(email, that.email) | |
| 126 | - && Objects.equal(year, that.year); | |
| 123 | + && Objects.equal(name, that.name) | |
| 124 | + && Objects.equal(email, that.email) | |
| 125 | + && Objects.equal(year, that.year); | |
| 127 | 126 | } |
| 128 | 127 | |
| 129 | 128 | @Override |
| @@ -156,7 +155,8 @@ | ||
| 156 | 155 | |
| 157 | 156 | private Set<String> tags; |
| 158 | 157 | |
| 159 | - public Post() {} | |
| 158 | + public Post() { | |
| 159 | + } | |
| 160 | 160 | |
| 161 | 161 | public Post(User user, String title) { |
| 162 | 162 | this.userId = user.getUserId(); |
| @@ -217,13 +217,13 @@ | ||
| 217 | 217 | if (other == null || other.getClass() != this.getClass()) |
| 218 | 218 | return false; |
| 219 | 219 | |
| 220 | - Post that = (Post)other; | |
| 220 | + Post that = (Post) other; | |
| 221 | 221 | return Objects.equal(userId, that.userId) |
| 222 | - && Objects.equal(postId, that.postId) | |
| 223 | - && Objects.equal(title, that.title) | |
| 224 | - && Objects.equal(content, that.content) | |
| 225 | - && Objects.equal(device, that.device) | |
| 226 | - && Objects.equal(tags, that.tags); | |
| 222 | + && Objects.equal(postId, that.postId) | |
| 223 | + && Objects.equal(title, that.title) | |
| 224 | + && Objects.equal(content, that.content) | |
| 225 | + && Objects.equal(device, that.device) | |
| 226 | + && Objects.equal(tags, that.tags); | |
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | @Override |
| @@ -257,13 +257,13 @@ | ||
| 257 | 257 | // somehow, but well, not a huge deal. |
| 258 | 258 | @Query("SELECT * FROM posts WHERE user_id=:userId AND post_id=:postId") |
| 259 | 259 | Post getOne(@Param("userId") UUID userId, |
| 260 | - @Param("postId") UUID postId); | |
| 260 | + @Param("postId") UUID postId); | |
| 261 | 261 | |
| 262 | 262 | // Note that the following method will be asynchronous (it will use executeAsync |
| 263 | 263 | // underneath) because it's return type is a ListenableFuture. Similarly, we know |
| 264 | 264 | // that we need to map the result to the Post entity thanks to the return type. |
| 265 | 265 | @Query("SELECT * FROM posts WHERE user_id=?") |
| 266 | - @QueryParameters(consistency="QUORUM") | |
| 266 | + @QueryParameters(consistency = "QUORUM") | |
| 267 | 267 | ListenableFuture<Result<Post>> getAllAsync(UUID userId); |
| 268 | 268 | |
| 269 | 269 | // The method above actually query stuff, but if a method is declared to return |
| @@ -295,7 +295,7 @@ | ||
| 295 | 295 | } |
| 296 | 296 | |
| 297 | 297 | @Test(groups = "short") |
| 298 | - @CassandraVersion(major=2.0) | |
| 298 | + @CassandraVersion(major = 2.0) | |
| 299 | 299 | public void testDynamicEntity() throws Exception { |
| 300 | 300 | MappingManager manager = new MappingManager(session); |
| 301 | 301 | |
| @@ -355,7 +355,7 @@ | ||
| 355 | 355 | |
| 356 | 356 | } |
| 357 | 357 | |
| 358 | - @Test(groups="short") | |
| 358 | + @Test(groups = "short") | |
| 359 | 359 | public void should_map_objects_from_partial_queries() throws Exception { |
| 360 | 360 | MappingManager manager = new MappingManager(session); |
| 361 | 361 | |
| @@ -392,7 +392,7 @@ | ||
| 392 | 392 | } |
| 393 | 393 | |
| 394 | 394 | |
| 395 | - @Test(groups="short") | |
| 395 | + @Test(groups = "short") | |
| 396 | 396 | public void should_return_table_metadata() throws Exception { |
| 397 | 397 | MappingManager manager = new MappingManager(session); |
| 398 | 398 | |
| @@ -403,7 +403,7 @@ | ||
| 403 | 403 | assertThat(m.getTableMetadata().getPartitionKey()).hasSize(1); |
| 404 | 404 | } |
| 405 | 405 | |
| 406 | - @Test(groups="short") | |
| 406 | + @Test(groups = "short") | |
| 407 | 407 | public void should_not_initialize_session_when_protocol_version_provided() { |
| 408 | 408 | Session newSession = cluster.newSession(); |
| 409 | 409 |
modified driver-mapping/src/test/java/com/datastax/driver/mapping/MapperUDTCollectionsTest.java +11 −12
| @@ -15,8 +15,7 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.mapping; |
| 17 | 17 | |
| 18 | -import java.util.*; | |
| 19 | - | |
| 18 | +import com.datastax.driver.core.CCMBridge; | |
| 20 | 19 | import com.datastax.driver.mapping.annotations.*; |
| 21 | 20 | import com.google.common.base.Objects; |
| 22 | 21 | import com.google.common.collect.ImmutableMap; |
| @@ -24,9 +23,9 @@ | ||
| 24 | 23 | import org.testng.annotations.Test; |
| 25 | 24 | import org.testng.collections.Lists; |
| 26 | 25 | |
| 27 | -import static org.testng.Assert.assertEquals; | |
| 26 | +import java.util.*; | |
| 28 | 27 | |
| 29 | -import com.datastax.driver.core.CCMBridge; | |
| 28 | +import static org.testng.Assert.assertEquals; | |
| 30 | 29 | |
| 31 | 30 | /** |
| 32 | 31 | * Tests mapping of collections of UDTs. |
| @@ -35,7 +34,7 @@ | ||
| 35 | 34 | |
| 36 | 35 | protected Collection<String> getTableDefinitions() { |
| 37 | 36 | return Arrays.asList("CREATE TYPE sub(i int)", |
| 38 | - "CREATE TABLE collection_examples (id int PRIMARY KEY, l list<frozen<sub>>, s set<frozen<sub>>, m1 map<int,frozen<sub>>, m2 map<frozen<sub>,int>, m3 map<frozen<sub>,frozen<sub>>)"); | |
| 37 | + "CREATE TABLE collection_examples (id int PRIMARY KEY, l list<frozen<sub>>, s set<frozen<sub>>, m1 map<int,frozen<sub>>, m2 map<frozen<sub>,int>, m3 map<frozen<sub>,frozen<sub>>)"); | |
| 39 | 38 | } |
| 40 | 39 | |
| 41 | 40 | @UDT(name = "sub") |
| @@ -60,7 +59,7 @@ | ||
| 60 | 59 | @Override |
| 61 | 60 | public boolean equals(Object other) { |
| 62 | 61 | if (other instanceof Sub) { |
| 63 | - Sub that = (Sub)other; | |
| 62 | + Sub that = (Sub) other; | |
| 64 | 63 | return this.i == that.i; |
| 65 | 64 | } |
| 66 | 65 | return false; |
| @@ -159,13 +158,13 @@ | ||
| 159 | 158 | @Override |
| 160 | 159 | public boolean equals(Object other) { |
| 161 | 160 | if (other instanceof CollectionExamples) { |
| 162 | - CollectionExamples that = (CollectionExamples)other; | |
| 161 | + CollectionExamples that = (CollectionExamples) other; | |
| 163 | 162 | return Objects.equal(this.id, that.id) && |
| 164 | - Objects.equal(this.l, that.l) && | |
| 165 | - Objects.equal(this.s, that.s) && | |
| 166 | - Objects.equal(this.m1, that.m1) && | |
| 167 | - Objects.equal(this.m2, that.m2) && | |
| 168 | - Objects.equal(this.m3, that.m3); | |
| 163 | + Objects.equal(this.l, that.l) && | |
| 164 | + Objects.equal(this.s, that.s) && | |
| 165 | + Objects.equal(this.m1, that.m1) && | |
| 166 | + Objects.equal(this.m2, that.m2) && | |
| 167 | + Objects.equal(this.m3, that.m3); | |
| 169 | 168 | } |
| 170 | 169 | return false; |
| 171 | 170 | } |
modified driver-mapping/src/test/java/com/datastax/driver/mapping/MapperUDTTest.java +25 −30
| @@ -15,32 +15,27 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.mapping; |
| 17 | 17 | |
| 18 | -import java.util.*; | |
| 19 | - | |
| 20 | 18 | import com.datastax.driver.core.*; |
| 21 | 19 | import com.datastax.driver.core.exceptions.CodecNotFoundException; |
| 20 | +import com.datastax.driver.core.utils.UUIDs; | |
| 21 | +import com.datastax.driver.mapping.annotations.*; | |
| 22 | +import com.google.common.base.Objects; | |
| 22 | 23 | import com.google.common.collect.Maps; |
| 23 | 24 | import org.assertj.core.data.MapEntry; |
| 24 | 25 | import org.testng.annotations.BeforeMethod; |
| 25 | - | |
| 26 | -import com.google.common.base.Objects; | |
| 27 | 26 | import org.testng.annotations.Test; |
| 28 | 27 | |
| 28 | +import java.util.*; | |
| 29 | + | |
| 29 | 30 | import static org.assertj.core.api.Assertions.assertThat; |
| 30 | 31 | import static org.assertj.core.api.Assertions.fail; |
| 31 | -import static org.testng.Assert.assertEquals; | |
| 32 | -import static org.testng.Assert.assertNull; | |
| 33 | -import static org.testng.Assert.assertTrue; | |
| 34 | - | |
| 35 | -import com.datastax.driver.core.utils.UUIDs; | |
| 36 | - | |
| 37 | -import com.datastax.driver.mapping.annotations.*; | |
| 32 | +import static org.testng.Assert.*; | |
| 38 | 33 | |
| 39 | 34 | public class MapperUDTTest extends CCMBridge.PerClassSingleNodeCluster { |
| 40 | 35 | |
| 41 | 36 | protected Collection<String> getTableDefinitions() { |
| 42 | 37 | return Arrays.asList("CREATE TYPE address (street text, city text, \"ZIP_code\" int, phones set<text>)", |
| 43 | - "CREATE TABLE users (user_id uuid PRIMARY KEY, name text, mainaddress frozen<address>, other_addresses map<text,frozen<address>>)"); | |
| 38 | + "CREATE TABLE users (user_id uuid PRIMARY KEY, name text, mainaddress frozen<address>, other_addresses map<text,frozen<address>>)"); | |
| 44 | 39 | } |
| 45 | 40 | |
| 46 | 41 | @BeforeMethod(groups = "short") |
| @@ -49,8 +44,8 @@ | ||
| 49 | 44 | } |
| 50 | 45 | |
| 51 | 46 | @Table(name = "users", |
| 52 | - readConsistency = "QUORUM", | |
| 53 | - writeConsistency = "QUORUM") | |
| 47 | + readConsistency = "QUORUM", | |
| 48 | + writeConsistency = "QUORUM") | |
| 54 | 49 | public static class User { |
| 55 | 50 | @PartitionKey |
| 56 | 51 | @Column(name = "user_id") |
| @@ -118,9 +113,9 @@ | ||
| 118 | 113 | if (other instanceof User) { |
| 119 | 114 | User that = (User) other; |
| 120 | 115 | return Objects.equal(this.userId, that.userId) && |
| 121 | - Objects.equal(this.name, that.name) && | |
| 122 | - Objects.equal(this.mainAddress, that.mainAddress) && | |
| 123 | - Objects.equal(this.otherAddresses, that.otherAddresses); | |
| 116 | + Objects.equal(this.name, that.name) && | |
| 117 | + Objects.equal(this.mainAddress, that.mainAddress) && | |
| 118 | + Objects.equal(this.otherAddresses, that.otherAddresses); | |
| 124 | 119 | } |
| 125 | 120 | return false; |
| 126 | 121 | } |
| @@ -133,11 +128,11 @@ | ||
| 133 | 128 | @Override |
| 134 | 129 | public String toString() { |
| 135 | 130 | return Objects.toStringHelper(User.class) |
| 136 | - .add("userId", userId) | |
| 137 | - .add("name", name) | |
| 138 | - .add("mainAddress", mainAddress) | |
| 139 | - .add("otherAddresses", otherAddresses) | |
| 140 | - .toString(); | |
| 131 | + .add("userId", userId) | |
| 132 | + .add("name", name) | |
| 133 | + .add("mainAddress", mainAddress) | |
| 134 | + .add("otherAddresses", otherAddresses) | |
| 135 | + .toString(); | |
| 141 | 136 | } |
| 142 | 137 | } |
| 143 | 138 | |
| @@ -210,9 +205,9 @@ | ||
| 210 | 205 | if (other instanceof Address) { |
| 211 | 206 | Address that = (Address) other; |
| 212 | 207 | return Objects.equal(this.street, that.street) && |
| 213 | - Objects.equal(this.city, that.city) && | |
| 214 | - Objects.equal(this.zipCode, that.zipCode) && | |
| 215 | - Objects.equal(this.phones, that.phones); | |
| 208 | + Objects.equal(this.city, that.city) && | |
| 209 | + Objects.equal(this.zipCode, that.zipCode) && | |
| 210 | + Objects.equal(this.phones, that.phones); | |
| 216 | 211 | } |
| 217 | 212 | return false; |
| 218 | 213 | } |
| @@ -225,11 +220,11 @@ | ||
| 225 | 220 | @Override |
| 226 | 221 | public String toString() { |
| 227 | 222 | return Objects.toStringHelper(Address.class) |
| 228 | - .add("street", street) | |
| 229 | - .add("city", city) | |
| 230 | - .add("zip", zipCode) | |
| 231 | - .add("phones", phones) | |
| 232 | - .toString(); | |
| 223 | + .add("street", street) | |
| 224 | + .add("city", city) | |
| 225 | + .add("zip", zipCode) | |
| 226 | + .add("phones", phones) | |
| 227 | + .toString(); | |
| 233 | 228 | } |
| 234 | 229 | } |
| 235 | 230 |
modified driver-mapping/src/test/java/com/datastax/driver/mapping/UDTFieldMapperTest.java +36 −38
| @@ -15,20 +15,18 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.mapping; |
| 17 | 17 | |
| 18 | -import java.util.HashMap; | |
| 19 | -import java.util.Map; | |
| 20 | - | |
| 21 | -import com.google.common.collect.ImmutableMap; | |
| 22 | -import org.testng.annotations.Test; | |
| 23 | - | |
| 24 | 18 | import com.datastax.driver.core.CCMBridge; |
| 25 | 19 | import com.datastax.driver.core.Cluster; |
| 26 | 20 | import com.datastax.driver.core.Session; |
| 27 | -import com.datastax.driver.core.TestUtils; | |
| 28 | 21 | import com.datastax.driver.core.utils.CassandraVersion; |
| 29 | 22 | import com.datastax.driver.mapping.annotations.*; |
| 23 | +import com.google.common.collect.ImmutableMap; | |
| 24 | +import org.testng.annotations.Test; | |
| 25 | + | |
| 26 | +import java.util.HashMap; | |
| 27 | +import java.util.Map; | |
| 30 | 28 | |
| 31 | -@CassandraVersion(major=2.1) | |
| 29 | +@CassandraVersion(major = 2.1) | |
| 32 | 30 | public class UDTFieldMapperTest { |
| 33 | 31 | |
| 34 | 32 | @Test(groups = "short") |
| @@ -42,13 +40,13 @@ | ||
| 42 | 40 | cluster = Cluster.builder().addContactPoint(CCMBridge.ipOfNode(1)).build(); |
| 43 | 41 | Session session1 = cluster.connect(); |
| 44 | 42 | session1.execute("create schema if not exists java_509 " + |
| 45 | - "with replication = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };"); | |
| 43 | + "with replication = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };"); | |
| 46 | 44 | session1.execute("create type java_509.my_tuple (" + |
| 47 | - "type text, " + | |
| 48 | - "value text);"); | |
| 45 | + "type text, " + | |
| 46 | + "value text);"); | |
| 49 | 47 | session1.execute("create table java_509.my_hash (" + |
| 50 | - "key int primary key, " + | |
| 51 | - "properties map<text, frozen<java_509.my_tuple>>);"); | |
| 48 | + "key int primary key, " + | |
| 49 | + "properties map<text, frozen<java_509.my_tuple>>);"); | |
| 52 | 50 | cluster.close(); |
| 53 | 51 | |
| 54 | 52 | // Create entities with another connection |
| @@ -56,20 +54,20 @@ | ||
| 56 | 54 | Session session2 = cluster.newSession(); |
| 57 | 55 | Mapper<MyHashWithKeyspace> hashMapper = new MappingManager(session2).mapper(MyHashWithKeyspace.class); |
| 58 | 56 | hashMapper.save(new MyHashWithKeyspace( |
| 59 | - 1, | |
| 60 | - ImmutableMap.of("key-1", new MyTupleWithKeyspace("first-half-1", "second-half-1")))); | |
| 57 | + 1, | |
| 58 | + ImmutableMap.of("key-1", new MyTupleWithKeyspace("first-half-1", "second-half-1")))); | |
| 61 | 59 | hashMapper.save(new MyHashWithKeyspace( |
| 62 | - 2, | |
| 63 | - ImmutableMap.of("key-2", new MyTupleWithKeyspace("first-half-2", null)))); | |
| 60 | + 2, | |
| 61 | + ImmutableMap.of("key-2", new MyTupleWithKeyspace("first-half-2", null)))); | |
| 64 | 62 | hashMapper.save(new MyHashWithKeyspace( |
| 65 | - 3, | |
| 66 | - ImmutableMap.of("key-3", new MyTupleWithKeyspace(null, "second-half-3")))); | |
| 63 | + 3, | |
| 64 | + ImmutableMap.of("key-3", new MyTupleWithKeyspace(null, "second-half-3")))); | |
| 67 | 65 | hashMapper.save(new MyHashWithKeyspace( |
| 68 | - 4, | |
| 69 | - new HashMap<String, MyTupleWithKeyspace>())); | |
| 66 | + 4, | |
| 67 | + new HashMap<String, MyTupleWithKeyspace>())); | |
| 70 | 68 | hashMapper.save(new MyHashWithKeyspace( |
| 71 | - 5, | |
| 72 | - null)); | |
| 69 | + 5, | |
| 70 | + null)); | |
| 73 | 71 | } finally { |
| 74 | 72 | if (cluster != null) |
| 75 | 73 | cluster.close(); |
| @@ -89,14 +87,14 @@ | ||
| 89 | 87 | cluster = Cluster.builder().addContactPoint(CCMBridge.ipOfNode(1)).build(); |
| 90 | 88 | Session session1 = cluster.connect(); |
| 91 | 89 | session1.execute("create schema if not exists java_509 " + |
| 92 | - "with replication = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };"); | |
| 90 | + "with replication = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };"); | |
| 93 | 91 | session1.execute("use java_509"); |
| 94 | 92 | session1.execute("create type my_tuple (" + |
| 95 | - "type text, " + | |
| 96 | - "value text);"); | |
| 93 | + "type text, " + | |
| 94 | + "value text);"); | |
| 97 | 95 | session1.execute("create table my_hash (" + |
| 98 | - "key int primary key, " + | |
| 99 | - "properties map<text, frozen<my_tuple>>);"); | |
| 96 | + "key int primary key, " + | |
| 97 | + "properties map<text, frozen<my_tuple>>);"); | |
| 100 | 98 | cluster.close(); |
| 101 | 99 | |
| 102 | 100 | // Create entities with another connection |
| @@ -106,20 +104,20 @@ | ||
| 106 | 104 | session2.execute("use java_509"); |
| 107 | 105 | Mapper<MyHash> hashMapper = new MappingManager(session2).mapper(MyHash.class); |
| 108 | 106 | hashMapper.save(new MyHash( |
| 109 | - 1, | |
| 110 | - ImmutableMap.of("key-1", new MyTuple("first-half-1", "second-half-1")))); | |
| 107 | + 1, | |
| 108 | + ImmutableMap.of("key-1", new MyTuple("first-half-1", "second-half-1")))); | |
| 111 | 109 | hashMapper.save(new MyHash( |
| 112 | - 2, | |
| 113 | - ImmutableMap.of("key-2", new MyTuple("first-half-2", null)))); | |
| 110 | + 2, | |
| 111 | + ImmutableMap.of("key-2", new MyTuple("first-half-2", null)))); | |
| 114 | 112 | hashMapper.save(new MyHash( |
| 115 | - 3, | |
| 116 | - ImmutableMap.of("key-3", new MyTuple(null, "second-half-3")))); | |
| 113 | + 3, | |
| 114 | + ImmutableMap.of("key-3", new MyTuple(null, "second-half-3")))); | |
| 117 | 115 | hashMapper.save(new MyHash( |
| 118 | - 4, | |
| 119 | - new HashMap<String, MyTuple>())); | |
| 116 | + 4, | |
| 117 | + new HashMap<String, MyTuple>())); | |
| 120 | 118 | hashMapper.save(new MyHash( |
| 121 | - 5, | |
| 122 | - null)); | |
| 119 | + 5, | |
| 120 | + null)); | |
| 123 | 121 | } finally { |
| 124 | 122 | if (cluster != null) |
| 125 | 123 | cluster.close(); |