kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 6697eb958eb956e05d2bcb33188880f388991f4cdd6fe7ee460f9355bd9554b4 |
|---|---|
| Author | olim7t <omichallat+github@gmail.com> · 2015-12-09 17:38 +01:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2015-12-09 17:38 +01:00 |
| Parents | 6ad0d047bddb |
283 files changed
modified driver-core/src/main/java/com/datastax/driver/core/AbstractGettableData.java +11 −13
| @@ -15,16 +15,14 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.exceptions.InvalidTypeException; | |
| 19 | + | |
| 18 | 20 | import java.math.BigDecimal; |
| 19 | 21 | import java.math.BigInteger; |
| 20 | 22 | import java.net.InetAddress; |
| 21 | 23 | import java.nio.ByteBuffer; |
| 22 | 24 | import java.util.*; |
| 23 | 25 | |
| 24 | -import com.google.common.collect.Lists; | |
| 25 | - | |
| 26 | -import com.datastax.driver.core.exceptions.InvalidTypeException; | |
| 27 | - | |
| 28 | 26 | abstract class AbstractGettableData implements GettableData { |
| 29 | 27 | |
| 30 | 28 | protected final ColumnDefinitions metadata; |
| @@ -153,16 +151,16 @@ | ||
| 153 | 151 | |
| 154 | 152 | public String getString(int i) { |
| 155 | 153 | DataType.Name type = metadata.checkType(i, DataType.Name.VARCHAR, |
| 156 | - DataType.Name.TEXT, | |
| 157 | - DataType.Name.ASCII); | |
| 154 | + DataType.Name.TEXT, | |
| 155 | + DataType.Name.ASCII); | |
| 158 | 156 | |
| 159 | 157 | ByteBuffer value = getValue(i); |
| 160 | 158 | if (value == null) |
| 161 | 159 | return null; |
| 162 | 160 | |
| 163 | 161 | return type == DataType.Name.ASCII |
| 164 | - ? TypeCodec.StringCodec.asciiInstance.deserialize(value) | |
| 165 | - : TypeCodec.StringCodec.utf8Instance.deserialize(value); | |
| 162 | + ? TypeCodec.StringCodec.asciiInstance.deserialize(value) | |
| 163 | + : TypeCodec.StringCodec.utf8Instance.deserialize(value); | |
| 166 | 164 | } |
| 167 | 165 | |
| 168 | 166 | public String getString(String name) { |
| @@ -205,8 +203,8 @@ | ||
| 205 | 203 | return null; |
| 206 | 204 | |
| 207 | 205 | return type == DataType.Name.UUID |
| 208 | - ? TypeCodec.UUIDCodec.instance.deserialize(value) | |
| 209 | - : TypeCodec.TimeUUIDCodec.instance.deserialize(value); | |
| 206 | + ? TypeCodec.UUIDCodec.instance.deserialize(value) | |
| 207 | + : TypeCodec.TimeUUIDCodec.instance.deserialize(value); | |
| 210 | 208 | } |
| 211 | 209 | |
| 212 | 210 | public UUID getUUID(String name) { |
| @@ -241,7 +239,7 @@ | ||
| 241 | 239 | if (value == null) |
| 242 | 240 | return Collections.<T>emptyList(); |
| 243 | 241 | |
| 244 | - return Collections.unmodifiableList((List<T>)type.codec().deserialize(value)); | |
| 242 | + return Collections.unmodifiableList((List<T>) type.codec().deserialize(value)); | |
| 245 | 243 | } |
| 246 | 244 | |
| 247 | 245 | public <T> List<T> getList(String name, Class<T> elementsClass) { |
| @@ -262,7 +260,7 @@ | ||
| 262 | 260 | if (value == null) |
| 263 | 261 | return Collections.<T>emptySet(); |
| 264 | 262 | |
| 265 | - return Collections.unmodifiableSet((Set<T>)type.codec().deserialize(value)); | |
| 263 | + return Collections.unmodifiableSet((Set<T>) type.codec().deserialize(value)); | |
| 266 | 264 | } |
| 267 | 265 | |
| 268 | 266 | public <T> Set<T> getSet(String name, Class<T> elementsClass) { |
| @@ -284,7 +282,7 @@ | ||
| 284 | 282 | if (value == null) |
| 285 | 283 | return Collections.<K, V>emptyMap(); |
| 286 | 284 | |
| 287 | - return Collections.unmodifiableMap((Map<K, V>)type.codec().deserialize(value)); | |
| 285 | + return Collections.unmodifiableMap((Map<K, V>) type.codec().deserialize(value)); | |
| 288 | 286 | } |
| 289 | 287 | |
| 290 | 288 | public <K, V> Map<K, V> getMap(String name, Class<K> keysClass, Class<V> valuesClass) { |
modified driver-core/src/main/java/com/datastax/driver/core/AbstractReconnectionHandler.java +25 −13
| @@ -15,25 +15,24 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.util.concurrent.*; | |
| 19 | -import java.util.concurrent.atomic.AtomicReference; | |
| 20 | - | |
| 18 | +import com.datastax.driver.core.exceptions.AuthenticationException; | |
| 19 | +import com.datastax.driver.core.policies.ReconnectionPolicy; | |
| 21 | 20 | import com.google.common.annotations.VisibleForTesting; |
| 22 | -import com.google.common.util.concurrent.ListenableFuture; | |
| 23 | 21 | import com.google.common.util.concurrent.AbstractFuture; |
| 22 | +import com.google.common.util.concurrent.ListenableFuture; | |
| 24 | 23 | import org.slf4j.Logger; |
| 25 | 24 | import org.slf4j.LoggerFactory; |
| 26 | 25 | |
| 27 | -import com.datastax.driver.core.exceptions.AuthenticationException; | |
| 28 | -import com.datastax.driver.core.policies.ReconnectionPolicy; | |
| 26 | +import java.util.concurrent.*; | |
| 27 | +import java.util.concurrent.atomic.AtomicReference; | |
| 29 | 28 | |
| 30 | 29 | /** |
| 31 | 30 | * Manages periodic reconnection attempts after a host has been marked down. |
| 32 | - * <p> | |
| 31 | + * <p/> | |
| 33 | 32 | * Concurrent attempts are handled via the {@link #currentAttempt} reference passed to the constructor. |
| 34 | 33 | * For a given reference, only one handler will run at a given time. Additional handlers will cancel |
| 35 | 34 | * themselves if they find a previous handler running. |
| 36 | - * <p> | |
| 35 | + * <p/> | |
| 37 | 36 | * This class is designed for concurrency, but instances must not be shared: each thread creates and |
| 38 | 37 | * starts its own private handler, all interactions happen through {@link #currentAttempt}. |
| 39 | 38 | */ |
| @@ -68,18 +67,31 @@ | ||
| 68 | 67 | } |
| 69 | 68 | |
| 70 | 69 | protected abstract Connection tryReconnect() throws ConnectionException, InterruptedException, UnsupportedProtocolVersionException, ClusterNameMismatchException; |
| 70 | + | |
| 71 | 71 | protected abstract void onReconnection(Connection connection); |
| 72 | 72 | |
| 73 | - protected boolean onConnectionException(ConnectionException e, long nextDelayMs) { return true; } | |
| 74 | - protected boolean onUnknownException(Exception e, long nextDelayMs) { return true; } | |
| 73 | + protected boolean onConnectionException(ConnectionException e, long nextDelayMs) { | |
| 74 | + return true; | |
| 75 | + } | |
| 76 | + | |
| 77 | + protected boolean onUnknownException(Exception e, long nextDelayMs) { | |
| 78 | + return true; | |
| 79 | + } | |
| 75 | 80 | |
| 76 | 81 | // Retrying on authentication errors makes sense for applications that can update the credentials at runtime, we don't want to force them |
| 77 | 82 | // to restart. |
| 78 | - protected boolean onAuthenticationException(AuthenticationException e, long nextDelayMs) { return true; } | |
| 83 | + protected boolean onAuthenticationException(AuthenticationException e, long nextDelayMs) { | |
| 84 | + return true; | |
| 85 | + } | |
| 79 | 86 | |
| 80 | 87 | // Retrying on these errors is unlikely to work |
| 81 | - protected boolean onUnsupportedProtocolVersionException(UnsupportedProtocolVersionException e, long nextDelayMs) { return false; } | |
| 82 | - protected boolean onClusterNameMismatchException(ClusterNameMismatchException e, long nextDelayMs) { return false; } | |
| 88 | + protected boolean onUnsupportedProtocolVersionException(UnsupportedProtocolVersionException e, long nextDelayMs) { | |
| 89 | + return false; | |
| 90 | + } | |
| 91 | + | |
| 92 | + protected boolean onClusterNameMismatchException(ClusterNameMismatchException e, long nextDelayMs) { | |
| 93 | + return false; | |
| 94 | + } | |
| 83 | 95 | |
| 84 | 96 | public void start() { |
| 85 | 97 | long firstDelay = (initialDelayMs >= 0) ? initialDelayMs : schedule.nextDelayMs(); |
modified driver-core/src/main/java/com/datastax/driver/core/AbstractSession.java +6 −4
| @@ -15,15 +15,17 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | +import com.google.common.base.Function; | |
| 19 | +import com.google.common.util.concurrent.Futures; | |
| 20 | +import com.google.common.util.concurrent.ListenableFuture; | |
| 21 | +import com.google.common.util.concurrent.Uninterruptibles; | |
| 22 | + | |
| 18 | 23 | import java.nio.ByteBuffer; |
| 19 | 24 | import java.util.concurrent.ExecutionException; |
| 20 | 25 | |
| 21 | -import com.google.common.base.Function; | |
| 22 | -import com.google.common.util.concurrent.*; | |
| 23 | - | |
| 24 | 26 | /** |
| 25 | 27 | * Abstract implementation of the Session interface. |
| 26 | - * | |
| 28 | + * <p/> | |
| 27 | 29 | * This is primarly intended to make mocking easier. |
| 28 | 30 | */ |
| 29 | 31 | public abstract class AbstractSession implements Session, AsyncInitSession { |
modified driver-core/src/main/java/com/datastax/driver/core/ArrayBackedResultSet.java +15 −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 | -import java.util.concurrent.ConcurrentLinkedQueue; | |
| 21 | -import java.util.concurrent.ExecutionException; | |
| 22 | -import java.util.concurrent.LinkedBlockingDeque; | |
| 23 | - | |
| 18 | +import com.datastax.driver.core.exceptions.DriverInternalError; | |
| 19 | +import com.datastax.driver.core.utils.MoreFutures; | |
| 24 | 20 | import com.google.common.util.concurrent.ListenableFuture; |
| 25 | 21 | import com.google.common.util.concurrent.SettableFuture; |
| 26 | 22 | import com.google.common.util.concurrent.Uninterruptibles; |
| 27 | 23 | import org.slf4j.Logger; |
| 28 | 24 | import org.slf4j.LoggerFactory; |
| 29 | 25 | |
| 30 | -import com.datastax.driver.core.exceptions.DriverInternalError; | |
| 31 | -import com.datastax.driver.core.utils.MoreFutures; | |
| 26 | +import java.nio.ByteBuffer; | |
| 27 | +import java.util.*; | |
| 28 | +import java.util.concurrent.ConcurrentLinkedQueue; | |
| 29 | +import java.util.concurrent.ExecutionException; | |
| 30 | +import java.util.concurrent.LinkedBlockingDeque; | |
| 32 | 31 | |
| 33 | 32 | /** |
| 34 | 33 | * Default implementation of a result set, backed by an ArrayDeque of ArrayList. |
| @@ -56,26 +55,26 @@ | ||
| 56 | 55 | case VOID: |
| 57 | 56 | return empty(info); |
| 58 | 57 | case ROWS: |
| 59 | - Responses.Result.Rows r = (Responses.Result.Rows)msg; | |
| 58 | + Responses.Result.Rows r = (Responses.Result.Rows) msg; | |
| 60 | 59 | |
| 61 | 60 | ColumnDefinitions columnDefs; |
| 62 | 61 | if (r.metadata.columns == null) { |
| 63 | 62 | assert statement instanceof BoundStatement; |
| 64 | - columnDefs = ((BoundStatement)statement).statement.getPreparedId().resultSetMetadata; | |
| 63 | + columnDefs = ((BoundStatement) statement).statement.getPreparedId().resultSetMetadata; | |
| 65 | 64 | assert columnDefs != null; |
| 66 | 65 | } else { |
| 67 | 66 | columnDefs = r.metadata.columns; |
| 68 | 67 | } |
| 69 | 68 | |
| 70 | 69 | Token.Factory tokenFactory = (session == null) ? null |
| 71 | - : session.getCluster().manager.metadata.tokenFactory(); | |
| 70 | + : session.getCluster().manager.metadata.tokenFactory(); | |
| 72 | 71 | |
| 73 | 72 | // info can be null only for internal calls, but we don't page those. We assert |
| 74 | 73 | // this explicitly because MultiPage implementation don't support info == null. |
| 75 | 74 | assert r.metadata.pagingState == null || info != null; |
| 76 | 75 | return r.metadata.pagingState == null |
| 77 | - ? new SinglePage(columnDefs, tokenFactory, r.data, info) | |
| 78 | - : new MultiPage(columnDefs, tokenFactory, r.data, info, r.metadata.pagingState, session, statement); | |
| 76 | + ? new SinglePage(columnDefs, tokenFactory, r.data, info) | |
| 77 | + : new MultiPage(columnDefs, tokenFactory, r.data, info, r.metadata.pagingState, session, statement); | |
| 79 | 78 | |
| 80 | 79 | case SET_KEYSPACE: |
| 81 | 80 | case SCHEMA_CHANGE: |
| @@ -320,10 +319,10 @@ | ||
| 320 | 319 | try { |
| 321 | 320 | switch (response.type) { |
| 322 | 321 | case RESULT: |
| 323 | - Responses.Result rm = (Responses.Result)response; | |
| 322 | + Responses.Result rm = (Responses.Result) response; | |
| 324 | 323 | info = update(info, rm, MultiPage.this.session); |
| 325 | 324 | if (rm.kind == Responses.Result.Kind.ROWS) { |
| 326 | - Responses.Result.Rows rows = (Responses.Result.Rows)rm; | |
| 325 | + Responses.Result.Rows rows = (Responses.Result.Rows) rm; | |
| 327 | 326 | if (rows.metadata.pagingState != null) |
| 328 | 327 | info = info.withPagingState(rows.metadata.pagingState).withStatement(statement); |
| 329 | 328 | MultiPage.this.nextPages.offer(rows.data); |
| @@ -343,7 +342,7 @@ | ||
| 343 | 342 | future.set(null); |
| 344 | 343 | break; |
| 345 | 344 | case ERROR: |
| 346 | - future.setException(((Responses.Error)response).asException(connection.address)); | |
| 345 | + future.setException(((Responses.Error) response).asException(connection.address)); | |
| 347 | 346 | break; |
| 348 | 347 | default: |
| 349 | 348 | // This mean we have probably have a bad node, so defunct the connection |
modified driver-core/src/main/java/com/datastax/driver/core/ArrayBackedRow.java +2 −2
| @@ -15,11 +15,11 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.exceptions.DriverInternalError; | |
| 19 | + | |
| 18 | 20 | import java.nio.ByteBuffer; |
| 19 | 21 | import java.util.List; |
| 20 | 22 | |
| 21 | -import com.datastax.driver.core.exceptions.DriverInternalError; | |
| 22 | - | |
| 23 | 23 | /** |
| 24 | 24 | * Implementation of a Row backed by an ArrayList. |
| 25 | 25 | */ |
modified driver-core/src/main/java/com/datastax/driver/core/AsyncInitSession.java +2 −2
| @@ -19,10 +19,10 @@ | ||
| 19 | 19 | |
| 20 | 20 | /** |
| 21 | 21 | * A {@link Session} that can be initialized asynchronously. |
| 22 | - * | |
| 22 | + * <p/> | |
| 23 | 23 | * This interface exists only for backward compatibility reasons: {@link #initAsync()} should really be |
| 24 | 24 | * defined by {@link Session}, but adding it after the fact would break binary compatibility. |
| 25 | - * | |
| 25 | + * <p/> | |
| 26 | 26 | * By default, all sessions returned by the driver implement this interface. The only way you would get |
| 27 | 27 | * sessions that don't is if you use a custom {@link Cluster} subclass. |
| 28 | 28 | */ |
modified driver-core/src/main/java/com/datastax/driver/core/AuthProvider.java +5 −5
| @@ -15,14 +15,14 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.net.InetSocketAddress; | |
| 19 | - | |
| 20 | 18 | import com.datastax.driver.core.exceptions.AuthenticationException; |
| 21 | 19 | |
| 20 | +import java.net.InetSocketAddress; | |
| 21 | + | |
| 22 | 22 | /** |
| 23 | 23 | * Provides {@link Authenticator} instances for use when connecting |
| 24 | 24 | * to Cassandra nodes. |
| 25 | - * | |
| 25 | + * <p/> | |
| 26 | 26 | * See {@link PlainTextAuthProvider} for an implementation which uses SASL |
| 27 | 27 | * PLAIN mechanism to authenticate using username/password strings |
| 28 | 28 | */ |
| @@ -30,13 +30,13 @@ | ||
| 30 | 30 | |
| 31 | 31 | /** |
| 32 | 32 | * A provider that provides no authentication capability. |
| 33 | - * <p> | |
| 33 | + * <p/> | |
| 34 | 34 | * This is only useful as a placeholder when no authentication is to be used. |
| 35 | 35 | */ |
| 36 | 36 | public static final AuthProvider NONE = new AuthProvider() { |
| 37 | 37 | public Authenticator newAuthenticator(InetSocketAddress host) { |
| 38 | 38 | throw new AuthenticationException(host, |
| 39 | - String.format("Host %s requires authentication, but no authenticator found in Cluster configuration", host)); | |
| 39 | + String.format("Host %s requires authentication, but no authenticator found in Cluster configuration", host)); | |
| 40 | 40 | } |
| 41 | 41 | }; |
| 42 | 42 |
modified driver-core/src/main/java/com/datastax/driver/core/Authenticator.java +17 −17
| @@ -17,26 +17,26 @@ | ||
| 17 | 17 | |
| 18 | 18 | /** |
| 19 | 19 | * Handles SASL authentication with Cassandra servers. |
| 20 | - * <p> | |
| 20 | + * <p/> | |
| 21 | 21 | * Each time a new connection is created and the server requires authentication, |
| 22 | 22 | * a new instance of this class will be created by the corresponding |
| 23 | 23 | * {@link AuthProvider} to handle that authentication. The lifecycle of that |
| 24 | 24 | * new {@code Authenticator} will be: |
| 25 | 25 | * <ol> |
| 26 | - * <li>The {@code initialResponse} method will be called. The initial return | |
| 27 | - * value will be sent to the server to initiate the handshake.</li> | |
| 28 | - * <li>The server will respond to each client response by either issuing a | |
| 29 | - * challenge or indicating that the authentication is complete (successfully or not). | |
| 30 | - * If a new challenge is issued, the authenticator {@code evaluateChallenge} | |
| 31 | - * method will be called to produce a response that will be sent to the | |
| 32 | - * server. This challenge/response negotiation will continue until the server | |
| 33 | - * responds that authentication is successful (or an {@code AuthenticationException} | |
| 34 | - * is raised). | |
| 35 | - * </li> | |
| 36 | - * <li>When the server indicates that authentication is successful, the | |
| 37 | - * {@code onAuthenticationSuccess} method will be called with the last information | |
| 38 | - * that the server may optionally have sent. | |
| 39 | - * </li> | |
| 26 | + * <li>The {@code initialResponse} method will be called. The initial return | |
| 27 | + * value will be sent to the server to initiate the handshake.</li> | |
| 28 | + * <li>The server will respond to each client response by either issuing a | |
| 29 | + * challenge or indicating that the authentication is complete (successfully or not). | |
| 30 | + * If a new challenge is issued, the authenticator {@code evaluateChallenge} | |
| 31 | + * method will be called to produce a response that will be sent to the | |
| 32 | + * server. This challenge/response negotiation will continue until the server | |
| 33 | + * responds that authentication is successful (or an {@code AuthenticationException} | |
| 34 | + * is raised). | |
| 35 | + * </li> | |
| 36 | + * <li>When the server indicates that authentication is successful, the | |
| 37 | + * {@code onAuthenticationSuccess} method will be called with the last information | |
| 38 | + * that the server may optionally have sent. | |
| 39 | + * </li> | |
| 40 | 40 | * </ol> |
| 41 | 41 | * The exact nature of the negotiation between client and server is specific |
| 42 | 42 | * to the authentication mechanism configured server side. |
| @@ -66,8 +66,8 @@ | ||
| 66 | 66 | * optionally sent by the server. |
| 67 | 67 | * |
| 68 | 68 | * @param token the information sent by the server with the authentication |
| 69 | - * successful message. This will be {@code null} if the server sends no | |
| 70 | - * particular information on authentication success. | |
| 69 | + * successful message. This will be {@code null} if the server sends no | |
| 70 | + * particular information on authentication success. | |
| 71 | 71 | */ |
| 72 | 72 | public void onAuthenticationSuccess(byte[] token); |
| 73 | 73 | } |
modified driver-core/src/main/java/com/datastax/driver/core/BatchStatement.java +16 −20
| @@ -15,19 +15,15 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.nio.ByteBuffer; | |
| 19 | -import java.util.ArrayList; | |
| 20 | -import java.util.Arrays; | |
| 21 | -import java.util.Collection; | |
| 22 | -import java.util.Collections; | |
| 23 | -import java.util.List; | |
| 24 | - | |
| 25 | 18 | import com.google.common.collect.ImmutableList; |
| 26 | 19 | |
| 20 | +import java.nio.ByteBuffer; | |
| 21 | +import java.util.*; | |
| 22 | + | |
| 27 | 23 | /** |
| 28 | 24 | * A statement that group a number of {@link Statement} so they get executed as |
| 29 | 25 | * a batch. |
| 30 | - * <p> | |
| 26 | + * <p/> | |
| 31 | 27 | * Note: BatchStatement is not supported with the native protocol version 1: you |
| 32 | 28 | * will get an {@link UnsupportedProtocolVersionException} when submitting one if |
| 33 | 29 | * version 1 of the protocol is in use (i.e. if you've force version 1 through |
| @@ -59,7 +55,9 @@ | ||
| 59 | 55 | * operations and it can only contain these. |
| 60 | 56 | */ |
| 61 | 57 | COUNTER |
| 62 | - }; | |
| 58 | + } | |
| 59 | + | |
| 60 | + ; | |
| 63 | 61 | |
| 64 | 62 | final Type batchType; |
| 65 | 63 | private final List<Statement> statements = new ArrayList<Statement>(); |
| @@ -84,14 +82,14 @@ | ||
| 84 | 82 | IdAndValues idAndVals = new IdAndValues(statements.size()); |
| 85 | 83 | for (Statement statement : statements) { |
| 86 | 84 | if (statement instanceof RegularStatement) { |
| 87 | - RegularStatement st = (RegularStatement)statement; | |
| 85 | + RegularStatement st = (RegularStatement) statement; | |
| 88 | 86 | ByteBuffer[] vals = st.getValues(); |
| 89 | 87 | idAndVals.ids.add(st.getQueryString()); |
| 90 | 88 | idAndVals.values.add(vals == null ? Collections.<ByteBuffer>emptyList() : Arrays.asList(vals)); |
| 91 | 89 | } else { |
| 92 | 90 | // We handle BatchStatement in add() so ... |
| 93 | 91 | assert statement instanceof BoundStatement; |
| 94 | - BoundStatement st = (BoundStatement)statement; | |
| 92 | + BoundStatement st = (BoundStatement) statement; | |
| 95 | 93 | idAndVals.ids.add(st.statement.getPreparedId().id); |
| 96 | 94 | idAndVals.values.add(Arrays.asList(st.values)); |
| 97 | 95 | } |
| @@ -101,13 +99,13 @@ | ||
| 101 | 99 | |
| 102 | 100 | /** |
| 103 | 101 | * Adds a new statement to this batch. |
| 104 | - * <p> | |
| 102 | + * <p/> | |
| 105 | 103 | * Note that {@code statement} can be any {@code Statement}. It is allowed to mix |
| 106 | 104 | * {@code RegularStatement} and {@code BoundStatement} in the same |
| 107 | 105 | * {@code BatchStatement} in particular. Adding another {@code BatchStatement} |
| 108 | 106 | * is also allowed for convenient and is equivalent to adding all the {@code Statement} |
| 109 | 107 | * contained in that other {@code BatchStatement}. |
| 110 | - * <p> | |
| 108 | + * <p/> | |
| 111 | 109 | * Please note that the options of the added Statement (all those defined directly by the |
| 112 | 110 | * {@link Statement} class: consistency level, fetch size, tracing, ...) will be ignored |
| 113 | 111 | * for the purpose of the execution of the Batch. Instead, the options used are the one |
| @@ -115,10 +113,9 @@ | ||
| 115 | 113 | * |
| 116 | 114 | * @param statement the new statement to add. |
| 117 | 115 | * @return this batch statement. |
| 118 | - * | |
| 119 | 116 | * @throws IllegalStateException if adding the new statement means that this |
| 120 | - * {@code BatchStatement} has more than 65536 statements (since this is the maximum number | |
| 121 | - * of statements for a BatchStatement allowed by the underlying protocol). | |
| 117 | + * {@code BatchStatement} has more than 65536 statements (since this is the maximum number | |
| 118 | + * of statements for a BatchStatement allowed by the underlying protocol). | |
| 122 | 119 | */ |
| 123 | 120 | public BatchStatement add(Statement statement) { |
| 124 | 121 | |
| @@ -126,7 +123,7 @@ | ||
| 126 | 123 | // easier to avoid endless loop if the use mistakenly pass a batch that depends on this |
| 127 | 124 | // object (or this directly). |
| 128 | 125 | if (statement instanceof BatchStatement) { |
| 129 | - for (Statement subStatements : ((BatchStatement)statement).statements) { | |
| 126 | + for (Statement subStatements : ((BatchStatement) statement).statements) { | |
| 130 | 127 | add(subStatements); |
| 131 | 128 | } |
| 132 | 129 | } else { |
| @@ -139,7 +136,7 @@ | ||
| 139 | 136 | |
| 140 | 137 | /** |
| 141 | 138 | * Adds multiple statements to this batch. |
| 142 | - * <p> | |
| 139 | + * <p/> | |
| 143 | 140 | * This is a shortcut method that calls {@link #add} on all the statements |
| 144 | 141 | * from {@code statements}. |
| 145 | 142 | * |
| @@ -184,7 +181,7 @@ | ||
| 184 | 181 | /** |
| 185 | 182 | * Throws an {@code UnsupportedOperationException} as setting the serial consistency is |
| 186 | 183 | * currently not supported for protocol batches by Cassandra. |
| 187 | - * <p> | |
| 184 | + * <p/> | |
| 188 | 185 | * The current version of the protocol uses does not allow to provide a serial consistency level |
| 189 | 186 | * for protocol batches (the batch created through this class). This is fixed by the protocol |
| 190 | 187 | * version 3 that will be part of Cassandra 2.1 and will be supported by the driver version 2.1. |
| @@ -193,7 +190,6 @@ | ||
| 193 | 190 | * |
| 194 | 191 | * @param serialConsistency the serial consistency level |
| 195 | 192 | * @return nothing since this call currently always throws an {@code UnsupportedOperationException}. |
| 196 | - * | |
| 197 | 193 | * @throws UnsupportedOperationException see above. |
| 198 | 194 | */ |
| 199 | 195 | @Override |
modified driver-core/src/main/java/com/datastax/driver/core/BoundStatement.java +183 −224
| @@ -15,31 +15,29 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.exceptions.InvalidTypeException; | |
| 19 | + | |
| 18 | 20 | import java.math.BigDecimal; |
| 19 | 21 | import java.math.BigInteger; |
| 20 | 22 | import java.net.InetAddress; |
| 21 | 23 | import java.nio.ByteBuffer; |
| 22 | 24 | import java.util.*; |
| 23 | 25 | |
| 24 | -import com.google.common.collect.Lists; | |
| 25 | - | |
| 26 | -import com.datastax.driver.core.exceptions.InvalidTypeException; | |
| 27 | - | |
| 28 | 26 | /** |
| 29 | 27 | * A prepared statement with values bound to the bind variables. |
| 30 | - * <p> | |
| 28 | + * <p/> | |
| 31 | 29 | * Once values has been provided for the variables of the {@link PreparedStatement} |
| 32 | 30 | * it has been created from, such BoundStatement can be executed (through |
| 33 | 31 | * {@link Session#execute(Statement)}). |
| 34 | - * <p> | |
| 32 | + * <p/> | |
| 35 | 33 | * The values of a BoundStatement can be set by either index or name. When |
| 36 | 34 | * setting them by name, names follow the case insensitivity rules explained in |
| 37 | 35 | * {@link ColumnDefinitions} but with the difference that if multiple bind |
| 38 | 36 | * variables have the same name, setting that name will set <b>all</b> the |
| 39 | 37 | * variables for that name. |
| 40 | - * <p> | |
| 38 | + * <p/> | |
| 41 | 39 | * Any variable that hasn't been specifically set will be considered {@code null}. |
| 42 | - * <p> | |
| 40 | + * <p/> | |
| 43 | 41 | * Bound values may also be retrieved using {@code get*()} methods. Note that this |
| 44 | 42 | * may have a non-negligible impact on performance: internally, values are stored |
| 45 | 43 | * in serialized form, so they need to be deserialized again. These methods are |
| @@ -56,6 +54,7 @@ | ||
| 56 | 54 | /** |
| 57 | 55 | * Creates a new {@code BoundStatement} from the provided prepared |
| 58 | 56 | * statement. |
| 57 | + * | |
| 59 | 58 | * @param statement the prepared statement from which to create a {@code BoundStatement}. |
| 60 | 59 | */ |
| 61 | 60 | public BoundStatement(PreparedStatement statement) { |
| @@ -90,7 +89,6 @@ | ||
| 90 | 89 | * |
| 91 | 90 | * @param i the index of the variable to check. |
| 92 | 91 | * @return whether the {@code i}th variable has been bound to a non null value. |
| 93 | - * | |
| 94 | 92 | * @throws IndexOutOfBoundsException if {@code i < 0 || i >= this.preparedStatement().variables().size()}. |
| 95 | 93 | */ |
| 96 | 94 | public boolean isSet(int i) { |
| @@ -105,9 +103,8 @@ | ||
| 105 | 103 | * @param name the name of the variable to check. |
| 106 | 104 | * @return whether the first occurrence of variable {@code name} has been |
| 107 | 105 | * bound to a non-null value. |
| 108 | - * | |
| 109 | 106 | * @throws IllegalArgumentException if {@code name} is not a prepared |
| 110 | - * variable, that is if {@code !this.preparedStatement().variables().names().contains(name)}. | |
| 107 | + * variable, that is if {@code !this.preparedStatement().variables().names().contains(name)}. | |
| 111 | 108 | */ |
| 112 | 109 | public boolean isSet(String name) { |
| 113 | 110 | return isSet(metadata().getFirstIdx(name)); |
| @@ -115,33 +112,31 @@ | ||
| 115 | 112 | |
| 116 | 113 | /** |
| 117 | 114 | * Bound values to the variables of this statement. |
| 118 | - * | |
| 115 | + * <p/> | |
| 119 | 116 | * This is a convenience method to bind all the variables of the |
| 120 | 117 | * {@code BoundStatement} in one call. |
| 121 | 118 | * |
| 122 | 119 | * @param values the values to bind to the variables of the newly created |
| 123 | - * BoundStatement. The first element of {@code values} will be bound to the | |
| 124 | - * first bind variable, etc. It is legal to provide fewer values than the | |
| 125 | - * statement has bound variables. In that case, the remaining variable need | |
| 126 | - * to be bound before execution. If more values than variables are provided | |
| 127 | - * however, an IllegalArgumentException wil be raised. | |
| 120 | + * BoundStatement. The first element of {@code values} will be bound to the | |
| 121 | + * first bind variable, etc. It is legal to provide fewer values than the | |
| 122 | + * statement has bound variables. In that case, the remaining variable need | |
| 123 | + * to be bound before execution. If more values than variables are provided | |
| 124 | + * however, an IllegalArgumentException wil be raised. | |
| 128 | 125 | * @return this bound statement. |
| 129 | - * | |
| 130 | 126 | * @throws IllegalArgumentException if more {@code values} are provided |
| 131 | - * than there is of bound variables in this statement. | |
| 132 | - * @throws InvalidTypeException if any of the provided value is not of | |
| 133 | - * correct type to be bound to the corresponding bind variable. | |
| 134 | - * @throws NullPointerException if one of {@code values} is a collection | |
| 135 | - * (List, Set or Map) containing a null value. Nulls are not supported in | |
| 136 | - * collections by CQL. | |
| 127 | + * than there is of bound variables in this statement. | |
| 128 | + * @throws InvalidTypeException if any of the provided value is not of | |
| 129 | + * correct type to be bound to the corresponding bind variable. | |
| 130 | + * @throws NullPointerException if one of {@code values} is a collection | |
| 131 | + * (List, Set or Map) containing a null value. Nulls are not supported in | |
| 132 | + * collections by CQL. | |
| 137 | 133 | */ |
| 138 | 134 | public BoundStatement bind(Object... values) { |
| 139 | 135 | |
| 140 | 136 | if (values.length > statement.getVariables().size()) |
| 141 | 137 | throw new IllegalArgumentException(String.format("Prepared statement has only %d variables, %d values provided", statement.getVariables().size(), values.length)); |
| 142 | 138 | |
| 143 | - for (int i = 0; i < values.length; i++) | |
| 144 | - { | |
| 139 | + for (int i = 0; i < values.length; i++) { | |
| 145 | 140 | Object toSet = values[i]; |
| 146 | 141 | |
| 147 | 142 | if (toSet == null) { |
| @@ -155,7 +150,7 @@ | ||
| 155 | 150 | if (!(toSet instanceof List)) |
| 156 | 151 | throw new InvalidTypeException(String.format("Invalid type for value %d, column is a list but %s provided", i, toSet.getClass())); |
| 157 | 152 | |
| 158 | - List<?> l = (List<?>)toSet; | |
| 153 | + List<?> l = (List<?>) toSet; | |
| 159 | 154 | // If the list is empty, it will never fail validation, but otherwise we should check the list given if of the right type |
| 160 | 155 | if (!l.isEmpty()) { |
| 161 | 156 | // Ugly? Yes |
| @@ -169,7 +164,7 @@ | ||
| 169 | 164 | if (!(toSet instanceof Set)) |
| 170 | 165 | throw new InvalidTypeException(String.format("Invalid type for value %d, column is a set but %s provided", i, toSet.getClass())); |
| 171 | 166 | |
| 172 | - Set<?> s = (Set<?>)toSet; | |
| 167 | + Set<?> s = (Set<?>) toSet; | |
| 173 | 168 | // If the list is empty, it will never fail validation, but otherwise we should check the list given if of the right type |
| 174 | 169 | if (!s.isEmpty()) { |
| 175 | 170 | // Ugly? Yes |
| @@ -183,7 +178,7 @@ | ||
| 183 | 178 | if (!(toSet instanceof Map)) |
| 184 | 179 | throw new InvalidTypeException(String.format("Invalid type for value %d, column is a map but %s provided", i, toSet.getClass())); |
| 185 | 180 | |
| 186 | - Map<?, ?> m = (Map<?, ?>)toSet; | |
| 181 | + Map<?, ?> m = (Map<?, ?>) toSet; | |
| 187 | 182 | // If the list is empty, it will never fail validation, but otherwise we should check the list given if of the right type |
| 188 | 183 | if (!m.isEmpty()) { |
| 189 | 184 | // Ugly? Yes |
| @@ -199,7 +194,7 @@ | ||
| 199 | 194 | break; |
| 200 | 195 | default: |
| 201 | 196 | if (toSet instanceof Token) |
| 202 | - toSet = ((Token)toSet).getValue(); | |
| 197 | + toSet = ((Token) toSet).getValue(); | |
| 203 | 198 | |
| 204 | 199 | Class<?> providedClass = toSet.getClass(); |
| 205 | 200 | Class<?> expectedClass = columnType.getName().javaType; |
| @@ -214,14 +209,13 @@ | ||
| 214 | 209 | |
| 215 | 210 | /** |
| 216 | 211 | * Sets the routing key for this bound statement. |
| 217 | - * <p> | |
| 212 | + * <p/> | |
| 218 | 213 | * This is useful when the routing key can neither be set on the {@code PreparedStatement} this bound statement |
| 219 | 214 | * was built from, nor automatically computed from bound variables. In particular, this is the case if the |
| 220 | 215 | * partition key is composite and only some of its components are bound. |
| 221 | 216 | * |
| 222 | 217 | * @param routingKey the raw (binary) value to use as routing key. |
| 223 | 218 | * @return this {@code BoundStatement} object. |
| 224 | - * | |
| 225 | 219 | * @see BoundStatement#getRoutingKey |
| 226 | 220 | */ |
| 227 | 221 | public BoundStatement setRoutingKey(ByteBuffer routingKey) { |
| @@ -231,7 +225,7 @@ | ||
| 231 | 225 | |
| 232 | 226 | /** |
| 233 | 227 | * The routing key for this bound query. |
| 234 | - * <p> | |
| 228 | + * <p/> | |
| 235 | 229 | * This method will return a non-{@code null} value if either of the following occur: |
| 236 | 230 | * <ul> |
| 237 | 231 | * <li>The routing key has been set directly through {@link BoundStatement#setRoutingKey}.</li> |
| @@ -241,8 +235,8 @@ | ||
| 241 | 235 | * key will then be built using the values provided for these partition key columns.</li> |
| 242 | 236 | * </ul> |
| 243 | 237 | * Otherwise, {@code null} is returned. |
| 244 | - * <p> | |
| 245 | - * | |
| 238 | + * <p/> | |
| 239 | + * <p/> | |
| 246 | 240 | * Note that if the routing key has been set through {@link BoundStatement#setRoutingKey}, then that takes |
| 247 | 241 | * precedence. If the routing key has been set through {@link PreparedStatement#setRoutingKey} then that is used |
| 248 | 242 | * next. If neither of those are set then it is computed. |
| @@ -279,7 +273,7 @@ | ||
| 279 | 273 | |
| 280 | 274 | /** |
| 281 | 275 | * Returns the keyspace this query operates on. |
| 282 | - * <p> | |
| 276 | + * <p/> | |
| 283 | 277 | * This method will always return a non-{@code null} value (unless the statement |
| 284 | 278 | * has no variables, but you should avoid prepared statement in the first in that |
| 285 | 279 | * case). The keyspace returned will be the one corresponding to the first |
| @@ -301,9 +295,8 @@ | ||
| 301 | 295 | * @param i the index of the variable to set. |
| 302 | 296 | * @param v the value to set. |
| 303 | 297 | * @return this BoundStatement. |
| 304 | - * | |
| 305 | 298 | * @throws IndexOutOfBoundsException if {@code i < 0 || i >= this.preparedStatement().variables().size()}. |
| 306 | - * @throws InvalidTypeException if column {@code i} is not of type BOOLEAN. | |
| 299 | + * @throws InvalidTypeException if column {@code i} is not of type BOOLEAN. | |
| 307 | 300 | */ |
| 308 | 301 | public BoundStatement setBool(int i, boolean v) { |
| 309 | 302 | metadata().checkType(i, DataType.Name.BOOLEAN); |
| @@ -315,13 +308,12 @@ | ||
| 315 | 308 | * provided boolean. |
| 316 | 309 | * |
| 317 | 310 | * @param name the name of the variable to set; if multiple variables |
| 318 | - * {@code name} are prepared, all of them are set. | |
| 319 | - * @param v the value to set. | |
| 311 | + * {@code name} are prepared, all of them are set. | |
| 312 | + * @param v the value to set. | |
| 320 | 313 | * @return this BoundStatement. |
| 321 | - * | |
| 322 | 314 | * @throws IllegalArgumentException if {@code name} is not a prepared |
| 323 | - * variable, that is, if {@code !this.preparedStatement().variables().names().contains(name)}. | |
| 324 | - * @throws InvalidTypeException if (any one occurrence of) {@code name} is not of type BOOLEAN. | |
| 315 | + * variable, that is, if {@code !this.preparedStatement().variables().names().contains(name)}. | |
| 316 | + * @throws InvalidTypeException if (any one occurrence of) {@code name} is not of type BOOLEAN. | |
| 325 | 317 | */ |
| 326 | 318 | public BoundStatement setBool(String name, boolean v) { |
| 327 | 319 | int[] indexes = metadata().getAllIdx(name); |
| @@ -339,9 +331,8 @@ | ||
| 339 | 331 | * @param i the index of the variable to set. |
| 340 | 332 | * @param v the value to set. |
| 341 | 333 | * @return this BoundStatement. |
| 342 | - * | |
| 343 | 334 | * @throws IndexOutOfBoundsException if {@code i < 0 || i >= this.preparedStatement().variables().size()}. |
| 344 | - * @throws InvalidTypeException if column {@code i} is not of type INT. | |
| 335 | + * @throws InvalidTypeException if column {@code i} is not of type INT. | |
| 345 | 336 | */ |
| 346 | 337 | public BoundStatement setInt(int i, int v) { |
| 347 | 338 | metadata().checkType(i, DataType.Name.INT); |
| @@ -353,13 +344,12 @@ | ||
| 353 | 344 | * provided integer. |
| 354 | 345 | * |
| 355 | 346 | * @param name the name of the variable to set; if multiple variables |
| 356 | - * {@code name} are prepared, all of them are set. | |
| 357 | - * @param v the value to set. | |
| 347 | + * {@code name} are prepared, all of them are set. | |
| 348 | + * @param v the value to set. | |
| 358 | 349 | * @return this BoundStatement. |
| 359 | - * | |
| 360 | 350 | * @throws IllegalArgumentException if {@code name} is not a prepared |
| 361 | - * variable, that is, if {@code !this.preparedStatement().variables().names().contains(name)}. | |
| 362 | - * @throws InvalidTypeException if (any one occurrence of) {@code name} is not of type INT. | |
| 351 | + * variable, that is, if {@code !this.preparedStatement().variables().names().contains(name)}. | |
| 352 | + * @throws InvalidTypeException if (any one occurrence of) {@code name} is not of type INT. | |
| 363 | 353 | */ |
| 364 | 354 | public BoundStatement setInt(String name, int v) { |
| 365 | 355 | int[] indexes = metadata().getAllIdx(name); |
| @@ -377,9 +367,8 @@ | ||
| 377 | 367 | * @param i the index of the variable to set. |
| 378 | 368 | * @param v the value to set. |
| 379 | 369 | * @return this BoundStatement. |
| 380 | - * | |
| 381 | 370 | * @throws IndexOutOfBoundsException if {@code i < 0 || i >= this.preparedStatement().variables().size()}. |
| 382 | - * @throws InvalidTypeException if column {@code i} is not of type BIGINT or COUNTER. | |
| 371 | + * @throws InvalidTypeException if column {@code i} is not of type BIGINT or COUNTER. | |
| 383 | 372 | */ |
| 384 | 373 | public BoundStatement setLong(int i, long v) { |
| 385 | 374 | metadata().checkType(i, DataType.Name.BIGINT, DataType.Name.COUNTER); |
| @@ -391,14 +380,13 @@ | ||
| 391 | 380 | * provided long. |
| 392 | 381 | * |
| 393 | 382 | * @param name the name of the variable to set; if multiple variables |
| 394 | - * {@code name} are prepared, all of them are set. | |
| 395 | - * @param v the value to set. | |
| 383 | + * {@code name} are prepared, all of them are set. | |
| 384 | + * @param v the value to set. | |
| 396 | 385 | * @return this BoundStatement. |
| 397 | - * | |
| 398 | 386 | * @throws IllegalArgumentException if {@code name} is not a prepared |
| 399 | - * variable, that is, if {@code !this.preparedStatement().variables().names().contains(name)}. | |
| 400 | - * @throws InvalidTypeException if (any occurrence of) {@code name} is | |
| 401 | - * not of type BIGINT or COUNTER. | |
| 387 | + * variable, that is, if {@code !this.preparedStatement().variables().names().contains(name)}. | |
| 388 | + * @throws InvalidTypeException if (any occurrence of) {@code name} is | |
| 389 | + * not of type BIGINT or COUNTER. | |
| 402 | 390 | */ |
| 403 | 391 | public BoundStatement setLong(String name, long v) { |
| 404 | 392 | int[] indexes = metadata().getAllIdx(name); |
| @@ -416,9 +404,8 @@ | ||
| 416 | 404 | * @param i the index of the variable to set. |
| 417 | 405 | * @param v the value to set. |
| 418 | 406 | * @return this BoundStatement. |
| 419 | - * | |
| 420 | 407 | * @throws IndexOutOfBoundsException if {@code i < 0 || i >= this.preparedStatement().variables().size()}. |
| 421 | - * @throws InvalidTypeException if column {@code i} is not of type TIMESTAMP. | |
| 408 | + * @throws InvalidTypeException if column {@code i} is not of type TIMESTAMP. | |
| 422 | 409 | */ |
| 423 | 410 | public BoundStatement setDate(int i, Date v) { |
| 424 | 411 | metadata().checkType(i, DataType.Name.TIMESTAMP); |
| @@ -430,14 +417,13 @@ | ||
| 430 | 417 | * provided date. |
| 431 | 418 | * |
| 432 | 419 | * @param name the name of the variable to set; if multiple variables |
| 433 | - * {@code name} are prepared, all of them are set. | |
| 434 | - * @param v the value to set. | |
| 420 | + * {@code name} are prepared, all of them are set. | |
| 421 | + * @param v the value to set. | |
| 435 | 422 | * @return this BoundStatement. |
| 436 | - * | |
| 437 | 423 | * @throws IllegalArgumentException if {@code name} is not a prepared |
| 438 | - * variable, that is, if {@code !this.preparedStatement().variables().names().contains(name)}. | |
| 439 | - * @throws InvalidTypeException if (any occurrence of) {@code name} is | |
| 440 | - * not of type TIMESTAMP. | |
| 424 | + * variable, that is, if {@code !this.preparedStatement().variables().names().contains(name)}. | |
| 425 | + * @throws InvalidTypeException if (any occurrence of) {@code name} is | |
| 426 | + * not of type TIMESTAMP. | |
| 441 | 427 | */ |
| 442 | 428 | public BoundStatement setDate(String name, Date v) { |
| 443 | 429 | int[] indexes = metadata().getAllIdx(name); |
| @@ -455,9 +441,8 @@ | ||
| 455 | 441 | * @param i the index of the variable to set. |
| 456 | 442 | * @param v the value to set. |
| 457 | 443 | * @return this BoundStatement. |
| 458 | - * | |
| 459 | 444 | * @throws IndexOutOfBoundsException if {@code i < 0 || i >= this.preparedStatement().variables().size()}. |
| 460 | - * @throws InvalidTypeException if column {@code i} is not of type FLOAT. | |
| 445 | + * @throws InvalidTypeException if column {@code i} is not of type FLOAT. | |
| 461 | 446 | */ |
| 462 | 447 | public BoundStatement setFloat(int i, float v) { |
| 463 | 448 | metadata().checkType(i, DataType.Name.FLOAT); |
| @@ -469,14 +454,13 @@ | ||
| 469 | 454 | * provided float. |
| 470 | 455 | * |
| 471 | 456 | * @param name the name of the variable to set; if multiple variables |
| 472 | - * {@code name} are prepared, all of them are set. | |
| 473 | - * @param v the value to set. | |
| 457 | + * {@code name} are prepared, all of them are set. | |
| 458 | + * @param v the value to set. | |
| 474 | 459 | * @return this BoundStatement. |
| 475 | - * | |
| 476 | 460 | * @throws IllegalArgumentException if {@code name} is not a prepared |
| 477 | - * variable, that is, if {@code !this.preparedStatement().variables().names().contains(name)}. | |
| 478 | - * @throws InvalidTypeException if (any occurrence of) {@code name} is | |
| 479 | - * not of type FLOAT. | |
| 461 | + * variable, that is, if {@code !this.preparedStatement().variables().names().contains(name)}. | |
| 462 | + * @throws InvalidTypeException if (any occurrence of) {@code name} is | |
| 463 | + * not of type FLOAT. | |
| 480 | 464 | */ |
| 481 | 465 | public BoundStatement setFloat(String name, float v) { |
| 482 | 466 | int[] indexes = metadata().getAllIdx(name); |
| @@ -494,9 +478,8 @@ | ||
| 494 | 478 | * @param i the index of the variable to set. |
| 495 | 479 | * @param v the value to set. |
| 496 | 480 | * @return this BoundStatement. |
| 497 | - * | |
| 498 | 481 | * @throws IndexOutOfBoundsException if {@code i < 0 || i >= this.preparedStatement().variables().size()}. |
| 499 | - * @throws InvalidTypeException if column {@code i} is not of type DOUBLE. | |
| 482 | + * @throws InvalidTypeException if column {@code i} is not of type DOUBLE. | |
| 500 | 483 | */ |
| 501 | 484 | public BoundStatement setDouble(int i, double v) { |
| 502 | 485 | metadata().checkType(i, DataType.Name.DOUBLE); |
| @@ -508,14 +491,13 @@ | ||
| 508 | 491 | * provided double. |
| 509 | 492 | * |
| 510 | 493 | * @param name the name of the variable to set; if multiple variables |
| 511 | - * {@code name} are prepared, all of them are set. | |
| 512 | - * @param v the value to set. | |
| 494 | + * {@code name} are prepared, all of them are set. | |
| 495 | + * @param v the value to set. | |
| 513 | 496 | * @return this BoundStatement. |
| 514 | - * | |
| 515 | 497 | * @throws IllegalArgumentException if {@code name} is not a prepared |
| 516 | - * variable, that is, if {@code !this.preparedStatement().variables().names().contains(name)}. | |
| 517 | - * @throws InvalidTypeException if (any occurrence of) {@code name} is | |
| 518 | - * not of type DOUBLE. | |
| 498 | + * variable, that is, if {@code !this.preparedStatement().variables().names().contains(name)}. | |
| 499 | + * @throws InvalidTypeException if (any occurrence of) {@code name} is | |
| 500 | + * not of type DOUBLE. | |
| 519 | 501 | */ |
| 520 | 502 | public BoundStatement setDouble(String name, double v) { |
| 521 | 503 | int[] indexes = metadata().getAllIdx(name); |
| @@ -533,15 +515,14 @@ | ||
| 533 | 515 | * @param i the index of the variable to set. |
| 534 | 516 | * @param v the value to set. |
| 535 | 517 | * @return this BoundStatement. |
| 536 | - * | |
| 537 | 518 | * @throws IndexOutOfBoundsException if {@code i < 0 || i >= this.preparedStatement().variables().size()}. |
| 538 | - * @throws InvalidTypeException if column {@code i} is of neither of the | |
| 539 | - * following types: VARCHAR, TEXT or ASCII. | |
| 519 | + * @throws InvalidTypeException if column {@code i} is of neither of the | |
| 520 | + * following types: VARCHAR, TEXT or ASCII. | |
| 540 | 521 | */ |
| 541 | 522 | public BoundStatement setString(int i, String v) { |
| 542 | 523 | DataType.Name type = metadata().checkType(i, DataType.Name.VARCHAR, |
| 543 | - DataType.Name.TEXT, | |
| 544 | - DataType.Name.ASCII); | |
| 524 | + DataType.Name.TEXT, | |
| 525 | + DataType.Name.ASCII); | |
| 545 | 526 | switch (type) { |
| 546 | 527 | case ASCII: |
| 547 | 528 | return setValue(i, v == null ? null : TypeCodec.StringCodec.asciiInstance.serialize(v)); |
| @@ -558,14 +539,13 @@ | ||
| 558 | 539 | * provided string. |
| 559 | 540 | * |
| 560 | 541 | * @param name the name of the variable to set; if multiple variables |
| 561 | - * {@code name} are prepared, all of them are set. | |
| 562 | - * @param v the value to set. | |
| 542 | + * {@code name} are prepared, all of them are set. | |
| 543 | + * @param v the value to set. | |
| 563 | 544 | * @return this BoundStatement. |
| 564 | - * | |
| 565 | 545 | * @throws IllegalArgumentException if {@code name} is not a prepared |
| 566 | - * variable, that is, if {@code !this.preparedStatement().variables().names().contains(name)}. | |
| 567 | - * @throws InvalidTypeException if (any occurrence of) {@code name} is | |
| 568 | - * of neither of the following types: VARCHAR, TEXT or ASCII. | |
| 546 | + * variable, that is, if {@code !this.preparedStatement().variables().names().contains(name)}. | |
| 547 | + * @throws InvalidTypeException if (any occurrence of) {@code name} is | |
| 548 | + * of neither of the following types: VARCHAR, TEXT or ASCII. | |
| 569 | 549 | */ |
| 570 | 550 | public BoundStatement setString(String name, String v) { |
| 571 | 551 | int[] indexes = metadata().getAllIdx(name); |
| @@ -576,7 +556,7 @@ | ||
| 576 | 556 | |
| 577 | 557 | /** |
| 578 | 558 | * Sets the {@code i}th value to the provided byte buffer. |
| 579 | - * | |
| 559 | + * <p/> | |
| 580 | 560 | * This method validate that the type of the column set is BLOB. If you |
| 581 | 561 | * want to insert manually serialized data into columns of another type, |
| 582 | 562 | * use {@link #setBytesUnsafe} instead. |
| @@ -584,9 +564,8 @@ | ||
| 584 | 564 | * @param i the index of the variable to set. |
| 585 | 565 | * @param v the value to set. |
| 586 | 566 | * @return this BoundStatement. |
| 587 | - * | |
| 588 | 567 | * @throws IndexOutOfBoundsException if {@code i < 0 || i >= this.preparedStatement().variables().size()}. |
| 589 | - * @throws InvalidTypeException if column {@code i} is not of type BLOB. | |
| 568 | + * @throws InvalidTypeException if column {@code i} is not of type BLOB. | |
| 590 | 569 | */ |
| 591 | 570 | public BoundStatement setBytes(int i, ByteBuffer v) { |
| 592 | 571 | metadata().checkType(i, DataType.Name.BLOB); |
| @@ -596,19 +575,18 @@ | ||
| 596 | 575 | /** |
| 597 | 576 | * Sets the value for (all occurrences of) variable {@code name} to the |
| 598 | 577 | * provided byte buffer. |
| 599 | - * | |
| 578 | + * <p/> | |
| 600 | 579 | * This method validate that the type of the column set is BLOB. If you |
| 601 | 580 | * want to insert manually serialized data into columns of another type, |
| 602 | 581 | * use {@link #setBytesUnsafe} instead. |
| 603 | 582 | * |
| 604 | 583 | * @param name the name of the variable to set; if multiple variables |
| 605 | - * {@code name} are prepared, all of them are set. | |
| 606 | - * @param v the value to set. | |
| 584 | + * {@code name} are prepared, all of them are set. | |
| 585 | + * @param v the value to set. | |
| 607 | 586 | * @return this BoundStatement. |
| 608 | - * | |
| 609 | 587 | * @throws IllegalArgumentException if {@code name} is not a prepared |
| 610 | - * variable, that is if {@code !this.preparedStatement().variables().names().contains(name)}. | |
| 611 | - * @throws InvalidTypeException if (any occurrence of) {@code name} is not of type BLOB. | |
| 588 | + * variable, that is if {@code !this.preparedStatement().variables().names().contains(name)}. | |
| 589 | + * @throws InvalidTypeException if (any occurrence of) {@code name} is not of type BLOB. | |
| 612 | 590 | */ |
| 613 | 591 | public BoundStatement setBytes(String name, ByteBuffer v) { |
| 614 | 592 | int[] indexes = metadata().getAllIdx(name); |
| @@ -622,7 +600,7 @@ | ||
| 622 | 600 | |
| 623 | 601 | /** |
| 624 | 602 | * Sets the {@code i}th value to the provided byte buffer. |
| 625 | - * | |
| 603 | + * <p/> | |
| 626 | 604 | * Contrary to {@link #setBytes}, this method does not check the |
| 627 | 605 | * type of the column set. If you insert data that is not compatible with |
| 628 | 606 | * the type of the column, you will get an {@code InvalidQueryException} at |
| @@ -631,7 +609,6 @@ | ||
| 631 | 609 | * @param i the index of the variable to set. |
| 632 | 610 | * @param v the value to set. |
| 633 | 611 | * @return this BoundStatement. |
| 634 | - * | |
| 635 | 612 | * @throws IndexOutOfBoundsException if {@code i < 0 || i >= this.preparedStatement().variables().size()}. |
| 636 | 613 | */ |
| 637 | 614 | public BoundStatement setBytesUnsafe(int i, ByteBuffer v) { |
| @@ -641,19 +618,18 @@ | ||
| 641 | 618 | /** |
| 642 | 619 | * Sets the value for (all occurrences of) variable {@code name} to the |
| 643 | 620 | * provided byte buffer. |
| 644 | - * | |
| 621 | + * <p/> | |
| 645 | 622 | * Contrary to {@link #setBytes}, this method does not check the |
| 646 | 623 | * type of the column set. If you insert data that is not compatible with |
| 647 | 624 | * the type of the column, you will get an {@code InvalidQueryException} at |
| 648 | 625 | * execute time. |
| 649 | 626 | * |
| 650 | 627 | * @param name the name of the variable to set; if multiple variables |
| 651 | - * {@code name} are prepared, all of them are set. | |
| 652 | - * @param v the value to set. | |
| 628 | + * {@code name} are prepared, all of them are set. | |
| 629 | + * @param v the value to set. | |
| 653 | 630 | * @return this BoundStatement. |
| 654 | - * | |
| 655 | 631 | * @throws IllegalArgumentException if {@code name} is not a prepared |
| 656 | - * variable, that is if {@code !this.preparedStatement().variables().names().contains(name)}. | |
| 632 | + * variable, that is if {@code !this.preparedStatement().variables().names().contains(name)}. | |
| 657 | 633 | */ |
| 658 | 634 | public BoundStatement setBytesUnsafe(String name, ByteBuffer v) { |
| 659 | 635 | int[] indexes = metadata().getAllIdx(name); |
| @@ -669,9 +645,8 @@ | ||
| 669 | 645 | * @param i the index of the variable to set. |
| 670 | 646 | * @param v the value to set. |
| 671 | 647 | * @return this BoundStatement. |
| 672 | - * | |
| 673 | 648 | * @throws IndexOutOfBoundsException if {@code i < 0 || i >= this.preparedStatement().variables().size()}. |
| 674 | - * @throws InvalidTypeException if column {@code i} is not of type VARINT. | |
| 649 | + * @throws InvalidTypeException if column {@code i} is not of type VARINT. | |
| 675 | 650 | */ |
| 676 | 651 | public BoundStatement setVarint(int i, BigInteger v) { |
| 677 | 652 | metadata().checkType(i, DataType.Name.VARINT); |
| @@ -683,14 +658,13 @@ | ||
| 683 | 658 | * provided big integer. |
| 684 | 659 | * |
| 685 | 660 | * @param name the name of the variable to set; if multiple variables |
| 686 | - * {@code name} are prepared, all of them are set. | |
| 687 | - * @param v the value to set. | |
| 661 | + * {@code name} are prepared, all of them are set. | |
| 662 | + * @param v the value to set. | |
| 688 | 663 | * @return this BoundStatement. |
| 689 | - * | |
| 690 | 664 | * @throws IllegalArgumentException if {@code name} is not a prepared |
| 691 | - * variable, that is, if {@code !this.preparedStatement().variables().names().contains(name)}. | |
| 692 | - * @throws InvalidTypeException if (any occurrence of) {@code name} is | |
| 693 | - * not of type VARINT. | |
| 665 | + * variable, that is, if {@code !this.preparedStatement().variables().names().contains(name)}. | |
| 666 | + * @throws InvalidTypeException if (any occurrence of) {@code name} is | |
| 667 | + * not of type VARINT. | |
| 694 | 668 | */ |
| 695 | 669 | public BoundStatement setVarint(String name, BigInteger v) { |
| 696 | 670 | int[] indexes = metadata().getAllIdx(name); |
| @@ -708,9 +682,8 @@ | ||
| 708 | 682 | * @param i the index of the variable to set. |
| 709 | 683 | * @param v the value to set. |
| 710 | 684 | * @return this BoundStatement. |
| 711 | - * | |
| 712 | 685 | * @throws IndexOutOfBoundsException if {@code i < 0 || i >= this.preparedStatement().variables().size()}. |
| 713 | - * @throws InvalidTypeException if column {@code i} is not of type DECIMAL. | |
| 686 | + * @throws InvalidTypeException if column {@code i} is not of type DECIMAL. | |
| 714 | 687 | */ |
| 715 | 688 | public BoundStatement setDecimal(int i, BigDecimal v) { |
| 716 | 689 | metadata().checkType(i, DataType.Name.DECIMAL); |
| @@ -722,14 +695,13 @@ | ||
| 722 | 695 | * provided big decimal. |
| 723 | 696 | * |
| 724 | 697 | * @param name the name of the variable to set; if multiple variables |
| 725 | - * {@code name} are prepared, all of them are set. | |
| 726 | - * @param v the value to set. | |
| 698 | + * {@code name} are prepared, all of them are set. | |
| 699 | + * @param v the value to set. | |
| 727 | 700 | * @return this BoundStatement. |
| 728 | - * | |
| 729 | 701 | * @throws IllegalArgumentException if {@code name} is not a prepared |
| 730 | - * variable, that is, if {@code !this.preparedStatement().variables().names().contains(name)}. | |
| 731 | - * @throws InvalidTypeException if (any occurrence of) {@code name} is | |
| 732 | - * not of type DECIMAL. | |
| 702 | + * variable, that is, if {@code !this.preparedStatement().variables().names().contains(name)}. | |
| 703 | + * @throws InvalidTypeException if (any occurrence of) {@code name} is | |
| 704 | + * not of type DECIMAL. | |
| 733 | 705 | */ |
| 734 | 706 | public BoundStatement setDecimal(String name, BigDecimal v) { |
| 735 | 707 | int[] indexes = metadata().getAllIdx(name); |
| @@ -747,15 +719,14 @@ | ||
| 747 | 719 | * @param i the index of the variable to set. |
| 748 | 720 | * @param v the value to set. |
| 749 | 721 | * @return this BoundStatement. |
| 750 | - * | |
| 751 | 722 | * @throws IndexOutOfBoundsException if {@code i < 0 || i >= this.preparedStatement().variables().size()}. |
| 752 | - * @throws InvalidTypeException if column {@code i} is not of type UUID or | |
| 753 | - * TIMEUUID, or if column {@code i} is of type TIMEUUID but {@code v} is | |
| 754 | - * not a type 1 UUID. | |
| 723 | + * @throws InvalidTypeException if column {@code i} is not of type UUID or | |
| 724 | + * TIMEUUID, or if column {@code i} is of type TIMEUUID but {@code v} is | |
| 725 | + * not a type 1 UUID. | |
| 755 | 726 | */ |
| 756 | 727 | public BoundStatement setUUID(int i, UUID v) { |
| 757 | 728 | DataType.Name type = metadata().checkType(i, DataType.Name.UUID, |
| 758 | - DataType.Name.TIMEUUID); | |
| 729 | + DataType.Name.TIMEUUID); | |
| 759 | 730 | |
| 760 | 731 | if (v == null) |
| 761 | 732 | return setValue(i, null); |
| @@ -764,8 +735,8 @@ | ||
| 764 | 735 | throw new InvalidTypeException(String.format("%s is not a Type 1 (time-based) UUID", v)); |
| 765 | 736 | |
| 766 | 737 | return type == DataType.Name.UUID |
| 767 | - ? setValue(i, TypeCodec.UUIDCodec.instance.serialize(v)) | |
| 768 | - : setValue(i, TypeCodec.TimeUUIDCodec.instance.serialize(v)); | |
| 738 | + ? setValue(i, TypeCodec.UUIDCodec.instance.serialize(v)) | |
| 739 | + : setValue(i, TypeCodec.TimeUUIDCodec.instance.serialize(v)); | |
| 769 | 740 | } |
| 770 | 741 | |
| 771 | 742 | /** |
| @@ -773,15 +744,14 @@ | ||
| 773 | 744 | * provided UUID. |
| 774 | 745 | * |
| 775 | 746 | * @param name the name of the variable to set; if multiple variables |
| 776 | - * {@code name} are prepared, all of them are set. | |
| 777 | - * @param v the value to set. | |
| 747 | + * {@code name} are prepared, all of them are set. | |
| 748 | + * @param v the value to set. | |
| 778 | 749 | * @return this BoundStatement. |
| 779 | - * | |
| 780 | 750 | * @throws IllegalArgumentException if {@code name} is not a prepared |
| 781 | - * variable, that is, if {@code !this.preparedStatement().variables().names().contains(name)}. | |
| 782 | - * @throws InvalidTypeException if (any occurrence of) {@code name} is | |
| 783 | - * not of type UUID or TIMEUUID, or if column {@code name} is of type | |
| 784 | - * TIMEUUID but {@code v} is not a type 1 UUID. | |
| 751 | + * variable, that is, if {@code !this.preparedStatement().variables().names().contains(name)}. | |
| 752 | + * @throws InvalidTypeException if (any occurrence of) {@code name} is | |
| 753 | + * not of type UUID or TIMEUUID, or if column {@code name} is of type | |
| 754 | + * TIMEUUID but {@code v} is not a type 1 UUID. | |
| 785 | 755 | */ |
| 786 | 756 | public BoundStatement setUUID(String name, UUID v) { |
| 787 | 757 | int[] indexes = metadata().getAllIdx(name); |
| @@ -801,9 +771,8 @@ | ||
| 801 | 771 | * @param i the index of the variable to set. |
| 802 | 772 | * @param v the value to set. |
| 803 | 773 | * @return this BoundStatement. |
| 804 | - * | |
| 805 | 774 | * @throws IndexOutOfBoundsException if {@code i < 0 || i >= this.preparedStatement().variables().size()}. |
| 806 | - * @throws InvalidTypeException if column {@code i} is not of type INET. | |
| 775 | + * @throws InvalidTypeException if column {@code i} is not of type INET. | |
| 807 | 776 | */ |
| 808 | 777 | public BoundStatement setInet(int i, InetAddress v) { |
| 809 | 778 | metadata().checkType(i, DataType.Name.INET); |
| @@ -815,14 +784,13 @@ | ||
| 815 | 784 | * provided inet address. |
| 816 | 785 | * |
| 817 | 786 | * @param name the name of the variable to set; if multiple variables |
| 818 | - * {@code name} are prepared, all of them are set. | |
| 819 | - * @param v the value to set. | |
| 787 | + * {@code name} are prepared, all of them are set. | |
| 788 | + * @param v the value to set. | |
| 820 | 789 | * @return this BoundStatement. |
| 821 | - * | |
| 822 | 790 | * @throws IllegalArgumentException if {@code name} is not a prepared |
| 823 | - * variable, that is, if {@code !this.preparedStatement().variables().names().contains(name)}. | |
| 824 | - * @throws InvalidTypeException if (any occurrence of) {@code name} is | |
| 825 | - * not of type INET. | |
| 791 | + * variable, that is, if {@code !this.preparedStatement().variables().names().contains(name)}. | |
| 792 | + * @throws InvalidTypeException if (any occurrence of) {@code name} is | |
| 793 | + * not of type INET. | |
| 826 | 794 | */ |
| 827 | 795 | public BoundStatement setInet(String name, InetAddress v) { |
| 828 | 796 | int[] indexes = metadata().getAllIdx(name); |
| @@ -836,16 +804,15 @@ | ||
| 836 | 804 | |
| 837 | 805 | /** |
| 838 | 806 | * Sets the {@code i}th value to the provided {@link Token}. |
| 839 | - * <p> | |
| 807 | + * <p/> | |
| 840 | 808 | * {@link #setPartitionKeyToken(Token)} should generally be preferred if you |
| 841 | 809 | * have a single token variable. |
| 842 | 810 | * |
| 843 | 811 | * @param i the index of the variable to set. |
| 844 | 812 | * @param v the value to set. |
| 845 | 813 | * @return this BoundStatement. |
| 846 | - * | |
| 847 | 814 | * @throws IndexOutOfBoundsException if {@code i < 0 || i >= this.preparedStatement().variables().size()}. |
| 848 | - * @throws InvalidTypeException if column {@code i} is not of the type of the token's value. | |
| 815 | + * @throws InvalidTypeException if column {@code i} is not of the type of the token's value. | |
| 849 | 816 | */ |
| 850 | 817 | public BoundStatement setToken(int i, Token v) { |
| 851 | 818 | metadata().checkType(i, v.getType().getName()); |
| @@ -855,10 +822,10 @@ | ||
| 855 | 822 | /** |
| 856 | 823 | * Sets the value for (all occurrences of) variable {@code name} to the |
| 857 | 824 | * provided token. |
| 858 | - * <p> | |
| 825 | + * <p/> | |
| 859 | 826 | * {@link #setPartitionKeyToken(Token)} should generally be preferred if you |
| 860 | 827 | * have a single token variable. |
| 861 | - * <p> | |
| 828 | + * <p/> | |
| 862 | 829 | * If you have multiple token variables, use positional binding ({@link #setToken(int, Token)}, |
| 863 | 830 | * or named bind markers: |
| 864 | 831 | * <pre> |
| @@ -869,14 +836,13 @@ | ||
| 869 | 836 | * </pre> |
| 870 | 837 | * |
| 871 | 838 | * @param name the name of the variable to set; if multiple variables |
| 872 | - * {@code name} are prepared, all of them are set. | |
| 873 | - * @param v the value to set. | |
| 839 | + * {@code name} are prepared, all of them are set. | |
| 840 | + * @param v the value to set. | |
| 874 | 841 | * @return this BoundStatement. |
| 875 | - * | |
| 876 | 842 | * @throws IllegalArgumentException if {@code name} is not a prepared |
| 877 | - * variable, that is, if {@code !this.preparedStatement().variables().names().contains(name)}. | |
| 878 | - * @throws InvalidTypeException if (any occurrence of) {@code name} is | |
| 879 | - * not of the type of the token's value. | |
| 843 | + * variable, that is, if {@code !this.preparedStatement().variables().names().contains(name)}. | |
| 844 | + * @throws InvalidTypeException if (any occurrence of) {@code name} is | |
| 845 | + * not of the type of the token's value. | |
| 880 | 846 | */ |
| 881 | 847 | public BoundStatement setToken(String name, Token v) { |
| 882 | 848 | int[] indexes = metadata().getAllIdx(name); |
| @@ -889,7 +855,7 @@ | ||
| 889 | 855 | * Sets the value for (all occurrences of) variable "{@code partition key token}" |
| 890 | 856 | * to the provided token (this is the name generated by Cassandra for markers |
| 891 | 857 | * corresponding to a {@code token(...)} call). |
| 892 | - * <p> | |
| 858 | + * <p/> | |
| 893 | 859 | * This method is a shorthand for statements with a single token variable: |
| 894 | 860 | * <pre> |
| 895 | 861 | * {@code |
| @@ -909,11 +875,10 @@ | ||
| 909 | 875 | * |
| 910 | 876 | * @param v the value to set. |
| 911 | 877 | * @return this BoundStatement. |
| 912 | - * | |
| 913 | 878 | * @throws IllegalArgumentException if {@code name} is not a prepared |
| 914 | - * variable, that is, if {@code !this.preparedStatement().variables().names().contains(name)}. | |
| 915 | - * @throws InvalidTypeException if (any occurrence of) {@code name} is | |
| 916 | - * not of the type of the token's value. | |
| 879 | + * variable, that is, if {@code !this.preparedStatement().variables().names().contains(name)}. | |
| 880 | + * @throws InvalidTypeException if (any occurrence of) {@code name} is | |
| 881 | + * not of the type of the token's value. | |
| 917 | 882 | */ |
| 918 | 883 | public BoundStatement setPartitionKeyToken(Token v) { |
| 919 | 884 | return setToken("partition key token", v); |
| @@ -921,20 +886,19 @@ | ||
| 921 | 886 | |
| 922 | 887 | /** |
| 923 | 888 | * Sets the {@code i}th value to the provided list. |
| 924 | - * <p> | |
| 889 | + * <p/> | |
| 925 | 890 | * Please note that {@code null} values are not supported inside collection by CQL. |
| 926 | 891 | * |
| 927 | 892 | * @param <T> the type of the elements of the list to set. |
| 928 | - * @param i the index of the variable to set. | |
| 929 | - * @param v the value to set. | |
| 893 | + * @param i the index of the variable to set. | |
| 894 | + * @param v the value to set. | |
| 930 | 895 | * @return this BoundStatement. |
| 931 | - * | |
| 932 | 896 | * @throws IndexOutOfBoundsException if {@code i < 0 || i >= this.preparedStatement().variables().size()}. |
| 933 | - * @throws InvalidTypeException if column {@code i} is not a list type or | |
| 934 | - * if the elements of {@code v} are not of the type of the elements of | |
| 935 | - * column {@code i}. | |
| 936 | - * @throws NullPointerException if {@code v} contains null values. Nulls are not supported in collections | |
| 937 | - * by CQL. | |
| 897 | + * @throws InvalidTypeException if column {@code i} is not a list type or | |
| 898 | + * if the elements of {@code v} are not of the type of the elements of | |
| 899 | + * column {@code i}. | |
| 900 | + * @throws NullPointerException if {@code v} contains null values. Nulls are not supported in collections | |
| 901 | + * by CQL. | |
| 938 | 902 | */ |
| 939 | 903 | public <T> BoundStatement setList(int i, List<T> v) { |
| 940 | 904 | DataType type = metadata().getType(i); |
| @@ -960,22 +924,21 @@ | ||
| 960 | 924 | /** |
| 961 | 925 | * Sets the value for (all occurrences of) variable {@code name} to the |
| 962 | 926 | * provided list. |
| 963 | - * <p> | |
| 927 | + * <p/> | |
| 964 | 928 | * Please note that {@code null} values are not supported inside collection by CQL. |
| 965 | 929 | * |
| 966 | - * @param <T> the type of the elements of the list to set. | |
| 930 | + * @param <T> the type of the elements of the list to set. | |
| 967 | 931 | * @param name the name of the variable to set; if multiple variables |
| 968 | - * {@code name} are prepared, all of them are set. | |
| 969 | - * @param v the value to set. | |
| 932 | + * {@code name} are prepared, all of them are set. | |
| 933 | + * @param v the value to set. | |
| 970 | 934 | * @return this BoundStatement. |
| 971 | - * | |
| 972 | 935 | * @throws IllegalArgumentException if {@code name} is not a prepared |
| 973 | - * variable, that is, if {@code !this.preparedStatement().variables().names().contains(name)}. | |
| 974 | - * @throws InvalidTypeException if (any occurrence of) {@code name} is | |
| 975 | - * not a list type or if the elements of {@code v} are not of the type of | |
| 976 | - * the elements of column {@code name}. | |
| 977 | - * @throws NullPointerException if {@code v} contains null values. Nulls are not supported in collections | |
| 978 | - * by CQL. | |
| 936 | + * variable, that is, if {@code !this.preparedStatement().variables().names().contains(name)}. | |
| 937 | + * @throws InvalidTypeException if (any occurrence of) {@code name} is | |
| 938 | + * not a list type or if the elements of {@code v} are not of the type of | |
| 939 | + * the elements of column {@code name}. | |
| 940 | + * @throws NullPointerException if {@code v} contains null values. Nulls are not supported in collections | |
| 941 | + * by CQL. | |
| 979 | 942 | */ |
| 980 | 943 | public <T> BoundStatement setList(String name, List<T> v) { |
| 981 | 944 | int[] indexes = metadata().getAllIdx(name); |
| @@ -986,21 +949,20 @@ | ||
| 986 | 949 | |
| 987 | 950 | /** |
| 988 | 951 | * Sets the {@code i}th value to the provided map. |
| 989 | - * <p> | |
| 952 | + * <p/> | |
| 990 | 953 | * Please note that {@code null} values are not supported inside collection by CQL. |
| 991 | 954 | * |
| 992 | 955 | * @param <K> the type of the keys for the map to set. |
| 993 | 956 | * @param <V> the type of the values for the map to set. |
| 994 | - * @param i the index of the variable to set. | |
| 995 | - * @param v the value to set. | |
| 957 | + * @param i the index of the variable to set. | |
| 958 | + * @param v the value to set. | |
| 996 | 959 | * @return this BoundStatement. |
| 997 | - * | |
| 998 | 960 | * @throws IndexOutOfBoundsException if {@code i < 0 || i >= this.preparedStatement().variables().size()}. |
| 999 | - * @throws InvalidTypeException if column {@code i} is not a map type or | |
| 1000 | - * if the elements (keys or values) of {@code v} are not of the type of the | |
| 1001 | - * elements of column {@code i}. | |
| 1002 | - * @throws NullPointerException if {@code v} contains null values. Nulls are not supported in collections | |
| 1003 | - * by CQL. | |
| 961 | + * @throws InvalidTypeException if column {@code i} is not a map type or | |
| 962 | + * if the elements (keys or values) of {@code v} are not of the type of the | |
| 963 | + * elements of column {@code i}. | |
| 964 | + * @throws NullPointerException if {@code v} contains null values. Nulls are not supported in collections | |
| 965 | + * by CQL. | |
| 1004 | 966 | */ |
| 1005 | 967 | public <K, V> BoundStatement setMap(int i, Map<K, V> v) { |
| 1006 | 968 | DataType type = metadata().getType(i); |
| @@ -1028,23 +990,22 @@ | ||
| 1028 | 990 | /** |
| 1029 | 991 | * Sets the value for (all occurrences of) variable {@code name} to the |
| 1030 | 992 | * provided map. |
| 1031 | - * <p> | |
| 993 | + * <p/> | |
| 1032 | 994 | * Please note that {@code null} values are not supported inside collection by CQL. |
| 1033 | 995 | * |
| 1034 | - * @param <K> the type of the keys for the map to set. | |
| 1035 | - * @param <V> the type of the values for the map to set. | |
| 996 | + * @param <K> the type of the keys for the map to set. | |
| 997 | + * @param <V> the type of the values for the map to set. | |
| 1036 | 998 | * @param name the name of the variable to set; if multiple variables |
| 1037 | - * {@code name} are prepared, all of them are set. | |
| 1038 | - * @param v the value to set. | |
| 999 | + * {@code name} are prepared, all of them are set. | |
| 1000 | + * @param v the value to set. | |
| 1039 | 1001 | * @return this BoundStatement. |
| 1040 | - * | |
| 1041 | 1002 | * @throws IllegalArgumentException if {@code name} is not a prepared |
| 1042 | - * variable, that is, if {@code !this.preparedStatement().variables().names().contains(name)}. | |
| 1043 | - * @throws InvalidTypeException if (any occurrence of) {@code name} is | |
| 1044 | - * not a map type or if the elements (keys or values) of {@code v} are not of | |
| 1045 | - * the type of the elements of column {@code name}. | |
| 1046 | - * @throws NullPointerException if {@code v} contains null values. Nulls are not supported in collections | |
| 1047 | - * by CQL. | |
| 1003 | + * variable, that is, if {@code !this.preparedStatement().variables().names().contains(name)}. | |
| 1004 | + * @throws InvalidTypeException if (any occurrence of) {@code name} is | |
| 1005 | + * not a map type or if the elements (keys or values) of {@code v} are not of | |
| 1006 | + * the type of the elements of column {@code name}. | |
| 1007 | + * @throws NullPointerException if {@code v} contains null values. Nulls are not supported in collections | |
| 1008 | + * by CQL. | |
| 1048 | 1009 | */ |
| 1049 | 1010 | public <K, V> BoundStatement setMap(String name, Map<K, V> v) { |
| 1050 | 1011 | int[] indexes = metadata().getAllIdx(name); |
| @@ -1055,20 +1016,19 @@ | ||
| 1055 | 1016 | |
| 1056 | 1017 | /** |
| 1057 | 1018 | * Sets the {@code i}th value to the provided set. |
| 1058 | - * <p> | |
| 1019 | + * <p/> | |
| 1059 | 1020 | * Please note that {@code null} values are not supported inside collection by CQL. |
| 1060 | 1021 | * |
| 1061 | 1022 | * @param <T> the type of the elements of the set to set. |
| 1062 | - * @param i the index of the variable to set. | |
| 1063 | - * @param v the value to set. | |
| 1023 | + * @param i the index of the variable to set. | |
| 1024 | + * @param v the value to set. | |
| 1064 | 1025 | * @return this BoundStatement. |
| 1065 | - * | |
| 1066 | 1026 | * @throws IndexOutOfBoundsException if {@code i < 0 || i >= this.preparedStatement().variables().size()}. |
| 1067 | - * @throws InvalidTypeException if column {@code i} is not a set type or | |
| 1068 | - * if the elements of {@code v} are not of the type of the elements of | |
| 1069 | - * column {@code i}. | |
| 1070 | - * @throws NullPointerException if {@code v} contains null values. Nulls are not supported in collections | |
| 1071 | - * by CQL. | |
| 1027 | + * @throws InvalidTypeException if column {@code i} is not a set type or | |
| 1028 | + * if the elements of {@code v} are not of the type of the elements of | |
| 1029 | + * column {@code i}. | |
| 1030 | + * @throws NullPointerException if {@code v} contains null values. Nulls are not supported in collections | |
| 1031 | + * by CQL. | |
| 1072 | 1032 | */ |
| 1073 | 1033 | public <T> BoundStatement setSet(int i, Set<T> v) { |
| 1074 | 1034 | DataType type = metadata().getType(i); |
| @@ -1093,22 +1053,21 @@ | ||
| 1093 | 1053 | /** |
| 1094 | 1054 | * Sets the value for (all occurrences of) variable {@code name} to the |
| 1095 | 1055 | * provided set. |
| 1096 | - * <p> | |
| 1056 | + * <p/> | |
| 1097 | 1057 | * Please note that {@code null} values are not supported inside collection by CQL. |
| 1098 | 1058 | * |
| 1099 | - * @param <T> the type of the elements of the set to set. | |
| 1059 | + * @param <T> the type of the elements of the set to set. | |
| 1100 | 1060 | * @param name the name of the variable to set; if multiple variables |
| 1101 | - * {@code name} are prepared, all of them are set. | |
| 1102 | - * @param v the value to set. | |
| 1061 | + * {@code name} are prepared, all of them are set. | |
| 1062 | + * @param v the value to set. | |
| 1103 | 1063 | * @return this BoundStatement. |
| 1104 | - * | |
| 1105 | 1064 | * @throws IllegalArgumentException if {@code name} is not a prepared |
| 1106 | - * variable, that is, if {@code !this.preparedStatement().variables().names().contains(name)}. | |
| 1107 | - * @throws InvalidTypeException if (any occurrence of) {@code name} is | |
| 1108 | - * not a map type or if the elements of {@code v} are not of the type of | |
| 1109 | - * the elements of column {@code name}. | |
| 1110 | - * @throws NullPointerException if {@code v} contains null values. Nulls are not supported in collections | |
| 1111 | - * by CQL. | |
| 1065 | + * variable, that is, if {@code !this.preparedStatement().variables().names().contains(name)}. | |
| 1066 | + * @throws InvalidTypeException if (any occurrence of) {@code name} is | |
| 1067 | + * not a map type or if the elements of {@code v} are not of the type of | |
| 1068 | + * the elements of column {@code name}. | |
| 1069 | + * @throws NullPointerException if {@code v} contains null values. Nulls are not supported in collections | |
| 1070 | + * by CQL. | |
| 1112 | 1071 | */ |
| 1113 | 1072 | public <T> BoundStatement setSet(String name, Set<T> v) { |
| 1114 | 1073 | int[] indexes = metadata().getAllIdx(name); |
modified driver-core/src/main/java/com/datastax/driver/core/BusyConnectionException.java +1 −2
| @@ -15,8 +15,7 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -class BusyConnectionException extends Exception | |
| 19 | -{ | |
| 18 | +class BusyConnectionException extends Exception { | |
| 20 | 19 | private static final long serialVersionUID = 0; |
| 21 | 20 | |
| 22 | 21 | public BusyConnectionException() { |
modified driver-core/src/main/java/com/datastax/driver/core/CBUtil.java +6 −6
| @@ -15,6 +15,10 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.exceptions.DriverInternalError; | |
| 19 | +import io.netty.buffer.ByteBuf; | |
| 20 | +import io.netty.util.CharsetUtil; | |
| 21 | + | |
| 18 | 22 | import java.net.InetAddress; |
| 19 | 23 | import java.net.InetSocketAddress; |
| 20 | 24 | import java.net.UnknownHostException; |
| @@ -22,17 +26,13 @@ | ||
| 22 | 26 | import java.nio.charset.CharacterCodingException; |
| 23 | 27 | import java.util.*; |
| 24 | 28 | |
| 25 | -import io.netty.buffer.ByteBuf; | |
| 26 | -import io.netty.util.CharsetUtil; | |
| 27 | - | |
| 28 | -import com.datastax.driver.core.exceptions.DriverInternalError; | |
| 29 | - | |
| 30 | 29 | /** |
| 31 | 30 | * ByteBuf utility methods. |
| 32 | 31 | */ |
| 33 | 32 | abstract class CBUtil { // TODO rename |
| 34 | 33 | |
| 35 | - private CBUtil() {} | |
| 34 | + private CBUtil() { | |
| 35 | + } | |
| 36 | 36 | |
| 37 | 37 | private static String readString(ByteBuf cb, int length) { |
| 38 | 38 | try { |
modified driver-core/src/main/java/com/datastax/driver/core/CassandraTypeParser.java +26 −27
| @@ -15,12 +15,11 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.util.*; | |
| 19 | - | |
| 20 | -import com.google.common.collect.ImmutableMap; | |
| 21 | - | |
| 22 | 18 | import com.datastax.driver.core.exceptions.DriverInternalError; |
| 23 | 19 | import com.datastax.driver.core.utils.Bytes; |
| 20 | +import com.google.common.collect.ImmutableMap; | |
| 21 | + | |
| 22 | +import java.util.*; | |
| 24 | 23 | |
| 25 | 24 | /* |
| 26 | 25 | * Helps transforming Cassandra types (as read in the schema tables) to |
| @@ -44,24 +43,24 @@ | ||
| 44 | 43 | private static final String MAP_TYPE = "org.apache.cassandra.db.marshal.MapType"; |
| 45 | 44 | |
| 46 | 45 | private static ImmutableMap<String, DataType> cassTypeToDataType = |
| 47 | - new ImmutableMap.Builder<String, DataType>() | |
| 48 | - .put("org.apache.cassandra.db.marshal.AsciiType", DataType.ascii()) | |
| 49 | - .put("org.apache.cassandra.db.marshal.LongType", DataType.bigint()) | |
| 50 | - .put("org.apache.cassandra.db.marshal.BytesType", DataType.blob()) | |
| 51 | - .put("org.apache.cassandra.db.marshal.BooleanType", DataType.cboolean()) | |
| 52 | - .put("org.apache.cassandra.db.marshal.CounterColumnType", DataType.counter()) | |
| 53 | - .put("org.apache.cassandra.db.marshal.DecimalType", DataType.decimal()) | |
| 54 | - .put("org.apache.cassandra.db.marshal.DoubleType", DataType.cdouble()) | |
| 55 | - .put("org.apache.cassandra.db.marshal.FloatType", DataType.cfloat()) | |
| 56 | - .put("org.apache.cassandra.db.marshal.InetAddressType", DataType.inet()) | |
| 57 | - .put("org.apache.cassandra.db.marshal.Int32Type", DataType.cint()) | |
| 58 | - .put("org.apache.cassandra.db.marshal.UTF8Type", DataType.text()) | |
| 59 | - .put("org.apache.cassandra.db.marshal.TimestampType", DataType.timestamp()) | |
| 60 | - .put("org.apache.cassandra.db.marshal.DateType", DataType.timestamp()) | |
| 61 | - .put("org.apache.cassandra.db.marshal.UUIDType", DataType.uuid()) | |
| 62 | - .put("org.apache.cassandra.db.marshal.IntegerType", DataType.varint()) | |
| 63 | - .put("org.apache.cassandra.db.marshal.TimeUUIDType", DataType.timeuuid()) | |
| 64 | - .build(); | |
| 46 | + new ImmutableMap.Builder<String, DataType>() | |
| 47 | + .put("org.apache.cassandra.db.marshal.AsciiType", DataType.ascii()) | |
| 48 | + .put("org.apache.cassandra.db.marshal.LongType", DataType.bigint()) | |
| 49 | + .put("org.apache.cassandra.db.marshal.BytesType", DataType.blob()) | |
| 50 | + .put("org.apache.cassandra.db.marshal.BooleanType", DataType.cboolean()) | |
| 51 | + .put("org.apache.cassandra.db.marshal.CounterColumnType", DataType.counter()) | |
| 52 | + .put("org.apache.cassandra.db.marshal.DecimalType", DataType.decimal()) | |
| 53 | + .put("org.apache.cassandra.db.marshal.DoubleType", DataType.cdouble()) | |
| 54 | + .put("org.apache.cassandra.db.marshal.FloatType", DataType.cfloat()) | |
| 55 | + .put("org.apache.cassandra.db.marshal.InetAddressType", DataType.inet()) | |
| 56 | + .put("org.apache.cassandra.db.marshal.Int32Type", DataType.cint()) | |
| 57 | + .put("org.apache.cassandra.db.marshal.UTF8Type", DataType.text()) | |
| 58 | + .put("org.apache.cassandra.db.marshal.TimestampType", DataType.timestamp()) | |
| 59 | + .put("org.apache.cassandra.db.marshal.DateType", DataType.timestamp()) | |
| 60 | + .put("org.apache.cassandra.db.marshal.UUIDType", DataType.uuid()) | |
| 61 | + .put("org.apache.cassandra.db.marshal.IntegerType", DataType.varint()) | |
| 62 | + .put("org.apache.cassandra.db.marshal.TimeUUIDType", DataType.timeuuid()) | |
| 63 | + .build(); | |
| 65 | 64 | |
| 66 | 65 | static DataType parseOne(String className) { |
| 67 | 66 | if (isReversed(className)) { |
| @@ -142,9 +141,9 @@ | ||
| 142 | 141 | |
| 143 | 142 | private ParseResult(DataType type, boolean reversed) { |
| 144 | 143 | this(false, |
| 145 | - Collections.<DataType>singletonList(type), | |
| 146 | - Collections.<Boolean>singletonList(reversed), | |
| 147 | - Collections.<String, DataType>emptyMap()); | |
| 144 | + Collections.<DataType>singletonList(type), | |
| 145 | + Collections.<Boolean>singletonList(reversed), | |
| 146 | + Collections.<String, DataType>emptyMap()); | |
| 148 | 147 | } |
| 149 | 148 | |
| 150 | 149 | private ParseResult(boolean isComposite, List<DataType> types, List<Boolean> reversed, Map<String, DataType> collections) { |
| @@ -328,8 +327,8 @@ | ||
| 328 | 327 | */ |
| 329 | 328 | private static boolean isIdentifierChar(int c) { |
| 330 | 329 | return (c >= '0' && c <= '9') |
| 331 | - || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') | |
| 332 | - || c == '-' || c == '+' || c == '.' || c == '_' || c == '&'; | |
| 330 | + || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') | |
| 331 | + || c == '-' || c == '+' || c == '.' || c == '_' || c == '&'; | |
| 333 | 332 | } |
| 334 | 333 | |
| 335 | 334 | // left idx positioned on the character stopping the read |
modified driver-core/src/main/java/com/datastax/driver/core/ChainedResultSetFuture.java +5 −5
| @@ -15,15 +15,15 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.util.concurrent.ExecutionException; | |
| 19 | -import java.util.concurrent.TimeUnit; | |
| 20 | -import java.util.concurrent.TimeoutException; | |
| 21 | - | |
| 22 | 18 | import com.google.common.util.concurrent.AbstractFuture; |
| 23 | 19 | import com.google.common.util.concurrent.FutureCallback; |
| 24 | 20 | import com.google.common.util.concurrent.Futures; |
| 25 | 21 | import com.google.common.util.concurrent.Uninterruptibles; |
| 26 | 22 | |
| 23 | +import java.util.concurrent.ExecutionException; | |
| 24 | +import java.util.concurrent.TimeUnit; | |
| 25 | +import java.util.concurrent.TimeoutException; | |
| 26 | + | |
| 27 | 27 | /** |
| 28 | 28 | * A {@code ResultSetFuture} that will complete when its source future completes. |
| 29 | 29 | */ |
| @@ -51,7 +51,7 @@ | ||
| 51 | 51 | @Override |
| 52 | 52 | public boolean cancel(boolean mayInterruptIfRunning) { |
| 53 | 53 | return (source == null || source.cancel(mayInterruptIfRunning)) |
| 54 | - && super.cancel(mayInterruptIfRunning); | |
| 54 | + && super.cancel(mayInterruptIfRunning); | |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | @Override |
modified driver-core/src/main/java/com/datastax/driver/core/CloseFuture.java +8 −7
| @@ -15,25 +15,26 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.util.List; | |
| 19 | - | |
| 20 | 18 | import com.google.common.util.concurrent.AbstractFuture; |
| 21 | 19 | import com.google.common.util.concurrent.FutureCallback; |
| 22 | 20 | import com.google.common.util.concurrent.Futures; |
| 23 | 21 | |
| 22 | +import java.util.List; | |
| 23 | + | |
| 24 | 24 | /** |
| 25 | 25 | * A future on the shutdown of a Cluster or Session instance. |
| 26 | - * <p> | |
| 26 | + * <p/> | |
| 27 | 27 | * This is a standard future except for the fact that this class has an |
| 28 | 28 | * additional {@link #force} method that can be used to expedite the shutdown |
| 29 | 29 | * process (see below). |
| 30 | - * <p> | |
| 30 | + * <p/> | |
| 31 | 31 | * Note that this class implements <a href="http://code.google.com/p/guava-libraries/">Guava</a>'s {@code |
| 32 | 32 | * ListenableFuture} and can so be used with Guava's future utilities. |
| 33 | 33 | */ |
| 34 | 34 | public abstract class CloseFuture extends AbstractFuture<Void> { |
| 35 | 35 | |
| 36 | - CloseFuture() {} | |
| 36 | + CloseFuture() { | |
| 37 | + } | |
| 37 | 38 | |
| 38 | 39 | static CloseFuture immediateFuture() { |
| 39 | 40 | CloseFuture future = new CloseFuture() { |
| @@ -48,11 +49,11 @@ | ||
| 48 | 49 | |
| 49 | 50 | /** |
| 50 | 51 | * Try to force the completion of the shutdown this is a future of. |
| 51 | - * <p> | |
| 52 | + * <p/> | |
| 52 | 53 | * This method will do its best to expedite the shutdown process. In |
| 53 | 54 | * particular, all connections will be closed right away, even if there is |
| 54 | 55 | * ongoing queries at the time this method is called. |
| 55 | - * <p> | |
| 56 | + * <p/> | |
| 56 | 57 | * Note that this method does not block. The completion of this method does |
| 57 | 58 | * not imply the shutdown process is done, you still need to wait on this |
| 58 | 59 | * future to ensure that, but calling this method will ensure said |
modified driver-core/src/main/java/com/datastax/driver/core/Cluster.java +220 −242
| @@ -15,16 +15,12 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.io.Closeable; | |
| 19 | -import java.net.InetAddress; | |
| 20 | -import java.net.InetSocketAddress; | |
| 21 | -import java.net.UnknownHostException; | |
| 22 | -import java.util.*; | |
| 23 | -import java.util.Map.Entry; | |
| 24 | -import java.util.concurrent.*; | |
| 25 | -import java.util.concurrent.atomic.AtomicInteger; | |
| 26 | -import java.util.concurrent.atomic.AtomicReference; | |
| 27 | - | |
| 18 | +import com.datastax.driver.core.exceptions.AuthenticationException; | |
| 19 | +import com.datastax.driver.core.exceptions.DriverInternalError; | |
| 20 | +import com.datastax.driver.core.exceptions.InvalidQueryException; | |
| 21 | +import com.datastax.driver.core.exceptions.NoHostAvailableException; | |
| 22 | +import com.datastax.driver.core.policies.*; | |
| 23 | +import com.datastax.driver.core.utils.MoreFutures; | |
| 28 | 24 | import com.google.common.annotations.VisibleForTesting; |
| 29 | 25 | import com.google.common.base.Functions; |
| 30 | 26 | import com.google.common.base.Objects; |
| @@ -34,16 +30,19 @@ | ||
| 34 | 30 | import org.slf4j.Logger; |
| 35 | 31 | import org.slf4j.LoggerFactory; |
| 36 | 32 | |
| 37 | -import com.datastax.driver.core.exceptions.AuthenticationException; | |
| 38 | -import com.datastax.driver.core.exceptions.DriverInternalError; | |
| 39 | -import com.datastax.driver.core.exceptions.InvalidQueryException; | |
| 40 | -import com.datastax.driver.core.exceptions.NoHostAvailableException; | |
| 41 | -import com.datastax.driver.core.policies.*; | |
| 42 | -import com.datastax.driver.core.utils.MoreFutures; | |
| 33 | +import java.io.Closeable; | |
| 34 | +import java.net.InetAddress; | |
| 35 | +import java.net.InetSocketAddress; | |
| 36 | +import java.net.UnknownHostException; | |
| 37 | +import java.util.*; | |
| 38 | +import java.util.Map.Entry; | |
| 39 | +import java.util.concurrent.*; | |
| 40 | +import java.util.concurrent.atomic.AtomicInteger; | |
| 41 | +import java.util.concurrent.atomic.AtomicReference; | |
| 43 | 42 | |
| 44 | 43 | /** |
| 45 | 44 | * Information and known state of a Cassandra cluster. |
| 46 | - * <p> | |
| 45 | + * <p/> | |
| 47 | 46 | * This is the main entry point of the driver. A simple example of access to a |
| 48 | 47 | * Cassandra cluster would be: |
| 49 | 48 | * <pre> |
| @@ -53,7 +52,7 @@ | ||
| 53 | 52 | * for (Row row : session.execute("SELECT * FROM table1")) |
| 54 | 53 | * // do something ... |
| 55 | 54 | * </pre> |
| 56 | - * <p> | |
| 55 | + * <p/> | |
| 57 | 56 | * A cluster object maintains a permanent connection to one of the cluster nodes |
| 58 | 57 | * which it uses solely to maintain information on the state and current |
| 59 | 58 | * topology of the cluster. Using the connection, the driver will discover all |
| @@ -67,7 +66,7 @@ | ||
| 67 | 66 | @VisibleForTesting |
| 68 | 67 | static final int NEW_NODE_DELAY_SECONDS = SystemProperties.getInt("com.datastax.driver.NEW_NODE_DELAY_SECONDS", 1); |
| 69 | 68 | private static final int NON_BLOCKING_EXECUTOR_SIZE = SystemProperties.getInt("com.datastax.driver.NON_BLOCKING_EXECUTOR_SIZE", |
| 70 | - Runtime.getRuntime().availableProcessors()); | |
| 69 | + Runtime.getRuntime().availableProcessors()); | |
| 71 | 70 | |
| 72 | 71 | private static final ResourceBundle driverProperties = ResourceBundle.getBundle("com.datastax.driver.core.Driver"); |
| 73 | 72 | |
| @@ -83,13 +82,13 @@ | ||
| 83 | 82 | |
| 84 | 83 | /** |
| 85 | 84 | * Constructs a new Cluster instance. |
| 86 | - * <p> | |
| 85 | + * <p/> | |
| 87 | 86 | * This constructor is mainly exposed so Cluster can be sub-classed as a means to make testing/mocking |
| 88 | 87 | * easier or to "intercept" its method call. Most users shouldn't extend this class however and |
| 89 | 88 | * should prefer either using the {@link #builder} or calling {@link #buildFrom} with a custom |
| 90 | 89 | * Initializer. |
| 91 | 90 | * |
| 92 | - * @param name the name to use for the cluster (this is not the Cassandra cluster name, see {@link #getClusterName}). | |
| 91 | + * @param name the name to use for the cluster (this is not the Cassandra cluster name, see {@link #getClusterName}). | |
| 93 | 92 | * @param contactPoints the list of contact points to use for the new cluster. |
| 94 | 93 | * @param configuration the configuration for the new cluster. |
| 95 | 94 | */ |
| @@ -99,7 +98,7 @@ | ||
| 99 | 98 | |
| 100 | 99 | /** |
| 101 | 100 | * Constructs a new Cluster instance. |
| 102 | - * <p> | |
| 101 | + * <p/> | |
| 103 | 102 | * This constructor is mainly exposed so Cluster can be sub-classed as a means to make testing/mocking |
| 104 | 103 | * easier or to "intercept" its method call. Most users shouldn't extend this class however and |
| 105 | 104 | * should prefer using the {@link #builder}. |
| @@ -109,9 +108,9 @@ | ||
| 109 | 108 | */ |
| 110 | 109 | protected Cluster(Initializer initializer) { |
| 111 | 110 | this(initializer.getClusterName(), |
| 112 | - checkNotEmpty(initializer.getContactPoints()), | |
| 113 | - initializer.getConfiguration(), | |
| 114 | - initializer.getInitialListeners()); | |
| 111 | + checkNotEmpty(initializer.getContactPoints()), | |
| 112 | + initializer.getConfiguration(), | |
| 113 | + initializer.getInitialListeners()); | |
| 115 | 114 | } |
| 116 | 115 | |
| 117 | 116 | private static List<InetSocketAddress> checkNotEmpty(List<InetSocketAddress> contactPoints) { |
| @@ -126,35 +125,34 @@ | ||
| 126 | 125 | |
| 127 | 126 | /** |
| 128 | 127 | * Initialize this Cluster instance. |
| 129 | - * | |
| 128 | + * <p/> | |
| 130 | 129 | * This method creates an initial connection to one of the contact points |
| 131 | 130 | * used to construct the {@code Cluster} instance. That connection is then |
| 132 | 131 | * used to populate the cluster {@link Metadata}. |
| 133 | - * <p> | |
| 132 | + * <p/> | |
| 134 | 133 | * Calling this method is optional in the sense that any call to one of the |
| 135 | 134 | * {@code connect} methods of this object will automatically trigger a call |
| 136 | 135 | * to this method beforehand. It is thus only useful to call this method if |
| 137 | 136 | * for some reason you want to populate the metadata (or test that at least |
| 138 | 137 | * one contact point can be reached) without creating a first {@code |
| 139 | 138 | * Session}. |
| 140 | - * <p> | |
| 139 | + * <p/> | |
| 141 | 140 | * Please note that this method only creates one control connection for |
| 142 | 141 | * gathering cluster metadata. In particular, it doesn't create any connection pools. |
| 143 | 142 | * Those are created when a new {@code Session} is created through |
| 144 | 143 | * {@code connect}. |
| 145 | - * <p> | |
| 144 | + * <p/> | |
| 146 | 145 | * This method has no effect if the cluster is already initialized. |
| 147 | 146 | * |
| 148 | 147 | * @return this {@code Cluster} object. |
| 149 | - * | |
| 150 | 148 | * @throws NoHostAvailableException if no host amongst the contact points |
| 151 | - * can be reached. | |
| 152 | - * @throws AuthenticationException if an authentication error occurs | |
| 153 | - * while contacting the initial contact points. | |
| 154 | - * @throws IllegalStateException if the Cluster was closed prior to calling | |
| 155 | - * this method. This can occur either directly (through {@link #close()} or | |
| 156 | - * {@link #closeAsync()}), or as a result of an error while initializing the | |
| 157 | - * Cluster. | |
| 149 | + * can be reached. | |
| 150 | + * @throws AuthenticationException if an authentication error occurs | |
| 151 | + * while contacting the initial contact points. | |
| 152 | + * @throws IllegalStateException if the Cluster was closed prior to calling | |
| 153 | + * this method. This can occur either directly (through {@link #close()} or | |
| 154 | + * {@link #closeAsync()}), or as a result of an error while initializing the | |
| 155 | + * Cluster. | |
| 158 | 156 | */ |
| 159 | 157 | public Cluster init() { |
| 160 | 158 | this.manager.init(); |
| @@ -163,18 +161,17 @@ | ||
| 163 | 161 | |
| 164 | 162 | /** |
| 165 | 163 | * Build a new cluster based on the provided initializer. |
| 166 | - * <p> | |
| 164 | + * <p/> | |
| 167 | 165 | * Note that for building a cluster pragmatically, Cluster.Builder |
| 168 | 166 | * provides a slightly less verbose shortcut with {@link Builder#build}. |
| 169 | - * <p> | |
| 167 | + * <p/> | |
| 170 | 168 | * Also note that that all the contact points provided by {@code |
| 171 | 169 | * initializer} must share the same port. |
| 172 | 170 | * |
| 173 | 171 | * @param initializer the Cluster.Initializer to use |
| 174 | 172 | * @return the newly created Cluster instance |
| 175 | - * | |
| 176 | 173 | * @throws IllegalArgumentException if the list of contact points provided |
| 177 | - * by {@code initializer} is empty or if not all those contact points have the same port. | |
| 174 | + * by {@code initializer} is empty or if not all those contact points have the same port. | |
| 178 | 175 | */ |
| 179 | 176 | public static Cluster buildFrom(Initializer initializer) { |
| 180 | 177 | return new Cluster(initializer); |
| @@ -182,7 +179,7 @@ | ||
| 182 | 179 | |
| 183 | 180 | /** |
| 184 | 181 | * Creates a new {@link Cluster.Builder} instance. |
| 185 | - * <p> | |
| 182 | + * <p/> | |
| 186 | 183 | * This is a convenience method for {@code new Cluster.Builder()}. |
| 187 | 184 | * |
| 188 | 185 | * @return the new cluster builder. |
| @@ -193,7 +190,7 @@ | ||
| 193 | 190 | |
| 194 | 191 | /** |
| 195 | 192 | * Returns the current version of the driver. |
| 196 | - * <p> | |
| 193 | + * <p/> | |
| 197 | 194 | * This is intended for products that wrap or extend the driver, as a way to check |
| 198 | 195 | * compatibility if end-users override the driver version in their application. |
| 199 | 196 | * |
| @@ -205,16 +202,16 @@ | ||
| 205 | 202 | |
| 206 | 203 | /** |
| 207 | 204 | * Creates a new session on this cluster but does not initialize it. |
| 208 | - * <p> | |
| 205 | + * <p/> | |
| 209 | 206 | * Because this method does not perform any initialization, it cannot fail. |
| 210 | 207 | * The initialization of the session (the connection of the Session to the |
| 211 | 208 | * Cassandra nodes) will occur if either the {@link Session#init} method is |
| 212 | 209 | * called explicitly, or whenever the returned session object is used. |
| 213 | - * <p> | |
| 210 | + * <p/> | |
| 214 | 211 | * Once a session returned by this method gets initialized (see above), it |
| 215 | 212 | * will be set to no keyspace. If you want to set such session to a |
| 216 | 213 | * keyspace, you will have to explicitly execute a 'USE mykeyspace' query. |
| 217 | - * <p> | |
| 214 | + * <p/> | |
| 218 | 215 | * Note that if you do not particularly need to defer initialization, it is |
| 219 | 216 | * simpler to use one of the {@code connect()} method of this class. |
| 220 | 217 | * |
| @@ -227,23 +224,22 @@ | ||
| 227 | 224 | |
| 228 | 225 | /** |
| 229 | 226 | * Creates a new session on this cluster and initialize it. |
| 230 | - * <p> | |
| 227 | + * <p/> | |
| 231 | 228 | * Note that this method will initialize the newly created session, trying |
| 232 | 229 | * to connect to the Cassandra nodes before returning. If you only want to |
| 233 | 230 | * create a Session object without initializing it right away, see |
| 234 | 231 | * {@link #newSession}. |
| 235 | 232 | * |
| 236 | 233 | * @return a new session on this cluster sets to no keyspace. |
| 237 | - * | |
| 238 | 234 | * @throws NoHostAvailableException if the Cluster has not been initialized |
| 239 | - * yet ({@link #init} has not be called and this is the first connect call) | |
| 240 | - * and no host amongst the contact points can be reached. | |
| 241 | - * @throws AuthenticationException if an authentication error occurs while | |
| 242 | - * contacting the initial contact points. | |
| 243 | - * @throws IllegalStateException if the Cluster was closed prior to calling | |
| 244 | - * this method. This can occur either directly (through {@link #close()} or | |
| 245 | - * {@link #closeAsync()}), or as a result of an error while initializing the | |
| 246 | - * Cluster. | |
| 235 | + * yet ({@link #init} has not be called and this is the first connect call) | |
| 236 | + * and no host amongst the contact points can be reached. | |
| 237 | + * @throws AuthenticationException if an authentication error occurs while | |
| 238 | + * contacting the initial contact points. | |
| 239 | + * @throws IllegalStateException if the Cluster was closed prior to calling | |
| 240 | + * this method. This can occur either directly (through {@link #close()} or | |
| 241 | + * {@link #closeAsync()}), or as a result of an error while initializing the | |
| 242 | + * Cluster. | |
| 247 | 243 | */ |
| 248 | 244 | public Session connect() { |
| 249 | 245 | try { |
| @@ -256,28 +252,27 @@ | ||
| 256 | 252 | /** |
| 257 | 253 | * Creates a new session on this cluster, initialize it and sets the |
| 258 | 254 | * keyspace to the provided one. |
| 259 | - * <p> | |
| 255 | + * <p/> | |
| 260 | 256 | * Note that this method will initialize the newly created session, trying |
| 261 | 257 | * to connect to the Cassandra nodes before returning. If you only want to |
| 262 | 258 | * create a Session object without initializing it right away, see |
| 263 | 259 | * {@link #newSession}. |
| 264 | 260 | * |
| 265 | 261 | * @param keyspace The name of the keyspace to use for the created |
| 266 | - * {@code Session}. | |
| 262 | + * {@code Session}. | |
| 267 | 263 | * @return a new session on this cluster sets to keyspace |
| 268 | 264 | * {@code keyspaceName}. |
| 269 | - * | |
| 270 | 265 | * @throws NoHostAvailableException if the Cluster has not been initialized |
| 271 | - * yet ({@link #init} has not be called and this is the first connect call) | |
| 272 | - * and no host amongst the contact points can be reached, or if no host can | |
| 273 | - * be contacted to set the {@code keyspace}. | |
| 274 | - * @throws AuthenticationException if an authentication error occurs while | |
| 275 | - * contacting the initial contact points. | |
| 276 | - * @throws InvalidQueryException if the keyspace does not exists. | |
| 277 | - * @throws IllegalStateException if the Cluster was closed prior to calling | |
| 278 | - * this method. This can occur either directly (through {@link #close()} or | |
| 279 | - * {@link #closeAsync()}), or as a result of an error while initializing the | |
| 280 | - * Cluster. | |
| 266 | + * yet ({@link #init} has not be called and this is the first connect call) | |
| 267 | + * and no host amongst the contact points can be reached, or if no host can | |
| 268 | + * be contacted to set the {@code keyspace}. | |
| 269 | + * @throws AuthenticationException if an authentication error occurs while | |
| 270 | + * contacting the initial contact points. | |
| 271 | + * @throws InvalidQueryException if the keyspace does not exists. | |
| 272 | + * @throws IllegalStateException if the Cluster was closed prior to calling | |
| 273 | + * this method. This can occur either directly (through {@link #close()} or | |
| 274 | + * {@link #closeAsync()}), or as a result of an error while initializing the | |
| 275 | + * Cluster. | |
| 281 | 276 | */ |
| 282 | 277 | public Session connect(String keyspace) { |
| 283 | 278 | try { |
| @@ -289,23 +284,20 @@ | ||
| 289 | 284 | |
| 290 | 285 | /** |
| 291 | 286 | * Creates a new session on this cluster and initializes it asynchronously. |
| 292 | - * | |
| 287 | + * <p/> | |
| 293 | 288 | * This will also initialize the {@code Cluster} if needed; note that cluster |
| 294 | 289 | * initialization happens synchronously on the thread that called this method. |
| 295 | 290 | * Therefore it is recommended to initialize the cluster at application |
| 296 | 291 | * startup, and not rely on this method to do it. |
| 297 | 292 | * |
| 298 | 293 | * @return a future that will complete when the session is fully initialized. |
| 299 | - * | |
| 300 | 294 | * @throws NoHostAvailableException if the Cluster has not been initialized |
| 301 | - * yet ({@link #init} has not been called and this is the first connect call) | |
| 302 | - * and no host amongst the contact points can be reached. | |
| 303 | - * | |
| 304 | - * @throws IllegalStateException if the Cluster was closed prior to calling | |
| 305 | - * this method. This can occur either directly (through {@link #close()} or | |
| 306 | - * {@link #closeAsync()}), or as a result of an error while initializing the | |
| 307 | - * Cluster. | |
| 308 | - * | |
| 295 | + * yet ({@link #init} has not been called and this is the first connect call) | |
| 296 | + * and no host amongst the contact points can be reached. | |
| 297 | + * @throws IllegalStateException if the Cluster was closed prior to calling | |
| 298 | + * this method. This can occur either directly (through {@link #close()} or | |
| 299 | + * {@link #closeAsync()}), or as a result of an error while initializing the | |
| 300 | + * Cluster. | |
| 309 | 301 | * @see #connect() |
| 310 | 302 | */ |
| 311 | 303 | public ListenableFuture<Session> connectAsync() { |
| @@ -315,24 +307,22 @@ | ||
| 315 | 307 | /** |
| 316 | 308 | * Creates a new session on this cluster, and initializes it to the given |
| 317 | 309 | * keyspace asynchronously. |
| 318 | - * | |
| 310 | + * <p/> | |
| 319 | 311 | * This will also initialize the {@code Cluster} if needed; note that cluster |
| 320 | 312 | * initialization happens synchronously on the thread that called this method. |
| 321 | 313 | * Therefore it is recommended to initialize the cluster at application |
| 322 | 314 | * startup, and not rely on this method to do it. |
| 323 | 315 | * |
| 324 | 316 | * @param keyspace The name of the keyspace to use for the created |
| 325 | - * {@code Session}. | |
| 317 | + * {@code Session}. | |
| 326 | 318 | * @return a future that will complete when the session is fully initialized. |
| 327 | - * | |
| 328 | 319 | * @throws NoHostAvailableException if the Cluster has not been initialized |
| 329 | - * yet ({@link #init} has not been called and this is the first connect call) | |
| 330 | - * and no host amongst the contact points can be reached. | |
| 331 | - * | |
| 332 | - * @throws IllegalStateException if the Cluster was closed prior to calling | |
| 333 | - * this method. This can occur either directly (through {@link #close()} or | |
| 334 | - * {@link #closeAsync()}), or as a result of an error while initializing the | |
| 335 | - * Cluster. | |
| 320 | + * yet ({@link #init} has not been called and this is the first connect call) | |
| 321 | + * and no host amongst the contact points can be reached. | |
| 322 | + * @throws IllegalStateException if the Cluster was closed prior to calling | |
| 323 | + * this method. This can occur either directly (through {@link #close()} or | |
| 324 | + * {@link #closeAsync()}), or as a result of an error while initializing the | |
| 325 | + * Cluster. | |
| 336 | 326 | */ |
| 337 | 327 | public ListenableFuture<Session> connectAsync(final String keyspace) { |
| 338 | 328 | checkNotClosed(manager); |
| @@ -360,7 +350,7 @@ | ||
| 360 | 350 | |
| 361 | 351 | /** |
| 362 | 352 | * The name of this cluster object. |
| 363 | - * <p> | |
| 353 | + * <p/> | |
| 364 | 354 | * Note that this is not the Cassandra cluster name, but rather a name |
| 365 | 355 | * assigned to this Cluster object. Currently, that name is only used |
| 366 | 356 | * for one purpose: to distinguish exposed JMX metrics when multiple |
| @@ -378,7 +368,7 @@ | ||
| 378 | 368 | |
| 379 | 369 | /** |
| 380 | 370 | * Returns read-only metadata on the connected cluster. |
| 381 | - * <p> | |
| 371 | + * <p/> | |
| 382 | 372 | * This includes the known nodes with their status as seen by the driver, |
| 383 | 373 | * as well as the schema definitions. Since this return metadata on the |
| 384 | 374 | * connected cluster, this method may trigger the creation of a connection |
| @@ -386,15 +376,14 @@ | ||
| 386 | 376 | * has been called yet). |
| 387 | 377 | * |
| 388 | 378 | * @return the cluster metadata. |
| 389 | - * | |
| 390 | 379 | * @throws NoHostAvailableException if the Cluster has not been initialized yet |
| 391 | - * and no host amongst the contact points can be reached. | |
| 392 | - * @throws AuthenticationException if an authentication error occurs | |
| 393 | - * while contacting the initial contact points. | |
| 394 | - * @throws IllegalStateException if the Cluster was closed prior to calling | |
| 395 | - * this method. This can occur either directly (through {@link #close()} or | |
| 396 | - * {@link #closeAsync()}), or as a result of an error while initializing the | |
| 397 | - * Cluster. | |
| 380 | + * and no host amongst the contact points can be reached. | |
| 381 | + * @throws AuthenticationException if an authentication error occurs | |
| 382 | + * while contacting the initial contact points. | |
| 383 | + * @throws IllegalStateException if the Cluster was closed prior to calling | |
| 384 | + * this method. This can occur either directly (through {@link #close()} or | |
| 385 | + * {@link #closeAsync()}), or as a result of an error while initializing the | |
| 386 | + * Cluster. | |
| 398 | 387 | */ |
| 399 | 388 | public Metadata getMetadata() { |
| 400 | 389 | manager.init(); |
| @@ -425,9 +414,9 @@ | ||
| 425 | 414 | /** |
| 426 | 415 | * Registers the provided listener to be notified on hosts |
| 427 | 416 | * up/down/added/removed events. |
| 428 | - * <p> | |
| 417 | + * <p/> | |
| 429 | 418 | * Registering the same listener multiple times is a no-op. |
| 430 | - * <p> | |
| 419 | + * <p/> | |
| 431 | 420 | * Note that while {@link LoadBalancingPolicy} implements |
| 432 | 421 | * {@code Host.StateListener}, the configured load balancing does not |
| 433 | 422 | * need to (and should not) be registered through this method to |
| @@ -444,7 +433,7 @@ | ||
| 444 | 433 | |
| 445 | 434 | /** |
| 446 | 435 | * Unregisters the provided listener from being notified on hosts events. |
| 447 | - * <p> | |
| 436 | + * <p/> | |
| 448 | 437 | * This method is a no-op if {@code listener} hadn't previously be |
| 449 | 438 | * registered against this Cluster. |
| 450 | 439 | * |
| @@ -460,13 +449,13 @@ | ||
| 460 | 449 | /** |
| 461 | 450 | * Registers the provided tracker to be updated with hosts read |
| 462 | 451 | * latencies. |
| 463 | - * <p> | |
| 452 | + * <p/> | |
| 464 | 453 | * Registering the same listener multiple times is a no-op. |
| 465 | - * <p> | |
| 454 | + * <p/> | |
| 466 | 455 | * Be wary that the registered tracker {@code update} method will be call |
| 467 | 456 | * very frequently (at the end of every query to a Cassandra host) and |
| 468 | 457 | * should thus not be costly. |
| 469 | - * <p> | |
| 458 | + * <p/> | |
| 470 | 459 | * The main use case for a {@code LatencyTracker} is so |
| 471 | 460 | * {@link LoadBalancingPolicy} can implement latency awareness |
| 472 | 461 | * Typically, {@link LatencyAwarePolicy} registers it's own internal |
| @@ -485,7 +474,7 @@ | ||
| 485 | 474 | /** |
| 486 | 475 | * Unregisters the provided latency tracking from being updated |
| 487 | 476 | * with host read latencies. |
| 488 | - * <p> | |
| 477 | + * <p/> | |
| 489 | 478 | * This method is a no-op if {@code tracker} hadn't previously be |
| 490 | 479 | * registered against this Cluster. |
| 491 | 480 | * |
| @@ -500,7 +489,7 @@ | ||
| 500 | 489 | |
| 501 | 490 | /** |
| 502 | 491 | * Registers the provided listener to be updated with schema change events. |
| 503 | - * <p> | |
| 492 | + * <p/> | |
| 504 | 493 | * Registering the same listener multiple times is a no-op. |
| 505 | 494 | * |
| 506 | 495 | * @param listener the new {@link SchemaChangeListener} to register. |
| @@ -516,7 +505,7 @@ | ||
| 516 | 505 | /** |
| 517 | 506 | * Unregisters the provided schema change listener from being updated |
| 518 | 507 | * with schema change events. |
| 519 | - * <p> | |
| 508 | + * <p/> | |
| 520 | 509 | * This method is a no-op if {@code listener} hadn't previously be |
| 521 | 510 | * registered against this Cluster. |
| 522 | 511 | * |
| @@ -532,17 +521,17 @@ | ||
| 532 | 521 | |
| 533 | 522 | /** |
| 534 | 523 | * Initiates a shutdown of this cluster instance. |
| 535 | - * <p> | |
| 524 | + * <p/> | |
| 536 | 525 | * This method is asynchronous and return a future on the completion |
| 537 | 526 | * of the shutdown process. As soon a the cluster is shutdown, no |
| 538 | 527 | * new request will be accepted, but already submitted queries are |
| 539 | 528 | * allowed to complete. This method closes all connections from all |
| 540 | 529 | * sessions and reclaims all resources used by this Cluster |
| 541 | 530 | * instance. |
| 542 | - * <p> | |
| 531 | + * <p/> | |
| 543 | 532 | * If for some reason you wish to expedite this process, the |
| 544 | 533 | * {@link CloseFuture#force} can be called on the result future. |
| 545 | - * <p> | |
| 534 | + * <p/> | |
| 546 | 535 | * This method has no particular effect if the cluster was already closed |
| 547 | 536 | * (in which case the returned future will return immediately). |
| 548 | 537 | * |
| @@ -555,7 +544,7 @@ | ||
| 555 | 544 | /** |
| 556 | 545 | * Initiates a shutdown of this cluster instance and blocks until |
| 557 | 546 | * that shutdown completes. |
| 558 | - * <p> | |
| 547 | + * <p/> | |
| 559 | 548 | * This method is a shortcut for {@code closeAsync().get()}. |
| 560 | 549 | */ |
| 561 | 550 | public void close() { |
| @@ -570,7 +559,7 @@ | ||
| 570 | 559 | |
| 571 | 560 | /** |
| 572 | 561 | * Whether this Cluster instance has been closed. |
| 573 | - * <p> | |
| 562 | + * <p/> | |
| 574 | 563 | * Note that this method returns true as soon as one of the close methods |
| 575 | 564 | * ({@link #closeAsync} or {@link #close}) has been called, it does not guarantee |
| 576 | 565 | * that the closing is done. If you want to guarantee that the closing is done, |
| @@ -591,11 +580,11 @@ | ||
| 591 | 580 | |
| 592 | 581 | /** |
| 593 | 582 | * Initializer for {@link Cluster} instances. |
| 594 | - * <p> | |
| 583 | + * <p/> | |
| 595 | 584 | * If you want to create a new {@code Cluster} instance programmatically, |
| 596 | 585 | * then it is advised to use {@link Cluster.Builder} which can be obtained from the |
| 597 | 586 | * {@link Cluster#builder} method. |
| 598 | - * <p> | |
| 587 | + * <p/> | |
| 599 | 588 | * But it is also possible to implement a custom {@code Initializer} that |
| 600 | 589 | * retrieves initialization from a web-service or from a configuration file. |
| 601 | 590 | */ |
| @@ -603,7 +592,7 @@ | ||
| 603 | 592 | |
| 604 | 593 | /** |
| 605 | 594 | * An optional name for the created cluster. |
| 606 | - * <p> | |
| 595 | + * <p/> | |
| 607 | 596 | * Such name is optional (a default name will be created otherwise) and is currently |
| 608 | 597 | * only use for JMX reporting of metrics. See {@link Cluster#getClusterName} for more |
| 609 | 598 | * information. |
| @@ -623,15 +612,15 @@ | ||
| 623 | 612 | |
| 624 | 613 | /** |
| 625 | 614 | * The configuration to use for the new cluster. |
| 626 | - * <p> | |
| 615 | + * <p/> | |
| 627 | 616 | * Note that some configuration can be modified after the cluster |
| 628 | 617 | * initialization but some others cannot. In particular, the ones that |
| 629 | 618 | * cannot be changed afterwards includes: |
| 630 | 619 | * <ul> |
| 631 | - * <li>the port use to connect to Cassandra nodes (see {@link ProtocolOptions}).</li> | |
| 632 | - * <li>the policies used (see {@link Policies}).</li> | |
| 633 | - * <li>the authentication info provided (see {@link Configuration}).</li> | |
| 634 | - * <li>whether metrics are enabled (see {@link Configuration}).</li> | |
| 620 | + * <li>the port use to connect to Cassandra nodes (see {@link ProtocolOptions}).</li> | |
| 621 | + * <li>the policies used (see {@link Policies}).</li> | |
| 622 | + * <li>the authentication info provided (see {@link Configuration}).</li> | |
| 623 | + * <li>whether metrics are enabled (see {@link Configuration}).</li> | |
| 635 | 624 | * </ul> |
| 636 | 625 | * |
| 637 | 626 | * @return the configuration to use for the new cluster. |
| @@ -640,7 +629,7 @@ | ||
| 640 | 629 | |
| 641 | 630 | /** |
| 642 | 631 | * Optional listeners to register against the newly created cluster. |
| 643 | - * <p> | |
| 632 | + * <p/> | |
| 644 | 633 | * Note that contrary to listeners registered post Cluster creation, |
| 645 | 634 | * the listeners returned by this method will see {@link Host.StateListener#onAdd} |
| 646 | 635 | * events for the initial contact points. |
| @@ -702,11 +691,11 @@ | ||
| 702 | 691 | |
| 703 | 692 | /** |
| 704 | 693 | * An optional name for the create cluster. |
| 705 | - * <p> | |
| 694 | + * <p/> | |
| 706 | 695 | * Note: this is not related to the Cassandra cluster name (though you |
| 707 | 696 | * are free to provide the same name). See {@link Cluster#getClusterName} for |
| 708 | 697 | * details. |
| 709 | - * <p> | |
| 698 | + * <p/> | |
| 710 | 699 | * If you use this method and create more than one Cluster instance in the |
| 711 | 700 | * same JVM (which should be avoided unless you need to connect to multiple |
| 712 | 701 | * Cassandra clusters), you should make sure each Cluster instance get a |
| @@ -722,7 +711,7 @@ | ||
| 722 | 711 | |
| 723 | 712 | /** |
| 724 | 713 | * The port to use to connect to the Cassandra host. |
| 725 | - * <p> | |
| 714 | + * <p/> | |
| 726 | 715 | * If not set through this method, the default port (9042) will be used |
| 727 | 716 | * instead. |
| 728 | 717 | * |
| @@ -736,12 +725,11 @@ | ||
| 736 | 725 | |
| 737 | 726 | /** |
| 738 | 727 | * Sets the maximum time to wait for schema agreement before returning from a DDL query. |
| 739 | - * <p> | |
| 728 | + * <p/> | |
| 740 | 729 | * If not set through this method, the default value (10 seconds) will be used. |
| 741 | 730 | * |
| 742 | 731 | * @param maxSchemaAgreementWaitSeconds the new value to set. |
| 743 | 732 | * @return this Builder. |
| 744 | - * | |
| 745 | 733 | * @throws IllegalStateException if the provided value is zero or less. |
| 746 | 734 | */ |
| 747 | 735 | public Builder withMaxSchemaAgreementWaitSeconds(int maxSchemaAgreementWaitSeconds) { |
| @@ -754,12 +742,12 @@ | ||
| 754 | 742 | |
| 755 | 743 | /** |
| 756 | 744 | * The native protocol version to use. |
| 757 | - * <p> | |
| 745 | + * <p/> | |
| 758 | 746 | * The driver supports both version 1 and 2 of the native protocol. Version 2 |
| 759 | 747 | * of the protocol has more features and should be preferred, but it is only |
| 760 | 748 | * supported by Cassandra 2.0 and above, so you will have to use version 1 with |
| 761 | 749 | * Cassandra 1.2 nodes. |
| 762 | - * <p> | |
| 750 | + * <p/> | |
| 763 | 751 | * By default, the driver will "auto-detect" which protocol version it can use |
| 764 | 752 | * when connecting to the first node. More precisely, it will try the version |
| 765 | 753 | * 2 first and will fallback to version 1 if it is not supported by that first |
| @@ -767,7 +755,7 @@ | ||
| 767 | 755 | * it won't change: if the first node the driver connects to is a Cassandra 1.2 |
| 768 | 756 | * node and auto-detection is used (the default), then the native protocol |
| 769 | 757 | * version 1 will be use for the lifetime of the Cluster instance. |
| 770 | - * <p> | |
| 758 | + * <p/> | |
| 771 | 759 | * This method allows to force the use of a particular protocol version. Forcing |
| 772 | 760 | * version 1 is always fine since all Cassandra version (at least all those |
| 773 | 761 | * supporting the native protocol in the first place) so far supports it. However, |
| @@ -778,22 +766,21 @@ | ||
| 778 | 766 | * an UnsupportedFeatureException). Using the protocol version 1 should thus |
| 779 | 767 | * only be considered when using Cassandra 1.2, until nodes have been upgraded |
| 780 | 768 | * to Cassandra 2.0. |
| 781 | - * <p> | |
| 769 | + * <p/> | |
| 782 | 770 | * If version 2 of the protocol is used, then Cassandra 1.2 nodes will be ignored |
| 783 | 771 | * (the driver won't connect to them). |
| 784 | - * <p> | |
| 772 | + * <p/> | |
| 785 | 773 | * The default behavior (auto-detection) is fine in almost all case, but you may |
| 786 | 774 | * want to force a particular version if you have a Cassandra cluster with mixed |
| 787 | 775 | * 1.2/2.0 nodes (i.e. during a Cassandra upgrade). |
| 788 | 776 | * |
| 789 | 777 | * @param version the native protocol version to use. The versions supported by |
| 790 | - * this driver are version 1 and 2. Negative values are also supported to trigger | |
| 791 | - * auto-detection (see above) but this is the default (so you don't have to call | |
| 792 | - * this method for that behavior). | |
| 778 | + * this driver are version 1 and 2. Negative values are also supported to trigger | |
| 779 | + * auto-detection (see above) but this is the default (so you don't have to call | |
| 780 | + * this method for that behavior). | |
| 793 | 781 | * @return this Builder. |
| 794 | - * | |
| 795 | 782 | * @throws IllegalArgumentException if {@code version} is neither 1, 2 or a |
| 796 | - * negative value. | |
| 783 | + * negative value. | |
| 797 | 784 | */ |
| 798 | 785 | public Builder withProtocolVersion(int version) { |
| 799 | 786 | if (version >= 0 && version != 1 && version != 2) |
| @@ -804,14 +791,14 @@ | ||
| 804 | 791 | |
| 805 | 792 | /** |
| 806 | 793 | * Adds a contact point. |
| 807 | - * <p> | |
| 794 | + * <p/> | |
| 808 | 795 | * Contact points are addresses of Cassandra nodes that the driver uses |
| 809 | 796 | * to discover the cluster topology. Only one contact point is required |
| 810 | 797 | * (the driver will retrieve the address of the other nodes |
| 811 | 798 | * automatically), but it is usually a good idea to provide more than |
| 812 | 799 | * one contact point, because if that single contact point is unavailable, |
| 813 | 800 | * the driver cannot initialize itself correctly. |
| 814 | - * <p> | |
| 801 | + * <p/> | |
| 815 | 802 | * Note that by default (that is, unless you use the {@link #withLoadBalancingPolicy}) |
| 816 | 803 | * method of this builder), the first succesfully contacted host will be use |
| 817 | 804 | * to define the local data-center for the client. If follows that if you are |
| @@ -821,11 +808,10 @@ | ||
| 821 | 808 | * |
| 822 | 809 | * @param address the address of the node to connect to |
| 823 | 810 | * @return this Builder. |
| 824 | - * | |
| 825 | 811 | * @throws IllegalArgumentException if no IP address for {@code address} |
| 826 | - * could be found | |
| 827 | - * @throws SecurityException if a security manager is present and | |
| 828 | - * permission to resolve the host name is denied. | |
| 812 | + * could be found | |
| 813 | + * @throws SecurityException if a security manager is present and | |
| 814 | + * permission to resolve the host name is denied. | |
| 829 | 815 | */ |
| 830 | 816 | public Builder addContactPoint(String address) { |
| 831 | 817 | // We explicitely check for nulls because InetAdress.getByName() will happily |
| @@ -844,18 +830,16 @@ | ||
| 844 | 830 | |
| 845 | 831 | /** |
| 846 | 832 | * Adds contact points. |
| 847 | - * <p> | |
| 833 | + * <p/> | |
| 848 | 834 | * See {@link Builder#addContactPoint} for more details on contact |
| 849 | 835 | * points. |
| 850 | 836 | * |
| 851 | 837 | * @param addresses addresses of the nodes to add as contact point. |
| 852 | 838 | * @return this Builder. |
| 853 | - * | |
| 854 | 839 | * @throws IllegalArgumentException if no IP address for at least one |
| 855 | - * of {@code addresses} could be found | |
| 856 | - * @throws SecurityException if a security manager is present and | |
| 857 | - * permission to resolve the host name is denied. | |
| 858 | - * | |
| 840 | + * of {@code addresses} could be found | |
| 841 | + * @throws SecurityException if a security manager is present and | |
| 842 | + * permission to resolve the host name is denied. | |
| 859 | 843 | * @see Builder#addContactPoint |
| 860 | 844 | */ |
| 861 | 845 | public Builder addContactPoints(String... addresses) { |
| @@ -866,19 +850,17 @@ | ||
| 866 | 850 | |
| 867 | 851 | /** |
| 868 | 852 | * Adds a contact point - or many if it host resolves to multiple <code>InetAddress</code>s (A records). |
| 869 | - * <p> | |
| 870 | - * | |
| 853 | + * <p/> | |
| 854 | + * <p/> | |
| 871 | 855 | * If the host name points to a dns records with multiple a-records, all InetAddresses |
| 872 | 856 | * returned will be used. Make sure that all resulting <code>InetAddress</code>s returned |
| 873 | 857 | * points to the same cluster and datacenter. |
| 874 | - * <p> | |
| 858 | + * <p/> | |
| 875 | 859 | * See {@link Builder#addContactPoint} for more details on contact |
| 876 | 860 | * points and thrown exceptions |
| 877 | 861 | * |
| 878 | 862 | * @param address address of the nodes to look up InetAddresses from to add as contact points. |
| 879 | 863 | * @return this Builder. |
| 880 | - * | |
| 881 | - * | |
| 882 | 864 | * @see Builder#addContactPoint |
| 883 | 865 | */ |
| 884 | 866 | public Builder addContactPoints(String address) { |
| @@ -898,13 +880,12 @@ | ||
| 898 | 880 | |
| 899 | 881 | /** |
| 900 | 882 | * Adds contact points. |
| 901 | - * <p> | |
| 883 | + * <p/> | |
| 902 | 884 | * See {@link Builder#addContactPoint} for more details on contact |
| 903 | 885 | * points. |
| 904 | 886 | * |
| 905 | 887 | * @param addresses addresses of the nodes to add as contact point. |
| 906 | 888 | * @return this Builder. |
| 907 | - * | |
| 908 | 889 | * @see Builder#addContactPoint |
| 909 | 890 | */ |
| 910 | 891 | public Builder addContactPoints(InetAddress... addresses) { |
| @@ -914,13 +895,12 @@ | ||
| 914 | 895 | |
| 915 | 896 | /** |
| 916 | 897 | * Adds contact points. |
| 917 | - * | |
| 898 | + * <p/> | |
| 918 | 899 | * See {@link Builder#addContactPoint} for more details on contact |
| 919 | 900 | * points. |
| 920 | 901 | * |
| 921 | 902 | * @param addresses addresses of the nodes to add as contact point |
| 922 | 903 | * @return this Builder |
| 923 | - * | |
| 924 | 904 | * @see Builder#addContactPoint |
| 925 | 905 | */ |
| 926 | 906 | public Builder addContactPoints(Collection<InetAddress> addresses) { |
| @@ -930,7 +910,7 @@ | ||
| 930 | 910 | |
| 931 | 911 | /** |
| 932 | 912 | * Adds contact points. |
| 933 | - * <p> | |
| 913 | + * <p/> | |
| 934 | 914 | * See {@link Builder#addContactPoint} for more details on contact |
| 935 | 915 | * points. Contrarily to other {@code addContactPoints} methods, this method |
| 936 | 916 | * allow to provide a different port for each contact points. Since Cassandra |
| @@ -947,7 +927,6 @@ | ||
| 947 | 927 | * |
| 948 | 928 | * @param addresses addresses of the nodes to add as contact point |
| 949 | 929 | * @return this Builder |
| 950 | - * | |
| 951 | 930 | * @see Builder#addContactPoint |
| 952 | 931 | */ |
| 953 | 932 | public Builder addContactPointsWithPorts(Collection<InetSocketAddress> addresses) { |
| @@ -957,7 +936,7 @@ | ||
| 957 | 936 | |
| 958 | 937 | /** |
| 959 | 938 | * Configures the load balancing policy to use for the new cluster. |
| 960 | - * <p> | |
| 939 | + * <p/> | |
| 961 | 940 | * If no load balancing policy is set through this method, |
| 962 | 941 | * {@link Policies#defaultLoadBalancingPolicy} will be used instead. |
| 963 | 942 | * |
| @@ -971,7 +950,7 @@ | ||
| 971 | 950 | |
| 972 | 951 | /** |
| 973 | 952 | * Configures the reconnection policy to use for the new cluster. |
| 974 | - * <p> | |
| 953 | + * <p/> | |
| 975 | 954 | * If no reconnection policy is set through this method, |
| 976 | 955 | * {@link Policies#DEFAULT_RECONNECTION_POLICY} will be used instead. |
| 977 | 956 | * |
| @@ -985,7 +964,7 @@ | ||
| 985 | 964 | |
| 986 | 965 | /** |
| 987 | 966 | * Configures the retry policy to use for the new cluster. |
| 988 | - * <p> | |
| 967 | + * <p/> | |
| 989 | 968 | * If no retry policy is set through this method, |
| 990 | 969 | * {@link Policies#DEFAULT_RETRY_POLICY} will be used instead. |
| 991 | 970 | * |
| @@ -999,7 +978,7 @@ | ||
| 999 | 978 | |
| 1000 | 979 | /** |
| 1001 | 980 | * Configures the address translater to use for the new cluster. |
| 1002 | - * <p> | |
| 981 | + * <p/> | |
| 1003 | 982 | * See {@link AddressTranslater} for more detail on address translation, |
| 1004 | 983 | * but the default translater, {@link IdentityTranslater}, should be |
| 1005 | 984 | * correct in most cases. If unsure, stick to the default. |
| @@ -1014,7 +993,7 @@ | ||
| 1014 | 993 | |
| 1015 | 994 | /** |
| 1016 | 995 | * Configures the speculative execution policy to use for the new cluster. |
| 1017 | - * <p> | |
| 996 | + * <p/> | |
| 1018 | 997 | * If no policy is set through this method, {@link Policies#defaultSpeculativeExecutionPolicy()} |
| 1019 | 998 | * will be used instead. |
| 1020 | 999 | * |
| @@ -1028,7 +1007,7 @@ | ||
| 1028 | 1007 | |
| 1029 | 1008 | /** |
| 1030 | 1009 | * Uses the provided credentials when connecting to Cassandra hosts. |
| 1031 | - * <p> | |
| 1010 | + * <p/> | |
| 1032 | 1011 | * This should be used if the Cassandra cluster has been configured to |
| 1033 | 1012 | * use the {@code PasswordAuthenticator}. If the the default {@code |
| 1034 | 1013 | * AllowAllAuthenticator} is used instead, using this method has no |
| @@ -1046,14 +1025,14 @@ | ||
| 1046 | 1025 | /** |
| 1047 | 1026 | * Use the specified AuthProvider when connecting to Cassandra |
| 1048 | 1027 | * hosts. |
| 1049 | - * <p> | |
| 1028 | + * <p/> | |
| 1050 | 1029 | * Use this method when a custom authentication scheme is in place. |
| 1051 | 1030 | * You shouldn't call both this method and {@code withCredentials} |
| 1052 | 1031 | * on the same {@code Builder} instance as one will supersede the |
| 1053 | 1032 | * other |
| 1054 | 1033 | * |
| 1055 | 1034 | * @param authProvider the {@link AuthProvider} to use to login to |
| 1056 | - * Cassandra hosts. | |
| 1035 | + * Cassandra hosts. | |
| 1057 | 1036 | * @return this Builder |
| 1058 | 1037 | */ |
| 1059 | 1038 | public Builder withAuthProvider(AuthProvider authProvider) { |
| @@ -1066,7 +1045,6 @@ | ||
| 1066 | 1045 | * |
| 1067 | 1046 | * @param compression the compression to set. |
| 1068 | 1047 | * @return this Builder. |
| 1069 | - * | |
| 1070 | 1048 | * @see ProtocolOptions.Compression |
| 1071 | 1049 | */ |
| 1072 | 1050 | public Builder withCompression(ProtocolOptions.Compression compression) { |
| @@ -1087,10 +1065,10 @@ | ||
| 1087 | 1065 | |
| 1088 | 1066 | /** |
| 1089 | 1067 | * Enables the use of SSL for the created {@code Cluster}. |
| 1090 | - * <p> | |
| 1068 | + * <p/> | |
| 1091 | 1069 | * Calling this method will use default SSL options (see {@link SSLOptions#SSLOptions()}). |
| 1092 | 1070 | * This is thus a shortcut for {@code withSSL(new SSLOptions())}. |
| 1093 | - * <p> | |
| 1071 | + * <p/> | |
| 1094 | 1072 | * Note that if SSL is enabled, the driver will not connect to any |
| 1095 | 1073 | * Cassandra nodes that doesn't have SSL enabled and it is strongly |
| 1096 | 1074 | * advised to enable SSL on every Cassandra node if you plan on using |
| @@ -1107,7 +1085,6 @@ | ||
| 1107 | 1085 | * Enable the use of SSL for the created {@code Cluster} using the provided options. |
| 1108 | 1086 | * |
| 1109 | 1087 | * @param sslOptions the SSL options to use. |
| 1110 | - * | |
| 1111 | 1088 | * @return this builder. |
| 1112 | 1089 | */ |
| 1113 | 1090 | public Builder withSSL(SSLOptions sslOptions) { |
| @@ -1117,7 +1094,7 @@ | ||
| 1117 | 1094 | |
| 1118 | 1095 | /** |
| 1119 | 1096 | * Register the provided listeners in the newly created cluster. |
| 1120 | - * <p> | |
| 1097 | + * <p/> | |
| 1121 | 1098 | * Note: repeated calls to this method will override the previous ones. |
| 1122 | 1099 | * |
| 1123 | 1100 | * @param listeners the listeners to register. |
| @@ -1130,7 +1107,7 @@ | ||
| 1130 | 1107 | |
| 1131 | 1108 | /** |
| 1132 | 1109 | * Disables JMX reporting of the metrics. |
| 1133 | - * <p> | |
| 1110 | + * <p/> | |
| 1134 | 1111 | * JMX reporting is enabled by default (see {@link Metrics}) but can be |
| 1135 | 1112 | * disabled using this option. If metrics are disabled, this is a |
| 1136 | 1113 | * no-op. |
| @@ -1144,7 +1121,7 @@ | ||
| 1144 | 1121 | |
| 1145 | 1122 | /** |
| 1146 | 1123 | * Sets the PoolingOptions to use for the newly created Cluster. |
| 1147 | - * <p> | |
| 1124 | + * <p/> | |
| 1148 | 1125 | * If no pooling options are set through this method, default pooling |
| 1149 | 1126 | * options will be used. |
| 1150 | 1127 | * |
| @@ -1158,7 +1135,7 @@ | ||
| 1158 | 1135 | |
| 1159 | 1136 | /** |
| 1160 | 1137 | * Sets the SocketOptions to use for the newly created Cluster. |
| 1161 | - * <p> | |
| 1138 | + * <p/> | |
| 1162 | 1139 | * If no socket options are set through this method, default socket |
| 1163 | 1140 | * options will be used. |
| 1164 | 1141 | * |
| @@ -1172,7 +1149,7 @@ | ||
| 1172 | 1149 | |
| 1173 | 1150 | /** |
| 1174 | 1151 | * Sets the QueryOptions to use for the newly created Cluster. |
| 1175 | - * <p> | |
| 1152 | + * <p/> | |
| 1176 | 1153 | * If no query options are set through this method, default query |
| 1177 | 1154 | * options will be used. |
| 1178 | 1155 | * |
| @@ -1186,7 +1163,7 @@ | ||
| 1186 | 1163 | |
| 1187 | 1164 | /** |
| 1188 | 1165 | * Set the {@link NettyOptions} to use for the newly created Cluster. |
| 1189 | - * <p> | |
| 1166 | + * <p/> | |
| 1190 | 1167 | * If no Netty options are set through this method, {@link NettyOptions#DEFAULT_INSTANCE} |
| 1191 | 1168 | * will be used as a default value, which means that no customization will be applied. |
| 1192 | 1169 | * |
| @@ -1200,7 +1177,7 @@ | ||
| 1200 | 1177 | |
| 1201 | 1178 | /** |
| 1202 | 1179 | * The configuration that will be used for the new cluster. |
| 1203 | - * <p> | |
| 1180 | + * <p/> | |
| 1204 | 1181 | * You <b>should not</b> modify this object directly because changes made |
| 1205 | 1182 | * to the returned object may not be used by the cluster build. |
| 1206 | 1183 | * Instead, you should use the other methods of this {@code Builder}. |
| @@ -1210,19 +1187,19 @@ | ||
| 1210 | 1187 | @Override |
| 1211 | 1188 | public Configuration getConfiguration() { |
| 1212 | 1189 | Policies policies = new Policies( |
| 1213 | - loadBalancingPolicy == null ? Policies.defaultLoadBalancingPolicy() : loadBalancingPolicy, | |
| 1214 | - Objects.firstNonNull(reconnectionPolicy, Policies.defaultReconnectionPolicy()), | |
| 1215 | - Objects.firstNonNull(retryPolicy, Policies.defaultRetryPolicy()), | |
| 1216 | - Objects.firstNonNull(addressTranslater, Policies.defaultAddressTranslater()), | |
| 1217 | - Objects.firstNonNull(speculativeExecutionPolicy, Policies.defaultSpeculativeExecutionPolicy()) | |
| 1190 | + loadBalancingPolicy == null ? Policies.defaultLoadBalancingPolicy() : loadBalancingPolicy, | |
| 1191 | + Objects.firstNonNull(reconnectionPolicy, Policies.defaultReconnectionPolicy()), | |
| 1192 | + Objects.firstNonNull(retryPolicy, Policies.defaultRetryPolicy()), | |
| 1193 | + Objects.firstNonNull(addressTranslater, Policies.defaultAddressTranslater()), | |
| 1194 | + Objects.firstNonNull(speculativeExecutionPolicy, Policies.defaultSpeculativeExecutionPolicy()) | |
| 1218 | 1195 | ); |
| 1219 | 1196 | return new Configuration(policies, |
| 1220 | - new ProtocolOptions(port, protocolVersion, maxSchemaAgreementWaitSeconds, sslOptions, authProvider).setCompression(compression), | |
| 1221 | - poolingOptions == null ? new PoolingOptions() : poolingOptions, | |
| 1222 | - socketOptions == null ? new SocketOptions() : socketOptions, | |
| 1223 | - metricsEnabled ? new MetricsOptions(jmxEnabled) : null, | |
| 1224 | - queryOptions == null ? new QueryOptions() : queryOptions, | |
| 1225 | - nettyOptions); | |
| 1197 | + new ProtocolOptions(port, protocolVersion, maxSchemaAgreementWaitSeconds, sslOptions, authProvider).setCompression(compression), | |
| 1198 | + poolingOptions == null ? new PoolingOptions() : poolingOptions, | |
| 1199 | + socketOptions == null ? new SocketOptions() : socketOptions, | |
| 1200 | + metricsEnabled ? new MetricsOptions(jmxEnabled) : null, | |
| 1201 | + queryOptions == null ? new QueryOptions() : queryOptions, | |
| 1202 | + nettyOptions); | |
| 1226 | 1203 | } |
| 1227 | 1204 | |
| 1228 | 1205 | @Override |
| @@ -1233,7 +1210,7 @@ | ||
| 1233 | 1210 | /** |
| 1234 | 1211 | * Builds the cluster with the configured set of initial contact points |
| 1235 | 1212 | * and policies. |
| 1236 | - * <p> | |
| 1213 | + * <p/> | |
| 1237 | 1214 | * This is a convenience method for {@code Cluster.buildFrom(this)}. |
| 1238 | 1215 | * |
| 1239 | 1216 | * @return the newly built Cluster instance. |
| @@ -1253,7 +1230,7 @@ | ||
| 1253 | 1230 | |
| 1254 | 1231 | /** |
| 1255 | 1232 | * The sessions and hosts managed by this a Cluster instance. |
| 1256 | - * <p> | |
| 1233 | + * <p/> | |
| 1257 | 1234 | * Note: the reason we create a Manager object separate from Cluster is |
| 1258 | 1235 | * that Manager is not publicly visible. For instance, we wouldn't want |
| 1259 | 1236 | * user to be able to call the {@link #onUp} and {@link #onDown} methods. |
| @@ -1304,7 +1281,7 @@ | ||
| 1304 | 1281 | |
| 1305 | 1282 | final Set<Host.StateListener> listeners; |
| 1306 | 1283 | final Set<LatencyTracker> trackers = new CopyOnWriteArraySet<LatencyTracker>(); |
| 1307 | - final Set<SchemaChangeListener> schemaChangeListeners = new CopyOnWriteArraySet<SchemaChangeListener>(); | |
| 1284 | + final Set<SchemaChangeListener> schemaChangeListeners = new CopyOnWriteArraySet<SchemaChangeListener>(); | |
| 1308 | 1285 | |
| 1309 | 1286 | EventDebouncer<NodeListRefreshRequest> nodeListRefreshRequestDebouncer; |
| 1310 | 1287 | EventDebouncer<NodeRefreshRequest> nodeRefreshRequestDebouncer; |
| @@ -1348,23 +1325,23 @@ | ||
| 1348 | 1325 | // create debouncers - at this stage, they are not running yet |
| 1349 | 1326 | QueryOptions queryOptions = configuration.getQueryOptions(); |
| 1350 | 1327 | this.nodeListRefreshRequestDebouncer = new EventDebouncer<NodeListRefreshRequest>( |
| 1351 | - "Node list refresh", | |
| 1352 | - scheduledTasksExecutor, | |
| 1353 | - new NodeListRefreshRequestDeliveryCallback(), | |
| 1354 | - queryOptions.getRefreshNodeListIntervalMillis(), | |
| 1355 | - queryOptions.getMaxPendingRefreshNodeListRequests()); | |
| 1328 | + "Node list refresh", | |
| 1329 | + scheduledTasksExecutor, | |
| 1330 | + new NodeListRefreshRequestDeliveryCallback(), | |
| 1331 | + queryOptions.getRefreshNodeListIntervalMillis(), | |
| 1332 | + queryOptions.getMaxPendingRefreshNodeListRequests()); | |
| 1356 | 1333 | this.nodeRefreshRequestDebouncer = new EventDebouncer<NodeRefreshRequest>( |
| 1357 | - "Node refresh", | |
| 1358 | - scheduledTasksExecutor, | |
| 1359 | - new NodeRefreshRequestDeliveryCallback(), | |
| 1360 | - queryOptions.getRefreshNodeIntervalMillis(), | |
| 1361 | - queryOptions.getMaxPendingRefreshNodeRequests()); | |
| 1334 | + "Node refresh", | |
| 1335 | + scheduledTasksExecutor, | |
| 1336 | + new NodeRefreshRequestDeliveryCallback(), | |
| 1337 | + queryOptions.getRefreshNodeIntervalMillis(), | |
| 1338 | + queryOptions.getMaxPendingRefreshNodeRequests()); | |
| 1362 | 1339 | this.schemaRefreshRequestDebouncer = new EventDebouncer<SchemaRefreshRequest>( |
| 1363 | - "Schema refresh", | |
| 1364 | - scheduledTasksExecutor, | |
| 1365 | - new SchemaRefreshRequestDeliveryCallback(), | |
| 1366 | - queryOptions.getRefreshSchemaIntervalMillis(), | |
| 1367 | - queryOptions.getMaxPendingRefreshSchemaRequests()); | |
| 1340 | + "Schema refresh", | |
| 1341 | + scheduledTasksExecutor, | |
| 1342 | + new SchemaRefreshRequestDeliveryCallback(), | |
| 1343 | + queryOptions.getRefreshSchemaIntervalMillis(), | |
| 1344 | + queryOptions.getMaxPendingRefreshSchemaRequests()); | |
| 1368 | 1345 | |
| 1369 | 1346 | this.scheduledTasksExecutor.scheduleWithFixedDelay(new CleanupIdleConnectionsTask(), 10, 10, TimeUnit.SECONDS); |
| 1370 | 1347 | |
| @@ -1475,11 +1452,11 @@ | ||
| 1475 | 1452 | |
| 1476 | 1453 | private ListeningExecutorService makeExecutor(int threads, String name, LinkedBlockingQueue<Runnable> workQueue) { |
| 1477 | 1454 | ThreadPoolExecutor executor = new ThreadPoolExecutor(threads, |
| 1478 | - threads, | |
| 1479 | - DEFAULT_THREAD_KEEP_ALIVE, | |
| 1480 | - TimeUnit.SECONDS, | |
| 1481 | - workQueue, | |
| 1482 | - threadFactory(name)); | |
| 1455 | + threads, | |
| 1456 | + DEFAULT_THREAD_KEEP_ALIVE, | |
| 1457 | + TimeUnit.SECONDS, | |
| 1458 | + workQueue, | |
| 1459 | + threadFactory(name)); | |
| 1483 | 1460 | |
| 1484 | 1461 | executor.allowCoreThreadTimeOut(true); |
| 1485 | 1462 | return MoreExecutors.listeningDecorator(executor); |
| @@ -1557,13 +1534,13 @@ | ||
| 1557 | 1534 | // And the load balancing policy |
| 1558 | 1535 | LoadBalancingPolicy loadBalancingPolicy = loadBalancingPolicy(); |
| 1559 | 1536 | if (loadBalancingPolicy instanceof CloseableLoadBalancingPolicy) |
| 1560 | - ((CloseableLoadBalancingPolicy)loadBalancingPolicy).close(); | |
| 1537 | + ((CloseableLoadBalancingPolicy) loadBalancingPolicy).close(); | |
| 1561 | 1538 | |
| 1562 | 1539 | speculativeRetryPolicy().close(); |
| 1563 | 1540 | |
| 1564 | 1541 | AddressTranslater translater = configuration.getPolicies().getAddressTranslater(); |
| 1565 | 1542 | if (translater instanceof CloseableAddressTranslater) |
| 1566 | - ((CloseableAddressTranslater)translater).close(); | |
| 1543 | + ((CloseableAddressTranslater) translater).close(); | |
| 1567 | 1544 | |
| 1568 | 1545 | for (SchemaChangeListener listener : schemaChangeListeners) { |
| 1569 | 1546 | listener.onUnregister(Cluster.this); |
| @@ -1582,8 +1559,8 @@ | ||
| 1582 | 1559 | } |
| 1583 | 1560 | |
| 1584 | 1561 | return closeFuture.compareAndSet(null, future) |
| 1585 | - ? future | |
| 1586 | - : closeFuture.get(); // We raced, it's ok, return the future that was actually set | |
| 1562 | + ? future | |
| 1563 | + : closeFuture.get(); // We raced, it's ok, return the future that was actually set | |
| 1587 | 1564 | } |
| 1588 | 1565 | |
| 1589 | 1566 | private void shutdownNow(ExecutorService executor) { |
| @@ -1591,20 +1568,20 @@ | ||
| 1591 | 1568 | // If some tasks were submitted to this executor but not yet commenced, make sure the corresponding futures complete |
| 1592 | 1569 | for (Runnable pendingTask : pendingTasks) { |
| 1593 | 1570 | if (pendingTask instanceof FutureTask<?>) |
| 1594 | - ((FutureTask<?>)pendingTask).cancel(false); | |
| 1571 | + ((FutureTask<?>) pendingTask).cancel(false); | |
| 1595 | 1572 | } |
| 1596 | 1573 | } |
| 1597 | 1574 | |
| 1598 | 1575 | void logUnsupportedVersionProtocol(Host host) { |
| 1599 | 1576 | logger.warn("Detected added or restarted Cassandra host {} but ignoring it since it does not support the version 2 of the native " |
| 1600 | - + "protocol which is currently in use. If you want to force the use of the version 1 of the native protocol, use " | |
| 1601 | - + "Cluster.Builder#usingProtocolVersion() when creating the Cluster instance.", host); | |
| 1577 | + + "protocol which is currently in use. If you want to force the use of the version 1 of the native protocol, use " | |
| 1578 | + + "Cluster.Builder#usingProtocolVersion() when creating the Cluster instance.", host); | |
| 1602 | 1579 | } |
| 1603 | 1580 | |
| 1604 | 1581 | void logClusterNameMismatch(Host host, String expectedClusterName, String actualClusterName) { |
| 1605 | 1582 | logger.warn("Detected added or restarted Cassandra host {} but ignoring it since its cluster name '{}' does not match the one " |
| 1606 | - + "currently known ({})", | |
| 1607 | - host, actualClusterName, expectedClusterName); | |
| 1583 | + + "currently known ({})", | |
| 1584 | + host, actualClusterName, expectedClusterName); | |
| 1608 | 1585 | } |
| 1609 | 1586 | |
| 1610 | 1587 | public ListenableFuture<?> triggerOnUp(final Host host) { |
| @@ -1727,7 +1704,7 @@ | ||
| 1727 | 1704 | } |
| 1728 | 1705 | |
| 1729 | 1706 | public ListenableFuture<?> triggerOnDown(final Host host, final boolean isHostAddition, final boolean startReconnection) { |
| 1730 | - if(!isClosed()) { | |
| 1707 | + if (!isClosed()) { | |
| 1731 | 1708 | return executor.submit(new ExceptionCatchingRunnable() { |
| 1732 | 1709 | @Override |
| 1733 | 1710 | public void runMayThrow() throws InterruptedException, ExecutionException { |
| @@ -2083,7 +2060,7 @@ | ||
| 2083 | 2060 | PreparedStatement previous = preparedQueries.putIfAbsent(stmt.getPreparedId().id, stmt); |
| 2084 | 2061 | if (previous != null) { |
| 2085 | 2062 | logger.warn("Re-preparing already prepared query {}. Please note that preparing the same query more than once is " |
| 2086 | - + "generally an anti-pattern and will likely affect performance. Consider preparing the statement only once.", stmt.getQueryString()); | |
| 2063 | + + "generally an anti-pattern and will likely affect performance. Consider preparing the statement only once.", stmt.getQueryString()); | |
| 2087 | 2064 | |
| 2088 | 2065 | // The one object in the cache will get GCed once it's not referenced by the client anymore since we use a weak reference. |
| 2089 | 2066 | // So we need to make sure that the instance we do return to the user is the one that is in the cache. |
| @@ -2096,7 +2073,7 @@ | ||
| 2096 | 2073 | * @param reusedConnection an existing connection (from a reconnection attempt) that we want to |
| 2097 | 2074 | * reuse to prepare the statements (might be null). |
| 2098 | 2075 | * @return a connection that the rest of the initialization process can use (it will be made part |
| 2099 | - * of a connection pool). Can be reusedConnection, or one that was open in the method. | |
| 2076 | + * of a connection pool). Can be reusedConnection, or one that was open in the method. | |
| 2100 | 2077 | */ |
| 2101 | 2078 | private Connection prepareAllQueries(Host host, Connection reusedConnection) throws InterruptedException, UnsupportedProtocolVersionException, ClusterNameMismatchException { |
| 2102 | 2079 | if (preparedQueries.isEmpty()) |
| @@ -2106,8 +2083,8 @@ | ||
| 2106 | 2083 | Connection connection = null; |
| 2107 | 2084 | try { |
| 2108 | 2085 | connection = (reusedConnection == null) |
| 2109 | - ? connectionFactory.open(host) | |
| 2110 | - : reusedConnection; | |
| 2086 | + ? connectionFactory.open(host) | |
| 2087 | + : reusedConnection; | |
| 2111 | 2088 | |
| 2112 | 2089 | try { |
| 2113 | 2090 | controlConnection.waitForSchemaAgreement(); |
| @@ -2247,13 +2224,13 @@ | ||
| 2247 | 2224 | return; |
| 2248 | 2225 | } |
| 2249 | 2226 | |
| 2250 | - final ProtocolEvent event = ((Responses.Event)response).event; | |
| 2227 | + final ProtocolEvent event = ((Responses.Event) response).event; | |
| 2251 | 2228 | |
| 2252 | 2229 | logger.debug("Received event {}, scheduling delivery", response); |
| 2253 | 2230 | |
| 2254 | 2231 | switch (event.type) { |
| 2255 | 2232 | case TOPOLOGY_CHANGE: |
| 2256 | - ProtocolEvent.TopologyChange tpc = (ProtocolEvent.TopologyChange)event; | |
| 2233 | + ProtocolEvent.TopologyChange tpc = (ProtocolEvent.TopologyChange) event; | |
| 2257 | 2234 | InetSocketAddress tpAddr = translateAddress(tpc.node.getAddress()); |
| 2258 | 2235 | Host.statesLogger.debug("[{}] received event {}", tpAddr, tpc.change); |
| 2259 | 2236 | switch (tpc.change) { |
| @@ -2269,7 +2246,7 @@ | ||
| 2269 | 2246 | } |
| 2270 | 2247 | break; |
| 2271 | 2248 | case STATUS_CHANGE: |
| 2272 | - ProtocolEvent.StatusChange stc = (ProtocolEvent.StatusChange)event; | |
| 2249 | + ProtocolEvent.StatusChange stc = (ProtocolEvent.StatusChange) event; | |
| 2273 | 2250 | InetSocketAddress stAddr = translateAddress(stc.node.getAddress()); |
| 2274 | 2251 | Host.statesLogger.debug("[{}] received event {}", stAddr, stc.status); |
| 2275 | 2252 | switch (stc.status) { |
| @@ -2285,7 +2262,7 @@ | ||
| 2285 | 2262 | if (!configuration.getQueryOptions().isMetadataEnabled()) |
| 2286 | 2263 | return; |
| 2287 | 2264 | |
| 2288 | - ProtocolEvent.SchemaChange scc = (ProtocolEvent.SchemaChange)event; | |
| 2265 | + ProtocolEvent.SchemaChange scc = (ProtocolEvent.SchemaChange) event; | |
| 2289 | 2266 | switch (scc.change) { |
| 2290 | 2267 | case CREATED: |
| 2291 | 2268 | if (scc.table.isEmpty()) |
| @@ -2296,7 +2273,7 @@ | ||
| 2296 | 2273 | case DROPPED: |
| 2297 | 2274 | if (scc.table.isEmpty()) { |
| 2298 | 2275 | final KeyspaceMetadata removed = manager.metadata.removeKeyspace(scc.keyspace); |
| 2299 | - if(removed != null) { | |
| 2276 | + if (removed != null) { | |
| 2300 | 2277 | executor.submit(new Runnable() { |
| 2301 | 2278 | @Override |
| 2302 | 2279 | public void run() { |
| @@ -2308,7 +2285,7 @@ | ||
| 2308 | 2285 | KeyspaceMetadata keyspace = manager.metadata.getKeyspaceInternal(scc.keyspace); |
| 2309 | 2286 | if (keyspace == null) |
| 2310 | 2287 | logger.warn("Received a DROPPED notification for {}.{}, but this keyspace is unknown in our metadata", |
| 2311 | - scc.keyspace, scc.table); | |
| 2288 | + scc.keyspace, scc.table); | |
| 2312 | 2289 | else { |
| 2313 | 2290 | final TableMetadata removed = keyspace.removeTable(scc.table); |
| 2314 | 2291 | if (removed != null) { |
| @@ -2409,7 +2386,8 @@ | ||
| 2409 | 2386 | } |
| 2410 | 2387 | |
| 2411 | 2388 | private class CleanupIdleConnectionsTask implements Runnable { |
| 2412 | - @Override public void run() { | |
| 2389 | + @Override | |
| 2390 | + public void run() { | |
| 2413 | 2391 | try { |
| 2414 | 2392 | long now = System.currentTimeMillis(); |
| 2415 | 2393 | for (SessionManager session : sessions) { |
| @@ -2443,22 +2421,22 @@ | ||
| 2443 | 2421 | * @return A coalesced request |
| 2444 | 2422 | */ |
| 2445 | 2423 | SchemaRefreshRequest coalesce(SchemaRefreshRequest that) { |
| 2446 | - if(this.keyspace == null || that.keyspace == null) | |
| 2424 | + if (this.keyspace == null || that.keyspace == null) | |
| 2447 | 2425 | return new SchemaRefreshRequest(null, null); |
| 2448 | - if(!this.keyspace.equals(that.keyspace)) | |
| 2426 | + if (!this.keyspace.equals(that.keyspace)) | |
| 2449 | 2427 | return new SchemaRefreshRequest(null, null); |
| 2450 | - if(this.table == null || that.table == null) | |
| 2428 | + if (this.table == null || that.table == null) | |
| 2451 | 2429 | return new SchemaRefreshRequest(keyspace, null); |
| 2452 | - if(!this.table.equals(that.table)) | |
| 2430 | + if (!this.table.equals(that.table)) | |
| 2453 | 2431 | return new SchemaRefreshRequest(keyspace, null); |
| 2454 | 2432 | return this; |
| 2455 | 2433 | } |
| 2456 | 2434 | |
| 2457 | 2435 | @Override |
| 2458 | 2436 | public String toString() { |
| 2459 | - if(this.keyspace == null) | |
| 2437 | + if (this.keyspace == null) | |
| 2460 | 2438 | return "Refresh ALL"; |
| 2461 | - if(this.table == null) | |
| 2439 | + if (this.table == null) | |
| 2462 | 2440 | return "Refresh keyspace " + keyspace; |
| 2463 | 2441 | return "Refresh keyspace " + keyspace + " table " + table; |
| 2464 | 2442 | } |
| @@ -2538,7 +2516,7 @@ | ||
| 2538 | 2516 | // If host already existed, retrieve it and check its state, if it's not up schedule a |
| 2539 | 2517 | // hostUp event. |
| 2540 | 2518 | Host existingHost = metadata.getHost(address); |
| 2541 | - if(!existingHost.isUp()) | |
| 2519 | + if (!existingHost.isUp()) | |
| 2542 | 2520 | futures.add(schedule(hostUp(existingHost))); |
| 2543 | 2521 | } |
| 2544 | 2522 | break; |
| @@ -2677,7 +2655,7 @@ | ||
| 2677 | 2655 | |
| 2678 | 2656 | /** |
| 2679 | 2657 | * Periodically ensures that closed connections are properly terminated once they have no more pending requests. |
| 2680 | - * | |
| 2658 | + * <p/> | |
| 2681 | 2659 | * This is normally done when the connection errors out, or when the last request is processed; this class acts as |
| 2682 | 2660 | * a last-effort protection since unterminated connections can lead to deadlocks. If it terminates a connection, |
| 2683 | 2661 | * this indicates a bug; warnings are logged so that this can be reported. |
modified driver-core/src/main/java/com/datastax/driver/core/ClusterNameMismatchException.java +1 −1
| @@ -30,7 +30,7 @@ | ||
| 30 | 30 | |
| 31 | 31 | public ClusterNameMismatchException(InetSocketAddress address, String actualClusterName, String expectedClusterName) { |
| 32 | 32 | super(String.format("[%s] Host %s reports cluster name '%s' that doesn't match our cluster name '%s'. This host will be ignored.", |
| 33 | - address, address, actualClusterName, expectedClusterName)); | |
| 33 | + address, address, actualClusterName, expectedClusterName)); | |
| 34 | 34 | this.address = address; |
| 35 | 35 | this.expectedClusterName = expectedClusterName; |
| 36 | 36 | this.actualClusterName = actualClusterName; |
modified driver-core/src/main/java/com/datastax/driver/core/ColumnDefinitions.java +23 −30
| @@ -15,22 +15,22 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.util.*; | |
| 19 | - | |
| 20 | 18 | import com.datastax.driver.core.exceptions.InvalidTypeException; |
| 21 | 19 | |
| 20 | +import java.util.*; | |
| 21 | + | |
| 22 | 22 | /** |
| 23 | 23 | * Metadata describing the columns returned in a {@link ResultSet} or a |
| 24 | 24 | * {@link PreparedStatement}. |
| 25 | - * <p> | |
| 25 | + * <p/> | |
| 26 | 26 | * A {@code columnDefinitions}} instance is mainly a list of |
| 27 | 27 | * {@code ColumnsDefinitions.Definition}. The definitions or metadata for a column |
| 28 | 28 | * can be accessed either by: |
| 29 | 29 | * <ul> |
| 30 | - * <li>index (indexed from 0)</li> | |
| 31 | - * <li>name</li> | |
| 30 | + * <li>index (indexed from 0)</li> | |
| 31 | + * <li>name</li> | |
| 32 | 32 | * </ul> |
| 33 | - * <p> | |
| 33 | + * <p/> | |
| 34 | 34 | * When accessed by name, column selection is case insensitive. In case multiple |
| 35 | 35 | * columns only differ by the case of their name, then the column returned with |
| 36 | 36 | * be the first column that has been defined in CQL without forcing case sensitivity |
| @@ -38,17 +38,17 @@ | ||
| 38 | 38 | * If none of the columns have been defined in this manner, the first column matching |
| 39 | 39 | * (with case insensitivity) is returned. You can force the case of a selection |
| 40 | 40 | * by double quoting the name. |
| 41 | - * <p> | |
| 41 | + * <p/> | |
| 42 | 42 | * For example: |
| 43 | 43 | * <ul> |
| 44 | - * <li>If {@code cd} contains column {@code fOO}, then {@code cd.contains("foo")}, | |
| 45 | - * {@code cd.contains("fOO")} and {@code cd.contains("Foo")} will return {@code true}.</li> | |
| 46 | - * <li>If {@code cd} contains both {@code foo} and {@code FOO} then: | |
| 47 | - * <ul> | |
| 48 | - * <li>{@code cd.getType("foo")}, {@code cd.getType("fOO")} and {@code cd.getType("FOO")} | |
| 49 | - * will all match column {@code foo}.</li> | |
| 50 | - * <li>{@code cd.getType("\"FOO\"")} will match column {@code FOO}</li> | |
| 51 | - * </ul> | |
| 44 | + * <li>If {@code cd} contains column {@code fOO}, then {@code cd.contains("foo")}, | |
| 45 | + * {@code cd.contains("fOO")} and {@code cd.contains("Foo")} will return {@code true}.</li> | |
| 46 | + * <li>If {@code cd} contains both {@code foo} and {@code FOO} then: | |
| 47 | + * <ul> | |
| 48 | + * <li>{@code cd.getType("foo")}, {@code cd.getType("fOO")} and {@code cd.getType("FOO")} | |
| 49 | + * will all match column {@code foo}.</li> | |
| 50 | + * <li>{@code cd.getType("\"FOO\"")} will match column {@code FOO}</li> | |
| 51 | + * </ul> | |
| 52 | 52 | * </ul> |
| 53 | 53 | * Note that the preceding rules mean that if a {@code ColumnDefinitions} object |
| 54 | 54 | * contains multiple occurrences of the exact same name (be it the same column |
| @@ -69,7 +69,7 @@ | ||
| 69 | 69 | |
| 70 | 70 | for (int i = 0; i < defs.length; i++) { |
| 71 | 71 | // Be optimistic, 99% of the time, previous will be null. |
| 72 | - int[] previous = this.byName.put(defs[i].name.toLowerCase(), new int[]{ i }); | |
| 72 | + int[] previous = this.byName.put(defs[i].name.toLowerCase(), new int[]{i}); | |
| 73 | 73 | if (previous != null) { |
| 74 | 74 | int[] indexes = new int[previous.length + 1]; |
| 75 | 75 | System.arraycopy(previous, 0, indexes, 0, previous.length); |
| @@ -113,7 +113,7 @@ | ||
| 113 | 113 | |
| 114 | 114 | /** |
| 115 | 115 | * Returns an iterator over the {@link Definition} contained in this metadata. |
| 116 | - * | |
| 116 | + * <p/> | |
| 117 | 117 | * The order of the iterator will be the one of this metadata. |
| 118 | 118 | * |
| 119 | 119 | * @return an iterator over the {@link Definition} contained in this metadata. |
| @@ -137,7 +137,6 @@ | ||
| 137 | 137 | * |
| 138 | 138 | * @param i the index in this metadata. |
| 139 | 139 | * @return the name of the {@code i}th column in this metadata. |
| 140 | - * | |
| 141 | 140 | * @throws IndexOutOfBoundsException if {@code i < 0} or {@code i >= size()} |
| 142 | 141 | */ |
| 143 | 142 | public String getName(int i) { |
| @@ -149,7 +148,6 @@ | ||
| 149 | 148 | * |
| 150 | 149 | * @param i the index in this metadata. |
| 151 | 150 | * @return the type of the {@code i}th column in this metadata. |
| 152 | - * | |
| 153 | 151 | * @throws IndexOutOfBoundsException if {@code i < 0} or {@code i >= size()} |
| 154 | 152 | */ |
| 155 | 153 | public DataType getType(int i) { |
| @@ -161,7 +159,6 @@ | ||
| 161 | 159 | * |
| 162 | 160 | * @param name the name of the column. |
| 163 | 161 | * @return the type of (the first occurrence of) {@code name} in this metadata. |
| 164 | - * | |
| 165 | 162 | * @throws IllegalArgumentException if {@code name} is not in this metadata. |
| 166 | 163 | */ |
| 167 | 164 | public DataType getType(String name) { |
| @@ -173,7 +170,6 @@ | ||
| 173 | 170 | * |
| 174 | 171 | * @param i the index in this metadata. |
| 175 | 172 | * @return the keyspace of the {@code i}th column in this metadata. |
| 176 | - * | |
| 177 | 173 | * @throws IndexOutOfBoundsException if {@code i < 0} or {@code i >= size()} |
| 178 | 174 | */ |
| 179 | 175 | public String getKeyspace(int i) { |
| @@ -185,7 +181,6 @@ | ||
| 185 | 181 | * |
| 186 | 182 | * @param name the name of the column. |
| 187 | 183 | * @return the keyspace of (the first occurrence of) column {@code name} in this metadata. |
| 188 | - * | |
| 189 | 184 | * @throws IllegalArgumentException if {@code name} is not in this metadata. |
| 190 | 185 | */ |
| 191 | 186 | public String getKeyspace(String name) { |
| @@ -197,7 +192,6 @@ | ||
| 197 | 192 | * |
| 198 | 193 | * @param i the index in this metadata. |
| 199 | 194 | * @return the table of the {@code i}th column in this metadata. |
| 200 | - * | |
| 201 | 195 | * @throws IndexOutOfBoundsException if {@code i < 0} or {@code i >= size()} |
| 202 | 196 | */ |
| 203 | 197 | public String getTable(int i) { |
| @@ -209,7 +203,6 @@ | ||
| 209 | 203 | * |
| 210 | 204 | * @param name the name of the column. |
| 211 | 205 | * @return the table of (the first occurrence of) column {@code name} in this metadata. |
| 212 | - * | |
| 213 | 206 | * @throws IllegalArgumentException if {@code name} is not in this metadata. |
| 214 | 207 | */ |
| 215 | 208 | public String getTable(String name) { |
| @@ -362,19 +355,19 @@ | ||
| 362 | 355 | |
| 363 | 356 | @Override |
| 364 | 357 | public final int hashCode() { |
| 365 | - return Arrays.hashCode(new Object[]{ keyspace, table, name, type}); | |
| 358 | + return Arrays.hashCode(new Object[]{keyspace, table, name, type}); | |
| 366 | 359 | } |
| 367 | 360 | |
| 368 | 361 | @Override |
| 369 | 362 | public final boolean equals(Object o) { |
| 370 | - if(!(o instanceof Definition)) | |
| 363 | + if (!(o instanceof Definition)) | |
| 371 | 364 | return false; |
| 372 | 365 | |
| 373 | - Definition other = (Definition)o; | |
| 366 | + Definition other = (Definition) o; | |
| 374 | 367 | return keyspace.equals(other.keyspace) |
| 375 | - && table.equals(other.table) | |
| 376 | - && name.equals(other.name) | |
| 377 | - && type.equals(other.type); | |
| 368 | + && table.equals(other.table) | |
| 369 | + && name.equals(other.name) | |
| 370 | + && type.equals(other.type); | |
| 378 | 371 | } |
| 379 | 372 | } |
| 380 | 373 | } |
modified driver-core/src/main/java/com/datastax/driver/core/ColumnMetadata.java +9 −9
| @@ -110,7 +110,7 @@ | ||
| 110 | 110 | if (o == null || getClass() != o.getClass()) |
| 111 | 111 | return false; |
| 112 | 112 | |
| 113 | - ColumnMetadata that = (ColumnMetadata)o; | |
| 113 | + ColumnMetadata that = (ColumnMetadata) o; | |
| 114 | 114 | |
| 115 | 115 | if (isStatic != that.isStatic) |
| 116 | 116 | return false; |
| @@ -166,7 +166,7 @@ | ||
| 166 | 166 | |
| 167 | 167 | /** |
| 168 | 168 | * Returns whether this index is a custom one. |
| 169 | - * <p> | |
| 169 | + * <p/> | |
| 170 | 170 | * If it is indeed a custom index, {@link #getIndexClassName} will |
| 171 | 171 | * return the name of the class used in Cassandra to implement that |
| 172 | 172 | * index. |
| @@ -189,7 +189,7 @@ | ||
| 189 | 189 | |
| 190 | 190 | /** |
| 191 | 191 | * Returns a CQL query representing this index. |
| 192 | - * | |
| 192 | + * <p/> | |
| 193 | 193 | * This method returns a single 'CREATE INDEX' query corresponding to |
| 194 | 194 | * this index definition. |
| 195 | 195 | * |
| @@ -201,8 +201,8 @@ | ||
| 201 | 201 | String cfName = Metadata.escapeId(table.getName()); |
| 202 | 202 | String colName = Metadata.escapeId(column.getName()); |
| 203 | 203 | return isCustomIndex() |
| 204 | - ? String.format("CREATE CUSTOM INDEX %s ON %s.%s (%s) USING '%s';", name, ksName, cfName, colName, customClassName) | |
| 205 | - : String.format("CREATE INDEX %s ON %s.%s (%s);", name, ksName, cfName, colName); | |
| 204 | + ? String.format("CREATE CUSTOM INDEX %s ON %s.%s (%s) USING '%s';", name, ksName, cfName, colName, customClassName) | |
| 205 | + : String.format("CREATE INDEX %s ON %s.%s (%s);", name, ksName, cfName, colName); | |
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | @Override |
| @@ -212,7 +212,7 @@ | ||
| 212 | 212 | if (o == null || getClass() != o.getClass()) |
| 213 | 213 | return false; |
| 214 | 214 | |
| 215 | - IndexMetadata that = (IndexMetadata)o; | |
| 215 | + IndexMetadata that = (IndexMetadata) o; | |
| 216 | 216 | |
| 217 | 217 | if (!name.equals(that.name)) |
| 218 | 218 | return false; |
| @@ -252,7 +252,7 @@ | ||
| 252 | 252 | // Temporary class that is used to make building the schema easier. Not meant to be |
| 253 | 253 | // exposed publicly at all. |
| 254 | 254 | static class Raw { |
| 255 | - public enum Kind { PARTITION_KEY, CLUSTERING_KEY, REGULAR, COMPACT_VALUE, STATIC } | |
| 255 | + public enum Kind {PARTITION_KEY, CLUSTERING_KEY, REGULAR, COMPACT_VALUE, STATIC} | |
| 256 | 256 | |
| 257 | 257 | public final String name; |
| 258 | 258 | public final Kind kind; |
| @@ -274,8 +274,8 @@ | ||
| 274 | 274 | |
| 275 | 275 | String name = row.getString(COLUMN_NAME); |
| 276 | 276 | Kind kind = version.getMajor() < 2 || row.isNull(KIND) |
| 277 | - ? Kind.REGULAR | |
| 278 | - : Enum.valueOf(Kind.class, row.getString(KIND).toUpperCase()); | |
| 277 | + ? Kind.REGULAR | |
| 278 | + : Enum.valueOf(Kind.class, row.getString(KIND).toUpperCase()); | |
| 279 | 279 | int componentIndex = row.isNull(COMPONENT_INDEX) ? 0 : row.getInt(COMPONENT_INDEX); |
| 280 | 280 | String validatorStr = row.getString(VALIDATOR); |
| 281 | 281 | boolean reversed = CassandraTypeParser.isReversed(validatorStr); |
modified driver-core/src/main/java/com/datastax/driver/core/Configuration.java +21 −20
| @@ -21,12 +21,12 @@ | ||
| 21 | 21 | * The configuration of the cluster. |
| 22 | 22 | * It configures the following: |
| 23 | 23 | * <ul> |
| 24 | - * <li>Cassandra protocol level configuration (compression).</li> | |
| 25 | - * <li>Connection pooling configurations.</li> | |
| 26 | - * <li>low-level TCP configuration options (tcpNoDelay, keepAlive, ...).</li> | |
| 27 | - * <li>Metrics related options.</li> | |
| 28 | - * <li>Query related options (default consistency level, fetchSize, ...).</li> | |
| 29 | - * <li>Netty layer customization options.</li> | |
| 24 | + * <li>Cassandra protocol level configuration (compression).</li> | |
| 25 | + * <li>Connection pooling configurations.</li> | |
| 26 | + * <li>low-level TCP configuration options (tcpNoDelay, keepAlive, ...).</li> | |
| 27 | + * <li>Metrics related options.</li> | |
| 28 | + * <li>Query related options (default consistency level, fetchSize, ...).</li> | |
| 29 | + * <li>Netty layer customization options.</li> | |
| 30 | 30 | * </ul> |
| 31 | 31 | * This is also where you get the configured policies, though those cannot be changed |
| 32 | 32 | * (they are set during the built of the Cluster object). |
| @@ -47,24 +47,24 @@ | ||
| 47 | 47 | */ |
| 48 | 48 | public Configuration() { |
| 49 | 49 | this(new Policies(), |
| 50 | - new ProtocolOptions(), | |
| 51 | - new PoolingOptions(), | |
| 52 | - new SocketOptions(), | |
| 53 | - new MetricsOptions(), | |
| 54 | - new QueryOptions(), | |
| 55 | - NettyOptions.DEFAULT_INSTANCE); | |
| 50 | + new ProtocolOptions(), | |
| 51 | + new PoolingOptions(), | |
| 52 | + new SocketOptions(), | |
| 53 | + new MetricsOptions(), | |
| 54 | + new QueryOptions(), | |
| 55 | + NettyOptions.DEFAULT_INSTANCE); | |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | /** |
| 59 | 59 | * Creates a configuration with the specified parameters. |
| 60 | - * | |
| 61 | - * @param policies the policies to use | |
| 60 | + * | |
| 61 | + * @param policies the policies to use | |
| 62 | 62 | * @param protocolOptions the protocol options to use |
| 63 | - * @param poolingOptions the pooling options to use | |
| 64 | - * @param socketOptions the socket options to use | |
| 65 | - * @param metricsOptions the metrics options, or null to disable metrics. | |
| 66 | - * @param queryOptions defaults related to queries. | |
| 67 | - * @param nettyOptions the {@link NettyOptions} instance to use | |
| 63 | + * @param poolingOptions the pooling options to use | |
| 64 | + * @param socketOptions the socket options to use | |
| 65 | + * @param metricsOptions the metrics options, or null to disable metrics. | |
| 66 | + * @param queryOptions defaults related to queries. | |
| 67 | + * @param nettyOptions the {@link NettyOptions} instance to use | |
| 68 | 68 | */ |
| 69 | 69 | public Configuration(Policies policies, |
| 70 | 70 | ProtocolOptions protocolOptions, |
| @@ -126,7 +126,7 @@ | ||
| 126 | 126 | |
| 127 | 127 | /** |
| 128 | 128 | * Returns the metrics configuration, if metrics are enabled. |
| 129 | - * <p> | |
| 129 | + * <p/> | |
| 130 | 130 | * Metrics collection is enabled by default but can be disabled at cluster |
| 131 | 131 | * construction time through {@link Cluster.Builder#withoutMetrics}. |
| 132 | 132 | * |
| @@ -147,6 +147,7 @@ | ||
| 147 | 147 | |
| 148 | 148 | /** |
| 149 | 149 | * Returns the {@link NettyOptions} instance for this configuration. |
| 150 | + * | |
| 150 | 151 | * @return the {@link NettyOptions} instance for this configuration. |
| 151 | 152 | */ |
| 152 | 153 | public NettyOptions getNettyOptions() { |
modified driver-core/src/main/java/com/datastax/driver/core/Connection.java +94 −95
| @@ -15,17 +15,11 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.lang.ref.WeakReference; | |
| 19 | -import java.net.InetSocketAddress; | |
| 20 | -import java.util.HashSet; | |
| 21 | -import java.util.Iterator; | |
| 22 | -import java.util.List; | |
| 23 | -import java.util.Queue; | |
| 24 | -import java.util.concurrent.*; | |
| 25 | -import java.util.concurrent.atomic.AtomicBoolean; | |
| 26 | -import java.util.concurrent.atomic.AtomicInteger; | |
| 27 | -import java.util.concurrent.atomic.AtomicReference; | |
| 28 | - | |
| 18 | +import com.datastax.driver.core.Responses.Result.SetKeyspace; | |
| 19 | +import com.datastax.driver.core.exceptions.AuthenticationException; | |
| 20 | +import com.datastax.driver.core.exceptions.DriverException; | |
| 21 | +import com.datastax.driver.core.exceptions.DriverInternalError; | |
| 22 | +import com.datastax.driver.core.utils.MoreFutures; | |
| 29 | 23 | import com.google.common.annotations.VisibleForTesting; |
| 30 | 24 | import com.google.common.collect.Lists; |
| 31 | 25 | import com.google.common.collect.MapMaker; |
| @@ -42,19 +36,23 @@ | ||
| 42 | 36 | import io.netty.util.Timer; |
| 43 | 37 | import io.netty.util.TimerTask; |
| 44 | 38 | import io.netty.util.concurrent.GlobalEventExecutor; |
| 45 | -import javax.net.ssl.SSLEngine; | |
| 46 | 39 | import org.slf4j.Logger; |
| 47 | 40 | import org.slf4j.LoggerFactory; |
| 48 | 41 | |
| 49 | -import static io.netty.handler.timeout.IdleState.ALL_IDLE; | |
| 50 | - | |
| 51 | -import com.datastax.driver.core.Responses.Result.SetKeyspace; | |
| 52 | -import com.datastax.driver.core.exceptions.AuthenticationException; | |
| 53 | -import com.datastax.driver.core.exceptions.DriverException; | |
| 54 | -import com.datastax.driver.core.exceptions.DriverInternalError; | |
| 55 | -import com.datastax.driver.core.utils.MoreFutures; | |
| 42 | +import javax.net.ssl.SSLEngine; | |
| 43 | +import java.lang.ref.WeakReference; | |
| 44 | +import java.net.InetSocketAddress; | |
| 45 | +import java.util.HashSet; | |
| 46 | +import java.util.Iterator; | |
| 47 | +import java.util.List; | |
| 48 | +import java.util.Queue; | |
| 49 | +import java.util.concurrent.*; | |
| 50 | +import java.util.concurrent.atomic.AtomicBoolean; | |
| 51 | +import java.util.concurrent.atomic.AtomicInteger; | |
| 52 | +import java.util.concurrent.atomic.AtomicReference; | |
| 56 | 53 | |
| 57 | 54 | import static com.datastax.driver.core.Message.Response.Type.ERROR; |
| 55 | +import static io.netty.handler.timeout.IdleState.ALL_IDLE; | |
| 58 | 56 | |
| 59 | 57 | // For LoggingHandler |
| 60 | 58 | //import org.jboss.netty.handler.logging.LoggingHandler; |
| @@ -70,7 +68,7 @@ | ||
| 70 | 68 | |
| 71 | 69 | private static final boolean DISABLE_COALESCING = SystemProperties.getBoolean("com.datastax.driver.DISABLE_COALESCING", false); |
| 72 | 70 | |
| 73 | - enum State {OPEN, TRASHED, RESURRECTING, GONE } | |
| 71 | + enum State {OPEN, TRASHED, RESURRECTING, GONE} | |
| 74 | 72 | |
| 75 | 73 | final AtomicReference<State> state = new AtomicReference<State>(State.OPEN); |
| 76 | 74 | |
| @@ -100,14 +98,14 @@ | ||
| 100 | 98 | private final AtomicReference<Owner> ownerRef = new AtomicReference<Owner>(); |
| 101 | 99 | |
| 102 | 100 | /** |
| 103 | - /** | |
| 101 | + * /** | |
| 104 | 102 | * Create a new connection to a Cassandra node and associate it with the given pool. |
| 105 | 103 | * |
| 106 | - * @param name the connection name | |
| 104 | + * @param name the connection name | |
| 107 | 105 | * @param address the remote address |
| 108 | 106 | * @param factory the connection factory to use |
| 109 | - * @param owner the component owning this connection (may be null). | |
| 110 | - * Note that an existing connection can also be associated to an owner later with {@link #setOwner(Owner)}. | |
| 107 | + * @param owner the component owning this connection (may be null). | |
| 108 | + * Note that an existing connection can also be associated to an owner later with {@link #setOwner(Owner)}. | |
| 111 | 109 | */ |
| 112 | 110 | protected Connection(String name, InetSocketAddress address, Factory factory, Owner owner) { |
| 113 | 111 | this.address = address; |
| @@ -134,9 +132,9 @@ | ||
| 134 | 132 | Bootstrap bootstrap = factory.newBootstrap(); |
| 135 | 133 | ProtocolOptions protocolOptions = factory.configuration.getProtocolOptions(); |
| 136 | 134 | bootstrap.handler( |
| 137 | - new Initializer(this, protocolVersion, protocolOptions.getCompression().compressor(), protocolOptions.getSSLOptions(), | |
| 138 | - factory.configuration.getPoolingOptions().getHeartbeatIntervalSeconds(), | |
| 139 | - factory.configuration.getNettyOptions())); | |
| 135 | + new Initializer(this, protocolVersion, protocolOptions.getCompression().compressor(), protocolOptions.getSSLOptions(), | |
| 136 | + factory.configuration.getPoolingOptions().getHeartbeatIntervalSeconds(), | |
| 137 | + factory.configuration.getNettyOptions())); | |
| 140 | 138 | |
| 141 | 139 | ChannelFuture future = bootstrap.connect(address); |
| 142 | 140 | |
| @@ -175,7 +173,7 @@ | ||
| 175 | 173 | Executor initExecutor = factory.manager.configuration.getPoolingOptions().getInitializationExecutor(); |
| 176 | 174 | |
| 177 | 175 | ListenableFuture<Void> initializeTransportFuture = Futures.transform(channelReadyFuture, |
| 178 | - onChannelReady(protocolVersion, initExecutor), initExecutor); | |
| 176 | + onChannelReady(protocolVersion, initExecutor), initExecutor); | |
| 179 | 177 | |
| 180 | 178 | |
| 181 | 179 | // Fallback on initializeTransportFuture so we can properly propagate specific exceptions. |
| @@ -191,10 +189,10 @@ | ||
| 191 | 189 | } else { |
| 192 | 190 | // Defunct to ensure that the error will be signaled (marking the host down) |
| 193 | 191 | Exception e = (t instanceof ConnectionException || t instanceof DriverException || t instanceof InterruptedException) |
| 194 | - ? (Exception)t | |
| 195 | - : new ConnectionException(Connection.this.address, | |
| 196 | - String.format("Unexpected error during transport initialization (%s)", t), | |
| 197 | - t); | |
| 192 | + ? (Exception) t | |
| 193 | + : new ConnectionException(Connection.this.address, | |
| 194 | + String.format("Unexpected error during transport initialization (%s)", t), | |
| 195 | + t); | |
| 198 | 196 | future.setException(defunct(e)); |
| 199 | 197 | } |
| 200 | 198 | return future; |
| @@ -218,8 +216,8 @@ | ||
| 218 | 216 | if (t == null) |
| 219 | 217 | return ""; |
| 220 | 218 | String msg = t.getMessage() == null || t.getMessage().isEmpty() |
| 221 | - ? t.toString() | |
| 222 | - : t.getMessage(); | |
| 219 | + ? t.toString() | |
| 220 | + : t.getMessage(); | |
| 223 | 221 | return " (" + msg + ')'; |
| 224 | 222 | } |
| 225 | 223 | |
| @@ -230,7 +228,7 @@ | ||
| 230 | 228 | ProtocolOptions.Compression compression = factory.configuration.getProtocolOptions().getCompression(); |
| 231 | 229 | Future startupResponseFuture = write(new Requests.Startup(compression)); |
| 232 | 230 | return Futures.transform(startupResponseFuture, |
| 233 | - onStartupResponse(protocolVersion, initExecutor), initExecutor); | |
| 231 | + onStartupResponse(protocolVersion, initExecutor), initExecutor); | |
| 234 | 232 | } |
| 235 | 233 | }; |
| 236 | 234 | } |
| @@ -243,22 +241,20 @@ | ||
| 243 | 241 | case READY: |
| 244 | 242 | return checkClusterName(initExecutor); |
| 245 | 243 | case ERROR: |
| 246 | - Responses.Error error = (Responses.Error)response; | |
| 244 | + Responses.Error error = (Responses.Error) response; | |
| 247 | 245 | // Testing for a specific string is a tad fragile but well, we don't have much choice |
| 248 | 246 | if (error.code == ExceptionCode.PROTOCOL_ERROR && error.message.contains("Invalid or unsupported protocol version")) |
| 249 | 247 | throw unsupportedProtocolVersionException(protocolVersion); |
| 250 | 248 | throw new TransportException(address, String.format("Error initializing connection: %s", error.message)); |
| 251 | 249 | case AUTHENTICATE: |
| 252 | 250 | Authenticator authenticator = factory.authProvider.newAuthenticator(address); |
| 253 | - if (protocolVersion == 1) | |
| 254 | - { | |
| 251 | + if (protocolVersion == 1) { | |
| 255 | 252 | if (authenticator instanceof ProtocolV1Authenticator) |
| 256 | 253 | return authenticateV1(authenticator, initExecutor); |
| 257 | 254 | else |
| 258 | 255 | // DSE 3.x always uses SASL authentication backported from protocol v2 |
| 259 | 256 | return authenticateV2(authenticator, initExecutor); |
| 260 | - } | |
| 261 | - else | |
| 257 | + } else | |
| 262 | 258 | return authenticateV2(authenticator, initExecutor); |
| 263 | 259 | default: |
| 264 | 260 | throw new TransportException(address, String.format("Unexpected %s response message from server to a STARTUP message", response.type)); |
| @@ -279,21 +275,21 @@ | ||
| 279 | 275 | return MoreFutures.VOID_SUCCESS; |
| 280 | 276 | } |
| 281 | 277 | |
| 282 | - DefaultResultSetFuture clusterNameFuture = new DefaultResultSetFuture(null,new Requests.Query("select cluster_name from system.local")); | |
| 278 | + DefaultResultSetFuture clusterNameFuture = new DefaultResultSetFuture(null, new Requests.Query("select cluster_name from system.local")); | |
| 283 | 279 | try { |
| 284 | 280 | write(clusterNameFuture); |
| 285 | 281 | return Futures.transform(clusterNameFuture, |
| 286 | - new AsyncFunction<ResultSet, Void>() { | |
| 287 | - @Override | |
| 288 | - public ListenableFuture<Void> apply(ResultSet rs) throws Exception { | |
| 289 | - Row row = rs.one(); | |
| 290 | - String actual = row.getString("cluster_name"); | |
| 291 | - if (!expected.equals(actual)) | |
| 292 | - throw new ClusterNameMismatchException(address, actual, expected); | |
| 293 | - markInitialized(); | |
| 294 | - return MoreFutures.VOID_SUCCESS; | |
| 295 | - } | |
| 296 | - }, executor); | |
| 282 | + new AsyncFunction<ResultSet, Void>() { | |
| 283 | + @Override | |
| 284 | + public ListenableFuture<Void> apply(ResultSet rs) throws Exception { | |
| 285 | + Row row = rs.one(); | |
| 286 | + String actual = row.getString("cluster_name"); | |
| 287 | + if (!expected.equals(actual)) | |
| 288 | + throw new ClusterNameMismatchException(address, actual, expected); | |
| 289 | + markInitialized(); | |
| 290 | + return MoreFutures.VOID_SUCCESS; | |
| 291 | + } | |
| 292 | + }, executor); | |
| 297 | 293 | } catch (Exception e) { |
| 298 | 294 | return Futures.immediateFailedFuture(e); |
| 299 | 295 | } |
| @@ -305,23 +301,23 @@ | ||
| 305 | 301 | } |
| 306 | 302 | |
| 307 | 303 | private ListenableFuture<Void> authenticateV1(Authenticator authenticator, final Executor executor) { |
| 308 | - Requests.Credentials creds = new Requests.Credentials(((ProtocolV1Authenticator)authenticator).getCredentials()); | |
| 304 | + Requests.Credentials creds = new Requests.Credentials(((ProtocolV1Authenticator) authenticator).getCredentials()); | |
| 309 | 305 | try { |
| 310 | 306 | Future authResponseFuture = write(creds); |
| 311 | 307 | return Futures.transform(authResponseFuture, |
| 312 | - new AsyncFunction<Message.Response, Void>() { | |
| 313 | - @Override | |
| 314 | - public ListenableFuture<Void> apply(Message.Response authResponse) throws Exception { | |
| 315 | - switch (authResponse.type) { | |
| 316 | - case READY: | |
| 317 | - return checkClusterName(executor); | |
| 318 | - case ERROR: | |
| 319 | - throw new AuthenticationException(address, ((Responses.Error)authResponse).message); | |
| 320 | - default: | |
| 321 | - throw new TransportException(address, String.format("Unexpected %s response message from server to a CREDENTIALS message", authResponse.type)); | |
| 308 | + new AsyncFunction<Message.Response, Void>() { | |
| 309 | + @Override | |
| 310 | + public ListenableFuture<Void> apply(Message.Response authResponse) throws Exception { | |
| 311 | + switch (authResponse.type) { | |
| 312 | + case READY: | |
| 313 | + return checkClusterName(executor); | |
| 314 | + case ERROR: | |
| 315 | + throw new AuthenticationException(address, ((Responses.Error) authResponse).message); | |
| 316 | + default: | |
| 317 | + throw new TransportException(address, String.format("Unexpected %s response message from server to a CREDENTIALS message", authResponse.type)); | |
| 318 | + } | |
| 322 | 319 | } |
| 323 | - } | |
| 324 | - }, executor); | |
| 320 | + }, executor); | |
| 325 | 321 | } catch (Exception e) { |
| 326 | 322 | return Futures.immediateFailedFuture(e); |
| 327 | 323 | } |
| @@ -347,10 +343,10 @@ | ||
| 347 | 343 | switch (authResponse.type) { |
| 348 | 344 | case AUTH_SUCCESS: |
| 349 | 345 | logger.trace("{} Authentication complete", this); |
| 350 | - authenticator.onAuthenticationSuccess(((Responses.AuthSuccess)authResponse).token); | |
| 346 | + authenticator.onAuthenticationSuccess(((Responses.AuthSuccess) authResponse).token); | |
| 351 | 347 | return checkClusterName(executor); |
| 352 | 348 | case AUTH_CHALLENGE: |
| 353 | - byte[] responseToServer = authenticator.evaluateChallenge(((Responses.AuthChallenge)authResponse).token); | |
| 349 | + byte[] responseToServer = authenticator.evaluateChallenge(((Responses.AuthChallenge) authResponse).token); | |
| 354 | 350 | if (responseToServer == null) { |
| 355 | 351 | // If we generate a null response, then authentication has completed, proceed without |
| 356 | 352 | // sending a further response back to the server. |
| @@ -367,10 +363,10 @@ | ||
| 367 | 363 | // attempted v2 auth against a server which only supports v1 |
| 368 | 364 | // The AIOOBE indicates that the server didn't recognise the |
| 369 | 365 | // initial AuthResponse message |
| 370 | - String message = ((Responses.Error)authResponse).message; | |
| 366 | + String message = ((Responses.Error) authResponse).message; | |
| 371 | 367 | if (message.startsWith("java.lang.ArrayIndexOutOfBoundsException: 15")) |
| 372 | 368 | message = String.format("Cannot use authenticator %s with protocol version 1, " |
| 373 | - + "only plain text authentication is supported with this protocol version", authenticator); | |
| 369 | + + "only plain text authentication is supported with this protocol version", authenticator); | |
| 374 | 370 | throw new AuthenticationException(address, message); |
| 375 | 371 | default: |
| 376 | 372 | throw new TransportException(address, String.format("Unexpected %s response message from server to authentication message", authResponse.type)); |
| @@ -435,14 +431,14 @@ | ||
| 435 | 431 | throw defunct(e); |
| 436 | 432 | } catch (BusyConnectionException e) { |
| 437 | 433 | logger.warn("Tried to set the keyspace on busy {}. " |
| 438 | - + "This should not happen but is not critical (it will be retried)", this); | |
| 434 | + + "This should not happen but is not critical (it will be retried)", this); | |
| 439 | 435 | throw new ConnectionException(address, "Tried to set the keyspace on busy connection"); |
| 440 | 436 | } catch (ExecutionException e) { |
| 441 | 437 | Throwable cause = e.getCause(); |
| 442 | 438 | if (cause instanceof OperationTimedOutException) { |
| 443 | 439 | // Rethrow so that the caller doesn't try to use the connection, but do not defunct as we don't want to mark down |
| 444 | 440 | logger.warn("Timeout while setting keyspace on {}. " |
| 445 | - + "This should not happen but is not critical (it will be retried)", this); | |
| 441 | + + "This should not happen but is not critical (it will be retried)", this); | |
| 446 | 442 | throw new ConnectionException(address, "Timeout while setting keyspace on connection"); |
| 447 | 443 | } else { |
| 448 | 444 | throw defunct(new ConnectionException(address, "Error while setting keyspace", cause)); |
| @@ -458,11 +454,11 @@ | ||
| 458 | 454 | @Override |
| 459 | 455 | public ListenableFuture<Void> apply(Message.Response response) throws Exception { |
| 460 | 456 | if (response instanceof SetKeyspace) { |
| 461 | - Connection.this.keyspace = ((SetKeyspace)response).keyspace; | |
| 457 | + Connection.this.keyspace = ((SetKeyspace) response).keyspace; | |
| 462 | 458 | return MoreFutures.VOID_SUCCESS; |
| 463 | 459 | } else if (response.type == ERROR) { |
| 464 | 460 | closeAsync().force(); |
| 465 | - Responses.Error error = (Responses.Error)response; | |
| 461 | + Responses.Error error = (Responses.Error) response; | |
| 466 | 462 | throw error.asException(address); |
| 467 | 463 | } else { |
| 468 | 464 | closeAsync().force(); |
| @@ -477,9 +473,8 @@ | ||
| 477 | 473 | * |
| 478 | 474 | * @param request the request to send |
| 479 | 475 | * @return a future on the server response |
| 480 | - * | |
| 481 | 476 | * @throws ConnectionException if the connection is closed |
| 482 | - * @throws TransportException if an I/O error while sending the request | |
| 477 | + * @throws TransportException if an I/O error while sending the request | |
| 483 | 478 | */ |
| 484 | 479 | public Future write(Message.Request request) throws ConnectionException, BusyConnectionException { |
| 485 | 480 | Future future = new Future(request); |
| @@ -573,7 +568,9 @@ | ||
| 573 | 568 | return this.ownerRef.get() != null; |
| 574 | 569 | } |
| 575 | 570 | |
| 576 | - /** @return whether the connection was already associated with an owner */ | |
| 571 | + /** | |
| 572 | + * @return whether the connection was already associated with an owner | |
| 573 | + */ | |
| 577 | 574 | boolean setOwner(Owner owner) { |
| 578 | 575 | return ownerRef.compareAndSet(null, owner); |
| 579 | 576 | } |
| @@ -585,7 +582,7 @@ | ||
| 585 | 582 | void release() { |
| 586 | 583 | Owner owner = ownerRef.get(); |
| 587 | 584 | if (owner instanceof HostConnectionPool) |
| 588 | - ((HostConnectionPool)owner).returnConnection(this); | |
| 585 | + ((HostConnectionPool) owner).returnConnection(this); | |
| 589 | 586 | } |
| 590 | 587 | |
| 591 | 588 | public boolean isClosed() { |
| @@ -594,13 +591,12 @@ | ||
| 594 | 591 | |
| 595 | 592 | /** |
| 596 | 593 | * Closes the connection: no new writes will be accepted after this method has returned. |
| 597 | - * | |
| 594 | + * <p/> | |
| 598 | 595 | * However, a closed connection might still have ongoing queries awaiting for their result. |
| 599 | 596 | * When all these ongoing queries have completed, the underlying channel will be closed; we |
| 600 | 597 | * refer to this final state as "terminated". |
| 601 | 598 | * |
| 602 | 599 | * @return a future that will complete once the connection has terminated. |
| 603 | - * | |
| 604 | 600 | * @see #tryTerminate(boolean) |
| 605 | 601 | */ |
| 606 | 602 | public CloseFuture closeAsync() { |
| @@ -640,12 +636,11 @@ | ||
| 640 | 636 | |
| 641 | 637 | /** |
| 642 | 638 | * Tries to terminate a closed connection, i.e. release system resources. |
| 643 | - * | |
| 639 | + * <p/> | |
| 644 | 640 | * This is called both by "normal" code and by {@link Cluster.ConnectionReaper}. |
| 645 | 641 | * |
| 646 | 642 | * @param force whether to proceed if there are still outstanding requests. |
| 647 | 643 | * @return whether the connection has actually terminated. |
| 648 | - * | |
| 649 | 644 | * @see #closeAsync() |
| 650 | 645 | */ |
| 651 | 646 | boolean tryTerminate(boolean force) { |
| @@ -715,7 +710,6 @@ | ||
| 715 | 710 | * Opens a new connection to the node this factory points to. |
| 716 | 711 | * |
| 717 | 712 | * @return the newly created (and initialized) connection. |
| 718 | - * | |
| 719 | 713 | * @throws ConnectionException if connection attempt fails. |
| 720 | 714 | */ |
| 721 | 715 | public Connection open(Host host) throws ConnectionException, InterruptedException, UnsupportedProtocolVersionException, ClusterNameMismatchException { |
| @@ -767,15 +761,15 @@ | ||
| 767 | 761 | static RuntimeException launderAsyncInitException(ExecutionException e) throws ConnectionException, InterruptedException, UnsupportedProtocolVersionException, ClusterNameMismatchException { |
| 768 | 762 | Throwable t = e.getCause(); |
| 769 | 763 | if (t instanceof ConnectionException) |
| 770 | - throw (ConnectionException)t; | |
| 764 | + throw (ConnectionException) t; | |
| 771 | 765 | if (t instanceof InterruptedException) |
| 772 | - throw (InterruptedException)t; | |
| 766 | + throw (InterruptedException) t; | |
| 773 | 767 | if (t instanceof UnsupportedProtocolVersionException) |
| 774 | - throw (UnsupportedProtocolVersionException)t; | |
| 768 | + throw (UnsupportedProtocolVersionException) t; | |
| 775 | 769 | if (t instanceof ClusterNameMismatchException) |
| 776 | - throw (ClusterNameMismatchException)t; | |
| 770 | + throw (ClusterNameMismatchException) t; | |
| 777 | 771 | if (t instanceof DriverException) |
| 778 | - throw (DriverException)t; | |
| 772 | + throw (DriverException) t; | |
| 779 | 773 | |
| 780 | 774 | return new RuntimeException("Unexpected exception during connection initialization", t); |
| 781 | 775 | } |
| @@ -798,7 +792,7 @@ | ||
| 798 | 792 | private Bootstrap newBootstrap() { |
| 799 | 793 | Bootstrap b = new Bootstrap(); |
| 800 | 794 | b.group(eventLoopGroup) |
| 801 | - .channel(channelClass); | |
| 795 | + .channel(channelClass); | |
| 802 | 796 | |
| 803 | 797 | SocketOptions options = configuration.getSocketOptions(); |
| 804 | 798 | |
| @@ -896,7 +890,7 @@ | ||
| 896 | 890 | } |
| 897 | 891 | |
| 898 | 892 | private static final ConcurrentMap<EventLoop, Flusher> flusherLookup = new MapMaker() |
| 899 | - .concurrencyLevel(16) | |
| 893 | + .concurrencyLevel(16) | |
| 900 | 894 | .weakKeys() |
| 901 | 895 | .makeMap(); |
| 902 | 896 | |
| @@ -965,7 +959,7 @@ | ||
| 965 | 959 | protected void channelRead0(ChannelHandlerContext ctx, Message.Response response) throws Exception { |
| 966 | 960 | int streamId = response.getStreamId(); |
| 967 | 961 | |
| 968 | - if(logger.isTraceEnabled()) | |
| 962 | + if (logger.isTraceEnabled()) | |
| 969 | 963 | logger.trace("{}, stream {}, received: {}", Connection.this, streamId, asDebugString(response)); |
| 970 | 964 | |
| 971 | 965 | if (streamId < 0) { |
| @@ -988,7 +982,7 @@ | ||
| 988 | 982 | streamIdHandler.unmark(streamId); |
| 989 | 983 | if (logger.isDebugEnabled()) |
| 990 | 984 | logger.debug("{} Response received on stream {} but no handler set anymore (either the request has " |
| 991 | - + "timed out or it was closed due to another error). Received message is {}", Connection.this, streamId, asDebugString(response)); | |
| 985 | + + "timed out or it was closed due to another error). Received message is {}", Connection.this, streamId, asDebugString(response)); | |
| 992 | 986 | return; |
| 993 | 987 | } |
| 994 | 988 | handler.cancelTimeout(); |
| @@ -1002,7 +996,7 @@ | ||
| 1002 | 996 | |
| 1003 | 997 | @Override |
| 1004 | 998 | public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { |
| 1005 | - if (!isClosed() && evt instanceof IdleStateEvent && ((IdleStateEvent)evt).state() == ALL_IDLE) { | |
| 999 | + if (!isClosed() && evt instanceof IdleStateEvent && ((IdleStateEvent) evt).state() == ALL_IDLE) { | |
| 1006 | 1000 | logger.debug("{} was inactive for {} seconds, sending heartbeat", Connection.this, factory.configuration.getPoolingOptions().getHeartbeatIntervalSeconds()); |
| 1007 | 1001 | write(HEARTBEAT_CALLBACK); |
| 1008 | 1002 | } |
| @@ -1034,8 +1028,7 @@ | ||
| 1034 | 1028 | |
| 1035 | 1029 | public void errorOutAllHandler(ConnectionException ce) { |
| 1036 | 1030 | Iterator<ResponseHandler> iter = pending.values().iterator(); |
| 1037 | - while (iter.hasNext()) | |
| 1038 | - { | |
| 1031 | + while (iter.hasNext()) { | |
| 1039 | 1032 | ResponseHandler handler = iter.next(); |
| 1040 | 1033 | handler.cancelTimeout(); |
| 1041 | 1034 | handler.callback.onException(Connection.this, ce, System.nanoTime() - handler.startTime, handler.retryCount); |
| @@ -1188,9 +1181,13 @@ | ||
| 1188 | 1181 | |
| 1189 | 1182 | interface ResponseCallback { |
| 1190 | 1183 | public Message.Request request(); |
| 1184 | + | |
| 1191 | 1185 | public int retryCount(); |
| 1186 | + | |
| 1192 | 1187 | public void onSet(Connection connection, Message.Response response, long latency, int retryCount); |
| 1188 | + | |
| 1193 | 1189 | public void onException(Connection connection, Exception exception, long latency, int retryCount); |
| 1190 | + | |
| 1194 | 1191 | public boolean onTimeout(Connection connection, long latency, int retryCount); |
| 1195 | 1192 | } |
| 1196 | 1193 | |
| @@ -1308,7 +1305,9 @@ | ||
| 1308 | 1305 | } |
| 1309 | 1306 | } |
| 1310 | 1307 | |
| 1311 | - /** A component that "owns" a connection, and should be notified when it dies. */ | |
| 1308 | + /** | |
| 1309 | + * A component that "owns" a connection, and should be notified when it dies. | |
| 1310 | + */ | |
| 1312 | 1311 | interface Owner { |
| 1313 | 1312 | void onConnectionDefunct(Connection connection); |
| 1314 | 1313 | } |
modified driver-core/src/main/java/com/datastax/driver/core/ConnectionException.java +2 −4
| @@ -23,14 +23,12 @@ | ||
| 23 | 23 | |
| 24 | 24 | public final InetSocketAddress address; |
| 25 | 25 | |
| 26 | - public ConnectionException(InetSocketAddress address, String msg, Throwable cause) | |
| 27 | - { | |
| 26 | + public ConnectionException(InetSocketAddress address, String msg, Throwable cause) { | |
| 28 | 27 | super(msg, cause); |
| 29 | 28 | this.address = address; |
| 30 | 29 | } |
| 31 | 30 | |
| 32 | - public ConnectionException(InetSocketAddress address, String msg) | |
| 33 | - { | |
| 31 | + public ConnectionException(InetSocketAddress address, String msg) { | |
| 34 | 32 | super(msg); |
| 35 | 33 | this.address = address; |
| 36 | 34 | } |
modified driver-core/src/main/java/com/datastax/driver/core/ConsistencyLevel.java +12 −11
| @@ -19,21 +19,22 @@ | ||
| 19 | 19 | |
| 20 | 20 | public enum ConsistencyLevel { |
| 21 | 21 | |
| 22 | - ANY (0), | |
| 23 | - ONE (1), | |
| 24 | - TWO (2), | |
| 25 | - THREE (3), | |
| 26 | - QUORUM (4), | |
| 27 | - ALL (5), | |
| 28 | - LOCAL_QUORUM (6), | |
| 29 | - EACH_QUORUM (7), | |
| 30 | - SERIAL (8), | |
| 31 | - LOCAL_SERIAL (9), | |
| 32 | - LOCAL_ONE (10); | |
| 22 | + ANY(0), | |
| 23 | + ONE(1), | |
| 24 | + TWO(2), | |
| 25 | + THREE(3), | |
| 26 | + QUORUM(4), | |
| 27 | + ALL(5), | |
| 28 | + LOCAL_QUORUM(6), | |
| 29 | + EACH_QUORUM(7), | |
| 30 | + SERIAL(8), | |
| 31 | + LOCAL_SERIAL(9), | |
| 32 | + LOCAL_ONE(10); | |
| 33 | 33 | |
| 34 | 34 | // Used by the native protocol |
| 35 | 35 | final int code; |
| 36 | 36 | private static final ConsistencyLevel[] codeIdx; |
| 37 | + | |
| 37 | 38 | static { |
| 38 | 39 | int maxCode = -1; |
| 39 | 40 | for (ConsistencyLevel cl : ConsistencyLevel.values()) |
modified driver-core/src/main/java/com/datastax/driver/core/ControlConnection.java +24 −24
| @@ -15,22 +15,22 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.net.InetAddress; | |
| 19 | -import java.net.InetSocketAddress; | |
| 20 | -import java.net.UnknownHostException; | |
| 21 | -import java.util.*; | |
| 22 | -import java.util.concurrent.*; | |
| 23 | -import java.util.concurrent.atomic.AtomicReference; | |
| 24 | - | |
| 18 | +import com.datastax.driver.core.exceptions.DriverException; | |
| 19 | +import com.datastax.driver.core.exceptions.DriverInternalError; | |
| 20 | +import com.datastax.driver.core.exceptions.NoHostAvailableException; | |
| 25 | 21 | import com.google.common.annotations.VisibleForTesting; |
| 26 | 22 | import com.google.common.base.Objects; |
| 27 | 23 | import com.google.common.util.concurrent.ListenableFuture; |
| 28 | 24 | import org.slf4j.Logger; |
| 29 | 25 | import org.slf4j.LoggerFactory; |
| 30 | 26 | |
| 31 | -import com.datastax.driver.core.exceptions.DriverException; | |
| 32 | -import com.datastax.driver.core.exceptions.DriverInternalError; | |
| 33 | -import com.datastax.driver.core.exceptions.NoHostAvailableException; | |
| 27 | +import java.net.InetAddress; | |
| 28 | +import java.net.InetSocketAddress; | |
| 29 | +import java.net.UnknownHostException; | |
| 30 | +import java.util.*; | |
| 31 | +import java.util.concurrent.ExecutionException; | |
| 32 | +import java.util.concurrent.TimeUnit; | |
| 33 | +import java.util.concurrent.atomic.AtomicReference; | |
| 34 | 34 | |
| 35 | 35 | class ControlConnection implements Host.StateListener, Connection.Owner { |
| 36 | 36 | |
| @@ -98,8 +98,8 @@ | ||
| 98 | 98 | Host connectedHost() { |
| 99 | 99 | Connection current = connectionRef.get(); |
| 100 | 100 | return (current == null) |
| 101 | - ? null | |
| 102 | - : cluster.metadata.getHost(current.address); | |
| 101 | + ? null | |
| 102 | + : cluster.metadata.getHost(current.address); | |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | void triggerReconnect() { |
| @@ -257,9 +257,9 @@ | ||
| 257 | 257 | try { |
| 258 | 258 | logger.trace("[Control connection] Registering for events"); |
| 259 | 259 | List<ProtocolEvent.Type> evs = Arrays.asList( |
| 260 | - ProtocolEvent.Type.TOPOLOGY_CHANGE, | |
| 261 | - ProtocolEvent.Type.STATUS_CHANGE, | |
| 262 | - ProtocolEvent.Type.SCHEMA_CHANGE | |
| 260 | + ProtocolEvent.Type.TOPOLOGY_CHANGE, | |
| 261 | + ProtocolEvent.Type.STATUS_CHANGE, | |
| 262 | + ProtocolEvent.Type.SCHEMA_CHANGE | |
| 263 | 263 | ); |
| 264 | 264 | connection.write(new Requests.Register(evs)); |
| 265 | 265 | |
| @@ -295,7 +295,7 @@ | ||
| 295 | 295 | } |
| 296 | 296 | |
| 297 | 297 | void refreshSchema(String keyspace, String table) throws InterruptedException { |
| 298 | - if(keyspace == null && table == null) { | |
| 298 | + if (keyspace == null && table == null) { | |
| 299 | 299 | logger.debug("[Control connection] Refreshing schema"); |
| 300 | 300 | } else { |
| 301 | 301 | logger.debug("[Control connection] Refreshing schema for {}{}", keyspace == null ? "" : keyspace, table == null ? "" : '.' + table); |
| @@ -335,8 +335,8 @@ | ||
| 335 | 335 | } |
| 336 | 336 | |
| 337 | 337 | DefaultResultSetFuture ksFuture = table == null |
| 338 | - ? new DefaultResultSetFuture(null, new Requests.Query(SELECT_KEYSPACES + whereClause)) | |
| 339 | - : null; | |
| 338 | + ? new DefaultResultSetFuture(null, new Requests.Query(SELECT_KEYSPACES + whereClause)) | |
| 339 | + : null; | |
| 340 | 340 | DefaultResultSetFuture cfFuture = new DefaultResultSetFuture(null, new Requests.Query(SELECT_COLUMN_FAMILIES + whereClause)); |
| 341 | 341 | DefaultResultSetFuture colsFuture = new DefaultResultSetFuture(null, new Requests.Query(SELECT_COLUMNS + whereClause)); |
| 342 | 342 | |
| @@ -353,7 +353,7 @@ | ||
| 353 | 353 | if (host == null || host.getCassandraVersion() == null) { |
| 354 | 354 | cassandraVersion = cluster.protocolVersion() == 1 ? VersionNumber.parse("1.2.0") : VersionNumber.parse("2.0.0"); |
| 355 | 355 | logger.warn("Cannot find Cassandra version for host {} to parse the schema, using {} based on protocol version in use. " |
| 356 | - + "If parsing the schema fails, this could be the cause", connection.address, cassandraVersion); | |
| 356 | + + "If parsing the schema fails, this could be the cause", connection.address, cassandraVersion); | |
| 357 | 357 | } else { |
| 358 | 358 | cassandraVersion = host.getCassandraVersion(); |
| 359 | 359 | } |
| @@ -417,8 +417,8 @@ | ||
| 417 | 417 | boolean isConnectedHost = c.address.equals(host.getSocketAddress()); |
| 418 | 418 | if (isConnectedHost || host.listenAddress != null) { |
| 419 | 419 | DefaultResultSetFuture future = isConnectedHost |
| 420 | - ? new DefaultResultSetFuture(null, new Requests.Query(SELECT_LOCAL)) | |
| 421 | - : new DefaultResultSetFuture(null, new Requests.Query(SELECT_PEERS + " WHERE peer='" + host.listenAddress.getHostAddress() + '\'')); | |
| 420 | + ? new DefaultResultSetFuture(null, new Requests.Query(SELECT_LOCAL)) | |
| 421 | + : new DefaultResultSetFuture(null, new Requests.Query(SELECT_PEERS + " WHERE peer='" + host.listenAddress.getHostAddress() + '\'')); | |
| 422 | 422 | c.write(future); |
| 423 | 423 | return future.get().one(); |
| 424 | 424 | } |
| @@ -499,8 +499,8 @@ | ||
| 499 | 499 | String version = row.getString("release_version"); |
| 500 | 500 | // We don't know if it's a 'local' or a 'peers' row, and only 'peers' rows have the 'peer' field. |
| 501 | 501 | InetAddress listenAddress = row.getColumnDefinitions().contains("peer") |
| 502 | - ? row.getInet("peer") | |
| 503 | - : null; | |
| 502 | + ? row.getInet("peer") | |
| 503 | + : null; | |
| 504 | 504 | |
| 505 | 505 | host.setVersionAndListenAdress(version, listenAddress); |
| 506 | 506 | } |
| @@ -692,7 +692,7 @@ | ||
| 692 | 692 | |
| 693 | 693 | if (current != null && current.address.equals(host.getSocketAddress())) { |
| 694 | 694 | logger.debug("[Control connection] {} is down/removed and it was the control host, triggering reconnect", |
| 695 | - current.address); | |
| 695 | + current.address); | |
| 696 | 696 | if (!current.isClosed()) |
| 697 | 697 | current.closeAsync(); |
| 698 | 698 | backgroundReconnect(0); |
modified driver-core/src/main/java/com/datastax/driver/core/ConvictionPolicy.java +4 −4
| @@ -15,16 +15,16 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.policies.ReconnectionPolicy; | |
| 19 | + | |
| 18 | 20 | import java.util.concurrent.atomic.AtomicInteger; |
| 19 | 21 | |
| 20 | 22 | import static java.util.concurrent.TimeUnit.MILLISECONDS; |
| 21 | 23 | import static java.util.concurrent.TimeUnit.NANOSECONDS; |
| 22 | 24 | |
| 23 | -import com.datastax.driver.core.policies.ReconnectionPolicy; | |
| 24 | - | |
| 25 | 25 | /** |
| 26 | 26 | * The policy with which to decide whether a host should be considered down. |
| 27 | - * | |
| 27 | + * <p/> | |
| 28 | 28 | * TODO: this class is fully abstract (rather than an interface) because I'm |
| 29 | 29 | * not sure it's worth exposing (and if we do expose it, we need to expose |
| 30 | 30 | * ConnectionException). Maybe just exposing say a threshold of error before |
| @@ -127,7 +127,7 @@ | ||
| 127 | 127 | @Override |
| 128 | 128 | boolean canReconnectNow() { |
| 129 | 129 | return nextReconnectionTime == Long.MIN_VALUE || |
| 130 | - System.nanoTime() >= nextReconnectionTime; | |
| 130 | + System.nanoTime() >= nextReconnectionTime; | |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | static class Factory implements ConvictionPolicy.Factory { |
modified driver-core/src/main/java/com/datastax/driver/core/DataType.java +81 −85
| @@ -15,19 +15,18 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.math.BigDecimal; | |
| 19 | -import java.math.BigInteger; | |
| 20 | -import java.net.InetAddress; | |
| 21 | -import java.nio.ByteBuffer; | |
| 22 | -import java.util.*; | |
| 23 | - | |
| 18 | +import com.datastax.driver.core.exceptions.DriverInternalError; | |
| 19 | +import com.datastax.driver.core.exceptions.InvalidTypeException; | |
| 24 | 20 | import com.google.common.base.Objects; |
| 25 | 21 | import com.google.common.collect.ImmutableList; |
| 26 | 22 | import com.google.common.collect.ImmutableSet; |
| 27 | 23 | import io.netty.buffer.ByteBuf; |
| 28 | 24 | |
| 29 | -import com.datastax.driver.core.exceptions.DriverInternalError; | |
| 30 | -import com.datastax.driver.core.exceptions.InvalidTypeException; | |
| 25 | +import java.math.BigDecimal; | |
| 26 | +import java.math.BigInteger; | |
| 27 | +import java.net.InetAddress; | |
| 28 | +import java.nio.ByteBuffer; | |
| 29 | +import java.util.*; | |
| 31 | 30 | |
| 32 | 31 | /** |
| 33 | 32 | * Data types supported by cassandra. |
| @@ -39,31 +38,32 @@ | ||
| 39 | 38 | */ |
| 40 | 39 | public enum Name { |
| 41 | 40 | |
| 42 | - ASCII (1, String.class), | |
| 43 | - BIGINT (2, Long.class), | |
| 44 | - BLOB (3, ByteBuffer.class), | |
| 45 | - BOOLEAN (4, Boolean.class), | |
| 46 | - COUNTER (5, Long.class), | |
| 47 | - DECIMAL (6, BigDecimal.class), | |
| 48 | - DOUBLE (7, Double.class), | |
| 49 | - FLOAT (8, Float.class), | |
| 50 | - INET (16, InetAddress.class), | |
| 51 | - INT (9, Integer.class), | |
| 52 | - TEXT (10, String.class), | |
| 53 | - TIMESTAMP (11, Date.class), | |
| 54 | - UUID (12, UUID.class), | |
| 55 | - VARCHAR (13, String.class), | |
| 56 | - VARINT (14, BigInteger.class), | |
| 57 | - TIMEUUID (15, UUID.class), | |
| 58 | - LIST (32, List.class), | |
| 59 | - SET (34, Set.class), | |
| 60 | - MAP (33, Map.class), | |
| 61 | - CUSTOM (0, ByteBuffer.class); | |
| 41 | + ASCII(1, String.class), | |
| 42 | + BIGINT(2, Long.class), | |
| 43 | + BLOB(3, ByteBuffer.class), | |
| 44 | + BOOLEAN(4, Boolean.class), | |
| 45 | + COUNTER(5, Long.class), | |
| 46 | + DECIMAL(6, BigDecimal.class), | |
| 47 | + DOUBLE(7, Double.class), | |
| 48 | + FLOAT(8, Float.class), | |
| 49 | + INET(16, InetAddress.class), | |
| 50 | + INT(9, Integer.class), | |
| 51 | + TEXT(10, String.class), | |
| 52 | + TIMESTAMP(11, Date.class), | |
| 53 | + UUID(12, UUID.class), | |
| 54 | + VARCHAR(13, String.class), | |
| 55 | + VARINT(14, BigInteger.class), | |
| 56 | + TIMEUUID(15, UUID.class), | |
| 57 | + LIST(32, List.class), | |
| 58 | + SET(34, Set.class), | |
| 59 | + MAP(33, Map.class), | |
| 60 | + CUSTOM(0, ByteBuffer.class); | |
| 62 | 61 | |
| 63 | 62 | final int protocolId; |
| 64 | 63 | final Class<?> javaType; |
| 65 | 64 | |
| 66 | 65 | private static final Name[] nameToIds; |
| 66 | + | |
| 67 | 67 | static { |
| 68 | 68 | int maxCode = -1; |
| 69 | 69 | for (Name name : Name.values()) |
| @@ -107,31 +107,31 @@ | ||
| 107 | 107 | |
| 108 | 108 | /** |
| 109 | 109 | * Returns the Java Class corresponding to this CQL type name. |
| 110 | - * | |
| 110 | + * <p/> | |
| 111 | 111 | * The correspondence between CQL types and java ones is as follow: |
| 112 | 112 | * <table> |
| 113 | - * <caption>DataType to Java class correspondence</caption> | |
| 114 | - * <tr><th>DataType (CQL)</th><th>Java Class</th></tr> | |
| 115 | - * <tr><td>ASCII </td><td>String</td></tr> | |
| 116 | - * <tr><td>BIGINT </td><td>Long</td></tr> | |
| 117 | - * <tr><td>BLOB </td><td>ByteBuffer</td></tr> | |
| 118 | - * <tr><td>BOOLEAN </td><td>Boolean</td></tr> | |
| 119 | - * <tr><td>COUNTER </td><td>Long</td></tr> | |
| 120 | - * <tr><td>CUSTOM </td><td>ByteBuffer</td></tr> | |
| 121 | - * <tr><td>DECIMAL </td><td>BigDecimal</td></tr> | |
| 122 | - * <tr><td>DOUBLE </td><td>Double</td></tr> | |
| 123 | - * <tr><td>FLOAT </td><td>Float</td></tr> | |
| 124 | - * <tr><td>INET </td><td>InetAddress</td></tr> | |
| 125 | - * <tr><td>INT </td><td>Integer</td></tr> | |
| 126 | - * <tr><td>LIST </td><td>List</td></tr> | |
| 127 | - * <tr><td>MAP </td><td>Map</td></tr> | |
| 128 | - * <tr><td>SET </td><td>Set</td></tr> | |
| 129 | - * <tr><td>TEXT </td><td>String</td></tr> | |
| 130 | - * <tr><td>TIMESTAMP </td><td>Date</td></tr> | |
| 131 | - * <tr><td>UUID </td><td>UUID</td></tr> | |
| 132 | - * <tr><td>VARCHAR </td><td>String</td></tr> | |
| 133 | - * <tr><td>VARINT </td><td>BigInteger</td></tr> | |
| 134 | - * <tr><td>TIMEUUID </td><td>UUID</td></tr> | |
| 113 | + * <caption>DataType to Java class correspondence</caption> | |
| 114 | + * <tr><th>DataType (CQL)</th><th>Java Class</th></tr> | |
| 115 | + * <tr><td>ASCII </td><td>String</td></tr> | |
| 116 | + * <tr><td>BIGINT </td><td>Long</td></tr> | |
| 117 | + * <tr><td>BLOB </td><td>ByteBuffer</td></tr> | |
| 118 | + * <tr><td>BOOLEAN </td><td>Boolean</td></tr> | |
| 119 | + * <tr><td>COUNTER </td><td>Long</td></tr> | |
| 120 | + * <tr><td>CUSTOM </td><td>ByteBuffer</td></tr> | |
| 121 | + * <tr><td>DECIMAL </td><td>BigDecimal</td></tr> | |
| 122 | + * <tr><td>DOUBLE </td><td>Double</td></tr> | |
| 123 | + * <tr><td>FLOAT </td><td>Float</td></tr> | |
| 124 | + * <tr><td>INET </td><td>InetAddress</td></tr> | |
| 125 | + * <tr><td>INT </td><td>Integer</td></tr> | |
| 126 | + * <tr><td>LIST </td><td>List</td></tr> | |
| 127 | + * <tr><td>MAP </td><td>Map</td></tr> | |
| 128 | + * <tr><td>SET </td><td>Set</td></tr> | |
| 129 | + * <tr><td>TEXT </td><td>String</td></tr> | |
| 130 | + * <tr><td>TIMESTAMP </td><td>Date</td></tr> | |
| 131 | + * <tr><td>UUID </td><td>UUID</td></tr> | |
| 132 | + * <tr><td>VARCHAR </td><td>String</td></tr> | |
| 133 | + * <tr><td>VARINT </td><td>BigInteger</td></tr> | |
| 134 | + * <tr><td>TIMEUUID </td><td>UUID</td></tr> | |
| 135 | 135 | * </table> |
| 136 | 136 | * |
| 137 | 137 | * @return the java Class corresponding to this CQL type name. |
| @@ -152,12 +152,14 @@ | ||
| 152 | 152 | private final TypeCodec<?> codec; |
| 153 | 153 | |
| 154 | 154 | private static final Map<Name, DataType> primitiveTypeMap = new EnumMap<Name, DataType>(Name.class); |
| 155 | + | |
| 155 | 156 | static { |
| 156 | 157 | for (Name name : Name.values()) { |
| 157 | 158 | if (!name.isCollection() && name != Name.CUSTOM) |
| 158 | 159 | primitiveTypeMap.put(name, new DataType(name, Collections.<DataType>emptyList(), TypeCodec.createFor(name))); |
| 159 | 160 | } |
| 160 | 161 | } |
| 162 | + | |
| 161 | 163 | private static final Set<DataType> primitiveTypeSet = ImmutableSet.copyOf(primitiveTypeMap.values()); |
| 162 | 164 | |
| 163 | 165 | private DataType(DataType.Name name, List<DataType> typeArguments, TypeCodec<?> codec) { |
| @@ -191,7 +193,7 @@ | ||
| 191 | 193 | |
| 192 | 194 | @SuppressWarnings("unchecked") |
| 193 | 195 | TypeCodec<Object> codec() { |
| 194 | - return (TypeCodec<Object>)codec; | |
| 196 | + return (TypeCodec<Object>) codec; | |
| 195 | 197 | } |
| 196 | 198 | |
| 197 | 199 | /** |
| @@ -364,7 +366,7 @@ | ||
| 364 | 366 | /** |
| 365 | 367 | * Returns the type of maps of {@code keyType} to {@code valueType} elements. |
| 366 | 368 | * |
| 367 | - * @param keyType the type of the map keys. | |
| 369 | + * @param keyType the type of the map keys. | |
| 368 | 370 | * @param valueType the type of the map values. |
| 369 | 371 | * @return the type of map of {@code keyType} to {@code valueType} elements. |
| 370 | 372 | */ |
| @@ -374,13 +376,13 @@ | ||
| 374 | 376 | |
| 375 | 377 | /** |
| 376 | 378 | * Returns a Custom type. |
| 377 | - * <p> | |
| 379 | + * <p/> | |
| 378 | 380 | * A custom type is defined by the name of the class used on the Cassandra |
| 379 | 381 | * side to implement it. Note that the support for custom type by the |
| 380 | 382 | * driver is limited: values of a custom type won't be interpreted by the |
| 381 | 383 | * driver in any way. They will thus have to be set (by {@link BoundStatement#setBytesUnsafe} |
| 382 | 384 | * and retrieved (by {@link Row#getBytesUnsafe}) as raw ByteBuffer. |
| 383 | - * <p> | |
| 385 | + * <p/> | |
| 384 | 386 | * The use of custom types is rarely useful and is thus not encouraged. |
| 385 | 387 | * |
| 386 | 388 | * @param typeClassName the server-side fully qualified class name for the type. |
| @@ -403,17 +405,17 @@ | ||
| 403 | 405 | |
| 404 | 406 | /** |
| 405 | 407 | * Returns the type arguments of this type. |
| 406 | - * <p> | |
| 408 | + * <p/> | |
| 407 | 409 | * Note that only the collection types (LIST, MAP, SET) have type |
| 408 | 410 | * arguments. For the other types, this will return an empty list. |
| 409 | - * <p> | |
| 411 | + * <p/> | |
| 410 | 412 | * For the collection types: |
| 411 | 413 | * <ul> |
| 412 | - * <li>For lists and sets, this method returns one argument, the type of | |
| 413 | - * the elements.</li> | |
| 414 | - * <li>For maps, this method returns two arguments, the first one is the | |
| 415 | - * type of the map keys, the second one is the type of the map | |
| 416 | - * values.</li> | |
| 414 | + * <li>For lists and sets, this method returns one argument, the type of | |
| 415 | + * the elements.</li> | |
| 416 | + * <li>For maps, this method returns two arguments, the first one is the | |
| 417 | + * type of the map keys, the second one is the type of the map | |
| 418 | + * values.</li> | |
| 417 | 419 | * </ul> |
| 418 | 420 | * |
| 419 | 421 | * @return an immutable list containing the type arguments of this type. |
| @@ -435,21 +437,20 @@ | ||
| 435 | 437 | /** |
| 436 | 438 | * Parses a string value for the type this object represent, returning its |
| 437 | 439 | * Cassandra binary representation. |
| 438 | - * <p> | |
| 440 | + * <p/> | |
| 439 | 441 | * Please note that currently, parsing collections is not supported and will |
| 440 | 442 | * throw an {@code InvalidTypeException}. |
| 441 | 443 | * |
| 442 | 444 | * @param value the value to parse. |
| 443 | 445 | * @return the binary representation of {@code value}. |
| 444 | - * | |
| 445 | 446 | * @throws InvalidTypeException if {@code value} is not a valid string |
| 446 | - * representation for this type. Please note that values for custom types | |
| 447 | - * can never be parsed and will always return this exception. | |
| 447 | + * representation for this type. Please note that values for custom types | |
| 448 | + * can never be parsed and will always return this exception. | |
| 448 | 449 | */ |
| 449 | 450 | public ByteBuffer parse(String value) { |
| 450 | 451 | if (name == Name.CUSTOM) |
| 451 | 452 | throw new InvalidTypeException(String.format("Cannot parse '%s' as value of custom type of class '%s' " |
| 452 | - + "(values for custom type cannot be parse and must be inputted as bytes directly)", value, customClassName)); | |
| 453 | + + "(values for custom type cannot be parse and must be inputted as bytes directly)", value, customClassName)); | |
| 453 | 454 | |
| 454 | 455 | if (name.isCollection()) |
| 455 | 456 | throw new InvalidTypeException(String.format("Cannot parse value as %s, parsing collections is not currently supported", name)); |
| @@ -462,10 +463,9 @@ | ||
| 462 | 463 | * |
| 463 | 464 | * @param value the value to format. |
| 464 | 465 | * @return a string corresponding to the CQL representation of {@code value}. |
| 465 | - * | |
| 466 | 466 | * @throws InvalidTypeException if {@code value} does not correspond to |
| 467 | - * a CQL value (known by the driver). Please note that for custom types this | |
| 468 | - * method will always return this exception. | |
| 467 | + * a CQL value (known by the driver). Please note that for custom types this | |
| 468 | + * method will always return this exception. | |
| 469 | 469 | */ |
| 470 | 470 | public String format(Object value) { |
| 471 | 471 | return value == null ? null : codec().format(value); |
| @@ -482,11 +482,10 @@ | ||
| 482 | 482 | |
| 483 | 483 | /** |
| 484 | 484 | * Returns the Java Class corresponding to this type. |
| 485 | - * | |
| 485 | + * <p/> | |
| 486 | 486 | * This is a shortcut for {@code getName().asJavaClass()}. |
| 487 | 487 | * |
| 488 | 488 | * @return the java Class corresponding to this type. |
| 489 | - * | |
| 490 | 489 | * @see Name#asJavaClass |
| 491 | 490 | */ |
| 492 | 491 | public Class<?> asJavaClass() { |
| @@ -506,15 +505,14 @@ | ||
| 506 | 505 | |
| 507 | 506 | /** |
| 508 | 507 | * Serialize a value of this type to bytes. |
| 509 | - * <p> | |
| 508 | + * <p/> | |
| 510 | 509 | * The actual format of the resulting bytes will correspond to the |
| 511 | 510 | * Cassandra encoding for this type. |
| 512 | 511 | * |
| 513 | 512 | * @param value the value to serialize. |
| 514 | 513 | * @return the value serialized, or {@code null} if {@code value} is null. |
| 515 | - * | |
| 516 | 514 | * @throws InvalidTypeException if {@code value} is not a valid object |
| 517 | - * for this {@code DataType}. | |
| 515 | + * for this {@code DataType}. | |
| 518 | 516 | */ |
| 519 | 517 | public ByteBuffer serialize(Object value) { |
| 520 | 518 | Class<?> providedClass = value.getClass(); |
| @@ -532,7 +530,7 @@ | ||
| 532 | 530 | |
| 533 | 531 | /** |
| 534 | 532 | * Deserialize a value of this type from the provided bytes. |
| 535 | - * <p> | |
| 533 | + * <p/> | |
| 536 | 534 | * The format of {@code bytes} must correspond to the Cassandra |
| 537 | 535 | * encoding for this type. |
| 538 | 536 | * |
| @@ -546,9 +544,8 @@ | ||
| 546 | 544 | * throwing an exception in that case. It is however highly discouraged to |
| 547 | 545 | * store empty byte buffers for types for which it doesn't make sense, so |
| 548 | 546 | * this implementation can generally be ignored). |
| 549 | - * | |
| 550 | 547 | * @throws InvalidTypeException if {@code bytes} is not a valid |
| 551 | - * encoding of an object of this {@code DataType}. | |
| 548 | + * encoding of an object of this {@code DataType}. | |
| 552 | 549 | */ |
| 553 | 550 | public Object deserialize(ByteBuffer bytes) { |
| 554 | 551 | return codec().deserialize(bytes); |
| @@ -556,7 +553,7 @@ | ||
| 556 | 553 | |
| 557 | 554 | /** |
| 558 | 555 | * Serialize an object based on its java class. |
| 559 | - * <p> | |
| 556 | + * <p/> | |
| 560 | 557 | * This is equivalent to {@link #serialize} but with the difference that |
| 561 | 558 | * the actual {@code DataType} of the resulting value is inferred from the |
| 562 | 559 | * java class of {@code value}. The correspondence between CQL {@code DataType} |
| @@ -566,10 +563,9 @@ | ||
| 566 | 563 | * |
| 567 | 564 | * @param value the value to serialize. |
| 568 | 565 | * @return the value serialized, or {@code null} if {@code value} is null. |
| 569 | - * | |
| 570 | 566 | * @throws IllegalArgumentException if {@code value} is not of a type |
| 571 | - * corresponding to a CQL3 type, i.e. is not a Class that could be returned | |
| 572 | - * by {@link DataType#asJavaClass}. | |
| 567 | + * corresponding to a CQL3 type, i.e. is not a Class that could be returned | |
| 568 | + * by {@link DataType#asJavaClass}. | |
| 573 | 569 | */ |
| 574 | 570 | public static ByteBuffer serializeValue(Object value) { |
| 575 | 571 | if (value == null) |
| @@ -591,15 +587,15 @@ | ||
| 591 | 587 | |
| 592 | 588 | @Override |
| 593 | 589 | public final int hashCode() { |
| 594 | - return Arrays.hashCode(new Object[]{ name, typeArguments, customClassName }); | |
| 590 | + return Arrays.hashCode(new Object[]{name, typeArguments, customClassName}); | |
| 595 | 591 | } |
| 596 | 592 | |
| 597 | 593 | @Override |
| 598 | 594 | public final boolean equals(Object o) { |
| 599 | - if(!(o instanceof DataType)) | |
| 595 | + if (!(o instanceof DataType)) | |
| 600 | 596 | return false; |
| 601 | 597 | |
| 602 | - DataType d = (DataType)o; | |
| 598 | + DataType d = (DataType) o; | |
| 603 | 599 | return name == d.name && typeArguments.equals(d.typeArguments) && Objects.equal(customClassName, d.customClassName); |
| 604 | 600 | } |
| 605 | 601 |
modified driver-core/src/main/java/com/datastax/driver/core/DefaultPreparedStatement.java +3 −3
| @@ -15,12 +15,12 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.policies.RetryPolicy; | |
| 19 | + | |
| 18 | 20 | import java.nio.ByteBuffer; |
| 19 | 21 | import java.util.List; |
| 20 | 22 | |
| 21 | -import com.datastax.driver.core.policies.RetryPolicy; | |
| 22 | - | |
| 23 | -public class DefaultPreparedStatement implements PreparedStatement{ | |
| 23 | +public class DefaultPreparedStatement implements PreparedStatement { | |
| 24 | 24 | |
| 25 | 25 | final PreparedId preparedId; |
| 26 | 26 |
modified driver-core/src/main/java/com/datastax/driver/core/DefaultResultSetFuture.java +39 −37
| @@ -15,16 +15,18 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.util.concurrent.ExecutionException; | |
| 19 | -import java.util.concurrent.TimeUnit; | |
| 20 | -import java.util.concurrent.TimeoutException; | |
| 21 | - | |
| 18 | +import com.datastax.driver.core.exceptions.DriverInternalError; | |
| 19 | +import com.datastax.driver.core.exceptions.NoHostAvailableException; | |
| 20 | +import com.datastax.driver.core.exceptions.QueryExecutionException; | |
| 21 | +import com.datastax.driver.core.exceptions.QueryValidationException; | |
| 22 | 22 | import com.google.common.util.concurrent.AbstractFuture; |
| 23 | 23 | import com.google.common.util.concurrent.Uninterruptibles; |
| 24 | 24 | import org.slf4j.Logger; |
| 25 | 25 | import org.slf4j.LoggerFactory; |
| 26 | 26 | |
| 27 | -import com.datastax.driver.core.exceptions.*; | |
| 27 | +import java.util.concurrent.ExecutionException; | |
| 28 | +import java.util.concurrent.TimeUnit; | |
| 29 | +import java.util.concurrent.TimeoutException; | |
| 28 | 30 | |
| 29 | 31 | /** |
| 30 | 32 | * Internal implementation of ResultSetFuture. |
| @@ -57,11 +59,11 @@ | ||
| 57 | 59 | try { |
| 58 | 60 | switch (response.type) { |
| 59 | 61 | case RESULT: |
| 60 | - Responses.Result rm = (Responses.Result)response; | |
| 62 | + Responses.Result rm = (Responses.Result) response; | |
| 61 | 63 | switch (rm.kind) { |
| 62 | 64 | case SET_KEYSPACE: |
| 63 | 65 | // propagate the keyspace change to other connections |
| 64 | - session.poolsState.setKeyspace(((Responses.Result.SetKeyspace)rm).keyspace); | |
| 66 | + session.poolsState.setKeyspace(((Responses.Result.SetKeyspace) rm).keyspace); | |
| 65 | 67 | set(ArrayBackedResultSet.fromMessage(rm, session, info, statement)); |
| 66 | 68 | break; |
| 67 | 69 | case SCHEMA_CHANGE: |
| @@ -70,7 +72,7 @@ | ||
| 70 | 72 | if (!cluster.configuration.getQueryOptions().isMetadataEnabled()) { |
| 71 | 73 | cluster.waitForSchemaAgreementAndSignal(connection, this, rs); |
| 72 | 74 | } else { |
| 73 | - Responses.Result.SchemaChange scc = (Responses.Result.SchemaChange)rm; | |
| 75 | + Responses.Result.SchemaChange scc = (Responses.Result.SchemaChange) rm; | |
| 74 | 76 | switch (scc.change) { |
| 75 | 77 | case CREATED: |
| 76 | 78 | if (scc.columnFamily.isEmpty()) { |
| @@ -99,7 +101,7 @@ | ||
| 99 | 101 | KeyspaceMetadata keyspace = cluster.metadata.getKeyspaceInternal(scc.keyspace); |
| 100 | 102 | if (keyspace == null) |
| 101 | 103 | logger.warn("Received a DROPPED notification for {}.{}, but this keyspace is unknown in our metadata", |
| 102 | - scc.keyspace, scc.columnFamily); | |
| 104 | + scc.keyspace, scc.columnFamily); | |
| 103 | 105 | else { |
| 104 | 106 | final TableMetadata removed = keyspace.removeTable(scc.columnFamily); |
| 105 | 107 | if (removed != null) { |
| @@ -133,7 +135,7 @@ | ||
| 133 | 135 | } |
| 134 | 136 | break; |
| 135 | 137 | case ERROR: |
| 136 | - setException(((Responses.Error)response).asException(connection.address)); | |
| 138 | + setException(((Responses.Error) response).asException(connection.address)); | |
| 137 | 139 | break; |
| 138 | 140 | default: |
| 139 | 141 | // This mean we have probably have a bad node, so defunct the connection |
| @@ -176,23 +178,23 @@ | ||
| 176 | 178 | |
| 177 | 179 | /** |
| 178 | 180 | * Waits for the query to return and return its result. |
| 179 | - * | |
| 181 | + * <p/> | |
| 180 | 182 | * This method is usually more convenient than {@link #get} because it: |
| 181 | 183 | * <ul> |
| 182 | - * <li>Waits for the result uninterruptibly, and so doesn't throw | |
| 183 | - * {@link InterruptedException}.</li> | |
| 184 | - * <li>Returns meaningful exceptions, instead of having to deal | |
| 185 | - * with ExecutionException.</li> | |
| 184 | + * <li>Waits for the result uninterruptibly, and so doesn't throw | |
| 185 | + * {@link InterruptedException}.</li> | |
| 186 | + * <li>Returns meaningful exceptions, instead of having to deal | |
| 187 | + * with ExecutionException.</li> | |
| 186 | 188 | * </ul> |
| 187 | 189 | * As such, it is the preferred way to get the future result. |
| 188 | 190 | * |
| 189 | 191 | * @throws NoHostAvailableException if no host in the cluster can be |
| 190 | - * contacted successfully to execute this query. | |
| 191 | - * @throws QueryExecutionException if the query triggered an execution | |
| 192 | - * exception, that is an exception thrown by Cassandra when it cannot execute | |
| 193 | - * the query with the requested consistency level successfully. | |
| 192 | + * contacted successfully to execute this query. | |
| 193 | + * @throws QueryExecutionException if the query triggered an execution | |
| 194 | + * exception, that is an exception thrown by Cassandra when it cannot execute | |
| 195 | + * the query with the requested consistency level successfully. | |
| 194 | 196 | * @throws QueryValidationException if the query is invalid (syntax error, |
| 195 | - * unauthorized or any other validation problem). | |
| 197 | + * unauthorized or any other validation problem). | |
| 196 | 198 | */ |
| 197 | 199 | public ResultSet getUninterruptibly() { |
| 198 | 200 | try { |
| @@ -205,26 +207,26 @@ | ||
| 205 | 207 | /** |
| 206 | 208 | * Waits for the provided time for the query to return and return its |
| 207 | 209 | * result if available. |
| 208 | - * | |
| 210 | + * <p/> | |
| 209 | 211 | * This method is usually more convenient than {@link #get} because it: |
| 210 | 212 | * <ul> |
| 211 | - * <li>Waits for the result uninterruptibly, and so doesn't throw | |
| 212 | - * {@link InterruptedException}.</li> | |
| 213 | - * <li>Returns meaningful exceptions, instead of having to deal | |
| 214 | - * with ExecutionException.</li> | |
| 213 | + * <li>Waits for the result uninterruptibly, and so doesn't throw | |
| 214 | + * {@link InterruptedException}.</li> | |
| 215 | + * <li>Returns meaningful exceptions, instead of having to deal | |
| 216 | + * with ExecutionException.</li> | |
| 215 | 217 | * </ul> |
| 216 | 218 | * As such, it is the preferred way to get the future result. |
| 217 | 219 | * |
| 218 | 220 | * @throws NoHostAvailableException if no host in the cluster can be |
| 219 | - * contacted successfully to execute this query. | |
| 220 | - * @throws QueryExecutionException if the query triggered an execution | |
| 221 | - * exception, that is an exception thrown by Cassandra when it cannot execute | |
| 222 | - * the query with the requested consistency level successfully. | |
| 221 | + * contacted successfully to execute this query. | |
| 222 | + * @throws QueryExecutionException if the query triggered an execution | |
| 223 | + * exception, that is an exception thrown by Cassandra when it cannot execute | |
| 224 | + * the query with the requested consistency level successfully. | |
| 223 | 225 | * @throws QueryValidationException if the query if invalid (syntax error, |
| 224 | - * unauthorized or any other validation problem). | |
| 225 | - * @throws TimeoutException if the wait timed out (Note that this is | |
| 226 | - * different from a Cassandra timeout, which is a {@code | |
| 227 | - * QueryExecutionException}). | |
| 226 | + * unauthorized or any other validation problem). | |
| 227 | + * @throws TimeoutException if the wait timed out (Note that this is | |
| 228 | + * different from a Cassandra timeout, which is a {@code | |
| 229 | + * QueryExecutionException}). | |
| 228 | 230 | */ |
| 229 | 231 | public ResultSet getUninterruptibly(long timeout, TimeUnit unit) throws TimeoutException { |
| 230 | 232 | try { |
| @@ -237,12 +239,12 @@ | ||
| 237 | 239 | /** |
| 238 | 240 | * Attempts to cancel the execution of the request corresponding to this |
| 239 | 241 | * future. This attempt will fail if the request has already returned. |
| 240 | - * <p> | |
| 242 | + * <p/> | |
| 241 | 243 | * Please note that this only cancels the request driver side, but nothing |
| 242 | 244 | * is done to interrupt the execution of the request Cassandra side (and that even |
| 243 | 245 | * if {@code mayInterruptIfRunning} is true) since Cassandra does not |
| 244 | 246 | * support such interruption. |
| 245 | - * <p> | |
| 247 | + * <p/> | |
| 246 | 248 | * This method can be used to ensure no more work is performed driver side |
| 247 | 249 | * (which, while it doesn't include stopping a request already submitted |
| 248 | 250 | * to a Cassandra node, may include not retrying another Cassandra host on |
| @@ -262,7 +264,7 @@ | ||
| 262 | 264 | * <pre> |
| 263 | 265 | * |
| 264 | 266 | * @param mayInterruptIfRunning the value of this parameter is currently |
| 265 | - * ignored. | |
| 267 | + * ignored. | |
| 266 | 268 | * @return {@code false} if the future could not be cancelled (it has already |
| 267 | 269 | * completed normally); {@code true} otherwise. |
| 268 | 270 | */ |
| @@ -271,7 +273,7 @@ | ||
| 271 | 273 | if (!super.cancel(mayInterruptIfRunning)) |
| 272 | 274 | return false; |
| 273 | 275 | |
| 274 | - if(handler != null) { | |
| 276 | + if (handler != null) { | |
| 275 | 277 | handler.cancel(); |
| 276 | 278 | } |
| 277 | 279 | return true; |
modified driver-core/src/main/java/com/datastax/driver/core/DelegatingCluster.java +2 −2
| @@ -15,11 +15,11 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | +import com.google.common.util.concurrent.ListenableFuture; | |
| 19 | + | |
| 18 | 20 | import java.net.InetSocketAddress; |
| 19 | 21 | import java.util.Collections; |
| 20 | 22 | |
| 21 | -import com.google.common.util.concurrent.ListenableFuture; | |
| 22 | - | |
| 23 | 23 | /** |
| 24 | 24 | * Base class for custom {@link Cluster} implementations that wrap another instance (delegate / decorator pattern). |
| 25 | 25 | */ |
modified driver-core/src/main/java/com/datastax/driver/core/DriverThrowables.java +4 −4
| @@ -15,18 +15,18 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.util.concurrent.ExecutionException; | |
| 19 | - | |
| 20 | 18 | import com.datastax.driver.core.exceptions.DriverException; |
| 21 | 19 | import com.datastax.driver.core.exceptions.DriverInternalError; |
| 22 | 20 | |
| 21 | +import java.util.concurrent.ExecutionException; | |
| 22 | + | |
| 23 | 23 | class DriverThrowables { |
| 24 | 24 | |
| 25 | 25 | static RuntimeException propagateCause(ExecutionException e) { |
| 26 | 26 | Throwable cause = e.getCause(); |
| 27 | 27 | |
| 28 | 28 | if (cause instanceof Error) |
| 29 | - throw ((Error)cause); | |
| 29 | + throw ((Error) cause); | |
| 30 | 30 | |
| 31 | 31 | // We could just rethrow e.getCause(). However, the cause of the ExecutionException has likely been |
| 32 | 32 | // created on the I/O thread receiving the response. Which means that the stacktrace associated |
| @@ -34,7 +34,7 @@ | ||
| 34 | 34 | // out which execute() statement actually raised the exception. So instead, we re-create the |
| 35 | 35 | // exception. |
| 36 | 36 | if (cause instanceof DriverException) |
| 37 | - throw ((DriverException)cause).copy(); | |
| 37 | + throw ((DriverException) cause).copy(); | |
| 38 | 38 | else |
| 39 | 39 | throw new DriverInternalError("Unexpected exception thrown", cause); |
| 40 | 40 | } |
modified driver-core/src/main/java/com/datastax/driver/core/EventDebouncer.java +19 −16
| @@ -15,15 +15,7 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.util.List; | |
| 19 | -import java.util.Queue; | |
| 20 | -import java.util.concurrent.*; | |
| 21 | -import java.util.concurrent.atomic.AtomicInteger; | |
| 22 | -import java.util.concurrent.atomic.AtomicReference; | |
| 23 | - | |
| 24 | -import static java.util.concurrent.TimeUnit.NANOSECONDS; | |
| 25 | -import static java.util.concurrent.TimeUnit.SECONDS; | |
| 26 | - | |
| 18 | +import com.datastax.driver.core.utils.MoreFutures; | |
| 27 | 19 | import com.google.common.collect.Lists; |
| 28 | 20 | import com.google.common.util.concurrent.FutureCallback; |
| 29 | 21 | import com.google.common.util.concurrent.Futures; |
| @@ -32,13 +24,22 @@ | ||
| 32 | 24 | import org.slf4j.Logger; |
| 33 | 25 | import org.slf4j.LoggerFactory; |
| 34 | 26 | |
| 35 | -import static com.google.common.base.Preconditions.checkNotNull; | |
| 27 | +import java.util.List; | |
| 28 | +import java.util.Queue; | |
| 29 | +import java.util.concurrent.ConcurrentLinkedQueue; | |
| 30 | +import java.util.concurrent.Future; | |
| 31 | +import java.util.concurrent.ScheduledExecutorService; | |
| 32 | +import java.util.concurrent.TimeUnit; | |
| 33 | +import java.util.concurrent.atomic.AtomicInteger; | |
| 34 | +import java.util.concurrent.atomic.AtomicReference; | |
| 36 | 35 | |
| 37 | -import com.datastax.driver.core.utils.MoreFutures; | |
| 36 | +import static com.google.common.base.Preconditions.checkNotNull; | |
| 37 | +import static java.util.concurrent.TimeUnit.NANOSECONDS; | |
| 38 | +import static java.util.concurrent.TimeUnit.SECONDS; | |
| 38 | 39 | |
| 39 | 40 | /** |
| 40 | 41 | * A helper class to debounce events received by the Control Connection. |
| 41 | - * | |
| 42 | + * <p/> | |
| 42 | 43 | * This class accumulates received events, and delivers them when either: |
| 43 | 44 | * - no events have been received for delayMs |
| 44 | 45 | * - maxPendingEvents have been received |
| @@ -87,7 +88,7 @@ | ||
| 87 | 88 | state = State.RUNNING; |
| 88 | 89 | if (!events.isEmpty()) { |
| 89 | 90 | logger.trace("{} debouncer: {} events were accumulated before the debouncer started: delivering now", |
| 90 | - name, eventCount.get()); | |
| 91 | + name, eventCount.get()); | |
| 91 | 92 | scheduleImmediateDelivery(); |
| 92 | 93 | } |
| 93 | 94 | } |
| @@ -114,7 +115,9 @@ | ||
| 114 | 115 | } |
| 115 | 116 | } |
| 116 | 117 | |
| 117 | - /** @return a future that will complete once the event has been processed */ | |
| 118 | + /** | |
| 119 | + * @return a future that will complete once the event has been processed | |
| 120 | + */ | |
| 118 | 121 | ListenableFuture<Void> eventReceived(T event) { |
| 119 | 122 | if (state == State.STOPPED) { |
| 120 | 123 | logger.trace("{} debouncer is stopped, rejecting event: {}", name, event); |
| @@ -130,8 +133,8 @@ | ||
| 130 | 133 | if (count > MAX_QUEUED_EVENTS && (now = System.nanoTime()) > lastOverflowWarning + OVERFLOW_WARNING_INTERVAL) { |
| 131 | 134 | lastOverflowWarning = now; |
| 132 | 135 | logger.warn("{} debouncer enqueued more than {} events, rejecting new events. " |
| 133 | - + "This should not happen and is likely a sign that something is wrong.", | |
| 134 | - name, MAX_QUEUED_EVENTS); | |
| 136 | + + "This should not happen and is likely a sign that something is wrong.", | |
| 137 | + name, MAX_QUEUED_EVENTS); | |
| 135 | 138 | return MoreFutures.VOID_SUCCESS; |
| 136 | 139 | } |
| 137 | 140 |
modified driver-core/src/main/java/com/datastax/driver/core/ExceptionCode.java +17 −16
| @@ -15,39 +15,40 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.exceptions.DriverInternalError; | |
| 19 | + | |
| 18 | 20 | import java.util.HashMap; |
| 19 | 21 | import java.util.Map; |
| 20 | 22 | |
| 21 | -import com.datastax.driver.core.exceptions.DriverInternalError; | |
| 22 | - | |
| 23 | 23 | /** |
| 24 | 24 | * Exceptions code, as defined by the native protocol. |
| 25 | 25 | */ |
| 26 | 26 | enum ExceptionCode { |
| 27 | 27 | |
| 28 | - SERVER_ERROR (0x0000), | |
| 29 | - PROTOCOL_ERROR (0x000A), | |
| 28 | + SERVER_ERROR(0x0000), | |
| 29 | + PROTOCOL_ERROR(0x000A), | |
| 30 | 30 | |
| 31 | - BAD_CREDENTIALS (0x0100), | |
| 31 | + BAD_CREDENTIALS(0x0100), | |
| 32 | 32 | |
| 33 | 33 | // 1xx: problem during request execution |
| 34 | - UNAVAILABLE (0x1000), | |
| 35 | - OVERLOADED (0x1001), | |
| 34 | + UNAVAILABLE(0x1000), | |
| 35 | + OVERLOADED(0x1001), | |
| 36 | 36 | IS_BOOTSTRAPPING(0x1002), |
| 37 | - TRUNCATE_ERROR (0x1003), | |
| 38 | - WRITE_TIMEOUT (0x1100), | |
| 39 | - READ_TIMEOUT (0x1200), | |
| 37 | + TRUNCATE_ERROR(0x1003), | |
| 38 | + WRITE_TIMEOUT(0x1100), | |
| 39 | + READ_TIMEOUT(0x1200), | |
| 40 | 40 | |
| 41 | 41 | // 2xx: problem validating the request |
| 42 | - SYNTAX_ERROR (0x2000), | |
| 43 | - UNAUTHORIZED (0x2100), | |
| 44 | - INVALID (0x2200), | |
| 45 | - CONFIG_ERROR (0x2300), | |
| 46 | - ALREADY_EXISTS (0x2400), | |
| 47 | - UNPREPARED (0x2500); | |
| 42 | + SYNTAX_ERROR(0x2000), | |
| 43 | + UNAUTHORIZED(0x2100), | |
| 44 | + INVALID(0x2200), | |
| 45 | + CONFIG_ERROR(0x2300), | |
| 46 | + ALREADY_EXISTS(0x2400), | |
| 47 | + UNPREPARED(0x2500); | |
| 48 | 48 | |
| 49 | 49 | public final int value; |
| 50 | 50 | private static final Map<Integer, ExceptionCode> valueToCode = new HashMap<Integer, ExceptionCode>(ExceptionCode.values().length); |
| 51 | + | |
| 51 | 52 | static { |
| 52 | 53 | for (ExceptionCode code : ExceptionCode.values()) |
| 53 | 54 | valueToCode.put(code.value, code); |
modified driver-core/src/main/java/com/datastax/driver/core/ExecutionInfo.java +11 −13
| @@ -15,11 +15,11 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.utils.Bytes; | |
| 19 | + | |
| 18 | 20 | import java.nio.ByteBuffer; |
| 19 | 21 | import java.util.List; |
| 20 | 22 | |
| 21 | -import com.datastax.driver.core.utils.Bytes; | |
| 22 | - | |
| 23 | 23 | /** |
| 24 | 24 | * Basic information on the execution of a query. |
| 25 | 25 | */ |
| @@ -62,7 +62,7 @@ | ||
| 62 | 62 | |
| 63 | 63 | /** |
| 64 | 64 | * The list of tried hosts for this query. |
| 65 | - * <p> | |
| 65 | + * <p/> | |
| 66 | 66 | * In general, this will be a singleton list with the host that coordinated |
| 67 | 67 | * that query. However: |
| 68 | 68 | * <ul> |
| @@ -74,7 +74,7 @@ | ||
| 74 | 74 | * <li>if {@link com.datastax.driver.core.policies.SpeculativeExecutionPolicy speculative executions} |
| 75 | 75 | * are enabled, other hosts might have been tried speculatively as well.</li> |
| 76 | 76 | * </ul> |
| 77 | - * <p> | |
| 77 | + * <p/> | |
| 78 | 78 | * If you are only interested in fetching the final (and often only) node |
| 79 | 79 | * coordinating the query, {@link #getQueriedHost} provides a shortcut to |
| 80 | 80 | * fetch the last element of the list returned by this method. |
| @@ -87,7 +87,7 @@ | ||
| 87 | 87 | |
| 88 | 88 | /** |
| 89 | 89 | * Return the Cassandra host that coordinated this query. |
| 90 | - * <p> | |
| 90 | + * <p/> | |
| 91 | 91 | * This is a shortcut for {@code getTriedHosts().get(getTriedHosts().size())}. |
| 92 | 92 | * |
| 93 | 93 | * @return return the Cassandra host that coordinated this query. |
| @@ -101,7 +101,7 @@ | ||
| 101 | 101 | * due to the {@link com.datastax.driver.core.policies.RetryPolicy}, this |
| 102 | 102 | * return the biggest consistency level that has been actually achieved by |
| 103 | 103 | * the query. |
| 104 | - * <p> | |
| 104 | + * <p/> | |
| 105 | 105 | * Note that the default {@code RetryPolicy} |
| 106 | 106 | * ({@link com.datastax.driver.core.policies.DefaultRetryPolicy}) |
| 107 | 107 | * will never allow a query to be successful without achieving the |
| @@ -131,12 +131,11 @@ | ||
| 131 | 131 | |
| 132 | 132 | /** |
| 133 | 133 | * The paging state of the query. |
| 134 | - * | |
| 134 | + * <p/> | |
| 135 | 135 | * This object represents the next page to be fetched if this query is |
| 136 | 136 | * multi page. It can be saved and reused later on the same statement. |
| 137 | 137 | * |
| 138 | 138 | * @return the paging state or null if there is no next page. |
| 139 | - * | |
| 140 | 139 | * @see Statement#setPagingState(PagingState) |
| 141 | 140 | */ |
| 142 | 141 | public PagingState getPagingState() { |
| @@ -147,12 +146,11 @@ | ||
| 147 | 146 | |
| 148 | 147 | /** |
| 149 | 148 | * Returns the "raw" paging state of the query. |
| 150 | - * | |
| 149 | + * <p/> | |
| 151 | 150 | * Contrary to {@link #getPagingState()}, there will be no validation when |
| 152 | 151 | * this is later reinjected into a statement. |
| 153 | 152 | * |
| 154 | 153 | * @return the paging state or null if there is no next page. |
| 155 | - * | |
| 156 | 154 | * @see Statement#setPagingStateUnsafe(byte[]) |
| 157 | 155 | */ |
| 158 | 156 | public byte[] getPagingStateUnsafe() { |
| @@ -163,15 +161,15 @@ | ||
| 163 | 161 | |
| 164 | 162 | /** |
| 165 | 163 | * Whether the cluster had reached schema agreement after the execution of this query. |
| 166 | - * | |
| 164 | + * <p/> | |
| 167 | 165 | * After a successful schema-altering query (ex: creating a table), the driver |
| 168 | 166 | * will check if the cluster's nodes agree on the new schema version. If not, |
| 169 | 167 | * it will keep retrying for a given delay (configurable via |
| 170 | 168 | * {@link Cluster.Builder#withMaxSchemaAgreementWaitSeconds(int)}). |
| 171 | - * <p> | |
| 169 | + * <p/> | |
| 172 | 170 | * If this method returns {@code false}, clients can call {@link Metadata#checkSchemaAgreement()} |
| 173 | 171 | * later to perform the check manually. |
| 174 | - * <p> | |
| 172 | + * <p/> | |
| 175 | 173 | * Note that the schema agreement check is only performed for schema-altering queries |
| 176 | 174 | * For other query types, this method will always return {@code true}. |
| 177 | 175 | * |
modified driver-core/src/main/java/com/datastax/driver/core/Frame.java +11 −13
| @@ -15,15 +15,14 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.util.EnumSet; | |
| 19 | -import java.util.List; | |
| 20 | - | |
| 18 | +import com.datastax.driver.core.exceptions.DriverInternalError; | |
| 21 | 19 | import io.netty.buffer.ByteBuf; |
| 22 | 20 | import io.netty.channel.ChannelHandler; |
| 23 | 21 | import io.netty.channel.ChannelHandlerContext; |
| 24 | 22 | import io.netty.handler.codec.*; |
| 25 | 23 | |
| 26 | -import com.datastax.driver.core.exceptions.DriverInternalError; | |
| 24 | +import java.util.EnumSet; | |
| 25 | +import java.util.List; | |
| 27 | 26 | |
| 28 | 27 | class Frame { |
| 29 | 28 | |
| @@ -33,13 +32,13 @@ | ||
| 33 | 32 | /** |
| 34 | 33 | * On-wire frame. |
| 35 | 34 | * Frames are defined as: |
| 36 | - * | |
| 37 | - * 0 8 16 24 32 | |
| 38 | - * +---------+---------+---------+---------+ | |
| 39 | - * | version | flags | stream | opcode | | |
| 40 | - * +---------+---------+---------+---------+ | |
| 41 | - * | length | | |
| 42 | - * +---------+---------+---------+---------+ | |
| 35 | + * <p/> | |
| 36 | + * 0 8 16 24 32 | |
| 37 | + * +---------+---------+---------+---------+ | |
| 38 | + * | version | flags | stream | opcode | | |
| 39 | + * +---------+---------+---------+---------+ | |
| 40 | + * | length | | |
| 41 | + * +---------+---------+---------+---------+ | |
| 43 | 42 | */ |
| 44 | 43 | private Frame(Header header, ByteBuf body) { |
| 45 | 44 | this.header = header; |
| @@ -88,8 +87,7 @@ | ||
| 88 | 87 | this.opcode = opcode; |
| 89 | 88 | } |
| 90 | 89 | |
| 91 | - public static enum Flag | |
| 92 | - { | |
| 90 | + public static enum Flag { | |
| 93 | 91 | // The order of that enum matters!! |
| 94 | 92 | COMPRESSED, |
| 95 | 93 | TRACING; |
modified driver-core/src/main/java/com/datastax/driver/core/FrameCompressor.java +9 −7
| @@ -15,26 +15,27 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.io.IOException; | |
| 19 | - | |
| 18 | +import com.datastax.driver.core.exceptions.DriverInternalError; | |
| 20 | 19 | import io.netty.buffer.Unpooled; |
| 21 | 20 | import net.jpountz.lz4.LZ4Factory; |
| 22 | 21 | import org.slf4j.Logger; |
| 23 | 22 | import org.slf4j.LoggerFactory; |
| 24 | 23 | import org.xerial.snappy.Snappy; |
| 25 | 24 | |
| 26 | -import com.datastax.driver.core.exceptions.DriverInternalError; | |
| 25 | +import java.io.IOException; | |
| 27 | 26 | |
| 28 | 27 | abstract class FrameCompressor { |
| 29 | 28 | |
| 30 | 29 | private static final Logger logger = LoggerFactory.getLogger(FrameCompressor.class); |
| 31 | 30 | |
| 32 | 31 | public abstract Frame compress(Frame frame) throws IOException; |
| 32 | + | |
| 33 | 33 | public abstract Frame decompress(Frame frame) throws IOException; |
| 34 | 34 | |
| 35 | 35 | public static class SnappyCompressor extends FrameCompressor { |
| 36 | 36 | |
| 37 | 37 | public static final SnappyCompressor instance; |
| 38 | + | |
| 38 | 39 | static { |
| 39 | 40 | SnappyCompressor i; |
| 40 | 41 | try { |
| @@ -78,6 +79,7 @@ | ||
| 78 | 79 | public static class LZ4Compressor extends FrameCompressor { |
| 79 | 80 | |
| 80 | 81 | public static final LZ4Compressor instance; |
| 82 | + | |
| 81 | 83 | static { |
| 82 | 84 | LZ4Compressor i; |
| 83 | 85 | try { |
| @@ -111,7 +113,7 @@ | ||
| 111 | 113 | |
| 112 | 114 | output[0] = (byte) (input.length >>> 24); |
| 113 | 115 | output[1] = (byte) (input.length >>> 16); |
| 114 | - output[2] = (byte) (input.length >>> 8); | |
| 116 | + output[2] = (byte) (input.length >>> 8); | |
| 115 | 117 | output[3] = (byte) (input.length); |
| 116 | 118 | |
| 117 | 119 | try { |
| @@ -126,9 +128,9 @@ | ||
| 126 | 128 | byte[] input = CBUtil.readRawBytes(frame.body); |
| 127 | 129 | |
| 128 | 130 | int uncompressedLength = ((input[0] & 0xFF) << 24) |
| 129 | - | ((input[1] & 0xFF) << 16) | |
| 130 | - | ((input[2] & 0xFF) << 8) | |
| 131 | - | ((input[3] & 0xFF)); | |
| 131 | + | ((input[1] & 0xFF) << 16) | |
| 132 | + | ((input[2] & 0xFF) << 8) | |
| 133 | + | ((input[3] & 0xFF)); | |
| 132 | 134 | |
| 133 | 135 | byte[] output = new byte[uncompressedLength]; |
| 134 | 136 |
modified driver-core/src/main/java/com/datastax/driver/core/GettableData.java +65 −101
| @@ -15,14 +15,14 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.exceptions.InvalidTypeException; | |
| 19 | + | |
| 18 | 20 | import java.math.BigDecimal; |
| 19 | 21 | import java.math.BigInteger; |
| 20 | 22 | import java.net.InetAddress; |
| 21 | 23 | import java.nio.ByteBuffer; |
| 22 | 24 | import java.util.*; |
| 23 | 25 | |
| 24 | -import com.datastax.driver.core.exceptions.InvalidTypeException; | |
| 25 | - | |
| 26 | 26 | /** |
| 27 | 27 | * Collection of (typed) CQL values that can be retrieved by index (starting at 0), or by name. |
| 28 | 28 | */ |
| @@ -32,7 +32,6 @@ | ||
| 32 | 32 | * |
| 33 | 33 | * @param i the index ({@code 0 <= i < size()}) of the value to check. |
| 34 | 34 | * @return whether the {@code i}th value is NULL. |
| 35 | - * | |
| 36 | 35 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 37 | 36 | */ |
| 38 | 37 | boolean isNull(int i); |
| @@ -42,7 +41,6 @@ | ||
| 42 | 41 | * |
| 43 | 42 | * @param name the name of the value to check. |
| 44 | 43 | * @return whether the value for {@code name} is NULL. |
| 45 | - * | |
| 46 | 44 | * @throws IllegalArgumentException if {@code name} is not a valid name for this object. |
| 47 | 45 | */ |
| 48 | 46 | boolean isNull(String name); |
| @@ -53,9 +51,8 @@ | ||
| 53 | 51 | * @param i the index to retrieve. |
| 54 | 52 | * @return the boolean value of the {@code i}th value. If the |
| 55 | 53 | * value is NULL, {@code false} is returned. |
| 56 | - * | |
| 57 | 54 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 58 | - * @throws InvalidTypeException if value {@code i} is not of type BOOLEAN. | |
| 55 | + * @throws InvalidTypeException if value {@code i} is not of type BOOLEAN. | |
| 59 | 56 | */ |
| 60 | 57 | boolean getBool(int i); |
| 61 | 58 | |
| @@ -65,9 +62,8 @@ | ||
| 65 | 62 | * @param name the name to retrieve. |
| 66 | 63 | * @return the boolean value for {@code name}. If the value is NULL, |
| 67 | 64 | * {@code false} is returned. |
| 68 | - * | |
| 69 | 65 | * @throws IllegalArgumentException if {@code name} is not a valid name for this object. |
| 70 | - * @throws InvalidTypeException if value {@code name} is not of type BOOLEAN. | |
| 66 | + * @throws InvalidTypeException if value {@code name} is not of type BOOLEAN. | |
| 71 | 67 | */ |
| 72 | 68 | boolean getBool(String name); |
| 73 | 69 | |
| @@ -77,9 +73,8 @@ | ||
| 77 | 73 | * @param i the index to retrieve. |
| 78 | 74 | * @return the value of the {@code i}th value as an integer. If the |
| 79 | 75 | * value is NULL, {@code 0} is returned. |
| 80 | - * | |
| 81 | 76 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 82 | - * @throws InvalidTypeException if value {@code i} is not of type INT. | |
| 77 | + * @throws InvalidTypeException if value {@code i} is not of type INT. | |
| 83 | 78 | */ |
| 84 | 79 | int getInt(int i); |
| 85 | 80 | |
| @@ -89,9 +84,8 @@ | ||
| 89 | 84 | * @param name the name to retrieve. |
| 90 | 85 | * @return the value for {@code name} as an integer. If the value is NULL, |
| 91 | 86 | * {@code 0} is returned. |
| 92 | - * | |
| 93 | 87 | * @throws IllegalArgumentException if {@code name} is not a valid name for this object. |
| 94 | - * @throws InvalidTypeException if value {@code name} is not of type INT. | |
| 88 | + * @throws InvalidTypeException if value {@code name} is not of type INT. | |
| 95 | 89 | */ |
| 96 | 90 | int getInt(String name); |
| 97 | 91 | |
| @@ -101,9 +95,8 @@ | ||
| 101 | 95 | * @param i the index to retrieve. |
| 102 | 96 | * @return the value of the {@code i}th value as a long. If the |
| 103 | 97 | * value is NULL, {@code 0L} is returned. |
| 104 | - * | |
| 105 | 98 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 106 | - * @throws InvalidTypeException if value {@code i} is not of type BIGINT or COUNTER. | |
| 99 | + * @throws InvalidTypeException if value {@code i} is not of type BIGINT or COUNTER. | |
| 107 | 100 | */ |
| 108 | 101 | long getLong(int i); |
| 109 | 102 | |
| @@ -113,9 +106,8 @@ | ||
| 113 | 106 | * @param name the name to retrieve. |
| 114 | 107 | * @return the value for {@code name} as a long. If the value is NULL, |
| 115 | 108 | * {@code 0L} is returned. |
| 116 | - * | |
| 117 | 109 | * @throws IllegalArgumentException if {@code name} is not a valid name for this object. |
| 118 | - * @throws InvalidTypeException if value {@code i} is not of type BIGINT or COUNTER. | |
| 110 | + * @throws InvalidTypeException if value {@code i} is not of type BIGINT or COUNTER. | |
| 119 | 111 | */ |
| 120 | 112 | long getLong(String name); |
| 121 | 113 | |
| @@ -125,9 +117,8 @@ | ||
| 125 | 117 | * @param i the index to retrieve. |
| 126 | 118 | * @return the value of the {@code i}th value as a data. If the |
| 127 | 119 | * value is NULL, {@code null} is returned. |
| 128 | - * | |
| 129 | 120 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 130 | - * @throws InvalidTypeException if value {@code i} is not of type TIMESTAMP. | |
| 121 | + * @throws InvalidTypeException if value {@code i} is not of type TIMESTAMP. | |
| 131 | 122 | */ |
| 132 | 123 | Date getDate(int i); |
| 133 | 124 | |
| @@ -137,9 +128,8 @@ | ||
| 137 | 128 | * @param name the name to retrieve. |
| 138 | 129 | * @return the value for {@code name} as a date. If the value is NULL, |
| 139 | 130 | * {@code null} is returned. |
| 140 | - * | |
| 141 | 131 | * @throws IllegalArgumentException if {@code name} is not a valid name for this object. |
| 142 | - * @throws InvalidTypeException if value {@code name} is not of type TIMESTAMP. | |
| 132 | + * @throws InvalidTypeException if value {@code name} is not of type TIMESTAMP. | |
| 143 | 133 | */ |
| 144 | 134 | Date getDate(String name); |
| 145 | 135 | |
| @@ -149,9 +139,8 @@ | ||
| 149 | 139 | * @param i the index to retrieve. |
| 150 | 140 | * @return the value of the {@code i}th value as a float. If the |
| 151 | 141 | * value is NULL, {@code 0.0f} is returned. |
| 152 | - * | |
| 153 | 142 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 154 | - * @throws InvalidTypeException if value {@code i} is not of type FLOAT. | |
| 143 | + * @throws InvalidTypeException if value {@code i} is not of type FLOAT. | |
| 155 | 144 | */ |
| 156 | 145 | float getFloat(int i); |
| 157 | 146 | |
| @@ -161,9 +150,8 @@ | ||
| 161 | 150 | * @param name the name to retrieve. |
| 162 | 151 | * @return the value for {@code name} as a float. If the value is NULL, |
| 163 | 152 | * {@code 0.0f} is returned. |
| 164 | - * | |
| 165 | 153 | * @throws IllegalArgumentException if {@code name} is not a valid name for this object. |
| 166 | - * @throws InvalidTypeException if value {@code name} is not of type FLOAT. | |
| 154 | + * @throws InvalidTypeException if value {@code name} is not of type FLOAT. | |
| 167 | 155 | */ |
| 168 | 156 | float getFloat(String name); |
| 169 | 157 | |
| @@ -173,9 +161,8 @@ | ||
| 173 | 161 | * @param i the index to retrieve. |
| 174 | 162 | * @return the value of the {@code i}th value as a double. If the |
| 175 | 163 | * value is NULL, {@code 0.0} is returned. |
| 176 | - * | |
| 177 | 164 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 178 | - * @throws InvalidTypeException if value {@code i} is not of type DOUBLE. | |
| 165 | + * @throws InvalidTypeException if value {@code i} is not of type DOUBLE. | |
| 179 | 166 | */ |
| 180 | 167 | double getDouble(int i); |
| 181 | 168 | |
| @@ -185,15 +172,14 @@ | ||
| 185 | 172 | * @param name the name to retrieve. |
| 186 | 173 | * @return the value for {@code name} as a double. If the value is NULL, |
| 187 | 174 | * {@code 0.0} is returned. |
| 188 | - * | |
| 189 | 175 | * @throws IllegalArgumentException if {@code name} is not a valid name for this object. |
| 190 | - * @throws InvalidTypeException if value {@code name} is not of type DOUBLE. | |
| 176 | + * @throws InvalidTypeException if value {@code name} is not of type DOUBLE. | |
| 191 | 177 | */ |
| 192 | 178 | double getDouble(String name); |
| 193 | 179 | |
| 194 | 180 | /** |
| 195 | 181 | * Returns the {@code i}th value as a ByteBuffer. |
| 196 | - * | |
| 182 | + * <p/> | |
| 197 | 183 | * Note: this method always return the bytes composing the value, even if |
| 198 | 184 | * it is not of type BLOB. That is, this method never throw an |
| 199 | 185 | * InvalidTypeException. However, if the type is not BLOB, it is up to the |
| @@ -202,14 +188,13 @@ | ||
| 202 | 188 | * @param i the index to retrieve. |
| 203 | 189 | * @return the value of the {@code i}th value as a ByteBuffer. If the |
| 204 | 190 | * value is NULL, {@code null} is returned. |
| 205 | - * | |
| 206 | 191 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 207 | 192 | */ |
| 208 | 193 | ByteBuffer getBytesUnsafe(int i); |
| 209 | 194 | |
| 210 | 195 | /** |
| 211 | 196 | * Returns the value for {@code name} as a ByteBuffer. |
| 212 | - * | |
| 197 | + * <p/> | |
| 213 | 198 | * Note: this method always return the bytes composing the value, even if |
| 214 | 199 | * it is not of type BLOB. That is, this method never throw an |
| 215 | 200 | * InvalidTypeException. However, if the type is not BLOB, it is up to the |
| @@ -218,38 +203,35 @@ | ||
| 218 | 203 | * @param name the name to retrieve. |
| 219 | 204 | * @return the value for {@code name} as a ByteBuffer. If the value is NULL, |
| 220 | 205 | * {@code null} is returned. |
| 221 | - * | |
| 222 | 206 | * @throws IllegalArgumentException if {@code name} is not a valid name for this object. |
| 223 | 207 | */ |
| 224 | 208 | ByteBuffer getBytesUnsafe(String name); |
| 225 | 209 | |
| 226 | 210 | /** |
| 227 | 211 | * Returns the {@code i}th value as a byte array. |
| 228 | - * <p> | |
| 212 | + * <p/> | |
| 229 | 213 | * Note that this method validate that the value is of type BLOB. If you want to retrieve |
| 230 | 214 | * the bytes for any type of values, use {@link #getBytesUnsafe(int)} instead. |
| 231 | 215 | * |
| 232 | 216 | * @param i the index to retrieve. |
| 233 | 217 | * @return the value of the {@code i}th value as a byte array. If the |
| 234 | 218 | * value is NULL, {@code null} is returned. |
| 235 | - * | |
| 236 | 219 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 237 | - * @throws InvalidTypeException if value {@code i} type is not of type BLOB. | |
| 220 | + * @throws InvalidTypeException if value {@code i} type is not of type BLOB. | |
| 238 | 221 | */ |
| 239 | 222 | ByteBuffer getBytes(int i); |
| 240 | 223 | |
| 241 | 224 | /** |
| 242 | 225 | * Returns the value for {@code name} as a byte array. |
| 243 | - * <p> | |
| 226 | + * <p/> | |
| 244 | 227 | * Note that this method validate that the value is of type BLOB. If you want to retrieve |
| 245 | 228 | * the bytes for any type of values, use {@link #getBytesUnsafe(String)} instead. |
| 246 | 229 | * |
| 247 | 230 | * @param name the name to retrieve. |
| 248 | 231 | * @return the value for {@code name} as a byte array. If the value is NULL, |
| 249 | 232 | * {@code null} is returned. |
| 250 | - * | |
| 251 | 233 | * @throws IllegalArgumentException if {@code name} is not a valid name for this object. |
| 252 | - * @throws InvalidTypeException if value {@code i} type is not of type BLOB. | |
| 234 | + * @throws InvalidTypeException if value {@code i} type is not of type BLOB. | |
| 253 | 235 | */ |
| 254 | 236 | ByteBuffer getBytes(String name); |
| 255 | 237 | |
| @@ -259,10 +241,9 @@ | ||
| 259 | 241 | * @param i the index to retrieve. |
| 260 | 242 | * @return the value of the {@code i}th value as a string. If the |
| 261 | 243 | * value is NULL, {@code null} is returned. |
| 262 | - * | |
| 263 | 244 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 264 | - * @throws InvalidTypeException if value {@code i} type is none of: | |
| 265 | - * VARCHAR, TEXT or ASCII. | |
| 245 | + * @throws InvalidTypeException if value {@code i} type is none of: | |
| 246 | + * VARCHAR, TEXT or ASCII. | |
| 266 | 247 | */ |
| 267 | 248 | String getString(int i); |
| 268 | 249 | |
| @@ -272,10 +253,9 @@ | ||
| 272 | 253 | * @param name the name to retrieve. |
| 273 | 254 | * @return the value for {@code name} as a string. If the value is NULL, |
| 274 | 255 | * {@code null} is returned. |
| 275 | - * | |
| 276 | 256 | * @throws IllegalArgumentException if {@code name} is not a valid name for this object. |
| 277 | - * @throws InvalidTypeException if value {@code name} type is none of: | |
| 278 | - * VARCHAR, TEXT or ASCII. | |
| 257 | + * @throws InvalidTypeException if value {@code name} type is none of: | |
| 258 | + * VARCHAR, TEXT or ASCII. | |
| 279 | 259 | */ |
| 280 | 260 | String getString(String name); |
| 281 | 261 | |
| @@ -285,9 +265,8 @@ | ||
| 285 | 265 | * @param i the index to retrieve. |
| 286 | 266 | * @return the value of the {@code i}th value as a variable |
| 287 | 267 | * length integer. If the value is NULL, {@code null} is returned. |
| 288 | - * | |
| 289 | 268 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 290 | - * @throws InvalidTypeException if value {@code i} is not of type VARINT. | |
| 269 | + * @throws InvalidTypeException if value {@code i} is not of type VARINT. | |
| 291 | 270 | */ |
| 292 | 271 | BigInteger getVarint(int i); |
| 293 | 272 | |
| @@ -297,9 +276,8 @@ | ||
| 297 | 276 | * @param name the name to retrieve. |
| 298 | 277 | * @return the value for {@code name} as a variable length integer. |
| 299 | 278 | * If the value is NULL, {@code null} is returned. |
| 300 | - * | |
| 301 | 279 | * @throws IllegalArgumentException if {@code name} is not a valid name for this object. |
| 302 | - * @throws InvalidTypeException if value {@code name} is not of type VARINT. | |
| 280 | + * @throws InvalidTypeException if value {@code name} is not of type VARINT. | |
| 303 | 281 | */ |
| 304 | 282 | BigInteger getVarint(String name); |
| 305 | 283 | |
| @@ -309,9 +287,8 @@ | ||
| 309 | 287 | * @param i the index to retrieve. |
| 310 | 288 | * @return the value of the {@code i}th value as a variable |
| 311 | 289 | * length decimal. If the value is NULL, {@code null} is returned. |
| 312 | - * | |
| 313 | 290 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 314 | - * @throws InvalidTypeException if value {@code i} is not of type DECIMAL. | |
| 291 | + * @throws InvalidTypeException if value {@code i} is not of type DECIMAL. | |
| 315 | 292 | */ |
| 316 | 293 | BigDecimal getDecimal(int i); |
| 317 | 294 | |
| @@ -321,9 +298,8 @@ | ||
| 321 | 298 | * @param name the name to retrieve. |
| 322 | 299 | * @return the value for {@code name} as a variable length decimal. |
| 323 | 300 | * If the value is NULL, {@code null} is returned. |
| 324 | - * | |
| 325 | 301 | * @throws IllegalArgumentException if {@code name} is not a valid name for this object. |
| 326 | - * @throws InvalidTypeException if value {@code name} is not of type DECIMAL. | |
| 302 | + * @throws InvalidTypeException if value {@code name} is not of type DECIMAL. | |
| 327 | 303 | */ |
| 328 | 304 | BigDecimal getDecimal(String name); |
| 329 | 305 | |
| @@ -333,10 +309,9 @@ | ||
| 333 | 309 | * @param i the index to retrieve. |
| 334 | 310 | * @return the value of the {@code i}th value as a UUID. |
| 335 | 311 | * If the value is NULL, {@code null} is returned. |
| 336 | - * | |
| 337 | 312 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 338 | - * @throws InvalidTypeException if value {@code i} is not of type UUID | |
| 339 | - * or TIMEUUID. | |
| 313 | + * @throws InvalidTypeException if value {@code i} is not of type UUID | |
| 314 | + * or TIMEUUID. | |
| 340 | 315 | */ |
| 341 | 316 | UUID getUUID(int i); |
| 342 | 317 | |
| @@ -346,10 +321,9 @@ | ||
| 346 | 321 | * @param name the name to retrieve. |
| 347 | 322 | * @return the value for {@code name} as a UUID. |
| 348 | 323 | * If the value is NULL, {@code null} is returned. |
| 349 | - * | |
| 350 | 324 | * @throws IllegalArgumentException if {@code name} is not a valid name for this object. |
| 351 | - * @throws InvalidTypeException if value {@code name} is not of type | |
| 352 | - * UUID or TIMEUUID. | |
| 325 | + * @throws InvalidTypeException if value {@code name} is not of type | |
| 326 | + * UUID or TIMEUUID. | |
| 353 | 327 | */ |
| 354 | 328 | UUID getUUID(String name); |
| 355 | 329 | |
| @@ -359,9 +333,8 @@ | ||
| 359 | 333 | * @param i the index to retrieve. |
| 360 | 334 | * @return the value of the {@code i}th value as an InetAddress. |
| 361 | 335 | * If the value is NULL, {@code null} is returned. |
| 362 | - * | |
| 363 | 336 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 364 | - * @throws InvalidTypeException if value {@code i} is not of type INET. | |
| 337 | + * @throws InvalidTypeException if value {@code i} is not of type INET. | |
| 365 | 338 | */ |
| 366 | 339 | InetAddress getInet(int i); |
| 367 | 340 | |
| @@ -371,120 +344,113 @@ | ||
| 371 | 344 | * @param name the name to retrieve. |
| 372 | 345 | * @return the value for {@code name} as an InetAddress. |
| 373 | 346 | * If the value is NULL, {@code null} is returned. |
| 374 | - * | |
| 375 | 347 | * @throws IllegalArgumentException if {@code name} is not a valid name for this object. |
| 376 | - * @throws InvalidTypeException if value {@code name} is not of type | |
| 377 | - * INET. | |
| 348 | + * @throws InvalidTypeException if value {@code name} is not of type | |
| 349 | + * INET. | |
| 378 | 350 | */ |
| 379 | 351 | InetAddress getInet(String name); |
| 380 | 352 | |
| 381 | 353 | /** |
| 382 | 354 | * Returns the {@code i}th value as a list. |
| 383 | 355 | * |
| 384 | - * @param <T> the type of the elements of the list to return. | |
| 385 | - * @param i the index to retrieve. | |
| 356 | + * @param <T> the type of the elements of the list to return. | |
| 357 | + * @param i the index to retrieve. | |
| 386 | 358 | * @param elementsClass the class for the elements of the list to retrieve. |
| 387 | 359 | * @return the value of the {@code i}th value as a list of |
| 388 | 360 | * {@code elementsClass} objects. If the value is NULL, an empty list is |
| 389 | 361 | * returned (note that Cassandra makes no difference between an empty list |
| 390 | 362 | * and column of type list that is not set). The returned list is immutable. |
| 391 | - * | |
| 392 | 363 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 393 | - * @throws InvalidTypeException if value {@code i} is not a list or if its | |
| 394 | - * elements are not of class {@code elementsClass}. | |
| 364 | + * @throws InvalidTypeException if value {@code i} is not a list or if its | |
| 365 | + * elements are not of class {@code elementsClass}. | |
| 395 | 366 | */ |
| 396 | 367 | <T> List<T> getList(int i, Class<T> elementsClass); |
| 397 | 368 | |
| 398 | 369 | /** |
| 399 | 370 | * Returns the value for {@code name} as a list. |
| 400 | 371 | * |
| 401 | - * @param <T> the type of the elements of the list to return. | |
| 402 | - * @param name the name to retrieve. | |
| 372 | + * @param <T> the type of the elements of the list to return. | |
| 373 | + * @param name the name to retrieve. | |
| 403 | 374 | * @param elementsClass the class for the elements of the list to retrieve. |
| 404 | 375 | * @return the value of the {@code i}th value as a list of |
| 405 | 376 | * {@code elementsClass} objects. If the value is NULL, an empty list is |
| 406 | 377 | * returned (note that Cassandra makes no difference between an empty list |
| 407 | 378 | * and column of type list that is not set). The returned list is immutable. |
| 408 | - * | |
| 409 | 379 | * @throws IllegalArgumentException if {@code name} is not a valid name for this object. |
| 410 | - * @throws InvalidTypeException if value {@code name} is not a list or if its | |
| 411 | - * elements are not of class {@code elementsClass}. | |
| 380 | + * @throws InvalidTypeException if value {@code name} is not a list or if its | |
| 381 | + * elements are not of class {@code elementsClass}. | |
| 412 | 382 | */ |
| 413 | 383 | <T> List<T> getList(String name, Class<T> elementsClass); |
| 414 | 384 | |
| 415 | 385 | /** |
| 416 | 386 | * Returns the {@code i}th value as a set. |
| 417 | 387 | * |
| 418 | - * @param <T> the type of the elements of the set to return. | |
| 419 | - * @param i the index to retrieve. | |
| 388 | + * @param <T> the type of the elements of the set to return. | |
| 389 | + * @param i the index to retrieve. | |
| 420 | 390 | * @param elementsClass the class for the elements of the set to retrieve. |
| 421 | 391 | * @return the value of the {@code i}th value as a set of |
| 422 | 392 | * {@code elementsClass} objects. If the value is NULL, an empty set is |
| 423 | 393 | * returned (note that Cassandra makes no difference between an empty set |
| 424 | 394 | * and column of type set that is not set). The returned set is immutable. |
| 425 | - * | |
| 426 | 395 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 427 | - * @throws InvalidTypeException if value {@code i} is not a set or if its | |
| 428 | - * elements are not of class {@code elementsClass}. | |
| 396 | + * @throws InvalidTypeException if value {@code i} is not a set or if its | |
| 397 | + * elements are not of class {@code elementsClass}. | |
| 429 | 398 | */ |
| 430 | 399 | <T> Set<T> getSet(int i, Class<T> elementsClass); |
| 431 | 400 | |
| 432 | 401 | /** |
| 433 | 402 | * Returns the value for {@code name} as a set. |
| 434 | 403 | * |
| 435 | - * @param <T> the type of the elements of the set to return. | |
| 436 | - * @param name the name to retrieve. | |
| 404 | + * @param <T> the type of the elements of the set to return. | |
| 405 | + * @param name the name to retrieve. | |
| 437 | 406 | * @param elementsClass the class for the elements of the set to retrieve. |
| 438 | 407 | * @return the value of the {@code i}th value as a set of |
| 439 | 408 | * {@code elementsClass} objects. If the value is NULL, an empty set is |
| 440 | 409 | * returned (note that Cassandra makes no difference between an empty set |
| 441 | 410 | * and column of type set that is not set). The returned set is immutable. |
| 442 | - * | |
| 443 | 411 | * @throws IllegalArgumentException if {@code name} is not a valid name for this object. |
| 444 | - * @throws InvalidTypeException if value {@code name} is not a set or if its | |
| 445 | - * elements are not of class {@code elementsClass}. | |
| 412 | + * @throws InvalidTypeException if value {@code name} is not a set or if its | |
| 413 | + * elements are not of class {@code elementsClass}. | |
| 446 | 414 | */ |
| 447 | 415 | <T> Set<T> getSet(String name, Class<T> elementsClass); |
| 448 | 416 | |
| 449 | 417 | /** |
| 450 | 418 | * Returns the {@code i}th value as a map. |
| 451 | 419 | * |
| 452 | - * @param <K> the type of the keys of the map to return. | |
| 453 | - * @param <V> the type of the values of the map to return. | |
| 454 | - * @param i the index to retrieve. | |
| 455 | - * @param keysClass the class for the keys of the map to retrieve. | |
| 420 | + * @param <K> the type of the keys of the map to return. | |
| 421 | + * @param <V> the type of the values of the map to return. | |
| 422 | + * @param i the index to retrieve. | |
| 423 | + * @param keysClass the class for the keys of the map to retrieve. | |
| 456 | 424 | * @param valuesClass the class for the values of the map to retrieve. |
| 457 | 425 | * @return the value of the {@code i}th value as a map of |
| 458 | 426 | * {@code keysClass} to {@code valuesClass} objects. If the value is NULL, |
| 459 | 427 | * an empty map is returned (note that Cassandra makes no difference |
| 460 | 428 | * between an empty map and column of type map that is not set). The |
| 461 | 429 | * returned map is immutable. |
| 462 | - * | |
| 463 | 430 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 464 | - * @throws InvalidTypeException if value {@code i} is not a map, if its | |
| 465 | - * keys are not of class {@code keysClass} or if its values are not of | |
| 466 | - * class {@code valuesClass}. | |
| 431 | + * @throws InvalidTypeException if value {@code i} is not a map, if its | |
| 432 | + * keys are not of class {@code keysClass} or if its values are not of | |
| 433 | + * class {@code valuesClass}. | |
| 467 | 434 | */ |
| 468 | 435 | <K, V> Map<K, V> getMap(int i, Class<K> keysClass, Class<V> valuesClass); |
| 469 | 436 | |
| 470 | 437 | /** |
| 471 | 438 | * Returns the value for {@code name} as a map. |
| 472 | 439 | * |
| 473 | - * @param <K> the type of the keys of the map to return. | |
| 474 | - * @param <V> the type of the values of the map to return. | |
| 475 | - * @param name the name to retrieve. | |
| 476 | - * @param keysClass the class for the keys of the map to retrieve. | |
| 440 | + * @param <K> the type of the keys of the map to return. | |
| 441 | + * @param <V> the type of the values of the map to return. | |
| 442 | + * @param name the name to retrieve. | |
| 443 | + * @param keysClass the class for the keys of the map to retrieve. | |
| 477 | 444 | * @param valuesClass the class for the values of the map to retrieve. |
| 478 | 445 | * @return the value of the {@code i}th value as a map of |
| 479 | 446 | * {@code keysClass} to {@code valuesClass} objects. If the value is NULL, |
| 480 | 447 | * an empty map is returned (note that Cassandra makes no difference |
| 481 | 448 | * between an empty map and column of type map that is not set). The |
| 482 | 449 | * returned map is immutable. |
| 483 | - * | |
| 484 | 450 | * @throws IllegalArgumentException if {@code name} is not a valid name for this object. |
| 485 | - * @throws InvalidTypeException if value {@code name} is not a map, if its | |
| 486 | - * keys are not of class {@code keysClass} or if its values are not of | |
| 487 | - * class {@code valuesClass}. | |
| 451 | + * @throws InvalidTypeException if value {@code name} is not a map, if its | |
| 452 | + * keys are not of class {@code keysClass} or if its values are not of | |
| 453 | + * class {@code valuesClass}. | |
| 488 | 454 | */ |
| 489 | 455 | <K, V> Map<K, V> getMap(String name, Class<K> keysClass, Class<V> valuesClass); |
| 490 | 456 | |
| @@ -496,7 +462,6 @@ | ||
| 496 | 462 | * @return the value of the {@code i}th value as the Java type matching its CQL type. |
| 497 | 463 | * If the value is NULL and is a simple type, NULL is returned. |
| 498 | 464 | * If it is NULL and is a collection type, an empty (immutable) collection is returned. |
| 499 | - * | |
| 500 | 465 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 501 | 466 | */ |
| 502 | 467 | Object getObject(int i); |
| @@ -508,7 +473,6 @@ | ||
| 508 | 473 | * @return the value of the {@code i}th value as the Java type matching its CQL type. |
| 509 | 474 | * If the value is NULL and is a simple type, NULL is returned. |
| 510 | 475 | * If it is NULL and is a collection type, an empty (immutable) collection is returned. |
| 511 | - * | |
| 512 | 476 | * @throws IllegalArgumentException if {@code name} is not a valid name for this object. |
| 513 | 477 | */ |
| 514 | 478 | Object getObject(String name); |
modified driver-core/src/main/java/com/datastax/driver/core/Host.java +26 −24
| @@ -15,21 +15,21 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.net.InetAddress; | |
| 19 | -import java.net.InetSocketAddress; | |
| 20 | -import java.util.Set; | |
| 21 | -import java.util.concurrent.atomic.AtomicReference; | |
| 22 | -import java.util.concurrent.locks.ReentrantLock; | |
| 23 | - | |
| 24 | 18 | import com.google.common.collect.ImmutableList; |
| 25 | 19 | import com.google.common.util.concurrent.Futures; |
| 26 | 20 | import com.google.common.util.concurrent.ListenableFuture; |
| 27 | 21 | import org.slf4j.Logger; |
| 28 | 22 | import org.slf4j.LoggerFactory; |
| 29 | 23 | |
| 24 | +import java.net.InetAddress; | |
| 25 | +import java.net.InetSocketAddress; | |
| 26 | +import java.util.Set; | |
| 27 | +import java.util.concurrent.atomic.AtomicReference; | |
| 28 | +import java.util.concurrent.locks.ReentrantLock; | |
| 29 | + | |
| 30 | 30 | /** |
| 31 | 31 | * A Cassandra node. |
| 32 | - * | |
| 32 | + * <p/> | |
| 33 | 33 | * This class keeps the information the driver maintain on a given Cassandra node. |
| 34 | 34 | */ |
| 35 | 35 | public class Host { |
| @@ -40,9 +40,12 @@ | ||
| 40 | 40 | |
| 41 | 41 | private final InetSocketAddress address; |
| 42 | 42 | |
| 43 | - enum State { ADDED, DOWN, UP } | |
| 43 | + enum State {ADDED, DOWN, UP} | |
| 44 | + | |
| 44 | 45 | volatile State state; |
| 45 | - /** Ensures state change notifications for that host are handled serially */ | |
| 46 | + /** | |
| 47 | + * Ensures state change notifications for that host are handled serially | |
| 48 | + */ | |
| 46 | 49 | final ReentrantLock notificationsLock = new ReentrantLock(true); |
| 47 | 50 | |
| 48 | 51 | final ConvictionPolicy convictionPolicy; |
| @@ -99,7 +102,7 @@ | ||
| 99 | 102 | |
| 100 | 103 | /** |
| 101 | 104 | * Returns the node address. |
| 102 | - * <p> | |
| 105 | + * <p/> | |
| 103 | 106 | * This is a shortcut for {@code getSocketAddress().getAddress()}. |
| 104 | 107 | * |
| 105 | 108 | * @return the node {@link InetAddress}. |
| @@ -119,7 +122,7 @@ | ||
| 119 | 122 | |
| 120 | 123 | /** |
| 121 | 124 | * Returns the name of the datacenter this host is part of. |
| 122 | - * <p> | |
| 125 | + * <p/> | |
| 123 | 126 | * The returned datacenter name is the one as known by Cassandra. |
| 124 | 127 | * It is also possible for this information to be unavailable. In that |
| 125 | 128 | * case this method returns {@code null}, and the caller should always be aware |
| @@ -133,7 +136,7 @@ | ||
| 133 | 136 | |
| 134 | 137 | /** |
| 135 | 138 | * Returns the name of the rack this host is part of. |
| 136 | - * <p> | |
| 139 | + * <p/> | |
| 137 | 140 | * The returned rack name is the one as known by Cassandra. |
| 138 | 141 | * It is also possible for this information to be unavailable. In that case |
| 139 | 142 | * this method returns {@code null}, and the caller should always aware of this |
| @@ -147,7 +150,7 @@ | ||
| 147 | 150 | |
| 148 | 151 | /** |
| 149 | 152 | * The Cassandra version the host is running. |
| 150 | - * <p> | |
| 153 | + * <p/> | |
| 151 | 154 | * As for other host information fetch from Cassandra above, the returned |
| 152 | 155 | * version can theoretically be null if the information is unavailable. |
| 153 | 156 | * |
| @@ -172,7 +175,7 @@ | ||
| 172 | 175 | |
| 173 | 176 | /** |
| 174 | 177 | * Returns whether the host is considered up by the driver. |
| 175 | - * <p> | |
| 178 | + * <p/> | |
| 176 | 179 | * Please note that this is only the view of the driver and may not reflect |
| 177 | 180 | * reality. In particular a node can be down but the driver hasn't detected |
| 178 | 181 | * it yet, or it can have been restarted and the driver hasn't detected it |
| @@ -189,7 +192,7 @@ | ||
| 189 | 192 | |
| 190 | 193 | /** |
| 191 | 194 | * Returns a description of the host's state, as seen by the driver. |
| 192 | - * <p> | |
| 195 | + * <p/> | |
| 193 | 196 | * This is exposed for debugging purposes only; the format of this string might |
| 194 | 197 | * change between driver versions, so clients should not make any assumptions |
| 195 | 198 | * about it. |
| @@ -203,12 +206,11 @@ | ||
| 203 | 206 | /** |
| 204 | 207 | * Returns a {@code ListenableFuture} representing the completion of the first |
| 205 | 208 | * reconnection attempt after a node has been suspected. |
| 206 | - * <p> | |
| 209 | + * <p/> | |
| 207 | 210 | * This is useful in load balancing policies when there are no more live nodes and |
| 208 | 211 | * we are trying suspected nodes. |
| 209 | 212 | * |
| 210 | 213 | * @return the future. |
| 211 | - * | |
| 212 | 214 | * @deprecated the suspicion mechanism has been disabled. This will always return |
| 213 | 215 | * a completed future. |
| 214 | 216 | */ |
| @@ -220,7 +222,7 @@ | ||
| 220 | 222 | /** |
| 221 | 223 | * Returns a {@code ListenableFuture} representing the completion of the reconnection |
| 222 | 224 | * attempts scheduled after a host is marked {@code DOWN}. |
| 223 | - * <p> | |
| 225 | + * <p/> | |
| 224 | 226 | * <b>If the caller cancels this future,</b> the driver will not try to reconnect to |
| 225 | 227 | * this host until it receives an UP event for it. Note that this could mean never, if |
| 226 | 228 | * the node was marked down because of a driver-side error (e.g. read timeout) but no |
| @@ -235,14 +237,14 @@ | ||
| 235 | 237 | |
| 236 | 238 | /** |
| 237 | 239 | * Triggers an asynchronous reconnection attempt to this host. |
| 238 | - * <p> | |
| 240 | + * <p/> | |
| 239 | 241 | * This method is intended for load balancing policies that mark hosts as {@link HostDistance#IGNORED IGNORED}, |
| 240 | 242 | * but still need a way to periodically check these hosts' states (UP / DOWN). |
| 241 | - * <p> | |
| 243 | + * <p/> | |
| 242 | 244 | * For a host that is at distance {@code IGNORED}, this method will try to reconnect exactly once: if |
| 243 | 245 | * reconnection succeeds, the host is marked {@code UP}; otherwise, no further attempts will be scheduled. |
| 244 | 246 | * It has no effect if the node is already {@code UP}, or if a reconnection attempt is already in progress. |
| 245 | - * <p> | |
| 247 | + * <p/> | |
| 246 | 248 | * Note that if the host is <em>not</em> a distance {@code IGNORED}, this method <em>will</em> trigger a periodic |
| 247 | 249 | * reconnection attempt if the reconnection fails. |
| 248 | 250 | */ |
| @@ -253,7 +255,7 @@ | ||
| 253 | 255 | @Override |
| 254 | 256 | public boolean equals(Object other) { |
| 255 | 257 | if (other instanceof Host) { |
| 256 | - Host that = (Host)other; | |
| 258 | + Host that = (Host) other; | |
| 257 | 259 | return this.address.equals(that.address); |
| 258 | 260 | } |
| 259 | 261 | return false; |
| @@ -284,7 +286,7 @@ | ||
| 284 | 286 | /** |
| 285 | 287 | * Interface for listeners that are interested in hosts added, up, down and |
| 286 | 288 | * removed events. |
| 287 | - * <p> | |
| 289 | + * <p/> | |
| 288 | 290 | * It is possible for the same event to be fired multiple times, |
| 289 | 291 | * particularly for up or down events. Therefore, a listener should ignore |
| 290 | 292 | * the same event if it has already been notified of a node's state. |
| @@ -293,7 +295,7 @@ | ||
| 293 | 295 | |
| 294 | 296 | /** |
| 295 | 297 | * Called when a new node is added to the cluster. |
| 296 | - * <p> | |
| 298 | + * <p/> | |
| 297 | 299 | * The newly added node should be considered up. |
| 298 | 300 | * |
| 299 | 301 | * @param host the host that has been newly added. |
modified driver-core/src/main/java/com/datastax/driver/core/HostConnectionPool.java +31 −26
| @@ -15,6 +15,14 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.exceptions.AuthenticationException; | |
| 19 | +import com.datastax.driver.core.utils.MoreFutures; | |
| 20 | +import com.google.common.base.Throwables; | |
| 21 | +import com.google.common.collect.Lists; | |
| 22 | +import com.google.common.util.concurrent.*; | |
| 23 | +import org.slf4j.Logger; | |
| 24 | +import org.slf4j.LoggerFactory; | |
| 25 | + | |
| 18 | 26 | import java.util.ArrayList; |
| 19 | 27 | import java.util.List; |
| 20 | 28 | import java.util.ListIterator; |
| @@ -26,19 +34,7 @@ | ||
| 26 | 34 | import java.util.concurrent.locks.Lock; |
| 27 | 35 | import java.util.concurrent.locks.ReentrantLock; |
| 28 | 36 | |
| 29 | -import com.google.common.base.Throwables; | |
| 30 | -import com.google.common.collect.Lists; | |
| 31 | -import com.google.common.util.concurrent.*; | |
| 32 | -import org.slf4j.Logger; | |
| 33 | -import org.slf4j.LoggerFactory; | |
| 34 | - | |
| 35 | -import com.datastax.driver.core.exceptions.AuthenticationException; | |
| 36 | -import com.datastax.driver.core.utils.MoreFutures; | |
| 37 | - | |
| 38 | -import static com.datastax.driver.core.Connection.State.GONE; | |
| 39 | -import static com.datastax.driver.core.Connection.State.OPEN; | |
| 40 | -import static com.datastax.driver.core.Connection.State.RESURRECTING; | |
| 41 | -import static com.datastax.driver.core.Connection.State.TRASHED; | |
| 37 | +import static com.datastax.driver.core.Connection.State.*; | |
| 42 | 38 | |
| 43 | 39 | class HostConnectionPool implements Connection.Owner { |
| 44 | 40 | |
| @@ -57,9 +53,13 @@ | ||
| 57 | 53 | |
| 58 | 54 | final List<Connection> connections; |
| 59 | 55 | private final AtomicInteger open; |
| 60 | - /** The total number of in-flight requests on all connections of this pool. */ | |
| 56 | + /** | |
| 57 | + * The total number of in-flight requests on all connections of this pool. | |
| 58 | + */ | |
| 61 | 59 | final AtomicInteger totalInFlight = new AtomicInteger(); |
| 62 | - /** The maximum value of {@link #totalInFlight} since the last call to {@link #cleanupIdleConnections(long)}*/ | |
| 60 | + /** | |
| 61 | + * The maximum value of {@link #totalInFlight} since the last call to {@link #cleanupIdleConnections(long)} | |
| 62 | + */ | |
| 63 | 63 | private final AtomicInteger maxTotalInFlight = new AtomicInteger(); |
| 64 | 64 | final Set<Connection> trash = new CopyOnWriteArraySet<Connection>(); |
| 65 | 65 | |
| @@ -73,10 +73,11 @@ | ||
| 73 | 73 | |
| 74 | 74 | private final AtomicReference<CloseFuture> closeFuture = new AtomicReference<CloseFuture>(); |
| 75 | 75 | |
| 76 | - private enum Phase { INITIALIZING, READY, INIT_FAILED, CLOSING } | |
| 76 | + private enum Phase {INITIALIZING, READY, INIT_FAILED, CLOSING} | |
| 77 | + | |
| 77 | 78 | private final AtomicReference<Phase> phase = new AtomicReference<Phase>(Phase.INITIALIZING); |
| 78 | 79 | |
| 79 | - public HostConnectionPool(final Host host, HostDistance hostDistance, final SessionManager manager){ | |
| 80 | + public HostConnectionPool(final Host host, HostDistance hostDistance, final SessionManager manager) { | |
| 80 | 81 | assert hostDistance != HostDistance.IGNORED; |
| 81 | 82 | this.host = host; |
| 82 | 83 | this.hostDistance = hostDistance; |
| @@ -144,7 +145,7 @@ | ||
| 144 | 145 | forceClose(connections); |
| 145 | 146 | } else { |
| 146 | 147 | logger.debug("Created connection pool to host {} ({} connections needed, {} successfully opened)", |
| 147 | - host, coreSize, connections.size()); | |
| 148 | + host, coreSize, connections.size()); | |
| 148 | 149 | phase.compareAndSet(Phase.INITIALIZING, Phase.READY); |
| 149 | 150 | initFuture.set(null); |
| 150 | 151 | } |
| @@ -264,7 +265,7 @@ | ||
| 264 | 265 | } else if (connectionCount < options().getMaxConnectionsPerHost(hostDistance)) { |
| 265 | 266 | // Add a connection if we fill the first n-1 connections and almost fill the last one |
| 266 | 267 | int currentCapacity = (connectionCount - 1) * StreamIdGenerator.MAX_STREAM_PER_CONNECTION |
| 267 | - + options().getMaxSimultaneousRequestsPerConnectionThreshold(hostDistance); | |
| 268 | + + options().getMaxSimultaneousRequestsPerConnectionThreshold(hostDistance); | |
| 268 | 269 | if (totalInFlightCount > currentCapacity) |
| 269 | 270 | maybeSpawnNewConnection(); |
| 270 | 271 | } |
| @@ -398,7 +399,7 @@ | ||
| 398 | 399 | return true; |
| 399 | 400 | |
| 400 | 401 | // First, make sure we don't go below core connections |
| 401 | - for (;;) { | |
| 402 | + for (; ; ) { | |
| 402 | 403 | int opened = open.get(); |
| 403 | 404 | if (opened <= options().getCoreConnectionsPerHost(hostDistance)) { |
| 404 | 405 | connection.state.set(OPEN); |
| @@ -422,7 +423,7 @@ | ||
| 422 | 423 | private boolean addConnectionIfUnderMaximum() { |
| 423 | 424 | |
| 424 | 425 | // First, make sure we don't cross the allowed limit of open connections |
| 425 | - for(;;) { | |
| 426 | + for (; ; ) { | |
| 426 | 427 | int opened = open.get(); |
| 427 | 428 | if (opened >= options().getMaxConnectionsPerHost(hostDistance)) |
| 428 | 429 | return false; |
| @@ -541,7 +542,9 @@ | ||
| 541 | 542 | cleanupTrash(now); |
| 542 | 543 | } |
| 543 | 544 | |
| 544 | - /** If we have more active connections than needed, trash some of them */ | |
| 545 | + /** | |
| 546 | + * If we have more active connections than needed, trash some of them | |
| 547 | + */ | |
| 545 | 548 | private void shrinkIfBelowCapacity() { |
| 546 | 549 | int currentLoad = maxTotalInFlight.getAndSet(totalInFlight.get()); |
| 547 | 550 | |
| @@ -553,7 +556,7 @@ | ||
| 553 | 556 | int toTrash = Math.max(0, actual - needed); |
| 554 | 557 | |
| 555 | 558 | logger.trace("Current inFlight = {}, {} connections needed, {} connections available, trashing {}", |
| 556 | - currentLoad, needed, actual, toTrash); | |
| 559 | + currentLoad, needed, actual, toTrash); | |
| 557 | 560 | |
| 558 | 561 | if (toTrash <= 0) |
| 559 | 562 | return; |
| @@ -566,7 +569,9 @@ | ||
| 566 | 569 | } |
| 567 | 570 | } |
| 568 | 571 | |
| 569 | - /** Close connections that have been sitting in the trash for too long */ | |
| 572 | + /** | |
| 573 | + * Close connections that have been sitting in the trash for too long | |
| 574 | + */ | |
| 570 | 575 | private void cleanupTrash(long now) { |
| 571 | 576 | for (Connection connection : trash) { |
| 572 | 577 | if (connection.maxIdleTime < now && connection.state.compareAndSet(TRASHED, GONE)) { |
| @@ -606,8 +611,8 @@ | ||
| 606 | 611 | future = new CloseFuture.Forwarding(discardAvailableConnections()); |
| 607 | 612 | |
| 608 | 613 | return closeFuture.compareAndSet(null, future) |
| 609 | - ? future | |
| 610 | - : closeFuture.get(); // We raced, it's ok, return the future that was actually set | |
| 614 | + ? future | |
| 615 | + : closeFuture.get(); // We raced, it's ok, return the future that was actually set | |
| 611 | 616 | } |
| 612 | 617 | |
| 613 | 618 | public int opened() { |
modified driver-core/src/main/java/com/datastax/driver/core/HostDistance.java +2 −2
| @@ -19,7 +19,7 @@ | ||
| 19 | 19 | * The distance to a Cassandra node as assigned by a |
| 20 | 20 | * {@link com.datastax.driver.core.policies.LoadBalancingPolicy} (through its {@code |
| 21 | 21 | * distance} method). |
| 22 | - * | |
| 22 | + * <p/> | |
| 23 | 23 | * The distance assigned to an host influences how many connections the driver |
| 24 | 24 | * maintains towards this host. If for a given host the assigned {@code HostDistance} |
| 25 | 25 | * is {@code LOCAL} or {@code REMOTE}, some connections will be maintained by |
| @@ -27,7 +27,7 @@ | ||
| 27 | 27 | * {@code LOCAL} host than to a {@code REMOTE} one (and thus well behaving |
| 28 | 28 | * {@code LoadBalancingPolicy} should assign a {@code REMOTE} distance only to |
| 29 | 29 | * hosts that are the less often queried). |
| 30 | - * <p> | |
| 30 | + * <p/> | |
| 31 | 31 | * However, if a host is assigned the distance {@code IGNORED}, no connection |
| 32 | 32 | * to that host will maintained active. In other words, {@code IGNORED} should |
| 33 | 33 | * be assigned to hosts that should not be used by this driver (because they |
modified driver-core/src/main/java/com/datastax/driver/core/KeyspaceMetadata.java +7 −7
| @@ -26,9 +26,9 @@ | ||
| 26 | 26 | */ |
| 27 | 27 | public class KeyspaceMetadata { |
| 28 | 28 | |
| 29 | - public static final String KS_NAME = "keyspace_name"; | |
| 30 | - private static final String DURABLE_WRITES = "durable_writes"; | |
| 31 | - private static final String STRATEGY_CLASS = "strategy_class"; | |
| 29 | + public static final String KS_NAME = "keyspace_name"; | |
| 30 | + private static final String DURABLE_WRITES = "durable_writes"; | |
| 31 | + private static final String STRATEGY_CLASS = "strategy_class"; | |
| 32 | 32 | private static final String STRATEGY_OPTIONS = "strategy_options"; |
| 33 | 33 | |
| 34 | 34 | private final String name; |
| @@ -114,10 +114,10 @@ | ||
| 114 | 114 | /** |
| 115 | 115 | * Returns a {@code String} containing CQL queries representing this |
| 116 | 116 | * keyspace and the table it contains. |
| 117 | - * | |
| 117 | + * <p/> | |
| 118 | 118 | * In other words, this method returns the queries that would allow to |
| 119 | 119 | * recreate the schema of this keyspace, along with all its table. |
| 120 | - * | |
| 120 | + * <p/> | |
| 121 | 121 | * Note that the returned String is formatted to be human readable (for |
| 122 | 122 | * some definition of human readable at least). |
| 123 | 123 | * |
| @@ -137,7 +137,7 @@ | ||
| 137 | 137 | |
| 138 | 138 | /** |
| 139 | 139 | * Returns a CQL query representing this keyspace. |
| 140 | - * | |
| 140 | + * <p/> | |
| 141 | 141 | * This method returns a single 'CREATE KEYSPACE' query with the options |
| 142 | 142 | * corresponding to this keyspace definition. |
| 143 | 143 | * |
| @@ -166,7 +166,7 @@ | ||
| 166 | 166 | if (o == null || getClass() != o.getClass()) |
| 167 | 167 | return false; |
| 168 | 168 | |
| 169 | - KeyspaceMetadata that = (KeyspaceMetadata)o; | |
| 169 | + KeyspaceMetadata that = (KeyspaceMetadata) o; | |
| 170 | 170 | |
| 171 | 171 | if (durableWrites != that.durableWrites) |
| 172 | 172 | return false; |
modified driver-core/src/main/java/com/datastax/driver/core/LatencyTracker.java +8 −8
| @@ -18,7 +18,7 @@ | ||
| 18 | 18 | /** |
| 19 | 19 | * Interface for objects that are interested in tracking the latencies |
| 20 | 20 | * of the driver queries to each Cassandra nodes. |
| 21 | - * <p> | |
| 21 | + * <p/> | |
| 22 | 22 | * An implementation of this interface can be registered against a Cluster |
| 23 | 23 | * object trough the {@link Cluster#register} method, after which the |
| 24 | 24 | * {@link #update(Host, Statement, Exception, long)} method will be called after each query of the driver to a Cassandra |
| @@ -29,17 +29,17 @@ | ||
| 29 | 29 | /** |
| 30 | 30 | * A method that is called after each request to a Cassandra node with |
| 31 | 31 | * the duration of that operation. |
| 32 | - * <p> | |
| 32 | + * <p/> | |
| 33 | 33 | * Note that there is no guarantee that this method won't be called |
| 34 | 34 | * concurrently by multiple threads, so implementations should synchronize |
| 35 | 35 | * internally if need be. |
| 36 | 36 | * |
| 37 | - * @param host The Cassandra host on which a request has been performed. | |
| 38 | - * This parameter is never {@code null}. | |
| 39 | - * @param statement The {@link com.datastax.driver.core.Statement} that has been executed. | |
| 40 | - * This parameter is never {@code null}. | |
| 41 | - * @param exception An {@link Exception} thrown when receiving the response, or {@code null} | |
| 42 | - * if the response was successful. | |
| 37 | + * @param host The Cassandra host on which a request has been performed. | |
| 38 | + * This parameter is never {@code null}. | |
| 39 | + * @param statement The {@link com.datastax.driver.core.Statement} that has been executed. | |
| 40 | + * This parameter is never {@code null}. | |
| 41 | + * @param exception An {@link Exception} thrown when receiving the response, or {@code null} | |
| 42 | + * if the response was successful. | |
| 43 | 43 | * @param newLatencyNanos the latency in nanoseconds of the operation. |
| 44 | 44 | * This latency corresponds to the time elapsed between |
| 45 | 45 | * when the query was sent to {@code host} and |
modified driver-core/src/main/java/com/datastax/driver/core/MD5Digest.java +7 −7
| @@ -15,17 +15,17 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.util.Arrays; | |
| 19 | - | |
| 20 | 18 | import com.datastax.driver.core.utils.Bytes; |
| 21 | 19 | |
| 20 | +import java.util.Arrays; | |
| 21 | + | |
| 22 | 22 | /** |
| 23 | 23 | * The result of the computation of an MD5 digest. |
| 24 | - * | |
| 24 | + * <p/> | |
| 25 | 25 | * A MD5 is really just a byte[] but arrays are a no go as map keys. We could |
| 26 | 26 | * wrap it in a ByteBuffer but: |
| 27 | - * 1. MD5Digest is a more explicit name than ByteBuffer to represent a md5. | |
| 28 | - * 2. Using our own class allows to use our FastByteComparison for equals. | |
| 27 | + * 1. MD5Digest is a more explicit name than ByteBuffer to represent a md5. | |
| 28 | + * 2. Using our own class allows to use our FastByteComparison for equals. | |
| 29 | 29 | */ |
| 30 | 30 | class MD5Digest { |
| 31 | 31 | |
| @@ -46,9 +46,9 @@ | ||
| 46 | 46 | |
| 47 | 47 | @Override |
| 48 | 48 | public final boolean equals(Object o) { |
| 49 | - if(!(o instanceof MD5Digest)) | |
| 49 | + if (!(o instanceof MD5Digest)) | |
| 50 | 50 | return false; |
| 51 | - MD5Digest that = (MD5Digest)o; | |
| 51 | + MD5Digest that = (MD5Digest) o; | |
| 52 | 52 | // handles nulls properly |
| 53 | 53 | return Arrays.equals(this.bytes, that.bytes); |
| 54 | 54 | } |
modified driver-core/src/main/java/com/datastax/driver/core/Message.java +49 −39
| @@ -15,11 +15,7 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.nio.ByteBuffer; | |
| 19 | -import java.util.EnumSet; | |
| 20 | -import java.util.List; | |
| 21 | -import java.util.UUID; | |
| 22 | - | |
| 18 | +import com.datastax.driver.core.exceptions.DriverInternalError; | |
| 23 | 19 | import io.netty.buffer.ByteBuf; |
| 24 | 20 | import io.netty.channel.ChannelHandler; |
| 25 | 21 | import io.netty.channel.ChannelHandlerContext; |
| @@ -28,7 +24,10 @@ | ||
| 28 | 24 | import org.slf4j.Logger; |
| 29 | 25 | import org.slf4j.LoggerFactory; |
| 30 | 26 | |
| 31 | -import com.datastax.driver.core.exceptions.DriverInternalError; | |
| 27 | +import java.nio.ByteBuffer; | |
| 28 | +import java.util.EnumSet; | |
| 29 | +import java.util.List; | |
| 30 | +import java.util.UUID; | |
| 32 | 31 | |
| 33 | 32 | /** |
| 34 | 33 | * A message from the CQL binary protocol. |
| @@ -39,6 +38,7 @@ | ||
| 39 | 38 | |
| 40 | 39 | public interface Coder<R extends Request> { |
| 41 | 40 | public void encode(R request, ByteBuf dest); |
| 41 | + | |
| 42 | 42 | public int encodedSize(R request); |
| 43 | 43 | } |
| 44 | 44 | |
| @@ -48,7 +48,8 @@ | ||
| 48 | 48 | |
| 49 | 49 | private volatile int streamId; |
| 50 | 50 | |
| 51 | - protected Message() {} | |
| 51 | + protected Message() { | |
| 52 | + } | |
| 52 | 53 | |
| 53 | 54 | public Message setStreamId(int streamId) { |
| 54 | 55 | this.streamId = streamId; |
| @@ -62,15 +63,15 @@ | ||
| 62 | 63 | public static abstract class Request extends Message { |
| 63 | 64 | |
| 64 | 65 | public enum Type { |
| 65 | - STARTUP (1, Requests.Startup.coder, Requests.Startup.coder), | |
| 66 | - CREDENTIALS (4, Requests.Credentials.coder, null), | |
| 67 | - OPTIONS (5, Requests.Options.coder, Requests.Options.coder), | |
| 68 | - QUERY (7, Requests.Query.coderV1, Requests.Query.coderV2), | |
| 69 | - PREPARE (9, Requests.Prepare.coder, Requests.Prepare.coder), | |
| 70 | - EXECUTE (10, Requests.Execute.coderV1, Requests.Execute.coderV2), | |
| 71 | - REGISTER (11, Requests.Register.coder, Requests.Register.coder), | |
| 72 | - BATCH (13, null, Requests.Batch.coder), | |
| 73 | - AUTH_RESPONSE (15, Requests.AuthResponse.coder, Requests.AuthResponse.coder); | |
| 66 | + STARTUP(1, Requests.Startup.coder, Requests.Startup.coder), | |
| 67 | + CREDENTIALS(4, Requests.Credentials.coder, null), | |
| 68 | + OPTIONS(5, Requests.Options.coder, Requests.Options.coder), | |
| 69 | + QUERY(7, Requests.Query.coderV1, Requests.Query.coderV2), | |
| 70 | + PREPARE(9, Requests.Prepare.coder, Requests.Prepare.coder), | |
| 71 | + EXECUTE(10, Requests.Execute.coderV1, Requests.Execute.coderV2), | |
| 72 | + REGISTER(11, Requests.Register.coder, Requests.Register.coder), | |
| 73 | + BATCH(13, null, Requests.Batch.coder), | |
| 74 | + AUTH_RESPONSE(15, Requests.AuthResponse.coder, Requests.AuthResponse.coder); | |
| 74 | 75 | |
| 75 | 76 | public final int opcode; |
| 76 | 77 | private final Coder<?> coderV1; |
| @@ -82,8 +83,7 @@ | ||
| 82 | 83 | this.coderV2 = coderV2; |
| 83 | 84 | } |
| 84 | 85 | |
| 85 | - public Coder<?> coder(int version) | |
| 86 | - { | |
| 86 | + public Coder<?> coder(int version) { | |
| 87 | 87 | assert version == 1 || version == 2 : "Unsupported protocol version, we shouldn't have arrived here"; |
| 88 | 88 | return version == 1 ? coderV1 : coderV2; |
| 89 | 89 | } |
| @@ -107,26 +107,36 @@ | ||
| 107 | 107 | |
| 108 | 108 | ConsistencyLevel consistency() { |
| 109 | 109 | switch (this.type) { |
| 110 | - case QUERY: return ((Requests.Query)this).options.consistency; | |
| 111 | - case EXECUTE: return ((Requests.Execute)this).options.consistency; | |
| 112 | - case BATCH: return ((Requests.Batch)this).consistency; | |
| 113 | - default: return null; | |
| 110 | + case QUERY: | |
| 111 | + return ((Requests.Query) this).options.consistency; | |
| 112 | + case EXECUTE: | |
| 113 | + return ((Requests.Execute) this).options.consistency; | |
| 114 | + case BATCH: | |
| 115 | + return ((Requests.Batch) this).consistency; | |
| 116 | + default: | |
| 117 | + return null; | |
| 114 | 118 | } |
| 115 | 119 | } |
| 116 | 120 | |
| 117 | 121 | ConsistencyLevel serialConsistency() { |
| 118 | 122 | switch (this.type) { |
| 119 | - case QUERY: return ((Requests.Query)this).options.serialConsistency; | |
| 120 | - case EXECUTE: return ((Requests.Execute)this).options.serialConsistency; | |
| 121 | - default: return null; | |
| 123 | + case QUERY: | |
| 124 | + return ((Requests.Query) this).options.serialConsistency; | |
| 125 | + case EXECUTE: | |
| 126 | + return ((Requests.Execute) this).options.serialConsistency; | |
| 127 | + default: | |
| 128 | + return null; | |
| 122 | 129 | } |
| 123 | 130 | } |
| 124 | 131 | |
| 125 | 132 | ByteBuffer pagingState() { |
| 126 | 133 | switch (this.type) { |
| 127 | - case QUERY: return ((Requests.Query)this).options.pagingState; | |
| 128 | - case EXECUTE: return ((Requests.Execute)this).options.pagingState; | |
| 129 | - default: return null; | |
| 134 | + case QUERY: | |
| 135 | + return ((Requests.Query) this).options.pagingState; | |
| 136 | + case EXECUTE: | |
| 137 | + return ((Requests.Execute) this).options.pagingState; | |
| 138 | + default: | |
| 139 | + return null; | |
| 130 | 140 | } |
| 131 | 141 | } |
| 132 | 142 | |
| @@ -142,20 +152,21 @@ | ||
| 142 | 152 | public static abstract class Response extends Message { |
| 143 | 153 | |
| 144 | 154 | public enum Type { |
| 145 | - ERROR (0, Responses.Error.decoder, Responses.Error.decoder), | |
| 146 | - READY (2, Responses.Ready.decoder, Responses.Ready.decoder), | |
| 147 | - AUTHENTICATE (3, Responses.Authenticate.decoder, Responses.Authenticate.decoder), | |
| 148 | - SUPPORTED (6, Responses.Supported.decoder, Responses.Supported.decoder), | |
| 149 | - RESULT (8, Responses.Result.decoderV1, Responses.Result.decoderV2), | |
| 150 | - EVENT (12, Responses.Event.decoder, Responses.Event.decoder), | |
| 151 | - AUTH_CHALLENGE (14, Responses.AuthChallenge.decoder, Responses.AuthChallenge.decoder), | |
| 152 | - AUTH_SUCCESS (16, Responses.AuthSuccess.decoder, Responses.AuthSuccess.decoder); | |
| 155 | + ERROR(0, Responses.Error.decoder, Responses.Error.decoder), | |
| 156 | + READY(2, Responses.Ready.decoder, Responses.Ready.decoder), | |
| 157 | + AUTHENTICATE(3, Responses.Authenticate.decoder, Responses.Authenticate.decoder), | |
| 158 | + SUPPORTED(6, Responses.Supported.decoder, Responses.Supported.decoder), | |
| 159 | + RESULT(8, Responses.Result.decoderV1, Responses.Result.decoderV2), | |
| 160 | + EVENT(12, Responses.Event.decoder, Responses.Event.decoder), | |
| 161 | + AUTH_CHALLENGE(14, Responses.AuthChallenge.decoder, Responses.AuthChallenge.decoder), | |
| 162 | + AUTH_SUCCESS(16, Responses.AuthSuccess.decoder, Responses.AuthSuccess.decoder); | |
| 153 | 163 | |
| 154 | 164 | public final int opcode; |
| 155 | 165 | private final Decoder<?> decoderV1; |
| 156 | 166 | private final Decoder<?> decoderV2; |
| 157 | 167 | |
| 158 | 168 | private static final Type[] opcodeIdx; |
| 169 | + | |
| 159 | 170 | static { |
| 160 | 171 | int maxOpcode = -1; |
| 161 | 172 | for (Type type : Type.values()) |
| @@ -181,8 +192,7 @@ | ||
| 181 | 192 | return t; |
| 182 | 193 | } |
| 183 | 194 | |
| 184 | - public Decoder<?> decoder(int version) | |
| 185 | - { | |
| 195 | + public Decoder<?> decoder(int version) { | |
| 186 | 196 | assert version == 1 || version == 2 : "Unsupported protocol version, we shouldn't have arrived here"; |
| 187 | 197 | return version == 1 ? decoderV1 : decoderV2; |
| 188 | 198 | } |
| @@ -239,7 +249,7 @@ | ||
| 239 | 249 | flags.add(Frame.Header.Flag.TRACING); |
| 240 | 250 | |
| 241 | 251 | @SuppressWarnings("unchecked") |
| 242 | - Coder<Request> coder = (Coder<Request>)request.type.coder(protocolVersion); | |
| 252 | + Coder<Request> coder = (Coder<Request>) request.type.coder(protocolVersion); | |
| 243 | 253 | ByteBuf body = ctx.alloc().buffer(coder.encodedSize(request)); |
| 244 | 254 | coder.encode(request, body); |
| 245 | 255 |
modified driver-core/src/main/java/com/datastax/driver/core/Metadata.java +43 −46
| @@ -15,6 +15,12 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | +import com.google.common.collect.ImmutableMap; | |
| 19 | +import com.google.common.collect.ImmutableSet; | |
| 20 | +import com.google.common.collect.Maps; | |
| 21 | +import org.slf4j.Logger; | |
| 22 | +import org.slf4j.LoggerFactory; | |
| 23 | + | |
| 18 | 24 | import java.net.InetSocketAddress; |
| 19 | 25 | import java.nio.ByteBuffer; |
| 20 | 26 | import java.util.*; |
| @@ -22,12 +28,6 @@ | ||
| 22 | 28 | import java.util.concurrent.ConcurrentMap; |
| 23 | 29 | import java.util.regex.Pattern; |
| 24 | 30 | |
| 25 | -import com.google.common.collect.ImmutableMap; | |
| 26 | -import com.google.common.collect.ImmutableSet; | |
| 27 | -import com.google.common.collect.Maps; | |
| 28 | -import org.slf4j.Logger; | |
| 29 | -import org.slf4j.LoggerFactory; | |
| 30 | - | |
| 31 | 31 | /** |
| 32 | 32 | * Keeps metadata on the connected cluster, including known nodes and schema definitions. |
| 33 | 33 | */ |
| @@ -127,7 +127,7 @@ | ||
| 127 | 127 | |
| 128 | 128 | private Map<String, TableMetadata> buildTables(KeyspaceMetadata keyspace, List<Row> tableRows, Map<String, Map<String, ColumnMetadata.Raw>> colsDefs, VersionNumber cassandraVersion) { |
| 129 | 129 | Map<String, TableMetadata> tables = new LinkedHashMap<String, TableMetadata>(); |
| 130 | - if(tableRows != null) { | |
| 130 | + if (tableRows != null) { | |
| 131 | 131 | for (Row tableDef : tableRows) { |
| 132 | 132 | String cfName = tableDef.getString(TableMetadata.CF_NAME); |
| 133 | 133 | try { |
| @@ -156,8 +156,8 @@ | ||
| 156 | 156 | } catch (RuntimeException e) { |
| 157 | 157 | // See ControlConnection#refreshSchema for why we'd rather not probably this further |
| 158 | 158 | logger.error(String.format("Error parsing schema for table %s.%s: " |
| 159 | - + "Cluster.getMetadata().getKeyspace(\"%s\").getTable(\"%s\") will be missing or incomplete", | |
| 160 | - keyspace.getName(), cfName, keyspace.getName(), cfName), e); | |
| 159 | + + "Cluster.getMetadata().getKeyspace(\"%s\").getTable(\"%s\") will be missing or incomplete", | |
| 160 | + keyspace.getName(), cfName, keyspace.getName(), cfName), e); | |
| 161 | 161 | } |
| 162 | 162 | } |
| 163 | 163 | } |
| @@ -169,11 +169,11 @@ | ||
| 169 | 169 | * This method also takes care of triggering the relevant events |
| 170 | 170 | * as the updates take place. |
| 171 | 171 | * |
| 172 | - * @param oldKeyspaces the set of keyspaces to be updated. | |
| 173 | - * @param newKeyspaces the temporary set of keyspaces built with information gathered | |
| 174 | - * from schema tables. | |
| 172 | + * @param oldKeyspaces the set of keyspaces to be updated. | |
| 173 | + * @param newKeyspaces the temporary set of keyspaces built with information gathered | |
| 174 | + * from schema tables. | |
| 175 | 175 | * @param keyspaceToRebuild If we are rebuilding just one keyspace, the update operation will be limited |
| 176 | - * to this keyspace only (in which case {@code newKeyspaces} shoudl contain only one entry for it) | |
| 176 | + * to this keyspace only (in which case {@code newKeyspaces} shoudl contain only one entry for it) | |
| 177 | 177 | */ |
| 178 | 178 | private void updateKeyspaces(Map<String, KeyspaceMetadata> oldKeyspaces, Map<String, KeyspaceMetadata> newKeyspaces, String keyspaceToRebuild) { |
| 179 | 179 | Iterator<KeyspaceMetadata> it = oldKeyspaces.values().iterator(); |
| @@ -205,11 +205,11 @@ | ||
| 205 | 205 | * This method also takes care of triggering the relevant events |
| 206 | 206 | * as the updates take place. |
| 207 | 207 | * |
| 208 | - * @param oldTables the set of tables to be updated. | |
| 209 | - * @param newTables the temporary set of tables built with information gathered | |
| 210 | - * from schema tables. | |
| 208 | + * @param oldTables the set of tables to be updated. | |
| 209 | + * @param newTables the temporary set of tables built with information gathered | |
| 210 | + * from schema tables. | |
| 211 | 211 | * @param tableToRebuild If we are rebuilding just one table, the update operation will be limited |
| 212 | - * to this table only (in which case {@code newTables} shoudl contain only one entry for it) | |
| 212 | + * to this table only (in which case {@code newTables} shoudl contain only one entry for it) | |
| 213 | 213 | */ |
| 214 | 214 | private void updateTables(Map<String, TableMetadata> oldTables, Map<String, TableMetadata> newTables, String tableToRebuild) { |
| 215 | 215 | Iterator<TableMetadata> it = oldTables.values().iterator(); |
| @@ -274,8 +274,8 @@ | ||
| 274 | 274 | return; |
| 275 | 275 | |
| 276 | 276 | Token.Factory factory = partitioner == null |
| 277 | - ? (tokenMap == null ? null : tokenMap.factory) | |
| 278 | - : Token.getFactory(partitioner); | |
| 277 | + ? (tokenMap == null ? null : tokenMap.factory) | |
| 278 | + : Token.getFactory(partitioner); | |
| 279 | 279 | if (factory == null) |
| 280 | 280 | return; |
| 281 | 281 | |
| @@ -335,7 +335,7 @@ | ||
| 335 | 335 | |
| 336 | 336 | /** |
| 337 | 337 | * Quote a keyspace, table or column identifier to make it case sensitive. |
| 338 | - * <p> | |
| 338 | + * <p/> | |
| 339 | 339 | * CQL identifiers, including keyspace, table and column ones, are case insensitive |
| 340 | 340 | * by default. Case sensitive identifiers can however be provided by enclosing |
| 341 | 341 | * the identifier in double quotes (see the |
| @@ -355,7 +355,7 @@ | ||
| 355 | 355 | |
| 356 | 356 | /** |
| 357 | 357 | * Returns the token ranges that define data distribution in the ring. |
| 358 | - * <p> | |
| 358 | + * <p/> | |
| 359 | 359 | * Note that this information is refreshed asynchronously by the control |
| 360 | 360 | * connection, when schema or ring topology changes. It might occasionally |
| 361 | 361 | * be stale. |
| @@ -371,13 +371,13 @@ | ||
| 371 | 371 | /** |
| 372 | 372 | * Returns the token ranges that are replicated on the given host, for the given |
| 373 | 373 | * keyspace. |
| 374 | - * <p> | |
| 374 | + * <p/> | |
| 375 | 375 | * Note that this information is refreshed asynchronously by the control |
| 376 | 376 | * connection, when schema or ring topology changes. It might occasionally |
| 377 | 377 | * be stale (or even empty). |
| 378 | 378 | * |
| 379 | 379 | * @param keyspace the name of the keyspace to get token ranges for. |
| 380 | - * @param host the host. | |
| 380 | + * @param host the host. | |
| 381 | 381 | * @return the (immutable) set of token ranges for {@code host} as known |
| 382 | 382 | * by the driver. Note that the result might be stale or empty if metadata |
| 383 | 383 | * was explicitly disabled with {@link QueryOptions#setMetadataEnabled(boolean)}. |
| @@ -400,14 +400,14 @@ | ||
| 400 | 400 | |
| 401 | 401 | /** |
| 402 | 402 | * Returns the set of hosts that are replica for a given partition key. |
| 403 | - * <p> | |
| 403 | + * <p/> | |
| 404 | 404 | * Note that this information is refreshed asynchronously by the control |
| 405 | 405 | * connection, when schema or ring topology changes. It might occasionally |
| 406 | 406 | * be stale (or even empty). |
| 407 | 407 | * |
| 408 | - * @param keyspace the name of the keyspace to get replicas for. | |
| 408 | + * @param keyspace the name of the keyspace to get replicas for. | |
| 409 | 409 | * @param partitionKey the partition key for which to find the set of |
| 410 | - * replica. | |
| 410 | + * replica. | |
| 411 | 411 | * @return the (immutable) set of replicas for {@code partitionKey} as known |
| 412 | 412 | * by the driver. Note that the result might be stale or empty if metadata was |
| 413 | 413 | * explicitly disabled with {@link QueryOptions#setMetadataEnabled(boolean)}. |
| @@ -425,13 +425,13 @@ | ||
| 425 | 425 | |
| 426 | 426 | /** |
| 427 | 427 | * Returns the set of hosts that are replica for a given token range. |
| 428 | - * <p> | |
| 428 | + * <p/> | |
| 429 | 429 | * Note that this information is refreshed asynchronously by the control |
| 430 | 430 | * connection, when schema or ring topology changes. It might occasionally |
| 431 | 431 | * be stale (or even empty). |
| 432 | 432 | * |
| 433 | 433 | * @param keyspace the name of the keyspace to get replicas for. |
| 434 | - * @param range the token range. | |
| 434 | + * @param range the token range. | |
| 435 | 435 | * @return the (immutable) set of replicas for {@code range} as known by the driver. |
| 436 | 436 | * Note that the result might be stale or empty if metadata was explicitly disabled |
| 437 | 437 | * with {@link QueryOptions#setMetadataEnabled(boolean)}. |
| @@ -476,7 +476,7 @@ | ||
| 476 | 476 | |
| 477 | 477 | /** |
| 478 | 478 | * Checks whether hosts that are currently up agree on the schema definition. |
| 479 | - * <p> | |
| 479 | + * <p/> | |
| 480 | 480 | * This method performs a one-time check only, without any form of retry; therefore {@link Cluster.Builder#withMaxSchemaAgreementWaitSeconds(int)} |
| 481 | 481 | * does not apply in this case. |
| 482 | 482 | * |
| @@ -496,7 +496,7 @@ | ||
| 496 | 496 | * Returns the metadata of a keyspace given its name. |
| 497 | 497 | * |
| 498 | 498 | * @param keyspace the name of the keyspace for which metadata should be |
| 499 | - * returned. | |
| 499 | + * returned. | |
| 500 | 500 | * @return the metadata of the requested keyspace or {@code null} if {@code |
| 501 | 501 | * keyspace} is not a known keyspace. Note that the result might be stale or null if |
| 502 | 502 | * metadata was explicitly disabled with {@link QueryOptions#setMetadataEnabled(boolean)}. |
| @@ -533,13 +533,13 @@ | ||
| 533 | 533 | /** |
| 534 | 534 | * Returns a {@code String} containing CQL queries representing the schema |
| 535 | 535 | * of this cluster. |
| 536 | - * | |
| 536 | + * <p/> | |
| 537 | 537 | * In other words, this method returns the queries that would allow to |
| 538 | 538 | * recreate the schema of this cluster. |
| 539 | - * | |
| 539 | + * <p/> | |
| 540 | 540 | * Note that the returned String is formatted to be human readable (for |
| 541 | 541 | * some definition of human readable at least). |
| 542 | - * | |
| 542 | + * <p/> | |
| 543 | 543 | * It might be stale or empty if metadata was explicitly disabled with |
| 544 | 544 | * {@link QueryOptions#setMetadataEnabled(boolean)}. |
| 545 | 545 | * |
| @@ -561,10 +561,9 @@ | ||
| 561 | 561 | * |
| 562 | 562 | * @param tokenStr the string representation. |
| 563 | 563 | * @return the token. |
| 564 | - * | |
| 565 | 564 | * @throws IllegalStateException if the token factory was not initialized. This would typically |
| 566 | - * happen if metadata was explicitly disabled with {@link QueryOptions#setMetadataEnabled(boolean)} | |
| 567 | - * before startup. | |
| 565 | + * happen if metadata was explicitly disabled with {@link QueryOptions#setMetadataEnabled(boolean)} | |
| 566 | + * before startup. | |
| 568 | 567 | */ |
| 569 | 568 | public Token newToken(String tokenStr) { |
| 570 | 569 | TokenMap current = tokenMap; |
| @@ -578,12 +577,11 @@ | ||
| 578 | 577 | * Builds a new {@link TokenRange}. |
| 579 | 578 | * |
| 580 | 579 | * @param start the start token. |
| 581 | - * @param end the end token. | |
| 580 | + * @param end the end token. | |
| 582 | 581 | * @return the range. |
| 583 | - * | |
| 584 | 582 | * @throws IllegalStateException if the token factory was not initialized. This would typically |
| 585 | - * happen if metadata was explicitly disabled with {@link QueryOptions#setMetadataEnabled(boolean)} | |
| 586 | - * before startup. | |
| 583 | + * happen if metadata was explicitly disabled with {@link QueryOptions#setMetadataEnabled(boolean)} | |
| 584 | + * before startup. | |
| 587 | 585 | */ |
| 588 | 586 | public TokenRange newTokenRange(Token start, Token end) { |
| 589 | 587 | TokenMap current = tokenMap; |
| @@ -655,12 +653,11 @@ | ||
| 655 | 653 | |
| 656 | 654 | Map<String, Map<Token, Set<Host>>> tokenToHosts = new HashMap<String, Map<Token, Set<Host>>>(); |
| 657 | 655 | Map<String, Map<Host, Set<TokenRange>>> hostsToRanges = new HashMap<String, Map<Host, Set<TokenRange>>>(); |
| 658 | - for (KeyspaceMetadata keyspace : keyspaces) | |
| 659 | - { | |
| 656 | + for (KeyspaceMetadata keyspace : keyspaces) { | |
| 660 | 657 | ReplicationStrategy strategy = keyspace.replicationStrategy(); |
| 661 | 658 | Map<Token, Set<Host>> ksTokens = (strategy == null) |
| 662 | - ? makeNonReplicatedMap(tokenToPrimary) | |
| 663 | - : strategy.computeTokenToReplicaMap(tokenToPrimary, ring); | |
| 659 | + ? makeNonReplicatedMap(tokenToPrimary) | |
| 660 | + : strategy.computeTokenToReplicaMap(tokenToPrimary, ring); | |
| 664 | 661 | |
| 665 | 662 | tokenToHosts.put(keyspace.getName(), ksTokens); |
| 666 | 663 | |
| @@ -711,8 +708,8 @@ | ||
| 711 | 708 | private static Set<TokenRange> makeTokenRanges(List<Token> ring, Token.Factory factory) { |
| 712 | 709 | ImmutableSet.Builder<TokenRange> builder = ImmutableSet.builder(); |
| 713 | 710 | // JAVA-684: if there is only one token, return the range ]minToken, minToken] |
| 714 | - if(ring.size() == 1) { | |
| 715 | - builder.add(new TokenRange(factory.minToken(), factory.minToken(), factory)); | |
| 711 | + if (ring.size() == 1) { | |
| 712 | + builder.add(new TokenRange(factory.minToken(), factory.minToken(), factory)); | |
| 716 | 713 | } else { |
| 717 | 714 | for (int i = 0; i < ring.size(); i++) { |
| 718 | 715 | Token start = ring.get(i); |
modified driver-core/src/main/java/com/datastax/driver/core/Metrics.java +16 −17
| @@ -15,20 +15,19 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.util.HashSet; | |
| 19 | -import java.util.Set; | |
| 20 | - | |
| 21 | 18 | import com.codahale.metrics.*; |
| 22 | - | |
| 23 | 19 | import com.datastax.driver.core.policies.SpeculativeExecutionPolicy; |
| 24 | 20 | |
| 21 | +import java.util.HashSet; | |
| 22 | +import java.util.Set; | |
| 23 | + | |
| 25 | 24 | /** |
| 26 | 25 | * Metrics exposed by the driver. |
| 27 | - * <p> | |
| 26 | + * <p/> | |
| 28 | 27 | * The metrics exposed by this class use the <a href="http://metrics.codahale.com/">Metrics</a> |
| 29 | 28 | * library and you should refer its <a href="http://metrics.codahale.com/manual/">documentation</a> |
| 30 | 29 | * for details on how to handle the exposed metric objects. |
| 31 | - * <p> | |
| 30 | + * <p/> | |
| 32 | 31 | * By default, metrics are exposed through JMX, which is very useful for |
| 33 | 32 | * development and browsing, but for production environments you may want to |
| 34 | 33 | * have a look at the <a href="http://metrics.codahale.com/manual/core/#reporters">reporters</a> |
| @@ -93,7 +92,7 @@ | ||
| 93 | 92 | } |
| 94 | 93 | }); |
| 95 | 94 | |
| 96 | - private final Gauge<Integer> reconnectionSchedulerQueueSize= registry.register("reconnection-scheduler-task-count", new Gauge<Integer>() { | |
| 95 | + private final Gauge<Integer> reconnectionSchedulerQueueSize = registry.register("reconnection-scheduler-task-count", new Gauge<Integer>() { | |
| 97 | 96 | @Override |
| 98 | 97 | public Integer getValue() { |
| 99 | 98 | return manager.reconnectionExecutor.getQueue().size(); |
| @@ -119,17 +118,17 @@ | ||
| 119 | 118 | |
| 120 | 119 | /** |
| 121 | 120 | * Returns the registry containing all metrics. |
| 122 | - * <p> | |
| 121 | + * <p/> | |
| 123 | 122 | * The metrics registry allows you to easily use the reporters that ship |
| 124 | 123 | * with <a href="http://metrics.codahale.com/manual/core/#reporters">Metrics</a> |
| 125 | 124 | * or a custom written one. |
| 126 | - * <p> | |
| 125 | + * <p/> | |
| 127 | 126 | * For instance, if {@code metrics} is {@code this} object, you could export the |
| 128 | 127 | * metrics to csv files using: |
| 129 | 128 | * <pre> |
| 130 | 129 | * com.codahale.metrics.CsvReporter.forRegistry(metrics.getRegistry()).build(new File("measurements/")).start(1, TimeUnit.SECONDS); |
| 131 | 130 | * </pre> |
| 132 | - * <p> | |
| 131 | + * <p/> | |
| 133 | 132 | * If you already have a {@code MetricRegistry} in your application and wish to |
| 134 | 133 | * add the driver's metrics to it, the recommended approach is to use a listener: |
| 135 | 134 | * <pre> |
| @@ -161,12 +160,12 @@ | ||
| 161 | 160 | |
| 162 | 161 | /** |
| 163 | 162 | * Returns metrics on the user requests performed on the Cluster. |
| 164 | - * <p> | |
| 163 | + * <p/> | |
| 165 | 164 | * This metric exposes |
| 166 | 165 | * <ul> |
| 167 | - * <li>the total number of requests.</li> | |
| 168 | - * <li>the requests rate (in requests per seconds), including 1, 5 and 15 minute rates.</li> | |
| 169 | - * <li>the mean, min and max latencies, as well as latency at a given percentile.</li> | |
| 166 | + * <li>the total number of requests.</li> | |
| 167 | + * <li>the requests rate (in requests per seconds), including 1, 5 and 15 minute rates.</li> | |
| 168 | + * <li>the mean, min and max latencies, as well as latency at a given percentile.</li> | |
| 170 | 169 | * </ul> |
| 171 | 170 | * |
| 172 | 171 | * @return a {@code Timer} metric object exposing the rate and latency for |
| @@ -216,7 +215,7 @@ | ||
| 216 | 215 | |
| 217 | 216 | /** |
| 218 | 217 | * Returns the total number of currently "trashed" connections to Cassandra hosts. |
| 219 | - * <p> | |
| 218 | + * <p/> | |
| 220 | 219 | * When the load to a host decreases, the driver will reclaim some connections in order to save |
| 221 | 220 | * resources. No requests are sent to these connections anymore, but they are kept open for an |
| 222 | 221 | * additional amount of time ({@link PoolingOptions#getIdleTimeoutSeconds()}), in case the load |
| @@ -289,11 +288,11 @@ | ||
| 289 | 288 | |
| 290 | 289 | /** |
| 291 | 290 | * Returns the number of connection to Cassandra nodes errors. |
| 292 | - * <p> | |
| 291 | + * <p/> | |
| 293 | 292 | * This represents the number of times that a request to a Cassandra node |
| 294 | 293 | * has failed due to a connection problem. This thus also corresponds to |
| 295 | 294 | * how often the driver had to pick a fallback host for a request. |
| 296 | - * <p> | |
| 295 | + * <p/> | |
| 297 | 296 | * You can expect a few connection errors when a Cassandra node fails |
| 298 | 297 | * (or is stopped) ,but if that number grows continuously you likely have |
| 299 | 298 | * a problem. |
modified driver-core/src/main/java/com/datastax/driver/core/MetricsOptions.java +3 −6
| @@ -25,8 +25,7 @@ | ||
| 25 | 25 | /** |
| 26 | 26 | * Creates a new {@code MetricsOptions} object with default values. |
| 27 | 27 | */ |
| 28 | - public MetricsOptions() | |
| 29 | - { | |
| 28 | + public MetricsOptions() { | |
| 30 | 29 | this(true); |
| 31 | 30 | } |
| 32 | 31 | |
| @@ -35,8 +34,7 @@ | ||
| 35 | 34 | * |
| 36 | 35 | * @param jmxEnabled whether to enable JMX reporting or not. |
| 37 | 36 | */ |
| 38 | - public MetricsOptions(boolean jmxEnabled) | |
| 39 | - { | |
| 37 | + public MetricsOptions(boolean jmxEnabled) { | |
| 40 | 38 | this.jmxEnabled = jmxEnabled; |
| 41 | 39 | } |
| 42 | 40 | |
| @@ -45,8 +43,7 @@ | ||
| 45 | 43 | * |
| 46 | 44 | * @return whether JMX reporting is enabled. |
| 47 | 45 | */ |
| 48 | - public boolean isJMXReportingEnabled() | |
| 49 | - { | |
| 46 | + public boolean isJMXReportingEnabled() { | |
| 50 | 47 | return jmxEnabled; |
| 51 | 48 | } |
| 52 | 49 | } |
modified driver-core/src/main/java/com/datastax/driver/core/NettyOptions.java +36 −41
| @@ -15,30 +15,25 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.util.concurrent.ThreadFactory; | |
| 19 | -import java.util.concurrent.TimeUnit; | |
| 20 | - | |
| 21 | -import static java.util.concurrent.TimeUnit.SECONDS; | |
| 22 | - | |
| 23 | 18 | import io.netty.bootstrap.Bootstrap; |
| 24 | 19 | import io.netty.buffer.PooledByteBufAllocator; |
| 25 | 20 | import io.netty.channel.ChannelOption; |
| 26 | 21 | import io.netty.channel.EventLoopGroup; |
| 27 | -import io.netty.channel.nio.NioEventLoopGroup; | |
| 28 | 22 | import io.netty.channel.socket.SocketChannel; |
| 29 | -import io.netty.channel.socket.nio.NioSocketChannel; | |
| 30 | 23 | import io.netty.util.HashedWheelTimer; |
| 31 | 24 | import io.netty.util.Timer; |
| 32 | 25 | |
| 26 | +import java.util.concurrent.ThreadFactory; | |
| 27 | + | |
| 33 | 28 | /** |
| 34 | 29 | * A set of hooks that allow clients to customize the driver's underlying Netty layer. |
| 35 | - * <p> | |
| 30 | + * <p/> | |
| 36 | 31 | * Clients that need to hook into the driver's underlying Netty layer can |
| 37 | 32 | * subclass this class and provide the necessary customization by overriding |
| 38 | 33 | * its methods. |
| 39 | - * <p> | |
| 34 | + * <p/> | |
| 40 | 35 | * Typically, clients would register this class with {@link Cluster#builder()}: |
| 41 | - * | |
| 36 | + * <p/> | |
| 42 | 37 | * <pre> |
| 43 | 38 | * NettyOptions nettyOptions = ... |
| 44 | 39 | * Cluster cluster = Cluster.builder() |
| @@ -46,24 +41,24 @@ | ||
| 46 | 41 | * .withNettyOptions(nettyOptions) |
| 47 | 42 | * .build(); |
| 48 | 43 | * </pre> |
| 49 | - * | |
| 44 | + * <p/> | |
| 50 | 45 | * <strong>Extending the NettyOptions API</strong> |
| 51 | - * <p> | |
| 46 | + * <p/> | |
| 52 | 47 | * Contrary to other driver options, the options available in this class should |
| 53 | 48 | * be considered as advanced features and as such, <em>they should only be |
| 54 | 49 | * modified by expert users</em>. |
| 55 | - * <p> | |
| 50 | + * <p/> | |
| 56 | 51 | * <strong>A misconfiguration introduced by the means of this API can have unexpected results |
| 57 | 52 | * and cause the driver to completely fail to connect.</strong> |
| 58 | - * <p> | |
| 53 | + * <p/> | |
| 59 | 54 | * Moreover, since versions 2.0.9 and 2.1.4 (see JAVA-538), |
| 60 | 55 | * the driver is available in two different flavors: with a standard Maven dependency on Netty, |
| 61 | 56 | * or with a "shaded" (internalized) Netty dependency. |
| 62 | - * <p> | |
| 57 | + * <p/> | |
| 63 | 58 | * Given that NettyOptions API exposes Netty classes ({@link SocketChannel}, etc.), |
| 64 | 59 | * <em>it should only be extended by clients using the non-shaded |
| 65 | 60 | * version of driver</em>. |
| 66 | - * <p> | |
| 61 | + * <p/> | |
| 67 | 62 | * <strong>Extending this API with shaded Netty classes is not supported, |
| 68 | 63 | * and in particular for OSGi applications, it is likely that such a configuration would lead to |
| 69 | 64 | * compile and/or runtime errors.</strong> |
| @@ -79,15 +74,15 @@ | ||
| 79 | 74 | |
| 80 | 75 | /** |
| 81 | 76 | * Return the {@code EventLoopGroup} instance to use. |
| 82 | - * <p> | |
| 77 | + * <p/> | |
| 83 | 78 | * This hook is invoked only once at {@link Cluster} initialization; |
| 84 | 79 | * the returned instance will be kept in use throughout the cluster lifecycle. |
| 85 | - * <p> | |
| 80 | + * <p/> | |
| 86 | 81 | * Typically, implementors would return a newly-created instance; |
| 87 | 82 | * it is however possible to re-use a shared instance, but in this |
| 88 | 83 | * case implementors should also override {@link #onClusterClose(EventLoopGroup)} |
| 89 | 84 | * to prevent the shared instance to be closed when the cluster is closed. |
| 90 | - * <p> | |
| 85 | + * <p/> | |
| 91 | 86 | * The default implementation returns a new instance of {@code io.netty.channel.epoll.EpollEventLoopGroup} |
| 92 | 87 | * if {@link NettyUtil#isEpollAvailable() epoll is available}, |
| 93 | 88 | * or {@code io.netty.channel.nio.NioEventLoopGroup} otherwise. |
| @@ -103,11 +98,11 @@ | ||
| 103 | 98 | |
| 104 | 99 | /** |
| 105 | 100 | * Return the specific {@code SocketChannel} subclass to use. |
| 106 | - * <p> | |
| 101 | + * <p/> | |
| 107 | 102 | * This hook is invoked only once at {@link Cluster} initialization; |
| 108 | 103 | * the returned instance will then be used each time the driver creates a new {@link Connection} |
| 109 | 104 | * and configures a new instance of {@link Bootstrap} for it. |
| 110 | - * <p> | |
| 105 | + * <p/> | |
| 111 | 106 | * The default implementation returns {@code io.netty.channel.epoll.EpollSocketChannel} if {@link NettyUtil#isEpollAvailable() epoll is available}, |
| 112 | 107 | * or {@code io.netty.channel.socket.nio.NioSocketChannel} otherwise. |
| 113 | 108 | * |
| @@ -120,13 +115,13 @@ | ||
| 120 | 115 | /** |
| 121 | 116 | * Hook invoked each time the driver creates a new {@link Connection} |
| 122 | 117 | * and configures a new instance of {@link Bootstrap} for it. |
| 123 | - * <p> | |
| 118 | + * <p/> | |
| 124 | 119 | * This hook is guaranteed to be called <em>after</em> the driver has applied all |
| 125 | 120 | * {@link SocketOptions}s. |
| 126 | - * <p> | |
| 121 | + * <p/> | |
| 127 | 122 | * This is a good place to add extra {@link io.netty.channel.ChannelHandler ChannelOption}s to the boostrap; e.g. |
| 128 | 123 | * plug a custom {@link io.netty.buffer.ByteBufAllocator ByteBufAllocator} implementation: |
| 129 | - * | |
| 124 | + * <p/> | |
| 130 | 125 | * <pre> |
| 131 | 126 | * ByteBufAllocator myCustomByteBufAllocator = ... |
| 132 | 127 | * |
| @@ -134,7 +129,7 @@ | ||
| 134 | 129 | * bootstrap.option(ChannelOption.ALLOCATOR, myCustomByteBufAllocator); |
| 135 | 130 | * } |
| 136 | 131 | * </pre> |
| 137 | - * | |
| 132 | + * <p/> | |
| 138 | 133 | * Note that the default implementation of this method configures a pooled {@code ByteBufAllocator} (Netty 4.0 |
| 139 | 134 | * defaults to unpooled). If you override this method to set unrelated options, make sure you call |
| 140 | 135 | * {@code super.afterBootstrapInitialized(bootstrap)}. |
| @@ -149,21 +144,21 @@ | ||
| 149 | 144 | /** |
| 150 | 145 | * Hook invoked each time the driver creates a new {@link Connection} |
| 151 | 146 | * and initializes the {@link SocketChannel channel}. |
| 152 | - * <p> | |
| 147 | + * <p/> | |
| 153 | 148 | * This hook is guaranteed to be called <em>after</em> the driver has registered |
| 154 | 149 | * all its internal channel handlers, and applied the configured {@link SSLOptions}, if any. |
| 155 | - * <p> | |
| 150 | + * <p/> | |
| 156 | 151 | * This is a good place to add extra {@link io.netty.channel.ChannelHandler ChannelHandler}s |
| 157 | 152 | * to the channel's pipeline; e.g. to add a custom SSL handler to the beginning of the handler chain, |
| 158 | 153 | * do the following: |
| 159 | - * | |
| 154 | + * <p/> | |
| 160 | 155 | * <pre> |
| 161 | 156 | * ChannelPipeline pipeline = channel.pipeline(); |
| 162 | 157 | * SSLEngine myCustomSSLEngine = ... |
| 163 | 158 | * SslHandler myCustomSSLHandler = new SslHandler(myCustomSSLEngine); |
| 164 | 159 | * pipeline.addFirst("ssl", myCustomSSLHandler); |
| 165 | 160 | * </pre> |
| 166 | - * | |
| 161 | + * <p/> | |
| 167 | 162 | * Note: if you intend to provide your own SSL implementation, |
| 168 | 163 | * do not enable the driver's built-in {@link SSLOptions} at the same time. |
| 169 | 164 | * |
| @@ -176,15 +171,15 @@ | ||
| 176 | 171 | |
| 177 | 172 | /** |
| 178 | 173 | * Hook invoked when the cluster is shutting down after a call to {@link Cluster#close()}. |
| 179 | - * <p> | |
| 174 | + * <p/> | |
| 180 | 175 | * This is guaranteed to be called only after all connections have been individually |
| 181 | 176 | * closed, and their channels closed, and only once per {@link EventLoopGroup} instance. |
| 182 | - * <p> | |
| 177 | + * <p/> | |
| 183 | 178 | * This gives the implementor a chance to close the {@link EventLoopGroup} properly, if required. |
| 184 | - * <p> | |
| 179 | + * <p/> | |
| 185 | 180 | * The default implementation initiates a {@link EventLoopGroup#shutdownGracefully() graceful shutdown} |
| 186 | 181 | * of the passed {@link EventLoopGroup}, then waits uninterruptibly for the shutdown to complete or timeout. |
| 187 | - * <p> | |
| 182 | + * <p/> | |
| 188 | 183 | * Implementation note: if the {@link EventLoopGroup} instance is being shared, or used for other purposes than to |
| 189 | 184 | * coordinate Netty events for the current cluster, then it should not be shut down here; |
| 190 | 185 | * subclasses would have to override this method accordingly to take the appropriate action. |
| @@ -197,17 +192,17 @@ | ||
| 197 | 192 | |
| 198 | 193 | /** |
| 199 | 194 | * Return the {@link Timer} instance used by Read Timeouts and Speculative Execution. |
| 200 | - * <p> | |
| 195 | + * <p/> | |
| 201 | 196 | * This hook is invoked only once at {@link Cluster} initialization; |
| 202 | 197 | * the returned instance will be kept in use throughout the cluster lifecycle. |
| 203 | - * <p> | |
| 198 | + * <p/> | |
| 204 | 199 | * Typically, implementors would return a newly-created instance; |
| 205 | 200 | * it is however possible to re-use a shared instance, but in this |
| 206 | 201 | * case implementors should also override {@link #onClusterClose(Timer)} |
| 207 | 202 | * to prevent the shared instance to be closed when the cluster is closed. |
| 208 | - * <p> | |
| 203 | + * <p/> | |
| 209 | 204 | * The default implementation returns a new instance created by {@link HashedWheelTimer#HashedWheelTimer(ThreadFactory)}. |
| 210 | - * | |
| 205 | + * | |
| 211 | 206 | * @param threadFactory The {@link ThreadFactory} to use when creating a new {@link HashedWheelTimer} instance; |
| 212 | 207 | * The driver will provide its own internal thread factory here. |
| 213 | 208 | * It is safe to ignore it and use another thread factory. |
| @@ -219,14 +214,14 @@ | ||
| 219 | 214 | |
| 220 | 215 | /** |
| 221 | 216 | * Hook invoked when the cluster is shutting down after a call to {@link Cluster#close()}. |
| 222 | - * <p> | |
| 217 | + * <p/> | |
| 223 | 218 | * This is guaranteed to be called only after all connections have been individually |
| 224 | 219 | * closed, and their channels closed, and only once per {@link Timer} instance. |
| 225 | - * <p> | |
| 220 | + * <p/> | |
| 226 | 221 | * This gives the implementor a chance to close the {@link Timer} properly, if required. |
| 227 | - * <p> | |
| 222 | + * <p/> | |
| 228 | 223 | * The default implementation calls a {@link Timer#stop()} of the passed {@link Timer} instance. |
| 229 | - * <p> | |
| 224 | + * <p/> | |
| 230 | 225 | * Implementation note: if the {@link Timer} instance is being shared, or used for other purposes than to |
| 231 | 226 | * schedule actions for the current cluster, than it should not be stopped here; |
| 232 | 227 | * subclasses would have to override this method accordingly to take the appropriate action. |
modified driver-core/src/main/java/com/datastax/driver/core/NettyUtil.java +14 −15
| @@ -15,10 +15,6 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.lang.reflect.Constructor; | |
| 19 | -import java.util.Locale; | |
| 20 | -import java.util.concurrent.ThreadFactory; | |
| 21 | - | |
| 22 | 18 | import com.google.common.base.Throwables; |
| 23 | 19 | import io.netty.channel.EventLoopGroup; |
| 24 | 20 | import io.netty.channel.nio.NioEventLoopGroup; |
| @@ -27,6 +23,10 @@ | ||
| 27 | 23 | import org.slf4j.Logger; |
| 28 | 24 | import org.slf4j.LoggerFactory; |
| 29 | 25 | |
| 26 | +import java.lang.reflect.Constructor; | |
| 27 | +import java.util.Locale; | |
| 28 | +import java.util.concurrent.ThreadFactory; | |
| 29 | + | |
| 30 | 30 | /** |
| 31 | 31 | * A set of utilities related to the underlying Netty layer. |
| 32 | 32 | */ |
| @@ -45,7 +45,7 @@ | ||
| 45 | 45 | |
| 46 | 46 | private static final Class<? extends SocketChannel> EPOLL_CHANNEL_CLASS; |
| 47 | 47 | |
| 48 | - private static final Class[] EVENT_GROUP_ARGUMENTS = { int.class, ThreadFactory.class }; | |
| 48 | + private static final Class[] EVENT_GROUP_ARGUMENTS = {int.class, ThreadFactory.class}; | |
| 49 | 49 | |
| 50 | 50 | static { |
| 51 | 51 | boolean shaded; |
| @@ -68,13 +68,13 @@ | ||
| 68 | 68 | Class<?> epoll = Class.forName("io.netty.channel.epoll.Epoll"); |
| 69 | 69 | if (FORCE_NIO) { |
| 70 | 70 | LOGGER.info("Found Netty's native epoll transport in the classpath, " |
| 71 | - + "but NIO was forced through the FORCE_NIO system property."); | |
| 71 | + + "but NIO was forced through the FORCE_NIO system property."); | |
| 72 | 72 | } else if (!System.getProperty("os.name", "").toLowerCase(Locale.US).equals("linux")) { |
| 73 | 73 | LOGGER.warn("Found Netty's native epoll transport, but not running on linux-based operating " + |
| 74 | - "system. Using NIO instead."); | |
| 75 | - } else if (!(Boolean)epoll.getMethod("isAvailable").invoke(null)) { | |
| 74 | + "system. Using NIO instead."); | |
| 75 | + } else if (!(Boolean) epoll.getMethod("isAvailable").invoke(null)) { | |
| 76 | 76 | LOGGER.warn("Found Netty's native epoll transport in the classpath, but epoll is not available. " |
| 77 | - + "Using NIO instead.", (Throwable)epoll.getMethod("unavailabilityCause").invoke(null)); | |
| 77 | + + "Using NIO instead.", (Throwable) epoll.getMethod("unavailabilityCause").invoke(null)); | |
| 78 | 78 | } else { |
| 79 | 79 | LOGGER.info("Found Netty's native epoll transport in the classpath, using it"); |
| 80 | 80 | useEpoll = true; |
| @@ -86,16 +86,16 @@ | ||
| 86 | 86 | } |
| 87 | 87 | } else { |
| 88 | 88 | LOGGER.info("Detected shaded Netty classes in the classpath; native epoll transport will not work properly, " |
| 89 | - + "defaulting to NIO."); | |
| 89 | + + "defaulting to NIO."); | |
| 90 | 90 | } |
| 91 | 91 | USE_EPOLL = useEpoll; |
| 92 | 92 | Constructor<? extends EventLoopGroup> constructor = null; |
| 93 | 93 | Class<? extends SocketChannel> channelClass = null; |
| 94 | 94 | if (USE_EPOLL) { |
| 95 | 95 | try { |
| 96 | - channelClass = (Class<? extends SocketChannel>)Class.forName("io.netty.channel.epoll.EpollSocketChannel"); | |
| 96 | + channelClass = (Class<? extends SocketChannel>) Class.forName("io.netty.channel.epoll.EpollSocketChannel"); | |
| 97 | 97 | Class<?> epoolEventLoupGroupClass = Class.forName("io.netty.channel.epoll.EpollEventLoopGroup"); |
| 98 | - constructor = (Constructor<? extends EventLoopGroup>)epoolEventLoupGroupClass.getDeclaredConstructor(EVENT_GROUP_ARGUMENTS); | |
| 98 | + constructor = (Constructor<? extends EventLoopGroup>) epoolEventLoupGroupClass.getDeclaredConstructor(EVENT_GROUP_ARGUMENTS); | |
| 99 | 99 | } catch (Exception e) { |
| 100 | 100 | throw new AssertionError("Netty's native epoll is in use but cannot locate Epoll classes, this should not happen: " + e); |
| 101 | 101 | } |
| @@ -105,7 +105,6 @@ | ||
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | /** |
| 108 | - * | |
| 109 | 108 | * @return true if the current driver bundle is using shaded Netty classes, false otherwise. |
| 110 | 109 | */ |
| 111 | 110 | |
| @@ -122,7 +121,7 @@ | ||
| 122 | 121 | |
| 123 | 122 | /** |
| 124 | 123 | * Return a new instance of {@link EventLoopGroup}. |
| 125 | - * <p> | |
| 124 | + * <p/> | |
| 126 | 125 | * Returns an instance of {@link io.netty.channel.epoll.EpollEventLoopGroup} if {@link #isEpollAvailable() epoll is available}, |
| 127 | 126 | * or an instance of {@link NioEventLoopGroup} otherwise. |
| 128 | 127 | * |
| @@ -143,7 +142,7 @@ | ||
| 143 | 142 | |
| 144 | 143 | /** |
| 145 | 144 | * Return the SocketChannel class to use. |
| 146 | - * <p> | |
| 145 | + * <p/> | |
| 147 | 146 | * Returns an instance of {@link io.netty.channel.epoll.EpollSocketChannel} if {@link #isEpollAvailable() epoll is available}, |
| 148 | 147 | * or an instance of {@link NioSocketChannel} otherwise. |
| 149 | 148 | * |
modified driver-core/src/main/java/com/datastax/driver/core/PagingState.java +11 −14
| @@ -16,21 +16,20 @@ | ||
| 16 | 16 | |
| 17 | 17 | package com.datastax.driver.core; |
| 18 | 18 | |
| 19 | +import com.datastax.driver.core.exceptions.PagingStateException; | |
| 20 | +import com.datastax.driver.core.utils.Bytes; | |
| 21 | + | |
| 19 | 22 | import java.nio.ByteBuffer; |
| 20 | 23 | import java.security.MessageDigest; |
| 21 | 24 | import java.security.NoSuchAlgorithmException; |
| 22 | 25 | import java.util.Arrays; |
| 23 | 26 | |
| 24 | -import com.datastax.driver.core.exceptions.InvalidQueryException; | |
| 25 | -import com.datastax.driver.core.exceptions.PagingStateException; | |
| 26 | -import com.datastax.driver.core.utils.Bytes; | |
| 27 | - | |
| 28 | 27 | /** |
| 29 | 28 | * The paging state of a query. |
| 30 | - * | |
| 29 | + * <p/> | |
| 31 | 30 | * This object represents the next page to be fetched if the query is |
| 32 | 31 | * multi page. It can be saved and reused later on the same statement. |
| 33 | - * | |
| 32 | + * <p/> | |
| 34 | 33 | * The PagingState can be serialized and deserialized either as a String |
| 35 | 34 | * or as a byte array. |
| 36 | 35 | * |
| @@ -53,7 +52,7 @@ | ||
| 53 | 52 | int hashSize = pagingStateBB.getShort(); |
| 54 | 53 | if (pagingSize + hashSize != pagingStateBB.remaining()) { |
| 55 | 54 | throw new PagingStateException("Cannot deserialize paging state, invalid format. " |
| 56 | - + "The serialized form was corrupted, or not initially generated from a PagingState object."); | |
| 55 | + + "The serialized form was corrupted, or not initially generated from a PagingState object."); | |
| 57 | 56 | } |
| 58 | 57 | this.pagingState = extractPagingState(complete); |
| 59 | 58 | this.hash = extractHashDigest(complete); |
| @@ -67,12 +66,12 @@ | ||
| 67 | 66 | try { |
| 68 | 67 | md = MessageDigest.getInstance("MD5"); |
| 69 | 68 | if (statement instanceof BoundStatement) { |
| 70 | - BoundStatement bs = ((BoundStatement)statement); | |
| 69 | + BoundStatement bs = ((BoundStatement) statement); | |
| 71 | 70 | md.update(bs.preparedStatement().getQueryString().getBytes()); |
| 72 | 71 | values = bs.values; |
| 73 | 72 | } else { |
| 74 | 73 | //it is a RegularStatement since Batch statements are not allowed |
| 75 | - RegularStatement rs = (RegularStatement)statement; | |
| 74 | + RegularStatement rs = (RegularStatement) statement; | |
| 76 | 75 | md.update(rs.getQueryString().getBytes()); |
| 77 | 76 | values = rs.getValues(); |
| 78 | 77 | } |
| @@ -118,8 +117,8 @@ | ||
| 118 | 117 | private ByteBuffer generateCompleteOutput() { |
| 119 | 118 | ByteBuffer res = ByteBuffer.allocate(pagingState.length + hash.length + 4); |
| 120 | 119 | |
| 121 | - res.putShort((short)pagingState.length); | |
| 122 | - res.putShort((short)hash.length); | |
| 120 | + res.putShort((short) pagingState.length); | |
| 121 | + res.putShort((short) hash.length); | |
| 123 | 122 | |
| 124 | 123 | res.put(pagingState); |
| 125 | 124 | res.put(hash); |
| @@ -143,7 +142,6 @@ | ||
| 143 | 142 | * |
| 144 | 143 | * @param string the string value. |
| 145 | 144 | * @return the PagingState object created. |
| 146 | - * | |
| 147 | 145 | * @throws PagingStateException if the string does not have the correct format. |
| 148 | 146 | */ |
| 149 | 147 | public static PagingState fromString(String string) { |
| @@ -152,7 +150,7 @@ | ||
| 152 | 150 | return new PagingState(complete); |
| 153 | 151 | } catch (Exception e) { |
| 154 | 152 | throw new PagingStateException("Cannot deserialize paging state, invalid format. " |
| 155 | - + "The serialized form was corrupted, or not initially generated from a PagingState object.", e); | |
| 153 | + + "The serialized form was corrupted, or not initially generated from a PagingState object.", e); | |
| 156 | 154 | } |
| 157 | 155 | } |
| 158 | 156 | |
| @@ -170,7 +168,6 @@ | ||
| 170 | 168 | * |
| 171 | 169 | * @param pagingState The byte array representation. |
| 172 | 170 | * @return the PagingState object created. |
| 173 | - * | |
| 174 | 171 | * @throws PagingStateException if the byte array does not have the correct format. |
| 175 | 172 | */ |
| 176 | 173 | public static PagingState fromBytes(byte[] pagingState) { |
modified driver-core/src/main/java/com/datastax/driver/core/PerHostPercentileTracker.java +31 −33
| @@ -15,16 +15,7 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.util.Set; | |
| 19 | -import java.util.concurrent.ConcurrentMap; | |
| 20 | -import java.util.concurrent.ExecutionException; | |
| 21 | -import java.util.concurrent.TimeUnit; | |
| 22 | -import java.util.concurrent.TimeoutException; | |
| 23 | - | |
| 24 | -import static java.util.concurrent.TimeUnit.MILLISECONDS; | |
| 25 | -import static java.util.concurrent.TimeUnit.MINUTES; | |
| 26 | -import static java.util.concurrent.TimeUnit.NANOSECONDS; | |
| 27 | - | |
| 18 | +import com.datastax.driver.core.exceptions.*; | |
| 28 | 19 | import com.google.common.annotations.Beta; |
| 29 | 20 | import com.google.common.collect.ImmutableSet; |
| 30 | 21 | import com.google.common.collect.MapMaker; |
| @@ -36,14 +27,19 @@ | ||
| 36 | 27 | import org.slf4j.Logger; |
| 37 | 28 | import org.slf4j.LoggerFactory; |
| 38 | 29 | |
| 39 | -import static com.google.common.base.Preconditions.checkArgument; | |
| 30 | +import java.util.Set; | |
| 31 | +import java.util.concurrent.ConcurrentMap; | |
| 32 | +import java.util.concurrent.ExecutionException; | |
| 33 | +import java.util.concurrent.TimeUnit; | |
| 34 | +import java.util.concurrent.TimeoutException; | |
| 40 | 35 | |
| 41 | -import com.datastax.driver.core.exceptions.*; | |
| 36 | +import static com.google.common.base.Preconditions.checkArgument; | |
| 37 | +import static java.util.concurrent.TimeUnit.*; | |
| 42 | 38 | |
| 43 | 39 | /** |
| 44 | 40 | * A {@link LatencyTracker} that records latencies for each host over a sliding time interval, and exposes an |
| 45 | 41 | * API to retrieve the latency at a given percentile. |
| 46 | - * <p> | |
| 42 | + * <p/> | |
| 47 | 43 | * To use this class, build an instance with {@link #builderWithHighestTrackableLatencyMillis(long)} and register |
| 48 | 44 | * it with your {@link com.datastax.driver.core.Cluster} instance: |
| 49 | 45 | * <pre> |
| @@ -55,13 +51,13 @@ | ||
| 55 | 51 | * ... |
| 56 | 52 | * tracker.getLatencyAtPercentile(host1, 99.0); |
| 57 | 53 | * </pre> |
| 58 | - * <p> | |
| 54 | + * <p/> | |
| 59 | 55 | * This class uses <a href="http://hdrhistogram.github.io/HdrHistogram/">HdrHistogram</a> to record latencies: |
| 60 | 56 | * for each host, there is a "live" histogram where current latencies are recorded, and a "cached", read-only histogram |
| 61 | 57 | * that is used when clients call {@link #getLatencyAtPercentile(Host, double)}. Each time the cached histogram becomes |
| 62 | 58 | * older than the interval, the two histograms are switched. Note that statistics will not be available during the first |
| 63 | 59 | * interval at cluster startup, since we don't have a cached histogram yet. |
| 64 | - * <p> | |
| 60 | + * <p/> | |
| 65 | 61 | * Note that this class is currently marked "beta": it hasn't been extensively tested yet, and the API is still subject |
| 66 | 62 | * to change. |
| 67 | 63 | */ |
| @@ -117,9 +113,9 @@ | ||
| 117 | 113 | /** |
| 118 | 114 | * Sets the number of significant decimal digits to which histograms will maintain value |
| 119 | 115 | * resolution and separation. This must be an integer between 0 and 5. |
| 120 | - * <p> | |
| 116 | + * <p/> | |
| 121 | 117 | * If not set explicitly, this value defaults to 3. |
| 122 | - * <p> | |
| 118 | + * <p/> | |
| 123 | 119 | * See <a href="http://hdrhistogram.github.io/HdrHistogram/JavaDoc/org/HdrHistogram/Histogram.html">the HdrHistogram Javadocs</a> |
| 124 | 120 | * for a more detailed explanation on how this parameter affects the resolution of recorded samples. |
| 125 | 121 | * |
| @@ -134,11 +130,11 @@ | ||
| 134 | 130 | /** |
| 135 | 131 | * Sets the minimum number of values that must be recorded for a host before we consider |
| 136 | 132 | * the sample size significant. |
| 137 | - * <p> | |
| 133 | + * <p/> | |
| 138 | 134 | * If this count is not reached during a given interval, {@link #getLatencyAtPercentile(Host, double)} |
| 139 | 135 | * will return a negative value, indicating that statistics are not available. In particular, this is true |
| 140 | 136 | * during the first interval. |
| 141 | - * <p> | |
| 137 | + * <p/> | |
| 142 | 138 | * If not set explicitly, this value default to 1000. |
| 143 | 139 | * |
| 144 | 140 | * @param minRecordedValues the new value. |
| @@ -151,9 +147,9 @@ | ||
| 151 | 147 | |
| 152 | 148 | /** |
| 153 | 149 | * Sets the number of distinct hosts that the driver will ever connect to. |
| 154 | - * <p> | |
| 150 | + * <p/> | |
| 155 | 151 | * This parameter is only used to pre-size internal maps in order to avoid unnecessary rehashing. |
| 156 | - * <p> | |
| 152 | + * <p/> | |
| 157 | 153 | * If not set explicitly, this value defaults to 16. |
| 158 | 154 | * |
| 159 | 155 | * @param numberOfHosts the new value. |
| @@ -166,16 +162,16 @@ | ||
| 166 | 162 | |
| 167 | 163 | /** |
| 168 | 164 | * Sets the time interval over which samples are recorded. |
| 169 | - * <p> | |
| 165 | + * <p/> | |
| 170 | 166 | * For each host, there is a "live" histogram where current latencies are recorded, and a "cached", read-only histogram |
| 171 | 167 | * that is used when clients call {@link #getLatencyAtPercentile(Host, double)}. Each time the cached histogram becomes |
| 172 | 168 | * older than the interval, the two histograms are switched. Note that statistics will not be available during the first |
| 173 | 169 | * interval at cluster startup, since we don't have a cached histogram yet. |
| 174 | - * <p> | |
| 170 | + * <p/> | |
| 175 | 171 | * If not set explicitly, this value defaults to 5 minutes. |
| 176 | 172 | * |
| 177 | 173 | * @param interval the new interval. |
| 178 | - * @param unit the unit that the interval is expressed in. | |
| 174 | + * @param unit the unit that the interval is expressed in. | |
| 179 | 175 | * @return this builder. |
| 180 | 176 | */ |
| 181 | 177 | public Builder withInterval(long interval, TimeUnit unit) { |
| @@ -203,20 +199,20 @@ | ||
| 203 | 199 | getRecorder(host).recordValue(latencyMs); |
| 204 | 200 | } catch (ArrayIndexOutOfBoundsException e) { |
| 205 | 201 | logger.warn("Got request with latency of {} ms, which exceeds the configured maximum trackable value {}", |
| 206 | - latencyMs, highestTrackableLatencyMillis); | |
| 202 | + latencyMs, highestTrackableLatencyMillis); | |
| 207 | 203 | } |
| 208 | 204 | } |
| 209 | 205 | |
| 210 | 206 | /** |
| 211 | 207 | * Returns the request latency for a host at a given percentile. |
| 212 | 208 | * |
| 213 | - * @param host the host. | |
| 209 | + * @param host the host. | |
| 214 | 210 | * @param percentile the percentile (for example, {@code 99.0} for the 99th percentile). |
| 215 | 211 | * @return the latency (in milliseconds) at the given percentile, or a negative value if it's not available yet. |
| 216 | 212 | */ |
| 217 | 213 | public long getLatencyAtPercentile(Host host, double percentile) { |
| 218 | 214 | checkArgument(percentile >= 0.0 && percentile < 100, |
| 219 | - "percentile must be between 0.0 and 100 (was %f)"); | |
| 215 | + "percentile must be between 0.0 and 100 (was %f)"); | |
| 220 | 216 | Histogram histogram = getLastIntervalHistogram(host); |
| 221 | 217 | if (histogram == null || histogram.getTotalCount() < minRecordedValues) |
| 222 | 218 | return -1; |
| @@ -240,7 +236,9 @@ | ||
| 240 | 236 | return recorder; |
| 241 | 237 | } |
| 242 | 238 | |
| 243 | - /** @return null if no histogram is available yet (no entries recorded, or not for long enough) */ | |
| 239 | + /** | |
| 240 | + * @return null if no histogram is available yet (no entries recorded, or not for long enough) | |
| 241 | + */ | |
| 244 | 242 | private Histogram getLastIntervalHistogram(Host host) { |
| 245 | 243 | try { |
| 246 | 244 | while (true) { |
| @@ -308,10 +306,10 @@ | ||
| 308 | 306 | * and tend to make the host's score look better than it actually is. |
| 309 | 307 | */ |
| 310 | 308 | private static final Set<Class<? extends Exception>> EXCLUDED_EXCEPTIONS = ImmutableSet.<Class<? extends Exception>>of( |
| 311 | - UnavailableException.class, // this is done via the snitch and is usually very fast | |
| 312 | - OverloadedException.class, | |
| 313 | - BootstrappingException.class, | |
| 314 | - UnpreparedException.class, | |
| 315 | - QueryValidationException.class // query validation also happens at early stages in the coordinator | |
| 309 | + UnavailableException.class, // this is done via the snitch and is usually very fast | |
| 310 | + OverloadedException.class, | |
| 311 | + BootstrappingException.class, | |
| 312 | + UnpreparedException.class, | |
| 313 | + QueryValidationException.class // query validation also happens at early stages in the coordinator | |
| 316 | 314 | ); |
| 317 | 315 | } |
modified driver-core/src/main/java/com/datastax/driver/core/PlainTextAuthProvider.java +8 −7
| @@ -15,15 +15,15 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.net.InetSocketAddress; | |
| 19 | -import java.util.Map; | |
| 20 | - | |
| 21 | 18 | import com.google.common.base.Charsets; |
| 22 | 19 | import com.google.common.collect.ImmutableMap; |
| 23 | 20 | |
| 21 | +import java.net.InetSocketAddress; | |
| 22 | +import java.util.Map; | |
| 23 | + | |
| 24 | 24 | /** |
| 25 | 25 | * A simple {@code AuthProvider} implementation. |
| 26 | - * <p> | |
| 26 | + * <p/> | |
| 27 | 27 | * This provider allows to programmatically define authentication |
| 28 | 28 | * information that will then apply to all hosts. The |
| 29 | 29 | * PlainTextAuthenticator instances it returns support SASL |
| @@ -38,6 +38,7 @@ | ||
| 38 | 38 | /** |
| 39 | 39 | * Creates a new simple authentication information provider with the |
| 40 | 40 | * supplied credentials. |
| 41 | + * | |
| 41 | 42 | * @param username to use for authentication requests |
| 42 | 43 | * @param password to use for authentication requests |
| 43 | 44 | */ |
| @@ -48,7 +49,7 @@ | ||
| 48 | 49 | |
| 49 | 50 | /** |
| 50 | 51 | * Changes the user name. |
| 51 | - * | |
| 52 | + * <p/> | |
| 52 | 53 | * The new credentials will be used for all connections initiated after this method was called. |
| 53 | 54 | * |
| 54 | 55 | * @param username the new name. |
| @@ -59,7 +60,7 @@ | ||
| 59 | 60 | |
| 60 | 61 | /** |
| 61 | 62 | * Changes the password. |
| 62 | - * | |
| 63 | + * <p/> | |
| 63 | 64 | * The new credentials will be used for all connections initiated after this method was called. |
| 64 | 65 | * |
| 65 | 66 | * @param password the new password. |
| @@ -117,7 +118,7 @@ | ||
| 117 | 118 | |
| 118 | 119 | Map<String, String> getCredentials() { |
| 119 | 120 | return ImmutableMap.of("username", new String(username, Charsets.UTF_8), |
| 120 | - "password", new String(password, Charsets.UTF_8)); | |
| 121 | + "password", new String(password, Charsets.UTF_8)); | |
| 121 | 122 | } |
| 122 | 123 | } |
| 123 | 124 | } |
modified driver-core/src/main/java/com/datastax/driver/core/PoolingOptions.java +43 −55
| @@ -15,20 +15,20 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.util.concurrent.Executor; | |
| 19 | - | |
| 20 | 18 | import com.google.common.base.Preconditions; |
| 21 | 19 | import com.google.common.util.concurrent.MoreExecutors; |
| 22 | 20 | |
| 21 | +import java.util.concurrent.Executor; | |
| 22 | + | |
| 23 | 23 | /** |
| 24 | 24 | * Options related to connection pooling. |
| 25 | - * <p> | |
| 25 | + * <p/> | |
| 26 | 26 | * The driver uses connections in an asynchronous manner. Meaning that |
| 27 | 27 | * multiple requests can be submitted on the same connection at the same |
| 28 | 28 | * time. This means that the driver only needs to maintain a relatively |
| 29 | 29 | * small number of connections to each Cassandra host. These options allow |
| 30 | 30 | * the driver to control how many connections are kept exactly. |
| 31 | - * <p> | |
| 31 | + * <p/> | |
| 32 | 32 | * For each host, the driver keeps a core pool of connections open at all |
| 33 | 33 | * times determined by calling ({@link #getCoreConnectionsPerHost}). |
| 34 | 34 | * If the use of those connections reaches a configurable threshold |
| @@ -37,7 +37,7 @@ | ||
| 37 | 37 | * connections ({@link #getMaxConnectionsPerHost}). When the pool exceeds |
| 38 | 38 | * the maximum number of connections, connections in excess are |
| 39 | 39 | * reclaimed. |
| 40 | - * <p> | |
| 40 | + * <p/> | |
| 41 | 41 | * Each of these parameters can be separately set for {@code LOCAL} and |
| 42 | 42 | * {@code REMOTE} hosts ({@link HostDistance}). For {@code IGNORED} hosts, |
| 43 | 43 | * the default for all those settings is 0 and cannot be changed. |
| @@ -62,10 +62,10 @@ | ||
| 62 | 62 | |
| 63 | 63 | private volatile Cluster.Manager manager; |
| 64 | 64 | |
| 65 | - private final int[] maxSimultaneousRequests = new int[]{ DEFAULT_MAX_REQUESTS, DEFAULT_MAX_REQUESTS, 0 }; | |
| 65 | + private final int[] maxSimultaneousRequests = new int[]{DEFAULT_MAX_REQUESTS, DEFAULT_MAX_REQUESTS, 0}; | |
| 66 | 66 | |
| 67 | - private final int[] coreConnections = new int[] { DEFAULT_CORE_POOL_LOCAL, DEFAULT_CORE_POOL_REMOTE, 0 }; | |
| 68 | - private final int[] maxConnections = new int[] { DEFAULT_MAX_POOL_LOCAL , DEFAULT_MAX_POOL_REMOTE, 0 }; | |
| 67 | + private final int[] coreConnections = new int[]{DEFAULT_CORE_POOL_LOCAL, DEFAULT_CORE_POOL_REMOTE, 0}; | |
| 68 | + private final int[] maxConnections = new int[]{DEFAULT_MAX_POOL_LOCAL, DEFAULT_MAX_POOL_REMOTE, 0}; | |
| 69 | 69 | |
| 70 | 70 | private volatile int idleTimeoutSeconds = DEFAULT_IDLE_TIMEOUT_SECONDS; |
| 71 | 71 | private volatile int poolTimeoutMillis = DEFAULT_POOL_TIMEOUT_MILLIS; |
| @@ -73,7 +73,8 @@ | ||
| 73 | 73 | |
| 74 | 74 | private volatile Executor initializationExecutor = DEFAULT_INITIALIZATION_EXECUTOR; |
| 75 | 75 | |
| 76 | - public PoolingOptions() {} | |
| 76 | + public PoolingOptions() { | |
| 77 | + } | |
| 77 | 78 | |
| 78 | 79 | void register(Cluster.Manager manager) { |
| 79 | 80 | this.manager = manager; |
| @@ -82,18 +83,17 @@ | ||
| 82 | 83 | /** |
| 83 | 84 | * Returns the number of simultaneous requests on a connection below which |
| 84 | 85 | * connections in excess are reclaimed. |
| 85 | - * <p> | |
| 86 | + * <p/> | |
| 86 | 87 | * If an opened connection to an host at distance {@code distance} |
| 87 | 88 | * handles less than this number of simultaneous requests and there is |
| 88 | 89 | * more than {@link #getCoreConnectionsPerHost} connections open to this |
| 89 | 90 | * host, the connection is closed. |
| 90 | - * <p> | |
| 91 | + * <p/> | |
| 91 | 92 | * The default value for this option is 25 for {@code LOCAL} and |
| 92 | 93 | * {@code REMOTE} hosts. |
| 93 | 94 | * |
| 94 | 95 | * @param distance the {@code HostDistance} for which to return this threshold. |
| 95 | 96 | * @return the configured threshold, or the default one if none have been set. |
| 96 | - * | |
| 97 | 97 | * @deprecated this option isn't used anymore with the current pool resizing algorithm. |
| 98 | 98 | */ |
| 99 | 99 | @Deprecated |
| @@ -105,13 +105,11 @@ | ||
| 105 | 105 | * Sets the number of simultaneous requests on a connection below which |
| 106 | 106 | * connections in excess are reclaimed. |
| 107 | 107 | * |
| 108 | - * @param distance the {@code HostDistance} for which to configure this threshold. | |
| 108 | + * @param distance the {@code HostDistance} for which to configure this threshold. | |
| 109 | 109 | * @param newMinSimultaneousRequests the value to set (between 0 and 128). |
| 110 | 110 | * @return this {@code PoolingOptions}. |
| 111 | - * | |
| 112 | 111 | * @throws IllegalArgumentException if {@code distance == HostDistance.IGNORED}, or if {@code minSimultaneousRequests} |
| 113 | - * is not in range, or if {@code newMinSimultaneousRequests} is greater than the maximum value for this distance. | |
| 114 | - * | |
| 112 | + * is not in range, or if {@code newMinSimultaneousRequests} is greater than the maximum value for this distance. | |
| 115 | 113 | * @deprecated this option isn't used anymore with the current pool resizing algorithm. |
| 116 | 114 | */ |
| 117 | 115 | @Deprecated |
| @@ -122,16 +120,16 @@ | ||
| 122 | 120 | /** |
| 123 | 121 | * Returns the number of simultaneous requests on all connections to an host after |
| 124 | 122 | * which more connections are created. |
| 125 | - * <p> | |
| 123 | + * <p/> | |
| 126 | 124 | * If all the connections opened to an host at distance {@code |
| 127 | 125 | * distance} connection are handling more than this number of |
| 128 | 126 | * simultaneous requests and there is less than |
| 129 | 127 | * {@link #getMaxConnectionsPerHost} connections open to this host, a |
| 130 | 128 | * new connection is open. |
| 131 | - * <p> | |
| 129 | + * <p/> | |
| 132 | 130 | * Note that a given connection cannot handle more than 128 |
| 133 | 131 | * simultaneous requests (protocol limitation). |
| 134 | - * <p> | |
| 132 | + * <p/> | |
| 135 | 133 | * The default value for this option is 100 for {@code LOCAL} and |
| 136 | 134 | * {@code REMOTE} hosts. |
| 137 | 135 | * |
| @@ -146,12 +144,11 @@ | ||
| 146 | 144 | * Sets number of simultaneous requests on all connections to an host after |
| 147 | 145 | * which more connections are created. |
| 148 | 146 | * |
| 149 | - * @param distance the {@code HostDistance} for which to configure this threshold. | |
| 147 | + * @param distance the {@code HostDistance} for which to configure this threshold. | |
| 150 | 148 | * @param newMaxSimultaneousRequests the value to set (between 0 and 128). |
| 151 | 149 | * @return this {@code PoolingOptions}. |
| 152 | - * | |
| 153 | 150 | * @throws IllegalArgumentException if {@code distance == HostDistance.IGNORED}, or if {@code maxSimultaneousRequests} |
| 154 | - * is not in range, or if {@code newMaxSimultaneousRequests} is less than the minimum value for this distance. | |
| 151 | + * is not in range, or if {@code newMaxSimultaneousRequests} is less than the minimum value for this distance. | |
| 155 | 152 | */ |
| 156 | 153 | public synchronized PoolingOptions setMaxSimultaneousRequestsPerConnectionThreshold(HostDistance distance, int newMaxSimultaneousRequests) { |
| 157 | 154 | if (distance == HostDistance.IGNORED) |
| @@ -164,7 +161,7 @@ | ||
| 164 | 161 | |
| 165 | 162 | /** |
| 166 | 163 | * Returns the core number of connections per host. |
| 167 | - * <p> | |
| 164 | + * <p/> | |
| 168 | 165 | * For the provided {@code distance}, this correspond to the number of |
| 169 | 166 | * connections initially created and kept open to each host of that |
| 170 | 167 | * distance. |
| @@ -179,18 +176,16 @@ | ||
| 179 | 176 | /** |
| 180 | 177 | * Sets the core number of connections per host. |
| 181 | 178 | * |
| 182 | - * @param distance the {@code HostDistance} for which to set this threshold. | |
| 179 | + * @param distance the {@code HostDistance} for which to set this threshold. | |
| 183 | 180 | * @param newCoreConnections the value to set |
| 184 | 181 | * @return this {@code PoolingOptions}. |
| 185 | - * | |
| 186 | 182 | * @throws IllegalArgumentException if {@code distance == HostDistance.IGNORED}, |
| 187 | - * or if {@code newCoreConnections} is greater than the maximum value for this distance. | |
| 188 | - * | |
| 183 | + * or if {@code newCoreConnections} is greater than the maximum value for this distance. | |
| 189 | 184 | * @see #setConnectionsPerHost(HostDistance, int, int) |
| 190 | 185 | */ |
| 191 | 186 | public synchronized PoolingOptions setCoreConnectionsPerHost(HostDistance distance, int newCoreConnections) { |
| 192 | 187 | if (distance == HostDistance.IGNORED) |
| 193 | - throw new IllegalArgumentException("Cannot set core connections per host for " + distance + " hosts"); | |
| 188 | + throw new IllegalArgumentException("Cannot set core connections per host for " + distance + " hosts"); | |
| 194 | 189 | |
| 195 | 190 | checkConnectionsPerHostOrder(newCoreConnections, maxConnections[distance.ordinal()], distance); |
| 196 | 191 | int oldCore = coreConnections[distance.ordinal()]; |
| @@ -202,7 +197,7 @@ | ||
| 202 | 197 | |
| 203 | 198 | /** |
| 204 | 199 | * Returns the maximum number of connections per host. |
| 205 | - * <p> | |
| 200 | + * <p/> | |
| 206 | 201 | * For the provided {@code distance}, this correspond to the maximum |
| 207 | 202 | * number of connections that can be created per host at that distance. |
| 208 | 203 | * |
| @@ -216,13 +211,11 @@ | ||
| 216 | 211 | /** |
| 217 | 212 | * Sets the maximum number of connections per host. |
| 218 | 213 | * |
| 219 | - * @param distance the {@code HostDistance} for which to set this threshold. | |
| 214 | + * @param distance the {@code HostDistance} for which to set this threshold. | |
| 220 | 215 | * @param newMaxConnections the value to set |
| 221 | 216 | * @return this {@code PoolingOptions}. |
| 222 | - * | |
| 223 | 217 | * @throws IllegalArgumentException if {@code distance == HostDistance.IGNORED}, |
| 224 | - * or if {@code newMaxConnections} is less than the core value for this distance. | |
| 225 | - * | |
| 218 | + * or if {@code newMaxConnections} is less than the core value for this distance. | |
| 226 | 219 | * @see #setConnectionsPerHost(HostDistance, int, int) |
| 227 | 220 | */ |
| 228 | 221 | public synchronized PoolingOptions setMaxConnectionsPerHost(HostDistance distance, int newMaxConnections) { |
| @@ -236,17 +229,16 @@ | ||
| 236 | 229 | |
| 237 | 230 | /** |
| 238 | 231 | * Sets the core and maximum number of connections per host in one call. |
| 239 | - * <p> | |
| 232 | + * <p/> | |
| 240 | 233 | * This is a convenience method that is equivalent to calling {@link #setCoreConnectionsPerHost(HostDistance, int)} |
| 241 | 234 | * and {@link #setMaxConnectionsPerHost(HostDistance, int)}. |
| 242 | 235 | * |
| 243 | 236 | * @param distance the {@code HostDistance} for which to set these threshold. |
| 244 | - * @param core the core number of connections. | |
| 245 | - * @param max the max number of connections. | |
| 237 | + * @param core the core number of connections. | |
| 238 | + * @param max the max number of connections. | |
| 246 | 239 | * @return this {@code PoolingOptions}. |
| 247 | - * | |
| 248 | 240 | * @throws IllegalArgumentException if {@code distance == HostDistance.IGNORED}, |
| 249 | - * or if {@code core} > {@code max}. | |
| 241 | + * or if {@code core} > {@code max}. | |
| 250 | 242 | */ |
| 251 | 243 | public synchronized PoolingOptions setConnectionsPerHost(HostDistance distance, int core, int max) { |
| 252 | 244 | if (distance == HostDistance.IGNORED) |
| @@ -269,13 +261,12 @@ | ||
| 269 | 261 | |
| 270 | 262 | /** |
| 271 | 263 | * Sets the timeout before an idle connection is removed. |
| 272 | - * <p> | |
| 264 | + * <p/> | |
| 273 | 265 | * The order of magnitude should be a few minutes (the default is 120 seconds). The |
| 274 | 266 | * timeout that triggers the removal has a granularity of 10 seconds. |
| 275 | 267 | * |
| 276 | 268 | * @param idleTimeoutSeconds the new timeout in seconds. |
| 277 | 269 | * @return this {@code PoolingOptions}. |
| 278 | - * | |
| 279 | 270 | * @throws IllegalArgumentException if the timeout is negative. |
| 280 | 271 | */ |
| 281 | 272 | public PoolingOptions setIdleTimeoutSeconds(int idleTimeoutSeconds) { |
| @@ -296,15 +287,14 @@ | ||
| 296 | 287 | |
| 297 | 288 | /** |
| 298 | 289 | * Sets the timeout when trying to acquire a connection from a host's pool. |
| 299 | - * <p> | |
| 290 | + * <p/> | |
| 300 | 291 | * If no connection is available within that time, the driver will try the |
| 301 | 292 | * next host from the query plan. |
| 302 | - * <p> | |
| 293 | + * <p/> | |
| 303 | 294 | * If this option is set to zero, the driver won't wait at all. |
| 304 | 295 | * |
| 305 | 296 | * @param poolTimeoutMillis the new value in milliseconds. |
| 306 | 297 | * @return this {@code PoolingOptions} |
| 307 | - * | |
| 308 | 298 | * @throws IllegalArgumentException if the timeout is negative. |
| 309 | 299 | */ |
| 310 | 300 | public PoolingOptions setPoolTimeoutMillis(int poolTimeoutMillis) { |
| @@ -316,6 +306,7 @@ | ||
| 316 | 306 | |
| 317 | 307 | /** |
| 318 | 308 | * Returns the heart beat interval, after which a message is sent on an idle connection to make sure it's still alive. |
| 309 | + * | |
| 319 | 310 | * @return the interval. |
| 320 | 311 | */ |
| 321 | 312 | public int getHeartbeatIntervalSeconds() { |
| @@ -324,17 +315,16 @@ | ||
| 324 | 315 | |
| 325 | 316 | /** |
| 326 | 317 | * Sets the heart beat interval, after which a message is sent on an idle connection to make sure it's still alive. |
| 327 | - * <p> | |
| 318 | + * <p/> | |
| 328 | 319 | * This is an application-level keep-alive, provided for convenience since adjusting the TCP keep-alive might not be |
| 329 | 320 | * practical in all environments. |
| 330 | - * <p> | |
| 321 | + * <p/> | |
| 331 | 322 | * This option should be set higher than {@link SocketOptions#getReadTimeoutMillis()}. |
| 332 | - * <p> | |
| 323 | + * <p/> | |
| 333 | 324 | * The default value for this option is 30 seconds. |
| 334 | 325 | * |
| 335 | 326 | * @param heartbeatIntervalSeconds the new value in seconds. If set to 0, it will disable the feature. |
| 336 | 327 | * @return this {@code PoolingOptions} |
| 337 | - * | |
| 338 | 328 | * @throws IllegalArgumentException if the interval is negative. |
| 339 | 329 | */ |
| 340 | 330 | public PoolingOptions setHeartbeatIntervalSeconds(int heartbeatIntervalSeconds) { |
| @@ -357,11 +347,11 @@ | ||
| 357 | 347 | |
| 358 | 348 | /** |
| 359 | 349 | * Sets the executor to use for connection initialization. |
| 360 | - * <p> | |
| 350 | + * <p/> | |
| 361 | 351 | * Connections are open in a completely asynchronous manner. Since initializing the transport |
| 362 | 352 | * requires separate CQL queries, the futures representing the completion of these queries are |
| 363 | 353 | * transformed and chained. This executor is where these transformations happen. |
| 364 | - * <p> | |
| 354 | + * <p/> | |
| 365 | 355 | * <b>This is an advanced option, which should be rarely needed in practice.</b> It defaults to |
| 366 | 356 | * Guava's {@code MoreExecutors.sameThreadExecutor()}, which results in running the transformations |
| 367 | 357 | * on the network I/O threads; this is fine if the transformations are fast and not I/O bound |
| @@ -372,7 +362,6 @@ | ||
| 372 | 362 | * |
| 373 | 363 | * @param initializationExecutor the executor to use |
| 374 | 364 | * @return this {@code PoolingOptions} |
| 375 | - * | |
| 376 | 365 | * @throws java.lang.NullPointerException if the executor is null |
| 377 | 366 | */ |
| 378 | 367 | public PoolingOptions setInitializationExecutor(Executor initializationExecutor) { |
| @@ -385,7 +374,7 @@ | ||
| 385 | 374 | * Requests the driver to re-evaluate the {@link HostDistance} (through the configured |
| 386 | 375 | * {@link com.datastax.driver.core.policies.LoadBalancingPolicy#distance}) for every known |
| 387 | 376 | * hosts and to drop/add connections to each hosts according to the computed distance. |
| 388 | - * <p> | |
| 377 | + * <p/> | |
| 389 | 378 | * Note that, due to backward compatibility issues, this method is not interruptible. If the |
| 390 | 379 | * caller thread gets interrupted, the method will complete and only then re-interrupt the |
| 391 | 380 | * thread (which you can check with {@code Thread.currentThread().isInterrupted()}). |
| @@ -398,7 +387,6 @@ | ||
| 398 | 387 | * Requests the driver to re-evaluate the {@link HostDistance} for a given node. |
| 399 | 388 | * |
| 400 | 389 | * @param host the host to refresh. |
| 401 | - * | |
| 402 | 390 | * @see #refreshConnectedHosts() |
| 403 | 391 | */ |
| 404 | 392 | public void refreshConnectedHost(Host host) { |
| @@ -408,13 +396,13 @@ | ||
| 408 | 396 | private static void checkRequestsPerConnectionRange(int value, String description, HostDistance distance) { |
| 409 | 397 | if (value < 0 || value > StreamIdGenerator.MAX_STREAM_PER_CONNECTION) |
| 410 | 398 | throw new IllegalArgumentException(String.format("%s for %s hosts must be in the range (0, %d)", |
| 411 | - description, distance, | |
| 412 | - StreamIdGenerator.MAX_STREAM_PER_CONNECTION)); | |
| 399 | + description, distance, | |
| 400 | + StreamIdGenerator.MAX_STREAM_PER_CONNECTION)); | |
| 413 | 401 | } |
| 414 | 402 | |
| 415 | 403 | private static void checkConnectionsPerHostOrder(int core, int max, HostDistance distance) { |
| 416 | 404 | if (core > max) |
| 417 | 405 | throw new IllegalArgumentException(String.format("Core connections for %s hosts must be less than max (%d > %d)", |
| 418 | - distance, core, max)); | |
| 406 | + distance, core, max)); | |
| 419 | 407 | } |
| 420 | 408 | } |
modified driver-core/src/main/java/com/datastax/driver/core/PreparedId.java +2 −4
| @@ -18,8 +18,7 @@ | ||
| 18 | 18 | /** |
| 19 | 19 | * Identifies a PreparedStatement. |
| 20 | 20 | */ |
| 21 | -public class PreparedId | |
| 22 | -{ | |
| 21 | +public class PreparedId { | |
| 23 | 22 | // This class is mostly here to group PreparedStatement data that are need for |
| 24 | 23 | // execution but that we don't want to expose publicly (see JAVA-195) |
| 25 | 24 | final MD5Digest id; |
| @@ -29,8 +28,7 @@ | ||
| 29 | 28 | |
| 30 | 29 | final int[] routingKeyIndexes; |
| 31 | 30 | |
| 32 | - PreparedId(MD5Digest id, ColumnDefinitions metadata, ColumnDefinitions resultSetMetadata, int[] routingKeyIndexes) | |
| 33 | - { | |
| 31 | + PreparedId(MD5Digest id, ColumnDefinitions metadata, ColumnDefinitions resultSetMetadata, int[] routingKeyIndexes) { | |
| 34 | 32 | this.id = id; |
| 35 | 33 | this.metadata = metadata; |
| 36 | 34 | this.resultSetMetadata = resultSetMetadata; |
modified driver-core/src/main/java/com/datastax/driver/core/PreparedStatement.java +26 −31
| @@ -15,20 +15,20 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.nio.ByteBuffer; | |
| 19 | - | |
| 20 | 18 | import com.datastax.driver.core.exceptions.InvalidTypeException; |
| 21 | 19 | import com.datastax.driver.core.policies.RetryPolicy; |
| 22 | 20 | |
| 21 | +import java.nio.ByteBuffer; | |
| 22 | + | |
| 23 | 23 | /** |
| 24 | 24 | * Represents a prepared statement, a query with bound variables that has been |
| 25 | 25 | * prepared (pre-parsed) by the database. |
| 26 | - * <p> | |
| 26 | + * <p/> | |
| 27 | 27 | * A prepared statement can be executed once concrete values have been provided |
| 28 | 28 | * for the bound variables. A prepared statement and the values for its |
| 29 | 29 | * bound variables constitute a BoundStatement and can be executed (by |
| 30 | 30 | * {@link Session#execute}). |
| 31 | - * <p> | |
| 31 | + * <p/> | |
| 32 | 32 | * A {@code PreparedStatement} object allows you to define specific defaults |
| 33 | 33 | * for the different properties of a {@link Statement} (Consistency level, tracing, ...), |
| 34 | 34 | * in which case those properties will be inherited as default by every |
| @@ -50,35 +50,33 @@ | ||
| 50 | 50 | /** |
| 51 | 51 | * Creates a new BoundStatement object and bind its variables to the |
| 52 | 52 | * provided values. |
| 53 | - * <p> | |
| 53 | + * <p/> | |
| 54 | 54 | * While the number of {@code values} cannot be greater than the number of bound |
| 55 | 55 | * variables, the number of {@code values} may be fewer than the number of bound |
| 56 | 56 | * variables. In that case, the remaining variables will have to be bound |
| 57 | 57 | * to values by another mean because the resulting {@code BoundStatement} |
| 58 | 58 | * being executable. |
| 59 | - * <p> | |
| 59 | + * <p/> | |
| 60 | 60 | * This method is a convenience for {@code new BoundStatement(this).bind(...)}. |
| 61 | 61 | * |
| 62 | 62 | * @param values the values to bind to the variables of the newly created |
| 63 | - * BoundStatement. | |
| 63 | + * BoundStatement. | |
| 64 | 64 | * @return the newly created {@code BoundStatement} with its variables |
| 65 | 65 | * bound to {@code values}. |
| 66 | - * | |
| 67 | 66 | * @throws IllegalArgumentException if more {@code values} are provided |
| 68 | - * than there is of bound variables in this statement. | |
| 69 | - * @throws InvalidTypeException if any of the provided value is not of | |
| 70 | - * correct type to be bound to the corresponding bind variable. | |
| 71 | - * @throws NullPointerException if one of {@code values} is a collection | |
| 72 | - * (List, Set or Map) containing a null value. Nulls are not supported in | |
| 73 | - * collections by CQL. | |
| 74 | - * | |
| 67 | + * than there is of bound variables in this statement. | |
| 68 | + * @throws InvalidTypeException if any of the provided value is not of | |
| 69 | + * correct type to be bound to the corresponding bind variable. | |
| 70 | + * @throws NullPointerException if one of {@code values} is a collection | |
| 71 | + * (List, Set or Map) containing a null value. Nulls are not supported in | |
| 72 | + * collections by CQL. | |
| 75 | 73 | * @see BoundStatement#bind |
| 76 | 74 | */ |
| 77 | 75 | public BoundStatement bind(Object... values); |
| 78 | 76 | |
| 79 | 77 | /** |
| 80 | 78 | * Creates a new BoundStatement object for this prepared statement. |
| 81 | - * <p> | |
| 79 | + * <p/> | |
| 82 | 80 | * This method do not bind any values to any of the prepared variables. Said |
| 83 | 81 | * values need to be bound on the resulting statement using BoundStatement's |
| 84 | 82 | * setters methods ({@link BoundStatement#setInt}, {@link BoundStatement#setLong}, ...). |
| @@ -89,23 +87,22 @@ | ||
| 89 | 87 | |
| 90 | 88 | /** |
| 91 | 89 | * Sets the routing key for this prepared statement. |
| 92 | - * <p> | |
| 90 | + * <p/> | |
| 93 | 91 | * While you can provide a fixed routing key for all executions of this prepared |
| 94 | 92 | * statement with this method, it is not mandatory to provide |
| 95 | 93 | * one through this method. This method should only be used |
| 96 | 94 | * if the partition key of the prepared query is not part of the prepared |
| 97 | 95 | * variables (that is if the partition key is fixed). |
| 98 | - * <p> | |
| 96 | + * <p/> | |
| 99 | 97 | * Note that if the partition key is part of the prepared variables, the |
| 100 | 98 | * routing key will be automatically computed once those variables are bound. |
| 101 | - * <p> | |
| 99 | + * <p/> | |
| 102 | 100 | * If the partition key is neither fixed nor part of the prepared variables (e.g. |
| 103 | 101 | * a composite partition key where only some of the components are bound), the |
| 104 | 102 | * routing key can also be set on each bound statement. |
| 105 | 103 | * |
| 106 | 104 | * @param routingKey the raw (binary) value to use as routing key. |
| 107 | 105 | * @return this {@code PreparedStatement} object. |
| 108 | - * | |
| 109 | 106 | * @see Statement#getRoutingKey |
| 110 | 107 | * @see BoundStatement#getRoutingKey |
| 111 | 108 | */ |
| @@ -113,15 +110,14 @@ | ||
| 113 | 110 | |
| 114 | 111 | /** |
| 115 | 112 | * Sets the routing key for this query. |
| 116 | - * <p> | |
| 113 | + * <p/> | |
| 117 | 114 | * See {@link #setRoutingKey(ByteBuffer)} for more information. This |
| 118 | 115 | * method is a variant for when the query partition key is composite and |
| 119 | 116 | * the routing key must be built from multiple values. |
| 120 | 117 | * |
| 121 | 118 | * @param routingKeyComponents the raw (binary) values to compose to obtain |
| 122 | - * the routing key. | |
| 119 | + * the routing key. | |
| 123 | 120 | * @return this {@code PreparedStatement} object. |
| 124 | - * | |
| 125 | 121 | * @see Statement#getRoutingKey |
| 126 | 122 | */ |
| 127 | 123 | public PreparedStatement setRoutingKey(ByteBuffer... routingKeyComponents); |
| @@ -137,10 +133,10 @@ | ||
| 137 | 133 | /** |
| 138 | 134 | * Sets a default consistency level for all bound statements |
| 139 | 135 | * created from this prepared statement. |
| 140 | - * <p> | |
| 136 | + * <p/> | |
| 141 | 137 | * If no consistency level is set through this method, the bound statement |
| 142 | 138 | * created from this object will use the default consistency level (ONE). |
| 143 | - * <p> | |
| 139 | + * <p/> | |
| 144 | 140 | * Changing the default consistency level is not retroactive, it only |
| 145 | 141 | * applies to BoundStatement created after the change. |
| 146 | 142 | * |
| @@ -161,18 +157,17 @@ | ||
| 161 | 157 | /** |
| 162 | 158 | * Sets a default serial consistency level for all bound statements |
| 163 | 159 | * created from this prepared statement. |
| 164 | - * <p> | |
| 160 | + * <p/> | |
| 165 | 161 | * If no serial consistency level is set through this method, the bound statement |
| 166 | 162 | * created from this object will use the default serial consistency level (SERIAL). |
| 167 | - * <p> | |
| 163 | + * <p/> | |
| 168 | 164 | * Changing the default serial consistency level is not retroactive, it only |
| 169 | 165 | * applies to BoundStatement created after the change. |
| 170 | 166 | * |
| 171 | 167 | * @param serialConsistency the default serial consistency level to set. |
| 172 | 168 | * @return this {@code PreparedStatement} object. |
| 173 | - * | |
| 174 | 169 | * @throws IllegalArgumentException if {@code serialConsistency} is not one of |
| 175 | - * {@code ConsistencyLevel.SERIAL} or {@code ConsistencyLevel.LOCAL_SERIAL}. | |
| 170 | + * {@code ConsistencyLevel.SERIAL} or {@code ConsistencyLevel.LOCAL_SERIAL}. | |
| 176 | 171 | */ |
| 177 | 172 | public PreparedStatement setSerialConsistencyLevel(ConsistencyLevel serialConsistency); |
| 178 | 173 | |
| @@ -188,7 +183,7 @@ | ||
| 188 | 183 | /** |
| 189 | 184 | * Returns the string of the query that was prepared to yield this {@code |
| 190 | 185 | * PreparedStatement}. |
| 191 | - * <p> | |
| 186 | + * <p/> | |
| 192 | 187 | * Note that a CQL3 query may be implicitly applied to the current keyspace |
| 193 | 188 | * (that is, if the keyspace is not explicitly qualified in the query |
| 194 | 189 | * itself). For prepared queries, the current keyspace used is the one at |
| @@ -241,7 +236,7 @@ | ||
| 241 | 236 | /** |
| 242 | 237 | * Convenience method to set a default retry policy for the {@code BoundStatement} |
| 243 | 238 | * created from this prepared statement. |
| 244 | - * <p> | |
| 239 | + * <p/> | |
| 245 | 240 | * Note that this method is completely optional. By default, the retry policy |
| 246 | 241 | * used is the one returned {@link com.datastax.driver.core.policies.Policies#getRetryPolicy} |
| 247 | 242 | * in the cluster configuration. This method is only useful if you want |
modified driver-core/src/main/java/com/datastax/driver/core/ProtocolEvent.java +6 −6
| @@ -15,13 +15,13 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.net.InetSocketAddress; | |
| 19 | - | |
| 20 | 18 | import io.netty.buffer.ByteBuf; |
| 21 | 19 | |
| 20 | +import java.net.InetSocketAddress; | |
| 21 | + | |
| 22 | 22 | class ProtocolEvent { |
| 23 | 23 | |
| 24 | - public enum Type { TOPOLOGY_CHANGE, STATUS_CHANGE, SCHEMA_CHANGE } | |
| 24 | + public enum Type {TOPOLOGY_CHANGE, STATUS_CHANGE, SCHEMA_CHANGE} | |
| 25 | 25 | |
| 26 | 26 | public final Type type; |
| 27 | 27 | |
| @@ -42,7 +42,7 @@ | ||
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | public static class TopologyChange extends ProtocolEvent { |
| 45 | - public enum Change { NEW_NODE, REMOVED_NODE, MOVED_NODE } | |
| 45 | + public enum Change {NEW_NODE, REMOVED_NODE, MOVED_NODE} | |
| 46 | 46 | |
| 47 | 47 | public final Change change; |
| 48 | 48 | public final InetSocketAddress node; |
| @@ -68,7 +68,7 @@ | ||
| 68 | 68 | |
| 69 | 69 | public static class StatusChange extends ProtocolEvent { |
| 70 | 70 | |
| 71 | - public enum Status { UP, DOWN } | |
| 71 | + public enum Status {UP, DOWN} | |
| 72 | 72 | |
| 73 | 73 | public final Status status; |
| 74 | 74 | public final InetSocketAddress node; |
| @@ -94,7 +94,7 @@ | ||
| 94 | 94 | |
| 95 | 95 | public static class SchemaChange extends ProtocolEvent { |
| 96 | 96 | |
| 97 | - public enum Change { CREATED, UPDATED, DROPPED } | |
| 97 | + public enum Change {CREATED, UPDATED, DROPPED} | |
| 98 | 98 | |
| 99 | 99 | public final Change change; |
| 100 | 100 | public final String keyspace; |
modified driver-core/src/main/java/com/datastax/driver/core/ProtocolOptions.java +27 −20
| @@ -26,21 +26,27 @@ | ||
| 26 | 26 | * Compression supported by the Cassandra binary protocol. |
| 27 | 27 | */ |
| 28 | 28 | public enum Compression { |
| 29 | - /** No compression */ | |
| 29 | + /** | |
| 30 | + * No compression | |
| 31 | + */ | |
| 30 | 32 | NONE("") { |
| 31 | 33 | @Override |
| 32 | 34 | FrameCompressor compressor() { |
| 33 | 35 | return null; |
| 34 | 36 | } |
| 35 | 37 | }, |
| 36 | - /** Snappy compression */ | |
| 38 | + /** | |
| 39 | + * Snappy compression | |
| 40 | + */ | |
| 37 | 41 | SNAPPY("snappy") { |
| 38 | 42 | @Override |
| 39 | 43 | FrameCompressor compressor() { |
| 40 | 44 | return FrameCompressor.SnappyCompressor.instance; |
| 41 | 45 | } |
| 42 | 46 | }, |
| 43 | - /** LZ4 compression */ | |
| 47 | + /** | |
| 48 | + * LZ4 compression | |
| 49 | + */ | |
| 44 | 50 | LZ4("lz4") { |
| 45 | 51 | @Override |
| 46 | 52 | FrameCompressor compressor() { |
| @@ -68,7 +74,9 @@ | ||
| 68 | 74 | public String toString() { |
| 69 | 75 | return protocolName; |
| 70 | 76 | } |
| 71 | - }; | |
| 77 | + } | |
| 78 | + | |
| 79 | + ; | |
| 72 | 80 | |
| 73 | 81 | /** |
| 74 | 82 | * The default port for Cassandra native binary protocol: 9042. |
| @@ -104,7 +112,7 @@ | ||
| 104 | 112 | /** |
| 105 | 113 | * Creates a new {@code ProtocolOptions} instance using the provided port |
| 106 | 114 | * (without SSL nor authentication). |
| 107 | - * <p> | |
| 115 | + * <p/> | |
| 108 | 116 | * This is a shortcut for {@code new ProtocolOptions(port, null, AuthProvider.NONE)}. |
| 109 | 117 | * |
| 110 | 118 | * @param port the port to use for the binary protocol. |
| @@ -117,15 +125,15 @@ | ||
| 117 | 125 | * Creates a new {@code ProtocolOptions} instance using the provided port |
| 118 | 126 | * and SSL context. |
| 119 | 127 | * |
| 120 | - * @param port the port to use for the binary protocol. | |
| 128 | + * @param port the port to use for the binary protocol. | |
| 121 | 129 | * @param protocolVersion the protocol version to use. This can be a negative number, in which case the |
| 122 | - * version uses will be the biggest version supported by the <em>first</em> node the driver connects to. | |
| 123 | - * Otherwise, it must be either 1 or 2 to force using a particular protocol version. See | |
| 124 | - * {@link Cluster.Builder#withProtocolVersion} for more details. | |
| 125 | - * @param sslOptions the SSL options to use. Use {@code null} if SSL is not | |
| 126 | - * to be used. | |
| 127 | - * @param authProvider the {@code AuthProvider} to use for authentication against | |
| 128 | - * the Cassandra nodes. | |
| 130 | + * version uses will be the biggest version supported by the <em>first</em> node the driver connects to. | |
| 131 | + * Otherwise, it must be either 1 or 2 to force using a particular protocol version. See | |
| 132 | + * {@link Cluster.Builder#withProtocolVersion} for more details. | |
| 133 | + * @param sslOptions the SSL options to use. Use {@code null} if SSL is not | |
| 134 | + * to be used. | |
| 135 | + * @param authProvider the {@code AuthProvider} to use for authentication against | |
| 136 | + * the Cassandra nodes. | |
| 129 | 137 | */ |
| 130 | 138 | public ProtocolOptions(int port, int protocolVersion, int maxSchemaAgreementWaitSeconds, SSLOptions sslOptions, AuthProvider authProvider) { |
| 131 | 139 | this.port = port; |
| @@ -166,7 +174,7 @@ | ||
| 166 | 174 | |
| 167 | 175 | /** |
| 168 | 176 | * Returns the compression used by the protocol. |
| 169 | - * <p> | |
| 177 | + * <p/> | |
| 170 | 178 | * By default, compression is not used. |
| 171 | 179 | * |
| 172 | 180 | * @return the compression used. |
| @@ -177,18 +185,17 @@ | ||
| 177 | 185 | |
| 178 | 186 | /** |
| 179 | 187 | * Sets the compression to use. |
| 180 | - * <p> | |
| 188 | + * <p/> | |
| 181 | 189 | * Note that while this setting can be changed at any time, it will |
| 182 | 190 | * only apply to newly created connections. |
| 183 | 191 | * |
| 184 | 192 | * @param compression the compression algorithm to use (or {@code |
| 185 | - * Compression.NONE} to disable compression). | |
| 193 | + * Compression.NONE} to disable compression). | |
| 186 | 194 | * @return this {@code ProtocolOptions} object. |
| 187 | - * | |
| 188 | 195 | * @throws IllegalStateException if the compression requested is not |
| 189 | - * available. Most compression algorithms require that the relevant be | |
| 190 | - * present in the classpath. If not, the compression will be | |
| 191 | - * unavailable. | |
| 196 | + * available. Most compression algorithms require that the relevant be | |
| 197 | + * present in the classpath. If not, the compression will be | |
| 198 | + * unavailable. | |
| 192 | 199 | */ |
| 193 | 200 | public ProtocolOptions setCompression(Compression compression) { |
| 194 | 201 | if (compression != Compression.NONE && compression.compressor() == null) |
modified driver-core/src/main/java/com/datastax/driver/core/ProtocolV1Authenticator.java +2 −2
| @@ -19,10 +19,10 @@ | ||
| 19 | 19 | |
| 20 | 20 | /** |
| 21 | 21 | * Parent class for {@link Authenticator} implementations that support native protocol v1 authentication. |
| 22 | - * | |
| 22 | + * <p/> | |
| 23 | 23 | * Protocol v1 uses simple, credentials-based authentication (as opposed to SASL for later protocol versions). |
| 24 | 24 | * In order to support protocol v1, an authenticator must extend this class. |
| 25 | - * | |
| 25 | + * <p/> | |
| 26 | 26 | * We use an abstract class instead of an interface because we don't want to expose {@link #getCredentials()}. |
| 27 | 27 | * |
| 28 | 28 | * @see <a href="https://github.com/apache/cassandra/blob/trunk/doc/native_protocol_v1.spec">Native protocol v1 specification</a> |
modified driver-core/src/main/java/com/datastax/driver/core/QueryLogger.java +65 −64
| @@ -15,22 +15,22 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.nio.ByteBuffer; | |
| 19 | -import java.util.List; | |
| 20 | - | |
| 21 | -import static java.util.concurrent.TimeUnit.NANOSECONDS; | |
| 22 | - | |
| 23 | 18 | import com.google.common.annotations.Beta; |
| 24 | 19 | import com.google.common.annotations.VisibleForTesting; |
| 25 | 20 | import org.slf4j.Logger; |
| 26 | 21 | import org.slf4j.LoggerFactory; |
| 27 | 22 | |
| 23 | +import java.nio.ByteBuffer; | |
| 24 | +import java.util.List; | |
| 25 | + | |
| 26 | +import static java.util.concurrent.TimeUnit.NANOSECONDS; | |
| 27 | + | |
| 28 | 28 | /** |
| 29 | 29 | * A configurable {@link LatencyTracker} that logs all executed statements. |
| 30 | - * <p> | |
| 30 | + * <p/> | |
| 31 | 31 | * Typically, client applications would instantiate one single query logger (using its {@link Builder}), |
| 32 | 32 | * configure it and register it on the relevant {@link Cluster} instance, e.g.: |
| 33 | - * | |
| 33 | + * <p/> | |
| 34 | 34 | * <pre> |
| 35 | 35 | * Cluster cluster = ... |
| 36 | 36 | * QueryLogger queryLogger = QueryLogger.builder(cluster) |
| @@ -39,55 +39,55 @@ | ||
| 39 | 39 | * .build(); |
| 40 | 40 | * cluster.register(queryLogger); |
| 41 | 41 | * </pre> |
| 42 | - * | |
| 42 | + * <p/> | |
| 43 | 43 | * Refer to the {@link Builder} documentation for more information on |
| 44 | 44 | * configuration settings for the query logger. |
| 45 | - * <p> | |
| 45 | + * <p/> | |
| 46 | 46 | * Once registered, the query logger will log every {@link RegularStatement}, {@link BoundStatement} or {@link BatchStatement} |
| 47 | 47 | * executed by the driver; |
| 48 | 48 | * note that it will never log other types of statement, null statements nor any special statement used internally by the driver. |
| 49 | - * <p> | |
| 49 | + * <p/> | |
| 50 | 50 | * There is one log for each request to a Cassandra node; because the driver sometimes retries the same statement on multiple nodes, |
| 51 | 51 | * a single statement execution (for example, a single call to {@link Session#execute(Statement)}) can produce multiple logs on |
| 52 | 52 | * different nodes. |
| 53 | - * <p> | |
| 53 | + * <p/> | |
| 54 | 54 | * For more flexibility, the query logger uses 3 different {@link Logger} instances: |
| 55 | - * | |
| 55 | + * <p/> | |
| 56 | 56 | * <ol> |
| 57 | - * <li>{@link #NORMAL_LOGGER}: used to log normal queries, i.e., queries that completed successfully | |
| 58 | - * within a configurable threshold in milliseconds.</li> | |
| 59 | - * <li>{@link #SLOW_LOGGER}: used to log slow queries, i.e., queries that completed successfully | |
| 60 | - * but that took longer than a configurable threshold in milliseconds to complete.</li> | |
| 61 | - * <li>{@link #ERROR_LOGGER}: used to log unsuccessful queries, i.e., | |
| 62 | - * queries that did not completed normally and threw an exception. | |
| 63 | - * Note this this logger will also print the full stack trace of the reported exception.</li> | |
| 57 | + * <li>{@link #NORMAL_LOGGER}: used to log normal queries, i.e., queries that completed successfully | |
| 58 | + * within a configurable threshold in milliseconds.</li> | |
| 59 | + * <li>{@link #SLOW_LOGGER}: used to log slow queries, i.e., queries that completed successfully | |
| 60 | + * but that took longer than a configurable threshold in milliseconds to complete.</li> | |
| 61 | + * <li>{@link #ERROR_LOGGER}: used to log unsuccessful queries, i.e., | |
| 62 | + * queries that did not completed normally and threw an exception. | |
| 63 | + * Note this this logger will also print the full stack trace of the reported exception.</li> | |
| 64 | 64 | * </ol> |
| 65 | - * | |
| 66 | - * <p> | |
| 65 | + * <p/> | |
| 66 | + * <p/> | |
| 67 | 67 | * The appropriate logger is chosen according to the following algorithm: |
| 68 | 68 | * <ol> |
| 69 | - * <li>if an exception has been thrown: use {@link #ERROR_LOGGER};</li> | |
| 70 | - * <li>otherwise, if the reported latency is greater than the configured threshold in milliseconds: use {@link #SLOW_LOGGER};</li> | |
| 71 | - * <li>otherwise, use {@link #NORMAL_LOGGER}.</li> | |
| 69 | + * <li>if an exception has been thrown: use {@link #ERROR_LOGGER};</li> | |
| 70 | + * <li>otherwise, if the reported latency is greater than the configured threshold in milliseconds: use {@link #SLOW_LOGGER};</li> | |
| 71 | + * <li>otherwise, use {@link #NORMAL_LOGGER}.</li> | |
| 72 | 72 | * </ol> |
| 73 | - * | |
| 74 | - * <p> | |
| 73 | + * <p/> | |
| 74 | + * <p/> | |
| 75 | 75 | * All loggers are activated by setting their levels to {@code DEBUG} or {@code TRACE} (including {@link #ERROR_LOGGER}). |
| 76 | 76 | * If the level is set to {@code TRACE} and the statement being logged is a {@link BoundStatement}, |
| 77 | 77 | * then the query parameters (if any) will be logged as well (names and actual values). |
| 78 | - * | |
| 79 | - * <p> | |
| 78 | + * <p/> | |
| 79 | + * <p/> | |
| 80 | 80 | * <strong>Constant thresholds vs. Dynamic thresholds</strong> |
| 81 | - * <p> | |
| 81 | + * <p/> | |
| 82 | 82 | * Currently the QueryLogger can track slow queries in two different ways: |
| 83 | 83 | * using a constant threshold in milliseconds (which is the default behavior), |
| 84 | 84 | * or using a dynamic threshold based on per-host percentiles computed by |
| 85 | 85 | * {@link PerHostPercentileTracker}. |
| 86 | - * <p> | |
| 86 | + * <p/> | |
| 87 | 87 | * <b>Note that the dynamic threshold version is currently provided as a beta preview: it hasn't been extensively |
| 88 | 88 | * tested yet, and the API is still subject to change.</b> To use it, you must first obtain and register |
| 89 | 89 | * an instance of {@link PerHostPercentileTracker}, then create your QueryLogger as follows: |
| 90 | - * | |
| 90 | + * <p/> | |
| 91 | 91 | * <pre> |
| 92 | 92 | * Cluster cluster = ... |
| 93 | 93 | * // create an instance of PerHostPercentileTracker and register it |
| @@ -100,8 +100,8 @@ | ||
| 100 | 100 | * .build(); |
| 101 | 101 | * cluster.register(queryLogger); |
| 102 | 102 | * </pre> |
| 103 | - | |
| 104 | - * <p> | |
| 103 | + * <p/> | |
| 104 | + * <p/> | |
| 105 | 105 | * This class is thread-safe. |
| 106 | 106 | * |
| 107 | 107 | * @since 2.0.10 |
| @@ -146,11 +146,11 @@ | ||
| 146 | 146 | /** |
| 147 | 147 | * The logger used to log normal queries, i.e., queries that completed successfully |
| 148 | 148 | * within a configurable threshold in milliseconds. |
| 149 | - * <p> | |
| 149 | + * <p/> | |
| 150 | 150 | * This logger is activated by setting its level to {@code DEBUG} or {@code TRACE}. |
| 151 | 151 | * Additionally, if the level is set to {@code TRACE} and the statement being logged is a {@link BoundStatement}, |
| 152 | 152 | * then the query parameters (if any) will be logged as well (names and actual values). |
| 153 | - * <p> | |
| 153 | + * <p/> | |
| 154 | 154 | * The name of this logger is {@code com.datastax.driver.core.QueryLogger.NORMAL}. |
| 155 | 155 | */ |
| 156 | 156 | public static final Logger NORMAL_LOGGER = LoggerFactory.getLogger("com.datastax.driver.core.QueryLogger.NORMAL"); |
| @@ -158,23 +158,23 @@ | ||
| 158 | 158 | /** |
| 159 | 159 | * The logger used to log slow queries, i.e., queries that completed successfully |
| 160 | 160 | * but whose execution time exceeded a configurable threshold in milliseconds. |
| 161 | - * <p> | |
| 161 | + * <p/> | |
| 162 | 162 | * This logger is activated by setting its level to {@code DEBUG} or {@code TRACE}. |
| 163 | 163 | * Additionally, if the level is set to {@code TRACE} and the statement being logged is a {@link BoundStatement}, |
| 164 | 164 | * then the query parameters (if any) will be logged as well (names and actual values). |
| 165 | - * <p> | |
| 165 | + * <p/> | |
| 166 | 166 | * The name of this logger is {@code com.datastax.driver.core.QueryLogger.SLOW}. |
| 167 | 167 | */ |
| 168 | 168 | public static final Logger SLOW_LOGGER = LoggerFactory.getLogger("com.datastax.driver.core.QueryLogger.SLOW"); |
| 169 | 169 | |
| 170 | 170 | /** |
| 171 | 171 | * The logger used to log unsuccessful queries, i.e., queries that did not complete normally and threw an exception. |
| 172 | - * <p> | |
| 172 | + * <p/> | |
| 173 | 173 | * This logger is activated by setting its level to {@code DEBUG} or {@code TRACE}. |
| 174 | 174 | * Additionally, if the level is set to {@code TRACE} and the statement being logged is a {@link BoundStatement}, |
| 175 | 175 | * then the query parameters (if any) will be logged as well (names and actual values). |
| 176 | 176 | * Note this this logger will also print the full stack trace of the reported exception. |
| 177 | - * <p> | |
| 177 | + * <p/> | |
| 178 | 178 | * The name of this logger is {@code com.datastax.driver.core.QueryLogger.ERROR}. |
| 179 | 179 | */ |
| 180 | 180 | public static final Logger ERROR_LOGGER = LoggerFactory.getLogger("com.datastax.driver.core.QueryLogger.ERROR"); |
| @@ -215,7 +215,7 @@ | ||
| 215 | 215 | |
| 216 | 216 | /** |
| 217 | 217 | * Creates a new {@link QueryLogger.Builder} instance. |
| 218 | - * <p> | |
| 218 | + * <p/> | |
| 219 | 219 | * This is a convenience method for {@code new QueryLogger.Builder()}. |
| 220 | 220 | * |
| 221 | 221 | * @param cluster the {@link Cluster} this QueryLogger will be attached to. |
| @@ -223,7 +223,7 @@ | ||
| 223 | 223 | * @throws NullPointerException if {@code cluster} is {@code null}. |
| 224 | 224 | */ |
| 225 | 225 | public static QueryLogger.Builder builder(Cluster cluster) { |
| 226 | - if(cluster == null) throw new NullPointerException("QueryLogger.Builder: cluster parameter cannot be null"); | |
| 226 | + if (cluster == null) throw new NullPointerException("QueryLogger.Builder: cluster parameter cannot be null"); | |
| 227 | 227 | return new QueryLogger.Builder(cluster); |
| 228 | 228 | } |
| 229 | 229 | |
| @@ -288,10 +288,10 @@ | ||
| 288 | 288 | /** |
| 289 | 289 | * A QueryLogger that uses a dynamic threshold in milliseconds |
| 290 | 290 | * to track slow queries. |
| 291 | - * <p> | |
| 291 | + * <p/> | |
| 292 | 292 | * Dynamic thresholds are based on per-host latency percentiles, as computed |
| 293 | 293 | * by {@link PerHostPercentileTracker}. |
| 294 | - * <p> | |
| 294 | + * <p/> | |
| 295 | 295 | * <b>This class is currently provided as a beta preview: it hasn't been extensively tested yet, and the API is still subject |
| 296 | 296 | * to change.</b> |
| 297 | 297 | */ |
| @@ -348,7 +348,7 @@ | ||
| 348 | 348 | * and logged as such by the driver. |
| 349 | 349 | * |
| 350 | 350 | * @param slowQueryLatencyThresholdPercentile Slow queries threshold percentile. |
| 351 | - * It must be comprised between 0 inclusive and 100 exclusive. | |
| 351 | + * It must be comprised between 0 inclusive and 100 exclusive. | |
| 352 | 352 | * @throws IllegalArgumentException if {@code slowQueryLatencyThresholdPercentile < 0 || slowQueryLatencyThresholdPercentile >= 100}. |
| 353 | 353 | */ |
| 354 | 354 | public void setSlowQueryLatencyThresholdPercentile(double slowQueryLatencyThresholdPercentile) { |
| @@ -402,7 +402,7 @@ | ||
| 402 | 402 | |
| 403 | 403 | /** |
| 404 | 404 | * Enables slow query latency tracking based on constant thresholds. |
| 405 | - * <p> | |
| 405 | + * <p/> | |
| 406 | 406 | * Note: You should either use {@link #withConstantThreshold(long) constant thresholds} |
| 407 | 407 | * or {@link #withDynamicThreshold(PerHostPercentileTracker, double) dynamic thresholds}, |
| 408 | 408 | * not both. |
| @@ -420,22 +420,22 @@ | ||
| 420 | 420 | |
| 421 | 421 | /** |
| 422 | 422 | * Enables slow query latency tracking based on dynamic thresholds. |
| 423 | - * <p> | |
| 423 | + * <p/> | |
| 424 | 424 | * Dynamic thresholds are based on per-host latency percentiles, as computed |
| 425 | 425 | * by {@link PerHostPercentileTracker}. |
| 426 | - * <p> | |
| 426 | + * <p/> | |
| 427 | 427 | * Note: You should either use {@link #withConstantThreshold(long) constant thresholds} |
| 428 | 428 | * or {@link #withDynamicThreshold(PerHostPercentileTracker, double) dynamic thresholds}, |
| 429 | 429 | * not both. |
| 430 | - * <p> | |
| 430 | + * <p/> | |
| 431 | 431 | * <b>This feature is currently provided as a beta preview: it hasn't been extensively tested yet, and the API is still subject |
| 432 | 432 | * to change.</b> |
| 433 | 433 | * |
| 434 | - * @param perHostPercentileLatencyTracker the {@link PerHostPercentileTracker} instance to use for recording per-host latency histograms. | |
| 435 | - * Cannot be {@code null}. | |
| 434 | + * @param perHostPercentileLatencyTracker the {@link PerHostPercentileTracker} instance to use for recording per-host latency histograms. | |
| 435 | + * Cannot be {@code null}. | |
| 436 | 436 | * @param slowQueryLatencyThresholdPercentile Slow queries threshold percentile. |
| 437 | - * It must be comprised between 0 inclusive and 100 exclusive. | |
| 438 | - * The default value is {@link #DEFAULT_SLOW_QUERY_THRESHOLD_PERCENTILE} | |
| 437 | + * It must be comprised between 0 inclusive and 100 exclusive. | |
| 438 | + * The default value is {@link #DEFAULT_SLOW_QUERY_THRESHOLD_PERCENTILE} | |
| 439 | 439 | * @return this {@link Builder} instance (for method chaining). |
| 440 | 440 | */ |
| 441 | 441 | @Beta |
| @@ -501,11 +501,12 @@ | ||
| 501 | 501 | |
| 502 | 502 | /** |
| 503 | 503 | * Build the {@link QueryLogger} instance. |
| 504 | + * | |
| 504 | 505 | * @return the {@link QueryLogger} instance. |
| 505 | 506 | * @throws IllegalArgumentException if the builder is unable to build a valid instance due to incorrect settings. |
| 506 | 507 | */ |
| 507 | 508 | public QueryLogger build() { |
| 508 | - if(constantThreshold) { | |
| 509 | + if (constantThreshold) { | |
| 509 | 510 | return new ConstantThresholdQueryLogger(cluster, maxQueryStringLength, maxParameterValueLength, maxLoggedParameters, slowQueryLatencyThresholdMillis); |
| 510 | 511 | } else { |
| 511 | 512 | return new DynamicThresholdQueryLogger(cluster, maxQueryStringLength, maxParameterValueLength, maxLoggedParameters, slowQueryLatencyThresholdPercentile, perHostPercentileLatencyTracker); |
| @@ -642,13 +643,13 @@ | ||
| 642 | 643 | if (showParameterValues) { |
| 643 | 644 | StringBuilder params = new StringBuilder(); |
| 644 | 645 | if (statement instanceof BoundStatement) { |
| 645 | - appendParameters((BoundStatement)statement, params, maxLoggedParameters); | |
| 646 | + appendParameters((BoundStatement) statement, params, maxLoggedParameters); | |
| 646 | 647 | } else if (statement instanceof BatchStatement) { |
| 647 | - BatchStatement batchStatement = (BatchStatement)statement; | |
| 648 | + BatchStatement batchStatement = (BatchStatement) statement; | |
| 648 | 649 | int remaining = maxLoggedParameters; |
| 649 | 650 | for (Statement inner : batchStatement.getStatements()) { |
| 650 | 651 | if (inner instanceof BoundStatement) { |
| 651 | - remaining = appendParameters((BoundStatement)inner, params, remaining); | |
| 652 | + remaining = appendParameters((BoundStatement) inner, params, remaining); | |
| 652 | 653 | } |
| 653 | 654 | } |
| 654 | 655 | } |
| @@ -663,12 +664,12 @@ | ||
| 663 | 664 | protected String statementAsString(Statement statement) { |
| 664 | 665 | StringBuilder sb = new StringBuilder(); |
| 665 | 666 | if (statement instanceof BatchStatement) { |
| 666 | - BatchStatement bs = (BatchStatement)statement; | |
| 667 | + BatchStatement bs = (BatchStatement) statement; | |
| 667 | 668 | int statements = bs.getStatements().size(); |
| 668 | 669 | int boundValues = countBoundValues(bs); |
| 669 | 670 | sb.append("[" + statements + " statements, " + boundValues + " bound values] "); |
| 670 | 671 | } else if (statement instanceof BoundStatement) { |
| 671 | - int boundValues = ((BoundStatement)statement).values.length; | |
| 672 | + int boundValues = ((BoundStatement) statement).values.length; | |
| 672 | 673 | sb.append("[" + boundValues + " bound values] "); |
| 673 | 674 | } |
| 674 | 675 | |
| @@ -680,7 +681,7 @@ | ||
| 680 | 681 | int count = 0; |
| 681 | 682 | for (Statement s : bs.getStatements()) { |
| 682 | 683 | if (s instanceof BoundStatement) |
| 683 | - count += ((BoundStatement)s).values.length; | |
| 684 | + count += ((BoundStatement) s).values.length; | |
| 684 | 685 | } |
| 685 | 686 | return count; |
| 686 | 687 | } |
| @@ -725,7 +726,7 @@ | ||
| 725 | 726 | int maxBufferLength = Math.max(2, (maxParameterValueLength - 2) / 2); |
| 726 | 727 | boolean bufferTooLarge = raw.remaining() > maxBufferLength; |
| 727 | 728 | if (bufferTooLarge) { |
| 728 | - raw = (ByteBuffer)raw.duplicate().limit(maxBufferLength); | |
| 729 | + raw = (ByteBuffer) raw.duplicate().limit(maxBufferLength); | |
| 729 | 730 | } |
| 730 | 731 | Object value = type.deserialize(raw); |
| 731 | 732 | valueStr = type.format(value); |
| @@ -745,14 +746,14 @@ | ||
| 745 | 746 | |
| 746 | 747 | protected int append(Statement statement, StringBuilder buffer, int remaining) { |
| 747 | 748 | if (statement instanceof StatementWrapper) |
| 748 | - statement = ((StatementWrapper)statement).getWrappedStatement(); | |
| 749 | + statement = ((StatementWrapper) statement).getWrappedStatement(); | |
| 749 | 750 | |
| 750 | 751 | if (statement instanceof RegularStatement) { |
| 751 | - remaining = append(((RegularStatement)statement).getQueryString().trim(), buffer, remaining); | |
| 752 | + remaining = append(((RegularStatement) statement).getQueryString().trim(), buffer, remaining); | |
| 752 | 753 | } else if (statement instanceof BoundStatement) { |
| 753 | - remaining = append(((BoundStatement)statement).preparedStatement().getQueryString().trim(), buffer, remaining); | |
| 754 | + remaining = append(((BoundStatement) statement).preparedStatement().getQueryString().trim(), buffer, remaining); | |
| 754 | 755 | } else if (statement instanceof BatchStatement) { |
| 755 | - BatchStatement batchStatement = (BatchStatement)statement; | |
| 756 | + BatchStatement batchStatement = (BatchStatement) statement; | |
| 756 | 757 | remaining = append("BEGIN", buffer, remaining); |
| 757 | 758 | switch (batchStatement.batchType) { |
| 758 | 759 | case UNLOGGED: |
modified driver-core/src/main/java/com/datastax/driver/core/QueryOptions.java +43 −46
| @@ -77,7 +77,8 @@ | ||
| 77 | 77 | * Creates a new {@link QueryOptions} instance using the {@link #DEFAULT_CONSISTENCY_LEVEL}, |
| 78 | 78 | * {@link #DEFAULT_SERIAL_CONSISTENCY_LEVEL} and {@link #DEFAULT_FETCH_SIZE}. |
| 79 | 79 | */ |
| 80 | - public QueryOptions() {} | |
| 80 | + public QueryOptions() { | |
| 81 | + } | |
| 81 | 82 | |
| 82 | 83 | void register(Cluster.Manager manager) { |
| 83 | 84 | this.manager = manager; |
| @@ -85,7 +86,7 @@ | ||
| 85 | 86 | |
| 86 | 87 | /** |
| 87 | 88 | * Sets the default consistency level to use for queries. |
| 88 | - * <p> | |
| 89 | + * <p/> | |
| 89 | 90 | * The consistency level set through this method will be use for queries |
| 90 | 91 | * that don't explicitly have a consistency level, i.e. when {@link Statement#getConsistencyLevel} |
| 91 | 92 | * returns {@code null}. |
| @@ -109,7 +110,7 @@ | ||
| 109 | 110 | |
| 110 | 111 | /** |
| 111 | 112 | * Sets the default serial consistency level to use for queries. |
| 112 | - * <p> | |
| 113 | + * <p/> | |
| 113 | 114 | * The serial consistency level set through this method will be use for queries |
| 114 | 115 | * that don't explicitly have a serial consistency level, i.e. when {@link Statement#getSerialConsistencyLevel} |
| 115 | 116 | * returns {@code null}. |
| @@ -133,21 +134,20 @@ | ||
| 133 | 134 | |
| 134 | 135 | /** |
| 135 | 136 | * Sets the default fetch size to use for SELECT queries. |
| 136 | - * <p> | |
| 137 | + * <p/> | |
| 137 | 138 | * The fetch size set through this method will be use for queries |
| 138 | 139 | * that don't explicitly have a fetch size, i.e. when {@link Statement#getFetchSize} |
| 139 | 140 | * is less or equal to 0. |
| 140 | 141 | * |
| 141 | 142 | * @param fetchSize the new fetch size to set as default. It must be |
| 142 | - * strictly positive but you can use {@code Integer.MAX_VALUE} to disable | |
| 143 | - * paging. | |
| 143 | + * strictly positive but you can use {@code Integer.MAX_VALUE} to disable | |
| 144 | + * paging. | |
| 144 | 145 | * @return this {@code QueryOptions} instance. |
| 145 | - * | |
| 146 | - * @throws IllegalArgumentException if {@code fetchSize <e; 0}. | |
| 146 | + * @throws IllegalArgumentException if {@code fetchSize <e; 0}. | |
| 147 | 147 | * @throws UnsupportedFeatureException if version 1 of the native protocol is in |
| 148 | - * use and {@code fetchSize != Integer.MAX_VALUE} as paging is not supported by | |
| 149 | - * version 1 of the protocol. See {@link Cluster.Builder#withProtocolVersion} | |
| 150 | - * for more details on protocol versions. | |
| 148 | + * use and {@code fetchSize != Integer.MAX_VALUE} as paging is not supported by | |
| 149 | + * version 1 of the protocol. See {@link Cluster.Builder#withProtocolVersion} | |
| 150 | + * for more details on protocol versions. | |
| 151 | 151 | */ |
| 152 | 152 | public QueryOptions setFetchSize(int fetchSize) { |
| 153 | 153 | if (fetchSize <= 0) |
| @@ -172,7 +172,7 @@ | ||
| 172 | 172 | |
| 173 | 173 | /** |
| 174 | 174 | * Sets the default idempotence for queries. |
| 175 | - * <p> | |
| 175 | + * <p/> | |
| 176 | 176 | * This will be used for statements for which {@link com.datastax.driver.core.Statement#isIdempotent()} |
| 177 | 177 | * returns {@code null}. |
| 178 | 178 | * |
| @@ -186,7 +186,7 @@ | ||
| 186 | 186 | |
| 187 | 187 | /** |
| 188 | 188 | * The default idempotence for queries. |
| 189 | - * <p> | |
| 189 | + * <p/> | |
| 190 | 190 | * It defaults to {@link #DEFAULT_IDEMPOTENCE}. |
| 191 | 191 | * |
| 192 | 192 | * @return the default idempotence for queries. |
| @@ -197,20 +197,20 @@ | ||
| 197 | 197 | |
| 198 | 198 | /** |
| 199 | 199 | * Set whether the driver should prepare statements on all hosts in the cluster. |
| 200 | - * <p> | |
| 200 | + * <p/> | |
| 201 | 201 | * A statement is normally prepared in two steps: |
| 202 | 202 | * <ol> |
| 203 | - * <li>prepare the query on a single host in the cluster;</li> | |
| 204 | - * <li>if that succeeds, prepare on all other hosts.</li> | |
| 203 | + * <li>prepare the query on a single host in the cluster;</li> | |
| 204 | + * <li>if that succeeds, prepare on all other hosts.</li> | |
| 205 | 205 | * </ol> |
| 206 | 206 | * This option controls whether step 2 is executed. It is enabled by default. |
| 207 | - * <p> | |
| 207 | + * <p/> | |
| 208 | 208 | * The reason why you might want to disable it is to optimize network usage if you |
| 209 | 209 | * have a large number of clients preparing the same set of statements at startup. |
| 210 | 210 | * If your load balancing policy distributes queries randomly, each client will pick |
| 211 | 211 | * a different host to prepare its statements, and on the whole each host has a good |
| 212 | 212 | * chance of having been hit by at least one client for each statement. |
| 213 | - * <p> | |
| 213 | + * <p/> | |
| 214 | 214 | * On the other hand, if that assumption turns out to be wrong and one host hasn't |
| 215 | 215 | * prepared a given statement, it needs to be re-prepared on the fly the first time |
| 216 | 216 | * it gets executed; this causes a performance penalty (one extra roundtrip to resend |
| @@ -229,7 +229,6 @@ | ||
| 229 | 229 | * Returns whether the driver should prepare statements on all hosts in the cluster. |
| 230 | 230 | * |
| 231 | 231 | * @return the value. |
| 232 | - * | |
| 233 | 232 | * @see #setPrepareOnAllHosts(boolean) |
| 234 | 233 | */ |
| 235 | 234 | public boolean isPrepareOnAllHosts() { |
| @@ -239,14 +238,14 @@ | ||
| 239 | 238 | /** |
| 240 | 239 | * Set whether the driver should re-prepare all cached prepared statements on a host |
| 241 | 240 | * when it marks it back up. |
| 242 | - * <p> | |
| 241 | + * <p/> | |
| 243 | 242 | * This option is enabled by default. |
| 244 | - * <p> | |
| 243 | + * <p/> | |
| 245 | 244 | * The reason why you might want to disable it is to optimize reconnection time when |
| 246 | 245 | * you believe hosts often get marked down because of temporary network issues, rather |
| 247 | 246 | * than the host really crashing. In that case, the host still has prepared statements |
| 248 | 247 | * in its cache when the driver reconnects, so re-preparing is redundant. |
| 249 | - * <p> | |
| 248 | + * <p/> | |
| 250 | 249 | * On the other hand, if that assumption turns out to be wrong and the host had |
| 251 | 250 | * really restarted, its prepared statement cache is empty, and statements need to be |
| 252 | 251 | * re-prepared on the fly the first time they get executed; this causes a performance |
| @@ -256,7 +255,7 @@ | ||
| 256 | 255 | * @param reprepareOnUp whether the driver should re-prepare when marking a node up. |
| 257 | 256 | * @return this {@code QueryOptions} instance. |
| 258 | 257 | */ |
| 259 | - public QueryOptions setReprepareOnUp(boolean reprepareOnUp){ | |
| 258 | + public QueryOptions setReprepareOnUp(boolean reprepareOnUp) { | |
| 260 | 259 | this.reprepareOnUp = reprepareOnUp; |
| 261 | 260 | return this; |
| 262 | 261 | } |
| @@ -266,7 +265,6 @@ | ||
| 266 | 265 | * when its marks that host back up. |
| 267 | 266 | * |
| 268 | 267 | * @return the value. |
| 269 | - * | |
| 270 | 268 | * @see #setReprepareOnUp(boolean) |
| 271 | 269 | */ |
| 272 | 270 | public boolean isReprepareOnUp() { |
| @@ -275,23 +273,23 @@ | ||
| 275 | 273 | |
| 276 | 274 | /** |
| 277 | 275 | * Toggle client-side token and schema metadata. |
| 278 | - * <p> | |
| 276 | + * <p/> | |
| 279 | 277 | * This feature is enabled by default. Some applications might wish to disable it |
| 280 | 278 | * in order to eliminate the overhead of querying the metadata and building its |
| 281 | 279 | * client-side representation. However, take note that doing so will have important |
| 282 | 280 | * consequences: |
| 283 | 281 | * <ul> |
| 284 | - * <li>most schema- or token-related methods in {@link Metadata} will return stale | |
| 285 | - * or null/empty results (see the javadoc of each method for details);</li> | |
| 286 | - * <li>{@link Metadata#newToken(String)} and | |
| 287 | - * {@link Metadata#newTokenRange(Token, Token)} will throw an exception if metadata | |
| 288 | - * was disabled before startup;</li> | |
| 289 | - * <li>token-aware routing will not work properly: if metadata was never initialized, | |
| 290 | - * {@link com.datastax.driver.core.policies.TokenAwarePolicy} will always delegate | |
| 291 | - * to its child policy. Otherwise, it might not pick the best coordinator (i.e. chose | |
| 292 | - * a host that is not a replica for the statement's routing key). In addition, statements | |
| 293 | - * prepared while the metadata was disabled might also be sent to a non-optimal coordinator, | |
| 294 | - * even if metadata was re-enabled later.</li> | |
| 282 | + * <li>most schema- or token-related methods in {@link Metadata} will return stale | |
| 283 | + * or null/empty results (see the javadoc of each method for details);</li> | |
| 284 | + * <li>{@link Metadata#newToken(String)} and | |
| 285 | + * {@link Metadata#newTokenRange(Token, Token)} will throw an exception if metadata | |
| 286 | + * was disabled before startup;</li> | |
| 287 | + * <li>token-aware routing will not work properly: if metadata was never initialized, | |
| 288 | + * {@link com.datastax.driver.core.policies.TokenAwarePolicy} will always delegate | |
| 289 | + * to its child policy. Otherwise, it might not pick the best coordinator (i.e. chose | |
| 290 | + * a host that is not a replica for the statement's routing key). In addition, statements | |
| 291 | + * prepared while the metadata was disabled might also be sent to a non-optimal coordinator, | |
| 292 | + * even if metadata was re-enabled later.</li> | |
| 295 | 293 | * </ul> |
| 296 | 294 | * |
| 297 | 295 | * @param enabled whether metadata is enabled. |
| @@ -310,7 +308,6 @@ | ||
| 310 | 308 | * Whether client-side token and schema metadata is enabled. |
| 311 | 309 | * |
| 312 | 310 | * @return the value. |
| 313 | - * | |
| 314 | 311 | * @see #setMetadataEnabled(boolean) |
| 315 | 312 | */ |
| 316 | 313 | public boolean isMetadataEnabled() { |
| @@ -319,7 +316,7 @@ | ||
| 319 | 316 | |
| 320 | 317 | /** |
| 321 | 318 | * Sets the default window size in milliseconds used to debounce node list refresh requests. |
| 322 | - * <p> | |
| 319 | + * <p/> | |
| 323 | 320 | * When the control connection receives a new schema refresh request, |
| 324 | 321 | * it puts it on hold and starts a timer, cancelling any previous running timer; |
| 325 | 322 | * when a timer expires, then the pending requests are coalesced and executed |
| @@ -344,14 +341,14 @@ | ||
| 344 | 341 | /** |
| 345 | 342 | * Sets the maximum number of schema refresh requests that the control connection can accumulate |
| 346 | 343 | * before executing them. |
| 347 | - * <p> | |
| 344 | + * <p/> | |
| 348 | 345 | * When the control connection receives a new schema refresh request, |
| 349 | 346 | * it puts it on hold and starts a timer, cancelling any previous running timer; |
| 350 | 347 | * if the control connection receives too many events, is parameter allows to trigger |
| 351 | 348 | * execution of pending requests, event if the last timer is still running. |
| 352 | 349 | * |
| 353 | 350 | * @param maxPendingRefreshSchemaRequests The maximum number of schema refresh requests that the control connection can accumulate |
| 354 | - * before executing them. | |
| 351 | + * before executing them. | |
| 355 | 352 | */ |
| 356 | 353 | public QueryOptions setMaxPendingRefreshSchemaRequests(int maxPendingRefreshSchemaRequests) { |
| 357 | 354 | this.maxPendingRefreshSchemaRequests = maxPendingRefreshSchemaRequests; |
| @@ -371,7 +368,7 @@ | ||
| 371 | 368 | |
| 372 | 369 | /** |
| 373 | 370 | * Sets the default window size in milliseconds used to debounce node list refresh requests. |
| 374 | - * <p> | |
| 371 | + * <p/> | |
| 375 | 372 | * When the control connection receives a new node list refresh request, |
| 376 | 373 | * it puts it on hold and starts a timer, cancelling any previous running timer; |
| 377 | 374 | * when a timer expires, then the pending requests are coalesced and executed |
| @@ -396,14 +393,14 @@ | ||
| 396 | 393 | /** |
| 397 | 394 | * Sets the maximum number of node list refresh requests that the control connection can accumulate |
| 398 | 395 | * before executing them. |
| 399 | - * <p> | |
| 396 | + * <p/> | |
| 400 | 397 | * When the control connection receives a new node list refresh request, |
| 401 | 398 | * it puts it on hold and starts a timer, cancelling any previous running timer; |
| 402 | 399 | * if the control connection receives too many events, is parameter allows to trigger |
| 403 | 400 | * execution of pending requests, event if the last timer is still running. |
| 404 | 401 | * |
| 405 | 402 | * @param maxPendingRefreshNodeListRequests The maximum number of node list refresh requests that the control connection can accumulate |
| 406 | - * before executing them. | |
| 403 | + * before executing them. | |
| 407 | 404 | */ |
| 408 | 405 | public QueryOptions setMaxPendingRefreshNodeListRequests(int maxPendingRefreshNodeListRequests) { |
| 409 | 406 | this.maxPendingRefreshNodeListRequests = maxPendingRefreshNodeListRequests; |
| @@ -423,7 +420,7 @@ | ||
| 423 | 420 | |
| 424 | 421 | /** |
| 425 | 422 | * Sets the default window size in milliseconds used to debounce node refresh requests. |
| 426 | - * <p> | |
| 423 | + * <p/> | |
| 427 | 424 | * When the control connection receives a new node refresh request, |
| 428 | 425 | * it puts it on hold and starts a timer, cancelling any previous running timer; |
| 429 | 426 | * when a timer expires, then the pending requests are coalesced and executed |
| @@ -448,14 +445,14 @@ | ||
| 448 | 445 | /** |
| 449 | 446 | * Sets the maximum number of node refresh requests that the control connection can accumulate |
| 450 | 447 | * before executing them. |
| 451 | - * <p> | |
| 448 | + * <p/> | |
| 452 | 449 | * When the control connection receives a new node refresh request, |
| 453 | 450 | * it puts it on hold and starts a timer, cancelling any previous running timer; |
| 454 | 451 | * if the control connection receives too many events, is parameter allows to trigger |
| 455 | 452 | * execution of pending requests, event if the last timer is still running. |
| 456 | 453 | * |
| 457 | 454 | * @param maxPendingRefreshNodeRequests The maximum number of node refresh requests that the control connection can accumulate |
| 458 | - * before executing them. | |
| 455 | + * before executing them. | |
| 459 | 456 | */ |
| 460 | 457 | public QueryOptions setMaxPendingRefreshNodeRequests(int maxPendingRefreshNodeRequests) { |
| 461 | 458 | this.maxPendingRefreshNodeRequests = maxPendingRefreshNodeRequests; |
modified driver-core/src/main/java/com/datastax/driver/core/QueryTrace.java +18 −25
| @@ -15,25 +15,24 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.exceptions.TraceRetrievalException; | |
| 19 | +import com.google.common.util.concurrent.Uninterruptibles; | |
| 20 | + | |
| 18 | 21 | import java.net.InetAddress; |
| 19 | 22 | import java.util.*; |
| 20 | 23 | import java.util.concurrent.TimeUnit; |
| 21 | 24 | import java.util.concurrent.locks.Lock; |
| 22 | 25 | import java.util.concurrent.locks.ReentrantLock; |
| 23 | 26 | |
| 24 | -import com.google.common.util.concurrent.Uninterruptibles; | |
| 25 | - | |
| 26 | -import com.datastax.driver.core.exceptions.TraceRetrievalException; | |
| 27 | - | |
| 28 | 27 | /** |
| 29 | 28 | * The Cassandra trace for a query. |
| 30 | - * <p> | |
| 29 | + * <p/> | |
| 31 | 30 | * A trace is generated by Cassandra when query tracing is enabled for the |
| 32 | 31 | * query. The trace itself is stored in Cassandra in the {@code sessions} and |
| 33 | 32 | * {@code events} table in the {@code system_traces} keyspace and can be |
| 34 | 33 | * retrieve manually using the trace identifier (the one returned by |
| 35 | 34 | * {@link #getTraceId}). |
| 36 | - * <p> | |
| 35 | + * <p/> | |
| 37 | 36 | * This class provides facilities to fetch the traces from Cassandra. Please |
| 38 | 37 | * note that the writing of the trace is done asynchronously in Cassandra. So |
| 39 | 38 | * accessing the trace too soon after the query may result in the trace being |
| @@ -68,7 +67,7 @@ | ||
| 68 | 67 | |
| 69 | 68 | /** |
| 70 | 69 | * Returns the identifier of this trace. |
| 71 | - * <p> | |
| 70 | + * <p/> | |
| 72 | 71 | * Note that contrary to the other methods in this class, this |
| 73 | 72 | * does not entail fetching query trace details from Cassandra. |
| 74 | 73 | * |
| @@ -83,9 +82,8 @@ | ||
| 83 | 82 | * |
| 84 | 83 | * @return the type of request or {@code null} if the request |
| 85 | 84 | * type is not yet available. |
| 86 | - * | |
| 87 | 85 | * @throws TraceRetrievalException if the trace details cannot be retrieve |
| 88 | - * from Cassandra successfully. | |
| 86 | + * from Cassandra successfully. | |
| 89 | 87 | */ |
| 90 | 88 | public String getRequestType() { |
| 91 | 89 | maybeFetchTrace(); |
| @@ -98,9 +96,8 @@ | ||
| 98 | 96 | * @return the (server side) duration of the query in microseconds. This |
| 99 | 97 | * method will return {@code Integer.MIN_VALUE} if the duration is not yet |
| 100 | 98 | * available. |
| 101 | - * | |
| 102 | 99 | * @throws TraceRetrievalException if the trace details cannot be retrieve |
| 103 | - * from Cassandra successfully. | |
| 100 | + * from Cassandra successfully. | |
| 104 | 101 | */ |
| 105 | 102 | public int getDurationMicros() { |
| 106 | 103 | maybeFetchTrace(); |
| @@ -112,9 +109,8 @@ | ||
| 112 | 109 | * |
| 113 | 110 | * @return the coordinator host of the query or {@code null} |
| 114 | 111 | * if the coordinator is not yet available. |
| 115 | - * | |
| 116 | 112 | * @throws TraceRetrievalException if the trace details cannot be retrieve |
| 117 | - * from Cassandra successfully. | |
| 113 | + * from Cassandra successfully. | |
| 118 | 114 | */ |
| 119 | 115 | public InetAddress getCoordinator() { |
| 120 | 116 | maybeFetchTrace(); |
| @@ -126,9 +122,8 @@ | ||
| 126 | 122 | * |
| 127 | 123 | * @return the parameters attached to this trace. or |
| 128 | 124 | * {@code null} if the coordinator is not yet available. |
| 129 | - * | |
| 130 | 125 | * @throws TraceRetrievalException if the trace details cannot be retrieve |
| 131 | - * from Cassandra successfully. | |
| 126 | + * from Cassandra successfully. | |
| 132 | 127 | */ |
| 133 | 128 | public Map<String, String> getParameters() { |
| 134 | 129 | maybeFetchTrace(); |
| @@ -140,9 +135,8 @@ | ||
| 140 | 135 | * |
| 141 | 136 | * @return the server side timestamp of the start of this query or |
| 142 | 137 | * 0 if the start timestamp is not available. |
| 143 | - * | |
| 144 | 138 | * @throws TraceRetrievalException if the trace details cannot be retrieve |
| 145 | - * from Cassandra successfully. | |
| 139 | + * from Cassandra successfully. | |
| 146 | 140 | */ |
| 147 | 141 | public long getStartedAt() { |
| 148 | 142 | maybeFetchTrace(); |
| @@ -151,7 +145,7 @@ | ||
| 151 | 145 | |
| 152 | 146 | /** |
| 153 | 147 | * Returns the events contained in this trace. |
| 154 | - * <p> | |
| 148 | + * <p/> | |
| 155 | 149 | * Query tracing is asynchronous in Cassandra. Hence, it |
| 156 | 150 | * is possible for the list returned to be missing some events for some of |
| 157 | 151 | * the replica involved in the query if the query trace is requested just |
| @@ -160,9 +154,8 @@ | ||
| 160 | 154 | * the query). |
| 161 | 155 | * |
| 162 | 156 | * @return the events contained in this trace. |
| 163 | - * | |
| 164 | 157 | * @throws TraceRetrievalException if the trace details cannot be retrieve |
| 165 | - * from Cassandra successfully. | |
| 158 | + * from Cassandra successfully. | |
| 166 | 159 | */ |
| 167 | 160 | public List<Event> getEvents() { |
| 168 | 161 | maybeFetchTrace(); |
| @@ -211,10 +204,10 @@ | ||
| 211 | 204 | events = new ArrayList<Event>(); |
| 212 | 205 | for (Row evRow : eventsFuture.get()) { |
| 213 | 206 | events.add(new Event(evRow.getString("activity"), |
| 214 | - evRow.getUUID("event_id").timestamp(), | |
| 215 | - evRow.getInet("source"), | |
| 216 | - evRow.getInt("source_elapsed"), | |
| 217 | - evRow.getString("thread"))); | |
| 207 | + evRow.getUUID("event_id").timestamp(), | |
| 208 | + evRow.getInet("source"), | |
| 209 | + evRow.getInt("source_elapsed"), | |
| 210 | + evRow.getString("thread"))); | |
| 218 | 211 | } |
| 219 | 212 | events = Collections.unmodifiableList(events); |
| 220 | 213 | |
| @@ -237,7 +230,7 @@ | ||
| 237 | 230 | |
| 238 | 231 | /** |
| 239 | 232 | * A trace event. |
| 240 | - * <p> | |
| 233 | + * <p/> | |
| 241 | 234 | * A query trace is composed of a list of trace events. |
| 242 | 235 | */ |
| 243 | 236 | public static class Event { |
modified driver-core/src/main/java/com/datastax/driver/core/RegularStatement.java +4 −4
| @@ -19,7 +19,7 @@ | ||
| 19 | 19 | |
| 20 | 20 | /** |
| 21 | 21 | * A regular (non-prepared and non batched) CQL statement. |
| 22 | - * <p> | |
| 22 | + * <p/> | |
| 23 | 23 | * This class represents a query string along with query options (and optionally |
| 24 | 24 | * binary values, see {@code getValues}). It can be extended but {@link SimpleStatement} |
| 25 | 25 | * is provided as a simple implementation to build a {@code RegularStatement} directly |
| @@ -30,7 +30,8 @@ | ||
| 30 | 30 | /** |
| 31 | 31 | * Creates a new RegularStatement. |
| 32 | 32 | */ |
| 33 | - protected RegularStatement() {} | |
| 33 | + protected RegularStatement() { | |
| 34 | + } | |
| 34 | 35 | |
| 35 | 36 | /** |
| 36 | 37 | * Returns the query string for this statement. |
| @@ -41,7 +42,7 @@ | ||
| 41 | 42 | |
| 42 | 43 | /** |
| 43 | 44 | * The values to use for this statement. |
| 44 | - * <p> | |
| 45 | + * <p/> | |
| 45 | 46 | * Note: Values for a RegularStatement (i.e. if this method does not return |
| 46 | 47 | * {@code null}) are not supported with the native protocol version 1: you |
| 47 | 48 | * will get an {@link UnsupportedProtocolVersionException} when submitting |
| @@ -51,7 +52,6 @@ | ||
| 51 | 52 | * |
| 52 | 53 | * @return the values to use for this statement or {@code null} if there is |
| 53 | 54 | * no such values. |
| 54 | - * | |
| 55 | 55 | * @see SimpleStatement#SimpleStatement(String, Object...) |
| 56 | 56 | */ |
| 57 | 57 | public abstract ByteBuffer[] getValues(); |
modified driver-core/src/main/java/com/datastax/driver/core/ReplicationStategy.java +12 −13
| @@ -15,14 +15,14 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.util.*; | |
| 19 | - | |
| 20 | 18 | import com.google.common.collect.ImmutableSet; |
| 21 | 19 | import com.google.common.collect.Maps; |
| 22 | 20 | import com.google.common.collect.Sets; |
| 23 | 21 | import org.slf4j.Logger; |
| 24 | 22 | import org.slf4j.LoggerFactory; |
| 25 | 23 | |
| 24 | +import java.util.*; | |
| 25 | + | |
| 26 | 26 | /* |
| 27 | 27 | * Computes the token->list<replica> association, given the token ring and token->primary token map. |
| 28 | 28 | * |
| @@ -42,8 +42,7 @@ | ||
| 42 | 42 | return repFactorString == null ? null : new SimpleStrategy(Integer.parseInt(repFactorString)); |
| 43 | 43 | } else if (strategyClass.contains("NetworkTopologyStrategy")) { |
| 44 | 44 | Map<String, Integer> dcRfs = new HashMap<String, Integer>(); |
| 45 | - for (Map.Entry<String, String> entry : replicationOptions.entrySet()) | |
| 46 | - { | |
| 45 | + for (Map.Entry<String, String> entry : replicationOptions.entrySet()) { | |
| 47 | 46 | if (entry.getKey().equals("class")) |
| 48 | 47 | continue; |
| 49 | 48 | |
| @@ -83,7 +82,7 @@ | ||
| 83 | 82 | // Consecutive sections of the ring can assigned to the same host |
| 84 | 83 | Set<Host> replicas = new LinkedHashSet<Host>(); |
| 85 | 84 | for (int j = 0; j < ring.size() && replicas.size() < rf; j++) |
| 86 | - replicas.add(tokenToPrimary.get(getTokenWrapping(i+j, ring))); | |
| 85 | + replicas.add(tokenToPrimary.get(getTokenWrapping(i + j, ring))); | |
| 87 | 86 | replicaMap.put(ring.get(i), ImmutableSet.copyOf(replicas)); |
| 88 | 87 | } |
| 89 | 88 | return replicaMap; |
| @@ -96,7 +95,7 @@ | ||
| 96 | 95 | if (o == null || getClass() != o.getClass()) |
| 97 | 96 | return false; |
| 98 | 97 | |
| 99 | - SimpleStrategy that = (SimpleStrategy)o; | |
| 98 | + SimpleStrategy that = (SimpleStrategy) o; | |
| 100 | 99 | |
| 101 | 100 | return replicationFactor == that.replicationFactor; |
| 102 | 101 | |
| @@ -119,7 +118,7 @@ | ||
| 119 | 118 | |
| 120 | 119 | Map<Token, Set<Host>> computeTokenToReplicaMap(Map<Token, Host> tokenToPrimary, List<Token> ring) { |
| 121 | 120 | |
| 122 | - // This is essentially a copy of org.apache.cassandra.locator.NetworkTopologyStrategy | |
| 121 | + // This is essentially a copy of org.apache.cassandra.locator.NetworkTopologyStrategy | |
| 123 | 122 | Map<String, Set<String>> racks = getRacksInDcs(tokenToPrimary.values()); |
| 124 | 123 | Map<Token, Set<Host>> replicaMap = new HashMap<Token, Set<Host>>(tokenToPrimary.size()); |
| 125 | 124 | Map<String, Integer> dcHostCount = Maps.newHashMapWithExpectedSize(replicationFactors.size()); |
| @@ -127,7 +126,7 @@ | ||
| 127 | 126 | // find maximum number of nodes in each DC |
| 128 | 127 | for (Host host : Sets.newHashSet(tokenToPrimary.values())) { |
| 129 | 128 | String dc = host.getDatacenter(); |
| 130 | - if(dcHostCount.get(dc) == null) { | |
| 129 | + if (dcHostCount.get(dc) == null) { | |
| 131 | 130 | dcHostCount.put(dc, 0); |
| 132 | 131 | } |
| 133 | 132 | dcHostCount.put(dc, dcHostCount.get(dc) + 1); |
| @@ -190,9 +189,9 @@ | ||
| 190 | 189 | int achievedFactor = entry.getValue().size(); |
| 191 | 190 | if (achievedFactor < expectedFactor && !warnedDcs.contains(dcName)) { |
| 192 | 191 | logger.warn("Error while computing token map for datacenter {}: " |
| 193 | - + "could not achieve replication factor {} (found {} replicas only), " | |
| 194 | - + "check your keyspace replication settings.", | |
| 195 | - dcName, expectedFactor, achievedFactor); | |
| 192 | + + "could not achieve replication factor {} (found {} replicas only), " | |
| 193 | + + "check your keyspace replication settings.", | |
| 194 | + dcName, expectedFactor, achievedFactor); | |
| 196 | 195 | // only warn once per DC |
| 197 | 196 | warnedDcs.add(dcName); |
| 198 | 197 | } |
| @@ -206,7 +205,7 @@ | ||
| 206 | 205 | private boolean allDone(Map<String, Set<Host>> map, Map<String, Integer> dcHostCount) { |
| 207 | 206 | for (Map.Entry<String, Set<Host>> entry : map.entrySet()) { |
| 208 | 207 | String dc = entry.getKey(); |
| 209 | - int dcCount = dcHostCount.get(dc) == null? 0 : dcHostCount.get(dc); | |
| 208 | + int dcCount = dcHostCount.get(dc) == null ? 0 : dcHostCount.get(dc); | |
| 210 | 209 | if (entry.getValue().size() < Math.min(replicationFactors.get(dc), dcCount)) |
| 211 | 210 | return false; |
| 212 | 211 | } |
| @@ -233,7 +232,7 @@ | ||
| 233 | 232 | if (o == null || getClass() != o.getClass()) |
| 234 | 233 | return false; |
| 235 | 234 | |
| 236 | - NetworkTopologyStrategy that = (NetworkTopologyStrategy)o; | |
| 235 | + NetworkTopologyStrategy that = (NetworkTopologyStrategy) o; | |
| 237 | 236 | |
| 238 | 237 | return replicationFactors.equals(that.replicationFactors); |
| 239 | 238 |
modified driver-core/src/main/java/com/datastax/driver/core/RequestHandler.java +68 −66
| @@ -15,6 +15,17 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | +import com.codahale.metrics.Timer; | |
| 19 | +import com.datastax.driver.core.exceptions.*; | |
| 20 | +import com.datastax.driver.core.policies.RetryPolicy; | |
| 21 | +import com.datastax.driver.core.policies.RetryPolicy.RetryDecision.Type; | |
| 22 | +import com.datastax.driver.core.policies.SpeculativeExecutionPolicy.SpeculativeExecutionPlan; | |
| 23 | +import com.google.common.collect.Sets; | |
| 24 | +import io.netty.util.Timeout; | |
| 25 | +import io.netty.util.TimerTask; | |
| 26 | +import org.slf4j.Logger; | |
| 27 | +import org.slf4j.LoggerFactory; | |
| 28 | + | |
| 18 | 29 | import java.net.InetSocketAddress; |
| 19 | 30 | import java.util.*; |
| 20 | 31 | import java.util.concurrent.ConcurrentHashMap; |
| @@ -25,18 +36,6 @@ | ||
| 25 | 36 | import java.util.concurrent.atomic.AtomicInteger; |
| 26 | 37 | import java.util.concurrent.atomic.AtomicReference; |
| 27 | 38 | |
| 28 | -import com.codahale.metrics.Timer; | |
| 29 | -import com.google.common.collect.Sets; | |
| 30 | -import io.netty.util.Timeout; | |
| 31 | -import io.netty.util.TimerTask; | |
| 32 | -import org.slf4j.Logger; | |
| 33 | -import org.slf4j.LoggerFactory; | |
| 34 | - | |
| 35 | -import com.datastax.driver.core.exceptions.*; | |
| 36 | -import com.datastax.driver.core.policies.RetryPolicy; | |
| 37 | -import com.datastax.driver.core.policies.RetryPolicy.RetryDecision.Type; | |
| 38 | -import com.datastax.driver.core.policies.SpeculativeExecutionPolicy.SpeculativeExecutionPlan; | |
| 39 | - | |
| 40 | 39 | /** |
| 41 | 40 | * Handles a request to cassandra, dealing with host failover and retries on |
| 42 | 41 | * unavailable/timeout. |
| @@ -69,7 +68,7 @@ | ||
| 69 | 68 | |
| 70 | 69 | public RequestHandler(SessionManager manager, Callback callback, Statement statement) { |
| 71 | 70 | this.id = Long.toString(System.identityHashCode(this)); |
| 72 | - if(logger.isTraceEnabled()) | |
| 71 | + if (logger.isTraceEnabled()) | |
| 73 | 72 | logger.trace("[{}] {}", id, statement); |
| 74 | 73 | this.manager = manager; |
| 75 | 74 | this.callback = callback; |
| @@ -80,12 +79,12 @@ | ||
| 80 | 79 | this.queryPlan = new QueryPlan(manager.loadBalancingPolicy().newQueryPlan(manager.poolsState.keyspace, statement)); |
| 81 | 80 | this.speculativeExecutionPlan = manager.speculativeRetryPolicy().newPlan(manager.poolsState.keyspace, statement); |
| 82 | 81 | this.allowSpeculativeExecutions = statement != Statement.DEFAULT |
| 83 | - && statement.isIdempotentWithDefault(manager.configuration().getQueryOptions()); | |
| 82 | + && statement.isIdempotentWithDefault(manager.configuration().getQueryOptions()); | |
| 84 | 83 | this.statement = statement; |
| 85 | 84 | |
| 86 | 85 | this.timerContext = metricsEnabled() |
| 87 | - ? metrics().getRequestsTimer().time() | |
| 88 | - : null; | |
| 86 | + ? metrics().getRequestsTimer().time() | |
| 87 | + : null; | |
| 89 | 88 | this.startTime = System.nanoTime(); |
| 90 | 89 | } |
| 91 | 90 | |
| @@ -120,7 +119,7 @@ | ||
| 120 | 119 | private void scheduleExecution(long delayMillis) { |
| 121 | 120 | if (isDone.get() || delayMillis <= 0) |
| 122 | 121 | return; |
| 123 | - if(logger.isTraceEnabled()) | |
| 122 | + if (logger.isTraceEnabled()) | |
| 124 | 123 | logger.trace("[{}] Schedule next speculative execution in {} ms", id, delayMillis); |
| 125 | 124 | scheduledExecutions.add(scheduler.newTimeout(newExecutionTask, delayMillis, TimeUnit.MILLISECONDS)); |
| 126 | 125 | } |
| @@ -159,12 +158,12 @@ | ||
| 159 | 158 | |
| 160 | 159 | private void setFinalResult(SpeculativeExecution execution, Connection connection, Message.Response response) { |
| 161 | 160 | if (!isDone.compareAndSet(false, true)) { |
| 162 | - if(logger.isTraceEnabled()) | |
| 161 | + if (logger.isTraceEnabled()) | |
| 163 | 162 | logger.trace("[{}] Got beaten to setting the result", execution.id); |
| 164 | 163 | return; |
| 165 | 164 | } |
| 166 | 165 | |
| 167 | - if(logger.isTraceEnabled()) | |
| 166 | + if (logger.isTraceEnabled()) | |
| 168 | 167 | logger.trace("[{}] Setting final result", execution.id); |
| 169 | 168 | |
| 170 | 169 | cancelPendingExecutions(execution); |
| @@ -183,19 +182,19 @@ | ||
| 183 | 182 | callback.onSet(connection, response, info, statement, System.nanoTime() - startTime); |
| 184 | 183 | } catch (Exception e) { |
| 185 | 184 | callback.onException(connection, |
| 186 | - new DriverInternalError("Unexpected exception while setting final result from " + response, e), | |
| 187 | - System.nanoTime() - startTime, /*unused*/0); | |
| 185 | + new DriverInternalError("Unexpected exception while setting final result from " + response, e), | |
| 186 | + System.nanoTime() - startTime, /*unused*/0); | |
| 188 | 187 | } |
| 189 | 188 | } |
| 190 | 189 | |
| 191 | 190 | private void setFinalException(SpeculativeExecution execution, Connection connection, Exception exception) { |
| 192 | 191 | if (!isDone.compareAndSet(false, true)) { |
| 193 | - if(logger.isTraceEnabled()) | |
| 192 | + if (logger.isTraceEnabled()) | |
| 194 | 193 | logger.trace("[{}] Got beaten to setting final exception", execution.id); |
| 195 | 194 | return; |
| 196 | 195 | } |
| 197 | 196 | |
| 198 | - if(logger.isTraceEnabled()) | |
| 197 | + if (logger.isTraceEnabled()) | |
| 199 | 198 | logger.trace("[{}] Setting final exception", execution.id); |
| 200 | 199 | |
| 201 | 200 | cancelPendingExecutions(execution); |
| @@ -214,7 +213,7 @@ | ||
| 214 | 213 | runningExecutions.remove(execution); |
| 215 | 214 | if (runningExecutions.isEmpty()) |
| 216 | 215 | setFinalException(execution, null, new NoHostAvailableException( |
| 217 | - errors == null ? Collections.<InetSocketAddress, Throwable>emptyMap() : errors)); | |
| 216 | + errors == null ? Collections.<InetSocketAddress, Throwable>emptyMap() : errors)); | |
| 218 | 217 | } |
| 219 | 218 | |
| 220 | 219 | private boolean metricsEnabled() { |
| @@ -227,6 +226,7 @@ | ||
| 227 | 226 | |
| 228 | 227 | interface Callback extends Connection.ResponseCallback { |
| 229 | 228 | void onSet(Connection connection, Message.Response response, ExecutionInfo info, Statement statement, long latency); |
| 229 | + | |
| 230 | 230 | void register(RequestHandler handler); |
| 231 | 231 | } |
| 232 | 232 | |
| @@ -260,7 +260,7 @@ | ||
| 260 | 260 | this.id = RequestHandler.this.id + "-" + position; |
| 261 | 261 | this.request = request; |
| 262 | 262 | this.queryStateRef = new AtomicReference<QueryState>(QueryState.INITIAL); |
| 263 | - if(logger.isTraceEnabled()) | |
| 263 | + if (logger.isTraceEnabled()) | |
| 264 | 264 | logger.trace("[{}] Starting", id); |
| 265 | 265 | } |
| 266 | 266 | |
| @@ -268,7 +268,7 @@ | ||
| 268 | 268 | try { |
| 269 | 269 | Host host; |
| 270 | 270 | while (!isDone.get() && (host = queryPlan.next()) != null && !queryStateRef.get().isCancelled()) { |
| 271 | - if(logger.isTraceEnabled()) | |
| 271 | + if (logger.isTraceEnabled()) | |
| 272 | 272 | logger.trace("[{}] Querying node {}", id, host); |
| 273 | 273 | if (query(host)) |
| 274 | 274 | return; |
| @@ -387,7 +387,7 @@ | ||
| 387 | 387 | if (previous.isCancelled()) { |
| 388 | 388 | return; |
| 389 | 389 | } else if (previous.inProgress && queryStateRef.compareAndSet(previous, QueryState.CANCELLED_WHILE_IN_PROGRESS)) { |
| 390 | - if(logger.isTraceEnabled()) | |
| 390 | + if (logger.isTraceEnabled()) | |
| 391 | 391 | logger.trace("[{}] Cancelled while in progress", id); |
| 392 | 392 | // The connectionHandler should be non-null, but we might miss the update if we're racing with write(). |
| 393 | 393 | // If it's still null, this will be handled by re-checking queryStateRef at the end of write(). |
| @@ -395,7 +395,7 @@ | ||
| 395 | 395 | connectionHandler.connection.release(); |
| 396 | 396 | return; |
| 397 | 397 | } else if (!previous.inProgress && queryStateRef.compareAndSet(previous, QueryState.CANCELLED_WHILE_COMPLETE)) { |
| 398 | - if(logger.isTraceEnabled()) | |
| 398 | + if (logger.isTraceEnabled()) | |
| 399 | 399 | logger.trace("[{}] Cancelled while complete", id); |
| 400 | 400 | return; |
| 401 | 401 | } |
| @@ -414,9 +414,9 @@ | ||
| 414 | 414 | public void onSet(Connection connection, Message.Response response, long latency, int retryCount) { |
| 415 | 415 | QueryState queryState = queryStateRef.get(); |
| 416 | 416 | if (!queryState.isInProgressAt(retryCount) || |
| 417 | - !queryStateRef.compareAndSet(queryState, queryState.complete())) { | |
| 417 | + !queryStateRef.compareAndSet(queryState, queryState.complete())) { | |
| 418 | 418 | logger.debug("onSet triggered but the response was completed by another thread, cancelling (retryCount = {}, queryState = {}, queryStateRef = {})", |
| 419 | - retryCount, queryState, queryStateRef.get()); | |
| 419 | + retryCount, queryState, queryStateRef.get()); | |
| 420 | 420 | return; |
| 421 | 421 | } |
| 422 | 422 | |
| @@ -429,12 +429,12 @@ | ||
| 429 | 429 | setFinalResult(connection, response); |
| 430 | 430 | break; |
| 431 | 431 | case ERROR: |
| 432 | - Responses.Error err = (Responses.Error)response; | |
| 432 | + Responses.Error err = (Responses.Error) response; | |
| 433 | 433 | exceptionToReport = err.asException(connection.address); |
| 434 | 434 | RetryPolicy.RetryDecision retry = null; |
| 435 | 435 | RetryPolicy retryPolicy = statement.getRetryPolicy() == null |
| 436 | - ? manager.configuration().getPolicies().getRetryPolicy() | |
| 437 | - : statement.getRetryPolicy(); | |
| 436 | + ? manager.configuration().getPolicies().getRetryPolicy() | |
| 437 | + : statement.getRetryPolicy(); | |
| 438 | 438 | switch (err.code) { |
| 439 | 439 | case READ_TIMEOUT: |
| 440 | 440 | connection.release(); |
| @@ -442,13 +442,13 @@ | ||
| 442 | 442 | if (metricsEnabled()) |
| 443 | 443 | metrics().getErrorMetrics().getReadTimeouts().inc(); |
| 444 | 444 | |
| 445 | - ReadTimeoutException rte = (ReadTimeoutException)err.infos; | |
| 445 | + ReadTimeoutException rte = (ReadTimeoutException) err.infos; | |
| 446 | 446 | retry = retryPolicy.onReadTimeout(statement, |
| 447 | - rte.getConsistencyLevel(), | |
| 448 | - rte.getRequiredAcknowledgements(), | |
| 449 | - rte.getReceivedAcknowledgements(), | |
| 450 | - rte.wasDataRetrieved(), | |
| 451 | - retriesByPolicy); | |
| 447 | + rte.getConsistencyLevel(), | |
| 448 | + rte.getRequiredAcknowledgements(), | |
| 449 | + rte.getReceivedAcknowledgements(), | |
| 450 | + rte.wasDataRetrieved(), | |
| 451 | + retriesByPolicy); | |
| 452 | 452 | |
| 453 | 453 | if (metricsEnabled()) { |
| 454 | 454 | if (retry.getType() == Type.RETRY) |
| @@ -463,13 +463,13 @@ | ||
| 463 | 463 | if (metricsEnabled()) |
| 464 | 464 | metrics().getErrorMetrics().getWriteTimeouts().inc(); |
| 465 | 465 | |
| 466 | - WriteTimeoutException wte = (WriteTimeoutException)err.infos; | |
| 466 | + WriteTimeoutException wte = (WriteTimeoutException) err.infos; | |
| 467 | 467 | retry = retryPolicy.onWriteTimeout(statement, |
| 468 | - wte.getConsistencyLevel(), | |
| 469 | - wte.getWriteType(), | |
| 470 | - wte.getRequiredAcknowledgements(), | |
| 471 | - wte.getReceivedAcknowledgements(), | |
| 472 | - retriesByPolicy); | |
| 468 | + wte.getConsistencyLevel(), | |
| 469 | + wte.getWriteType(), | |
| 470 | + wte.getRequiredAcknowledgements(), | |
| 471 | + wte.getReceivedAcknowledgements(), | |
| 472 | + retriesByPolicy); | |
| 473 | 473 | |
| 474 | 474 | if (metricsEnabled()) { |
| 475 | 475 | if (retry.getType() == Type.RETRY) |
| @@ -484,12 +484,12 @@ | ||
| 484 | 484 | if (metricsEnabled()) |
| 485 | 485 | metrics().getErrorMetrics().getUnavailables().inc(); |
| 486 | 486 | |
| 487 | - UnavailableException ue = (UnavailableException)err.infos; | |
| 487 | + UnavailableException ue = (UnavailableException) err.infos; | |
| 488 | 488 | retry = retryPolicy.onUnavailable(statement, |
| 489 | - ue.getConsistencyLevel(), | |
| 490 | - ue.getRequiredReplicas(), | |
| 491 | - ue.getAliveReplicas(), | |
| 492 | - retriesByPolicy); | |
| 489 | + ue.getConsistencyLevel(), | |
| 490 | + ue.getRequiredReplicas(), | |
| 491 | + ue.getAliveReplicas(), | |
| 492 | + retriesByPolicy); | |
| 493 | 493 | |
| 494 | 494 | if (metricsEnabled()) { |
| 495 | 495 | if (retry.getType() == Type.RETRY) |
| @@ -532,7 +532,7 @@ | ||
| 532 | 532 | case UNPREPARED: |
| 533 | 533 | // Do not release connection yet, because we might reuse it to send the PREPARE message (see write() call below) |
| 534 | 534 | assert err.infos instanceof MD5Digest; |
| 535 | - MD5Digest id = (MD5Digest)err.infos; | |
| 535 | + MD5Digest id = (MD5Digest) err.infos; | |
| 536 | 536 | PreparedStatement toPrepare = manager.cluster.manager.preparedQueries.get(id); |
| 537 | 537 | if (toPrepare == null) { |
| 538 | 538 | // This shouldn't happen |
| @@ -552,12 +552,12 @@ | ||
| 552 | 552 | // that's shared with other requests). |
| 553 | 553 | connection.release(); |
| 554 | 554 | throw new IllegalStateException(String.format("Statement was prepared on keyspace %s, can't execute it on %s (%s)", |
| 555 | - toPrepare.getQueryKeyspace(), connection.keyspace(), toPrepare.getQueryString())); | |
| 555 | + toPrepare.getQueryKeyspace(), connection.keyspace(), toPrepare.getQueryString())); | |
| 556 | 556 | } |
| 557 | 557 | |
| 558 | 558 | logger.info("Query {} is not prepared on {}, preparing before retrying executing. " |
| 559 | - + "Seeing this message a few times is fine, but seeing it a lot may be source of performance problems", | |
| 560 | - toPrepare.getQueryString(), connection.address); | |
| 559 | + + "Seeing this message a few times is fine, but seeing it a lot may be source of performance problems", | |
| 560 | + toPrepare.getQueryString(), connection.address); | |
| 561 | 561 | |
| 562 | 562 | write(connection, prepareAndRetry(toPrepare.getQueryString())); |
| 563 | 563 | // we're done for now, the prepareAndRetry callback will handle the rest |
| @@ -625,9 +625,9 @@ | ||
| 625 | 625 | public void onSet(Connection connection, Message.Response response, long latency, int retryCount) { |
| 626 | 626 | QueryState queryState = queryStateRef.get(); |
| 627 | 627 | if (!queryState.isInProgressAt(retryCount) || |
| 628 | - !queryStateRef.compareAndSet(queryState, queryState.complete())) { | |
| 628 | + !queryStateRef.compareAndSet(queryState, queryState.complete())) { | |
| 629 | 629 | logger.debug("onSet triggered but the response was completed by another thread, cancelling (retryCount = {}, queryState = {}, queryStateRef = {})", |
| 630 | - retryCount, queryState, queryStateRef.get()); | |
| 630 | + retryCount, queryState, queryStateRef.get()); | |
| 631 | 631 | return; |
| 632 | 632 | } |
| 633 | 633 | |
| @@ -636,7 +636,7 @@ | ||
| 636 | 636 | // TODO should we check the response ? |
| 637 | 637 | switch (response.type) { |
| 638 | 638 | case RESULT: |
| 639 | - if (((Responses.Result)response).kind == Responses.Result.Kind.PREPARED) { | |
| 639 | + if (((Responses.Result) response).kind == Responses.Result.Kind.PREPARED) { | |
| 640 | 640 | logger.debug("Scheduling retry now that query is prepared"); |
| 641 | 641 | retry(true, null); |
| 642 | 642 | } else { |
| @@ -666,9 +666,9 @@ | ||
| 666 | 666 | public boolean onTimeout(Connection connection, long latency, int retryCount) { |
| 667 | 667 | QueryState queryState = queryStateRef.get(); |
| 668 | 668 | if (!queryState.isInProgressAt(retryCount) || |
| 669 | - !queryStateRef.compareAndSet(queryState, queryState.complete())) { | |
| 669 | + !queryStateRef.compareAndSet(queryState, queryState.complete())) { | |
| 670 | 670 | logger.debug("onTimeout triggered but the response was completed by another thread, cancelling (retryCount = {}, queryState = {}, queryStateRef = {})", |
| 671 | - retryCount, queryState, queryStateRef.get()); | |
| 671 | + retryCount, queryState, queryStateRef.get()); | |
| 672 | 672 | return false; |
| 673 | 673 | } |
| 674 | 674 | connection.release(); |
| @@ -683,9 +683,9 @@ | ||
| 683 | 683 | public void onException(Connection connection, Exception exception, long latency, int retryCount) { |
| 684 | 684 | QueryState queryState = queryStateRef.get(); |
| 685 | 685 | if (!queryState.isInProgressAt(retryCount) || |
| 686 | - !queryStateRef.compareAndSet(queryState, queryState.complete())) { | |
| 686 | + !queryStateRef.compareAndSet(queryState, queryState.complete())) { | |
| 687 | 687 | logger.debug("onException triggered but the response was completed by another thread, cancelling (retryCount = {}, queryState = {}, queryStateRef = {})", |
| 688 | - retryCount, queryState, queryStateRef.get()); | |
| 688 | + retryCount, queryState, queryStateRef.get()); | |
| 689 | 689 | return; |
| 690 | 690 | } |
| 691 | 691 | |
| @@ -696,7 +696,7 @@ | ||
| 696 | 696 | if (exception instanceof ConnectionException) { |
| 697 | 697 | if (metricsEnabled()) |
| 698 | 698 | metrics().getErrorMetrics().getConnectionErrors().inc(); |
| 699 | - ConnectionException ce = (ConnectionException)exception; | |
| 699 | + ConnectionException ce = (ConnectionException) exception; | |
| 700 | 700 | logError(ce.address, ce); |
| 701 | 701 | retry(false, null); |
| 702 | 702 | return; |
| @@ -715,9 +715,9 @@ | ||
| 715 | 715 | public boolean onTimeout(Connection connection, long latency, int retryCount) { |
| 716 | 716 | QueryState queryState = queryStateRef.get(); |
| 717 | 717 | if (!queryState.isInProgressAt(retryCount) || |
| 718 | - !queryStateRef.compareAndSet(queryState, queryState.complete())) { | |
| 718 | + !queryStateRef.compareAndSet(queryState, queryState.complete())) { | |
| 719 | 719 | logger.debug("onTimeout triggered but the response was completed by another thread, cancelling (retryCount = {}, queryState = {}, queryStateRef = {})", |
| 720 | - retryCount, queryState, queryStateRef.get()); | |
| 720 | + retryCount, queryState, queryStateRef.get()); | |
| 721 | 721 | return false; |
| 722 | 722 | } |
| 723 | 723 | |
| @@ -754,7 +754,7 @@ | ||
| 754 | 754 | |
| 755 | 755 | /** |
| 756 | 756 | * The state of a SpeculativeExecution. |
| 757 | - * | |
| 757 | + * <p/> | |
| 758 | 758 | * This is used to prevent races between request completion (either success or error) and timeout. |
| 759 | 759 | * A retry is in progress once we have written the request to the connection and until we get back a response (see onSet |
| 760 | 760 | * or onException) or a timeout (see onTimeout). |
| @@ -808,7 +808,9 @@ | ||
| 808 | 808 | this.iterator = iterator; |
| 809 | 809 | } |
| 810 | 810 | |
| 811 | - /** @return null if there are no more hosts */ | |
| 811 | + /** | |
| 812 | + * @return null if there are no more hosts | |
| 813 | + */ | |
| 812 | 814 | synchronized Host next() { |
| 813 | 815 | return iterator.hasNext() ? iterator.next() : null; |
| 814 | 816 | } |
modified driver-core/src/main/java/com/datastax/driver/core/Requests.java +44 −40
| @@ -15,18 +15,19 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | +import com.google.common.collect.ImmutableMap; | |
| 19 | +import io.netty.buffer.ByteBuf; | |
| 20 | + | |
| 18 | 21 | import java.nio.ByteBuffer; |
| 19 | 22 | import java.util.Collections; |
| 20 | 23 | import java.util.EnumSet; |
| 21 | 24 | import java.util.List; |
| 22 | 25 | import java.util.Map; |
| 23 | 26 | |
| 24 | -import com.google.common.collect.ImmutableMap; | |
| 25 | -import io.netty.buffer.ByteBuf; | |
| 26 | - | |
| 27 | 27 | class Requests { |
| 28 | 28 | |
| 29 | - private Requests() {} | |
| 29 | + private Requests() { | |
| 30 | + } | |
| 30 | 31 | |
| 31 | 32 | public static class Startup extends Message.Request { |
| 32 | 33 | private static final String CQL_VERSION_OPTION = "CQL_VERSION"; |
| @@ -86,9 +87,9 @@ | ||
| 86 | 87 | |
| 87 | 88 | public static class Options extends Message.Request { |
| 88 | 89 | |
| 89 | - public static final Message.Coder<Options> coder = new Message.Coder<Options>() | |
| 90 | - { | |
| 91 | - public void encode(Options msg, ByteBuf dest) {} | |
| 90 | + public static final Message.Coder<Options> coder = new Message.Coder<Options>() { | |
| 91 | + public void encode(Options msg, ByteBuf dest) { | |
| 92 | + } | |
| 92 | 93 | |
| 93 | 94 | public int encodedSize(Options msg) { |
| 94 | 95 | return 0; |
| @@ -115,7 +116,7 @@ | ||
| 115 | 116 | |
| 116 | 117 | public int encodedSize(Query msg) { |
| 117 | 118 | return CBUtil.sizeOfLongString(msg.query) |
| 118 | - + CBUtil.sizeOfConsistencyLevel(msg.options.consistency); | |
| 119 | + + CBUtil.sizeOfConsistencyLevel(msg.options.consistency); | |
| 119 | 120 | } |
| 120 | 121 | }; |
| 121 | 122 | |
| @@ -127,7 +128,7 @@ | ||
| 127 | 128 | |
| 128 | 129 | public int encodedSize(Query msg) { |
| 129 | 130 | return CBUtil.sizeOfLongString(msg.query) |
| 130 | - + msg.options.encodedSize(); | |
| 131 | + + msg.options.encodedSize(); | |
| 131 | 132 | } |
| 132 | 133 | }; |
| 133 | 134 | |
| @@ -171,8 +172,8 @@ | ||
| 171 | 172 | |
| 172 | 173 | public int encodedSize(Execute msg) { |
| 173 | 174 | return CBUtil.sizeOfBytes(msg.statementId.bytes) |
| 174 | - + CBUtil.sizeOfValueList(msg.options.values) | |
| 175 | - + CBUtil.sizeOfConsistencyLevel(msg.options.consistency); | |
| 175 | + + CBUtil.sizeOfValueList(msg.options.values) | |
| 176 | + + CBUtil.sizeOfConsistencyLevel(msg.options.consistency); | |
| 176 | 177 | } |
| 177 | 178 | }; |
| 178 | 179 | |
| @@ -184,7 +185,7 @@ | ||
| 184 | 185 | |
| 185 | 186 | public int encodedSize(Execute msg) { |
| 186 | 187 | return CBUtil.sizeOfBytes(msg.statementId.bytes) |
| 187 | - + msg.options.encodedSize(); | |
| 188 | + + msg.options.encodedSize(); | |
| 188 | 189 | } |
| 189 | 190 | }; |
| 190 | 191 | |
| @@ -226,8 +227,7 @@ | ||
| 226 | 227 | public static EnumSet<Flag> deserialize(int flags) { |
| 227 | 228 | EnumSet<Flag> set = EnumSet.noneOf(Flag.class); |
| 228 | 229 | Flag[] values = Flag.values(); |
| 229 | - for (int n = 0; n < values.length; n++) | |
| 230 | - { | |
| 230 | + for (int n = 0; n < values.length; n++) { | |
| 231 | 231 | if ((flags & (1 << n)) != 0) |
| 232 | 232 | set.add(values[n]); |
| 233 | 233 | } |
| @@ -243,11 +243,11 @@ | ||
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | public static final QueryProtocolOptions DEFAULT = new QueryProtocolOptions(ConsistencyLevel.ONE, |
| 246 | - Collections.<ByteBuffer>emptyList(), | |
| 247 | - false, | |
| 248 | - -1, | |
| 249 | - null, | |
| 250 | - ConsistencyLevel.SERIAL); | |
| 246 | + Collections.<ByteBuffer>emptyList(), | |
| 247 | + false, | |
| 248 | + -1, | |
| 249 | + null, | |
| 250 | + ConsistencyLevel.SERIAL); | |
| 251 | 251 | |
| 252 | 252 | private final EnumSet<Flag> flags = EnumSet.noneOf(Flag.class); |
| 253 | 253 | public final ConsistencyLevel consistency; |
| @@ -291,7 +291,7 @@ | ||
| 291 | 291 | public void encode(ByteBuf dest) { |
| 292 | 292 | CBUtil.writeConsistencyLevel(consistency, dest); |
| 293 | 293 | |
| 294 | - dest.writeByte((byte)Flag.serialize(flags)); | |
| 294 | + dest.writeByte((byte) Flag.serialize(flags)); | |
| 295 | 295 | |
| 296 | 296 | if (flags.contains(Flag.VALUES)) |
| 297 | 297 | CBUtil.writeValueList(values, dest); |
| @@ -304,17 +304,17 @@ | ||
| 304 | 304 | } |
| 305 | 305 | |
| 306 | 306 | public int encodedSize() { |
| 307 | - int size = CBUtil.sizeOfConsistencyLevel(consistency) + 1; | |
| 308 | - | |
| 309 | - if (flags.contains(Flag.VALUES)) | |
| 310 | - size += CBUtil.sizeOfValueList(values); | |
| 311 | - if (flags.contains(Flag.PAGE_SIZE)) | |
| 312 | - size += 4; | |
| 313 | - if (flags.contains(Flag.PAGING_STATE)) | |
| 314 | - size += CBUtil.sizeOfValue(pagingState); | |
| 315 | - if (flags.contains(Flag.SERIAL_CONSISTENCY)) | |
| 316 | - size += CBUtil.sizeOfConsistencyLevel(serialConsistency); | |
| 317 | - return size; | |
| 307 | + int size = CBUtil.sizeOfConsistencyLevel(consistency) + 1; | |
| 308 | + | |
| 309 | + if (flags.contains(Flag.VALUES)) | |
| 310 | + size += CBUtil.sizeOfValueList(values); | |
| 311 | + if (flags.contains(Flag.PAGE_SIZE)) | |
| 312 | + size += 4; | |
| 313 | + if (flags.contains(Flag.PAGING_STATE)) | |
| 314 | + size += CBUtil.sizeOfValue(pagingState); | |
| 315 | + if (flags.contains(Flag.SERIAL_CONSISTENCY)) | |
| 316 | + size += CBUtil.sizeOfConsistencyLevel(serialConsistency); | |
| 317 | + return size; | |
| 318 | 318 | } |
| 319 | 319 | |
| 320 | 320 | @Override |
| @@ -335,11 +335,11 @@ | ||
| 335 | 335 | |
| 336 | 336 | for (int i = 0; i < queries; i++) { |
| 337 | 337 | Object q = msg.queryOrIdList.get(i); |
| 338 | - dest.writeByte((byte)(q instanceof String ? 0 : 1)); | |
| 338 | + dest.writeByte((byte) (q instanceof String ? 0 : 1)); | |
| 339 | 339 | if (q instanceof String) |
| 340 | - CBUtil.writeLongString((String)q, dest); | |
| 340 | + CBUtil.writeLongString((String) q, dest); | |
| 341 | 341 | else |
| 342 | - CBUtil.writeBytes(((MD5Digest)q).bytes, dest); | |
| 342 | + CBUtil.writeBytes(((MD5Digest) q).bytes, dest); | |
| 343 | 343 | |
| 344 | 344 | CBUtil.writeValueList(msg.values.get(i), dest); |
| 345 | 345 | } |
| @@ -352,8 +352,8 @@ | ||
| 352 | 352 | for (int i = 0; i < msg.queryOrIdList.size(); i++) { |
| 353 | 353 | Object q = msg.queryOrIdList.get(i); |
| 354 | 354 | size += 1 + (q instanceof String |
| 355 | - ? CBUtil.sizeOfLongString((String)q) | |
| 356 | - : CBUtil.sizeOfBytes(((MD5Digest)q).bytes)); | |
| 355 | + ? CBUtil.sizeOfLongString((String) q) | |
| 356 | + : CBUtil.sizeOfBytes(((MD5Digest) q).bytes)); | |
| 357 | 357 | |
| 358 | 358 | size += CBUtil.sizeOfValueList(msg.values.get(i)); |
| 359 | 359 | } |
| @@ -363,10 +363,14 @@ | ||
| 363 | 363 | |
| 364 | 364 | private byte fromType(BatchStatement.Type type) { |
| 365 | 365 | switch (type) { |
| 366 | - case LOGGED: return 0; | |
| 367 | - case UNLOGGED: return 1; | |
| 368 | - case COUNTER: return 2; | |
| 369 | - default: throw new AssertionError(); | |
| 366 | + case LOGGED: | |
| 367 | + return 0; | |
| 368 | + case UNLOGGED: | |
| 369 | + return 1; | |
| 370 | + case COUNTER: | |
| 371 | + return 2; | |
| 372 | + default: | |
| 373 | + throw new AssertionError(); | |
| 370 | 374 | } |
| 371 | 375 | } |
| 372 | 376 | }; |
modified driver-core/src/main/java/com/datastax/driver/core/Responses.java +46 −31
| @@ -15,18 +15,18 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.exceptions.*; | |
| 19 | +import com.datastax.driver.core.utils.Bytes; | |
| 20 | +import io.netty.buffer.ByteBuf; | |
| 21 | + | |
| 18 | 22 | import java.net.InetSocketAddress; |
| 19 | 23 | import java.nio.ByteBuffer; |
| 20 | 24 | import java.util.*; |
| 21 | 25 | |
| 22 | -import io.netty.buffer.ByteBuf; | |
| 23 | - | |
| 24 | -import com.datastax.driver.core.exceptions.*; | |
| 25 | -import com.datastax.driver.core.utils.Bytes; | |
| 26 | - | |
| 27 | 26 | class Responses { |
| 28 | 27 | |
| 29 | - private Responses() {} | |
| 28 | + private Responses() { | |
| 29 | + } | |
| 30 | 30 | |
| 31 | 31 | public static class Error extends Message.Response { |
| 32 | 32 | |
| @@ -82,22 +82,38 @@ | ||
| 82 | 82 | |
| 83 | 83 | public DriverException asException(InetSocketAddress host) { |
| 84 | 84 | switch (code) { |
| 85 | - case SERVER_ERROR: return new ServerError(host, message); | |
| 86 | - case PROTOCOL_ERROR: return new ProtocolError(host, message); | |
| 87 | - case BAD_CREDENTIALS: return new AuthenticationException(host, message); | |
| 88 | - case UNAVAILABLE: return ((UnavailableException)infos).copy(host); // We copy to have a nice stack trace | |
| 89 | - case OVERLOADED: return new OverloadedException(host, message); | |
| 90 | - case IS_BOOTSTRAPPING: return new BootstrappingException(host, message); | |
| 91 | - case TRUNCATE_ERROR: return new TruncateException(host, message); | |
| 92 | - case WRITE_TIMEOUT: return ((WriteTimeoutException)infos).copy(host); | |
| 93 | - case READ_TIMEOUT: return ((ReadTimeoutException)infos).copy(host); | |
| 94 | - case SYNTAX_ERROR: return new SyntaxError(host, message); | |
| 95 | - case UNAUTHORIZED: return new UnauthorizedException(host, message); | |
| 96 | - case INVALID: return new InvalidQueryException(host, message); | |
| 97 | - case CONFIG_ERROR: return new InvalidConfigurationInQueryException(host, message); | |
| 98 | - case ALREADY_EXISTS: return ((AlreadyExistsException)infos).copy(host); | |
| 99 | - case UNPREPARED: return new UnpreparedException(host, message); | |
| 100 | - default: return new DriverInternalError(String.format("Unknown protocol error code %s returned by %s. The error message was: %s", code, host, message)); | |
| 85 | + case SERVER_ERROR: | |
| 86 | + return new ServerError(host, message); | |
| 87 | + case PROTOCOL_ERROR: | |
| 88 | + return new ProtocolError(host, message); | |
| 89 | + case BAD_CREDENTIALS: | |
| 90 | + return new AuthenticationException(host, message); | |
| 91 | + case UNAVAILABLE: | |
| 92 | + return ((UnavailableException) infos).copy(host); // We copy to have a nice stack trace | |
| 93 | + case OVERLOADED: | |
| 94 | + return new OverloadedException(host, message); | |
| 95 | + case IS_BOOTSTRAPPING: | |
| 96 | + return new BootstrappingException(host, message); | |
| 97 | + case TRUNCATE_ERROR: | |
| 98 | + return new TruncateException(host, message); | |
| 99 | + case WRITE_TIMEOUT: | |
| 100 | + return ((WriteTimeoutException) infos).copy(host); | |
| 101 | + case READ_TIMEOUT: | |
| 102 | + return ((ReadTimeoutException) infos).copy(host); | |
| 103 | + case SYNTAX_ERROR: | |
| 104 | + return new SyntaxError(host, message); | |
| 105 | + case UNAUTHORIZED: | |
| 106 | + return new UnauthorizedException(host, message); | |
| 107 | + case INVALID: | |
| 108 | + return new InvalidQueryException(host, message); | |
| 109 | + case CONFIG_ERROR: | |
| 110 | + return new InvalidConfigurationInQueryException(host, message); | |
| 111 | + case ALREADY_EXISTS: | |
| 112 | + return ((AlreadyExistsException) infos).copy(host); | |
| 113 | + case UNPREPARED: | |
| 114 | + return new UnpreparedException(host, message); | |
| 115 | + default: | |
| 116 | + return new DriverInternalError(String.format("Unknown protocol error code %s returned by %s. The error message was: %s", code, host, message)); | |
| 101 | 117 | } |
| 102 | 118 | } |
| 103 | 119 | |
| @@ -202,10 +218,10 @@ | ||
| 202 | 218 | }; |
| 203 | 219 | |
| 204 | 220 | public enum Kind { |
| 205 | - VOID (1, Void.subcodec, Void.subcodec), | |
| 206 | - ROWS (2, Rows.subcodec, Rows.subcodec), | |
| 207 | - SET_KEYSPACE (3, SetKeyspace.subcodec, SetKeyspace.subcodec), | |
| 208 | - PREPARED (4, Prepared.subcodecV1, Prepared.subcodecV2), | |
| 221 | + VOID(1, Void.subcodec, Void.subcodec), | |
| 222 | + ROWS(2, Rows.subcodec, Rows.subcodec), | |
| 223 | + SET_KEYSPACE(3, SetKeyspace.subcodec, SetKeyspace.subcodec), | |
| 224 | + PREPARED(4, Prepared.subcodecV1, Prepared.subcodecV2), | |
| 209 | 225 | SCHEMA_CHANGE(5, SchemaChange.subcodec, SchemaChange.subcodec); |
| 210 | 226 | |
| 211 | 227 | private final int id; |
| @@ -213,6 +229,7 @@ | ||
| 213 | 229 | private final Message.Decoder<Result> subDecoderV2; |
| 214 | 230 | |
| 215 | 231 | private static final Kind[] ids; |
| 232 | + | |
| 216 | 233 | static { |
| 217 | 234 | int maxId = -1; |
| 218 | 235 | for (Kind k : Kind.values()) |
| @@ -289,8 +306,7 @@ | ||
| 289 | 306 | |
| 290 | 307 | public static class Metadata { |
| 291 | 308 | |
| 292 | - private static enum Flag | |
| 293 | - { | |
| 309 | + private static enum Flag { | |
| 294 | 310 | // The order of that enum matters!! |
| 295 | 311 | GLOBAL_TABLES_SPEC, |
| 296 | 312 | HAS_MORE_PAGES, |
| @@ -470,15 +486,14 @@ | ||
| 470 | 486 | |
| 471 | 487 | public static class SchemaChange extends Result { |
| 472 | 488 | |
| 473 | - public enum Change { CREATED, UPDATED, DROPPED } | |
| 489 | + public enum Change {CREATED, UPDATED, DROPPED} | |
| 474 | 490 | |
| 475 | 491 | public final Change change; |
| 476 | 492 | public final String keyspace; |
| 477 | 493 | public final String columnFamily; |
| 478 | 494 | |
| 479 | 495 | public static final Message.Decoder<Result> subcodec = new Message.Decoder<Result>() { |
| 480 | - public Result decode(ByteBuf body) | |
| 481 | - { | |
| 496 | + public Result decode(ByteBuf body) { | |
| 482 | 497 | Change change = CBUtil.readEnumValue(Change.class, body); |
| 483 | 498 | String keyspace = CBUtil.readString(body); |
| 484 | 499 | String columnFamily = CBUtil.readString(body); |
modified driver-core/src/main/java/com/datastax/driver/core/ResultSet.java +18 −19
| @@ -16,14 +16,14 @@ | ||
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | 18 | |
| 19 | +import com.google.common.util.concurrent.ListenableFuture; | |
| 20 | + | |
| 19 | 21 | import java.util.Iterator; |
| 20 | 22 | import java.util.List; |
| 21 | 23 | |
| 22 | -import com.google.common.util.concurrent.ListenableFuture; | |
| 23 | - | |
| 24 | 24 | /** |
| 25 | 25 | * The result of a query. |
| 26 | - * <p> | |
| 26 | + * <p/> | |
| 27 | 27 | * The retrieval of the rows of a ResultSet is generally paged (a first page |
| 28 | 28 | * of result is fetched and the next one is only fetched once all the results |
| 29 | 29 | * of the first one has been consumed). The size of the pages can be configured |
| @@ -36,7 +36,7 @@ | ||
| 36 | 36 | * through {@link Cluster.Builder#withProtocolVersion}). If the protocol version 1 |
| 37 | 37 | * is in use, a ResultSet is always fetched in it's entirely and it's up to the |
| 38 | 38 | * client to make sure that no query can yield ResultSet that won't hold in memory. |
| 39 | - * <p> | |
| 39 | + * <p/> | |
| 40 | 40 | * Note that this class is not thread-safe. |
| 41 | 41 | */ |
| 42 | 42 | public interface ResultSet extends Iterable<Row> { |
| @@ -65,7 +65,7 @@ | ||
| 65 | 65 | |
| 66 | 66 | /** |
| 67 | 67 | * Returns all the remaining rows in this ResultSet as a list. |
| 68 | - * <p> | |
| 68 | + * <p/> | |
| 69 | 69 | * Note that, contrary to {@code iterator()} or successive calls to |
| 70 | 70 | * {@code one()}, this method forces fetching the full content of the ResultSet |
| 71 | 71 | * at once, holding it all in memory in particular. It is thus recommended |
| @@ -80,11 +80,11 @@ | ||
| 80 | 80 | |
| 81 | 81 | /** |
| 82 | 82 | * Returns an iterator over the rows contained in this ResultSet. |
| 83 | - * | |
| 83 | + * <p/> | |
| 84 | 84 | * The {@link Iterator#next} method is equivalent to calling {@link #one}. |
| 85 | 85 | * So this iterator will consume results from this ResultSet and after a |
| 86 | 86 | * full iteration, the ResultSet will be empty. |
| 87 | - * | |
| 87 | + * <p/> | |
| 88 | 88 | * The returned iterator does not support the {@link Iterator#remove} method. |
| 89 | 89 | * |
| 90 | 90 | * @return an iterator that will consume and return the remaining rows of |
| @@ -106,7 +106,7 @@ | ||
| 106 | 106 | /** |
| 107 | 107 | * Whether all results from this result set have been fetched from the |
| 108 | 108 | * database. |
| 109 | - * <p> | |
| 109 | + * <p/> | |
| 110 | 110 | * Note that if {@code isFullyFetched()}, then {@link #getAvailableWithoutFetching} |
| 111 | 111 | * will return how many rows remain in the result set before exhaustion. But |
| 112 | 112 | * please note that {@code !isFullyFetched()} never guarantees that the result set |
| @@ -118,12 +118,12 @@ | ||
| 118 | 118 | |
| 119 | 119 | /** |
| 120 | 120 | * Force fetching the next page of results for this result set, if any. |
| 121 | - * <p> | |
| 121 | + * <p/> | |
| 122 | 122 | * This method is entirely optional. It will be called automatically while |
| 123 | 123 | * the result set is consumed (through {@link #one}, {@link #all} or iteration) |
| 124 | 124 | * when needed (i.e. when {@code getAvailableWithoutFetching() == 0} and |
| 125 | 125 | * {@code isFullyFetched() == false}). |
| 126 | - * <p> | |
| 126 | + * <p/> | |
| 127 | 127 | * You can however call this method manually to force the fetching of the |
| 128 | 128 | * next page of results. This can allow to prefetch results before they are |
| 129 | 129 | * strictly needed. For instance, if you want to prefetch the next page of |
| @@ -143,7 +143,7 @@ | ||
| 143 | 143 | * fetchMoreResults} will not block the processing of the 100 currently available |
| 144 | 144 | * rows (but {@code iter.hasNext()} will block once those rows have been processed |
| 145 | 145 | * until the fetch query returns, if it hasn't yet). |
| 146 | - * <p> | |
| 146 | + * <p/> | |
| 147 | 147 | * Only one page of results (for a given result set) can be |
| 148 | 148 | * fetched at any given time. If this method is called twice and the query |
| 149 | 149 | * triggered by the first call has not returned yet when the second one is |
| @@ -160,12 +160,12 @@ | ||
| 160 | 160 | |
| 161 | 161 | /** |
| 162 | 162 | * Returns information on the execution of the last query made for this ResultSet. |
| 163 | - * <p> | |
| 163 | + * <p/> | |
| 164 | 164 | * Note that in most cases, a ResultSet is fetched with only one query, but large |
| 165 | 165 | * result sets can be paged and thus be retrieved by multiple queries. In that |
| 166 | 166 | * case this method return the {@code ExecutionInfo} for the last query |
| 167 | 167 | * performed. To retrieve the information for all queries, use {@link #getAllExecutionInfo}. |
| 168 | - * <p> | |
| 168 | + * <p/> | |
| 169 | 169 | * The returned object includes basic information such as the queried hosts, |
| 170 | 170 | * but also the Cassandra query trace if tracing was enabled for the query. |
| 171 | 171 | * |
| @@ -176,7 +176,7 @@ | ||
| 176 | 176 | /** |
| 177 | 177 | * Return the execution information for all queries made to retrieve this |
| 178 | 178 | * ResultSet. |
| 179 | - * <p> | |
| 179 | + * <p/> | |
| 180 | 180 | * Unless the ResultSet is large enough to get paged underneath, the returned |
| 181 | 181 | * list will be singleton. If paging has been used however, the returned list |
| 182 | 182 | * contains the {@code ExecutionInfo} for all the queries done to obtain this |
| @@ -189,26 +189,25 @@ | ||
| 189 | 189 | /** |
| 190 | 190 | * If the query that produced this ResultSet was a conditional update, |
| 191 | 191 | * return whether it was successfully applied. |
| 192 | - * <p> | |
| 192 | + * <p/> | |
| 193 | 193 | * This is equivalent to calling: |
| 194 | - * | |
| 194 | + * <p/> | |
| 195 | 195 | * <pre> |
| 196 | 196 | * rs.one().getBool("[applied]"); |
| 197 | 197 | * </pre> |
| 198 | - * <p> | |
| 198 | + * <p/> | |
| 199 | 199 | * For consistency, this method always returns {@code true} for |
| 200 | 200 | * non-conditional queries (although there is no reason to call the method |
| 201 | 201 | * in that case). This is also the case for conditional DDL statements |
| 202 | 202 | * ({@code CREATE KEYSPACE... IF NOT EXISTS}, {@code CREATE TABLE... IF NOT EXISTS}), |
| 203 | 203 | * for which Cassandra doesn't return an {@code [applied]} column. |
| 204 | - * <p> | |
| 204 | + * <p/> | |
| 205 | 205 | * Note that, for versions of Cassandra strictly lower than 2.0.9 and 2.1.0-rc2, |
| 206 | 206 | * a server-side bug (CASSANDRA-7337) causes this method to always return |
| 207 | 207 | * {@code true} for batches containing conditional queries. |
| 208 | 208 | * |
| 209 | 209 | * @return if the query was a conditional update, whether it was applied. |
| 210 | 210 | * {@code true} for other types of queries. |
| 211 | - * | |
| 212 | 211 | * @see <a href="https://issues.apache.org/jira/browse/CASSANDRA-7337">CASSANDRA-7337</a> |
| 213 | 212 | */ |
| 214 | 213 | public boolean wasApplied(); |
modified driver-core/src/main/java/com/datastax/driver/core/ResultSetFuture.java +32 −35
| @@ -15,18 +15,17 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.util.concurrent.TimeUnit; | |
| 19 | -import java.util.concurrent.TimeoutException; | |
| 20 | - | |
| 21 | -import com.google.common.util.concurrent.ListenableFuture; | |
| 22 | - | |
| 23 | 18 | import com.datastax.driver.core.exceptions.NoHostAvailableException; |
| 24 | 19 | import com.datastax.driver.core.exceptions.QueryExecutionException; |
| 25 | 20 | import com.datastax.driver.core.exceptions.QueryValidationException; |
| 21 | +import com.google.common.util.concurrent.ListenableFuture; | |
| 22 | + | |
| 23 | +import java.util.concurrent.TimeUnit; | |
| 24 | +import java.util.concurrent.TimeoutException; | |
| 26 | 25 | |
| 27 | 26 | /** |
| 28 | 27 | * A future on a {@link ResultSet}. |
| 29 | - * | |
| 28 | + * <p/> | |
| 30 | 29 | * Note that this class implements <a href="http://code.google.com/p/guava-libraries/">Guava</a>'s {@code |
| 31 | 30 | * ListenableFuture} and can so be used with Guava's future utilities. |
| 32 | 31 | */ |
| @@ -34,67 +33,65 @@ | ||
| 34 | 33 | |
| 35 | 34 | /** |
| 36 | 35 | * Waits for the query to return and return its result. |
| 37 | - * | |
| 36 | + * <p/> | |
| 38 | 37 | * This method is usually more convenient than {@link #get} because it: |
| 39 | 38 | * <ul> |
| 40 | - * <li>Waits for the result uninterruptibly, and so doesn't throw | |
| 41 | - * {@link InterruptedException}.</li> | |
| 42 | - * <li>Returns meaningful exceptions, instead of having to deal | |
| 43 | - * with ExecutionException.</li> | |
| 39 | + * <li>Waits for the result uninterruptibly, and so doesn't throw | |
| 40 | + * {@link InterruptedException}.</li> | |
| 41 | + * <li>Returns meaningful exceptions, instead of having to deal | |
| 42 | + * with ExecutionException.</li> | |
| 44 | 43 | * </ul> |
| 45 | 44 | * As such, it is the preferred way to get the future result. |
| 46 | 45 | * |
| 47 | 46 | * @return the query result set. |
| 48 | - * | |
| 49 | 47 | * @throws NoHostAvailableException if no host in the cluster can be |
| 50 | - * contacted successfully to execute this query. | |
| 51 | - * @throws QueryExecutionException if the query triggered an execution | |
| 52 | - * exception, that is an exception thrown by Cassandra when it cannot execute | |
| 53 | - * the query with the requested consistency level successfully. | |
| 48 | + * contacted successfully to execute this query. | |
| 49 | + * @throws QueryExecutionException if the query triggered an execution | |
| 50 | + * exception, that is an exception thrown by Cassandra when it cannot execute | |
| 51 | + * the query with the requested consistency level successfully. | |
| 54 | 52 | * @throws QueryValidationException if the query is invalid (syntax error, |
| 55 | - * unauthorized or any other validation problem). | |
| 53 | + * unauthorized or any other validation problem). | |
| 56 | 54 | */ |
| 57 | 55 | public ResultSet getUninterruptibly(); |
| 58 | 56 | |
| 59 | 57 | /** |
| 60 | 58 | * Waits for the provided time for the query to return and return its |
| 61 | 59 | * result if available. |
| 62 | - * | |
| 60 | + * <p/> | |
| 63 | 61 | * This method is usually more convenient than {@link #get} because it: |
| 64 | 62 | * <ul> |
| 65 | - * <li>Waits for the result uninterruptibly, and so doesn't throw | |
| 66 | - * {@link InterruptedException}.</li> | |
| 67 | - * <li>Returns meaningful exceptions, instead of having to deal | |
| 68 | - * with ExecutionException.</li> | |
| 63 | + * <li>Waits for the result uninterruptibly, and so doesn't throw | |
| 64 | + * {@link InterruptedException}.</li> | |
| 65 | + * <li>Returns meaningful exceptions, instead of having to deal | |
| 66 | + * with ExecutionException.</li> | |
| 69 | 67 | * </ul> |
| 70 | 68 | * As such, it is the preferred way to get the future result. |
| 71 | 69 | * |
| 72 | 70 | * @param timeout the time to wait for the query to return. |
| 73 | - * @param unit the unit for {@code timeout}. | |
| 71 | + * @param unit the unit for {@code timeout}. | |
| 74 | 72 | * @return the query result set. |
| 75 | - * | |
| 76 | 73 | * @throws NoHostAvailableException if no host in the cluster can be |
| 77 | - * contacted successfully to execute this query. | |
| 78 | - * @throws QueryExecutionException if the query triggered an execution | |
| 79 | - * exception, that is an exception thrown by Cassandra when it cannot execute | |
| 80 | - * the query with the requested consistency level successfully. | |
| 74 | + * contacted successfully to execute this query. | |
| 75 | + * @throws QueryExecutionException if the query triggered an execution | |
| 76 | + * exception, that is an exception thrown by Cassandra when it cannot execute | |
| 77 | + * the query with the requested consistency level successfully. | |
| 81 | 78 | * @throws QueryValidationException if the query if invalid (syntax error, |
| 82 | - * unauthorized or any other validation problem). | |
| 83 | - * @throws TimeoutException if the wait timed out (Note that this is | |
| 84 | - * different from a Cassandra timeout, which is a {@code | |
| 85 | - * QueryExecutionException}). | |
| 79 | + * unauthorized or any other validation problem). | |
| 80 | + * @throws TimeoutException if the wait timed out (Note that this is | |
| 81 | + * different from a Cassandra timeout, which is a {@code | |
| 82 | + * QueryExecutionException}). | |
| 86 | 83 | */ |
| 87 | 84 | public ResultSet getUninterruptibly(long timeout, TimeUnit unit) throws TimeoutException; |
| 88 | 85 | |
| 89 | 86 | /** |
| 90 | 87 | * Attempts to cancel the execution of the request corresponding to this |
| 91 | 88 | * future. This attempt will fail if the request has already returned. |
| 92 | - * <p> | |
| 89 | + * <p/> | |
| 93 | 90 | * Please note that this only cancel the request driver side, but nothing |
| 94 | 91 | * is done to interrupt the execution of the request Cassandra side (and that even |
| 95 | 92 | * if {@code mayInterruptIfRunning} is true) since Cassandra does not |
| 96 | 93 | * support such interruption. |
| 97 | - * <p> | |
| 94 | + * <p/> | |
| 98 | 95 | * This method can be used to ensure no more work is performed driver side |
| 99 | 96 | * (which, while it doesn't include stopping a request already submitted |
| 100 | 97 | * to a Cassandra node, may include not retrying another Cassandra host on |
| @@ -114,7 +111,7 @@ | ||
| 114 | 111 | * </pre> |
| 115 | 112 | * |
| 116 | 113 | * @param mayInterruptIfRunning the value of this parameter is currently |
| 117 | - * ignored. | |
| 114 | + * ignored. | |
| 118 | 115 | * @return {@code false} if the future could not be cancelled (it has already |
| 119 | 116 | * completed normally); {@code true} otherwise. |
| 120 | 117 | */ |
modified driver-core/src/main/java/com/datastax/driver/core/Row.java +94 −131
| @@ -15,17 +15,17 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.exceptions.InvalidTypeException; | |
| 19 | + | |
| 18 | 20 | import java.math.BigDecimal; |
| 19 | 21 | import java.math.BigInteger; |
| 20 | 22 | import java.net.InetAddress; |
| 21 | 23 | import java.nio.ByteBuffer; |
| 22 | 24 | import java.util.*; |
| 23 | 25 | |
| 24 | -import com.datastax.driver.core.exceptions.InvalidTypeException; | |
| 25 | - | |
| 26 | 26 | /** |
| 27 | 27 | * A CQL Row returned in a {@link ResultSet}. |
| 28 | - * <p> | |
| 28 | + * <p/> | |
| 29 | 29 | * The values of a CQL Row can be retrieve by either index (index starts at 0) |
| 30 | 30 | * or name. When setting them by name, names follow the case insensitivity |
| 31 | 31 | * rules explained in {@link ColumnDefinitions}. |
| @@ -44,7 +44,6 @@ | ||
| 44 | 44 | * |
| 45 | 45 | * @param i the index ({@code 0 <= i < size()}) of the column to check. |
| 46 | 46 | * @return whether the {@code i}th value of this row is NULL. |
| 47 | - * | |
| 48 | 47 | * @throws IndexOutOfBoundsException if {@code i < 0 || i >= this.columns().size()}. |
| 49 | 48 | */ |
| 50 | 49 | @Override |
| @@ -55,9 +54,8 @@ | ||
| 55 | 54 | * |
| 56 | 55 | * @param name the name of the column to check. |
| 57 | 56 | * @return whether the value of column {@code name} is NULL. |
| 58 | - * | |
| 59 | 57 | * @throws IllegalArgumentException if {@code name} is not part of the |
| 60 | - * ResultSet this row is part of, i.e. if {@code !this.columns().names().contains(name)}. | |
| 58 | + * ResultSet this row is part of, i.e. if {@code !this.columns().names().contains(name)}. | |
| 61 | 59 | */ |
| 62 | 60 | @Override |
| 63 | 61 | public boolean isNull(String name); |
| @@ -68,9 +66,8 @@ | ||
| 68 | 66 | * @param i the index ({@code 0 <= i < size()}) of the column to retrieve. |
| 69 | 67 | * @return the boolean value of the {@code i}th column in this row. If the |
| 70 | 68 | * value is NULL, {@code false} is returned. |
| 71 | - * | |
| 72 | 69 | * @throws IndexOutOfBoundsException if {@code i < 0 || i >= this.columns().size()}. |
| 73 | - * @throws InvalidTypeException if column {@code i} is not of type BOOLEAN. | |
| 70 | + * @throws InvalidTypeException if column {@code i} is not of type BOOLEAN. | |
| 74 | 71 | */ |
| 75 | 72 | @Override |
| 76 | 73 | public boolean getBool(int i); |
| @@ -81,10 +78,9 @@ | ||
| 81 | 78 | * @param name the name of the column to retrieve. |
| 82 | 79 | * @return the boolean value of column {@code name}. If the value is NULL, |
| 83 | 80 | * {@code false} is returned. |
| 84 | - * | |
| 85 | 81 | * @throws IllegalArgumentException if {@code name} is not part of the |
| 86 | - * ResultSet this row is part of, i.e. if {@code !this.columns().names().contains(name)}. | |
| 87 | - * @throws InvalidTypeException if column {@code name} is not of type BOOLEAN. | |
| 82 | + * ResultSet this row is part of, i.e. if {@code !this.columns().names().contains(name)}. | |
| 83 | + * @throws InvalidTypeException if column {@code name} is not of type BOOLEAN. | |
| 88 | 84 | */ |
| 89 | 85 | @Override |
| 90 | 86 | public boolean getBool(String name); |
| @@ -95,9 +91,8 @@ | ||
| 95 | 91 | * @param i the index ({@code 0 <= i < size()}) of the column to retrieve. |
| 96 | 92 | * @return the value of the {@code i}th column in this row as an integer. If the |
| 97 | 93 | * value is NULL, {@code 0} is returned. |
| 98 | - * | |
| 99 | 94 | * @throws IndexOutOfBoundsException if {@code i < 0 || i >= this.columns().size()}. |
| 100 | - * @throws InvalidTypeException if column {@code i} is not of type INT. | |
| 95 | + * @throws InvalidTypeException if column {@code i} is not of type INT. | |
| 101 | 96 | */ |
| 102 | 97 | @Override |
| 103 | 98 | public int getInt(int i); |
| @@ -108,10 +103,9 @@ | ||
| 108 | 103 | * @param name the name of the column to retrieve. |
| 109 | 104 | * @return the value of column {@code name} as an integer. If the value is NULL, |
| 110 | 105 | * {@code 0} is returned. |
| 111 | - * | |
| 112 | 106 | * @throws IllegalArgumentException if {@code name} is not part of the |
| 113 | - * ResultSet this row is part of, i.e. if {@code !this.columns().names().contains(name)}. | |
| 114 | - * @throws InvalidTypeException if column {@code name} is not of type INT. | |
| 107 | + * ResultSet this row is part of, i.e. if {@code !this.columns().names().contains(name)}. | |
| 108 | + * @throws InvalidTypeException if column {@code name} is not of type INT. | |
| 115 | 109 | */ |
| 116 | 110 | @Override |
| 117 | 111 | public int getInt(String name); |
| @@ -122,9 +116,8 @@ | ||
| 122 | 116 | * @param i the index ({@code 0 <= i < size()}) of the column to retrieve. |
| 123 | 117 | * @return the value of the {@code i}th column in this row as a long. If the |
| 124 | 118 | * value is NULL, {@code 0L} is returned. |
| 125 | - * | |
| 126 | 119 | * @throws IndexOutOfBoundsException if {@code i < 0 || i >= this.columns().size()}. |
| 127 | - * @throws InvalidTypeException if column {@code i} is not of type BIGINT or COUNTER. | |
| 120 | + * @throws InvalidTypeException if column {@code i} is not of type BIGINT or COUNTER. | |
| 128 | 121 | */ |
| 129 | 122 | @Override |
| 130 | 123 | public long getLong(int i); |
| @@ -135,10 +128,9 @@ | ||
| 135 | 128 | * @param name the name of the column to retrieve. |
| 136 | 129 | * @return the value of column {@code name} as a long. If the value is NULL, |
| 137 | 130 | * {@code 0L} is returned. |
| 138 | - * | |
| 139 | 131 | * @throws IllegalArgumentException if {@code name} is not part of the |
| 140 | - * ResultSet this row is part of, i.e. if {@code !this.columns().names().contains(name)}. | |
| 141 | - * @throws InvalidTypeException if column {@code i} is not of type BIGINT or COUNTER. | |
| 132 | + * ResultSet this row is part of, i.e. if {@code !this.columns().names().contains(name)}. | |
| 133 | + * @throws InvalidTypeException if column {@code i} is not of type BIGINT or COUNTER. | |
| 142 | 134 | */ |
| 143 | 135 | @Override |
| 144 | 136 | public long getLong(String name); |
| @@ -149,9 +141,8 @@ | ||
| 149 | 141 | * @param i the index ({@code 0 <= i < size()}) of the column to retrieve. |
| 150 | 142 | * @return the value of the {@code i}th column in this row as a data. If the |
| 151 | 143 | * value is NULL, {@code null} is returned. |
| 152 | - * | |
| 153 | 144 | * @throws IndexOutOfBoundsException if {@code i < 0 || i >= this.columns().size()}. |
| 154 | - * @throws InvalidTypeException if column {@code i} is not of type TIMESTAMP. | |
| 145 | + * @throws InvalidTypeException if column {@code i} is not of type TIMESTAMP. | |
| 155 | 146 | */ |
| 156 | 147 | @Override |
| 157 | 148 | public Date getDate(int i); |
| @@ -162,10 +153,9 @@ | ||
| 162 | 153 | * @param name the name of the column to retrieve. |
| 163 | 154 | * @return the value of column {@code name} as a date. If the value is NULL, |
| 164 | 155 | * {@code null} is returned. |
| 165 | - * | |
| 166 | 156 | * @throws IllegalArgumentException if {@code name} is not part of the |
| 167 | - * ResultSet this row is part of, i.e. if {@code !this.columns().names().contains(name)}. | |
| 168 | - * @throws InvalidTypeException if column {@code name} is not of type TIMESTAMP. | |
| 157 | + * ResultSet this row is part of, i.e. if {@code !this.columns().names().contains(name)}. | |
| 158 | + * @throws InvalidTypeException if column {@code name} is not of type TIMESTAMP. | |
| 169 | 159 | */ |
| 170 | 160 | @Override |
| 171 | 161 | public Date getDate(String name); |
| @@ -176,9 +166,8 @@ | ||
| 176 | 166 | * @param i the index ({@code 0 <= i < size()}) of the column to retrieve. |
| 177 | 167 | * @return the value of the {@code i}th column in this row as a float. If the |
| 178 | 168 | * value is NULL, {@code 0.0f} is returned. |
| 179 | - * | |
| 180 | 169 | * @throws IndexOutOfBoundsException if {@code i < 0 || i >= this.columns().size()}. |
| 181 | - * @throws InvalidTypeException if column {@code i} is not of type FLOAT. | |
| 170 | + * @throws InvalidTypeException if column {@code i} is not of type FLOAT. | |
| 182 | 171 | */ |
| 183 | 172 | @Override |
| 184 | 173 | public float getFloat(int i); |
| @@ -189,10 +178,9 @@ | ||
| 189 | 178 | * @param name the name of the column to retrieve. |
| 190 | 179 | * @return the value of column {@code name} as a float. If the value is NULL, |
| 191 | 180 | * {@code 0.0f} is returned. |
| 192 | - * | |
| 193 | 181 | * @throws IllegalArgumentException if {@code name} is not part of the |
| 194 | - * ResultSet this row is part of, i.e. if {@code !this.columns().names().contains(name)}. | |
| 195 | - * @throws InvalidTypeException if column {@code name} is not of type FLOAT. | |
| 182 | + * ResultSet this row is part of, i.e. if {@code !this.columns().names().contains(name)}. | |
| 183 | + * @throws InvalidTypeException if column {@code name} is not of type FLOAT. | |
| 196 | 184 | */ |
| 197 | 185 | @Override |
| 198 | 186 | public float getFloat(String name); |
| @@ -203,9 +191,8 @@ | ||
| 203 | 191 | * @param i the index ({@code 0 <= i < size()}) of the column to retrieve. |
| 204 | 192 | * @return the value of the {@code i}th column in this row as a double. If the |
| 205 | 193 | * value is NULL, {@code 0.0} is returned. |
| 206 | - * | |
| 207 | 194 | * @throws IndexOutOfBoundsException if {@code i < 0 || i >= this.columns().size()}. |
| 208 | - * @throws InvalidTypeException if column {@code i} is not of type DOUBLE. | |
| 195 | + * @throws InvalidTypeException if column {@code i} is not of type DOUBLE. | |
| 209 | 196 | */ |
| 210 | 197 | @Override |
| 211 | 198 | public double getDouble(int i); |
| @@ -216,17 +203,16 @@ | ||
| 216 | 203 | * @param name the name of the column to retrieve. |
| 217 | 204 | * @return the value of column {@code name} as a double. If the value is NULL, |
| 218 | 205 | * {@code 0.0} is returned. |
| 219 | - * | |
| 220 | 206 | * @throws IllegalArgumentException if {@code name} is not part of the |
| 221 | - * ResultSet this row is part of, i.e. if {@code !this.columns().names().contains(name)}. | |
| 222 | - * @throws InvalidTypeException if column {@code name} is not of type DOUBLE. | |
| 207 | + * ResultSet this row is part of, i.e. if {@code !this.columns().names().contains(name)}. | |
| 208 | + * @throws InvalidTypeException if column {@code name} is not of type DOUBLE. | |
| 223 | 209 | */ |
| 224 | 210 | @Override |
| 225 | 211 | public double getDouble(String name); |
| 226 | 212 | |
| 227 | 213 | /** |
| 228 | 214 | * Returns the {@code i}th value of this row as a ByteBuffer. |
| 229 | - * | |
| 215 | + * <p/> | |
| 230 | 216 | * Note: this method always return the bytes composing the value, even if |
| 231 | 217 | * the column is not of type BLOB. That is, this method never throw an |
| 232 | 218 | * InvalidTypeException. However, if the type is not BLOB, it is up to the |
| @@ -235,7 +221,6 @@ | ||
| 235 | 221 | * @param i the index ({@code 0 <= i < size()}) of the column to retrieve. |
| 236 | 222 | * @return the value of the {@code i}th column in this row as a ByteBuffer. If the |
| 237 | 223 | * value is NULL, {@code null} is returned. |
| 238 | - * | |
| 239 | 224 | * @throws IndexOutOfBoundsException if {@code i < 0 || i >= this.columns().size()}. |
| 240 | 225 | */ |
| 241 | 226 | @Override |
| @@ -243,7 +228,7 @@ | ||
| 243 | 228 | |
| 244 | 229 | /** |
| 245 | 230 | * Returns the value of column {@code name} as a ByteBuffer. |
| 246 | - * | |
| 231 | + * <p/> | |
| 247 | 232 | * Note: this method always return the bytes composing the value, even if |
| 248 | 233 | * the column is not of type BLOB. That is, this method never throw an |
| 249 | 234 | * InvalidTypeException. However, if the type is not BLOB, it is up to the |
| @@ -252,42 +237,39 @@ | ||
| 252 | 237 | * @param name the name of the column to retrieve. |
| 253 | 238 | * @return the value of column {@code name} as a ByteBuffer. If the value is NULL, |
| 254 | 239 | * {@code null} is returned. |
| 255 | - * | |
| 256 | 240 | * @throws IllegalArgumentException if {@code name} is not part of the |
| 257 | - * ResultSet this row is part of, i.e. if {@code !this.columns().names().contains(name)}. | |
| 241 | + * ResultSet this row is part of, i.e. if {@code !this.columns().names().contains(name)}. | |
| 258 | 242 | */ |
| 259 | 243 | @Override |
| 260 | 244 | public ByteBuffer getBytesUnsafe(String name); |
| 261 | 245 | |
| 262 | 246 | /** |
| 263 | 247 | * Returns the {@code i}th value of this row as a byte array. |
| 264 | - * <p> | |
| 248 | + * <p/> | |
| 265 | 249 | * Note that this method validate that the column is of type BLOB. If you want to retrieve |
| 266 | 250 | * the bytes for any type of columns, use {@link #getBytesUnsafe(int)} instead. |
| 267 | 251 | * |
| 268 | 252 | * @param i the index ({@code 0 <= i < size()}) of the column to retrieve. |
| 269 | 253 | * @return the value of the {@code i}th column in this row as a byte array. If the |
| 270 | 254 | * value is NULL, {@code null} is returned. |
| 271 | - * | |
| 272 | 255 | * @throws IndexOutOfBoundsException if {@code i < 0 || i >= this.columns().size()}. |
| 273 | - * @throws InvalidTypeException if column {@code i} type is not of type BLOB. | |
| 256 | + * @throws InvalidTypeException if column {@code i} type is not of type BLOB. | |
| 274 | 257 | */ |
| 275 | 258 | @Override |
| 276 | 259 | public ByteBuffer getBytes(int i); |
| 277 | 260 | |
| 278 | 261 | /** |
| 279 | 262 | * Returns the value of column {@code name} as a byte array. |
| 280 | - * <p> | |
| 263 | + * <p/> | |
| 281 | 264 | * Note that this method validate that the column is of type BLOB. If you want to retrieve |
| 282 | 265 | * the bytes for any type of columns, use {@link #getBytesUnsafe(String)} instead. |
| 283 | 266 | * |
| 284 | 267 | * @param name the name of the column to retrieve. |
| 285 | 268 | * @return the value of column {@code name} as a byte array. If the value is NULL, |
| 286 | 269 | * {@code null} is returned. |
| 287 | - * | |
| 288 | 270 | * @throws IllegalArgumentException if {@code name} is not part of the |
| 289 | - * ResultSet this row is part of, i.e. if {@code !this.columns().names().contains(name)}. | |
| 290 | - * @throws InvalidTypeException if column {@code i} type is not of type BLOB. | |
| 271 | + * ResultSet this row is part of, i.e. if {@code !this.columns().names().contains(name)}. | |
| 272 | + * @throws InvalidTypeException if column {@code i} type is not of type BLOB. | |
| 291 | 273 | */ |
| 292 | 274 | @Override |
| 293 | 275 | public ByteBuffer getBytes(String name); |
| @@ -298,10 +280,9 @@ | ||
| 298 | 280 | * @param i the index ({@code 0 <= i < size()}) of the column to retrieve. |
| 299 | 281 | * @return the value of the {@code i}th column in this row as a string. If the |
| 300 | 282 | * value is NULL, {@code null} is returned. |
| 301 | - * | |
| 302 | 283 | * @throws IndexOutOfBoundsException if {@code i < 0 || i >= this.columns().size()}. |
| 303 | - * @throws InvalidTypeException if column {@code i} type is none of: | |
| 304 | - * VARCHAR, TEXT or ASCII. | |
| 284 | + * @throws InvalidTypeException if column {@code i} type is none of: | |
| 285 | + * VARCHAR, TEXT or ASCII. | |
| 305 | 286 | */ |
| 306 | 287 | @Override |
| 307 | 288 | public String getString(int i); |
| @@ -312,11 +293,10 @@ | ||
| 312 | 293 | * @param name the name of the column to retrieve. |
| 313 | 294 | * @return the value of column {@code name} as a string. If the value is NULL, |
| 314 | 295 | * {@code null} is returned. |
| 315 | - * | |
| 316 | 296 | * @throws IllegalArgumentException if {@code name} is not part of the |
| 317 | - * ResultSet this row is part of, i.e. if {@code !this.columns().names().contains(name)}. | |
| 318 | - * @throws InvalidTypeException if column {@code name} type is none of: | |
| 319 | - * VARCHAR, TEXT or ASCII. | |
| 297 | + * ResultSet this row is part of, i.e. if {@code !this.columns().names().contains(name)}. | |
| 298 | + * @throws InvalidTypeException if column {@code name} type is none of: | |
| 299 | + * VARCHAR, TEXT or ASCII. | |
| 320 | 300 | */ |
| 321 | 301 | @Override |
| 322 | 302 | public String getString(String name); |
| @@ -327,9 +307,8 @@ | ||
| 327 | 307 | * @param i the index ({@code 0 <= i < size()}) of the column to retrieve. |
| 328 | 308 | * @return the value of the {@code i}th column in this row as a variable |
| 329 | 309 | * length integer. If the value is NULL, {@code null} is returned. |
| 330 | - * | |
| 331 | 310 | * @throws IndexOutOfBoundsException if {@code i < 0 || i >= this.columns().size()}. |
| 332 | - * @throws InvalidTypeException if column {@code i} is not of type VARINT. | |
| 311 | + * @throws InvalidTypeException if column {@code i} is not of type VARINT. | |
| 333 | 312 | */ |
| 334 | 313 | @Override |
| 335 | 314 | public BigInteger getVarint(int i); |
| @@ -340,10 +319,9 @@ | ||
| 340 | 319 | * @param name the name of the column to retrieve. |
| 341 | 320 | * @return the value of column {@code name} as a variable length integer. |
| 342 | 321 | * If the value is NULL, {@code null} is returned. |
| 343 | - * | |
| 344 | 322 | * @throws IllegalArgumentException if {@code name} is not part of the |
| 345 | - * ResultSet this row is part of, i.e. if {@code !this.columns().names().contains(name)}. | |
| 346 | - * @throws InvalidTypeException if column {@code name} is not of type VARINT. | |
| 323 | + * ResultSet this row is part of, i.e. if {@code !this.columns().names().contains(name)}. | |
| 324 | + * @throws InvalidTypeException if column {@code name} is not of type VARINT. | |
| 347 | 325 | */ |
| 348 | 326 | @Override |
| 349 | 327 | public BigInteger getVarint(String name); |
| @@ -354,9 +332,8 @@ | ||
| 354 | 332 | * @param i the index ({@code 0 <= i < size()}) of the column to retrieve. |
| 355 | 333 | * @return the value of the {@code i}th column in this row as a variable |
| 356 | 334 | * length decimal. If the value is NULL, {@code null} is returned. |
| 357 | - * | |
| 358 | 335 | * @throws IndexOutOfBoundsException if {@code i < 0 || i >= this.columns().size()}. |
| 359 | - * @throws InvalidTypeException if column {@code i} is not of type DECIMAL. | |
| 336 | + * @throws InvalidTypeException if column {@code i} is not of type DECIMAL. | |
| 360 | 337 | */ |
| 361 | 338 | @Override |
| 362 | 339 | public BigDecimal getDecimal(int i); |
| @@ -367,10 +344,9 @@ | ||
| 367 | 344 | * @param name the name of the column to retrieve. |
| 368 | 345 | * @return the value of column {@code name} as a variable length decimal. |
| 369 | 346 | * If the value is NULL, {@code null} is returned. |
| 370 | - * | |
| 371 | 347 | * @throws IllegalArgumentException if {@code name} is not part of the |
| 372 | - * ResultSet this row is part of, i.e. if {@code !this.columns().names().contains(name)}. | |
| 373 | - * @throws InvalidTypeException if column {@code name} is not of type DECIMAL. | |
| 348 | + * ResultSet this row is part of, i.e. if {@code !this.columns().names().contains(name)}. | |
| 349 | + * @throws InvalidTypeException if column {@code name} is not of type DECIMAL. | |
| 374 | 350 | */ |
| 375 | 351 | @Override |
| 376 | 352 | public BigDecimal getDecimal(String name); |
| @@ -381,10 +357,9 @@ | ||
| 381 | 357 | * @param i the index ({@code 0 <= i < size()}) of the column to retrieve. |
| 382 | 358 | * @return the value of the {@code i}th column in this row as a UUID. |
| 383 | 359 | * If the value is NULL, {@code null} is returned. |
| 384 | - * | |
| 385 | 360 | * @throws IndexOutOfBoundsException if {@code i < 0 || i >= this.columns().size()}. |
| 386 | - * @throws InvalidTypeException if column {@code i} is not of type UUID | |
| 387 | - * or TIMEUUID. | |
| 361 | + * @throws InvalidTypeException if column {@code i} is not of type UUID | |
| 362 | + * or TIMEUUID. | |
| 388 | 363 | */ |
| 389 | 364 | @Override |
| 390 | 365 | public UUID getUUID(int i); |
| @@ -395,11 +370,10 @@ | ||
| 395 | 370 | * @param name the name of the column to retrieve. |
| 396 | 371 | * @return the value of column {@code name} as a UUID. |
| 397 | 372 | * If the value is NULL, {@code null} is returned. |
| 398 | - * | |
| 399 | 373 | * @throws IllegalArgumentException if {@code name} is not part of the |
| 400 | - * ResultSet this row is part of, i.e. if {@code !this.columns().names().contains(name)}. | |
| 401 | - * @throws InvalidTypeException if column {@code name} is not of type | |
| 402 | - * UUID or TIMEUUID. | |
| 374 | + * ResultSet this row is part of, i.e. if {@code !this.columns().names().contains(name)}. | |
| 375 | + * @throws InvalidTypeException if column {@code name} is not of type | |
| 376 | + * UUID or TIMEUUID. | |
| 403 | 377 | */ |
| 404 | 378 | @Override |
| 405 | 379 | public UUID getUUID(String name); |
| @@ -410,9 +384,8 @@ | ||
| 410 | 384 | * @param i the index ({@code 0 <= i < size()}) of the column to retrieve. |
| 411 | 385 | * @return the value of the {@code i}th column in this row as an InetAddress. |
| 412 | 386 | * If the value is NULL, {@code null} is returned. |
| 413 | - * | |
| 414 | 387 | * @throws IndexOutOfBoundsException if {@code i < 0 || i >= this.columns().size()}. |
| 415 | - * @throws InvalidTypeException if column {@code i} is not of type INET. | |
| 388 | + * @throws InvalidTypeException if column {@code i} is not of type INET. | |
| 416 | 389 | */ |
| 417 | 390 | @Override |
| 418 | 391 | public InetAddress getInet(int i); |
| @@ -423,49 +396,46 @@ | ||
| 423 | 396 | * @param name the name of the column to retrieve. |
| 424 | 397 | * @return the value of column {@code name} as an InetAddress. |
| 425 | 398 | * If the value is NULL, {@code null} is returned. |
| 426 | - * | |
| 427 | 399 | * @throws IllegalArgumentException if {@code name} is not part of the |
| 428 | - * ResultSet this row is part of, i.e. if {@code !this.columns().names().contains(name)}. | |
| 429 | - * @throws InvalidTypeException if column {@code name} is not of type | |
| 430 | - * INET. | |
| 400 | + * ResultSet this row is part of, i.e. if {@code !this.columns().names().contains(name)}. | |
| 401 | + * @throws InvalidTypeException if column {@code name} is not of type | |
| 402 | + * INET. | |
| 431 | 403 | */ |
| 432 | 404 | @Override |
| 433 | 405 | public InetAddress getInet(String name); |
| 434 | 406 | |
| 435 | 407 | /** |
| 436 | 408 | * Returns the {@code i}th value of this row as a {@link Token}. |
| 437 | - * <p> | |
| 409 | + * <p/> | |
| 438 | 410 | * {@link #getPartitionKeyToken()} should generally be preferred to this method (unless the |
| 439 | 411 | * token column is aliased). |
| 440 | 412 | * |
| 441 | 413 | * @param i the index ({@code 0 <= i < size()}) of the column to retrieve. |
| 442 | 414 | * @return the value of the {@code i}th column in this row as an Token. |
| 443 | - * | |
| 444 | 415 | * @throws IndexOutOfBoundsException if {@code i < 0 || i >= this.columns().size()}. |
| 445 | - * @throws InvalidTypeException if column {@code i} is not of the type of token values | |
| 446 | - * for this cluster (this depends on the configured partitioner). | |
| 416 | + * @throws InvalidTypeException if column {@code i} is not of the type of token values | |
| 417 | + * for this cluster (this depends on the configured partitioner). | |
| 447 | 418 | */ |
| 448 | 419 | public Token getToken(int i); |
| 449 | 420 | |
| 450 | 421 | /** |
| 451 | 422 | * Returns the value of column {@code name} as a {@link Token}. |
| 452 | - * <p> | |
| 423 | + * <p/> | |
| 453 | 424 | * {@link #getPartitionKeyToken()} should generally be preferred to this method (unless the |
| 454 | 425 | * token column is aliased). |
| 455 | 426 | * |
| 456 | 427 | * @param name the name of the column to retrieve. |
| 457 | 428 | * @return the value of column {@code name} as a Token. |
| 458 | - * | |
| 459 | 429 | * @throws IllegalArgumentException if {@code name} is not part of the |
| 460 | - * ResultSet this row is part of, i.e. if {@code !this.columns().names().contains(name)}. | |
| 461 | - * @throws InvalidTypeException if column {@code name} is not of the type of token values | |
| 462 | - * for this cluster (this depends on the configured partitioner). | |
| 430 | + * ResultSet this row is part of, i.e. if {@code !this.columns().names().contains(name)}. | |
| 431 | + * @throws InvalidTypeException if column {@code name} is not of the type of token values | |
| 432 | + * for this cluster (this depends on the configured partitioner). | |
| 463 | 433 | */ |
| 464 | 434 | public Token getToken(String name); |
| 465 | 435 | |
| 466 | 436 | /** |
| 467 | 437 | * Returns the value of the first column containing a {@link Token}. |
| 468 | - * <p> | |
| 438 | + * <p/> | |
| 469 | 439 | * This method is a shorthand for queries returning a single token in an unaliased |
| 470 | 440 | * column. It will look for the first name matching {@code token(...)}: |
| 471 | 441 | * <pre> |
| @@ -478,28 +448,26 @@ | ||
| 478 | 448 | * {@link #getToken(int)} or {@link #getToken(String)}. |
| 479 | 449 | * |
| 480 | 450 | * @return the value of column {@code name} as a Token. |
| 481 | - * | |
| 482 | 451 | * @throws IllegalStateException if no column named {@code token(...)} exists in this |
| 483 | - * ResultSet. | |
| 484 | - * @throws InvalidTypeException if the first column named {@code token(...)} is not of | |
| 485 | - * the type of token values for this cluster (this depends on the configured partitioner). | |
| 452 | + * ResultSet. | |
| 453 | + * @throws InvalidTypeException if the first column named {@code token(...)} is not of | |
| 454 | + * the type of token values for this cluster (this depends on the configured partitioner). | |
| 486 | 455 | */ |
| 487 | 456 | public Token getPartitionKeyToken(); |
| 488 | 457 | |
| 489 | 458 | /** |
| 490 | 459 | * Returns the {@code i}th value of this row as a list. |
| 491 | 460 | * |
| 492 | - * @param <T> the type of the elements of the list to return. | |
| 493 | - * @param i the index ({@code 0 <= i < size()}) of the column to retrieve. | |
| 461 | + * @param <T> the type of the elements of the list to return. | |
| 462 | + * @param i the index ({@code 0 <= i < size()}) of the column to retrieve. | |
| 494 | 463 | * @param elementsClass the class for the elements of the list to retrieve. |
| 495 | 464 | * @return the value of the {@code i}th column in this row as a list of |
| 496 | 465 | * {@code elementsClass} objects. If the value is NULL, an empty list is |
| 497 | 466 | * returned (note that Cassandra makes no difference between an empty list |
| 498 | 467 | * and column of type list that is not set). The returned list is immutable. |
| 499 | - * | |
| 500 | 468 | * @throws IndexOutOfBoundsException if {@code i < 0 || i >= this.columns().size()}. |
| 501 | - * @throws InvalidTypeException if column {@code i} is not a list or if its | |
| 502 | - * elements are not of class {@code elementsClass}. | |
| 469 | + * @throws InvalidTypeException if column {@code i} is not a list or if its | |
| 470 | + * elements are not of class {@code elementsClass}. | |
| 503 | 471 | */ |
| 504 | 472 | @Override |
| 505 | 473 | public <T> List<T> getList(int i, Class<T> elementsClass); |
| @@ -507,18 +475,17 @@ | ||
| 507 | 475 | /** |
| 508 | 476 | * Returns the value of column {@code name} as a list. |
| 509 | 477 | * |
| 510 | - * @param <T> the type of the elements of the list to return. | |
| 511 | - * @param name the name of the column to retrieve. | |
| 478 | + * @param <T> the type of the elements of the list to return. | |
| 479 | + * @param name the name of the column to retrieve. | |
| 512 | 480 | * @param elementsClass the class for the elements of the list to retrieve. |
| 513 | 481 | * @return the value of the {@code i}th column in this row as a list of |
| 514 | 482 | * {@code elementsClass} objects. If the value is NULL, an empty list is |
| 515 | 483 | * returned (note that Cassandra makes no difference between an empty list |
| 516 | 484 | * and column of type list that is not set). The returned list is immutable. |
| 517 | - * | |
| 518 | 485 | * @throws IllegalArgumentException if {@code name} is not part of the |
| 519 | - * ResultSet this row is part of, i.e. if {@code !this.columns().names().contains(name)}. | |
| 520 | - * @throws InvalidTypeException if column {@code name} is not a list or if its | |
| 521 | - * elements are not of class {@code elementsClass}. | |
| 486 | + * ResultSet this row is part of, i.e. if {@code !this.columns().names().contains(name)}. | |
| 487 | + * @throws InvalidTypeException if column {@code name} is not a list or if its | |
| 488 | + * elements are not of class {@code elementsClass}. | |
| 522 | 489 | */ |
| 523 | 490 | @Override |
| 524 | 491 | public <T> List<T> getList(String name, Class<T> elementsClass); |
| @@ -526,17 +493,16 @@ | ||
| 526 | 493 | /** |
| 527 | 494 | * Returns the {@code i}th value of this row as a set. |
| 528 | 495 | * |
| 529 | - * @param <T> the type of the elements of the set to return. | |
| 530 | - * @param i the index ({@code 0 <= i < size()}) of the column to retrieve. | |
| 496 | + * @param <T> the type of the elements of the set to return. | |
| 497 | + * @param i the index ({@code 0 <= i < size()}) of the column to retrieve. | |
| 531 | 498 | * @param elementsClass the class for the elements of the set to retrieve. |
| 532 | 499 | * @return the value of the {@code i}th column in this row as a set of |
| 533 | 500 | * {@code elementsClass} objects. If the value is NULL, an empty set is |
| 534 | 501 | * returned (note that Cassandra makes no difference between an empty set |
| 535 | 502 | * and column of type set that is not set). The returned set is immutable. |
| 536 | - * | |
| 537 | 503 | * @throws IndexOutOfBoundsException if {@code i < 0 || i >= this.columns().size()}. |
| 538 | - * @throws InvalidTypeException if column {@code i} is not a set or if its | |
| 539 | - * elements are not of class {@code elementsClass}. | |
| 504 | + * @throws InvalidTypeException if column {@code i} is not a set or if its | |
| 505 | + * elements are not of class {@code elementsClass}. | |
| 540 | 506 | */ |
| 541 | 507 | @Override |
| 542 | 508 | public <T> Set<T> getSet(int i, Class<T> elementsClass); |
| @@ -544,18 +510,17 @@ | ||
| 544 | 510 | /** |
| 545 | 511 | * Returns the value of column {@code name} as a set. |
| 546 | 512 | * |
| 547 | - * @param <T> the type of the elements of the set to return. | |
| 548 | - * @param name the name of the column to retrieve. | |
| 513 | + * @param <T> the type of the elements of the set to return. | |
| 514 | + * @param name the name of the column to retrieve. | |
| 549 | 515 | * @param elementsClass the class for the elements of the set to retrieve. |
| 550 | 516 | * @return the value of the {@code i}th column in this row as a set of |
| 551 | 517 | * {@code elementsClass} objects. If the value is NULL, an empty set is |
| 552 | 518 | * returned (note that Cassandra makes no difference between an empty set |
| 553 | 519 | * and column of type set that is not set). The returned set is immutable. |
| 554 | - * | |
| 555 | 520 | * @throws IllegalArgumentException if {@code name} is not part of the |
| 556 | - * ResultSet this row is part of, i.e. if {@code !this.columns().names().contains(name)}. | |
| 557 | - * @throws InvalidTypeException if column {@code name} is not a set or if its | |
| 558 | - * elements are not of class {@code elementsClass}. | |
| 521 | + * ResultSet this row is part of, i.e. if {@code !this.columns().names().contains(name)}. | |
| 522 | + * @throws InvalidTypeException if column {@code name} is not a set or if its | |
| 523 | + * elements are not of class {@code elementsClass}. | |
| 559 | 524 | */ |
| 560 | 525 | @Override |
| 561 | 526 | public <T> Set<T> getSet(String name, Class<T> elementsClass); |
| @@ -563,21 +528,20 @@ | ||
| 563 | 528 | /** |
| 564 | 529 | * Returns the {@code i}th value of this row as a map. |
| 565 | 530 | * |
| 566 | - * @param <K> the type of the keys of the map to return. | |
| 567 | - * @param <V> the type of the values of the map to return. | |
| 568 | - * @param i the index ({@code 0 <= i < size()}) of the column to retrieve. | |
| 569 | - * @param keysClass the class for the keys of the map to retrieve. | |
| 531 | + * @param <K> the type of the keys of the map to return. | |
| 532 | + * @param <V> the type of the values of the map to return. | |
| 533 | + * @param i the index ({@code 0 <= i < size()}) of the column to retrieve. | |
| 534 | + * @param keysClass the class for the keys of the map to retrieve. | |
| 570 | 535 | * @param valuesClass the class for the values of the map to retrieve. |
| 571 | 536 | * @return the value of the {@code i}th column in this row as a map of |
| 572 | 537 | * {@code keysClass} to {@code valuesClass} objects. If the value is NULL, |
| 573 | 538 | * an empty map is returned (note that Cassandra makes no difference |
| 574 | 539 | * between an empty map and column of type map that is not set). The |
| 575 | 540 | * returned map is immutable. |
| 576 | - * | |
| 577 | 541 | * @throws IndexOutOfBoundsException if {@code i < 0 || i >= this.columns().size()}. |
| 578 | - * @throws InvalidTypeException if column {@code i} is not a map, if its | |
| 579 | - * keys are not of class {@code keysClass} or if its values are not of | |
| 580 | - * class {@code valuesClass}. | |
| 542 | + * @throws InvalidTypeException if column {@code i} is not a map, if its | |
| 543 | + * keys are not of class {@code keysClass} or if its values are not of | |
| 544 | + * class {@code valuesClass}. | |
| 581 | 545 | */ |
| 582 | 546 | @Override |
| 583 | 547 | public <K, V> Map<K, V> getMap(int i, Class<K> keysClass, Class<V> valuesClass); |
| @@ -585,22 +549,21 @@ | ||
| 585 | 549 | /** |
| 586 | 550 | * Returns the value of column {@code name} as a map. |
| 587 | 551 | * |
| 588 | - * @param <K> the type of the keys of the map to return. | |
| 589 | - * @param <V> the type of the values of the map to return. | |
| 590 | - * @param name the name of the column to retrieve. | |
| 591 | - * @param keysClass the class for the keys of the map to retrieve. | |
| 552 | + * @param <K> the type of the keys of the map to return. | |
| 553 | + * @param <V> the type of the values of the map to return. | |
| 554 | + * @param name the name of the column to retrieve. | |
| 555 | + * @param keysClass the class for the keys of the map to retrieve. | |
| 592 | 556 | * @param valuesClass the class for the values of the map to retrieve. |
| 593 | 557 | * @return the value of the {@code i}th column in this row as a map of |
| 594 | 558 | * {@code keysClass} to {@code valuesClass} objects. If the value is NULL, |
| 595 | 559 | * an empty map is returned (note that Cassandra makes no difference |
| 596 | 560 | * between an empty map and column of type map that is not set). The |
| 597 | 561 | * returned map is immutable. |
| 598 | - * | |
| 599 | 562 | * @throws IllegalArgumentException if {@code name} is not part of the |
| 600 | - * ResultSet this row is part of, i.e. if {@code !this.columns().names().contains(name)}. | |
| 601 | - * @throws InvalidTypeException if column {@code name} is not a map, if its | |
| 602 | - * keys are not of class {@code keysClass} or if its values are not of | |
| 603 | - * class {@code valuesClass}. | |
| 563 | + * ResultSet this row is part of, i.e. if {@code !this.columns().names().contains(name)}. | |
| 564 | + * @throws InvalidTypeException if column {@code name} is not a map, if its | |
| 565 | + * keys are not of class {@code keysClass} or if its values are not of | |
| 566 | + * class {@code valuesClass}. | |
| 604 | 567 | */ |
| 605 | 568 | @Override |
| 606 | 569 | public <K, V> Map<K, V> getMap(String name, Class<K> keysClass, Class<V> valuesClass); |
modified driver-core/src/main/java/com/datastax/driver/core/SSLOptions.java +4 −5
| @@ -16,7 +16,6 @@ | ||
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | 18 | import javax.net.ssl.SSLContext; |
| 19 | -import java.security.KeyManagementException; | |
| 20 | 19 | import java.security.NoSuchAlgorithmException; |
| 21 | 20 | |
| 22 | 21 | /** |
| @@ -27,19 +26,19 @@ | ||
| 27 | 26 | /** |
| 28 | 27 | * The default SSL cipher suites. |
| 29 | 28 | */ |
| 30 | - public static final String[] DEFAULT_SSL_CIPHER_SUITES = { "TLS_RSA_WITH_AES_128_CBC_SHA", "TLS_RSA_WITH_AES_256_CBC_SHA" }; | |
| 29 | + public static final String[] DEFAULT_SSL_CIPHER_SUITES = {"TLS_RSA_WITH_AES_128_CBC_SHA", "TLS_RSA_WITH_AES_256_CBC_SHA"}; | |
| 31 | 30 | |
| 32 | 31 | final SSLContext context; |
| 33 | 32 | final String[] cipherSuites; |
| 34 | 33 | |
| 35 | 34 | /** |
| 36 | 35 | * Creates default SSL options. |
| 37 | - * <p> | |
| 36 | + * <p/> | |
| 38 | 37 | * The resulting options will use the default JSSE options, and you can use the default |
| 39 | 38 | * <a href="http://docs.oracle.com/javase/6/docs/technotes/guides/security/jsse/JSSERefGuide.html#Customization">JSSE System properties</a> |
| 40 | 39 | * to customize it's behavior. This may in particular involve |
| 41 | 40 | * <a href="http://docs.oracle.com/javase/6/docs/technotes/guides/security/jsse/JSSERefGuide.html#CreateKeystore">creating a simple keyStore and trustStore</a>. |
| 42 | - * <p> | |
| 41 | + * <p/> | |
| 43 | 42 | * The cipher suites used by this default instance are the one defined by |
| 44 | 43 | * {@code DEFAULT_SSL_CIPHER_SUITES} and match the default cipher suites |
| 45 | 44 | * supported by Cassandra server side. |
| @@ -51,7 +50,7 @@ | ||
| 51 | 50 | /** |
| 52 | 51 | * Creates SSL options that uses the provided SSL context and cipher suites. |
| 53 | 52 | * |
| 54 | - * @param context the {@code SSLContext} to use. | |
| 53 | + * @param context the {@code SSLContext} to use. | |
| 55 | 54 | * @param cipherSuites the cipher suites to use. |
| 56 | 55 | */ |
| 57 | 56 | public SSLOptions(SSLContext context, String[] cipherSuites) { |
modified driver-core/src/main/java/com/datastax/driver/core/SchemaChangeListener.java +4 −4
| @@ -17,10 +17,10 @@ | ||
| 17 | 17 | |
| 18 | 18 | /** |
| 19 | 19 | * Interface for objects that are interested in tracking schema change events in the cluster. |
| 20 | - * <p> | |
| 20 | + * <p/> | |
| 21 | 21 | * An implementation of this interface can be registered against a Cluster |
| 22 | 22 | * object through the {@link com.datastax.driver.core.Cluster#register(SchemaChangeListener)} method. |
| 23 | - * <p> | |
| 23 | + * <p/> | |
| 24 | 24 | * Note that the methods defined by this interface will be executed by internal driver threads, and are |
| 25 | 25 | * therefore expected to have short execution times. If you need to perform long computations or blocking |
| 26 | 26 | * calls in response to schema change events, it is strongly recommended to schedule them asynchronously |
| @@ -45,7 +45,7 @@ | ||
| 45 | 45 | /** |
| 46 | 46 | * Called when a keyspace has changed. |
| 47 | 47 | * |
| 48 | - * @param current the keyspace that has changed, in its current form (after the change). | |
| 48 | + * @param current the keyspace that has changed, in its current form (after the change). | |
| 49 | 49 | * @param previous the keyspace that has changed, in its previous form (before the change). |
| 50 | 50 | */ |
| 51 | 51 | void onKeyspaceChanged(KeyspaceMetadata current, KeyspaceMetadata previous); |
| @@ -67,7 +67,7 @@ | ||
| 67 | 67 | /** |
| 68 | 68 | * Called when a table has changed. |
| 69 | 69 | * |
| 70 | - * @param current the table that has changed, in its current form (after the change). | |
| 70 | + * @param current the table that has changed, in its current form (after the change). | |
| 71 | 71 | * @param previous the table that has changed, in its previous form (before the change). |
| 72 | 72 | */ |
| 73 | 73 | void onTableChanged(TableMetadata current, TableMetadata previous); |
modified driver-core/src/main/java/com/datastax/driver/core/Session.java +82 −93
| @@ -15,21 +15,20 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.io.Closeable; | |
| 19 | -import java.util.Collection; | |
| 20 | - | |
| 18 | +import com.datastax.driver.core.exceptions.*; | |
| 21 | 19 | import com.google.common.util.concurrent.ListenableFuture; |
| 22 | 20 | |
| 23 | -import com.datastax.driver.core.exceptions.*; | |
| 21 | +import java.io.Closeable; | |
| 22 | +import java.util.Collection; | |
| 24 | 23 | |
| 25 | 24 | /** |
| 26 | 25 | * A session holds connections to a Cassandra cluster, allowing it to be queried. |
| 27 | - * | |
| 26 | + * <p/> | |
| 28 | 27 | * Each session maintains multiple connections to the cluster nodes, |
| 29 | 28 | * provides policies to choose which node to use for each query (round-robin on |
| 30 | 29 | * all nodes of the cluster by default), and handles retries for failed query (when |
| 31 | 30 | * it makes sense), etc... |
| 32 | - * <p> | |
| 31 | + * <p/> | |
| 33 | 32 | * Session instances are thread-safe and usually a single instance is enough |
| 34 | 33 | * per application. As a given session can only be "logged" into one keyspace at |
| 35 | 34 | * a time (where the "logged" keyspace is the one used by query if the query doesn't |
| @@ -42,7 +41,7 @@ | ||
| 42 | 41 | |
| 43 | 42 | /** |
| 44 | 43 | * The keyspace to which this Session is currently logged in, if any. |
| 45 | - * <p> | |
| 44 | + * <p/> | |
| 46 | 45 | * This correspond to the name passed to {@link Cluster#connect(String)}, or to the |
| 47 | 46 | * last keyspace logged into through a "USE" CQL query if one was used. |
| 48 | 47 | * |
| @@ -54,7 +53,7 @@ | ||
| 54 | 53 | /** |
| 55 | 54 | * Force the initialization of this Session instance if it hasn't been |
| 56 | 55 | * initialized yet. |
| 57 | - * <p> | |
| 56 | + * <p/> | |
| 58 | 57 | * Please note first that most use won't need to call this method |
| 59 | 58 | * explicitly. If you use the {@link Cluster#connect} method {@code Cluster} |
| 60 | 59 | * to create your Session, the returned session will be already |
| @@ -63,73 +62,70 @@ | ||
| 63 | 62 | * initialized the first time that session is used for querying. This method |
| 64 | 63 | * is thus only useful if you use {@link Cluster#newSession} and want to |
| 65 | 64 | * explicitly force initialization without querying. |
| 66 | - * <p> | |
| 65 | + * <p/> | |
| 67 | 66 | * Session initialization consists in connecting the Session to the known |
| 68 | 67 | * Cassandra hosts (at least those that should not be ignored due to |
| 69 | 68 | * the {@code LoadBalancingPolicy} in place). |
| 70 | - * <p> | |
| 69 | + * <p/> | |
| 71 | 70 | * If the Cluster instance this Session depends on is not itself |
| 72 | 71 | * initialized, it will be initialized by this method. |
| 73 | - * <p> | |
| 72 | + * <p/> | |
| 74 | 73 | * If the session is already initialized, this method is a no-op. |
| 75 | 74 | * |
| 76 | 75 | * @return this {@code Session} object. |
| 77 | - * | |
| 78 | 76 | * @throws NoHostAvailableException if this initialization triggers the |
| 79 | - * Cluster initialization and no host amongst the contact points can be | |
| 80 | - * reached. | |
| 81 | - * @throws AuthenticationException if this initialization triggers the | |
| 82 | - * Cluster initialization and an authentication error occurs while contacting | |
| 83 | - * the initial contact points. | |
| 77 | + * Cluster initialization and no host amongst the contact points can be | |
| 78 | + * reached. | |
| 79 | + * @throws AuthenticationException if this initialization triggers the | |
| 80 | + * Cluster initialization and an authentication error occurs while contacting | |
| 81 | + * the initial contact points. | |
| 84 | 82 | */ |
| 85 | 83 | public Session init(); |
| 86 | 84 | |
| 87 | 85 | /** |
| 88 | 86 | * Executes the provided query. |
| 89 | - * | |
| 87 | + * <p/> | |
| 90 | 88 | * This is a convenience method for {@code execute(new SimpleStatement(query))}. |
| 91 | 89 | * |
| 92 | 90 | * @param query the CQL query to execute. |
| 93 | 91 | * @return the result of the query. That result will never be null but can |
| 94 | 92 | * be empty (and will be for any non SELECT query). |
| 95 | - * | |
| 96 | 93 | * @throws NoHostAvailableException if no host in the cluster can be |
| 97 | - * contacted successfully to execute this query. | |
| 98 | - * @throws QueryExecutionException if the query triggered an execution | |
| 99 | - * exception, i.e. an exception thrown by Cassandra when it cannot execute | |
| 100 | - * the query with the requested consistency level successfully. | |
| 94 | + * contacted successfully to execute this query. | |
| 95 | + * @throws QueryExecutionException if the query triggered an execution | |
| 96 | + * exception, i.e. an exception thrown by Cassandra when it cannot execute | |
| 97 | + * the query with the requested consistency level successfully. | |
| 101 | 98 | * @throws QueryValidationException if the query if invalid (syntax error, |
| 102 | - * unauthorized or any other validation problem). | |
| 99 | + * unauthorized or any other validation problem). | |
| 103 | 100 | */ |
| 104 | 101 | public ResultSet execute(String query); |
| 105 | 102 | |
| 106 | 103 | /** |
| 107 | 104 | * Executes the provided query using the provided value. |
| 108 | - * | |
| 105 | + * <p/> | |
| 109 | 106 | * This is a convenience method for {@code execute(new SimpleStatement(query, values))}. |
| 110 | 107 | * |
| 111 | - * @param query the CQL query to execute. | |
| 108 | + * @param query the CQL query to execute. | |
| 112 | 109 | * @param values values required for the execution of {@code query}. See |
| 113 | - * {@link SimpleStatement#SimpleStatement(String, Object...)} for more detail. | |
| 110 | + * {@link SimpleStatement#SimpleStatement(String, Object...)} for more detail. | |
| 114 | 111 | * @return the result of the query. That result will never be null but can |
| 115 | 112 | * be empty (and will be for any non SELECT query). |
| 116 | - * | |
| 117 | - * @throws NoHostAvailableException if no host in the cluster can be | |
| 118 | - * contacted successfully to execute this query. | |
| 119 | - * @throws QueryExecutionException if the query triggered an execution | |
| 120 | - * exception, i.e. an exception thrown by Cassandra when it cannot execute | |
| 121 | - * the query with the requested consistency level successfully. | |
| 122 | - * @throws QueryValidationException if the query if invalid (syntax error, | |
| 123 | - * unauthorized or any other validation problem). | |
| 113 | + * @throws NoHostAvailableException if no host in the cluster can be | |
| 114 | + * contacted successfully to execute this query. | |
| 115 | + * @throws QueryExecutionException if the query triggered an execution | |
| 116 | + * exception, i.e. an exception thrown by Cassandra when it cannot execute | |
| 117 | + * the query with the requested consistency level successfully. | |
| 118 | + * @throws QueryValidationException if the query if invalid (syntax error, | |
| 119 | + * unauthorized or any other validation problem). | |
| 124 | 120 | * @throws UnsupportedFeatureException if version 1 of the protocol |
| 125 | - * is in use (i.e. if you've force version 1 through {@link Cluster.Builder#withProtocolVersion} | |
| 126 | - * or you use Cassandra 1.2). | |
| 121 | + * is in use (i.e. if you've force version 1 through {@link Cluster.Builder#withProtocolVersion} | |
| 122 | + * or you use Cassandra 1.2). | |
| 127 | 123 | */ |
| 128 | 124 | public ResultSet execute(String query, Object... values); |
| 129 | 125 | |
| 130 | 126 | /** |
| 131 | 127 | * Executes the provided query. |
| 132 | - * | |
| 128 | + * <p/> | |
| 133 | 129 | * This method blocks until at least some result has been received from the |
| 134 | 130 | * database. However, for SELECT queries, it does not guarantee that the |
| 135 | 131 | * result has been received in full. But it does guarantee that some |
| @@ -140,24 +136,23 @@ | ||
| 140 | 136 | * @param statement the CQL query to execute (that can be any {@code Statement}). |
| 141 | 137 | * @return the result of the query. That result will never be null but can |
| 142 | 138 | * be empty (and will be for any non SELECT query). |
| 143 | - * | |
| 144 | - * @throws NoHostAvailableException if no host in the cluster can be | |
| 145 | - * contacted successfully to execute this query. | |
| 146 | - * @throws QueryExecutionException if the query triggered an execution | |
| 147 | - * exception, i.e. an exception thrown by Cassandra when it cannot execute | |
| 148 | - * the query with the requested consistency level successfully. | |
| 149 | - * @throws QueryValidationException if the query if invalid (syntax error, | |
| 150 | - * unauthorized or any other validation problem). | |
| 139 | + * @throws NoHostAvailableException if no host in the cluster can be | |
| 140 | + * contacted successfully to execute this query. | |
| 141 | + * @throws QueryExecutionException if the query triggered an execution | |
| 142 | + * exception, i.e. an exception thrown by Cassandra when it cannot execute | |
| 143 | + * the query with the requested consistency level successfully. | |
| 144 | + * @throws QueryValidationException if the query if invalid (syntax error, | |
| 145 | + * unauthorized or any other validation problem). | |
| 151 | 146 | * @throws UnsupportedFeatureException if the protocol version 1 is in use and |
| 152 | - * a feature not supported has been used. Features that are not supported by | |
| 153 | - * the version protocol 1 include: BatchStatement, ResultSet paging and binary | |
| 154 | - * values in RegularStatement. | |
| 147 | + * a feature not supported has been used. Features that are not supported by | |
| 148 | + * the version protocol 1 include: BatchStatement, ResultSet paging and binary | |
| 149 | + * values in RegularStatement. | |
| 155 | 150 | */ |
| 156 | 151 | public ResultSet execute(Statement statement); |
| 157 | 152 | |
| 158 | 153 | /** |
| 159 | 154 | * Executes the provided query asynchronously. |
| 160 | - * <p> | |
| 155 | + * <p/> | |
| 161 | 156 | * This is a convenience method for {@code executeAsync(new SimpleStatement(query))}. |
| 162 | 157 | * |
| 163 | 158 | * @param query the CQL query to execute. |
| @@ -167,40 +162,38 @@ | ||
| 167 | 162 | |
| 168 | 163 | /** |
| 169 | 164 | * Executes the provided query asynchronously using the provided values. |
| 170 | - * | |
| 165 | + * <p/> | |
| 171 | 166 | * This is a convenience method for {@code executeAsync(new SimpleStatement(query, values))}. |
| 172 | 167 | * |
| 173 | - * @param query the CQL query to execute. | |
| 168 | + * @param query the CQL query to execute. | |
| 174 | 169 | * @param values values required for the execution of {@code query}. See |
| 175 | - * {@link SimpleStatement#SimpleStatement(String, Object...)} for more detail. | |
| 170 | + * {@link SimpleStatement#SimpleStatement(String, Object...)} for more detail. | |
| 176 | 171 | * @return a future on the result of the query. |
| 177 | - * | |
| 178 | 172 | * @throws UnsupportedFeatureException if version 1 of the protocol |
| 179 | - * is in use (i.e. if you've force version 1 through {@link Cluster.Builder#withProtocolVersion} | |
| 180 | - * or you use Cassandra 1.2). | |
| 173 | + * is in use (i.e. if you've force version 1 through {@link Cluster.Builder#withProtocolVersion} | |
| 174 | + * or you use Cassandra 1.2). | |
| 181 | 175 | */ |
| 182 | 176 | public ResultSetFuture executeAsync(String query, Object... values); |
| 183 | 177 | |
| 184 | 178 | /** |
| 185 | 179 | * Executes the provided query asynchronously. |
| 186 | - * | |
| 180 | + * <p/> | |
| 187 | 181 | * This method does not block. It returns as soon as the query has been |
| 188 | 182 | * passed to the underlying network stack. In particular, returning from |
| 189 | 183 | * this method does not guarantee that the query is valid or has even been |
| 190 | 184 | * submitted to a live node. Any exception pertaining to the failure of the |
| 191 | 185 | * query will be thrown when accessing the {@link ResultSetFuture}. |
| 192 | - * <p> | |
| 186 | + * <p/> | |
| 193 | 187 | * Note that for queries that doesn't return a result (INSERT, UPDATE and |
| 194 | 188 | * DELETE), you will need to access the ResultSetFuture (that is call one of |
| 195 | 189 | * its get method to make sure the query was successful. |
| 196 | 190 | * |
| 197 | 191 | * @param statement the CQL query to execute (that can be either any {@code Statement}. |
| 198 | 192 | * @return a future on the result of the query. |
| 199 | - * | |
| 200 | 193 | * @throws UnsupportedFeatureException if the protocol version 1 is in use and |
| 201 | - * a feature not supported has been used. Features that are not supported by | |
| 202 | - * the version protocol 1 include: BatchStatement, ResultSet paging and binary | |
| 203 | - * values in RegularStatement. | |
| 194 | + * a feature not supported has been used. Features that are not supported by | |
| 195 | + * the version protocol 1 include: BatchStatement, ResultSet paging and binary | |
| 196 | + * values in RegularStatement. | |
| 204 | 197 | */ |
| 205 | 198 | public ResultSetFuture executeAsync(Statement statement); |
| 206 | 199 | |
| @@ -209,15 +202,14 @@ | ||
| 209 | 202 | * |
| 210 | 203 | * @param query the CQL query string to prepare |
| 211 | 204 | * @return the prepared statement corresponding to {@code query}. |
| 212 | - * | |
| 213 | 205 | * @throws NoHostAvailableException if no host in the cluster can be |
| 214 | - * contacted successfully to prepare this query. | |
| 206 | + * contacted successfully to prepare this query. | |
| 215 | 207 | */ |
| 216 | 208 | public PreparedStatement prepare(String query); |
| 217 | 209 | |
| 218 | 210 | /** |
| 219 | 211 | * Prepares the provided query. |
| 220 | - * <p> | |
| 212 | + * <p/> | |
| 221 | 213 | * This method is essentially a shortcut for {@code prepare(statement.getQueryString())}, |
| 222 | 214 | * but note that the resulting {@code PreparedStatement} will inherit the query properties |
| 223 | 215 | * set on {@code statement}. Concretely, this means that in the following code: |
| @@ -227,7 +219,7 @@ | ||
| 227 | 219 | * session.execute(prepared.bind("someValue")); |
| 228 | 220 | * </pre> |
| 229 | 221 | * the final execution will be performed with Quorum consistency. |
| 230 | - * <p> | |
| 222 | + * <p/> | |
| 231 | 223 | * Please note that if the same CQL statement is prepared more than once, all |
| 232 | 224 | * calls to this method will return the same {@code PreparedStatement} object |
| 233 | 225 | * but the method will still apply the properties of the prepared |
| @@ -235,19 +227,18 @@ | ||
| 235 | 227 | * |
| 236 | 228 | * @param statement the statement to prepare |
| 237 | 229 | * @return the prepared statement corresponding to {@code statement}. |
| 238 | - * | |
| 239 | 230 | * @throws NoHostAvailableException if no host in the cluster can be |
| 240 | - * contacted successfully to prepare this statement. | |
| 231 | + * contacted successfully to prepare this statement. | |
| 241 | 232 | * @throws IllegalArgumentException if {@code statement.getValues() != null} |
| 242 | - * (values for executing a prepared statement should be provided after preparation | |
| 243 | - * though the {@link PreparedStatement#bind} method or through a corresponding | |
| 244 | - * {@link BoundStatement}). | |
| 233 | + * (values for executing a prepared statement should be provided after preparation | |
| 234 | + * though the {@link PreparedStatement#bind} method or through a corresponding | |
| 235 | + * {@link BoundStatement}). | |
| 245 | 236 | */ |
| 246 | 237 | public PreparedStatement prepare(RegularStatement statement); |
| 247 | 238 | |
| 248 | 239 | /** |
| 249 | 240 | * Prepares the provided query string asynchronously. |
| 250 | - * <p> | |
| 241 | + * <p/> | |
| 251 | 242 | * This method is equivalent to {@link #prepare(String)} except that it |
| 252 | 243 | * does not block but return a future instead. Any error during preparation will |
| 253 | 244 | * be thrown when accessing the future, not by this method itself. |
| @@ -259,11 +250,11 @@ | ||
| 259 | 250 | |
| 260 | 251 | /** |
| 261 | 252 | * Prepares the provided query asynchronously. |
| 262 | - * <p> | |
| 253 | + * <p/> | |
| 263 | 254 | * This method is essentially a shortcut for {@code prepareAsync(statement.getQueryString())}, |
| 264 | 255 | * but with the additional effect that the resulting {@code |
| 265 | 256 | * PreparedStatement} will inherit the query properties set on {@code statement}. |
| 266 | - * <p> | |
| 257 | + * <p/> | |
| 267 | 258 | * Please note that if the same CQL statement is prepared more than once, all |
| 268 | 259 | * calls to this method will return the same {@code PreparedStatement} object |
| 269 | 260 | * but the method will still apply the properties of the prepared |
| @@ -271,31 +262,29 @@ | ||
| 271 | 262 | * |
| 272 | 263 | * @param statement the statement to prepare |
| 273 | 264 | * @return a future on the prepared statement corresponding to {@code statement}. |
| 274 | - * | |
| 275 | - * @see Session#prepare(RegularStatement) | |
| 276 | - * | |
| 277 | 265 | * @throws IllegalArgumentException if {@code statement.getValues() != null} |
| 278 | - * (values for executing a prepared statement should be provided after preparation | |
| 279 | - * though the {@link PreparedStatement#bind} method or through a corresponding | |
| 280 | - * {@link BoundStatement}). | |
| 266 | + * (values for executing a prepared statement should be provided after preparation | |
| 267 | + * though the {@link PreparedStatement#bind} method or through a corresponding | |
| 268 | + * {@link BoundStatement}). | |
| 269 | + * @see Session#prepare(RegularStatement) | |
| 281 | 270 | */ |
| 282 | 271 | public ListenableFuture<PreparedStatement> prepareAsync(RegularStatement statement); |
| 283 | 272 | |
| 284 | 273 | /** |
| 285 | 274 | * Initiates a shutdown of this session instance. |
| 286 | - * <p> | |
| 275 | + * <p/> | |
| 287 | 276 | * This method is asynchronous and return a future on the completion |
| 288 | 277 | * of the shutdown process. As soon a the session is shutdown, no |
| 289 | 278 | * new request will be accepted, but already submitted queries are |
| 290 | 279 | * allowed to complete. This method closes all connections of this |
| 291 | 280 | * session and reclaims all resources used by it. |
| 292 | - * <p> | |
| 281 | + * <p/> | |
| 293 | 282 | * If for some reason you wish to expedite this process, the |
| 294 | 283 | * {@link CloseFuture#force} can be called on the result future. |
| 295 | - * <p> | |
| 284 | + * <p/> | |
| 296 | 285 | * This method has no particular effect if the session was already closed |
| 297 | 286 | * (in which case the returned future will return immediately). |
| 298 | - * <p> | |
| 287 | + * <p/> | |
| 299 | 288 | * Note that this method does not close the corresponding {@code Cluster} |
| 300 | 289 | * instance (which holds additional resources, in particular internal |
| 301 | 290 | * executors that must be shut down in order for the client program to |
| @@ -310,9 +299,9 @@ | ||
| 310 | 299 | /** |
| 311 | 300 | * Initiates a shutdown of this session instance and blocks until |
| 312 | 301 | * that shutdown completes. |
| 313 | - * <p> | |
| 302 | + * <p/> | |
| 314 | 303 | * This method is a shortcut for {@code closeAsync().get()}. |
| 315 | - * <p> | |
| 304 | + * <p/> | |
| 316 | 305 | * Note that this method does not close the corresponding {@code Cluster} |
| 317 | 306 | * instance (which holds additional resources, in particular internal |
| 318 | 307 | * executors that must be shut down in order for the client program to |
| @@ -324,7 +313,7 @@ | ||
| 324 | 313 | |
| 325 | 314 | /** |
| 326 | 315 | * Whether this Session instance has been closed. |
| 327 | - * <p> | |
| 316 | + * <p/> | |
| 328 | 317 | * Note that this method returns true as soon as one closing this Session |
| 329 | 318 | * has started but it does not guarantee that the closing is done. If you |
| 330 | 319 | * want to guarantee that the closing is done, you can call {@code close()} |
| @@ -345,7 +334,7 @@ | ||
| 345 | 334 | |
| 346 | 335 | /** |
| 347 | 336 | * Return a snapshot of the state of this Session. |
| 348 | - * <p> | |
| 337 | + * <p/> | |
| 349 | 338 | * The returned object provides information on which hosts the session is |
| 350 | 339 | * connected to, how many connections are opened to each host, etc... |
| 351 | 340 | * The returned object is immutable, it is a snapshot of the Session State |
| @@ -357,7 +346,7 @@ | ||
| 357 | 346 | |
| 358 | 347 | /** |
| 359 | 348 | * The state of a Session. |
| 360 | - * <p> | |
| 349 | + * <p/> | |
| 361 | 350 | * This mostly exposes information on the connections maintained by a Session: |
| 362 | 351 | * which host it is connected to, how many connection is has for each host, etc... |
| 363 | 352 | */ |
| @@ -372,7 +361,7 @@ | ||
| 372 | 361 | /** |
| 373 | 362 | * The hosts to which the session is currently connected (more precisely, at the time |
| 374 | 363 | * this State has been grabbed). |
| 375 | - * <p> | |
| 364 | + * <p/> | |
| 376 | 365 | * Please note that this method really returns the hosts for which the session currently |
| 377 | 366 | * holds a connection pool. A such, it's unlikely but not impossible for a host to be listed |
| 378 | 367 | * in the output of this method but to have {@code getOpenConnections} return 0, if the |
| @@ -384,7 +373,7 @@ | ||
| 384 | 373 | |
| 385 | 374 | /** |
| 386 | 375 | * The number of open connections to a given host. |
| 387 | - * <p> | |
| 376 | + * <p/> | |
| 388 | 377 | * Note that this refers to <em>active</em> connections. The actual number of connections also |
| 389 | 378 | * includes {@link #getTrashedConnections(Host)}. |
| 390 | 379 | * |
| @@ -396,7 +385,7 @@ | ||
| 396 | 385 | |
| 397 | 386 | /** |
| 398 | 387 | * The number of "trashed" connections to a given host. |
| 399 | - * <p> | |
| 388 | + * <p/> | |
| 400 | 389 | * When the load to a host decreases, the driver will reclaim some connections in order to save |
| 401 | 390 | * resources. No requests are sent to these connections anymore, but they are kept open for an |
| 402 | 391 | * additional amount of time ({@link PoolingOptions#getIdleTimeoutSeconds()}), in case the load |
| @@ -410,7 +399,7 @@ | ||
| 410 | 399 | |
| 411 | 400 | /** |
| 412 | 401 | * The number of queries that are currently being executed though a given host. |
| 413 | - * <p> | |
| 402 | + * <p/> | |
| 414 | 403 | * This correspond to the number of queries that have been sent (by the session this |
| 415 | 404 | * is a State of) to the Cassandra Host on one of its connection but haven't yet returned. |
| 416 | 405 | * In that sense this provide a sort of measure of how busy the connections to that node |
modified driver-core/src/main/java/com/datastax/driver/core/SessionManager.java +42 −40
| @@ -15,19 +15,6 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.net.InetSocketAddress; | |
| 19 | -import java.nio.ByteBuffer; | |
| 20 | -import java.util.*; | |
| 21 | -import java.util.concurrent.*; | |
| 22 | -import java.util.concurrent.atomic.AtomicReference; | |
| 23 | - | |
| 24 | -import com.google.common.base.Functions; | |
| 25 | -import com.google.common.collect.ImmutableList; | |
| 26 | -import com.google.common.collect.Lists; | |
| 27 | -import com.google.common.util.concurrent.*; | |
| 28 | -import org.slf4j.Logger; | |
| 29 | -import org.slf4j.LoggerFactory; | |
| 30 | - | |
| 31 | 18 | import com.datastax.driver.core.Message.Response; |
| 32 | 19 | import com.datastax.driver.core.exceptions.DriverInternalError; |
| 33 | 20 | import com.datastax.driver.core.exceptions.InvalidQueryException; |
| @@ -36,6 +23,21 @@ | ||
| 36 | 23 | import com.datastax.driver.core.policies.ReconnectionPolicy; |
| 37 | 24 | import com.datastax.driver.core.policies.SpeculativeExecutionPolicy; |
| 38 | 25 | import com.datastax.driver.core.utils.MoreFutures; |
| 26 | +import com.google.common.base.Functions; | |
| 27 | +import com.google.common.collect.ImmutableList; | |
| 28 | +import com.google.common.collect.Lists; | |
| 29 | +import com.google.common.util.concurrent.*; | |
| 30 | +import org.slf4j.Logger; | |
| 31 | +import org.slf4j.LoggerFactory; | |
| 32 | + | |
| 33 | +import java.net.InetSocketAddress; | |
| 34 | +import java.nio.ByteBuffer; | |
| 35 | +import java.util.*; | |
| 36 | +import java.util.concurrent.ConcurrentHashMap; | |
| 37 | +import java.util.concurrent.ConcurrentMap; | |
| 38 | +import java.util.concurrent.ExecutionException; | |
| 39 | +import java.util.concurrent.TimeUnit; | |
| 40 | +import java.util.concurrent.atomic.AtomicReference; | |
| 39 | 41 | |
| 40 | 42 | /** |
| 41 | 43 | * Driver implementation of the Session interface. |
| @@ -83,14 +85,14 @@ | ||
| 83 | 85 | Collection<Host> hosts = cluster.getMetadata().allHosts(); |
| 84 | 86 | ListenableFuture<?> allPoolsCreatedFuture = createPools(hosts); |
| 85 | 87 | ListenableFuture<?> allPoolsUpdatedFuture = Futures.transform(allPoolsCreatedFuture, |
| 86 | - new AsyncFunction<Object, Object>() { | |
| 87 | - @Override | |
| 88 | - @SuppressWarnings("unchecked") | |
| 89 | - public ListenableFuture<Object> apply(Object input) throws Exception { | |
| 90 | - isInit = true; | |
| 91 | - return (ListenableFuture<Object>)updateCreatedPools(); | |
| 92 | - } | |
| 93 | - }); | |
| 88 | + new AsyncFunction<Object, Object>() { | |
| 89 | + @Override | |
| 90 | + @SuppressWarnings("unchecked") | |
| 91 | + public ListenableFuture<Object> apply(Object input) throws Exception { | |
| 92 | + isInit = true; | |
| 93 | + return (ListenableFuture<Object>) updateCreatedPools(); | |
| 94 | + } | |
| 95 | + }); | |
| 94 | 96 | |
| 95 | 97 | Futures.addCallback(allPoolsUpdatedFuture, new FutureCallback<Object>() { |
| 96 | 98 | @Override |
| @@ -162,8 +164,8 @@ | ||
| 162 | 164 | future = new CloseFuture.Forwarding(futures); |
| 163 | 165 | |
| 164 | 166 | return closeFuture.compareAndSet(null, future) |
| 165 | - ? future | |
| 166 | - : closeFuture.get(); // We raced, it's ok, return the future that was actually set | |
| 167 | + ? future | |
| 168 | + : closeFuture.get(); // We raced, it's ok, return the future that was actually set | |
| 167 | 169 | } |
| 168 | 170 | |
| 169 | 171 | public boolean isClosed() { |
| @@ -183,10 +185,10 @@ | ||
| 183 | 185 | public ListenableFuture<PreparedStatement> apply(Response response) { |
| 184 | 186 | switch (response.type) { |
| 185 | 187 | case RESULT: |
| 186 | - Responses.Result rm = (Responses.Result)response; | |
| 188 | + Responses.Result rm = (Responses.Result) response; | |
| 187 | 189 | switch (rm.kind) { |
| 188 | 190 | case PREPARED: |
| 189 | - Responses.Result.Prepared pmsg = (Responses.Result.Prepared)rm; | |
| 191 | + Responses.Result.Prepared pmsg = (Responses.Result.Prepared) rm; | |
| 190 | 192 | PreparedStatement stmt = DefaultPreparedStatement.fromMessage(pmsg, cluster.getMetadata(), query, poolsState.keyspace); |
| 191 | 193 | stmt = cluster.manager.addPrepared(stmt); |
| 192 | 194 | if (cluster.getConfiguration().getQueryOptions().isPrepareOnAllHosts()) { |
| @@ -198,14 +200,14 @@ | ||
| 198 | 200 | } |
| 199 | 201 | default: |
| 200 | 202 | return Futures.immediateFailedFuture( |
| 201 | - new DriverInternalError(String.format("%s response received when prepared statement was expected", rm.kind))); | |
| 203 | + new DriverInternalError(String.format("%s response received when prepared statement was expected", rm.kind))); | |
| 202 | 204 | } |
| 203 | 205 | case ERROR: |
| 204 | 206 | return Futures.immediateFailedFuture( |
| 205 | - ((Responses.Error)response).asException(future.getAddress())); | |
| 207 | + ((Responses.Error) response).asException(future.getAddress())); | |
| 206 | 208 | default: |
| 207 | 209 | return Futures.immediateFailedFuture( |
| 208 | - new DriverInternalError(String.format("%s response received when prepared statement was expected", response.type))); | |
| 210 | + new DriverInternalError(String.format("%s response received when prepared statement was expected", response.type))); | |
| 209 | 211 | } |
| 210 | 212 | } |
| 211 | 213 | }); |
| @@ -356,7 +358,7 @@ | ||
| 356 | 358 | cluster.manager.logUnsupportedVersionProtocol(host); |
| 357 | 359 | cluster.manager.triggerOnDown(host, false); |
| 358 | 360 | } else if (t instanceof ClusterNameMismatchException) { |
| 359 | - ClusterNameMismatchException e = (ClusterNameMismatchException)t; | |
| 361 | + ClusterNameMismatchException e = (ClusterNameMismatchException) t; | |
| 360 | 362 | cluster.manager.logClusterNameMismatch(host, e.expectedClusterName, e.actualClusterName); |
| 361 | 363 | cluster.manager.triggerOnDown(host, false); |
| 362 | 364 | } else { |
| @@ -373,8 +375,8 @@ | ||
| 373 | 375 | CloseFuture removePool(Host host) { |
| 374 | 376 | final HostConnectionPool pool = pools.remove(host); |
| 375 | 377 | return pool == null |
| 376 | - ? CloseFuture.immediateFuture() | |
| 377 | - : pool.closeAsync(); | |
| 378 | + ? CloseFuture.immediateFuture() | |
| 379 | + : pool.closeAsync(); | |
| 378 | 380 | } |
| 379 | 381 | |
| 380 | 382 | /* |
| @@ -502,16 +504,16 @@ | ||
| 502 | 504 | } |
| 503 | 505 | |
| 504 | 506 | if (statement instanceof StatementWrapper) |
| 505 | - statement = ((StatementWrapper)statement).getWrappedStatement(); | |
| 507 | + statement = ((StatementWrapper) statement).getWrappedStatement(); | |
| 506 | 508 | |
| 507 | 509 | if (statement instanceof RegularStatement) { |
| 508 | - RegularStatement rs = (RegularStatement)statement; | |
| 510 | + RegularStatement rs = (RegularStatement) statement; | |
| 509 | 511 | |
| 510 | 512 | // It saddens me that we special case for the query builder here, but for now this is simpler. |
| 511 | 513 | // We could provide a general API in RegularStatement instead at some point but it's unclear what's |
| 512 | 514 | // the cleanest way to do that is right now (and it's probably not really that useful anyway). |
| 513 | 515 | if (protoVersion == 1 && rs instanceof com.datastax.driver.core.querybuilder.BuiltStatement) |
| 514 | - ((com.datastax.driver.core.querybuilder.BuiltStatement)rs).setForceNoValues(true); | |
| 516 | + ((com.datastax.driver.core.querybuilder.BuiltStatement) rs).setForceNoValues(true); | |
| 515 | 517 | |
| 516 | 518 | ByteBuffer[] rawValues = rs.getValues(); |
| 517 | 519 | |
| @@ -523,10 +525,10 @@ | ||
| 523 | 525 | Requests.QueryProtocolOptions options = new Requests.QueryProtocolOptions(consistency, values, false, fetchSize, usedPagingState, serialConsistency); |
| 524 | 526 | return new Requests.Query(qString, options, statement.isTracing()); |
| 525 | 527 | } else if (statement instanceof BoundStatement) { |
| 526 | - BoundStatement bs = (BoundStatement)statement; | |
| 528 | + BoundStatement bs = (BoundStatement) statement; | |
| 527 | 529 | if (!cluster.manager.preparedQueries.containsKey(bs.statement.getPreparedId().id)) { |
| 528 | 530 | throw new InvalidQueryException(String.format("Tried to execute unknown prepared query : %s. " |
| 529 | - + "You may have used a PreparedStatement that was created with another Cluster instance.", bs.statement.getPreparedId().id)); | |
| 531 | + + "You may have used a PreparedStatement that was created with another Cluster instance.", bs.statement.getPreparedId().id)); | |
| 530 | 532 | } |
| 531 | 533 | boolean skipMetadata = protoVersion != 1 && bs.statement.getPreparedId().resultSetMetadata != null; |
| 532 | 534 | Requests.QueryProtocolOptions options = new Requests.QueryProtocolOptions(consistency, Arrays.asList(bs.values), skipMetadata, fetchSize, usedPagingState, serialConsistency); |
| @@ -538,7 +540,7 @@ | ||
| 538 | 540 | if (protoVersion == 1) |
| 539 | 541 | throw new UnsupportedFeatureException("Protocol level batching is not supported"); |
| 540 | 542 | |
| 541 | - BatchStatement bs = (BatchStatement)statement; | |
| 543 | + BatchStatement bs = (BatchStatement) statement; | |
| 542 | 544 | BatchStatement.IdAndValues idAndVals = bs.getIdAndValues(); |
| 543 | 545 | return new Requests.Batch(bs.batchType, idAndVals.ids, idAndVals.values, consistency, statement.isTracing()); |
| 544 | 546 | } |
| @@ -546,7 +548,7 @@ | ||
| 546 | 548 | |
| 547 | 549 | /** |
| 548 | 550 | * Execute the provided request. |
| 549 | - * | |
| 551 | + * <p/> | |
| 550 | 552 | * This method will find a suitable node to connect to using the |
| 551 | 553 | * {@link LoadBalancingPolicy} and handle host failover. |
| 552 | 554 | */ |
| @@ -593,8 +595,8 @@ | ||
| 593 | 595 | } |
| 594 | 596 | // Return the statement when all futures are done |
| 595 | 597 | return Futures.transform( |
| 596 | - Futures.successfulAsList(futures), | |
| 597 | - Functions.constant(statement)); | |
| 598 | + Futures.successfulAsList(futures), | |
| 599 | + Functions.constant(statement)); | |
| 598 | 600 | } |
| 599 | 601 | |
| 600 | 602 | ResultSetFuture executeQuery(Message.Request msg, Statement statement) { |
modified driver-core/src/main/java/com/datastax/driver/core/SimpleJSONParser.java +10 −10
| @@ -22,15 +22,15 @@ | ||
| 22 | 22 | * The only reason we need to read json in the driver is because for |
| 23 | 23 | * historical reason Cassandra encodes a few properties using json in |
| 24 | 24 | * the schema and we need to decode them. |
| 25 | - * | |
| 25 | + * <p/> | |
| 26 | 26 | * We however don't need a full-blown JSON library because: |
| 27 | - * 1) we know we only need to decode string lists and string maps | |
| 28 | - * 2) we can basically assume the input is valid, we don't particularly | |
| 29 | - * have to bother about decoding exactly JSON as long as we at least | |
| 30 | - * decode what we need. | |
| 31 | - * 3) we don't really care much about performance, none of this is done | |
| 32 | - * in performance sensitive parts. | |
| 33 | - * | |
| 27 | + * 1) we know we only need to decode string lists and string maps | |
| 28 | + * 2) we can basically assume the input is valid, we don't particularly | |
| 29 | + * have to bother about decoding exactly JSON as long as we at least | |
| 30 | + * decode what we need. | |
| 31 | + * 3) we don't really care much about performance, none of this is done | |
| 32 | + * in performance sensitive parts. | |
| 33 | + * <p/> | |
| 34 | 34 | * So instead of pulling a new dependency, we roll out our own very dumb |
| 35 | 35 | * parser. We should obviously not expose this publicly. |
| 36 | 36 | */ |
| @@ -123,7 +123,7 @@ | ||
| 123 | 123 | * the closing double-quote. |
| 124 | 124 | */ |
| 125 | 125 | private String nextString() { |
| 126 | - assert input.charAt(idx-1) == '"' : "Char is '" + input.charAt(idx-1) + '\''; | |
| 126 | + assert input.charAt(idx - 1) == '"' : "Char is '" + input.charAt(idx - 1) + '\''; | |
| 127 | 127 | StringBuilder sb = new StringBuilder(); |
| 128 | 128 | while (true) { |
| 129 | 129 | char c = nextChar(); |
| @@ -150,7 +150,7 @@ | ||
| 150 | 150 | sb.append('\r'); |
| 151 | 151 | break; |
| 152 | 152 | case 'u': |
| 153 | - sb.append((char)Integer.parseInt(input.substring(idx, idx+4), 16)); | |
| 153 | + sb.append((char) Integer.parseInt(input.substring(idx, idx + 4), 16)); | |
| 154 | 154 | idx += 4; |
| 155 | 155 | break; |
| 156 | 156 | case '"': |
modified driver-core/src/main/java/com/datastax/driver/core/SimpleStatement.java +18 −25
| @@ -41,7 +41,7 @@ | ||
| 41 | 41 | |
| 42 | 42 | /** |
| 43 | 43 | * Creates a new {@code SimpleStatement} with the provided query string and values. |
| 44 | - * <p> | |
| 44 | + * <p/> | |
| 45 | 45 | * This version of SimpleStatement is useful when you do not want to execute a |
| 46 | 46 | * query only once (and thus do not want to resort to prepared statement), but |
| 47 | 47 | * do not want to convert all column values to string (typically, if you have blob |
| @@ -60,11 +60,11 @@ | ||
| 60 | 60 | * </pre> |
| 61 | 61 | * except that the former version: |
| 62 | 62 | * <ul> |
| 63 | - * <li>Requires only one round-trip to a Cassandra node.</li> | |
| 64 | - * <li>Does not left any prepared statement stored in memory (neither client or | |
| 65 | - * server side) once it has been executed.</li> | |
| 63 | + * <li>Requires only one round-trip to a Cassandra node.</li> | |
| 64 | + * <li>Does not left any prepared statement stored in memory (neither client or | |
| 65 | + * server side) once it has been executed.</li> | |
| 66 | 66 | * </ul> |
| 67 | - * <p> | |
| 67 | + * <p/> | |
| 68 | 68 | * Note that the type of the {@code values} provided to this method will |
| 69 | 69 | * not be validated by the driver as is done by {@link BoundStatement#bind} since |
| 70 | 70 | * {@code query} is not parsed (and hence the driver cannot know what those value |
| @@ -75,7 +75,7 @@ | ||
| 75 | 75 | * thrown by this constructor however if one of the value does not correspond to |
| 76 | 76 | * any CQL3 type (for instance, if it is a custom class). |
| 77 | 77 | * |
| 78 | - * @param query the query string. | |
| 78 | + * @param query the query string. | |
| 79 | 79 | * @param values values required for the execution of {@code query}. |
| 80 | 80 | * @throws IllegalArgumentException if the number of values is greater than 65535. |
| 81 | 81 | */ |
| @@ -92,7 +92,7 @@ | ||
| 92 | 92 | Object value = values[i]; |
| 93 | 93 | try { |
| 94 | 94 | if (value instanceof Token) |
| 95 | - value = ((Token)value).getValue(); | |
| 95 | + value = ((Token) value).getValue(); | |
| 96 | 96 | serializedValues[i] = DataType.serializeValue(value); |
| 97 | 97 | } catch (IllegalArgumentException e) { |
| 98 | 98 | // Catch and rethrow to provide a more helpful error message (one that include which value is bad) |
| @@ -119,7 +119,7 @@ | ||
| 119 | 119 | |
| 120 | 120 | /** |
| 121 | 121 | * Returns the number of values provided for this statement. |
| 122 | - * <p> | |
| 122 | + * <p/> | |
| 123 | 123 | * This is more efficient than calling {@link #getValues()} and getting the length |
| 124 | 124 | * of the returned array, because {@code getValues()} does some internal conversions. |
| 125 | 125 | * |
| @@ -134,8 +134,7 @@ | ||
| 134 | 134 | * |
| 135 | 135 | * @param i the index to retrieve. |
| 136 | 136 | * @return the value of the {@code i}th value of this statement. |
| 137 | - * | |
| 138 | - * @throws IllegalStateException if this statement does not have values. | |
| 137 | + * @throws IllegalStateException if this statement does not have values. | |
| 139 | 138 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 140 | 139 | */ |
| 141 | 140 | public Object getObject(int i) { |
| @@ -148,14 +147,13 @@ | ||
| 148 | 147 | |
| 149 | 148 | /** |
| 150 | 149 | * Returns the routing key for the query. |
| 151 | - * <p> | |
| 150 | + * <p/> | |
| 152 | 151 | * Unless the routing key has been explicitly set through |
| 153 | 152 | * {@link #setRoutingKey}, this method will return {@code null} to |
| 154 | 153 | * avoid having to parse the query string to retrieve the partition key. |
| 155 | 154 | * |
| 156 | 155 | * @return the routing key set through {@link #setRoutingKey} if such a key |
| 157 | 156 | * was set, {@code null} otherwise. |
| 158 | - * | |
| 159 | 157 | * @see Statement#getRoutingKey |
| 160 | 158 | */ |
| 161 | 159 | @Override |
| @@ -165,18 +163,17 @@ | ||
| 165 | 163 | |
| 166 | 164 | /** |
| 167 | 165 | * Sets the routing key for this query. |
| 168 | - * <p> | |
| 166 | + * <p/> | |
| 169 | 167 | * This method allows you to manually provide a routing key for this query. It |
| 170 | 168 | * is thus optional since the routing key is only an hint for token aware |
| 171 | 169 | * load balancing policy but is never mandatory. |
| 172 | - * <p> | |
| 170 | + * <p/> | |
| 173 | 171 | * If the partition key for the query is composite, use the |
| 174 | 172 | * {@link #setRoutingKey(ByteBuffer...)} method instead to build the |
| 175 | 173 | * routing key. |
| 176 | 174 | * |
| 177 | 175 | * @param routingKey the raw (binary) value to use as routing key. |
| 178 | 176 | * @return this {@code SimpleStatement} object. |
| 179 | - * | |
| 180 | 177 | * @see Statement#getRoutingKey |
| 181 | 178 | */ |
| 182 | 179 | public SimpleStatement setRoutingKey(ByteBuffer routingKey) { |
| @@ -186,14 +183,13 @@ | ||
| 186 | 183 | |
| 187 | 184 | /** |
| 188 | 185 | * Returns the keyspace this query operates on. |
| 189 | - * <p> | |
| 186 | + * <p/> | |
| 190 | 187 | * Unless the keyspace has been explicitly set through {@link #setKeyspace}, |
| 191 | 188 | * this method will return {@code null} to avoid having to parse the query |
| 192 | 189 | * string. |
| 193 | 190 | * |
| 194 | 191 | * @return the keyspace set through {@link #setKeyspace} if such keyspace was |
| 195 | 192 | * set, {@code null} otherwise. |
| 196 | - * | |
| 197 | 193 | * @see Statement#getKeyspace |
| 198 | 194 | */ |
| 199 | 195 | @Override |
| @@ -203,18 +199,17 @@ | ||
| 203 | 199 | |
| 204 | 200 | /** |
| 205 | 201 | * Sets the keyspace this query operates on. |
| 206 | - * <p> | |
| 202 | + * <p/> | |
| 207 | 203 | * This method allows you to manually provide a keyspace for this query. It |
| 208 | 204 | * is thus optional since the value returned by this method is only an hint |
| 209 | 205 | * for token aware load balancing policy but is never mandatory. |
| 210 | - * <p> | |
| 206 | + * <p/> | |
| 211 | 207 | * Do note that if the query does not use a fully qualified keyspace, then |
| 212 | 208 | * you do not need to set the keyspace through that method as the |
| 213 | 209 | * currently logged in keyspace will be used. |
| 214 | 210 | * |
| 215 | 211 | * @param keyspace the name of the keyspace this query operates on. |
| 216 | 212 | * @return this {@code SimpleStatement} object. |
| 217 | - * | |
| 218 | 213 | * @see Statement#getKeyspace |
| 219 | 214 | */ |
| 220 | 215 | public SimpleStatement setKeyspace(String keyspace) { |
| @@ -224,15 +219,14 @@ | ||
| 224 | 219 | |
| 225 | 220 | /** |
| 226 | 221 | * Sets the routing key for this query. |
| 227 | - * <p> | |
| 222 | + * <p/> | |
| 228 | 223 | * See {@link #setRoutingKey(ByteBuffer)} for more information. This |
| 229 | 224 | * method is a variant for when the query partition key is composite and |
| 230 | 225 | * thus the routing key must be built from multiple values. |
| 231 | 226 | * |
| 232 | 227 | * @param routingKeyComponents the raw (binary) values to compose to obtain |
| 233 | - * the routing key. | |
| 228 | + * the routing key. | |
| 234 | 229 | * @return this {@code SimpleStatement} object. |
| 235 | - * | |
| 236 | 230 | * @see Statement#getRoutingKey |
| 237 | 231 | */ |
| 238 | 232 | public SimpleStatement setRoutingKey(ByteBuffer... routingKeyComponents) { |
| @@ -247,8 +241,7 @@ | ||
| 247 | 241 | totalLength += 2 + bb.remaining() + 1; |
| 248 | 242 | |
| 249 | 243 | ByteBuffer out = ByteBuffer.allocate(totalLength); |
| 250 | - for (ByteBuffer buffer : buffers) | |
| 251 | - { | |
| 244 | + for (ByteBuffer buffer : buffers) { | |
| 252 | 245 | ByteBuffer bb = buffer.duplicate(); |
| 253 | 246 | putShortLength(out, bb.remaining()); |
| 254 | 247 | out.put(bb); |
modified driver-core/src/main/java/com/datastax/driver/core/SocketOptions.java +25 −34
| @@ -24,7 +24,7 @@ | ||
| 24 | 24 | /** |
| 25 | 25 | * The default connection timeout in milliseconds if none is set explicitly |
| 26 | 26 | * using {@link #setConnectTimeoutMillis}. |
| 27 | - * <p> | |
| 27 | + * <p/> | |
| 28 | 28 | * That default is of 5 seconds. |
| 29 | 29 | */ |
| 30 | 30 | public static final int DEFAULT_CONNECT_TIMEOUT_MILLIS = 5000; |
| @@ -32,7 +32,7 @@ | ||
| 32 | 32 | /** |
| 33 | 33 | * The default read timeout in milliseconds if none is set explicitly |
| 34 | 34 | * using {@link #setReadTimeoutMillis}. |
| 35 | - * <p> | |
| 35 | + * <p/> | |
| 36 | 36 | * That default is of 12 seconds so as to be slightly bigger that the |
| 37 | 37 | * default Cassandra timeout. |
| 38 | 38 | * |
| @@ -52,11 +52,12 @@ | ||
| 52 | 52 | /** |
| 53 | 53 | * Creates a new {@code SocketOptions} instance with default values. |
| 54 | 54 | */ |
| 55 | - public SocketOptions() {} | |
| 55 | + public SocketOptions() { | |
| 56 | + } | |
| 56 | 57 | |
| 57 | 58 | /** |
| 58 | 59 | * The connection timeout in milliseconds. |
| 59 | - * <p> | |
| 60 | + * <p/> | |
| 60 | 61 | * As the name implies, the connection timeout defines how long the driver |
| 61 | 62 | * waits to establish a new connection to a Cassandra node before giving up. |
| 62 | 63 | * |
| @@ -79,10 +80,10 @@ | ||
| 79 | 80 | |
| 80 | 81 | /** |
| 81 | 82 | * The per-host read timeout in milliseconds. |
| 82 | - * <p> | |
| 83 | + * <p/> | |
| 83 | 84 | * This defines how long the driver will wait for a given Cassandra node to |
| 84 | 85 | * answer a query. |
| 85 | - * <p> | |
| 86 | + * <p/> | |
| 86 | 87 | * Please note that this is not the maximum time a call to {@link Session#execute} may block; |
| 87 | 88 | * this is the maximum time that call will wait for one particular |
| 88 | 89 | * Cassandra host, but other hosts will be tried if one of them times out. In |
| @@ -92,12 +93,12 @@ | ||
| 92 | 93 | * {@link com.datastax.driver.core.policies.LoadBalancingPolicy} in use). |
| 93 | 94 | * If you want to control how long to wait for a query, use {@link Session#executeAsync} |
| 94 | 95 | * and the {@code ResultSetFuture#get(long, TimeUnit)} method. |
| 95 | - * <p> | |
| 96 | + * <p/> | |
| 96 | 97 | * Also note that for efficiency reasons, this read timeout is approximate: it |
| 97 | 98 | * has an accuracy of up to 100 milliseconds (i.e. it may fire up to 100 milliseconds late). |
| 98 | 99 | * It is not meant to be used for precise timeout, but rather as a protection |
| 99 | 100 | * against misbehaving Cassandra nodes. |
| 100 | - * <p> | |
| 101 | + * <p/> | |
| 101 | 102 | * |
| 102 | 103 | * @return the read timeout in milliseconds. |
| 103 | 104 | */ |
| @@ -107,18 +108,18 @@ | ||
| 107 | 108 | |
| 108 | 109 | /** |
| 109 | 110 | * Sets the per-host read timeout in milliseconds. |
| 110 | - * <p> | |
| 111 | + * <p/> | |
| 111 | 112 | * When setting this value, keep in mind the following: |
| 112 | 113 | * <ul> |
| 113 | - * <li>it should be higher than the timeout settings used on the Cassandra side | |
| 114 | - * ({@code *_request_timeout_in_ms} in {@code cassandra.yaml}).</li> | |
| 115 | - * <li>the read timeout is only approximate and only control the timeout to one Cassandra | |
| 116 | - * host, not the full query (see {@link #getReadTimeoutMillis} for more details). If a | |
| 117 | - * high level of precision on the timeout to a request is required, you should use | |
| 118 | - * the {@link ResultSetFuture#get(long, java.util.concurrent.TimeUnit)} method. | |
| 119 | - * </li> | |
| 114 | + * <li>it should be higher than the timeout settings used on the Cassandra side | |
| 115 | + * ({@code *_request_timeout_in_ms} in {@code cassandra.yaml}).</li> | |
| 116 | + * <li>the read timeout is only approximate and only control the timeout to one Cassandra | |
| 117 | + * host, not the full query (see {@link #getReadTimeoutMillis} for more details). If a | |
| 118 | + * high level of precision on the timeout to a request is required, you should use | |
| 119 | + * the {@link ResultSetFuture#get(long, java.util.concurrent.TimeUnit)} method. | |
| 120 | + * </li> | |
| 120 | 121 | * </ul> |
| 121 | - * <p> | |
| 122 | + * <p/> | |
| 122 | 123 | * Setting a value of 0 disables read timeouts. |
| 123 | 124 | * |
| 124 | 125 | * @param readTimeoutMillis the timeout to set. |
| @@ -141,13 +142,12 @@ | ||
| 141 | 142 | |
| 142 | 143 | /** |
| 143 | 144 | * Sets whether to enable TCP keepalive. |
| 144 | - * <p> | |
| 145 | + * <p/> | |
| 145 | 146 | * By default, this option is not set by the driver. The actual value will be the default |
| 146 | 147 | * from the underlying Netty transport (Java NIO or native epoll). |
| 147 | 148 | * |
| 148 | 149 | * @param keepAlive whether to enable or disable the option. |
| 149 | 150 | * @return this {@code SocketOptions}. |
| 150 | - * | |
| 151 | 151 | * @see java.net.SocketOptions#TCP_NODELAY |
| 152 | 152 | */ |
| 153 | 153 | public SocketOptions setKeepAlive(boolean keepAlive) { |
| @@ -167,13 +167,12 @@ | ||
| 167 | 167 | |
| 168 | 168 | /** |
| 169 | 169 | * Sets whether to enable reuse-address. |
| 170 | - * <p> | |
| 170 | + * <p/> | |
| 171 | 171 | * By default, this option is not set by the driver. The actual value will be the default |
| 172 | 172 | * from the underlying Netty transport (Java NIO or native epoll). |
| 173 | 173 | * |
| 174 | 174 | * @param reuseAddress whether to enable or disable the option. |
| 175 | 175 | * @return this {@code SocketOptions}. |
| 176 | - * | |
| 177 | 176 | * @see java.net.SocketOptions#SO_REUSEADDR |
| 178 | 177 | */ |
| 179 | 178 | public SocketOptions setReuseAddress(boolean reuseAddress) { |
| @@ -185,7 +184,6 @@ | ||
| 185 | 184 | * Returns the linger-on-close timeout. |
| 186 | 185 | * |
| 187 | 186 | * @return the value of the option, or {@code null} if it is not set. |
| 188 | - * | |
| 189 | 187 | * @see #setSoLinger(int) |
| 190 | 188 | */ |
| 191 | 189 | public Integer getSoLinger() { |
| @@ -194,13 +192,12 @@ | ||
| 194 | 192 | |
| 195 | 193 | /** |
| 196 | 194 | * Sets the linger-on-close timeout. |
| 197 | - * <p> | |
| 195 | + * <p/> | |
| 198 | 196 | * By default, this option is not set by the driver. The actual value will be the default |
| 199 | 197 | * from the underlying Netty transport (Java NIO or native epoll). |
| 200 | - | |
| 198 | + * | |
| 201 | 199 | * @param soLinger the new value. |
| 202 | 200 | * @return this {@code SocketOptions}. |
| 203 | - * | |
| 204 | 201 | * @see java.net.SocketOptions#SO_LINGER |
| 205 | 202 | */ |
| 206 | 203 | public SocketOptions setSoLinger(int soLinger) { |
| @@ -212,7 +209,6 @@ | ||
| 212 | 209 | * Returns whether Nagle's algorithm is disabled. |
| 213 | 210 | * |
| 214 | 211 | * @return the value of the option ({@code true} means Nagle is disabled), or {@code null} if it is not set. |
| 215 | - * | |
| 216 | 212 | * @see #setTcpNoDelay(boolean) |
| 217 | 213 | */ |
| 218 | 214 | public Boolean getTcpNoDelay() { |
| @@ -221,12 +217,11 @@ | ||
| 221 | 217 | |
| 222 | 218 | /** |
| 223 | 219 | * Sets whether to disable Nagle's algorithm. |
| 224 | - * <p> | |
| 220 | + * <p/> | |
| 225 | 221 | * By default, this option is set to {@code true} (Nagle disabled). |
| 226 | 222 | * |
| 227 | 223 | * @param tcpNoDelay whether to enable or disable the option. |
| 228 | 224 | * @return this {@code SocketOptions}. |
| 229 | - * | |
| 230 | 225 | * @see java.net.SocketOptions#TCP_NODELAY |
| 231 | 226 | */ |
| 232 | 227 | public SocketOptions setTcpNoDelay(boolean tcpNoDelay) { |
| @@ -238,7 +233,6 @@ | ||
| 238 | 233 | * Returns the hint to the size of the underlying buffers for incoming network I/O. |
| 239 | 234 | * |
| 240 | 235 | * @return the value of the option, or {@code null} if it is not set. |
| 241 | - * | |
| 242 | 236 | * @see #setReceiveBufferSize(int) |
| 243 | 237 | */ |
| 244 | 238 | public Integer getReceiveBufferSize() { |
| @@ -247,13 +241,12 @@ | ||
| 247 | 241 | |
| 248 | 242 | /** |
| 249 | 243 | * Sets a hint to the size of the underlying buffers for incoming network I/O. |
| 250 | - * <p> | |
| 244 | + * <p/> | |
| 251 | 245 | * By default, this option is not set by the driver. The actual value will be the default |
| 252 | 246 | * from the underlying Netty transport (Java NIO or native epoll). |
| 253 | 247 | * |
| 254 | 248 | * @param receiveBufferSize the new value. |
| 255 | 249 | * @return this {@code SocketOptions}. |
| 256 | - * | |
| 257 | 250 | * @see java.net.SocketOptions#SO_RCVBUF |
| 258 | 251 | */ |
| 259 | 252 | public SocketOptions setReceiveBufferSize(int receiveBufferSize) { |
| @@ -265,7 +258,6 @@ | ||
| 265 | 258 | * Returns the hint to the size of the underlying buffers for outgoing network I/O. |
| 266 | 259 | * |
| 267 | 260 | * @return the value of the option, or {@code null} if it is not set. |
| 268 | - * | |
| 269 | 261 | * @see #setSendBufferSize(int) |
| 270 | 262 | */ |
| 271 | 263 | public Integer getSendBufferSize() { |
| @@ -274,13 +266,12 @@ | ||
| 274 | 266 | |
| 275 | 267 | /** |
| 276 | 268 | * Sets a hint to the size of the underlying buffers for outgoing network I/O. |
| 277 | - * <p> | |
| 269 | + * <p/> | |
| 278 | 270 | * By default, this option is not set by the driver. The actual value will be the default |
| 279 | 271 | * from the underlying Netty transport (Java NIO or native epoll). |
| 280 | 272 | * |
| 281 | 273 | * @param sendBufferSize the new value. |
| 282 | 274 | * @return this {@code SocketOptions}. |
| 283 | - * | |
| 284 | 275 | * @see java.net.SocketOptions#SO_SNDBUF |
| 285 | 276 | */ |
| 286 | 277 | public SocketOptions setSendBufferSize(int sendBufferSize) { |
modified driver-core/src/main/java/com/datastax/driver/core/Statement.java +29 −31
| @@ -15,15 +15,15 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.nio.ByteBuffer; | |
| 19 | - | |
| 20 | 18 | import com.datastax.driver.core.exceptions.PagingStateException; |
| 21 | 19 | import com.datastax.driver.core.policies.RetryPolicy; |
| 22 | 20 | import com.datastax.driver.core.querybuilder.BuiltStatement; |
| 23 | 21 | |
| 22 | +import java.nio.ByteBuffer; | |
| 23 | + | |
| 24 | 24 | /** |
| 25 | 25 | * An executable query. |
| 26 | - * <p> | |
| 26 | + * <p/> | |
| 27 | 27 | * This represents either a {@link RegularStatement}, a {@link BoundStatement} or a |
| 28 | 28 | * {@link BatchStatement} along with the querying options (consistency level, |
| 29 | 29 | * whether to trace the query, ...). |
| @@ -80,7 +80,7 @@ | ||
| 80 | 80 | |
| 81 | 81 | /** |
| 82 | 82 | * Sets the serial consistency level for the query. |
| 83 | - * | |
| 83 | + * <p/> | |
| 84 | 84 | * The serial consistency level is only used by conditional updates (so INSERT, UPDATE |
| 85 | 85 | * and DELETE with an IF condition). For those, the serial consistency level defines |
| 86 | 86 | * the consistency level of the serial phase (or "paxos" phase) while the |
| @@ -90,20 +90,19 @@ | ||
| 90 | 90 | * QUORUM read is guaranteed to see that write. But if the regular consistency of that |
| 91 | 91 | * write is ANY, then only a read with a consistency of SERIAL is guaranteed to see it |
| 92 | 92 | * (even a read with consistency ALL is not guaranteed to be enough). |
| 93 | - * <p> | |
| 93 | + * <p/> | |
| 94 | 94 | * The serial consistency can only be one of {@code ConsistencyLevel.SERIAL} or |
| 95 | 95 | * {@code ConsistencyLevel.LOCAL_SERIAL}. While {@code ConsistencyLevel.SERIAL} guarantees full |
| 96 | 96 | * linearizability (with other SERIAL updates), {@code ConsistencyLevel.LOCAL_SERIAL} only |
| 97 | 97 | * guarantees it in the local data center. |
| 98 | - * <p> | |
| 98 | + * <p/> | |
| 99 | 99 | * The serial consistency level is ignored for any query that is not a conditional |
| 100 | 100 | * update (serial reads should use the regular consistency level for instance). |
| 101 | 101 | * |
| 102 | 102 | * @param serialConsistency the serial consistency level to set. |
| 103 | 103 | * @return this {@code Statement} object. |
| 104 | - * | |
| 105 | 104 | * @throws IllegalArgumentException if {@code serialConsistency} is not one of |
| 106 | - * {@code ConsistencyLevel.SERIAL} or {@code ConsistencyLevel.LOCAL_SERIAL}. | |
| 105 | + * {@code ConsistencyLevel.SERIAL} or {@code ConsistencyLevel.LOCAL_SERIAL}. | |
| 107 | 106 | */ |
| 108 | 107 | public Statement setSerialConsistencyLevel(ConsistencyLevel serialConsistency) { |
| 109 | 108 | if (serialConsistency != ConsistencyLevel.SERIAL && serialConsistency != ConsistencyLevel.LOCAL_SERIAL) |
| @@ -114,7 +113,7 @@ | ||
| 114 | 113 | |
| 115 | 114 | /** |
| 116 | 115 | * The serial consistency level for this query. |
| 117 | - * <p> | |
| 116 | + * <p/> | |
| 118 | 117 | * See {@link #setSerialConsistencyLevel} for more detail on the serial consistency level. |
| 119 | 118 | * |
| 120 | 119 | * @return the consistency level for this query, or {@code null} if no serial |
| @@ -127,7 +126,7 @@ | ||
| 127 | 126 | |
| 128 | 127 | /** |
| 129 | 128 | * Enables tracing for this query. |
| 130 | - * | |
| 129 | + * <p/> | |
| 131 | 130 | * By default (that is unless you call this method), tracing is not enabled. |
| 132 | 131 | * |
| 133 | 132 | * @return this {@code Statement} object. |
| @@ -158,9 +157,9 @@ | ||
| 158 | 157 | } |
| 159 | 158 | |
| 160 | 159 | /** |
| 161 | - * Returns the routing key (in binary raw form) to use for token aware | |
| 160 | + * Returns the routing key (in binary raw form) to use for token aware | |
| 162 | 161 | * routing of this query. |
| 163 | - * <p> | |
| 162 | + * <p/> | |
| 164 | 163 | * The routing key is optional in that implementers are free to |
| 165 | 164 | * return {@code null}. The routing key is an hint used for token-aware routing (see |
| 166 | 165 | * {@link com.datastax.driver.core.policies.TokenAwarePolicy}), and |
| @@ -175,7 +174,7 @@ | ||
| 175 | 174 | |
| 176 | 175 | /** |
| 177 | 176 | * Returns the keyspace this query operates on. |
| 178 | - * <p> | |
| 177 | + * <p/> | |
| 179 | 178 | * Note that not all query specify on which keyspace they operate on, and |
| 180 | 179 | * so this method can always return {@code null}. Firstly, some queries do |
| 181 | 180 | * not operate inside a keyspace: keyspace creation, {@code USE} queries, |
| @@ -195,7 +194,7 @@ | ||
| 195 | 194 | |
| 196 | 195 | /** |
| 197 | 196 | * Sets the retry policy to use for this query. |
| 198 | - * <p> | |
| 197 | + * <p/> | |
| 199 | 198 | * The default retry policy, if this method is not called, is the one returned by |
| 200 | 199 | * {@link com.datastax.driver.core.policies.Policies#getRetryPolicy} in the |
| 201 | 200 | * cluster configuration. This method is thus only useful in case you want |
| @@ -222,7 +221,7 @@ | ||
| 222 | 221 | |
| 223 | 222 | /** |
| 224 | 223 | * Sets the query fetch size. |
| 225 | - * <p> | |
| 224 | + * <p/> | |
| 226 | 225 | * The fetch size controls how much resulting rows will be retrieved |
| 227 | 226 | * simultaneously (the goal being to avoid loading too much results |
| 228 | 227 | * in memory for queries yielding large results). Please note that |
| @@ -230,9 +229,9 @@ | ||
| 230 | 229 | * use such a low value in practice as it will yield very poor |
| 231 | 230 | * performance. If in doubt, leaving the default is probably a good |
| 232 | 231 | * idea. |
| 233 | - * <p> | |
| 232 | + * <p/> | |
| 234 | 233 | * Only {@code SELECT} queries only ever make use of that setting. |
| 235 | - * <p> | |
| 234 | + * <p/> | |
| 236 | 235 | * Note: Paging is not supported with the native protocol version 1. If |
| 237 | 236 | * you call this method with {@code fetchSize > 0} and |
| 238 | 237 | * {@code fetchSize != Integer.MAX_VALUE} and the protocol version is in |
| @@ -241,8 +240,8 @@ | ||
| 241 | 240 | * when submitting this statement for execution. |
| 242 | 241 | * |
| 243 | 242 | * @param fetchSize the fetch size to use. If {@code fetchSize <e; 0}, |
| 244 | - * the default fetch size will be used. To disable paging of the | |
| 245 | - * result set, use {@code fetchSize == Integer.MAX_VALUE}. | |
| 243 | + * the default fetch size will be used. To disable paging of the | |
| 244 | + * result set, use {@code fetchSize == Integer.MAX_VALUE}. | |
| 246 | 245 | * @return this {@code Statement} object. |
| 247 | 246 | */ |
| 248 | 247 | public Statement setFetchSize(int fetchSize) { |
| @@ -263,10 +262,10 @@ | ||
| 263 | 262 | |
| 264 | 263 | /** |
| 265 | 264 | * Sets the paging state. |
| 266 | - * <p> | |
| 265 | + * <p/> | |
| 267 | 266 | * This will cause the next execution of this statement to fetch results from a given |
| 268 | 267 | * page, rather than restarting from the beginning. |
| 269 | - * <p> | |
| 268 | + * <p/> | |
| 270 | 269 | * You get the paging state from a previous execution of the statement (see |
| 271 | 270 | * {@link ExecutionInfo#getPagingState()}. |
| 272 | 271 | * This is typically used to iterate in a "stateless" manner (e.g. across HTTP requests): |
| @@ -296,11 +295,11 @@ | ||
| 296 | 295 | * } |
| 297 | 296 | * } |
| 298 | 297 | * </pre> |
| 299 | - * <p> | |
| 298 | + * <p/> | |
| 300 | 299 | * The paging state can only be reused between perfectly identical statements |
| 301 | 300 | * (same query string, same bound parameters). Altering the contents of the paging state |
| 302 | 301 | * or trying to set it on a different statement will cause this method to fail. |
| 303 | - * <p> | |
| 302 | + * <p/> | |
| 304 | 303 | * Note that, due to internal implementation details, the paging state is not portable |
| 305 | 304 | * across native protocol versions (see the |
| 306 | 305 | * <a href="http://datastax.github.io/java-driver/features/native_protocol">online documentation</a> |
| @@ -312,7 +311,6 @@ | ||
| 312 | 311 | * @param pagingState the paging state to set, or {@code null} to remove any state that was |
| 313 | 312 | * previously set on this statement. |
| 314 | 313 | * @return this {@code Statement} object. |
| 315 | - * | |
| 316 | 314 | * @throws PagingStateException if the paging state does not match this statement. |
| 317 | 315 | */ |
| 318 | 316 | public Statement setPagingState(PagingState pagingState) { |
| @@ -325,8 +323,8 @@ | ||
| 325 | 323 | this.pagingState = pagingState.getRawState(); |
| 326 | 324 | } else { |
| 327 | 325 | throw new PagingStateException("Paging state mismatch, " |
| 328 | - + "this means that either the paging state contents were altered, " | |
| 329 | - + "or you're trying to apply it to a different statement"); | |
| 326 | + + "this means that either the paging state contents were altered, " | |
| 327 | + + "or you're trying to apply it to a different statement"); | |
| 330 | 328 | } |
| 331 | 329 | } |
| 332 | 330 | return this; |
| @@ -334,7 +332,7 @@ | ||
| 334 | 332 | |
| 335 | 333 | /** |
| 336 | 334 | * Sets the paging state. |
| 337 | - * <p> | |
| 335 | + * <p/> | |
| 338 | 336 | * Contrary to {@link #setPagingState(PagingState)}, this method takes the "raw" form of the |
| 339 | 337 | * paging state (previously extracted with {@link ExecutionInfo#getPagingStateUnsafe()}. |
| 340 | 338 | * It won't validate that this statement matches the one that the paging state was extracted from. |
| @@ -362,7 +360,7 @@ | ||
| 362 | 360 | |
| 363 | 361 | /** |
| 364 | 362 | * Sets whether this statement is idempotent. |
| 365 | - * <p> | |
| 363 | + * <p/> | |
| 366 | 364 | * See {@link #isIdempotent()} for more explanations about this property. |
| 367 | 365 | * |
| 368 | 366 | * @param idempotent the new value. |
| @@ -376,14 +374,14 @@ | ||
| 376 | 374 | /** |
| 377 | 375 | * Whether this statement is idempotent, i.e. whether it can be applied multiple times |
| 378 | 376 | * without changing the result beyond the initial application. |
| 379 | - * <p> | |
| 377 | + * <p/> | |
| 380 | 378 | * Idempotence plays a role in {@link com.datastax.driver.core.policies.SpeculativeExecutionPolicy speculative executions}. |
| 381 | 379 | * If a statement is <em>not idempotent</em>, the driver will not schedule speculative |
| 382 | 380 | * executions for it. |
| 383 | - * <p> | |
| 381 | + * <p/> | |
| 384 | 382 | * Note that this method can return {@code null}, in which case the driver will default to |
| 385 | 383 | * {@link QueryOptions#getDefaultIdempotence()}. |
| 386 | - * <p> | |
| 384 | + * <p/> | |
| 387 | 385 | * By default, this method returns {@code null} for all statements, except for |
| 388 | 386 | * {@link BuiltStatement}s, where the value will be inferred from the query: if it updates |
| 389 | 387 | * counters, prepends/appends to a list, or uses a function call or |
modified driver-core/src/main/java/com/datastax/driver/core/StatementWrapper.java +6 −6
| @@ -15,19 +15,19 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.nio.ByteBuffer; | |
| 19 | - | |
| 20 | 18 | import com.datastax.driver.core.policies.LoadBalancingPolicy; |
| 21 | 19 | import com.datastax.driver.core.policies.RetryPolicy; |
| 22 | 20 | import com.datastax.driver.core.policies.SpeculativeExecutionPolicy; |
| 23 | 21 | |
| 22 | +import java.nio.ByteBuffer; | |
| 23 | + | |
| 24 | 24 | /** |
| 25 | 25 | * Base class for custom {@link Statement} implementations that wrap another statement. |
| 26 | - * <p> | |
| 26 | + * <p/> | |
| 27 | 27 | * This is intended for use with a custom {@link RetryPolicy}, {@link LoadBalancingPolicy} or |
| 28 | 28 | * {@link SpeculativeExecutionPolicy}. The client code can wrap a statement to "mark" it, or |
| 29 | 29 | * add information that will lead to special handling in the policy. |
| 30 | - * <p> | |
| 30 | + * <p/> | |
| 31 | 31 | * Example: |
| 32 | 32 | * <pre> |
| 33 | 33 | * {@code |
| @@ -71,8 +71,8 @@ | ||
| 71 | 71 | Statement getWrappedStatement() { |
| 72 | 72 | // Protect against multiple levels of wrapping (even though there is no practical reason for that) |
| 73 | 73 | return (wrapped instanceof StatementWrapper) |
| 74 | - ? ((StatementWrapper)wrapped).getWrappedStatement() | |
| 75 | - : wrapped; | |
| 74 | + ? ((StatementWrapper) wrapped).getWrappedStatement() | |
| 75 | + : wrapped; | |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | @Override |
modified driver-core/src/main/java/com/datastax/driver/core/SystemProperties.java +1 −1
| @@ -20,7 +20,7 @@ | ||
| 20 | 20 | |
| 21 | 21 | /** |
| 22 | 22 | * Allows overriding internal settings via system properties. |
| 23 | - * <p> | |
| 23 | + * <p/> | |
| 24 | 24 | * Warning: this is meant for integration tests only, NOT FOR PRODUCTION USE. |
| 25 | 25 | */ |
| 26 | 26 | class SystemProperties { |
modified driver-core/src/main/java/com/datastax/driver/core/TableMetadata.java +57 −55
| @@ -15,13 +15,13 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.util.*; | |
| 19 | - | |
| 20 | 18 | import com.google.common.base.Predicate; |
| 21 | 19 | import com.google.common.collect.Iterables; |
| 22 | 20 | import org.slf4j.Logger; |
| 23 | 21 | import org.slf4j.LoggerFactory; |
| 24 | 22 | |
| 23 | +import java.util.*; | |
| 24 | + | |
| 25 | 25 | /** |
| 26 | 26 | * Describes a Table. |
| 27 | 27 | */ |
| @@ -29,19 +29,19 @@ | ||
| 29 | 29 | |
| 30 | 30 | private static final Logger logger = LoggerFactory.getLogger(TableMetadata.class); |
| 31 | 31 | |
| 32 | - static final String CF_NAME = "columnfamily_name"; | |
| 32 | + static final String CF_NAME = "columnfamily_name"; | |
| 33 | 33 | |
| 34 | - private static final String KEY_VALIDATOR = "key_validator"; | |
| 35 | - private static final String COMPARATOR = "comparator"; | |
| 36 | - private static final String VALIDATOR = "default_validator"; | |
| 34 | + private static final String KEY_VALIDATOR = "key_validator"; | |
| 35 | + private static final String COMPARATOR = "comparator"; | |
| 36 | + private static final String VALIDATOR = "default_validator"; | |
| 37 | 37 | |
| 38 | - private static final String KEY_ALIASES = "key_aliases"; | |
| 39 | - private static final String COLUMN_ALIASES = "column_aliases"; | |
| 40 | - private static final String VALUE_ALIAS = "value_alias"; | |
| 38 | + private static final String KEY_ALIASES = "key_aliases"; | |
| 39 | + private static final String COLUMN_ALIASES = "column_aliases"; | |
| 40 | + private static final String VALUE_ALIAS = "value_alias"; | |
| 41 | 41 | |
| 42 | - private static final String DEFAULT_KEY_ALIAS = "key"; | |
| 42 | + private static final String DEFAULT_KEY_ALIAS = "key"; | |
| 43 | 43 | private static final String DEFAULT_COLUMN_ALIAS = "column"; |
| 44 | - private static final String DEFAULT_VALUE_ALIAS = "value"; | |
| 44 | + private static final String DEFAULT_VALUE_ALIAS = "value"; | |
| 45 | 45 | |
| 46 | 46 | private static final Comparator<ColumnMetadata> columnMetadataComparator = new Comparator<ColumnMetadata>() { |
| 47 | 47 | public int compare(ColumnMetadata c1, ColumnMetadata c2) { |
| @@ -61,7 +61,7 @@ | ||
| 61 | 61 | |
| 62 | 62 | /** |
| 63 | 63 | * Clustering orders. |
| 64 | - * <p> | |
| 64 | + * <p/> | |
| 65 | 65 | * This is used by {@link #getClusteringOrder} to indicate the clustering |
| 66 | 66 | * order of a table. |
| 67 | 67 | */ |
| @@ -100,8 +100,8 @@ | ||
| 100 | 100 | CassandraTypeParser.ParseResult keyValidator = CassandraTypeParser.parseWithComposite(row.getString(KEY_VALIDATOR)); |
| 101 | 101 | CassandraTypeParser.ParseResult comparator = CassandraTypeParser.parseWithComposite(row.getString(COMPARATOR)); |
| 102 | 102 | List<String> columnAliases = cassandraVersion.getMajor() >= 2 || row.getString(COLUMN_ALIASES) == null |
| 103 | - ? Collections.<String>emptyList() | |
| 104 | - : SimpleJSONParser.parseStringList(row.getString(COLUMN_ALIASES)); | |
| 103 | + ? Collections.<String>emptyList() | |
| 104 | + : SimpleJSONParser.parseStringList(row.getString(COLUMN_ALIASES)); | |
| 105 | 105 | |
| 106 | 106 | int clusteringSize = findClusteringSize(comparator, rawCols.values(), columnAliases, cassandraVersion); |
| 107 | 107 | boolean isDense = clusteringSize != comparator.types.size() - 1; |
| @@ -121,8 +121,8 @@ | ||
| 121 | 121 | // See ControlConnection#refreshSchema for why we'd rather not probably this further. Since table options is one thing |
| 122 | 122 | // that tends to change often in Cassandra, it's worth special casing this. |
| 123 | 123 | logger.error(String.format("Error parsing schema options for table %s.%s: " |
| 124 | - + "Cluster.getMetadata().getKeyspace(\"%s\").getTable(\"%s\").getOptions() will return null", | |
| 125 | - ksm.getName(), name, ksm.getName(), name), e); | |
| 124 | + + "Cluster.getMetadata().getKeyspace(\"%s\").getTable(\"%s\").getOptions() will return null", | |
| 125 | + ksm.getName(), name, ksm.getName(), name), e); | |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | TableMetadata tm = new TableMetadata(ksm, name, partitionKey, clusteringColumns, columns, options, clusteringOrder, cassandraVersion); |
| @@ -135,8 +135,8 @@ | ||
| 135 | 135 | // In C* 1.2, only the REGULAR columns are in the columns schema table, so we need to add the names from |
| 136 | 136 | // the aliases (and make sure we handle default aliases). |
| 137 | 137 | List<String> keyAliases = row.getString(KEY_ALIASES) == null |
| 138 | - ? Collections.<String>emptyList() | |
| 139 | - : SimpleJSONParser.parseStringList(row.getString(KEY_ALIASES)); | |
| 138 | + ? Collections.<String>emptyList() | |
| 139 | + : SimpleJSONParser.parseStringList(row.getString(KEY_ALIASES)); | |
| 140 | 140 | for (int i = 0; i < partitionKey.size(); i++) { |
| 141 | 141 | String alias = keyAliases.size() > i ? keyAliases.get(i) : (i == 0 ? DEFAULT_KEY_ALIAS : DEFAULT_KEY_ALIAS + (i + 1)); |
| 142 | 142 | partitionKey.set(i, ColumnMetadata.forAlias(tm, alias, keyValidator.types.get(i))); |
| @@ -234,8 +234,8 @@ | ||
| 234 | 234 | * Returns metadata on a column of this table. |
| 235 | 235 | * |
| 236 | 236 | * @param name the name of the column to retrieve ({@code name} will be |
| 237 | - * interpreted as a case-insensitive identifier unless enclosed in double-quotes, | |
| 238 | - * see {@link Metadata#quote}). | |
| 237 | + * interpreted as a case-insensitive identifier unless enclosed in double-quotes, | |
| 238 | + * see {@link Metadata#quote}). | |
| 239 | 239 | * @return the metadata for the {@code name} column if it exists, or |
| 240 | 240 | * {@code null} otherwise. |
| 241 | 241 | */ |
| @@ -245,7 +245,7 @@ | ||
| 245 | 245 | |
| 246 | 246 | /** |
| 247 | 247 | * Returns a list containing all the columns of this table. |
| 248 | - * | |
| 248 | + * <p/> | |
| 249 | 249 | * The order of the columns in the list is consistent with |
| 250 | 250 | * the order of the columns returned by a {@code SELECT * FROM thisTable}: |
| 251 | 251 | * the first column is the partition key, next are the clustering |
| @@ -260,7 +260,7 @@ | ||
| 260 | 260 | |
| 261 | 261 | /** |
| 262 | 262 | * Returns the list of columns composing the primary key for this table. |
| 263 | - * | |
| 263 | + * <p/> | |
| 264 | 264 | * A table will always at least have a partition key (that |
| 265 | 265 | * may itself be one or more columns), so the returned list at least |
| 266 | 266 | * has one element. |
| @@ -276,7 +276,7 @@ | ||
| 276 | 276 | |
| 277 | 277 | /** |
| 278 | 278 | * Returns the list of columns composing the partition key for this table. |
| 279 | - * | |
| 279 | + * <p/> | |
| 280 | 280 | * A table always has a partition key so the returned list has |
| 281 | 281 | * at least one element. |
| 282 | 282 | * |
| @@ -298,7 +298,7 @@ | ||
| 298 | 298 | |
| 299 | 299 | /** |
| 300 | 300 | * Returns the clustering order for this table. |
| 301 | - * <p> | |
| 301 | + * <p/> | |
| 302 | 302 | * The returned contains the clustering order of each clustering column. The |
| 303 | 303 | * {@code i}th element of the result correspond to the order (ascending or |
| 304 | 304 | * descending) of the {@code i}th clustering column (see |
| @@ -328,11 +328,11 @@ | ||
| 328 | 328 | /** |
| 329 | 329 | * Returns a {@code String} containing CQL queries representing this |
| 330 | 330 | * table and the index on it. |
| 331 | - * | |
| 331 | + * <p/> | |
| 332 | 332 | * In other words, this method returns the queries that would allow you to |
| 333 | 333 | * recreate the schema of this table, along with the index defined on |
| 334 | 334 | * columns of this table. |
| 335 | - * | |
| 335 | + * <p/> | |
| 336 | 336 | * Note that the returned String is formatted to be human readable (for |
| 337 | 337 | * some definition of human readable at least). |
| 338 | 338 | * |
| @@ -356,10 +356,10 @@ | ||
| 356 | 356 | |
| 357 | 357 | /** |
| 358 | 358 | * Returns a CQL query representing this table. |
| 359 | - * | |
| 359 | + * <p/> | |
| 360 | 360 | * This method returns a single 'CREATE TABLE' query with the options |
| 361 | 361 | * corresponding to this table definition. |
| 362 | - * | |
| 362 | + * <p/> | |
| 363 | 363 | * Note that the returned string is a single line; the returned query |
| 364 | 364 | * is not formatted in any way. |
| 365 | 365 | * |
| @@ -377,7 +377,7 @@ | ||
| 377 | 377 | if (o == null || getClass() != o.getClass()) |
| 378 | 378 | return false; |
| 379 | 379 | |
| 380 | - TableMetadata that = (TableMetadata)o; | |
| 380 | + TableMetadata that = (TableMetadata) o; | |
| 381 | 381 | |
| 382 | 382 | if (!name.equals(that.name)) |
| 383 | 383 | return false; |
| @@ -423,7 +423,8 @@ | ||
| 423 | 423 | sb.append('('); |
| 424 | 424 | boolean first = true; |
| 425 | 425 | for (ColumnMetadata cm : partitionKey) { |
| 426 | - if (first) first = false; else sb.append(", "); | |
| 426 | + if (first) first = false; | |
| 427 | + else sb.append(", "); | |
| 427 | 428 | sb.append(Metadata.escapeId(cm.getName())); |
| 428 | 429 | } |
| 429 | 430 | sb.append(')'); |
| @@ -449,7 +450,7 @@ | ||
| 449 | 450 | and(sb, formatted).append("bloom_filter_fp_chance = ").append(options.bfFpChance); |
| 450 | 451 | and(sb, formatted).append("caching = '").append(options.caching).append('\''); |
| 451 | 452 | if (options.comment != null) |
| 452 | - and(sb, formatted).append("comment = '").append(options.comment.replace("'","''")).append('\''); | |
| 453 | + and(sb, formatted).append("comment = '").append(options.comment.replace("'", "''")).append('\''); | |
| 453 | 454 | and(sb, formatted).append("compaction = ").append(formatOptionMap(options.compaction)); |
| 454 | 455 | and(sb, formatted).append("compression = ").append(formatOptionMap(options.compression)); |
| 455 | 456 | if (cassandraVersion.getMajor() >= 2) { |
| @@ -475,7 +476,8 @@ | ||
| 475 | 476 | sb.append("{ "); |
| 476 | 477 | boolean first = true; |
| 477 | 478 | for (Map.Entry<String, String> entry : m.entrySet()) { |
| 478 | - if (first) first = false; else sb.append(", "); | |
| 479 | + if (first) first = false; | |
| 480 | + else sb.append(", "); | |
| 479 | 481 | sb.append('\'').append(entry.getKey()).append('\''); |
| 480 | 482 | sb.append(" : "); |
| 481 | 483 | try { |
| @@ -511,23 +513,23 @@ | ||
| 511 | 513 | |
| 512 | 514 | public static class Options { |
| 513 | 515 | |
| 514 | - private static final String COMMENT = "comment"; | |
| 515 | - private static final String READ_REPAIR = "read_repair_chance"; | |
| 516 | - private static final String LOCAL_READ_REPAIR = "local_read_repair_chance"; | |
| 517 | - private static final String REPLICATE_ON_WRITE = "replicate_on_write"; | |
| 518 | - private static final String GC_GRACE = "gc_grace_seconds"; | |
| 519 | - private static final String BF_FP_CHANCE = "bloom_filter_fp_chance"; | |
| 520 | - private static final String CACHING = "caching"; | |
| 521 | - private static final String COMPACTION_CLASS = "compaction_strategy_class"; | |
| 522 | - private static final String COMPACTION_OPTIONS = "compaction_strategy_options"; | |
| 516 | + private static final String COMMENT = "comment"; | |
| 517 | + private static final String READ_REPAIR = "read_repair_chance"; | |
| 518 | + private static final String LOCAL_READ_REPAIR = "local_read_repair_chance"; | |
| 519 | + private static final String REPLICATE_ON_WRITE = "replicate_on_write"; | |
| 520 | + private static final String GC_GRACE = "gc_grace_seconds"; | |
| 521 | + private static final String BF_FP_CHANCE = "bloom_filter_fp_chance"; | |
| 522 | + private static final String CACHING = "caching"; | |
| 523 | + private static final String COMPACTION_CLASS = "compaction_strategy_class"; | |
| 524 | + private static final String COMPACTION_OPTIONS = "compaction_strategy_options"; | |
| 523 | 525 | private static final String MIN_COMPACTION_THRESHOLD = "min_compaction_threshold"; |
| 524 | 526 | private static final String MAX_COMPACTION_THRESHOLD = "max_compaction_threshold"; |
| 525 | - private static final String POPULATE_CACHE_ON_FLUSH = "populate_io_cache_on_flush"; | |
| 526 | - private static final String COMPRESSION_PARAMS = "compression_parameters"; | |
| 527 | + private static final String POPULATE_CACHE_ON_FLUSH = "populate_io_cache_on_flush"; | |
| 528 | + private static final String COMPRESSION_PARAMS = "compression_parameters"; | |
| 527 | 529 | private static final String MEMTABLE_FLUSH_PERIOD_MS = "memtable_flush_period_in_ms"; |
| 528 | - private static final String DEFAULT_TTL = "default_time_to_live"; | |
| 529 | - private static final String SPECULATIVE_RETRY = "speculative_retry"; | |
| 530 | - private static final String INDEX_INTERVAL = "index_interval"; | |
| 530 | + private static final String DEFAULT_TTL = "default_time_to_live"; | |
| 531 | + private static final String SPECULATIVE_RETRY = "speculative_retry"; | |
| 532 | + private static final String INDEX_INTERVAL = "index_interval"; | |
| 531 | 533 | |
| 532 | 534 | private static final boolean DEFAULT_REPLICATE_ON_WRITE = true; |
| 533 | 535 | private static final double DEFAULT_BF_FP_CHANCE = 0.01; |
| @@ -577,7 +579,7 @@ | ||
| 577 | 579 | |
| 578 | 580 | private static boolean isNullOrAbsent(Row row, String name) { |
| 579 | 581 | return row.getColumnDefinitions().getIndexOf(name) < 0 |
| 580 | - || row.isNull(name); | |
| 582 | + || row.isNull(name); | |
| 581 | 583 | } |
| 582 | 584 | |
| 583 | 585 | /** |
| @@ -618,7 +620,7 @@ | ||
| 618 | 620 | |
| 619 | 621 | /** |
| 620 | 622 | * Returns whether replicateOnWrite is set for this table. |
| 621 | - * | |
| 623 | + * <p/> | |
| 622 | 624 | * This is only meaningful for tables holding counters. |
| 623 | 625 | * |
| 624 | 626 | * @return whether replicateOnWrite is set for this table. |
| @@ -678,7 +680,7 @@ | ||
| 678 | 680 | |
| 679 | 681 | /** |
| 680 | 682 | * Returns the default TTL for this table. |
| 681 | - * <p> | |
| 683 | + * <p/> | |
| 682 | 684 | * Note: this option is not available in Cassandra 1.2 and will return 0 (no default |
| 683 | 685 | * TTL) when connected to 1.2 nodes. |
| 684 | 686 | * |
| @@ -691,7 +693,7 @@ | ||
| 691 | 693 | |
| 692 | 694 | /** |
| 693 | 695 | * Returns the speculative retry option for this table. |
| 694 | - * <p> | |
| 696 | + * <p/> | |
| 695 | 697 | * Note: this option is not available in Cassandra 1.2 and will return "NONE" (no |
| 696 | 698 | * speculative retry) when connected to 1.2 nodes. |
| 697 | 699 | * |
| @@ -703,7 +705,7 @@ | ||
| 703 | 705 | |
| 704 | 706 | /** |
| 705 | 707 | * Returns the index interval option for this table. |
| 706 | - * <p> | |
| 708 | + * <p/> | |
| 707 | 709 | * Note: this option is not available in Cassandra 1.2 (more precisely, it is not |
| 708 | 710 | * configurable per-table) and will return 128 (the default index interval) when |
| 709 | 711 | * connected to 1.2 nodes. |
| @@ -739,7 +741,7 @@ | ||
| 739 | 741 | if (o == null || getClass() != o.getClass()) |
| 740 | 742 | return false; |
| 741 | 743 | |
| 742 | - Options options = (Options)o; | |
| 744 | + Options options = (Options) o; | |
| 743 | 745 | |
| 744 | 746 | if (isCompactStorage != options.isCompactStorage) |
| 745 | 747 | return false; |
| @@ -780,13 +782,13 @@ | ||
| 780 | 782 | result = (isCompactStorage ? 1 : 0); |
| 781 | 783 | result = 31 * result + (comment != null ? comment.hashCode() : 0); |
| 782 | 784 | temp = Double.doubleToLongBits(readRepair); |
| 783 | - result = 31 * result + (int)(temp ^ (temp >>> 32)); | |
| 785 | + result = 31 * result + (int) (temp ^ (temp >>> 32)); | |
| 784 | 786 | temp = Double.doubleToLongBits(localReadRepair); |
| 785 | - result = 31 * result + (int)(temp ^ (temp >>> 32)); | |
| 787 | + result = 31 * result + (int) (temp ^ (temp >>> 32)); | |
| 786 | 788 | result = 31 * result + (replicateOnWrite ? 1 : 0); |
| 787 | 789 | result = 31 * result + gcGrace; |
| 788 | 790 | temp = Double.doubleToLongBits(bfFpChance); |
| 789 | - result = 31 * result + (int)(temp ^ (temp >>> 32)); | |
| 791 | + result = 31 * result + (int) (temp ^ (temp >>> 32)); | |
| 790 | 792 | result = 31 * result + (caching != null ? caching.hashCode() : 0); |
| 791 | 793 | result = 31 * result + (populateCacheOnFlush ? 1 : 0); |
| 792 | 794 | result = 31 * result + memtableFlushPeriodMs; |
modified driver-core/src/main/java/com/datastax/driver/core/Token.java +104 −66
| @@ -15,19 +15,17 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.utils.Bytes; | |
| 19 | +import com.google.common.annotations.VisibleForTesting; | |
| 20 | +import com.google.common.collect.Lists; | |
| 21 | +import com.google.common.primitives.UnsignedBytes; | |
| 22 | + | |
| 18 | 23 | import java.math.BigInteger; |
| 19 | 24 | import java.nio.ByteBuffer; |
| 20 | 25 | import java.security.MessageDigest; |
| 21 | 26 | import java.security.NoSuchAlgorithmException; |
| 22 | -import java.util.Arrays; | |
| 23 | 27 | import java.util.List; |
| 24 | 28 | |
| 25 | -import com.google.common.annotations.VisibleForTesting; | |
| 26 | -import com.google.common.collect.Lists; | |
| 27 | -import com.google.common.primitives.UnsignedBytes; | |
| 28 | - | |
| 29 | -import com.datastax.driver.core.utils.Bytes; | |
| 30 | - | |
| 31 | 29 | /** |
| 32 | 30 | * A token on the Cassandra ring. |
| 33 | 31 | */ |
| @@ -60,17 +58,24 @@ | ||
| 60 | 58 | |
| 61 | 59 | static abstract class Factory { |
| 62 | 60 | abstract Token fromString(String tokenStr); |
| 61 | + | |
| 63 | 62 | abstract DataType getTokenType(); |
| 63 | + | |
| 64 | 64 | abstract Token deserialize(ByteBuffer buffer); |
| 65 | - /** The minimum token is a special value that no key ever hashes to, it's used both as lower and upper bound. */ | |
| 65 | + | |
| 66 | + /** | |
| 67 | + * The minimum token is a special value that no key ever hashes to, it's used both as lower and upper bound. | |
| 68 | + */ | |
| 66 | 69 | abstract Token minToken(); |
| 70 | + | |
| 67 | 71 | abstract Token hash(ByteBuffer partitionKey); |
| 72 | + | |
| 68 | 73 | abstract List<Token> split(Token startToken, Token endToken, int numberOfSplits); |
| 69 | 74 | |
| 70 | 75 | // Base implementation for split |
| 71 | 76 | protected List<BigInteger> split(BigInteger start, BigInteger range, |
| 72 | - BigInteger ringEnd, BigInteger ringLength, | |
| 73 | - int numberOfSplits) { | |
| 77 | + BigInteger ringEnd, BigInteger ringLength, | |
| 78 | + int numberOfSplits) { | |
| 74 | 79 | BigInteger[] tmp = range.divideAndRemainder(BigInteger.valueOf(numberOfSplits)); |
| 75 | 80 | BigInteger divider = tmp[0]; |
| 76 | 81 | int remainder = tmp[1].intValue(); |
| @@ -78,7 +83,7 @@ | ||
| 78 | 83 | List<BigInteger> results = Lists.newArrayListWithExpectedSize(numberOfSplits - 1); |
| 79 | 84 | BigInteger current = start; |
| 80 | 85 | BigInteger dividerPlusOne = (remainder == 0) ? null // won't be used |
| 81 | - : divider.add(BigInteger.ONE); | |
| 86 | + : divider.add(BigInteger.ONE); | |
| 82 | 87 | |
| 83 | 88 | for (int i = 1; i < numberOfSplits; i++) { |
| 84 | 89 | current = current.add(remainder-- > 0 ? dividerPlusOne : divider); |
| @@ -107,9 +112,9 @@ | ||
| 107 | 112 | int i_8 = index << 3; |
| 108 | 113 | int blockOffset = offset + i_8; |
| 109 | 114 | return ((long) key.get(blockOffset + 0) & 0xff) + (((long) key.get(blockOffset + 1) & 0xff) << 8) + |
| 110 | - (((long) key.get(blockOffset + 2) & 0xff) << 16) + (((long) key.get(blockOffset + 3) & 0xff) << 24) + | |
| 111 | - (((long) key.get(blockOffset + 4) & 0xff) << 32) + (((long) key.get(blockOffset + 5) & 0xff) << 40) + | |
| 112 | - (((long) key.get(blockOffset + 6) & 0xff) << 48) + (((long) key.get(blockOffset + 7) & 0xff) << 56); | |
| 115 | + (((long) key.get(blockOffset + 2) & 0xff) << 16) + (((long) key.get(blockOffset + 3) & 0xff) << 24) + | |
| 116 | + (((long) key.get(blockOffset + 4) & 0xff) << 32) + (((long) key.get(blockOffset + 5) & 0xff) << 40) + | |
| 117 | + (((long) key.get(blockOffset + 6) & 0xff) << 48) + (((long) key.get(blockOffset + 7) & 0xff) << 56); | |
| 113 | 118 | } |
| 114 | 119 | |
| 115 | 120 | private long rotl64(long v, int n) { |
| @@ -144,14 +149,24 @@ | ||
| 144 | 149 | //---------- |
| 145 | 150 | // body |
| 146 | 151 | |
| 147 | - for(int i = 0; i < nblocks; i++) { | |
| 148 | - long k1 = getblock(data, offset, i*2+0); | |
| 149 | - long k2 = getblock(data, offset, i*2+1); | |
| 150 | - | |
| 151 | - k1 *= c1; k1 = rotl64(k1,31); k1 *= c2; h1 ^= k1; | |
| 152 | - h1 = rotl64(h1,27); h1 += h2; h1 = h1*5+0x52dce729; | |
| 153 | - k2 *= c2; k2 = rotl64(k2,33); k2 *= c1; h2 ^= k2; | |
| 154 | - h2 = rotl64(h2,31); h2 += h1; h2 = h2*5+0x38495ab5; | |
| 152 | + for (int i = 0; i < nblocks; i++) { | |
| 153 | + long k1 = getblock(data, offset, i * 2 + 0); | |
| 154 | + long k2 = getblock(data, offset, i * 2 + 1); | |
| 155 | + | |
| 156 | + k1 *= c1; | |
| 157 | + k1 = rotl64(k1, 31); | |
| 158 | + k1 *= c2; | |
| 159 | + h1 ^= k1; | |
| 160 | + h1 = rotl64(h1, 27); | |
| 161 | + h1 += h2; | |
| 162 | + h1 = h1 * 5 + 0x52dce729; | |
| 163 | + k2 *= c2; | |
| 164 | + k2 = rotl64(k2, 33); | |
| 165 | + k2 *= c1; | |
| 166 | + h2 ^= k2; | |
| 167 | + h2 = rotl64(h2, 31); | |
| 168 | + h2 += h1; | |
| 169 | + h2 = h2 * 5 + 0x38495ab5; | |
| 155 | 170 | } |
| 156 | 171 | |
| 157 | 172 | //---------- |
| @@ -163,31 +178,54 @@ | ||
| 163 | 178 | long k1 = 0; |
| 164 | 179 | long k2 = 0; |
| 165 | 180 | |
| 166 | - switch(length & 15) { | |
| 167 | - case 15: k2 ^= ((long) data.get(offset+14)) << 48; | |
| 168 | - case 14: k2 ^= ((long) data.get(offset+13)) << 40; | |
| 169 | - case 13: k2 ^= ((long) data.get(offset+12)) << 32; | |
| 170 | - case 12: k2 ^= ((long) data.get(offset+11)) << 24; | |
| 171 | - case 11: k2 ^= ((long) data.get(offset+10)) << 16; | |
| 172 | - case 10: k2 ^= ((long) data.get(offset+9)) << 8; | |
| 173 | - case 9: k2 ^= ((long) data.get(offset+8)) << 0; | |
| 174 | - k2 *= c2; k2 = rotl64(k2,33); k2 *= c1; h2 ^= k2; | |
| 175 | - | |
| 176 | - case 8: k1 ^= ((long) data.get(offset+7)) << 56; | |
| 177 | - case 7: k1 ^= ((long) data.get(offset+6)) << 48; | |
| 178 | - case 6: k1 ^= ((long) data.get(offset+5)) << 40; | |
| 179 | - case 5: k1 ^= ((long) data.get(offset+4)) << 32; | |
| 180 | - case 4: k1 ^= ((long) data.get(offset+3)) << 24; | |
| 181 | - case 3: k1 ^= ((long) data.get(offset+2)) << 16; | |
| 182 | - case 2: k1 ^= ((long) data.get(offset+1)) << 8; | |
| 183 | - case 1: k1 ^= ((long) data.get(offset)); | |
| 184 | - k1 *= c1; k1 = rotl64(k1,31); k1 *= c2; h1 ^= k1; | |
| 185 | - }; | |
| 181 | + switch (length & 15) { | |
| 182 | + case 15: | |
| 183 | + k2 ^= ((long) data.get(offset + 14)) << 48; | |
| 184 | + case 14: | |
| 185 | + k2 ^= ((long) data.get(offset + 13)) << 40; | |
| 186 | + case 13: | |
| 187 | + k2 ^= ((long) data.get(offset + 12)) << 32; | |
| 188 | + case 12: | |
| 189 | + k2 ^= ((long) data.get(offset + 11)) << 24; | |
| 190 | + case 11: | |
| 191 | + k2 ^= ((long) data.get(offset + 10)) << 16; | |
| 192 | + case 10: | |
| 193 | + k2 ^= ((long) data.get(offset + 9)) << 8; | |
| 194 | + case 9: | |
| 195 | + k2 ^= ((long) data.get(offset + 8)) << 0; | |
| 196 | + k2 *= c2; | |
| 197 | + k2 = rotl64(k2, 33); | |
| 198 | + k2 *= c1; | |
| 199 | + h2 ^= k2; | |
| 200 | + | |
| 201 | + case 8: | |
| 202 | + k1 ^= ((long) data.get(offset + 7)) << 56; | |
| 203 | + case 7: | |
| 204 | + k1 ^= ((long) data.get(offset + 6)) << 48; | |
| 205 | + case 6: | |
| 206 | + k1 ^= ((long) data.get(offset + 5)) << 40; | |
| 207 | + case 5: | |
| 208 | + k1 ^= ((long) data.get(offset + 4)) << 32; | |
| 209 | + case 4: | |
| 210 | + k1 ^= ((long) data.get(offset + 3)) << 24; | |
| 211 | + case 3: | |
| 212 | + k1 ^= ((long) data.get(offset + 2)) << 16; | |
| 213 | + case 2: | |
| 214 | + k1 ^= ((long) data.get(offset + 1)) << 8; | |
| 215 | + case 1: | |
| 216 | + k1 ^= ((long) data.get(offset)); | |
| 217 | + k1 *= c1; | |
| 218 | + k1 = rotl64(k1, 31); | |
| 219 | + k1 *= c2; | |
| 220 | + h1 ^= k1; | |
| 221 | + } | |
| 222 | + ; | |
| 186 | 223 | |
| 187 | 224 | //---------- |
| 188 | 225 | // finalization |
| 189 | 226 | |
| 190 | - h1 ^= length; h2 ^= length; | |
| 227 | + h1 ^= length; | |
| 228 | + h2 ^= length; | |
| 191 | 229 | |
| 192 | 230 | h1 += h2; |
| 193 | 231 | h2 += h1; |
| @@ -233,16 +271,16 @@ | ||
| 233 | 271 | if (startToken.equals(endToken) && startToken.equals(MIN_TOKEN)) |
| 234 | 272 | endToken = MAX_TOKEN; |
| 235 | 273 | |
| 236 | - BigInteger start = BigInteger.valueOf(((M3PToken)startToken).value); | |
| 237 | - BigInteger end = BigInteger.valueOf(((M3PToken)endToken).value); | |
| 274 | + BigInteger start = BigInteger.valueOf(((M3PToken) startToken).value); | |
| 275 | + BigInteger end = BigInteger.valueOf(((M3PToken) endToken).value); | |
| 238 | 276 | |
| 239 | 277 | BigInteger range = end.subtract(start); |
| 240 | 278 | if (range.compareTo(BigInteger.ZERO) < 0) |
| 241 | 279 | range = range.add(RING_LENGTH); |
| 242 | 280 | |
| 243 | 281 | List<BigInteger> values = super.split(start, range, |
| 244 | - RING_END, RING_LENGTH, | |
| 245 | - numberOfSplits); | |
| 282 | + RING_END, RING_LENGTH, | |
| 283 | + numberOfSplits); | |
| 246 | 284 | List<Token> tokens = Lists.newArrayListWithExpectedSize(values.size()); |
| 247 | 285 | for (BigInteger value : values) |
| 248 | 286 | tokens.add(new M3PToken(value.longValue())); |
| @@ -267,7 +305,7 @@ | ||
| 267 | 305 | @Override |
| 268 | 306 | public int compareTo(Token other) { |
| 269 | 307 | assert other instanceof M3PToken; |
| 270 | - long otherValue = ((M3PToken)other).value; | |
| 308 | + long otherValue = ((M3PToken) other).value; | |
| 271 | 309 | return value < otherValue ? -1 : (value == otherValue) ? 0 : 1; |
| 272 | 310 | } |
| 273 | 311 | |
| @@ -278,12 +316,12 @@ | ||
| 278 | 316 | if (obj == null || this.getClass() != obj.getClass()) |
| 279 | 317 | return false; |
| 280 | 318 | |
| 281 | - return value == ((M3PToken)obj).value; | |
| 319 | + return value == ((M3PToken) obj).value; | |
| 282 | 320 | } |
| 283 | 321 | |
| 284 | 322 | @Override |
| 285 | 323 | public int hashCode() { |
| 286 | - return (int)(value^(value>>>32)); | |
| 324 | + return (int) (value ^ (value >>> 32)); | |
| 287 | 325 | } |
| 288 | 326 | |
| 289 | 327 | @Override |
| @@ -346,8 +384,8 @@ | ||
| 346 | 384 | if (tokenOrder == 0 && startToken.equals(MIN_TOKEN)) |
| 347 | 385 | throw new IllegalArgumentException("Cannot split whole ring with ordered partitioner"); |
| 348 | 386 | |
| 349 | - OPPToken oppStartToken = (OPPToken)startToken; | |
| 350 | - OPPToken oppEndToken = (OPPToken)endToken; | |
| 387 | + OPPToken oppStartToken = (OPPToken) startToken; | |
| 388 | + OPPToken oppEndToken = (OPPToken) endToken; | |
| 351 | 389 | |
| 352 | 390 | int significantBytes; |
| 353 | 391 | BigInteger start, end, range, ringEnd, ringLength; |
| @@ -389,8 +427,8 @@ | ||
| 389 | 427 | } |
| 390 | 428 | |
| 391 | 429 | List<BigInteger> values = super.split(start, range, |
| 392 | - ringEnd, ringLength, | |
| 393 | - numberOfSplits); | |
| 430 | + ringEnd, ringLength, | |
| 431 | + numberOfSplits); | |
| 394 | 432 | List<Token> tokens = Lists.newArrayListWithExpectedSize(values.size()); |
| 395 | 433 | for (BigInteger value : values) |
| 396 | 434 | tokens.add(new OPPToken(toBytes(value, significantBytes))); |
| @@ -446,8 +484,8 @@ | ||
| 446 | 484 | private static ByteBuffer stripTrailingZeroBytes(ByteBuffer b) { |
| 447 | 485 | byte result[] = Bytes.getArray(b); |
| 448 | 486 | int zeroIndex = result.length; |
| 449 | - for(int i = result.length-1; i > 0; i--) { | |
| 450 | - if(result[i] == 0) { | |
| 487 | + for (int i = result.length - 1; i > 0; i--) { | |
| 488 | + if (result[i] == 0) { | |
| 451 | 489 | zeroIndex = i; |
| 452 | 490 | } else { |
| 453 | 491 | break; |
| @@ -470,8 +508,8 @@ | ||
| 470 | 508 | public int compareTo(Token other) { |
| 471 | 509 | assert other instanceof OPPToken; |
| 472 | 510 | return UnsignedBytes.lexicographicalComparator().compare( |
| 473 | - Bytes.getArray(value), | |
| 474 | - Bytes.getArray(((OPPToken)other).value)); | |
| 511 | + Bytes.getArray(value), | |
| 512 | + Bytes.getArray(((OPPToken) other).value)); | |
| 475 | 513 | } |
| 476 | 514 | |
| 477 | 515 | @Override |
| @@ -481,7 +519,7 @@ | ||
| 481 | 519 | if (obj == null || this.getClass() != obj.getClass()) |
| 482 | 520 | return false; |
| 483 | 521 | |
| 484 | - return value.equals(((OPPToken)obj).value); | |
| 522 | + return value.equals(((OPPToken) obj).value); | |
| 485 | 523 | } |
| 486 | 524 | |
| 487 | 525 | @Override |
| @@ -532,7 +570,7 @@ | ||
| 532 | 570 | |
| 533 | 571 | @Override |
| 534 | 572 | Token deserialize(ByteBuffer buffer) { |
| 535 | - return new RPToken((BigInteger)getTokenType().deserialize(buffer)); | |
| 573 | + return new RPToken((BigInteger) getTokenType().deserialize(buffer)); | |
| 536 | 574 | } |
| 537 | 575 | |
| 538 | 576 | @Override |
| @@ -551,16 +589,16 @@ | ||
| 551 | 589 | if (startToken.equals(endToken) && startToken.equals(MIN_TOKEN)) |
| 552 | 590 | endToken = MAX_TOKEN; |
| 553 | 591 | |
| 554 | - BigInteger start = ((RPToken)startToken).value; | |
| 555 | - BigInteger end = ((RPToken)endToken).value; | |
| 592 | + BigInteger start = ((RPToken) startToken).value; | |
| 593 | + BigInteger end = ((RPToken) endToken).value; | |
| 556 | 594 | |
| 557 | 595 | BigInteger range = end.subtract(start); |
| 558 | 596 | if (range.compareTo(BigInteger.ZERO) < 0) |
| 559 | 597 | range = range.add(RING_LENGTH); |
| 560 | 598 | |
| 561 | 599 | List<BigInteger> values = super.split(start, range, |
| 562 | - MAX_VALUE, RING_LENGTH, | |
| 563 | - numberOfSplits); | |
| 600 | + MAX_VALUE, RING_LENGTH, | |
| 601 | + numberOfSplits); | |
| 564 | 602 | List<Token> tokens = Lists.newArrayListWithExpectedSize(values.size()); |
| 565 | 603 | for (BigInteger value : values) |
| 566 | 604 | tokens.add(new RPToken(value)); |
| @@ -585,7 +623,7 @@ | ||
| 585 | 623 | @Override |
| 586 | 624 | public int compareTo(Token other) { |
| 587 | 625 | assert other instanceof RPToken; |
| 588 | - return value.compareTo(((RPToken)other).value); | |
| 626 | + return value.compareTo(((RPToken) other).value); | |
| 589 | 627 | } |
| 590 | 628 | |
| 591 | 629 | @Override |
| @@ -595,7 +633,7 @@ | ||
| 595 | 633 | if (obj == null || this.getClass() != obj.getClass()) |
| 596 | 634 | return false; |
| 597 | 635 | |
| 598 | - return value.equals(((RPToken)obj).value); | |
| 636 | + return value.equals(((RPToken) obj).value); | |
| 599 | 637 | } |
| 600 | 638 | |
| 601 | 639 | @Override |
modified driver-core/src/main/java/com/datastax/driver/core/TokenRange.java +46 −48
| @@ -15,21 +15,20 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.util.ArrayList; | |
| 19 | -import java.util.Iterator; | |
| 20 | -import java.util.List; | |
| 21 | - | |
| 22 | 18 | import com.google.common.annotations.VisibleForTesting; |
| 23 | 19 | import com.google.common.base.Objects; |
| 24 | 20 | import com.google.common.collect.ImmutableList; |
| 25 | 21 | import com.google.common.collect.Lists; |
| 26 | 22 | |
| 23 | +import java.util.ArrayList; | |
| 24 | +import java.util.List; | |
| 25 | + | |
| 27 | 26 | /** |
| 28 | 27 | * A range of tokens on the Cassandra ring. |
| 29 | - * <p> | |
| 28 | + * <p/> | |
| 30 | 29 | * A range is start-exclusive and end-inclusive. It is empty when start and end are the same token, except if that is the minimum |
| 31 | 30 | * token, in which case the range covers the whole ring (this is consistent with the behavior of CQL range queries). |
| 32 | - * <p> | |
| 31 | + * <p/> | |
| 33 | 32 | * Note that CQL does not handle wrapping. To query all partitions in a range, see {@link #unwrap()}. |
| 34 | 33 | */ |
| 35 | 34 | public final class TokenRange implements Comparable<TokenRange> { |
| @@ -64,12 +63,11 @@ | ||
| 64 | 63 | |
| 65 | 64 | /** |
| 66 | 65 | * Splits this range into a number of smaller ranges of equal "size" (referring to the number of tokens, not the actual amount of data). |
| 67 | - * <p> | |
| 66 | + * <p/> | |
| 68 | 67 | * Splitting an empty range is not permitted. But note that, in edge cases, splitting a range might produce one or more empty ranges. |
| 69 | 68 | * |
| 70 | 69 | * @param numberOfSplits the number of splits to create. |
| 71 | 70 | * @return the splits. |
| 72 | - * | |
| 73 | 71 | * @throws IllegalArgumentException if the range is empty or if numberOfSplits < 1. |
| 74 | 72 | */ |
| 75 | 73 | public List<TokenRange> splitEvenly(int numberOfSplits) { |
| @@ -91,7 +89,7 @@ | ||
| 91 | 89 | |
| 92 | 90 | /** |
| 93 | 91 | * Returns whether this range is empty. |
| 94 | - * <p> | |
| 92 | + * <p/> | |
| 95 | 93 | * A range is empty when start and end are the same token, except if that is the minimum token, |
| 96 | 94 | * in which case the range covers the whole ring (this is consistent with the behavior of CQL |
| 97 | 95 | * range queries). |
| @@ -114,13 +112,13 @@ | ||
| 114 | 112 | /** |
| 115 | 113 | * Splits this range into a list of two non-wrapping ranges. This will return the range itself if it is |
| 116 | 114 | * non-wrapping, or two ranges otherwise. |
| 117 | - * <p> | |
| 115 | + * <p/> | |
| 118 | 116 | * For example: |
| 119 | 117 | * <ul> |
| 120 | - * <li>{@code ]1,10]} unwraps to itself;</li> | |
| 121 | - * <li>{@code ]10,1]} unwraps to {@code ]10,min_token]} and {@code ]min_token,1]}.</li> | |
| 118 | + * <li>{@code ]1,10]} unwraps to itself;</li> | |
| 119 | + * <li>{@code ]10,1]} unwraps to {@code ]10,min_token]} and {@code ]min_token,1]}.</li> | |
| 122 | 120 | * </ul> |
| 123 | - * <p> | |
| 121 | + * <p/> | |
| 124 | 122 | * This is useful for CQL range queries, which do not handle wrapping: |
| 125 | 123 | * <pre> |
| 126 | 124 | * {@code |
| @@ -137,8 +135,8 @@ | ||
| 137 | 135 | public List<TokenRange> unwrap() { |
| 138 | 136 | if (isWrappedAround()) { |
| 139 | 137 | return ImmutableList.of( |
| 140 | - new TokenRange(start, factory.minToken(), factory), | |
| 141 | - new TokenRange(factory.minToken(), end, factory)); | |
| 138 | + new TokenRange(start, factory.minToken(), factory), | |
| 139 | + new TokenRange(factory.minToken(), end, factory)); | |
| 142 | 140 | } else { |
| 143 | 141 | return ImmutableList.of(this); |
| 144 | 142 | } |
| @@ -146,11 +144,11 @@ | ||
| 146 | 144 | |
| 147 | 145 | /** |
| 148 | 146 | * Returns whether this range intersects another one. |
| 149 | - * <p> | |
| 147 | + * <p/> | |
| 150 | 148 | * For example: |
| 151 | 149 | * <ul> |
| 152 | - * <li>{@code ]3,5]} intersects {@code ]1,4]}, {@code ]4,5]}...</li> | |
| 153 | - * <li>{@code ]3,5]} does not intersect {@code ]1,2]}, {@code ]2,3]}, {@code ]5,7]}...</li> | |
| 150 | + * <li>{@code ]3,5]} intersects {@code ]1,4]}, {@code ]4,5]}...</li> | |
| 151 | + * <li>{@code ]3,5]} does not intersect {@code ]1,2]}, {@code ]2,3]}, {@code ]5,7]}...</li> | |
| 154 | 152 | * </ul> |
| 155 | 153 | * |
| 156 | 154 | * @param that the other range. |
| @@ -162,17 +160,17 @@ | ||
| 162 | 160 | return false; |
| 163 | 161 | |
| 164 | 162 | return this.contains(that.start, true) |
| 165 | - || this.contains(that.end, false) | |
| 166 | - || that.contains(this.start, true) | |
| 167 | - || that.contains(this.end, false); | |
| 163 | + || this.contains(that.end, false) | |
| 164 | + || that.contains(this.start, true) | |
| 165 | + || that.contains(this.end, false); | |
| 168 | 166 | } |
| 169 | 167 | |
| 170 | 168 | /** |
| 171 | 169 | * Computes the intersection of this range with another one. |
| 172 | - * <p> | |
| 170 | + * <p/> | |
| 173 | 171 | * If either of these ranges overlap the the ring, they are unwrapped and the unwrapped |
| 174 | 172 | * tokens are compared with one another. |
| 175 | - * <p> | |
| 173 | + * <p/> | |
| 176 | 174 | * This call will fail if the two ranges do not intersect, you must check by calling |
| 177 | 175 | * {@link #intersects(TokenRange)} beforehand. |
| 178 | 176 | * |
| @@ -189,20 +187,20 @@ | ||
| 189 | 187 | // Compare the unwrapped ranges to one another. |
| 190 | 188 | List<TokenRange> unwrappedForThis = this.unwrap(); |
| 191 | 189 | List<TokenRange> unwrappedForThat = that.unwrap(); |
| 192 | - for(TokenRange t1 : unwrappedForThis) { | |
| 193 | - for(TokenRange t2 : unwrappedForThat) { | |
| 194 | - if(t1.intersects(t2)) { | |
| 190 | + for (TokenRange t1 : unwrappedForThis) { | |
| 191 | + for (TokenRange t2 : unwrappedForThat) { | |
| 192 | + if (t1.intersects(t2)) { | |
| 195 | 193 | intersected.add(new TokenRange( |
| 196 | - (t1.contains(t2.start, true)) ? t2.start : t1.start, | |
| 197 | - (t1.contains(t2.end, false)) ? t2.end : t1.end, | |
| 198 | - factory)); | |
| 194 | + (t1.contains(t2.start, true)) ? t2.start : t1.start, | |
| 195 | + (t1.contains(t2.end, false)) ? t2.end : t1.end, | |
| 196 | + factory)); | |
| 199 | 197 | } |
| 200 | 198 | } |
| 201 | 199 | } |
| 202 | 200 | |
| 203 | 201 | // If two intersecting ranges were produced, merge them if they are adjacent. |
| 204 | 202 | // This could happen in the case that two wrapped ranges intersected. |
| 205 | - if(intersected.size() == 2) { | |
| 203 | + if (intersected.size() == 2) { | |
| 206 | 204 | TokenRange t1 = intersected.get(0); |
| 207 | 205 | TokenRange t2 = intersected.get(1); |
| 208 | 206 | if (t1.end.equals(t2.start) || t2.end.equals(t1.start)) { |
| @@ -229,29 +227,28 @@ | ||
| 229 | 227 | private boolean contains(Token token, boolean isStart) { |
| 230 | 228 | boolean isAfterStart = isStart ? token.compareTo(start) >= 0 : token.compareTo(start) > 0; |
| 231 | 229 | boolean isBeforeEnd = end.equals(factory.minToken()) || |
| 232 | - (isStart ? token.compareTo(end) < 0 : token.compareTo(end) <= 0); | |
| 230 | + (isStart ? token.compareTo(end) < 0 : token.compareTo(end) <= 0); | |
| 233 | 231 | return isWrappedAround() |
| 234 | - ? isAfterStart || isBeforeEnd | |
| 235 | - : isAfterStart && isBeforeEnd; | |
| 232 | + ? isAfterStart || isBeforeEnd | |
| 233 | + : isAfterStart && isBeforeEnd; | |
| 236 | 234 | } |
| 237 | 235 | |
| 238 | 236 | /** |
| 239 | 237 | * Merges this range with another one. |
| 240 | - * <p> | |
| 238 | + * <p/> | |
| 241 | 239 | * The two ranges should either intersect or be adjacent; in other words, the merged range |
| 242 | 240 | * should not include tokens that are in neither of the original ranges. |
| 243 | - * <p> | |
| 241 | + * <p/> | |
| 244 | 242 | * For example: |
| 245 | 243 | * <ul> |
| 246 | - * <li>merging {@code ]3,5]} with {@code ]4,7]} produces {@code ]3,7]};</li> | |
| 247 | - * <li>merging {@code ]3,5]} with {@code ]4,5]} produces {@code ]3,5]};</li> | |
| 248 | - * <li>merging {@code ]3,5]} with {@code ]5,8]} produces {@code ]3,8]};</li> | |
| 249 | - * <li>merging {@code ]3,5]} with {@code ]6,8]} fails.</li> | |
| 244 | + * <li>merging {@code ]3,5]} with {@code ]4,7]} produces {@code ]3,7]};</li> | |
| 245 | + * <li>merging {@code ]3,5]} with {@code ]4,5]} produces {@code ]3,5]};</li> | |
| 246 | + * <li>merging {@code ]3,5]} with {@code ]5,8]} produces {@code ]3,8]};</li> | |
| 247 | + * <li>merging {@code ]3,5]} with {@code ]6,8]} fails.</li> | |
| 250 | 248 | * </ul> |
| 251 | 249 | * |
| 252 | 250 | * @param that the other range. |
| 253 | 251 | * @return the resulting range. |
| 254 | - * | |
| 255 | 252 | * @throws IllegalArgumentException if the ranges neither intersect nor are adjacent. |
| 256 | 253 | */ |
| 257 | 254 | public TokenRange mergeWith(TokenRange that) { |
| @@ -260,8 +257,8 @@ | ||
| 260 | 257 | |
| 261 | 258 | if (!(this.intersects(that) || this.end.equals(that.start) || that.end.equals(this.start))) |
| 262 | 259 | throw new IllegalArgumentException(String.format( |
| 263 | - "Can't merge %s with %s because they neither intersect nor are adjacent", | |
| 264 | - this, that)); | |
| 260 | + "Can't merge %s with %s because they neither intersect nor are adjacent", | |
| 261 | + this, that)); | |
| 265 | 262 | |
| 266 | 263 | if (this.isEmpty()) |
| 267 | 264 | return that; |
| @@ -279,8 +276,8 @@ | ||
| 279 | 276 | |
| 280 | 277 | // Starting at this.start, see how far we can go while staying in at least one of the ranges. |
| 281 | 278 | Token mergedEnd = (thatStartsInThis && !this.contains(that.end, false)) |
| 282 | - ? that.end | |
| 283 | - : this.end; | |
| 279 | + ? that.end | |
| 280 | + : this.end; | |
| 284 | 281 | |
| 285 | 282 | // Repeat in the other direction. |
| 286 | 283 | Token mergedStart = thisStartsInThat ? that.start : this.start; |
| @@ -297,9 +294,9 @@ | ||
| 297 | 294 | if (other == this) |
| 298 | 295 | return true; |
| 299 | 296 | if (other instanceof TokenRange) { |
| 300 | - TokenRange that = (TokenRange)other; | |
| 297 | + TokenRange that = (TokenRange) other; | |
| 301 | 298 | return Objects.equal(this.start, that.start) && |
| 302 | - Objects.equal(this.end, that.end); | |
| 299 | + Objects.equal(this.end, that.end); | |
| 303 | 300 | } |
| 304 | 301 | return false; |
| 305 | 302 | } |
| @@ -314,8 +311,9 @@ | ||
| 314 | 311 | return String.format("]%s, %s]", start, end); |
| 315 | 312 | } |
| 316 | 313 | |
| 317 | - @Override public int compareTo(TokenRange other) { | |
| 318 | - if(this.equals(other)) { | |
| 314 | + @Override | |
| 315 | + public int compareTo(TokenRange other) { | |
| 316 | + if (this.equals(other)) { | |
| 319 | 317 | return 0; |
| 320 | 318 | } else { |
| 321 | 319 | int compareStart = this.start.compareTo(other.start); |
modified driver-core/src/main/java/com/datastax/driver/core/TransportException.java +3 −6
| @@ -21,17 +21,14 @@ | ||
| 21 | 21 | * A connection exception that has to do with the transport itself, i.e. that |
| 22 | 22 | * suggests the node is down. |
| 23 | 23 | */ |
| 24 | -class TransportException extends ConnectionException | |
| 25 | -{ | |
| 24 | +class TransportException extends ConnectionException { | |
| 26 | 25 | private static final long serialVersionUID = 0; |
| 27 | 26 | |
| 28 | - public TransportException(InetSocketAddress address, String msg, Throwable cause) | |
| 29 | - { | |
| 27 | + public TransportException(InetSocketAddress address, String msg, Throwable cause) { | |
| 30 | 28 | super(address, msg, cause); |
| 31 | 29 | } |
| 32 | 30 | |
| 33 | - public TransportException(InetSocketAddress address, String msg) | |
| 34 | - { | |
| 31 | + public TransportException(InetSocketAddress address, String msg) { | |
| 35 | 32 | super(address, msg); |
| 36 | 33 | } |
| 37 | 34 | } |
modified driver-core/src/main/java/com/datastax/driver/core/TypeCodec.java +83 −67
| @@ -15,6 +15,9 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.exceptions.InvalidTypeException; | |
| 19 | +import com.datastax.driver.core.utils.Bytes; | |
| 20 | + | |
| 18 | 21 | import java.math.BigDecimal; |
| 19 | 22 | import java.math.BigInteger; |
| 20 | 23 | import java.net.InetAddress; |
| @@ -28,42 +31,40 @@ | ||
| 28 | 31 | import java.util.*; |
| 29 | 32 | import java.util.regex.Pattern; |
| 30 | 33 | |
| 31 | -import com.datastax.driver.core.exceptions.InvalidTypeException; | |
| 32 | -import com.datastax.driver.core.utils.Bytes; | |
| 33 | - | |
| 34 | 34 | abstract class TypeCodec<T> { |
| 35 | 35 | |
| 36 | 36 | private static final Map<DataType.Name, TypeCodec<?>> primitiveCodecs = new EnumMap<DataType.Name, TypeCodec<?>>(DataType.Name.class); |
| 37 | + | |
| 37 | 38 | static { |
| 38 | - primitiveCodecs.put(DataType.Name.ASCII, StringCodec.asciiInstance); | |
| 39 | - primitiveCodecs.put(DataType.Name.BIGINT, LongCodec.instance); | |
| 40 | - primitiveCodecs.put(DataType.Name.BLOB, BytesCodec.instance); | |
| 41 | - primitiveCodecs.put(DataType.Name.BOOLEAN, BooleanCodec.instance); | |
| 42 | - primitiveCodecs.put(DataType.Name.COUNTER, LongCodec.instance); | |
| 43 | - primitiveCodecs.put(DataType.Name.DECIMAL, DecimalCodec.instance); | |
| 44 | - primitiveCodecs.put(DataType.Name.DOUBLE, DoubleCodec.instance); | |
| 45 | - primitiveCodecs.put(DataType.Name.FLOAT, FloatCodec.instance); | |
| 46 | - primitiveCodecs.put(DataType.Name.INET, InetCodec.instance); | |
| 47 | - primitiveCodecs.put(DataType.Name.INT, IntCodec.instance); | |
| 48 | - primitiveCodecs.put(DataType.Name.TEXT, StringCodec.utf8Instance); | |
| 39 | + primitiveCodecs.put(DataType.Name.ASCII, StringCodec.asciiInstance); | |
| 40 | + primitiveCodecs.put(DataType.Name.BIGINT, LongCodec.instance); | |
| 41 | + primitiveCodecs.put(DataType.Name.BLOB, BytesCodec.instance); | |
| 42 | + primitiveCodecs.put(DataType.Name.BOOLEAN, BooleanCodec.instance); | |
| 43 | + primitiveCodecs.put(DataType.Name.COUNTER, LongCodec.instance); | |
| 44 | + primitiveCodecs.put(DataType.Name.DECIMAL, DecimalCodec.instance); | |
| 45 | + primitiveCodecs.put(DataType.Name.DOUBLE, DoubleCodec.instance); | |
| 46 | + primitiveCodecs.put(DataType.Name.FLOAT, FloatCodec.instance); | |
| 47 | + primitiveCodecs.put(DataType.Name.INET, InetCodec.instance); | |
| 48 | + primitiveCodecs.put(DataType.Name.INT, IntCodec.instance); | |
| 49 | + primitiveCodecs.put(DataType.Name.TEXT, StringCodec.utf8Instance); | |
| 49 | 50 | primitiveCodecs.put(DataType.Name.TIMESTAMP, DateCodec.instance); |
| 50 | - primitiveCodecs.put(DataType.Name.UUID, UUIDCodec.instance); | |
| 51 | - primitiveCodecs.put(DataType.Name.VARCHAR, StringCodec.utf8Instance); | |
| 52 | - primitiveCodecs.put(DataType.Name.VARINT, BigIntegerCodec.instance); | |
| 53 | - primitiveCodecs.put(DataType.Name.TIMEUUID, TimeUUIDCodec.instance); | |
| 54 | - primitiveCodecs.put(DataType.Name.CUSTOM, BytesCodec.instance); | |
| 51 | + primitiveCodecs.put(DataType.Name.UUID, UUIDCodec.instance); | |
| 52 | + primitiveCodecs.put(DataType.Name.VARCHAR, StringCodec.utf8Instance); | |
| 53 | + primitiveCodecs.put(DataType.Name.VARINT, BigIntegerCodec.instance); | |
| 54 | + primitiveCodecs.put(DataType.Name.TIMEUUID, TimeUUIDCodec.instance); | |
| 55 | + primitiveCodecs.put(DataType.Name.CUSTOM, BytesCodec.instance); | |
| 55 | 56 | } |
| 56 | 57 | |
| 57 | 58 | private static final Map<DataType.Name, TypeCodec<List<?>>> primitiveListsCodecs = new EnumMap<DataType.Name, TypeCodec<List<?>>>(DataType.Name.class); |
| 58 | 59 | private static final Map<DataType.Name, TypeCodec<Set<?>>> primitiveSetsCodecs = new EnumMap<DataType.Name, TypeCodec<Set<?>>>(DataType.Name.class); |
| 59 | 60 | private static final Map<DataType.Name, Map<DataType.Name, TypeCodec<Map<?, ?>>>> primitiveMapsCodecs = new EnumMap<DataType.Name, Map<DataType.Name, TypeCodec<Map<?, ?>>>>(DataType.Name.class); |
| 61 | + | |
| 60 | 62 | static { |
| 61 | 63 | populatePrimitiveCollectionCodecs(); |
| 62 | 64 | } |
| 63 | 65 | |
| 64 | 66 | @SuppressWarnings({"unchecked", "rawtypes"}) |
| 65 | - private static void populatePrimitiveCollectionCodecs() | |
| 66 | - { | |
| 67 | + private static void populatePrimitiveCollectionCodecs() { | |
| 67 | 68 | for (Map.Entry<DataType.Name, TypeCodec<?>> entry : primitiveCodecs.entrySet()) { |
| 68 | 69 | DataType.Name type = entry.getKey(); |
| 69 | 70 | TypeCodec<?> codec = entry.getValue(); |
| @@ -76,34 +77,37 @@ | ||
| 76 | 77 | } |
| 77 | 78 | } |
| 78 | 79 | |
| 79 | - private TypeCodec() {} | |
| 80 | + private TypeCodec() { | |
| 81 | + } | |
| 80 | 82 | |
| 81 | 83 | public abstract T parse(String value); |
| 84 | + | |
| 82 | 85 | public abstract String format(T value); |
| 83 | 86 | |
| 84 | 87 | public abstract ByteBuffer serialize(T value); |
| 88 | + | |
| 85 | 89 | public abstract T deserialize(ByteBuffer bytes); |
| 86 | 90 | |
| 87 | 91 | @SuppressWarnings("unchecked") |
| 88 | 92 | static <T> TypeCodec<T> createFor(DataType.Name name) { |
| 89 | 93 | assert !name.isCollection(); |
| 90 | - return (TypeCodec<T>)primitiveCodecs.get(name); | |
| 94 | + return (TypeCodec<T>) primitiveCodecs.get(name); | |
| 91 | 95 | } |
| 92 | 96 | |
| 93 | 97 | @SuppressWarnings("unchecked") |
| 94 | 98 | static <T> TypeCodec<List<T>> listOf(DataType arg) { |
| 95 | 99 | TypeCodec<List<?>> codec = primitiveListsCodecs.get(arg.getName()); |
| 96 | 100 | return codec != null |
| 97 | - ? (TypeCodec)codec | |
| 98 | - : new ListCodec<T>(TypeCodec.<T>createFor(arg.getName())); | |
| 101 | + ? (TypeCodec) codec | |
| 102 | + : new ListCodec<T>(TypeCodec.<T>createFor(arg.getName())); | |
| 99 | 103 | } |
| 100 | 104 | |
| 101 | 105 | @SuppressWarnings("unchecked") |
| 102 | 106 | static <T> TypeCodec<Set<T>> setOf(DataType arg) { |
| 103 | 107 | TypeCodec<Set<?>> codec = primitiveSetsCodecs.get(arg.getName()); |
| 104 | 108 | return codec != null |
| 105 | - ? (TypeCodec)codec | |
| 106 | - : new SetCodec<T>(TypeCodec.<T>createFor(arg.getName())); | |
| 109 | + ? (TypeCodec) codec | |
| 110 | + : new SetCodec<T>(TypeCodec.<T>createFor(arg.getName())); | |
| 107 | 111 | } |
| 108 | 112 | |
| 109 | 113 | @SuppressWarnings("unchecked") |
| @@ -111,8 +115,8 @@ | ||
| 111 | 115 | Map<DataType.Name, TypeCodec<Map<?, ?>>> valueCodecs = primitiveMapsCodecs.get(keys.getName()); |
| 112 | 116 | TypeCodec<Map<?, ?>> codec = valueCodecs == null ? null : valueCodecs.get(values.getName()); |
| 113 | 117 | return codec != null |
| 114 | - ? (TypeCodec)codec | |
| 115 | - : new MapCodec<K, V>(TypeCodec.<K>createFor(keys.getName()), TypeCodec.<V>createFor(values.getName())); | |
| 118 | + ? (TypeCodec) codec | |
| 119 | + : new MapCodec<K, V>(TypeCodec.<K>createFor(keys.getName()), TypeCodec.<V>createFor(values.getName())); | |
| 116 | 120 | } |
| 117 | 121 | |
| 118 | 122 | /* This is ugly, but not sure how we can do much better/faster |
| @@ -163,7 +167,7 @@ | ||
| 163 | 167 | return DataType.uuid(); |
| 164 | 168 | |
| 165 | 169 | if (value instanceof List) { |
| 166 | - List<?> l = (List<?>)value; | |
| 170 | + List<?> l = (List<?>) value; | |
| 167 | 171 | if (l.isEmpty()) |
| 168 | 172 | return DataType.list(DataType.blob()); |
| 169 | 173 | DataType eltType = getDataTypeFor(l.get(0)); |
| @@ -171,7 +175,7 @@ | ||
| 171 | 175 | } |
| 172 | 176 | |
| 173 | 177 | if (value instanceof Set) { |
| 174 | - Set<?> s = (Set<?>)value; | |
| 178 | + Set<?> s = (Set<?>) value; | |
| 175 | 179 | if (s.isEmpty()) |
| 176 | 180 | return DataType.set(DataType.blob()); |
| 177 | 181 | DataType eltType = getDataTypeFor(s.iterator().next()); |
| @@ -179,15 +183,15 @@ | ||
| 179 | 183 | } |
| 180 | 184 | |
| 181 | 185 | if (value instanceof Map) { |
| 182 | - Map<?, ?> m = (Map<?, ?>)value; | |
| 186 | + Map<?, ?> m = (Map<?, ?>) value; | |
| 183 | 187 | if (m.isEmpty()) |
| 184 | 188 | return DataType.map(DataType.blob(), DataType.blob()); |
| 185 | 189 | Map.Entry<?, ?> e = m.entrySet().iterator().next(); |
| 186 | 190 | DataType keyType = getDataTypeFor(e.getKey()); |
| 187 | 191 | DataType valueType = getDataTypeFor(e.getValue()); |
| 188 | 192 | return keyType == null || valueType == null |
| 189 | - ? null | |
| 190 | - : DataType.map(keyType, valueType); | |
| 193 | + ? null | |
| 194 | + : DataType.map(keyType, valueType); | |
| 191 | 195 | } |
| 192 | 196 | |
| 193 | 197 | return null; |
| @@ -198,15 +202,15 @@ | ||
| 198 | 202 | if (elements > 65535) |
| 199 | 203 | throw new IllegalArgumentException("Native protocol version 2 supports up to 65535 elements in any collection - but collection contains " + elements + " elements"); |
| 200 | 204 | ByteBuffer result = ByteBuffer.allocate(2 + size); |
| 201 | - result.putShort((short)elements); | |
| 205 | + result.putShort((short) elements); | |
| 202 | 206 | for (ByteBuffer bb : buffers) { |
| 203 | 207 | int elemSize = bb.remaining(); |
| 204 | 208 | if (elemSize > 65535) |
| 205 | 209 | throw new IllegalArgumentException("Native protocol version 2 supports only elements with size up to 65535 bytes - but element size is " + elemSize + " bytes"); |
| 206 | - result.putShort((short)elemSize); | |
| 210 | + result.putShort((short) elemSize); | |
| 207 | 211 | result.put(bb.duplicate()); |
| 208 | 212 | } |
| 209 | - return (ByteBuffer)result.flip(); | |
| 213 | + return (ByteBuffer) result.flip(); | |
| 210 | 214 | } |
| 211 | 215 | |
| 212 | 216 | // Utility method for collections |
| @@ -245,7 +249,7 @@ | ||
| 245 | 249 | int nbMatch = 0; |
| 246 | 250 | int start = -1; |
| 247 | 251 | do { |
| 248 | - start = text.indexOf(search, start+1); | |
| 252 | + start = text.indexOf(search, start + 1); | |
| 249 | 253 | if (start != -1) |
| 250 | 254 | ++nbMatch; |
| 251 | 255 | } while (start != -1); |
| @@ -283,7 +287,8 @@ | ||
| 283 | 287 | |
| 284 | 288 | public static final LongCodec instance = new LongCodec(); |
| 285 | 289 | |
| 286 | - private LongCodec() {} | |
| 290 | + private LongCodec() { | |
| 291 | + } | |
| 287 | 292 | |
| 288 | 293 | @Override |
| 289 | 294 | public Long parse(String value) { |
| @@ -327,7 +332,8 @@ | ||
| 327 | 332 | |
| 328 | 333 | public static final BytesCodec instance = new BytesCodec(); |
| 329 | 334 | |
| 330 | - private BytesCodec() {} | |
| 335 | + private BytesCodec() { | |
| 336 | + } | |
| 331 | 337 | |
| 332 | 338 | @Override |
| 333 | 339 | public ByteBuffer parse(String value) { |
| @@ -352,12 +358,13 @@ | ||
| 352 | 358 | |
| 353 | 359 | static class BooleanCodec extends TypeCodec<Boolean> { |
| 354 | 360 | |
| 355 | - private static final ByteBuffer TRUE = ByteBuffer.wrap(new byte[] {1}); | |
| 356 | - private static final ByteBuffer FALSE = ByteBuffer.wrap(new byte[] {0}); | |
| 361 | + private static final ByteBuffer TRUE = ByteBuffer.wrap(new byte[]{1}); | |
| 362 | + private static final ByteBuffer FALSE = ByteBuffer.wrap(new byte[]{0}); | |
| 357 | 363 | |
| 358 | 364 | public static final BooleanCodec instance = new BooleanCodec(); |
| 359 | 365 | |
| 360 | - private BooleanCodec() {} | |
| 366 | + private BooleanCodec() { | |
| 367 | + } | |
| 361 | 368 | |
| 362 | 369 | @Override |
| 363 | 370 | public Boolean parse(String value) { |
| @@ -400,7 +407,8 @@ | ||
| 400 | 407 | |
| 401 | 408 | public static final DecimalCodec instance = new DecimalCodec(); |
| 402 | 409 | |
| 403 | - private DecimalCodec() {} | |
| 410 | + private DecimalCodec() { | |
| 411 | + } | |
| 404 | 412 | |
| 405 | 413 | @Override |
| 406 | 414 | public BigDecimal parse(String value) { |
| @@ -448,7 +456,8 @@ | ||
| 448 | 456 | |
| 449 | 457 | public static final DoubleCodec instance = new DoubleCodec(); |
| 450 | 458 | |
| 451 | - private DoubleCodec() {} | |
| 459 | + private DoubleCodec() { | |
| 460 | + } | |
| 452 | 461 | |
| 453 | 462 | @Override |
| 454 | 463 | public Double parse(String value) { |
| @@ -492,7 +501,8 @@ | ||
| 492 | 501 | |
| 493 | 502 | public static final FloatCodec instance = new FloatCodec(); |
| 494 | 503 | |
| 495 | - private FloatCodec() {} | |
| 504 | + private FloatCodec() { | |
| 505 | + } | |
| 496 | 506 | |
| 497 | 507 | @Override |
| 498 | 508 | public Float parse(String value) { |
| @@ -536,7 +546,8 @@ | ||
| 536 | 546 | |
| 537 | 547 | public static final InetCodec instance = new InetCodec(); |
| 538 | 548 | |
| 539 | - private InetCodec() {} | |
| 549 | + private InetCodec() { | |
| 550 | + } | |
| 540 | 551 | |
| 541 | 552 | @Override |
| 542 | 553 | public InetAddress parse(String value) { |
| @@ -571,7 +582,8 @@ | ||
| 571 | 582 | |
| 572 | 583 | public static final IntCodec instance = new IntCodec(); |
| 573 | 584 | |
| 574 | - private IntCodec() {} | |
| 585 | + private IntCodec() { | |
| 586 | + } | |
| 575 | 587 | |
| 576 | 588 | @Override |
| 577 | 589 | public Integer parse(String value) { |
| @@ -613,27 +625,28 @@ | ||
| 613 | 625 | |
| 614 | 626 | static class DateCodec extends TypeCodec<Date> { |
| 615 | 627 | |
| 616 | - private static final String[] iso8601Patterns = new String[] { | |
| 617 | - "yyyy-MM-dd HH:mm", | |
| 618 | - "yyyy-MM-dd HH:mm:ss", | |
| 619 | - "yyyy-MM-dd HH:mmZ", | |
| 620 | - "yyyy-MM-dd HH:mm:ssZ", | |
| 621 | - "yyyy-MM-dd HH:mm:ss.SSS", | |
| 622 | - "yyyy-MM-dd HH:mm:ss.SSSZ", | |
| 623 | - "yyyy-MM-dd'T'HH:mm", | |
| 624 | - "yyyy-MM-dd'T'HH:mmZ", | |
| 625 | - "yyyy-MM-dd'T'HH:mm:ss", | |
| 626 | - "yyyy-MM-dd'T'HH:mm:ssZ", | |
| 627 | - "yyyy-MM-dd'T'HH:mm:ss.SSS", | |
| 628 | - "yyyy-MM-dd'T'HH:mm:ss.SSSZ", | |
| 629 | - "yyyy-MM-dd", | |
| 630 | - "yyyy-MM-ddZ" | |
| 628 | + private static final String[] iso8601Patterns = new String[]{ | |
| 629 | + "yyyy-MM-dd HH:mm", | |
| 630 | + "yyyy-MM-dd HH:mm:ss", | |
| 631 | + "yyyy-MM-dd HH:mmZ", | |
| 632 | + "yyyy-MM-dd HH:mm:ssZ", | |
| 633 | + "yyyy-MM-dd HH:mm:ss.SSS", | |
| 634 | + "yyyy-MM-dd HH:mm:ss.SSSZ", | |
| 635 | + "yyyy-MM-dd'T'HH:mm", | |
| 636 | + "yyyy-MM-dd'T'HH:mmZ", | |
| 637 | + "yyyy-MM-dd'T'HH:mm:ss", | |
| 638 | + "yyyy-MM-dd'T'HH:mm:ssZ", | |
| 639 | + "yyyy-MM-dd'T'HH:mm:ss.SSS", | |
| 640 | + "yyyy-MM-dd'T'HH:mm:ss.SSSZ", | |
| 641 | + "yyyy-MM-dd", | |
| 642 | + "yyyy-MM-ddZ" | |
| 631 | 643 | }; |
| 632 | 644 | |
| 633 | 645 | public static final DateCodec instance = new DateCodec(); |
| 634 | 646 | private static final Pattern IS_LONG_PATTERN = Pattern.compile("^-?\\d+$"); |
| 635 | 647 | |
| 636 | - private DateCodec() {} | |
| 648 | + private DateCodec() { | |
| 649 | + } | |
| 637 | 650 | |
| 638 | 651 | /* |
| 639 | 652 | * Copied and adapted from apache commons DateUtils.parseStrictly method (that is used Cassandra side |
| @@ -697,7 +710,8 @@ | ||
| 697 | 710 | |
| 698 | 711 | public static final UUIDCodec instance = new UUIDCodec(); |
| 699 | 712 | |
| 700 | - protected UUIDCodec() {} | |
| 713 | + protected UUIDCodec() { | |
| 714 | + } | |
| 701 | 715 | |
| 702 | 716 | @Override |
| 703 | 717 | public UUID parse(String value) { |
| @@ -731,7 +745,8 @@ | ||
| 731 | 745 | |
| 732 | 746 | public static final TimeUUIDCodec instance = new TimeUUIDCodec(); |
| 733 | 747 | |
| 734 | - private TimeUUIDCodec() {} | |
| 748 | + private TimeUUIDCodec() { | |
| 749 | + } | |
| 735 | 750 | |
| 736 | 751 | @Override |
| 737 | 752 | public UUID parse(String value) { |
| @@ -754,7 +769,8 @@ | ||
| 754 | 769 | |
| 755 | 770 | public static final BigIntegerCodec instance = new BigIntegerCodec(); |
| 756 | 771 | |
| 757 | - private BigIntegerCodec() {} | |
| 772 | + private BigIntegerCodec() { | |
| 773 | + } | |
| 758 | 774 | |
| 759 | 775 | @Override |
| 760 | 776 | public BigInteger parse(String value) { |
modified driver-core/src/main/java/com/datastax/driver/core/UnsupportedProtocolVersionException.java +1 −2
| @@ -28,8 +28,7 @@ | ||
| 28 | 28 | public final InetSocketAddress address; |
| 29 | 29 | public final int versionUnsupported; |
| 30 | 30 | |
| 31 | - public UnsupportedProtocolVersionException(InetSocketAddress address, int versionUnsupported) | |
| 32 | - { | |
| 31 | + public UnsupportedProtocolVersionException(InetSocketAddress address, int versionUnsupported) { | |
| 33 | 32 | super(String.format("[%s] Host %s does not support protocol version %d", address, address, versionUnsupported)); |
| 34 | 33 | this.address = address; |
| 35 | 34 | this.versionUnsupported = versionUnsupported; |
modified driver-core/src/main/java/com/datastax/driver/core/VersionNumber.java +15 −16
| @@ -15,17 +15,17 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | +import com.google.common.base.Objects; | |
| 19 | + | |
| 18 | 20 | import java.util.Arrays; |
| 19 | 21 | import java.util.Collections; |
| 20 | 22 | import java.util.List; |
| 21 | -import java.util.regex.Pattern; | |
| 22 | 23 | import java.util.regex.Matcher; |
| 23 | - | |
| 24 | -import com.google.common.base.Objects; | |
| 24 | +import java.util.regex.Pattern; | |
| 25 | 25 | |
| 26 | 26 | /** |
| 27 | 27 | * A version number in the form X.Y.Z with optional pre-release labels and build metadata. |
| 28 | - * <p> | |
| 28 | + * <p/> | |
| 29 | 29 | * Version numbers compare the usual way, the major number (X) is compared first, then the minor |
| 30 | 30 | * one (Y) and then the patch level one (Z). Lastly, versions with pre-release sorts before the |
| 31 | 31 | * versions that don't have one, and labels are sorted alphabetically if necessary. Build metadata |
| @@ -56,7 +56,7 @@ | ||
| 56 | 56 | |
| 57 | 57 | /** |
| 58 | 58 | * Parse a version from a string. |
| 59 | - * <p> | |
| 59 | + * <p/> | |
| 60 | 60 | * The version string should have primarily the form X.Y.Z to which can be appended |
| 61 | 61 | * one or more pre-release label after dashes (2.0.1-beta1, 2.1.4-rc1-SNAPSHOT) |
| 62 | 62 | * and an optional build label (2.1.0-beta1+a20ba.sha). Out of convenience, the |
| @@ -64,9 +64,8 @@ | ||
| 64 | 64 | * |
| 65 | 65 | * @param version the string to parse |
| 66 | 66 | * @return the parsed version number. |
| 67 | - * | |
| 68 | 67 | * @throws IllegalArgumentException if the provided string does not |
| 69 | - * represent a valid version. | |
| 68 | + * represent a valid version. | |
| 70 | 69 | */ |
| 71 | 70 | public static VersionNumber parse(String version) { |
| 72 | 71 | if (version == null) |
| @@ -127,7 +126,7 @@ | ||
| 127 | 126 | |
| 128 | 127 | /** |
| 129 | 128 | * The DSE patch version number (will only be present for version of Cassandra in DSE). |
| 130 | - * <p> | |
| 129 | + * <p/> | |
| 131 | 130 | * DataStax Entreprise (DSE) adds a fourth number to the version number to track potential |
| 132 | 131 | * hot fixes and/or DSE specific patches that may have been applied to the Cassandra version. |
| 133 | 132 | * In that case, this method return that fourth number. |
| @@ -161,7 +160,7 @@ | ||
| 161 | 160 | |
| 162 | 161 | /** |
| 163 | 162 | * The next stable version, i.e. the version stripped of its pre-release labels and build metadata. |
| 164 | - * <p> | |
| 163 | + * <p/> | |
| 165 | 164 | * This is mostly used during our development stage, where we test the driver against pre-release |
| 166 | 165 | * versions of Cassandra like 2.1.0-rc7-SNAPSHOT, but need to compare to the stable version 2.1.0 |
| 167 | 166 | * when testing for native protocol compatibility, etc. |
| @@ -218,18 +217,18 @@ | ||
| 218 | 217 | |
| 219 | 218 | @Override |
| 220 | 219 | public boolean equals(Object o) { |
| 221 | - if(!(o instanceof VersionNumber)) | |
| 220 | + if (!(o instanceof VersionNumber)) | |
| 222 | 221 | return false; |
| 223 | - VersionNumber that = (VersionNumber)o; | |
| 222 | + VersionNumber that = (VersionNumber) o; | |
| 224 | 223 | if (major != that.major || minor != that.minor || patch != that.patch) |
| 225 | 224 | return false; |
| 226 | 225 | |
| 227 | 226 | return major == that.major |
| 228 | - && minor == that.minor | |
| 229 | - && patch == that.patch | |
| 230 | - && dsePatch == that.dsePatch | |
| 231 | - && (preReleases == null ? that.preReleases == null : Arrays.equals(preReleases, that.preReleases)) | |
| 232 | - && Objects.equal(build, that.build); | |
| 227 | + && minor == that.minor | |
| 228 | + && patch == that.patch | |
| 229 | + && dsePatch == that.dsePatch | |
| 230 | + && (preReleases == null ? that.preReleases == null : Arrays.equals(preReleases, that.preReleases)) | |
| 231 | + && Objects.equal(build, that.build); | |
| 233 | 232 | } |
| 234 | 233 | |
| 235 | 234 | @Override |
modified driver-core/src/main/java/com/datastax/driver/core/WriteType.java +14 −7
| @@ -17,25 +17,32 @@ | ||
| 17 | 17 | |
| 18 | 18 | /** |
| 19 | 19 | * The type of a Cassandra write query. |
| 20 | - * <p> | |
| 20 | + * <p/> | |
| 21 | 21 | * This information is returned by Cassandra when a write timeout is raised to |
| 22 | 22 | * indicate what type of write timed out. This information is useful to decide |
| 23 | 23 | * which retry policy to adopt. |
| 24 | 24 | */ |
| 25 | -public enum WriteType | |
| 26 | -{ | |
| 27 | - /** A write to a single partition key. Such writes are guaranteed to be atomic and isolated. */ | |
| 25 | +public enum WriteType { | |
| 26 | + /** | |
| 27 | + * A write to a single partition key. Such writes are guaranteed to be atomic and isolated. | |
| 28 | + */ | |
| 28 | 29 | SIMPLE, |
| 29 | 30 | /** |
| 30 | 31 | * A write to a multiple partition key that used the distributed batch log to ensure atomicity |
| 31 | 32 | * (atomicity meaning that if any statement in the batch succeeds, all will eventually succeed). |
| 32 | 33 | */ |
| 33 | 34 | BATCH, |
| 34 | - /** A write to a multiple partition key that doesn't use the distributed batch log. Atomicity for such writes is not guaranteed */ | |
| 35 | + /** | |
| 36 | + * A write to a multiple partition key that doesn't use the distributed batch log. Atomicity for such writes is not guaranteed | |
| 37 | + */ | |
| 35 | 38 | UNLOGGED_BATCH, |
| 36 | - /** A counter write (that can be for one or multiple partition key). Such write should not be replayed to avoid over-counting. */ | |
| 39 | + /** | |
| 40 | + * A counter write (that can be for one or multiple partition key). Such write should not be replayed to avoid over-counting. | |
| 41 | + */ | |
| 37 | 42 | COUNTER, |
| 38 | - /** The initial write to the distributed batch log that Cassandra performs internally before a BATCH write. */ | |
| 43 | + /** | |
| 44 | + * The initial write to the distributed batch log that Cassandra performs internally before a BATCH write. | |
| 45 | + */ | |
| 39 | 46 | BATCH_LOG, |
| 40 | 47 | /** |
| 41 | 48 | * A conditional write. If a timeout has this {@code WriteType}, the timeout has happened while doing the compare-and-swap for |
modified driver-core/src/main/java/com/datastax/driver/core/exceptions/AlreadyExistsException.java +5 −5
| @@ -114,13 +114,13 @@ | ||
| 114 | 114 | /** |
| 115 | 115 | * Create a copy of this exception with a nicer stack trace, and including the coordinator |
| 116 | 116 | * address that caused this exception to be raised. |
| 117 | - * <p> | |
| 117 | + * <p/> | |
| 118 | 118 | * This method is mainly intended for internal use by the driver and exists mainly because: |
| 119 | 119 | * <ol> |
| 120 | - * <li>the original exception was decoded from a response frame | |
| 121 | - * and at that time, the coordinator address was not available; and</li> | |
| 122 | - * <li>the newly-created exception will refer to the current thread in its stack trace, | |
| 123 | - * which generally yields a more user-friendly stack trace that the original one.</li> | |
| 120 | + * <li>the original exception was decoded from a response frame | |
| 121 | + * and at that time, the coordinator address was not available; and</li> | |
| 122 | + * <li>the newly-created exception will refer to the current thread in its stack trace, | |
| 123 | + * which generally yields a more user-friendly stack trace that the original one.</li> | |
| 124 | 124 | * </ol> |
| 125 | 125 | * |
| 126 | 126 | * @param address The full address of the host that caused this exception to be thrown. |
modified driver-core/src/main/java/com/datastax/driver/core/exceptions/CoordinatorException.java +1 −2
| @@ -26,12 +26,11 @@ | ||
| 26 | 26 | |
| 27 | 27 | /** |
| 28 | 28 | * The coordinator host that caused this exception to be raised. |
| 29 | - * <p> | |
| 29 | + * <p/> | |
| 30 | 30 | * This is a shortcut for {@link InetSocketAddress#getAddress() getAddress().getAddress()}. |
| 31 | 31 | * |
| 32 | 32 | * @return The coordinator host that caused this exception to be raised; |
| 33 | 33 | * may be {@code null} if the coordinator is not known. |
| 34 | - * | |
| 35 | 34 | */ |
| 36 | 35 | InetAddress getHost(); |
| 37 | 36 |
modified driver-core/src/main/java/com/datastax/driver/core/exceptions/DriverException.java +1 −1
| @@ -40,7 +40,7 @@ | ||
| 40 | 40 | |
| 41 | 41 | /** |
| 42 | 42 | * Copy the exception. |
| 43 | - * <p> | |
| 43 | + * <p/> | |
| 44 | 44 | * This return a new exception, equivalent to the original one, except that |
| 45 | 45 | * because a new object is created in the current thread, the top-most |
| 46 | 46 | * element in the stacktrace of the exception will refer to the current |
modified driver-core/src/main/java/com/datastax/driver/core/exceptions/DriverInternalError.java +1 −1
| @@ -17,7 +17,7 @@ | ||
| 17 | 17 | |
| 18 | 18 | /** |
| 19 | 19 | * An unexpected error happened internally. |
| 20 | - * | |
| 20 | + * <p/> | |
| 21 | 21 | * This should never be raise and indicates a bug (either in the driver or in |
| 22 | 22 | * Cassandra). |
| 23 | 23 | */ |
modified driver-core/src/main/java/com/datastax/driver/core/exceptions/InvalidConfigurationInQueryException.java +1 −2
| @@ -15,13 +15,12 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core.exceptions; |
| 17 | 17 | |
| 18 | -import java.net.InetAddress; | |
| 19 | 18 | import java.net.InetSocketAddress; |
| 20 | 19 | |
| 21 | 20 | /** |
| 22 | 21 | * A specific invalid query exception that indicates that the query is invalid |
| 23 | 22 | * because of some configuration problem. |
| 24 | - * <p> | |
| 23 | + * <p/> | |
| 25 | 24 | * This is generally throw by query that manipulate the schema (CREATE and |
| 26 | 25 | * ALTER) when the required configuration options are invalid. |
| 27 | 26 | */ |
modified driver-core/src/main/java/com/datastax/driver/core/exceptions/NoHostAvailableException.java +8 −9
| @@ -24,13 +24,13 @@ | ||
| 24 | 24 | /** |
| 25 | 25 | * Exception thrown when a query cannot be performed because no host are |
| 26 | 26 | * available. |
| 27 | - * | |
| 27 | + * <p/> | |
| 28 | 28 | * This exception is thrown if |
| 29 | 29 | * <ul> |
| 30 | - * <li>either there is no host live in the cluster at the moment of the query</li> | |
| 31 | - * <li>all host that have been tried have failed due to a connection problem</li> | |
| 30 | + * <li>either there is no host live in the cluster at the moment of the query</li> | |
| 31 | + * <li>all host that have been tried have failed due to a connection problem</li> | |
| 32 | 32 | * </ul> |
| 33 | - * | |
| 33 | + * <p/> | |
| 34 | 34 | * For debugging purpose, the list of hosts that have been tried along with the |
| 35 | 35 | * failure cause can be retrieved using the {@link #errors} method. |
| 36 | 36 | */ |
| @@ -66,9 +66,9 @@ | ||
| 66 | 66 | /** |
| 67 | 67 | * Builds a custom message for this exception. |
| 68 | 68 | * |
| 69 | - * @param maxErrors the maximum number of errors displayed (useful to limit the size of the message for big clusters). Beyond this limit, | |
| 70 | - * host names are still displayed, but not the associated errors. Set to {@code Integer.MAX_VALUE} to display all hosts. | |
| 71 | - * @param formatted whether to format the output (line break between each host). | |
| 69 | + * @param maxErrors the maximum number of errors displayed (useful to limit the size of the message for big clusters). Beyond this limit, | |
| 70 | + * host names are still displayed, but not the associated errors. Set to {@code Integer.MAX_VALUE} to display all hosts. | |
| 71 | + * @param formatted whether to format the output (line break between each host). | |
| 72 | 72 | * @param includeStackTraces whether to include the full stacktrace of each host error. Note that this automatically implies |
| 73 | 73 | * {@code formatted}. |
| 74 | 74 | * @return the message. |
| @@ -96,8 +96,7 @@ | ||
| 96 | 96 | |
| 97 | 97 | int n = 0; |
| 98 | 98 | boolean truncated = false; |
| 99 | - for (Map.Entry<InetSocketAddress, Throwable> entry : errors.entrySet()) | |
| 100 | - { | |
| 99 | + for (Map.Entry<InetSocketAddress, Throwable> entry : errors.entrySet()) { | |
| 101 | 100 | if (n > 0) out.print(formatted ? "\n" : ", "); |
| 102 | 101 | out.print(entry.getKey()); |
| 103 | 102 | if (n < maxErrorsInMessage) { |
modified driver-core/src/main/java/com/datastax/driver/core/exceptions/QueryExecutionException.java +1 −1
| @@ -17,7 +17,7 @@ | ||
| 17 | 17 | |
| 18 | 18 | /** |
| 19 | 19 | * Exception related to the execution of a query. |
| 20 | - * | |
| 20 | + * <p/> | |
| 21 | 21 | * This correspond to the exception that Cassandra throw when a (valid) query |
| 22 | 22 | * cannot be executed (TimeoutException, UnavailableException, ...). |
| 23 | 23 | */ |
modified driver-core/src/main/java/com/datastax/driver/core/exceptions/QueryTimeoutException.java +3 −3
| @@ -15,14 +15,14 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core.exceptions; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.ConsistencyLevel; | |
| 19 | + | |
| 18 | 20 | import java.net.InetAddress; |
| 19 | 21 | import java.net.InetSocketAddress; |
| 20 | 22 | |
| 21 | -import com.datastax.driver.core.ConsistencyLevel; | |
| 22 | - | |
| 23 | 23 | /** |
| 24 | 24 | * A Cassandra timeout during a query. |
| 25 | - * | |
| 25 | + * <p/> | |
| 26 | 26 | * Such an exception is returned when the query has been tried by Cassandra but |
| 27 | 27 | * cannot be achieved with the requested consistency level within the rpc |
| 28 | 28 | * timeout set for Cassandra. |
modified driver-core/src/main/java/com/datastax/driver/core/exceptions/ReadTimeoutException.java +27 −27
| @@ -15,10 +15,10 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core.exceptions; |
| 17 | 17 | |
| 18 | -import java.net.InetSocketAddress; | |
| 19 | - | |
| 20 | 18 | import com.datastax.driver.core.ConsistencyLevel; |
| 21 | 19 | |
| 20 | +import java.net.InetSocketAddress; | |
| 21 | + | |
| 22 | 22 | /** |
| 23 | 23 | * A Cassandra timeout during a read query. |
| 24 | 24 | */ |
| @@ -38,11 +38,11 @@ | ||
| 38 | 38 | |
| 39 | 39 | public ReadTimeoutException(InetSocketAddress address, ConsistencyLevel consistency, int received, int required, boolean dataPresent) { |
| 40 | 40 | super( |
| 41 | - address, | |
| 42 | - String.format("Cassandra timeout during read query at consistency %s (%s)", consistency, formatDetails(received, required, dataPresent)), | |
| 43 | - consistency, | |
| 44 | - received, | |
| 45 | - required | |
| 41 | + address, | |
| 42 | + String.format("Cassandra timeout during read query at consistency %s (%s)", consistency, formatDetails(received, required, dataPresent)), | |
| 43 | + consistency, | |
| 44 | + received, | |
| 45 | + required | |
| 46 | 46 | ); |
| 47 | 47 | this.dataPresent = dataPresent; |
| 48 | 48 | } |
| @@ -63,7 +63,7 @@ | ||
| 63 | 63 | |
| 64 | 64 | /** |
| 65 | 65 | * Whether the actual data was amongst the received replica responses. |
| 66 | - * | |
| 66 | + * <p/> | |
| 67 | 67 | * During reads, Cassandra doesn't request data from every replica to |
| 68 | 68 | * minimize internal network traffic. Instead, some replica are only asked |
| 69 | 69 | * for a checksum of the data. A read timeout may occurred even if enough |
| @@ -80,26 +80,26 @@ | ||
| 80 | 80 | @Override |
| 81 | 81 | public DriverException copy() { |
| 82 | 82 | return new ReadTimeoutException( |
| 83 | - getAddress(), | |
| 84 | - getMessage(), | |
| 85 | - this, | |
| 86 | - getConsistencyLevel(), | |
| 87 | - getReceivedAcknowledgements(), | |
| 88 | - getRequiredAcknowledgements(), | |
| 89 | - wasDataRetrieved() | |
| 83 | + getAddress(), | |
| 84 | + getMessage(), | |
| 85 | + this, | |
| 86 | + getConsistencyLevel(), | |
| 87 | + getReceivedAcknowledgements(), | |
| 88 | + getRequiredAcknowledgements(), | |
| 89 | + wasDataRetrieved() | |
| 90 | 90 | ); |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | /** |
| 94 | 94 | * Create a copy of this exception with a nicer stack trace, and including the coordinator |
| 95 | 95 | * address that caused this exception to be raised. |
| 96 | - * <p> | |
| 96 | + * <p/> | |
| 97 | 97 | * This method is mainly intended for internal use by the driver and exists mainly because: |
| 98 | 98 | * <ol> |
| 99 | - * <li>the original exception was decoded from a response frame | |
| 100 | - * and at that time, the coordinator address was not available; and</li> | |
| 101 | - * <li>the newly-created exception will refer to the current thread in its stack trace, | |
| 102 | - * which generally yields a more user-friendly stack trace that the original one.</li> | |
| 99 | + * <li>the original exception was decoded from a response frame | |
| 100 | + * and at that time, the coordinator address was not available; and</li> | |
| 101 | + * <li>the newly-created exception will refer to the current thread in its stack trace, | |
| 102 | + * which generally yields a more user-friendly stack trace that the original one.</li> | |
| 103 | 103 | * </ol> |
| 104 | 104 | * |
| 105 | 105 | * @param address The full address of the host that caused this exception to be thrown. |
| @@ -107,13 +107,13 @@ | ||
| 107 | 107 | */ |
| 108 | 108 | public ReadTimeoutException copy(InetSocketAddress address) { |
| 109 | 109 | return new ReadTimeoutException( |
| 110 | - address, | |
| 111 | - getMessage(), | |
| 112 | - this, | |
| 113 | - getConsistencyLevel(), | |
| 114 | - getReceivedAcknowledgements(), | |
| 115 | - getRequiredAcknowledgements(), | |
| 116 | - wasDataRetrieved() | |
| 110 | + address, | |
| 111 | + getMessage(), | |
| 112 | + this, | |
| 113 | + getConsistencyLevel(), | |
| 114 | + getReceivedAcknowledgements(), | |
| 115 | + getRequiredAcknowledgements(), | |
| 116 | + wasDataRetrieved() | |
| 117 | 117 | ); |
| 118 | 118 | } |
| 119 | 119 |
modified driver-core/src/main/java/com/datastax/driver/core/exceptions/UnavailableException.java +7 −7
| @@ -15,11 +15,11 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core.exceptions; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.ConsistencyLevel; | |
| 19 | + | |
| 18 | 20 | import java.net.InetAddress; |
| 19 | 21 | import java.net.InetSocketAddress; |
| 20 | 22 | |
| 21 | -import com.datastax.driver.core.ConsistencyLevel; | |
| 22 | - | |
| 23 | 23 | /** |
| 24 | 24 | * Exception thrown when the coordinator knows there is not enough replica |
| 25 | 25 | * alive to perform a query with the requested consistency level. |
| @@ -112,13 +112,13 @@ | ||
| 112 | 112 | /** |
| 113 | 113 | * Create a copy of this exception with a nicer stack trace, and including the coordinator |
| 114 | 114 | * address that caused this exception to be raised. |
| 115 | - * <p> | |
| 115 | + * <p/> | |
| 116 | 116 | * This method is mainly intended for internal use by the driver and exists mainly because: |
| 117 | 117 | * <ol> |
| 118 | - * <li>the original exception was decoded from a response frame | |
| 119 | - * and at that time, the coordinator address was not available; and</li> | |
| 120 | - * <li>the newly-created exception will refer to the current thread in its stack trace, | |
| 121 | - * which generally yields a more user-friendly stack trace that the original one.</li> | |
| 118 | + * <li>the original exception was decoded from a response frame | |
| 119 | + * and at that time, the coordinator address was not available; and</li> | |
| 120 | + * <li>the newly-created exception will refer to the current thread in its stack trace, | |
| 121 | + * which generally yields a more user-friendly stack trace that the original one.</li> | |
| 122 | 122 | * </ol> |
| 123 | 123 | * |
| 124 | 124 | * @param address The full address of the host that caused this exception to be thrown. |
modified driver-core/src/main/java/com/datastax/driver/core/exceptions/WriteTimeoutException.java +26 −26
| @@ -15,11 +15,11 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core.exceptions; |
| 17 | 17 | |
| 18 | -import java.net.InetSocketAddress; | |
| 19 | - | |
| 20 | 18 | import com.datastax.driver.core.ConsistencyLevel; |
| 21 | 19 | import com.datastax.driver.core.WriteType; |
| 22 | 20 | |
| 21 | +import java.net.InetSocketAddress; | |
| 22 | + | |
| 23 | 23 | /** |
| 24 | 24 | * A Cassandra timeout during a write query. |
| 25 | 25 | */ |
| @@ -39,11 +39,11 @@ | ||
| 39 | 39 | |
| 40 | 40 | public WriteTimeoutException(InetSocketAddress address, ConsistencyLevel consistency, WriteType writeType, int received, int required) { |
| 41 | 41 | super( |
| 42 | - address, | |
| 43 | - String.format("Cassandra timeout during write query at consistency %s (%d replica were required but only %d acknowledged the write)", consistency, required, received), | |
| 44 | - consistency, | |
| 45 | - received, | |
| 46 | - required); | |
| 42 | + address, | |
| 43 | + String.format("Cassandra timeout during write query at consistency %s (%d replica were required but only %d acknowledged the write)", consistency, required, received), | |
| 44 | + consistency, | |
| 45 | + received, | |
| 46 | + required); | |
| 47 | 47 | this.writeType = writeType; |
| 48 | 48 | } |
| 49 | 49 | |
| @@ -64,26 +64,26 @@ | ||
| 64 | 64 | @Override |
| 65 | 65 | public DriverException copy() { |
| 66 | 66 | return new WriteTimeoutException( |
| 67 | - getAddress(), | |
| 68 | - getMessage(), | |
| 69 | - this, | |
| 70 | - getConsistencyLevel(), | |
| 71 | - getWriteType(), | |
| 72 | - getReceivedAcknowledgements(), | |
| 73 | - getRequiredAcknowledgements() | |
| 67 | + getAddress(), | |
| 68 | + getMessage(), | |
| 69 | + this, | |
| 70 | + getConsistencyLevel(), | |
| 71 | + getWriteType(), | |
| 72 | + getReceivedAcknowledgements(), | |
| 73 | + getRequiredAcknowledgements() | |
| 74 | 74 | ); |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | /** |
| 78 | 78 | * Create a copy of this exception with a nicer stack trace, and including the coordinator |
| 79 | 79 | * address that caused this exception to be raised. |
| 80 | - * <p> | |
| 80 | + * <p/> | |
| 81 | 81 | * This method is mainly intended for internal use by the driver and exists mainly because: |
| 82 | 82 | * <ol> |
| 83 | - * <li>the original exception was decoded from a response frame | |
| 84 | - * and at that time, the coordinator address was not available; and</li> | |
| 85 | - * <li>the newly-created exception will refer to the current thread in its stack trace, | |
| 86 | - * which generally yields a more user-friendly stack trace that the original one.</li> | |
| 83 | + * <li>the original exception was decoded from a response frame | |
| 84 | + * and at that time, the coordinator address was not available; and</li> | |
| 85 | + * <li>the newly-created exception will refer to the current thread in its stack trace, | |
| 86 | + * which generally yields a more user-friendly stack trace that the original one.</li> | |
| 87 | 87 | * </ol> |
| 88 | 88 | * |
| 89 | 89 | * @param address The full address of the host that caused this exception to be thrown. |
| @@ -91,13 +91,13 @@ | ||
| 91 | 91 | */ |
| 92 | 92 | public WriteTimeoutException copy(InetSocketAddress address) { |
| 93 | 93 | return new WriteTimeoutException( |
| 94 | - address, | |
| 95 | - getMessage(), | |
| 96 | - this, | |
| 97 | - getConsistencyLevel(), | |
| 98 | - getWriteType(), | |
| 99 | - getReceivedAcknowledgements(), | |
| 100 | - getRequiredAcknowledgements() | |
| 94 | + address, | |
| 95 | + getMessage(), | |
| 96 | + this, | |
| 97 | + getConsistencyLevel(), | |
| 98 | + getWriteType(), | |
| 99 | + getReceivedAcknowledgements(), | |
| 100 | + getRequiredAcknowledgements() | |
| 101 | 101 | ); |
| 102 | 102 | } |
| 103 | 103 |
modified driver-core/src/main/java/com/datastax/driver/core/package-info.java +1 −1
| @@ -15,7 +15,7 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | /** |
| 17 | 17 | * The main package for the DataStax Java driver for Cassandra. |
| 18 | - * <p> | |
| 18 | + * <p/> | |
| 19 | 19 | * The main entry for this package is the {@link com.datastax.driver.core.Cluster} class. |
| 20 | 20 | */ |
| 21 | 21 | package com.datastax.driver.core; |
modified driver-core/src/main/java/com/datastax/driver/core/policies/AddressTranslater.java +8 −8
| @@ -15,14 +15,14 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core.policies; |
| 17 | 17 | |
| 18 | -import java.net.InetSocketAddress; | |
| 19 | - | |
| 20 | 18 | import com.datastax.driver.core.Cluster; |
| 21 | 19 | |
| 20 | +import java.net.InetSocketAddress; | |
| 21 | + | |
| 22 | 22 | /** |
| 23 | 23 | * Translates IP addresses received from Cassandra nodes into locally queriable |
| 24 | 24 | * addresses. |
| 25 | - * <p> | |
| 25 | + * <p/> | |
| 26 | 26 | * The driver auto-detect new Cassandra nodes added to the cluster through server |
| 27 | 27 | * side pushed notifications and through checking the system tables. For each |
| 28 | 28 | * node, the address the driver will receive will correspond to the address set as |
| @@ -35,7 +35,7 @@ | ||
| 35 | 35 | * pass by a router to reach that node). This interface allows to deal with |
| 36 | 36 | * such cases, by allowing to translate an address as sent by a Cassandra node |
| 37 | 37 | * to another address to be used by the driver for connection. |
| 38 | - * <p> | |
| 38 | + * <p/> | |
| 39 | 39 | * Please note that the contact points addresses provided while creating the |
| 40 | 40 | * {@link Cluster} instance are not "tanslated", only IP address retrieve from or sent |
| 41 | 41 | * by Cassandra nodes to the driver are. |
| @@ -46,10 +46,10 @@ | ||
| 46 | 46 | * Translates a Cassandra {@code rpc_address} to another address if necessary. |
| 47 | 47 | * |
| 48 | 48 | * @param address the address of a node as returned by Cassandra. Note that |
| 49 | - * if the {@code rpc_address} of a node has been configured to {@code 0.0.0.0} | |
| 50 | - * server side, then the provided address will be the node {@code listen_address}, | |
| 51 | - * *not* {@code 0.0.0.0}. Also note that the port for {@code InetSocketAddress} | |
| 52 | - * will always be the one set at Cluster construction time (9042 by default). | |
| 49 | + * if the {@code rpc_address} of a node has been configured to {@code 0.0.0.0} | |
| 50 | + * server side, then the provided address will be the node {@code listen_address}, | |
| 51 | + * *not* {@code 0.0.0.0}. Also note that the port for {@code InetSocketAddress} | |
| 52 | + * will always be the one set at Cluster construction time (9042 by default). | |
| 53 | 53 | * @return the address the driver should actually use to connect to the node |
| 54 | 54 | * designated by {@code address}. If the return is {@code null}, then {@code |
| 55 | 55 | * address} will be used by the driver (it is thus equivalent to returing |
modified driver-core/src/main/java/com/datastax/driver/core/policies/CloseableAddressTranslater.java +1 −1
| @@ -20,7 +20,7 @@ | ||
| 20 | 20 | /** |
| 21 | 21 | * Extends {@link AddressTranslater} for implementations that need to free some resources |
| 22 | 22 | * at {@link Cluster} shutdown. |
| 23 | - * <p> | |
| 23 | + * <p/> | |
| 24 | 24 | * Note: the only reason {@link #close()} was not added directly to {@code AddressTranslater} |
| 25 | 25 | * is backward-compatibility. |
| 26 | 26 | */ |
modified driver-core/src/main/java/com/datastax/driver/core/policies/CloseableLoadBalancingPolicy.java +2 −2
| @@ -17,14 +17,14 @@ | ||
| 17 | 17 | |
| 18 | 18 | /** |
| 19 | 19 | * A load balancing policy that wants to be notified at cluster shutdown. |
| 20 | - * | |
| 20 | + * <p/> | |
| 21 | 21 | * The only reason that this is separate from {@link LoadBalancingPolicy} is to avoid breaking binary compatibility at the |
| 22 | 22 | * time this was introduced (2.0.7 / 2.1.3). It might be merged with the parent interface in a future major version. |
| 23 | 23 | */ |
| 24 | 24 | public interface CloseableLoadBalancingPolicy extends LoadBalancingPolicy { |
| 25 | 25 | /** |
| 26 | 26 | * Gets invoked at cluster shutdown. |
| 27 | - * | |
| 27 | + * <p/> | |
| 28 | 28 | * This gives the policy the opportunity to perform some cleanup, for instance stop threads that it might have started. |
| 29 | 29 | */ |
| 30 | 30 | void close(); |
modified driver-core/src/main/java/com/datastax/driver/core/policies/ConstantSpeculativeExecutionPolicy.java +6 −8
| @@ -15,13 +15,12 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core.policies; |
| 17 | 17 | |
| 18 | -import java.util.concurrent.atomic.AtomicInteger; | |
| 19 | - | |
| 20 | -import com.google.common.base.Preconditions; | |
| 21 | - | |
| 22 | 18 | import com.datastax.driver.core.Cluster; |
| 23 | 19 | import com.datastax.driver.core.Host; |
| 24 | 20 | import com.datastax.driver.core.Statement; |
| 21 | +import com.google.common.base.Preconditions; | |
| 22 | + | |
| 23 | +import java.util.concurrent.atomic.AtomicInteger; | |
| 25 | 24 | |
| 26 | 25 | /** |
| 27 | 26 | * A {@link SpeculativeExecutionPolicy} that schedules a given number of speculative executions, separated by a fixed delay. |
| @@ -33,16 +32,15 @@ | ||
| 33 | 32 | /** |
| 34 | 33 | * Builds a new instance. |
| 35 | 34 | * |
| 36 | - * @param constantDelayMillis the delay between each speculative execution. Must be strictly positive. | |
| 35 | + * @param constantDelayMillis the delay between each speculative execution. Must be strictly positive. | |
| 37 | 36 | * @param maxSpeculativeExecutions the number of speculative executions. Must be strictly positive. |
| 38 | - * | |
| 39 | 37 | * @throws IllegalArgumentException if one of the arguments does not respect the preconditions above. |
| 40 | 38 | */ |
| 41 | 39 | public ConstantSpeculativeExecutionPolicy(final long constantDelayMillis, final int maxSpeculativeExecutions) { |
| 42 | 40 | Preconditions.checkArgument(constantDelayMillis > 0, |
| 43 | - "delay must be strictly positive (was %d)", constantDelayMillis); | |
| 41 | + "delay must be strictly positive (was %d)", constantDelayMillis); | |
| 44 | 42 | Preconditions.checkArgument(maxSpeculativeExecutions > 0, |
| 45 | - "number of speculative executions must be strictly positive (was %d)", maxSpeculativeExecutions); | |
| 43 | + "number of speculative executions must be strictly positive (was %d)", maxSpeculativeExecutions); | |
| 46 | 44 | this.constantDelayMillis = constantDelayMillis; |
| 47 | 45 | this.maxSpeculativeExecutions = maxSpeculativeExecutions; |
| 48 | 46 | } |
modified driver-core/src/main/java/com/datastax/driver/core/policies/DCAwareRoundRobinPolicy.java +29 −33
| @@ -15,35 +15,31 @@ | ||
| 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.ConcurrentMap; | |
| 21 | -import java.util.concurrent.CopyOnWriteArrayList; | |
| 22 | -import java.util.concurrent.atomic.AtomicInteger; | |
| 23 | - | |
| 18 | +import com.datastax.driver.core.*; | |
| 24 | 19 | import com.google.common.annotations.VisibleForTesting; |
| 25 | -import com.google.common.base.*; | |
| 20 | +import com.google.common.base.Joiner; | |
| 21 | +import com.google.common.base.Preconditions; | |
| 22 | +import com.google.common.base.Strings; | |
| 26 | 23 | import com.google.common.collect.AbstractIterator; |
| 27 | 24 | import org.slf4j.Logger; |
| 28 | 25 | import org.slf4j.LoggerFactory; |
| 29 | 26 | |
| 30 | -import com.datastax.driver.core.Cluster; | |
| 31 | -import com.datastax.driver.core.Configuration; | |
| 32 | -import com.datastax.driver.core.ConsistencyLevel; | |
| 33 | -import com.datastax.driver.core.Host; | |
| 34 | -import com.datastax.driver.core.HostDistance; | |
| 35 | -import com.datastax.driver.core.Statement; | |
| 27 | +import java.util.*; | |
| 28 | +import java.util.concurrent.ConcurrentHashMap; | |
| 29 | +import java.util.concurrent.ConcurrentMap; | |
| 30 | +import java.util.concurrent.CopyOnWriteArrayList; | |
| 31 | +import java.util.concurrent.atomic.AtomicInteger; | |
| 36 | 32 | |
| 37 | 33 | /** |
| 38 | 34 | * A data-center aware Round-robin load balancing policy. |
| 39 | - * <p> | |
| 35 | + * <p/> | |
| 40 | 36 | * This policy provides round-robin queries over the node of the local |
| 41 | 37 | * data center. It also includes in the query plans returned a configurable |
| 42 | 38 | * number of hosts in the remote data centers, but those are always tried |
| 43 | 39 | * after the local nodes. In other words, this policy guarantees that no |
| 44 | 40 | * host in a remote data center will be queried unless no host in the local |
| 45 | 41 | * data center can be reached. |
| 46 | - * <p> | |
| 42 | + * <p/> | |
| 47 | 43 | * If used with a single data center, this policy is equivalent to the |
| 48 | 44 | * {@link RoundRobinPolicy}, but its DC awareness incurs a slight overhead |
| 49 | 45 | * so the latter should be preferred to this policy in that case. |
| @@ -160,16 +156,16 @@ | ||
| 160 | 156 | |
| 161 | 157 | @SuppressWarnings("unchecked") |
| 162 | 158 | private static CopyOnWriteArrayList<Host> cloneList(CopyOnWriteArrayList<Host> list) { |
| 163 | - return (CopyOnWriteArrayList<Host>)list.clone(); | |
| 159 | + return (CopyOnWriteArrayList<Host>) list.clone(); | |
| 164 | 160 | } |
| 165 | 161 | |
| 166 | 162 | /** |
| 167 | 163 | * Return the HostDistance for the provided host. |
| 168 | - * <p> | |
| 164 | + * <p/> | |
| 169 | 165 | * This policy consider nodes in the local datacenter as {@code LOCAL}. |
| 170 | 166 | * For each remote datacenter, it considers a configurable number of |
| 171 | 167 | * hosts as {@code REMOTE} and the rest is {@code IGNORED}. |
| 172 | - * <p> | |
| 168 | + * <p/> | |
| 173 | 169 | * To configure how many host in each remote datacenter is considered |
| 174 | 170 | * {@code REMOTE}, see {@link #DCAwareRoundRobinPolicy(String, int)}. |
| 175 | 171 | * |
| @@ -189,13 +185,13 @@ | ||
| 189 | 185 | // We need to clone, otherwise our subList call is not thread safe |
| 190 | 186 | dcHosts = cloneList(dcHosts); |
| 191 | 187 | return dcHosts.subList(0, Math.min(dcHosts.size(), usedHostsPerRemoteDc)).contains(host) |
| 192 | - ? HostDistance.REMOTE | |
| 193 | - : HostDistance.IGNORED; | |
| 188 | + ? HostDistance.REMOTE | |
| 189 | + : HostDistance.IGNORED; | |
| 194 | 190 | } |
| 195 | 191 | |
| 196 | 192 | /** |
| 197 | 193 | * Returns the hosts to use for a new query. |
| 198 | - * <p> | |
| 194 | + * <p/> | |
| 199 | 195 | * The returned plan will always try each known host in the local |
| 200 | 196 | * datacenter first, and then, if none of the local host is reachable, |
| 201 | 197 | * will try up to a configurable number of other host per remote datacenter. |
| @@ -203,8 +199,8 @@ | ||
| 203 | 199 | * Round-robin algorithm. |
| 204 | 200 | * |
| 205 | 201 | * @param loggedKeyspace the keyspace currently logged in on for this |
| 206 | - * query. | |
| 207 | - * @param statement the query for which to build the plan. | |
| 202 | + * query. | |
| 203 | + * @param statement the query for which to build the plan. | |
| 208 | 204 | * @return a new query plan, i.e. an iterator indicating which host to |
| 209 | 205 | * try first for querying, which one to use as failover, etc... |
| 210 | 206 | */ |
| @@ -247,8 +243,8 @@ | ||
| 247 | 243 | } |
| 248 | 244 | |
| 249 | 245 | ConsistencyLevel cl = statement.getConsistencyLevel() == null |
| 250 | - ? configuration.getQueryOptions().getConsistencyLevel() | |
| 251 | - : statement.getConsistencyLevel(); | |
| 246 | + ? configuration.getQueryOptions().getConsistencyLevel() | |
| 247 | + : statement.getConsistencyLevel(); | |
| 252 | 248 | |
| 253 | 249 | if (dontHopForLocalCL && cl.isDCLocal()) |
| 254 | 250 | return endOfData(); |
| @@ -333,10 +329,10 @@ | ||
| 333 | 329 | |
| 334 | 330 | /** |
| 335 | 331 | * Sets the name of the datacenter that will be considered "local" by the policy. |
| 336 | - * <p> | |
| 332 | + * <p/> | |
| 337 | 333 | * This must be the name as known by Cassandra (in other words, the name in that appears in |
| 338 | 334 | * {@code system.peers}, or in the output of admin tools like nodetool). |
| 339 | - * <p> | |
| 335 | + * <p/> | |
| 340 | 336 | * If this method isn't called, the policy will default to the datacenter of the first node |
| 341 | 337 | * connected to. This will always be ok if all the contact points use at {@code Cluster} |
| 342 | 338 | * creation are in the local data-center. Otherwise, you should provide the name yourself |
| @@ -347,24 +343,24 @@ | ||
| 347 | 343 | */ |
| 348 | 344 | public Builder withLocalDc(String localDc) { |
| 349 | 345 | Preconditions.checkArgument(!Strings.isNullOrEmpty(localDc), |
| 350 | - "localDc name can't be null or empty. If you want to let the policy autodetect the datacenter, don't call Builder.withLocalDC"); | |
| 346 | + "localDc name can't be null or empty. If you want to let the policy autodetect the datacenter, don't call Builder.withLocalDC"); | |
| 351 | 347 | this.localDc = localDc; |
| 352 | 348 | return this; |
| 353 | 349 | } |
| 354 | 350 | |
| 355 | 351 | /** |
| 356 | 352 | * Sets the number of hosts per remote datacenter that the policy should consider. |
| 357 | - * <p> | |
| 353 | + * <p/> | |
| 358 | 354 | * The policy's {@code distance()} method will return a {@code HostDistance.REMOTE} distance for only {@code usedHostsPerRemoteDc} |
| 359 | 355 | * hosts per remote datacenter. Other hosts of the remote datacenters will be ignored (and thus no connections to them will be |
| 360 | 356 | * maintained). |
| 361 | - * <p> | |
| 357 | + * <p/> | |
| 362 | 358 | * If {@code usedHostsPerRemoteDc > 0}, then if for a query no host in the local datacenter can be reached and if the consistency |
| 363 | 359 | * level of the query is not {@code LOCAL_ONE} or {@code LOCAL_QUORUM}, then up to {@code usedHostsPerRemoteDc} hosts per remote |
| 364 | 360 | * datacenter will be tried by the policy as a fallback. By default, no remote host will be used for {@code LOCAL_ONE} and |
| 365 | 361 | * {@code LOCAL_QUORUM}, since this would change the meaning of the consistency level, somewhat breaking the consistency contract |
| 366 | 362 | * (this can be overridden with {@link #allowRemoteDCsForLocalConsistencyLevel()}). |
| 367 | - * <p> | |
| 363 | + * <p/> | |
| 368 | 364 | * If this method isn't called, the policy will default to 0. |
| 369 | 365 | * |
| 370 | 366 | * @param usedHostsPerRemoteDc the number. |
| @@ -372,7 +368,7 @@ | ||
| 372 | 368 | */ |
| 373 | 369 | public Builder withUsedHostsPerRemoteDc(int usedHostsPerRemoteDc) { |
| 374 | 370 | Preconditions.checkArgument(usedHostsPerRemoteDc >= 0, |
| 375 | - "usedHostsPerRemoteDc must be equal or greater than 0"); | |
| 371 | + "usedHostsPerRemoteDc must be equal or greater than 0"); | |
| 376 | 372 | this.usedHostsPerRemoteDc = usedHostsPerRemoteDc; |
| 377 | 373 | return this; |
| 378 | 374 | } |
| @@ -380,7 +376,7 @@ | ||
| 380 | 376 | /** |
| 381 | 377 | * Allows the policy to return remote hosts when building query plans for queries having consistency level {@code LOCAL_ONE} |
| 382 | 378 | * or {@code LOCAL_QUORUM}. |
| 383 | - * <p> | |
| 379 | + * <p/> | |
| 384 | 380 | * When used in conjunction with {@link #withUsedHostsPerRemoteDc(int) usedHostsPerRemoteDc} > 0, this overrides the policy of |
| 385 | 381 | * never using remote datacenter nodes for {@code LOCAL_ONE} and {@code LOCAL_QUORUM} queries. It is however inadvisable to do |
| 386 | 382 | * so in almost all cases, as this would potentially break consistency guarantees and if you are fine with that, it's probably |
modified driver-core/src/main/java/com/datastax/driver/core/policies/DefaultRetryPolicy.java +32 −31
| @@ -21,16 +21,16 @@ | ||
| 21 | 21 | |
| 22 | 22 | /** |
| 23 | 23 | * The default retry policy. |
| 24 | - * <p> | |
| 24 | + * <p/> | |
| 25 | 25 | * This policy retries queries in only two cases: |
| 26 | 26 | * <ul> |
| 27 | - * <li>On a read timeout, if enough replicas replied but data was not retrieved.</li> | |
| 28 | - * <li>On a write timeout, if we timeout while writing the distributed log used by batch statements.</li> | |
| 27 | + * <li>On a read timeout, if enough replicas replied but data was not retrieved.</li> | |
| 28 | + * <li>On a write timeout, if we timeout while writing the distributed log used by batch statements.</li> | |
| 29 | 29 | * </ul> |
| 30 | - * <p> | |
| 30 | + * <p/> | |
| 31 | 31 | * This retry policy is conservative in that it will never retry with a |
| 32 | 32 | * different consistency level than the one of the initial operation. |
| 33 | - * <p> | |
| 33 | + * <p/> | |
| 34 | 34 | * In some cases, it may be convenient to use a more aggressive retry policy |
| 35 | 35 | * like {@link DowngradingConsistencyRetryPolicy}. |
| 36 | 36 | */ |
| @@ -38,11 +38,12 @@ | ||
| 38 | 38 | |
| 39 | 39 | public static final DefaultRetryPolicy INSTANCE = new DefaultRetryPolicy(); |
| 40 | 40 | |
| 41 | - private DefaultRetryPolicy() {} | |
| 41 | + private DefaultRetryPolicy() { | |
| 42 | + } | |
| 42 | 43 | |
| 43 | 44 | /** |
| 44 | 45 | * Defines whether to retry and at which consistency level on a read timeout. |
| 45 | - * <p> | |
| 46 | + * <p/> | |
| 46 | 47 | * This method triggers a maximum of one retry, and only if enough |
| 47 | 48 | * replicas had responded to the read request but data was not retrieved |
| 48 | 49 | * amongst those. Indeed, that case usually means that enough replica |
| @@ -52,15 +53,15 @@ | ||
| 52 | 53 | * timeout the dead replica will likely have been detected as dead and |
| 53 | 54 | * the retry has a high chance of success. |
| 54 | 55 | * |
| 55 | - * @param statement the original query that timed out. | |
| 56 | - * @param cl the original consistency level of the read that timed out. | |
| 56 | + * @param statement the original query that timed out. | |
| 57 | + * @param cl the original consistency level of the read that timed out. | |
| 57 | 58 | * @param requiredResponses the number of responses that were required to |
| 58 | - * achieve the requested consistency level. | |
| 59 | + * achieve the requested consistency level. | |
| 59 | 60 | * @param receivedResponses the number of responses that had been received |
| 60 | - * by the time the timeout exception was raised. | |
| 61 | - * @param dataRetrieved whether actual data (by opposition to data checksum) | |
| 62 | - * was present in the received responses. | |
| 63 | - * @param nbRetry the number of retries already performed for this operation. | |
| 61 | + * by the time the timeout exception was raised. | |
| 62 | + * @param dataRetrieved whether actual data (by opposition to data checksum) | |
| 63 | + * was present in the received responses. | |
| 64 | + * @param nbRetry the number of retries already performed for this operation. | |
| 64 | 65 | * @return {@code RetryDecision.retry(cl)} if no retry attempt has yet been tried and |
| 65 | 66 | * {@code receivedResponses >= requiredResponses && !dataRetrieved}, {@code RetryDecision.rethrow()} otherwise. |
| 66 | 67 | */ |
| @@ -74,7 +75,7 @@ | ||
| 74 | 75 | |
| 75 | 76 | /** |
| 76 | 77 | * Defines whether to retry and at which consistency level on a write timeout. |
| 77 | - * <p> | |
| 78 | + * <p/> | |
| 78 | 79 | * This method triggers a maximum of one retry, and only in the case of |
| 79 | 80 | * a {@code WriteType.BATCH_LOG} write. The reasoning for the retry in |
| 80 | 81 | * that case is that write to the distributed batch log is tried by the |
| @@ -85,14 +86,14 @@ | ||
| 85 | 86 | * nodes will likely have been detected as dead and the retry has thus a |
| 86 | 87 | * high chance of success. |
| 87 | 88 | * |
| 88 | - * @param statement the original query that timed out. | |
| 89 | - * @param cl the original consistency level of the write that timed out. | |
| 90 | - * @param writeType the type of the write that timed out. | |
| 89 | + * @param statement the original query that timed out. | |
| 90 | + * @param cl the original consistency level of the write that timed out. | |
| 91 | + * @param writeType the type of the write that timed out. | |
| 91 | 92 | * @param requiredAcks the number of acknowledgments that were required to |
| 92 | - * achieve the requested consistency level. | |
| 93 | + * achieve the requested consistency level. | |
| 93 | 94 | * @param receivedAcks the number of acknowledgments that had been received |
| 94 | - * by the time the timeout exception was raised. | |
| 95 | - * @param nbRetry the number of retry already performed for this operation. | |
| 95 | + * by the time the timeout exception was raised. | |
| 96 | + * @param nbRetry the number of retry already performed for this operation. | |
| 96 | 97 | * @return {@code RetryDecision.retry(cl)} if no retry attempt has yet been tried and |
| 97 | 98 | * {@code writeType == WriteType.BATCH_LOG}, {@code RetryDecision.rethrow()} otherwise. |
| 98 | 99 | */ |
| @@ -108,7 +109,7 @@ | ||
| 108 | 109 | /** |
| 109 | 110 | * Defines whether to retry and at which consistency level on an |
| 110 | 111 | * unavailable exception. |
| 111 | - * <p> | |
| 112 | + * <p/> | |
| 112 | 113 | * This method triggers a retry iff no retry has been executed before |
| 113 | 114 | * (nbRetry == 0), with |
| 114 | 115 | * {@link RetryPolicy.RetryDecision#tryNextHost(ConsistencyLevel) RetryDecision.tryNextHost(cl)}, |
| @@ -119,20 +120,20 @@ | ||
| 119 | 120 | * be "network" isolated from all the other nodes but can still answer to |
| 120 | 121 | * the client, it makes sense to retry the query on another node. |
| 121 | 122 | * |
| 122 | - * @param statement the original query for which the consistency level cannot | |
| 123 | - * be achieved. | |
| 124 | - * @param cl the original consistency level for the operation. | |
| 123 | + * @param statement the original query for which the consistency level cannot | |
| 124 | + * be achieved. | |
| 125 | + * @param cl the original consistency level for the operation. | |
| 125 | 126 | * @param requiredReplica the number of replica that should have been |
| 126 | - * (known) alive for the operation to be attempted. | |
| 127 | - * @param aliveReplica the number of replica that were know to be alive by | |
| 128 | - * the coordinator of the operation. | |
| 129 | - * @param nbRetry the number of retry already performed for this operation. | |
| 127 | + * (known) alive for the operation to be attempted. | |
| 128 | + * @param aliveReplica the number of replica that were know to be alive by | |
| 129 | + * the coordinator of the operation. | |
| 130 | + * @param nbRetry the number of retry already performed for this operation. | |
| 130 | 131 | * @return {@code RetryDecision.rethrow()}. |
| 131 | 132 | */ |
| 132 | 133 | @Override |
| 133 | 134 | public RetryDecision onUnavailable(Statement statement, ConsistencyLevel cl, int requiredReplica, int aliveReplica, int nbRetry) { |
| 134 | 135 | return (nbRetry == 0) |
| 135 | - ? RetryDecision.tryNextHost(cl) | |
| 136 | - : RetryDecision.rethrow(); | |
| 136 | + ? RetryDecision.tryNextHost(cl) | |
| 137 | + : RetryDecision.rethrow(); | |
| 137 | 138 | } |
| 138 | 139 | } |
modified driver-core/src/main/java/com/datastax/driver/core/policies/DowngradingConsistencyRetryPolicy.java +44 −43
| @@ -22,7 +22,7 @@ | ||
| 22 | 22 | /** |
| 23 | 23 | * A retry policy that sometimes retry with a lower consistency level than |
| 24 | 24 | * the one initially requested. |
| 25 | - * <p> | |
| 25 | + * <p/> | |
| 26 | 26 | * <b>BEWARE</b>: This policy may retry queries using a lower consistency |
| 27 | 27 | * level than the one initially requested. By doing so, it may break |
| 28 | 28 | * consistency guarantees. In other words, if you use this retry policy, |
| @@ -32,34 +32,34 @@ | ||
| 32 | 32 | * are ok with that. It is also highly recommended to always wrap this |
| 33 | 33 | * policy into {@link LoggingRetryPolicy} to log the occurrences of |
| 34 | 34 | * such consistency break. |
| 35 | - * <p> | |
| 35 | + * <p/> | |
| 36 | 36 | * This policy implements the same retries than the {@link DefaultRetryPolicy} |
| 37 | 37 | * policy. But on top of that, it also retries in the following cases: |
| 38 | 38 | * <ul> |
| 39 | - * <li>On a read timeout: if the number of replica that responded is | |
| 40 | - * greater than one but lower than is required by the requested | |
| 41 | - * consistency level, the operation is retried at a lower consistency | |
| 42 | - * level.</li> | |
| 43 | - * <li>On a write timeout: if the operation is an {@code | |
| 44 | - * WriteType.UNLOGGED_BATCH} and at least one replica acknowledged the | |
| 45 | - * write, the operation is retried at a lower consistency level. | |
| 46 | - * Furthermore, for other operation, if at least one replica acknowledged | |
| 47 | - * the write, the timeout is ignored.</li> | |
| 48 | - * <li>On an unavailable exception: if at least one replica is alive, the | |
| 49 | - * operation is retried at a lower consistency level.</li> | |
| 39 | + * <li>On a read timeout: if the number of replica that responded is | |
| 40 | + * greater than one but lower than is required by the requested | |
| 41 | + * consistency level, the operation is retried at a lower consistency | |
| 42 | + * level.</li> | |
| 43 | + * <li>On a write timeout: if the operation is an {@code | |
| 44 | + * WriteType.UNLOGGED_BATCH} and at least one replica acknowledged the | |
| 45 | + * write, the operation is retried at a lower consistency level. | |
| 46 | + * Furthermore, for other operation, if at least one replica acknowledged | |
| 47 | + * the write, the timeout is ignored.</li> | |
| 48 | + * <li>On an unavailable exception: if at least one replica is alive, the | |
| 49 | + * operation is retried at a lower consistency level.</li> | |
| 50 | 50 | * </ul> |
| 51 | - * <p> | |
| 51 | + * <p/> | |
| 52 | 52 | * The reasoning being this retry policy is the following one. If, based |
| 53 | 53 | * on the information the Cassandra coordinator node returns, retrying the |
| 54 | 54 | * operation with the initially requested consistency has a change to |
| 55 | 55 | * succeed, do it. Otherwise, if based on these information we know <b>the |
| 56 | 56 | * initially requested consistency level cannot be achieve currently</b>, then: |
| 57 | 57 | * <ul> |
| 58 | - * <li>For writes, ignore the exception (thus silently failing the | |
| 59 | - * consistency requirement) if we know the write has been persisted on at | |
| 60 | - * least one replica.</li> | |
| 61 | - * <li>For reads, try reading at a lower consistency level (thus silently | |
| 62 | - * failing the consistency requirement).</li> | |
| 58 | + * <li>For writes, ignore the exception (thus silently failing the | |
| 59 | + * consistency requirement) if we know the write has been persisted on at | |
| 60 | + * least one replica.</li> | |
| 61 | + * <li>For reads, try reading at a lower consistency level (thus silently | |
| 62 | + * failing the consistency requirement).</li> | |
| 63 | 63 | * </ul> |
| 64 | 64 | * In other words, this policy implements the idea that if the requested |
| 65 | 65 | * consistency level cannot be achieved, the next best thing for writes is |
| @@ -70,7 +70,8 @@ | ||
| 70 | 70 | |
| 71 | 71 | public static final DowngradingConsistencyRetryPolicy INSTANCE = new DowngradingConsistencyRetryPolicy(); |
| 72 | 72 | |
| 73 | - private DowngradingConsistencyRetryPolicy() {} | |
| 73 | + private DowngradingConsistencyRetryPolicy() { | |
| 74 | + } | |
| 74 | 75 | |
| 75 | 76 | private RetryDecision maxLikelyToWorkCL(int knownOk) { |
| 76 | 77 | if (knownOk >= 3) |
| @@ -85,7 +86,7 @@ | ||
| 85 | 86 | |
| 86 | 87 | /** |
| 87 | 88 | * Defines whether to retry and at which consistency level on a read timeout. |
| 88 | - * <p> | |
| 89 | + * <p/> | |
| 89 | 90 | * This method triggers a maximum of one retry. If less replica |
| 90 | 91 | * responded than required by the consistency level (but at least one |
| 91 | 92 | * replica did respond), the operation is retried at a lower |
| @@ -93,15 +94,15 @@ | ||
| 93 | 94 | * retrieve, the operation is retried with the initial consistency |
| 94 | 95 | * level. Otherwise, an exception is thrown. |
| 95 | 96 | * |
| 96 | - * @param statement the original query that timed out. | |
| 97 | - * @param cl the original consistency level of the read that timed out. | |
| 97 | + * @param statement the original query that timed out. | |
| 98 | + * @param cl the original consistency level of the read that timed out. | |
| 98 | 99 | * @param requiredResponses the number of responses that were required to |
| 99 | - * achieve the requested consistency level. | |
| 100 | + * achieve the requested consistency level. | |
| 100 | 101 | * @param receivedResponses the number of responses that had been received |
| 101 | - * by the time the timeout exception was raised. | |
| 102 | - * @param dataRetrieved whether actual data (by opposition to data checksum) | |
| 103 | - * was present in the received responses. | |
| 104 | - * @param nbRetry the number of retry already performed for this operation. | |
| 102 | + * by the time the timeout exception was raised. | |
| 103 | + * @param dataRetrieved whether actual data (by opposition to data checksum) | |
| 104 | + * was present in the received responses. | |
| 105 | + * @param nbRetry the number of retry already performed for this operation. | |
| 105 | 106 | * @return a RetryDecision as defined above. |
| 106 | 107 | */ |
| 107 | 108 | @Override |
| @@ -126,7 +127,7 @@ | ||
| 126 | 127 | |
| 127 | 128 | /** |
| 128 | 129 | * Defines whether to retry and at which consistency level on a write timeout. |
| 129 | - * <p> | |
| 130 | + * <p/> | |
| 130 | 131 | * This method triggers a maximum of one retry. If {@code writeType == |
| 131 | 132 | * WriteType.BATCH_LOG}, the write is retried with the initial |
| 132 | 133 | * consistency level. If {@code writeType == WriteType.UNLOGGED_BATCH} |
| @@ -137,14 +138,14 @@ | ||
| 137 | 138 | * and {@code WriteType.BATCH} types, if we know the write has been persisted on at |
| 138 | 139 | * least one replica, we ignore the exception. Otherwise, an exception is thrown. |
| 139 | 140 | * |
| 140 | - * @param statement the original query that timed out. | |
| 141 | - * @param cl the original consistency level of the write that timed out. | |
| 142 | - * @param writeType the type of the write that timed out. | |
| 141 | + * @param statement the original query that timed out. | |
| 142 | + * @param cl the original consistency level of the write that timed out. | |
| 143 | + * @param writeType the type of the write that timed out. | |
| 143 | 144 | * @param requiredAcks the number of acknowledgments that were required to |
| 144 | - * achieve the requested consistency level. | |
| 145 | + * achieve the requested consistency level. | |
| 145 | 146 | * @param receivedAcks the number of acknowledgments that had been received |
| 146 | - * by the time the timeout exception was raised. | |
| 147 | - * @param nbRetry the number of retry already performed for this operation. | |
| 147 | + * by the time the timeout exception was raised. | |
| 148 | + * @param nbRetry the number of retry already performed for this operation. | |
| 148 | 149 | * @return a RetryDecision as defined above. |
| 149 | 150 | */ |
| 150 | 151 | @Override |
| @@ -171,19 +172,19 @@ | ||
| 171 | 172 | /** |
| 172 | 173 | * Defines whether to retry and at which consistency level on an |
| 173 | 174 | * unavailable exception. |
| 174 | - * <p> | |
| 175 | + * <p/> | |
| 175 | 176 | * This method triggers a maximum of one retry. If at least one replica |
| 176 | 177 | * is know to be alive, the operation is retried at a lower consistency |
| 177 | 178 | * level. |
| 178 | 179 | * |
| 179 | - * @param statement the original query for which the consistency level cannot | |
| 180 | - * be achieved. | |
| 181 | - * @param cl the original consistency level for the operation. | |
| 180 | + * @param statement the original query for which the consistency level cannot | |
| 181 | + * be achieved. | |
| 182 | + * @param cl the original consistency level for the operation. | |
| 182 | 183 | * @param requiredReplica the number of replica that should have been |
| 183 | - * (known) alive for the operation to be attempted. | |
| 184 | - * @param aliveReplica the number of replica that were know to be alive by | |
| 185 | - * the coordinator of the operation. | |
| 186 | - * @param nbRetry the number of retry already performed for this operation. | |
| 184 | + * (known) alive for the operation to be attempted. | |
| 185 | + * @param aliveReplica the number of replica that were know to be alive by | |
| 186 | + * the coordinator of the operation. | |
| 187 | + * @param nbRetry the number of retry already performed for this operation. | |
| 187 | 188 | * @return a RetryDecision as defined above. |
| 188 | 189 | */ |
| 189 | 190 | @Override |
modified driver-core/src/main/java/com/datastax/driver/core/policies/EC2MultiRegionAddressTranslater.java +14 −15
| @@ -15,12 +15,11 @@ | ||
| 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.Enumeration; | |
| 21 | -import java.util.Hashtable; | |
| 22 | - | |
| 18 | +import com.datastax.driver.core.exceptions.DriverException; | |
| 23 | 19 | import com.google.common.annotations.VisibleForTesting; |
| 20 | +import org.slf4j.Logger; | |
| 21 | +import org.slf4j.LoggerFactory; | |
| 22 | + | |
| 24 | 23 | import javax.naming.Context; |
| 25 | 24 | import javax.naming.NamingEnumeration; |
| 26 | 25 | import javax.naming.NamingException; |
| @@ -28,22 +27,22 @@ | ||
| 28 | 27 | import javax.naming.directory.Attributes; |
| 29 | 28 | import javax.naming.directory.DirContext; |
| 30 | 29 | import javax.naming.directory.InitialDirContext; |
| 31 | -import org.slf4j.Logger; | |
| 32 | -import org.slf4j.LoggerFactory; | |
| 33 | - | |
| 34 | -import com.datastax.driver.core.exceptions.DriverException; | |
| 30 | +import java.net.InetAddress; | |
| 31 | +import java.net.InetSocketAddress; | |
| 32 | +import java.util.Enumeration; | |
| 33 | +import java.util.Hashtable; | |
| 35 | 34 | |
| 36 | 35 | /** |
| 37 | 36 | * {@link AddressTranslater} implementation for a multi-region EC2 deployment <b>where clients are also deployed in EC2</b>. |
| 38 | - * <p> | |
| 37 | + * <p/> | |
| 39 | 38 | * Its distinctive feature is that it translates addresses according to the location of the Cassandra host: |
| 40 | 39 | * <ul> |
| 41 | 40 | * <li>addresses in different EC2 regions (than the client) are unchanged;</li> |
| 42 | 41 | * <li>addresses in the same EC2 region are <b>translated to private IPs</b>.</li> |
| 43 | 42 | * </ul> |
| 44 | 43 | * This optimizes network costs, because Amazon charges more for communication over public IPs. |
| 45 | - * | |
| 46 | - * <p> | |
| 44 | + * <p/> | |
| 45 | + * <p/> | |
| 47 | 46 | * Implementation note: this class performs a reverse DNS lookup of the origin address, to find the domain name of the target |
| 48 | 47 | * instance. Then it performs a forward DNS lookup of the domain name; the EC2 DNS does the private/public switch automatically |
| 49 | 48 | * based on location. |
| @@ -93,9 +92,9 @@ | ||
| 93 | 92 | } |
| 94 | 93 | |
| 95 | 94 | private String lookupPtrRecord(String reversedDomain) throws Exception { |
| 96 | - Attributes attrs = ctx.getAttributes(reversedDomain, new String[]{ "PTR" }); | |
| 95 | + Attributes attrs = ctx.getAttributes(reversedDomain, new String[]{"PTR"}); | |
| 97 | 96 | for (NamingEnumeration ae = attrs.getAll(); ae.hasMoreElements(); ) { |
| 98 | - Attribute attr = (Attribute)ae.next(); | |
| 97 | + Attribute attr = (Attribute) ae.next(); | |
| 99 | 98 | for (Enumeration<?> vals = attr.getAll(); vals.hasMoreElements(); ) |
| 100 | 99 | return vals.nextElement().toString(); |
| 101 | 100 | } |
| @@ -136,7 +135,7 @@ | ||
| 136 | 135 | int lowNibble = b & 0x0F; |
| 137 | 136 | int highNibble = b >> 4 & 0x0F; |
| 138 | 137 | builder.append(Integer.toHexString(lowNibble)).append('.') |
| 139 | - .append(Integer.toHexString(highNibble)).append('.'); | |
| 138 | + .append(Integer.toHexString(highNibble)).append('.'); | |
| 140 | 139 | } |
| 141 | 140 | builder.append("ip6.arpa"); |
| 142 | 141 | return builder.toString(); |
modified driver-core/src/main/java/com/datastax/driver/core/policies/ExponentialReconnectionPolicy.java +3 −3
| @@ -30,8 +30,8 @@ | ||
| 30 | 30 | * Creates a reconnection policy waiting exponentially longer for each new attempt. |
| 31 | 31 | * |
| 32 | 32 | * @param baseDelayMs the base delay in milliseconds to use for |
| 33 | - * the schedules created by this policy. | |
| 34 | - * @param maxDelayMs the maximum delay to wait between two attempts. | |
| 33 | + * the schedules created by this policy. | |
| 34 | + * @param maxDelayMs the maximum delay to wait between two attempts. | |
| 35 | 35 | */ |
| 36 | 36 | public ExponentialReconnectionPolicy(long baseDelayMs, long maxDelayMs) { |
| 37 | 37 | if (baseDelayMs < 0 || maxDelayMs < 0) |
| @@ -71,7 +71,7 @@ | ||
| 71 | 71 | |
| 72 | 72 | /** |
| 73 | 73 | * A new schedule that used an exponentially growing delay between reconnection attempts. |
| 74 | - * <p> | |
| 74 | + * <p/> | |
| 75 | 75 | * For this schedule, reconnection attempt {@code i} will be tried |
| 76 | 76 | * {@code Math.min(2^(i-1) * getBaseDelayMs(), getMaxDelayMs())} milliseconds after the previous one. |
| 77 | 77 | * |
modified driver-core/src/main/java/com/datastax/driver/core/policies/FallthroughRetryPolicy.java +23 −22
| @@ -21,7 +21,7 @@ | ||
| 21 | 21 | |
| 22 | 22 | /** |
| 23 | 23 | * A retry policy that never retry (nor ignore). |
| 24 | - * <p> | |
| 24 | + * <p/> | |
| 25 | 25 | * All of the methods of this retry policy unconditionally return {@link RetryPolicy.RetryDecision#rethrow}. |
| 26 | 26 | * If this policy is used, retry will have to be implemented in business code. |
| 27 | 27 | */ |
| @@ -29,20 +29,21 @@ | ||
| 29 | 29 | |
| 30 | 30 | public static final FallthroughRetryPolicy INSTANCE = new FallthroughRetryPolicy(); |
| 31 | 31 | |
| 32 | - private FallthroughRetryPolicy() {} | |
| 32 | + private FallthroughRetryPolicy() { | |
| 33 | + } | |
| 33 | 34 | |
| 34 | 35 | /** |
| 35 | 36 | * Defines whether to retry and at which consistency level on a read timeout. |
| 36 | 37 | * |
| 37 | - * @param statement the original query that timed out. | |
| 38 | - * @param cl the original consistency level of the read that timed out. | |
| 38 | + * @param statement the original query that timed out. | |
| 39 | + * @param cl the original consistency level of the read that timed out. | |
| 39 | 40 | * @param requiredResponses the number of responses that were required to |
| 40 | - * achieve the requested consistency level. | |
| 41 | + * achieve the requested consistency level. | |
| 41 | 42 | * @param receivedResponses the number of responses that had been received |
| 42 | - * by the time the timeout exception was raised. | |
| 43 | - * @param dataRetrieved whether actual data (by opposition to data checksum) | |
| 44 | - * was present in the received responses. | |
| 45 | - * @param nbRetry the number of retry already performed for this operation. | |
| 43 | + * by the time the timeout exception was raised. | |
| 44 | + * @param dataRetrieved whether actual data (by opposition to data checksum) | |
| 45 | + * was present in the received responses. | |
| 46 | + * @param nbRetry the number of retry already performed for this operation. | |
| 46 | 47 | * @return {@code RetryDecision.rethrow()}. |
| 47 | 48 | */ |
| 48 | 49 | @Override |
| @@ -53,14 +54,14 @@ | ||
| 53 | 54 | /** |
| 54 | 55 | * Defines whether to retry and at which consistency level on a write timeout. |
| 55 | 56 | * |
| 56 | - * @param statement the original query that timed out. | |
| 57 | - * @param cl the original consistency level of the write that timed out. | |
| 58 | - * @param writeType the type of the write that timed out. | |
| 57 | + * @param statement the original query that timed out. | |
| 58 | + * @param cl the original consistency level of the write that timed out. | |
| 59 | + * @param writeType the type of the write that timed out. | |
| 59 | 60 | * @param requiredAcks the number of acknowledgments that were required to |
| 60 | - * achieve the requested consistency level. | |
| 61 | + * achieve the requested consistency level. | |
| 61 | 62 | * @param receivedAcks the number of acknowledgments that had been received |
| 62 | - * by the time the timeout exception was raised. | |
| 63 | - * @param nbRetry the number of retry already performed for this operation. | |
| 63 | + * by the time the timeout exception was raised. | |
| 64 | + * @param nbRetry the number of retry already performed for this operation. | |
| 64 | 65 | * @return {@code RetryDecision.rethrow()}. |
| 65 | 66 | */ |
| 66 | 67 | @Override |
| @@ -72,14 +73,14 @@ | ||
| 72 | 73 | * Defines whether to retry and at which consistency level on an |
| 73 | 74 | * unavailable exception. |
| 74 | 75 | * |
| 75 | - * @param statement the original query for which the consistency level cannot | |
| 76 | - * be achieved. | |
| 77 | - * @param cl the original consistency level for the operation. | |
| 76 | + * @param statement the original query for which the consistency level cannot | |
| 77 | + * be achieved. | |
| 78 | + * @param cl the original consistency level for the operation. | |
| 78 | 79 | * @param requiredReplica the number of replica that should have been |
| 79 | - * (known) alive for the operation to be attempted. | |
| 80 | - * @param aliveReplica the number of replica that were know to be alive by | |
| 81 | - * the coordinator of the operation. | |
| 82 | - * @param nbRetry the number of retry already performed for this operation. | |
| 80 | + * (known) alive for the operation to be attempted. | |
| 81 | + * @param aliveReplica the number of replica that were know to be alive by | |
| 82 | + * the coordinator of the operation. | |
| 83 | + * @param nbRetry the number of retry already performed for this operation. | |
| 83 | 84 | * @return {@code RetryDecision.rethrow()}. |
| 84 | 85 | */ |
| 85 | 86 | @Override |
modified driver-core/src/main/java/com/datastax/driver/core/policies/HostFilterPolicy.java +18 −22
| @@ -15,25 +15,23 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core.policies; |
| 17 | 17 | |
| 18 | -import java.net.InetSocketAddress; | |
| 19 | -import java.util.ArrayList; | |
| 20 | -import java.util.Collection; | |
| 21 | -import java.util.Iterator; | |
| 22 | -import java.util.List; | |
| 23 | - | |
| 24 | -import com.google.common.base.Predicate; | |
| 25 | -import com.google.common.base.Predicates; | |
| 26 | -import com.google.common.collect.ImmutableSet; | |
| 27 | - | |
| 28 | 18 | import com.datastax.driver.core.Cluster; |
| 29 | 19 | import com.datastax.driver.core.Host; |
| 30 | 20 | import com.datastax.driver.core.HostDistance; |
| 31 | 21 | import com.datastax.driver.core.Statement; |
| 22 | +import com.google.common.base.Predicate; | |
| 23 | +import com.google.common.base.Predicates; | |
| 24 | +import com.google.common.collect.ImmutableSet; | |
| 25 | + | |
| 26 | +import java.util.ArrayList; | |
| 27 | +import java.util.Collection; | |
| 28 | +import java.util.Iterator; | |
| 29 | +import java.util.List; | |
| 32 | 30 | |
| 33 | 31 | /** |
| 34 | 32 | * A load balancing policy wrapper that ensures that only hosts matching the predicate |
| 35 | 33 | * will ever be returned. |
| 36 | - * <p> | |
| 34 | + * <p/> | |
| 37 | 35 | * This policy wraps another load balancing policy and will delegate the choice |
| 38 | 36 | * of hosts to the wrapped policy with the exception that only hosts matching |
| 39 | 37 | * the predicate provided when constructing this policy will ever be |
| @@ -49,8 +47,8 @@ | ||
| 49 | 47 | * matching the predicate. |
| 50 | 48 | * |
| 51 | 49 | * @param childPolicy the wrapped policy. |
| 52 | - * @param predicate the host predicate. Only hosts matching this predicate may get connected | |
| 53 | - * to (whether they will get connected to or not depends on the child policy). | |
| 50 | + * @param predicate the host predicate. Only hosts matching this predicate may get connected | |
| 51 | + * to (whether they will get connected to or not depends on the child policy). | |
| 54 | 52 | */ |
| 55 | 53 | public HostFilterPolicy(LoadBalancingPolicy childPolicy, Predicate<Host> predicate) { |
| 56 | 54 | this.childPolicy = childPolicy; |
| @@ -66,7 +64,7 @@ | ||
| 66 | 64 | * {@inheritDoc} |
| 67 | 65 | * |
| 68 | 66 | * @throws IllegalArgumentException if none of the host in {@code hosts} |
| 69 | - * (which will correspond to the contact points) matches the predicate. | |
| 67 | + * (which will correspond to the contact points) matches the predicate. | |
| 70 | 68 | */ |
| 71 | 69 | @Override |
| 72 | 70 | public void init(Cluster cluster, Collection<Host> hosts) { |
| @@ -90,13 +88,13 @@ | ||
| 90 | 88 | @Override |
| 91 | 89 | public HostDistance distance(Host host) { |
| 92 | 90 | return predicate.apply(host) |
| 93 | - ? childPolicy.distance(host) | |
| 94 | - : HostDistance.IGNORED; | |
| 91 | + ? childPolicy.distance(host) | |
| 92 | + : HostDistance.IGNORED; | |
| 95 | 93 | } |
| 96 | 94 | |
| 97 | 95 | /** |
| 98 | 96 | * {@inheritDoc} |
| 99 | - * <p> | |
| 97 | + * <p/> | |
| 100 | 98 | * It is guaranteed that only hosts matching the predicate will be returned. |
| 101 | 99 | */ |
| 102 | 100 | @Override |
| @@ -141,7 +139,7 @@ | ||
| 141 | 139 | @Override |
| 142 | 140 | public void close() { |
| 143 | 141 | if (childPolicy instanceof CloseableLoadBalancingPolicy) |
| 144 | - ((CloseableLoadBalancingPolicy)childPolicy).close(); | |
| 142 | + ((CloseableLoadBalancingPolicy) childPolicy).close(); | |
| 145 | 143 | } |
| 146 | 144 | |
| 147 | 145 | /** |
| @@ -149,8 +147,7 @@ | ||
| 149 | 147 | * whose DC belongs to the provided list. |
| 150 | 148 | * |
| 151 | 149 | * @param childPolicy the wrapped policy. |
| 152 | - * @param dcs the DCs. | |
| 153 | - * | |
| 150 | + * @param dcs the DCs. | |
| 154 | 151 | * @return the policy. |
| 155 | 152 | */ |
| 156 | 153 | public static HostFilterPolicy fromDCWhiteList(LoadBalancingPolicy childPolicy, Iterable<String> dcs) { |
| @@ -162,8 +159,7 @@ | ||
| 162 | 159 | * whose DC belongs to the provided list. |
| 163 | 160 | * |
| 164 | 161 | * @param childPolicy the wrapped policy. |
| 165 | - * @param dcs the DCs. | |
| 166 | - * | |
| 162 | + * @param dcs the DCs. | |
| 167 | 163 | * @return the policy. |
| 168 | 164 | */ |
| 169 | 165 | public static HostFilterPolicy fromDCBlackList(LoadBalancingPolicy childPolicy, Iterable<String> dcs) { |
modified driver-core/src/main/java/com/datastax/driver/core/policies/IdentityTranslater.java +1 −1
| @@ -25,7 +25,7 @@ | ||
| 25 | 25 | |
| 26 | 26 | /** |
| 27 | 27 | * Translates a Cassandra {@code rpc_address} to another address if necessary. |
| 28 | - * <p> | |
| 28 | + * <p/> | |
| 29 | 29 | * This method is the identity function, it always return the address passed |
| 30 | 30 | * in argument, doing no translation. |
| 31 | 31 | * |
modified driver-core/src/main/java/com/datastax/driver/core/policies/LatencyAwarePolicy.java +53 −57
| @@ -15,10 +15,8 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core.policies; |
| 17 | 17 | |
| 18 | -import java.util.*; | |
| 19 | -import java.util.concurrent.*; | |
| 20 | -import java.util.concurrent.atomic.AtomicReference; | |
| 21 | - | |
| 18 | +import com.datastax.driver.core.*; | |
| 19 | +import com.datastax.driver.core.exceptions.*; | |
| 22 | 20 | import com.google.common.annotations.VisibleForTesting; |
| 23 | 21 | import com.google.common.collect.AbstractIterator; |
| 24 | 22 | import com.google.common.collect.ImmutableMap; |
| @@ -27,19 +25,20 @@ | ||
| 27 | 25 | import org.slf4j.Logger; |
| 28 | 26 | import org.slf4j.LoggerFactory; |
| 29 | 27 | |
| 30 | -import com.datastax.driver.core.*; | |
| 31 | -import com.datastax.driver.core.exceptions.*; | |
| 28 | +import java.util.*; | |
| 29 | +import java.util.concurrent.*; | |
| 30 | +import java.util.concurrent.atomic.AtomicReference; | |
| 32 | 31 | |
| 33 | 32 | /** |
| 34 | 33 | * A wrapper load balancing policy that adds latency awareness to a child policy. |
| 35 | - * <p> | |
| 34 | + * <p/> | |
| 36 | 35 | * When used, this policy will collect the latencies of the queries to each |
| 37 | 36 | * Cassandra node and maintain a per-node latency score (an average). Based |
| 38 | 37 | * on these scores, the policy will penalize (technically, it will ignore them |
| 39 | 38 | * unless no other nodes are up) the nodes that are slower than the best |
| 40 | 39 | * performing node by more than some configurable amount (the exclusion |
| 41 | 40 | * threshold). |
| 42 | - * <p> | |
| 41 | + * <p/> | |
| 43 | 42 | * The latency score for a given node is a based on a form of |
| 44 | 43 | * <a href="http://en.wikipedia.org/wiki/Moving_average#Exponential_moving_average">exponential moving average</a>. |
| 45 | 44 | * In other words, the latency score of a node is the average of its previously |
| @@ -48,13 +47,13 @@ | ||
| 48 | 47 | * time elapsed since the previous measure (to account for the fact that |
| 49 | 48 | * latencies are not necessarily reported with equal regularity, neither |
| 50 | 49 | * over time nor between different nodes). |
| 51 | - * <p> | |
| 50 | + * <p/> | |
| 52 | 51 | * Once a node is excluded from query plans (because its averaged latency grew |
| 53 | 52 | * over the exclusion threshold), its latency score will not be updated anymore |
| 54 | 53 | * (since it is not queried). To give a chance to this node to recover, the |
| 55 | 54 | * policy has a configurable retry period. The policy will not penalize a host |
| 56 | 55 | * for which no measurement has been collected for more than this retry period. |
| 57 | - * <p> | |
| 56 | + * <p/> | |
| 58 | 57 | * Please see the {@link Builder} class and methods for more details on the |
| 59 | 58 | * possible parameters of this policy. |
| 60 | 59 | * |
| @@ -100,7 +99,7 @@ | ||
| 100 | 99 | * that the resulting policy should wrap. |
| 101 | 100 | * |
| 102 | 101 | * @param childPolicy the load balancing policy to wrap with latency |
| 103 | - * awareness. | |
| 102 | + * awareness. | |
| 104 | 103 | * @return the created builder. |
| 105 | 104 | */ |
| 106 | 105 | public static Builder builder(LoadBalancingPolicy childPolicy) { |
| @@ -140,11 +139,11 @@ | ||
| 140 | 139 | continue; |
| 141 | 140 | } |
| 142 | 141 | |
| 143 | - if (stats.getLatencyScore() > ((long)(exclusionThreshold * currentMin))) { | |
| 142 | + if (stats.getLatencyScore() > ((long) (exclusionThreshold * currentMin))) { | |
| 144 | 143 | excludedThisTick.add(host); |
| 145 | 144 | if (!excludedAtLastTick.contains(host)) |
| 146 | 145 | logger.debug(String.format("Host %s has an average latency score of %.3fms, more than %f times more than the minimum %.3fms: will be avoided temporarily.", |
| 147 | - host, inMS(stats.getLatencyScore()), exclusionThreshold, inMS(currentMin))); | |
| 146 | + host, inMS(stats.getLatencyScore()), exclusionThreshold, inMS(currentMin))); | |
| 148 | 147 | continue; |
| 149 | 148 | } |
| 150 | 149 | |
| @@ -162,7 +161,7 @@ | ||
| 162 | 161 | } |
| 163 | 162 | |
| 164 | 163 | private static double inMS(long nanos) { |
| 165 | - return ((double)nanos) / (1000 * 1000); | |
| 164 | + return ((double) nanos) / (1000 * 1000); | |
| 166 | 165 | } |
| 167 | 166 | |
| 168 | 167 | private static double inMS(double nanos) { |
| @@ -192,19 +191,19 @@ | ||
| 192 | 191 | |
| 193 | 192 | /** |
| 194 | 193 | * Returns the hosts to use for a new query. |
| 195 | - * <p> | |
| 194 | + * <p/> | |
| 196 | 195 | * The returned plan will be the same as the plan generated by the |
| 197 | 196 | * child policy, but with the (initial) exclusion of hosts whose recent |
| 198 | 197 | * (averaged) latency is more than {@code exclusionThreshold * minLatency} |
| 199 | 198 | * (where {@code minLatency} is the (averaged) latency of the fastest |
| 200 | 199 | * host). |
| 201 | - * <p> | |
| 200 | + * <p/> | |
| 202 | 201 | * The hosts that are initially excluded due to their latency will be returned |
| 203 | 202 | * by this iterator, but only only after all non-excluded hosts of the |
| 204 | 203 | * child policy have been returned. |
| 205 | 204 | * |
| 206 | 205 | * @param loggedKeyspace the currently logged keyspace. |
| 207 | - * @param statement the statement for which to build the plan. | |
| 206 | + * @param statement the statement for which to build the plan. | |
| 208 | 207 | * @return the new query plan. |
| 209 | 208 | */ |
| 210 | 209 | @Override |
| @@ -229,7 +228,7 @@ | ||
| 229 | 228 | |
| 230 | 229 | // If the host latency is within acceptable bound of the faster known host, return |
| 231 | 230 | // that host. Otherwise, skip it. |
| 232 | - if (latency.average <= ((long)(exclusionThreshold * (double)min))) | |
| 231 | + if (latency.average <= ((long) (exclusionThreshold * (double) min))) | |
| 233 | 232 | return host; |
| 234 | 233 | |
| 235 | 234 | if (skipped == null) |
| @@ -241,7 +240,9 @@ | ||
| 241 | 240 | return skipped.poll(); |
| 242 | 241 | |
| 243 | 242 | return endOfData(); |
| 244 | - }; | |
| 243 | + } | |
| 244 | + | |
| 245 | + ; | |
| 245 | 246 | }; |
| 246 | 247 | } |
| 247 | 248 | |
| @@ -379,11 +380,11 @@ | ||
| 379 | 380 | * and tend to make the host's score look better than it actually is. |
| 380 | 381 | */ |
| 381 | 382 | private static final Set<Class<? extends DriverException>> EXCLUDED_EXCEPTIONS = ImmutableSet.of( |
| 382 | - UnavailableException.class, // this is done via the snitch and is usually very fast | |
| 383 | - OverloadedException.class, | |
| 384 | - BootstrappingException.class, | |
| 385 | - UnpreparedException.class, | |
| 386 | - QueryValidationException.class // query validation also happens at early stages in the coordinator | |
| 383 | + UnavailableException.class, // this is done via the snitch and is usually very fast | |
| 384 | + OverloadedException.class, | |
| 385 | + BootstrappingException.class, | |
| 386 | + UnpreparedException.class, | |
| 387 | + QueryValidationException.class // query validation also happens at early stages in the coordinator | |
| 387 | 388 | ); |
| 388 | 389 | |
| 389 | 390 | private class Tracker implements LatencyTracker { |
| @@ -392,7 +393,7 @@ | ||
| 392 | 393 | private volatile long cachedMin = -1L; |
| 393 | 394 | |
| 394 | 395 | public void update(Host host, Statement statement, Exception exception, long newLatencyNanos) { |
| 395 | - if(shouldConsiderNewLatency(statement, exception)) { | |
| 396 | + if (shouldConsiderNewLatency(statement, exception)) { | |
| 396 | 397 | HostLatencyTracker hostTracker = latencies.get(host); |
| 397 | 398 | if (hostTracker == null) { |
| 398 | 399 | hostTracker = new HostLatencyTracker(scale, (30L * minMeasure) / 100L); |
| @@ -406,9 +407,9 @@ | ||
| 406 | 407 | |
| 407 | 408 | private boolean shouldConsiderNewLatency(Statement statement, Exception exception) { |
| 408 | 409 | // query was successful: always consider |
| 409 | - if(exception == null) return true; | |
| 410 | + if (exception == null) return true; | |
| 410 | 411 | // filter out "fast" errors |
| 411 | - if(EXCLUDED_EXCEPTIONS.contains(exception.getClass())) return false; | |
| 412 | + if (EXCLUDED_EXCEPTIONS.contains(exception.getClass())) return false; | |
| 412 | 413 | return true; |
| 413 | 414 | } |
| 414 | 415 | |
| @@ -465,7 +466,7 @@ | ||
| 465 | 466 | private final AtomicReference<TimestampedAverage> current = new AtomicReference<TimestampedAverage>(); |
| 466 | 467 | |
| 467 | 468 | HostLatencyTracker(long scale, long thresholdToAccount) { |
| 468 | - this.scale = (double)scale; // We keep in double since that's how we'll use it. | |
| 469 | + this.scale = (double) scale; // We keep in double since that's how we'll use it. | |
| 469 | 470 | this.thresholdToAccount = thresholdToAccount; |
| 470 | 471 | } |
| 471 | 472 | |
| @@ -499,11 +500,11 @@ | ||
| 499 | 500 | if (delay <= 0) |
| 500 | 501 | return null; |
| 501 | 502 | |
| 502 | - double scaledDelay = ((double)delay)/scale; | |
| 503 | + double scaledDelay = ((double) delay) / scale; | |
| 503 | 504 | // Note: We don't use log1p because we it's quite a bit slower and we don't care about the precision (and since we |
| 504 | 505 | // refuse ridiculously big scales, scaledDelay can't be so low that scaledDelay+1 == 1.0 (due to rounding)). |
| 505 | - double prevWeight = Math.log(scaledDelay+1) / scaledDelay; | |
| 506 | - long newAverage = (long)((1.0 - prevWeight) * newLatencyNanos + prevWeight * previous.average); | |
| 506 | + double prevWeight = Math.log(scaledDelay + 1) / scaledDelay; | |
| 507 | + long newAverage = (long) ((1.0 - prevWeight) * newLatencyNanos + prevWeight * previous.average); | |
| 507 | 508 | |
| 508 | 509 | return new TimestampedAverage(currentTimestamp, newAverage, nbMeasure); |
| 509 | 510 | } |
| @@ -515,13 +516,13 @@ | ||
| 515 | 516 | |
| 516 | 517 | /** |
| 517 | 518 | * Helper builder object to create a latency aware policy. |
| 518 | - * <p> | |
| 519 | + * <p/> | |
| 519 | 520 | * This helper allows to configure the different parameters used by |
| 520 | 521 | * {@code LatencyAwarePolicy}. The only mandatory parameter is the child |
| 521 | 522 | * policy that will be wrapped with latency awareness. The other parameters |
| 522 | 523 | * can be set through the methods of this builder, but all have defaults (that |
| 523 | 524 | * are documented in the javadoc of each method) if you don't. |
| 524 | - * <p> | |
| 525 | + * <p/> | |
| 525 | 526 | * If you observe that the resulting policy excludes hosts too aggressively or |
| 526 | 527 | * not enough so, the main parameters to check are the exclusion threshold |
| 527 | 528 | * ({@link #withExclusionThreshold}) and scale ({@link #withScale}). |
| @@ -549,7 +550,7 @@ | ||
| 549 | 550 | * that the resulting policy wraps. |
| 550 | 551 | * |
| 551 | 552 | * @param childPolicy the load balancing policy to wrap with latency |
| 552 | - * awareness. | |
| 553 | + * awareness. | |
| 553 | 554 | */ |
| 554 | 555 | public Builder(LoadBalancingPolicy childPolicy) { |
| 555 | 556 | this.childPolicy = childPolicy; |
| @@ -557,19 +558,18 @@ | ||
| 557 | 558 | |
| 558 | 559 | /** |
| 559 | 560 | * Sets the exclusion threshold to use for the resulting latency aware policy. |
| 560 | - * <p> | |
| 561 | + * <p/> | |
| 561 | 562 | * The exclusion threshold controls how much worse the average latency |
| 562 | 563 | * of a node must be compared to the fastest performing node for it to be |
| 563 | 564 | * penalized by the policy. |
| 564 | - * <p> | |
| 565 | + * <p/> | |
| 565 | 566 | * The default exclusion threshold (if this method is not called) is <b>2</b>. |
| 566 | 567 | * In other words, the resulting policy excludes nodes that are more than |
| 567 | 568 | * twice slower than the fastest node. |
| 568 | 569 | * |
| 569 | 570 | * @param exclusionThreshold the exclusion threshold to use. Must be |
| 570 | - * greater or equal to 1. | |
| 571 | + * greater or equal to 1. | |
| 571 | 572 | * @return this builder. |
| 572 | - * | |
| 573 | 573 | * @throws IllegalArgumentException if {@code exclusionThreshold < 1}. |
| 574 | 574 | */ |
| 575 | 575 | public Builder withExclusionThreshold(double exclusionThreshold) { |
| @@ -581,32 +581,31 @@ | ||
| 581 | 581 | |
| 582 | 582 | /** |
| 583 | 583 | * Sets the scale to use for the resulting latency aware policy. |
| 584 | - * <p> | |
| 584 | + * <p/> | |
| 585 | 585 | * The {@code scale} provides control on how the weight given to older latencies |
| 586 | 586 | * decreases over time. For a given host, if a new latency \(l\) is received at |
| 587 | 587 | * time \(t\), and the previously calculated average is \(prev\) calculated at |
| 588 | 588 | * time \(t'\), then the newly calculated average \(avg\) for that host is calculated |
| 589 | 589 | * thusly: |
| 590 | 590 | * \[ |
| 591 | - * d = \frac{t - t'}{scale} \\ | |
| 592 | - * \alpha = 1 - \left(\frac{\ln(d+1)}{d}\right) \\ | |
| 593 | - * avg = \alpha * l + (1-\alpha) * prev | |
| 591 | + * d = \frac{t - t'}{scale} \\ | |
| 592 | + * \alpha = 1 - \left(\frac{\ln(d+1)}{d}\right) \\ | |
| 593 | + * avg = \alpha * l + (1-\alpha) * prev | |
| 594 | 594 | * \] |
| 595 | 595 | * Typically, with a {@code scale} of 100 milliseconds (the default), if a new |
| 596 | 596 | * latency is measured and the previous measure is 10 millisecond old (so \(d=0.1\)), |
| 597 | 597 | * then \(\alpha\) will be around \(0.05\). In other words, the new latency will |
| 598 | 598 | * weight 5% of the updated average. A bigger scale will get less weight to new |
| 599 | 599 | * measurements (compared to previous ones), a smaller one will give them more weight. |
| 600 | - * <p> | |
| 600 | + * <p/> | |
| 601 | 601 | * The default scale (if this method is not used) is of <b>100 milliseconds</b>. If unsure, try |
| 602 | 602 | * this default scale first and experiment only if it doesn't provide acceptable results |
| 603 | 603 | * (hosts are excluded too quickly or not fast enough and tuning the exclusion threshold |
| 604 | 604 | * doesn't help). |
| 605 | 605 | * |
| 606 | 606 | * @param scale the scale to use. |
| 607 | - * @param unit the unit of {@code scale}. | |
| 607 | + * @param unit the unit of {@code scale}. | |
| 608 | 608 | * @return this builder. |
| 609 | - * | |
| 610 | 609 | * @throws IllegalArgumentException if {@code scale <e; 0}. |
| 611 | 610 | */ |
| 612 | 611 | public Builder withScale(long scale, TimeUnit unit) { |
| @@ -618,7 +617,7 @@ | ||
| 618 | 617 | |
| 619 | 618 | /** |
| 620 | 619 | * Sets the retry period for the resulting latency aware policy. |
| 621 | - * <p> | |
| 620 | + * <p/> | |
| 622 | 621 | * The retry period defines how long a node may be penalized by the |
| 623 | 622 | * policy before it is given a 2nd change. More precisely, a node is excluded |
| 624 | 623 | * from query plans if both his calculated average latency is {@code exclusionThreshold} |
| @@ -628,9 +627,8 @@ | ||
| 628 | 627 | * latency updated, this is basically how long the policy will exclude a node. |
| 629 | 628 | * |
| 630 | 629 | * @param retryPeriod the retry period to use. |
| 631 | - * @param unit the unit for {@code retryPeriod}. | |
| 630 | + * @param unit the unit for {@code retryPeriod}. | |
| 632 | 631 | * @return this builder. |
| 633 | - * | |
| 634 | 632 | * @throws IllegalArgumentException if {@code retryPeriod < 0}. |
| 635 | 633 | */ |
| 636 | 634 | public Builder withRetryPeriod(long retryPeriod, TimeUnit unit) { |
| @@ -642,14 +640,14 @@ | ||
| 642 | 640 | |
| 643 | 641 | /** |
| 644 | 642 | * Sets the update rate for the resulting latency aware policy. |
| 645 | - * | |
| 643 | + * <p/> | |
| 646 | 644 | * The update rate defines how often the minimum average latency is |
| 647 | 645 | * recomputed. While the average latency score of each node is computed |
| 648 | 646 | * iteratively (updated each time a new latency is collected), the |
| 649 | 647 | * minimum score needs to be recomputed from scratch every time, which |
| 650 | 648 | * is slightly more costly. For this reason, the minimum is only |
| 651 | 649 | * re-calculated at the given fixed rate and cached between re-calculation. |
| 652 | - * <p> | |
| 650 | + * <p/> | |
| 653 | 651 | * The default update rate if <b>100 milliseconds</b>, which should be |
| 654 | 652 | * appropriate for most applications. In particular, note that while we |
| 655 | 653 | * want to avoid to recompute the minimum for every query, that |
| @@ -658,9 +656,8 @@ | ||
| 658 | 656 | * unnecessarily slow for instance). |
| 659 | 657 | * |
| 660 | 658 | * @param updateRate the update rate to use. |
| 661 | - * @param unit the unit for {@code updateRate}. | |
| 659 | + * @param unit the unit for {@code updateRate}. | |
| 662 | 660 | * @return this builder. |
| 663 | - * | |
| 664 | 661 | * @throws IllegalArgumentException if {@code updateRate <e; 0}. |
| 665 | 662 | */ |
| 666 | 663 | public Builder withUpdateRate(long updateRate, TimeUnit unit) { |
| @@ -673,7 +670,7 @@ | ||
| 673 | 670 | /** |
| 674 | 671 | * Sets the minimum number of measurements per-host to consider for |
| 675 | 672 | * the resulting latency aware policy. |
| 676 | - * <p> | |
| 673 | + * <p/> | |
| 677 | 674 | * Penalizing nodes is based on an average of their recently measured |
| 678 | 675 | * average latency. This average is only meaningful if a minimum of |
| 679 | 676 | * measurements have been collected (moreover, a newly started |
| @@ -686,10 +683,10 @@ | ||
| 686 | 683 | * ignored, while the {@code 70%} next ones are accounted in the latency |
| 687 | 684 | * computed but the node won't get convicted until we've had at least |
| 688 | 685 | * {@code minMeasure} measurements). |
| 689 | - * <p> | |
| 686 | + * <p/> | |
| 690 | 687 | * Note that the number of collected measurements for a given host is |
| 691 | 688 | * reset if the node is restarted. |
| 692 | - * <p> | |
| 689 | + * <p/> | |
| 693 | 690 | * The default for this option (if this method is not called) is <b>50</b>. |
| 694 | 691 | * Note that it is probably not a good idea to put this option too low |
| 695 | 692 | * if only to avoid the influence of JVM warm-up on newly restarted |
| @@ -697,7 +694,6 @@ | ||
| 697 | 694 | * |
| 698 | 695 | * @param minMeasure the minimum measurements to consider. |
| 699 | 696 | * @return this builder. |
| 700 | - * | |
| 701 | 697 | * @throws IllegalArgumentException if {@code minMeasure < 0}. |
| 702 | 698 | */ |
| 703 | 699 | public Builder withMininumMeasurements(int minMeasure) { |
| @@ -721,7 +717,7 @@ | ||
| 721 | 717 | @Override |
| 722 | 718 | public void close() { |
| 723 | 719 | if (childPolicy instanceof CloseableLoadBalancingPolicy) |
| 724 | - ((CloseableLoadBalancingPolicy)childPolicy).close(); | |
| 720 | + ((CloseableLoadBalancingPolicy) childPolicy).close(); | |
| 725 | 721 | updaterService.shutdown(); |
| 726 | 722 | } |
| 727 | 723 | } |
modified driver-core/src/main/java/com/datastax/driver/core/policies/LoadBalancingPolicy.java +18 −18
| @@ -15,25 +15,25 @@ | ||
| 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 | * The policy that decides which Cassandra hosts to contact for each new query. |
| 28 | - * <p> | |
| 28 | + * <p/> | |
| 29 | 29 | * Two methods need to be implemented: |
| 30 | 30 | * <ul> |
| 31 | - * <li>{@link LoadBalancingPolicy#distance}: returns the "distance" of an | |
| 32 | - * host for that balancing policy. </li> | |
| 33 | - * <li>{@link LoadBalancingPolicy#newQueryPlan}: it is used for each query to | |
| 34 | - * find which host to query first, and which hosts to use as failover.</li> | |
| 31 | + * <li>{@link LoadBalancingPolicy#distance}: returns the "distance" of an | |
| 32 | + * host for that balancing policy. </li> | |
| 33 | + * <li>{@link LoadBalancingPolicy#newQueryPlan}: it is used for each query to | |
| 34 | + * find which host to query first, and which hosts to use as failover.</li> | |
| 35 | 35 | * </ul> |
| 36 | - * <p> | |
| 36 | + * <p/> | |
| 37 | 37 | * The {@code LoadBalancingPolicy} is a {@link com.datastax.driver.core.Host.StateListener} |
| 38 | 38 | * and is thus informed of hosts up/down events. For efficiency purposes, the |
| 39 | 39 | * policy is expected to exclude down hosts from query plans. |
| @@ -42,25 +42,25 @@ | ||
| 42 | 42 | |
| 43 | 43 | /** |
| 44 | 44 | * Initialize this load balancing policy. |
| 45 | - * <p> | |
| 45 | + * <p/> | |
| 46 | 46 | * Note that the driver guarantees that it will call this method exactly |
| 47 | 47 | * once per policy object and will do so before any call to another of the |
| 48 | 48 | * methods of the policy. |
| 49 | 49 | * |
| 50 | 50 | * @param cluster the {@code Cluster} instance for which the policy is created. |
| 51 | - * @param hosts the initial hosts to use. | |
| 51 | + * @param hosts the initial hosts to use. | |
| 52 | 52 | */ |
| 53 | 53 | public void init(Cluster cluster, Collection<Host> hosts); |
| 54 | 54 | |
| 55 | 55 | /** |
| 56 | 56 | * Returns the distance assigned by this policy to the provided host. |
| 57 | - * <p> | |
| 57 | + * <p/> | |
| 58 | 58 | * The distance of an host influence how much connections are kept to the |
| 59 | 59 | * node (see {@link HostDistance}). A policy should assign a {@code |
| 60 | 60 | * LOCAL} distance to nodes that are susceptible to be returned first by |
| 61 | 61 | * {@code newQueryPlan} and it is useless for {@code newQueryPlan} to |
| 62 | 62 | * return hosts to which it assigns an {@code IGNORED} distance. |
| 63 | - * <p> | |
| 63 | + * <p/> | |
| 64 | 64 | * The host distance is primarily used to prevent keeping too many |
| 65 | 65 | * connections to host in remote datacenters when the policy itself always |
| 66 | 66 | * picks host in the local datacenter first. |
| @@ -72,7 +72,7 @@ | ||
| 72 | 72 | |
| 73 | 73 | /** |
| 74 | 74 | * Returns the hosts to use for a new query. |
| 75 | - * <p> | |
| 75 | + * <p/> | |
| 76 | 76 | * Each new query will call this method. The first host in the result will |
| 77 | 77 | * then be used to perform the query. In the event of a connection problem |
| 78 | 78 | * (the queried host is down or appear to be so), the next host will be |
| @@ -80,10 +80,10 @@ | ||
| 80 | 80 | * will fail. |
| 81 | 81 | * |
| 82 | 82 | * @param loggedKeyspace the currently logged keyspace (the one set through either |
| 83 | - * {@link Cluster#connect(String)} or by manually doing a {@code USE} query) for | |
| 84 | - * the session on which this plan need to be built. This can be {@code null} if | |
| 85 | - * the corresponding session has no keyspace logged in. | |
| 86 | - * @param statement the query for which to build a plan. | |
| 83 | + * {@link Cluster#connect(String)} or by manually doing a {@code USE} query) for | |
| 84 | + * the session on which this plan need to be built. This can be {@code null} if | |
| 85 | + * the corresponding session has no keyspace logged in. | |
| 86 | + * @param statement the query for which to build a plan. | |
| 87 | 87 | * @return an iterator of Host. The query is tried against the hosts |
| 88 | 88 | * returned by this iterator in order, until the query has been sent |
| 89 | 89 | * successfully to one of the host. |
modified driver-core/src/main/java/com/datastax/driver/core/policies/LoggingRetryPolicy.java +4 −5
| @@ -15,16 +15,15 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core.policies; |
| 17 | 17 | |
| 18 | -import org.slf4j.Logger; | |
| 19 | -import org.slf4j.LoggerFactory; | |
| 20 | - | |
| 21 | 18 | import com.datastax.driver.core.ConsistencyLevel; |
| 22 | 19 | import com.datastax.driver.core.Statement; |
| 23 | 20 | import com.datastax.driver.core.WriteType; |
| 21 | +import org.slf4j.Logger; | |
| 22 | +import org.slf4j.LoggerFactory; | |
| 24 | 23 | |
| 25 | 24 | /** |
| 26 | 25 | * A retry policy that wraps another policy, logging the decision made by its sub-policy. |
| 27 | - * <p> | |
| 26 | + * <p/> | |
| 28 | 27 | * Note that this policy only log the IGNORE and RETRY decisions (since |
| 29 | 28 | * RETHROW decisions are just meant to propagate the cassandra exception). The |
| 30 | 29 | * logging is done at the INFO level. |
| @@ -38,7 +37,7 @@ | ||
| 38 | 37 | * Creates a new {@code RetryPolicy} that logs the decision of {@code policy}. |
| 39 | 38 | * |
| 40 | 39 | * @param policy the policy to wrap. The policy created by this constructor |
| 41 | - * will return the same decision than {@code policy} but will log them. | |
| 40 | + * will return the same decision than {@code policy} but will log them. | |
| 42 | 41 | */ |
| 43 | 42 | public LoggingRetryPolicy(RetryPolicy policy) { |
| 44 | 43 | this.policy = policy; |
modified driver-core/src/main/java/com/datastax/driver/core/policies/NoSpeculativeExecutionPolicy.java +3 −1
| @@ -24,7 +24,9 @@ | ||
| 24 | 24 | */ |
| 25 | 25 | public class NoSpeculativeExecutionPolicy implements SpeculativeExecutionPolicy { |
| 26 | 26 | |
| 27 | - /** The single instance (this class is stateless). */ | |
| 27 | + /** | |
| 28 | + * The single instance (this class is stateless). | |
| 29 | + */ | |
| 28 | 30 | public static final NoSpeculativeExecutionPolicy INSTANCE = new NoSpeculativeExecutionPolicy(); |
| 29 | 31 | |
| 30 | 32 | private static final SpeculativeExecutionPlan PLAN = new SpeculativeExecutionPlan() { |
modified driver-core/src/main/java/com/datastax/driver/core/policies/PercentileSpeculativeExecutionPolicy.java +13 −14
| @@ -15,20 +15,19 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core.policies; |
| 17 | 17 | |
| 18 | -import java.util.concurrent.atomic.AtomicInteger; | |
| 19 | - | |
| 20 | -import com.google.common.annotations.Beta; | |
| 21 | - | |
| 22 | -import static com.google.common.base.Preconditions.checkArgument; | |
| 23 | - | |
| 24 | 18 | import com.datastax.driver.core.Cluster; |
| 25 | 19 | import com.datastax.driver.core.Host; |
| 26 | -import com.datastax.driver.core.Statement; | |
| 27 | 20 | import com.datastax.driver.core.PerHostPercentileTracker; |
| 21 | +import com.datastax.driver.core.Statement; | |
| 22 | +import com.google.common.annotations.Beta; | |
| 23 | + | |
| 24 | +import java.util.concurrent.atomic.AtomicInteger; | |
| 25 | + | |
| 26 | +import static com.google.common.base.Preconditions.checkArgument; | |
| 28 | 27 | |
| 29 | 28 | /** |
| 30 | 29 | * A policy that triggers speculative executions when the request to the current host is above a given percentile. |
| 31 | - * | |
| 30 | + * <p/> | |
| 32 | 31 | * This class uses a {@link PerHostPercentileTracker} that must be registered with the cluster instance: |
| 33 | 32 | * <pre> |
| 34 | 33 | * PerHostPercentileTracker tracker = PerHostPercentileTracker |
| @@ -43,7 +42,7 @@ | ||
| 43 | 42 | * </pre> |
| 44 | 43 | * You <b>must</b> register the tracker with the cluster yourself (as shown on the last line above), this class will not |
| 45 | 44 | * do it itself. |
| 46 | - * <p> | |
| 45 | + * <p/> | |
| 47 | 46 | * <b>This class is currently provided as a beta preview: it hasn't been extensively tested yet, and the API is still subject |
| 48 | 47 | * to change.</b> |
| 49 | 48 | */ |
| @@ -56,17 +55,17 @@ | ||
| 56 | 55 | /** |
| 57 | 56 | * Builds a new instance. |
| 58 | 57 | * |
| 59 | - * @param percentileTracker the component that will record latencies. Note that this policy doesn't register it with the {@code Cluster}, | |
| 60 | - * you <b>must</b> do it yourself (see the code example in this class's Javadoc). | |
| 61 | - * @param percentile the percentile that a request's latency must fall into to be considered slow (ex: {@code 99.0}). | |
| 58 | + * @param percentileTracker the component that will record latencies. Note that this policy doesn't register it with the {@code Cluster}, | |
| 59 | + * you <b>must</b> do it yourself (see the code example in this class's Javadoc). | |
| 60 | + * @param percentile the percentile that a request's latency must fall into to be considered slow (ex: {@code 99.0}). | |
| 62 | 61 | * @param maxSpeculativeExecutions the maximum number of speculative executions that will be triggered for a given request (this does not |
| 63 | 62 | * include the initial, normal request). Must be strictly positive. |
| 64 | 63 | */ |
| 65 | 64 | public PercentileSpeculativeExecutionPolicy(PerHostPercentileTracker percentileTracker, double percentile, int maxSpeculativeExecutions) { |
| 66 | 65 | checkArgument(maxSpeculativeExecutions > 0, |
| 67 | - "number of speculative executions must be strictly positive (was %d)", maxSpeculativeExecutions); | |
| 66 | + "number of speculative executions must be strictly positive (was %d)", maxSpeculativeExecutions); | |
| 68 | 67 | checkArgument(percentile >= 0.0 && percentile < 100, |
| 69 | - "percentile must be between 0.0 and 100 (was %f)"); | |
| 68 | + "percentile must be between 0.0 and 100 (was %f)"); | |
| 70 | 69 | |
| 71 | 70 | this.percentileTracker = percentileTracker; |
| 72 | 71 | this.percentile = percentile; |
modified driver-core/src/main/java/com/datastax/driver/core/policies/Policies.java +17 −17
| @@ -33,17 +33,17 @@ | ||
| 33 | 33 | |
| 34 | 34 | public Policies() { |
| 35 | 35 | this(defaultLoadBalancingPolicy(), defaultReconnectionPolicy(), defaultRetryPolicy(), |
| 36 | - defaultAddressTranslater(), defaultSpeculativeExecutionPolicy()); | |
| 36 | + defaultAddressTranslater(), defaultSpeculativeExecutionPolicy()); | |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | /** |
| 40 | 40 | * Creates a new {@code Policies} object using the provided policies. |
| 41 | - * <p> | |
| 41 | + * <p/> | |
| 42 | 42 | * This constructor use the default {@link IdentityTranslater}. |
| 43 | 43 | * |
| 44 | 44 | * @param loadBalancingPolicy the load balancing policy to use. |
| 45 | - * @param reconnectionPolicy the reconnection policy to use. | |
| 46 | - * @param retryPolicy the retry policy to use. | |
| 45 | + * @param reconnectionPolicy the reconnection policy to use. | |
| 46 | + * @param retryPolicy the retry policy to use. | |
| 47 | 47 | */ |
| 48 | 48 | public Policies(LoadBalancingPolicy loadBalancingPolicy, |
| 49 | 49 | ReconnectionPolicy reconnectionPolicy, |
| @@ -56,9 +56,9 @@ | ||
| 56 | 56 | * Creates a new {@code Policies} object using the provided policies. |
| 57 | 57 | * |
| 58 | 58 | * @param loadBalancingPolicy the load balancing policy to use. |
| 59 | - * @param reconnectionPolicy the reconnection policy to use. | |
| 60 | - * @param retryPolicy the retry policy to use. | |
| 61 | - * @param addressTranslater the address translater to use. | |
| 59 | + * @param reconnectionPolicy the reconnection policy to use. | |
| 60 | + * @param retryPolicy the retry policy to use. | |
| 61 | + * @param addressTranslater the address translater to use. | |
| 62 | 62 | */ |
| 63 | 63 | public Policies(LoadBalancingPolicy loadBalancingPolicy, |
| 64 | 64 | ReconnectionPolicy reconnectionPolicy, |
| @@ -74,12 +74,12 @@ | ||
| 74 | 74 | |
| 75 | 75 | /** |
| 76 | 76 | * The default load balancing policy. |
| 77 | - * <p> | |
| 77 | + * <p/> | |
| 78 | 78 | * The default load balancing policy is {@link DCAwareRoundRobinPolicy} with token |
| 79 | 79 | * awareness (so {@code new TokenAwarePolicy(new DCAwareRoundRobinPolicy())}). |
| 80 | - * <p> | |
| 80 | + * <p/> | |
| 81 | 81 | * Note that this policy shuffles the replicas when token awareness is used, see |
| 82 | - * {@link TokenAwarePolicy#TokenAwarePolicy(LoadBalancingPolicy,boolean)} for an | |
| 82 | + * {@link TokenAwarePolicy#TokenAwarePolicy(LoadBalancingPolicy, boolean)} for an | |
| 83 | 83 | * explanation of the tradeoffs. |
| 84 | 84 | * |
| 85 | 85 | * @return the default load balancing policy. |
| @@ -92,7 +92,7 @@ | ||
| 92 | 92 | |
| 93 | 93 | /** |
| 94 | 94 | * The default reconnection policy. |
| 95 | - * <p> | |
| 95 | + * <p/> | |
| 96 | 96 | * The default reconnection policy is an {@link ExponentialReconnectionPolicy} |
| 97 | 97 | * where the base delay is 1 second and the max delay is 10 minutes; |
| 98 | 98 | * |
| @@ -104,7 +104,7 @@ | ||
| 104 | 104 | |
| 105 | 105 | /** |
| 106 | 106 | * The default retry policy. |
| 107 | - * <p> | |
| 107 | + * <p/> | |
| 108 | 108 | * The default retry policy is {@link DefaultRetryPolicy}. |
| 109 | 109 | * |
| 110 | 110 | * @return the default retry policy. |
| @@ -115,7 +115,7 @@ | ||
| 115 | 115 | |
| 116 | 116 | /** |
| 117 | 117 | * The default address translater. |
| 118 | - * <p> | |
| 118 | + * <p/> | |
| 119 | 119 | * The default address translater is {@link IdentityTranslater}. |
| 120 | 120 | * |
| 121 | 121 | * @return the default address translater. |
| @@ -126,7 +126,7 @@ | ||
| 126 | 126 | |
| 127 | 127 | /** |
| 128 | 128 | * The default speculative retry policy. |
| 129 | - * <p> | |
| 129 | + * <p/> | |
| 130 | 130 | * The default speculative retry policy is a {@link NoSpeculativeExecutionPolicy}. |
| 131 | 131 | * |
| 132 | 132 | * @return the default speculative retry policy. |
| @@ -137,7 +137,7 @@ | ||
| 137 | 137 | |
| 138 | 138 | /** |
| 139 | 139 | * The load balancing policy in use. |
| 140 | - * <p> | |
| 140 | + * <p/> | |
| 141 | 141 | * The load balancing policy defines how Cassandra hosts are picked for queries. |
| 142 | 142 | * |
| 143 | 143 | * @return the load balancing policy in use. |
| @@ -148,7 +148,7 @@ | ||
| 148 | 148 | |
| 149 | 149 | /** |
| 150 | 150 | * The reconnection policy in use. |
| 151 | - * <p> | |
| 151 | + * <p/> | |
| 152 | 152 | * The reconnection policy defines how often the driver tries to reconnect to a dead node. |
| 153 | 153 | * |
| 154 | 154 | * @return the reconnection policy in use. |
| @@ -159,7 +159,7 @@ | ||
| 159 | 159 | |
| 160 | 160 | /** |
| 161 | 161 | * The retry policy in use. |
| 162 | - * <p> | |
| 162 | + * <p/> | |
| 163 | 163 | * The retry policy defines in which conditions a query should be |
| 164 | 164 | * automatically retries by the driver. |
| 165 | 165 | * |
modified driver-core/src/main/java/com/datastax/driver/core/policies/ReconnectionPolicy.java +4 −4
| @@ -17,18 +17,18 @@ | ||
| 17 | 17 | |
| 18 | 18 | /** |
| 19 | 19 | * Policy that decides how often the reconnection to a dead node is attempted. |
| 20 | - * | |
| 20 | + * <p/> | |
| 21 | 21 | * Each time a node is detected dead (because a connection error occurs), a new |
| 22 | 22 | * {@code ReconnectionSchedule} instance is created (through the {@link #newSchedule()}). |
| 23 | 23 | * Then each call to the {@link ReconnectionSchedule#nextDelayMs} method of |
| 24 | 24 | * this instance will decide when the next reconnection attempt to this node |
| 25 | 25 | * will be tried. |
| 26 | - * | |
| 26 | + * <p/> | |
| 27 | 27 | * Note that if the driver receives a push notification from the Cassandra cluster |
| 28 | 28 | * that a node is UP, any existing {@code ReconnectionSchedule} on that node |
| 29 | 29 | * will be cancelled and a new one will be created (in effect, the driver reset |
| 30 | 30 | * the scheduler). |
| 31 | - * | |
| 31 | + * <p/> | |
| 32 | 32 | * The default {@link ExponentialReconnectionPolicy} policy is usually |
| 33 | 33 | * adequate. |
| 34 | 34 | */ |
| @@ -48,7 +48,7 @@ | ||
| 48 | 48 | |
| 49 | 49 | /** |
| 50 | 50 | * When to attempt the next reconnection. |
| 51 | - * | |
| 51 | + * <p/> | |
| 52 | 52 | * This method will be called once when the host is detected down to |
| 53 | 53 | * schedule the first reconnection attempt, and then once after each failed |
| 54 | 54 | * reconnection attempt to schedule the next one. Hence each call to this |
modified driver-core/src/main/java/com/datastax/driver/core/policies/RetryPolicy.java +41 −34
| @@ -22,7 +22,7 @@ | ||
| 22 | 22 | /** |
| 23 | 23 | * A policy that defines a default behavior to adopt when a request returns |
| 24 | 24 | * a TimeoutException or an UnavailableException. |
| 25 | - * | |
| 25 | + * <p/> | |
| 26 | 26 | * Such policy allows to centralize the handling of query retries, allowing to |
| 27 | 27 | * minimize the need for exception catching/handling in business code. |
| 28 | 28 | */ |
| @@ -31,28 +31,32 @@ | ||
| 31 | 31 | /** |
| 32 | 32 | * A retry decision to adopt on a Cassandra exception (read/write timeout |
| 33 | 33 | * or unavailable exception). |
| 34 | - * <p> | |
| 34 | + * <p/> | |
| 35 | 35 | * There is three possible decision: |
| 36 | 36 | * <ul> |
| 37 | - * <li>RETHROW: no retry should be attempted and an exception should be thrown</li> | |
| 38 | - * <li>RETRY: the operation will be retried. The consistency level of the | |
| 39 | - * retry should be specified.</li> | |
| 40 | - * <li>IGNORE: no retry should be attempted and the exception should be | |
| 41 | - * ignored. In that case, the operation that triggered the Cassandra | |
| 42 | - * exception will return an empty result set.</li> | |
| 37 | + * <li>RETHROW: no retry should be attempted and an exception should be thrown</li> | |
| 38 | + * <li>RETRY: the operation will be retried. The consistency level of the | |
| 39 | + * retry should be specified.</li> | |
| 40 | + * <li>IGNORE: no retry should be attempted and the exception should be | |
| 41 | + * ignored. In that case, the operation that triggered the Cassandra | |
| 42 | + * exception will return an empty result set.</li> | |
| 43 | 43 | * </ul> |
| 44 | 44 | */ |
| 45 | 45 | class RetryDecision { |
| 46 | 46 | /** |
| 47 | 47 | * The type of retry decisions. |
| 48 | 48 | */ |
| 49 | - public enum Type { RETRY, RETHROW, IGNORE }; | |
| 49 | + public enum Type { | |
| 50 | + RETRY, RETHROW, IGNORE | |
| 51 | + } | |
| 52 | + | |
| 53 | + ; | |
| 50 | 54 | |
| 51 | 55 | private final Type type; |
| 52 | 56 | private final ConsistencyLevel retryCL; |
| 53 | 57 | private final boolean retryCurrent; |
| 54 | 58 | |
| 55 | - private RetryDecision(Type type, ConsistencyLevel retryCL, boolean retryCurrent){ | |
| 59 | + private RetryDecision(Type type, ConsistencyLevel retryCL, boolean retryCurrent) { | |
| 56 | 60 | this.type = type; |
| 57 | 61 | this.retryCL = retryCL; |
| 58 | 62 | this.retryCurrent = retryCurrent; |
| @@ -127,9 +131,12 @@ | ||
| 127 | 131 | @Override |
| 128 | 132 | public String toString() { |
| 129 | 133 | switch (type) { |
| 130 | - case RETRY: return "Retry at " + retryCL + " on " + (retryCurrent ? "same " : "next ") + "host."; | |
| 131 | - case RETHROW: return "Rethrow"; | |
| 132 | - case IGNORE: return "Ignore"; | |
| 134 | + case RETRY: | |
| 135 | + return "Retry at " + retryCL + " on " + (retryCurrent ? "same " : "next ") + "host."; | |
| 136 | + case RETHROW: | |
| 137 | + return "Rethrow"; | |
| 138 | + case IGNORE: | |
| 139 | + return "Ignore"; | |
| 133 | 140 | } |
| 134 | 141 | throw new AssertionError(); |
| 135 | 142 | } |
| @@ -137,21 +144,21 @@ | ||
| 137 | 144 | |
| 138 | 145 | /** |
| 139 | 146 | * Defines whether to retry and at which consistency level on a read timeout. |
| 140 | - * <p> | |
| 147 | + * <p/> | |
| 141 | 148 | * Note that this method may be called even if |
| 142 | 149 | * {@code requiredResponses >= receivedResponses} if {@code dataPresent} is |
| 143 | 150 | * {@code false} (see |
| 144 | 151 | * {@link com.datastax.driver.core.exceptions.ReadTimeoutException#wasDataRetrieved}). |
| 145 | 152 | * |
| 146 | - * @param statement the original query that timed out. | |
| 147 | - * @param cl the original consistency level of the read that timed out. | |
| 153 | + * @param statement the original query that timed out. | |
| 154 | + * @param cl the original consistency level of the read that timed out. | |
| 148 | 155 | * @param requiredResponses the number of responses that were required to |
| 149 | - * achieve the requested consistency level. | |
| 156 | + * achieve the requested consistency level. | |
| 150 | 157 | * @param receivedResponses the number of responses that had been received |
| 151 | - * by the time the timeout exception was raised. | |
| 152 | - * @param dataRetrieved whether actual data (by opposition to data checksum) | |
| 153 | - * was present in the received responses. | |
| 154 | - * @param nbRetry the number of retry already performed for this operation. | |
| 158 | + * by the time the timeout exception was raised. | |
| 159 | + * @param dataRetrieved whether actual data (by opposition to data checksum) | |
| 160 | + * was present in the received responses. | |
| 161 | + * @param nbRetry the number of retry already performed for this operation. | |
| 155 | 162 | * @return the retry decision. If {@code RetryDecision.RETHROW} is returned, |
| 156 | 163 | * a {@link com.datastax.driver.core.exceptions.ReadTimeoutException} will |
| 157 | 164 | * be thrown for the operation. |
| @@ -161,14 +168,14 @@ | ||
| 161 | 168 | /** |
| 162 | 169 | * Defines whether to retry and at which consistency level on a write timeout. |
| 163 | 170 | * |
| 164 | - * @param statement the original query that timed out. | |
| 165 | - * @param cl the original consistency level of the write that timed out. | |
| 166 | - * @param writeType the type of the write that timed out. | |
| 171 | + * @param statement the original query that timed out. | |
| 172 | + * @param cl the original consistency level of the write that timed out. | |
| 173 | + * @param writeType the type of the write that timed out. | |
| 167 | 174 | * @param requiredAcks the number of acknowledgments that were required to |
| 168 | - * achieve the requested consistency level. | |
| 175 | + * achieve the requested consistency level. | |
| 169 | 176 | * @param receivedAcks the number of acknowledgments that had been received |
| 170 | - * by the time the timeout exception was raised. | |
| 171 | - * @param nbRetry the number of retry already performed for this operation. | |
| 177 | + * by the time the timeout exception was raised. | |
| 178 | + * @param nbRetry the number of retry already performed for this operation. | |
| 172 | 179 | * @return the retry decision. If {@code RetryDecision.RETHROW} is returned, |
| 173 | 180 | * a {@link com.datastax.driver.core.exceptions.WriteTimeoutException} will |
| 174 | 181 | * be thrown for the operation. |
| @@ -179,14 +186,14 @@ | ||
| 179 | 186 | * Defines whether to retry and at which consistency level on an |
| 180 | 187 | * unavailable exception. |
| 181 | 188 | * |
| 182 | - * @param statement the original query for which the consistency level cannot | |
| 183 | - * be achieved. | |
| 184 | - * @param cl the original consistency level for the operation. | |
| 189 | + * @param statement the original query for which the consistency level cannot | |
| 190 | + * be achieved. | |
| 191 | + * @param cl the original consistency level for the operation. | |
| 185 | 192 | * @param requiredReplica the number of replica that should have been |
| 186 | - * (known) alive for the operation to be attempted. | |
| 187 | - * @param aliveReplica the number of replica that were know to be alive by | |
| 188 | - * the coordinator of the operation. | |
| 189 | - * @param nbRetry the number of retry already performed for this operation. | |
| 193 | + * (known) alive for the operation to be attempted. | |
| 194 | + * @param aliveReplica the number of replica that were know to be alive by | |
| 195 | + * the coordinator of the operation. | |
| 196 | + * @param nbRetry the number of retry already performed for this operation. | |
| 190 | 197 | * @return the retry decision. If {@code RetryDecision.RETHROW} is returned, |
| 191 | 198 | * an {@link com.datastax.driver.core.exceptions.UnavailableException} will |
| 192 | 199 | * be thrown for the operation. |
modified driver-core/src/main/java/com/datastax/driver/core/policies/RoundRobinPolicy.java +18 −26
| @@ -15,34 +15,25 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core.policies; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.*; | |
| 19 | +import com.google.common.collect.AbstractIterator; | |
| 20 | +import org.slf4j.Logger; | |
| 21 | +import org.slf4j.LoggerFactory; | |
| 22 | + | |
| 18 | 23 | import java.util.Collection; |
| 19 | 24 | import java.util.Iterator; |
| 20 | 25 | import java.util.List; |
| 21 | 26 | import java.util.Random; |
| 22 | 27 | import java.util.concurrent.CopyOnWriteArrayList; |
| 23 | -import java.util.concurrent.ExecutionException; | |
| 24 | -import java.util.concurrent.TimeUnit; | |
| 25 | -import java.util.concurrent.TimeoutException; | |
| 26 | 28 | import java.util.concurrent.atomic.AtomicInteger; |
| 27 | 29 | |
| 28 | -import com.google.common.collect.AbstractIterator; | |
| 29 | -import org.slf4j.Logger; | |
| 30 | -import org.slf4j.LoggerFactory; | |
| 31 | - | |
| 32 | -import com.datastax.driver.core.Cluster; | |
| 33 | -import com.datastax.driver.core.Configuration; | |
| 34 | -import com.datastax.driver.core.ConsistencyLevel; | |
| 35 | -import com.datastax.driver.core.Host; | |
| 36 | -import com.datastax.driver.core.HostDistance; | |
| 37 | -import com.datastax.driver.core.Statement; | |
| 38 | - | |
| 39 | 30 | /** |
| 40 | 31 | * A Round-robin load balancing policy. |
| 41 | - * <p> | |
| 32 | + * <p/> | |
| 42 | 33 | * This policy queries nodes in a round-robin fashion. For a given query, |
| 43 | 34 | * if an host fail, the next one (following the round-robin order) is |
| 44 | 35 | * tried, until all hosts have been tried. |
| 45 | - * <p> | |
| 36 | + * <p/> | |
| 46 | 37 | * This policy is not datacenter aware and will include every known |
| 47 | 38 | * Cassandra host in its round robin algorithm. If you use multiple |
| 48 | 39 | * datacenter this will be inefficient and you will want to use the |
| @@ -62,7 +53,8 @@ | ||
| 62 | 53 | * Creates a load balancing policy that picks host to query in a round robin |
| 63 | 54 | * fashion (on all the hosts of the Cassandra cluster). |
| 64 | 55 | */ |
| 65 | - public RoundRobinPolicy() {} | |
| 56 | + public RoundRobinPolicy() { | |
| 57 | + } | |
| 66 | 58 | |
| 67 | 59 | @Override |
| 68 | 60 | public void init(Cluster cluster, Collection<Host> hosts) { |
| @@ -73,7 +65,7 @@ | ||
| 73 | 65 | |
| 74 | 66 | /** |
| 75 | 67 | * Return the HostDistance for the provided host. |
| 76 | - * <p> | |
| 68 | + * <p/> | |
| 77 | 69 | * This policy consider all nodes as local. This is generally the right |
| 78 | 70 | * thing to do in a single datacenter deployment. If you use multiple |
| 79 | 71 | * datacenter, see {@link DCAwareRoundRobinPolicy} instead. |
| @@ -88,14 +80,14 @@ | ||
| 88 | 80 | |
| 89 | 81 | /** |
| 90 | 82 | * Returns the hosts to use for a new query. |
| 91 | - * <p> | |
| 83 | + * <p/> | |
| 92 | 84 | * The returned plan will try each known host of the cluster. Upon each |
| 93 | 85 | * call to this method, the {@code i}th host of the plans returned will cycle |
| 94 | 86 | * over all the hosts of the cluster in a round-robin fashion. |
| 95 | 87 | * |
| 96 | 88 | * @param loggedKeyspace the keyspace currently logged in on for this |
| 97 | - * query. | |
| 98 | - * @param statement the query for which to build the plan. | |
| 89 | + * query. | |
| 90 | + * @param statement the query for which to build the plan. | |
| 99 | 91 | * @return a new query plan, i.e. an iterator indicating which host to |
| 100 | 92 | * try first for querying, which one to use as failover, etc... |
| 101 | 93 | */ |
| @@ -104,13 +96,13 @@ | ||
| 104 | 96 | |
| 105 | 97 | if (!hasLoggedLocalCLUse) { |
| 106 | 98 | ConsistencyLevel cl = statement.getConsistencyLevel() == null |
| 107 | - ? configuration.getQueryOptions().getConsistencyLevel() | |
| 108 | - : statement.getConsistencyLevel(); | |
| 99 | + ? configuration.getQueryOptions().getConsistencyLevel() | |
| 100 | + : statement.getConsistencyLevel(); | |
| 109 | 101 | if (cl.isDCLocal()) { |
| 110 | 102 | hasLoggedLocalCLUse = true; |
| 111 | 103 | logger.warn("Detected request at Consistency Level {} but the non-DC aware RoundRobinPolicy is in use. " |
| 112 | - + "It is strongly advised to use DCAwareRoundRobinPolicy if you have multiple DCs/use DC-aware consistency levels " | |
| 113 | - + "(note: this message will only be logged once)", statement.getConsistencyLevel()); | |
| 104 | + + "It is strongly advised to use DCAwareRoundRobinPolicy if you have multiple DCs/use DC-aware consistency levels " | |
| 105 | + + "(note: this message will only be logged once)", statement.getConsistencyLevel()); | |
| 114 | 106 | } |
| 115 | 107 | } |
| 116 | 108 | |
| @@ -119,7 +111,7 @@ | ||
| 119 | 111 | // would be racy). We use clone() as it don't involve a copy of the |
| 120 | 112 | // underlying array (and thus we rely on liveHosts being a CopyOnWriteArrayList). |
| 121 | 113 | @SuppressWarnings("unchecked") |
| 122 | - final List<Host> hosts = (List<Host>)liveHosts.clone(); | |
| 114 | + final List<Host> hosts = (List<Host>) liveHosts.clone(); | |
| 123 | 115 | final int startIdx = index.getAndIncrement(); |
| 124 | 116 | |
| 125 | 117 | // Overflow protection; not theoretically thread safe but should be good enough |
modified driver-core/src/main/java/com/datastax/driver/core/policies/SpeculativeExecutionPolicy.java +7 −7
| @@ -22,7 +22,7 @@ | ||
| 22 | 22 | /** |
| 23 | 23 | * The policy that decides if the driver will send speculative queries to the next hosts when the current host takes too |
| 24 | 24 | * long to respond. |
| 25 | - * <p> | |
| 25 | + * <p/> | |
| 26 | 26 | * Note that only idempotent statements will be speculatively retried, see |
| 27 | 27 | * {@link com.datastax.driver.core.Statement#isIdempotent()} for more information. |
| 28 | 28 | */ |
| @@ -38,24 +38,24 @@ | ||
| 38 | 38 | * Returns the plan to use for a new query. |
| 39 | 39 | * |
| 40 | 40 | * @param loggedKeyspace the currently logged keyspace (the one set through either |
| 41 | - * {@link Cluster#connect(String)} or by manually doing a {@code USE} query) for | |
| 42 | - * the session on which this plan need to be built. This can be {@code null} if | |
| 43 | - * the corresponding session has no keyspace logged in. | |
| 44 | - * @param statement the query for which to build a plan. | |
| 41 | + * {@link Cluster#connect(String)} or by manually doing a {@code USE} query) for | |
| 42 | + * the session on which this plan need to be built. This can be {@code null} if | |
| 43 | + * the corresponding session has no keyspace logged in. | |
| 44 | + * @param statement the query for which to build a plan. | |
| 45 | 45 | * @return the plan. |
| 46 | 46 | */ |
| 47 | 47 | SpeculativeExecutionPlan newPlan(String loggedKeyspace, Statement statement); |
| 48 | 48 | |
| 49 | 49 | /** |
| 50 | 50 | * Gets invoked at cluster shutdown. |
| 51 | - * | |
| 51 | + * <p/> | |
| 52 | 52 | * This gives the policy the opportunity to perform some cleanup, for instance stop threads that it might have started. |
| 53 | 53 | */ |
| 54 | 54 | void close(); |
| 55 | 55 | |
| 56 | 56 | /** |
| 57 | 57 | * A plan that governs speculative executions for a given query. |
| 58 | - * <p> | |
| 58 | + * <p/> | |
| 59 | 59 | * Each time a host is queried, {@link #nextExecution(Host)} is invoked to determine if and when a speculative query to |
| 60 | 60 | * the next host will be sent. |
| 61 | 61 | */ |
modified driver-core/src/main/java/com/datastax/driver/core/policies/TokenAwarePolicy.java +18 −22
| @@ -15,31 +15,29 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core.policies; |
| 17 | 17 | |
| 18 | -import java.nio.ByteBuffer; | |
| 19 | -import java.util.*; | |
| 20 | - | |
| 21 | -import com.google.common.collect.Lists; | |
| 22 | - | |
| 18 | +import com.datastax.driver.core.*; | |
| 23 | 19 | import com.google.common.collect.AbstractIterator; |
| 20 | +import com.google.common.collect.Lists; | |
| 24 | 21 | |
| 25 | -import com.datastax.driver.core.*; | |
| 22 | +import java.nio.ByteBuffer; | |
| 23 | +import java.util.*; | |
| 26 | 24 | |
| 27 | 25 | /** |
| 28 | 26 | * A wrapper load balancing policy that add token awareness to a child policy. |
| 29 | - * <p> | |
| 27 | + * <p/> | |
| 30 | 28 | * This policy encapsulates another policy. The resulting policy works in |
| 31 | 29 | * the following way: |
| 32 | 30 | * <ul> |
| 33 | - * <li>the {@code distance} method is inherited from the child policy.</li> | |
| 34 | - * <li>the iterator return by the {@code newQueryPlan} method will first | |
| 35 | - * return the {@code LOCAL} replicas for the query (based on {@link Statement#getRoutingKey}) | |
| 36 | - * <i>if possible</i> (i.e. if the query {@code getRoutingKey} method | |
| 37 | - * doesn't return {@code null} and if {@link Metadata#getReplicas} | |
| 38 | - * returns a non empty set of replicas for that partition key). If no | |
| 39 | - * local replica can be either found or successfully contacted, the rest | |
| 40 | - * of the query plan will fallback to one of the child policy.</li> | |
| 31 | + * <li>the {@code distance} method is inherited from the child policy.</li> | |
| 32 | + * <li>the iterator return by the {@code newQueryPlan} method will first | |
| 33 | + * return the {@code LOCAL} replicas for the query (based on {@link Statement#getRoutingKey}) | |
| 34 | + * <i>if possible</i> (i.e. if the query {@code getRoutingKey} method | |
| 35 | + * doesn't return {@code null} and if {@link Metadata#getReplicas} | |
| 36 | + * returns a non empty set of replicas for that partition key). If no | |
| 37 | + * local replica can be either found or successfully contacted, the rest | |
| 38 | + * of the query plan will fallback to one of the child policy.</li> | |
| 41 | 39 | * </ul> |
| 42 | - * <p> | |
| 40 | + * <p/> | |
| 43 | 41 | * Do note that only replica for which the child policy {@code distance} |
| 44 | 42 | * method returns {@code HostDistance.LOCAL} will be considered having |
| 45 | 43 | * priority. For example, if you wrap {@link DCAwareRoundRobinPolicy} with this |
| @@ -55,7 +53,7 @@ | ||
| 55 | 53 | /** |
| 56 | 54 | * Creates a new {@code TokenAware} policy. |
| 57 | 55 | * |
| 58 | - * @param childPolicy the load balancing policy to wrap with token awareness. | |
| 56 | + * @param childPolicy the load balancing policy to wrap with token awareness. | |
| 59 | 57 | * @param shuffleReplicas whether to shuffle the replicas returned by {@code getRoutingKey}. |
| 60 | 58 | * Note that setting this parameter to {@code true} might decrease the |
| 61 | 59 | * effectiveness of caching (especially at consistency level ONE), since |
| @@ -63,7 +61,6 @@ | ||
| 63 | 61 | * "primary" replica without shuffling). |
| 64 | 62 | * On the other hand, shuffling will better distribute writes, and can |
| 65 | 63 | * alleviate hotspots caused by "fat" partitions. |
| 66 | - * | |
| 67 | 64 | */ |
| 68 | 65 | public TokenAwarePolicy(LoadBalancingPolicy childPolicy, boolean shuffleReplicas) { |
| 69 | 66 | this.childPolicy = childPolicy; |
| @@ -74,8 +71,7 @@ | ||
| 74 | 71 | * Creates a new {@code TokenAware} policy with shuffling of replicas. |
| 75 | 72 | * |
| 76 | 73 | * @param childPolicy the load balancing policy to wrap with token |
| 77 | - * awareness. | |
| 78 | - * | |
| 74 | + * awareness. | |
| 79 | 75 | * @see #TokenAwarePolicy(LoadBalancingPolicy, boolean) |
| 80 | 76 | */ |
| 81 | 77 | public TokenAwarePolicy(LoadBalancingPolicy childPolicy) { |
| @@ -106,7 +102,7 @@ | ||
| 106 | 102 | |
| 107 | 103 | /** |
| 108 | 104 | * Returns the hosts to use for a new query. |
| 109 | - * <p> | |
| 105 | + * <p/> | |
| 110 | 106 | * The returned plan will first return replicas (whose {@code HostDistance} |
| 111 | 107 | * for the child policy is {@code LOCAL}) for the query if it can determine |
| 112 | 108 | * them (i.e. mainly if {@code statement.getRoutingKey()} is not {@code null}). |
| @@ -193,6 +189,6 @@ | ||
| 193 | 189 | @Override |
| 194 | 190 | public void close() { |
| 195 | 191 | if (childPolicy instanceof CloseableLoadBalancingPolicy) |
| 196 | - ((CloseableLoadBalancingPolicy)childPolicy).close(); | |
| 192 | + ((CloseableLoadBalancingPolicy) childPolicy).close(); | |
| 197 | 193 | } |
| 198 | 194 | } |
modified driver-core/src/main/java/com/datastax/driver/core/policies/WhiteListPolicy.java +7 −8
| @@ -15,24 +15,23 @@ | ||
| 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.Host; | |
| 21 | 19 | import com.google.common.base.Predicate; |
| 22 | 20 | import com.google.common.collect.ImmutableSet; |
| 23 | 21 | |
| 24 | -import com.datastax.driver.core.Host; | |
| 22 | +import java.net.InetSocketAddress; | |
| 23 | +import java.util.Collection; | |
| 25 | 24 | |
| 26 | 25 | /** |
| 27 | 26 | * A load balancing policy wrapper that ensure that only hosts from a provided |
| 28 | 27 | * white list will ever be returned. |
| 29 | - * <p> | |
| 28 | + * <p/> | |
| 30 | 29 | * This policy wraps another load balancing policy and will delegate the choice |
| 31 | 30 | * of hosts to the wrapped policy with the exception that only hosts contained |
| 32 | 31 | * in the white list provided when constructing this policy will ever be |
| 33 | 32 | * returned. Any host not in the while list will be considered {@code IGNORED} |
| 34 | 33 | * and thus will not be connected to. |
| 35 | - * <p> | |
| 34 | + * <p/> | |
| 36 | 35 | * This policy can be useful to ensure that the driver only connects to a |
| 37 | 36 | * predefined set of hosts. Keep in mind however that this policy defeats |
| 38 | 37 | * somewhat the host auto-detection of the driver. As such, this policy is only |
| @@ -50,8 +49,8 @@ | ||
| 50 | 49 | * from the provided while list. |
| 51 | 50 | * |
| 52 | 51 | * @param childPolicy the wrapped policy. |
| 53 | - * @param whiteList the white listed hosts. Only hosts from this list may get connected | |
| 54 | - * to (whether they will get connected to or not depends on the child policy). | |
| 52 | + * @param whiteList the white listed hosts. Only hosts from this list may get connected | |
| 53 | + * to (whether they will get connected to or not depends on the child policy). | |
| 55 | 54 | */ |
| 56 | 55 | public WhiteListPolicy(LoadBalancingPolicy childPolicy, Collection<InetSocketAddress> whiteList) { |
| 57 | 56 | super(childPolicy, buildPredicate(whiteList)); |
modified driver-core/src/main/java/com/datastax/driver/core/querybuilder/Assignment.java +2 −2
| @@ -64,8 +64,8 @@ | ||
| 64 | 64 | |
| 65 | 65 | CounterAssignment(String name, Object value, boolean isIncr) { |
| 66 | 66 | super(name); |
| 67 | - if (!isIncr && value instanceof Long && ((Long)value) < 0) { | |
| 68 | - this.value = -((Long)value); | |
| 67 | + if (!isIncr && value instanceof Long && ((Long) value) < 0) { | |
| 68 | + this.value = -((Long) value); | |
| 69 | 69 | this.isIncr = true; |
| 70 | 70 | } else { |
| 71 | 71 | this.value = value; |
modified driver-core/src/main/java/com/datastax/driver/core/querybuilder/Batch.java +13 −19
| @@ -15,13 +15,12 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core.querybuilder; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.RegularStatement; | |
| 19 | + | |
| 18 | 20 | import java.nio.ByteBuffer; |
| 19 | 21 | import java.util.ArrayList; |
| 20 | -import java.util.Collections; | |
| 21 | 22 | import java.util.List; |
| 22 | 23 | |
| 23 | -import com.datastax.driver.core.RegularStatement; | |
| 24 | - | |
| 25 | 24 | /** |
| 26 | 25 | * A built BATCH statement. |
| 27 | 26 | */ |
| @@ -36,10 +35,10 @@ | ||
| 36 | 35 | private int nonBuiltStatementValues; |
| 37 | 36 | |
| 38 | 37 | Batch(RegularStatement[] statements, boolean logged) { |
| 39 | - super((String)null); | |
| 38 | + super((String) null); | |
| 40 | 39 | this.statements = statements.length == 0 |
| 41 | - ? new ArrayList<RegularStatement>() | |
| 42 | - : new ArrayList<RegularStatement>(statements.length); | |
| 40 | + ? new ArrayList<RegularStatement>() | |
| 41 | + : new ArrayList<RegularStatement>(statements.length); | |
| 43 | 42 | this.logged = logged; |
| 44 | 43 | this.usings = new Options(this); |
| 45 | 44 | |
| @@ -52,8 +51,8 @@ | ||
| 52 | 51 | StringBuilder builder = new StringBuilder(); |
| 53 | 52 | |
| 54 | 53 | builder.append(isCounterOp() |
| 55 | - ? "BEGIN COUNTER BATCH" | |
| 56 | - : (logged ? "BEGIN BATCH" : "BEGIN UNLOGGED BATCH")); | |
| 54 | + ? "BEGIN COUNTER BATCH" | |
| 55 | + : (logged ? "BEGIN BATCH" : "BEGIN UNLOGGED BATCH")); | |
| 57 | 56 | |
| 58 | 57 | if (!usings.usings.isEmpty()) { |
| 59 | 58 | builder.append(" USING "); |
| @@ -64,7 +63,7 @@ | ||
| 64 | 63 | for (int i = 0; i < statements.size(); i++) { |
| 65 | 64 | RegularStatement stmt = statements.get(i); |
| 66 | 65 | if (stmt instanceof BuiltStatement) { |
| 67 | - BuiltStatement bst = (BuiltStatement)stmt; | |
| 66 | + BuiltStatement bst = (BuiltStatement) stmt; | |
| 68 | 67 | builder.append(maybeAddSemicolon(bst.buildQueryString(variables))); |
| 69 | 68 | |
| 70 | 69 | } else { |
| @@ -87,9 +86,8 @@ | ||
| 87 | 86 | * |
| 88 | 87 | * @param statement the new statement to add. |
| 89 | 88 | * @return this batch. |
| 90 | - * | |
| 91 | 89 | * @throws IllegalArgumentException if counter and non-counter operations |
| 92 | - * are mixed. | |
| 90 | + * are mixed. | |
| 93 | 91 | */ |
| 94 | 92 | public Batch add(RegularStatement statement) { |
| 95 | 93 | boolean isCounterOp = statement instanceof BuiltStatement && ((BuiltStatement) statement).isCounterOp(); |
| @@ -101,12 +99,9 @@ | ||
| 101 | 99 | |
| 102 | 100 | this.statements.add(statement); |
| 103 | 101 | |
| 104 | - if (statement instanceof BuiltStatement) | |
| 105 | - { | |
| 106 | - this.hasBindMarkers |= ((BuiltStatement)statement).hasBindMarkers; | |
| 107 | - } | |
| 108 | - else | |
| 109 | - { | |
| 102 | + if (statement instanceof BuiltStatement) { | |
| 103 | + this.hasBindMarkers |= ((BuiltStatement) statement).hasBindMarkers; | |
| 104 | + } else { | |
| 110 | 105 | // For non-BuiltStatement, we cannot know if it includes a bind makers and we assume it does. In practice, |
| 111 | 106 | // this means we will always serialize values as strings when there is non-BuiltStatement |
| 112 | 107 | this.hasBindMarkers = true; |
| @@ -134,8 +129,7 @@ | ||
| 134 | 129 | |
| 135 | 130 | ByteBuffer[] values = new ByteBuffer[nonBuiltStatementValues]; |
| 136 | 131 | int i = 0; |
| 137 | - for (RegularStatement statement : statements) | |
| 138 | - { | |
| 132 | + for (RegularStatement statement : statements) { | |
| 139 | 133 | if (statement instanceof BuiltStatement) |
| 140 | 134 | continue; |
| 141 | 135 |
modified driver-core/src/main/java/com/datastax/driver/core/querybuilder/BindMarker.java +2 −2
| @@ -17,10 +17,10 @@ | ||
| 17 | 17 | |
| 18 | 18 | /** |
| 19 | 19 | * A CQL3 bind marker. |
| 20 | - * <p> | |
| 20 | + * <p/> | |
| 21 | 21 | * This can be either an anonymous bind marker or a named one (but note that |
| 22 | 22 | * named ones are only supported starting in Cassandra 2.0.1). |
| 23 | - * <p> | |
| 23 | + * <p/> | |
| 24 | 24 | * Please note that to create a new bind maker object you should use |
| 25 | 25 | * {@link QueryBuilder#bindMarker()} (anonymous marker) or |
| 26 | 26 | * {@link QueryBuilder#bindMarker(String)} (named marker). |
modified driver-core/src/main/java/com/datastax/driver/core/querybuilder/BuiltStatement.java +11 −13
| @@ -15,14 +15,14 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core.querybuilder; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.*; | |
| 19 | +import com.datastax.driver.core.policies.RetryPolicy; | |
| 20 | + | |
| 18 | 21 | import java.nio.ByteBuffer; |
| 19 | 22 | import java.util.ArrayList; |
| 20 | 23 | import java.util.List; |
| 21 | 24 | import java.util.regex.Pattern; |
| 22 | 25 | |
| 23 | -import com.datastax.driver.core.*; | |
| 24 | -import com.datastax.driver.core.policies.RetryPolicy; | |
| 25 | - | |
| 26 | 26 | /** |
| 27 | 27 | * Common ancestor to the query builder built statements. |
| 28 | 28 | */ |
| @@ -75,8 +75,7 @@ | ||
| 75 | 75 | * |
| 76 | 76 | * @param i the index to retrieve. |
| 77 | 77 | * @return the value of the {@code i}th value of this statement. |
| 78 | - * | |
| 79 | - * @throws IllegalStateException if this statement does not have values. | |
| 78 | + * @throws IllegalStateException if this statement does not have values. | |
| 80 | 79 | * @throws IndexOutOfBoundsException if {@code i} is not a valid index for this object. |
| 81 | 80 | */ |
| 82 | 81 | public Object getObject(int i) { |
| @@ -182,8 +181,8 @@ | ||
| 182 | 181 | return null; |
| 183 | 182 | |
| 184 | 183 | return routingKey.length == 1 |
| 185 | - ? routingKey[0] | |
| 186 | - : compose(routingKey); | |
| 184 | + ? routingKey[0] | |
| 185 | + : compose(routingKey); | |
| 187 | 186 | } |
| 188 | 187 | |
| 189 | 188 | @Override |
| @@ -217,7 +216,7 @@ | ||
| 217 | 216 | |
| 218 | 217 | /** |
| 219 | 218 | * Allows to force this builder to not generate values (through its {@code getValues()} method). |
| 220 | - * <p> | |
| 219 | + * <p/> | |
| 221 | 220 | * By default (and unless the protocol version 1 is in use, see below) and |
| 222 | 221 | * for performance reasons, the query builder will not serialize all values |
| 223 | 222 | * provided to strings. This means that the {@link #getQueryString} may |
| @@ -230,13 +229,13 @@ | ||
| 230 | 229 | * return {@code null} and that the string returned by {@code |
| 231 | 230 | * getQueryString()} will contain no other bind markers than the one |
| 232 | 231 | * inputted by the user. |
| 233 | - * <p> | |
| 232 | + * <p/> | |
| 234 | 233 | * If the native protocol version 1 is in use, the driver will default |
| 235 | 234 | * to not generating values since those are not supported by that version of |
| 236 | 235 | * the protocol. In practice, the driver will automatically call this method |
| 237 | 236 | * with {@code true} as argument prior to execution. Hence, calling this |
| 238 | 237 | * method when the protocol version 1 is in use is basically a no-op. |
| 239 | - * <p> | |
| 238 | + * <p/> | |
| 240 | 239 | * Note that this method is mainly useful for debugging purpose. In general, |
| 241 | 240 | * the default behavior should be the correct and most efficient one. |
| 242 | 241 | * |
| @@ -256,8 +255,7 @@ | ||
| 256 | 255 | totalLength += 2 + bb.remaining() + 1; |
| 257 | 256 | |
| 258 | 257 | ByteBuffer out = ByteBuffer.allocate(totalLength); |
| 259 | - for (ByteBuffer buffer : buffers) | |
| 260 | - { | |
| 258 | + for (ByteBuffer buffer : buffers) { | |
| 261 | 259 | ByteBuffer bb = buffer.duplicate(); |
| 262 | 260 | putShortLength(out, bb.remaining()); |
| 263 | 261 | out.put(bb); |
| @@ -280,7 +278,7 @@ | ||
| 280 | 278 | T statement; |
| 281 | 279 | |
| 282 | 280 | ForwardingStatement(T statement) { |
| 283 | - super((String)null); | |
| 281 | + super((String) null); | |
| 284 | 282 | this.statement = statement; |
| 285 | 283 | } |
| 286 | 284 |
modified driver-core/src/main/java/com/datastax/driver/core/querybuilder/Clause.java +1 −0
| @@ -20,6 +20,7 @@ | ||
| 20 | 20 | public abstract class Clause extends Utils.Appendeable { |
| 21 | 21 | |
| 22 | 22 | abstract String name(); |
| 23 | + | |
| 23 | 24 | abstract Object firstValue(); |
| 24 | 25 | |
| 25 | 26 | private static abstract class AbstractClause extends Clause { |
modified driver-core/src/main/java/com/datastax/driver/core/querybuilder/Delete.java +14 −16
| @@ -15,11 +15,11 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core.querybuilder; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.TableMetadata; | |
| 19 | + | |
| 18 | 20 | import java.util.ArrayList; |
| 19 | 21 | import java.util.List; |
| 20 | 22 | |
| 21 | -import com.datastax.driver.core.TableMetadata; | |
| 22 | - | |
| 23 | 23 | /** |
| 24 | 24 | * A built DELETE statement. |
| 25 | 25 | */ |
| @@ -86,7 +86,7 @@ | ||
| 86 | 86 | |
| 87 | 87 | /** |
| 88 | 88 | * Adds a WHERE clause to this statement. |
| 89 | - * | |
| 89 | + * <p/> | |
| 90 | 90 | * This is a shorter/more readable version for {@code where().and(clause)}. |
| 91 | 91 | * |
| 92 | 92 | * @param clause the clause to add. |
| @@ -107,7 +107,7 @@ | ||
| 107 | 107 | |
| 108 | 108 | /** |
| 109 | 109 | * Adds a conditions clause (IF) to this statement. |
| 110 | - * <p> | |
| 110 | + * <p/> | |
| 111 | 111 | * This is a shorter/more readable version for {@code onlyIf().and(condition)}. |
| 112 | 112 | * |
| 113 | 113 | * @param condition the condition to add. |
| @@ -138,7 +138,7 @@ | ||
| 138 | 138 | |
| 139 | 139 | /** |
| 140 | 140 | * Sets the 'IF EXISTS' option for this DELETE statement. |
| 141 | - * | |
| 141 | + * <p/> | |
| 142 | 142 | * <p> |
| 143 | 143 | * A delete with that option will report whether the statement actually |
| 144 | 144 | * resulted in data being deleted. The existence check and deletion are |
| @@ -174,8 +174,7 @@ | ||
| 174 | 174 | * @param clause the clause to add. |
| 175 | 175 | * @return this WHERE clause. |
| 176 | 176 | */ |
| 177 | - public Where and(Clause clause) | |
| 178 | - { | |
| 177 | + public Where and(Clause clause) { | |
| 179 | 178 | clauses.add(clause); |
| 180 | 179 | statement.maybeAddRoutingKey(clause.name(), clause.firstValue()); |
| 181 | 180 | checkForBindMarkers(clause); |
| @@ -195,7 +194,7 @@ | ||
| 195 | 194 | /** |
| 196 | 195 | * Sets the 'IF EXISTS' option for the DELETE statement this WHERE clause |
| 197 | 196 | * is part of. |
| 198 | - * | |
| 197 | + * <p/> | |
| 199 | 198 | * <p> |
| 200 | 199 | * A delete with that option will report whether the statement actually |
| 201 | 200 | * resulted in data being deleted. The existence check and deletion are |
| @@ -288,7 +287,7 @@ | ||
| 288 | 287 | * Adds the table to delete from. |
| 289 | 288 | * |
| 290 | 289 | * @param keyspace the name of the keyspace to delete from. |
| 291 | - * @param table the name of the table to delete from. | |
| 290 | + * @param table the name of the table to delete from. | |
| 292 | 291 | * @return a newly built DELETE statement that deletes from {@code keyspace.table}. |
| 293 | 292 | */ |
| 294 | 293 | public Delete from(String keyspace, String table) { |
| @@ -315,7 +314,6 @@ | ||
| 315 | 314 | * Deletes all columns (i.e. "DELETE FROM ...") |
| 316 | 315 | * |
| 317 | 316 | * @return an in-build DELETE statement. |
| 318 | - * | |
| 319 | 317 | * @throws IllegalStateException if some columns had already been selected for this builder. |
| 320 | 318 | */ |
| 321 | 319 | public Builder all() { |
| @@ -340,7 +338,7 @@ | ||
| 340 | 338 | * Deletes the provided list element. |
| 341 | 339 | * |
| 342 | 340 | * @param columnName the name of the list column. |
| 343 | - * @param idx the index of the element to delete. | |
| 341 | + * @param idx the index of the element to delete. | |
| 344 | 342 | * @return this in-build DELETE Selection |
| 345 | 343 | */ |
| 346 | 344 | public Selection listElt(String columnName, int idx) { |
| @@ -353,7 +351,7 @@ | ||
| 353 | 351 | * specified as a bind marker. |
| 354 | 352 | * |
| 355 | 353 | * @param columnName the name of the list column. |
| 356 | - * @param idx the index of the element to delete. | |
| 354 | + * @param idx the index of the element to delete. | |
| 357 | 355 | * @return this in-build DELETE Selection |
| 358 | 356 | */ |
| 359 | 357 | public Selection listElt(String columnName, BindMarker idx) { |
| @@ -365,7 +363,7 @@ | ||
| 365 | 363 | * Deletes the provided set element. |
| 366 | 364 | * |
| 367 | 365 | * @param columnName the name of the set column. |
| 368 | - * @param element the element to delete. | |
| 366 | + * @param element the element to delete. | |
| 369 | 367 | * @return this in-build DELETE Selection |
| 370 | 368 | */ |
| 371 | 369 | public Selection setElt(String columnName, Object element) { |
| @@ -378,7 +376,7 @@ | ||
| 378 | 376 | * specified as a bind marker. |
| 379 | 377 | * |
| 380 | 378 | * @param columnName the name of the set column. |
| 381 | - * @param element the element to delete. | |
| 379 | + * @param element the element to delete. | |
| 382 | 380 | * @return this in-build DELETE Selection |
| 383 | 381 | */ |
| 384 | 382 | public Selection setElt(String columnName, BindMarker element) { |
| @@ -390,7 +388,7 @@ | ||
| 390 | 388 | * Deletes a map element given a key. |
| 391 | 389 | * |
| 392 | 390 | * @param columnName the name of the map column. |
| 393 | - * @param key the key for the element to delete. | |
| 391 | + * @param key the key for the element to delete. | |
| 394 | 392 | * @return this in-build DELETE Selection |
| 395 | 393 | */ |
| 396 | 394 | public Selection mapElt(String columnName, Object key) { |
| @@ -478,7 +476,7 @@ | ||
| 478 | 476 | |
| 479 | 477 | /** |
| 480 | 478 | * Adds the provided condition for the deletion. |
| 481 | - * <p> | |
| 479 | + * <p/> | |
| 482 | 480 | * Note that while the query builder accept any type of {@code Clause} |
| 483 | 481 | * as conditions, Cassandra currently only allows equality ones. |
| 484 | 482 | * |
modified driver-core/src/main/java/com/datastax/driver/core/querybuilder/Insert.java +15 −17
| @@ -15,13 +15,12 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core.querybuilder; |
| 17 | 17 | |
| 18 | -import java.nio.ByteBuffer; | |
| 18 | +import com.datastax.driver.core.TableMetadata; | |
| 19 | + | |
| 19 | 20 | import java.util.ArrayList; |
| 20 | 21 | import java.util.Arrays; |
| 21 | 22 | import java.util.List; |
| 22 | 23 | |
| 23 | -import com.datastax.driver.core.TableMetadata; | |
| 24 | - | |
| 25 | 24 | /** |
| 26 | 25 | * A built INSERT statement. |
| 27 | 26 | */ |
| @@ -72,7 +71,7 @@ | ||
| 72 | 71 | /** |
| 73 | 72 | * Adds a column/value pair to the values inserted by this INSERT statement. |
| 74 | 73 | * |
| 75 | - * @param name the name of the column to insert/update. | |
| 74 | + * @param name the name of the column to insert/update. | |
| 76 | 75 | * @param value the value to insert/update for {@code name}. |
| 77 | 76 | * @return this INSERT statement. |
| 78 | 77 | */ |
| @@ -89,10 +88,10 @@ | ||
| 89 | 88 | /** |
| 90 | 89 | * Adds multiple column/value pairs to the values inserted by this INSERT statement. |
| 91 | 90 | * |
| 92 | - * @param names a list of column names to insert/update. | |
| 91 | + * @param names a list of column names to insert/update. | |
| 93 | 92 | * @param values a list of values to insert/update. The {@code i}th |
| 94 | - * value in {@code values} will be inserted for the {@code i}th column | |
| 95 | - * in {@code names}. | |
| 93 | + * value in {@code values} will be inserted for the {@code i}th column | |
| 94 | + * in {@code names}. | |
| 96 | 95 | * @return this INSERT statement. |
| 97 | 96 | * @throws IllegalArgumentException if {@code names.length != values.length}. |
| 98 | 97 | */ |
| @@ -103,10 +102,10 @@ | ||
| 103 | 102 | /** |
| 104 | 103 | * Adds multiple column/value pairs to the values inserted by this INSERT statement. |
| 105 | 104 | * |
| 106 | - * @param names a list of column names to insert/update. | |
| 105 | + * @param names a list of column names to insert/update. | |
| 107 | 106 | * @param values a list of values to insert/update. The {@code i}th |
| 108 | - * value in {@code values} will be inserted for the {@code i}th column | |
| 109 | - * in {@code names}. | |
| 107 | + * value in {@code values} will be inserted for the {@code i}th column | |
| 108 | + * in {@code names}. | |
| 110 | 109 | * @return this INSERT statement. |
| 111 | 110 | * @throws IllegalArgumentException if {@code names.size() != values.size()}. |
| 112 | 111 | */ |
| @@ -137,13 +136,13 @@ | ||
| 137 | 136 | |
| 138 | 137 | /** |
| 139 | 138 | * Sets the 'IF NOT EXISTS' option for this INSERT statement. |
| 140 | - * <p> | |
| 139 | + * <p/> | |
| 141 | 140 | * An insert with that option will not succeed unless the row does not |
| 142 | 141 | * exist at the time the insertion is executed. The existence check and |
| 143 | 142 | * insertions are done transactionally in the sense that if multiple |
| 144 | 143 | * clients attempt to create a given row with this option, then at most one |
| 145 | 144 | * may succeed. |
| 146 | - * <p> | |
| 145 | + * <p/> | |
| 147 | 146 | * Please keep in mind that using this option has a non negligible |
| 148 | 147 | * performance impact and should be avoided when possible. |
| 149 | 148 | * |
| @@ -180,7 +179,7 @@ | ||
| 180 | 179 | /** |
| 181 | 180 | * Adds a column/value pair to the values inserted by this INSERT statement. |
| 182 | 181 | * |
| 183 | - * @param name the name of the column to insert/update. | |
| 182 | + * @param name the name of the column to insert/update. | |
| 184 | 183 | * @param value the value to insert/update for {@code name}. |
| 185 | 184 | * @return the INSERT statement those options are part of. |
| 186 | 185 | */ |
| @@ -191,12 +190,11 @@ | ||
| 191 | 190 | /** |
| 192 | 191 | * Adds multiple column/value pairs to the values inserted by this INSERT statement. |
| 193 | 192 | * |
| 194 | - * @param names a list of column names to insert/update. | |
| 193 | + * @param names a list of column names to insert/update. | |
| 195 | 194 | * @param values a list of values to insert/update. The {@code i}th |
| 196 | - * value in {@code values} will be inserted for the {@code i}th column | |
| 197 | - * in {@code names}. | |
| 195 | + * value in {@code values} will be inserted for the {@code i}th column | |
| 196 | + * in {@code names}. | |
| 198 | 197 | * @return the INSERT statement those options are part of. |
| 199 | - * | |
| 200 | 198 | * @throws IllegalArgumentException if {@code names.length != values.length}. |
| 201 | 199 | */ |
| 202 | 200 | public Insert values(String[] names, Object[] values) { |
modified driver-core/src/main/java/com/datastax/driver/core/querybuilder/Ordering.java +0 −1
| @@ -15,7 +15,6 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core.querybuilder; |
| 17 | 17 | |
| 18 | -import java.nio.ByteBuffer; | |
| 19 | 18 | import java.util.List; |
| 20 | 19 | |
| 21 | 20 | public class Ordering extends Utils.Appendeable { |
modified driver-core/src/main/java/com/datastax/driver/core/querybuilder/QueryBuilder.java +101 −106
| @@ -15,34 +15,35 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core.querybuilder; |
| 17 | 17 | |
| 18 | -import java.util.*; | |
| 19 | - | |
| 20 | 18 | import com.datastax.driver.core.RegularStatement; |
| 21 | 19 | import com.datastax.driver.core.TableMetadata; |
| 22 | 20 | import com.datastax.driver.core.exceptions.InvalidQueryException; |
| 23 | 21 | |
| 22 | +import java.util.*; | |
| 23 | + | |
| 24 | 24 | /** |
| 25 | 25 | * Static methods to build a CQL3 query. |
| 26 | - * <p> | |
| 26 | + * <p/> | |
| 27 | 27 | * The queries built by this builder will provide a value for the |
| 28 | 28 | * {@link com.datastax.driver.core.Statement#getRoutingKey} method only when a |
| 29 | 29 | * {@link com.datastax.driver.core.TableMetadata} is provided to the builder. |
| 30 | 30 | * It is thus advised to do so if a {@link com.datastax.driver.core.policies.TokenAwarePolicy} |
| 31 | 31 | * is in use. |
| 32 | - * <p> | |
| 32 | + * <p/> | |
| 33 | 33 | * The provider builders perform very little validation of the built query. |
| 34 | 34 | * There is thus no guarantee that a built query is valid, and it is |
| 35 | 35 | * definitively possible to create invalid queries. |
| 36 | - * <p> | |
| 36 | + * <p/> | |
| 37 | 37 | * Note that it could be convenient to use an 'import static' to use the methods of this class. |
| 38 | 38 | */ |
| 39 | 39 | public final class QueryBuilder { |
| 40 | 40 | |
| 41 | - private QueryBuilder() {} | |
| 41 | + private QueryBuilder() { | |
| 42 | + } | |
| 42 | 43 | |
| 43 | 44 | /** |
| 44 | 45 | * Start building a new SELECT query that selects the provided names. |
| 45 | - * | |
| 46 | + * <p/> | |
| 46 | 47 | * Note that {@code select(c1, c2)} is just a shortcut for {@code select().column(c1).column(c2) }. |
| 47 | 48 | * |
| 48 | 49 | * @param columns the columns names that should be selected by the query. |
| @@ -50,7 +51,7 @@ | ||
| 50 | 51 | * least a FROM clause to complete the query). |
| 51 | 52 | */ |
| 52 | 53 | public static Select.Builder select(String... columns) { |
| 53 | - return new Select.Builder(Arrays.asList((Object[])columns)); | |
| 54 | + return new Select.Builder(Arrays.asList((Object[]) columns)); | |
| 54 | 55 | } |
| 55 | 56 | |
| 56 | 57 | /** |
| @@ -78,7 +79,7 @@ | ||
| 78 | 79 | * Start building a new INSERT query. |
| 79 | 80 | * |
| 80 | 81 | * @param keyspace the name of the keyspace to use. |
| 81 | - * @param table the name of the table to insert into. | |
| 82 | + * @param table the name of the table to insert into. | |
| 82 | 83 | * @return an in-construction INSERT query. |
| 83 | 84 | */ |
| 84 | 85 | public static Insert insertInto(String keyspace, String table) { |
| @@ -110,7 +111,7 @@ | ||
| 110 | 111 | * Start building a new UPDATE query. |
| 111 | 112 | * |
| 112 | 113 | * @param keyspace the name of the keyspace to use. |
| 113 | - * @param table the name of the table to update. | |
| 114 | + * @param table the name of the table to update. | |
| 114 | 115 | * @return an in-construction UPDATE query (at least a SET and a WHERE |
| 115 | 116 | * clause needs to be provided to complete the query). |
| 116 | 117 | */ |
| @@ -153,7 +154,7 @@ | ||
| 153 | 154 | |
| 154 | 155 | /** |
| 155 | 156 | * Built a new BATCH query on the provided statements. |
| 156 | - * <p> | |
| 157 | + * <p/> | |
| 157 | 158 | * This method will build a logged batch (this is the default in CQL3). To |
| 158 | 159 | * create unlogged batches, use {@link #unloggedBatch}. Also note that |
| 159 | 160 | * for convenience, if the provided statements are counter statements, this |
| @@ -170,14 +171,14 @@ | ||
| 170 | 171 | |
| 171 | 172 | /** |
| 172 | 173 | * Built a new UNLOGGED BATCH query on the provided statements. |
| 173 | - * <p> | |
| 174 | + * <p/> | |
| 174 | 175 | * Compared to logged batches (the default), unlogged batch don't |
| 175 | 176 | * use the distributed batch log server side and as such are not |
| 176 | 177 | * guaranteed to be atomic. In other words, if an unlogged batch |
| 177 | 178 | * timeout, some of the batched statements may have been persisted |
| 178 | 179 | * while some have not. Unlogged batch will however be slightly |
| 179 | 180 | * faster than logged batch. |
| 180 | - * <p> | |
| 181 | + * <p/> | |
| 181 | 182 | * If the statements added to the batch are counter statements, the |
| 182 | 183 | * resulting batch will be a COUNTER one. |
| 183 | 184 | * |
| @@ -203,7 +204,7 @@ | ||
| 203 | 204 | * Creates a new TRUNCATE query. |
| 204 | 205 | * |
| 205 | 206 | * @param keyspace the name of the keyspace to use. |
| 206 | - * @param table the name of the table to truncate. | |
| 207 | + * @param table the name of the table to truncate. | |
| 207 | 208 | * @return the truncation query. |
| 208 | 209 | */ |
| 209 | 210 | public static Truncate truncate(String keyspace, String table) { |
| @@ -246,7 +247,7 @@ | ||
| 246 | 247 | |
| 247 | 248 | /** |
| 248 | 249 | * The token of column names. |
| 249 | - * <p> | |
| 250 | + * <p/> | |
| 250 | 251 | * This variant is most useful when the partition key is composite. |
| 251 | 252 | * |
| 252 | 253 | * @param columnNames the column names to take the token of. |
| @@ -255,7 +256,7 @@ | ||
| 255 | 256 | public static String token(String... columnNames) { |
| 256 | 257 | StringBuilder sb = new StringBuilder(); |
| 257 | 258 | sb.append("token("); |
| 258 | - Utils.joinAndAppendNames(sb, ",", Arrays.asList((Object[])columnNames)); | |
| 259 | + Utils.joinAndAppendNames(sb, ",", Arrays.asList((Object[]) columnNames)); | |
| 259 | 260 | sb.append(')'); |
| 260 | 261 | return sb.toString(); |
| 261 | 262 | } |
| @@ -264,7 +265,7 @@ | ||
| 264 | 265 | * Creates an "equal" where clause stating the provided column must be |
| 265 | 266 | * equal to the provided value. |
| 266 | 267 | * |
| 267 | - * @param name the column name | |
| 268 | + * @param name the column name | |
| 268 | 269 | * @param value the value |
| 269 | 270 | * @return the corresponding where clause. |
| 270 | 271 | */ |
| @@ -276,31 +277,31 @@ | ||
| 276 | 277 | * Create an "in" where clause stating the provided column must be equal |
| 277 | 278 | * to one of the provided values. |
| 278 | 279 | * |
| 279 | - * @param name the column name | |
| 280 | + * @param name the column name | |
| 280 | 281 | * @param values the values |
| 281 | 282 | * @return the corresponding where clause. |
| 282 | 283 | */ |
| 283 | 284 | public static Clause in(String name, Object... values) { |
| 284 | 285 | return new Clause.InClause(name, Arrays.asList(values)); |
| 285 | 286 | } |
| 286 | - | |
| 287 | + | |
| 287 | 288 | /** |
| 288 | 289 | * Create an "in" where clause stating the provided column must be equal |
| 289 | 290 | * to one of the provided values. |
| 290 | 291 | * |
| 291 | - * @param name the column name | |
| 292 | + * @param name the column name | |
| 292 | 293 | * @param values the values |
| 293 | 294 | * @return the corresponding where clause. |
| 294 | 295 | */ |
| 295 | - public static Clause in(String name, List<?> values) { | |
| 296 | - return new Clause.InClause(name, values); | |
| 297 | - } | |
| 296 | + public static Clause in(String name, List<?> values) { | |
| 297 | + return new Clause.InClause(name, values); | |
| 298 | + } | |
| 298 | 299 | |
| 299 | 300 | /** |
| 300 | 301 | * Creates a "lesser than" where clause stating the provided column must be less than |
| 301 | 302 | * the provided value. |
| 302 | 303 | * |
| 303 | - * @param name the column name | |
| 304 | + * @param name the column name | |
| 304 | 305 | * @param value the value |
| 305 | 306 | * @return the corresponding where clause. |
| 306 | 307 | */ |
| @@ -310,16 +311,15 @@ | ||
| 310 | 311 | |
| 311 | 312 | /** |
| 312 | 313 | * Creates a "lesser than" where clause for a group of clustering columns. |
| 313 | - * <p> | |
| 314 | + * <p/> | |
| 314 | 315 | * For instance, {@code lt(Arrays.asList("a", "b"), Arrays.asList(2, "test"))} |
| 315 | 316 | * will generate the CQL WHERE clause {@code (a, b) < (2, 'test') }. |
| 316 | - * <p> | |
| 317 | + * <p/> | |
| 317 | 318 | * Please note that this variant is only supported starting with Cassandra 2.0.6. |
| 318 | 319 | * |
| 319 | - * @param names the column names | |
| 320 | + * @param names the column names | |
| 320 | 321 | * @param values the values |
| 321 | 322 | * @return the corresponding where clause. |
| 322 | - * | |
| 323 | 323 | * @throws IllegalArgumentException if {@code names.size() != values.size()}. |
| 324 | 324 | */ |
| 325 | 325 | public static Clause lt(List<String> names, List<?> values) { |
| @@ -333,7 +333,7 @@ | ||
| 333 | 333 | * Creates a "lesser than or equal" where clause stating the provided column must |
| 334 | 334 | * be lesser than or equal to the provided value. |
| 335 | 335 | * |
| 336 | - * @param name the column name | |
| 336 | + * @param name the column name | |
| 337 | 337 | * @param value the value |
| 338 | 338 | * @return the corresponding where clause. |
| 339 | 339 | */ |
| @@ -343,16 +343,15 @@ | ||
| 343 | 343 | |
| 344 | 344 | /** |
| 345 | 345 | * Creates a "lesser than or equal" where clause for a group of clustering columns. |
| 346 | - * <p> | |
| 346 | + * <p/> | |
| 347 | 347 | * For instance, {@code lte(Arrays.asList("a", "b"), Arrays.asList(2, "test"))} |
| 348 | 348 | * will generate the CQL WHERE clause {@code (a, b) <e; (2, 'test') }. |
| 349 | - * <p> | |
| 349 | + * <p/> | |
| 350 | 350 | * Please note that this variant is only supported starting with Cassandra 2.0.6. |
| 351 | 351 | * |
| 352 | - * @param names the column names | |
| 352 | + * @param names the column names | |
| 353 | 353 | * @param values the values |
| 354 | 354 | * @return the corresponding where clause. |
| 355 | - * | |
| 356 | 355 | * @throws IllegalArgumentException if {@code names.size() != values.size()}. |
| 357 | 356 | */ |
| 358 | 357 | public static Clause lte(List<String> names, List<?> values) { |
| @@ -366,7 +365,7 @@ | ||
| 366 | 365 | * Creates a "greater than" where clause stating the provided column must |
| 367 | 366 | * be greater to the provided value. |
| 368 | 367 | * |
| 369 | - * @param name the column name | |
| 368 | + * @param name the column name | |
| 370 | 369 | * @param value the value |
| 371 | 370 | * @return the corresponding where clause. |
| 372 | 371 | */ |
| @@ -376,16 +375,15 @@ | ||
| 376 | 375 | |
| 377 | 376 | /** |
| 378 | 377 | * Creates a "greater than" where clause for a group of clustering columns. |
| 379 | - * <p> | |
| 378 | + * <p/> | |
| 380 | 379 | * For instance, {@code gt(Arrays.asList("a", "b"), Arrays.asList(2, "test"))} |
| 381 | 380 | * will generate the CQL WHERE clause {@code (a, b) > (2, 'test') }. |
| 382 | - * <p> | |
| 381 | + * <p/> | |
| 383 | 382 | * Please note that this variant is only supported starting with Cassandra 2.0.6. |
| 384 | 383 | * |
| 385 | - * @param names the column names | |
| 384 | + * @param names the column names | |
| 386 | 385 | * @param values the values |
| 387 | 386 | * @return the corresponding where clause. |
| 388 | - * | |
| 389 | 387 | * @throws IllegalArgumentException if {@code names.size() != values.size()}. |
| 390 | 388 | */ |
| 391 | 389 | public static Clause gt(List<String> names, List<?> values) { |
| @@ -399,7 +397,7 @@ | ||
| 399 | 397 | * Creates a "greater than or equal" where clause stating the provided |
| 400 | 398 | * column must be greater than or equal to the provided value. |
| 401 | 399 | * |
| 402 | - * @param name the column name | |
| 400 | + * @param name the column name | |
| 403 | 401 | * @param value the value |
| 404 | 402 | * @return the corresponding where clause. |
| 405 | 403 | */ |
| @@ -409,16 +407,15 @@ | ||
| 409 | 407 | |
| 410 | 408 | /** |
| 411 | 409 | * Creates a "greater than or equal" where clause for a group of clustering columns. |
| 412 | - * <p> | |
| 410 | + * <p/> | |
| 413 | 411 | * For instance, {@code gte(Arrays.asList("a", "b"), Arrays.asList(2, "test"))} |
| 414 | 412 | * will generate the CQL WHERE clause {@code (a, b) >e; (2, 'test') }. |
| 415 | - * <p> | |
| 413 | + * <p/> | |
| 416 | 414 | * Please note that this variant is only supported starting with Cassandra 2.0.6. |
| 417 | 415 | * |
| 418 | - * @param names the column names | |
| 416 | + * @param names the column names | |
| 419 | 417 | * @param values the values |
| 420 | 418 | * @return the corresponding where clause. |
| 421 | - * | |
| 422 | 419 | * @throws IllegalArgumentException if {@code names.size() != values.size()}. |
| 423 | 420 | */ |
| 424 | 421 | public static Clause gte(List<String> names, List<?> values) { |
| @@ -453,7 +450,6 @@ | ||
| 453 | 450 | * |
| 454 | 451 | * @param timestamp the timestamp (in microseconds) to use. |
| 455 | 452 | * @return the corresponding option |
| 456 | - * | |
| 457 | 453 | * @throws IllegalArgumentException if {@code timestamp > 0}. |
| 458 | 454 | */ |
| 459 | 455 | public static Using timestamp(long timestamp) { |
| @@ -478,7 +474,6 @@ | ||
| 478 | 474 | * |
| 479 | 475 | * @param ttl the ttl (in seconds) to use. |
| 480 | 476 | * @return the corresponding option |
| 481 | - * | |
| 482 | 477 | * @throws IllegalArgumentException if {@code ttl > 0}. |
| 483 | 478 | */ |
| 484 | 479 | public static Using ttl(int ttl) { |
| @@ -500,10 +495,10 @@ | ||
| 500 | 495 | |
| 501 | 496 | /** |
| 502 | 497 | * Simple "set" assignment of a value to a column. |
| 503 | - * <p> | |
| 498 | + * <p/> | |
| 504 | 499 | * This will generate: {@code name = value}. |
| 505 | 500 | * |
| 506 | - * @param name the column name | |
| 501 | + * @param name the column name | |
| 507 | 502 | * @param value the value to assign |
| 508 | 503 | * @return the correspond assignment (to use in an update query) |
| 509 | 504 | */ |
| @@ -513,7 +508,7 @@ | ||
| 513 | 508 | |
| 514 | 509 | /** |
| 515 | 510 | * Incrementation of a counter column. |
| 516 | - * <p> | |
| 511 | + * <p/> | |
| 517 | 512 | * This will generate: {@code name = name + 1}. |
| 518 | 513 | * |
| 519 | 514 | * @param name the column name to increment |
| @@ -525,10 +520,10 @@ | ||
| 525 | 520 | |
| 526 | 521 | /** |
| 527 | 522 | * Incrementation of a counter column by a provided value. |
| 528 | - * <p> | |
| 523 | + * <p/> | |
| 529 | 524 | * This will generate: {@code name = name + value}. |
| 530 | 525 | * |
| 531 | - * @param name the column name to increment | |
| 526 | + * @param name the column name to increment | |
| 532 | 527 | * @param value the value by which to increment |
| 533 | 528 | * @return the correspond assignment (to use in an update query) |
| 534 | 529 | */ |
| @@ -538,10 +533,10 @@ | ||
| 538 | 533 | |
| 539 | 534 | /** |
| 540 | 535 | * Incrementation of a counter column by a provided value. |
| 541 | - * <p> | |
| 536 | + * <p/> | |
| 542 | 537 | * This will generate: {@code name = name + value}. |
| 543 | 538 | * |
| 544 | - * @param name the column name to increment | |
| 539 | + * @param name the column name to increment | |
| 545 | 540 | * @param value a bind marker representing the value by which to increment |
| 546 | 541 | * @return the correspond assignment (to use in an update query) |
| 547 | 542 | */ |
| @@ -551,7 +546,7 @@ | ||
| 551 | 546 | |
| 552 | 547 | /** |
| 553 | 548 | * Decrementation of a counter column. |
| 554 | - * <p> | |
| 549 | + * <p/> | |
| 555 | 550 | * This will generate: {@code name = name - 1}. |
| 556 | 551 | * |
| 557 | 552 | * @param name the column name to decrement |
| @@ -563,10 +558,10 @@ | ||
| 563 | 558 | |
| 564 | 559 | /** |
| 565 | 560 | * Decrementation of a counter column by a provided value. |
| 566 | - * <p> | |
| 561 | + * <p/> | |
| 567 | 562 | * This will generate: {@code name = name - value}. |
| 568 | 563 | * |
| 569 | - * @param name the column name to decrement | |
| 564 | + * @param name the column name to decrement | |
| 570 | 565 | * @param value the value by which to decrement |
| 571 | 566 | * @return the correspond assignment (to use in an update query) |
| 572 | 567 | */ |
| @@ -576,10 +571,10 @@ | ||
| 576 | 571 | |
| 577 | 572 | /** |
| 578 | 573 | * Decrementation of a counter column by a provided value. |
| 579 | - * <p> | |
| 574 | + * <p/> | |
| 580 | 575 | * This will generate: {@code name = name - value}. |
| 581 | 576 | * |
| 582 | - * @param name the column name to decrement | |
| 577 | + * @param name the column name to decrement | |
| 583 | 578 | * @param value a bind marker representing the value by which to decrement |
| 584 | 579 | * @return the correspond assignment (to use in an update query) |
| 585 | 580 | */ |
| @@ -589,10 +584,10 @@ | ||
| 589 | 584 | |
| 590 | 585 | /** |
| 591 | 586 | * Prepend a value to a list column. |
| 592 | - * <p> | |
| 587 | + * <p/> | |
| 593 | 588 | * This will generate: {@code name = [ value ] + name}. |
| 594 | 589 | * |
| 595 | - * @param name the column name (must be of type list). | |
| 590 | + * @param name the column name (must be of type list). | |
| 596 | 591 | * @param value the value to prepend. Using a BindMarker here is not supported. |
| 597 | 592 | * To use a BindMarker use {@code QueryBuilder#prependAll} with a |
| 598 | 593 | * singleton list. |
| @@ -607,7 +602,7 @@ | ||
| 607 | 602 | |
| 608 | 603 | /** |
| 609 | 604 | * Prepend a list of values to a list column. |
| 610 | - * <p> | |
| 605 | + * <p/> | |
| 611 | 606 | * This will generate: {@code name = list + name}. |
| 612 | 607 | * |
| 613 | 608 | * @param name the column name (must be of type list). |
| @@ -620,7 +615,7 @@ | ||
| 620 | 615 | |
| 621 | 616 | /** |
| 622 | 617 | * Prepend a list of values to a list column. |
| 623 | - * <p> | |
| 618 | + * <p/> | |
| 624 | 619 | * This will generate: {@code name = list + name}. |
| 625 | 620 | * |
| 626 | 621 | * @param name the column name (must be of type list). |
| @@ -633,10 +628,10 @@ | ||
| 633 | 628 | |
| 634 | 629 | /** |
| 635 | 630 | * Append a value to a list column. |
| 636 | - * <p> | |
| 631 | + * <p/> | |
| 637 | 632 | * This will generate: {@code name = name + [value]}. |
| 638 | 633 | * |
| 639 | - * @param name the column name (must be of type list). | |
| 634 | + * @param name the column name (must be of type list). | |
| 640 | 635 | * @param value the value to append. Using a BindMarker here is not supported. |
| 641 | 636 | * To use a BindMarker use {@code QueryBuilder#appendAll} with a |
| 642 | 637 | * singleton list. |
| @@ -651,7 +646,7 @@ | ||
| 651 | 646 | |
| 652 | 647 | /** |
| 653 | 648 | * Append a list of values to a list column. |
| 654 | - * <p> | |
| 649 | + * <p/> | |
| 655 | 650 | * This will generate: {@code name = name + list}. |
| 656 | 651 | * |
| 657 | 652 | * @param name the column name (must be of type list). |
| @@ -664,7 +659,7 @@ | ||
| 664 | 659 | |
| 665 | 660 | /** |
| 666 | 661 | * Append a list of values to a list column. |
| 667 | - * <p> | |
| 662 | + * <p/> | |
| 668 | 663 | * This will generate: {@code name = name + list}. |
| 669 | 664 | * |
| 670 | 665 | * @param name the column name (must be of type list). |
| @@ -677,10 +672,10 @@ | ||
| 677 | 672 | |
| 678 | 673 | /** |
| 679 | 674 | * Discard a value from a list column. |
| 680 | - * <p> | |
| 675 | + * <p/> | |
| 681 | 676 | * This will generate: {@code name = name - [value]}. |
| 682 | 677 | * |
| 683 | - * @param name the column name (must be of type list). | |
| 678 | + * @param name the column name (must be of type list). | |
| 684 | 679 | * @param value the value to discard. Using a BindMarker here is not supported. |
| 685 | 680 | * To use a BindMarker use {@code QueryBuilder#discardAll} with a singleton list. |
| 686 | 681 | * @return the correspond assignment (to use in an update query) |
| @@ -694,7 +689,7 @@ | ||
| 694 | 689 | |
| 695 | 690 | /** |
| 696 | 691 | * Discard a list of values to a list column. |
| 697 | - * <p> | |
| 692 | + * <p/> | |
| 698 | 693 | * This will generate: {@code name = name - list}. |
| 699 | 694 | * |
| 700 | 695 | * @param name the column name (must be of type list). |
| @@ -707,7 +702,7 @@ | ||
| 707 | 702 | |
| 708 | 703 | /** |
| 709 | 704 | * Discard a list of values to a list column. |
| 710 | - * <p> | |
| 705 | + * <p/> | |
| 711 | 706 | * This will generate: {@code name = name - list}. |
| 712 | 707 | * |
| 713 | 708 | * @param name the column name (must be of type list). |
| @@ -720,11 +715,11 @@ | ||
| 720 | 715 | |
| 721 | 716 | /** |
| 722 | 717 | * Sets a list column value by index. |
| 723 | - * <p> | |
| 718 | + * <p/> | |
| 724 | 719 | * This will generate: {@code name[idx] = value}. |
| 725 | 720 | * |
| 726 | - * @param name the column name (must be of type list). | |
| 727 | - * @param idx the index to set | |
| 721 | + * @param name the column name (must be of type list). | |
| 722 | + * @param idx the index to set | |
| 728 | 723 | * @param value the value to set |
| 729 | 724 | * @return the correspond assignment (to use in an update query) |
| 730 | 725 | */ |
| @@ -734,17 +729,17 @@ | ||
| 734 | 729 | |
| 735 | 730 | /** |
| 736 | 731 | * Adds a value to a set column. |
| 737 | - * <p> | |
| 732 | + * <p/> | |
| 738 | 733 | * This will generate: {@code name = name + {value}}. |
| 739 | 734 | * |
| 740 | - * @param name the column name (must be of type set). | |
| 735 | + * @param name the column name (must be of type set). | |
| 741 | 736 | * @param value the value to add. Using a BindMarker here is not supported. |
| 742 | 737 | * To use a BindMarker use {@code QueryBuilder#addAll} with a |
| 743 | 738 | * singleton set. |
| 744 | 739 | * @return the correspond assignment (to use in an update query) |
| 745 | 740 | */ |
| 746 | 741 | public static Assignment add(String name, Object value) { |
| 747 | - if (value instanceof BindMarker){ | |
| 742 | + if (value instanceof BindMarker) { | |
| 748 | 743 | throw new InvalidQueryException("Binding a value in add() is not supported, use addAll() and bind a singleton list"); |
| 749 | 744 | } |
| 750 | 745 | return addAll(name, Collections.singleton(value)); |
| @@ -752,11 +747,11 @@ | ||
| 752 | 747 | |
| 753 | 748 | /** |
| 754 | 749 | * Adds a set of values to a set column. |
| 755 | - * <p> | |
| 750 | + * <p/> | |
| 756 | 751 | * This will generate: {@code name = name + set}. |
| 757 | 752 | * |
| 758 | 753 | * @param name the column name (must be of type set). |
| 759 | - * @param set the set of values to append | |
| 754 | + * @param set the set of values to append | |
| 760 | 755 | * @return the correspond assignment (to use in an update query) |
| 761 | 756 | */ |
| 762 | 757 | public static Assignment addAll(String name, Set<?> set) { |
| @@ -765,11 +760,11 @@ | ||
| 765 | 760 | |
| 766 | 761 | /** |
| 767 | 762 | * Adds a set of values to a set column. |
| 768 | - * <p> | |
| 763 | + * <p/> | |
| 769 | 764 | * This will generate: {@code name = name + set}. |
| 770 | 765 | * |
| 771 | 766 | * @param name the column name (must be of type set). |
| 772 | - * @param set a bind marker representing the set of values to append | |
| 767 | + * @param set a bind marker representing the set of values to append | |
| 773 | 768 | * @return the correspond assignment (to use in an update query) |
| 774 | 769 | */ |
| 775 | 770 | public static Assignment addAll(String name, BindMarker set) { |
| @@ -778,10 +773,10 @@ | ||
| 778 | 773 | |
| 779 | 774 | /** |
| 780 | 775 | * Remove a value from a set column. |
| 781 | - * <p> | |
| 776 | + * <p/> | |
| 782 | 777 | * This will generate: {@code name = name - {value}}. |
| 783 | 778 | * |
| 784 | - * @param name the column name (must be of type set). | |
| 779 | + * @param name the column name (must be of type set). | |
| 785 | 780 | * @param value the value to remove. Using a BindMarker here is not supported. |
| 786 | 781 | * To use a BindMarker use {@code QueryBuilder#removeAll} with a singleton set. |
| 787 | 782 | * @return the correspond assignment (to use in an update query) |
| @@ -795,11 +790,11 @@ | ||
| 795 | 790 | |
| 796 | 791 | /** |
| 797 | 792 | * Remove a set of values from a set column. |
| 798 | - * <p> | |
| 793 | + * <p/> | |
| 799 | 794 | * This will generate: {@code name = name - set}. |
| 800 | 795 | * |
| 801 | 796 | * @param name the column name (must be of type set). |
| 802 | - * @param set the set of values to remove | |
| 797 | + * @param set the set of values to remove | |
| 803 | 798 | * @return the correspond assignment (to use in an update query) |
| 804 | 799 | */ |
| 805 | 800 | public static Assignment removeAll(String name, Set<?> set) { |
| @@ -808,11 +803,11 @@ | ||
| 808 | 803 | |
| 809 | 804 | /** |
| 810 | 805 | * Remove a set of values from a set column. |
| 811 | - * <p> | |
| 806 | + * <p/> | |
| 812 | 807 | * This will generate: {@code name = name - set}. |
| 813 | 808 | * |
| 814 | 809 | * @param name the column name (must be of type set). |
| 815 | - * @param set a bind marker representing the set of values to remove | |
| 810 | + * @param set a bind marker representing the set of values to remove | |
| 816 | 811 | * @return the correspond assignment (to use in an update query) |
| 817 | 812 | */ |
| 818 | 813 | public static Assignment removeAll(String name, BindMarker set) { |
| @@ -821,11 +816,11 @@ | ||
| 821 | 816 | |
| 822 | 817 | /** |
| 823 | 818 | * Puts a new key/value pair to a map column. |
| 824 | - * <p> | |
| 819 | + * <p/> | |
| 825 | 820 | * This will generate: {@code name[key] = value}. |
| 826 | 821 | * |
| 827 | - * @param name the column name (must be of type map). | |
| 828 | - * @param key the key to put | |
| 822 | + * @param name the column name (must be of type map). | |
| 823 | + * @param key the key to put | |
| 829 | 824 | * @param value the value to put |
| 830 | 825 | * @return the correspond assignment (to use in an update query) |
| 831 | 826 | */ |
| @@ -835,11 +830,11 @@ | ||
| 835 | 830 | |
| 836 | 831 | /** |
| 837 | 832 | * Puts a map of new key/value pairs to a map column. |
| 838 | - * <p> | |
| 833 | + * <p/> | |
| 839 | 834 | * This will generate: {@code name = name + map}. |
| 840 | 835 | * |
| 841 | 836 | * @param name the column name (must be of type map). |
| 842 | - * @param map the map of key/value pairs to put | |
| 837 | + * @param map the map of key/value pairs to put | |
| 843 | 838 | * @return the correspond assignment (to use in an update query) |
| 844 | 839 | */ |
| 845 | 840 | public static Assignment putAll(String name, Map<?, ?> map) { |
| @@ -848,11 +843,11 @@ | ||
| 848 | 843 | |
| 849 | 844 | /** |
| 850 | 845 | * Puts a map of new key/value pairs to a map column. |
| 851 | - * <p> | |
| 846 | + * <p/> | |
| 852 | 847 | * This will generate: {@code name = name + map}. |
| 853 | 848 | * |
| 854 | 849 | * @param name the column name (must be of type map). |
| 855 | - * @param map a bind marker representing the map of key/value pairs to put | |
| 850 | + * @param map a bind marker representing the map of key/value pairs to put | |
| 856 | 851 | * @return the correspond assignment (to use in an update query) |
| 857 | 852 | */ |
| 858 | 853 | public static Assignment putAll(String name, BindMarker map) { |
| @@ -861,7 +856,7 @@ | ||
| 861 | 856 | |
| 862 | 857 | /** |
| 863 | 858 | * An object representing an anonymous bind marker (a question mark). |
| 864 | - * <p> | |
| 859 | + * <p/> | |
| 865 | 860 | * This can be used wherever a value is expected. For instance, one can do: |
| 866 | 861 | * <pre> |
| 867 | 862 | * {@code |
| @@ -879,7 +874,7 @@ | ||
| 879 | 874 | |
| 880 | 875 | /** |
| 881 | 876 | * An object representing a named bind marker. |
| 882 | - * <p> | |
| 877 | + * <p/> | |
| 883 | 878 | * This can be used wherever a value is expected. For instance, one can do: |
| 884 | 879 | * <pre> |
| 885 | 880 | * {@code |
| @@ -888,7 +883,7 @@ | ||
| 888 | 883 | * PreparedState p = session.prepare(i.toString()); |
| 889 | 884 | * } |
| 890 | 885 | * </pre> |
| 891 | - * <p> | |
| 886 | + * <p/> | |
| 892 | 887 | * Please note that named bind makers are only supported starting with Cassandra 2.0.1. |
| 893 | 888 | * |
| 894 | 889 | * @param name the name for the bind marker. |
| @@ -900,19 +895,19 @@ | ||
| 900 | 895 | |
| 901 | 896 | /** |
| 902 | 897 | * Protects a value from any interpretation by the query builder. |
| 903 | - * <p> | |
| 898 | + * <p/> | |
| 904 | 899 | * The following table exemplify the behavior of this function: |
| 905 | 900 | * <table border=1> |
| 906 | - * <caption>Examples of use</caption> | |
| 907 | - * <tr><th>Code</th><th>Resulting query string</th></tr> | |
| 908 | - * <tr><td>{@code select().from("t").where(eq("c", "C'est la vie!")); }</td><td>{@code "SELECT * FROM t WHERE c='C''est la vie!';"}</td></tr> | |
| 909 | - * <tr><td>{@code select().from("t").where(eq("c", raw("C'est la vie!"))); }</td><td>{@code "SELECT * FROM t WHERE c=C'est la vie!;"}</td></tr> | |
| 910 | - * <tr><td>{@code select().from("t").where(eq("c", raw("'C'est la vie!'"))); }</td><td>{@code "SELECT * FROM t WHERE c='C'est la vie!';"}</td></tr> | |
| 911 | - * <tr><td>{@code select().from("t").where(eq("c", "now()")); }</td><td>{@code "SELECT * FROM t WHERE c='now()';"}</td></tr> | |
| 912 | - * <tr><td>{@code select().from("t").where(eq("c", raw("now()"))); }</td><td>{@code "SELECT * FROM t WHERE c=now();"}</td></tr> | |
| 901 | + * <caption>Examples of use</caption> | |
| 902 | + * <tr><th>Code</th><th>Resulting query string</th></tr> | |
| 903 | + * <tr><td>{@code select().from("t").where(eq("c", "C'est la vie!")); }</td><td>{@code "SELECT * FROM t WHERE c='C''est la vie!';"}</td></tr> | |
| 904 | + * <tr><td>{@code select().from("t").where(eq("c", raw("C'est la vie!"))); }</td><td>{@code "SELECT * FROM t WHERE c=C'est la vie!;"}</td></tr> | |
| 905 | + * <tr><td>{@code select().from("t").where(eq("c", raw("'C'est la vie!'"))); }</td><td>{@code "SELECT * FROM t WHERE c='C'est la vie!';"}</td></tr> | |
| 906 | + * <tr><td>{@code select().from("t").where(eq("c", "now()")); }</td><td>{@code "SELECT * FROM t WHERE c='now()';"}</td></tr> | |
| 907 | + * <tr><td>{@code select().from("t").where(eq("c", raw("now()"))); }</td><td>{@code "SELECT * FROM t WHERE c=now();"}</td></tr> | |
| 913 | 908 | * </table> |
| 914 | 909 | * <i>Note: the 2nd and 3rd examples in this table are not a valid CQL3 queries.</i> |
| 915 | - * <p> | |
| 910 | + * <p/> | |
| 916 | 911 | * The use of that method is generally discouraged since it lead to security risks. However, |
| 917 | 912 | * if you know what you are doing, it allows to escape the interpretations done by the |
| 918 | 913 | * QueryBuilder. |
| @@ -927,7 +922,7 @@ | ||
| 927 | 922 | /** |
| 928 | 923 | * Creates a function call. |
| 929 | 924 | * |
| 930 | - * @param name the name of the function to call. | |
| 925 | + * @param name the name of the function to call. | |
| 931 | 926 | * @param parameters the parameters for the function. |
| 932 | 927 | * @return the function call. |
| 933 | 928 | */ |
| @@ -955,7 +950,7 @@ | ||
| 955 | 950 | |
| 956 | 951 | /** |
| 957 | 952 | * Declares that the name in argument should be treated as a column name. |
| 958 | - * <p> | |
| 953 | + * <p/> | |
| 959 | 954 | * This mainly meant for use with {@link Select.Selection#fcall} when a |
| 960 | 955 | * function should apply to a column name, not a string value. |
| 961 | 956 | * |
modified driver-core/src/main/java/com/datastax/driver/core/querybuilder/Select.java +29 −37
| @@ -15,13 +15,13 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core.querybuilder; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.TableMetadata; | |
| 19 | + | |
| 18 | 20 | import java.util.ArrayList; |
| 19 | 21 | import java.util.Arrays; |
| 20 | 22 | import java.util.Collections; |
| 21 | 23 | import java.util.List; |
| 22 | 24 | |
| 23 | -import com.datastax.driver.core.TableMetadata; | |
| 24 | - | |
| 25 | 25 | /** |
| 26 | 26 | * A built SELECT statement. |
| 27 | 27 | */ |
| @@ -93,7 +93,7 @@ | ||
| 93 | 93 | |
| 94 | 94 | /** |
| 95 | 95 | * Adds a WHERE clause to this statement. |
| 96 | - * | |
| 96 | + * <p/> | |
| 97 | 97 | * This is a shorter/more readable version for {@code where().and(clause)}. |
| 98 | 98 | * |
| 99 | 99 | * @param clause the clause to add. |
| @@ -117,9 +117,8 @@ | ||
| 117 | 117 | * |
| 118 | 118 | * @param orderings the orderings to define for this query. |
| 119 | 119 | * @return this statement. |
| 120 | - * | |
| 121 | 120 | * @throws IllegalStateException if an ORDER BY clause has already been |
| 122 | - * provided. | |
| 121 | + * provided. | |
| 123 | 122 | */ |
| 124 | 123 | public Select orderBy(Ordering... orderings) { |
| 125 | 124 | if (this.orderings != null) |
| @@ -136,10 +135,9 @@ | ||
| 136 | 135 | * |
| 137 | 136 | * @param limit the limit to set. |
| 138 | 137 | * @return this statement. |
| 139 | - * | |
| 140 | 138 | * @throws IllegalArgumentException if {@code limit >e; 0}. |
| 141 | - * @throws IllegalStateException if a LIMIT clause has already been | |
| 142 | - * provided. | |
| 139 | + * @throws IllegalStateException if a LIMIT clause has already been | |
| 140 | + * provided. | |
| 143 | 141 | */ |
| 144 | 142 | public Select limit(int limit) { |
| 145 | 143 | if (limit <= 0) |
| @@ -158,9 +156,8 @@ | ||
| 158 | 156 | * |
| 159 | 157 | * @param marker the marker to use for the limit. |
| 160 | 158 | * @return this statement. |
| 161 | - * | |
| 162 | 159 | * @throws IllegalStateException if a LIMIT clause has already been |
| 163 | - * provided. | |
| 160 | + * provided. | |
| 164 | 161 | */ |
| 165 | 162 | public Select limit(BindMarker marker) { |
| 166 | 163 | if (this.limit != null) |
| @@ -211,9 +208,8 @@ | ||
| 211 | 208 | * |
| 212 | 209 | * @param orderings the orderings to add. |
| 213 | 210 | * @return the select statement this Where clause if part of. |
| 214 | - * | |
| 215 | 211 | * @throws IllegalStateException if an ORDER BY clause has already been |
| 216 | - * provided. | |
| 212 | + * provided. | |
| 217 | 213 | */ |
| 218 | 214 | public Select orderBy(Ordering... orderings) { |
| 219 | 215 | return statement.orderBy(orderings); |
| @@ -225,10 +221,9 @@ | ||
| 225 | 221 | * |
| 226 | 222 | * @param limit the limit to set. |
| 227 | 223 | * @return the select statement this Where clause if part of. |
| 228 | - * | |
| 229 | 224 | * @throws IllegalArgumentException if {@code limit >e; 0}. |
| 230 | - * @throws IllegalStateException if a LIMIT clause has already been | |
| 231 | - * provided. | |
| 225 | + * @throws IllegalStateException if a LIMIT clause has already been | |
| 226 | + * provided. | |
| 232 | 227 | */ |
| 233 | 228 | public Select limit(int limit) { |
| 234 | 229 | return statement.limit(limit); |
| @@ -240,9 +235,8 @@ | ||
| 240 | 235 | * |
| 241 | 236 | * @param limit the bind marker to use as limit. |
| 242 | 237 | * @return the select statement this Where clause if part of. |
| 243 | - * | |
| 244 | 238 | * @throws IllegalStateException if a LIMIT clause has already been |
| 245 | - * provided. | |
| 239 | + * provided. | |
| 246 | 240 | */ |
| 247 | 241 | public Select limit(BindMarker limit) { |
| 248 | 242 | return statement.limit(limit); |
| @@ -257,7 +251,8 @@ | ||
| 257 | 251 | List<Object> columnNames; |
| 258 | 252 | boolean isDistinct; |
| 259 | 253 | |
| 260 | - Builder() {} | |
| 254 | + Builder() { | |
| 255 | + } | |
| 261 | 256 | |
| 262 | 257 | Builder(List<Object> columnNames) { |
| 263 | 258 | this.columnNames = columnNames; |
| @@ -287,7 +282,7 @@ | ||
| 287 | 282 | * Adds the table to select from. |
| 288 | 283 | * |
| 289 | 284 | * @param keyspace the name of the keyspace to select from. |
| 290 | - * @param table the name of the table to select from. | |
| 285 | + * @param table the name of the table to select from. | |
| 291 | 286 | * @return a newly built SELECT statement that selects from {@code keyspace.table}. |
| 292 | 287 | */ |
| 293 | 288 | public Select from(String keyspace, String table) { |
| @@ -324,7 +319,6 @@ | ||
| 324 | 319 | * Selects all columns (i.e. "SELECT * ...") |
| 325 | 320 | * |
| 326 | 321 | * @return an in-build SELECT statement. |
| 327 | - * | |
| 328 | 322 | * @throws IllegalStateException if some columns had already been selected for this builder. |
| 329 | 323 | */ |
| 330 | 324 | public abstract Builder all(); |
| @@ -333,7 +327,6 @@ | ||
| 333 | 327 | * Selects the count of all returned rows (i.e. "SELECT count(*) ..."). |
| 334 | 328 | * |
| 335 | 329 | * @return an in-build SELECT statement. |
| 336 | - * | |
| 337 | 330 | * @throws IllegalStateException if some columns had already been selected for this builder. |
| 338 | 331 | */ |
| 339 | 332 | public abstract Builder countAll(); |
| @@ -348,7 +341,7 @@ | ||
| 348 | 341 | |
| 349 | 342 | /** |
| 350 | 343 | * Selects the write time of provided column. |
| 351 | - * <p> | |
| 344 | + * <p/> | |
| 352 | 345 | * This is a shortcut for {@code fcall("writetime", QueryBuilder.column(name))}. |
| 353 | 346 | * |
| 354 | 347 | * @param name the name of the column to select the write time of. |
| @@ -358,7 +351,7 @@ | ||
| 358 | 351 | |
| 359 | 352 | /** |
| 360 | 353 | * Selects the ttl of provided column. |
| 361 | - * <p> | |
| 354 | + * <p/> | |
| 362 | 355 | * This is a shortcut for {@code fcall("ttl", QueryBuilder.column(name))}. |
| 363 | 356 | * |
| 364 | 357 | * @param name the name of the column to select the ttl of. |
| @@ -368,16 +361,16 @@ | ||
| 368 | 361 | |
| 369 | 362 | /** |
| 370 | 363 | * Creates a function call. |
| 371 | - * <p> | |
| 364 | + * <p/> | |
| 372 | 365 | * Please note that the parameters are interpreted as values, and so |
| 373 | 366 | * {@code fcall("textToBlob", "foo")} will generate the string |
| 374 | 367 | * {@code "textToBlob('foo')"}. If you want to generate |
| 375 | 368 | * {@code "textToBlob(foo)"}, i.e. if the argument must be interpreted |
| 376 | 369 | * as a column name (in a select clause), you will need to use the |
| 377 | - * {@link QueryBuilder#column} method, and so | |
| 370 | + * {@link QueryBuilder#column} method, and so | |
| 378 | 371 | * {@code fcall("textToBlob", QueryBuilder.column(foo)}. |
| 379 | 372 | * |
| 380 | - * @param name the name of the function. | |
| 373 | + * @param name the name of the function. | |
| 381 | 374 | * @param parameters the parameters for the function call. |
| 382 | 375 | * @return this in-build SELECT statement |
| 383 | 376 | */ |
| @@ -386,7 +379,7 @@ | ||
| 386 | 379 | |
| 387 | 380 | /** |
| 388 | 381 | * An Selection clause for an in-construction SELECT statement. |
| 389 | - * <p> | |
| 382 | + * <p/> | |
| 390 | 383 | * This only differs from {@link Selection} in that you can add an |
| 391 | 384 | * alias for the previously selected item through {@link SelectionOrAlias#as}. |
| 392 | 385 | */ |
| @@ -394,7 +387,8 @@ | ||
| 394 | 387 | |
| 395 | 388 | private Object previousSelection; |
| 396 | 389 | |
| 397 | - SelectionOrAlias() {} | |
| 390 | + SelectionOrAlias() { | |
| 391 | + } | |
| 398 | 392 | |
| 399 | 393 | /** |
| 400 | 394 | * Adds an alias for the just selected item. |
| @@ -430,7 +424,6 @@ | ||
| 430 | 424 | * Selects all columns (i.e. "SELECT * ...") |
| 431 | 425 | * |
| 432 | 426 | * @return an in-build SELECT statement. |
| 433 | - * | |
| 434 | 427 | * @throws IllegalStateException if some columns had already been selected for this builder. |
| 435 | 428 | */ |
| 436 | 429 | public Builder all() { |
| @@ -439,14 +432,13 @@ | ||
| 439 | 432 | if (previousSelection != null) |
| 440 | 433 | throw new IllegalStateException(String.format("Some columns ([%s]) have already been selected.", previousSelection)); |
| 441 | 434 | |
| 442 | - return (Builder)this; | |
| 435 | + return (Builder) this; | |
| 443 | 436 | } |
| 444 | 437 | |
| 445 | 438 | /** |
| 446 | 439 | * Selects the count of all returned rows (i.e. "SELECT count(*) ..."). |
| 447 | 440 | * |
| 448 | 441 | * @return an in-build SELECT statement. |
| 449 | - * | |
| 450 | 442 | * @throws IllegalStateException if some columns had already been selected for this builder. |
| 451 | 443 | */ |
| 452 | 444 | public Builder countAll() { |
| @@ -456,7 +448,7 @@ | ||
| 456 | 448 | throw new IllegalStateException(String.format("Some columns ([%s]) have already been selected.", previousSelection)); |
| 457 | 449 | |
| 458 | 450 | columnNames = COUNT_ALL; |
| 459 | - return (Builder)this; | |
| 451 | + return (Builder) this; | |
| 460 | 452 | } |
| 461 | 453 | |
| 462 | 454 | /** |
| @@ -471,7 +463,7 @@ | ||
| 471 | 463 | |
| 472 | 464 | /** |
| 473 | 465 | * Selects the write time of provided column. |
| 474 | - * <p> | |
| 466 | + * <p/> | |
| 475 | 467 | * This is a shortcut for {@code fcall("writetime", QueryBuilder.column(name))}. |
| 476 | 468 | * |
| 477 | 469 | * @param name the name of the column to select the write time of. |
| @@ -483,7 +475,7 @@ | ||
| 483 | 475 | |
| 484 | 476 | /** |
| 485 | 477 | * Selects the ttl of provided column. |
| 486 | - * <p> | |
| 478 | + * <p/> | |
| 487 | 479 | * This is a shortcut for {@code fcall("ttl", QueryBuilder.column(name))}. |
| 488 | 480 | * |
| 489 | 481 | * @param name the name of the column to select the ttl of. |
| @@ -495,13 +487,13 @@ | ||
| 495 | 487 | |
| 496 | 488 | /** |
| 497 | 489 | * Creates a function call. |
| 498 | - * <p> | |
| 490 | + * <p/> | |
| 499 | 491 | * Please note that the parameters are interpreted as values, and so |
| 500 | 492 | * {@code fcall("textToBlob", "foo")} will generate the string |
| 501 | 493 | * {@code "textToBlob('foo')"}. If you want to generate |
| 502 | 494 | * {@code "textToBlob(foo)"}, i.e. if the argument must be interpreted |
| 503 | 495 | * as a column name (in a select clause), you will need to use the |
| 504 | - * {@link QueryBuilder#column} method, and so | |
| 496 | + * {@link QueryBuilder#column} method, and so | |
| 505 | 497 | * {@code fcall("textToBlob", QueryBuilder.column(foo)}. |
| 506 | 498 | */ |
| 507 | 499 | public SelectionOrAlias fcall(String name, Object... parameters) { |
| @@ -512,7 +504,7 @@ | ||
| 512 | 504 | * Adds the table to select from. |
| 513 | 505 | * |
| 514 | 506 | * @param keyspace the name of the keyspace to select from. |
| 515 | - * @param table the name of the table to select from. | |
| 507 | + * @param table the name of the table to select from. | |
| 516 | 508 | * @return a newly built SELECT statement that selects from {@code keyspace.table}. |
| 517 | 509 | */ |
| 518 | 510 | @Override |
modified driver-core/src/main/java/com/datastax/driver/core/querybuilder/Truncate.java +2 −3
| @@ -15,11 +15,10 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core.querybuilder; |
| 17 | 17 | |
| 18 | -import java.nio.ByteBuffer; | |
| 19 | -import java.util.List; | |
| 20 | - | |
| 21 | 18 | import com.datastax.driver.core.TableMetadata; |
| 22 | 19 | |
| 20 | +import java.util.List; | |
| 21 | + | |
| 23 | 22 | /** |
| 24 | 23 | * A built TRUNCATE statement. |
| 25 | 24 | */ |
modified driver-core/src/main/java/com/datastax/driver/core/querybuilder/Update.java +13 −14
| @@ -15,13 +15,12 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core.querybuilder; |
| 17 | 17 | |
| 18 | -import java.nio.ByteBuffer; | |
| 19 | -import java.util.ArrayList; | |
| 20 | -import java.util.List; | |
| 21 | - | |
| 22 | 18 | import com.datastax.driver.core.TableMetadata; |
| 23 | 19 | import com.datastax.driver.core.querybuilder.Assignment.CounterAssignment; |
| 24 | 20 | |
| 21 | +import java.util.ArrayList; | |
| 22 | +import java.util.List; | |
| 23 | + | |
| 25 | 24 | /** |
| 26 | 25 | * A built UPDATE statement. |
| 27 | 26 | */ |
| @@ -92,7 +91,7 @@ | ||
| 92 | 91 | |
| 93 | 92 | /** |
| 94 | 93 | * Adds an assignment to this UPDATE statement. |
| 95 | - * | |
| 94 | + * <p/> | |
| 96 | 95 | * This is a shorter/more readable version for {@code with().and(assignment)}. |
| 97 | 96 | * |
| 98 | 97 | * @param assignment the assignment to add. |
| @@ -113,7 +112,7 @@ | ||
| 113 | 112 | |
| 114 | 113 | /** |
| 115 | 114 | * Adds a WHERE clause to this statement. |
| 116 | - * | |
| 115 | + * <p/> | |
| 117 | 116 | * This is a shorter/more readable version for {@code where().and(clause)}. |
| 118 | 117 | * |
| 119 | 118 | * @param clause the clause to add. |
| @@ -134,7 +133,7 @@ | ||
| 134 | 133 | |
| 135 | 134 | /** |
| 136 | 135 | * Adds a conditions clause (IF) to this statement. |
| 137 | - * <p> | |
| 136 | + * <p/> | |
| 138 | 137 | * This is a shorter/more readable version for {@code onlyIf().and(condition)}. |
| 139 | 138 | * |
| 140 | 139 | * @param condition the condition to add. |
| @@ -274,11 +273,11 @@ | ||
| 274 | 273 | public Conditions onlyIf(Clause condition) { |
| 275 | 274 | return statement.onlyIf(condition); |
| 276 | 275 | } |
| 277 | - | |
| 276 | + | |
| 278 | 277 | /** |
| 279 | 278 | * Sets the 'IF EXISTS' option for the UPDATE statement this WHERE clause |
| 280 | 279 | * is part of. |
| 281 | - * | |
| 280 | + * <p/> | |
| 282 | 281 | * <p> |
| 283 | 282 | * An update with that option will report whether the statement actually |
| 284 | 283 | * resulted in data being updated. The existence check and update are |
| @@ -354,10 +353,10 @@ | ||
| 354 | 353 | |
| 355 | 354 | /** |
| 356 | 355 | * Conditions for an UPDATE statement. |
| 357 | - * <p> | |
| 356 | + * <p/> | |
| 358 | 357 | * When provided some conditions, an update will not apply unless the |
| 359 | 358 | * provided conditions applies. |
| 360 | - * <p> | |
| 359 | + * <p/> | |
| 361 | 360 | * Please keep in mind that provided conditions has a non negligible |
| 362 | 361 | * performance impact and should be avoided when possible. |
| 363 | 362 | */ |
| @@ -371,7 +370,7 @@ | ||
| 371 | 370 | |
| 372 | 371 | /** |
| 373 | 372 | * Adds the provided condition for the update. |
| 374 | - * <p> | |
| 373 | + * <p/> | |
| 375 | 374 | * Note that while the query builder accept any type of {@code Clause} |
| 376 | 375 | * as conditions, Cassandra currently only allow equality ones. |
| 377 | 376 | * |
| @@ -413,9 +412,9 @@ | ||
| 413 | 412 | public Options using(Using using) { |
| 414 | 413 | return statement.using(using); |
| 415 | 414 | } |
| 416 | - | |
| 415 | + | |
| 417 | 416 | } |
| 418 | - | |
| 417 | + | |
| 419 | 418 | public static class IfExists extends BuiltStatement.ForwardingStatement<Update> { |
| 420 | 419 | IfExists(Update statement) { |
| 421 | 420 | super(statement); |
modified driver-core/src/main/java/com/datastax/driver/core/querybuilder/Using.java +0 −1
| @@ -15,7 +15,6 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core.querybuilder; |
| 17 | 17 | |
| 18 | -import java.nio.ByteBuffer; | |
| 19 | 18 | import java.util.List; |
| 20 | 19 | |
| 21 | 20 | public abstract class Using extends Utils.Appendeable { |
modified driver-core/src/main/java/com/datastax/driver/core/querybuilder/Utils.java +26 −24
| @@ -15,6 +15,8 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core.querybuilder; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.DataType; | |
| 19 | + | |
| 18 | 20 | import java.math.BigDecimal; |
| 19 | 21 | import java.math.BigInteger; |
| 20 | 22 | import java.net.InetAddress; |
| @@ -24,8 +26,6 @@ | ||
| 24 | 26 | |
| 25 | 27 | import static com.google.common.base.Preconditions.checkNotNull; |
| 26 | 28 | |
| 27 | -import com.datastax.driver.core.DataType; | |
| 28 | - | |
| 29 | 29 | // Static utilities private to the query builder |
| 30 | 30 | abstract class Utils { |
| 31 | 31 | |
| @@ -133,9 +133,9 @@ | ||
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | if (rawValue) |
| 136 | - sb.append((String)value); | |
| 136 | + sb.append((String) value); | |
| 137 | 137 | else |
| 138 | - appendValueString((String)value, sb); | |
| 138 | + appendValueString((String) value, sb); | |
| 139 | 139 | } |
| 140 | 140 | } |
| 141 | 141 | |
| @@ -156,7 +156,7 @@ | ||
| 156 | 156 | sb.append(value); |
| 157 | 157 | return true; |
| 158 | 158 | } else if (value instanceof FCall) { |
| 159 | - FCall fcall = (FCall)value; | |
| 159 | + FCall fcall = (FCall) value; | |
| 160 | 160 | sb.append(fcall.name).append('('); |
| 161 | 161 | for (int i = 0; i < fcall.parameters.length; i++) { |
| 162 | 162 | if (i > 0) |
| @@ -166,7 +166,7 @@ | ||
| 166 | 166 | sb.append(')'); |
| 167 | 167 | return true; |
| 168 | 168 | } else if (value instanceof CName) { |
| 169 | - appendName(((CName)value).name, sb); | |
| 169 | + appendName(((CName) value).name, sb); | |
| 170 | 170 | return true; |
| 171 | 171 | } else if (value == null) { |
| 172 | 172 | sb.append("null"); |
| @@ -182,10 +182,10 @@ | ||
| 182 | 182 | appendList((List) value, sb, rawValue); |
| 183 | 183 | return true; |
| 184 | 184 | } else if (value instanceof Set) { |
| 185 | - appendSet((Set)value, sb, rawValue); | |
| 185 | + appendSet((Set) value, sb, rawValue); | |
| 186 | 186 | return true; |
| 187 | 187 | } else if (value instanceof Map) { |
| 188 | - appendMap((Map)value, sb, rawValue); | |
| 188 | + appendMap((Map) value, sb, rawValue); | |
| 189 | 189 | return true; |
| 190 | 190 | } else { |
| 191 | 191 | return false; |
| @@ -218,7 +218,8 @@ | ||
| 218 | 218 | sb.append('{'); |
| 219 | 219 | boolean first = true; |
| 220 | 220 | for (Object elt : s) { |
| 221 | - if (first) first = false; else sb.append(','); | |
| 221 | + if (first) first = false; | |
| 222 | + else sb.append(','); | |
| 222 | 223 | appendFlatValue(elt, sb, rawValue); |
| 223 | 224 | } |
| 224 | 225 | sb.append('}'); |
| @@ -248,7 +249,7 @@ | ||
| 248 | 249 | if (!(value instanceof FCall)) |
| 249 | 250 | return false; |
| 250 | 251 | |
| 251 | - FCall fcall = (FCall)value; | |
| 252 | + FCall fcall = (FCall) value; | |
| 252 | 253 | for (Object param : fcall.parameters) |
| 253 | 254 | if (containsBindMarker(param)) |
| 254 | 255 | return true; |
| @@ -256,23 +257,23 @@ | ||
| 256 | 257 | } |
| 257 | 258 | |
| 258 | 259 | static boolean isIdempotent(Object value) { |
| 259 | - if(value == null) { | |
| 260 | + if (value == null) { | |
| 260 | 261 | return true; |
| 261 | 262 | } else if (value instanceof Assignment) { |
| 262 | - Assignment assignment = (Assignment)value; | |
| 263 | + Assignment assignment = (Assignment) value; | |
| 263 | 264 | return assignment.isIdempotent(); |
| 264 | 265 | } else if (value instanceof FCall) { |
| 265 | 266 | return false; |
| 266 | 267 | } else if (value instanceof RawString) { |
| 267 | 268 | return false; |
| 268 | - } else if(value instanceof Collection) { | |
| 269 | - for (Object elt : ((Collection)value)) { | |
| 270 | - if(!isIdempotent(elt)) | |
| 269 | + } else if (value instanceof Collection) { | |
| 270 | + for (Object elt : ((Collection) value)) { | |
| 271 | + if (!isIdempotent(elt)) | |
| 271 | 272 | return false; |
| 272 | 273 | } |
| 273 | 274 | return true; |
| 274 | 275 | } else if (value instanceof Map) { |
| 275 | - for (Map.Entry<?, ?> entry : ((Map<?, ?>)value).entrySet()) { | |
| 276 | + for (Map.Entry<?, ?> entry : ((Map<?, ?>) value).entrySet()) { | |
| 276 | 277 | if (!isIdempotent(entry.getKey()) || !isIdempotent(entry.getValue())) |
| 277 | 278 | return false; |
| 278 | 279 | } |
| @@ -286,9 +287,9 @@ | ||
| 286 | 287 | |
| 287 | 288 | static boolean isRawValue(Object value) { |
| 288 | 289 | return value != null |
| 289 | - && !(value instanceof FCall) | |
| 290 | - && !(value instanceof CName) | |
| 291 | - && !(value instanceof BindMarker); | |
| 290 | + && !(value instanceof FCall) | |
| 291 | + && !(value instanceof CName) | |
| 292 | + && !(value instanceof BindMarker); | |
| 292 | 293 | } |
| 293 | 294 | |
| 294 | 295 | static String toRawString(Object value) { |
| @@ -307,11 +308,11 @@ | ||
| 307 | 308 | |
| 308 | 309 | static StringBuilder appendName(Object name, StringBuilder sb) { |
| 309 | 310 | if (name instanceof String) { |
| 310 | - appendName((String)name, sb); | |
| 311 | + appendName((String) name, sb); | |
| 311 | 312 | } else if (name instanceof CName) { |
| 312 | - appendName(((CName)name).name, sb); | |
| 313 | + appendName(((CName) name).name, sb); | |
| 313 | 314 | } else if (name instanceof FCall) { |
| 314 | - FCall fcall = (FCall)name; | |
| 315 | + FCall fcall = (FCall) name; | |
| 315 | 316 | sb.append(fcall.name).append('('); |
| 316 | 317 | for (int i = 0; i < fcall.parameters.length; i++) { |
| 317 | 318 | if (i > 0) |
| @@ -320,7 +321,7 @@ | ||
| 320 | 321 | } |
| 321 | 322 | sb.append(')'); |
| 322 | 323 | } else if (name instanceof Alias) { |
| 323 | - Alias alias = (Alias)name; | |
| 324 | + Alias alias = (Alias) name; | |
| 324 | 325 | appendName(alias.column, sb); |
| 325 | 326 | sb.append(" AS ").append(alias.alias); |
| 326 | 327 | } else { |
| @@ -331,6 +332,7 @@ | ||
| 331 | 332 | |
| 332 | 333 | static abstract class Appendeable { |
| 333 | 334 | abstract void appendTo(StringBuilder sb, List<Object> values); |
| 335 | + | |
| 334 | 336 | abstract boolean containsBindMarker(); |
| 335 | 337 | } |
| 336 | 338 | |
| @@ -343,7 +345,7 @@ | ||
| 343 | 345 | int nbMatch = 0; |
| 344 | 346 | int start = -1; |
| 345 | 347 | do { |
| 346 | - start = text.indexOf(search, start+1); | |
| 348 | + start = text.indexOf(search, start + 1); | |
| 347 | 349 | if (start != -1) |
| 348 | 350 | ++nbMatch; |
| 349 | 351 | } while (start != -1); |
modified driver-core/src/main/java/com/datastax/driver/core/querybuilder/package-info.java +1 −1
| @@ -15,7 +15,7 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | /** |
| 17 | 17 | * A CQL3 query builder. |
| 18 | - * <p> | |
| 18 | + * <p/> | |
| 19 | 19 | * The main entry for this package is the {@code QueryBuilder} class. |
| 20 | 20 | */ |
| 21 | 21 | package com.datastax.driver.core.querybuilder; |
modified driver-core/src/main/java/com/datastax/driver/core/utils/Bytes.java +20 −19
| @@ -24,20 +24,22 @@ | ||
| 24 | 24 | */ |
| 25 | 25 | public final class Bytes { |
| 26 | 26 | |
| 27 | - private Bytes() {} | |
| 27 | + private Bytes() { | |
| 28 | + } | |
| 28 | 29 | |
| 29 | 30 | private static final byte[] charToByte = new byte[256]; |
| 30 | 31 | private static final char[] byteToChar = new char[16]; |
| 32 | + | |
| 31 | 33 | static { |
| 32 | 34 | for (char c = 0; c < charToByte.length; ++c) { |
| 33 | 35 | if (c >= '0' && c <= '9') |
| 34 | - charToByte[c] = (byte)(c - '0'); | |
| 36 | + charToByte[c] = (byte) (c - '0'); | |
| 35 | 37 | else if (c >= 'A' && c <= 'F') |
| 36 | - charToByte[c] = (byte)(c - 'A' + 10); | |
| 38 | + charToByte[c] = (byte) (c - 'A' + 10); | |
| 37 | 39 | else if (c >= 'a' && c <= 'f') |
| 38 | - charToByte[c] = (byte)(c - 'a' + 10); | |
| 40 | + charToByte[c] = (byte) (c - 'a' + 10); | |
| 39 | 41 | else |
| 40 | - charToByte[c] = (byte)-1; | |
| 42 | + charToByte[c] = (byte) -1; | |
| 41 | 43 | } |
| 42 | 44 | |
| 43 | 45 | for (int i = 0; i < 16; ++i) { |
| @@ -51,6 +53,7 @@ | ||
| 51 | 53 | * That's stolen from Cassandra's code. |
| 52 | 54 | */ |
| 53 | 55 | private static final Constructor<String> stringConstructor; |
| 56 | + | |
| 54 | 57 | static { |
| 55 | 58 | Constructor<String> c; |
| 56 | 59 | try { |
| @@ -79,7 +82,7 @@ | ||
| 79 | 82 | |
| 80 | 83 | /** |
| 81 | 84 | * Converts a blob to its CQL hex string representation. |
| 82 | - * <p> | |
| 85 | + * <p/> | |
| 83 | 86 | * A CQL blob string representation consist of the hexadecimal |
| 84 | 87 | * representation of the blob bytes prefixed by "0x". |
| 85 | 88 | * |
| @@ -102,7 +105,7 @@ | ||
| 102 | 105 | |
| 103 | 106 | /** |
| 104 | 107 | * Converts a blob to its CQL hex string representation. |
| 105 | - * <p> | |
| 108 | + * <p/> | |
| 106 | 109 | * A CQL blob string representation consist of the hexadecimal |
| 107 | 110 | * representation of the blob bytes. |
| 108 | 111 | * |
| @@ -125,7 +128,7 @@ | ||
| 125 | 128 | |
| 126 | 129 | /** |
| 127 | 130 | * Converts a blob to its CQL hex string representation. |
| 128 | - * <p> | |
| 131 | + * <p/> | |
| 129 | 132 | * A CQL blob string representation consist of the hexadecimal |
| 130 | 133 | * representation of the blob bytes prefixed by "0x". |
| 131 | 134 | * |
| @@ -139,7 +142,7 @@ | ||
| 139 | 142 | |
| 140 | 143 | /** |
| 141 | 144 | * Parse an hex string representing a CQL blob. |
| 142 | - * <p> | |
| 145 | + * <p/> | |
| 143 | 146 | * The input should be a valid representation of a CQL blob, i.e. it |
| 144 | 147 | * must start by "0x" followed by the hexadecimal representation of the |
| 145 | 148 | * blob bytes. |
| @@ -147,9 +150,8 @@ | ||
| 147 | 150 | * @param str the CQL blob string representation to parse. |
| 148 | 151 | * @return the bytes corresponding to {@code str}. If {@code str} |
| 149 | 152 | * is {@code null}, this method returns {@code null}. |
| 150 | - * | |
| 151 | 153 | * @throws IllegalArgumentException if {@code str} is not a valid CQL |
| 152 | - * blob string. | |
| 154 | + * blob string. | |
| 153 | 155 | */ |
| 154 | 156 | public static ByteBuffer fromHexString(String str) { |
| 155 | 157 | if ((str.length() & 1) == 1) |
| @@ -163,7 +165,7 @@ | ||
| 163 | 165 | |
| 164 | 166 | /** |
| 165 | 167 | * Extract the content of the provided {@code ByteBuffer} as a byte array. |
| 166 | - * <p> | |
| 168 | + * <p/> | |
| 167 | 169 | * This method work with any type of {@code ByteBuffer} (direct and non-direct |
| 168 | 170 | * ones), but when the {@code ByteBuffer} is backed by an array, this method |
| 169 | 171 | * will try to avoid copy when possible. As a consequence, changes to the |
| @@ -188,13 +190,13 @@ | ||
| 188 | 190 | bytes.duplicate().get(array); |
| 189 | 191 | return array; |
| 190 | 192 | } |
| 191 | - | |
| 193 | + | |
| 192 | 194 | private static String toRawHexString(ByteBuffer bytes, char[] array, int offset) { |
| 193 | 195 | int size = bytes.remaining(); |
| 194 | 196 | int bytesOffset = bytes.position(); |
| 195 | - assert array.length >= offset + 2*size; | |
| 197 | + assert array.length >= offset + 2 * size; | |
| 196 | 198 | for (int i = 0; i < size; i++) { |
| 197 | - int bint = bytes.get(i+bytesOffset); | |
| 199 | + int bint = bytes.get(i + bytesOffset); | |
| 198 | 200 | array[offset + i * 2] = byteToChar[(bint & 0xf0) >> 4]; |
| 199 | 201 | array[offset + 1 + i * 2] = byteToChar[bint & 0x0f]; |
| 200 | 202 | } |
| @@ -203,13 +205,12 @@ | ||
| 203 | 205 | |
| 204 | 206 | /** |
| 205 | 207 | * Converts a CQL hex string representation into a byte array. |
| 206 | - * <p> | |
| 208 | + * <p/> | |
| 207 | 209 | * A CQL blob string representation consist of the hexadecimal |
| 208 | 210 | * representation of the blob bytes. |
| 209 | 211 | * |
| 210 | - * @param str the string converted in hex representation. | |
| 212 | + * @param str the string converted in hex representation. | |
| 211 | 213 | * @param strOffset he offset for starting the string conversion |
| 212 | - * | |
| 213 | 214 | * @return the byte array which the String was representing. |
| 214 | 215 | */ |
| 215 | 216 | |
| @@ -220,7 +221,7 @@ | ||
| 220 | 221 | byte halfByte2 = charToByte[str.charAt(strOffset + i * 2 + 1)]; |
| 221 | 222 | if (halfByte1 == -1 || halfByte2 == -1) |
| 222 | 223 | throw new IllegalArgumentException("Non-hex characters in " + str); |
| 223 | - bytes[i] = (byte)((halfByte1 << 4) | halfByte2); | |
| 224 | + bytes[i] = (byte) ((halfByte1 << 4) | halfByte2); | |
| 224 | 225 | } |
| 225 | 226 | return bytes; |
| 226 | 227 | } |
modified driver-core/src/main/java/com/datastax/driver/core/utils/UUIDs.java +20 −18
| @@ -15,6 +15,8 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core.utils; |
| 17 | 17 | |
| 18 | +import com.google.common.base.Charsets; | |
| 19 | + | |
| 18 | 20 | import java.net.InetAddress; |
| 19 | 21 | import java.net.NetworkInterface; |
| 20 | 22 | import java.net.SocketException; |
| @@ -24,15 +26,16 @@ | ||
| 24 | 26 | import java.util.*; |
| 25 | 27 | import java.util.concurrent.atomic.AtomicLong; |
| 26 | 28 | |
| 27 | -import com.google.common.base.Charsets; | |
| 28 | - | |
| 29 | 29 | /** |
| 30 | 30 | * Utility methods to work with UUID and most specifically with time-based ones |
| 31 | 31 | * (version 1). |
| 32 | 32 | */ |
| 33 | 33 | public final class UUIDs { |
| 34 | 34 | |
| 35 | - private UUIDs() {}; | |
| 35 | + private UUIDs() { | |
| 36 | + } | |
| 37 | + | |
| 38 | + ; | |
| 36 | 39 | |
| 37 | 40 | // http://www.ietf.org/rfc/rfc4122.txt |
| 38 | 41 | private static final long START_EPOCH = makeEpoch(); |
| @@ -96,7 +99,7 @@ | ||
| 96 | 99 | |
| 97 | 100 | long node = 0; |
| 98 | 101 | for (int i = 0; i < 6; i++) |
| 99 | - node |= (0x00000000000000ffL & (long)hash[i]) << (i*8); | |
| 102 | + node |= (0x00000000000000ffL & (long) hash[i]) << (i * 8); | |
| 100 | 103 | // Since we don't use the mac address, the spec says that multicast |
| 101 | 104 | // bit (least significant bit of the first byte of the node ID) must be 1. |
| 102 | 105 | return node | 0x0000010000000000L; |
| @@ -123,7 +126,7 @@ | ||
| 123 | 126 | |
| 124 | 127 | /** |
| 125 | 128 | * Creates a new random (version 4) UUID. |
| 126 | - * <p> | |
| 129 | + * <p/> | |
| 127 | 130 | * This method is just a convenience for {@code UUID.randomUUID()}. |
| 128 | 131 | * |
| 129 | 132 | * @return a newly generated, pseudo random, version 4 UUID. |
| @@ -134,7 +137,7 @@ | ||
| 134 | 137 | |
| 135 | 138 | /** |
| 136 | 139 | * Creates a new time-based (version 1) UUID. |
| 137 | - * <p> | |
| 140 | + * <p/> | |
| 138 | 141 | * UUID generated by this method are suitable for use with the |
| 139 | 142 | * {@code timeuuid} Cassandra type. In particular the generated UUID |
| 140 | 143 | * includes the timestamp of its generation. |
| @@ -148,27 +151,27 @@ | ||
| 148 | 151 | /** |
| 149 | 152 | * Creates a "fake" time-based UUID that sorts as the smallest possible |
| 150 | 153 | * version 1 UUID generated at the provided timestamp. |
| 151 | - * <p> | |
| 154 | + * <p/> | |
| 152 | 155 | * Such created UUID are useful in queries to select a time range of a |
| 153 | 156 | * {@code timeuuid} column. |
| 154 | - * <p> | |
| 157 | + * <p/> | |
| 155 | 158 | * The UUID created by this method <b>are not unique</b> and as such are |
| 156 | 159 | * <b>not</b> suitable for anything else than querying a specific time |
| 157 | 160 | * range. In particular, you should not insert such UUID. |
| 158 | - * <p> | |
| 161 | + * <p/> | |
| 159 | 162 | * Also, the timestamp to provide as parameter must be a unix timestamp (as |
| 160 | 163 | * returned by {@link System#currentTimeMillis} or {@link java.util.Date#getTime}), |
| 161 | 164 | * not a UUID 100-nanoseconds intervals since 15 October 1582. In other |
| 162 | 165 | * words, given a UUID {@code uuid}, you should never do |
| 163 | 166 | * {@code startOf(uuid.timestamp())} but rather |
| 164 | 167 | * {@code startOf(unixTimestamp(uuid.timestamp()))}. |
| 165 | - * <p> | |
| 168 | + * <p/> | |
| 166 | 169 | * Lastly, please note that Cassandra's timeuuid sorting is not compatible |
| 167 | 170 | * with {@link UUID#compareTo} and hence the UUID created by this method |
| 168 | 171 | * are not necessarily lower bound for that latter method. |
| 169 | 172 | * |
| 170 | 173 | * @param timestamp the unix timestamp for which the created UUID must be a |
| 171 | - * lower bound. | |
| 174 | + * lower bound. | |
| 172 | 175 | * @return the smallest (for Cassandra timeuuid sorting) UUID of {@code timestamp}. |
| 173 | 176 | */ |
| 174 | 177 | public static UUID startOf(long timestamp) { |
| @@ -178,27 +181,27 @@ | ||
| 178 | 181 | /** |
| 179 | 182 | * Creates a "fake" time-based UUID that sorts as the biggest possible |
| 180 | 183 | * version 1 UUID generated at the provided timestamp. |
| 181 | - * <p> | |
| 184 | + * <p/> | |
| 182 | 185 | * Such created UUID are useful in queries to select a time range of a |
| 183 | 186 | * {@code timeuuid} column. |
| 184 | - * <p> | |
| 187 | + * <p/> | |
| 185 | 188 | * The UUID created by this method <b>are not unique</b> and as such are |
| 186 | 189 | * <b>not</b> suitable for anything else than querying a specific time |
| 187 | 190 | * range. In particular, you should not insert such UUID. |
| 188 | - * <p> | |
| 191 | + * <p/> | |
| 189 | 192 | * Also, the timestamp to provide as parameter must be a unix timestamp (as |
| 190 | 193 | * returned by {@link System#currentTimeMillis} or {@link java.util.Date#getTime}), |
| 191 | 194 | * not a UUID 100-nanoseconds intervals since 15 October 1582. In other |
| 192 | 195 | * words, given a UUID {@code uuid}, you should never do |
| 193 | 196 | * {@code startOf(uuid.timestamp())} but rather |
| 194 | 197 | * {@code startOf(unixTimestamp(uuid.timestamp()))}. |
| 195 | - * <p> | |
| 198 | + * <p/> | |
| 196 | 199 | * Lastly, please note that Cassandra's timeuuid sorting is not compatible |
| 197 | 200 | * with {@link UUID#compareTo} and hence the UUID created by this method |
| 198 | 201 | * are not necessarily upper bound for that latter method. |
| 199 | 202 | * |
| 200 | 203 | * @param timestamp the unix timestamp for which the created UUID must be an |
| 201 | - * upper bound. | |
| 204 | + * upper bound. | |
| 202 | 205 | * @return the biggest (for Cassandra timeuuid sorting) UUID of {@code timestamp}. |
| 203 | 206 | */ |
| 204 | 207 | public static UUID endOf(long timestamp) { |
| @@ -208,7 +211,7 @@ | ||
| 208 | 211 | |
| 209 | 212 | /** |
| 210 | 213 | * Return the unix timestamp contained by the provided time-based UUID. |
| 211 | - * <p> | |
| 214 | + * <p/> | |
| 212 | 215 | * This method is not equivalent to {@code uuid.timestamp()}. More |
| 213 | 216 | * precisely, a version 1 UUID stores a timestamp that represents the |
| 214 | 217 | * number of 100-nanoseconds intervals since midnight, 15 October 1582 and |
| @@ -221,7 +224,6 @@ | ||
| 221 | 224 | * |
| 222 | 225 | * @param uuid the UUID to return the timestamp of. |
| 223 | 226 | * @return the unix timestamp of {@code uuid}. |
| 224 | - * | |
| 225 | 227 | * @throws IllegalArgumentException if {@code uuid} is not a version 1 UUID. |
| 226 | 228 | */ |
| 227 | 229 | public static long unixTimestamp(UUID uuid) { |
modified driver-core/src/test/java/com/datastax/driver/core/AbstractPoliciesTest.java +5 −4
| @@ -20,11 +20,10 @@ | ||
| 20 | 20 | import java.util.HashMap; |
| 21 | 21 | import java.util.Map; |
| 22 | 22 | |
| 23 | -import static org.testng.Assert.*; | |
| 24 | - | |
| 25 | 23 | import static com.datastax.driver.core.TestUtils.*; |
| 26 | 24 | import static com.datastax.driver.core.querybuilder.QueryBuilder.batch; |
| 27 | 25 | import static com.datastax.driver.core.querybuilder.QueryBuilder.insertInto; |
| 26 | +import static org.testng.Assert.*; | |
| 28 | 27 | |
| 29 | 28 | public abstract class AbstractPoliciesTest { |
| 30 | 29 | private static final boolean DEBUG = false; |
| @@ -107,7 +106,9 @@ | ||
| 107 | 106 | } |
| 108 | 107 | } |
| 109 | 108 | |
| 110 | - /** Assert that one of the nodes in the list was queried with n, no matter which one */ | |
| 109 | + /** | |
| 110 | + * Assert that one of the nodes in the list was queried with n, no matter which one | |
| 111 | + */ | |
| 111 | 112 | protected void assertOneNodeQueried(int n, String... hosts) { |
| 112 | 113 | try { |
| 113 | 114 | boolean found = false; |
| @@ -180,7 +181,7 @@ | ||
| 180 | 181 | if (batch) |
| 181 | 182 | // BUG: WriteType == SIMPLE |
| 182 | 183 | c.session.execute(batch() |
| 183 | - .add(insertInto(SIMPLE_TABLE).values(new String[]{ "k", "i"}, new Object[]{ 0, 0 })) | |
| 184 | + .add(insertInto(SIMPLE_TABLE).values(new String[]{"k", "i"}, new Object[]{0, 0})) | |
| 184 | 185 | .setConsistencyLevel(cl)); |
| 185 | 186 | else |
| 186 | 187 | c.session.execute(new SimpleStatement(String.format("INSERT INTO %s(k, i) VALUES (0, 0)", SIMPLE_TABLE)).setConsistencyLevel(cl)); |
modified driver-core/src/test/java/com/datastax/driver/core/AbstractReconnectionHandlerTest.java +18 −19
| @@ -15,13 +15,9 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.net.InetSocketAddress; | |
| 19 | -import java.util.concurrent.CyclicBarrier; | |
| 20 | -import java.util.concurrent.Executors; | |
| 21 | -import java.util.concurrent.ScheduledExecutorService; | |
| 22 | -import java.util.concurrent.TimeUnit; | |
| 23 | -import java.util.concurrent.atomic.AtomicReference; | |
| 24 | - | |
| 18 | +import com.datastax.driver.core.AbstractReconnectionHandler.HandlerFuture; | |
| 19 | +import com.datastax.driver.core.AbstractReconnectionHandlerTest.MockReconnectionWork.ReconnectBehavior; | |
| 20 | +import com.datastax.driver.core.policies.ReconnectionPolicy.ReconnectionSchedule; | |
| 25 | 21 | import com.google.common.util.concurrent.Futures; |
| 26 | 22 | import com.google.common.util.concurrent.ListenableFuture; |
| 27 | 23 | import com.google.common.util.concurrent.SettableFuture; |
| @@ -32,16 +28,17 @@ | ||
| 32 | 28 | import org.testng.annotations.BeforeMethod; |
| 33 | 29 | import org.testng.annotations.Test; |
| 34 | 30 | |
| 31 | +import java.net.InetSocketAddress; | |
| 32 | +import java.util.concurrent.CyclicBarrier; | |
| 33 | +import java.util.concurrent.Executors; | |
| 34 | +import java.util.concurrent.ScheduledExecutorService; | |
| 35 | +import java.util.concurrent.TimeUnit; | |
| 36 | +import java.util.concurrent.atomic.AtomicReference; | |
| 37 | + | |
| 35 | 38 | import static org.assertj.core.api.Assertions.assertThat; |
| 36 | -import static org.mockito.Mockito.spy; | |
| 37 | -import static org.mockito.Mockito.timeout; | |
| 38 | -import static org.mockito.Mockito.verify; | |
| 39 | +import static org.mockito.Mockito.*; | |
| 39 | 40 | import static org.testng.Assert.fail; |
| 40 | 41 | |
| 41 | -import com.datastax.driver.core.AbstractReconnectionHandler.HandlerFuture; | |
| 42 | -import com.datastax.driver.core.AbstractReconnectionHandlerTest.MockReconnectionWork.ReconnectBehavior; | |
| 43 | -import com.datastax.driver.core.policies.ReconnectionPolicy.ReconnectionSchedule; | |
| 44 | - | |
| 45 | 42 | public class AbstractReconnectionHandlerTest { |
| 46 | 43 | private static final Logger logger = LoggerFactory.getLogger(AbstractReconnectionHandlerTest.class); |
| 47 | 44 | |
| @@ -169,7 +166,7 @@ | ||
| 169 | 166 | // The future will be marked cancelled and thus not executed. |
| 170 | 167 | ListenableFuture<?> currentAttempt = future.get(); |
| 171 | 168 | assertThat(currentAttempt).isInstanceOf(HandlerFuture.class); |
| 172 | - HandlerFuture handlerFuture = (HandlerFuture)currentAttempt; | |
| 169 | + HandlerFuture handlerFuture = (HandlerFuture) currentAttempt; | |
| 173 | 170 | assertThat(handlerFuture.isCancelled()); |
| 174 | 171 | |
| 175 | 172 | // The next try should also be cancelled. |
| @@ -276,7 +273,7 @@ | ||
| 276 | 273 | |
| 277 | 274 | /** |
| 278 | 275 | * A reconnection schedule that allows manually setting the delay. |
| 279 | - * | |
| 276 | + * <p/> | |
| 280 | 277 | * To make testing easier, nextDelay blocks until tick() is called from the main thread. |
| 281 | 278 | */ |
| 282 | 279 | static class MockReconnectionSchedule implements ReconnectionSchedule { |
| @@ -321,14 +318,16 @@ | ||
| 321 | 318 | |
| 322 | 319 | /** |
| 323 | 320 | * Simulates the work done by the overridable methods of the handler. |
| 324 | - * | |
| 321 | + * <p/> | |
| 325 | 322 | * Allows choosing whether the next reconnect will succeed or throw an exception. |
| 326 | 323 | * To make testing easier, tryReconnect blocks until tick() is called from the main thread. |
| 327 | 324 | */ |
| 328 | 325 | static class MockReconnectionWork { |
| 329 | 326 | enum ReconnectBehavior { |
| 330 | 327 | SUCCEED, THROW_EXCEPTION |
| 331 | - }; | |
| 328 | + } | |
| 329 | + | |
| 330 | + ; | |
| 332 | 331 | |
| 333 | 332 | private final CyclicBarrier barrier = new CyclicBarrier(2); |
| 334 | 333 | |
| @@ -353,7 +352,7 @@ | ||
| 353 | 352 | case THROW_EXCEPTION: |
| 354 | 353 | logger.debug("simulate reconnection error"); |
| 355 | 354 | throw new ConnectionException(new InetSocketAddress(8888), |
| 356 | - "Simulated exception from mock reconnection"); | |
| 355 | + "Simulated exception from mock reconnection"); | |
| 357 | 356 | default: |
| 358 | 357 | throw new AssertionError(); |
| 359 | 358 | } |
modified driver-core/src/test/java/com/datastax/driver/core/AbstractReplicationStrategyTest.java +7 −9
| @@ -15,6 +15,9 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | +import com.google.common.collect.ImmutableList; | |
| 19 | +import com.google.common.collect.ImmutableList.Builder; | |
| 20 | + | |
| 18 | 21 | import java.net.InetAddress; |
| 19 | 22 | import java.net.InetSocketAddress; |
| 20 | 23 | import java.net.UnknownHostException; |
| @@ -23,13 +26,8 @@ | ||
| 23 | 26 | import java.util.Map; |
| 24 | 27 | import java.util.Set; |
| 25 | 28 | |
| 26 | -import com.google.common.collect.ImmutableList; | |
| 27 | -import com.google.common.collect.ImmutableList.Builder; | |
| 28 | - | |
| 29 | 29 | import static org.mockito.Mockito.mock; |
| 30 | -import static org.testng.Assert.assertEquals; | |
| 31 | -import static org.testng.Assert.assertNotNull; | |
| 32 | -import static org.testng.Assert.assertTrue; | |
| 30 | +import static org.testng.Assert.*; | |
| 33 | 31 | |
| 34 | 32 | /** |
| 35 | 33 | * Base class for replication strategy tests. Currently only supports testing |
| @@ -68,7 +66,7 @@ | ||
| 68 | 66 | if (!(o instanceof HostMock)) |
| 69 | 67 | return false; |
| 70 | 68 | |
| 71 | - return address.equals(((HostMock)o).address); | |
| 69 | + return address.equals(((HostMock) o).address); | |
| 72 | 70 | } |
| 73 | 71 | |
| 74 | 72 | @Override |
| @@ -102,7 +100,7 @@ | ||
| 102 | 100 | * Returns null if parameter host is not a mock |
| 103 | 101 | */ |
| 104 | 102 | protected static HostMock asMock(Host host) { |
| 105 | - return (host instanceof HostMock ? (HostMock)host : null); | |
| 103 | + return (host instanceof HostMock ? (HostMock) host : null); | |
| 106 | 104 | } |
| 107 | 105 | |
| 108 | 106 | /** |
| @@ -158,7 +156,7 @@ | ||
| 158 | 156 | protected static InetSocketAddress socketAddress(String address) { |
| 159 | 157 | try { |
| 160 | 158 | return new InetSocketAddress(InetAddress.getByName(address), 9042); |
| 161 | - } catch(UnknownHostException ex) { | |
| 159 | + } catch (UnknownHostException ex) { | |
| 162 | 160 | throw new RuntimeException(ex); |
| 163 | 161 | } |
| 164 | 162 | } |
modified driver-core/src/test/java/com/datastax/driver/core/Assertions.java +1 −1
| @@ -18,7 +18,7 @@ | ||
| 18 | 18 | /** |
| 19 | 19 | * Augment AssertJ with custom assertions for the Java driver. |
| 20 | 20 | */ |
| 21 | -public class Assertions extends org.assertj.core.api.Assertions{ | |
| 21 | +public class Assertions extends org.assertj.core.api.Assertions { | |
| 22 | 22 | public static ClusterAssert assertThat(Cluster cluster) { |
| 23 | 23 | return new ClusterAssert(cluster); |
| 24 | 24 | } |
modified driver-core/src/test/java/com/datastax/driver/core/AsyncQueryTest.java +14 −15
| @@ -15,27 +15,26 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.util.Collection; | |
| 19 | -import java.util.List; | |
| 20 | -import java.util.concurrent.*; | |
| 21 | - | |
| 18 | +import com.datastax.driver.core.exceptions.InvalidQueryException; | |
| 22 | 19 | import com.google.common.base.Function; |
| 23 | 20 | import com.google.common.collect.Lists; |
| 24 | 21 | import com.google.common.util.concurrent.*; |
| 25 | 22 | import org.testng.annotations.DataProvider; |
| 26 | 23 | import org.testng.annotations.Test; |
| 27 | 24 | |
| 25 | +import java.util.Collection; | |
| 26 | +import java.util.List; | |
| 27 | +import java.util.concurrent.*; | |
| 28 | + | |
| 28 | 29 | import static org.assertj.core.api.Assertions.assertThat; |
| 29 | 30 | import static org.testng.Assert.assertEquals; |
| 30 | 31 | import static org.testng.Assert.assertTrue; |
| 31 | 32 | |
| 32 | -import com.datastax.driver.core.exceptions.InvalidQueryException; | |
| 33 | - | |
| 34 | 33 | public class AsyncQueryTest extends CCMBridge.PerClassSingleNodeCluster { |
| 35 | 34 | |
| 36 | - @DataProvider(name="keyspace") | |
| 35 | + @DataProvider(name = "keyspace") | |
| 37 | 36 | public static Object[][] keyspace() { |
| 38 | - return new Object[][]{ { "asyncquerytest" }, { "\"AsyncQueryTest\"" } }; | |
| 37 | + return new Object[][]{{"asyncquerytest"}, {"\"AsyncQueryTest\""}}; | |
| 39 | 38 | } |
| 40 | 39 | |
| 41 | 40 | @Override |
| @@ -43,7 +42,7 @@ | ||
| 43 | 42 | List<String> definitions = Lists.newArrayList(); |
| 44 | 43 | |
| 45 | 44 | for (Object[] objects : keyspace()) { |
| 46 | - String keyspace = (String)objects[0]; | |
| 45 | + String keyspace = (String) objects[0]; | |
| 47 | 46 | |
| 48 | 47 | definitions.add(String.format("create keyspace %s WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1}", keyspace)); |
| 49 | 48 | definitions.add(String.format("create table %s.foo(k int primary key, v int)", keyspace)); |
| @@ -79,8 +78,8 @@ | ||
| 79 | 78 | Cluster cluster2 = null; |
| 80 | 79 | try { |
| 81 | 80 | cluster2 = Cluster.builder() |
| 82 | - .addContactPointsWithPorts(Lists.newArrayList(host.getSocketAddress())) | |
| 83 | - .build(); | |
| 81 | + .addContactPointsWithPorts(Lists.newArrayList(host.getSocketAddress())) | |
| 82 | + .build(); | |
| 84 | 83 | Session session2 = cluster2.newSession(); |
| 85 | 84 | |
| 86 | 85 | // Neither cluster2 nor session2 are initialized at this point |
| @@ -97,7 +96,7 @@ | ||
| 97 | 96 | } |
| 98 | 97 | |
| 99 | 98 | @Test(groups = "short", dataProvider = "keyspace", enabled = false, |
| 100 | - description = "disabled because the blocking USE call in the current pool implementation makes it deadlock") | |
| 99 | + description = "disabled because the blocking USE call in the current pool implementation makes it deadlock") | |
| 101 | 100 | public void should_chain_query_on_async_session_init_with_same_executor(String keyspace) throws Exception { |
| 102 | 101 | ListenableFuture<Integer> resultFuture = connectAndQuery(keyspace, MoreExecutors.sameThreadExecutor()); |
| 103 | 102 | |
| @@ -125,8 +124,8 @@ | ||
| 125 | 124 | Uninterruptibles.getUninterruptibly(resultFuture); |
| 126 | 125 | } catch (ExecutionException e) { |
| 127 | 126 | assertThat(e.getCause()) |
| 128 | - .isInstanceOf(InvalidQueryException.class) | |
| 129 | - .hasMessage("Keyspace 'wrong_keyspace' does not exist"); | |
| 127 | + .isInstanceOf(InvalidQueryException.class) | |
| 128 | + .hasMessage("Keyspace 'wrong_keyspace' does not exist"); | |
| 130 | 129 | } |
| 131 | 130 | } |
| 132 | 131 | |
| @@ -147,7 +146,7 @@ | ||
| 147 | 146 | } |
| 148 | 147 | |
| 149 | 148 | private static HostConnectionPool getPool(Session session) { |
| 150 | - Collection<HostConnectionPool> pools = ((SessionManager)session).pools.values(); | |
| 149 | + Collection<HostConnectionPool> pools = ((SessionManager) session).pools.values(); | |
| 151 | 150 | assertEquals(pools.size(), 1); |
| 152 | 151 | return pools.iterator().next(); |
| 153 | 152 | } |
modified driver-core/src/test/java/com/datastax/driver/core/AuthenticationTest.java +8 −9
| @@ -15,16 +15,15 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.util.concurrent.TimeUnit; | |
| 19 | - | |
| 18 | +import com.datastax.driver.core.exceptions.AuthenticationException; | |
| 19 | +import com.datastax.driver.core.exceptions.NoHostAvailableException; | |
| 20 | 20 | import org.slf4j.Logger; |
| 21 | 21 | import org.slf4j.LoggerFactory; |
| 22 | 22 | import org.testng.annotations.AfterClass; |
| 23 | 23 | import org.testng.annotations.BeforeClass; |
| 24 | 24 | import org.testng.annotations.Test; |
| 25 | 25 | |
| 26 | -import com.datastax.driver.core.exceptions.AuthenticationException; | |
| 27 | -import com.datastax.driver.core.exceptions.NoHostAvailableException; | |
| 26 | +import java.util.concurrent.TimeUnit; | |
| 28 | 27 | |
| 29 | 28 | /** |
| 30 | 29 | * Tests for authenticated cluster access |
| @@ -38,12 +37,12 @@ | ||
| 38 | 37 | /** |
| 39 | 38 | * creates a cluster and turns on password authentication before starting it. |
| 40 | 39 | */ |
| 41 | - @BeforeClass (groups = "short") | |
| 40 | + @BeforeClass(groups = "short") | |
| 42 | 41 | public void setupClusterWithAuthentication() throws InterruptedException { |
| 43 | 42 | ccm = CCMBridge.builder("test") |
| 44 | - .withCassandraConfiguration("authenticator", "PasswordAuthenticator") | |
| 45 | - .notStarted() | |
| 46 | - .build(); | |
| 43 | + .withCassandraConfiguration("authenticator", "PasswordAuthenticator") | |
| 44 | + .notStarted() | |
| 45 | + .build(); | |
| 47 | 46 | ccm.start(1, "-Dcassandra.superuser_setup_delay_ms=0"); |
| 48 | 47 | |
| 49 | 48 | // Even though we've override the default user setup delay, still wait |
| @@ -51,7 +50,7 @@ | ||
| 51 | 50 | TimeUnit.SECONDS.sleep(1); |
| 52 | 51 | } |
| 53 | 52 | |
| 54 | - @AfterClass (groups = "short") | |
| 53 | + @AfterClass(groups = "short") | |
| 55 | 54 | public void shutdownCluster() { |
| 56 | 55 | if (ccm != null) |
| 57 | 56 | ccm.stop(); |
modified driver-core/src/test/java/com/datastax/driver/core/BatchStatementTest.java +5 −6
| @@ -15,17 +15,16 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.exceptions.UnsupportedFeatureException; | |
| 19 | +import com.datastax.driver.core.utils.CassandraVersion; | |
| 20 | +import org.testng.annotations.Test; | |
| 21 | + | |
| 18 | 22 | import java.util.Collection; |
| 19 | 23 | import java.util.Collections; |
| 20 | 24 | |
| 21 | -import org.testng.annotations.Test; | |
| 22 | - | |
| 23 | 25 | import static org.testng.Assert.assertEquals; |
| 24 | 26 | import static org.testng.Assert.assertTrue; |
| 25 | 27 | |
| 26 | -import com.datastax.driver.core.exceptions.UnsupportedFeatureException; | |
| 27 | -import com.datastax.driver.core.utils.CassandraVersion; | |
| 28 | - | |
| 29 | 28 | public class BatchStatementTest extends CCMBridge.PerClassSingleNodeCluster { |
| 30 | 29 | |
| 31 | 30 | @Override |
| @@ -80,7 +79,7 @@ | ||
| 80 | 79 | } |
| 81 | 80 | |
| 82 | 81 | @Test(groups = "short") |
| 83 | - @CassandraVersion(major=2.0, minor=9, description="This will only work with C* 2.0.9 (CASSANDRA-7337)") | |
| 82 | + @CassandraVersion(major = 2.0, minor = 9, description = "This will only work with C* 2.0.9 (CASSANDRA-7337)") | |
| 84 | 83 | public void casBatchTest() throws Throwable { |
| 85 | 84 | try { |
| 86 | 85 | PreparedStatement st = session.prepare("INSERT INTO test (k, v) VALUES (?, ?) IF NOT EXISTS"); |
modified driver-core/src/test/java/com/datastax/driver/core/BoundStatementTest.java +9 −11
| @@ -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 | - | |
| 18 | +import com.datastax.driver.core.exceptions.InvalidTypeException; | |
| 21 | 19 | import com.google.common.collect.Lists; |
| 22 | 20 | import org.testng.annotations.BeforeClass; |
| 23 | 21 | import org.testng.annotations.Test; |
| 24 | 22 | |
| 23 | +import java.util.Collection; | |
| 24 | + | |
| 25 | 25 | import static org.assertj.core.api.Assertions.assertThat; |
| 26 | 26 | import static org.assertj.core.api.Assertions.fail; |
| 27 | 27 | |
| 28 | -import com.datastax.driver.core.exceptions.InvalidTypeException; | |
| 29 | - | |
| 30 | 28 | public class BoundStatementTest extends CCMBridge.PerClassSingleNodeCluster { |
| 31 | 29 | |
| 32 | 30 | PreparedStatement prepared; |
| @@ -47,16 +45,16 @@ | ||
| 47 | 45 | BoundStatement statement = prepared.bind(1, "test", Lists.newArrayList(1)); |
| 48 | 46 | |
| 49 | 47 | assertThat(statement.getInt(0)) |
| 50 | - .isEqualTo(statement.getInt("k")) | |
| 51 | - .isEqualTo(1); | |
| 48 | + .isEqualTo(statement.getInt("k")) | |
| 49 | + .isEqualTo(1); | |
| 52 | 50 | |
| 53 | 51 | assertThat(statement.getString(1)) |
| 54 | - .isEqualTo(statement.getString("v1")) | |
| 55 | - .isEqualTo("test"); | |
| 52 | + .isEqualTo(statement.getString("v1")) | |
| 53 | + .isEqualTo("test"); | |
| 56 | 54 | |
| 57 | 55 | assertThat(statement.getList(2, Integer.class)) |
| 58 | - .isEqualTo(statement.getList("v2", Integer.class)) | |
| 59 | - .isEqualTo(Lists.newArrayList(1)); | |
| 56 | + .isEqualTo(statement.getList("v2", Integer.class)) | |
| 57 | + .isEqualTo(Lists.newArrayList(1)); | |
| 60 | 58 | |
| 61 | 59 | try { |
| 62 | 60 | statement.getString(0); |
modified driver-core/src/test/java/com/datastax/driver/core/CCMBridge.java +59 −45
| @@ -15,17 +15,9 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.io.*; | |
| 19 | -import java.net.InetAddress; | |
| 20 | -import java.net.InetSocketAddress; | |
| 21 | -import java.net.Socket; | |
| 22 | -import java.net.UnknownHostException; | |
| 23 | -import java.util.Collection; | |
| 24 | -import java.util.Collections; | |
| 25 | -import java.util.Map; | |
| 26 | -import java.util.concurrent.TimeUnit; | |
| 27 | -import java.util.concurrent.atomic.AtomicLong; | |
| 28 | - | |
| 18 | +import com.datastax.driver.core.exceptions.AlreadyExistsException; | |
| 19 | +import com.datastax.driver.core.exceptions.DriverException; | |
| 20 | +import com.datastax.driver.core.exceptions.NoHostAvailableException; | |
| 29 | 21 | import com.google.common.base.Joiner; |
| 30 | 22 | import com.google.common.collect.ImmutableMap; |
| 31 | 23 | import com.google.common.collect.Maps; |
| @@ -38,14 +30,20 @@ | ||
| 38 | 30 | import org.testng.annotations.AfterClass; |
| 39 | 31 | import org.testng.annotations.BeforeClass; |
| 40 | 32 | |
| 41 | -import static org.testng.Assert.fail; | |
| 42 | - | |
| 43 | -import com.datastax.driver.core.exceptions.AlreadyExistsException; | |
| 44 | -import com.datastax.driver.core.exceptions.DriverException; | |
| 45 | -import com.datastax.driver.core.exceptions.NoHostAvailableException; | |
| 33 | +import java.io.*; | |
| 34 | +import java.net.InetAddress; | |
| 35 | +import java.net.InetSocketAddress; | |
| 36 | +import java.net.Socket; | |
| 37 | +import java.net.UnknownHostException; | |
| 38 | +import java.util.Collection; | |
| 39 | +import java.util.Collections; | |
| 40 | +import java.util.Map; | |
| 41 | +import java.util.concurrent.TimeUnit; | |
| 42 | +import java.util.concurrent.atomic.AtomicLong; | |
| 46 | 43 | |
| 47 | 44 | import static com.datastax.driver.core.TestUtils.CREATE_KEYSPACE_SIMPLE_FORMAT; |
| 48 | 45 | import static com.datastax.driver.core.TestUtils.SIMPLE_KEYSPACE; |
| 46 | +import static org.testng.Assert.fail; | |
| 49 | 47 | |
| 50 | 48 | public class CCMBridge { |
| 51 | 49 | |
| @@ -81,11 +79,11 @@ | ||
| 81 | 79 | * The environment variables to use when invoking CCM. Inherits the current processes environment, but will also |
| 82 | 80 | * prepend to the PATH variable the value of the 'ccm.path' property and set JAVA_HOME variable to the |
| 83 | 81 | * 'ccm.java.home' variable. |
| 84 | - * | |
| 82 | + * <p/> | |
| 85 | 83 | * At times it is necessary to use a separate java install for CCM then what is being used for running tests. |
| 86 | 84 | * For example, if you want to run tests with JDK 6 but against Cassandra 2.0, which requires JDK 7. |
| 87 | 85 | */ |
| 88 | - private static final Map<String,String> ENVIRONMENT_MAP; | |
| 86 | + private static final Map<String, String> ENVIRONMENT_MAP; | |
| 89 | 87 | |
| 90 | 88 | /** |
| 91 | 89 | * The command to use to launch CCM |
| @@ -98,7 +96,7 @@ | ||
| 98 | 96 | String branch = System.getProperty("cassandra.branch"); |
| 99 | 97 | if (installDirectory != null && !installDirectory.trim().isEmpty()) { |
| 100 | 98 | CASSANDRA_INSTALL_ARGS = "--install-dir=" + new File(installDirectory).getAbsolutePath(); |
| 101 | - } else if(branch != null && !branch.trim().isEmpty()) { | |
| 99 | + } else if (branch != null && !branch.trim().isEmpty()) { | |
| 102 | 100 | CASSANDRA_INSTALL_ARGS = "-v git:" + branch; |
| 103 | 101 | } else { |
| 104 | 102 | CASSANDRA_INSTALL_ARGS = "-v " + CASSANDRA_VERSION; |
| @@ -111,12 +109,12 @@ | ||
| 111 | 109 | IP_PREFIX = ip_prefix; |
| 112 | 110 | |
| 113 | 111 | // Inherit the current environment. |
| 114 | - Map<String,String> envMap = Maps.newHashMap(new ProcessBuilder().environment()); | |
| 112 | + Map<String, String> envMap = Maps.newHashMap(new ProcessBuilder().environment()); | |
| 115 | 113 | // If ccm.path is set, override the PATH variable with it. |
| 116 | 114 | String ccmPath = System.getProperty("ccm.path"); |
| 117 | - if(ccmPath != null) { | |
| 115 | + if (ccmPath != null) { | |
| 118 | 116 | String existingPath = envMap.get("PATH"); |
| 119 | - if(existingPath == null) { | |
| 117 | + if (existingPath == null) { | |
| 120 | 118 | existingPath = ""; |
| 121 | 119 | } |
| 122 | 120 | envMap.put("PATH", ccmPath + File.pathSeparator + existingPath); |
| @@ -130,7 +128,7 @@ | ||
| 130 | 128 | |
| 131 | 129 | // If ccm.java.home is set, override the JAVA_HOME variable with it. |
| 132 | 130 | String ccmJavaHome = System.getProperty("ccm.java.home"); |
| 133 | - if(ccmJavaHome != null) { | |
| 131 | + if (ccmJavaHome != null) { | |
| 134 | 132 | envMap.put("JAVA_HOME", ccmJavaHome); |
| 135 | 133 | } |
| 136 | 134 | ENVIRONMENT_MAP = ImmutableMap.copyOf(envMap); |
| @@ -138,6 +136,7 @@ | ||
| 138 | 136 | |
| 139 | 137 | /** |
| 140 | 138 | * Checks if the operating system is a Windows one |
| 139 | + * | |
| 141 | 140 | * @return <code>true</code> if the operating system is a Windows one, <code>false</code> otherwise. |
| 142 | 141 | */ |
| 143 | 142 | private static boolean isWindows() { |
| @@ -156,11 +155,12 @@ | ||
| 156 | 155 | * <p> |
| 157 | 156 | * Extracts a keystore from the classpath into a temporary file. |
| 158 | 157 | * </p> |
| 159 | - * | |
| 158 | + * <p/> | |
| 160 | 159 | * <p> |
| 161 | 160 | * This is needed as the keystore could be part of a built test jar used by other |
| 162 | 161 | * projects, and they need to be extracted to a file system so cassandra may use them. |
| 163 | 162 | * </p> |
| 163 | + * | |
| 164 | 164 | * @param storePath Path in classpath where the keystore exists. |
| 165 | 165 | * @return The generated File. |
| 166 | 166 | */ |
| @@ -228,7 +228,7 @@ | ||
| 228 | 228 | |
| 229 | 229 | public void stop(String clusterName) { |
| 230 | 230 | logger.info("Stopping Cluster : " + clusterName); |
| 231 | - execute(CCM_COMMAND + " stop "+clusterName); | |
| 231 | + execute(CCM_COMMAND + " stop " + clusterName); | |
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | public void forceStop(int n) { |
| @@ -269,7 +269,7 @@ | ||
| 269 | 269 | String binaryItf = IP_PREFIX + n + ":" + binaryPort; |
| 270 | 270 | String remoteLogItf = IP_PREFIX + n + ":" + remoteDebugPort; |
| 271 | 271 | execute(CCM_COMMAND + " add node%d -i %s%d -b -t %s -l %s --binary-itf %s -j %d -r %s -s", |
| 272 | - n, IP_PREFIX, n, thriftItf, storageItf, binaryItf, jmxPort, remoteLogItf); | |
| 272 | + n, IP_PREFIX, n, thriftItf, storageItf, binaryItf, jmxPort, remoteLogItf); | |
| 273 | 273 | execute(CCM_COMMAND + " node%d start --wait-other-notice --wait-for-binary-proto", n); |
| 274 | 274 | } |
| 275 | 275 | |
| @@ -294,12 +294,14 @@ | ||
| 294 | 294 | Executor executor = new DefaultExecutor(); |
| 295 | 295 | |
| 296 | 296 | LogOutputStream outStream = new LogOutputStream() { |
| 297 | - @Override protected void processLine(String line, int logLevel) { | |
| 297 | + @Override | |
| 298 | + protected void processLine(String line, int logLevel) { | |
| 298 | 299 | logger.debug("ccmout> " + line); |
| 299 | 300 | } |
| 300 | 301 | }; |
| 301 | 302 | LogOutputStream errStream = new LogOutputStream() { |
| 302 | - @Override protected void processLine(String line, int logLevel) { | |
| 303 | + @Override | |
| 304 | + protected void processLine(String line, int logLevel) { | |
| 303 | 305 | logger.error("ccmerr> " + line); |
| 304 | 306 | } |
| 305 | 307 | }; |
| @@ -408,7 +410,7 @@ | ||
| 408 | 410 | |
| 409 | 411 | protected static CCMBridge ccmBridge; |
| 410 | 412 | private static boolean erroredOut; |
| 411 | - private static boolean clusterInitialized=false; | |
| 413 | + private static boolean clusterInitialized = false; | |
| 412 | 414 | private static AtomicLong ksNumber; |
| 413 | 415 | protected String keyspace; |
| 414 | 416 | |
| @@ -429,25 +431,25 @@ | ||
| 429 | 431 | erroredOut = true; |
| 430 | 432 | } |
| 431 | 433 | |
| 432 | - @BeforeClass(groups = { "isolated", "short", "long" }) | |
| 434 | + @BeforeClass(groups = {"isolated", "short", "long"}) | |
| 433 | 435 | public void beforeClass() { |
| 434 | 436 | maybeInitCluster(); |
| 435 | 437 | initKeyspace(); |
| 436 | 438 | } |
| 437 | 439 | |
| 438 | - @AfterClass(groups = { "isolated", "short", "long" }) | |
| 440 | + @AfterClass(groups = {"isolated", "short", "long"}) | |
| 439 | 441 | public void afterClass() { |
| 440 | 442 | try { |
| 441 | 443 | clearSimpleKeyspace(); |
| 442 | 444 | } finally { |
| 443 | - if(cluster != null) { | |
| 445 | + if (cluster != null) { | |
| 444 | 446 | cluster.close(); |
| 445 | 447 | } |
| 446 | 448 | } |
| 447 | 449 | } |
| 448 | 450 | |
| 449 | - private void maybeInitCluster(){ | |
| 450 | - if (!clusterInitialized){ | |
| 451 | + private void maybeInitCluster() { | |
| 452 | + if (!clusterInitialized) { | |
| 451 | 453 | try { |
| 452 | 454 | //launch ccm cluster |
| 453 | 455 | ccmBridge = CCMBridge.builder("test-class").withoutNodes().notStarted().build(); |
| @@ -481,8 +483,8 @@ | ||
| 481 | 483 | builder = configure(builder); |
| 482 | 484 | |
| 483 | 485 | cluster = builder.addContactPointsWithPorts(Collections.singletonList(hostAddress)) |
| 484 | - .withNettyOptions(TestUtils.nonQuietClusterCloseOptions) | |
| 485 | - .build(); | |
| 486 | + .withNettyOptions(TestUtils.nonQuietClusterCloseOptions) | |
| 487 | + .build(); | |
| 486 | 488 | session = cluster.connect(); |
| 487 | 489 | keyspace = SIMPLE_KEYSPACE + "_" + ksNumber.incrementAndGet(); |
| 488 | 490 | session.execute(String.format(CREATE_KEYSPACE_SIMPLE_FORMAT, keyspace, 1)); |
| @@ -509,7 +511,7 @@ | ||
| 509 | 511 | } |
| 510 | 512 | |
| 511 | 513 | private void clearSimpleKeyspace() { |
| 512 | - if(keyspace != null) { | |
| 514 | + if (keyspace != null) { | |
| 513 | 515 | logger.debug("Removing keyspace {}.", keyspace); |
| 514 | 516 | // Temporarily extend read timeout to 1 minute to accommodate dropping keyspaces and |
| 515 | 517 | // tables being slow, particularly in a CI environment. |
| @@ -520,7 +522,7 @@ | ||
| 520 | 522 | if (ksm != null) { |
| 521 | 523 | // drop each table individually as this seems to be more dependable than dropping |
| 522 | 524 | // the entire keyspace at once if it has many tables. |
| 523 | - if(ksm.getTables().size() > 10) { | |
| 525 | + if (ksm.getTables().size() > 10) { | |
| 524 | 526 | for (TableMetadata table : ksm.getTables()) { |
| 525 | 527 | logger.debug("Dropping table {}.{}.", keyspace, table.getName()); |
| 526 | 528 | session.execute("DROP TABLE " + keyspace + "." + table.getName()); |
| @@ -607,10 +609,12 @@ | ||
| 607 | 609 | } |
| 608 | 610 | } |
| 609 | 611 | |
| 610 | - /** use {@link #builder(String)} to get an instance */ | |
| 612 | + /** | |
| 613 | + * use {@link #builder(String)} to get an instance | |
| 614 | + */ | |
| 611 | 615 | public static class Builder { |
| 612 | 616 | private final String clusterName; |
| 613 | - private Integer[] nodes = { 1 }; | |
| 617 | + private Integer[] nodes = {1}; | |
| 614 | 618 | private boolean start = true; |
| 615 | 619 | private String cassandraInstallArgs = CASSANDRA_INSTALL_ARGS; |
| 616 | 620 | private String[] startOptions = new String[0]; |
| @@ -621,7 +625,9 @@ | ||
| 621 | 625 | this.clusterName = clusterName; |
| 622 | 626 | } |
| 623 | 627 | |
| 624 | - /** Number of nodes for each DC. Defaults to [1] (1 DC with 1 node) */ | |
| 628 | + /** | |
| 629 | + * Number of nodes for each DC. Defaults to [1] (1 DC with 1 node) | |
| 630 | + */ | |
| 625 | 631 | public Builder withNodes(Integer... nodes) { |
| 626 | 632 | this.nodes = nodes; |
| 627 | 633 | return this; |
| @@ -644,25 +650,33 @@ | ||
| 644 | 650 | return this; |
| 645 | 651 | } |
| 646 | 652 | |
| 647 | - /** Whether to start the cluster immediately (defaults to true if this is never called) */ | |
| 653 | + /** | |
| 654 | + * Whether to start the cluster immediately (defaults to true if this is never called) | |
| 655 | + */ | |
| 648 | 656 | public Builder notStarted() { |
| 649 | 657 | this.start = false; |
| 650 | 658 | return this; |
| 651 | 659 | } |
| 652 | 660 | |
| 653 | - /** Defaults to system property cassandra.version */ | |
| 661 | + /** | |
| 662 | + * Defaults to system property cassandra.version | |
| 663 | + */ | |
| 654 | 664 | public Builder withCassandraVersion(String cassandraVersion) { |
| 655 | 665 | this.cassandraInstallArgs = "-v " + cassandraVersion; |
| 656 | 666 | return this; |
| 657 | 667 | } |
| 658 | 668 | |
| 659 | - /** Free-form options that will be added at the end of the start command */ | |
| 669 | + /** | |
| 670 | + * Free-form options that will be added at the end of the start command | |
| 671 | + */ | |
| 660 | 672 | public Builder withStartOptions(String... options) { |
| 661 | 673 | this.startOptions = options; |
| 662 | 674 | return this; |
| 663 | 675 | } |
| 664 | 676 | |
| 665 | - /** Customizes entries in cassandra.yaml (can be called multiple times) */ | |
| 677 | + /** | |
| 678 | + * Customizes entries in cassandra.yaml (can be called multiple times) | |
| 679 | + */ | |
| 666 | 680 | public Builder withCassandraConfiguration(String key, String value) { |
| 667 | 681 | this.cassandraConfiguration.put(key, value); |
| 668 | 682 | return this; |
modified driver-core/src/test/java/com/datastax/driver/core/CaseSensitivityTest.java +11 −14
| @@ -17,11 +17,8 @@ | ||
| 17 | 17 | |
| 18 | 18 | import org.testng.annotations.Test; |
| 19 | 19 | |
| 20 | -import static org.testng.Assert.assertEquals; | |
| 21 | -import static org.testng.Assert.assertNotNull; | |
| 22 | -import static org.testng.Assert.assertNull; | |
| 23 | - | |
| 24 | 20 | import static com.datastax.driver.core.TestUtils.CREATE_KEYSPACE_SIMPLE_FORMAT; |
| 21 | +import static org.testng.Assert.*; | |
| 25 | 22 | |
| 26 | 23 | public class CaseSensitivityTest { |
| 27 | 24 | |
| @@ -38,11 +35,11 @@ | ||
| 38 | 35 | @Test(groups = "short") |
| 39 | 36 | public void testCaseInsensitiveKeyspace() throws Throwable { |
| 40 | 37 | CCMBridge.CCMCluster c = CCMBridge.buildCluster(1, Cluster.builder() |
| 41 | - .withQueryOptions(new QueryOptions() | |
| 42 | - .setRefreshNodeIntervalMillis(0) | |
| 43 | - .setRefreshNodeListIntervalMillis(0) | |
| 44 | - .setRefreshSchemaIntervalMillis(0) | |
| 45 | - ) | |
| 38 | + .withQueryOptions(new QueryOptions() | |
| 39 | + .setRefreshNodeIntervalMillis(0) | |
| 40 | + .setRefreshNodeListIntervalMillis(0) | |
| 41 | + .setRefreshSchemaIntervalMillis(0) | |
| 42 | + ) | |
| 46 | 43 | ); |
| 47 | 44 | Session s = c.session; |
| 48 | 45 | try { |
| @@ -64,11 +61,11 @@ | ||
| 64 | 61 | @Test(groups = "short") |
| 65 | 62 | public void testCaseSensitiveKeyspace() throws Throwable { |
| 66 | 63 | CCMBridge.CCMCluster c = CCMBridge.buildCluster(1, Cluster.builder() |
| 67 | - .withQueryOptions(new QueryOptions() | |
| 68 | - .setRefreshNodeIntervalMillis(0) | |
| 69 | - .setRefreshNodeListIntervalMillis(0) | |
| 70 | - .setRefreshSchemaIntervalMillis(0) | |
| 71 | - ) | |
| 64 | + .withQueryOptions(new QueryOptions() | |
| 65 | + .setRefreshNodeIntervalMillis(0) | |
| 66 | + .setRefreshNodeListIntervalMillis(0) | |
| 67 | + .setRefreshSchemaIntervalMillis(0) | |
| 68 | + ) | |
| 72 | 69 | ); |
| 73 | 70 | Session s = c.session; |
| 74 | 71 | try { |
modified driver-core/src/test/java/com/datastax/driver/core/CassandraTypeParserTest.java +3 −2
| @@ -15,9 +15,10 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | +import org.testng.annotations.Test; | |
| 19 | + | |
| 18 | 20 | import java.util.Arrays; |
| 19 | 21 | |
| 20 | -import org.testng.annotations.Test; | |
| 21 | 22 | import static org.testng.Assert.*; |
| 22 | 23 | |
| 23 | 24 | public class CassandraTypeParserTest { |
| @@ -42,7 +43,7 @@ | ||
| 42 | 43 | public void parseWithCompositeTest() { |
| 43 | 44 | |
| 44 | 45 | String s = "org.apache.cassandra.db.marshal.CompositeType(org.apache.cassandra.db.marshal.Int32Type, org.apache.cassandra.db.marshal.UTF8Type,"; |
| 45 | - s += "org.apache.cassandra.db.marshal.ColumnToCollectionType(6162:org.apache.cassandra.db.marshal.ListType(org.apache.cassandra.db.marshal.Int32Type)))"; | |
| 46 | + s += "org.apache.cassandra.db.marshal.ColumnToCollectionType(6162:org.apache.cassandra.db.marshal.ListType(org.apache.cassandra.db.marshal.Int32Type)))"; | |
| 46 | 47 | CassandraTypeParser.ParseResult r1 = CassandraTypeParser.parseWithComposite(s); |
| 47 | 48 | assertTrue(r1.isComposite); |
| 48 | 49 | assertEquals(r1.types, Arrays.asList(DataType.cint(), DataType.text())); |
modified driver-core/src/test/java/com/datastax/driver/core/ClusterAssert.java +15 −14
| @@ -15,14 +15,14 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | +import com.google.common.collect.Iterators; | |
| 19 | +import org.assertj.core.api.AbstractAssert; | |
| 20 | + | |
| 18 | 21 | import java.util.Iterator; |
| 19 | 22 | import java.util.Set; |
| 20 | 23 | import java.util.TreeSet; |
| 21 | 24 | import java.util.concurrent.TimeUnit; |
| 22 | 25 | |
| 23 | -import com.google.common.collect.Iterators; | |
| 24 | -import org.assertj.core.api.AbstractAssert; | |
| 25 | - | |
| 26 | 26 | import static org.assertj.core.api.Assertions.assertThat; |
| 27 | 27 | |
| 28 | 28 | public class ClusterAssert extends AbstractAssert<ClusterAssert, Cluster> { |
| @@ -56,26 +56,27 @@ | ||
| 56 | 56 | // Wait for the node to be added if it's not already known. |
| 57 | 57 | // In 2.2+ C* does not send an added event until the node is ready so we wait a long time. |
| 58 | 58 | Host host = TestUtils.findOrWaitForHost(actual, hostNumber, |
| 59 | - 60 + Cluster.NEW_NODE_DELAY_SECONDS, TimeUnit.SECONDS); | |
| 59 | + 60 + Cluster.NEW_NODE_DELAY_SECONDS, TimeUnit.SECONDS); | |
| 60 | 60 | return new HostAssert(host, actual); |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | public HostAssert host(String hostAddress) { |
| 64 | 64 | Host host = TestUtils.findOrWaitForHost(actual, hostAddress, |
| 65 | - 60 + Cluster.NEW_NODE_DELAY_SECONDS, TimeUnit.SECONDS); | |
| 65 | + 60 + Cluster.NEW_NODE_DELAY_SECONDS, TimeUnit.SECONDS); | |
| 66 | 66 | return new HostAssert(host, actual); |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
| 70 | 70 | * Asserts that {@link Cluster}'s {@link Host}s have valid {@link TokenRange}s with the given keyspace. |
| 71 | - * | |
| 71 | + * <p/> | |
| 72 | 72 | * Ensures that no ranges intersect and that they cover the entire ring. |
| 73 | + * | |
| 73 | 74 | * @param keyspace Keyspace to grab {@link TokenRange}s from. |
| 74 | 75 | */ |
| 75 | 76 | public ClusterAssert hasValidTokenRanges(String keyspace) { |
| 76 | 77 | // Sort the token ranges so they are in order (needed for vnodes). |
| 77 | 78 | Set<TokenRange> ranges = new TreeSet<TokenRange>(); |
| 78 | - for(Host host : actual.getMetadata().getAllHosts()) { | |
| 79 | + for (Host host : actual.getMetadata().getAllHosts()) { | |
| 79 | 80 | ranges.addAll(actual.getMetadata().getTokenRanges(keyspace, host)); |
| 80 | 81 | } |
| 81 | 82 | return hasValidTokenRanges(ranges); |
| @@ -83,7 +84,7 @@ | ||
| 83 | 84 | |
| 84 | 85 | /** |
| 85 | 86 | * Asserts that {@link Cluster}'s {@link Host}s have valid {@link TokenRange}s. |
| 86 | - * | |
| 87 | + * <p/> | |
| 87 | 88 | * Ensures that no ranges intersect and that they cover the entire ring. |
| 88 | 89 | */ |
| 89 | 90 | public ClusterAssert hasValidTokenRanges() { |
| @@ -94,13 +95,13 @@ | ||
| 94 | 95 | |
| 95 | 96 | /** |
| 96 | 97 | * Asserts that given Set of {@link TokenRange}s are valid. |
| 97 | - * | |
| 98 | + * <p/> | |
| 98 | 99 | * Ensures that no ranges intersect and that they cover the entire ring. |
| 99 | 100 | */ |
| 100 | 101 | private ClusterAssert hasValidTokenRanges(Set<TokenRange> ranges) { |
| 101 | 102 | // Ensure no ranges intersect. |
| 102 | 103 | Iterator<TokenRange> it = ranges.iterator(); |
| 103 | - while(it.hasNext()) { | |
| 104 | + while (it.hasNext()) { | |
| 104 | 105 | TokenRange range = it.next(); |
| 105 | 106 | Assertions.assertThat(range).doesNotIntersect(Iterators.toArray(it, TokenRange.class)); |
| 106 | 107 | } |
| @@ -108,15 +109,15 @@ | ||
| 108 | 109 | // Ensure the defined ranges cover the entire ring. |
| 109 | 110 | it = ranges.iterator(); |
| 110 | 111 | TokenRange mergedRange = it.next(); |
| 111 | - while(it.hasNext()) { | |
| 112 | + while (it.hasNext()) { | |
| 112 | 113 | TokenRange next = it.next(); |
| 113 | 114 | mergedRange = mergedRange.mergeWith(next); |
| 114 | 115 | } |
| 115 | 116 | boolean isFullRing = mergedRange.getStart().equals(mergedRange.getEnd()) |
| 116 | - && !mergedRange.isEmpty(); | |
| 117 | + && !mergedRange.isEmpty(); | |
| 117 | 118 | assertThat(isFullRing) |
| 118 | - .as("Ring is not fully defined for Cluster.") | |
| 119 | - .isTrue(); | |
| 119 | + .as("Ring is not fully defined for Cluster.") | |
| 120 | + .isTrue(); | |
| 120 | 121 | |
| 121 | 122 | return this; |
| 122 | 123 | } |
modified driver-core/src/test/java/com/datastax/driver/core/ClusterDelegateTest.java +2 −2
| @@ -15,11 +15,11 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.util.Collection; | |
| 19 | - | |
| 20 | 18 | import com.google.common.collect.Lists; |
| 21 | 19 | import org.testng.annotations.Test; |
| 22 | 20 | |
| 21 | +import java.util.Collection; | |
| 22 | + | |
| 23 | 23 | import static org.assertj.core.api.Assertions.assertThat; |
| 24 | 24 | |
| 25 | 25 | public class ClusterDelegateTest extends CCMBridge.PerClassSingleNodeCluster { |
modified driver-core/src/test/java/com/datastax/driver/core/ClusterInitTest.java +48 −53
| @@ -15,15 +15,8 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.net.InetAddress; | |
| 19 | -import java.net.InetSocketAddress; | |
| 20 | -import java.net.UnknownHostException; | |
| 21 | -import java.util.Collections; | |
| 22 | -import java.util.List; | |
| 23 | -import java.util.Map; | |
| 24 | -import java.util.concurrent.TimeUnit; | |
| 25 | -import java.util.concurrent.TimeoutException; | |
| 26 | - | |
| 18 | +import com.datastax.driver.core.exceptions.NoHostAvailableException; | |
| 19 | +import com.datastax.driver.core.policies.ConstantReconnectionPolicy; | |
| 27 | 20 | import com.google.common.collect.ImmutableMap; |
| 28 | 21 | import com.google.common.collect.ImmutableSet; |
| 29 | 22 | import com.google.common.collect.Lists; |
| @@ -35,13 +28,14 @@ | ||
| 35 | 28 | import org.slf4j.LoggerFactory; |
| 36 | 29 | import org.testng.annotations.Test; |
| 37 | 30 | |
| 38 | -import static org.mockito.Mockito.atLeast; | |
| 39 | -import static org.mockito.Mockito.atMost; | |
| 40 | -import static org.mockito.Mockito.spy; | |
| 41 | -import static org.mockito.Mockito.verify; | |
| 42 | - | |
| 43 | -import com.datastax.driver.core.exceptions.NoHostAvailableException; | |
| 44 | -import com.datastax.driver.core.policies.ConstantReconnectionPolicy; | |
| 31 | +import java.net.InetAddress; | |
| 32 | +import java.net.InetSocketAddress; | |
| 33 | +import java.net.UnknownHostException; | |
| 34 | +import java.util.Collections; | |
| 35 | +import java.util.List; | |
| 36 | +import java.util.Map; | |
| 37 | +import java.util.concurrent.TimeUnit; | |
| 38 | +import java.util.concurrent.TimeoutException; | |
| 45 | 39 | |
| 46 | 40 | import static com.datastax.driver.core.Assertions.assertThat; |
| 47 | 41 | import static com.datastax.driver.core.Assertions.fail; |
| @@ -49,6 +43,7 @@ | ||
| 49 | 43 | import static com.datastax.driver.core.HostDistance.LOCAL; |
| 50 | 44 | import static com.datastax.driver.core.TestUtils.nonDebouncingQueryOptions; |
| 51 | 45 | import static com.datastax.driver.core.TestUtils.nonQuietClusterCloseOptions; |
| 46 | +import static org.mockito.Mockito.*; | |
| 52 | 47 | |
| 53 | 48 | public class ClusterInitTest { |
| 54 | 49 | private static final Logger logger = LoggerFactory.getLogger(ClusterInitTest.class); |
| @@ -99,19 +94,19 @@ | ||
| 99 | 94 | PoolingOptions poolingOptions = new PoolingOptions().setConnectionsPerHost(LOCAL, 1, 1); |
| 100 | 95 | |
| 101 | 96 | cluster = Cluster.builder() |
| 102 | - .withPort(scassandra.getBinaryPort()) | |
| 103 | - .addContactPoints( | |
| 104 | - realHostAddress, | |
| 105 | - failingHosts.get(0).address, failingHosts.get(1).address, | |
| 106 | - failingHosts.get(2).address, failingHosts.get(3).address, | |
| 107 | - missingHostAddress | |
| 108 | - ) | |
| 109 | - .withSocketOptions(socketOptions) | |
| 110 | - .withReconnectionPolicy(reconnectionPolicy) | |
| 111 | - .withPoolingOptions(poolingOptions) | |
| 112 | - .withProtocolVersion(TestUtils.getDesiredProtocolVersion()) | |
| 113 | - .withQueryOptions(nonDebouncingQueryOptions()) | |
| 114 | - .build(); | |
| 97 | + .withPort(scassandra.getBinaryPort()) | |
| 98 | + .addContactPoints( | |
| 99 | + realHostAddress, | |
| 100 | + failingHosts.get(0).address, failingHosts.get(1).address, | |
| 101 | + failingHosts.get(2).address, failingHosts.get(3).address, | |
| 102 | + missingHostAddress | |
| 103 | + ) | |
| 104 | + .withSocketOptions(socketOptions) | |
| 105 | + .withReconnectionPolicy(reconnectionPolicy) | |
| 106 | + .withPoolingOptions(poolingOptions) | |
| 107 | + .withProtocolVersion(TestUtils.getDesiredProtocolVersion()) | |
| 108 | + .withQueryOptions(nonDebouncingQueryOptions()) | |
| 109 | + .build(); | |
| 115 | 110 | cluster.connect(); |
| 116 | 111 | |
| 117 | 112 | // For information only: |
| @@ -137,7 +132,7 @@ | ||
| 137 | 132 | // There is a possible race here in that the host is marked down in a separate Executor in onDown |
| 138 | 133 | // and then starts a periodic reconnection attempt shortly after. Since setDown is called before |
| 139 | 134 | // startPeriodicReconnectionAttempt, we add a slight delay here if the future isn't set yet. |
| 140 | - if(host.getReconnectionAttemptFuture() == null || host.getReconnectionAttemptFuture().isDone()) { | |
| 135 | + if (host.getReconnectionAttemptFuture() == null || host.getReconnectionAttemptFuture().isDone()) { | |
| 141 | 136 | logger.warn("Periodic Reconnection Attempt hasn't started yet for {}, waiting 1 second and then checking.", host); |
| 142 | 137 | Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS); |
| 143 | 138 | } |
| @@ -163,19 +158,19 @@ | ||
| 163 | 158 | * @jira_ticket JAVA-954 |
| 164 | 159 | * @expected_result No reconnection scheduled. |
| 165 | 160 | */ |
| 166 | - @Test(groups="short", expectedExceptions = NoHostAvailableException.class) | |
| 161 | + @Test(groups = "short", expectedExceptions = NoHostAvailableException.class) | |
| 167 | 162 | public void should_not_schedule_reconnections_before_init_complete() { |
| 168 | 163 | // Both contact points time out so we're sure we'll try both of them and init will never complete. |
| 169 | 164 | List<FakeHost> hosts = Lists.newArrayList( |
| 170 | - new FakeHost(CCMBridge.ipOfNode(0), 9042, THROWING_CONNECT_TIMEOUTS), | |
| 171 | - new FakeHost(CCMBridge.ipOfNode(1), 9042, THROWING_CONNECT_TIMEOUTS)); | |
| 165 | + new FakeHost(CCMBridge.ipOfNode(0), 9042, THROWING_CONNECT_TIMEOUTS), | |
| 166 | + new FakeHost(CCMBridge.ipOfNode(1), 9042, THROWING_CONNECT_TIMEOUTS)); | |
| 172 | 167 | // Use a low reconnection interval and keep the default connect timeout (5 seconds). So if a reconnection was scheduled, |
| 173 | 168 | // we would see a call to the reconnection policy. |
| 174 | 169 | CountingReconnectionPolicy reconnectionPolicy = new CountingReconnectionPolicy(new ConstantReconnectionPolicy(100)); |
| 175 | 170 | Cluster cluster = Cluster.builder() |
| 176 | - .addContactPoints(hosts.get(0).address, hosts.get(1).address) | |
| 177 | - .withReconnectionPolicy(reconnectionPolicy) | |
| 178 | - .build(); | |
| 171 | + .addContactPoints(hosts.get(0).address, hosts.get(1).address) | |
| 172 | + .withReconnectionPolicy(reconnectionPolicy) | |
| 173 | + .build(); | |
| 179 | 174 | try { |
| 180 | 175 | cluster.init(); |
| 181 | 176 | } finally { |
| @@ -200,9 +195,9 @@ | ||
| 200 | 195 | @Test(groups = "short") |
| 201 | 196 | public void should_be_able_to_close_cluster_that_never_successfully_connected() throws Exception { |
| 202 | 197 | Cluster cluster = Cluster.builder() |
| 203 | - .addContactPointsWithPorts(Collections.singleton(new InetSocketAddress("127.0.0.1", 65534))) | |
| 204 | - .withNettyOptions(nonQuietClusterCloseOptions) | |
| 205 | - .build(); | |
| 198 | + .addContactPointsWithPorts(Collections.singleton(new InetSocketAddress("127.0.0.1", 65534))) | |
| 199 | + .withNettyOptions(nonQuietClusterCloseOptions) | |
| 200 | + .build(); | |
| 206 | 201 | try { |
| 207 | 202 | cluster.connect(); |
| 208 | 203 | fail("Should not have been able to connect."); |
| @@ -218,8 +213,8 @@ | ||
| 218 | 213 | |
| 219 | 214 | private void primePeerRows(Scassandra scassandra, List<FakeHost> otherHosts) throws UnknownHostException { |
| 220 | 215 | PrimingClient primingClient = PrimingClient.builder() |
| 221 | - .withHost("localhost").withPort(scassandra.getAdminPort()) | |
| 222 | - .build(); | |
| 216 | + .withHost("localhost").withPort(scassandra.getAdminPort()) | |
| 217 | + .build(); | |
| 223 | 218 | |
| 224 | 219 | List<Map<String, ?>> rows = Lists.newArrayListWithCapacity(5); |
| 225 | 220 | |
| @@ -227,20 +222,20 @@ | ||
| 227 | 222 | for (FakeHost otherHost : otherHosts) { |
| 228 | 223 | InetAddress address = InetAddress.getByName(otherHost.address); |
| 229 | 224 | rows.add(ImmutableMap.<String, Object>builder() |
| 230 | - .put("peer", address) | |
| 231 | - .put("rpc_address", address) | |
| 232 | - .put("data_center", "datacenter1") | |
| 233 | - .put("rack", "rack1") | |
| 234 | - .put("release_version", "2.0.1") | |
| 235 | - .put("tokens", ImmutableSet.of(Long.toString(Long.MIN_VALUE + i++))) | |
| 236 | - .build()); | |
| 225 | + .put("peer", address) | |
| 226 | + .put("rpc_address", address) | |
| 227 | + .put("data_center", "datacenter1") | |
| 228 | + .put("rack", "rack1") | |
| 229 | + .put("release_version", "2.0.1") | |
| 230 | + .put("tokens", ImmutableSet.of(Long.toString(Long.MIN_VALUE + i++))) | |
| 231 | + .build()); | |
| 237 | 232 | } |
| 238 | 233 | |
| 239 | 234 | primingClient.prime( |
| 240 | - PrimingRequest.queryBuilder() | |
| 241 | - .withQuery("SELECT * FROM system.peers") | |
| 242 | - .withColumnTypes(ScassandraCluster.SELECT_PEERS) | |
| 243 | - .withRows(rows) | |
| 244 | - .build()); | |
| 235 | + PrimingRequest.queryBuilder() | |
| 236 | + .withQuery("SELECT * FROM system.peers") | |
| 237 | + .withColumnTypes(ScassandraCluster.SELECT_PEERS) | |
| 238 | + .withRows(rows) | |
| 239 | + .build()); | |
| 245 | 240 | } |
| 246 | 241 | } |
modified driver-core/src/test/java/com/datastax/driver/core/ClusterStressTest.java +5 −5
| @@ -108,7 +108,7 @@ | ||
| 108 | 108 | if (error == null) { |
| 109 | 109 | Throwable cause = e.getCause(); |
| 110 | 110 | if (cause instanceof AssertionError) |
| 111 | - error = (AssertionError)cause; | |
| 111 | + error = (AssertionError) cause; | |
| 112 | 112 | else |
| 113 | 113 | error = assertionError("Error while creating a cluster", cause); |
| 114 | 114 | } |
| @@ -136,7 +136,7 @@ | ||
| 136 | 136 | if (error == null) { |
| 137 | 137 | Throwable cause = e.getCause(); |
| 138 | 138 | if (cause instanceof AssertionError) |
| 139 | - error = (AssertionError)cause; | |
| 139 | + error = (AssertionError) cause; | |
| 140 | 140 | else |
| 141 | 141 | error = assertionError("Error while closing a cluster", cause); |
| 142 | 142 | } |
| @@ -169,19 +169,19 @@ | ||
| 169 | 169 | // There should be 1 control connection after initializing. |
| 170 | 170 | cluster.init(); |
| 171 | 171 | assertEquals(cluster.manager.sessions.size(), 0); |
| 172 | - assertEquals((int)cluster.getMetrics().getOpenConnections().getValue(), 1); | |
| 172 | + assertEquals((int) cluster.getMetrics().getOpenConnections().getValue(), 1); | |
| 173 | 173 | assertEquals(channelMonitor.openChannels(contactPoints).size(), 1); |
| 174 | 174 | |
| 175 | 175 | // The first session initializes the cluster and its control connection |
| 176 | 176 | Session session = cluster.connect(); |
| 177 | 177 | assertEquals(cluster.manager.sessions.size(), 1); |
| 178 | - assertEquals((int)cluster.getMetrics().getOpenConnections().getValue(), 1 + TestUtils.numberOfLocalCoreConnections(cluster)); | |
| 178 | + assertEquals((int) cluster.getMetrics().getOpenConnections().getValue(), 1 + TestUtils.numberOfLocalCoreConnections(cluster)); | |
| 179 | 179 | assertEquals(channelMonitor.openChannels(contactPoints).size(), 1 + TestUtils.numberOfLocalCoreConnections(cluster)); |
| 180 | 180 | |
| 181 | 181 | // Closing the session keeps the control connection opened |
| 182 | 182 | session.close(); |
| 183 | 183 | assertEquals(cluster.manager.sessions.size(), 0); |
| 184 | - assertEquals((int)cluster.getMetrics().getOpenConnections().getValue(), 1); | |
| 184 | + assertEquals((int) cluster.getMetrics().getOpenConnections().getValue(), 1); | |
| 185 | 185 | assertEquals(channelMonitor.openChannels(contactPoints).size(), 1); |
| 186 | 186 | |
| 187 | 187 | return this; |
modified driver-core/src/test/java/com/datastax/driver/core/ColumnDefinitionsTest.java +14 −13
| @@ -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.assertTrue; |
| 20 | 21 | |
| 21 | 22 | public class ColumnDefinitionsTest { |
| @@ -26,9 +27,9 @@ | ||
| 26 | 27 | ColumnDefinitions defs; |
| 27 | 28 | |
| 28 | 29 | defs = new ColumnDefinitions(new ColumnDefinitions.Definition[]{ |
| 29 | - new ColumnDefinitions.Definition("ks", "cf", "aColumn", DataType.text()), | |
| 30 | - new ColumnDefinitions.Definition("ks", "cf", "fOO", DataType.text()), | |
| 31 | - new ColumnDefinitions.Definition("ks", "cf", "anotherColumn", DataType.text()) | |
| 30 | + new ColumnDefinitions.Definition("ks", "cf", "aColumn", DataType.text()), | |
| 31 | + new ColumnDefinitions.Definition("ks", "cf", "fOO", DataType.text()), | |
| 32 | + new ColumnDefinitions.Definition("ks", "cf", "anotherColumn", DataType.text()) | |
| 32 | 33 | }); |
| 33 | 34 | |
| 34 | 35 | assertTrue(defs.contains("foo")); |
| @@ -36,13 +37,13 @@ | ||
| 36 | 37 | assertTrue(defs.contains("FOO")); |
| 37 | 38 | |
| 38 | 39 | defs = new ColumnDefinitions(new ColumnDefinitions.Definition[]{ |
| 39 | - new ColumnDefinitions.Definition("ks", "cf", "aColumn", DataType.text()), | |
| 40 | - new ColumnDefinitions.Definition("ks", "cf", "foo", DataType.text()), | |
| 41 | - new ColumnDefinitions.Definition("ks", "cf", "anotherColumn", DataType.text()), | |
| 42 | - new ColumnDefinitions.Definition("ks", "cf", "FOO", DataType.cint()), | |
| 43 | - new ColumnDefinitions.Definition("ks", "cf", "with \" quote", DataType.text()), | |
| 44 | - new ColumnDefinitions.Definition("ks", "cf", "\"in quote\"", DataType.text()), | |
| 45 | - new ColumnDefinitions.Definition("ks", "cf", "in quote", DataType.cint()), | |
| 40 | + new ColumnDefinitions.Definition("ks", "cf", "aColumn", DataType.text()), | |
| 41 | + new ColumnDefinitions.Definition("ks", "cf", "foo", DataType.text()), | |
| 42 | + new ColumnDefinitions.Definition("ks", "cf", "anotherColumn", DataType.text()), | |
| 43 | + new ColumnDefinitions.Definition("ks", "cf", "FOO", DataType.cint()), | |
| 44 | + new ColumnDefinitions.Definition("ks", "cf", "with \" quote", DataType.text()), | |
| 45 | + new ColumnDefinitions.Definition("ks", "cf", "\"in quote\"", DataType.text()), | |
| 46 | + new ColumnDefinitions.Definition("ks", "cf", "in quote", DataType.cint()), | |
| 46 | 47 | }); |
| 47 | 48 | |
| 48 | 49 | assertTrue(defs.getType("foo").equals(DataType.text())); |
| @@ -61,9 +62,9 @@ | ||
| 61 | 62 | public void multiDefinitionTest() { |
| 62 | 63 | |
| 63 | 64 | ColumnDefinitions defs = new ColumnDefinitions(new ColumnDefinitions.Definition[]{ |
| 64 | - new ColumnDefinitions.Definition("ks", "cf1", "column", DataType.text()), | |
| 65 | - new ColumnDefinitions.Definition("ks", "cf2", "column", DataType.cint()), | |
| 66 | - new ColumnDefinitions.Definition("ks", "cf3", "column", DataType.cfloat()) | |
| 65 | + new ColumnDefinitions.Definition("ks", "cf1", "column", DataType.text()), | |
| 66 | + new ColumnDefinitions.Definition("ks", "cf2", "column", DataType.cint()), | |
| 67 | + new ColumnDefinitions.Definition("ks", "cf3", "column", DataType.cfloat()) | |
| 67 | 68 | }); |
| 68 | 69 | |
| 69 | 70 | assertTrue(defs.getType("column").equals(DataType.text())); |
modified driver-core/src/test/java/com/datastax/driver/core/ConditionalUpdateTest.java +6 −5
| @@ -15,18 +15,19 @@ | ||
| 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.util.Collection; |
| 19 | 22 | import java.util.Collections; |
| 20 | 23 | |
| 21 | -import org.testng.annotations.Test; | |
| 22 | -import static org.testng.Assert.*; | |
| 23 | - | |
| 24 | -import com.datastax.driver.core.utils.CassandraVersion; | |
| 24 | +import static org.testng.Assert.assertFalse; | |
| 25 | +import static org.testng.Assert.assertTrue; | |
| 25 | 26 | |
| 26 | 27 | /** |
| 27 | 28 | * Test {@link ResultSet#wasApplied()} for conditional updates. |
| 28 | 29 | */ |
| 29 | -@CassandraVersion(major=2.0, description="Conditional Updates requires 2.0+.") | |
| 30 | +@CassandraVersion(major = 2.0, description = "Conditional Updates requires 2.0+.") | |
| 30 | 31 | public class ConditionalUpdateTest extends CCMBridge.PerClassSingleNodeCluster { |
| 31 | 32 | |
| 32 | 33 | @Override |
modified driver-core/src/test/java/com/datastax/driver/core/ConnectionReleaseTest.java +16 −16
| @@ -34,32 +34,32 @@ | ||
| 34 | 34 | public class ConnectionReleaseTest extends ScassandraTestBase { |
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | - * <p> | |
| 37 | + * <p/> | |
| 38 | 38 | * Validates that when a future is set that the stream associated with the future's request is released. |
| 39 | 39 | * This prevents situations where a user may not be specifying a separate executor on a callback/ |
| 40 | 40 | * transform to a ResultSetFuture, which is not recommended, causing executeAsync to block in borrowConnection |
| 41 | 41 | * until stream ids become available. |
| 42 | - * | |
| 42 | + * <p/> | |
| 43 | 43 | * Executes the following: |
| 44 | - * | |
| 44 | + * <p/> | |
| 45 | 45 | * <ol> |
| 46 | - * <li>Sets # of connections per host to 1.</li> | |
| 47 | - * <li>Sends MAX_STREAM_PER_CONNECTION-1 requests that take 10 seconds to execute.</li> | |
| 48 | - * <li>Calls executeAsync to retrieve records from test1 with k=1.</li> | |
| 49 | - * <li>Transforms executeAsync to take the 'c' column from the result and query test2. | |
| 50 | - * This is done without an executor to ensure the netty worker is used and has to wait for the function | |
| 51 | - * completion.</li> | |
| 52 | - * <li>Asserts that the transformed future completes within pool timeout and the value is as expected.</li> | |
| 46 | + * <li>Sets # of connections per host to 1.</li> | |
| 47 | + * <li>Sends MAX_STREAM_PER_CONNECTION-1 requests that take 10 seconds to execute.</li> | |
| 48 | + * <li>Calls executeAsync to retrieve records from test1 with k=1.</li> | |
| 49 | + * <li>Transforms executeAsync to take the 'c' column from the result and query test2. | |
| 50 | + * This is done without an executor to ensure the netty worker is used and has to wait for the function | |
| 51 | + * completion.</li> | |
| 52 | + * <li>Asserts that the transformed future completes within pool timeout and the value is as expected.</li> | |
| 53 | 53 | * </ol> |
| 54 | 54 | * |
| 55 | 55 | * @jira_ticket JAVA-666 |
| 56 | 56 | * @expected_result Are able to transform a Future without hanging in executeAsync as connection should be freed |
| 57 | - * before the transform function is called. | |
| 57 | + * before the transform function is called. | |
| 58 | 58 | * @test_category queries:async |
| 59 | 59 | * @since 2.0.10, 2.1.6 |
| 60 | 60 | */ |
| 61 | 61 | @SuppressWarnings("unchecked") |
| 62 | - @Test(groups="short") | |
| 62 | + @Test(groups = "short") | |
| 63 | 63 | public void should_release_connection_before_completing_future() throws Exception { |
| 64 | 64 | Cluster cluster = null; |
| 65 | 65 | Collection<ResultSetFuture> mockFutures = Lists.newArrayList(); |
| @@ -92,7 +92,7 @@ | ||
| 92 | 92 | |
| 93 | 93 | final Session session = cluster.connect("ks"); |
| 94 | 94 | // Consume all stream ids except one. |
| 95 | - for(int i = 0; i < StreamIdGenerator.MAX_STREAM_PER_CONNECTION-1; i++) | |
| 95 | + for (int i = 0; i < StreamIdGenerator.MAX_STREAM_PER_CONNECTION - 1; i++) | |
| 96 | 96 | mockFutures.add(session.executeAsync("mock query")); |
| 97 | 97 | |
| 98 | 98 | |
| @@ -114,15 +114,15 @@ | ||
| 114 | 114 | try { |
| 115 | 115 | ResultSet result = future.get(waitTimeInMs, TimeUnit.MILLISECONDS); |
| 116 | 116 | assertThat(result.one().getString("n")).isEqualTo("world"); |
| 117 | - } catch (TimeoutException e) { | |
| 117 | + } catch (TimeoutException e) { | |
| 118 | 118 | fail("Future timed out after " + waitTimeInMs + "ms. " + |
| 119 | 119 | "There is a strong possibility connection is not being released."); |
| 120 | 120 | } |
| 121 | 121 | } finally { |
| 122 | 122 | // Cancel all pending requests. |
| 123 | - for(ResultSetFuture future : mockFutures) | |
| 123 | + for (ResultSetFuture future : mockFutures) | |
| 124 | 124 | future.cancel(true); |
| 125 | - if(cluster != null) | |
| 125 | + if (cluster != null) | |
| 126 | 126 | cluster.close(); |
| 127 | 127 | } |
| 128 | 128 | } |
modified driver-core/src/test/java/com/datastax/driver/core/ConsistencyTest.java +91 −92
| @@ -15,15 +15,6 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.util.Arrays; | |
| 19 | -import java.util.EnumSet; | |
| 20 | -import java.util.List; | |
| 21 | -import java.util.Set; | |
| 22 | - | |
| 23 | -import org.slf4j.Logger; | |
| 24 | -import org.slf4j.LoggerFactory; | |
| 25 | -import org.testng.annotations.Test; | |
| 26 | - | |
| 27 | 18 | import com.datastax.driver.core.exceptions.InvalidQueryException; |
| 28 | 19 | import com.datastax.driver.core.exceptions.ReadTimeoutException; |
| 29 | 20 | import com.datastax.driver.core.exceptions.UnavailableException; |
| @@ -32,6 +23,14 @@ | ||
| 32 | 23 | import com.datastax.driver.core.policies.DowngradingConsistencyRetryPolicy; |
| 33 | 24 | import com.datastax.driver.core.policies.RoundRobinPolicy; |
| 34 | 25 | import com.datastax.driver.core.policies.TokenAwarePolicy; |
| 26 | +import org.slf4j.Logger; | |
| 27 | +import org.slf4j.LoggerFactory; | |
| 28 | +import org.testng.annotations.Test; | |
| 29 | + | |
| 30 | +import java.util.Arrays; | |
| 31 | +import java.util.EnumSet; | |
| 32 | +import java.util.List; | |
| 33 | +import java.util.Set; | |
| 35 | 34 | |
| 36 | 35 | import static com.datastax.driver.core.TestUtils.stopAndWait; |
| 37 | 36 | import static org.testng.Assert.assertTrue; |
| @@ -61,13 +60,13 @@ | ||
| 61 | 60 | List<ConsistencyLevel> acceptedList = Arrays.asList(ConsistencyLevel.ANY); |
| 62 | 61 | |
| 63 | 62 | List<ConsistencyLevel> failList = Arrays.asList( |
| 64 | - ConsistencyLevel.ONE, | |
| 65 | - ConsistencyLevel.TWO, | |
| 66 | - ConsistencyLevel.THREE, | |
| 67 | - ConsistencyLevel.QUORUM, | |
| 68 | - ConsistencyLevel.ALL, | |
| 69 | - ConsistencyLevel.LOCAL_QUORUM, | |
| 70 | - ConsistencyLevel.EACH_QUORUM); | |
| 63 | + ConsistencyLevel.ONE, | |
| 64 | + ConsistencyLevel.TWO, | |
| 65 | + ConsistencyLevel.THREE, | |
| 66 | + ConsistencyLevel.QUORUM, | |
| 67 | + ConsistencyLevel.ALL, | |
| 68 | + ConsistencyLevel.LOCAL_QUORUM, | |
| 69 | + ConsistencyLevel.EACH_QUORUM); | |
| 71 | 70 | |
| 72 | 71 | // Test successful writes |
| 73 | 72 | for (ConsistencyLevel cl : acceptedList) { |
| @@ -84,7 +83,7 @@ | ||
| 84 | 83 | query(c, 12, cl); |
| 85 | 84 | } catch (InvalidQueryException e) { |
| 86 | 85 | List<String> acceptableErrorMessages = Arrays.asList( |
| 87 | - "ANY ConsistencyLevel is only supported for writes"); | |
| 86 | + "ANY ConsistencyLevel is only supported for writes"); | |
| 88 | 87 | assertTrue(acceptableErrorMessages.contains(e.getMessage())); |
| 89 | 88 | } |
| 90 | 89 | } |
| @@ -96,8 +95,8 @@ | ||
| 96 | 95 | fail(String.format("Test passed at CL.%s.", cl)); |
| 97 | 96 | } catch (InvalidQueryException e) { |
| 98 | 97 | List<String> acceptableErrorMessages = Arrays.asList( |
| 99 | - "consistency level LOCAL_QUORUM not compatible with replication strategy (org.apache.cassandra.locator.SimpleStrategy)", | |
| 100 | - "consistency level EACH_QUORUM not compatible with replication strategy (org.apache.cassandra.locator.SimpleStrategy)"); | |
| 98 | + "consistency level LOCAL_QUORUM not compatible with replication strategy (org.apache.cassandra.locator.SimpleStrategy)", | |
| 99 | + "consistency level EACH_QUORUM not compatible with replication strategy (org.apache.cassandra.locator.SimpleStrategy)"); | |
| 101 | 100 | assertTrue(acceptableErrorMessages.contains(e.getMessage()), String.format("Received: %s", e.getMessage())); |
| 102 | 101 | } catch (UnavailableException e) { |
| 103 | 102 | // expected to fail when the client has already marked the |
| @@ -115,8 +114,8 @@ | ||
| 115 | 114 | fail(String.format("Test passed at CL.%s.", cl)); |
| 116 | 115 | } catch (InvalidQueryException e) { |
| 117 | 116 | List<String> acceptableErrorMessages = Arrays.asList( |
| 118 | - "consistency level LOCAL_QUORUM not compatible with replication strategy (org.apache.cassandra.locator.SimpleStrategy)", | |
| 119 | - "EACH_QUORUM ConsistencyLevel is only supported for writes"); | |
| 117 | + "consistency level LOCAL_QUORUM not compatible with replication strategy (org.apache.cassandra.locator.SimpleStrategy)", | |
| 118 | + "EACH_QUORUM ConsistencyLevel is only supported for writes"); | |
| 120 | 119 | assertTrue(acceptableErrorMessages.contains(e.getMessage()), String.format("Received: %s", e.getMessage())); |
| 121 | 120 | } catch (ReadTimeoutException e) { |
| 122 | 121 | // expected to fail when the client hasn't marked the |
| @@ -154,17 +153,17 @@ | ||
| 154 | 153 | stopAndWait(c, 2); |
| 155 | 154 | |
| 156 | 155 | List<ConsistencyLevel> acceptedList = Arrays.asList( |
| 157 | - ConsistencyLevel.ANY, | |
| 158 | - ConsistencyLevel.ONE | |
| 159 | - ); | |
| 156 | + ConsistencyLevel.ANY, | |
| 157 | + ConsistencyLevel.ONE | |
| 158 | + ); | |
| 160 | 159 | |
| 161 | 160 | List<ConsistencyLevel> failList = Arrays.asList( |
| 162 | - ConsistencyLevel.TWO, | |
| 163 | - ConsistencyLevel.QUORUM, | |
| 164 | - ConsistencyLevel.THREE, | |
| 165 | - ConsistencyLevel.ALL, | |
| 166 | - ConsistencyLevel.LOCAL_QUORUM, | |
| 167 | - ConsistencyLevel.EACH_QUORUM); | |
| 161 | + ConsistencyLevel.TWO, | |
| 162 | + ConsistencyLevel.QUORUM, | |
| 163 | + ConsistencyLevel.THREE, | |
| 164 | + ConsistencyLevel.ALL, | |
| 165 | + ConsistencyLevel.LOCAL_QUORUM, | |
| 166 | + ConsistencyLevel.EACH_QUORUM); | |
| 168 | 167 | |
| 169 | 168 | // Test successful writes |
| 170 | 169 | for (ConsistencyLevel cl : acceptedList) { |
| @@ -181,7 +180,7 @@ | ||
| 181 | 180 | query(c, 12, cl); |
| 182 | 181 | } catch (InvalidQueryException e) { |
| 183 | 182 | List<String> acceptableErrorMessages = Arrays.asList( |
| 184 | - "ANY ConsistencyLevel is only supported for writes"); | |
| 183 | + "ANY ConsistencyLevel is only supported for writes"); | |
| 185 | 184 | assertTrue(acceptableErrorMessages.contains(e.getMessage())); |
| 186 | 185 | } |
| 187 | 186 | } |
| @@ -193,8 +192,8 @@ | ||
| 193 | 192 | fail(String.format("Test passed at CL.%s.", cl)); |
| 194 | 193 | } catch (InvalidQueryException e) { |
| 195 | 194 | List<String> acceptableErrorMessages = Arrays.asList( |
| 196 | - "consistency level LOCAL_QUORUM not compatible with replication strategy (org.apache.cassandra.locator.SimpleStrategy)", | |
| 197 | - "consistency level EACH_QUORUM not compatible with replication strategy (org.apache.cassandra.locator.SimpleStrategy)"); | |
| 195 | + "consistency level LOCAL_QUORUM not compatible with replication strategy (org.apache.cassandra.locator.SimpleStrategy)", | |
| 196 | + "consistency level EACH_QUORUM not compatible with replication strategy (org.apache.cassandra.locator.SimpleStrategy)"); | |
| 198 | 197 | assertTrue(acceptableErrorMessages.contains(e.getMessage()), String.format("Received: %s", e.getMessage())); |
| 199 | 198 | } catch (UnavailableException e) { |
| 200 | 199 | // expected to fail when the client has already marked the |
| @@ -212,8 +211,8 @@ | ||
| 212 | 211 | fail(String.format("Test passed at CL.%s.", cl)); |
| 213 | 212 | } catch (InvalidQueryException e) { |
| 214 | 213 | List<String> acceptableErrorMessages = Arrays.asList( |
| 215 | - "consistency level LOCAL_QUORUM not compatible with replication strategy (org.apache.cassandra.locator.SimpleStrategy)", | |
| 216 | - "EACH_QUORUM ConsistencyLevel is only supported for writes"); | |
| 214 | + "consistency level LOCAL_QUORUM not compatible with replication strategy (org.apache.cassandra.locator.SimpleStrategy)", | |
| 215 | + "EACH_QUORUM ConsistencyLevel is only supported for writes"); | |
| 217 | 216 | assertTrue(acceptableErrorMessages.contains(e.getMessage()), String.format("Received: %s", e.getMessage())); |
| 218 | 217 | } catch (ReadTimeoutException e) { |
| 219 | 218 | // expected to fail when the client hasn't marked the |
| @@ -256,18 +255,18 @@ | ||
| 256 | 255 | cls.remove(ConsistencyLevel.LOCAL_SERIAL); |
| 257 | 256 | |
| 258 | 257 | List<ConsistencyLevel> acceptedList = Arrays.asList( |
| 259 | - ConsistencyLevel.ANY, | |
| 260 | - ConsistencyLevel.ONE, | |
| 261 | - ConsistencyLevel.TWO, | |
| 262 | - ConsistencyLevel.QUORUM, | |
| 263 | - ConsistencyLevel.LOCAL_QUORUM, | |
| 264 | - ConsistencyLevel.EACH_QUORUM | |
| 265 | - ); | |
| 258 | + ConsistencyLevel.ANY, | |
| 259 | + ConsistencyLevel.ONE, | |
| 260 | + ConsistencyLevel.TWO, | |
| 261 | + ConsistencyLevel.QUORUM, | |
| 262 | + ConsistencyLevel.LOCAL_QUORUM, | |
| 263 | + ConsistencyLevel.EACH_QUORUM | |
| 264 | + ); | |
| 266 | 265 | |
| 267 | 266 | List<ConsistencyLevel> failList = Arrays.asList( |
| 268 | - ConsistencyLevel.THREE, | |
| 269 | - ConsistencyLevel.ALL | |
| 270 | - ); | |
| 267 | + ConsistencyLevel.THREE, | |
| 268 | + ConsistencyLevel.ALL | |
| 269 | + ); | |
| 271 | 270 | |
| 272 | 271 | |
| 273 | 272 | // Test successful writes |
| @@ -285,8 +284,8 @@ | ||
| 285 | 284 | query(c, 12, cl); |
| 286 | 285 | } catch (InvalidQueryException e) { |
| 287 | 286 | List<String> acceptableErrorMessages = Arrays.asList( |
| 288 | - "ANY ConsistencyLevel is only supported for writes", | |
| 289 | - "EACH_QUORUM ConsistencyLevel is only supported for writes" | |
| 287 | + "ANY ConsistencyLevel is only supported for writes", | |
| 288 | + "EACH_QUORUM ConsistencyLevel is only supported for writes" | |
| 290 | 289 | ); |
| 291 | 290 | assertTrue(acceptableErrorMessages.contains(e.getMessage()), "Got unexpected message " + e.getMessage()); |
| 292 | 291 | } |
| @@ -348,17 +347,17 @@ | ||
| 348 | 347 | stopAndWait(c, 2); |
| 349 | 348 | |
| 350 | 349 | List<ConsistencyLevel> acceptedList = Arrays.asList( |
| 351 | - ConsistencyLevel.ANY | |
| 352 | - ); | |
| 350 | + ConsistencyLevel.ANY | |
| 351 | + ); | |
| 353 | 352 | |
| 354 | 353 | List<ConsistencyLevel> failList = Arrays.asList( |
| 355 | - ConsistencyLevel.ONE, | |
| 356 | - ConsistencyLevel.TWO, | |
| 357 | - ConsistencyLevel.THREE, | |
| 358 | - ConsistencyLevel.QUORUM, | |
| 359 | - ConsistencyLevel.ALL, | |
| 360 | - ConsistencyLevel.LOCAL_QUORUM, | |
| 361 | - ConsistencyLevel.EACH_QUORUM); | |
| 354 | + ConsistencyLevel.ONE, | |
| 355 | + ConsistencyLevel.TWO, | |
| 356 | + ConsistencyLevel.THREE, | |
| 357 | + ConsistencyLevel.QUORUM, | |
| 358 | + ConsistencyLevel.ALL, | |
| 359 | + ConsistencyLevel.LOCAL_QUORUM, | |
| 360 | + ConsistencyLevel.EACH_QUORUM); | |
| 362 | 361 | |
| 363 | 362 | // Test successful writes |
| 364 | 363 | for (ConsistencyLevel cl : acceptedList) { |
| @@ -375,7 +374,7 @@ | ||
| 375 | 374 | query(c, 12, cl); |
| 376 | 375 | } catch (InvalidQueryException e) { |
| 377 | 376 | List<String> acceptableErrorMessages = Arrays.asList( |
| 378 | - "ANY ConsistencyLevel is only supported for writes"); | |
| 377 | + "ANY ConsistencyLevel is only supported for writes"); | |
| 379 | 378 | assertTrue(acceptableErrorMessages.contains(e.getMessage())); |
| 380 | 379 | } |
| 381 | 380 | } |
| @@ -401,7 +400,7 @@ | ||
| 401 | 400 | fail(String.format("Test passed at CL.%s.", cl)); |
| 402 | 401 | } catch (InvalidQueryException e) { |
| 403 | 402 | List<String> acceptableErrorMessages = Arrays.asList( |
| 404 | - "EACH_QUORUM ConsistencyLevel is only supported for writes" | |
| 403 | + "EACH_QUORUM ConsistencyLevel is only supported for writes" | |
| 405 | 404 | ); |
| 406 | 405 | assertTrue(acceptableErrorMessages.contains(e.getMessage()), "Got unexpected message " + e.getMessage()); |
| 407 | 406 | } catch (ReadTimeoutException e) { |
| @@ -425,8 +424,8 @@ | ||
| 425 | 424 | @Test(groups = "long") |
| 426 | 425 | public void testRFTwoDowngradingCL() throws Throwable { |
| 427 | 426 | Cluster.Builder builder = Cluster.builder() |
| 428 | - .withLoadBalancingPolicy(new TokenAwarePolicy(new RoundRobinPolicy(), false)) | |
| 429 | - .withRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE); | |
| 427 | + .withLoadBalancingPolicy(new TokenAwarePolicy(new RoundRobinPolicy(), false)) | |
| 428 | + .withRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE); | |
| 430 | 429 | CCMBridge.CCMCluster c = CCMBridge.buildCluster(3, builder); |
| 431 | 430 | try { |
| 432 | 431 | |
| @@ -461,8 +460,8 @@ | ||
| 461 | 460 | query(c, 12, cl); |
| 462 | 461 | } catch (InvalidQueryException e) { |
| 463 | 462 | List<String> acceptableErrorMessages = Arrays.asList( |
| 464 | - "ANY ConsistencyLevel is only supported for writes", | |
| 465 | - "EACH_QUORUM ConsistencyLevel is only supported for writes" | |
| 463 | + "ANY ConsistencyLevel is only supported for writes", | |
| 464 | + "EACH_QUORUM ConsistencyLevel is only supported for writes" | |
| 466 | 465 | ); |
| 467 | 466 | assertTrue(acceptableErrorMessages.contains(e.getMessage()), "Got unexpected message " + e.getMessage()); |
| 468 | 467 | } |
| @@ -486,8 +485,8 @@ | ||
| 486 | 485 | @Test(groups = "long") |
| 487 | 486 | public void testRFThreeTokenAwareDowngradingCL() throws Throwable { |
| 488 | 487 | Cluster.Builder builder = Cluster.builder() |
| 489 | - .withLoadBalancingPolicy(new TokenAwarePolicy(new RoundRobinPolicy(), false)) | |
| 490 | - .withRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE); | |
| 488 | + .withLoadBalancingPolicy(new TokenAwarePolicy(new RoundRobinPolicy(), false)) | |
| 489 | + .withRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE); | |
| 491 | 490 | testRFThreeDowngradingCL(builder); |
| 492 | 491 | } |
| 493 | 492 | |
| @@ -535,8 +534,8 @@ | ||
| 535 | 534 | query(c, 12, cl); |
| 536 | 535 | } catch (InvalidQueryException e) { |
| 537 | 536 | List<String> acceptableErrorMessages = Arrays.asList( |
| 538 | - "ANY ConsistencyLevel is only supported for writes", | |
| 539 | - "EACH_QUORUM ConsistencyLevel is only supported for writes" | |
| 537 | + "ANY ConsistencyLevel is only supported for writes", | |
| 538 | + "EACH_QUORUM ConsistencyLevel is only supported for writes" | |
| 540 | 539 | ); |
| 541 | 540 | assertTrue(acceptableErrorMessages.contains(e.getMessage()), "Got unexpected message " + e.getMessage()); |
| 542 | 541 | } |
| @@ -554,8 +553,8 @@ | ||
| 554 | 553 | @Test(groups = "long") |
| 555 | 554 | public void testRFThreeDowngradingCLTwoDCs() throws Throwable { |
| 556 | 555 | Cluster.Builder builder = Cluster.builder() |
| 557 | - .withLoadBalancingPolicy(new TokenAwarePolicy(new RoundRobinPolicy(), false)) | |
| 558 | - .withRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE); | |
| 556 | + .withLoadBalancingPolicy(new TokenAwarePolicy(new RoundRobinPolicy(), false)) | |
| 557 | + .withRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE); | |
| 559 | 558 | CCMBridge.CCMCluster c = CCMBridge.buildCluster(3, 3, builder); |
| 560 | 559 | try { |
| 561 | 560 | |
| @@ -576,15 +575,15 @@ | ||
| 576 | 575 | logger.info("Node 3 stopped."); |
| 577 | 576 | |
| 578 | 577 | List<ConsistencyLevel> acceptedList = Arrays.asList( |
| 579 | - ConsistencyLevel.ANY, | |
| 580 | - ConsistencyLevel.ONE, | |
| 581 | - ConsistencyLevel.TWO, | |
| 582 | - ConsistencyLevel.QUORUM, | |
| 583 | - ConsistencyLevel.THREE, | |
| 584 | - ConsistencyLevel.ALL, | |
| 585 | - ConsistencyLevel.LOCAL_QUORUM, | |
| 586 | - ConsistencyLevel.EACH_QUORUM | |
| 587 | - ); | |
| 578 | + ConsistencyLevel.ANY, | |
| 579 | + ConsistencyLevel.ONE, | |
| 580 | + ConsistencyLevel.TWO, | |
| 581 | + ConsistencyLevel.QUORUM, | |
| 582 | + ConsistencyLevel.THREE, | |
| 583 | + ConsistencyLevel.ALL, | |
| 584 | + ConsistencyLevel.LOCAL_QUORUM, | |
| 585 | + ConsistencyLevel.EACH_QUORUM | |
| 586 | + ); | |
| 588 | 587 | |
| 589 | 588 | List<ConsistencyLevel> failList = Arrays.asList(); |
| 590 | 589 | |
| @@ -605,8 +604,8 @@ | ||
| 605 | 604 | query(c, 12, cl); |
| 606 | 605 | } catch (InvalidQueryException e) { |
| 607 | 606 | List<String> acceptableErrorMessages = Arrays.asList( |
| 608 | - "EACH_QUORUM ConsistencyLevel is only supported for writes", | |
| 609 | - "ANY ConsistencyLevel is only supported for writes"); | |
| 607 | + "EACH_QUORUM ConsistencyLevel is only supported for writes", | |
| 608 | + "ANY ConsistencyLevel is only supported for writes"); | |
| 610 | 609 | assertTrue(acceptableErrorMessages.contains(e.getMessage()), String.format("Received: %s", e.getMessage())); |
| 611 | 610 | } |
| 612 | 611 | } |
| @@ -653,8 +652,8 @@ | ||
| 653 | 652 | @Test(groups = "long") |
| 654 | 653 | public void testRFThreeDowngradingCLTwoDCsDCAware() throws Throwable { |
| 655 | 654 | Cluster.Builder builder = Cluster.builder() |
| 656 | - .withLoadBalancingPolicy(new TokenAwarePolicy(new DCAwareRoundRobinPolicy("dc2"), false)) | |
| 657 | - .withRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE); | |
| 655 | + .withLoadBalancingPolicy(new TokenAwarePolicy(new DCAwareRoundRobinPolicy("dc2"), false)) | |
| 656 | + .withRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE); | |
| 658 | 657 | CCMBridge.CCMCluster c = CCMBridge.buildCluster(3, 3, builder); |
| 659 | 658 | try { |
| 660 | 659 | |
| @@ -673,15 +672,15 @@ | ||
| 673 | 672 | c.cassandraCluster.stop(2); |
| 674 | 673 | |
| 675 | 674 | List<ConsistencyLevel> acceptedList = Arrays.asList( |
| 676 | - ConsistencyLevel.ANY, | |
| 677 | - ConsistencyLevel.ONE, | |
| 678 | - ConsistencyLevel.TWO, | |
| 679 | - ConsistencyLevel.QUORUM, | |
| 680 | - ConsistencyLevel.THREE, | |
| 681 | - ConsistencyLevel.ALL, | |
| 682 | - ConsistencyLevel.LOCAL_QUORUM, | |
| 683 | - ConsistencyLevel.EACH_QUORUM | |
| 684 | - ); | |
| 675 | + ConsistencyLevel.ANY, | |
| 676 | + ConsistencyLevel.ONE, | |
| 677 | + ConsistencyLevel.TWO, | |
| 678 | + ConsistencyLevel.QUORUM, | |
| 679 | + ConsistencyLevel.THREE, | |
| 680 | + ConsistencyLevel.ALL, | |
| 681 | + ConsistencyLevel.LOCAL_QUORUM, | |
| 682 | + ConsistencyLevel.EACH_QUORUM | |
| 683 | + ); | |
| 685 | 684 | |
| 686 | 685 | List<ConsistencyLevel> failList = Arrays.asList(); |
| 687 | 686 | |
| @@ -700,8 +699,8 @@ | ||
| 700 | 699 | query(c, 12, cl); |
| 701 | 700 | } catch (InvalidQueryException e) { |
| 702 | 701 | List<String> acceptableErrorMessages = Arrays.asList( |
| 703 | - "EACH_QUORUM ConsistencyLevel is only supported for writes", | |
| 704 | - "ANY ConsistencyLevel is only supported for writes"); | |
| 702 | + "EACH_QUORUM ConsistencyLevel is only supported for writes", | |
| 703 | + "ANY ConsistencyLevel is only supported for writes"); | |
| 705 | 704 | assertTrue(acceptableErrorMessages.contains(e.getMessage()), String.format("Received: %s", e.getMessage())); |
| 706 | 705 | } |
| 707 | 706 | } |
modified driver-core/src/test/java/com/datastax/driver/core/ControlConnectionTest.java +27 −30
| @@ -15,31 +15,28 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.net.InetAddress; | |
| 19 | -import java.util.Collection; | |
| 20 | -import java.util.Iterator; | |
| 21 | -import java.util.Map; | |
| 22 | -import java.util.concurrent.TimeUnit; | |
| 23 | -import java.util.concurrent.atomic.AtomicInteger; | |
| 24 | - | |
| 18 | +import com.datastax.driver.core.policies.DelegatingLoadBalancingPolicy; | |
| 19 | +import com.datastax.driver.core.policies.LoadBalancingPolicy; | |
| 20 | +import com.datastax.driver.core.policies.Policies; | |
| 21 | +import com.datastax.driver.core.policies.ReconnectionPolicy; | |
| 25 | 22 | import com.google.common.base.Function; |
| 26 | 23 | import com.google.common.collect.HashMultiset; |
| 27 | -import com.google.common.collect.Iterables; | |
| 28 | 24 | import com.google.common.collect.Maps; |
| 29 | 25 | import org.slf4j.Logger; |
| 30 | 26 | import org.slf4j.LoggerFactory; |
| 31 | 27 | import org.testng.annotations.Test; |
| 32 | 28 | |
| 33 | -import static com.google.common.collect.Lists.newArrayList; | |
| 29 | +import java.net.InetAddress; | |
| 30 | +import java.util.Collection; | |
| 31 | +import java.util.Iterator; | |
| 32 | +import java.util.Map; | |
| 33 | +import java.util.concurrent.TimeUnit; | |
| 34 | +import java.util.concurrent.atomic.AtomicInteger; | |
| 34 | 35 | |
| 35 | 36 | import static com.datastax.driver.core.Assertions.assertThat; |
| 36 | 37 | import static com.datastax.driver.core.TestUtils.nonDebouncingQueryOptions; |
| 37 | 38 | import static com.datastax.driver.core.TestUtils.nonQuietClusterCloseOptions; |
| 38 | - | |
| 39 | -import com.datastax.driver.core.policies.DelegatingLoadBalancingPolicy; | |
| 40 | -import com.datastax.driver.core.policies.LoadBalancingPolicy; | |
| 41 | -import com.datastax.driver.core.policies.Policies; | |
| 42 | -import com.datastax.driver.core.policies.ReconnectionPolicy; | |
| 39 | +import static com.google.common.collect.Lists.newArrayList; | |
| 43 | 40 | |
| 44 | 41 | public class ControlConnectionTest { |
| 45 | 42 | |
| @@ -74,10 +71,10 @@ | ||
| 74 | 71 | ccm = CCMBridge.builder("test").withNodes(2).build(); |
| 75 | 72 | // We pass only the first host as contact point, so we know the control connection will be on this host |
| 76 | 73 | cluster = Cluster.builder() |
| 77 | - .addContactPoint(CCMBridge.ipOfNode(1)) | |
| 78 | - .withReconnectionPolicy(reconnectionPolicy) | |
| 79 | - .withLoadBalancingPolicy(loadBalancingPolicy) | |
| 80 | - .build(); | |
| 74 | + .addContactPoint(CCMBridge.ipOfNode(1)) | |
| 75 | + .withReconnectionPolicy(reconnectionPolicy) | |
| 76 | + .withLoadBalancingPolicy(loadBalancingPolicy) | |
| 77 | + .build(); | |
| 81 | 78 | cluster.init(); |
| 82 | 79 | |
| 83 | 80 | // Kill the control connection host, there should be exactly one reconnection attempt |
| @@ -101,10 +98,10 @@ | ||
| 101 | 98 | * Ensures that if the host that the Control Connection is connected to is removed/decommissioned that the |
| 102 | 99 | * Control Connection is reestablished to another host. |
| 103 | 100 | * |
| 104 | - * @since 2.0.9 | |
| 105 | 101 | * @jira_ticket JAVA-597 |
| 106 | 102 | * @expected_result Control Connection is reestablished to another host. |
| 107 | 103 | * @test_category control_connection |
| 104 | + * @since 2.0.9 | |
| 108 | 105 | */ |
| 109 | 106 | @Test(groups = "long") |
| 110 | 107 | public void should_reestablish_if_control_node_decommissioned() throws InterruptedException { |
| @@ -148,7 +145,7 @@ | ||
| 148 | 145 | * |
| 149 | 146 | * @jira_ticket JAVA-618 |
| 150 | 147 | * @expected_result All 5 hosts were chosen within 100 attempts. There is a very small possibility |
| 151 | - * that this may not be the case and this is not actually an error. | |
| 148 | + * that this may not be the case and this is not actually an error. | |
| 152 | 149 | * @test_category control_connection |
| 153 | 150 | * @since 2.0.11, 2.1.8, 2.2.0 |
| 154 | 151 | */ |
| @@ -161,15 +158,15 @@ | ||
| 161 | 158 | |
| 162 | 159 | try { |
| 163 | 160 | Collection<String> contactPoints = newArrayList(); |
| 164 | - for(int i = 1; i <= hostCount; i++) { | |
| 161 | + for (int i = 1; i <= hostCount; i++) { | |
| 165 | 162 | contactPoints.add(scassandras.address(i)); |
| 166 | 163 | } |
| 167 | 164 | final HashMultiset<InetAddress> occurrencesByHost = HashMultiset.create(hostCount); |
| 168 | - for(int i = 0; i < iterations; i++) { | |
| 165 | + for (int i = 0; i < iterations; i++) { | |
| 169 | 166 | Cluster cluster = Cluster.builder() |
| 170 | - .addContactPoints(contactPoints.toArray(new String[hostCount])) | |
| 171 | - .withNettyOptions(nonQuietClusterCloseOptions) | |
| 172 | - .build(); | |
| 167 | + .addContactPoints(contactPoints.toArray(new String[hostCount])) | |
| 168 | + .withNettyOptions(nonQuietClusterCloseOptions) | |
| 169 | + .build(); | |
| 173 | 170 | |
| 174 | 171 | try { |
| 175 | 172 | cluster.init(); |
| @@ -178,7 +175,7 @@ | ||
| 178 | 175 | cluster.close(); |
| 179 | 176 | } |
| 180 | 177 | } |
| 181 | - if(logger.isDebugEnabled()) { | |
| 178 | + if (logger.isDebugEnabled()) { | |
| 182 | 179 | Map<InetAddress, Integer> hostCounts = Maps.toMap(occurrencesByHost.elementSet(), new Function<InetAddress, Integer>() { |
| 183 | 180 | @Override |
| 184 | 181 | public Integer apply(InetAddress input) { |
| @@ -190,10 +187,10 @@ | ||
| 190 | 187 | // There is an incredibly low chance that a host may not be used based on randomness. |
| 191 | 188 | // This probability is very low however. |
| 192 | 189 | assertThat(occurrencesByHost.elementSet().size()) |
| 193 | - .as("Not all hosts were used as contact points. There is a very small chance" | |
| 194 | - + " of this happening based on randomness, investigate whether or not this" | |
| 195 | - + " is a bug.") | |
| 196 | - .isEqualTo(hostCount); | |
| 190 | + .as("Not all hosts were used as contact points. There is a very small chance" | |
| 191 | + + " of this happening based on randomness, investigate whether or not this" | |
| 192 | + + " is a bug.") | |
| 193 | + .isEqualTo(hostCount); | |
| 197 | 194 | } finally { |
| 198 | 195 | scassandras.stop(); |
| 199 | 196 | } |
modified driver-core/src/test/java/com/datastax/driver/core/CountingReconnectionPolicy.java +2 −2
| @@ -15,10 +15,10 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.util.concurrent.atomic.AtomicInteger; | |
| 19 | - | |
| 20 | 18 | import com.datastax.driver.core.policies.ReconnectionPolicy; |
| 21 | 19 | |
| 20 | +import java.util.concurrent.atomic.AtomicInteger; | |
| 21 | + | |
| 22 | 22 | /** |
| 23 | 23 | * A reconnection policy that tracks how many times its schedule has been invoked. |
| 24 | 24 | */ |
modified driver-core/src/test/java/com/datastax/driver/core/CustomTypeTest.java +14 −13
| @@ -15,13 +15,14 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | +import org.testng.annotations.Test; | |
| 19 | + | |
| 18 | 20 | import java.nio.ByteBuffer; |
| 19 | 21 | import java.util.ArrayList; |
| 20 | 22 | import java.util.Collection; |
| 21 | 23 | import java.util.Collections; |
| 22 | 24 | import java.util.List; |
| 23 | 25 | |
| 24 | -import org.testng.annotations.Test; | |
| 25 | 26 | import static org.testng.Assert.assertEquals; |
| 26 | 27 | |
| 27 | 28 | /** |
| @@ -32,12 +33,12 @@ | ||
| 32 | 33 | @Override |
| 33 | 34 | protected Collection<String> getTableDefinitions() { |
| 34 | 35 | return Collections.singleton( |
| 35 | - "CREATE TABLE test (" | |
| 36 | - + " k int," | |
| 37 | - + " c 'DynamicCompositeType(s => UTF8Type, i => Int32Type)'," | |
| 38 | - + " v int," | |
| 39 | - + " PRIMARY KEY (k, c)" | |
| 40 | - + ") WITH COMPACT STORAGE" | |
| 36 | + "CREATE TABLE test (" | |
| 37 | + + " k int," | |
| 38 | + + " c 'DynamicCompositeType(s => UTF8Type, i => Int32Type)'," | |
| 39 | + + " v int," | |
| 40 | + + " PRIMARY KEY (k, c)" | |
| 41 | + + ") WITH COMPACT STORAGE" | |
| 41 | 42 | ); |
| 42 | 43 | } |
| 43 | 44 | |
| @@ -48,20 +49,20 @@ | ||
| 48 | 49 | for (Object p : params) { |
| 49 | 50 | if (p instanceof Integer) { |
| 50 | 51 | ByteBuffer elt = ByteBuffer.allocate(2 + 2 + 4 + 1); |
| 51 | - elt.putShort((short)(0x8000 | 'i')); | |
| 52 | + elt.putShort((short) (0x8000 | 'i')); | |
| 52 | 53 | elt.putShort((short) 4); |
| 53 | - elt.putInt((Integer)p); | |
| 54 | - elt.put((byte)0); | |
| 54 | + elt.putInt((Integer) p); | |
| 55 | + elt.put((byte) 0); | |
| 55 | 56 | elt.flip(); |
| 56 | 57 | size += elt.remaining(); |
| 57 | 58 | l.add(elt); |
| 58 | 59 | } else if (p instanceof String) { |
| 59 | - ByteBuffer bytes = ByteBuffer.wrap(((String)p).getBytes()); | |
| 60 | + ByteBuffer bytes = ByteBuffer.wrap(((String) p).getBytes()); | |
| 60 | 61 | ByteBuffer elt = ByteBuffer.allocate(2 + 2 + bytes.remaining() + 1); |
| 61 | - elt.putShort((short)(0x8000 | 's')); | |
| 62 | + elt.putShort((short) (0x8000 | 's')); | |
| 62 | 63 | elt.putShort((short) bytes.remaining()); |
| 63 | 64 | elt.put(bytes); |
| 64 | - elt.put((byte)0); | |
| 65 | + elt.put((byte) 0); | |
| 65 | 66 | elt.flip(); |
| 66 | 67 | size += elt.remaining(); |
| 67 | 68 | l.add(elt); |
modified driver-core/src/test/java/com/datastax/driver/core/DataProviders.java +9 −9
| @@ -15,13 +15,13 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.util.Arrays; | |
| 19 | -import java.util.Iterator; | |
| 20 | - | |
| 21 | 18 | import com.google.common.base.Predicate; |
| 22 | 19 | import com.google.common.collect.Iterables; |
| 23 | 20 | import org.testng.annotations.DataProvider; |
| 24 | 21 | |
| 22 | +import java.util.Arrays; | |
| 23 | +import java.util.Iterator; | |
| 24 | + | |
| 25 | 25 | public class DataProviders { |
| 26 | 26 | |
| 27 | 27 | /** |
| @@ -37,7 +37,7 @@ | ||
| 37 | 37 | } |
| 38 | 38 | }).iterator(); |
| 39 | 39 | |
| 40 | - return new Iterator<Object[]> () { | |
| 40 | + return new Iterator<Object[]>() { | |
| 41 | 41 | |
| 42 | 42 | @Override |
| 43 | 43 | public boolean hasNext() { |
| @@ -46,8 +46,8 @@ | ||
| 46 | 46 | |
| 47 | 47 | @Override |
| 48 | 48 | public Object[] next() { |
| 49 | - return new Object[] { | |
| 50 | - consistencyLevels.next() | |
| 49 | + return new Object[]{ | |
| 50 | + consistencyLevels.next() | |
| 51 | 51 | }; |
| 52 | 52 | } |
| 53 | 53 | |
| @@ -63,9 +63,9 @@ | ||
| 63 | 63 | */ |
| 64 | 64 | @DataProvider(name = "serialConsistencyLevels") |
| 65 | 65 | public static Object[][] serialConsistencyLevels() { |
| 66 | - return new Object[][] { | |
| 67 | - { ConsistencyLevel.SERIAL }, | |
| 68 | - { ConsistencyLevel.LOCAL_SERIAL } | |
| 66 | + return new Object[][]{ | |
| 67 | + {ConsistencyLevel.SERIAL}, | |
| 68 | + {ConsistencyLevel.LOCAL_SERIAL} | |
| 69 | 69 | }; |
| 70 | 70 | } |
| 71 | 71 |
modified driver-core/src/test/java/com/datastax/driver/core/DataTypeIntegrationTest.java +20 −16
| @@ -15,22 +15,26 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.util.*; | |
| 19 | -import java.util.concurrent.atomic.AtomicInteger; | |
| 20 | - | |
| 21 | -import com.google.common.collect.*; | |
| 18 | +import com.datastax.driver.core.utils.CassandraVersion; | |
| 19 | +import com.google.common.collect.ImmutableList; | |
| 20 | +import com.google.common.collect.ImmutableMap; | |
| 21 | +import com.google.common.collect.Lists; | |
| 22 | +import com.google.common.collect.Sets; | |
| 22 | 23 | import org.slf4j.Logger; |
| 23 | 24 | import org.slf4j.LoggerFactory; |
| 24 | 25 | import org.testng.annotations.Test; |
| 25 | 26 | |
| 27 | +import java.util.Collection; | |
| 28 | +import java.util.List; | |
| 29 | +import java.util.Map; | |
| 30 | +import java.util.concurrent.atomic.AtomicInteger; | |
| 31 | + | |
| 26 | 32 | import static org.assertj.core.api.Assertions.assertThat; |
| 27 | 33 | import static org.assertj.core.api.Assertions.fail; |
| 28 | 34 | |
| 29 | -import com.datastax.driver.core.utils.CassandraVersion; | |
| 30 | - | |
| 31 | 35 | /** |
| 32 | 36 | * The goal of this test is to cover the serialization and deserialization of datatypes. |
| 33 | - * | |
| 37 | + * <p/> | |
| 34 | 38 | * It creates a table with a column of a given type, inserts a value and then tries to retrieve it. |
| 35 | 39 | * There are 3 variants for the insert query: a raw string, a simple statement with a parameter |
| 36 | 40 | * (protocol > v2 only) and a prepared statement. |
| @@ -53,7 +57,7 @@ | ||
| 53 | 57 | for (TestTable table : tables) { |
| 54 | 58 | if (cassandraVersion.compareTo(table.minCassandraVersion) < 0) |
| 55 | 59 | logger.debug("Skipping table because it uses a feature not supported by Cassandra {}: {}", |
| 56 | - cassandraVersion, table.createStatement); | |
| 60 | + cassandraVersion, table.createStatement); | |
| 57 | 61 | else |
| 58 | 62 | statements.add(table.createStatement); |
| 59 | 63 | } |
| @@ -101,12 +105,12 @@ | ||
| 101 | 105 | Object queriedValue = table.testColumnType.deserialize(row.getBytesUnsafe("v")); |
| 102 | 106 | |
| 103 | 107 | assertThat(queriedValue) |
| 104 | - .as("Test failure on %s statement with table:%n%s;%n" + | |
| 105 | - "insert statement:%n%s;%n", | |
| 106 | - statementType, | |
| 107 | - table.createStatement, | |
| 108 | - table.insertStatement) | |
| 109 | - .isEqualTo(table.sampleValue); | |
| 108 | + .as("Test failure on %s statement with table:%n%s;%n" + | |
| 109 | + "insert statement:%n%s;%n", | |
| 110 | + statementType, | |
| 111 | + table.createStatement, | |
| 112 | + table.insertStatement) | |
| 113 | + .isEqualTo(table.sampleValue); | |
| 110 | 114 | |
| 111 | 115 | session.execute(table.truncateStatement); |
| 112 | 116 | } |
| @@ -187,8 +191,8 @@ | ||
| 187 | 191 | Object valueSample = valueEntry.getValue(); |
| 188 | 192 | |
| 189 | 193 | tables.add(new TestTable(DataType.map(keyType, valueType), |
| 190 | - ImmutableMap.builder().put(keySample, valueSample).build(), | |
| 191 | - "1.2.0")); | |
| 194 | + ImmutableMap.builder().put(keySample, valueSample).build(), | |
| 195 | + "1.2.0")); | |
| 192 | 196 | } |
| 193 | 197 | } |
| 194 | 198 | return tables; |
modified driver-core/src/test/java/com/datastax/driver/core/DataTypeTest.java +3 −4
| @@ -15,17 +15,16 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.exceptions.InvalidTypeException; | |
| 19 | +import org.testng.annotations.Test; | |
| 20 | + | |
| 18 | 21 | import java.nio.ByteBuffer; |
| 19 | 22 | import java.util.Arrays; |
| 20 | 23 | import java.util.List; |
| 21 | 24 | |
| 22 | -import org.testng.annotations.Test; | |
| 23 | - | |
| 24 | 25 | import static org.testng.Assert.assertEquals; |
| 25 | 26 | import static org.testng.Assert.fail; |
| 26 | 27 | |
| 27 | -import com.datastax.driver.core.exceptions.InvalidTypeException; | |
| 28 | - | |
| 29 | 28 | public class DataTypeTest { |
| 30 | 29 | |
| 31 | 30 | @Test(groups = "unit") |
modified driver-core/src/test/java/com/datastax/driver/core/EventDebouncerIntegrationTest.java +10 −11
| @@ -15,18 +15,17 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | +import org.testng.annotations.Test; | |
| 19 | + | |
| 18 | 20 | import java.util.Collection; |
| 19 | 21 | import java.util.concurrent.CountDownLatch; |
| 20 | 22 | import java.util.concurrent.CyclicBarrier; |
| 21 | 23 | import java.util.concurrent.TimeUnit; |
| 22 | 24 | |
| 23 | -import org.testng.annotations.Test; | |
| 24 | - | |
| 25 | +import static com.datastax.driver.core.CCMBridge.ipOfNode; | |
| 25 | 26 | import static org.assertj.core.api.Assertions.assertThat; |
| 26 | 27 | import static org.assertj.core.api.Fail.fail; |
| 27 | 28 | |
| 28 | -import static com.datastax.driver.core.CCMBridge.ipOfNode; | |
| 29 | - | |
| 30 | 29 | public class EventDebouncerIntegrationTest { |
| 31 | 30 | |
| 32 | 31 | /** |
| @@ -43,13 +42,13 @@ | ||
| 43 | 42 | TestLoadBalancingPolicy policy = new TestLoadBalancingPolicy(); |
| 44 | 43 | CCMBridge ccm = CCMBridge.builder("main").withNodes(3).build(); |
| 45 | 44 | final Cluster cluster = new Cluster.Builder() |
| 46 | - .addContactPoints(ipOfNode(1)) | |
| 47 | - .withLoadBalancingPolicy(policy) | |
| 48 | - .withQueryOptions(new QueryOptions() | |
| 49 | - .setRefreshNodeIntervalMillis(0) | |
| 50 | - .setRefreshNodeListIntervalMillis(0) | |
| 51 | - .setRefreshSchemaIntervalMillis(0) | |
| 52 | - ).build(); | |
| 45 | + .addContactPoints(ipOfNode(1)) | |
| 46 | + .withLoadBalancingPolicy(policy) | |
| 47 | + .withQueryOptions(new QueryOptions() | |
| 48 | + .setRefreshNodeIntervalMillis(0) | |
| 49 | + .setRefreshNodeListIntervalMillis(0) | |
| 50 | + .setRefreshSchemaIntervalMillis(0) | |
| 51 | + ).build(); | |
| 53 | 52 | try { |
| 54 | 53 | new Thread() { |
| 55 | 54 | @Override |
modified driver-core/src/test/java/com/datastax/driver/core/EventDebouncerTest.java +12 −11
| @@ -15,9 +15,19 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.EventDebouncer.DeliveryCallback; | |
| 19 | +import com.google.common.util.concurrent.Futures; | |
| 20 | +import com.google.common.util.concurrent.ListenableFuture; | |
| 21 | +import org.testng.annotations.AfterMethod; | |
| 22 | +import org.testng.annotations.BeforeMethod; | |
| 23 | +import org.testng.annotations.Test; | |
| 24 | + | |
| 18 | 25 | import java.util.ArrayList; |
| 19 | 26 | import java.util.List; |
| 20 | -import java.util.concurrent.*; | |
| 27 | +import java.util.concurrent.CopyOnWriteArrayList; | |
| 28 | +import java.util.concurrent.CountDownLatch; | |
| 29 | +import java.util.concurrent.Executors; | |
| 30 | +import java.util.concurrent.ScheduledExecutorService; | |
| 21 | 31 | import java.util.concurrent.atomic.AtomicInteger; |
| 22 | 32 | import java.util.concurrent.locks.Condition; |
| 23 | 33 | import java.util.concurrent.locks.Lock; |
| @@ -25,17 +35,8 @@ | ||
| 25 | 35 | |
| 26 | 36 | import static java.util.concurrent.TimeUnit.MILLISECONDS; |
| 27 | 37 | import static java.util.concurrent.TimeUnit.SECONDS; |
| 28 | - | |
| 29 | -import com.google.common.util.concurrent.Futures; | |
| 30 | -import com.google.common.util.concurrent.ListenableFuture; | |
| 31 | -import org.testng.annotations.AfterMethod; | |
| 32 | -import org.testng.annotations.BeforeMethod; | |
| 33 | -import org.testng.annotations.Test; | |
| 34 | - | |
| 35 | 38 | import static org.assertj.core.api.Assertions.assertThat; |
| 36 | 39 | |
| 37 | -import com.datastax.driver.core.EventDebouncer.DeliveryCallback; | |
| 38 | - | |
| 39 | 40 | public class EventDebouncerTest { |
| 40 | 41 | |
| 41 | 42 | private ScheduledExecutorService executor; |
| @@ -240,7 +241,7 @@ | ||
| 240 | 241 | if (o == null || getClass() != o.getClass()) |
| 241 | 242 | return false; |
| 242 | 243 | |
| 243 | - MockEvent mockEvent = (MockEvent)o; | |
| 244 | + MockEvent mockEvent = (MockEvent) o; | |
| 244 | 245 | |
| 245 | 246 | return i == mockEvent.i; |
| 246 | 247 |
modified driver-core/src/test/java/com/datastax/driver/core/FakeHost.java +4 −3
| @@ -63,14 +63,15 @@ | ||
| 63 | 63 | this.behavior = behavior; |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | - @Override public void run() { | |
| 66 | + @Override | |
| 67 | + public void run() { | |
| 67 | 68 | ServerSocket server = null; |
| 68 | 69 | Socket client = null; |
| 69 | 70 | try { |
| 70 | 71 | InetAddress bindAddress = InetAddress.getByName(address); |
| 71 | 72 | int backlog = (behavior == Behavior.THROWING_CONNECT_TIMEOUTS) |
| 72 | - ? 1 | |
| 73 | - : -1; // default | |
| 73 | + ? 1 | |
| 74 | + : -1; // default | |
| 74 | 75 | server = new ServerSocket(port, backlog, bindAddress); |
| 75 | 76 | |
| 76 | 77 | if (behavior == Behavior.THROWING_CONNECT_TIMEOUTS) { |
modified driver-core/src/test/java/com/datastax/driver/core/FetchingTest.java +4 −4
| @@ -15,14 +15,14 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.exceptions.UnsupportedFeatureException; | |
| 19 | +import org.testng.annotations.Test; | |
| 20 | + | |
| 18 | 21 | import java.util.Collection; |
| 19 | 22 | import java.util.Collections; |
| 20 | 23 | |
| 21 | -import org.testng.annotations.Test; | |
| 22 | 24 | import static org.testng.Assert.*; |
| 23 | 25 | |
| 24 | -import com.datastax.driver.core.exceptions.UnsupportedFeatureException; | |
| 25 | - | |
| 26 | 26 | /** |
| 27 | 27 | * Test ResultSet paging correct behavior. |
| 28 | 28 | */ |
| @@ -52,7 +52,7 @@ | ||
| 52 | 52 | for (int i = 0; i < 100; i++) { |
| 53 | 53 | // isExhausted makes sure we do fetch if needed |
| 54 | 54 | assertFalse(rs.isExhausted()); |
| 55 | - assertEquals(rs.getAvailableWithoutFetching(), 5-(i%5)); | |
| 55 | + assertEquals(rs.getAvailableWithoutFetching(), 5 - (i % 5)); | |
| 56 | 56 | assertEquals(rs.one().getInt(0), i); |
| 57 | 57 | } |
| 58 | 58 |
modified driver-core/src/test/java/com/datastax/driver/core/HeartbeatTest.java +12 −13
| @@ -15,8 +15,6 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import static java.util.concurrent.TimeUnit.SECONDS; | |
| 19 | - | |
| 20 | 18 | import org.apache.log4j.Level; |
| 21 | 19 | import org.apache.log4j.Logger; |
| 22 | 20 | import org.testng.annotations.AfterMethod; |
| @@ -24,6 +22,7 @@ | ||
| 24 | 22 | import org.testng.annotations.Test; |
| 25 | 23 | |
| 26 | 24 | import static com.datastax.driver.core.Assertions.assertThat; |
| 25 | +import static java.util.concurrent.TimeUnit.SECONDS; | |
| 27 | 26 | |
| 28 | 27 | public class HeartbeatTest { |
| 29 | 28 | |
| @@ -37,7 +36,7 @@ | ||
| 37 | 36 | connectionLogger.addAppender(logs); |
| 38 | 37 | } |
| 39 | 38 | |
| 40 | - @AfterMethod(groups="long") | |
| 39 | + @AfterMethod(groups = "long") | |
| 41 | 40 | public void stopCapturingLogs() { |
| 42 | 41 | connectionLogger.setLevel(null); |
| 43 | 42 | connectionLogger.removeAppender(logs); |
| @@ -59,9 +58,9 @@ | ||
| 59 | 58 | try { |
| 60 | 59 | ccm = CCMBridge.builder("test").withNodes(1).build(); |
| 61 | 60 | cluster = Cluster.builder().addContactPoint(CCMBridge.ipOfNode(1)) |
| 62 | - .withPoolingOptions(new PoolingOptions() | |
| 63 | - .setHeartbeatIntervalSeconds(3)) | |
| 64 | - .build(); | |
| 61 | + .withPoolingOptions(new PoolingOptions() | |
| 62 | + .setHeartbeatIntervalSeconds(3)) | |
| 63 | + .build(); | |
| 65 | 64 | |
| 66 | 65 | // Don't create any session, only the control connection will be established |
| 67 | 66 | cluster.init(); |
| @@ -75,14 +74,14 @@ | ||
| 75 | 74 | // Ensure heartbeat is sent after no activity. |
| 76 | 75 | SECONDS.sleep(4); |
| 77 | 76 | assertThat(logs.getNext()) |
| 78 | - .contains("sending heartbeat") | |
| 79 | - .contains("heartbeat query succeeded"); | |
| 77 | + .contains("sending heartbeat") | |
| 78 | + .contains("heartbeat query succeeded"); | |
| 80 | 79 | |
| 81 | 80 | // Ensure heartbeat is sent after continued inactivity. |
| 82 | 81 | SECONDS.sleep(4); |
| 83 | 82 | assertThat(logs.getNext()) |
| 84 | - .contains("sending heartbeat") | |
| 85 | - .contains("heartbeat query succeeded"); | |
| 83 | + .contains("sending heartbeat") | |
| 84 | + .contains("heartbeat query succeeded"); | |
| 86 | 85 | |
| 87 | 86 | // Ensure heartbeat is not sent after activity. |
| 88 | 87 | logs.getNext(); |
| @@ -95,8 +94,8 @@ | ||
| 95 | 94 | // Finally, ensure heartbeat is sent after inactivity. |
| 96 | 95 | SECONDS.sleep(4); |
| 97 | 96 | assertThat(logs.getNext()) |
| 98 | - .contains("sending heartbeat") | |
| 99 | - .contains("heartbeat query succeeded"); | |
| 97 | + .contains("sending heartbeat") | |
| 98 | + .contains("heartbeat query succeeded"); | |
| 100 | 99 | } finally { |
| 101 | 100 | if (cluster != null) |
| 102 | 101 | cluster.close(); |
| @@ -107,7 +106,7 @@ | ||
| 107 | 106 | |
| 108 | 107 | /** |
| 109 | 108 | * Ensures that a heartbeat message is not sent if the configured heartbeat interval is 0. |
| 110 | - * | |
| 109 | + * <p/> | |
| 111 | 110 | * While difficult to prove the absence of evidence, the test will wait up to the default heartbeat interval |
| 112 | 111 | * (30 seconds + 1) and check to see if the heartbeat was sent. |
| 113 | 112 | * |
modified driver-core/src/test/java/com/datastax/driver/core/HostAssert.java +8 −9
| @@ -15,17 +15,16 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.Host.State; | |
| 19 | +import com.datastax.driver.core.Host.StateListener; | |
| 20 | +import com.datastax.driver.core.policies.LoadBalancingPolicy; | |
| 21 | +import org.assertj.core.api.AbstractAssert; | |
| 22 | + | |
| 18 | 23 | import java.util.concurrent.CountDownLatch; |
| 19 | 24 | import java.util.concurrent.TimeUnit; |
| 20 | -import java.util.concurrent.atomic.AtomicBoolean; | |
| 21 | 25 | |
| 22 | -import static org.assertj.core.api.Assertions.fail; | |
| 23 | -import org.assertj.core.api.AbstractAssert; | |
| 24 | 26 | import static org.assertj.core.api.Assertions.assertThat; |
| 25 | - | |
| 26 | -import com.datastax.driver.core.Host.State; | |
| 27 | -import com.datastax.driver.core.Host.StateListener; | |
| 28 | -import com.datastax.driver.core.policies.LoadBalancingPolicy; | |
| 27 | +import static org.assertj.core.api.Assertions.fail; | |
| 29 | 28 | |
| 30 | 29 | public class HostAssert extends AbstractAssert<HostAssert, Host> { |
| 31 | 30 | |
| @@ -63,7 +62,7 @@ | ||
| 63 | 62 | |
| 64 | 63 | public HostAssert isReconnectingFromDown() { |
| 65 | 64 | assertThat(actual.getReconnectionAttemptFuture() != null && !actual.getReconnectionAttemptFuture().isDone()) |
| 66 | - .isTrue(); | |
| 65 | + .isTrue(); | |
| 67 | 66 | return this; |
| 68 | 67 | } |
| 69 | 68 | |
| @@ -74,7 +73,7 @@ | ||
| 74 | 73 | |
| 75 | 74 | public HostAssert isNotReconnectingFromDown() { |
| 76 | 75 | assertThat(actual.getReconnectionAttemptFuture() != null && !actual.getReconnectionAttemptFuture().isDone()) |
| 77 | - .isFalse(); | |
| 76 | + .isFalse(); | |
| 78 | 77 | return this; |
| 79 | 78 | } |
| 80 | 79 |
modified driver-core/src/test/java/com/datastax/driver/core/HostConnectionPoolMultiTest.java +8 −9
| @@ -27,7 +27,6 @@ | ||
| 27 | 27 | import static com.datastax.driver.core.HostDistance.LOCAL; |
| 28 | 28 | import static com.datastax.driver.core.TestUtils.nonDebouncingQueryOptions; |
| 29 | 29 | import static java.util.concurrent.TimeUnit.SECONDS; |
| 30 | - | |
| 31 | 30 | import static org.scassandra.http.client.ClosedConnectionReport.CloseType.CLOSE; |
| 32 | 31 | |
| 33 | 32 | public class HostConnectionPoolMultiTest { |
| @@ -36,15 +35,15 @@ | ||
| 36 | 35 | |
| 37 | 36 | private Cluster cluster; |
| 38 | 37 | |
| 39 | - @BeforeMethod(groups={"short", "long"}) | |
| 38 | + @BeforeMethod(groups = {"short", "long"}) | |
| 40 | 39 | private void setUp() { |
| 41 | 40 | scassandra = ScassandraCluster.builder().withNodes(2).build(); |
| 42 | 41 | scassandra.init(); |
| 43 | 42 | } |
| 44 | 43 | |
| 45 | - @AfterMethod(groups={"short", "long"}) | |
| 44 | + @AfterMethod(groups = {"short", "long"}) | |
| 46 | 45 | private void tearDown() { |
| 47 | - if(cluster != null) { | |
| 46 | + if (cluster != null) { | |
| 48 | 47 | cluster.close(); |
| 49 | 48 | } |
| 50 | 49 | scassandra.stop(); |
| @@ -70,11 +69,11 @@ | ||
| 70 | 69 | * @test_category connection:connection_pool |
| 71 | 70 | * @since 2.0.11 |
| 72 | 71 | */ |
| 73 | - @Test(groups="short") | |
| 72 | + @Test(groups = "short") | |
| 74 | 73 | public void should_mark_host_down_if_all_connections_fail_on_init() { |
| 75 | 74 | // Prevent any connections on node 2. |
| 76 | 75 | scassandra.node(2).currentClient().disableListener(); |
| 77 | - createCluster(8,8); | |
| 76 | + createCluster(8, 8); | |
| 78 | 77 | |
| 79 | 78 | // Node 2 should be in a down state while node 1 stays up. |
| 80 | 79 | assertThat(cluster).host(2).goesDownWithin(10, SECONDS); |
| @@ -93,16 +92,16 @@ | ||
| 93 | 92 | * @test_category connection:connection_pool |
| 94 | 93 | * @since 2.0.11 |
| 95 | 94 | */ |
| 96 | - @Test(groups="short") | |
| 95 | + @Test(groups = "short") | |
| 97 | 96 | public void should_replace_control_connection_if_it_goes_down_but_host_remains_up() { |
| 98 | - createCluster(1,2); | |
| 97 | + createCluster(1, 2); | |
| 99 | 98 | |
| 100 | 99 | // Ensure control connection is on node 1. |
| 101 | 100 | assertThat(cluster).usesControlHost(1); |
| 102 | 101 | |
| 103 | 102 | // Identify the socket associated with the control connection. |
| 104 | 103 | Connection controlConnection = cluster.manager.controlConnection.connectionRef.get(); |
| 105 | - InetSocketAddress controlSocket = (InetSocketAddress)controlConnection.channel.localAddress(); | |
| 104 | + InetSocketAddress controlSocket = (InetSocketAddress) controlConnection.channel.localAddress(); | |
| 106 | 105 | |
| 107 | 106 | // Close the control connection. |
| 108 | 107 | scassandra.node(1).currentClient() |
modified driver-core/src/test/java/com/datastax/driver/core/HostConnectionPoolTest.java +81 −82
| @@ -15,6 +15,14 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | +import com.codahale.metrics.Gauge; | |
| 19 | +import com.datastax.driver.core.policies.ConstantReconnectionPolicy; | |
| 20 | +import com.google.common.util.concurrent.Uninterruptibles; | |
| 21 | +import org.scassandra.cql.PrimitiveType; | |
| 22 | +import org.scassandra.http.client.PrimingRequest; | |
| 23 | +import org.testng.annotations.BeforeClass; | |
| 24 | +import org.testng.annotations.Test; | |
| 25 | + | |
| 18 | 26 | import java.net.InetSocketAddress; |
| 19 | 27 | import java.util.Iterator; |
| 20 | 28 | import java.util.List; |
| @@ -22,30 +30,19 @@ | ||
| 22 | 30 | import java.util.concurrent.atomic.AtomicBoolean; |
| 23 | 31 | import java.util.concurrent.atomic.AtomicReference; |
| 24 | 32 | |
| 33 | +import static com.datastax.driver.core.Assertions.assertThat; | |
| 34 | +import static com.google.common.collect.Lists.newArrayList; | |
| 25 | 35 | import static java.util.Collections.singletonList; |
| 26 | 36 | import static java.util.concurrent.TimeUnit.SECONDS; |
| 27 | - | |
| 28 | -import com.codahale.metrics.Gauge; | |
| 29 | -import com.google.common.util.concurrent.Uninterruptibles; | |
| 30 | -import org.scassandra.cql.PrimitiveType; | |
| 31 | -import org.scassandra.http.client.PrimingRequest; | |
| 32 | -import org.testng.annotations.BeforeClass; | |
| 33 | -import org.testng.annotations.Test; | |
| 34 | - | |
| 35 | -import static com.google.common.collect.Lists.newArrayList; | |
| 36 | 37 | import static org.mockito.Mockito.*; |
| 37 | 38 | import static org.scassandra.http.client.ClosedConnectionReport.CloseType.CLOSE; |
| 38 | 39 | import static org.scassandra.http.client.PrimingRequest.then; |
| 39 | 40 | import static org.testng.Assert.fail; |
| 40 | 41 | |
| 41 | -import com.datastax.driver.core.policies.ConstantReconnectionPolicy; | |
| 42 | - | |
| 43 | -import static com.datastax.driver.core.Assertions.assertThat; | |
| 44 | - | |
| 45 | 42 | public class HostConnectionPoolTest extends ScassandraTestBase.PerClassCluster { |
| 46 | 43 | |
| 47 | 44 | |
| 48 | - @BeforeClass(groups={"short", "long"}) | |
| 45 | + @BeforeClass(groups = {"short", "long"}) | |
| 49 | 46 | public void reinitializeCluster() { |
| 50 | 47 | // Don't use the provided cluster, each test will create its own instead. |
| 51 | 48 | cluster.close(); |
| @@ -72,10 +69,10 @@ | ||
| 72 | 69 | */ |
| 73 | 70 | private List<MockRequest> sendRequests(int count, HostConnectionPool pool, List<Connection> expectedConnections) throws ConnectionException, BusyConnectionException, TimeoutException { |
| 74 | 71 | List<MockRequest> requests = newArrayList(); |
| 75 | - for(int i = 0; i < count; i++) { | |
| 72 | + for (int i = 0; i < count; i++) { | |
| 76 | 73 | MockRequest request = MockRequest.send(pool); |
| 77 | 74 | requests.add(request); |
| 78 | - if(expectedConnections != null) | |
| 75 | + if (expectedConnections != null) | |
| 79 | 76 | assertThat(expectedConnections).contains(request.connection); |
| 80 | 77 | } |
| 81 | 78 | return requests; |
| @@ -86,8 +83,8 @@ | ||
| 86 | 83 | */ |
| 87 | 84 | private void completeRequests(int count, List<MockRequest> requests) { |
| 88 | 85 | Iterator<MockRequest> requestIt = requests.iterator(); |
| 89 | - for(int i = 0; i < count; i++) { | |
| 90 | - if(requestIt.hasNext()) { | |
| 86 | + for (int i = 0; i < count; i++) { | |
| 87 | + if (requestIt.hasNext()) { | |
| 91 | 88 | MockRequest request = requestIt.next(); |
| 92 | 89 | request.simulateSuccessResponse(); |
| 93 | 90 | requestIt.remove(); |
| @@ -101,7 +98,7 @@ | ||
| 101 | 98 | * Completes all requests by simulating a successful response. |
| 102 | 99 | */ |
| 103 | 100 | private void completeRequests(List<MockRequest> requests) { |
| 104 | - for(MockRequest request : requests) { | |
| 101 | + for (MockRequest request : requests) { | |
| 105 | 102 | request.simulateSuccessResponse(); |
| 106 | 103 | } |
| 107 | 104 | } |
| @@ -110,9 +107,9 @@ | ||
| 110 | 107 | * Ensures that if a fixed-sized pool has filled its core connections that borrowConnection will timeout instead |
| 111 | 108 | * of creating a new connection. |
| 112 | 109 | * |
| 113 | - * @since 2.0.10, 2.1.6 | |
| 114 | 110 | * @jira_ticket JAVA-419 |
| 115 | 111 | * @test_category connection:connection_pool |
| 112 | + * @since 2.0.10, 2.1.6 | |
| 116 | 113 | */ |
| 117 | 114 | @Test(groups = "short") |
| 118 | 115 | public void fixed_size_pool_should_fill_its_core_connections_and_then_timeout() throws ConnectionException, TimeoutException, BusyConnectionException { |
| @@ -139,9 +136,9 @@ | ||
| 139 | 136 | * Ensures that if a variable-sized pool has filled up to its maximum connections that borrowConnection will |
| 140 | 137 | * timeout instead of creating a new connection. |
| 141 | 138 | * |
| 142 | - * @since 2.0.10, 2.1.6 | |
| 143 | 139 | * @jira_ticket JAVA-419 |
| 144 | 140 | * @test_category connection:connection_pool |
| 141 | + * @since 2.0.10, 2.1.6 | |
| 145 | 142 | */ |
| 146 | 143 | @Test(groups = "short") |
| 147 | 144 | public void variable_size_pool_should_fill_its_connections_and_then_timeout() throws Exception { |
| @@ -187,9 +184,9 @@ | ||
| 187 | 184 | /** |
| 188 | 185 | * Ensures that if the core connection pool is full that borrowConnection will create and use a new connection. |
| 189 | 186 | * |
| 190 | - * @since 2.0.10, 2.1.6 | |
| 191 | 187 | * @jira_ticket JAVA-419 |
| 192 | 188 | * @test_category connection:connection_pool |
| 189 | + * @since 2.0.10, 2.1.6 | |
| 193 | 190 | */ |
| 194 | 191 | @Test(groups = "short") |
| 195 | 192 | public void should_add_extra_connection_when_core_full() throws Exception { |
| @@ -217,9 +214,9 @@ | ||
| 217 | 214 | * Ensures that a trashed connection that has not been timed out should be resurrected into the connection pool if |
| 218 | 215 | * borrowConnection is called and a new connection is needed. |
| 219 | 216 | * |
| 220 | - * @since 2.0.10, 2.1.6 | |
| 221 | 217 | * @jira_ticket JAVA-419 |
| 222 | 218 | * @test_category connection:connection_pool |
| 219 | + * @since 2.0.10, 2.1.6 | |
| 223 | 220 | */ |
| 224 | 221 | @Test(groups = "long") |
| 225 | 222 | public void should_resurrect_trashed_connection_within_idle_timeout() throws Exception { |
| @@ -277,9 +274,9 @@ | ||
| 277 | 274 | * Ensures that a trashed connection that has been timed out should not be resurrected into the connection pool if |
| 278 | 275 | * borrowConnection is called and a new connection is needed. |
| 279 | 276 | * |
| 280 | - * @since 2.0.10, 2.1.6 | |
| 281 | 277 | * @jira_ticket JAVA-419 |
| 282 | 278 | * @test_category connection:connection_pool |
| 279 | + * @since 2.0.10, 2.1.6 | |
| 283 | 280 | */ |
| 284 | 281 | @Test(groups = "long") |
| 285 | 282 | public void should_not_resurrect_trashed_connection_after_idle_timeout() throws Exception { |
| @@ -331,8 +328,8 @@ | ||
| 331 | 328 | MockRequest request = MockRequest.send(pool); |
| 332 | 329 | requests.add(request); |
| 333 | 330 | assertThat(request.connection) |
| 334 | - .isNotEqualTo(connection2) // should not be the full connection | |
| 335 | - .isNotEqualTo(connection1); // should not be the previously trashed one | |
| 331 | + .isNotEqualTo(connection2) // should not be the full connection | |
| 332 | + .isNotEqualTo(connection1); // should not be the previously trashed one | |
| 336 | 333 | } finally { |
| 337 | 334 | completeRequests(requests); |
| 338 | 335 | cluster.close(); |
| @@ -342,9 +339,9 @@ | ||
| 342 | 339 | /** |
| 343 | 340 | * Ensures that a trashed connection that has been timed out should not be closed until it has 0 in flight requests. |
| 344 | 341 | * |
| 345 | - * @since 2.0.10, 2.1.6 | |
| 346 | 342 | * @jira_ticket JAVA-419 |
| 347 | 343 | * @test_category connection:connection_pool |
| 344 | + * @since 2.0.10, 2.1.6 | |
| 348 | 345 | */ |
| 349 | 346 | @Test(groups = "long") |
| 350 | 347 | public void should_not_close_trashed_connection_until_no_in_flight() throws Exception { |
| @@ -394,9 +391,9 @@ | ||
| 394 | 391 | * Ensures that if a connection that has less than the minimum available stream ids is returned to the pool that |
| 395 | 392 | * the connection is put in the trash. |
| 396 | 393 | * |
| 397 | - * @since 2.0.10, 2.1.6 | |
| 398 | 394 | * @jira_ticket JAVA-419 |
| 399 | 395 | * @test_category connection:connection_pool |
| 396 | + * @since 2.0.10, 2.1.6 | |
| 400 | 397 | */ |
| 401 | 398 | @Test(groups = "short") |
| 402 | 399 | public void should_trash_on_returning_connection_with_insufficient_streams() throws Exception { |
| @@ -444,7 +441,7 @@ | ||
| 444 | 441 | * @test_category connection:connection_pool |
| 445 | 442 | * @since 2.0.11 |
| 446 | 443 | */ |
| 447 | - @Test(groups="short") | |
| 444 | + @Test(groups = "short") | |
| 448 | 445 | public void should_keep_host_up_when_one_connection_lost() throws Exception { |
| 449 | 446 | Cluster cluster = createClusterBuilder().build(); |
| 450 | 447 | try { |
| @@ -454,7 +451,7 @@ | ||
| 454 | 451 | |
| 455 | 452 | // Drop a connection and ensure the host stays up. |
| 456 | 453 | currentClient.disableListener(); |
| 457 | - currentClient.closeConnection(CLOSE, ((InetSocketAddress)core0.channel.localAddress())); | |
| 454 | + currentClient.closeConnection(CLOSE, ((InetSocketAddress) core0.channel.localAddress())); | |
| 458 | 455 | Uninterruptibles.sleepUninterruptibly(100, TimeUnit.MILLISECONDS); |
| 459 | 456 | |
| 460 | 457 | // connection 0 should be down, while connection 1 and the Host should remain up. |
| @@ -478,22 +475,22 @@ | ||
| 478 | 475 | * @test_category connection:connection_pool |
| 479 | 476 | * @since 2.0.11 |
| 480 | 477 | */ |
| 481 | - @Test(groups="short") | |
| 478 | + @Test(groups = "short") | |
| 482 | 479 | public void should_mark_host_down_when_no_connections_remaining() throws Exception { |
| 483 | 480 | int readTimeout = 1000; |
| 484 | 481 | int reconnectInterval = 1000; |
| 485 | 482 | Cluster cluster = this.createClusterBuilder() |
| 486 | - .withSocketOptions(new SocketOptions() | |
| 487 | - .setConnectTimeoutMillis(readTimeout) | |
| 488 | - .setReadTimeoutMillis(reconnectInterval)) | |
| 489 | - .withReconnectionPolicy(new ConstantReconnectionPolicy(1000)).build(); | |
| 483 | + .withSocketOptions(new SocketOptions() | |
| 484 | + .setConnectTimeoutMillis(readTimeout) | |
| 485 | + .setReadTimeoutMillis(reconnectInterval)) | |
| 486 | + .withReconnectionPolicy(new ConstantReconnectionPolicy(1000)).build(); | |
| 490 | 487 | try { |
| 491 | 488 | cluster.init(); |
| 492 | 489 | |
| 493 | 490 | Connection.Factory factory = spy(cluster.manager.connectionFactory); |
| 494 | 491 | cluster.manager.connectionFactory = factory; |
| 495 | 492 | |
| 496 | - HostConnectionPool pool = createPool(cluster, 8,8); | |
| 493 | + HostConnectionPool pool = createPool(cluster, 8, 8); | |
| 497 | 494 | // copy list to track these connections. |
| 498 | 495 | List<Connection> connections = newArrayList(pool.connections); |
| 499 | 496 | |
| @@ -508,13 +505,13 @@ | ||
| 508 | 505 | assertThat(cluster).hasClosedControlConnection(); |
| 509 | 506 | |
| 510 | 507 | // Ensure all connections are closed. |
| 511 | - for(Connection connection : connections) { | |
| 508 | + for (Connection connection : connections) { | |
| 512 | 509 | assertThat(connection.isClosed()).isTrue(); |
| 513 | 510 | } |
| 514 | 511 | |
| 515 | 512 | // Expect a reconnect attempt on host after reconnect interval |
| 516 | 513 | // on behalf of the control connection. |
| 517 | - verify(factory, timeout(reconnectInterval*2).atLeastOnce()).open(host); | |
| 514 | + verify(factory, timeout(reconnectInterval * 2).atLeastOnce()).open(host); | |
| 518 | 515 | |
| 519 | 516 | // Sleep for a bit to allow reconnect to fail. |
| 520 | 517 | Uninterruptibles.sleepUninterruptibly(readTimeout * 2, TimeUnit.MILLISECONDS); |
| @@ -528,9 +525,9 @@ | ||
| 528 | 525 | // Reconnect attempt should have been connected for control connection |
| 529 | 526 | // and pool. |
| 530 | 527 | // 2 attempts for connection.open (reconnect control connection and initial connection for host state). |
| 531 | - verify(factory, after(reconnectInterval*2).atLeast(2)).open(host); | |
| 528 | + verify(factory, after(reconnectInterval * 2).atLeast(2)).open(host); | |
| 532 | 529 | // 7 attempts for core connections after first initial connection. |
| 533 | - verify(factory, timeout(reconnectInterval*2)).newConnections(any(HostConnectionPool.class), eq(7)); | |
| 530 | + verify(factory, timeout(reconnectInterval * 2)).newConnections(any(HostConnectionPool.class), eq(7)); | |
| 534 | 531 | |
| 535 | 532 | // Wait some reasonable amount of time for connection to reestablish. |
| 536 | 533 | Uninterruptibles.sleepUninterruptibly(readTimeout, TimeUnit.MILLISECONDS); |
| @@ -553,15 +550,15 @@ | ||
| 553 | 550 | * @test_category connection:connection_pool |
| 554 | 551 | * @since 2.0.11 |
| 555 | 552 | */ |
| 556 | - @Test(groups="short") | |
| 553 | + @Test(groups = "short") | |
| 557 | 554 | public void should_create_new_connections_when_connection_lost_and_under_core_connections() throws Exception { |
| 558 | 555 | int readTimeout = 1000; |
| 559 | 556 | int reconnectInterval = 1000; |
| 560 | 557 | Cluster cluster = this.createClusterBuilder() |
| 561 | - .withSocketOptions(new SocketOptions() | |
| 562 | - .setConnectTimeoutMillis(readTimeout) | |
| 563 | - .setReadTimeoutMillis(reconnectInterval)) | |
| 564 | - .withReconnectionPolicy(new ConstantReconnectionPolicy(1000)).build(); | |
| 558 | + .withSocketOptions(new SocketOptions() | |
| 559 | + .setConnectTimeoutMillis(readTimeout) | |
| 560 | + .setReadTimeoutMillis(reconnectInterval)) | |
| 561 | + .withReconnectionPolicy(new ConstantReconnectionPolicy(1000)).build(); | |
| 565 | 562 | List<MockRequest> requests = newArrayList(); |
| 566 | 563 | try { |
| 567 | 564 | cluster.init(); |
| @@ -577,8 +574,8 @@ | ||
| 577 | 574 | // Drop two core connections. |
| 578 | 575 | // Disable new connections initially and we'll eventually reenable it. |
| 579 | 576 | currentClient.disableListener(); |
| 580 | - currentClient.closeConnection(CLOSE, ((InetSocketAddress)core0.channel.localAddress())); | |
| 581 | - currentClient.closeConnection(CLOSE, ((InetSocketAddress)core2.channel.localAddress())); | |
| 577 | + currentClient.closeConnection(CLOSE, ((InetSocketAddress) core0.channel.localAddress())); | |
| 578 | + currentClient.closeConnection(CLOSE, ((InetSocketAddress) core2.channel.localAddress())); | |
| 582 | 579 | Uninterruptibles.sleepUninterruptibly(100, TimeUnit.MILLISECONDS); |
| 583 | 580 | |
| 584 | 581 | // Since we have a connection left the host should remain up. |
| @@ -646,10 +643,10 @@ | ||
| 646 | 643 | int readTimeout = 1000; |
| 647 | 644 | int reconnectInterval = 1000; |
| 648 | 645 | Cluster cluster = this.createClusterBuilder() |
| 649 | - .withSocketOptions(new SocketOptions() | |
| 650 | - .setConnectTimeoutMillis(readTimeout) | |
| 651 | - .setReadTimeoutMillis(reconnectInterval)) | |
| 652 | - .withReconnectionPolicy(new ConstantReconnectionPolicy(1000)).build(); | |
| 646 | + .withSocketOptions(new SocketOptions() | |
| 647 | + .setConnectTimeoutMillis(readTimeout) | |
| 648 | + .setReadTimeoutMillis(reconnectInterval)) | |
| 649 | + .withReconnectionPolicy(new ConstantReconnectionPolicy(1000)).build(); | |
| 653 | 650 | List<MockRequest> requests = newArrayList(); |
| 654 | 651 | try { |
| 655 | 652 | cluster.init(); |
| @@ -679,12 +676,12 @@ | ||
| 679 | 676 | Connection extra1 = pool.connections.get(1); |
| 680 | 677 | |
| 681 | 678 | // Drop a connection and disable listening. |
| 682 | - currentClient.closeConnection(CLOSE, ((InetSocketAddress)core0.channel.localAddress())); | |
| 679 | + currentClient.closeConnection(CLOSE, ((InetSocketAddress) core0.channel.localAddress())); | |
| 683 | 680 | Uninterruptibles.sleepUninterruptibly(100, TimeUnit.MILLISECONDS); |
| 684 | 681 | currentClient.disableListener(); |
| 685 | 682 | |
| 686 | 683 | // Since core0 was closed, all of it's requests should have errored. |
| 687 | - for(MockRequest request : core0requests) { | |
| 684 | + for (MockRequest request : core0requests) { | |
| 688 | 685 | verify(request, times(1)).onException(any(Connection.class), any(Exception.class), anyLong(), anyInt()); |
| 689 | 686 | } |
| 690 | 687 | |
| @@ -744,15 +741,15 @@ | ||
| 744 | 741 | * @test_category connection:connection_pool |
| 745 | 742 | * @since 2.0.11 |
| 746 | 743 | */ |
| 747 | - @Test(groups="short") | |
| 744 | + @Test(groups = "short") | |
| 748 | 745 | public void should_not_mark_host_down_if_some_connections_fail_on_init() throws Exception { |
| 749 | 746 | int readTimeout = 1000; |
| 750 | 747 | int reconnectInterval = 1000; |
| 751 | 748 | Cluster cluster = this.createClusterBuilder() |
| 752 | - .withSocketOptions(new SocketOptions() | |
| 753 | - .setConnectTimeoutMillis(readTimeout) | |
| 754 | - .setReadTimeoutMillis(reconnectInterval)) | |
| 755 | - .withReconnectionPolicy(new ConstantReconnectionPolicy(1000)).build(); | |
| 749 | + .withSocketOptions(new SocketOptions() | |
| 750 | + .setConnectTimeoutMillis(readTimeout) | |
| 751 | + .setReadTimeoutMillis(reconnectInterval)) | |
| 752 | + .withReconnectionPolicy(new ConstantReconnectionPolicy(1000)).build(); | |
| 756 | 753 | List<MockRequest> requests = newArrayList(); |
| 757 | 754 | try { |
| 758 | 755 | cluster.init(); |
| @@ -810,10 +807,10 @@ | ||
| 810 | 807 | int readTimeout = 1000; |
| 811 | 808 | int reconnectInterval = 1000; |
| 812 | 809 | Cluster cluster = this.createClusterBuilder() |
| 813 | - .withSocketOptions(new SocketOptions() | |
| 814 | - .setConnectTimeoutMillis(readTimeout) | |
| 815 | - .setReadTimeoutMillis(reconnectInterval)) | |
| 816 | - .withReconnectionPolicy(new ConstantReconnectionPolicy(1000)).build(); | |
| 810 | + .withSocketOptions(new SocketOptions() | |
| 811 | + .setConnectTimeoutMillis(readTimeout) | |
| 812 | + .setReadTimeoutMillis(reconnectInterval)) | |
| 813 | + .withReconnectionPolicy(new ConstantReconnectionPolicy(1000)).build(); | |
| 817 | 814 | try { |
| 818 | 815 | // Init cluster so control connection is created. |
| 819 | 816 | cluster.init(); |
| @@ -851,15 +848,15 @@ | ||
| 851 | 848 | * @test_category connection:connection_pool |
| 852 | 849 | * @since 2.0.11 |
| 853 | 850 | */ |
| 854 | - @Test(groups="short") | |
| 851 | + @Test(groups = "short") | |
| 855 | 852 | public void should_wait_on_connection_if_not_convicted_and_no_connections_available() throws Exception { |
| 856 | 853 | int readTimeout = 1000; |
| 857 | 854 | int reconnectInterval = 1000; |
| 858 | 855 | Cluster cluster = this.createClusterBuilder() |
| 859 | - .withSocketOptions(new SocketOptions() | |
| 860 | - .setConnectTimeoutMillis(readTimeout) | |
| 861 | - .setReadTimeoutMillis(reconnectInterval)) | |
| 862 | - .withReconnectionPolicy(new ConstantReconnectionPolicy(1000)).build(); | |
| 856 | + .withSocketOptions(new SocketOptions() | |
| 857 | + .setConnectTimeoutMillis(readTimeout) | |
| 858 | + .setReadTimeoutMillis(reconnectInterval)) | |
| 859 | + .withReconnectionPolicy(new ConstantReconnectionPolicy(1000)).build(); | |
| 863 | 860 | try { |
| 864 | 861 | // Init cluster so control connection is created. |
| 865 | 862 | cluster.init(); |
| @@ -906,15 +903,15 @@ | ||
| 906 | 903 | * @test_category connection:connection_pool |
| 907 | 904 | * @since 2.0.11 |
| 908 | 905 | */ |
| 909 | - @Test(groups="short") | |
| 906 | + @Test(groups = "short") | |
| 910 | 907 | public void should_wait_on_connection_if_zero_core_connections() throws Exception { |
| 911 | 908 | int readTimeout = 1000; |
| 912 | 909 | int reconnectInterval = 1000; |
| 913 | 910 | Cluster cluster = this.createClusterBuilder() |
| 914 | - .withSocketOptions(new SocketOptions() | |
| 915 | - .setConnectTimeoutMillis(readTimeout) | |
| 916 | - .setReadTimeoutMillis(reconnectInterval)) | |
| 917 | - .withReconnectionPolicy(new ConstantReconnectionPolicy(1000)).build(); | |
| 911 | + .withSocketOptions(new SocketOptions() | |
| 912 | + .setConnectTimeoutMillis(readTimeout) | |
| 913 | + .setReadTimeoutMillis(reconnectInterval)) | |
| 914 | + .withReconnectionPolicy(new ConstantReconnectionPolicy(1000)).build(); | |
| 918 | 915 | try { |
| 919 | 916 | // Init cluster so control connection is created. |
| 920 | 917 | cluster.init(); |
| @@ -942,26 +939,26 @@ | ||
| 942 | 939 | |
| 943 | 940 | private HostConnectionPool createPool(Cluster cluster, int coreConnections, int maxConnections) { |
| 944 | 941 | cluster.getConfiguration().getPoolingOptions() |
| 945 | - .setMaxConnectionsPerHost(HostDistance.LOCAL, maxConnections) | |
| 946 | - .setCoreConnectionsPerHost(HostDistance.LOCAL, coreConnections); | |
| 942 | + .setMaxConnectionsPerHost(HostDistance.LOCAL, maxConnections) | |
| 943 | + .setCoreConnectionsPerHost(HostDistance.LOCAL, coreConnections); | |
| 947 | 944 | Session session = cluster.connect(); |
| 948 | 945 | Host host = TestUtils.findHost(cluster, 1); |
| 949 | 946 | |
| 950 | 947 | // Replace the existing pool with a spy pool and return it. |
| 951 | - SessionManager sm = ((SessionManager)session); | |
| 948 | + SessionManager sm = ((SessionManager) session); | |
| 952 | 949 | return sm.pools.get(host); |
| 953 | 950 | } |
| 954 | 951 | |
| 955 | 952 | /** |
| 956 | - * <p> | |
| 953 | + * <p/> | |
| 957 | 954 | * This test uses a table named "Java349" with 1000 column and performs asynchronously 100k insertions. While the |
| 958 | 955 | * insertions are being executed, the number of opened connection is monitored. |
| 959 | 956 | * <p/> |
| 960 | 957 | * If at anytime, the number of opened connections is negative, this test will fail. |
| 961 | 958 | * |
| 962 | - * @since 2.0.6, 2.1.1 | |
| 963 | 959 | * @jira_ticket JAVA-349 |
| 964 | 960 | * @test_category connection:connection_pool |
| 961 | + * @since 2.0.6, 2.1.1 | |
| 965 | 962 | */ |
| 966 | 963 | @Test(groups = "long", enabled = false /* this test causes timeouts on Jenkins */) |
| 967 | 964 | public void open_connections_metric_should_always_be_positive() throws InterruptedException { |
| @@ -1021,17 +1018,19 @@ | ||
| 1021 | 1018 | sb.append(");"); |
| 1022 | 1019 | |
| 1023 | 1020 | PrimingRequest preparedStatementPrime = PrimingRequest.preparedStatementBuilder() |
| 1024 | - .withQuery(sb.toString()) | |
| 1025 | - .withThen(then().withVariableTypes(PrimitiveType.INT)) | |
| 1026 | - .build(); | |
| 1021 | + .withQuery(sb.toString()) | |
| 1022 | + .withThen(then().withVariableTypes(PrimitiveType.INT)) | |
| 1023 | + .build(); | |
| 1027 | 1024 | primingClient.prime(preparedStatementPrime); |
| 1028 | 1025 | return sb.toString(); |
| 1029 | 1026 | } |
| 1030 | 1027 | |
| 1031 | - /** Mock ResponseCallback that simulates the behavior of SpeculativeExecution (in terms of borrowing/releasing connections). */ | |
| 1028 | + /** | |
| 1029 | + * Mock ResponseCallback that simulates the behavior of SpeculativeExecution (in terms of borrowing/releasing connections). | |
| 1030 | + */ | |
| 1032 | 1031 | static class MockRequest implements Connection.ResponseCallback { |
| 1033 | 1032 | |
| 1034 | - enum State { START, COMPLETED, FAILED, TIMED_OUT } | |
| 1033 | + enum State {START, COMPLETED, FAILED, TIMED_OUT} | |
| 1035 | 1034 | |
| 1036 | 1035 | final Connection connection; |
| 1037 | 1036 | private Connection.ResponseHandler responseHandler; |
modified driver-core/src/test/java/com/datastax/driver/core/LargeDataTest.java +31 −15
| @@ -15,18 +15,17 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.nio.ByteBuffer; | |
| 19 | - | |
| 20 | -import org.testng.annotations.Test; | |
| 21 | -import static org.testng.Assert.assertEquals; | |
| 22 | -import static org.testng.Assert.assertTrue; | |
| 23 | - | |
| 24 | 18 | import com.datastax.driver.core.querybuilder.Batch; |
| 25 | 19 | import com.datastax.driver.core.querybuilder.Insert; |
| 26 | 20 | import com.datastax.driver.core.utils.CassandraVersion; |
| 21 | +import org.testng.annotations.Test; | |
| 22 | + | |
| 23 | +import java.nio.ByteBuffer; | |
| 27 | 24 | |
| 28 | 25 | import static com.datastax.driver.core.TestUtils.CREATE_KEYSPACE_SIMPLE_FORMAT; |
| 29 | 26 | import static com.datastax.driver.core.querybuilder.QueryBuilder.*; |
| 27 | +import static org.testng.Assert.assertEquals; | |
| 28 | +import static org.testng.Assert.assertTrue; | |
| 30 | 29 | |
| 31 | 30 | /** |
| 32 | 31 | * Test limitations when using large amounts of data with the driver |
| @@ -179,10 +178,11 @@ | ||
| 179 | 178 | |
| 180 | 179 | /** |
| 181 | 180 | * Test a wide row of size 1,000,000 |
| 181 | + * | |
| 182 | 182 | * @throws Throwable |
| 183 | 183 | */ |
| 184 | 184 | @Test(groups = "stress") |
| 185 | - @CassandraVersion(major=2.0, minor=0, description="< 2.0 is skipped as 1.2 does not handle reading wide rows well.") | |
| 185 | + @CassandraVersion(major = 2.0, minor = 0, description = "< 2.0 is skipped as 1.2 does not handle reading wide rows well.") | |
| 186 | 186 | public void wideRows() throws Throwable { |
| 187 | 187 | Cluster.Builder builder = Cluster.builder(); |
| 188 | 188 | CCMBridge.CCMCluster c = CCMBridge.buildCluster(1, builder); |
| @@ -203,10 +203,11 @@ | ||
| 203 | 203 | |
| 204 | 204 | /** |
| 205 | 205 | * Test a batch that writes a row of size 10,000 |
| 206 | + * | |
| 206 | 207 | * @throws Throwable |
| 207 | 208 | */ |
| 208 | 209 | @Test(groups = "stress") |
| 209 | - @CassandraVersion(major=2.0, minor=0, description="< 2.0 is skipped as 1.2 does not handle large batches well.") | |
| 210 | + @CassandraVersion(major = 2.0, minor = 0, description = "< 2.0 is skipped as 1.2 does not handle large batches well.") | |
| 210 | 211 | public void wideBatchRows() throws Throwable { |
| 211 | 212 | Cluster.Builder builder = Cluster.builder(); |
| 212 | 213 | CCMBridge.CCMCluster c = CCMBridge.buildCluster(1, builder); |
| @@ -227,6 +228,7 @@ | ||
| 227 | 228 | |
| 228 | 229 | /** |
| 229 | 230 | * Test a wide row of size 1,000,000 consisting of a ByteBuffer |
| 231 | + * | |
| 230 | 232 | * @throws Throwable |
| 231 | 233 | */ |
| 232 | 234 | @Test(groups = "stress") |
| @@ -250,6 +252,7 @@ | ||
| 250 | 252 | |
| 251 | 253 | /** |
| 252 | 254 | * Test a row with a single extra large text value |
| 255 | + * | |
| 253 | 256 | * @throws Throwable |
| 254 | 257 | */ |
| 255 | 258 | @Test(groups = "stress") |
| @@ -273,6 +276,7 @@ | ||
| 273 | 276 | |
| 274 | 277 | /** |
| 275 | 278 | * Creates a table with 330 columns |
| 279 | + * | |
| 276 | 280 | * @throws Throwable |
| 277 | 281 | */ |
| 278 | 282 | @Test(groups = "stress") |
| @@ -305,6 +309,7 @@ | ||
| 305 | 309 | |
| 306 | 310 | /** |
| 307 | 311 | * Tests 10 random tests consisting of the other methods in this class |
| 312 | + * | |
| 308 | 313 | * @throws Throwable |
| 309 | 314 | */ |
| 310 | 315 | @Test(groups = "duration") |
| @@ -331,13 +336,24 @@ | ||
| 331 | 336 | |
| 332 | 337 | try { |
| 333 | 338 | for (int i = 0; i < 10; ++i) { |
| 334 | - switch ((int) (Math.random() * 5)){ | |
| 335 | - case 0: testWideRows(c, 0); break; | |
| 336 | - case 1: testWideBatchRows(c, 0); break; | |
| 337 | - case 2: testByteRows(c, 0); break; | |
| 338 | - case 3: testLargeText(c, 0); break; | |
| 339 | - case 4: testWideTable(c, 0); break; | |
| 340 | - default: break; | |
| 339 | + switch ((int) (Math.random() * 5)) { | |
| 340 | + case 0: | |
| 341 | + testWideRows(c, 0); | |
| 342 | + break; | |
| 343 | + case 1: | |
| 344 | + testWideBatchRows(c, 0); | |
| 345 | + break; | |
| 346 | + case 2: | |
| 347 | + testByteRows(c, 0); | |
| 348 | + break; | |
| 349 | + case 3: | |
| 350 | + testLargeText(c, 0); | |
| 351 | + break; | |
| 352 | + case 4: | |
| 353 | + testWideTable(c, 0); | |
| 354 | + break; | |
| 355 | + default: | |
| 356 | + break; | |
| 341 | 357 | } |
| 342 | 358 | } |
| 343 | 359 | } catch (Throwable e) { |
modified driver-core/src/test/java/com/datastax/driver/core/LoadBalancingPolicyBootstrapTest.java +21 −22
| @@ -15,23 +15,21 @@ | ||
| 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.policies.DelegatingLoadBalancingPolicy; | |
| 19 | +import com.datastax.driver.core.policies.LoadBalancingPolicy; | |
| 20 | +import com.datastax.driver.core.policies.RoundRobinPolicy; | |
| 21 | 21 | import com.google.common.base.Objects; |
| 22 | 22 | import com.google.common.collect.Lists; |
| 23 | 23 | import org.slf4j.Logger; |
| 24 | 24 | import org.slf4j.LoggerFactory; |
| 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.policies.DelegatingLoadBalancingPolicy; | |
| 30 | -import com.datastax.driver.core.policies.LoadBalancingPolicy; | |
| 31 | -import com.datastax.driver.core.policies.RoundRobinPolicy; | |
| 27 | +import java.util.Collection; | |
| 28 | +import java.util.List; | |
| 32 | 29 | |
| 33 | 30 | import static com.datastax.driver.core.LoadBalancingPolicyBootstrapTest.HistoryPolicy.Action.*; |
| 34 | 31 | import static com.datastax.driver.core.LoadBalancingPolicyBootstrapTest.HistoryPolicy.entry; |
| 32 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 35 | 33 | |
| 36 | 34 | public class LoadBalancingPolicyBootstrapTest { |
| 37 | 35 | |
| @@ -53,15 +51,15 @@ | ||
| 53 | 51 | try { |
| 54 | 52 | ccm = CCMBridge.builder("test").withNodes(2).build(); |
| 55 | 53 | cluster = Cluster.builder() |
| 56 | - .addContactPoints(CCMBridge.ipOfNode(1), CCMBridge.ipOfNode(2)) | |
| 57 | - .withLoadBalancingPolicy(policy) | |
| 58 | - .build(); | |
| 54 | + .addContactPoints(CCMBridge.ipOfNode(1), CCMBridge.ipOfNode(2)) | |
| 55 | + .withLoadBalancingPolicy(policy) | |
| 56 | + .build(); | |
| 59 | 57 | |
| 60 | 58 | cluster.init(); |
| 61 | 59 | |
| 62 | 60 | assertThat(policy.history).containsOnly( |
| 63 | - entry(INIT, TestUtils.findHost(cluster, 1)), | |
| 64 | - entry(INIT, TestUtils.findHost(cluster, 2)) | |
| 61 | + entry(INIT, TestUtils.findHost(cluster, 1)), | |
| 62 | + entry(INIT, TestUtils.findHost(cluster, 2)) | |
| 65 | 63 | ); |
| 66 | 64 | } finally { |
| 67 | 65 | if (cluster != null) |
| @@ -104,23 +102,23 @@ | ||
| 104 | 102 | |
| 105 | 103 | HistoryPolicy policy = new HistoryPolicy(new RoundRobinPolicy()); |
| 106 | 104 | cluster = Cluster.builder() |
| 107 | - .addContactPoints(CCMBridge.ipOfNode(1), CCMBridge.ipOfNode(2)) | |
| 108 | - .withLoadBalancingPolicy(policy) | |
| 109 | - .build(); | |
| 105 | + .addContactPoints(CCMBridge.ipOfNode(1), CCMBridge.ipOfNode(2)) | |
| 106 | + .withLoadBalancingPolicy(policy) | |
| 107 | + .build(); | |
| 110 | 108 | |
| 111 | 109 | cluster.init(); |
| 112 | 110 | |
| 113 | 111 | if (policy.history.contains(entry(DOWN, TestUtils.findHost(cluster, nodeToStop)))) { |
| 114 | 112 | // This is the situation we're testing, the control connection tried the stopped node first. |
| 115 | 113 | assertThat(policy.history).containsExactly( |
| 116 | - entry(INIT, TestUtils.findHost(cluster, activeNode)), | |
| 117 | - entry(DOWN, TestUtils.findHost(cluster, nodeToStop)) | |
| 114 | + entry(INIT, TestUtils.findHost(cluster, activeNode)), | |
| 115 | + entry(DOWN, TestUtils.findHost(cluster, nodeToStop)) | |
| 118 | 116 | ); |
| 119 | 117 | break; |
| 120 | 118 | } else { |
| 121 | 119 | assertThat(policy.history).containsOnly( |
| 122 | - entry(INIT, TestUtils.findHost(cluster, 1)), | |
| 123 | - entry(INIT, TestUtils.findHost(cluster, 2)) | |
| 120 | + entry(INIT, TestUtils.findHost(cluster, 1)), | |
| 121 | + entry(INIT, TestUtils.findHost(cluster, 2)) | |
| 124 | 122 | ); |
| 125 | 123 | |
| 126 | 124 | logger.info("Could not get first contact point to fail, retrying"); |
| @@ -160,7 +158,7 @@ | ||
| 160 | 158 | if (other == this) |
| 161 | 159 | return true; |
| 162 | 160 | if (other instanceof Entry) { |
| 163 | - Entry that = (Entry)other; | |
| 161 | + Entry that = (Entry) other; | |
| 164 | 162 | return this.action == that.action && this.host.equals(that.host); |
| 165 | 163 | } |
| 166 | 164 | return false; |
| @@ -171,7 +169,8 @@ | ||
| 171 | 169 | return Objects.hashCode(action, host); |
| 172 | 170 | } |
| 173 | 171 | |
| 174 | - @Override public String toString() { | |
| 172 | + @Override | |
| 173 | + public String toString() { | |
| 175 | 174 | return Objects.toStringHelper(this).add("action", action).add("host", host).toString(); |
| 176 | 175 | } |
| 177 | 176 | } |
modified driver-core/src/test/java/com/datastax/driver/core/LoadBalancingPolicyRefreshTest.java +19 −10
| @@ -15,15 +15,15 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.net.InetAddress; | |
| 19 | -import java.util.*; | |
| 20 | - | |
| 18 | +import com.datastax.driver.core.policies.LoadBalancingPolicy; | |
| 21 | 19 | import com.google.common.collect.Iterators; |
| 22 | 20 | import org.testng.annotations.Test; |
| 23 | 21 | |
| 24 | -import static org.testng.Assert.*; | |
| 22 | +import java.net.InetAddress; | |
| 23 | +import java.util.Collection; | |
| 24 | +import java.util.Iterator; | |
| 25 | 25 | |
| 26 | -import com.datastax.driver.core.policies.LoadBalancingPolicy; | |
| 26 | +import static org.testng.Assert.assertTrue; | |
| 27 | 27 | |
| 28 | 28 | // Test that PoolingOpions.refreshConnectedHosts works as expected (JAVA-309) |
| 29 | 29 | public class LoadBalancingPolicyRefreshTest { |
| @@ -57,11 +57,20 @@ | ||
| 57 | 57 | return Iterators.<Host>singletonIterator(theHost); |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | - public void onAdd(Host h) {} | |
| 61 | - public void onRemove(Host h) {} | |
| 62 | - public void onUp(Host h) {} | |
| 63 | - public void onDown(Host h) {} | |
| 64 | - public void onSuspected(Host h) {} | |
| 60 | + public void onAdd(Host h) { | |
| 61 | + } | |
| 62 | + | |
| 63 | + public void onRemove(Host h) { | |
| 64 | + } | |
| 65 | + | |
| 66 | + public void onUp(Host h) { | |
| 67 | + } | |
| 68 | + | |
| 69 | + public void onDown(Host h) { | |
| 70 | + } | |
| 71 | + | |
| 72 | + public void onSuspected(Host h) { | |
| 73 | + } | |
| 65 | 74 | } |
| 66 | 75 | |
| 67 | 76 | @Test(groups = "short") |
modified driver-core/src/test/java/com/datastax/driver/core/M3PTokenFactoryTest.java +18 −19
| @@ -15,12 +15,11 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.util.List; | |
| 19 | - | |
| 20 | 18 | import org.testng.annotations.Test; |
| 21 | 19 | |
| 20 | +import java.util.List; | |
| 21 | + | |
| 22 | 22 | import static org.assertj.core.api.Assertions.assertThat; |
| 23 | -import static org.testng.Assert.fail; | |
| 24 | 23 | |
| 25 | 24 | public class M3PTokenFactoryTest { |
| 26 | 25 | Token.Factory factory = Token.M3PToken.FACTORY; |
| @@ -29,8 +28,8 @@ | ||
| 29 | 28 | public void should_split_range() { |
| 30 | 29 | List<Token> splits = factory.split(factory.fromString("-9223372036854775808"), factory.fromString("4611686018427387904"), 3); |
| 31 | 30 | assertThat(splits).containsExactly( |
| 32 | - factory.fromString("-4611686018427387904"), | |
| 33 | - factory.fromString("0") | |
| 31 | + factory.fromString("-4611686018427387904"), | |
| 32 | + factory.fromString("0") | |
| 34 | 33 | ); |
| 35 | 34 | } |
| 36 | 35 | |
| @@ -38,8 +37,8 @@ | ||
| 38 | 37 | public void should_split_range_that_wraps_around_the_ring() { |
| 39 | 38 | List<Token> splits = factory.split(factory.fromString("4611686018427387904"), factory.fromString("0"), 3); |
| 40 | 39 | assertThat(splits).containsExactly( |
| 41 | - factory.fromString("-9223372036854775807"), | |
| 42 | - factory.fromString("-4611686018427387903") | |
| 40 | + factory.fromString("-9223372036854775807"), | |
| 41 | + factory.fromString("-4611686018427387903") | |
| 43 | 42 | ); |
| 44 | 43 | } |
| 45 | 44 | |
| @@ -47,8 +46,8 @@ | ||
| 47 | 46 | public void should_split_range_when_division_not_integral() { |
| 48 | 47 | List<Token> splits = factory.split(factory.fromString("0"), factory.fromString("11"), 3); |
| 49 | 48 | assertThat(splits).containsExactly( |
| 50 | - factory.fromString("4"), | |
| 51 | - factory.fromString("8") | |
| 49 | + factory.fromString("4"), | |
| 50 | + factory.fromString("8") | |
| 52 | 51 | ); |
| 53 | 52 | } |
| 54 | 53 | |
| @@ -56,10 +55,10 @@ | ||
| 56 | 55 | public void should_split_range_producing_empty_splits() { |
| 57 | 56 | List<Token> splits = factory.split(factory.fromString("0"), factory.fromString("2"), 5); |
| 58 | 57 | assertThat(splits).containsExactly( |
| 59 | - factory.fromString("1"), | |
| 60 | - factory.fromString("2"), | |
| 61 | - factory.fromString("2"), | |
| 62 | - factory.fromString("2") | |
| 58 | + factory.fromString("1"), | |
| 59 | + factory.fromString("2"), | |
| 60 | + factory.fromString("2"), | |
| 61 | + factory.fromString("2") | |
| 63 | 62 | ); |
| 64 | 63 | } |
| 65 | 64 | |
| @@ -71,14 +70,14 @@ | ||
| 71 | 70 | // These are edge cases where we want to make sure we don't accidentally generate the ]min,min] range (which is the whole ring) |
| 72 | 71 | List<Token> splits = factory.split(maxToken, minToken, 3); |
| 73 | 72 | assertThat(splits).containsExactly( |
| 74 | - maxToken, | |
| 75 | - maxToken | |
| 73 | + maxToken, | |
| 74 | + maxToken | |
| 76 | 75 | ); |
| 77 | 76 | |
| 78 | 77 | splits = factory.split(minToken, factory.fromString("-9223372036854775807"), 3); |
| 79 | 78 | assertThat(splits).containsExactly( |
| 80 | - factory.fromString("-9223372036854775807"), | |
| 81 | - factory.fromString("-9223372036854775807") | |
| 79 | + factory.fromString("-9223372036854775807"), | |
| 80 | + factory.fromString("-9223372036854775807") | |
| 82 | 81 | ); |
| 83 | 82 | } |
| 84 | 83 | |
| @@ -86,8 +85,8 @@ | ||
| 86 | 85 | public void should_split_whole_ring() { |
| 87 | 86 | List<Token> splits = factory.split(factory.fromString("-9223372036854775808"), factory.fromString("-9223372036854775808"), 3); |
| 88 | 87 | assertThat(splits).containsExactly( |
| 89 | - factory.fromString("-3074457345618258603"), | |
| 90 | - factory.fromString("3074457345618258602") | |
| 88 | + factory.fromString("-3074457345618258603"), | |
| 89 | + factory.fromString("3074457345618258602") | |
| 91 | 90 | ); |
| 92 | 91 | } |
| 93 | 92 |
modified driver-core/src/test/java/com/datastax/driver/core/M3PTokenIntegrationTest.java +2 −1
| @@ -22,7 +22,8 @@ | ||
| 22 | 22 | super("", DataType.bigint()); |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | - @Override protected Token.Factory tokenFactory() { | |
| 25 | + @Override | |
| 26 | + protected Token.Factory tokenFactory() { | |
| 26 | 27 | return M3PToken.FACTORY; |
| 27 | 28 | } |
| 28 | 29 | } |
modified driver-core/src/test/java/com/datastax/driver/core/M3PTokenVnodeIntegrationTest.java +2 −1
| @@ -20,7 +20,8 @@ | ||
| 20 | 20 | super("", DataType.bigint(), true); |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | - @Override protected Token.Factory tokenFactory() { | |
| 23 | + @Override | |
| 24 | + protected Token.Factory tokenFactory() { | |
| 24 | 25 | return Token.M3PToken.FACTORY; |
| 25 | 26 | } |
| 26 | 27 | } |
modified driver-core/src/test/java/com/datastax/driver/core/MemoryAppender.java +5 −6
| @@ -15,21 +15,20 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | +import org.apache.log4j.PatternLayout; | |
| 19 | +import org.apache.log4j.WriterAppender; | |
| 20 | +import org.apache.log4j.spi.LoggingEvent; | |
| 21 | + | |
| 18 | 22 | import java.io.StringWriter; |
| 19 | -import java.util.concurrent.TimeoutException; | |
| 20 | 23 | import java.util.concurrent.locks.Condition; |
| 21 | 24 | import java.util.concurrent.locks.Lock; |
| 22 | 25 | import java.util.concurrent.locks.ReentrantLock; |
| 23 | 26 | |
| 24 | 27 | import static java.util.concurrent.TimeUnit.MILLISECONDS; |
| 25 | 28 | |
| 26 | -import org.apache.log4j.PatternLayout; | |
| 27 | -import org.apache.log4j.WriterAppender; | |
| 28 | -import org.apache.log4j.spi.LoggingEvent; | |
| 29 | - | |
| 30 | 29 | /** |
| 31 | 30 | * Simple Log4J appender that captures logs to memory in order to inspect them in unit tests. |
| 32 | - * <p> | |
| 31 | + * <p/> | |
| 33 | 32 | * There is no purging mechanism, so make sure it doesn't stay enabled for too long (this is best |
| 34 | 33 | * done with an {@code @After} method that removes it). |
| 35 | 34 | */ |
modified driver-core/src/test/java/com/datastax/driver/core/MetadataTest.java +19 −19
| @@ -15,11 +15,11 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.util.Map; | |
| 19 | - | |
| 20 | 18 | import com.google.common.collect.Maps; |
| 21 | 19 | import org.testng.annotations.Test; |
| 22 | 20 | |
| 21 | +import java.util.Map; | |
| 22 | + | |
| 23 | 23 | import static com.datastax.driver.core.Assertions.assertThat; |
| 24 | 24 | import static com.datastax.driver.core.TestUtils.nonDebouncingQueryOptions; |
| 25 | 25 | import static com.datastax.driver.core.TestUtils.waitFor; |
| @@ -30,18 +30,18 @@ | ||
| 30 | 30 | * <p> |
| 31 | 31 | * Validates that when the topology of the cluster changes that Cluster Metadata is properly updated. |
| 32 | 32 | * </p> |
| 33 | - * | |
| 34 | - * <p> | |
| 33 | + * <p/> | |
| 34 | + * <p/> | |
| 35 | 35 | * This test does the following: |
| 36 | - * | |
| 36 | + * <p/> | |
| 37 | 37 | * <ol> |
| 38 | - * <li>Creates a 3 node cluster and capture token range data from the {@link Cluster}'s {@link Metadata}</li> | |
| 39 | - * <li>Decommission node 3.</li> | |
| 40 | - * <li>Validates that the token range data was updated to reflect node 3 leaving and the other nodes | |
| 41 | - * taking on its token range.</li> | |
| 42 | - * <li>Adds a new node, node 4.</li> | |
| 43 | - * <li>Validates that the token range data was updated to reflect node 4 joining the {@link Cluster} and | |
| 44 | - * the token ranges reflecting this.</li> | |
| 38 | + * <li>Creates a 3 node cluster and capture token range data from the {@link Cluster}'s {@link Metadata}</li> | |
| 39 | + * <li>Decommission node 3.</li> | |
| 40 | + * <li>Validates that the token range data was updated to reflect node 3 leaving and the other nodes | |
| 41 | + * taking on its token range.</li> | |
| 42 | + * <li>Adds a new node, node 4.</li> | |
| 43 | + * <li>Validates that the token range data was updated to reflect node 4 joining the {@link Cluster} and | |
| 44 | + * the token ranges reflecting this.</li> | |
| 45 | 45 | * </ol> |
| 46 | 46 | * |
| 47 | 47 | * @test_category metadata:token |
| @@ -49,7 +49,7 @@ | ||
| 49 | 49 | * @jira_ticket JAVA-312 |
| 50 | 50 | * @since 2.0.10, 2.1.5 |
| 51 | 51 | */ |
| 52 | - @Test(groups="long") | |
| 52 | + @Test(groups = "long") | |
| 53 | 53 | public void should_update_metadata_on_topology_change() { |
| 54 | 54 | CCMBridge ccm = null; |
| 55 | 55 | Cluster cluster = null; |
| @@ -58,9 +58,9 @@ | ||
| 58 | 58 | ccm = CCMBridge.builder("test").withNodes(3).build(); |
| 59 | 59 | |
| 60 | 60 | cluster = Cluster.builder() |
| 61 | - .addContactPoint(CCMBridge.ipOfNode(1)) | |
| 62 | - .withQueryOptions(nonDebouncingQueryOptions()) | |
| 63 | - .build(); | |
| 61 | + .addContactPoint(CCMBridge.ipOfNode(1)) | |
| 62 | + .withQueryOptions(nonDebouncingQueryOptions()) | |
| 63 | + .build(); | |
| 64 | 64 | Session session = cluster.connect(); |
| 65 | 65 | |
| 66 | 66 | String keyspace = "test"; |
| @@ -99,8 +99,8 @@ | ||
| 99 | 99 | TokenRange host4Range = metadata.getTokenRanges(keyspace, host4).iterator().next(); |
| 100 | 100 | |
| 101 | 101 | // Ensure no host token range intersects with node 4. |
| 102 | - for(Host host : metadata.getAllHosts()) { | |
| 103 | - if(!host.equals(host4)) { | |
| 102 | + for (Host host : metadata.getAllHosts()) { | |
| 103 | + if (!host.equals(host4)) { | |
| 104 | 104 | TokenRange hostRange = metadata.getTokenRanges(keyspace, host).iterator().next(); |
| 105 | 105 | assertThat(host4Range).doesNotIntersect(hostRange); |
| 106 | 106 | } |
| @@ -122,7 +122,7 @@ | ||
| 122 | 122 | */ |
| 123 | 123 | private Map<Host, Token> getTokenForHosts(Metadata metadata) { |
| 124 | 124 | Map<Host, Token> tokensByHost = Maps.newHashMap(); |
| 125 | - for(Host host : metadata.getAllHosts()) { | |
| 125 | + for (Host host : metadata.getAllHosts()) { | |
| 126 | 126 | tokensByHost.put(host, host.getTokens().iterator().next()); |
| 127 | 127 | } |
| 128 | 128 | return tokensByHost; |
modified driver-core/src/test/java/com/datastax/driver/core/MetricsTest.java +6 −7
| @@ -15,16 +15,15 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.util.Collection; | |
| 19 | - | |
| 18 | +import com.datastax.driver.core.Metrics.Errors; | |
| 19 | +import com.datastax.driver.core.policies.RetryPolicy; | |
| 20 | +import com.datastax.driver.core.policies.RetryPolicy.RetryDecision; | |
| 20 | 21 | import com.google.common.collect.Lists; |
| 21 | 22 | import org.testng.annotations.Test; |
| 22 | 23 | |
| 23 | -import static org.testng.Assert.assertEquals; | |
| 24 | +import java.util.Collection; | |
| 24 | 25 | |
| 25 | -import com.datastax.driver.core.Metrics.Errors; | |
| 26 | -import com.datastax.driver.core.policies.RetryPolicy; | |
| 27 | -import com.datastax.driver.core.policies.RetryPolicy.RetryDecision; | |
| 26 | +import static org.testng.Assert.assertEquals; | |
| 28 | 27 | |
| 29 | 28 | public class MetricsTest extends CCMBridge.PerClassSingleNodeCluster { |
| 30 | 29 | private volatile RetryDecision retryDecision; |
| @@ -52,7 +51,7 @@ | ||
| 52 | 51 | @Override |
| 53 | 52 | protected Collection<String> getTableDefinitions() { |
| 54 | 53 | return Lists.newArrayList("CREATE TABLE test (k int primary key, v int)", |
| 55 | - "INSERT INTO test (k, v) VALUES (1, 1)"); | |
| 54 | + "INSERT INTO test (k, v) VALUES (1, 1)"); | |
| 56 | 55 | } |
| 57 | 56 | |
| 58 | 57 | @Test(groups = "short") |
modified driver-core/src/test/java/com/datastax/driver/core/MissingRpcAddressTest.java +13 −14
| @@ -15,21 +15,20 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.net.InetAddress; | |
| 19 | -import java.net.InetSocketAddress; | |
| 20 | - | |
| 18 | +import com.datastax.driver.core.policies.Policies; | |
| 19 | +import com.datastax.driver.core.policies.WhiteListPolicy; | |
| 21 | 20 | import com.google.common.collect.Lists; |
| 22 | 21 | import org.testng.annotations.Test; |
| 23 | 22 | |
| 23 | +import java.net.InetAddress; | |
| 24 | +import java.net.InetSocketAddress; | |
| 25 | + | |
| 24 | 26 | import static org.testng.Assert.assertEquals; |
| 25 | 27 | import static org.testng.Assert.assertNull; |
| 26 | 28 | |
| 27 | -import com.datastax.driver.core.policies.Policies; | |
| 28 | -import com.datastax.driver.core.policies.WhiteListPolicy; | |
| 29 | - | |
| 30 | 29 | /** |
| 31 | 30 | * Tests the behavior of the driver when some hosts have no rpc_address in the control host's system tables (JAVA-428). |
| 32 | - * | |
| 31 | + * <p/> | |
| 33 | 32 | * This can happen because of gossip bugs. We want to ignore these hosts because this is most likely indicative of an error state. |
| 34 | 33 | */ |
| 35 | 34 | public class MissingRpcAddressTest { |
| @@ -43,8 +42,8 @@ | ||
| 43 | 42 | deleteNode2RpcAddressFromNode1(); |
| 44 | 43 | // Use only one contact point to make sure that the control connection is on node1 |
| 45 | 44 | cluster = Cluster.builder() |
| 46 | - .addContactPoint(CCMBridge.IP_PREFIX + "1") | |
| 47 | - .build(); | |
| 45 | + .addContactPoint(CCMBridge.IP_PREFIX + "1") | |
| 46 | + .build(); | |
| 48 | 47 | cluster.connect(); |
| 49 | 48 | |
| 50 | 49 | // Since node2's RPC address is unknown on our control host, it should have been ignored |
| @@ -62,11 +61,11 @@ | ||
| 62 | 61 | Cluster cluster = null; |
| 63 | 62 | try { |
| 64 | 63 | cluster = Cluster.builder() |
| 65 | - .addContactPoint(CCMBridge.IP_PREFIX + "1") | |
| 66 | - // ensure we will only connect to node1 | |
| 67 | - .withLoadBalancingPolicy(new WhiteListPolicy(Policies.defaultLoadBalancingPolicy(), | |
| 68 | - Lists.newArrayList(socketAddress(1)))) | |
| 69 | - .build(); | |
| 64 | + .addContactPoint(CCMBridge.IP_PREFIX + "1") | |
| 65 | + // ensure we will only connect to node1 | |
| 66 | + .withLoadBalancingPolicy(new WhiteListPolicy(Policies.defaultLoadBalancingPolicy(), | |
| 67 | + Lists.newArrayList(socketAddress(1)))) | |
| 68 | + .build(); | |
| 70 | 69 | Session session = cluster.connect(); |
| 71 | 70 | String deleteStmt = String.format("DELETE rpc_address FROM system.peers WHERE peer = '%s'", |
| 72 | 71 | InetAddress.getByName(CCMBridge.IP_PREFIX + "2").getHostName()); |
modified driver-core/src/test/java/com/datastax/driver/core/NettyOptionsTest.java +10 −13
| @@ -15,8 +15,6 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.util.concurrent.ThreadFactory; | |
| 19 | - | |
| 20 | 18 | import io.netty.bootstrap.Bootstrap; |
| 21 | 19 | import io.netty.channel.ChannelHandler; |
| 22 | 20 | import io.netty.channel.ChannelHandlerContext; |
| @@ -25,24 +23,23 @@ | ||
| 25 | 23 | import io.netty.channel.socket.SocketChannel; |
| 26 | 24 | import io.netty.util.HashedWheelTimer; |
| 27 | 25 | import io.netty.util.Timer; |
| 28 | -import org.mockito.ArgumentCaptor; | |
| 29 | 26 | import org.mockito.invocation.InvocationOnMock; |
| 30 | 27 | import org.mockito.stubbing.Answer; |
| 31 | 28 | import org.testng.annotations.DataProvider; |
| 32 | 29 | import org.testng.annotations.Test; |
| 33 | 30 | |
| 31 | +import java.util.concurrent.ThreadFactory; | |
| 32 | + | |
| 33 | +import static com.datastax.driver.core.CCMBridge.ipOfNode; | |
| 34 | 34 | import static org.mockito.Answers.CALLS_REAL_METHODS; |
| 35 | 35 | import static org.mockito.Matchers.any; |
| 36 | 36 | import static org.mockito.Mockito.*; |
| 37 | 37 | |
| 38 | -import static com.datastax.driver.core.Assertions.assertThat; | |
| 39 | -import static com.datastax.driver.core.CCMBridge.ipOfNode; | |
| 40 | - | |
| 41 | 38 | public class NettyOptionsTest { |
| 42 | 39 | |
| 43 | 40 | @DataProvider(name = "NettyOptionsTest") |
| 44 | 41 | public static Object[][] parameters() { |
| 45 | - Object[][] params = new Object[][] { {1,1}, {3,4} }; | |
| 42 | + Object[][] params = new Object[][]{{1, 1}, {3, 4}}; | |
| 46 | 43 | return params; |
| 47 | 44 | } |
| 48 | 45 | |
| @@ -68,12 +65,12 @@ | ||
| 68 | 65 | } |
| 69 | 66 | }).when(nettyOptions).afterChannelInitialized(any(SocketChannel.class)); |
| 70 | 67 | cluster = Cluster.builder() |
| 71 | - .addContactPoint(ipOfNode(1)) | |
| 72 | - .withPoolingOptions(new PoolingOptions() | |
| 73 | - .setCoreConnectionsPerHost(HostDistance.LOCAL, coreConnections) | |
| 74 | - ) | |
| 75 | - .withNettyOptions(nettyOptions) | |
| 76 | - .build(); | |
| 68 | + .addContactPoint(ipOfNode(1)) | |
| 69 | + .withPoolingOptions(new PoolingOptions() | |
| 70 | + .setCoreConnectionsPerHost(HostDistance.LOCAL, coreConnections) | |
| 71 | + ) | |
| 72 | + .withNettyOptions(nettyOptions) | |
| 73 | + .build(); | |
| 77 | 74 | // when |
| 78 | 75 | cluster.connect();// force session creation to populate pools |
| 79 | 76 | cluster.close(); |
modified driver-core/src/test/java/com/datastax/driver/core/NetworkTopologyStrategyTest.java +263 −262
| @@ -15,11 +15,6 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.net.InetSocketAddress; | |
| 19 | -import java.util.List; | |
| 20 | -import java.util.Map; | |
| 21 | -import java.util.Set; | |
| 22 | - | |
| 23 | 18 | import com.google.common.collect.ImmutableList; |
| 24 | 19 | import com.google.common.collect.ImmutableMap; |
| 25 | 20 | import com.google.common.collect.ImmutableMap.Builder; |
| @@ -29,6 +24,11 @@ | ||
| 29 | 24 | import org.apache.log4j.Logger; |
| 30 | 25 | import org.testng.annotations.Test; |
| 31 | 26 | |
| 27 | +import java.net.InetSocketAddress; | |
| 28 | +import java.util.List; | |
| 29 | +import java.util.Map; | |
| 30 | +import java.util.Set; | |
| 31 | + | |
| 32 | 32 | import static org.assertj.core.api.Assertions.assertThat; |
| 33 | 33 | |
| 34 | 34 | public class NetworkTopologyStrategyTest extends AbstractReplicationStrategyTest { |
| @@ -49,7 +49,7 @@ | ||
| 49 | 49 | |
| 50 | 50 | private static ReplicationStrategy networkTopologyStrategy(ReplicationFactorDefinition... rfs) { |
| 51 | 51 | Builder<String, String> builder = ImmutableMap.<String, String>builder() |
| 52 | - .put("class", "NetworkTopologyStrategy"); | |
| 52 | + .put("class", "NetworkTopologyStrategy"); | |
| 53 | 53 | |
| 54 | 54 | for (ReplicationFactorDefinition rf : rfs) |
| 55 | 55 | builder.put(rf.dc, String.valueOf(rf.replicationFactor)); |
| @@ -109,6 +109,7 @@ | ||
| 109 | 109 | |
| 110 | 110 | private static final List<Token> largeRing = Lists.newArrayList(); |
| 111 | 111 | private static final Map<Token, Host> largeRingTokenToPrimary = Maps.newHashMap(); |
| 112 | + | |
| 112 | 113 | static { |
| 113 | 114 | for (int i = 0; i < 100; i++) { |
| 114 | 115 | InetSocketAddress address = socketAddress("127.0.0." + i); |
| @@ -121,46 +122,46 @@ | ||
| 121 | 122 | } |
| 122 | 123 | |
| 123 | 124 | private static final List<Token> exampleRing = ImmutableList.<Token>builder() |
| 124 | - .add(TOKEN01) | |
| 125 | - .add(TOKEN02) | |
| 126 | - .add(TOKEN03) | |
| 127 | - .add(TOKEN04) | |
| 128 | - .add(TOKEN05) | |
| 129 | - .add(TOKEN06) | |
| 130 | - .add(TOKEN07) | |
| 131 | - .add(TOKEN08) | |
| 132 | - .add(TOKEN09) | |
| 133 | - .add(TOKEN10) | |
| 134 | - .add(TOKEN11) | |
| 135 | - .add(TOKEN12) | |
| 136 | - .add(TOKEN13) | |
| 137 | - .add(TOKEN14) | |
| 138 | - .add(TOKEN15) | |
| 139 | - .add(TOKEN16) | |
| 140 | - .add(TOKEN17) | |
| 141 | - .add(TOKEN18) | |
| 142 | - .build(); | |
| 125 | + .add(TOKEN01) | |
| 126 | + .add(TOKEN02) | |
| 127 | + .add(TOKEN03) | |
| 128 | + .add(TOKEN04) | |
| 129 | + .add(TOKEN05) | |
| 130 | + .add(TOKEN06) | |
| 131 | + .add(TOKEN07) | |
| 132 | + .add(TOKEN08) | |
| 133 | + .add(TOKEN09) | |
| 134 | + .add(TOKEN10) | |
| 135 | + .add(TOKEN11) | |
| 136 | + .add(TOKEN12) | |
| 137 | + .add(TOKEN13) | |
| 138 | + .add(TOKEN14) | |
| 139 | + .add(TOKEN15) | |
| 140 | + .add(TOKEN16) | |
| 141 | + .add(TOKEN17) | |
| 142 | + .add(TOKEN18) | |
| 143 | + .build(); | |
| 143 | 144 | |
| 144 | 145 | private static final Map<Token, Host> exampleTokenToPrimary = ImmutableMap.<Token, Host>builder() |
| 145 | - .put(TOKEN01, host(IP1, DC1, RACK11)) | |
| 146 | - .put(TOKEN02, host(IP1, DC1, RACK11)) | |
| 147 | - .put(TOKEN03, host(IP5, DC1, RACK12)) | |
| 148 | - .put(TOKEN04, host(IP3, DC1, RACK11)) | |
| 149 | - .put(TOKEN05, host(IP1, DC1, RACK11)) | |
| 150 | - .put(TOKEN06, host(IP5, DC1, RACK12)) | |
| 151 | - .put(TOKEN07, host(IP2, DC2, RACK21)) | |
| 152 | - .put(TOKEN08, host(IP6, DC2, RACK22)) | |
| 153 | - .put(TOKEN09, host(IP3, DC1, RACK11)) | |
| 154 | - .put(TOKEN10, host(IP4, DC2, RACK21)) | |
| 155 | - .put(TOKEN11, host(IP5, DC1, RACK12)) | |
| 156 | - .put(TOKEN12, host(IP4, DC2, RACK21)) | |
| 157 | - .put(TOKEN13, host(IP4, DC2, RACK21)) | |
| 158 | - .put(TOKEN14, host(IP2, DC2, RACK21)) | |
| 159 | - .put(TOKEN15, host(IP6, DC2, RACK22)) | |
| 160 | - .put(TOKEN16, host(IP3, DC1, RACK11)) | |
| 161 | - .put(TOKEN17, host(IP2, DC2, RACK21)) | |
| 162 | - .put(TOKEN18, host(IP6, DC2, RACK22)) | |
| 163 | - .build(); | |
| 146 | + .put(TOKEN01, host(IP1, DC1, RACK11)) | |
| 147 | + .put(TOKEN02, host(IP1, DC1, RACK11)) | |
| 148 | + .put(TOKEN03, host(IP5, DC1, RACK12)) | |
| 149 | + .put(TOKEN04, host(IP3, DC1, RACK11)) | |
| 150 | + .put(TOKEN05, host(IP1, DC1, RACK11)) | |
| 151 | + .put(TOKEN06, host(IP5, DC1, RACK12)) | |
| 152 | + .put(TOKEN07, host(IP2, DC2, RACK21)) | |
| 153 | + .put(TOKEN08, host(IP6, DC2, RACK22)) | |
| 154 | + .put(TOKEN09, host(IP3, DC1, RACK11)) | |
| 155 | + .put(TOKEN10, host(IP4, DC2, RACK21)) | |
| 156 | + .put(TOKEN11, host(IP5, DC1, RACK12)) | |
| 157 | + .put(TOKEN12, host(IP4, DC2, RACK21)) | |
| 158 | + .put(TOKEN13, host(IP4, DC2, RACK21)) | |
| 159 | + .put(TOKEN14, host(IP2, DC2, RACK21)) | |
| 160 | + .put(TOKEN15, host(IP6, DC2, RACK22)) | |
| 161 | + .put(TOKEN16, host(IP3, DC1, RACK11)) | |
| 162 | + .put(TOKEN17, host(IP2, DC2, RACK21)) | |
| 163 | + .put(TOKEN18, host(IP6, DC2, RACK22)) | |
| 164 | + .build(); | |
| 164 | 165 | |
| 165 | 166 | /* |
| 166 | 167 | * -------------- |
| @@ -171,18 +172,18 @@ | ||
| 171 | 172 | @Test(groups = "unit") |
| 172 | 173 | public void networkTopologyWithSimpleDCLayoutTest1() { |
| 173 | 174 | List<Token> ring = ImmutableList.<Token>builder() |
| 174 | - .add(TOKEN01) | |
| 175 | - .add(TOKEN04) | |
| 176 | - .add(TOKEN14) | |
| 177 | - .add(TOKEN19) | |
| 178 | - .build(); | |
| 175 | + .add(TOKEN01) | |
| 176 | + .add(TOKEN04) | |
| 177 | + .add(TOKEN14) | |
| 178 | + .add(TOKEN19) | |
| 179 | + .build(); | |
| 179 | 180 | |
| 180 | 181 | Map<Token, Host> tokenToPrimary = ImmutableMap.<Token, Host>builder() |
| 181 | - .put(TOKEN01, host(IP1, DC1, RACK11)) | |
| 182 | - .put(TOKEN04, host(IP2, DC2, RACK21)) | |
| 183 | - .put(TOKEN14, host(IP1, DC1, RACK11)) | |
| 184 | - .put(TOKEN19, host(IP2, DC2, RACK21)) | |
| 185 | - .build(); | |
| 182 | + .put(TOKEN01, host(IP1, DC1, RACK11)) | |
| 183 | + .put(TOKEN04, host(IP2, DC2, RACK21)) | |
| 184 | + .put(TOKEN14, host(IP1, DC1, RACK11)) | |
| 185 | + .put(TOKEN19, host(IP2, DC2, RACK21)) | |
| 186 | + .build(); | |
| 186 | 187 | |
| 187 | 188 | ReplicationStrategy strategy = networkTopologyStrategy(rf(DC1, 1), rf(DC2, 1)); |
| 188 | 189 | |
| @@ -197,26 +198,26 @@ | ||
| 197 | 198 | @Test(groups = "unit") |
| 198 | 199 | public void networkTopologyWithSimpleDCLayoutTest2() { |
| 199 | 200 | List<Token> ring = ImmutableList.<Token>builder() |
| 200 | - .add(TOKEN01) | |
| 201 | - .add(TOKEN03) | |
| 202 | - .add(TOKEN05) | |
| 203 | - .add(TOKEN07) | |
| 204 | - .add(TOKEN13) | |
| 205 | - .add(TOKEN15) | |
| 206 | - .add(TOKEN17) | |
| 207 | - .add(TOKEN19) | |
| 208 | - .build(); | |
| 201 | + .add(TOKEN01) | |
| 202 | + .add(TOKEN03) | |
| 203 | + .add(TOKEN05) | |
| 204 | + .add(TOKEN07) | |
| 205 | + .add(TOKEN13) | |
| 206 | + .add(TOKEN15) | |
| 207 | + .add(TOKEN17) | |
| 208 | + .add(TOKEN19) | |
| 209 | + .build(); | |
| 209 | 210 | |
| 210 | 211 | Map<Token, Host> tokenToPrimary = ImmutableMap.<Token, Host>builder() |
| 211 | - .put(TOKEN01, host(IP1, DC1, RACK11)) | |
| 212 | - .put(TOKEN03, host(IP2, DC2, RACK21)) | |
| 213 | - .put(TOKEN05, host(IP3, DC1, RACK11)) | |
| 214 | - .put(TOKEN07, host(IP4, DC2, RACK21)) | |
| 215 | - .put(TOKEN13, host(IP1, DC1, RACK11)) | |
| 216 | - .put(TOKEN15, host(IP2, DC2, RACK21)) | |
| 217 | - .put(TOKEN17, host(IP3, DC1, RACK11)) | |
| 218 | - .put(TOKEN19, host(IP4, DC2, RACK21)) | |
| 219 | - .build(); | |
| 212 | + .put(TOKEN01, host(IP1, DC1, RACK11)) | |
| 213 | + .put(TOKEN03, host(IP2, DC2, RACK21)) | |
| 214 | + .put(TOKEN05, host(IP3, DC1, RACK11)) | |
| 215 | + .put(TOKEN07, host(IP4, DC2, RACK21)) | |
| 216 | + .put(TOKEN13, host(IP1, DC1, RACK11)) | |
| 217 | + .put(TOKEN15, host(IP2, DC2, RACK21)) | |
| 218 | + .put(TOKEN17, host(IP3, DC1, RACK11)) | |
| 219 | + .put(TOKEN19, host(IP4, DC2, RACK21)) | |
| 220 | + .build(); | |
| 220 | 221 | |
| 221 | 222 | ReplicationStrategy strategy = networkTopologyStrategy(rf(DC1, 1), rf(DC2, 1)); |
| 222 | 223 | |
| @@ -235,22 +236,22 @@ | ||
| 235 | 236 | @Test(groups = "unit") |
| 236 | 237 | public void networkTopologyWithSimple3DCLayoutTest() { |
| 237 | 238 | List<Token> ring = ImmutableList.<Token>builder() |
| 238 | - .add(TOKEN01) | |
| 239 | - .add(TOKEN05) | |
| 240 | - .add(TOKEN09) | |
| 241 | - .add(TOKEN11) | |
| 242 | - .add(TOKEN15) | |
| 243 | - .add(TOKEN19) | |
| 244 | - .build(); | |
| 239 | + .add(TOKEN01) | |
| 240 | + .add(TOKEN05) | |
| 241 | + .add(TOKEN09) | |
| 242 | + .add(TOKEN11) | |
| 243 | + .add(TOKEN15) | |
| 244 | + .add(TOKEN19) | |
| 245 | + .build(); | |
| 245 | 246 | |
| 246 | 247 | Map<Token, Host> tokenToPrimary = ImmutableMap.<Token, Host>builder() |
| 247 | - .put(TOKEN01, host(IP1, DC1, RACK11)) | |
| 248 | - .put(TOKEN05, host(IP2, DC2, RACK21)) | |
| 249 | - .put(TOKEN09, host(IP3, DC3, RACK31)) | |
| 250 | - .put(TOKEN11, host(IP1, DC1, RACK11)) | |
| 251 | - .put(TOKEN15, host(IP2, DC2, RACK21)) | |
| 252 | - .put(TOKEN19, host(IP3, DC3, RACK31)) | |
| 253 | - .build(); | |
| 248 | + .put(TOKEN01, host(IP1, DC1, RACK11)) | |
| 249 | + .put(TOKEN05, host(IP2, DC2, RACK21)) | |
| 250 | + .put(TOKEN09, host(IP3, DC3, RACK31)) | |
| 251 | + .put(TOKEN11, host(IP1, DC1, RACK11)) | |
| 252 | + .put(TOKEN15, host(IP2, DC2, RACK21)) | |
| 253 | + .put(TOKEN19, host(IP3, DC3, RACK31)) | |
| 254 | + .build(); | |
| 254 | 255 | |
| 255 | 256 | ReplicationStrategy strategy = networkTopologyStrategy(rf(DC1, 1), rf(DC2, 1), rf(DC3, 1)); |
| 256 | 257 | |
| @@ -267,30 +268,30 @@ | ||
| 267 | 268 | @Test(groups = "unit") |
| 268 | 269 | public void networkTopologyWithUnbalancedRingTest() { |
| 269 | 270 | List<Token> ring = ImmutableList.<Token>builder() |
| 270 | - .add(TOKEN01) | |
| 271 | - .add(TOKEN03) | |
| 272 | - .add(TOKEN05) | |
| 273 | - .add(TOKEN07) | |
| 274 | - .add(TOKEN09) | |
| 275 | - .add(TOKEN11) | |
| 276 | - .add(TOKEN13) | |
| 277 | - .add(TOKEN15) | |
| 278 | - .add(TOKEN17) | |
| 279 | - .add(TOKEN19) | |
| 280 | - .build(); | |
| 271 | + .add(TOKEN01) | |
| 272 | + .add(TOKEN03) | |
| 273 | + .add(TOKEN05) | |
| 274 | + .add(TOKEN07) | |
| 275 | + .add(TOKEN09) | |
| 276 | + .add(TOKEN11) | |
| 277 | + .add(TOKEN13) | |
| 278 | + .add(TOKEN15) | |
| 279 | + .add(TOKEN17) | |
| 280 | + .add(TOKEN19) | |
| 281 | + .build(); | |
| 281 | 282 | |
| 282 | 283 | Map<Token, Host> tokenToPrimary = ImmutableMap.<Token, Host>builder() |
| 283 | - .put(TOKEN01, host(IP1, DC1, RACK11)) | |
| 284 | - .put(TOKEN03, host(IP1, DC1, RACK11)) | |
| 285 | - .put(TOKEN05, host(IP2, DC2, RACK21)) | |
| 286 | - .put(TOKEN07, host(IP3, DC1, RACK11)) | |
| 287 | - .put(TOKEN09, host(IP4, DC2, RACK21)) | |
| 288 | - .put(TOKEN11, host(IP1, DC1, RACK11)) | |
| 289 | - .put(TOKEN13, host(IP1, DC1, RACK11)) | |
| 290 | - .put(TOKEN15, host(IP2, DC2, RACK21)) | |
| 291 | - .put(TOKEN17, host(IP3, DC1, RACK11)) | |
| 292 | - .put(TOKEN19, host(IP4, DC2, RACK21)) | |
| 293 | - .build(); | |
| 284 | + .put(TOKEN01, host(IP1, DC1, RACK11)) | |
| 285 | + .put(TOKEN03, host(IP1, DC1, RACK11)) | |
| 286 | + .put(TOKEN05, host(IP2, DC2, RACK21)) | |
| 287 | + .put(TOKEN07, host(IP3, DC1, RACK11)) | |
| 288 | + .put(TOKEN09, host(IP4, DC2, RACK21)) | |
| 289 | + .put(TOKEN11, host(IP1, DC1, RACK11)) | |
| 290 | + .put(TOKEN13, host(IP1, DC1, RACK11)) | |
| 291 | + .put(TOKEN15, host(IP2, DC2, RACK21)) | |
| 292 | + .put(TOKEN17, host(IP3, DC1, RACK11)) | |
| 293 | + .put(TOKEN19, host(IP4, DC2, RACK21)) | |
| 294 | + .build(); | |
| 294 | 295 | |
| 295 | 296 | ReplicationStrategy strategy = networkTopologyStrategy(rf(DC1, 2), rf(DC2, 2)); |
| 296 | 297 | |
| @@ -311,42 +312,42 @@ | ||
| 311 | 312 | @Test(groups = "unit") |
| 312 | 313 | public void networkTopologyWithDCMultirackLayoutTest() { |
| 313 | 314 | List<Token> ring = ImmutableList.<Token>builder() |
| 314 | - .add(TOKEN01) | |
| 315 | - .add(TOKEN02) | |
| 316 | - .add(TOKEN03) | |
| 317 | - .add(TOKEN04) | |
| 318 | - .add(TOKEN05) | |
| 319 | - .add(TOKEN06) | |
| 320 | - .add(TOKEN07) | |
| 321 | - .add(TOKEN08) | |
| 322 | - .add(TOKEN12) | |
| 323 | - .add(TOKEN13) | |
| 324 | - .add(TOKEN14) | |
| 325 | - .add(TOKEN15) | |
| 326 | - .add(TOKEN16) | |
| 327 | - .add(TOKEN17) | |
| 328 | - .add(TOKEN18) | |
| 329 | - .add(TOKEN19) | |
| 330 | - .build(); | |
| 315 | + .add(TOKEN01) | |
| 316 | + .add(TOKEN02) | |
| 317 | + .add(TOKEN03) | |
| 318 | + .add(TOKEN04) | |
| 319 | + .add(TOKEN05) | |
| 320 | + .add(TOKEN06) | |
| 321 | + .add(TOKEN07) | |
| 322 | + .add(TOKEN08) | |
| 323 | + .add(TOKEN12) | |
| 324 | + .add(TOKEN13) | |
| 325 | + .add(TOKEN14) | |
| 326 | + .add(TOKEN15) | |
| 327 | + .add(TOKEN16) | |
| 328 | + .add(TOKEN17) | |
| 329 | + .add(TOKEN18) | |
| 330 | + .add(TOKEN19) | |
| 331 | + .build(); | |
| 331 | 332 | |
| 332 | 333 | Map<Token, Host> tokenToPrimary = ImmutableMap.<Token, Host>builder() |
| 333 | - .put(TOKEN01, host(IP1, DC1, RACK11)) | |
| 334 | - .put(TOKEN02, host(IP2, DC2, RACK21)) | |
| 335 | - .put(TOKEN03, host(IP3, DC1, RACK12)) | |
| 336 | - .put(TOKEN04, host(IP4, DC2, RACK22)) | |
| 337 | - .put(TOKEN05, host(IP5, DC1, RACK11)) | |
| 338 | - .put(TOKEN06, host(IP6, DC2, RACK21)) | |
| 339 | - .put(TOKEN07, host(IP7, DC1, RACK12)) | |
| 340 | - .put(TOKEN08, host(IP8, DC2, RACK22)) | |
| 341 | - .put(TOKEN12, host(IP1, DC1, RACK11)) | |
| 342 | - .put(TOKEN13, host(IP2, DC2, RACK21)) | |
| 343 | - .put(TOKEN14, host(IP3, DC1, RACK12)) | |
| 344 | - .put(TOKEN15, host(IP4, DC2, RACK22)) | |
| 345 | - .put(TOKEN16, host(IP5, DC1, RACK11)) | |
| 346 | - .put(TOKEN17, host(IP6, DC2, RACK21)) | |
| 347 | - .put(TOKEN18, host(IP7, DC1, RACK12)) | |
| 348 | - .put(TOKEN19, host(IP8, DC2, RACK22)) | |
| 349 | - .build(); | |
| 334 | + .put(TOKEN01, host(IP1, DC1, RACK11)) | |
| 335 | + .put(TOKEN02, host(IP2, DC2, RACK21)) | |
| 336 | + .put(TOKEN03, host(IP3, DC1, RACK12)) | |
| 337 | + .put(TOKEN04, host(IP4, DC2, RACK22)) | |
| 338 | + .put(TOKEN05, host(IP5, DC1, RACK11)) | |
| 339 | + .put(TOKEN06, host(IP6, DC2, RACK21)) | |
| 340 | + .put(TOKEN07, host(IP7, DC1, RACK12)) | |
| 341 | + .put(TOKEN08, host(IP8, DC2, RACK22)) | |
| 342 | + .put(TOKEN12, host(IP1, DC1, RACK11)) | |
| 343 | + .put(TOKEN13, host(IP2, DC2, RACK21)) | |
| 344 | + .put(TOKEN14, host(IP3, DC1, RACK12)) | |
| 345 | + .put(TOKEN15, host(IP4, DC2, RACK22)) | |
| 346 | + .put(TOKEN16, host(IP5, DC1, RACK11)) | |
| 347 | + .put(TOKEN17, host(IP6, DC2, RACK21)) | |
| 348 | + .put(TOKEN18, host(IP7, DC1, RACK12)) | |
| 349 | + .put(TOKEN19, host(IP8, DC2, RACK22)) | |
| 350 | + .build(); | |
| 350 | 351 | |
| 351 | 352 | ReplicationStrategy strategy = networkTopologyStrategy(rf(DC1, 2), rf(DC2, 2)); |
| 352 | 353 | |
| @@ -373,44 +374,44 @@ | ||
| 373 | 374 | @Test(groups = "unit") |
| 374 | 375 | public void networkTopologyWithMultirackHostSkippingTest1() { |
| 375 | 376 | List<Token> ring = ImmutableList.<Token>builder() |
| 376 | - .add(TOKEN01) | |
| 377 | - .add(TOKEN02) | |
| 378 | - .add(TOKEN03) | |
| 379 | - .add(TOKEN04) | |
| 380 | - .add(TOKEN05) | |
| 381 | - .add(TOKEN06) | |
| 382 | - .add(TOKEN07) | |
| 383 | - .add(TOKEN08) | |
| 384 | - .add(TOKEN12) | |
| 385 | - .add(TOKEN13) | |
| 386 | - .add(TOKEN14) | |
| 387 | - .add(TOKEN15) | |
| 388 | - .add(TOKEN16) | |
| 389 | - .add(TOKEN17) | |
| 390 | - .add(TOKEN18) | |
| 391 | - .add(TOKEN19) | |
| 392 | - .build(); | |
| 377 | + .add(TOKEN01) | |
| 378 | + .add(TOKEN02) | |
| 379 | + .add(TOKEN03) | |
| 380 | + .add(TOKEN04) | |
| 381 | + .add(TOKEN05) | |
| 382 | + .add(TOKEN06) | |
| 383 | + .add(TOKEN07) | |
| 384 | + .add(TOKEN08) | |
| 385 | + .add(TOKEN12) | |
| 386 | + .add(TOKEN13) | |
| 387 | + .add(TOKEN14) | |
| 388 | + .add(TOKEN15) | |
| 389 | + .add(TOKEN16) | |
| 390 | + .add(TOKEN17) | |
| 391 | + .add(TOKEN18) | |
| 392 | + .add(TOKEN19) | |
| 393 | + .build(); | |
| 393 | 394 | |
| 394 | 395 | //this is to simulate when we hit the same rack in a DC first as a second replica |
| 395 | 396 | //so that'll get skipped and re-added later as a third |
| 396 | 397 | Map<Token, Host> tokenToPrimary = ImmutableMap.<Token, Host>builder() |
| 397 | - .put(TOKEN01, host(IP1, DC1, RACK11)) | |
| 398 | - .put(TOKEN02, host(IP2, DC2, RACK21)) | |
| 399 | - .put(TOKEN03, host(IP3, DC1, RACK11)) | |
| 400 | - .put(TOKEN04, host(IP4, DC2, RACK21)) | |
| 401 | - .put(TOKEN05, host(IP5, DC1, RACK12)) | |
| 402 | - .put(TOKEN06, host(IP6, DC2, RACK22)) | |
| 403 | - .put(TOKEN07, host(IP7, DC1, RACK12)) | |
| 404 | - .put(TOKEN08, host(IP8, DC2, RACK22)) | |
| 405 | - .put(TOKEN12, host(IP1, DC1, RACK11)) | |
| 406 | - .put(TOKEN13, host(IP2, DC2, RACK21)) | |
| 407 | - .put(TOKEN14, host(IP3, DC1, RACK11)) | |
| 408 | - .put(TOKEN15, host(IP4, DC2, RACK21)) | |
| 409 | - .put(TOKEN16, host(IP5, DC1, RACK12)) | |
| 410 | - .put(TOKEN17, host(IP6, DC2, RACK22)) | |
| 411 | - .put(TOKEN18, host(IP7, DC1, RACK12)) | |
| 412 | - .put(TOKEN19, host(IP8, DC2, RACK22)) | |
| 413 | - .build(); | |
| 398 | + .put(TOKEN01, host(IP1, DC1, RACK11)) | |
| 399 | + .put(TOKEN02, host(IP2, DC2, RACK21)) | |
| 400 | + .put(TOKEN03, host(IP3, DC1, RACK11)) | |
| 401 | + .put(TOKEN04, host(IP4, DC2, RACK21)) | |
| 402 | + .put(TOKEN05, host(IP5, DC1, RACK12)) | |
| 403 | + .put(TOKEN06, host(IP6, DC2, RACK22)) | |
| 404 | + .put(TOKEN07, host(IP7, DC1, RACK12)) | |
| 405 | + .put(TOKEN08, host(IP8, DC2, RACK22)) | |
| 406 | + .put(TOKEN12, host(IP1, DC1, RACK11)) | |
| 407 | + .put(TOKEN13, host(IP2, DC2, RACK21)) | |
| 408 | + .put(TOKEN14, host(IP3, DC1, RACK11)) | |
| 409 | + .put(TOKEN15, host(IP4, DC2, RACK21)) | |
| 410 | + .put(TOKEN16, host(IP5, DC1, RACK12)) | |
| 411 | + .put(TOKEN17, host(IP6, DC2, RACK22)) | |
| 412 | + .put(TOKEN18, host(IP7, DC1, RACK12)) | |
| 413 | + .put(TOKEN19, host(IP8, DC2, RACK22)) | |
| 414 | + .build(); | |
| 414 | 415 | |
| 415 | 416 | ReplicationStrategy strategy = networkTopologyStrategy(rf(DC1, 3), rf(DC2, 3)); |
| 416 | 417 | |
| @@ -438,42 +439,42 @@ | ||
| 438 | 439 | @Test(groups = "unit") |
| 439 | 440 | public void networkTopologyWithMultirackHostSkippingTest2() { |
| 440 | 441 | List<Token> ring = ImmutableList.<Token>builder() |
| 441 | - .add(TOKEN01) | |
| 442 | - .add(TOKEN02) | |
| 443 | - .add(TOKEN03) | |
| 444 | - .add(TOKEN04) | |
| 445 | - .add(TOKEN05) | |
| 446 | - .add(TOKEN06) | |
| 447 | - .add(TOKEN07) | |
| 448 | - .add(TOKEN08) | |
| 449 | - .add(TOKEN12) | |
| 450 | - .add(TOKEN13) | |
| 451 | - .add(TOKEN14) | |
| 452 | - .add(TOKEN15) | |
| 453 | - .add(TOKEN16) | |
| 454 | - .add(TOKEN17) | |
| 455 | - .add(TOKEN18) | |
| 456 | - .add(TOKEN19) | |
| 457 | - .build(); | |
| 442 | + .add(TOKEN01) | |
| 443 | + .add(TOKEN02) | |
| 444 | + .add(TOKEN03) | |
| 445 | + .add(TOKEN04) | |
| 446 | + .add(TOKEN05) | |
| 447 | + .add(TOKEN06) | |
| 448 | + .add(TOKEN07) | |
| 449 | + .add(TOKEN08) | |
| 450 | + .add(TOKEN12) | |
| 451 | + .add(TOKEN13) | |
| 452 | + .add(TOKEN14) | |
| 453 | + .add(TOKEN15) | |
| 454 | + .add(TOKEN16) | |
| 455 | + .add(TOKEN17) | |
| 456 | + .add(TOKEN18) | |
| 457 | + .add(TOKEN19) | |
| 458 | + .build(); | |
| 458 | 459 | |
| 459 | 460 | Map<Token, Host> tokenToPrimary = ImmutableMap.<Token, Host>builder() |
| 460 | - .put(TOKEN01, host(IP1, DC1, RACK11)) | |
| 461 | - .put(TOKEN02, host(IP1, DC1, RACK11)) | |
| 462 | - .put(TOKEN03, host(IP3, DC1, RACK11)) | |
| 463 | - .put(TOKEN04, host(IP3, DC1, RACK11)) | |
| 464 | - .put(TOKEN05, host(IP5, DC1, RACK12)) | |
| 465 | - .put(TOKEN06, host(IP5, DC1, RACK12)) | |
| 466 | - .put(TOKEN07, host(IP7, DC1, RACK12)) | |
| 467 | - .put(TOKEN08, host(IP7, DC1, RACK12)) | |
| 468 | - .put(TOKEN12, host(IP2, DC2, RACK21)) | |
| 469 | - .put(TOKEN13, host(IP2, DC2, RACK21)) | |
| 470 | - .put(TOKEN14, host(IP4, DC2, RACK21)) | |
| 471 | - .put(TOKEN15, host(IP4, DC2, RACK21)) | |
| 472 | - .put(TOKEN16, host(IP6, DC2, RACK22)) | |
| 473 | - .put(TOKEN17, host(IP6, DC2, RACK22)) | |
| 474 | - .put(TOKEN18, host(IP8, DC2, RACK22)) | |
| 475 | - .put(TOKEN19, host(IP8, DC2, RACK22)) | |
| 476 | - .build(); | |
| 461 | + .put(TOKEN01, host(IP1, DC1, RACK11)) | |
| 462 | + .put(TOKEN02, host(IP1, DC1, RACK11)) | |
| 463 | + .put(TOKEN03, host(IP3, DC1, RACK11)) | |
| 464 | + .put(TOKEN04, host(IP3, DC1, RACK11)) | |
| 465 | + .put(TOKEN05, host(IP5, DC1, RACK12)) | |
| 466 | + .put(TOKEN06, host(IP5, DC1, RACK12)) | |
| 467 | + .put(TOKEN07, host(IP7, DC1, RACK12)) | |
| 468 | + .put(TOKEN08, host(IP7, DC1, RACK12)) | |
| 469 | + .put(TOKEN12, host(IP2, DC2, RACK21)) | |
| 470 | + .put(TOKEN13, host(IP2, DC2, RACK21)) | |
| 471 | + .put(TOKEN14, host(IP4, DC2, RACK21)) | |
| 472 | + .put(TOKEN15, host(IP4, DC2, RACK21)) | |
| 473 | + .put(TOKEN16, host(IP6, DC2, RACK22)) | |
| 474 | + .put(TOKEN17, host(IP6, DC2, RACK22)) | |
| 475 | + .put(TOKEN18, host(IP8, DC2, RACK22)) | |
| 476 | + .put(TOKEN19, host(IP8, DC2, RACK22)) | |
| 477 | + .build(); | |
| 477 | 478 | |
| 478 | 479 | ReplicationStrategy strategy = networkTopologyStrategy(rf(DC1, 3), rf(DC2, 3)); |
| 479 | 480 | |
| @@ -501,42 +502,42 @@ | ||
| 501 | 502 | public void networkTopologyWithMultirackHostSkippingTest3() { |
| 502 | 503 | //this is the same topology as in the previous test, but with different rfs |
| 503 | 504 | List<Token> ring = ImmutableList.<Token>builder() |
| 504 | - .add(TOKEN01) | |
| 505 | - .add(TOKEN02) | |
| 506 | - .add(TOKEN03) | |
| 507 | - .add(TOKEN04) | |
| 508 | - .add(TOKEN05) | |
| 509 | - .add(TOKEN06) | |
| 510 | - .add(TOKEN07) | |
| 511 | - .add(TOKEN08) | |
| 512 | - .add(TOKEN12) | |
| 513 | - .add(TOKEN13) | |
| 514 | - .add(TOKEN14) | |
| 515 | - .add(TOKEN15) | |
| 516 | - .add(TOKEN16) | |
| 517 | - .add(TOKEN17) | |
| 518 | - .add(TOKEN18) | |
| 519 | - .add(TOKEN19) | |
| 520 | - .build(); | |
| 505 | + .add(TOKEN01) | |
| 506 | + .add(TOKEN02) | |
| 507 | + .add(TOKEN03) | |
| 508 | + .add(TOKEN04) | |
| 509 | + .add(TOKEN05) | |
| 510 | + .add(TOKEN06) | |
| 511 | + .add(TOKEN07) | |
| 512 | + .add(TOKEN08) | |
| 513 | + .add(TOKEN12) | |
| 514 | + .add(TOKEN13) | |
| 515 | + .add(TOKEN14) | |
| 516 | + .add(TOKEN15) | |
| 517 | + .add(TOKEN16) | |
| 518 | + .add(TOKEN17) | |
| 519 | + .add(TOKEN18) | |
| 520 | + .add(TOKEN19) | |
| 521 | + .build(); | |
| 521 | 522 | |
| 522 | 523 | Map<Token, Host> tokenToPrimary = ImmutableMap.<Token, Host>builder() |
| 523 | - .put(TOKEN01, host(IP1, DC1, RACK11)) | |
| 524 | - .put(TOKEN02, host(IP1, DC1, RACK11)) | |
| 525 | - .put(TOKEN03, host(IP3, DC1, RACK11)) | |
| 526 | - .put(TOKEN04, host(IP3, DC1, RACK11)) | |
| 527 | - .put(TOKEN05, host(IP5, DC1, RACK12)) | |
| 528 | - .put(TOKEN06, host(IP5, DC1, RACK12)) | |
| 529 | - .put(TOKEN07, host(IP7, DC1, RACK12)) | |
| 530 | - .put(TOKEN08, host(IP7, DC1, RACK12)) | |
| 531 | - .put(TOKEN12, host(IP2, DC2, RACK21)) | |
| 532 | - .put(TOKEN13, host(IP2, DC2, RACK21)) | |
| 533 | - .put(TOKEN14, host(IP4, DC2, RACK21)) | |
| 534 | - .put(TOKEN15, host(IP4, DC2, RACK21)) | |
| 535 | - .put(TOKEN16, host(IP6, DC2, RACK22)) | |
| 536 | - .put(TOKEN17, host(IP6, DC2, RACK22)) | |
| 537 | - .put(TOKEN18, host(IP8, DC2, RACK22)) | |
| 538 | - .put(TOKEN19, host(IP8, DC2, RACK22)) | |
| 539 | - .build(); | |
| 524 | + .put(TOKEN01, host(IP1, DC1, RACK11)) | |
| 525 | + .put(TOKEN02, host(IP1, DC1, RACK11)) | |
| 526 | + .put(TOKEN03, host(IP3, DC1, RACK11)) | |
| 527 | + .put(TOKEN04, host(IP3, DC1, RACK11)) | |
| 528 | + .put(TOKEN05, host(IP5, DC1, RACK12)) | |
| 529 | + .put(TOKEN06, host(IP5, DC1, RACK12)) | |
| 530 | + .put(TOKEN07, host(IP7, DC1, RACK12)) | |
| 531 | + .put(TOKEN08, host(IP7, DC1, RACK12)) | |
| 532 | + .put(TOKEN12, host(IP2, DC2, RACK21)) | |
| 533 | + .put(TOKEN13, host(IP2, DC2, RACK21)) | |
| 534 | + .put(TOKEN14, host(IP4, DC2, RACK21)) | |
| 535 | + .put(TOKEN15, host(IP4, DC2, RACK21)) | |
| 536 | + .put(TOKEN16, host(IP6, DC2, RACK22)) | |
| 537 | + .put(TOKEN17, host(IP6, DC2, RACK22)) | |
| 538 | + .put(TOKEN18, host(IP8, DC2, RACK22)) | |
| 539 | + .put(TOKEN19, host(IP8, DC2, RACK22)) | |
| 540 | + .build(); | |
| 540 | 541 | |
| 541 | 542 | //all nodes will contain all data, question is the replica order |
| 542 | 543 | ReplicationStrategy strategy = networkTopologyStrategy(rf(DC1, 4), rf(DC2, 4)); |
| @@ -589,24 +590,24 @@ | ||
| 589 | 590 | @Test(groups = "unit") |
| 590 | 591 | public void networkTopologyStrategyNoNodesInDCTest() { |
| 591 | 592 | long t1 = System.currentTimeMillis(); |
| 592 | - Map<Token, Set<Host>> replicaMap = networkTopologyStrategy(rf(DC1, 2), rf(DC2, 2)) | |
| 593 | + Map<Token, Set<Host>> replicaMap = networkTopologyStrategy(rf(DC1, 2), rf(DC2, 2)) | |
| 593 | 594 | .computeTokenToReplicaMap(largeRingTokenToPrimary, largeRing); |
| 594 | 595 | assertThat(System.currentTimeMillis() - t1).isLessThan(10000); |
| 595 | 596 | |
| 596 | 597 | InetSocketAddress currNode = null; |
| 597 | 598 | InetSocketAddress nextNode; |
| 598 | 599 | for (int node = 0; node < 99; node++) { // 100th wraps so doesn't match this, check after |
| 599 | - if(currNode == null) { | |
| 600 | + if (currNode == null) { | |
| 600 | 601 | currNode = socketAddress("127.0.0." + node); |
| 601 | 602 | } |
| 602 | - nextNode = socketAddress("127.0.0." + (node+1)); | |
| 603 | + nextNode = socketAddress("127.0.0." + (node + 1)); | |
| 603 | 604 | for (int vnodes = 0; vnodes < 256; vnodes++) { |
| 604 | 605 | Token token = token("" + ((node * 256) + vnodes)); |
| 605 | 606 | assertReplicaPlacement(replicaMap, token, currNode, nextNode); |
| 606 | 607 | } |
| 607 | 608 | currNode = nextNode; |
| 608 | 609 | } |
| 609 | - assertReplicaPlacement(replicaMap, token(""+ 99 * 256), currNode, socketAddress("127.0.0.0")); | |
| 610 | + assertReplicaPlacement(replicaMap, token("" + 99 * 256), currNode, socketAddress("127.0.0.0")); | |
| 610 | 611 | } |
| 611 | 612 | |
| 612 | 613 | |
| @@ -642,30 +643,30 @@ | ||
| 642 | 643 | logger.addAppender(logs); |
| 643 | 644 | |
| 644 | 645 | List<Token> ring = ImmutableList.<Token>builder() |
| 645 | - .add(TOKEN01) | |
| 646 | - .add(TOKEN02) | |
| 647 | - .add(TOKEN03) | |
| 648 | - .add(TOKEN04) | |
| 649 | - .build(); | |
| 646 | + .add(TOKEN01) | |
| 647 | + .add(TOKEN02) | |
| 648 | + .add(TOKEN03) | |
| 649 | + .add(TOKEN04) | |
| 650 | + .build(); | |
| 650 | 651 | |
| 651 | 652 | Map<Token, Host> tokenToPrimary = ImmutableMap.<Token, Host>builder() |
| 652 | - .put(TOKEN01, host(IP1, DC1, RACK11)) | |
| 653 | - .put(TOKEN02, host(IP2, DC1, RACK12)) | |
| 654 | - .put(TOKEN03, host(IP3, DC2, RACK21)) | |
| 655 | - .put(TOKEN04, host(IP4, DC2, RACK22)) | |
| 656 | - .build(); | |
| 653 | + .put(TOKEN01, host(IP1, DC1, RACK11)) | |
| 654 | + .put(TOKEN02, host(IP2, DC1, RACK12)) | |
| 655 | + .put(TOKEN03, host(IP3, DC2, RACK21)) | |
| 656 | + .put(TOKEN04, host(IP4, DC2, RACK22)) | |
| 657 | + .build(); | |
| 657 | 658 | |
| 658 | 659 | // Wrong configuration: impossible replication factor for DC2 |
| 659 | 660 | networkTopologyStrategy(rf(DC1, 2), rf(DC2, 3)) |
| 660 | - .computeTokenToReplicaMap(tokenToPrimary, ring); | |
| 661 | + .computeTokenToReplicaMap(tokenToPrimary, ring); | |
| 661 | 662 | assertThat(logs.getNext()) |
| 662 | - .contains("Error while computing token map for datacenter DC2"); | |
| 663 | + .contains("Error while computing token map for datacenter DC2"); | |
| 663 | 664 | |
| 664 | 665 | // Wrong configuration: non-existing datacenter |
| 665 | 666 | networkTopologyStrategy(rf(DC1, 2), rf("does_not_exist", 2)) |
| 666 | - .computeTokenToReplicaMap(tokenToPrimary, ring); | |
| 667 | + .computeTokenToReplicaMap(tokenToPrimary, ring); | |
| 667 | 668 | assertThat(logs.getNext()) |
| 668 | - .contains("Error while computing token map for datacenter does_not_exist"); | |
| 669 | + .contains("Error while computing token map for datacenter does_not_exist"); | |
| 669 | 670 | |
| 670 | 671 | logger.setLevel(null); |
| 671 | 672 | logger.removeAppender(logs); |
modified driver-core/src/test/java/com/datastax/driver/core/NodeListRefreshDebouncerTest.java +12 −14
| @@ -15,18 +15,16 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.util.Collection; | |
| 19 | - | |
| 20 | -import org.testng.annotations.*; | |
| 18 | +import org.testng.annotations.AfterClass; | |
| 19 | +import org.testng.annotations.AfterMethod; | |
| 20 | +import org.testng.annotations.BeforeClass; | |
| 21 | +import org.testng.annotations.Test; | |
| 21 | 22 | |
| 22 | -import static com.google.common.collect.Lists.newArrayList; | |
| 23 | -import static org.mockito.Mockito.reset; | |
| 24 | -import static org.mockito.Mockito.spy; | |
| 25 | -import static org.mockito.Mockito.timeout; | |
| 26 | -import static org.mockito.Mockito.times; | |
| 27 | -import static org.mockito.Mockito.verify; | |
| 23 | +import java.util.Collection; | |
| 28 | 24 | |
| 29 | 25 | import static com.datastax.driver.core.TestUtils.CREATE_KEYSPACE_SIMPLE_FORMAT; |
| 26 | +import static com.google.common.collect.Lists.newArrayList; | |
| 27 | +import static org.mockito.Mockito.*; | |
| 30 | 28 | |
| 31 | 29 | public class NodeListRefreshDebouncerTest extends CCMBridge.PerClassSingleNodeCluster { |
| 32 | 30 | |
| @@ -57,9 +55,9 @@ | ||
| 57 | 55 | queryOptions.setRefreshSchemaIntervalMillis(0); |
| 58 | 56 | // Create a separate cluster that will receive the schema events on its control connection. |
| 59 | 57 | cluster2 = this.configure(Cluster.builder()) |
| 60 | - .addContactPointsWithPorts(newArrayList(hostAddress)) | |
| 61 | - .withQueryOptions(queryOptions) | |
| 62 | - .build(); | |
| 58 | + .addContactPointsWithPorts(newArrayList(hostAddress)) | |
| 59 | + .withQueryOptions(queryOptions) | |
| 60 | + .build(); | |
| 63 | 61 | session2 = cluster2.connect(); |
| 64 | 62 | |
| 65 | 63 | // Create a spy of the Cluster's control connection and replace it with the spy. |
| @@ -77,7 +75,7 @@ | ||
| 77 | 75 | public void teardown() { |
| 78 | 76 | cluster2.close(); |
| 79 | 77 | // drop all keyspaces |
| 80 | - for(String keyspace : keyspaces) { | |
| 78 | + for (String keyspace : keyspaces) { | |
| 81 | 79 | session.execute("DROP KEYSPACE " + keyspace); |
| 82 | 80 | } |
| 83 | 81 | } |
| @@ -112,7 +110,7 @@ | ||
| 112 | 110 | // Create keyspaces 5 times to cause |
| 113 | 111 | // refreshNodeListAndTokenMap to be called. |
| 114 | 112 | String prefix = "srwmprr"; |
| 115 | - for(int i = 0; i < 5; i++) { | |
| 113 | + for (int i = 0; i < 5; i++) { | |
| 116 | 114 | String keyspace = prefix + i; |
| 117 | 115 | session.execute(String.format(CREATE_KEYSPACE_SIMPLE_FORMAT, keyspace, 1)); |
| 118 | 116 | keyspaces.add(keyspace); |
modified driver-core/src/test/java/com/datastax/driver/core/NodeRefreshDebouncerTest.java +10 −13
| @@ -15,19 +15,16 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.util.Collection; | |
| 19 | -import java.util.concurrent.TimeUnit; | |
| 20 | - | |
| 21 | 18 | import org.mockito.ArgumentCaptor; |
| 22 | 19 | import org.testng.annotations.Test; |
| 23 | 20 | |
| 24 | -import static com.google.common.collect.Lists.newArrayList; | |
| 25 | -import static org.mockito.ArgumentCaptor.forClass; | |
| 26 | -import static org.mockito.Mockito.mock; | |
| 27 | -import static org.mockito.Mockito.timeout; | |
| 28 | -import static org.mockito.Mockito.verify; | |
| 21 | +import java.util.Collection; | |
| 22 | +import java.util.concurrent.TimeUnit; | |
| 29 | 23 | |
| 30 | 24 | import static com.datastax.driver.core.Assertions.assertThat; |
| 25 | +import static com.google.common.collect.Lists.newArrayList; | |
| 26 | +import static org.mockito.ArgumentCaptor.forClass; | |
| 27 | +import static org.mockito.Mockito.*; | |
| 31 | 28 | |
| 32 | 29 | public class NodeRefreshDebouncerTest extends CCMBridge.PerClassSingleNodeCluster { |
| 33 | 30 | |
| @@ -40,22 +37,22 @@ | ||
| 40 | 37 | * Ensures that when a new node is bootstrapped into the cluster, stopped, and then subsequently |
| 41 | 38 | * started within {@link QueryOptions#setRefreshNodeIntervalMillis(int)} that an 'onAdd' event |
| 42 | 39 | * event is the only one processed and that the {@link Host} is marked up. |
| 43 | - * <p> | |
| 40 | + * <p/> | |
| 44 | 41 | * Since NEW_NODE_DELAY_SECONDS is typically configured with a high value (60 seconds default |
| 45 | 42 | * in the maven profile) this test can take a very long time. |
| 46 | 43 | * |
| 47 | 44 | * @jira_ticket JAVA-657 |
| 48 | 45 | * @since 2.0.11 |
| 49 | 46 | */ |
| 50 | - @Test(groups="long") | |
| 47 | + @Test(groups = "long") | |
| 51 | 48 | public void should_call_onAdd_with_bootstrap_stop_start() { |
| 52 | 49 | int refreshNodeInterval = 10000; |
| 53 | 50 | QueryOptions queryOptions = new QueryOptions().setRefreshNodeIntervalMillis(refreshNodeInterval); |
| 54 | 51 | CCMBridge ccm = CCMBridge.builder("test").withNodes(1).build(); |
| 55 | 52 | Cluster cluster = Cluster.builder() |
| 56 | - .addContactPoint(CCMBridge.ipOfNode(1)) | |
| 57 | - .withQueryOptions(queryOptions) | |
| 58 | - .build(); | |
| 53 | + .addContactPoint(CCMBridge.ipOfNode(1)) | |
| 54 | + .withQueryOptions(queryOptions) | |
| 55 | + .build(); | |
| 59 | 56 | |
| 60 | 57 | try { |
| 61 | 58 | cluster.connect(); |
modified driver-core/src/test/java/com/datastax/driver/core/OPPTokenFactoryTest.java +15 −17
| @@ -15,15 +15,13 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | +import org.testng.annotations.Test; | |
| 19 | + | |
| 18 | 20 | import java.math.BigInteger; |
| 19 | 21 | import java.nio.ByteBuffer; |
| 20 | 22 | import java.util.List; |
| 21 | 23 | |
| 22 | -import com.google.common.collect.Lists; | |
| 23 | -import org.testng.annotations.Test; | |
| 24 | - | |
| 25 | 24 | import static org.assertj.core.api.Assertions.assertThat; |
| 26 | -import static org.testng.Assert.fail; | |
| 27 | 25 | |
| 28 | 26 | public class OPPTokenFactoryTest { |
| 29 | 27 | private static final Token.Factory factory = Token.OPPToken.FACTORY; |
| @@ -34,8 +32,8 @@ | ||
| 34 | 32 | public void should_split_range() { |
| 35 | 33 | List<Token> splits = factory.split(token('a'), token('d'), 3); |
| 36 | 34 | assertThat(splits).containsExactly( |
| 37 | - token('b'), | |
| 38 | - token('c') | |
| 35 | + token('b'), | |
| 36 | + token('c') | |
| 39 | 37 | ); |
| 40 | 38 | } |
| 41 | 39 | |
| @@ -47,38 +45,38 @@ | ||
| 47 | 45 | // These are edge cases where we want to make sure we don't accidentally generate the ]min,min] range (which is the whole ring) |
| 48 | 46 | List<Token> splits = factory.split(minToken, zero, 3); |
| 49 | 47 | assertThat(splits).containsExactly( |
| 50 | - zero, | |
| 51 | - zero | |
| 48 | + zero, | |
| 49 | + zero | |
| 52 | 50 | ); |
| 53 | 51 | } |
| 54 | 52 | |
| 55 | 53 | @Test(groups = "unit") |
| 56 | 54 | public void should_strip_trailing_0_bytes() { |
| 57 | - Token with0Bytes = factory.deserialize(ByteBuffer.wrap(new byte[]{4,0,0,0})); | |
| 55 | + Token with0Bytes = factory.deserialize(ByteBuffer.wrap(new byte[]{4, 0, 0, 0})); | |
| 58 | 56 | Token without0Bytes = factory.deserialize(ByteBuffer.wrap(new byte[]{4})); |
| 59 | 57 | Token fromStringWith0Bytes = factory.fromString("040000"); |
| 60 | 58 | |
| 61 | 59 | assertThat(with0Bytes) |
| 62 | - .isEqualTo(without0Bytes) | |
| 63 | - .isEqualTo(fromStringWith0Bytes); | |
| 60 | + .isEqualTo(without0Bytes) | |
| 61 | + .isEqualTo(fromStringWith0Bytes); | |
| 64 | 62 | |
| 65 | 63 | Token withMixed0Bytes = factory.fromString("0004000400"); |
| 66 | 64 | Token withoutMixed0Bytes = factory.fromString("00040004"); |
| 67 | 65 | |
| 68 | 66 | assertThat(withMixed0Bytes) |
| 69 | - .isEqualTo(withoutMixed0Bytes); | |
| 67 | + .isEqualTo(withoutMixed0Bytes); | |
| 70 | 68 | } |
| 71 | 69 | |
| 72 | 70 | @Test(groups = "unit") |
| 73 | 71 | public void should_split_range_that_wraps_around_the_ring() { |
| 74 | - for(int start = 1; start < 128; start++) { | |
| 75 | - for(int end = start; end < start; end++) { | |
| 72 | + for (int start = 1; start < 128; start++) { | |
| 73 | + for (int end = start; end < start; end++) { | |
| 76 | 74 | // Take the midpoint of the ring and offset by the midpoint of start+end. |
| 77 | 75 | long expected = 0x81 + ((start + end) / 2); |
| 78 | 76 | TokenRange tr = new TokenRange(token(start), token(end), factory); |
| 79 | 77 | assertThat(factory.split(tr.getStart(), tr.getEnd(), 2)) |
| 80 | - .as("Expected 0x%X for start: %d, end: %d", expected, start, end) | |
| 81 | - .containsExactly(token(expected)); | |
| 78 | + .as("Expected 0x%X for start: %d, end: %d", expected, start, end) | |
| 79 | + .containsExactly(token(expected)); | |
| 82 | 80 | } |
| 83 | 81 | } |
| 84 | 82 | } |
| @@ -89,7 +87,7 @@ | ||
| 89 | 87 | } |
| 90 | 88 | |
| 91 | 89 | private Token token(char c) { |
| 92 | - return new Token.OPPToken(ByteBuffer.wrap(new byte[]{ (byte)c })); | |
| 90 | + return new Token.OPPToken(ByteBuffer.wrap(new byte[]{(byte) c})); | |
| 93 | 91 | } |
| 94 | 92 | |
| 95 | 93 | private Token token(long i) { |
modified driver-core/src/test/java/com/datastax/driver/core/OPPTokenIntegrationTest.java +2 −1
| @@ -22,7 +22,8 @@ | ||
| 22 | 22 | super("-p ByteOrderedPartitioner", DataType.blob()); |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | - @Override protected Token.Factory tokenFactory() { | |
| 25 | + @Override | |
| 26 | + protected Token.Factory tokenFactory() { | |
| 26 | 27 | return OPPToken.FACTORY; |
| 27 | 28 | } |
| 28 | 29 | } |
modified driver-core/src/test/java/com/datastax/driver/core/OPPTokenVnodeIntegrationTest.java +2 −1
| @@ -20,7 +20,8 @@ | ||
| 20 | 20 | super("-p ByteOrderedPartitioner", DataType.blob(), true); |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | - @Override protected Token.Factory tokenFactory() { | |
| 23 | + @Override | |
| 24 | + protected Token.Factory tokenFactory() { | |
| 24 | 25 | return Token.OPPToken.FACTORY; |
| 25 | 26 | } |
| 26 | 27 | } |
modified driver-core/src/test/java/com/datastax/driver/core/PagingStateTest.java +17 −18
| @@ -15,21 +15,20 @@ | ||
| 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.Iterator; | |
| 21 | - | |
| 18 | +import com.datastax.driver.core.exceptions.PagingStateException; | |
| 22 | 19 | import com.datastax.driver.core.utils.CassandraVersion; |
| 23 | 20 | import org.slf4j.Logger; |
| 24 | 21 | import org.slf4j.LoggerFactory; |
| 25 | 22 | import org.testng.annotations.BeforeClass; |
| 26 | 23 | import org.testng.annotations.Test; |
| 27 | 24 | |
| 28 | -import static org.assertj.core.api.Assertions.assertThat; | |
| 25 | +import java.util.Collection; | |
| 26 | +import java.util.Collections; | |
| 27 | +import java.util.Iterator; | |
| 29 | 28 | |
| 30 | -import com.datastax.driver.core.exceptions.PagingStateException; | |
| 29 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 31 | 30 | |
| 32 | -@CassandraVersion(major=2.0) | |
| 31 | +@CassandraVersion(major = 2.0) | |
| 33 | 32 | public class PagingStateTest extends CCMBridge.PerClassSingleNodeCluster { |
| 34 | 33 | private static final Logger logger = LoggerFactory.getLogger(PagingStateTest.class); |
| 35 | 34 | public static final String KEY = "paging_test"; |
| @@ -51,7 +50,7 @@ | ||
| 51 | 50 | * |
| 52 | 51 | * @test_category paging |
| 53 | 52 | * @expected_result {@link ResultSet} from the query with the provided {@link PagingState} starts from the |
| 54 | - * subsequent row from the first query. | |
| 53 | + * subsequent row from the first query. | |
| 55 | 54 | */ |
| 56 | 55 | @Test(groups = "short") |
| 57 | 56 | public void should_complete_when_using_paging_state() { |
| @@ -68,13 +67,13 @@ | ||
| 68 | 67 | } |
| 69 | 68 | |
| 70 | 69 | /** |
| 71 | - * <p> | |
| 70 | + * <p/> | |
| 72 | 71 | * Validates that if the {@link PagingState} is altered in any way that it may not be reused. |
| 73 | 72 | * The paging state is altered in the following ways: |
| 74 | - * | |
| 73 | + * <p/> | |
| 75 | 74 | * <ol> |
| 76 | - * <li>Altering a byte in the paging state raw bytes.</li> | |
| 77 | - * <li>Setting the {@link PagingState} on a different Statement. (should fail hash validation)</li> | |
| 75 | + * <li>Altering a byte in the paging state raw bytes.</li> | |
| 76 | + * <li>Setting the {@link PagingState} on a different Statement. (should fail hash validation)</li> | |
| 78 | 77 | * </ol> |
| 79 | 78 | * |
| 80 | 79 | * @test_category paging |
| @@ -93,7 +92,7 @@ | ||
| 93 | 92 | String savedPagingStateString = savedPagingState.toString(); |
| 94 | 93 | |
| 95 | 94 | // corrupting the paging state |
| 96 | - savedPagingStateBuffer[6] = (byte)42; | |
| 95 | + savedPagingStateBuffer[6] = (byte) 42; | |
| 97 | 96 | |
| 98 | 97 | try { |
| 99 | 98 | st.setFetchSize(20).setPagingState(PagingState.fromBytes(savedPagingStateBuffer)); |
| @@ -123,10 +122,10 @@ | ||
| 123 | 122 | * |
| 124 | 123 | * @test_category paging |
| 125 | 124 | * @expected_result {@link ResultSet} from the query with the provided paging state starts from the subsequent row |
| 126 | - * from the first query. | |
| 125 | + * from the first query. | |
| 127 | 126 | */ |
| 128 | 127 | @Test(groups = "short") |
| 129 | - @CassandraVersion(major=2.0) | |
| 128 | + @CassandraVersion(major = 2.0) | |
| 130 | 129 | public void should_be_able_to_use_state_with_bound_statement() { |
| 131 | 130 | PreparedStatement prepared = session.prepare("SELECT v from test where k=?"); |
| 132 | 131 | BoundStatement bs = prepared.bind(KEY); |
| @@ -149,7 +148,7 @@ | ||
| 149 | 148 | * @expected_result A failure is thrown when setting paging state on a different {@link BoundStatement}. |
| 150 | 149 | */ |
| 151 | 150 | @Test(groups = "short", expectedExceptions = {PagingStateException.class}) |
| 152 | - @CassandraVersion(major=2.0) | |
| 151 | + @CassandraVersion(major = 2.0) | |
| 153 | 152 | public void should_not_be_able_to_use_state_with_different_bound_statement() { |
| 154 | 153 | PreparedStatement prepared = session.prepare("SELECT v from test where k=?"); |
| 155 | 154 | BoundStatement bs0 = prepared.bind(KEY); |
| @@ -196,7 +195,7 @@ | ||
| 196 | 195 | @Test(groups = "unit", expectedExceptions = {PagingStateException.class}) |
| 197 | 196 | public void should_fail_when_given_invalid_byte_array() { |
| 198 | 197 | // Given an expected page state of size 1 and hash of size 1, we should expect 6 bytes, but only receive 5. |
| 199 | - byte[] complete = { 0x00, 0x01, 0x00, 0x01, 0x00 }; | |
| 198 | + byte[] complete = {0x00, 0x01, 0x00, 0x01, 0x00}; | |
| 200 | 199 | PagingState.fromBytes(complete); |
| 201 | 200 | } |
| 202 | 201 | |
| @@ -214,7 +213,7 @@ | ||
| 214 | 213 | * |
| 215 | 214 | * @test_category paging |
| 216 | 215 | * @expected_result {@link ResultSet} from the query with the provided raw paging state starts from the |
| 217 | - * subsequent row from the first query. | |
| 216 | + * subsequent row from the first query. | |
| 218 | 217 | */ |
| 219 | 218 | @Test(groups = "short") |
| 220 | 219 | public void should_complete_when_using_unsafe_paging_state() { |
modified driver-core/src/test/java/com/datastax/driver/core/PoolingOptionsTest.java +3 −1
| @@ -19,7 +19,9 @@ | ||
| 19 | 19 | |
| 20 | 20 | import java.util.Collection; |
| 21 | 21 | import java.util.Collections; |
| 22 | -import java.util.concurrent.*; | |
| 22 | +import java.util.concurrent.LinkedBlockingQueue; | |
| 23 | +import java.util.concurrent.ThreadPoolExecutor; | |
| 24 | +import java.util.concurrent.TimeUnit; | |
| 23 | 25 | |
| 24 | 26 | import static org.assertj.core.api.Assertions.assertThat; |
| 25 | 27 | import static org.mockito.Matchers.any; |
modified driver-core/src/test/java/com/datastax/driver/core/PreparedStatementTest.java +30 −27
| @@ -15,25 +15,22 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.net.InetAddress; | |
| 19 | -import java.util.*; | |
| 20 | - | |
| 18 | +import com.datastax.driver.core.exceptions.InvalidQueryException; | |
| 19 | +import com.datastax.driver.core.exceptions.UnsupportedFeatureException; | |
| 21 | 20 | import com.google.common.collect.ImmutableList; |
| 22 | 21 | import org.testng.annotations.Test; |
| 23 | 22 | |
| 23 | +import java.net.InetAddress; | |
| 24 | +import java.util.*; | |
| 25 | + | |
| 26 | +import static com.datastax.driver.core.TestUtils.*; | |
| 24 | 27 | import static org.assertj.core.api.Assertions.assertThat; |
| 25 | 28 | import static org.testng.Assert.assertEquals; |
| 26 | 29 | import static org.testng.Assert.assertTrue; |
| 27 | 30 | |
| 28 | -import com.datastax.driver.core.exceptions.InvalidQueryException; | |
| 29 | -import com.datastax.driver.core.exceptions.NoHostAvailableException; | |
| 30 | -import com.datastax.driver.core.exceptions.UnsupportedFeatureException; | |
| 31 | - | |
| 32 | -import static com.datastax.driver.core.TestUtils.*; | |
| 33 | - | |
| 34 | 31 | /** |
| 35 | 32 | * Prepared statement tests. |
| 36 | - * | |
| 33 | + * <p/> | |
| 37 | 34 | * Note: this class also happens to test all the get methods from Row. |
| 38 | 35 | */ |
| 39 | 36 | public class PreparedStatementTest extends CCMBridge.PerClassSingleNodeCluster { |
| @@ -163,7 +160,8 @@ | ||
| 163 | 160 | |
| 164 | 161 | String name = "c_list_" + rawType; |
| 165 | 162 | DataType type = DataType.list(rawType); |
| 166 | - List<Object> value = (List<Object>)getFixedValue(type);; | |
| 163 | + List<Object> value = (List<Object>) getFixedValue(type); | |
| 164 | + ; | |
| 167 | 165 | PreparedStatement ps = session.prepare(String.format("INSERT INTO %s(k, %s) VALUES ('prepared_list', ?)", ALL_LIST_TABLE, name)); |
| 168 | 166 | BoundStatement bs = ps.bind(); |
| 169 | 167 | session.execute(setBoundValue(bs, name, type, value)); |
| @@ -187,7 +185,8 @@ | ||
| 187 | 185 | |
| 188 | 186 | String name = "c_list_" + rawType; |
| 189 | 187 | DataType type = DataType.list(rawType); |
| 190 | - List<Object> value = (List<Object>)getFixedValue2(type);; | |
| 188 | + List<Object> value = (List<Object>) getFixedValue2(type); | |
| 189 | + ; | |
| 191 | 190 | PreparedStatement ps = session.prepare(String.format("INSERT INTO %s(k, %s) VALUES ('prepared_list', ?)", ALL_LIST_TABLE, name)); |
| 192 | 191 | BoundStatement bs = ps.bind(); |
| 193 | 192 | session.execute(setBoundValue(bs, name, type, value)); |
| @@ -208,7 +207,8 @@ | ||
| 208 | 207 | |
| 209 | 208 | String name = "c_set_" + rawType; |
| 210 | 209 | DataType type = DataType.set(rawType); |
| 211 | - Set<Object> value = (Set<Object>)getFixedValue(type);; | |
| 210 | + Set<Object> value = (Set<Object>) getFixedValue(type); | |
| 211 | + ; | |
| 212 | 212 | PreparedStatement ps = session.prepare(String.format("INSERT INTO %s(k, %s) VALUES ('prepared_set', ?)", ALL_SET_TABLE, name)); |
| 213 | 213 | BoundStatement bs = ps.bind(); |
| 214 | 214 | session.execute(setBoundValue(bs, name, type, value)); |
| @@ -232,7 +232,8 @@ | ||
| 232 | 232 | |
| 233 | 233 | String name = "c_set_" + rawType; |
| 234 | 234 | DataType type = DataType.set(rawType); |
| 235 | - Set<Object> value = (Set<Object>)getFixedValue2(type);; | |
| 235 | + Set<Object> value = (Set<Object>) getFixedValue2(type); | |
| 236 | + ; | |
| 236 | 237 | PreparedStatement ps = session.prepare(String.format("INSERT INTO %s(k, %s) VALUES ('prepared_set', ?)", ALL_SET_TABLE, name)); |
| 237 | 238 | BoundStatement bs = ps.bind(); |
| 238 | 239 | session.execute(setBoundValue(bs, name, type, value)); |
| @@ -258,7 +259,8 @@ | ||
| 258 | 259 | |
| 259 | 260 | String name = "c_map_" + rawKeyType + '_' + rawValueType; |
| 260 | 261 | DataType type = DataType.map(rawKeyType, rawValueType); |
| 261 | - Map<Object, Object> value = (Map<Object, Object>)getFixedValue(type);; | |
| 262 | + Map<Object, Object> value = (Map<Object, Object>) getFixedValue(type); | |
| 263 | + ; | |
| 262 | 264 | PreparedStatement ps = session.prepare(String.format("INSERT INTO %s(k, %s) VALUES ('prepared_map', ?)", ALL_MAP_TABLE, name)); |
| 263 | 265 | BoundStatement bs = ps.bind(); |
| 264 | 266 | session.execute(setBoundValue(bs, name, type, value)); |
| @@ -288,7 +290,8 @@ | ||
| 288 | 290 | |
| 289 | 291 | String name = "c_map_" + rawKeyType + '_' + rawValueType; |
| 290 | 292 | DataType type = DataType.map(rawKeyType, rawValueType); |
| 291 | - Map<Object, Object> value = (Map<Object, Object>)getFixedValue2(type);; | |
| 293 | + Map<Object, Object> value = (Map<Object, Object>) getFixedValue2(type); | |
| 294 | + ; | |
| 292 | 295 | PreparedStatement ps = session.prepare(String.format("INSERT INTO %s(k, %s) VALUES ('prepared_map', ?)", ALL_MAP_TABLE, name)); |
| 293 | 296 | BoundStatement bs = ps.bind(); |
| 294 | 297 | session.execute(setBoundValue(bs, name, type, value)); |
| @@ -341,7 +344,7 @@ | ||
| 341 | 344 | * Prints the table definitions that will be used in testing |
| 342 | 345 | * (for exporting purposes) |
| 343 | 346 | */ |
| 344 | - @Test(groups = { "docs" }) | |
| 347 | + @Test(groups = {"docs"}) | |
| 345 | 348 | public void printTableDefinitions() { |
| 346 | 349 | for (String definition : getTableDefinitions()) { |
| 347 | 350 | System.out.println(definition); |
| @@ -379,21 +382,21 @@ | ||
| 379 | 382 | } |
| 380 | 383 | } |
| 381 | 384 | |
| 382 | - @Test(groups="short") | |
| 385 | + @Test(groups = "short") | |
| 383 | 386 | public void should_set_routing_key_on_case_insensitive_keyspace_and_table() { |
| 384 | - session.execute(String.format("CREATE TABLE %s.foo (i int PRIMARY KEY)",keyspace)); | |
| 387 | + session.execute(String.format("CREATE TABLE %s.foo (i int PRIMARY KEY)", keyspace)); | |
| 385 | 388 | |
| 386 | - PreparedStatement ps = session.prepare(String.format("INSERT INTO %s.foo (i) VALUES (?)",keyspace)); | |
| 389 | + PreparedStatement ps = session.prepare(String.format("INSERT INTO %s.foo (i) VALUES (?)", keyspace)); | |
| 387 | 390 | BoundStatement bs = ps.bind(1); |
| 388 | 391 | assertThat(bs.getRoutingKey()).isNotNull(); |
| 389 | 392 | } |
| 390 | 393 | |
| 391 | - @Test(groups="short") | |
| 394 | + @Test(groups = "short") | |
| 392 | 395 | public void should_set_routing_key_on_case_sensitive_keyspace_and_table() { |
| 393 | 396 | session.execute("CREATE KEYSPACE \"Test\" WITH replication = { " |
| 394 | - + " 'class': 'SimpleStrategy'," | |
| 395 | - + " 'replication_factor': '1'" | |
| 396 | - + "}"); | |
| 397 | + + " 'class': 'SimpleStrategy'," | |
| 398 | + + " 'replication_factor': '1'" | |
| 399 | + + "}"); | |
| 397 | 400 | session.execute("CREATE TABLE \"Test\".\"Foo\" (i int PRIMARY KEY)"); |
| 398 | 401 | |
| 399 | 402 | PreparedStatement ps = session.prepare("INSERT INTO \"Test\".\"Foo\" (i) VALUES (?)"); |
| @@ -401,11 +404,11 @@ | ||
| 401 | 404 | assertThat(bs.getRoutingKey()).isNotNull(); |
| 402 | 405 | } |
| 403 | 406 | |
| 404 | - @Test(groups="short", expectedExceptions = InvalidQueryException.class) | |
| 407 | + @Test(groups = "short", expectedExceptions = InvalidQueryException.class) | |
| 405 | 408 | public void should_fail_when_prepared_on_another_cluster() throws Exception { |
| 406 | 409 | Cluster otherCluster = Cluster.builder() |
| 407 | - .addContactPointsWithPorts(ImmutableList.of(hostAddress)) | |
| 408 | - .build(); | |
| 410 | + .addContactPointsWithPorts(ImmutableList.of(hostAddress)) | |
| 411 | + .build(); | |
| 409 | 412 | try { |
| 410 | 413 | PreparedStatement pst = otherCluster.connect().prepare("select * from system.peers where inet = ?"); |
| 411 | 414 | BoundStatement bs = pst.bind().setInet(0, InetAddress.getByName("localhost")); |
modified driver-core/src/test/java/com/datastax/driver/core/PrimitiveTypeSamples.java +23 −24
| @@ -15,6 +15,10 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.utils.Bytes; | |
| 19 | +import com.google.common.collect.ImmutableMap; | |
| 20 | +import com.google.common.collect.Lists; | |
| 21 | + | |
| 18 | 22 | import java.math.BigDecimal; |
| 19 | 23 | import java.math.BigInteger; |
| 20 | 24 | import java.net.InetAddress; |
| @@ -24,16 +28,11 @@ | ||
| 24 | 28 | import java.util.Map; |
| 25 | 29 | import java.util.UUID; |
| 26 | 30 | |
| 27 | -import com.google.common.collect.ImmutableMap; | |
| 28 | -import com.google.common.collect.Lists; | |
| 29 | - | |
| 30 | 31 | import static org.assertj.core.api.Assertions.assertThat; |
| 31 | 32 | |
| 32 | -import com.datastax.driver.core.utils.Bytes; | |
| 33 | - | |
| 34 | 33 | /** |
| 35 | 34 | * This class provides sample values for each primitive data type. |
| 36 | - * | |
| 35 | + * <p/> | |
| 37 | 36 | * These values have no particular meaning, the goal is just to have an instance that can be used in automated tests. |
| 38 | 37 | */ |
| 39 | 38 | public class PrimitiveTypeSamples { |
| @@ -43,29 +42,29 @@ | ||
| 43 | 42 | private static Map<DataType, Object> generateAll() { |
| 44 | 43 | try { |
| 45 | 44 | ImmutableMap<DataType, Object> result = ImmutableMap.<DataType, Object>builder() |
| 46 | - .put(DataType.ascii(), "ascii") | |
| 47 | - .put(DataType.bigint(), Long.MAX_VALUE) | |
| 48 | - .put(DataType.blob(), Bytes.fromHexString("0xCAFE")) | |
| 49 | - .put(DataType.cboolean(), Boolean.TRUE) | |
| 50 | - .put(DataType.decimal(), new BigDecimal("12.3E+7")) | |
| 51 | - .put(DataType.cdouble(), Double.MAX_VALUE) | |
| 52 | - .put(DataType.cfloat(), Float.MAX_VALUE) | |
| 53 | - .put(DataType.inet(), InetAddress.getByName("123.123.123.123")) | |
| 54 | - .put(DataType.cint(), Integer.MAX_VALUE) | |
| 55 | - .put(DataType.text(), "text") | |
| 56 | - .put(DataType.varchar(), "text") | |
| 57 | - .put(DataType.timestamp(), new Date(872835240000L)) | |
| 58 | - .put(DataType.timeuuid(), UUID.fromString("FE2B4360-28C6-11E2-81C1-0800200C9A66")) | |
| 59 | - .put(DataType.uuid(), UUID.fromString("067e6162-3b6f-4ae2-a171-2470b63dff00")) | |
| 60 | - .put(DataType.varint(), new BigInteger(Integer.toString(Integer.MAX_VALUE) + "000")) | |
| 61 | - .build(); | |
| 45 | + .put(DataType.ascii(), "ascii") | |
| 46 | + .put(DataType.bigint(), Long.MAX_VALUE) | |
| 47 | + .put(DataType.blob(), Bytes.fromHexString("0xCAFE")) | |
| 48 | + .put(DataType.cboolean(), Boolean.TRUE) | |
| 49 | + .put(DataType.decimal(), new BigDecimal("12.3E+7")) | |
| 50 | + .put(DataType.cdouble(), Double.MAX_VALUE) | |
| 51 | + .put(DataType.cfloat(), Float.MAX_VALUE) | |
| 52 | + .put(DataType.inet(), InetAddress.getByName("123.123.123.123")) | |
| 53 | + .put(DataType.cint(), Integer.MAX_VALUE) | |
| 54 | + .put(DataType.text(), "text") | |
| 55 | + .put(DataType.varchar(), "text") | |
| 56 | + .put(DataType.timestamp(), new Date(872835240000L)) | |
| 57 | + .put(DataType.timeuuid(), UUID.fromString("FE2B4360-28C6-11E2-81C1-0800200C9A66")) | |
| 58 | + .put(DataType.uuid(), UUID.fromString("067e6162-3b6f-4ae2-a171-2470b63dff00")) | |
| 59 | + .put(DataType.varint(), new BigInteger(Integer.toString(Integer.MAX_VALUE) + "000")) | |
| 60 | + .build(); | |
| 62 | 61 | |
| 63 | 62 | // Check that we cover all types (except counter) |
| 64 | 63 | List<DataType> tmp = Lists.newArrayList(DataType.allPrimitiveTypes()); |
| 65 | 64 | tmp.removeAll(result.keySet()); |
| 66 | 65 | assertThat(tmp) |
| 67 | - .as("new datatype not covered in test") | |
| 68 | - .containsOnly(DataType.counter()); | |
| 66 | + .as("new datatype not covered in test") | |
| 67 | + .containsOnly(DataType.counter()); | |
| 69 | 68 | |
| 70 | 69 | return result; |
| 71 | 70 | } catch (UnknownHostException e) { |
modified driver-core/src/test/java/com/datastax/driver/core/QueryLoggerErrorsTest.java +53 −55
| @@ -15,6 +15,7 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.exceptions.*; | |
| 18 | 19 | import org.apache.log4j.Logger; |
| 19 | 20 | import org.scassandra.http.client.PrimingRequest; |
| 20 | 21 | import org.testng.annotations.AfterMethod; |
| @@ -22,6 +23,7 @@ | ||
| 22 | 23 | import org.testng.annotations.DataProvider; |
| 23 | 24 | import org.testng.annotations.Test; |
| 24 | 25 | |
| 26 | +import static com.datastax.driver.core.QueryLogger.builder; | |
| 25 | 27 | import static org.apache.log4j.Level.DEBUG; |
| 26 | 28 | import static org.apache.log4j.Level.INFO; |
| 27 | 29 | import static org.assertj.core.api.Assertions.assertThat; |
| @@ -30,10 +32,6 @@ | ||
| 30 | 32 | import static org.scassandra.http.client.PrimingRequest.queryBuilder; |
| 31 | 33 | import static org.scassandra.http.client.PrimingRequest.then; |
| 32 | 34 | |
| 33 | -import com.datastax.driver.core.exceptions.*; | |
| 34 | - | |
| 35 | -import static com.datastax.driver.core.QueryLogger.builder; | |
| 36 | - | |
| 37 | 35 | /** |
| 38 | 36 | * Tests for {@link QueryLogger} using Scassandra. |
| 39 | 37 | * Contains only tests for exceptions (client timeout, read timeout, unavailable...); |
| @@ -51,7 +49,7 @@ | ||
| 51 | 49 | private Session session = null; |
| 52 | 50 | private QueryLogger queryLogger = null; |
| 53 | 51 | |
| 54 | - @BeforeMethod(groups = { "short", "unit" }) | |
| 52 | + @BeforeMethod(groups = {"short", "unit"}) | |
| 55 | 53 | public void setUp() { |
| 56 | 54 | slow.setLevel(INFO); |
| 57 | 55 | error.setLevel(INFO); |
| @@ -64,7 +62,7 @@ | ||
| 64 | 62 | session = cluster.connect(); |
| 65 | 63 | } |
| 66 | 64 | |
| 67 | - @AfterMethod(groups = { "short", "unit" }) | |
| 65 | + @AfterMethod(groups = {"short", "unit"}) | |
| 68 | 66 | public void tearDown() { |
| 69 | 67 | slow.setLevel(null); |
| 70 | 68 | error.setLevel(null); |
| @@ -73,7 +71,7 @@ | ||
| 73 | 71 | |
| 74 | 72 | queryLogger = null; |
| 75 | 73 | |
| 76 | - if(cluster != null) { | |
| 74 | + if (cluster != null) { | |
| 77 | 75 | cluster.close(); |
| 78 | 76 | } |
| 79 | 77 | } |
| @@ -83,24 +81,24 @@ | ||
| 83 | 81 | // given |
| 84 | 82 | slow.setLevel(DEBUG); |
| 85 | 83 | queryLogger = builder(cluster) |
| 86 | - .withConstantThreshold(10) | |
| 87 | - .build(); | |
| 84 | + .withConstantThreshold(10) | |
| 85 | + .build(); | |
| 88 | 86 | cluster.register(queryLogger); |
| 89 | 87 | String query = "SELECT foo FROM bar"; |
| 90 | 88 | primingClient.prime( |
| 91 | - queryBuilder() | |
| 92 | - .withQuery(query) | |
| 93 | - .withThen(then().withFixedDelay(100L)) | |
| 94 | - .build() | |
| 89 | + queryBuilder() | |
| 90 | + .withQuery(query) | |
| 91 | + .withThen(then().withFixedDelay(100L)) | |
| 92 | + .build() | |
| 95 | 93 | ); |
| 96 | 94 | // when |
| 97 | 95 | session.execute(query); |
| 98 | 96 | // then |
| 99 | 97 | String line = slowAppender.waitAndGet(5000); |
| 100 | 98 | assertThat(line) |
| 101 | - .contains("Query too slow") | |
| 102 | - .contains(ip) | |
| 103 | - .contains(query); | |
| 99 | + .contains("Query too slow") | |
| 100 | + .contains(ip) | |
| 101 | + .contains(query); | |
| 104 | 102 | } |
| 105 | 103 | |
| 106 | 104 | @Test(groups = "short") |
| @@ -112,10 +110,10 @@ | ||
| 112 | 110 | cluster.getConfiguration().getSocketOptions().setReadTimeoutMillis(1); |
| 113 | 111 | String query = "SELECT foo FROM bar"; |
| 114 | 112 | primingClient.prime( |
| 115 | - queryBuilder() | |
| 116 | - .withQuery(query) | |
| 117 | - .withThen(then().withFixedDelay(100L)) | |
| 118 | - .build() | |
| 113 | + queryBuilder() | |
| 114 | + .withQuery(query) | |
| 115 | + .withThen(then().withFixedDelay(100L)) | |
| 116 | + .build() | |
| 119 | 117 | ); |
| 120 | 118 | // when |
| 121 | 119 | try { |
| @@ -127,34 +125,34 @@ | ||
| 127 | 125 | // then |
| 128 | 126 | String line = errorAppender.waitAndGet(5000); |
| 129 | 127 | assertThat(line) |
| 130 | - .contains("Query error") | |
| 131 | - .contains(ip) | |
| 132 | - .contains(Integer.toString(scassandra.getBinaryPort())) | |
| 133 | - .contains(query) | |
| 134 | - .contains(OperationTimedOutException.class.getName()); | |
| 128 | + .contains("Query error") | |
| 129 | + .contains(ip) | |
| 130 | + .contains(Integer.toString(scassandra.getBinaryPort())) | |
| 131 | + .contains(query) | |
| 132 | + .contains(OperationTimedOutException.class.getName()); | |
| 135 | 133 | } |
| 136 | 134 | |
| 137 | - @DataProvider(name="errors") | |
| 135 | + @DataProvider(name = "errors") | |
| 138 | 136 | public static Object[][] createErrors() { |
| 139 | - return new Object[][] { | |
| 140 | - { unavailable, NoHostAvailableException.class, UnavailableException.class }, | |
| 141 | - { write_request_timeout, WriteTimeoutException.class, WriteTimeoutException.class }, | |
| 142 | - { read_request_timeout, ReadTimeoutException.class, ReadTimeoutException.class }, | |
| 143 | - { server_error, NoHostAvailableException.class, ServerError.class }, | |
| 144 | - { protocol_error, ProtocolError.class, ProtocolError.class }, | |
| 145 | - { bad_credentials, AuthenticationException.class, AuthenticationException.class }, | |
| 146 | - { overloaded, NoHostAvailableException.class, OverloadedException.class }, | |
| 147 | - { is_bootstrapping, NoHostAvailableException.class, BootstrappingException.class }, | |
| 148 | - { truncate_error, TruncateException.class, TruncateException.class }, | |
| 149 | - { syntax_error, SyntaxError.class, SyntaxError.class }, | |
| 150 | - { invalid, InvalidQueryException.class, InvalidQueryException.class }, | |
| 151 | - { config_error, InvalidConfigurationInQueryException.class, InvalidConfigurationInQueryException.class }, | |
| 152 | - { already_exists, AlreadyExistsException.class, AlreadyExistsException.class }, | |
| 153 | - { unprepared, DriverInternalError.class, UnpreparedException.class } | |
| 137 | + return new Object[][]{ | |
| 138 | + {unavailable, NoHostAvailableException.class, UnavailableException.class}, | |
| 139 | + {write_request_timeout, WriteTimeoutException.class, WriteTimeoutException.class}, | |
| 140 | + {read_request_timeout, ReadTimeoutException.class, ReadTimeoutException.class}, | |
| 141 | + {server_error, NoHostAvailableException.class, ServerError.class}, | |
| 142 | + {protocol_error, ProtocolError.class, ProtocolError.class}, | |
| 143 | + {bad_credentials, AuthenticationException.class, AuthenticationException.class}, | |
| 144 | + {overloaded, NoHostAvailableException.class, OverloadedException.class}, | |
| 145 | + {is_bootstrapping, NoHostAvailableException.class, BootstrappingException.class}, | |
| 146 | + {truncate_error, TruncateException.class, TruncateException.class}, | |
| 147 | + {syntax_error, SyntaxError.class, SyntaxError.class}, | |
| 148 | + {invalid, InvalidQueryException.class, InvalidQueryException.class}, | |
| 149 | + {config_error, InvalidConfigurationInQueryException.class, InvalidConfigurationInQueryException.class}, | |
| 150 | + {already_exists, AlreadyExistsException.class, AlreadyExistsException.class}, | |
| 151 | + {unprepared, DriverInternalError.class, UnpreparedException.class} | |
| 154 | 152 | }; |
| 155 | 153 | } |
| 156 | 154 | |
| 157 | - @Test(groups = "short", dataProvider="errors") | |
| 155 | + @Test(groups = "short", dataProvider = "errors") | |
| 158 | 156 | public void should_log_exception_from_the_given_result(PrimingRequest.Result result, Class<? extends Exception> expectedException, Class<? extends Exception> loggedException) throws Exception { |
| 159 | 157 | // given |
| 160 | 158 | error.setLevel(DEBUG); |
| @@ -162,22 +160,22 @@ | ||
| 162 | 160 | cluster.register(queryLogger); |
| 163 | 161 | String query = "SELECT foo FROM bar"; |
| 164 | 162 | primingClient.prime( |
| 165 | - queryBuilder() | |
| 166 | - .withQuery(query) | |
| 167 | - .withThen(then().withResult(result)) | |
| 168 | - .build() | |
| 163 | + queryBuilder() | |
| 164 | + .withQuery(query) | |
| 165 | + .withThen(then().withResult(result)) | |
| 166 | + .build() | |
| 169 | 167 | ); |
| 170 | 168 | // when |
| 171 | 169 | try { |
| 172 | 170 | session.execute(query); |
| 173 | 171 | fail("Should have thrown NoHostAvailableException"); |
| 174 | - } catch(Exception e) { | |
| 175 | - if(e instanceof NoHostAvailableException) { | |
| 172 | + } catch (Exception e) { | |
| 173 | + if (e instanceof NoHostAvailableException) { | |
| 176 | 174 | assertThat(expectedException).isEqualTo(NoHostAvailableException.class); |
| 177 | 175 | // ok |
| 178 | - Throwable error = ((NoHostAvailableException)e).getErrors().get(hostAddress); | |
| 176 | + Throwable error = ((NoHostAvailableException) e).getErrors().get(hostAddress); | |
| 179 | 177 | assertThat(error).isNotNull(); |
| 180 | - if(loggedException.getSuperclass() == DriverInternalError.class) { | |
| 178 | + if (loggedException.getSuperclass() == DriverInternalError.class) { | |
| 181 | 179 | assertThat(error).isOfAnyClassIn(DriverException.class); |
| 182 | 180 | } else { |
| 183 | 181 | assertThat(error).isOfAnyClassIn(loggedException); |
| @@ -189,11 +187,11 @@ | ||
| 189 | 187 | // then |
| 190 | 188 | String line = errorAppender.waitAndGet(5000); |
| 191 | 189 | assertThat(line) |
| 192 | - .contains("Query error") | |
| 193 | - .contains(ip) | |
| 194 | - .contains(Integer.toString(scassandra.getBinaryPort())) | |
| 195 | - .contains(query) | |
| 196 | - .contains(loggedException.getName()); | |
| 190 | + .contains("Query error") | |
| 191 | + .contains(ip) | |
| 192 | + .contains(Integer.toString(scassandra.getBinaryPort())) | |
| 193 | + .contains(query) | |
| 194 | + .contains(loggedException.getName()); | |
| 197 | 195 | } |
| 198 | 196 | |
| 199 | 197 | } |
| No newline at the end of the file |
modified driver-core/src/test/java/com/datastax/driver/core/QueryLoggerTest.java +173 −176
| @@ -15,10 +15,7 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.nio.ByteBuffer; | |
| 19 | -import java.util.ArrayList; | |
| 20 | -import java.util.List; | |
| 21 | - | |
| 18 | +import com.datastax.driver.core.exceptions.DriverException; | |
| 22 | 19 | import com.datastax.driver.core.utils.CassandraVersion; |
| 23 | 20 | import com.google.common.base.Function; |
| 24 | 21 | import com.google.common.base.Joiner; |
| @@ -31,19 +28,18 @@ | ||
| 31 | 28 | import org.testng.annotations.BeforeMethod; |
| 32 | 29 | import org.testng.annotations.Test; |
| 33 | 30 | |
| 34 | -import static com.datastax.driver.core.BatchStatement.Type.COUNTER; | |
| 35 | -import static org.apache.log4j.Level.DEBUG; | |
| 36 | -import static org.apache.log4j.Level.INFO; | |
| 37 | -import static org.apache.log4j.Level.TRACE; | |
| 38 | -import static org.assertj.core.api.Assertions.assertThat; | |
| 39 | -import static org.mockito.Mockito.mock; | |
| 40 | - | |
| 41 | -import com.datastax.driver.core.exceptions.DriverException; | |
| 31 | +import java.nio.ByteBuffer; | |
| 32 | +import java.util.ArrayList; | |
| 33 | +import java.util.List; | |
| 42 | 34 | |
| 35 | +import static com.datastax.driver.core.BatchStatement.Type.COUNTER; | |
| 43 | 36 | import static com.datastax.driver.core.BatchStatement.Type.UNLOGGED; |
| 44 | 37 | import static com.datastax.driver.core.CCMBridge.ipOfNode; |
| 45 | 38 | import static com.datastax.driver.core.QueryLogger.*; |
| 46 | 39 | import static com.datastax.driver.core.TestUtils.getFixedValue; |
| 40 | +import static org.apache.log4j.Level.*; | |
| 41 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 42 | +import static org.mockito.Mockito.mock; | |
| 47 | 43 | |
| 48 | 44 | /** |
| 49 | 45 | * Main tests for {@link QueryLogger} using {@link com.datastax.driver.core.CCMBridge}. |
| @@ -60,31 +56,31 @@ | ||
| 60 | 56 | })); |
| 61 | 57 | |
| 62 | 58 | private static final List<Object> values = Lists.transform(dataTypes, new Function<DataType, Object>() { |
| 63 | - @Override | |
| 64 | - public Object apply(DataType type) { | |
| 65 | - return getFixedValue(type); | |
| 59 | + @Override | |
| 60 | + public Object apply(DataType type) { | |
| 61 | + return getFixedValue(type); | |
| 62 | + } | |
| 66 | 63 | } |
| 67 | - } | |
| 68 | 64 | ); |
| 69 | 65 | |
| 70 | 66 | private static final String definitions = Joiner.on(", ").join( |
| 71 | - Lists.transform(dataTypes, new Function<DataType, String>() { | |
| 72 | - @Override | |
| 73 | - public String apply(DataType type) { | |
| 74 | - return "c_" + type + " " + type; | |
| 75 | - } | |
| 76 | - } | |
| 77 | - ) | |
| 67 | + Lists.transform(dataTypes, new Function<DataType, String>() { | |
| 68 | + @Override | |
| 69 | + public String apply(DataType type) { | |
| 70 | + return "c_" + type + " " + type; | |
| 71 | + } | |
| 72 | + } | |
| 73 | + ) | |
| 78 | 74 | ); |
| 79 | 75 | |
| 80 | 76 | private static final String assignments = Joiner.on(", ").join( |
| 81 | - Lists.transform(dataTypes, new Function<DataType, String>() { | |
| 82 | - @Override | |
| 83 | - public String apply(DataType type) { | |
| 84 | - return "c_" + type + " = ?"; | |
| 85 | - } | |
| 86 | - } | |
| 87 | - ) | |
| 77 | + Lists.transform(dataTypes, new Function<DataType, String>() { | |
| 78 | + @Override | |
| 79 | + public String apply(DataType type) { | |
| 80 | + return "c_" + type + " = ?"; | |
| 81 | + } | |
| 82 | + } | |
| 83 | + ) | |
| 88 | 84 | ); |
| 89 | 85 | |
| 90 | 86 | private Logger normal = Logger.getLogger(NORMAL_LOGGER.getName()); |
| @@ -97,14 +93,14 @@ | ||
| 97 | 93 | |
| 98 | 94 | private QueryLogger queryLogger; |
| 99 | 95 | |
| 100 | - @BeforeMethod(groups = { "short", "unit" }) | |
| 96 | + @BeforeMethod(groups = {"short", "unit"}) | |
| 101 | 97 | public void startCapturingLogs() { |
| 102 | 98 | normal.addAppender(normalAppender = new MemoryAppender()); |
| 103 | 99 | slow.addAppender(slowAppender = new MemoryAppender()); |
| 104 | 100 | error.addAppender(errorAppender = new MemoryAppender()); |
| 105 | 101 | } |
| 106 | 102 | |
| 107 | - @AfterMethod(groups = { "short", "unit" }) | |
| 103 | + @AfterMethod(groups = {"short", "unit"}) | |
| 108 | 104 | public void stopCapturingLogs() { |
| 109 | 105 | normal.setLevel(null); |
| 110 | 106 | slow.setLevel(null); |
| @@ -114,16 +110,16 @@ | ||
| 114 | 110 | error.removeAppender(errorAppender); |
| 115 | 111 | } |
| 116 | 112 | |
| 117 | - @BeforeMethod(groups = { "short", "unit" }) | |
| 113 | + @BeforeMethod(groups = {"short", "unit"}) | |
| 118 | 114 | public void resetLogLevels() { |
| 119 | 115 | normal.setLevel(INFO); |
| 120 | 116 | slow.setLevel(INFO); |
| 121 | 117 | error.setLevel(INFO); |
| 122 | 118 | } |
| 123 | 119 | |
| 124 | - @AfterMethod(groups = { "short", "unit" }) | |
| 120 | + @AfterMethod(groups = {"short", "unit"}) | |
| 125 | 121 | public void unregisterQueryLogger() { |
| 126 | - if(cluster != null && queryLogger != null) { | |
| 122 | + if (cluster != null && queryLogger != null) { | |
| 127 | 123 | cluster.unregister(queryLogger); |
| 128 | 124 | } |
| 129 | 125 | } |
| @@ -135,18 +131,18 @@ | ||
| 135 | 131 | // given |
| 136 | 132 | normal.setLevel(DEBUG); |
| 137 | 133 | queryLogger = QueryLogger.builder(cluster) |
| 138 | - .withConstantThreshold(Long.MAX_VALUE) | |
| 139 | - .build(); | |
| 134 | + .withConstantThreshold(Long.MAX_VALUE) | |
| 135 | + .build(); | |
| 140 | 136 | cluster.register(queryLogger); |
| 141 | 137 | String query = "SELECT c_text FROM test WHERE pk = 42"; |
| 142 | 138 | session.execute(query); |
| 143 | 139 | // then |
| 144 | 140 | String line = normalAppender.waitAndGet(10000); |
| 145 | 141 | assertThat(line) |
| 146 | - .contains("Query completed normally") | |
| 147 | - .contains(ipOfNode(1)) | |
| 148 | - .contains(query) | |
| 149 | - .doesNotContain("parameters"); | |
| 142 | + .contains("Query completed normally") | |
| 143 | + .contains(ipOfNode(1)) | |
| 144 | + .contains(query) | |
| 145 | + .doesNotContain("parameters"); | |
| 150 | 146 | } |
| 151 | 147 | |
| 152 | 148 | @Test(groups = "short") |
| @@ -154,8 +150,8 @@ | ||
| 154 | 150 | // given |
| 155 | 151 | normal.setLevel(DEBUG); |
| 156 | 152 | queryLogger = QueryLogger.builder(cluster) |
| 157 | - .withConstantThreshold(Long.MAX_VALUE) | |
| 158 | - .build(); | |
| 153 | + .withConstantThreshold(Long.MAX_VALUE) | |
| 154 | + .build(); | |
| 159 | 155 | cluster.register(queryLogger); |
| 160 | 156 | String query = "SELECT * FROM test where pk = ?"; |
| 161 | 157 | PreparedStatement ps = session.prepare(query); |
| @@ -164,21 +160,21 @@ | ||
| 164 | 160 | // then |
| 165 | 161 | String line = normalAppender.waitAndGet(10000); |
| 166 | 162 | assertThat(line) |
| 167 | - .contains("Query completed normally") | |
| 168 | - .contains(ipOfNode(1)) | |
| 169 | - .contains(query) | |
| 170 | - .doesNotContain("actual parameters"); | |
| 163 | + .contains("Query completed normally") | |
| 164 | + .contains(ipOfNode(1)) | |
| 165 | + .contains(query) | |
| 166 | + .doesNotContain("actual parameters"); | |
| 171 | 167 | } |
| 172 | 168 | |
| 173 | 169 | @Test(groups = "short") |
| 174 | - @CassandraVersion(major=2.0) | |
| 170 | + @CassandraVersion(major = 2.0) | |
| 175 | 171 | public void should_log_batch_statements() throws Exception { |
| 176 | 172 | // given |
| 177 | 173 | normal.setLevel(DEBUG); |
| 178 | 174 | queryLogger = QueryLogger.builder(cluster) |
| 179 | - .withConstantThreshold(Long.MAX_VALUE) | |
| 180 | - .withMaxQueryStringLength(Integer.MAX_VALUE) | |
| 181 | - .build(); | |
| 175 | + .withConstantThreshold(Long.MAX_VALUE) | |
| 176 | + .withMaxQueryStringLength(Integer.MAX_VALUE) | |
| 177 | + .build(); | |
| 182 | 178 | cluster.register(queryLogger); |
| 183 | 179 | // when |
| 184 | 180 | String query1 = "INSERT INTO test (pk) VALUES (?)"; |
| @@ -192,24 +188,24 @@ | ||
| 192 | 188 | // then |
| 193 | 189 | String line = normalAppender.waitAndGet(10000); |
| 194 | 190 | assertThat(line) |
| 195 | - .contains("Query completed normally") | |
| 196 | - .contains(ipOfNode(1)) | |
| 197 | - .contains("BEGIN BATCH") | |
| 198 | - .contains("APPLY BATCH") | |
| 199 | - .contains(query1) | |
| 200 | - .contains(query2) | |
| 201 | - .doesNotContain("c_int:"); | |
| 191 | + .contains("Query completed normally") | |
| 192 | + .contains(ipOfNode(1)) | |
| 193 | + .contains("BEGIN BATCH") | |
| 194 | + .contains("APPLY BATCH") | |
| 195 | + .contains(query1) | |
| 196 | + .contains(query2) | |
| 197 | + .doesNotContain("c_int:"); | |
| 202 | 198 | } |
| 203 | 199 | |
| 204 | 200 | @Test(groups = "short") |
| 205 | - @CassandraVersion(major=2.0) | |
| 201 | + @CassandraVersion(major = 2.0) | |
| 206 | 202 | public void should_log_unlogged_batch_statements() throws Exception { |
| 207 | 203 | // given |
| 208 | 204 | normal.setLevel(DEBUG); |
| 209 | 205 | queryLogger = QueryLogger.builder(cluster) |
| 210 | - .withConstantThreshold(Long.MAX_VALUE) | |
| 211 | - .withMaxQueryStringLength(Integer.MAX_VALUE) | |
| 212 | - .build(); | |
| 206 | + .withConstantThreshold(Long.MAX_VALUE) | |
| 207 | + .withMaxQueryStringLength(Integer.MAX_VALUE) | |
| 208 | + .build(); | |
| 213 | 209 | cluster.register(queryLogger); |
| 214 | 210 | // when |
| 215 | 211 | String query1 = "INSERT INTO test (pk) VALUES (?)"; |
| @@ -223,17 +219,17 @@ | ||
| 223 | 219 | // then |
| 224 | 220 | String line = normalAppender.waitAndGet(10000); |
| 225 | 221 | assertThat(line) |
| 226 | - .contains("Query completed normally") | |
| 227 | - .contains(ipOfNode(1)) | |
| 228 | - .contains("BEGIN UNLOGGED BATCH") | |
| 229 | - .contains("APPLY BATCH") | |
| 230 | - .contains(query1) | |
| 231 | - .contains(query2) | |
| 232 | - .doesNotContain("c_int:"); | |
| 222 | + .contains("Query completed normally") | |
| 223 | + .contains(ipOfNode(1)) | |
| 224 | + .contains("BEGIN UNLOGGED BATCH") | |
| 225 | + .contains("APPLY BATCH") | |
| 226 | + .contains(query1) | |
| 227 | + .contains(query2) | |
| 228 | + .doesNotContain("c_int:"); | |
| 233 | 229 | } |
| 234 | 230 | |
| 235 | 231 | @Test(groups = "short") |
| 236 | - @CassandraVersion(major=2.0) | |
| 232 | + @CassandraVersion(major = 2.0) | |
| 237 | 233 | public void should_log_counter_batch_statements() throws Exception { |
| 238 | 234 | // Create a special table for testing with counters. |
| 239 | 235 | session.execute( |
| @@ -276,6 +272,7 @@ | ||
| 276 | 272 | public ByteBuffer getRoutingKey() { |
| 277 | 273 | return null; |
| 278 | 274 | } |
| 275 | + | |
| 279 | 276 | @Override |
| 280 | 277 | public String getKeyspace() { |
| 281 | 278 | return null; |
| @@ -348,9 +345,9 @@ | ||
| 348 | 345 | // given |
| 349 | 346 | normal.setLevel(DEBUG); |
| 350 | 347 | queryLogger = QueryLogger.builder(cluster) |
| 351 | - .withConstantThreshold(Long.MAX_VALUE) | |
| 352 | - .withMaxQueryStringLength(Integer.MAX_VALUE) | |
| 353 | - .build(); | |
| 348 | + .withConstantThreshold(Long.MAX_VALUE) | |
| 349 | + .withMaxQueryStringLength(Integer.MAX_VALUE) | |
| 350 | + .build(); | |
| 354 | 351 | cluster.register(queryLogger); |
| 355 | 352 | // when |
| 356 | 353 | String query = "SELECT * FROM test where pk = ?"; |
| @@ -360,10 +357,10 @@ | ||
| 360 | 357 | // then |
| 361 | 358 | String line = normalAppender.waitAndGet(10000); |
| 362 | 359 | assertThat(line) |
| 363 | - .contains("Query completed normally") | |
| 364 | - .contains(ipOfNode(1)) | |
| 365 | - .contains(query) | |
| 366 | - .doesNotContain("pk:42"); | |
| 360 | + .contains("Query completed normally") | |
| 361 | + .contains(ipOfNode(1)) | |
| 362 | + .contains(query) | |
| 363 | + .doesNotContain("pk:42"); | |
| 367 | 364 | } |
| 368 | 365 | |
| 369 | 366 | // Tests for slow and error queries are in QueryLoggerErrorsTest |
| @@ -371,14 +368,14 @@ | ||
| 371 | 368 | // Tests with query parameters (log level TRACE) |
| 372 | 369 | |
| 373 | 370 | @Test(groups = "short") |
| 374 | - @CassandraVersion(major=2.0) | |
| 371 | + @CassandraVersion(major = 2.0) | |
| 375 | 372 | public void should_log_non_null_named_parameter() throws Exception { |
| 376 | 373 | // given |
| 377 | 374 | normal.setLevel(TRACE); |
| 378 | 375 | queryLogger = QueryLogger.builder(cluster) |
| 379 | - .withConstantThreshold(Long.MAX_VALUE) | |
| 380 | - .withMaxQueryStringLength(Integer.MAX_VALUE) | |
| 381 | - .build(); | |
| 376 | + .withConstantThreshold(Long.MAX_VALUE) | |
| 377 | + .withMaxQueryStringLength(Integer.MAX_VALUE) | |
| 378 | + .build(); | |
| 382 | 379 | cluster.register(queryLogger); |
| 383 | 380 | // when |
| 384 | 381 | String query = "UPDATE test SET c_text = :param1 WHERE pk = :param2"; |
| @@ -390,11 +387,11 @@ | ||
| 390 | 387 | // then |
| 391 | 388 | String line = normalAppender.waitAndGet(10000); |
| 392 | 389 | assertThat(line) |
| 393 | - .contains("Query completed normally") | |
| 394 | - .contains(ipOfNode(1)) | |
| 395 | - .contains(query) | |
| 396 | - .contains("param2:42") | |
| 397 | - .contains("param1:'foo'"); | |
| 390 | + .contains("Query completed normally") | |
| 391 | + .contains(ipOfNode(1)) | |
| 392 | + .contains(query) | |
| 393 | + .contains("param2:42") | |
| 394 | + .contains("param1:'foo'"); | |
| 398 | 395 | } |
| 399 | 396 | |
| 400 | 397 | @Test(groups = "short") |
| @@ -413,11 +410,11 @@ | ||
| 413 | 410 | // then |
| 414 | 411 | String line = normalAppender.waitAndGet(10000); |
| 415 | 412 | assertThat(line) |
| 416 | - .contains("Query completed normally") | |
| 417 | - .contains(ipOfNode(1)) | |
| 418 | - .contains(query) | |
| 419 | - .contains("pk:42") | |
| 420 | - .contains("c_text:'foo'"); | |
| 413 | + .contains("Query completed normally") | |
| 414 | + .contains(ipOfNode(1)) | |
| 415 | + .contains(query) | |
| 416 | + .contains("pk:42") | |
| 417 | + .contains("c_text:'foo'"); | |
| 421 | 418 | } |
| 422 | 419 | |
| 423 | 420 | @Test(groups = "short") |
| @@ -436,15 +433,15 @@ | ||
| 436 | 433 | // then |
| 437 | 434 | String line = normalAppender.waitAndGet(10000); |
| 438 | 435 | assertThat(line) |
| 439 | - .contains("Query completed normally") | |
| 440 | - .contains(ipOfNode(1)) | |
| 441 | - .contains(query) | |
| 442 | - .contains("pk:42") | |
| 443 | - .contains("c_text:NULL"); | |
| 436 | + .contains("Query completed normally") | |
| 437 | + .contains(ipOfNode(1)) | |
| 438 | + .contains(query) | |
| 439 | + .contains("pk:42") | |
| 440 | + .contains("c_text:NULL"); | |
| 444 | 441 | } |
| 445 | 442 | |
| 446 | 443 | @Test(groups = "short") |
| 447 | - @CassandraVersion(major=2.0) | |
| 444 | + @CassandraVersion(major = 2.0) | |
| 448 | 445 | public void should_log_bound_statement_parameters_inside_batch_statement() throws Exception { |
| 449 | 446 | // given |
| 450 | 447 | normal.setLevel(TRACE); |
| @@ -460,14 +457,14 @@ | ||
| 460 | 457 | // then |
| 461 | 458 | String line = normalAppender.waitAndGet(10000); |
| 462 | 459 | assertThat(line) |
| 463 | - .contains("Query completed normally") | |
| 464 | - .contains(ipOfNode(1)) | |
| 465 | - .contains(query1) | |
| 466 | - .contains(query2) | |
| 467 | - .contains("pk:42") | |
| 468 | - .contains("pk:43") | |
| 469 | - .contains("c_text:'foo'") | |
| 470 | - .contains("c_int:12345"); | |
| 460 | + .contains("Query completed normally") | |
| 461 | + .contains(ipOfNode(1)) | |
| 462 | + .contains(query1) | |
| 463 | + .contains(query2) | |
| 464 | + .contains("pk:42") | |
| 465 | + .contains("pk:43") | |
| 466 | + .contains("c_text:'foo'") | |
| 467 | + .contains("c_int:12345"); | |
| 471 | 468 | } |
| 472 | 469 | // Test different CQL types |
| 473 | 470 | |
| @@ -476,8 +473,8 @@ | ||
| 476 | 473 | // given |
| 477 | 474 | normal.setLevel(TRACE); |
| 478 | 475 | queryLogger = QueryLogger.builder(cluster) |
| 479 | - .withMaxParameterValueLength(Integer.MAX_VALUE) | |
| 480 | - .build(); | |
| 476 | + .withMaxParameterValueLength(Integer.MAX_VALUE) | |
| 477 | + .build(); | |
| 481 | 478 | cluster.register(queryLogger); |
| 482 | 479 | // when |
| 483 | 480 | String query = "UPDATE test SET " + assignments + " WHERE pk = 42"; |
| @@ -487,9 +484,9 @@ | ||
| 487 | 484 | // then |
| 488 | 485 | String line = normalAppender.waitAndGet(10000); |
| 489 | 486 | assertThat(line) |
| 490 | - .contains("Query completed normally") | |
| 491 | - .contains(ipOfNode(1)) | |
| 492 | - .contains(query); | |
| 487 | + .contains("Query completed normally") | |
| 488 | + .contains(ipOfNode(1)) | |
| 489 | + .contains(query); | |
| 493 | 490 | for (DataType type : dataTypes) { |
| 494 | 491 | assertThat(line).contains(type.format(getFixedValue(type))); |
| 495 | 492 | } |
| @@ -502,8 +499,8 @@ | ||
| 502 | 499 | // given |
| 503 | 500 | normal.setLevel(DEBUG); |
| 504 | 501 | queryLogger = QueryLogger.builder(cluster) |
| 505 | - .withMaxQueryStringLength(5) | |
| 506 | - .build(); | |
| 502 | + .withMaxQueryStringLength(5) | |
| 503 | + .build(); | |
| 507 | 504 | cluster.register(queryLogger); |
| 508 | 505 | // when |
| 509 | 506 | String query = "SELECT * FROM test WHERE pk = 42"; |
| @@ -511,20 +508,20 @@ | ||
| 511 | 508 | // then |
| 512 | 509 | String line = normalAppender.waitAndGet(10000); |
| 513 | 510 | assertThat(line) |
| 514 | - .contains("Query completed normally") | |
| 515 | - .contains(ipOfNode(1)) | |
| 516 | - .contains("SELEC" + TRUNCATED_OUTPUT) | |
| 517 | - .doesNotContain(query); | |
| 511 | + .contains("Query completed normally") | |
| 512 | + .contains(ipOfNode(1)) | |
| 513 | + .contains("SELEC" + TRUNCATED_OUTPUT) | |
| 514 | + .doesNotContain(query); | |
| 518 | 515 | } |
| 519 | 516 | |
| 520 | - @CassandraVersion(major=2.0) | |
| 517 | + @CassandraVersion(major = 2.0) | |
| 521 | 518 | @Test(groups = "short") |
| 522 | 519 | public void should_show_total_statements_for_batches_even_if_query_truncated() throws Exception { |
| 523 | 520 | // given |
| 524 | 521 | normal.setLevel(DEBUG); |
| 525 | 522 | queryLogger = QueryLogger.builder(cluster) |
| 526 | - .withMaxQueryStringLength(5) | |
| 527 | - .build(); | |
| 523 | + .withMaxQueryStringLength(5) | |
| 524 | + .build(); | |
| 528 | 525 | cluster.register(queryLogger); |
| 529 | 526 | // when |
| 530 | 527 | String query1 = "UPDATE test SET c_text = ? WHERE pk = ?"; |
| @@ -536,12 +533,12 @@ | ||
| 536 | 533 | // then |
| 537 | 534 | String line = normalAppender.waitAndGet(10000); |
| 538 | 535 | assertThat(line) |
| 539 | - .contains("Query completed normally") | |
| 540 | - .contains(ipOfNode(1)) | |
| 541 | - .contains("BEGIN" + TRUNCATED_OUTPUT) | |
| 542 | - .doesNotContain(query1) | |
| 543 | - .doesNotContain(query2) | |
| 544 | - .contains(" [2 statements"); | |
| 536 | + .contains("Query completed normally") | |
| 537 | + .contains(ipOfNode(1)) | |
| 538 | + .contains("BEGIN" + TRUNCATED_OUTPUT) | |
| 539 | + .doesNotContain(query1) | |
| 540 | + .doesNotContain(query2) | |
| 541 | + .contains(" [2 statements"); | |
| 545 | 542 | } |
| 546 | 543 | |
| 547 | 544 | @Test(groups = "short") |
| @@ -549,8 +546,8 @@ | ||
| 549 | 546 | // given |
| 550 | 547 | normal.setLevel(DEBUG); |
| 551 | 548 | queryLogger = QueryLogger.builder(cluster) |
| 552 | - .withMaxQueryStringLength(-1) | |
| 553 | - .build(); | |
| 549 | + .withMaxQueryStringLength(-1) | |
| 550 | + .build(); | |
| 554 | 551 | cluster.register(queryLogger); |
| 555 | 552 | // when |
| 556 | 553 | String query = "SELECT * FROM test WHERE pk = 42"; |
| @@ -558,20 +555,20 @@ | ||
| 558 | 555 | // then |
| 559 | 556 | String line = normalAppender.waitAndGet(10000); |
| 560 | 557 | assertThat(line) |
| 561 | - .contains("Query completed normally") | |
| 562 | - .contains(ipOfNode(1)) | |
| 563 | - .contains(query) | |
| 564 | - .doesNotContain(TRUNCATED_OUTPUT); | |
| 558 | + .contains("Query completed normally") | |
| 559 | + .contains(ipOfNode(1)) | |
| 560 | + .contains(query) | |
| 561 | + .doesNotContain(TRUNCATED_OUTPUT); | |
| 565 | 562 | } |
| 566 | 563 | |
| 567 | - @CassandraVersion(major=2.0) | |
| 564 | + @CassandraVersion(major = 2.0) | |
| 568 | 565 | @Test(groups = "short") |
| 569 | 566 | public void should_truncate_parameter_when_max_length_exceeded() throws Exception { |
| 570 | 567 | // given |
| 571 | 568 | normal.setLevel(TRACE); |
| 572 | 569 | queryLogger = QueryLogger.builder(cluster) |
| 573 | - .withMaxParameterValueLength(5) | |
| 574 | - .build(); | |
| 570 | + .withMaxParameterValueLength(5) | |
| 571 | + .build(); | |
| 575 | 572 | cluster.register(queryLogger); |
| 576 | 573 | // when |
| 577 | 574 | String query = "UPDATE test SET c_int = ? WHERE pk = ?"; |
| @@ -583,10 +580,10 @@ | ||
| 583 | 580 | // then |
| 584 | 581 | String line = normalAppender.waitAndGet(10000); |
| 585 | 582 | assertThat(line) |
| 586 | - .contains("Query completed normally") | |
| 587 | - .contains(ipOfNode(1)) | |
| 588 | - .contains("c_int:12345" + TRUNCATED_OUTPUT) | |
| 589 | - .doesNotContain("123456"); | |
| 583 | + .contains("Query completed normally") | |
| 584 | + .contains(ipOfNode(1)) | |
| 585 | + .contains("c_int:12345" + TRUNCATED_OUTPUT) | |
| 586 | + .doesNotContain("123456"); | |
| 590 | 587 | } |
| 591 | 588 | |
| 592 | 589 | @Test(groups = "short") |
| @@ -594,23 +591,23 @@ | ||
| 594 | 591 | // given |
| 595 | 592 | normal.setLevel(TRACE); |
| 596 | 593 | queryLogger = QueryLogger.builder(cluster) |
| 597 | - .withMaxParameterValueLength(6) | |
| 598 | - .build(); | |
| 594 | + .withMaxParameterValueLength(6) | |
| 595 | + .build(); | |
| 599 | 596 | cluster.register(queryLogger); |
| 600 | 597 | // when |
| 601 | 598 | String query = "UPDATE test SET c_blob = ? WHERE pk = ?"; |
| 602 | 599 | PreparedStatement ps = session.prepare(query); |
| 603 | 600 | BoundStatement bs = ps.bind(); |
| 604 | - bs.setBytes("c_blob", ByteBuffer.wrap(Bytes.toArray(Lists.newArrayList(1,2,3)))); | |
| 601 | + bs.setBytes("c_blob", ByteBuffer.wrap(Bytes.toArray(Lists.newArrayList(1, 2, 3)))); | |
| 605 | 602 | bs.setInt("pk", 42); |
| 606 | 603 | session.execute(bs); |
| 607 | 604 | // then |
| 608 | 605 | String line = normalAppender.waitAndGet(10000); |
| 609 | 606 | assertThat(line) |
| 610 | - .contains("Query completed normally") | |
| 611 | - .contains(ipOfNode(1)) | |
| 612 | - .contains("c_blob:0x0102" + TRUNCATED_OUTPUT) | |
| 613 | - .doesNotContain("123456"); | |
| 607 | + .contains("Query completed normally") | |
| 608 | + .contains(ipOfNode(1)) | |
| 609 | + .contains("c_blob:0x0102" + TRUNCATED_OUTPUT) | |
| 610 | + .doesNotContain("123456"); | |
| 614 | 611 | } |
| 615 | 612 | |
| 616 | 613 | @Test(groups = "short") |
| @@ -618,8 +615,8 @@ | ||
| 618 | 615 | // given |
| 619 | 616 | normal.setLevel(TRACE); |
| 620 | 617 | queryLogger = QueryLogger.builder(cluster) |
| 621 | - .withMaxParameterValueLength(-1) | |
| 622 | - .build(); | |
| 618 | + .withMaxParameterValueLength(-1) | |
| 619 | + .build(); | |
| 623 | 620 | cluster.register(queryLogger); |
| 624 | 621 | // when |
| 625 | 622 | String query = "UPDATE test SET c_int = ? WHERE pk = ?"; |
| @@ -631,10 +628,10 @@ | ||
| 631 | 628 | // then |
| 632 | 629 | String line = normalAppender.waitAndGet(10000); |
| 633 | 630 | assertThat(line) |
| 634 | - .contains("Query completed normally") | |
| 635 | - .contains(ipOfNode(1)) | |
| 636 | - .contains("c_int:123456") | |
| 637 | - .doesNotContain(TRUNCATED_OUTPUT); | |
| 631 | + .contains("Query completed normally") | |
| 632 | + .contains(ipOfNode(1)) | |
| 633 | + .contains("c_int:123456") | |
| 634 | + .doesNotContain(TRUNCATED_OUTPUT); | |
| 638 | 635 | } |
| 639 | 636 | |
| 640 | 637 | @Test(groups = "short") |
| @@ -642,8 +639,8 @@ | ||
| 642 | 639 | // given |
| 643 | 640 | normal.setLevel(TRACE); |
| 644 | 641 | queryLogger = QueryLogger.builder(cluster) |
| 645 | - .withMaxLoggedParameters(1) | |
| 646 | - .build(); | |
| 642 | + .withMaxLoggedParameters(1) | |
| 643 | + .build(); | |
| 647 | 644 | cluster.register(queryLogger); |
| 648 | 645 | // when |
| 649 | 646 | String query = "UPDATE test SET c_int = ? WHERE pk = ?"; |
| @@ -655,21 +652,21 @@ | ||
| 655 | 652 | // then |
| 656 | 653 | String line = normalAppender.waitAndGet(10000); |
| 657 | 654 | assertThat(line) |
| 658 | - .contains("Query completed normally") | |
| 659 | - .contains(ipOfNode(1)) | |
| 660 | - .contains("c_int:123456") | |
| 661 | - .doesNotContain("pk:42") | |
| 662 | - .contains(FURTHER_PARAMS_OMITTED); | |
| 655 | + .contains("Query completed normally") | |
| 656 | + .contains(ipOfNode(1)) | |
| 657 | + .contains("c_int:123456") | |
| 658 | + .doesNotContain("pk:42") | |
| 659 | + .contains(FURTHER_PARAMS_OMITTED); | |
| 663 | 660 | } |
| 664 | 661 | |
| 665 | 662 | @Test(groups = "short") |
| 666 | - @CassandraVersion(major=2.0) | |
| 663 | + @CassandraVersion(major = 2.0) | |
| 667 | 664 | public void should_not_log_exceeding_number_of_parameters_in_batch_statement() throws Exception { |
| 668 | 665 | // given |
| 669 | 666 | normal.setLevel(TRACE); |
| 670 | 667 | queryLogger = QueryLogger.builder(cluster) |
| 671 | - .withMaxLoggedParameters(1) | |
| 672 | - .build(); | |
| 668 | + .withMaxLoggedParameters(1) | |
| 669 | + .build(); | |
| 673 | 670 | cluster.register(queryLogger); |
| 674 | 671 | // when |
| 675 | 672 | String query1 = "UPDATE test SET c_text = ? WHERE pk = ?"; |
| @@ -681,15 +678,15 @@ | ||
| 681 | 678 | // then |
| 682 | 679 | String line = normalAppender.waitAndGet(10000); |
| 683 | 680 | assertThat(line) |
| 684 | - .contains("Query completed normally") | |
| 685 | - .contains(ipOfNode(1)) | |
| 686 | - .contains(query1) | |
| 687 | - .contains(query2) | |
| 688 | - .contains("c_text:'foo'") | |
| 689 | - .doesNotContain("pk:42") | |
| 690 | - .doesNotContain("c_int:12345") | |
| 691 | - .doesNotContain("pk:43") | |
| 692 | - .contains(FURTHER_PARAMS_OMITTED); | |
| 681 | + .contains("Query completed normally") | |
| 682 | + .contains(ipOfNode(1)) | |
| 683 | + .contains(query1) | |
| 684 | + .contains(query2) | |
| 685 | + .contains("c_text:'foo'") | |
| 686 | + .doesNotContain("pk:42") | |
| 687 | + .doesNotContain("c_int:12345") | |
| 688 | + .doesNotContain("pk:43") | |
| 689 | + .contains(FURTHER_PARAMS_OMITTED); | |
| 693 | 690 | } |
| 694 | 691 | |
| 695 | 692 | @Test(groups = "short") |
| @@ -697,8 +694,8 @@ | ||
| 697 | 694 | // given |
| 698 | 695 | normal.setLevel(TRACE); |
| 699 | 696 | queryLogger = QueryLogger.builder(cluster) |
| 700 | - .withMaxLoggedParameters(-1) | |
| 701 | - .build(); | |
| 697 | + .withMaxLoggedParameters(-1) | |
| 698 | + .build(); | |
| 702 | 699 | cluster.register(queryLogger); |
| 703 | 700 | // when |
| 704 | 701 | String query = "UPDATE test SET c_int = ? WHERE pk = ?"; |
| @@ -710,10 +707,10 @@ | ||
| 710 | 707 | // then |
| 711 | 708 | String line = normalAppender.waitAndGet(10000); |
| 712 | 709 | assertThat(line) |
| 713 | - .contains("Query completed normally") | |
| 714 | - .contains(ipOfNode(1)) | |
| 715 | - .contains("c_int:123456") | |
| 716 | - .contains("pk:42"); | |
| 710 | + .contains("Query completed normally") | |
| 711 | + .contains(ipOfNode(1)) | |
| 712 | + .contains("c_int:123456") | |
| 713 | + .contains("pk:42"); | |
| 717 | 714 | } |
| 718 | 715 | |
| 719 | 716 | @Override |
modified driver-core/src/test/java/com/datastax/driver/core/QueryOptionsTest.java +11 −10
| @@ -15,13 +15,14 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.util.List; | |
| 19 | -import java.util.concurrent.TimeUnit; | |
| 20 | - | |
| 21 | 18 | import com.google.common.collect.Lists; |
| 22 | -import org.scassandra.Scassandra; | |
| 23 | 19 | import org.scassandra.http.client.PreparedStatementPreparation; |
| 24 | -import org.testng.annotations.*; | |
| 20 | +import org.testng.annotations.AfterMethod; | |
| 21 | +import org.testng.annotations.BeforeMethod; | |
| 22 | +import org.testng.annotations.Test; | |
| 23 | + | |
| 24 | +import java.util.List; | |
| 25 | +import java.util.concurrent.TimeUnit; | |
| 25 | 26 | |
| 26 | 27 | import static com.datastax.driver.core.Assertions.assertThat; |
| 27 | 28 | import static com.datastax.driver.core.TestUtils.nonQuietClusterCloseOptions; |
| @@ -46,11 +47,11 @@ | ||
| 46 | 47 | queryOptions = new QueryOptions(); |
| 47 | 48 | loadBalancingPolicy = new SortingLoadBalancingPolicy(); |
| 48 | 49 | cluster = Cluster.builder() |
| 49 | - .addContactPoint(CCMBridge.ipOfNode(2)) | |
| 50 | - .withLoadBalancingPolicy(loadBalancingPolicy) | |
| 51 | - .withQueryOptions(queryOptions) | |
| 52 | - .withNettyOptions(nonQuietClusterCloseOptions) | |
| 53 | - .build(); | |
| 50 | + .addContactPoint(CCMBridge.ipOfNode(2)) | |
| 51 | + .withLoadBalancingPolicy(loadBalancingPolicy) | |
| 52 | + .withQueryOptions(queryOptions) | |
| 53 | + .withNettyOptions(nonQuietClusterCloseOptions) | |
| 54 | + .build(); | |
| 54 | 55 | |
| 55 | 56 | session = cluster.connect(); |
| 56 | 57 |
modified driver-core/src/test/java/com/datastax/driver/core/QueryTracker.java +11 −11
| @@ -15,17 +15,17 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | +import com.google.common.util.concurrent.Futures; | |
| 19 | +import com.google.common.util.concurrent.ListenableFuture; | |
| 20 | +import com.google.common.util.concurrent.Uninterruptibles; | |
| 21 | +import org.assertj.core.util.Maps; | |
| 22 | + | |
| 18 | 23 | import java.net.InetAddress; |
| 19 | 24 | import java.util.List; |
| 20 | 25 | import java.util.Map; |
| 21 | 26 | import java.util.concurrent.ExecutionException; |
| 22 | 27 | import java.util.concurrent.TimeUnit; |
| 23 | 28 | |
| 24 | -import com.google.common.util.concurrent.Futures; | |
| 25 | -import com.google.common.util.concurrent.ListenableFuture; | |
| 26 | -import com.google.common.util.concurrent.Uninterruptibles; | |
| 27 | -import org.assertj.core.util.Maps; | |
| 28 | - | |
| 29 | 29 | import static com.google.common.collect.Lists.newArrayList; |
| 30 | 30 | import static org.assertj.core.api.Assertions.assertThat; |
| 31 | 31 | import static org.testng.Assert.fail; |
| @@ -49,7 +49,7 @@ | ||
| 49 | 49 | |
| 50 | 50 | public void query(Session session, int times, ConsistencyLevel cl, Class<? extends Exception> expectedException) { |
| 51 | 51 | Statement statement = new SimpleStatement(QUERY); |
| 52 | - if(cl != null) { | |
| 52 | + if (cl != null) { | |
| 53 | 53 | statement.setConsistencyLevel(cl); |
| 54 | 54 | } |
| 55 | 55 | |
| @@ -63,20 +63,20 @@ | ||
| 63 | 63 | public void query(Session session, int times, Statement statement, Class<? extends Exception> expectedException) { |
| 64 | 64 | List<ListenableFuture<ResultSet>> futures = newArrayList(); |
| 65 | 65 | |
| 66 | - for(int i = 0; i < times; i++) { | |
| 66 | + for (int i = 0; i < times; i++) { | |
| 67 | 67 | futures.add(session.executeAsync(statement)); |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | try { |
| 71 | 71 | List<ResultSet> results = Uninterruptibles.getUninterruptibly(Futures.allAsList(futures), 1, TimeUnit.MINUTES); |
| 72 | - for(ResultSet result : results) { | |
| 72 | + for (ResultSet result : results) { | |
| 73 | 73 | InetAddress coordinator = result.getExecutionInfo().getQueriedHost().getAddress(); |
| 74 | 74 | Integer n = coordinators.get(coordinator); |
| 75 | 75 | coordinators.put(coordinator, n == null ? 1 : n + 1); |
| 76 | 76 | } |
| 77 | 77 | } catch (ExecutionException ex) { |
| 78 | 78 | Throwable cause = ex.getCause(); |
| 79 | - if(expectedException == null) { | |
| 79 | + if (expectedException == null) { | |
| 80 | 80 | fail("Queries failed", ex); |
| 81 | 81 | } else { |
| 82 | 82 | assertThat(cause).isInstanceOf(expectedException); |
| @@ -99,8 +99,8 @@ | ||
| 99 | 99 | public void assertQueried(ScassandraCluster sCluster, int dc, int node, int n) { |
| 100 | 100 | int queryCount = queryCount(sCluster, dc, node); |
| 101 | 101 | assertThat(queryCount) |
| 102 | - .as("Expected node %d:%d to be queried %d times but was %d", dc, node, n, queryCount) | |
| 103 | - .isEqualTo(n); | |
| 102 | + .as("Expected node %d:%d to be queried %d times but was %d", dc, node, n, queryCount) | |
| 103 | + .isEqualTo(n); | |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | public void reset() { |
modified driver-core/src/test/java/com/datastax/driver/core/RPTokenFactoryTest.java +15 −16
| @@ -15,12 +15,11 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.util.List; | |
| 19 | - | |
| 20 | 18 | import org.testng.annotations.Test; |
| 21 | 19 | |
| 20 | +import java.util.List; | |
| 21 | + | |
| 22 | 22 | import static org.assertj.core.api.Assertions.assertThat; |
| 23 | -import static org.testng.Assert.fail; | |
| 24 | 23 | |
| 25 | 24 | public class RPTokenFactoryTest { |
| 26 | 25 | Token.Factory factory = Token.RPToken.FACTORY; |
| @@ -29,21 +28,21 @@ | ||
| 29 | 28 | public void should_split_range() { |
| 30 | 29 | List<Token> splits = factory.split(factory.fromString("0"), factory.fromString("127605887595351923798765477786913079296"), 3); |
| 31 | 30 | assertThat(splits).containsExactly( |
| 32 | - factory.fromString("42535295865117307932921825928971026432"), | |
| 33 | - factory.fromString("85070591730234615865843651857942052864") | |
| 31 | + factory.fromString("42535295865117307932921825928971026432"), | |
| 32 | + factory.fromString("85070591730234615865843651857942052864") | |
| 34 | 33 | ); |
| 35 | 34 | } |
| 36 | 35 | |
| 37 | 36 | @Test(groups = "unit") |
| 38 | 37 | public void should_split_range_that_wraps_around_the_ring() { |
| 39 | 38 | List<Token> splits = factory.split( |
| 40 | - factory.fromString("127605887595351923798765477786913079296"), | |
| 41 | - factory.fromString("85070591730234615865843651857942052864"), | |
| 42 | - 3); | |
| 39 | + factory.fromString("127605887595351923798765477786913079296"), | |
| 40 | + factory.fromString("85070591730234615865843651857942052864"), | |
| 41 | + 3); | |
| 43 | 42 | |
| 44 | 43 | assertThat(splits).containsExactly( |
| 45 | - factory.fromString("0"), | |
| 46 | - factory.fromString("42535295865117307932921825928971026432") | |
| 44 | + factory.fromString("0"), | |
| 45 | + factory.fromString("42535295865117307932921825928971026432") | |
| 47 | 46 | ); |
| 48 | 47 | } |
| 49 | 48 | |
| @@ -55,14 +54,14 @@ | ||
| 55 | 54 | // These are edge cases where we want to make sure we don't accidentally generate the ]min,min] range (which is the whole ring) |
| 56 | 55 | List<Token> splits = factory.split(maxToken, minToken, 3); |
| 57 | 56 | assertThat(splits).containsExactly( |
| 58 | - maxToken, | |
| 59 | - maxToken | |
| 57 | + maxToken, | |
| 58 | + maxToken | |
| 60 | 59 | ); |
| 61 | 60 | |
| 62 | 61 | splits = factory.split(minToken, factory.fromString("0"), 3); |
| 63 | 62 | assertThat(splits).containsExactly( |
| 64 | - factory.fromString("0"), | |
| 65 | - factory.fromString("0") | |
| 63 | + factory.fromString("0"), | |
| 64 | + factory.fromString("0") | |
| 66 | 65 | ); |
| 67 | 66 | } |
| 68 | 67 | |
| @@ -70,8 +69,8 @@ | ||
| 70 | 69 | public void should_split_whole_ring() { |
| 71 | 70 | List<Token> splits = factory.split(factory.fromString("-1"), factory.fromString("-1"), 3); |
| 72 | 71 | assertThat(splits).containsExactly( |
| 73 | - factory.fromString("56713727820156410577229101238628035242"), | |
| 74 | - factory.fromString("113427455640312821154458202477256070485") | |
| 72 | + factory.fromString("56713727820156410577229101238628035242"), | |
| 73 | + factory.fromString("113427455640312821154458202477256070485") | |
| 75 | 74 | ); |
| 76 | 75 | } |
| 77 | 76 | } |
modified driver-core/src/test/java/com/datastax/driver/core/RPTokenIntegrationTest.java +2 −1
| @@ -22,7 +22,8 @@ | ||
| 22 | 22 | super("-p RandomPartitioner", DataType.varint()); |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | - @Override protected Token.Factory tokenFactory() { | |
| 25 | + @Override | |
| 26 | + protected Token.Factory tokenFactory() { | |
| 26 | 27 | return RPToken.FACTORY; |
| 27 | 28 | } |
| 28 | 29 | } |
modified driver-core/src/test/java/com/datastax/driver/core/RPTokenVnodeIntegrationTest.java +2 −1
| @@ -20,7 +20,8 @@ | ||
| 20 | 20 | super("-p RandomPartitioner", DataType.varint(), true); |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | - @Override protected Token.Factory tokenFactory() { | |
| 23 | + @Override | |
| 24 | + protected Token.Factory tokenFactory() { | |
| 24 | 25 | return Token.RPToken.FACTORY; |
| 25 | 26 | } |
| 26 | 27 | } |
modified driver-core/src/test/java/com/datastax/driver/core/RecommissionedNodeTest.java +17 −18
| @@ -15,25 +15,24 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.util.concurrent.TimeUnit; | |
| 19 | - | |
| 18 | +import com.datastax.driver.core.utils.CassandraVersion; | |
| 20 | 19 | import org.slf4j.Logger; |
| 21 | 20 | import org.slf4j.LoggerFactory; |
| 22 | 21 | import org.testng.annotations.AfterMethod; |
| 23 | 22 | import org.testng.annotations.BeforeMethod; |
| 24 | 23 | import org.testng.annotations.Test; |
| 25 | 24 | |
| 25 | +import java.util.concurrent.TimeUnit; | |
| 26 | 26 | |
| 27 | -import com.datastax.driver.core.utils.CassandraVersion; | |
| 28 | - | |
| 29 | -import static com.datastax.driver.core.Assertions.*; | |
| 27 | +import static com.datastax.driver.core.Assertions.assertThat; | |
| 28 | +import static com.datastax.driver.core.Assertions.fail; | |
| 30 | 29 | import static com.datastax.driver.core.Host.State.DOWN; |
| 31 | 30 | import static com.datastax.driver.core.Host.State.UP; |
| 32 | 31 | import static com.datastax.driver.core.TestUtils.nonDebouncingQueryOptions; |
| 33 | 32 | |
| 34 | 33 | /** |
| 35 | 34 | * Due to C* gossip bugs, system.peers may report nodes that are gone from the cluster. |
| 36 | - * | |
| 35 | + * <p/> | |
| 37 | 36 | * This class tests scenarios where these nodes have been recommissioned to another cluster and |
| 38 | 37 | * come back up. The driver must detect that they are not part of the cluster anymore, and ignore them. |
| 39 | 38 | */ |
| @@ -52,7 +51,7 @@ | ||
| 52 | 51 | |
| 53 | 52 | // Now start the driver that will connect to node2 and node3, and consider node1 down |
| 54 | 53 | mainCluster = Cluster.builder().addContactPoint(CCMBridge.IP_PREFIX + "2") |
| 55 | - .withQueryOptions(nonDebouncingQueryOptions()).build(); | |
| 54 | + .withQueryOptions(nonDebouncingQueryOptions()).build(); | |
| 56 | 55 | mainCluster.connect(); |
| 57 | 56 | waitForCountUpHosts(mainCluster, 2); |
| 58 | 57 | // From that point, reconnections to node1 have been scheduled. |
| @@ -75,7 +74,7 @@ | ||
| 75 | 74 | |
| 76 | 75 | // Start the driver, the control connection will be on node2 |
| 77 | 76 | mainCluster = Cluster.builder().addContactPoint(CCMBridge.IP_PREFIX + "2") |
| 78 | - .withQueryOptions(nonDebouncingQueryOptions()).build(); | |
| 77 | + .withQueryOptions(nonDebouncingQueryOptions()).build(); | |
| 79 | 78 | mainCluster.connect(); |
| 80 | 79 | waitForCountUpHosts(mainCluster, 1); |
| 81 | 80 | |
| @@ -103,7 +102,7 @@ | ||
| 103 | 102 | |
| 104 | 103 | // Start the driver, it should only connect to node 2 |
| 105 | 104 | mainCluster = Cluster.builder().addContactPoint(CCMBridge.IP_PREFIX + "2") |
| 106 | - .withQueryOptions(nonDebouncingQueryOptions()).build(); | |
| 105 | + .withQueryOptions(nonDebouncingQueryOptions()).build(); | |
| 107 | 106 | |
| 108 | 107 | // When we first initialize the Cluster, all hosts are marked UP |
| 109 | 108 | assertThat(mainCluster).host(2).hasState(UP); |
| @@ -114,13 +113,13 @@ | ||
| 114 | 113 | |
| 115 | 114 | // Node 1 should now be DOWN with no reconnection attempt |
| 116 | 115 | assertThat(mainCluster).host(1) |
| 117 | - .goesDownWithin(10, TimeUnit.SECONDS) | |
| 118 | - .hasState(DOWN) | |
| 119 | - .isNotReconnectingFromDown(); | |
| 116 | + .goesDownWithin(10, TimeUnit.SECONDS) | |
| 117 | + .hasState(DOWN) | |
| 118 | + .isNotReconnectingFromDown(); | |
| 120 | 119 | } |
| 121 | 120 | |
| 122 | 121 | @Test(groups = "long") |
| 123 | - @CassandraVersion(major=2.0) | |
| 122 | + @CassandraVersion(major = 2.0) | |
| 124 | 123 | public void should_ignore_node_that_does_not_support_protocol_version_on_session_init() throws Exception { |
| 125 | 124 | // Simulate the bug before starting the cluster |
| 126 | 125 | mainCcm = CCMBridge.builder("main").withNodes(2).build(); |
| @@ -132,16 +131,16 @@ | ||
| 132 | 131 | |
| 133 | 132 | // Start the driver, it should only connect to node 2 |
| 134 | 133 | mainCluster = Cluster.builder().addContactPoint(CCMBridge.IP_PREFIX + "2") |
| 135 | - .withQueryOptions(nonDebouncingQueryOptions()).build(); | |
| 134 | + .withQueryOptions(nonDebouncingQueryOptions()).build(); | |
| 136 | 135 | |
| 137 | 136 | // Create a session. This will try to open a pool to node 1 and find that it doesn't support protocol version. |
| 138 | 137 | mainCluster.connect(); |
| 139 | 138 | |
| 140 | 139 | // Node 1 should now be DOWN with no reconnection attempt |
| 141 | 140 | assertThat(mainCluster).host(1) |
| 142 | - .goesDownWithin(10, TimeUnit.SECONDS) | |
| 143 | - .hasState(DOWN) | |
| 144 | - .isNotReconnectingFromDown(); | |
| 141 | + .goesDownWithin(10, TimeUnit.SECONDS) | |
| 142 | + .hasState(DOWN) | |
| 143 | + .isNotReconnectingFromDown(); | |
| 145 | 144 | } |
| 146 | 145 | |
| 147 | 146 | @BeforeMethod(groups = "long") |
| @@ -183,7 +182,7 @@ | ||
| 183 | 182 | |
| 184 | 183 | if (i == maxRetries) |
| 185 | 184 | fail(String.format("Up host count didn't reach %d after %d seconds", |
| 186 | - expectedCount, i * interval)); | |
| 185 | + expectedCount, i * interval)); | |
| 187 | 186 | else |
| 188 | 187 | logger.debug("Counted {} up hosts after {} seconds", actualCount, i * interval); |
| 189 | 188 |
modified driver-core/src/test/java/com/datastax/driver/core/ReconnectionPolicyTest.java +18 −11
| @@ -15,14 +15,14 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import org.testng.annotations.Test; | |
| 19 | -import static org.testng.Assert.assertTrue; | |
| 20 | -import static org.testng.Assert.fail; | |
| 21 | - | |
| 22 | 18 | import com.datastax.driver.core.exceptions.NoHostAvailableException; |
| 23 | 19 | import com.datastax.driver.core.policies.ConstantReconnectionPolicy; |
| 24 | 20 | import com.datastax.driver.core.policies.ExponentialReconnectionPolicy; |
| 25 | 21 | import com.datastax.driver.core.policies.ReconnectionPolicy; |
| 22 | +import org.testng.annotations.Test; | |
| 23 | + | |
| 24 | +import static org.testng.Assert.assertTrue; | |
| 25 | +import static org.testng.Assert.fail; | |
| 26 | 26 | |
| 27 | 27 | public class ReconnectionPolicyTest extends AbstractPoliciesTest { |
| 28 | 28 | |
| @@ -47,22 +47,26 @@ | ||
| 47 | 47 | try { |
| 48 | 48 | new ExponentialReconnectionPolicy(-1, 1); |
| 49 | 49 | fail(); |
| 50 | - } catch (IllegalArgumentException e) {} | |
| 50 | + } catch (IllegalArgumentException e) { | |
| 51 | + } | |
| 51 | 52 | |
| 52 | 53 | try { |
| 53 | 54 | new ExponentialReconnectionPolicy(1, -1); |
| 54 | 55 | fail(); |
| 55 | - } catch (IllegalArgumentException e) {} | |
| 56 | + } catch (IllegalArgumentException e) { | |
| 57 | + } | |
| 56 | 58 | |
| 57 | 59 | try { |
| 58 | 60 | new ExponentialReconnectionPolicy(-1, -1); |
| 59 | 61 | fail(); |
| 60 | - } catch (IllegalArgumentException e) {} | |
| 62 | + } catch (IllegalArgumentException e) { | |
| 63 | + } | |
| 61 | 64 | |
| 62 | 65 | try { |
| 63 | 66 | new ExponentialReconnectionPolicy(2, 1); |
| 64 | 67 | fail(); |
| 65 | - } catch (IllegalArgumentException e) {} | |
| 68 | + } catch (IllegalArgumentException e) { | |
| 69 | + } | |
| 66 | 70 | |
| 67 | 71 | // Test nextDelays() |
| 68 | 72 | ReconnectionPolicy.ReconnectionSchedule schedule = new ExponentialReconnectionPolicy(2 * 1000, 5 * 60 * 1000).newSchedule(); |
| @@ -104,7 +108,8 @@ | ||
| 104 | 108 | try { |
| 105 | 109 | new ConstantReconnectionPolicy(-1); |
| 106 | 110 | fail(); |
| 107 | - } catch (IllegalArgumentException e) {} | |
| 111 | + } catch (IllegalArgumentException e) { | |
| 112 | + } | |
| 108 | 113 | |
| 109 | 114 | // Test nextDelays() |
| 110 | 115 | ReconnectionPolicy.ReconnectionSchedule schedule = new ConstantReconnectionPolicy(10 * 1000).newSchedule(); |
| @@ -142,7 +147,8 @@ | ||
| 142 | 147 | startTime = System.nanoTime() / 1000000000; |
| 143 | 148 | query(c, 12); |
| 144 | 149 | fail("Test race condition where node has not shut off quickly enough."); |
| 145 | - } catch (NoHostAvailableException e) {} | |
| 150 | + } catch (NoHostAvailableException e) { | |
| 151 | + } | |
| 146 | 152 | |
| 147 | 153 | long thisTime; |
| 148 | 154 | boolean restarted = false; |
| @@ -184,7 +190,8 @@ | ||
| 184 | 190 | startTime = System.nanoTime() / 1000000000; |
| 185 | 191 | query(c, 12); |
| 186 | 192 | fail("Test race condition where node has not shut off quickly enough."); |
| 187 | - } catch (NoHostAvailableException e) {} | |
| 193 | + } catch (NoHostAvailableException e) { | |
| 194 | + } | |
| 188 | 195 | |
| 189 | 196 | restarted = false; |
| 190 | 197 | while (true) { |
modified driver-core/src/test/java/com/datastax/driver/core/ReconnectionTest.java +44 −45
| @@ -15,6 +15,14 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.Host.State; | |
| 19 | +import com.datastax.driver.core.policies.ConstantReconnectionPolicy; | |
| 20 | +import com.datastax.driver.core.policies.DelegatingLoadBalancingPolicy; | |
| 21 | +import com.datastax.driver.core.policies.LoadBalancingPolicy; | |
| 22 | +import com.datastax.driver.core.policies.RoundRobinPolicy; | |
| 23 | +import com.google.common.util.concurrent.ListenableFuture; | |
| 24 | +import org.testng.annotations.Test; | |
| 25 | + | |
| 18 | 26 | import java.io.IOException; |
| 19 | 27 | import java.net.InetSocketAddress; |
| 20 | 28 | import java.util.Collections; |
| @@ -24,21 +32,10 @@ | ||
| 24 | 32 | import java.util.concurrent.TimeUnit; |
| 25 | 33 | import java.util.concurrent.atomic.AtomicInteger; |
| 26 | 34 | |
| 35 | +import static com.datastax.driver.core.Assertions.assertThat; | |
| 27 | 36 | import static java.util.concurrent.TimeUnit.SECONDS; |
| 28 | - | |
| 29 | -import com.google.common.util.concurrent.ListenableFuture; | |
| 30 | -import org.testng.annotations.Test; | |
| 31 | - | |
| 32 | 37 | import static org.assertj.core.api.Assertions.assertThat; |
| 33 | -import static org.mockito.Mockito.reset; | |
| 34 | -import static org.mockito.Mockito.spy; | |
| 35 | -import static org.mockito.Mockito.times; | |
| 36 | -import static org.mockito.Mockito.verify; | |
| 37 | - | |
| 38 | -import com.datastax.driver.core.Host.State; | |
| 39 | -import com.datastax.driver.core.policies.*; | |
| 40 | - | |
| 41 | -import static com.datastax.driver.core.Assertions.assertThat; | |
| 38 | +import static org.mockito.Mockito.*; | |
| 42 | 39 | |
| 43 | 40 | /** |
| 44 | 41 | * Scenarios where a Cluster loses connection to a host and reconnects. |
| @@ -53,9 +50,9 @@ | ||
| 53 | 50 | ccm = CCMBridge.builder("test").withNodes(2).build(); |
| 54 | 51 | int reconnectionDelay = 1000; |
| 55 | 52 | cluster = Cluster.builder() |
| 56 | - .addContactPoint(CCMBridge.ipOfNode(1)) | |
| 57 | - .withReconnectionPolicy(new ConstantReconnectionPolicy(reconnectionDelay)) | |
| 58 | - .build(); | |
| 53 | + .addContactPoint(CCMBridge.ipOfNode(1)) | |
| 54 | + .withReconnectionPolicy(new ConstantReconnectionPolicy(reconnectionDelay)) | |
| 55 | + .build(); | |
| 59 | 56 | cluster.connect(); |
| 60 | 57 | |
| 61 | 58 | assertThat(cluster).usesControlHost(1); |
| @@ -69,7 +66,7 @@ | ||
| 69 | 66 | ccm.start(2); |
| 70 | 67 | ccm.waitForUp(2); |
| 71 | 68 | |
| 72 | - assertThat(cluster).host(2).comesUpWithin(Cluster.NEW_NODE_DELAY_SECONDS*2, SECONDS); | |
| 69 | + assertThat(cluster).host(2).comesUpWithin(Cluster.NEW_NODE_DELAY_SECONDS * 2, SECONDS); | |
| 73 | 70 | |
| 74 | 71 | // Give the control connection a few moments to reconnect |
| 75 | 72 | TimeUnit.MILLISECONDS.sleep(reconnectionDelay * 2); |
| @@ -88,9 +85,9 @@ | ||
| 88 | 85 | Cluster cluster = null; |
| 89 | 86 | try { |
| 90 | 87 | ccm = CCMBridge.builder("test") |
| 91 | - .withCassandraConfiguration("authenticator", "PasswordAuthenticator") // default credentials: cassandra / cassandra | |
| 92 | - .notStarted() | |
| 93 | - .build(); | |
| 88 | + .withCassandraConfiguration("authenticator", "PasswordAuthenticator") // default credentials: cassandra / cassandra | |
| 89 | + .notStarted() | |
| 90 | + .build(); | |
| 94 | 91 | ccm.start(1, "-Dcassandra.superuser_setup_delay_ms=0"); |
| 95 | 92 | |
| 96 | 93 | CountingAuthProvider authProvider = new CountingAuthProvider("cassandra", "cassandra"); |
| @@ -98,11 +95,11 @@ | ||
| 98 | 95 | CountingReconnectionPolicy reconnectionPolicy = new CountingReconnectionPolicy(new ConstantReconnectionPolicy(reconnectionDelayMs)); |
| 99 | 96 | |
| 100 | 97 | cluster = Cluster.builder() |
| 101 | - .addContactPoint(CCMBridge.ipOfNode(1)) | |
| 102 | - // Start with the correct auth so that we can initialize the server | |
| 103 | - .withAuthProvider(authProvider) | |
| 104 | - .withReconnectionPolicy(reconnectionPolicy) | |
| 105 | - .build(); | |
| 98 | + .addContactPoint(CCMBridge.ipOfNode(1)) | |
| 99 | + // Start with the correct auth so that we can initialize the server | |
| 100 | + .withAuthProvider(authProvider) | |
| 101 | + .withReconnectionPolicy(reconnectionPolicy) | |
| 102 | + .build(); | |
| 106 | 103 | |
| 107 | 104 | cluster.init(); |
| 108 | 105 | assertThat(cluster).usesControlHost(1); |
| @@ -128,7 +125,7 @@ | ||
| 128 | 125 | authProvider.setPassword("cassandra"); |
| 129 | 126 | |
| 130 | 127 | // The driver should eventually reconnect to the node |
| 131 | - assertThat(cluster).host(1).comesUpWithin(Cluster.NEW_NODE_DELAY_SECONDS*2, SECONDS); | |
| 128 | + assertThat(cluster).host(1).comesUpWithin(Cluster.NEW_NODE_DELAY_SECONDS * 2, SECONDS); | |
| 132 | 129 | } finally { |
| 133 | 130 | if (cluster != null) |
| 134 | 131 | cluster.close(); |
| @@ -148,9 +145,9 @@ | ||
| 148 | 145 | try { |
| 149 | 146 | ccm = CCMBridge.builder("test").withNodes(2).build(); |
| 150 | 147 | cluster = Cluster.builder() |
| 151 | - .addContactPoint(CCMBridge.ipOfNode(1)) | |
| 152 | - .withReconnectionPolicy(reconnectionPolicy) | |
| 153 | - .build(); | |
| 148 | + .addContactPoint(CCMBridge.ipOfNode(1)) | |
| 149 | + .withReconnectionPolicy(reconnectionPolicy) | |
| 150 | + .build(); | |
| 154 | 151 | cluster.connect(); |
| 155 | 152 | |
| 156 | 153 | // Stop a node and cancel the reconnection attempts to it |
| @@ -168,7 +165,7 @@ | ||
| 168 | 165 | ccm.waitForUp(2); |
| 169 | 166 | |
| 170 | 167 | // The driver should now see the node as UP again |
| 171 | - assertThat(cluster).host(2).comesUpWithin(Cluster.NEW_NODE_DELAY_SECONDS*2, SECONDS); | |
| 168 | + assertThat(cluster).host(2).comesUpWithin(Cluster.NEW_NODE_DELAY_SECONDS * 2, SECONDS); | |
| 172 | 169 | |
| 173 | 170 | } finally { |
| 174 | 171 | if (cluster != null) |
| @@ -189,10 +186,10 @@ | ||
| 189 | 186 | try { |
| 190 | 187 | ccm = CCMBridge.builder("test").withNodes(1).build(); |
| 191 | 188 | cluster = Cluster.builder() |
| 192 | - .addContactPoint(CCMBridge.ipOfNode(1)) | |
| 193 | - .withLoadBalancingPolicy(loadBalancingPolicy) | |
| 194 | - .withReconnectionPolicy(new ConstantReconnectionPolicy(reconnectionDelayMillis)) | |
| 195 | - .build(); | |
| 189 | + .addContactPoint(CCMBridge.ipOfNode(1)) | |
| 190 | + .withLoadBalancingPolicy(loadBalancingPolicy) | |
| 191 | + .withReconnectionPolicy(new ConstantReconnectionPolicy(reconnectionDelayMillis)) | |
| 192 | + .build(); | |
| 196 | 193 | cluster.connect(); |
| 197 | 194 | |
| 198 | 195 | // Tweak the LBP so that the control connection never reconnects, otherwise |
| @@ -229,7 +226,7 @@ | ||
| 229 | 226 | // Trigger another one-time reconnection attempt (this will succeed). The |
| 230 | 227 | // host should be back up. |
| 231 | 228 | host1.tryReconnectOnce(); |
| 232 | - assertThat(cluster).host(1).comesUpWithin(Cluster.NEW_NODE_DELAY_SECONDS*2, SECONDS); | |
| 229 | + assertThat(cluster).host(1).comesUpWithin(Cluster.NEW_NODE_DELAY_SECONDS * 2, SECONDS); | |
| 233 | 230 | } finally { |
| 234 | 231 | if (cluster != null) |
| 235 | 232 | cluster.close(); |
| @@ -255,12 +252,12 @@ | ||
| 255 | 252 | try { |
| 256 | 253 | ccm = CCMBridge.builder("test").withNodes(1).build(); |
| 257 | 254 | cluster = Cluster.builder() |
| 258 | - .addContactPoint(CCMBridge.ipOfNode(1)) | |
| 259 | - .withReconnectionPolicy(new ConstantReconnectionPolicy(5000)) | |
| 260 | - .withLoadBalancingPolicy(loadBalancingPolicy) | |
| 261 | - .withSocketOptions(socketOptions) | |
| 262 | - .withProtocolVersion(TestUtils.getDesiredProtocolVersion()) | |
| 263 | - .build(); | |
| 255 | + .addContactPoint(CCMBridge.ipOfNode(1)) | |
| 256 | + .withReconnectionPolicy(new ConstantReconnectionPolicy(5000)) | |
| 257 | + .withLoadBalancingPolicy(loadBalancingPolicy) | |
| 258 | + .withSocketOptions(socketOptions) | |
| 259 | + .withProtocolVersion(TestUtils.getDesiredProtocolVersion()) | |
| 260 | + .build(); | |
| 264 | 261 | // Create two sessions to have multiple pools |
| 265 | 262 | cluster.connect(); |
| 266 | 263 | cluster.connect(); |
| @@ -285,7 +282,7 @@ | ||
| 285 | 282 | // Reset the spy and count the number of connections attempts for 1 reconnect |
| 286 | 283 | reset(socketOptions); |
| 287 | 284 | host1.tryReconnectOnce(); |
| 288 | - assertThat(cluster).host(1).comesUpWithin(Cluster.NEW_NODE_DELAY_SECONDS*2, SECONDS); | |
| 285 | + assertThat(cluster).host(1).comesUpWithin(Cluster.NEW_NODE_DELAY_SECONDS * 2, SECONDS); | |
| 289 | 286 | // Expect 1 connection from the reconnection attempt 3 for the pools (we need 4 |
| 290 | 287 | // but the one from the reconnection attempt gets reused). |
| 291 | 288 | verify(socketOptions, times(4)).getKeepAlive(); |
| @@ -297,7 +294,9 @@ | ||
| 297 | 294 | } |
| 298 | 295 | } |
| 299 | 296 | |
| 300 | - /** Extends the plain text auth provider to track how many times the credentials have been requested */ | |
| 297 | + /** | |
| 298 | + * Extends the plain text auth provider to track how many times the credentials have been requested | |
| 299 | + */ | |
| 301 | 300 | static class CountingAuthProvider extends PlainTextAuthProvider { |
| 302 | 301 | final AtomicInteger count = new AtomicInteger(); |
| 303 | 302 | |
| @@ -330,8 +329,8 @@ | ||
| 330 | 329 | public HostDistance distance(Host host) { |
| 331 | 330 | HostDistance distance = distances.get(host); |
| 332 | 331 | return (distance != null) |
| 333 | - ? distance | |
| 334 | - : super.distance(host); | |
| 332 | + ? distance | |
| 333 | + : super.distance(host); | |
| 335 | 334 | } |
| 336 | 335 | |
| 337 | 336 | public void setDistance(Host host, HostDistance distance) { |
modified driver-core/src/test/java/com/datastax/driver/core/RefreshConnectedHostTest.java +25 −27
| @@ -15,17 +15,15 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import static java.util.concurrent.TimeUnit.SECONDS; | |
| 19 | - | |
| 20 | -import org.mockito.Mockito; | |
| 21 | -import org.testng.annotations.Test; | |
| 22 | - | |
| 23 | 18 | import com.datastax.driver.core.Host.State; |
| 24 | 19 | import com.datastax.driver.core.policies.ConstantReconnectionPolicy; |
| 25 | 20 | import com.datastax.driver.core.policies.LimitingLoadBalancingPolicy; |
| 26 | 21 | import com.datastax.driver.core.policies.RoundRobinPolicy; |
| 22 | +import org.mockito.Mockito; | |
| 23 | +import org.testng.annotations.Test; | |
| 27 | 24 | |
| 28 | 25 | import static com.datastax.driver.core.Assertions.assertThat; |
| 26 | +import static java.util.concurrent.TimeUnit.SECONDS; | |
| 29 | 27 | |
| 30 | 28 | public class RefreshConnectedHostTest { |
| 31 | 29 | |
| @@ -49,40 +47,40 @@ | ||
| 49 | 47 | |
| 50 | 48 | PoolingOptions poolingOptions = Mockito.spy(new PoolingOptions()); |
| 51 | 49 | cluster = Cluster.builder() |
| 52 | - .addContactPoint(CCMBridge.ipOfNode(1)) | |
| 53 | - .withPoolingOptions(poolingOptions) | |
| 54 | - .withLoadBalancingPolicy(loadBalancingPolicy) | |
| 55 | - .withReconnectionPolicy(new ConstantReconnectionPolicy(1000)) | |
| 56 | - .withQueryOptions(TestUtils.nonDebouncingQueryOptions()) | |
| 57 | - .build(); | |
| 50 | + .addContactPoint(CCMBridge.ipOfNode(1)) | |
| 51 | + .withPoolingOptions(poolingOptions) | |
| 52 | + .withLoadBalancingPolicy(loadBalancingPolicy) | |
| 53 | + .withReconnectionPolicy(new ConstantReconnectionPolicy(1000)) | |
| 54 | + .withQueryOptions(TestUtils.nonDebouncingQueryOptions()) | |
| 55 | + .build(); | |
| 58 | 56 | |
| 59 | 57 | Session session = cluster.connect(); |
| 60 | 58 | |
| 61 | 59 | assertThat(cluster).usesControlHost(1); |
| 62 | 60 | assertThat(cluster).host(1) |
| 63 | - .hasState(State.UP) | |
| 64 | - .isAtDistance(HostDistance.LOCAL); | |
| 61 | + .hasState(State.UP) | |
| 62 | + .isAtDistance(HostDistance.LOCAL); | |
| 65 | 63 | // Wait for the node to be up, because apparently on Jenkins it's still only ADDED when we reach this line |
| 66 | 64 | // Waiting for NEW_NODE_DELAY_SECONDS+1 allows the driver to create a connection pool and mark the node up |
| 67 | 65 | assertThat(cluster).host(2) |
| 68 | - .comesUpWithin(Cluster.NEW_NODE_DELAY_SECONDS+1, SECONDS) | |
| 69 | - .isAtDistance(HostDistance.LOCAL); | |
| 66 | + .comesUpWithin(Cluster.NEW_NODE_DELAY_SECONDS + 1, SECONDS) | |
| 67 | + .isAtDistance(HostDistance.LOCAL); | |
| 70 | 68 | |
| 71 | 69 | // Bring host 3 up, its presence should be acknowledged but it should be ignored |
| 72 | 70 | ccm.start(3); |
| 73 | 71 | ccm.waitForUp(3); |
| 74 | 72 | |
| 75 | 73 | assertThat(cluster).host(1) |
| 76 | - .hasState(State.UP) | |
| 77 | - .isAtDistance(HostDistance.LOCAL); | |
| 74 | + .hasState(State.UP) | |
| 75 | + .isAtDistance(HostDistance.LOCAL); | |
| 78 | 76 | assertThat(cluster).host(2) |
| 79 | - .hasState(State.UP) | |
| 80 | - .isAtDistance(HostDistance.LOCAL); | |
| 77 | + .hasState(State.UP) | |
| 78 | + .isAtDistance(HostDistance.LOCAL); | |
| 81 | 79 | |
| 82 | 80 | // Ensure that the host is added to the Cluster. |
| 83 | 81 | assertThat(cluster).host(3) |
| 84 | - .comesUpWithin(Cluster.NEW_NODE_DELAY_SECONDS+1, SECONDS) | |
| 85 | - .isAtDistance(HostDistance.IGNORED); | |
| 82 | + .comesUpWithin(Cluster.NEW_NODE_DELAY_SECONDS + 1, SECONDS) | |
| 83 | + .isAtDistance(HostDistance.IGNORED); | |
| 86 | 84 | assertThat(session).hasNoPoolFor(3); |
| 87 | 85 | |
| 88 | 86 | // Kill host 2, host 3 should take its place |
| @@ -90,19 +88,19 @@ | ||
| 90 | 88 | TestUtils.waitFor(CCMBridge.ipOfNode(3), cluster); |
| 91 | 89 | |
| 92 | 90 | assertThat(cluster).host(1) |
| 93 | - .hasState(State.UP) | |
| 94 | - .isAtDistance(HostDistance.LOCAL); | |
| 91 | + .hasState(State.UP) | |
| 92 | + .isAtDistance(HostDistance.LOCAL); | |
| 95 | 93 | assertThat(cluster).host(2) |
| 96 | - .hasState(State.DOWN); | |
| 94 | + .hasState(State.DOWN); | |
| 97 | 95 | assertThat(cluster).host(3) |
| 98 | - .hasState(State.UP) | |
| 99 | - .isAtDistance(HostDistance.LOCAL); | |
| 96 | + .hasState(State.UP) | |
| 97 | + .isAtDistance(HostDistance.LOCAL); | |
| 100 | 98 | assertThat(session).hasPoolFor(3); |
| 101 | 99 | |
| 102 | 100 | // This is when refreshConnectedHost should have been invoked, it triggers pool creation when |
| 103 | 101 | // we switch the node from IGNORED to UP: |
| 104 | 102 | Mockito.verify(poolingOptions) |
| 105 | - .refreshConnectedHost(TestUtils.findHost(cluster, 3)); | |
| 103 | + .refreshConnectedHost(TestUtils.findHost(cluster, 3)); | |
| 106 | 104 | |
| 107 | 105 | } finally { |
| 108 | 106 | if (cluster != null) |
modified driver-core/src/test/java/com/datastax/driver/core/ReplicationStrategyTest.java +18 −17
| @@ -17,6 +17,7 @@ | ||
| 17 | 17 | |
| 18 | 18 | import com.google.common.collect.ImmutableMap; |
| 19 | 19 | import org.testng.annotations.Test; |
| 20 | + | |
| 20 | 21 | import static org.testng.Assert.*; |
| 21 | 22 | |
| 22 | 23 | public class ReplicationStrategyTest { |
| @@ -25,9 +26,9 @@ | ||
| 25 | 26 | public void createSimpleReplicationStrategyTest() throws Exception { |
| 26 | 27 | ReplicationStrategy strategy = ReplicationStrategy.create( |
| 27 | 28 | ImmutableMap.<String, String>builder() |
| 28 | - .put("class", "SimpleStrategy") | |
| 29 | - .put("replication_factor", "3") | |
| 30 | - .build()); | |
| 29 | + .put("class", "SimpleStrategy") | |
| 30 | + .put("replication_factor", "3") | |
| 31 | + .build()); | |
| 31 | 32 | |
| 32 | 33 | assertNotNull(strategy); |
| 33 | 34 | assertTrue(strategy instanceof ReplicationStrategy.SimpleStrategy); |
| @@ -37,10 +38,10 @@ | ||
| 37 | 38 | public void createNetworkTopologyStrategyTest() throws Exception { |
| 38 | 39 | ReplicationStrategy strategy = ReplicationStrategy.create( |
| 39 | 40 | ImmutableMap.<String, String>builder() |
| 40 | - .put("class", "NetworkTopologyStrategy") | |
| 41 | - .put("dc1", "2") | |
| 42 | - .put("dc2", "2") | |
| 43 | - .build()); | |
| 41 | + .put("class", "NetworkTopologyStrategy") | |
| 42 | + .put("dc1", "2") | |
| 43 | + .put("dc2", "2") | |
| 44 | + .build()); | |
| 44 | 45 | |
| 45 | 46 | assertNotNull(strategy); |
| 46 | 47 | assertTrue(strategy instanceof ReplicationStrategy.NetworkTopologyStrategy); |
| @@ -50,9 +51,9 @@ | ||
| 50 | 51 | public void createSimpleReplicationStrategyWithoutFactorTest() throws Exception { |
| 51 | 52 | ReplicationStrategy strategy = ReplicationStrategy.create( |
| 52 | 53 | ImmutableMap.<String, String>builder() |
| 53 | - .put("class", "SimpleStrategy") | |
| 54 | - //no replication_factor | |
| 55 | - .build()); | |
| 54 | + .put("class", "SimpleStrategy") | |
| 55 | + //no replication_factor | |
| 56 | + .build()); | |
| 56 | 57 | |
| 57 | 58 | assertNull(strategy); |
| 58 | 59 | } |
| @@ -61,10 +62,10 @@ | ||
| 61 | 62 | public void createUnknownStrategyTest() throws Exception { |
| 62 | 63 | ReplicationStrategy strategy = ReplicationStrategy.create( |
| 63 | 64 | ImmutableMap.<String, String>builder() |
| 64 | - //no such strategy | |
| 65 | - .put("class", "FooStrategy") | |
| 66 | - .put("foo_factor", "3") | |
| 67 | - .build()); | |
| 65 | + //no such strategy | |
| 66 | + .put("class", "FooStrategy") | |
| 67 | + .put("foo_factor", "3") | |
| 68 | + .build()); | |
| 68 | 69 | |
| 69 | 70 | assertNull(strategy); |
| 70 | 71 | } |
| @@ -73,9 +74,9 @@ | ||
| 73 | 74 | public void createUnspecifiedStrategyTest() throws Exception { |
| 74 | 75 | ReplicationStrategy strategy = ReplicationStrategy.create( |
| 75 | 76 | ImmutableMap.<String, String>builder() |
| 76 | - //nothing useful is set | |
| 77 | - .put("foo", "bar") | |
| 78 | - .build()); | |
| 77 | + //nothing useful is set | |
| 78 | + .put("foo", "bar") | |
| 79 | + .build()); | |
| 79 | 80 | |
| 80 | 81 | assertNull(strategy); |
| 81 | 82 | } |
modified driver-core/src/test/java/com/datastax/driver/core/RequestHandlerTest.java +14 −14
| @@ -15,14 +15,14 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.util.concurrent.TimeUnit; | |
| 19 | -import java.util.concurrent.TimeoutException; | |
| 20 | - | |
| 21 | 18 | import com.google.common.collect.ImmutableMap; |
| 22 | 19 | import org.scassandra.Scassandra; |
| 23 | 20 | import org.scassandra.http.client.PrimingRequest; |
| 24 | 21 | import org.testng.annotations.Test; |
| 25 | 22 | |
| 23 | +import java.util.concurrent.TimeUnit; | |
| 24 | +import java.util.concurrent.TimeoutException; | |
| 25 | + | |
| 26 | 26 | import static org.assertj.core.api.Assertions.assertThat; |
| 27 | 27 | |
| 28 | 28 | public class RequestHandlerTest { |
| @@ -36,19 +36,19 @@ | ||
| 36 | 36 | // Use a mock server that takes a constant time to reply |
| 37 | 37 | scassandra.start(); |
| 38 | 38 | scassandra.primingClient().prime( |
| 39 | - PrimingRequest.queryBuilder() | |
| 40 | - .withQuery("mock query") | |
| 41 | - .withRows(ImmutableMap.of("key", 1)) | |
| 42 | - .withFixedDelay(10) | |
| 43 | - .build() | |
| 39 | + PrimingRequest.queryBuilder() | |
| 40 | + .withQuery("mock query") | |
| 41 | + .withRows(ImmutableMap.of("key", 1)) | |
| 42 | + .withFixedDelay(10) | |
| 43 | + .build() | |
| 44 | 44 | ); |
| 45 | 45 | |
| 46 | 46 | cluster = Cluster.builder().addContactPoint("127.0.0.1").withPort(scassandra.getBinaryPort()) |
| 47 | - .withPoolingOptions(new PoolingOptions() | |
| 48 | - .setCoreConnectionsPerHost(HostDistance.LOCAL, 1) | |
| 49 | - .setMaxConnectionsPerHost(HostDistance.LOCAL, 1) | |
| 50 | - .setHeartbeatIntervalSeconds(0)) | |
| 51 | - .build(); | |
| 47 | + .withPoolingOptions(new PoolingOptions() | |
| 48 | + .setCoreConnectionsPerHost(HostDistance.LOCAL, 1) | |
| 49 | + .setMaxConnectionsPerHost(HostDistance.LOCAL, 1) | |
| 50 | + .setHeartbeatIntervalSeconds(0)) | |
| 51 | + .build(); | |
| 52 | 52 | |
| 53 | 53 | Session session = cluster.connect(); |
| 54 | 54 | |
| @@ -82,7 +82,7 @@ | ||
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | private Connection getSingleConnection(Session session) { |
| 85 | - HostConnectionPool pool = ((SessionManager)session).pools.values().iterator().next(); | |
| 85 | + HostConnectionPool pool = ((SessionManager) session).pools.values().iterator().next(); | |
| 86 | 86 | return pool.connections.get(0); |
| 87 | 87 | } |
| 88 | 88 | } |
modified driver-core/src/test/java/com/datastax/driver/core/SSLAuthenticatedEncryptionTest.java +4 −5
| @@ -15,11 +15,10 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.exceptions.NoHostAvailableException; | |
| 18 | 19 | import com.google.common.base.Optional; |
| 19 | 20 | import org.testng.annotations.Test; |
| 20 | 21 | |
| 21 | -import com.datastax.driver.core.exceptions.NoHostAvailableException; | |
| 22 | - | |
| 23 | 22 | import static com.datastax.driver.core.CCMBridge.*; |
| 24 | 23 | |
| 25 | 24 | public class SSLAuthenticatedEncryptionTest extends SSLTestBase { |
| @@ -38,7 +37,7 @@ | ||
| 38 | 37 | * @test_category connection:ssl, authentication |
| 39 | 38 | * @expected_result Connection can be established to a cassandra node using SSL that requires client auth. |
| 40 | 39 | */ |
| 41 | - @Test(groups="short") | |
| 40 | + @Test(groups = "short") | |
| 42 | 41 | public void should_connect_with_ssl_with_client_auth_and_node_requires_auth() throws Exception { |
| 43 | 42 | connectWithSSLOptions(getSSLOptions(Optional.of(DEFAULT_CLIENT_KEYSTORE_PATH), Optional.of(DEFAULT_CLIENT_TRUSTSTORE_PATH))); |
| 44 | 43 | } |
| @@ -54,7 +53,7 @@ | ||
| 54 | 53 | * @test_category connection:ssl, authentication |
| 55 | 54 | * @expected_result Connection is not established. |
| 56 | 55 | */ |
| 57 | - @Test(groups="short", expectedExceptions={NoHostAvailableException.class}) | |
| 56 | + @Test(groups = "short", expectedExceptions = {NoHostAvailableException.class}) | |
| 58 | 57 | public void should_not_connect_without_client_auth_but_node_requires_auth() throws Exception { |
| 59 | 58 | connectWithSSLOptions(getSSLOptions(Optional.<String>absent(), Optional.of(DEFAULT_CLIENT_TRUSTSTORE_PATH))); |
| 60 | 59 | } |
| @@ -67,7 +66,7 @@ | ||
| 67 | 66 | * @test_category connection:ssl, authentication |
| 68 | 67 | * @expected_result Connection can be established. |
| 69 | 68 | */ |
| 70 | - @Test(groups="isolated") | |
| 69 | + @Test(groups = "isolated") | |
| 71 | 70 | public void should_use_system_properties_with_default_ssl_options() throws Exception { |
| 72 | 71 | System.setProperty("javax.net.ssl.keyStore", DEFAULT_CLIENT_KEYSTORE_FILE.getAbsolutePath()); |
| 73 | 72 | System.setProperty("javax.net.ssl.keyStorePassword", DEFAULT_CLIENT_KEYSTORE_PASSWORD); |
modified driver-core/src/test/java/com/datastax/driver/core/SSLEncryptionTest.java +13 −14
| @@ -15,12 +15,11 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.util.concurrent.TimeUnit; | |
| 19 | - | |
| 18 | +import com.datastax.driver.core.exceptions.NoHostAvailableException; | |
| 20 | 19 | import com.google.common.base.Optional; |
| 21 | 20 | import org.testng.annotations.Test; |
| 22 | 21 | |
| 23 | -import com.datastax.driver.core.exceptions.NoHostAvailableException; | |
| 22 | +import java.util.concurrent.TimeUnit; | |
| 24 | 23 | |
| 25 | 24 | import static com.datastax.driver.core.Assertions.assertThat; |
| 26 | 25 | import static com.datastax.driver.core.CCMBridge.*; |
| @@ -40,7 +39,7 @@ | ||
| 40 | 39 | * @test_category connection:ssl |
| 41 | 40 | * @expected_result Connection can be established to a cassandra node using SSL. |
| 42 | 41 | */ |
| 43 | - @Test(groups="short") | |
| 42 | + @Test(groups = "short") | |
| 44 | 43 | public void should_connect_with_ssl_without_client_auth_and_node_doesnt_require_auth() throws Exception { |
| 45 | 44 | connectWithSSLOptions(getSSLOptions(Optional.<String>absent(), Optional.of(DEFAULT_CLIENT_TRUSTSTORE_PATH))); |
| 46 | 45 | } |
| @@ -54,7 +53,7 @@ | ||
| 54 | 53 | * @test_category connection:ssl |
| 55 | 54 | * @expected_result Connection can not be established to a cassandra node using SSL with an untrusted cert. |
| 56 | 55 | */ |
| 57 | - @Test(groups="short", expectedExceptions={NoHostAvailableException.class}) | |
| 56 | + @Test(groups = "short", expectedExceptions = {NoHostAvailableException.class}) | |
| 58 | 57 | public void should_not_connect_with_ssl_without_trusting_server_cert() throws Exception { |
| 59 | 58 | connectWithSSLOptions(getSSLOptions(Optional.<String>absent(), Optional.<String>absent())); |
| 60 | 59 | } |
| @@ -64,7 +63,7 @@ | ||
| 64 | 63 | * Validates that an SSL connection can not be established if the client is not specifying SSL, but |
| 65 | 64 | * the cassandra node is using SSL. |
| 66 | 65 | * </p> |
| 67 | - * | |
| 66 | + * <p/> | |
| 68 | 67 | * <p> |
| 69 | 68 | * Note that future versions of cassandra may support both SSL-encrypted and non-SSL connections |
| 70 | 69 | * simultaneously (CASSANDRA-8803) |
| @@ -73,13 +72,13 @@ | ||
| 73 | 72 | * @test_category connection:ssl |
| 74 | 73 | * @expected_result Connection can not be established to a cassandra node using SSL and the client not using SSL. |
| 75 | 74 | */ |
| 76 | - @Test(groups="short", expectedExceptions={NoHostAvailableException.class}) | |
| 75 | + @Test(groups = "short", expectedExceptions = {NoHostAvailableException.class}) | |
| 77 | 76 | public void should_not_connect_without_ssl_but_node_uses_ssl() throws Exception { |
| 78 | 77 | Cluster cluster = null; |
| 79 | 78 | try { |
| 80 | 79 | cluster = Cluster.builder() |
| 81 | - .addContactPoint(CCMBridge.IP_PREFIX + '1') | |
| 82 | - .build(); | |
| 80 | + .addContactPoint(CCMBridge.IP_PREFIX + '1') | |
| 81 | + .build(); | |
| 83 | 82 | |
| 84 | 83 | cluster.connect(); |
| 85 | 84 | } finally { |
| @@ -97,14 +96,14 @@ | ||
| 97 | 96 | * @test_category connection:ssl |
| 98 | 97 | * @expected_result Connection is re-established within a sufficient amount of time after a node comes back online. |
| 99 | 98 | */ |
| 100 | - @Test(groups="long") | |
| 99 | + @Test(groups = "long") | |
| 101 | 100 | public void should_reconnect_with_ssl_on_node_up() throws Exception { |
| 102 | 101 | Cluster cluster = null; |
| 103 | 102 | try { |
| 104 | 103 | cluster = Cluster.builder() |
| 105 | - .addContactPoint(CCMBridge.IP_PREFIX + '1') | |
| 106 | - .withSSL(getSSLOptions(Optional.of(DEFAULT_CLIENT_KEYSTORE_PATH), Optional.of(DEFAULT_CLIENT_TRUSTSTORE_PATH))) | |
| 107 | - .build(); | |
| 104 | + .addContactPoint(CCMBridge.IP_PREFIX + '1') | |
| 105 | + .withSSL(getSSLOptions(Optional.of(DEFAULT_CLIENT_KEYSTORE_PATH), Optional.of(DEFAULT_CLIENT_TRUSTSTORE_PATH))) | |
| 106 | + .build(); | |
| 108 | 107 | |
| 109 | 108 | cluster.connect(); |
| 110 | 109 | |
| @@ -126,7 +125,7 @@ | ||
| 126 | 125 | * @test_category connection:ssl |
| 127 | 126 | * @expected_result Connection can be established. |
| 128 | 127 | */ |
| 129 | - @Test(groups="isolated") | |
| 128 | + @Test(groups = "isolated") | |
| 130 | 129 | public void should_use_system_properties_with_default_ssl_options() throws Exception { |
| 131 | 130 | System.setProperty("javax.net.ssl.trustStore", DEFAULT_CLIENT_TRUSTSTORE_FILE.getAbsolutePath()); |
| 132 | 131 | System.setProperty("javax.net.ssl.trustStorePassword", DEFAULT_CLIENT_TRUSTSTORE_PASSWORD); |
modified driver-core/src/test/java/com/datastax/driver/core/SSLTestBase.java +21 −22
| @@ -15,20 +15,19 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.security.KeyStore; | |
| 19 | -import java.security.SecureRandom; | |
| 20 | - | |
| 21 | 18 | import com.google.common.base.Optional; |
| 19 | +import org.testng.annotations.AfterClass; | |
| 20 | +import org.testng.annotations.BeforeClass; | |
| 21 | + | |
| 22 | 22 | import javax.net.ssl.KeyManagerFactory; |
| 23 | 23 | import javax.net.ssl.SSLContext; |
| 24 | 24 | import javax.net.ssl.TrustManagerFactory; |
| 25 | -import org.testng.annotations.AfterClass; | |
| 26 | -import org.testng.annotations.BeforeClass; | |
| 25 | +import java.security.KeyStore; | |
| 26 | +import java.security.SecureRandom; | |
| 27 | 27 | |
| 28 | -import static com.datastax.driver.core.CCMBridge.DEFAULT_CLIENT_KEYSTORE_FILE; | |
| 29 | 28 | import static com.datastax.driver.core.CCMBridge.DEFAULT_CLIENT_KEYSTORE_PASSWORD; |
| 30 | -import static com.datastax.driver.core.CCMBridge.DEFAULT_CLIENT_TRUSTSTORE_FILE; | |
| 31 | 29 | import static com.datastax.driver.core.CCMBridge.DEFAULT_CLIENT_TRUSTSTORE_PASSWORD; |
| 30 | + | |
| 32 | 31 | public abstract class SSLTestBase { |
| 33 | 32 | |
| 34 | 33 | private final boolean requireClientAuth; |
| @@ -39,14 +38,14 @@ | ||
| 39 | 38 | this.requireClientAuth = requireClientAuth; |
| 40 | 39 | } |
| 41 | 40 | |
| 42 | - @BeforeClass(groups={"isolated", "short", "long"}) | |
| 41 | + @BeforeClass(groups = {"isolated", "short", "long"}) | |
| 43 | 42 | public void beforeClass() { |
| 44 | 43 | ccm = CCMBridge.builder("test") |
| 45 | - .withSSL(requireClientAuth) | |
| 46 | - .build(); | |
| 44 | + .withSSL(requireClientAuth) | |
| 45 | + .build(); | |
| 47 | 46 | } |
| 48 | 47 | |
| 49 | - @AfterClass(groups={"isolated", "short", "long"}) | |
| 48 | + @AfterClass(groups = {"isolated", "short", "long"}) | |
| 50 | 49 | public void afterClass() { |
| 51 | 50 | ccm.remove(); |
| 52 | 51 | } |
| @@ -59,15 +58,15 @@ | ||
| 59 | 58 | * |
| 60 | 59 | * @param sslOptions SSLOptions to use. |
| 61 | 60 | * @throws Exception A {@link com.datastax.driver.core.exceptions.NoHostAvailableException} will be |
| 62 | - * raised here if connection cannot be established. | |
| 61 | + * raised here if connection cannot be established. | |
| 63 | 62 | */ |
| 64 | 63 | protected void connectWithSSLOptions(SSLOptions sslOptions) throws Exception { |
| 65 | 64 | Cluster cluster = null; |
| 66 | 65 | try { |
| 67 | 66 | cluster = Cluster.builder() |
| 68 | - .addContactPoint(CCMBridge.IP_PREFIX + '1') | |
| 69 | - .withSSL(sslOptions) | |
| 70 | - .build(); | |
| 67 | + .addContactPoint(CCMBridge.IP_PREFIX + '1') | |
| 68 | + .withSSL(sslOptions) | |
| 69 | + .build(); | |
| 71 | 70 | |
| 72 | 71 | cluster.connect(); |
| 73 | 72 | } finally { |
| @@ -83,15 +82,15 @@ | ||
| 83 | 82 | * </p> |
| 84 | 83 | * |
| 85 | 84 | * @throws Exception A {@link com.datastax.driver.core.exceptions.NoHostAvailableException} will be |
| 86 | - * raised here if connection cannot be established. | |
| 85 | + * raised here if connection cannot be established. | |
| 87 | 86 | */ |
| 88 | 87 | protected void connectWithSSL() throws Exception { |
| 89 | 88 | Cluster cluster = null; |
| 90 | 89 | try { |
| 91 | 90 | cluster = Cluster.builder() |
| 92 | - .addContactPoint(CCMBridge.IP_PREFIX + '1') | |
| 93 | - .withSSL() | |
| 94 | - .build(); | |
| 91 | + .addContactPoint(CCMBridge.IP_PREFIX + '1') | |
| 92 | + .withSSL() | |
| 93 | + .build(); | |
| 95 | 94 | |
| 96 | 95 | cluster.connect(); |
| 97 | 96 | } finally { |
| @@ -101,7 +100,7 @@ | ||
| 101 | 100 | } |
| 102 | 101 | |
| 103 | 102 | /** |
| 104 | - * @param keyStorePath Path to keystore, if absent is not used. | |
| 103 | + * @param keyStorePath Path to keystore, if absent is not used. | |
| 105 | 104 | * @param trustStorePath Path to truststore, if absent is not used. |
| 106 | 105 | * @return {@link com.datastax.driver.core.SSLOptions} with the given keystore and truststore path's for |
| 107 | 106 | * server certificate validation and client certificate authentication. |
| @@ -109,7 +108,7 @@ | ||
| 109 | 108 | public SSLOptions getSSLOptions(Optional<String> keyStorePath, Optional<String> trustStorePath) throws Exception { |
| 110 | 109 | |
| 111 | 110 | TrustManagerFactory tmf = null; |
| 112 | - if(trustStorePath.isPresent()) { | |
| 111 | + if (trustStorePath.isPresent()) { | |
| 113 | 112 | KeyStore ks = KeyStore.getInstance("JKS"); |
| 114 | 113 | ks.load(this.getClass().getResourceAsStream(trustStorePath.get()), DEFAULT_CLIENT_TRUSTSTORE_PASSWORD.toCharArray()); |
| 115 | 114 | |
| @@ -118,7 +117,7 @@ | ||
| 118 | 117 | } |
| 119 | 118 | |
| 120 | 119 | KeyManagerFactory kmf = null; |
| 121 | - if(keyStorePath.isPresent()) { | |
| 120 | + if (keyStorePath.isPresent()) { | |
| 122 | 121 | KeyStore ks = KeyStore.getInstance("JKS"); |
| 123 | 122 | ks.load(this.getClass().getResourceAsStream(keyStorePath.get()), DEFAULT_CLIENT_KEYSTORE_PASSWORD.toCharArray()); |
| 124 | 123 |
modified driver-core/src/test/java/com/datastax/driver/core/ScassandraCluster.java +167 −174
| @@ -15,11 +15,6 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.util.List; | |
| 19 | -import java.util.Map; | |
| 20 | -import java.util.TreeSet; | |
| 21 | -import java.util.concurrent.TimeUnit; | |
| 22 | - | |
| 23 | 18 | import com.beust.jcommander.internal.Lists; |
| 24 | 19 | import com.google.common.collect.ImmutableList; |
| 25 | 20 | import com.google.common.collect.ImmutableMap; |
| @@ -31,20 +26,18 @@ | ||
| 31 | 26 | import org.slf4j.Logger; |
| 32 | 27 | import org.slf4j.LoggerFactory; |
| 33 | 28 | |
| 29 | +import java.util.List; | |
| 30 | +import java.util.Map; | |
| 31 | +import java.util.TreeSet; | |
| 32 | +import java.util.concurrent.TimeUnit; | |
| 33 | + | |
| 34 | +import static com.datastax.driver.core.Assertions.assertThat; | |
| 34 | 35 | import static org.scassandra.cql.MapType.map; |
| 35 | -import static org.scassandra.cql.PrimitiveType.BIG_INT; | |
| 36 | -import static org.scassandra.cql.PrimitiveType.BOOLEAN; | |
| 37 | -import static org.scassandra.cql.PrimitiveType.DOUBLE; | |
| 38 | -import static org.scassandra.cql.PrimitiveType.INET; | |
| 39 | -import static org.scassandra.cql.PrimitiveType.INT; | |
| 40 | -import static org.scassandra.cql.PrimitiveType.TEXT; | |
| 41 | -import static org.scassandra.cql.PrimitiveType.UUID; | |
| 36 | +import static org.scassandra.cql.PrimitiveType.*; | |
| 42 | 37 | import static org.scassandra.cql.SetType.set; |
| 43 | 38 | import static org.scassandra.http.client.PrimingRequest.then; |
| 44 | 39 | import static org.scassandra.http.client.types.ColumnMetadata.column; |
| 45 | 40 | |
| 46 | -import static com.datastax.driver.core.Assertions.assertThat; | |
| 47 | - | |
| 48 | 41 | public class ScassandraCluster { |
| 49 | 42 | |
| 50 | 43 | private static final Logger logger = LoggerFactory.getLogger(ScassandraCluster.class); |
| @@ -53,25 +46,25 @@ | ||
| 53 | 46 | |
| 54 | 47 | private final List<Scassandra> instances; |
| 55 | 48 | |
| 56 | - private final Map<Integer,List<Scassandra>> dcNodeMap; | |
| 49 | + private final Map<Integer, List<Scassandra>> dcNodeMap; | |
| 57 | 50 | |
| 58 | - private final List<Map<String,? extends Object>> keyspaceRows; | |
| 51 | + private final List<Map<String, ? extends Object>> keyspaceRows; | |
| 59 | 52 | |
| 60 | - ScassandraCluster(Integer[] nodes, String ipPrefix, int binaryPort, int adminPort, List<Map<String,? extends Object>> keyspaceRows) { | |
| 53 | + ScassandraCluster(Integer[] nodes, String ipPrefix, int binaryPort, int adminPort, List<Map<String, ? extends Object>> keyspaceRows) { | |
| 61 | 54 | this.ipPrefix = ipPrefix; |
| 62 | 55 | |
| 63 | 56 | int node = 1; |
| 64 | 57 | ImmutableList.Builder<Scassandra> instanceListBuilder = ImmutableList.builder(); |
| 65 | - ImmutableMap.Builder<Integer, List<Scassandra>> dcNodeMapBuilder = ImmutableMap.builder(); | |
| 66 | - for(int dc=0; dc < nodes.length; dc++) { | |
| 58 | + ImmutableMap.Builder<Integer, List<Scassandra>> dcNodeMapBuilder = ImmutableMap.builder(); | |
| 59 | + for (int dc = 0; dc < nodes.length; dc++) { | |
| 67 | 60 | ImmutableList.Builder<Scassandra> dcNodeListBuilder = ImmutableList.builder(); |
| 68 | - for(int n=0; n < nodes[dc]; n++) { | |
| 61 | + for (int n = 0; n < nodes[dc]; n++) { | |
| 69 | 62 | String ip = ipPrefix + node++; |
| 70 | 63 | Scassandra instance = ScassandraFactory.createServer(ip, binaryPort, ip, adminPort); |
| 71 | 64 | instanceListBuilder = instanceListBuilder.add(instance); |
| 72 | 65 | dcNodeListBuilder = dcNodeListBuilder.add(instance); |
| 73 | 66 | } |
| 74 | - dcNodeMapBuilder.put(dc+1, dcNodeListBuilder.build()); | |
| 67 | + dcNodeMapBuilder.put(dc + 1, dcNodeListBuilder.build()); | |
| 75 | 68 | } |
| 76 | 69 | instances = instanceListBuilder.build(); |
| 77 | 70 | dcNodeMap = dcNodeMapBuilder.build(); |
| @@ -79,7 +72,7 @@ | ||
| 79 | 72 | } |
| 80 | 73 | |
| 81 | 74 | public Scassandra node(int node) { |
| 82 | - return instances.get(node-1); | |
| 75 | + return instances.get(node - 1); | |
| 83 | 76 | } |
| 84 | 77 | |
| 85 | 78 | public List<Scassandra> nodes() { |
| @@ -101,11 +94,11 @@ | ||
| 101 | 94 | public int ipSuffix(int dc, int node) { |
| 102 | 95 | // TODO: Scassandra should be updated to include address to avoid O(n) lookup. |
| 103 | 96 | int nodeCount = 0; |
| 104 | - for(Integer dcNum : new TreeSet<Integer>(dcNodeMap.keySet())) { | |
| 97 | + for (Integer dcNum : new TreeSet<Integer>(dcNodeMap.keySet())) { | |
| 105 | 98 | List<Scassandra> nodesInDc = dcNodeMap.get(dc); |
| 106 | - for(int n = 0; n < nodesInDc.size(); n++) { | |
| 99 | + for (int n = 0; n < nodesInDc.size(); n++) { | |
| 107 | 100 | nodeCount++; |
| 108 | - if(dcNum == dc && n+1 == node) { | |
| 101 | + if (dcNum == dc && n + 1 == node) { | |
| 109 | 102 | return nodeCount; |
| 110 | 103 | } |
| 111 | 104 | } |
| @@ -116,13 +109,13 @@ | ||
| 116 | 109 | public String address(int dc, int node) { |
| 117 | 110 | // TODO: Scassandra should be updated to include address to avoid O(n) lookup. |
| 118 | 111 | int ipSuffix = ipSuffix(dc, node); |
| 119 | - return ipSuffix == -1 ? null : ipPrefix + ipSuffix; | |
| 112 | + return ipSuffix == -1 ? null : ipPrefix + ipSuffix; | |
| 120 | 113 | } |
| 121 | 114 | |
| 122 | 115 | public Host host(Cluster cluster, int dc, int node) { |
| 123 | 116 | String address = address(dc, node); |
| 124 | - for(Host host : cluster.getMetadata().getAllHosts()) { | |
| 125 | - if(host.getAddress().getHostAddress().equals(address)) { | |
| 117 | + for (Host host : cluster.getMetadata().getAllHosts()) { | |
| 118 | + if (host.getAddress().getHostAddress().equals(address)) { | |
| 126 | 119 | return host; |
| 127 | 120 | } |
| 128 | 121 | } |
| @@ -134,8 +127,8 @@ | ||
| 134 | 127 | } |
| 135 | 128 | |
| 136 | 129 | public void init() { |
| 137 | - for(Map.Entry<Integer, List<Scassandra>> dc : dcNodeMap.entrySet()) { | |
| 138 | - for(Scassandra node : dc.getValue()) { | |
| 130 | + for (Map.Entry<Integer, List<Scassandra>> dc : dcNodeMap.entrySet()) { | |
| 131 | + for (Scassandra node : dc.getValue()) { | |
| 139 | 132 | node.start(); |
| 140 | 133 | primeMetadata(node); |
| 141 | 134 | } |
| @@ -144,7 +137,7 @@ | ||
| 144 | 137 | |
| 145 | 138 | public void stop() { |
| 146 | 139 | logger.debug("Stopping ScassandraCluster."); |
| 147 | - for(Scassandra node : instances) { | |
| 140 | + for (Scassandra node : instances) { | |
| 148 | 141 | node.stop(); |
| 149 | 142 | } |
| 150 | 143 | } |
| @@ -152,18 +145,18 @@ | ||
| 152 | 145 | /** |
| 153 | 146 | * First stops each node in {@code dc} and then asserts that each node's {@link Host} |
| 154 | 147 | * is marked down for the given {@link Cluster} instance within 10 seconds. |
| 155 | - * | |
| 148 | + * <p/> | |
| 156 | 149 | * If any of the nodes are the control host, this node is stopped last, to reduce |
| 157 | 150 | * likelihood of control connection choosing a host that will be shut down. |
| 158 | 151 | * |
| 159 | 152 | * @param cluster cluster to wait for down statuses on. |
| 160 | - * @param dc DC to stop. | |
| 153 | + * @param dc DC to stop. | |
| 161 | 154 | */ |
| 162 | 155 | public void stopDC(Cluster cluster, int dc) { |
| 163 | 156 | logger.debug("Stopping all nodes in {}.", datacenter(dc)); |
| 164 | 157 | // If any node is the control host, stop it last. |
| 165 | 158 | int controlHost = -1; |
| 166 | - for(int i = 1; i <= nodes(dc).size(); i++) { | |
| 159 | + for (int i = 1; i <= nodes(dc).size(); i++) { | |
| 167 | 160 | int id = ipSuffix(dc, i); |
| 168 | 161 | Host host = TestUtils.findHost(cluster, id); |
| 169 | 162 | if (cluster.manager.controlConnection.connectedHost() == host) { |
| @@ -174,7 +167,7 @@ | ||
| 174 | 167 | stop(cluster, id); |
| 175 | 168 | } |
| 176 | 169 | |
| 177 | - if(controlHost != -1) { | |
| 170 | + if (controlHost != -1) { | |
| 178 | 171 | stop(cluster, controlHost); |
| 179 | 172 | } |
| 180 | 173 | } |
| @@ -184,7 +177,7 @@ | ||
| 184 | 177 | * for the given {@link Cluster} instance within 10 seconds. |
| 185 | 178 | * |
| 186 | 179 | * @param cluster cluster to wait for down status on. |
| 187 | - * @param node Node to stop. | |
| 180 | + * @param node Node to stop. | |
| 188 | 181 | */ |
| 189 | 182 | public void stop(Cluster cluster, int node) { |
| 190 | 183 | logger.debug("Stopping node {}.", node); |
| @@ -198,8 +191,8 @@ | ||
| 198 | 191 | * for the given {@link Cluster} instance within 10 seconds. |
| 199 | 192 | * |
| 200 | 193 | * @param cluster cluster to wait for down status on. |
| 201 | - * @param dc Data center node is in. | |
| 202 | - * @param node Node to stop. | |
| 194 | + * @param dc Data center node is in. | |
| 195 | + * @param node Node to stop. | |
| 203 | 196 | */ |
| 204 | 197 | public void stop(Cluster cluster, int dc, int node) { |
| 205 | 198 | logger.debug("Stopping node {} in {}.", node, datacenter(dc)); |
| @@ -211,11 +204,11 @@ | ||
| 211 | 204 | * is marked up for the given {@link Cluster} instance within 10 seconds. |
| 212 | 205 | * |
| 213 | 206 | * @param cluster cluster to wait for up statuses on. |
| 214 | - * @param dc DC to start. | |
| 207 | + * @param dc DC to start. | |
| 215 | 208 | */ |
| 216 | 209 | public void startDC(Cluster cluster, int dc) { |
| 217 | 210 | logger.debug("Starting all nodes in {}.", datacenter(dc)); |
| 218 | - for(int i = 1; i <= nodes(dc).size(); i++) { | |
| 211 | + for (int i = 1; i <= nodes(dc).size(); i++) { | |
| 219 | 212 | int id = ipSuffix(dc, i); |
| 220 | 213 | start(cluster, id); |
| 221 | 214 | } |
| @@ -226,7 +219,7 @@ | ||
| 226 | 219 | * for the given {@link Cluster} instance within 10 seconds. |
| 227 | 220 | * |
| 228 | 221 | * @param cluster cluster to wait for up status on. |
| 229 | - * @param node Node to start. | |
| 222 | + * @param node Node to start. | |
| 230 | 223 | */ |
| 231 | 224 | public void start(Cluster cluster, int node) { |
| 232 | 225 | logger.debug("Starting node {}.", node); |
| @@ -240,8 +233,8 @@ | ||
| 240 | 233 | * for the given {@link Cluster} instance within 10 seconds. |
| 241 | 234 | * |
| 242 | 235 | * @param cluster cluster to wait for up status on. |
| 243 | - * @param dc Data center node is in. | |
| 244 | - * @param node Node to start. | |
| 236 | + * @param dc Data center node is in. | |
| 237 | + * @param node Node to start. | |
| 245 | 238 | */ |
| 246 | 239 | public void start(Cluster cluster, int dc, int node) { |
| 247 | 240 | logger.debug("Starting node {} in {}.", node, datacenter(dc)); |
| @@ -250,11 +243,11 @@ | ||
| 250 | 243 | |
| 251 | 244 | private List<Long> getTokensForDC(int dc) { |
| 252 | 245 | // Offset DCs by dc * 100 to ensure unique tokens. |
| 253 | - int offset = (dc-1) * 100; | |
| 246 | + int offset = (dc - 1) * 100; | |
| 254 | 247 | int dcNodeCount = nodes(dc).size(); |
| 255 | 248 | List<Long> tokens = Lists.newArrayList(dcNodeCount); |
| 256 | - for(int i = 0; i < dcNodeCount; i++) { | |
| 257 | - tokens.add((i * ((long)Math.pow(2, 64)/dcNodeCount) + offset)); | |
| 249 | + for (int i = 0; i < dcNodeCount; i++) { | |
| 250 | + tokens.add((i * ((long) Math.pow(2, 64) / dcNodeCount) + offset)); | |
| 258 | 251 | } |
| 259 | 252 | return tokens; |
| 260 | 253 | } |
| @@ -263,163 +256,163 @@ | ||
| 263 | 256 | PrimingClient client = node.primingClient(); |
| 264 | 257 | int nodeCount = 0; |
| 265 | 258 | |
| 266 | - ImmutableList.Builder<Map<String,?>> rows = ImmutableList.builder(); | |
| 267 | - for(Integer dc : new TreeSet<Integer>(dcNodeMap.keySet())) { | |
| 259 | + ImmutableList.Builder<Map<String, ?>> rows = ImmutableList.builder(); | |
| 260 | + for (Integer dc : new TreeSet<Integer>(dcNodeMap.keySet())) { | |
| 268 | 261 | List<Scassandra> nodesInDc = dcNodeMap.get(dc); |
| 269 | 262 | List<Long> tokens = getTokensForDC(dc); |
| 270 | - for(int n = 0; n < nodesInDc.size(); n++) { | |
| 263 | + for (int n = 0; n < nodesInDc.size(); n++) { | |
| 271 | 264 | String address = ipPrefix + ++nodeCount; |
| 272 | 265 | Scassandra peer = nodesInDc.get(n); |
| 273 | 266 | String query; |
| 274 | - Map<String,Object> row; | |
| 267 | + Map<String, Object> row; | |
| 275 | 268 | org.scassandra.http.client.types.ColumnMetadata[] metadata; |
| 276 | - if(node == peer) { // prime system.local. | |
| 269 | + if (node == peer) { // prime system.local. | |
| 277 | 270 | metadata = SELECT_LOCAL; |
| 278 | 271 | query = "SELECT * FROM system.local WHERE key='local'"; |
| 279 | 272 | row = ImmutableMap.<String, Object>builder() |
| 280 | - .put("key", "local") | |
| 281 | - .put("bootstrapped", "COMPLETED") | |
| 282 | - .put("broadcast_address", address) | |
| 283 | - .put("cluster_name", "scassandra") | |
| 284 | - .put("cql_version", "3.2.0") | |
| 285 | - .put("data_center", datacenter(dc)) | |
| 286 | - .put("listen_address", address) | |
| 287 | - .put("partitioner", "org.apache.cassandra.dht.Murmur3Partitioner") | |
| 288 | - .put("rack", "rack1") | |
| 289 | - .put("release_version", "2.1.8") | |
| 290 | - .put("tokens", ImmutableSet.of(tokens.get(n))) | |
| 291 | - .build(); | |
| 273 | + .put("key", "local") | |
| 274 | + .put("bootstrapped", "COMPLETED") | |
| 275 | + .put("broadcast_address", address) | |
| 276 | + .put("cluster_name", "scassandra") | |
| 277 | + .put("cql_version", "3.2.0") | |
| 278 | + .put("data_center", datacenter(dc)) | |
| 279 | + .put("listen_address", address) | |
| 280 | + .put("partitioner", "org.apache.cassandra.dht.Murmur3Partitioner") | |
| 281 | + .put("rack", "rack1") | |
| 282 | + .put("release_version", "2.1.8") | |
| 283 | + .put("tokens", ImmutableSet.of(tokens.get(n))) | |
| 284 | + .build(); | |
| 292 | 285 | } else { // prime system.peers. |
| 293 | 286 | query = "SELECT * FROM system.peers WHERE peer='" + address + "'"; |
| 294 | 287 | metadata = SELECT_PEERS; |
| 295 | 288 | row = ImmutableMap.<String, Object>builder() |
| 296 | - .put("peer", address) | |
| 297 | - .put("rpc_address", address) | |
| 298 | - .put("data_center", datacenter(dc)) | |
| 299 | - .put("rack", "rack1") | |
| 300 | - .put("release_version", "2.1.8") | |
| 301 | - .put("tokens", ImmutableSet.of(Long.toString(tokens.get(n)))) | |
| 302 | - .build(); | |
| 289 | + .put("peer", address) | |
| 290 | + .put("rpc_address", address) | |
| 291 | + .put("data_center", datacenter(dc)) | |
| 292 | + .put("rack", "rack1") | |
| 293 | + .put("release_version", "2.1.8") | |
| 294 | + .put("tokens", ImmutableSet.of(Long.toString(tokens.get(n)))) | |
| 295 | + .build(); | |
| 303 | 296 | rows.add(row); |
| 304 | 297 | } |
| 305 | 298 | client.prime(PrimingRequest.queryBuilder() |
| 306 | - .withQuery(query) | |
| 307 | - .withThen(then() | |
| 308 | - .withColumnTypes(metadata) | |
| 309 | - .withRows(row) | |
| 310 | - .build()) | |
| 311 | - .build()); | |
| 299 | + .withQuery(query) | |
| 300 | + .withThen(then() | |
| 301 | + .withColumnTypes(metadata) | |
| 302 | + .withRows(row) | |
| 303 | + .build()) | |
| 304 | + .build()); | |
| 312 | 305 | } |
| 313 | 306 | } |
| 314 | 307 | |
| 315 | 308 | client.prime(PrimingRequest.queryBuilder() |
| 316 | - .withQuery("SELECT * FROM system.peers") | |
| 317 | - .withThen(then() | |
| 318 | - .withColumnTypes(SELECT_PEERS) | |
| 319 | - .withRows(rows.build()) | |
| 320 | - .build()) | |
| 321 | - .build()); | |
| 309 | + .withQuery("SELECT * FROM system.peers") | |
| 310 | + .withThen(then() | |
| 311 | + .withColumnTypes(SELECT_PEERS) | |
| 312 | + .withRows(rows.build()) | |
| 313 | + .build()) | |
| 314 | + .build()); | |
| 322 | 315 | |
| 323 | 316 | // Needed to ensure cluster_name matches what we expect on connection. |
| 324 | - Map<String,Object> clusterNameRow = ImmutableMap.<String,Object>builder() | |
| 325 | - .put("cluster_name", "scassandra") | |
| 326 | - .build(); | |
| 317 | + Map<String, Object> clusterNameRow = ImmutableMap.<String, Object>builder() | |
| 318 | + .put("cluster_name", "scassandra") | |
| 319 | + .build(); | |
| 327 | 320 | client.prime(PrimingRequest.queryBuilder() |
| 328 | - .withQuery("select cluster_name from system.local") | |
| 329 | - .withThen(then() | |
| 330 | - .withColumnTypes(SELECT_CLUSTER_NAME) | |
| 331 | - .withRows(clusterNameRow) | |
| 332 | - .build()) | |
| 333 | - .build()); | |
| 321 | + .withQuery("select cluster_name from system.local") | |
| 322 | + .withThen(then() | |
| 323 | + .withColumnTypes(SELECT_CLUSTER_NAME) | |
| 324 | + .withRows(clusterNameRow) | |
| 325 | + .build()) | |
| 326 | + .build()); | |
| 334 | 327 | |
| 335 | 328 | |
| 336 | 329 | // Prime keyspaces |
| 337 | 330 | client.prime(PrimingRequest.queryBuilder() |
| 338 | - .withQuery("SELECT * FROM system.schema_keyspaces") | |
| 339 | - .withThen(then() | |
| 340 | - .withColumnTypes(SELECT_SCHEMA_KEYSPACES) | |
| 341 | - .withRows(keyspaceRows) | |
| 342 | - .build()) | |
| 343 | - .build()); | |
| 331 | + .withQuery("SELECT * FROM system.schema_keyspaces") | |
| 332 | + .withThen(then() | |
| 333 | + .withColumnTypes(SELECT_SCHEMA_KEYSPACES) | |
| 334 | + .withRows(keyspaceRows) | |
| 335 | + .build()) | |
| 336 | + .build()); | |
| 344 | 337 | } |
| 345 | 338 | |
| 346 | 339 | static final org.scassandra.http.client.types.ColumnMetadata[] SELECT_PEERS = { |
| 347 | - column("peer", INET), | |
| 348 | - column("rpc_address", INET), | |
| 349 | - column("data_center", TEXT), | |
| 350 | - column("rack", TEXT), | |
| 351 | - column("release_version", TEXT), | |
| 352 | - column("tokens", set(TEXT)) | |
| 340 | + column("peer", INET), | |
| 341 | + column("rpc_address", INET), | |
| 342 | + column("data_center", TEXT), | |
| 343 | + column("rack", TEXT), | |
| 344 | + column("release_version", TEXT), | |
| 345 | + column("tokens", set(TEXT)) | |
| 353 | 346 | }; |
| 354 | 347 | |
| 355 | 348 | static final org.scassandra.http.client.types.ColumnMetadata[] SELECT_LOCAL = { |
| 356 | - column("key", TEXT), | |
| 357 | - column("bootstrapped", TEXT), | |
| 358 | - column("broadcast_address", INET), | |
| 359 | - column("cluster_name", TEXT), | |
| 360 | - column("cql_version", TEXT), | |
| 361 | - column("data_center", TEXT), | |
| 362 | - column("listen_address", INET), | |
| 363 | - column("partitioner", TEXT), | |
| 364 | - column("rack", TEXT), | |
| 365 | - column("release_version", TEXT), | |
| 366 | - column("tokens", set(TEXT)), | |
| 349 | + column("key", TEXT), | |
| 350 | + column("bootstrapped", TEXT), | |
| 351 | + column("broadcast_address", INET), | |
| 352 | + column("cluster_name", TEXT), | |
| 353 | + column("cql_version", TEXT), | |
| 354 | + column("data_center", TEXT), | |
| 355 | + column("listen_address", INET), | |
| 356 | + column("partitioner", TEXT), | |
| 357 | + column("rack", TEXT), | |
| 358 | + column("release_version", TEXT), | |
| 359 | + column("tokens", set(TEXT)), | |
| 367 | 360 | }; |
| 368 | 361 | |
| 369 | 362 | static final org.scassandra.http.client.types.ColumnMetadata[] SELECT_CLUSTER_NAME = { |
| 370 | - column("cluster_name", TEXT) | |
| 363 | + column("cluster_name", TEXT) | |
| 371 | 364 | }; |
| 372 | 365 | |
| 373 | 366 | static final org.scassandra.http.client.types.ColumnMetadata[] SELECT_SCHEMA_KEYSPACES = { |
| 374 | - column("durable_writes", BOOLEAN), | |
| 375 | - column("keyspace_name", TEXT), | |
| 376 | - column("strategy_class", TEXT), | |
| 377 | - column("strategy_options", TEXT) | |
| 367 | + column("durable_writes", BOOLEAN), | |
| 368 | + column("keyspace_name", TEXT), | |
| 369 | + column("strategy_class", TEXT), | |
| 370 | + column("strategy_options", TEXT) | |
| 378 | 371 | }; |
| 379 | 372 | |
| 380 | 373 | static final org.scassandra.http.client.types.ColumnMetadata[] SELECT_SCHEMA_COLUMN_FAMILIES = { |
| 381 | - column("bloom_filter_fp_chance", DOUBLE), | |
| 382 | - column("caching", TEXT), | |
| 383 | - column("cf_id", UUID), | |
| 384 | - column("column_aliases", TEXT), | |
| 385 | - column("columnfamily_name", TEXT), | |
| 386 | - column("comment", TEXT), | |
| 387 | - column("compaction_strategy_class", TEXT), | |
| 388 | - column("compaction_strategy_options", TEXT), | |
| 389 | - column("comparator", TEXT), | |
| 390 | - column("compression_parameters", TEXT), | |
| 391 | - column("default_time_to_live", INT), | |
| 392 | - column("default_validator", TEXT), | |
| 393 | - column("dropped_columns", map(TEXT, BIG_INT)), | |
| 394 | - column("gc_grace_seconds", INT), | |
| 395 | - column("index_interval", INT), | |
| 396 | - column("is_dense", BOOLEAN), | |
| 397 | - column("key_aliases", TEXT), | |
| 398 | - column("key_validator", TEXT), | |
| 399 | - column("keyspace_name", TEXT), | |
| 400 | - column("local_read_repair_chance", DOUBLE), | |
| 401 | - column("max_compaction_threshold", INT), | |
| 402 | - column("max_index_interval", INT), | |
| 403 | - column("memtable_flush_period_in_ms", INT), | |
| 404 | - column("min_compaction_threshold", INT), | |
| 405 | - column("min_index_interval", INT), | |
| 406 | - column("read_repair_chance", DOUBLE), | |
| 407 | - column("speculative_retry", TEXT), | |
| 408 | - column("subcomparator", TEXT), | |
| 409 | - column("type", TEXT), | |
| 410 | - column("value_alias", TEXT) | |
| 374 | + column("bloom_filter_fp_chance", DOUBLE), | |
| 375 | + column("caching", TEXT), | |
| 376 | + column("cf_id", UUID), | |
| 377 | + column("column_aliases", TEXT), | |
| 378 | + column("columnfamily_name", TEXT), | |
| 379 | + column("comment", TEXT), | |
| 380 | + column("compaction_strategy_class", TEXT), | |
| 381 | + column("compaction_strategy_options", TEXT), | |
| 382 | + column("comparator", TEXT), | |
| 383 | + column("compression_parameters", TEXT), | |
| 384 | + column("default_time_to_live", INT), | |
| 385 | + column("default_validator", TEXT), | |
| 386 | + column("dropped_columns", map(TEXT, BIG_INT)), | |
| 387 | + column("gc_grace_seconds", INT), | |
| 388 | + column("index_interval", INT), | |
| 389 | + column("is_dense", BOOLEAN), | |
| 390 | + column("key_aliases", TEXT), | |
| 391 | + column("key_validator", TEXT), | |
| 392 | + column("keyspace_name", TEXT), | |
| 393 | + column("local_read_repair_chance", DOUBLE), | |
| 394 | + column("max_compaction_threshold", INT), | |
| 395 | + column("max_index_interval", INT), | |
| 396 | + column("memtable_flush_period_in_ms", INT), | |
| 397 | + column("min_compaction_threshold", INT), | |
| 398 | + column("min_index_interval", INT), | |
| 399 | + column("read_repair_chance", DOUBLE), | |
| 400 | + column("speculative_retry", TEXT), | |
| 401 | + column("subcomparator", TEXT), | |
| 402 | + column("type", TEXT), | |
| 403 | + column("value_alias", TEXT) | |
| 411 | 404 | }; |
| 412 | 405 | |
| 413 | 406 | static final org.scassandra.http.client.types.ColumnMetadata[] SELECT_SCHEMA_COLUMNS = { |
| 414 | - column("column_name", TEXT), | |
| 415 | - column("columnfamily_name", TEXT), | |
| 416 | - column("component_index", INT), | |
| 417 | - column("index_name", TEXT), | |
| 418 | - column("index_options", TEXT), | |
| 419 | - column("index_type", TEXT), | |
| 420 | - column("keyspace_name", TEXT), | |
| 421 | - column("type", TEXT), | |
| 422 | - column("validator", TEXT), | |
| 407 | + column("column_name", TEXT), | |
| 408 | + column("columnfamily_name", TEXT), | |
| 409 | + column("component_index", INT), | |
| 410 | + column("index_name", TEXT), | |
| 411 | + column("index_options", TEXT), | |
| 412 | + column("index_type", TEXT), | |
| 413 | + column("keyspace_name", TEXT), | |
| 414 | + column("type", TEXT), | |
| 415 | + column("validator", TEXT), | |
| 423 | 416 | }; |
| 424 | 417 | |
| 425 | 418 | public static ScassandraClusterBuilder builder() { |
| @@ -430,10 +423,10 @@ | ||
| 430 | 423 | |
| 431 | 424 | private Integer nodes[] = {1}; |
| 432 | 425 | private String ipPrefix = CCMBridge.IP_PREFIX; |
| 433 | - private final List<Map<String,? extends Object>> keyspaceRows = Lists.newArrayList(); | |
| 426 | + private final List<Map<String, ? extends Object>> keyspaceRows = Lists.newArrayList(); | |
| 434 | 427 | |
| 435 | 428 | |
| 436 | - public ScassandraClusterBuilder withNodes(Integer ... nodes) { | |
| 429 | + public ScassandraClusterBuilder withNodes(Integer... nodes) { | |
| 437 | 430 | this.nodes = nodes; |
| 438 | 431 | return this; |
| 439 | 432 | } |
| @@ -444,20 +437,20 @@ | ||
| 444 | 437 | } |
| 445 | 438 | |
| 446 | 439 | public ScassandraClusterBuilder withSimpleKeyspace(String name, int replicationFactor) { |
| 447 | - Map<String,Object> simpleKeyspaceRow = ImmutableMap.<String,Object>builder() | |
| 448 | - .put("durable_writes", false) | |
| 449 | - .put("keyspace_name", name) | |
| 450 | - .put("strategy_class", "SimpleStrategy") | |
| 451 | - .put("strategy_options", "{\"replication_factor\":\"" + replicationFactor + "\"}") | |
| 452 | - .build(); | |
| 440 | + Map<String, Object> simpleKeyspaceRow = ImmutableMap.<String, Object>builder() | |
| 441 | + .put("durable_writes", false) | |
| 442 | + .put("keyspace_name", name) | |
| 443 | + .put("strategy_class", "SimpleStrategy") | |
| 444 | + .put("strategy_options", "{\"replication_factor\":\"" + replicationFactor + "\"}") | |
| 445 | + .build(); | |
| 453 | 446 | |
| 454 | 447 | keyspaceRows.add(simpleKeyspaceRow); |
| 455 | 448 | return this; |
| 456 | 449 | } |
| 457 | 450 | |
| 458 | - public ScassandraClusterBuilder withNetworkTopologyKeyspace(String name, Map<Integer,Integer> replicationFactors) { | |
| 451 | + public ScassandraClusterBuilder withNetworkTopologyKeyspace(String name, Map<Integer, Integer> replicationFactors) { | |
| 459 | 452 | StringBuilder strategyOptionsBuilder = new StringBuilder("{"); |
| 460 | - for(Map.Entry<Integer,Integer> dc : replicationFactors.entrySet()) { | |
| 453 | + for (Map.Entry<Integer, Integer> dc : replicationFactors.entrySet()) { | |
| 461 | 454 | strategyOptionsBuilder.append("\""); |
| 462 | 455 | strategyOptionsBuilder.append(datacenter(dc.getKey())); |
| 463 | 456 | strategyOptionsBuilder.append("\":\""); |
| @@ -467,12 +460,12 @@ | ||
| 467 | 460 | |
| 468 | 461 | String strategyOptions = strategyOptionsBuilder.substring(0, strategyOptionsBuilder.length() - 1) + "}"; |
| 469 | 462 | |
| 470 | - Map<String,Object> ntsKeyspaceRow = ImmutableMap.<String,Object>builder() | |
| 471 | - .put("durable_writes", false) | |
| 472 | - .put("keyspace_name", name) | |
| 473 | - .put("strategy_class", "NetworkTopologyStrategy") | |
| 474 | - .put("strategy_options", strategyOptions) | |
| 475 | - .build(); | |
| 463 | + Map<String, Object> ntsKeyspaceRow = ImmutableMap.<String, Object>builder() | |
| 464 | + .put("durable_writes", false) | |
| 465 | + .put("keyspace_name", name) | |
| 466 | + .put("strategy_class", "NetworkTopologyStrategy") | |
| 467 | + .put("strategy_options", strategyOptions) | |
| 468 | + .build(); | |
| 476 | 469 | |
| 477 | 470 | keyspaceRows.add(ntsKeyspaceRow); |
| 478 | 471 | return this; |
modified driver-core/src/test/java/com/datastax/driver/core/ScassandraTestBase.java +20 −19
| @@ -15,9 +15,6 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.net.InetSocketAddress; | |
| 19 | -import java.util.Collections; | |
| 20 | - | |
| 21 | 18 | import org.scassandra.Scassandra; |
| 22 | 19 | import org.scassandra.ScassandraFactory; |
| 23 | 20 | import org.scassandra.http.client.ActivityClient; |
| @@ -30,6 +27,9 @@ | ||
| 30 | 27 | import org.testng.annotations.BeforeClass; |
| 31 | 28 | import org.testng.annotations.BeforeMethod; |
| 32 | 29 | |
| 30 | +import java.net.InetSocketAddress; | |
| 31 | +import java.util.Collections; | |
| 32 | + | |
| 33 | 33 | import static org.assertj.core.api.Assertions.fail; |
| 34 | 34 | |
| 35 | 35 | /** |
| @@ -58,7 +58,7 @@ | ||
| 58 | 58 | |
| 59 | 59 | protected static String ip = CCMBridge.IP_PREFIX + "1"; |
| 60 | 60 | |
| 61 | - @BeforeClass(groups = { "short", "long" }) | |
| 61 | + @BeforeClass(groups = {"short", "long"}) | |
| 62 | 62 | public void startScassandra() { |
| 63 | 63 | scassandra = ScassandraFactory.createServer(ip, BINARY_PORT, ip, ADMIN_PORT); |
| 64 | 64 | scassandra.start(); |
| @@ -68,14 +68,14 @@ | ||
| 68 | 68 | hostAddress = new InetSocketAddress(ip, scassandra.getBinaryPort()); |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - @AfterClass(groups = { "short", "long" }) | |
| 71 | + @AfterClass(groups = {"short", "long"}) | |
| 72 | 72 | public void stopScassandra() { |
| 73 | - if(scassandra != null) | |
| 73 | + if (scassandra != null) | |
| 74 | 74 | scassandra.stop(); |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - @BeforeMethod(groups = { "short", "long" }) | |
| 78 | - @AfterMethod(groups = { "short", "long" }) | |
| 77 | + @BeforeMethod(groups = {"short", "long"}) | |
| 78 | + @AfterMethod(groups = {"short", "long"}) | |
| 79 | 79 | public void resetClients() { |
| 80 | 80 | activityClient.clearAllRecordedActivity(); |
| 81 | 81 | primingClient.clearAllPrimes(); |
| @@ -84,28 +84,29 @@ | ||
| 84 | 84 | |
| 85 | 85 | protected Cluster.Builder createClusterBuilder() { |
| 86 | 86 | Cluster.Builder builder = Cluster.builder() |
| 87 | - .addContactPointsWithPorts(Collections.singletonList(hostAddress)) | |
| 88 | - .withPoolingOptions(new PoolingOptions() | |
| 89 | - .setCoreConnectionsPerHost(HostDistance.LOCAL, 1) | |
| 90 | - .setMaxConnectionsPerHost(HostDistance.LOCAL, 1) | |
| 91 | - .setHeartbeatIntervalSeconds(0)) | |
| 92 | - .withPort(scassandra.getBinaryPort()); | |
| 87 | + .addContactPointsWithPorts(Collections.singletonList(hostAddress)) | |
| 88 | + .withPoolingOptions(new PoolingOptions() | |
| 89 | + .setCoreConnectionsPerHost(HostDistance.LOCAL, 1) | |
| 90 | + .setMaxConnectionsPerHost(HostDistance.LOCAL, 1) | |
| 91 | + .setHeartbeatIntervalSeconds(0)) | |
| 92 | + .withPort(scassandra.getBinaryPort()); | |
| 93 | 93 | return builder; |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | /** |
| 97 | 97 | * An overrideable method for building on to the Cluster.Builder used for this |
| 98 | 98 | * class. |
| 99 | + * | |
| 99 | 100 | * @param builder |
| 100 | 101 | * @return |
| 101 | 102 | */ |
| 102 | 103 | protected Cluster.Builder configure(Cluster.Builder builder) { |
| 103 | - return builder; | |
| 104 | + return builder; | |
| 104 | 105 | } |
| 105 | 106 | |
| 106 | 107 | protected Host retrieveSingleHost(Cluster cluster) { |
| 107 | 108 | Host host = cluster.getMetadata().getHost(hostAddress); |
| 108 | - if(host == null) { | |
| 109 | + if (host == null) { | |
| 109 | 110 | fail("Unable to retrieve host"); |
| 110 | 111 | } |
| 111 | 112 | return host; |
| @@ -123,7 +124,7 @@ | ||
| 123 | 124 | |
| 124 | 125 | protected Host host; |
| 125 | 126 | |
| 126 | - @BeforeClass(groups = { "short", "long" }, dependsOnMethods = "startScassandra") | |
| 127 | + @BeforeClass(groups = {"short", "long"}, dependsOnMethods = "startScassandra") | |
| 127 | 128 | public void initCluster() { |
| 128 | 129 | Cluster.Builder builder = createClusterBuilder(); |
| 129 | 130 | cluster = builder.build(); |
| @@ -131,13 +132,13 @@ | ||
| 131 | 132 | session = cluster.connect(); |
| 132 | 133 | } |
| 133 | 134 | |
| 134 | - @AfterClass(groups = { "short", "long" }) | |
| 135 | + @AfterClass(groups = {"short", "long"}) | |
| 135 | 136 | public void closeCluster() { |
| 136 | 137 | if (cluster != null) |
| 137 | 138 | cluster.close(); |
| 138 | 139 | } |
| 139 | 140 | |
| 140 | - @AfterClass(groups = { "short", "long" }, dependsOnMethods = "closeCluster") | |
| 141 | + @AfterClass(groups = {"short", "long"}, dependsOnMethods = "closeCluster") | |
| 141 | 142 | @Override |
| 142 | 143 | public void stopScassandra() { |
| 143 | 144 | super.stopScassandra(); |
modified driver-core/src/test/java/com/datastax/driver/core/SchemaAgreementTest.java +6 −7
| @@ -15,18 +15,17 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.net.InetAddress; | |
| 19 | -import java.util.UUID; | |
| 20 | - | |
| 18 | +import com.datastax.driver.core.exceptions.DriverException; | |
| 19 | +import com.datastax.driver.core.utils.UUIDs; | |
| 21 | 20 | import org.testng.annotations.AfterClass; |
| 22 | 21 | import org.testng.annotations.AfterMethod; |
| 23 | 22 | import org.testng.annotations.BeforeClass; |
| 24 | 23 | import org.testng.annotations.Test; |
| 25 | 24 | |
| 26 | -import static org.assertj.core.api.Assertions.assertThat; | |
| 25 | +import java.net.InetAddress; | |
| 26 | +import java.util.UUID; | |
| 27 | 27 | |
| 28 | -import com.datastax.driver.core.exceptions.DriverException; | |
| 29 | -import com.datastax.driver.core.utils.UUIDs; | |
| 28 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 30 | 29 | |
| 31 | 30 | public class SchemaAgreementTest { |
| 32 | 31 | |
| @@ -102,7 +101,7 @@ | ||
| 102 | 101 | |
| 103 | 102 | private static void forceSchemaVersion(Session session, InetAddress peerAddress, UUID schemaVersion) { |
| 104 | 103 | session.execute(String.format("UPDATE system.peers SET schema_version = %s WHERE peer = %s", |
| 105 | - DataType.uuid().format(schemaVersion), DataType.inet().format(peerAddress))); | |
| 104 | + DataType.uuid().format(schemaVersion), DataType.inet().format(peerAddress))); | |
| 106 | 105 | } |
| 107 | 106 | |
| 108 | 107 | @AfterMethod(groups = "short") |
modified driver-core/src/test/java/com/datastax/driver/core/SchemaChangesCCTest.java +34 −40
| @@ -15,27 +15,21 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.util.Collections; | |
| 19 | -import java.util.Iterator; | |
| 20 | -import java.util.concurrent.TimeUnit; | |
| 21 | - | |
| 18 | +import com.datastax.driver.core.policies.DelegatingLoadBalancingPolicy; | |
| 19 | +import com.datastax.driver.core.policies.LoadBalancingPolicy; | |
| 20 | +import com.datastax.driver.core.policies.Policies; | |
| 22 | 21 | import com.google.common.util.concurrent.Uninterruptibles; |
| 23 | 22 | import org.mockito.ArgumentCaptor; |
| 24 | 23 | import org.testng.annotations.Test; |
| 25 | 24 | |
| 26 | -import static org.mockito.Matchers.any; | |
| 27 | -import static org.mockito.Mockito.mock; | |
| 28 | -import static org.mockito.Mockito.reset; | |
| 29 | -import static org.mockito.Mockito.timeout; | |
| 30 | -import static org.mockito.Mockito.verify; | |
| 31 | -import static org.testng.Assert.fail; | |
| 32 | - | |
| 33 | -import com.datastax.driver.core.policies.DelegatingLoadBalancingPolicy; | |
| 34 | -import com.datastax.driver.core.policies.LoadBalancingPolicy; | |
| 35 | -import com.datastax.driver.core.policies.Policies; | |
| 25 | +import java.util.Collections; | |
| 26 | +import java.util.Iterator; | |
| 27 | +import java.util.concurrent.TimeUnit; | |
| 36 | 28 | |
| 37 | 29 | import static com.datastax.driver.core.Assertions.assertThat; |
| 38 | 30 | import static com.datastax.driver.core.TestUtils.CREATE_KEYSPACE_SIMPLE_FORMAT; |
| 31 | +import static org.mockito.Matchers.any; | |
| 32 | +import static org.mockito.Mockito.*; | |
| 39 | 33 | |
| 40 | 34 | public class SchemaChangesCCTest { |
| 41 | 35 | |
| @@ -44,8 +38,8 @@ | ||
| 44 | 38 | /** |
| 45 | 39 | * Validates that any schema change events made while the control connection is down are |
| 46 | 40 | * propagated when the control connection is re-established. |
| 47 | - * <p> | |
| 48 | - * | |
| 41 | + * <p/> | |
| 42 | + * <p/> | |
| 49 | 43 | * Note that on control connection recovery not all schema changes are propagated. For example, |
| 50 | 44 | * if a table was altered and then dropped only a drop event would be received as that is all |
| 51 | 45 | * that can be discerned. |
| @@ -55,13 +49,13 @@ | ||
| 55 | 49 | * @jira_ticket JAVA-151 |
| 56 | 50 | * @since 2.0.11, 2.1.8, 2.2.1 |
| 57 | 51 | */ |
| 58 | - @Test(groups="long") | |
| 52 | + @Test(groups = "long") | |
| 59 | 53 | public void should_receive_changes_made_while_control_connection_is_down_on_reconnect() throws Exception { |
| 60 | 54 | ToggleablePolicy lbPolicy = new ToggleablePolicy(Policies.defaultLoadBalancingPolicy()); |
| 61 | 55 | |
| 62 | 56 | CCMBridge ccm = CCMBridge.builder("SchemaChangesCCTest").withNodes(2).build(); |
| 63 | 57 | Cluster.Builder builder = Cluster.builder() |
| 64 | - .withLoadBalancingPolicy(lbPolicy); | |
| 58 | + .withLoadBalancingPolicy(lbPolicy); | |
| 65 | 59 | Cluster cluster = builder.addContactPoint(CCMBridge.ipOfNode(1)).build(); |
| 66 | 60 | // Put cluster2 control connection on node 2 so it doesn't go down (to prevent noise for debugging). |
| 67 | 61 | Cluster cluster2 = builder.addContactPoint(CCMBridge.ipOfNode(2)).build(); |
| @@ -116,29 +110,29 @@ | ||
| 116 | 110 | // Poll on the control connection and wait for it to be reestablished. |
| 117 | 111 | long maxControlConnectionWait = 60000; |
| 118 | 112 | long startTime = System.currentTimeMillis(); |
| 119 | - while(!cluster.manager.controlConnection.isOpen() && System.currentTimeMillis() - startTime < maxControlConnectionWait) { | |
| 113 | + while (!cluster.manager.controlConnection.isOpen() && System.currentTimeMillis() - startTime < maxControlConnectionWait) { | |
| 120 | 114 | Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS); |
| 121 | 115 | } |
| 122 | 116 | |
| 123 | 117 | assertThat(cluster.manager.controlConnection.isOpen()) |
| 124 | - .as("Control connection was not opened after %dms.", maxControlConnectionWait) | |
| 125 | - .isTrue(); | |
| 118 | + .as("Control connection was not opened after %dms.", maxControlConnectionWait) | |
| 119 | + .isTrue(); | |
| 126 | 120 | |
| 127 | 121 | // Ensure the drop keyspace event shows up. |
| 128 | 122 | ArgumentCaptor<KeyspaceMetadata> removedKeyspace = ArgumentCaptor.forClass(KeyspaceMetadata.class); |
| 129 | 123 | verify(listener, timeout(NOTIF_TIMEOUT_MS).times(1)).onKeyspaceRemoved(removedKeyspace.capture()); |
| 130 | 124 | assertThat(removedKeyspace.getValue()) |
| 131 | - .hasName("ks2") | |
| 132 | - .isEqualTo(predroppedKeyspace); | |
| 125 | + .hasName("ks2") | |
| 126 | + .isEqualTo(predroppedKeyspace); | |
| 133 | 127 | |
| 134 | 128 | // Ensure the drop table event shows up. |
| 135 | 129 | ArgumentCaptor<TableMetadata> droppedTable = ArgumentCaptor.forClass(TableMetadata.class); |
| 136 | 130 | verify(listener, timeout(NOTIF_TIMEOUT_MS).times(1)).onTableRemoved(droppedTable.capture()); |
| 137 | 131 | |
| 138 | 132 | assertThat(droppedTable.getValue()) |
| 139 | - .isInKeyspace("ks1") | |
| 140 | - .hasName("tbl2") | |
| 141 | - .isEqualTo(predroppedTable); | |
| 133 | + .isInKeyspace("ks1") | |
| 134 | + .hasName("tbl2") | |
| 135 | + .isEqualTo(predroppedTable); | |
| 142 | 136 | |
| 143 | 137 | // Ensure that the alter keyspace event shows up. |
| 144 | 138 | ArgumentCaptor<KeyspaceMetadata> alteredKeyspace = ArgumentCaptor.forClass(KeyspaceMetadata.class); |
| @@ -147,14 +141,14 @@ | ||
| 147 | 141 | |
| 148 | 142 | // Previous metadata should match the metadata observed before disconnect. |
| 149 | 143 | assertThat(originalKeyspace.getValue()) |
| 150 | - .hasName("ks1") | |
| 151 | - .isDurableWrites() | |
| 152 | - .isEqualTo(prealteredKeyspace); | |
| 144 | + .hasName("ks1") | |
| 145 | + .isDurableWrites() | |
| 146 | + .isEqualTo(prealteredKeyspace); | |
| 153 | 147 | |
| 154 | 148 | // New metadata should reflect that the durable writes attribute changed. |
| 155 | 149 | assertThat(alteredKeyspace.getValue()) |
| 156 | - .hasName("ks1") | |
| 157 | - .isNotDurableWrites(); | |
| 150 | + .hasName("ks1") | |
| 151 | + .isNotDurableWrites(); | |
| 158 | 152 | |
| 159 | 153 | // Ensure the alter table event shows up. |
| 160 | 154 | ArgumentCaptor<TableMetadata> alteredTable = ArgumentCaptor.forClass(TableMetadata.class); |
| @@ -163,16 +157,16 @@ | ||
| 163 | 157 | |
| 164 | 158 | // Previous metadata should match the metadata observed before disconnect. |
| 165 | 159 | assertThat(originalTable.getValue()) |
| 166 | - .isInKeyspace("ks1") | |
| 167 | - .hasName("tbl1") | |
| 168 | - .hasColumn("v", DataType.text()) | |
| 169 | - .isEqualTo(prealteredTable); | |
| 160 | + .isInKeyspace("ks1") | |
| 161 | + .hasName("tbl1") | |
| 162 | + .hasColumn("v", DataType.text()) | |
| 163 | + .isEqualTo(prealteredTable); | |
| 170 | 164 | |
| 171 | 165 | // New metadata should reflect that the column type changed. |
| 172 | 166 | assertThat(alteredTable.getValue()) |
| 173 | - .isInKeyspace("ks1") | |
| 174 | - .hasName("tbl1") | |
| 175 | - .hasColumn("v", DataType.blob()); | |
| 167 | + .isInKeyspace("ks1") | |
| 168 | + .hasName("tbl1") | |
| 169 | + .hasColumn("v", DataType.blob()); | |
| 176 | 170 | |
| 177 | 171 | // Ensure the add keyspace event shows up. |
| 178 | 172 | ArgumentCaptor<KeyspaceMetadata> addedKeyspace = ArgumentCaptor.forClass(KeyspaceMetadata.class); |
| @@ -185,8 +179,8 @@ | ||
| 185 | 179 | verify(listener, timeout(NOTIF_TIMEOUT_MS).times(1)).onTableAdded(addedTable.capture()); |
| 186 | 180 | |
| 187 | 181 | assertThat(addedTable.getValue()) |
| 188 | - .isInKeyspace("ks1") | |
| 189 | - .hasName("tbl3"); | |
| 182 | + .isInKeyspace("ks1") | |
| 183 | + .hasName("tbl3"); | |
| 190 | 184 | } finally { |
| 191 | 185 | cluster.close(); |
| 192 | 186 | ccm.remove(); |
modified driver-core/src/test/java/com/datastax/driver/core/SchemaChangesTest.java +48 −48
| @@ -15,24 +15,22 @@ | ||
| 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 | - | |
| 18 | +import com.datastax.driver.core.utils.Bytes; | |
| 22 | 19 | import com.google.common.collect.Lists; |
| 23 | 20 | import com.google.common.util.concurrent.Futures; |
| 24 | 21 | import com.google.common.util.concurrent.ListenableFuture; |
| 25 | 22 | import org.mockito.ArgumentCaptor; |
| 26 | 23 | import org.testng.annotations.*; |
| 27 | 24 | |
| 28 | -import static org.mockito.Matchers.any; | |
| 29 | -import static org.mockito.Mockito.*; | |
| 30 | - | |
| 31 | -import com.datastax.driver.core.utils.Bytes; | |
| 25 | +import java.util.Collection; | |
| 26 | +import java.util.Collections; | |
| 27 | +import java.util.List; | |
| 32 | 28 | |
| 33 | 29 | import static com.datastax.driver.core.Assertions.assertThat; |
| 34 | 30 | import static com.datastax.driver.core.Metadata.handleId; |
| 35 | 31 | import static com.datastax.driver.core.TestUtils.nonDebouncingQueryOptions; |
| 32 | +import static org.mockito.Matchers.any; | |
| 33 | +import static org.mockito.Mockito.*; | |
| 36 | 34 | |
| 37 | 35 | public class SchemaChangesTest extends CCMBridge.PerClassSingleNodeCluster { |
| 38 | 36 | |
| @@ -44,7 +42,9 @@ | ||
| 44 | 42 | private static final String ALTER_TABLE = "ALTER TABLE %s.table1 ADD j int"; |
| 45 | 43 | private static final String DROP_TABLE = "DROP TABLE %s.table1"; |
| 46 | 44 | |
| 47 | - /** The maximum time that the test will wait to check that listeners have been notified */ | |
| 45 | + /** | |
| 46 | + * The maximum time that the test will wait to check that listeners have been notified | |
| 47 | + */ | |
| 48 | 48 | private static final int NOTIF_TIMEOUT_MS = 5000; |
| 49 | 49 | |
| 50 | 50 | Cluster cluster1; |
| @@ -74,16 +74,16 @@ | ||
| 74 | 74 | @BeforeClass(groups = "short") |
| 75 | 75 | public void setup() throws InterruptedException { |
| 76 | 76 | Cluster.Builder builder = configure(Cluster.builder()) |
| 77 | - .addContactPointsWithPorts(Collections.singletonList(hostAddress)) | |
| 78 | - .withQueryOptions(nonDebouncingQueryOptions()); | |
| 77 | + .addContactPointsWithPorts(Collections.singletonList(hostAddress)) | |
| 78 | + .withQueryOptions(nonDebouncingQueryOptions()); | |
| 79 | 79 | cluster1 = builder.build(); |
| 80 | 80 | cluster2 = builder.build(); |
| 81 | 81 | schemaDisabledCluster = spy(configure(Cluster.builder()) |
| 82 | - .addContactPointsWithPorts(Collections.singletonList(hostAddress)) | |
| 83 | - .withClusterName("schema-disabled") | |
| 84 | - .withQueryOptions(nonDebouncingQueryOptions() | |
| 85 | - .setMetadataEnabled(false) | |
| 86 | - ).build()); | |
| 82 | + .addContactPointsWithPorts(Collections.singletonList(hostAddress)) | |
| 83 | + .withClusterName("schema-disabled") | |
| 84 | + .withQueryOptions(nonDebouncingQueryOptions() | |
| 85 | + .setMetadataEnabled(false) | |
| 86 | + ).build()); | |
| 87 | 87 | |
| 88 | 88 | schemaDisabledSession = schemaDisabledCluster.connect(); |
| 89 | 89 | |
| @@ -117,12 +117,12 @@ | ||
| 117 | 117 | |
| 118 | 118 | @DataProvider(name = "existingKeyspaceName") |
| 119 | 119 | public static Object[][] existingKeyspaceName() { |
| 120 | - return new Object[][]{ { "lowercase" }, { "\"CaseSensitive\"" } }; | |
| 120 | + return new Object[][]{{"lowercase"}, {"\"CaseSensitive\""}}; | |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | @DataProvider(name = "newKeyspaceName") |
| 124 | 124 | public static Object[][] newKeyspaceName() { |
| 125 | - return new Object[][]{ { "lowercase2" }, { "\"CaseSensitive2\"" } }; | |
| 125 | + return new Object[][]{{"lowercase2"}, {"\"CaseSensitive2\""}}; | |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | @BeforeMethod(groups = "short") |
| @@ -152,8 +152,8 @@ | ||
| 152 | 152 | ArgumentCaptor<TableMetadata> added = ArgumentCaptor.forClass(TableMetadata.class); |
| 153 | 153 | verify(listener, timeout(NOTIF_TIMEOUT_MS).times(1)).onTableAdded(added.capture()); |
| 154 | 154 | assertThat(added.getValue()) |
| 155 | - .isInKeyspace(handleId(keyspace)) | |
| 156 | - .hasName("table1"); | |
| 155 | + .isInKeyspace(handleId(keyspace)) | |
| 156 | + .hasName("table1"); | |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | for (Metadata m : metadatas) |
| @@ -170,8 +170,8 @@ | ||
| 170 | 170 | added = ArgumentCaptor.forClass(TableMetadata.class); |
| 171 | 171 | verify(listener, timeout(NOTIF_TIMEOUT_MS).times(1)).onTableAdded(added.capture()); |
| 172 | 172 | assertThat(added.getValue()) |
| 173 | - .isInKeyspace(handleId(keyspace)) | |
| 174 | - .hasName("table1"); | |
| 173 | + .isInKeyspace(handleId(keyspace)) | |
| 174 | + .hasName("table1"); | |
| 175 | 175 | } |
| 176 | 176 | execute(ALTER_TABLE, keyspace); |
| 177 | 177 | for (SchemaChangeListener listener : listeners) { |
| @@ -179,12 +179,12 @@ | ||
| 179 | 179 | ArgumentCaptor<TableMetadata> previous = ArgumentCaptor.forClass(TableMetadata.class); |
| 180 | 180 | verify(listener, timeout(NOTIF_TIMEOUT_MS).times(1)).onTableChanged(current.capture(), previous.capture()); |
| 181 | 181 | assertThat(previous.getValue()) |
| 182 | - .isEqualTo(added.getValue()) | |
| 183 | - .hasNoColumn("j"); | |
| 182 | + .isEqualTo(added.getValue()) | |
| 183 | + .hasNoColumn("j"); | |
| 184 | 184 | assertThat(current.getValue()) |
| 185 | - .isInKeyspace(handleId(keyspace)) | |
| 186 | - .hasName("table1") | |
| 187 | - .hasColumn("j"); | |
| 185 | + .isInKeyspace(handleId(keyspace)) | |
| 186 | + .hasName("table1") | |
| 187 | + .hasColumn("j"); | |
| 188 | 188 | } |
| 189 | 189 | for (Metadata m : metadatas) |
| 190 | 190 | assertThat(m.getKeyspace(keyspace).getTable("table1")).hasColumn("j"); |
| @@ -197,8 +197,8 @@ | ||
| 197 | 197 | ArgumentCaptor<TableMetadata> added = ArgumentCaptor.forClass(TableMetadata.class); |
| 198 | 198 | verify(listener, timeout(NOTIF_TIMEOUT_MS).times(1)).onTableAdded(added.capture()); |
| 199 | 199 | assertThat(added.getValue()) |
| 200 | - .hasName("table1") | |
| 201 | - .isInKeyspace(handleId(keyspace)); | |
| 200 | + .hasName("table1") | |
| 201 | + .isInKeyspace(handleId(keyspace)); | |
| 202 | 202 | } |
| 203 | 203 | execute(DROP_TABLE, keyspace); |
| 204 | 204 | for (Metadata m : metadatas) |
| @@ -239,11 +239,11 @@ | ||
| 239 | 239 | ArgumentCaptor<KeyspaceMetadata> previous = ArgumentCaptor.forClass(KeyspaceMetadata.class); |
| 240 | 240 | verify(listener, timeout(NOTIF_TIMEOUT_MS).times(1)).onKeyspaceChanged(current.capture(), previous.capture()); |
| 241 | 241 | assertThat(previous.getValue()) |
| 242 | - .isEqualTo(added.getValue()) | |
| 243 | - .isDurableWrites(); | |
| 242 | + .isEqualTo(added.getValue()) | |
| 243 | + .isDurableWrites(); | |
| 244 | 244 | assertThat(current.getValue()) |
| 245 | - .hasName(handleId(keyspace)) | |
| 246 | - .isNotDurableWrites(); | |
| 245 | + .hasName(handleId(keyspace)) | |
| 246 | + .isNotDurableWrites(); | |
| 247 | 247 | } |
| 248 | 248 | for (Metadata m : metadatas) |
| 249 | 249 | assertThat(m.getKeyspace(keyspace)).isNotDurableWrites(); |
| @@ -260,13 +260,13 @@ | ||
| 260 | 260 | ArgumentCaptor<TableMetadata> table = ArgumentCaptor.forClass(TableMetadata.class); |
| 261 | 261 | verify(listener, timeout(NOTIF_TIMEOUT_MS).times(1)).onTableRemoved(table.capture()); |
| 262 | 262 | assertThat(table.getValue()) |
| 263 | - .hasName("table1") | |
| 264 | - .isInKeyspace(handleId(keyspace)); | |
| 263 | + .hasName("table1") | |
| 264 | + .isInKeyspace(handleId(keyspace)); | |
| 265 | 265 | |
| 266 | 266 | ArgumentCaptor<KeyspaceMetadata> ks = ArgumentCaptor.forClass(KeyspaceMetadata.class); |
| 267 | 267 | verify(listener, timeout(NOTIF_TIMEOUT_MS).times(1)).onKeyspaceRemoved(ks.capture()); |
| 268 | 268 | assertThat(ks.getValue()) |
| 269 | - .hasName(handleId(keyspace)); | |
| 269 | + .hasName(handleId(keyspace)); | |
| 270 | 270 | } |
| 271 | 271 | for (Metadata m : metadatas) { |
| 272 | 272 | assertThat(m.getKeyspace(keyspace)).isNull(); |
| @@ -285,10 +285,10 @@ | ||
| 285 | 285 | @Test(groups = "short", expectedExceptions = IllegalStateException.class) |
| 286 | 286 | public void should_throw_illegal_state_exception_on_newToken_with_metadata_disabled() { |
| 287 | 287 | Cluster cluster = configure(Cluster.builder()) |
| 288 | - .addContactPointsWithPorts(Collections.singletonList(hostAddress)) | |
| 289 | - .withQueryOptions(nonDebouncingQueryOptions() | |
| 290 | - .setMetadataEnabled(false) | |
| 291 | - ).build(); | |
| 288 | + .addContactPointsWithPorts(Collections.singletonList(hostAddress)) | |
| 289 | + .withQueryOptions(nonDebouncingQueryOptions() | |
| 290 | + .setMetadataEnabled(false) | |
| 291 | + ).build(); | |
| 292 | 292 | |
| 293 | 293 | try { |
| 294 | 294 | cluster.init(); |
| @@ -309,10 +309,10 @@ | ||
| 309 | 309 | @Test(groups = "short", expectedExceptions = IllegalStateException.class) |
| 310 | 310 | public void should_throw_illegal_state_exception_on_newTokenRange_with_metadata_disabled() { |
| 311 | 311 | Cluster cluster = configure(Cluster.builder()) |
| 312 | - .addContactPointsWithPorts(Collections.singletonList(hostAddress)) | |
| 313 | - .withQueryOptions(nonDebouncingQueryOptions() | |
| 314 | - .setMetadataEnabled(false) | |
| 315 | - ).build(); | |
| 312 | + .addContactPointsWithPorts(Collections.singletonList(hostAddress)) | |
| 313 | + .withQueryOptions(nonDebouncingQueryOptions() | |
| 314 | + .setMetadataEnabled(false) | |
| 315 | + ).build(); | |
| 316 | 316 | |
| 317 | 317 | try { |
| 318 | 318 | cluster.init(); |
| @@ -383,10 +383,10 @@ | ||
| 383 | 383 | @AfterMethod(groups = "short") |
| 384 | 384 | public void cleanup() throws InterruptedException { |
| 385 | 385 | ListenableFuture<List<ResultSet>> f = Futures.successfulAsList(Lists.newArrayList( |
| 386 | - session1.executeAsync("DROP TABLE lowercase.table1"), | |
| 387 | - session1.executeAsync("DROP TABLE \"CaseSensitive\".table1"), | |
| 388 | - session1.executeAsync("DROP KEYSPACE lowercase2"), | |
| 389 | - session1.executeAsync("DROP KEYSPACE \"CaseSensitive2\"") | |
| 386 | + session1.executeAsync("DROP TABLE lowercase.table1"), | |
| 387 | + session1.executeAsync("DROP TABLE \"CaseSensitive\".table1"), | |
| 388 | + session1.executeAsync("DROP KEYSPACE lowercase2"), | |
| 389 | + session1.executeAsync("DROP KEYSPACE \"CaseSensitive2\"") | |
| 390 | 390 | )); |
| 391 | 391 | Futures.getUnchecked(f); |
| 392 | 392 | } |
modified driver-core/src/test/java/com/datastax/driver/core/SchemaRefreshDebouncerTest.java +26 −27
| @@ -15,21 +15,20 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.util.Collection; | |
| 19 | - | |
| 20 | 18 | import org.mockito.ArgumentCaptor; |
| 21 | 19 | import org.testng.annotations.AfterClass; |
| 22 | 20 | import org.testng.annotations.AfterMethod; |
| 23 | 21 | import org.testng.annotations.BeforeClass; |
| 24 | 22 | import org.testng.annotations.Test; |
| 25 | 23 | |
| 26 | -import static com.google.common.collect.Lists.newArrayList; | |
| 27 | -import static org.mockito.ArgumentCaptor.forClass; | |
| 28 | -import static org.mockito.Mockito.*; | |
| 24 | +import java.util.Collection; | |
| 29 | 25 | |
| 30 | 26 | import static com.datastax.driver.core.Assertions.assertThat; |
| 31 | 27 | import static com.datastax.driver.core.TestUtils.CREATE_KEYSPACE_SIMPLE_FORMAT; |
| 32 | 28 | import static com.datastax.driver.core.TestUtils.CREATE_TABLE_SIMPLE_FORMAT; |
| 29 | +import static com.google.common.collect.Lists.newArrayList; | |
| 30 | +import static org.mockito.ArgumentCaptor.forClass; | |
| 31 | +import static org.mockito.Mockito.*; | |
| 33 | 32 | |
| 34 | 33 | public class SchemaRefreshDebouncerTest extends CCMBridge.PerClassSingleNodeCluster { |
| 35 | 34 | |
| @@ -61,9 +60,9 @@ | ||
| 61 | 60 | queryOptions.setMaxPendingRefreshSchemaRequests(5); |
| 62 | 61 | // Create a separate cluster that will receive the schema events on its control connection. |
| 63 | 62 | cluster2 = this.configure(Cluster.builder()) |
| 64 | - .addContactPointsWithPorts(newArrayList(hostAddress)) | |
| 65 | - .withQueryOptions(queryOptions) | |
| 66 | - .build(); | |
| 63 | + .addContactPointsWithPorts(newArrayList(hostAddress)) | |
| 64 | + .withQueryOptions(queryOptions) | |
| 65 | + .build(); | |
| 67 | 66 | session2 = cluster2.connect(); |
| 68 | 67 | |
| 69 | 68 | // Create a spy of the Cluster's control connection and replace it with the spy. |
| @@ -88,7 +87,7 @@ | ||
| 88 | 87 | public void teardown() { |
| 89 | 88 | cluster2.close(); |
| 90 | 89 | // drop all keyspaces |
| 91 | - for(String keyspace : keyspaces) { | |
| 90 | + for (String keyspace : keyspaces) { | |
| 92 | 91 | session.execute("DROP KEYSPACE " + keyspace); |
| 93 | 92 | } |
| 94 | 93 | } |
| @@ -180,7 +179,7 @@ | ||
| 180 | 179 | reset(listener); |
| 181 | 180 | |
| 182 | 181 | int tableCount = 3; |
| 183 | - for(int i =0 ; i < tableCount; i++) { | |
| 182 | + for (int i = 0; i < tableCount; i++) { | |
| 184 | 183 | session.execute(String.format(CREATE_TABLE_SIMPLE_FORMAT, keyspace + "." + "tbl" + i)); |
| 185 | 184 | } |
| 186 | 185 | |
| @@ -193,7 +192,7 @@ | ||
| 193 | 192 | KeyspaceMetadata ksm = cluster2.getMetadata().getKeyspace(keyspace); |
| 194 | 193 | assertThat(ksm).isNotNull(); |
| 195 | 194 | // metadata is present for each table. |
| 196 | - for(int i = 0; i < tableCount; i++) { | |
| 195 | + for (int i = 0; i < tableCount; i++) { | |
| 197 | 196 | String table = "tbl" + i; |
| 198 | 197 | // Should have never been a refreshSchema on the table. |
| 199 | 198 | verify(controlConnection, never()).refreshSchema(keyspace, table); |
| @@ -231,16 +230,16 @@ | ||
| 231 | 230 | ArgumentCaptor<TableMetadata> captor = forClass(TableMetadata.class); |
| 232 | 231 | verify(listener, timeout(DEBOUNCE_TIME * 2).only()).onTableChanged(captor.capture(), original.capture()); |
| 233 | 232 | assertThat(captor.getValue()) |
| 234 | - .hasName(table) | |
| 235 | - .isInKeyspace(keyspace) | |
| 236 | - .hasColumn(columnName) | |
| 237 | - .hasComment(comment); | |
| 233 | + .hasName(table) | |
| 234 | + .isInKeyspace(keyspace) | |
| 235 | + .hasColumn(columnName) | |
| 236 | + .hasComment(comment); | |
| 238 | 237 | |
| 239 | 238 | assertThat(original.getValue()) |
| 240 | - .hasName(table) | |
| 241 | - .isInKeyspace(keyspace) | |
| 242 | - .hasNoColumn(columnName) | |
| 243 | - .doesNotHaveComment(comment); | |
| 239 | + .hasName(table) | |
| 240 | + .isInKeyspace(keyspace) | |
| 241 | + .hasNoColumn(columnName) | |
| 242 | + .doesNotHaveComment(comment); | |
| 244 | 243 | |
| 245 | 244 | // Verify a refresh of the table was executed, but only once. |
| 246 | 245 | verify(controlConnection, times(1)).refreshSchema(keyspace, table); |
| @@ -249,10 +248,10 @@ | ||
| 249 | 248 | assertThat(ksm).isNotNull(); |
| 250 | 249 | TableMetadata tm = ksm.getTable(table); |
| 251 | 250 | assertThat(tm) |
| 252 | - .hasName(table) | |
| 253 | - .isInKeyspace(keyspace) | |
| 254 | - .hasColumn(columnName) | |
| 255 | - .hasComment(comment); | |
| 251 | + .hasName(table) | |
| 252 | + .isInKeyspace(keyspace) | |
| 253 | + .hasColumn(columnName) | |
| 254 | + .hasComment(comment); | |
| 256 | 255 | } |
| 257 | 256 | |
| 258 | 257 | /** |
| @@ -268,7 +267,7 @@ | ||
| 268 | 267 | @Test(groups = "short") |
| 269 | 268 | public void should_debounce_and_coalesce_multiple_keyspace_creates_into_refresh_entire_schema() throws Exception { |
| 270 | 269 | String prefix = "sdacmkc"; |
| 271 | - for(int i = 0; i < 3; i++) { | |
| 270 | + for (int i = 0; i < 3; i++) { | |
| 272 | 271 | session.execute(String.format(CREATE_KEYSPACE_SIMPLE_FORMAT, prefix + i, 1)); |
| 273 | 272 | keyspaces.add(prefix + i); |
| 274 | 273 | } |
| @@ -277,7 +276,7 @@ | ||
| 277 | 276 | // Verify a complete schema refresh was executed, but only once. |
| 278 | 277 | verify(controlConnection, times(1)).refreshSchema(null, null); |
| 279 | 278 | |
| 280 | - for(int i = 0; i < 3; i++) { | |
| 279 | + for (int i = 0; i < 3; i++) { | |
| 281 | 280 | KeyspaceMetadata ksm = cluster2.getMetadata().getKeyspace(prefix + i); |
| 282 | 281 | assertThat(ksm).isNotNull().hasName(prefix + i); |
| 283 | 282 | } |
| @@ -295,7 +294,7 @@ | ||
| 295 | 294 | @Test(groups = "short") |
| 296 | 295 | public void should_refresh_when_max_pending_requests_reached() throws Exception { |
| 297 | 296 | String prefix = "srwmprr"; |
| 298 | - for(int i = 0; i < 5; i++) { | |
| 297 | + for (int i = 0; i < 5; i++) { | |
| 299 | 298 | session.execute(String.format(CREATE_KEYSPACE_SIMPLE_FORMAT, prefix + i, 1)); |
| 300 | 299 | keyspaces.add(prefix + i); |
| 301 | 300 | } |
| @@ -305,7 +304,7 @@ | ||
| 305 | 304 | // Verify a complete schema refresh was executed, but only once. |
| 306 | 305 | verify(controlConnection, times(1)).refreshSchema(null, null); |
| 307 | 306 | |
| 308 | - for(int i = 0; i < 5; i++) { | |
| 307 | + for (int i = 0; i < 5; i++) { | |
| 309 | 308 | KeyspaceMetadata ksm = cluster2.getMetadata().getKeyspace(prefix + i); |
| 310 | 309 | assertThat(ksm).isNotNull().hasName(prefix + i); |
| 311 | 310 | } |
modified driver-core/src/test/java/com/datastax/driver/core/SchemaTest.java +60 −59
| @@ -15,11 +15,12 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.util.*; | |
| 19 | - | |
| 20 | 18 | import org.slf4j.Logger; |
| 21 | 19 | import org.slf4j.LoggerFactory; |
| 22 | 20 | import org.testng.annotations.Test; |
| 21 | + | |
| 22 | +import java.util.*; | |
| 23 | + | |
| 23 | 24 | import static org.testng.Assert.assertEquals; |
| 24 | 25 | |
| 25 | 26 | /** |
| @@ -36,9 +37,9 @@ | ||
| 36 | 37 | @Override |
| 37 | 38 | protected Cluster.Builder configure(Cluster.Builder builder) { |
| 38 | 39 | return builder.withQueryOptions(new QueryOptions() |
| 39 | - .setRefreshNodeIntervalMillis(0) | |
| 40 | - .setRefreshNodeListIntervalMillis(0) | |
| 41 | - .setRefreshSchemaIntervalMillis(0) | |
| 40 | + .setRefreshNodeIntervalMillis(0) | |
| 41 | + .setRefreshNodeListIntervalMillis(0) | |
| 42 | + .setRefreshSchemaIntervalMillis(0) | |
| 42 | 43 | ); |
| 43 | 44 | } |
| 44 | 45 | |
| @@ -46,51 +47,51 @@ | ||
| 46 | 47 | protected Collection<String> getTableDefinitions() { |
| 47 | 48 | |
| 48 | 49 | String sparse = String.format("CREATE TABLE %s.sparse (\n" |
| 49 | - + " k text,\n" | |
| 50 | - + " c1 int,\n" | |
| 51 | - + " c2 float,\n" | |
| 52 | - + " l list<text>,\n" | |
| 53 | - + " v int,\n" | |
| 54 | - + " PRIMARY KEY (k, c1, c2)\n" | |
| 55 | - + ");", keyspace); | |
| 50 | + + " k text,\n" | |
| 51 | + + " c1 int,\n" | |
| 52 | + + " c2 float,\n" | |
| 53 | + + " l list<text>,\n" | |
| 54 | + + " v int,\n" | |
| 55 | + + " PRIMARY KEY (k, c1, c2)\n" | |
| 56 | + + ");", keyspace); | |
| 56 | 57 | |
| 57 | 58 | String st = String.format("CREATE TABLE %s.static (\n" |
| 58 | - + " k text,\n" | |
| 59 | - + " i int,\n" | |
| 60 | - + " m map<text, timeuuid>,\n" | |
| 61 | - + " v int,\n" | |
| 62 | - + " PRIMARY KEY (k)\n" | |
| 63 | - + ");", keyspace); | |
| 59 | + + " k text,\n" | |
| 60 | + + " i int,\n" | |
| 61 | + + " m map<text, timeuuid>,\n" | |
| 62 | + + " v int,\n" | |
| 63 | + + " PRIMARY KEY (k)\n" | |
| 64 | + + ");", keyspace); | |
| 64 | 65 | |
| 65 | 66 | String counters = String.format("CREATE TABLE %s.counters (\n" |
| 66 | - + " k text,\n" | |
| 67 | - + " c counter,\n" | |
| 68 | - + " PRIMARY KEY (k)\n" | |
| 69 | - + ");", keyspace); | |
| 67 | + + " k text,\n" | |
| 68 | + + " c counter,\n" | |
| 69 | + + " PRIMARY KEY (k)\n" | |
| 70 | + + ");", keyspace); | |
| 70 | 71 | |
| 71 | 72 | String compactStatic = String.format("CREATE TABLE %s.compact_static (\n" |
| 72 | - + " k text,\n" | |
| 73 | - + " i int,\n" | |
| 74 | - + " t timeuuid,\n" | |
| 75 | - + " v int,\n" | |
| 76 | - + " PRIMARY KEY (k)\n" | |
| 77 | - + ") WITH COMPACT STORAGE;", keyspace); | |
| 73 | + + " k text,\n" | |
| 74 | + + " i int,\n" | |
| 75 | + + " t timeuuid,\n" | |
| 76 | + + " v int,\n" | |
| 77 | + + " PRIMARY KEY (k)\n" | |
| 78 | + + ") WITH COMPACT STORAGE;", keyspace); | |
| 78 | 79 | |
| 79 | 80 | String compactDynamic = String.format("CREATE TABLE %s.compact_dynamic (\n" |
| 80 | - + " k text,\n" | |
| 81 | - + " c int,\n" | |
| 82 | - + " v timeuuid,\n" | |
| 83 | - + " PRIMARY KEY (k, c)\n" | |
| 84 | - + ") WITH COMPACT STORAGE;", keyspace); | |
| 81 | + + " k text,\n" | |
| 82 | + + " c int,\n" | |
| 83 | + + " v timeuuid,\n" | |
| 84 | + + " PRIMARY KEY (k, c)\n" | |
| 85 | + + ") WITH COMPACT STORAGE;", keyspace); | |
| 85 | 86 | |
| 86 | 87 | String compactComposite = String.format("CREATE TABLE %s.compact_composite (\n" |
| 87 | - + " k text,\n" | |
| 88 | - + " c1 int,\n" | |
| 89 | - + " c2 float,\n" | |
| 90 | - + " c3 double,\n" | |
| 91 | - + " v timeuuid,\n" | |
| 92 | - + " PRIMARY KEY (k, c1, c2, c3)\n" | |
| 93 | - + ") WITH COMPACT STORAGE;", keyspace); | |
| 88 | + + " k text,\n" | |
| 89 | + + " c1 int,\n" | |
| 90 | + + " c2 float,\n" | |
| 91 | + + " c3 double,\n" | |
| 92 | + + " v timeuuid,\n" | |
| 93 | + + " PRIMARY KEY (k, c1, c2, c3)\n" | |
| 94 | + + ") WITH COMPACT STORAGE;", keyspace); | |
| 94 | 95 | |
| 95 | 96 | cql3.put("sparse", sparse); |
| 96 | 97 | cql3.put("static", st); |
| @@ -102,7 +103,7 @@ | ||
| 102 | 103 | Properties properties = System.getProperties(); |
| 103 | 104 | String vmVersion = properties.getProperty("java.vm.specification.version"); |
| 104 | 105 | double javaVersion = 1.6; |
| 105 | - if(vmVersion != null) { | |
| 106 | + if (vmVersion != null) { | |
| 106 | 107 | try { |
| 107 | 108 | javaVersion = Double.parseDouble(vmVersion); |
| 108 | 109 | } catch (NumberFormatException e) { |
| @@ -112,27 +113,27 @@ | ||
| 112 | 113 | |
| 113 | 114 | // Ordering of compaction options will be dependent on JDK. See schemaOptionsTest comments for explanation of why this is needed. |
| 114 | 115 | String compactionOptions; |
| 115 | - if(javaVersion >= 1.8) | |
| 116 | + if (javaVersion >= 1.8) | |
| 116 | 117 | compactionOptions = " AND compaction = { 'sstable_size_in_mb' : 15, 'class' : 'org.apache.cassandra.db.compaction.LeveledCompactionStrategy' }\n"; |
| 117 | 118 | else |
| 118 | 119 | compactionOptions = " AND compaction = { 'class' : 'org.apache.cassandra.db.compaction.LeveledCompactionStrategy', 'sstable_size_in_mb' : 15 }\n"; |
| 119 | 120 | |
| 120 | 121 | withOptions = String.format("CREATE TABLE %s.with_options (\n" |
| 121 | - + " k text,\n" | |
| 122 | - + " v1 int,\n" | |
| 123 | - + " v2 int,\n" | |
| 124 | - + " i int,\n" | |
| 125 | - + " PRIMARY KEY (k, v1, v2)\n" | |
| 126 | - + ") WITH CLUSTERING ORDER BY (v1 DESC, v2 ASC)\n" | |
| 127 | - + " AND read_repair_chance = 0.5\n" | |
| 128 | - + " AND dclocal_read_repair_chance = 0.6\n" | |
| 129 | - + " AND replicate_on_write = true\n" | |
| 130 | - + " AND gc_grace_seconds = 42\n" | |
| 131 | - + " AND bloom_filter_fp_chance = 0.01\n" | |
| 132 | - + " AND caching = 'ALL'\n" | |
| 133 | - + " AND comment = 'My awesome table'\n" | |
| 134 | - + compactionOptions | |
| 135 | - + " AND compression = { 'sstable_compression' : 'org.apache.cassandra.io.compress.SnappyCompressor', 'chunk_length_kb' : 128 };", keyspace); | |
| 122 | + + " k text,\n" | |
| 123 | + + " v1 int,\n" | |
| 124 | + + " v2 int,\n" | |
| 125 | + + " i int,\n" | |
| 126 | + + " PRIMARY KEY (k, v1, v2)\n" | |
| 127 | + + ") WITH CLUSTERING ORDER BY (v1 DESC, v2 ASC)\n" | |
| 128 | + + " AND read_repair_chance = 0.5\n" | |
| 129 | + + " AND dclocal_read_repair_chance = 0.6\n" | |
| 130 | + + " AND replicate_on_write = true\n" | |
| 131 | + + " AND gc_grace_seconds = 42\n" | |
| 132 | + + " AND bloom_filter_fp_chance = 0.01\n" | |
| 133 | + + " AND caching = 'ALL'\n" | |
| 134 | + + " AND comment = 'My awesome table'\n" | |
| 135 | + + compactionOptions | |
| 136 | + + " AND compression = { 'sstable_compression' : 'org.apache.cassandra.io.compress.SnappyCompressor', 'chunk_length_kb' : 128 };", keyspace); | |
| 136 | 137 | |
| 137 | 138 | List<String> allDefs = new ArrayList<String>(); |
| 138 | 139 | allDefs.addAll(cql3.values()); |
| @@ -182,8 +183,8 @@ | ||
| 182 | 183 | // Strip the last ';' |
| 183 | 184 | withOpts = withOpts.substring(0, withOpts.length() - 1) + '\n'; |
| 184 | 185 | withOpts += " AND default_time_to_live = 0\n" |
| 185 | - + " AND speculative_retry = '99.0PERCENTILE'\n" | |
| 186 | - + " AND index_interval = 128;"; | |
| 186 | + + " AND speculative_retry = '99.0PERCENTILE'\n" | |
| 187 | + + " AND index_interval = 128;"; | |
| 187 | 188 | } |
| 188 | 189 | assertEquals(metadata.exportAsString(), withOpts); |
| 189 | 190 | } |
modified driver-core/src/test/java/com/datastax/driver/core/SessionAssert.java +1 −1
| @@ -23,7 +23,7 @@ | ||
| 23 | 23 | |
| 24 | 24 | protected SessionAssert(Session actual) { |
| 25 | 25 | // We are cheating a bit by casting, but this is the only implementation anyway |
| 26 | - super((SessionManager)actual, SessionAssert.class); | |
| 26 | + super((SessionManager) actual, SessionAssert.class); | |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | public SessionAssert hasPoolFor(int hostNumber) { |
modified driver-core/src/test/java/com/datastax/driver/core/SessionLeakTest.java +9 −13
| @@ -15,6 +15,7 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.exceptions.InvalidQueryException; | |
| 18 | 19 | import com.datastax.driver.core.utils.SocketChannelMonitor; |
| 19 | 20 | import com.google.common.collect.Lists; |
| 20 | 21 | import org.testng.annotations.Test; |
| @@ -24,15 +25,10 @@ | ||
| 24 | 25 | import java.util.List; |
| 25 | 26 | import java.util.concurrent.TimeUnit; |
| 26 | 27 | |
| 27 | -import static org.testng.Assert.assertEquals; | |
| 28 | -import static java.util.concurrent.TimeUnit.MINUTES; | |
| 29 | - | |
| 30 | -import static org.assertj.core.api.Assertions.fail; | |
| 31 | - | |
| 32 | -import com.datastax.driver.core.exceptions.InvalidQueryException; | |
| 33 | - | |
| 34 | 28 | import static com.datastax.driver.core.Assertions.assertThat; |
| 35 | 29 | import static com.datastax.driver.core.TestUtils.nonDebouncingQueryOptions; |
| 30 | +import static java.util.concurrent.TimeUnit.MINUTES; | |
| 31 | +import static org.assertj.core.api.Assertions.fail; | |
| 36 | 32 | |
| 37 | 33 | public class SessionLeakTest { |
| 38 | 34 | |
| @@ -94,7 +90,7 @@ | ||
| 94 | 90 | assertThat(cluster.manager.sessions.size()).isEqualTo(0); |
| 95 | 91 | assertOpenConnections(1); |
| 96 | 92 | } finally { |
| 97 | - if(cluster != null){ | |
| 93 | + if (cluster != null) { | |
| 98 | 94 | cluster.close(); |
| 99 | 95 | } |
| 100 | 96 | if (ccmBridge != null) { |
| @@ -116,9 +112,9 @@ | ||
| 116 | 112 | channelMonitor.reportAtFixedInterval(1, TimeUnit.SECONDS); |
| 117 | 113 | try { |
| 118 | 114 | cluster = Cluster.builder() |
| 119 | - .addContactPointsWithPorts(Collections.singletonList( | |
| 120 | - new InetSocketAddress(CCMBridge.IP_PREFIX + '1', 9042))) | |
| 121 | - .withNettyOptions(channelMonitor.nettyOptions()).build(); | |
| 115 | + .addContactPointsWithPorts(Collections.singletonList( | |
| 116 | + new InetSocketAddress(CCMBridge.IP_PREFIX + '1', 9042))) | |
| 117 | + .withNettyOptions(channelMonitor.nettyOptions()).build(); | |
| 122 | 118 | |
| 123 | 119 | cluster.init(); |
| 124 | 120 | |
| @@ -132,7 +128,7 @@ | ||
| 132 | 128 | |
| 133 | 129 | fail("Should not have connected to a wrong keyspace"); |
| 134 | 130 | |
| 135 | - } catch(InvalidQueryException e) { | |
| 131 | + } catch (InvalidQueryException e) { | |
| 136 | 132 | |
| 137 | 133 | // ok |
| 138 | 134 | |
| @@ -140,7 +136,7 @@ | ||
| 140 | 136 | |
| 141 | 137 | assertThat(cluster.manager.sessions.size()).isEqualTo(0); |
| 142 | 138 | |
| 143 | - if(cluster != null){ | |
| 139 | + if (cluster != null) { | |
| 144 | 140 | cluster.close(); |
| 145 | 141 | } |
| 146 | 142 | if (ccmBridge != null) { |
modified driver-core/src/test/java/com/datastax/driver/core/SessionStressTest.java +2 −2
| @@ -212,10 +212,10 @@ | ||
| 212 | 212 | |
| 213 | 213 | // Immediately wait for CloseFutures, this should be very quick since all this work does is call closeAsync. |
| 214 | 214 | List<ListenableFuture<Void>> futures = Lists.newArrayListWithCapacity(iterations); |
| 215 | - for(ListenableFuture<CloseFuture> closeFuture : closeFutures) { | |
| 215 | + for (ListenableFuture<CloseFuture> closeFuture : closeFutures) { | |
| 216 | 216 | try { |
| 217 | 217 | futures.add(closeFuture.get()); |
| 218 | - } catch(Exception e) { | |
| 218 | + } catch (Exception e) { | |
| 219 | 219 | logger.error("Got interrupted exception while waiting on closeFuture.", e); |
| 220 | 220 | } |
| 221 | 221 | } |
modified driver-core/src/test/java/com/datastax/driver/core/SessionTest.java +15 −19
| @@ -15,25 +15,21 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.net.InetSocketAddress; | |
| 19 | -import java.util.*; | |
| 20 | -import java.util.concurrent.CountDownLatch; | |
| 21 | -import java.util.concurrent.ExecutorService; | |
| 22 | -import java.util.concurrent.Executors; | |
| 23 | -import java.util.concurrent.TimeUnit; | |
| 24 | - | |
| 25 | 18 | import com.datastax.driver.core.utils.CassandraVersion; |
| 26 | 19 | import com.datastax.driver.core.utils.SocketChannelMonitor; |
| 27 | -import io.netty.channel.socket.SocketChannel; | |
| 28 | 20 | import org.slf4j.Logger; |
| 29 | 21 | import org.slf4j.LoggerFactory; |
| 30 | 22 | import org.testng.annotations.Test; |
| 31 | 23 | |
| 32 | -import static org.testng.Assert.assertEquals; | |
| 33 | -import static org.testng.Assert.assertTrue; | |
| 34 | -import static org.testng.Assert.fail; | |
| 24 | +import java.net.InetSocketAddress; | |
| 25 | +import java.util.*; | |
| 26 | +import java.util.concurrent.CountDownLatch; | |
| 27 | +import java.util.concurrent.ExecutorService; | |
| 28 | +import java.util.concurrent.Executors; | |
| 29 | +import java.util.concurrent.TimeUnit; | |
| 35 | 30 | |
| 36 | 31 | import static com.datastax.driver.core.TestUtils.nonQuietClusterCloseOptions; |
| 32 | +import static org.testng.Assert.*; | |
| 37 | 33 | |
| 38 | 34 | /** |
| 39 | 35 | * Simple test of the Sessions methods against a one node cluster. |
| @@ -50,9 +46,9 @@ | ||
| 50 | 46 | @Override |
| 51 | 47 | protected Collection<String> getTableDefinitions() { |
| 52 | 48 | return Arrays.asList(String.format(TestUtils.CREATE_TABLE_SIMPLE_FORMAT, TABLE1), |
| 53 | - String.format(TestUtils.CREATE_TABLE_SIMPLE_FORMAT, TABLE2), | |
| 54 | - String.format(TestUtils.CREATE_TABLE_SIMPLE_FORMAT, TABLE3), | |
| 55 | - String.format("CREATE TABLE %s (k text PRIMARY KEY, c counter)", COUNTER_TABLE)); | |
| 49 | + String.format(TestUtils.CREATE_TABLE_SIMPLE_FORMAT, TABLE2), | |
| 50 | + String.format(TestUtils.CREATE_TABLE_SIMPLE_FORMAT, TABLE3), | |
| 51 | + String.format("CREATE TABLE %s (k text PRIMARY KEY, c counter)", COUNTER_TABLE)); | |
| 56 | 52 | } |
| 57 | 53 | |
| 58 | 54 | @Test(groups = "short") |
| @@ -134,7 +130,7 @@ | ||
| 134 | 130 | * @expected_result session established and queries made successfully using it. |
| 135 | 131 | */ |
| 136 | 132 | @Test(groups = "short") |
| 137 | - @CassandraVersion(major=2.0) | |
| 133 | + @CassandraVersion(major = 2.0) | |
| 138 | 134 | public void session_should_function_with_lz4_compression() throws Exception { |
| 139 | 135 | compressionTest(ProtocolOptions.Compression.LZ4); |
| 140 | 136 | } |
| @@ -206,7 +202,7 @@ | ||
| 206 | 202 | // ensure sessions.size() returns to 0 with only 1 active connection |
| 207 | 203 | session.close(); |
| 208 | 204 | assertEquals(cluster.manager.sessions.size(), 0); |
| 209 | - assertEquals((int)cluster.getMetrics().getOpenConnections().getValue(), 1); | |
| 205 | + assertEquals((int) cluster.getMetrics().getOpenConnections().getValue(), 1); | |
| 210 | 206 | assertEquals(channelMonitor.openChannels(contactPoints).size(), 1); |
| 211 | 207 | |
| 212 | 208 | // give the driver time to close sessions |
| @@ -252,9 +248,9 @@ | ||
| 252 | 248 | // Use our own cluster and session (not the ones provided by the parent class) because we want an uninitialized cluster |
| 253 | 249 | // (note the use of newSession below) |
| 254 | 250 | final Cluster cluster = Cluster.builder() |
| 255 | - .addContactPointsWithPorts(Collections.singletonList(hostAddress)) | |
| 256 | - .withNettyOptions(nonQuietClusterCloseOptions) | |
| 257 | - .build(); | |
| 251 | + .addContactPointsWithPorts(Collections.singletonList(hostAddress)) | |
| 252 | + .withNettyOptions(nonQuietClusterCloseOptions) | |
| 253 | + .build(); | |
| 258 | 254 | final Session session = cluster.newSession(); |
| 259 | 255 | |
| 260 | 256 | // Spawn two threads to simulate the race |
modified driver-core/src/test/java/com/datastax/driver/core/SimpleJSONParserTest.java +2 −2
| @@ -15,10 +15,10 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import com.google.common.collect.ImmutableMap; | |
| 19 | 18 | import com.google.common.collect.ImmutableList; |
| 20 | - | |
| 19 | +import com.google.common.collect.ImmutableMap; | |
| 21 | 20 | import org.testng.annotations.Test; |
| 21 | + | |
| 22 | 22 | import static org.testng.Assert.assertEquals; |
| 23 | 23 | |
| 24 | 24 | public class SimpleJSONParserTest { |
modified driver-core/src/test/java/com/datastax/driver/core/SimpleStatementTest.java +8 −8
| @@ -15,28 +15,28 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | +import org.testng.annotations.Test; | |
| 19 | + | |
| 18 | 20 | import java.util.Collections; |
| 19 | 21 | import java.util.List; |
| 20 | 22 | |
| 21 | -import org.testng.annotations.Test; | |
| 22 | - | |
| 23 | 23 | import static org.assertj.core.api.Assertions.assertThat; |
| 24 | 24 | |
| 25 | 25 | public class SimpleStatementTest { |
| 26 | 26 | |
| 27 | - @Test(groups = "unit", expectedExceptions = { IllegalArgumentException.class }) | |
| 27 | + @Test(groups = "unit", expectedExceptions = {IllegalArgumentException.class}) | |
| 28 | 28 | public void should_fail_if_too_many_variables() { |
| 29 | - List<Object> args = Collections.nCopies(1 << 16, (Object)1); | |
| 29 | + List<Object> args = Collections.nCopies(1 << 16, (Object) 1); | |
| 30 | 30 | new SimpleStatement("mock query", args.toArray()); |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | - @Test(groups = "unit", expectedExceptions = { IllegalStateException.class }) | |
| 33 | + @Test(groups = "unit", expectedExceptions = {IllegalStateException.class}) | |
| 34 | 34 | public void should_throw_ISE_if_getObject_called_on_statement_without_values() { |
| 35 | 35 | new SimpleStatement("doesn't matter").getObject(0); |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | |
| 39 | - @Test(groups = "unit", expectedExceptions = { IndexOutOfBoundsException.class }) | |
| 39 | + @Test(groups = "unit", expectedExceptions = {IndexOutOfBoundsException.class}) | |
| 40 | 40 | public void should_throw_IOOBE_if_getObject_called_with_wrong_index() { |
| 41 | 41 | new SimpleStatement("doesn't matter", new Object()).getObject(1); |
| 42 | 42 | } |
| @@ -51,10 +51,10 @@ | ||
| 51 | 51 | @Test(groups = "unit") |
| 52 | 52 | public void should_return_number_of_values() { |
| 53 | 53 | assertThat( |
| 54 | - new SimpleStatement("doesn't matter").valuesCount() | |
| 54 | + new SimpleStatement("doesn't matter").valuesCount() | |
| 55 | 55 | ).isEqualTo(0); |
| 56 | 56 | assertThat( |
| 57 | - new SimpleStatement("doesn't matter", 1, 2).valuesCount() | |
| 57 | + new SimpleStatement("doesn't matter", 1, 2).valuesCount() | |
| 58 | 58 | ).isEqualTo(2); |
| 59 | 59 | } |
| 60 | 60 |
modified driver-core/src/test/java/com/datastax/driver/core/SimpleStrategyTest.java +72 −72
| @@ -15,15 +15,15 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | +import com.google.common.collect.ImmutableList; | |
| 19 | +import com.google.common.collect.ImmutableMap; | |
| 20 | +import org.testng.annotations.Test; | |
| 21 | + | |
| 18 | 22 | import java.net.InetSocketAddress; |
| 19 | 23 | import java.util.List; |
| 20 | 24 | import java.util.Map; |
| 21 | 25 | import java.util.Set; |
| 22 | 26 | |
| 23 | -import com.google.common.collect.ImmutableList; | |
| 24 | -import com.google.common.collect.ImmutableMap; | |
| 25 | -import org.testng.annotations.Test; | |
| 26 | - | |
| 27 | 27 | public class SimpleStrategyTest extends AbstractReplicationStrategyTest { |
| 28 | 28 | |
| 29 | 29 | private static ReplicationStrategy simpleStrategy(int replicationFactor) { |
| @@ -73,46 +73,46 @@ | ||
| 73 | 73 | private static final ReplicationStrategy exampleStrategyTooManyReplicas = simpleStrategy(8); |
| 74 | 74 | |
| 75 | 75 | private static final List<Token> exampleRing = ImmutableList.<Token>builder() |
| 76 | - .add(TOKEN01) | |
| 77 | - .add(TOKEN02) | |
| 78 | - .add(TOKEN03) | |
| 79 | - .add(TOKEN04) | |
| 80 | - .add(TOKEN05) | |
| 81 | - .add(TOKEN06) | |
| 82 | - .add(TOKEN07) | |
| 83 | - .add(TOKEN08) | |
| 84 | - .add(TOKEN09) | |
| 85 | - .add(TOKEN10) | |
| 86 | - .add(TOKEN11) | |
| 87 | - .add(TOKEN12) | |
| 88 | - .add(TOKEN13) | |
| 89 | - .add(TOKEN14) | |
| 90 | - .add(TOKEN15) | |
| 91 | - .add(TOKEN16) | |
| 92 | - .add(TOKEN17) | |
| 93 | - .add(TOKEN18) | |
| 94 | - .build(); | |
| 76 | + .add(TOKEN01) | |
| 77 | + .add(TOKEN02) | |
| 78 | + .add(TOKEN03) | |
| 79 | + .add(TOKEN04) | |
| 80 | + .add(TOKEN05) | |
| 81 | + .add(TOKEN06) | |
| 82 | + .add(TOKEN07) | |
| 83 | + .add(TOKEN08) | |
| 84 | + .add(TOKEN09) | |
| 85 | + .add(TOKEN10) | |
| 86 | + .add(TOKEN11) | |
| 87 | + .add(TOKEN12) | |
| 88 | + .add(TOKEN13) | |
| 89 | + .add(TOKEN14) | |
| 90 | + .add(TOKEN15) | |
| 91 | + .add(TOKEN16) | |
| 92 | + .add(TOKEN17) | |
| 93 | + .add(TOKEN18) | |
| 94 | + .build(); | |
| 95 | 95 | |
| 96 | 96 | private static final Map<Token, Host> exampleTokenToPrimary = ImmutableMap.<Token, Host>builder() |
| 97 | - .put(TOKEN01, host(IP1)) | |
| 98 | - .put(TOKEN02, host(IP1)) | |
| 99 | - .put(TOKEN03, host(IP5)) | |
| 100 | - .put(TOKEN04, host(IP3)) | |
| 101 | - .put(TOKEN05, host(IP1)) | |
| 102 | - .put(TOKEN06, host(IP5)) | |
| 103 | - .put(TOKEN07, host(IP2)) | |
| 104 | - .put(TOKEN08, host(IP6)) | |
| 105 | - .put(TOKEN09, host(IP3)) | |
| 106 | - .put(TOKEN10, host(IP4)) | |
| 107 | - .put(TOKEN11, host(IP5)) | |
| 108 | - .put(TOKEN12, host(IP4)) | |
| 109 | - .put(TOKEN13, host(IP4)) | |
| 110 | - .put(TOKEN14, host(IP2)) | |
| 111 | - .put(TOKEN15, host(IP6)) | |
| 112 | - .put(TOKEN16, host(IP3)) | |
| 113 | - .put(TOKEN17, host(IP2)) | |
| 114 | - .put(TOKEN18, host(IP6)) | |
| 115 | - .build(); | |
| 97 | + .put(TOKEN01, host(IP1)) | |
| 98 | + .put(TOKEN02, host(IP1)) | |
| 99 | + .put(TOKEN03, host(IP5)) | |
| 100 | + .put(TOKEN04, host(IP3)) | |
| 101 | + .put(TOKEN05, host(IP1)) | |
| 102 | + .put(TOKEN06, host(IP5)) | |
| 103 | + .put(TOKEN07, host(IP2)) | |
| 104 | + .put(TOKEN08, host(IP6)) | |
| 105 | + .put(TOKEN09, host(IP3)) | |
| 106 | + .put(TOKEN10, host(IP4)) | |
| 107 | + .put(TOKEN11, host(IP5)) | |
| 108 | + .put(TOKEN12, host(IP4)) | |
| 109 | + .put(TOKEN13, host(IP4)) | |
| 110 | + .put(TOKEN14, host(IP2)) | |
| 111 | + .put(TOKEN15, host(IP6)) | |
| 112 | + .put(TOKEN16, host(IP3)) | |
| 113 | + .put(TOKEN17, host(IP2)) | |
| 114 | + .put(TOKEN18, host(IP6)) | |
| 115 | + .build(); | |
| 116 | 116 | |
| 117 | 117 | /* |
| 118 | 118 | * -------------- |
| @@ -123,18 +123,18 @@ | ||
| 123 | 123 | @Test(groups = "unit") |
| 124 | 124 | public void simpleStrategySimpleTopologyTest() { |
| 125 | 125 | List<Token> ring = ImmutableList.<Token>builder() |
| 126 | - .add(TOKEN01) | |
| 127 | - .add(TOKEN06) | |
| 128 | - .add(TOKEN14) | |
| 129 | - .add(TOKEN19) | |
| 130 | - .build(); | |
| 126 | + .add(TOKEN01) | |
| 127 | + .add(TOKEN06) | |
| 128 | + .add(TOKEN14) | |
| 129 | + .add(TOKEN19) | |
| 130 | + .build(); | |
| 131 | 131 | |
| 132 | 132 | Map<Token, Host> tokenToPrimary = ImmutableMap.<Token, Host>builder() |
| 133 | - .put(TOKEN01, host(IP1)) | |
| 134 | - .put(TOKEN06, host(IP2)) | |
| 135 | - .put(TOKEN14, host(IP1)) | |
| 136 | - .put(TOKEN19, host(IP2)) | |
| 137 | - .build(); | |
| 133 | + .put(TOKEN01, host(IP1)) | |
| 134 | + .put(TOKEN06, host(IP2)) | |
| 135 | + .put(TOKEN14, host(IP1)) | |
| 136 | + .put(TOKEN19, host(IP2)) | |
| 137 | + .build(); | |
| 138 | 138 | |
| 139 | 139 | ReplicationStrategy strategy = simpleStrategy(2); |
| 140 | 140 | |
| @@ -149,18 +149,18 @@ | ||
| 149 | 149 | @Test(groups = "unit") |
| 150 | 150 | public void simpleStrategyConsecutiveRingSectionsTest() { |
| 151 | 151 | List<Token> ring = ImmutableList.<Token>builder() |
| 152 | - .add(TOKEN01) | |
| 153 | - .add(TOKEN06) | |
| 154 | - .add(TOKEN14) | |
| 155 | - .add(TOKEN19) | |
| 156 | - .build(); | |
| 152 | + .add(TOKEN01) | |
| 153 | + .add(TOKEN06) | |
| 154 | + .add(TOKEN14) | |
| 155 | + .add(TOKEN19) | |
| 156 | + .build(); | |
| 157 | 157 | |
| 158 | 158 | Map<Token, Host> tokenToPrimary = ImmutableMap.<Token, Host>builder() |
| 159 | - .put(TOKEN01, host(IP1)) | |
| 160 | - .put(TOKEN06, host(IP1)) | |
| 161 | - .put(TOKEN14, host(IP2)) | |
| 162 | - .put(TOKEN19, host(IP2)) | |
| 163 | - .build(); | |
| 159 | + .put(TOKEN01, host(IP1)) | |
| 160 | + .put(TOKEN06, host(IP1)) | |
| 161 | + .put(TOKEN14, host(IP2)) | |
| 162 | + .put(TOKEN19, host(IP2)) | |
| 163 | + .build(); | |
| 164 | 164 | |
| 165 | 165 | ReplicationStrategy strategy = simpleStrategy(2); |
| 166 | 166 | |
| @@ -175,18 +175,18 @@ | ||
| 175 | 175 | @Test(groups = "unit") |
| 176 | 176 | public void simpleStrategyUnbalancedRingTest() { |
| 177 | 177 | List<Token> ring = ImmutableList.<Token>builder() |
| 178 | - .add(TOKEN01) | |
| 179 | - .add(TOKEN06) | |
| 180 | - .add(TOKEN14) | |
| 181 | - .add(TOKEN19) | |
| 182 | - .build(); | |
| 178 | + .add(TOKEN01) | |
| 179 | + .add(TOKEN06) | |
| 180 | + .add(TOKEN14) | |
| 181 | + .add(TOKEN19) | |
| 182 | + .build(); | |
| 183 | 183 | |
| 184 | 184 | Map<Token, Host> tokenToPrimary = ImmutableMap.<Token, Host>builder() |
| 185 | - .put(TOKEN01, host(IP1)) | |
| 186 | - .put(TOKEN06, host(IP1)) | |
| 187 | - .put(TOKEN14, host(IP2)) | |
| 188 | - .put(TOKEN19, host(IP1)) | |
| 189 | - .build(); | |
| 185 | + .put(TOKEN01, host(IP1)) | |
| 186 | + .put(TOKEN06, host(IP1)) | |
| 187 | + .put(TOKEN14, host(IP2)) | |
| 188 | + .put(TOKEN19, host(IP1)) | |
| 189 | + .build(); | |
| 190 | 190 | |
| 191 | 191 | ReplicationStrategy strategy = simpleStrategy(2); |
| 192 | 192 |
modified driver-core/src/test/java/com/datastax/driver/core/SingleTokenIntegrationTest.java +17 −18
| @@ -15,12 +15,11 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.nio.ByteBuffer; | |
| 19 | -import java.util.Set; | |
| 20 | - | |
| 18 | +import com.datastax.driver.core.utils.Bytes; | |
| 21 | 19 | import org.testng.annotations.Test; |
| 22 | 20 | |
| 23 | -import com.datastax.driver.core.utils.Bytes; | |
| 21 | +import java.nio.ByteBuffer; | |
| 22 | +import java.util.Set; | |
| 24 | 23 | |
| 25 | 24 | import static com.datastax.driver.core.Assertions.assertThat; |
| 26 | 25 | |
| @@ -35,18 +34,18 @@ | ||
| 35 | 34 | |
| 36 | 35 | try { |
| 37 | 36 | ccm = CCMBridge.builder("test") |
| 38 | - // force the initial token to a non-min value to validate that the single range will always be ]minToken, minToken] | |
| 39 | - .withCassandraConfiguration("initial_token", "1") | |
| 40 | - .build(); | |
| 37 | + // force the initial token to a non-min value to validate that the single range will always be ]minToken, minToken] | |
| 38 | + .withCassandraConfiguration("initial_token", "1") | |
| 39 | + .build(); | |
| 41 | 40 | |
| 42 | 41 | cluster = Cluster.builder() |
| 43 | - .addContactPoint(CCMBridge.ipOfNode(1)) | |
| 44 | - .withQueryOptions(new QueryOptions() | |
| 45 | - .setRefreshNodeIntervalMillis(0) | |
| 46 | - .setRefreshNodeListIntervalMillis(0) | |
| 47 | - .setRefreshSchemaIntervalMillis(0) | |
| 48 | - ) | |
| 49 | - .build(); | |
| 42 | + .addContactPoint(CCMBridge.ipOfNode(1)) | |
| 43 | + .withQueryOptions(new QueryOptions() | |
| 44 | + .setRefreshNodeIntervalMillis(0) | |
| 45 | + .setRefreshNodeListIntervalMillis(0) | |
| 46 | + .setRefreshSchemaIntervalMillis(0) | |
| 47 | + ) | |
| 48 | + .build(); | |
| 50 | 49 | |
| 51 | 50 | Session session = cluster.connect(); |
| 52 | 51 | session.execute("create keyspace test with replication = {'class': 'SimpleStrategy', 'replication_factor': 1}"); |
| @@ -57,10 +56,10 @@ | ||
| 57 | 56 | assertThat(tokenRanges).hasSize(1); |
| 58 | 57 | TokenRange tokenRange = tokenRanges.iterator().next(); |
| 59 | 58 | assertThat(tokenRange) |
| 60 | - .startsWith(Token.M3PToken.FACTORY.minToken()) | |
| 61 | - .endsWith(Token.M3PToken.FACTORY.minToken()) | |
| 62 | - .isNotEmpty() | |
| 63 | - .isNotWrappedAround(); | |
| 59 | + .startsWith(Token.M3PToken.FACTORY.minToken()) | |
| 60 | + .endsWith(Token.M3PToken.FACTORY.minToken()) | |
| 61 | + .isNotEmpty() | |
| 62 | + .isNotWrappedAround(); | |
| 64 | 63 | |
| 65 | 64 | Set<Host> hostsForRange = metadata.getReplicas("test", tokenRange); |
| 66 | 65 | Host host1 = TestUtils.findHost(cluster, 1); |
modified driver-core/src/test/java/com/datastax/driver/core/SortingLoadBalancingPolicy.java +5 −6
| @@ -15,16 +15,15 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.policies.LoadBalancingPolicy; | |
| 19 | +import com.google.common.primitives.UnsignedBytes; | |
| 20 | + | |
| 18 | 21 | import java.util.Collection; |
| 19 | 22 | import java.util.Comparator; |
| 20 | 23 | import java.util.Iterator; |
| 21 | 24 | import java.util.SortedSet; |
| 22 | 25 | import java.util.concurrent.ConcurrentSkipListSet; |
| 23 | 26 | |
| 24 | -import com.google.common.primitives.UnsignedBytes; | |
| 25 | - | |
| 26 | -import com.datastax.driver.core.policies.LoadBalancingPolicy; | |
| 27 | - | |
| 28 | 27 | /** |
| 29 | 28 | * A load balancing policy that sorts hosts on the last byte of the address, |
| 30 | 29 | * so that the query plan is always [host1, host2, host3]. |
| @@ -37,8 +36,8 @@ | ||
| 37 | 36 | byte[] address1 = host1.getAddress().getAddress(); |
| 38 | 37 | byte[] address2 = host2.getAddress().getAddress(); |
| 39 | 38 | return UnsignedBytes.compare( |
| 40 | - address1[address1.length - 1], | |
| 41 | - address2[address2.length - 1]); | |
| 39 | + address1[address1.length - 1], | |
| 40 | + address2[address2.length - 1]); | |
| 42 | 41 | } |
| 43 | 42 | }); |
| 44 | 43 |
modified driver-core/src/test/java/com/datastax/driver/core/SpeculativeExecutionTest.java +54 −56
| @@ -15,24 +15,22 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.util.*; | |
| 19 | - | |
| 18 | +import com.datastax.driver.core.policies.ConstantSpeculativeExecutionPolicy; | |
| 19 | +import com.datastax.driver.core.policies.RetryPolicy; | |
| 20 | 20 | import com.datastax.driver.core.policies.SpeculativeExecutionPolicy; |
| 21 | 21 | import com.google.common.collect.ImmutableList; |
| 22 | 22 | import com.google.common.collect.ImmutableMap; |
| 23 | -import org.scassandra.Scassandra; | |
| 24 | 23 | import org.scassandra.http.client.PrimingRequest; |
| 25 | -import org.testng.annotations.*; | |
| 24 | +import org.testng.annotations.AfterMethod; | |
| 25 | +import org.testng.annotations.BeforeMethod; | |
| 26 | +import org.testng.annotations.Test; | |
| 26 | 27 | |
| 27 | -import com.datastax.driver.core.policies.ConstantSpeculativeExecutionPolicy; | |
| 28 | -import com.datastax.driver.core.policies.RetryPolicy; | |
| 28 | +import java.util.List; | |
| 29 | +import java.util.Map; | |
| 29 | 30 | |
| 30 | 31 | import static com.datastax.driver.core.Assertions.assertThat; |
| 31 | 32 | import static com.datastax.driver.core.TestUtils.nonQuietClusterCloseOptions; |
| 32 | - | |
| 33 | -import static org.mockito.Mockito.mock; | |
| 34 | -import static org.mockito.Mockito.times; | |
| 35 | -import static org.mockito.Mockito.verify; | |
| 33 | +import static org.mockito.Mockito.*; | |
| 36 | 34 | |
| 37 | 35 | public class SpeculativeExecutionTest { |
| 38 | 36 | ScassandraCluster scassandras; |
| @@ -52,13 +50,13 @@ | ||
| 52 | 50 | |
| 53 | 51 | loadBalancingPolicy = new SortingLoadBalancingPolicy(); |
| 54 | 52 | cluster = Cluster.builder() |
| 55 | - .addContactPoint(scassandras.address(2)) | |
| 56 | - .withLoadBalancingPolicy(loadBalancingPolicy) | |
| 57 | - .withSpeculativeExecutionPolicy(new ConstantSpeculativeExecutionPolicy(speculativeExecutionDelay, 1)) | |
| 58 | - .withQueryOptions(new QueryOptions().setDefaultIdempotence(true)) | |
| 59 | - .withRetryPolicy(new CustomRetryPolicy()) | |
| 60 | - .withNettyOptions(nonQuietClusterCloseOptions) | |
| 61 | - .build(); | |
| 53 | + .addContactPoint(scassandras.address(2)) | |
| 54 | + .withLoadBalancingPolicy(loadBalancingPolicy) | |
| 55 | + .withSpeculativeExecutionPolicy(new ConstantSpeculativeExecutionPolicy(speculativeExecutionDelay, 1)) | |
| 56 | + .withQueryOptions(new QueryOptions().setDefaultIdempotence(true)) | |
| 57 | + .withRetryPolicy(new CustomRetryPolicy()) | |
| 58 | + .withNettyOptions(nonQuietClusterCloseOptions) | |
| 59 | + .build(); | |
| 62 | 60 | |
| 63 | 61 | session = cluster.connect(); |
| 64 | 62 | |
| @@ -80,9 +78,9 @@ | ||
| 80 | 78 | @Test(groups = "short") |
| 81 | 79 | public void should_not_start_speculative_execution_if_first_execution_completes_successfully() { |
| 82 | 80 | scassandras.node(1).primingClient().prime(PrimingRequest.queryBuilder() |
| 83 | - .withQuery("mock query") | |
| 84 | - .withRows(row("result", "result1")) | |
| 85 | - .build() | |
| 81 | + .withQuery("mock query") | |
| 82 | + .withRows(row("result", "result1")) | |
| 83 | + .build() | |
| 86 | 84 | ); |
| 87 | 85 | |
| 88 | 86 | long execStartCount = errors.getSpeculativeExecutions().getCount(); |
| @@ -99,17 +97,17 @@ | ||
| 99 | 97 | public void should_not_start_speculative_execution_if_first_execution_retries_but_is_still_fast_enough() { |
| 100 | 98 | // will retry once on this node: |
| 101 | 99 | scassandras.node(1).primingClient().prime(PrimingRequest.queryBuilder() |
| 102 | - .withQuery("mock query") | |
| 103 | - .withConsistency(PrimingRequest.Consistency.TWO) | |
| 104 | - .withResult(PrimingRequest.Result.read_request_timeout) | |
| 105 | - .build() | |
| 100 | + .withQuery("mock query") | |
| 101 | + .withConsistency(PrimingRequest.Consistency.TWO) | |
| 102 | + .withResult(PrimingRequest.Result.read_request_timeout) | |
| 103 | + .build() | |
| 106 | 104 | ); |
| 107 | 105 | |
| 108 | 106 | scassandras.node(1).primingClient().prime(PrimingRequest.queryBuilder() |
| 109 | - .withQuery("mock query") | |
| 110 | - .withConsistency(PrimingRequest.Consistency.ONE) | |
| 111 | - .withRows(row("result", "result1")) | |
| 112 | - .build() | |
| 107 | + .withQuery("mock query") | |
| 108 | + .withConsistency(PrimingRequest.Consistency.ONE) | |
| 109 | + .withRows(row("result", "result1")) | |
| 110 | + .build() | |
| 113 | 111 | ); |
| 114 | 112 | |
| 115 | 113 | long execStartCount = errors.getSpeculativeExecutions().getCount(); |
| @@ -129,16 +127,16 @@ | ||
| 129 | 127 | @Test(groups = "short") |
| 130 | 128 | public void should_start_speculative_execution_if_first_execution_takes_too_long() { |
| 131 | 129 | scassandras.node(1).primingClient().prime(PrimingRequest.queryBuilder() |
| 132 | - .withQuery("mock query") | |
| 133 | - .withFixedDelay(400) | |
| 134 | - .withRows(row("result", "result1")) | |
| 135 | - .build() | |
| 130 | + .withQuery("mock query") | |
| 131 | + .withFixedDelay(400) | |
| 132 | + .withRows(row("result", "result1")) | |
| 133 | + .build() | |
| 136 | 134 | ); |
| 137 | 135 | |
| 138 | 136 | scassandras.node(2).primingClient().prime(PrimingRequest.queryBuilder() |
| 139 | - .withQuery("mock query") | |
| 140 | - .withRows(row("result", "result2")) | |
| 141 | - .build() | |
| 137 | + .withQuery("mock query") | |
| 138 | + .withRows(row("result", "result2")) | |
| 139 | + .build() | |
| 142 | 140 | ); |
| 143 | 141 | long execStartCount = errors.getSpeculativeExecutions().getCount(); |
| 144 | 142 | |
| @@ -156,28 +154,28 @@ | ||
| 156 | 154 | cluster.getConfiguration().getSocketOptions().setReadTimeoutMillis(1000); |
| 157 | 155 | |
| 158 | 156 | scassandras.node(1).primingClient() |
| 159 | - // execution1 starts with host1, which will time out at t=1000 | |
| 160 | - .prime(PrimingRequest.queryBuilder() | |
| 161 | - .withQuery("mock query") | |
| 162 | - .withFixedDelay(2000) | |
| 163 | - .withRows(row("result", "result1")) | |
| 164 | - .build()); | |
| 165 | - // at t=1000, execution1 moves to host3, which eventually succeeds at t=1500 | |
| 157 | + // execution1 starts with host1, which will time out at t=1000 | |
| 158 | + .prime(PrimingRequest.queryBuilder() | |
| 159 | + .withQuery("mock query") | |
| 160 | + .withFixedDelay(2000) | |
| 161 | + .withRows(row("result", "result1")) | |
| 162 | + .build()); | |
| 163 | + // at t=1000, execution1 moves to host3, which eventually succeeds at t=1500 | |
| 166 | 164 | scassandras.node(3).primingClient() |
| 167 | - .prime(PrimingRequest.queryBuilder() | |
| 168 | - .withQuery("mock query") | |
| 169 | - .withFixedDelay(500) | |
| 170 | - .withRows(row("result", "result3")) | |
| 171 | - .build()); | |
| 172 | - // meanwhile, execution2 starts at t=200, using host2 which times out at t=1200 | |
| 173 | - // at that time, the query plan is empty so execution2 fails | |
| 174 | - // The goal of this test is to check that execution2 does not fail the query, since execution1 is still running | |
| 165 | + .prime(PrimingRequest.queryBuilder() | |
| 166 | + .withQuery("mock query") | |
| 167 | + .withFixedDelay(500) | |
| 168 | + .withRows(row("result", "result3")) | |
| 169 | + .build()); | |
| 170 | + // meanwhile, execution2 starts at t=200, using host2 which times out at t=1200 | |
| 171 | + // at that time, the query plan is empty so execution2 fails | |
| 172 | + // The goal of this test is to check that execution2 does not fail the query, since execution1 is still running | |
| 175 | 173 | scassandras.node(2).primingClient() |
| 176 | - .prime(PrimingRequest.queryBuilder() | |
| 177 | - .withQuery("mock query") | |
| 178 | - .withFixedDelay(2000) | |
| 179 | - .withRows(row("result", "result2")) | |
| 180 | - .build()); | |
| 174 | + .prime(PrimingRequest.queryBuilder() | |
| 175 | + .withQuery("mock query") | |
| 176 | + .withFixedDelay(2000) | |
| 177 | + .withRows(row("result", "result2")) | |
| 178 | + .build()); | |
| 181 | 179 | long execStartCount = errors.getSpeculativeExecutions().getCount(); |
| 182 | 180 | |
| 183 | 181 | ResultSet rs = session.execute("mock query"); |
| @@ -197,7 +195,7 @@ | ||
| 197 | 195 | * @jira_ticket JAVA-796 |
| 198 | 196 | * @since 2.0.11, 2.1.7, 2.2.1 |
| 199 | 197 | */ |
| 200 | - @Test(groups="short") | |
| 198 | + @Test(groups = "short") | |
| 201 | 199 | public void should_init_and_close_policy_on_cluster() { |
| 202 | 200 | SpeculativeExecutionPolicy mockPolicy = mock(SpeculativeExecutionPolicy.class); |
| 203 | 201 |
modified driver-core/src/test/java/com/datastax/driver/core/StateListenerTest.java +7 −9
| @@ -15,17 +15,15 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.util.concurrent.CountDownLatch; | |
| 19 | - | |
| 20 | -import static java.util.concurrent.TimeUnit.MINUTES; | |
| 21 | - | |
| 22 | 18 | import org.slf4j.Logger; |
| 23 | 19 | import org.slf4j.LoggerFactory; |
| 24 | 20 | import org.testng.annotations.Test; |
| 25 | 21 | |
| 26 | -import static org.assertj.core.api.Assertions.assertThat; | |
| 22 | +import java.util.concurrent.CountDownLatch; | |
| 27 | 23 | |
| 28 | 24 | import static com.datastax.driver.core.StateListenerTest.TestListener.Event.*; |
| 25 | +import static java.util.concurrent.TimeUnit.MINUTES; | |
| 26 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 29 | 27 | |
| 30 | 28 | public class StateListenerTest { |
| 31 | 29 | private static final Logger logger = LoggerFactory.getLogger(StateListenerTest.class); |
| @@ -37,8 +35,8 @@ | ||
| 37 | 35 | try { |
| 38 | 36 | ccm = CCMBridge.builder("test").build(); |
| 39 | 37 | cluster = Cluster.builder() |
| 40 | - .addContactPoint(CCMBridge.ipOfNode(1)) | |
| 41 | - .build(); | |
| 38 | + .addContactPoint(CCMBridge.ipOfNode(1)) | |
| 39 | + .build(); | |
| 42 | 40 | cluster.init(); |
| 43 | 41 | TestListener listener = new TestListener(); |
| 44 | 42 | cluster.register(listener); |
| @@ -82,8 +80,8 @@ | ||
| 82 | 80 | |
| 83 | 81 | void waitForEvent() throws InterruptedException { |
| 84 | 82 | assertThat(latch.await(2, MINUTES)) |
| 85 | - .as("Timed out waiting for event " + expectedEvent) | |
| 86 | - .isTrue(); | |
| 83 | + .as("Timed out waiting for event " + expectedEvent) | |
| 84 | + .isTrue(); | |
| 87 | 85 | assertThat(actualEvent).isEqualTo(expectedEvent); |
| 88 | 86 | } |
| 89 | 87 |
modified driver-core/src/test/java/com/datastax/driver/core/StatementIdempotenceTest.java +52 −54
| @@ -15,17 +15,15 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.querybuilder.BuiltStatement; | |
| 18 | 19 | import com.google.common.collect.ImmutableList; |
| 19 | 20 | import com.google.common.collect.ImmutableMap; |
| 20 | 21 | import com.google.common.collect.Lists; |
| 21 | 22 | import com.google.common.collect.Sets; |
| 22 | 23 | import org.testng.annotations.Test; |
| 23 | 24 | |
| 24 | -import static org.assertj.core.api.Assertions.assertThat; | |
| 25 | - | |
| 26 | -import com.datastax.driver.core.querybuilder.BuiltStatement; | |
| 27 | - | |
| 28 | 25 | import static com.datastax.driver.core.querybuilder.QueryBuilder.*; |
| 26 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 29 | 27 | |
| 30 | 28 | public class StatementIdempotenceTest { |
| 31 | 29 | @Test(groups = "unit") |
| @@ -41,7 +39,7 @@ | ||
| 41 | 39 | QueryOptions queryOptions = new QueryOptions(); |
| 42 | 40 | SimpleStatement statement = new SimpleStatement(""); |
| 43 | 41 | |
| 44 | - for (boolean valueInOptions : new boolean[]{ true, false }) { | |
| 42 | + for (boolean valueInOptions : new boolean[]{true, false}) { | |
| 45 | 43 | queryOptions.setDefaultIdempotence(valueInOptions); |
| 46 | 44 | assertThat(statement.isIdempotentWithDefault(queryOptions)).isEqualTo(valueInOptions); |
| 47 | 45 | } |
| @@ -52,8 +50,8 @@ | ||
| 52 | 50 | QueryOptions queryOptions = new QueryOptions(); |
| 53 | 51 | SimpleStatement statement = new SimpleStatement(""); |
| 54 | 52 | |
| 55 | - for (boolean valueInOptions : new boolean[]{ true, false }) | |
| 56 | - for (boolean valueInStatement : new boolean[]{ true, false }) { | |
| 53 | + for (boolean valueInOptions : new boolean[]{true, false}) | |
| 54 | + for (boolean valueInStatement : new boolean[]{true, false}) { | |
| 57 | 55 | queryOptions.setDefaultIdempotence(valueInOptions); |
| 58 | 56 | statement.setIdempotent(valueInStatement); |
| 59 | 57 | assertThat(statement.isIdempotentWithDefault(queryOptions)).isEqualTo(valueInStatement); |
| @@ -64,18 +62,18 @@ | ||
| 64 | 62 | public void should_infer_for_built_statement() { |
| 65 | 63 | for (BuiltStatement statement : idempotentBuiltStatements()) |
| 66 | 64 | assertThat(statement.isIdempotent()) |
| 67 | - .as(statement.getQueryString()) | |
| 68 | - .isTrue(); | |
| 65 | + .as(statement.getQueryString()) | |
| 66 | + .isTrue(); | |
| 69 | 67 | |
| 70 | 68 | for (BuiltStatement statement : nonIdempotentBuiltStatements()) |
| 71 | 69 | assertThat(statement.isIdempotent()) |
| 72 | - .as(statement.getQueryString()) | |
| 73 | - .isFalse(); | |
| 70 | + .as(statement.getQueryString()) | |
| 71 | + .isFalse(); | |
| 74 | 72 | } |
| 75 | 73 | |
| 76 | 74 | @Test(groups = "unit") |
| 77 | 75 | public void should_override_inferred_value_when_manually_set_on_built_statement() { |
| 78 | - for (boolean manualValue : new boolean[]{ true, false }) { | |
| 76 | + for (boolean manualValue : new boolean[]{true, false}) { | |
| 79 | 77 | for (BuiltStatement statement : idempotentBuiltStatements()) { |
| 80 | 78 | statement.setIdempotent(manualValue); |
| 81 | 79 | assertThat(statement.isIdempotent()).isEqualTo(manualValue); |
| @@ -90,66 +88,66 @@ | ||
| 90 | 88 | |
| 91 | 89 | private static ImmutableList<BuiltStatement> idempotentBuiltStatements() { |
| 92 | 90 | return ImmutableList.<BuiltStatement>of( |
| 93 | - update("foo").with(set("v", 1)).where(eq("k", 1)), // set simple value | |
| 94 | - update("foo").with(add("s", 1)).where(eq("k", 1)), // add to set | |
| 95 | - update("foo").with(put("m", "a", 1)).where(eq("k", 1)), // put in map | |
| 96 | - | |
| 97 | - // select statements should be idempotent even with function calls | |
| 98 | - select().countAll() .from("foo").where(eq("k", 1)), | |
| 99 | - select().ttl("v") .from("foo").where(eq("k", 1)), | |
| 100 | - select().writeTime("v") .from("foo").where(eq("k", 1)), | |
| 101 | - select().fcall("token", "k").from("foo").where(eq("k", 1)) | |
| 91 | + update("foo").with(set("v", 1)).where(eq("k", 1)), // set simple value | |
| 92 | + update("foo").with(add("s", 1)).where(eq("k", 1)), // add to set | |
| 93 | + update("foo").with(put("m", "a", 1)).where(eq("k", 1)), // put in map | |
| 94 | + | |
| 95 | + // select statements should be idempotent even with function calls | |
| 96 | + select().countAll().from("foo").where(eq("k", 1)), | |
| 97 | + select().ttl("v").from("foo").where(eq("k", 1)), | |
| 98 | + select().writeTime("v").from("foo").where(eq("k", 1)), | |
| 99 | + select().fcall("token", "k").from("foo").where(eq("k", 1)) | |
| 102 | 100 | |
| 103 | 101 | ); |
| 104 | 102 | } |
| 105 | 103 | |
| 106 | 104 | private static ImmutableList<BuiltStatement> nonIdempotentBuiltStatements() { |
| 107 | 105 | return ImmutableList.of( |
| 108 | - update("foo").with(append("l", 1)).where(eq("k", 1)), // append to list | |
| 109 | - update("foo").with(set("v", 1)).and(prepend("l", 1)).where(eq("k", 1)), // prepend to list | |
| 110 | - update("foo").with(incr("c")).where(eq("k", 1)), // counter update | |
| 106 | + update("foo").with(append("l", 1)).where(eq("k", 1)), // append to list | |
| 107 | + update("foo").with(set("v", 1)).and(prepend("l", 1)).where(eq("k", 1)), // prepend to list | |
| 108 | + update("foo").with(incr("c")).where(eq("k", 1)), // counter update | |
| 111 | 109 | |
| 112 | - // function calls | |
| 110 | + // function calls | |
| 113 | 111 | |
| 114 | - insertInto("foo").value("k", 1).value("v", fcall("token", "k")), | |
| 115 | - insertInto("foo").value("k", 1).value("v", now()), | |
| 116 | - insertInto("foo").value("k", 1).value("v", uuid()), | |
| 112 | + insertInto("foo").value("k", 1).value("v", fcall("token", "k")), | |
| 113 | + insertInto("foo").value("k", 1).value("v", now()), | |
| 114 | + insertInto("foo").value("k", 1).value("v", uuid()), | |
| 117 | 115 | |
| 118 | - insertInto("foo").value("k", 1).value("v", Sets.newHashSet(fcall("token", "k"))), | |
| 119 | - insertInto("foo").value("k", 1).value("v", Sets.newHashSet(now())), | |
| 120 | - insertInto("foo").value("k", 1).value("v", Sets.newHashSet(uuid())), | |
| 116 | + insertInto("foo").value("k", 1).value("v", Sets.newHashSet(fcall("token", "k"))), | |
| 117 | + insertInto("foo").value("k", 1).value("v", Sets.newHashSet(now())), | |
| 118 | + insertInto("foo").value("k", 1).value("v", Sets.newHashSet(uuid())), | |
| 121 | 119 | |
| 122 | - insertInto("foo").values(new String[]{"k", "v"}, new Object[]{1, fcall("token", "k")}), | |
| 123 | - insertInto("foo").values(new String[]{"k", "v"}, new Object[]{1, now()}), | |
| 124 | - insertInto("foo").values(new String[]{"k", "v"}, new Object[]{1, uuid()}), | |
| 120 | + insertInto("foo").values(new String[]{"k", "v"}, new Object[]{1, fcall("token", "k")}), | |
| 121 | + insertInto("foo").values(new String[]{"k", "v"}, new Object[]{1, now()}), | |
| 122 | + insertInto("foo").values(new String[]{"k", "v"}, new Object[]{1, uuid()}), | |
| 125 | 123 | |
| 126 | - insertInto("foo").values(new String[]{"k", "v"}, new Object[]{1, ImmutableMap.of("foo", fcall("token", "k"))}), | |
| 127 | - insertInto("foo").values(new String[]{"k", "v"}, new Object[]{1, ImmutableMap.of("foo", now())}), | |
| 128 | - insertInto("foo").values(new String[]{"k", "v"}, new Object[]{1, ImmutableMap.of("foo", uuid())}), | |
| 124 | + insertInto("foo").values(new String[]{"k", "v"}, new Object[]{1, ImmutableMap.of("foo", fcall("token", "k"))}), | |
| 125 | + insertInto("foo").values(new String[]{"k", "v"}, new Object[]{1, ImmutableMap.of("foo", now())}), | |
| 126 | + insertInto("foo").values(new String[]{"k", "v"}, new Object[]{1, ImmutableMap.of("foo", uuid())}), | |
| 129 | 127 | |
| 130 | - insertInto("foo").values(new String[]{"k", "v"}, new Object[]{1, ImmutableMap.of(fcall("token", "k"), "foo")}), | |
| 131 | - insertInto("foo").values(new String[]{"k", "v"}, new Object[]{1, ImmutableMap.of(now() , "foo")}), | |
| 132 | - insertInto("foo").values(new String[]{"k", "v"}, new Object[]{1, ImmutableMap.of(uuid() , "foo")}), | |
| 128 | + insertInto("foo").values(new String[]{"k", "v"}, new Object[]{1, ImmutableMap.of(fcall("token", "k"), "foo")}), | |
| 129 | + insertInto("foo").values(new String[]{"k", "v"}, new Object[]{1, ImmutableMap.of(now(), "foo")}), | |
| 130 | + insertInto("foo").values(new String[]{"k", "v"}, new Object[]{1, ImmutableMap.of(uuid(), "foo")}), | |
| 133 | 131 | |
| 134 | - update("foo").with(set("v", fcall("token", "k"))) .where(eq("k", 1)), | |
| 135 | - update("foo").with(set("v", now())) .where(eq("k", 1)), | |
| 136 | - update("foo").with(set("v", uuid())) .where(eq("k", 1)), | |
| 132 | + update("foo").with(set("v", fcall("token", "k"))).where(eq("k", 1)), | |
| 133 | + update("foo").with(set("v", now())).where(eq("k", 1)), | |
| 134 | + update("foo").with(set("v", uuid())).where(eq("k", 1)), | |
| 137 | 135 | |
| 138 | - update("foo").with(set("v", Lists.newArrayList(fcall("token", "k")))).where(eq("k", 1)), | |
| 139 | - update("foo").with(set("v", Lists.newArrayList(now()))) .where(eq("k", 1)), | |
| 140 | - update("foo").with(set("v", Lists.newArrayList(uuid()))) .where(eq("k", 1)), | |
| 136 | + update("foo").with(set("v", Lists.newArrayList(fcall("token", "k")))).where(eq("k", 1)), | |
| 137 | + update("foo").with(set("v", Lists.newArrayList(now()))).where(eq("k", 1)), | |
| 138 | + update("foo").with(set("v", Lists.newArrayList(uuid()))).where(eq("k", 1)), | |
| 141 | 139 | |
| 142 | - // raw() calls | |
| 140 | + // raw() calls | |
| 143 | 141 | |
| 144 | - insertInto("foo").value("k", 1).value("v", raw("foo()")), | |
| 145 | - insertInto("foo").value("k", 1).value("v", Sets.newHashSet(raw("foo()"))), | |
| 142 | + insertInto("foo").value("k", 1).value("v", raw("foo()")), | |
| 143 | + insertInto("foo").value("k", 1).value("v", Sets.newHashSet(raw("foo()"))), | |
| 146 | 144 | |
| 147 | - insertInto("foo").values(new String[]{"k", "v"}, new Object[]{1, raw("foo()")}), | |
| 148 | - insertInto("foo").values(new String[]{"k", "v"}, new Object[]{1, ImmutableMap.of("foo", raw("foo()"))}), | |
| 149 | - insertInto("foo").values(new String[]{"k", "v"}, new Object[]{1, ImmutableMap.of(raw("foo()"), "foo")}), | |
| 145 | + insertInto("foo").values(new String[]{"k", "v"}, new Object[]{1, raw("foo()")}), | |
| 146 | + insertInto("foo").values(new String[]{"k", "v"}, new Object[]{1, ImmutableMap.of("foo", raw("foo()"))}), | |
| 147 | + insertInto("foo").values(new String[]{"k", "v"}, new Object[]{1, ImmutableMap.of(raw("foo()"), "foo")}), | |
| 150 | 148 | |
| 151 | - update("foo").with(set("v", raw("foo()"))) .where(eq("k", 1)), | |
| 152 | - update("foo").with(set("v", Lists.newArrayList(raw("foo()")))).where(eq("k", 1)) | |
| 149 | + update("foo").with(set("v", raw("foo()"))).where(eq("k", 1)), | |
| 150 | + update("foo").with(set("v", Lists.newArrayList(raw("foo()")))).where(eq("k", 1)) | |
| 153 | 151 | |
| 154 | 152 | ); |
| 155 | 153 | } |
modified driver-core/src/test/java/com/datastax/driver/core/StatementWrapperTest.java +20 −13
| @@ -15,17 +15,16 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.policies.*; | |
| 19 | +import com.google.common.collect.Lists; | |
| 20 | +import org.testng.annotations.Test; | |
| 21 | + | |
| 18 | 22 | import java.util.Collection; |
| 19 | 23 | import java.util.Iterator; |
| 20 | 24 | import java.util.concurrent.atomic.AtomicInteger; |
| 21 | 25 | |
| 22 | -import com.google.common.collect.Lists; | |
| 23 | -import org.testng.annotations.Test; | |
| 24 | - | |
| 25 | 26 | import static org.assertj.core.api.Assertions.assertThat; |
| 26 | 27 | |
| 27 | -import com.datastax.driver.core.policies.*; | |
| 28 | - | |
| 29 | 28 | public class StatementWrapperTest extends CCMBridge.PerClassSingleNodeCluster { |
| 30 | 29 | @Override |
| 31 | 30 | protected Collection<String> getTableDefinitions() { |
| @@ -39,9 +38,9 @@ | ||
| 39 | 38 | @Override |
| 40 | 39 | protected Cluster.Builder configure(Cluster.Builder builder) { |
| 41 | 40 | return builder |
| 42 | - .withLoadBalancingPolicy(loadBalancingPolicy) | |
| 43 | - .withSpeculativeExecutionPolicy(speculativeExecutionPolicy) | |
| 44 | - .withRetryPolicy(retryPolicy); | |
| 41 | + .withLoadBalancingPolicy(loadBalancingPolicy) | |
| 42 | + .withSpeculativeExecutionPolicy(speculativeExecutionPolicy) | |
| 43 | + .withRetryPolicy(retryPolicy); | |
| 45 | 44 | } |
| 46 | 45 | |
| 47 | 46 | @Test(groups = "short") |
| @@ -75,7 +74,7 @@ | ||
| 75 | 74 | // Set CL TWO with only one node, so the statement will always cause UNAVAILABLE, |
| 76 | 75 | // which our custom policy ignores. |
| 77 | 76 | Statement s = new SimpleStatement("select * from system.local") |
| 78 | - .setConsistencyLevel(ConsistencyLevel.TWO); | |
| 77 | + .setConsistencyLevel(ConsistencyLevel.TWO); | |
| 79 | 78 | |
| 80 | 79 | session.execute(s); |
| 81 | 80 | assertThat(retryPolicy.customStatementsHandled.get()).isEqualTo(0); |
| @@ -84,14 +83,18 @@ | ||
| 84 | 83 | assertThat(retryPolicy.customStatementsHandled.get()).isEqualTo(1); |
| 85 | 84 | } |
| 86 | 85 | |
| 87 | - /** A custom wrapper that's just used to mark statements. */ | |
| 86 | + /** | |
| 87 | + * A custom wrapper that's just used to mark statements. | |
| 88 | + */ | |
| 88 | 89 | static class CustomStatement extends StatementWrapper { |
| 89 | 90 | protected CustomStatement(Statement wrapped) { |
| 90 | 91 | super(wrapped); |
| 91 | 92 | } |
| 92 | 93 | } |
| 93 | 94 | |
| 94 | - /** A load balancing policy that counts how many times it has seen the custom wrapper */ | |
| 95 | + /** | |
| 96 | + * A load balancing policy that counts how many times it has seen the custom wrapper | |
| 97 | + */ | |
| 95 | 98 | static class CustomLoadBalancingPolicy extends DelegatingLoadBalancingPolicy { |
| 96 | 99 | final AtomicInteger customStatementsHandled = new AtomicInteger(); |
| 97 | 100 | |
| @@ -107,7 +110,9 @@ | ||
| 107 | 110 | } |
| 108 | 111 | } |
| 109 | 112 | |
| 110 | - /** A speculative execution policy that counts how many times it has seen the custom wrapper */ | |
| 113 | + /** | |
| 114 | + * A speculative execution policy that counts how many times it has seen the custom wrapper | |
| 115 | + */ | |
| 111 | 116 | static class CustomSpeculativeExecutionPolicy extends DelegatingSpeculativeExecutionPolicy { |
| 112 | 117 | final AtomicInteger customStatementsHandled = new AtomicInteger(); |
| 113 | 118 | |
| @@ -123,7 +128,9 @@ | ||
| 123 | 128 | } |
| 124 | 129 | } |
| 125 | 130 | |
| 126 | - /** A retry policy that counts how many times it has seen the custom wrapper for UNAVAILABLE errors. */ | |
| 131 | + /** | |
| 132 | + * A retry policy that counts how many times it has seen the custom wrapper for UNAVAILABLE errors. | |
| 133 | + */ | |
| 127 | 134 | static class CustomRetryPolicy implements RetryPolicy { |
| 128 | 135 | final AtomicInteger customStatementsHandled = new AtomicInteger(); |
| 129 | 136 |
modified driver-core/src/test/java/com/datastax/driver/core/StreamIdGeneratorTest.java +1 −0
| @@ -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 | import static org.testng.Assert.fail; |
| 21 | 22 |
modified driver-core/src/test/java/com/datastax/driver/core/TableMetadataTest.java +8 −8
| @@ -15,29 +15,29 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.util.Collection; | |
| 19 | - | |
| 20 | 18 | import com.google.common.collect.Lists; |
| 21 | 19 | import org.testng.annotations.Test; |
| 22 | 20 | |
| 21 | +import java.util.Collection; | |
| 22 | + | |
| 23 | 23 | import static org.assertj.core.api.Assertions.assertThat; |
| 24 | 24 | |
| 25 | 25 | public class TableMetadataTest extends CCMBridge.PerClassSingleNodeCluster { |
| 26 | 26 | @Override |
| 27 | 27 | protected Collection<String> getTableDefinitions() { |
| 28 | 28 | return Lists.newArrayList( |
| 29 | - "CREATE TABLE single_quote (\n" | |
| 30 | - + " c1 int PRIMARY KEY\n" | |
| 31 | - + ") WITH comment = 'comment with single quote '' should work'" | |
| 29 | + "CREATE TABLE single_quote (\n" | |
| 30 | + + " c1 int PRIMARY KEY\n" | |
| 31 | + + ") WITH comment = 'comment with single quote '' should work'" | |
| 32 | 32 | ); |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | @Override |
| 36 | 36 | protected Cluster.Builder configure(Cluster.Builder builder) { |
| 37 | 37 | return builder.withQueryOptions(new QueryOptions() |
| 38 | - .setRefreshNodeIntervalMillis(0) | |
| 39 | - .setRefreshNodeListIntervalMillis(0) | |
| 40 | - .setRefreshSchemaIntervalMillis(0) | |
| 38 | + .setRefreshNodeIntervalMillis(0) | |
| 39 | + .setRefreshNodeListIntervalMillis(0) | |
| 40 | + .setRefreshSchemaIntervalMillis(0) | |
| 41 | 41 | ); |
| 42 | 42 | } |
| 43 | 43 |
modified driver-core/src/test/java/com/datastax/driver/core/TestListener.java +12 −12
| @@ -15,15 +15,13 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.utils.CassandraVersion; | |
| 18 | 19 | import org.testng.*; |
| 19 | 20 | import org.testng.internal.ConstructorOrMethod; |
| 20 | 21 | |
| 21 | -import java.lang.annotation.Annotation; | |
| 22 | 22 | import java.lang.reflect.Method; |
| 23 | 23 | import java.util.concurrent.TimeUnit; |
| 24 | 24 | |
| 25 | -import com.datastax.driver.core.utils.CassandraVersion; | |
| 26 | - | |
| 27 | 25 | public class TestListener extends TestListenerAdapter implements IInvokedMethodListener { |
| 28 | 26 | |
| 29 | 27 | private long start_time = System.nanoTime(); |
| @@ -74,16 +72,17 @@ | ||
| 74 | 72 | |
| 75 | 73 | static String formatIntoHHMMSS(long secondsTotal) { |
| 76 | 74 | long hours = secondsTotal / 3600, |
| 77 | - remainder = secondsTotal % 3600, | |
| 78 | - minutes = remainder / 60, | |
| 79 | - seconds = remainder % 60; | |
| 75 | + remainder = secondsTotal % 3600, | |
| 76 | + minutes = remainder / 60, | |
| 77 | + seconds = remainder % 60; | |
| 80 | 78 | |
| 81 | 79 | return ((hours < 10 ? "0" : "") + hours |
| 82 | - + ':' + (minutes < 10 ? "0" : "") + minutes | |
| 83 | - + ':' + (seconds< 10 ? "0" : "") + seconds); | |
| 80 | + + ':' + (minutes < 10 ? "0" : "") + minutes | |
| 81 | + + ':' + (seconds < 10 ? "0" : "") + seconds); | |
| 84 | 82 | } |
| 85 | 83 | |
| 86 | - @Override public void beforeInvocation(IInvokedMethod testMethod, ITestResult testResult) { | |
| 84 | + @Override | |
| 85 | + public void beforeInvocation(IInvokedMethod testMethod, ITestResult testResult) { | |
| 87 | 86 | // Check to see if the class or method is annotated with 'CassandraVersion', if so ensure the |
| 88 | 87 | // version we are testing with meets the requirement, if not a SkipException is thrown |
| 89 | 88 | // and this test is skipped. |
| @@ -91,19 +90,20 @@ | ||
| 91 | 90 | ConstructorOrMethod constructorOrMethod = testNgMethod.getConstructorOrMethod(); |
| 92 | 91 | |
| 93 | 92 | Class<?> clazz = testNgMethod.getInstance().getClass(); |
| 94 | - if(clazz != null && clazz.isAnnotationPresent(CassandraVersion.class)) { | |
| 93 | + if (clazz != null && clazz.isAnnotationPresent(CassandraVersion.class)) { | |
| 95 | 94 | CassandraVersion cassandraVersion = clazz.getAnnotation(CassandraVersion.class); |
| 96 | 95 | TestUtils.versionCheck(cassandraVersion.major(), cassandraVersion.minor(), cassandraVersion.description()); |
| 97 | 96 | } |
| 98 | 97 | |
| 99 | 98 | Method method = constructorOrMethod.getMethod(); |
| 100 | - if(method != null && method.isAnnotationPresent(CassandraVersion.class)) { | |
| 99 | + if (method != null && method.isAnnotationPresent(CassandraVersion.class)) { | |
| 101 | 100 | CassandraVersion cassandraVersion = method.getAnnotation(CassandraVersion.class); |
| 102 | 101 | TestUtils.versionCheck(cassandraVersion.major(), cassandraVersion.minor(), cassandraVersion.description()); |
| 103 | 102 | } |
| 104 | 103 | } |
| 105 | 104 | |
| 106 | - @Override public void afterInvocation(IInvokedMethod testMethod, ITestResult testResult) { | |
| 105 | + @Override | |
| 106 | + public void afterInvocation(IInvokedMethod testMethod, ITestResult testResult) { | |
| 107 | 107 | // Do nothing |
| 108 | 108 | } |
| 109 | 109 | } |
modified driver-core/src/test/java/com/datastax/driver/core/TestUtils.java +74 −56
| @@ -15,6 +15,17 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.policies.RoundRobinPolicy; | |
| 19 | +import com.datastax.driver.core.policies.WhiteListPolicy; | |
| 20 | +import com.google.common.util.concurrent.Futures; | |
| 21 | +import com.google.common.util.concurrent.Uninterruptibles; | |
| 22 | +import io.netty.channel.EventLoopGroup; | |
| 23 | +import org.scassandra.Scassandra; | |
| 24 | +import org.scassandra.ScassandraFactory; | |
| 25 | +import org.slf4j.Logger; | |
| 26 | +import org.slf4j.LoggerFactory; | |
| 27 | +import org.testng.SkipException; | |
| 28 | + | |
| 18 | 29 | import java.io.IOException; |
| 19 | 30 | import java.math.BigDecimal; |
| 20 | 31 | import java.math.BigInteger; |
| @@ -26,18 +37,6 @@ | ||
| 26 | 37 | import java.util.concurrent.CountDownLatch; |
| 27 | 38 | import java.util.concurrent.TimeUnit; |
| 28 | 39 | |
| 29 | -import com.google.common.util.concurrent.Futures; | |
| 30 | -import com.google.common.util.concurrent.Uninterruptibles; | |
| 31 | -import io.netty.channel.EventLoopGroup; | |
| 32 | -import org.scassandra.Scassandra; | |
| 33 | -import org.scassandra.ScassandraFactory; | |
| 34 | -import org.slf4j.Logger; | |
| 35 | -import org.slf4j.LoggerFactory; | |
| 36 | -import org.testng.SkipException; | |
| 37 | - | |
| 38 | -import com.datastax.driver.core.policies.RoundRobinPolicy; | |
| 39 | -import com.datastax.driver.core.policies.WhiteListPolicy; | |
| 40 | - | |
| 41 | 40 | /** |
| 42 | 41 | * A number of static fields/methods handy for tests. |
| 43 | 42 | */ |
| @@ -58,65 +57,65 @@ | ||
| 58 | 57 | |
| 59 | 58 | public static final int TEST_BASE_NODE_WAIT = SystemProperties.getInt("com.datastax.driver.TEST_BASE_NODE_WAIT", 60); |
| 60 | 59 | |
| 61 | - @SuppressWarnings({ "unchecked", "rawtypes" }) | |
| 60 | + @SuppressWarnings({"unchecked", "rawtypes"}) | |
| 62 | 61 | public static BoundStatement setBoundValue(BoundStatement bs, String name, DataType type, Object value) { |
| 63 | 62 | switch (type.getName()) { |
| 64 | 63 | case ASCII: |
| 65 | - bs.setString(name, (String)value); | |
| 64 | + bs.setString(name, (String) value); | |
| 66 | 65 | break; |
| 67 | 66 | case BIGINT: |
| 68 | - bs.setLong(name, (Long)value); | |
| 67 | + bs.setLong(name, (Long) value); | |
| 69 | 68 | break; |
| 70 | 69 | case BLOB: |
| 71 | - bs.setBytes(name, (ByteBuffer)value); | |
| 70 | + bs.setBytes(name, (ByteBuffer) value); | |
| 72 | 71 | break; |
| 73 | 72 | case BOOLEAN: |
| 74 | - bs.setBool(name, (Boolean)value); | |
| 73 | + bs.setBool(name, (Boolean) value); | |
| 75 | 74 | break; |
| 76 | 75 | case COUNTER: |
| 77 | 76 | // Just a no-op, we shouldn't handle counters the same way than other types |
| 78 | 77 | break; |
| 79 | 78 | case DECIMAL: |
| 80 | - bs.setDecimal(name, (BigDecimal)value); | |
| 79 | + bs.setDecimal(name, (BigDecimal) value); | |
| 81 | 80 | break; |
| 82 | 81 | case DOUBLE: |
| 83 | - bs.setDouble(name, (Double)value); | |
| 82 | + bs.setDouble(name, (Double) value); | |
| 84 | 83 | break; |
| 85 | 84 | case FLOAT: |
| 86 | - bs.setFloat(name, (Float)value); | |
| 85 | + bs.setFloat(name, (Float) value); | |
| 87 | 86 | break; |
| 88 | 87 | case INET: |
| 89 | - bs.setInet(name, (InetAddress)value); | |
| 88 | + bs.setInet(name, (InetAddress) value); | |
| 90 | 89 | break; |
| 91 | 90 | case INT: |
| 92 | - bs.setInt(name, (Integer)value); | |
| 91 | + bs.setInt(name, (Integer) value); | |
| 93 | 92 | break; |
| 94 | 93 | case TEXT: |
| 95 | - bs.setString(name, (String)value); | |
| 94 | + bs.setString(name, (String) value); | |
| 96 | 95 | break; |
| 97 | 96 | case TIMESTAMP: |
| 98 | - bs.setDate(name, (Date)value); | |
| 97 | + bs.setDate(name, (Date) value); | |
| 99 | 98 | break; |
| 100 | 99 | case UUID: |
| 101 | - bs.setUUID(name, (UUID)value); | |
| 100 | + bs.setUUID(name, (UUID) value); | |
| 102 | 101 | break; |
| 103 | 102 | case VARCHAR: |
| 104 | - bs.setString(name, (String)value); | |
| 103 | + bs.setString(name, (String) value); | |
| 105 | 104 | break; |
| 106 | 105 | case VARINT: |
| 107 | - bs.setVarint(name, (BigInteger)value); | |
| 106 | + bs.setVarint(name, (BigInteger) value); | |
| 108 | 107 | break; |
| 109 | 108 | case TIMEUUID: |
| 110 | - bs.setUUID(name, (UUID)value); | |
| 109 | + bs.setUUID(name, (UUID) value); | |
| 111 | 110 | break; |
| 112 | 111 | case LIST: |
| 113 | - bs.setList(name, (List)value); | |
| 112 | + bs.setList(name, (List) value); | |
| 114 | 113 | break; |
| 115 | 114 | case SET: |
| 116 | - bs.setSet(name, (Set)value); | |
| 115 | + bs.setSet(name, (Set) value); | |
| 117 | 116 | break; |
| 118 | 117 | case MAP: |
| 119 | - bs.setMap(name, (Map)value); | |
| 118 | + bs.setMap(name, (Map) value); | |
| 120 | 119 | break; |
| 121 | 120 | default: |
| 122 | 121 | throw new RuntimeException("Missing handling of " + type); |
| @@ -178,7 +177,7 @@ | ||
| 178 | 177 | case BIGINT: |
| 179 | 178 | return 42L; |
| 180 | 179 | case BLOB: |
| 181 | - return ByteBuffer.wrap(new byte[]{ (byte)4, (byte)12, (byte)1 }); | |
| 180 | + return ByteBuffer.wrap(new byte[]{(byte) 4, (byte) 12, (byte) 1}); | |
| 182 | 181 | case BOOLEAN: |
| 183 | 182 | return true; |
| 184 | 183 | case COUNTER: |
| @@ -190,7 +189,7 @@ | ||
| 190 | 189 | case FLOAT: |
| 191 | 190 | return 3.142519f; |
| 192 | 191 | case INET: |
| 193 | - return InetAddress.getByAddress(new byte[]{ (byte)127, (byte)0, (byte)0, (byte)1 }); | |
| 192 | + return InetAddress.getByAddress(new byte[]{(byte) 127, (byte) 0, (byte) 0, (byte) 1}); | |
| 194 | 193 | case INT: |
| 195 | 194 | return 24; |
| 196 | 195 | case TEXT: |
| @@ -206,11 +205,17 @@ | ||
| 206 | 205 | case TIMEUUID: |
| 207 | 206 | return UUID.fromString("FE2B4360-28C6-11E2-81C1-0800200C9A66"); |
| 208 | 207 | case LIST: |
| 209 | - return new ArrayList<Object>(){{ add(getFixedValue(type.getTypeArguments().get(0))); }}; | |
| 208 | + return new ArrayList<Object>() {{ | |
| 209 | + add(getFixedValue(type.getTypeArguments().get(0))); | |
| 210 | + }}; | |
| 210 | 211 | case SET: |
| 211 | - return new HashSet<Object>(){{ add(getFixedValue(type.getTypeArguments().get(0))); }}; | |
| 212 | + return new HashSet<Object>() {{ | |
| 213 | + add(getFixedValue(type.getTypeArguments().get(0))); | |
| 214 | + }}; | |
| 212 | 215 | case MAP: |
| 213 | - return new HashMap<Object, Object>(){{ put(getFixedValue(type.getTypeArguments().get(0)), getFixedValue(type.getTypeArguments().get(1))); }}; | |
| 216 | + return new HashMap<Object, Object>() {{ | |
| 217 | + put(getFixedValue(type.getTypeArguments().get(0)), getFixedValue(type.getTypeArguments().get(1))); | |
| 218 | + }}; | |
| 214 | 219 | } |
| 215 | 220 | } catch (Exception e) { |
| 216 | 221 | throw new RuntimeException(e); |
| @@ -260,11 +265,17 @@ | ||
| 260 | 265 | case TIMEUUID: |
| 261 | 266 | return UUID.fromString("FE2B4360-28C6-11E2-81C1-0800200C9A66"); |
| 262 | 267 | case LIST: |
| 263 | - return new ArrayList<Object>(){{ add(getFixedValue2(type.getTypeArguments().get(0))); }}; | |
| 268 | + return new ArrayList<Object>() {{ | |
| 269 | + add(getFixedValue2(type.getTypeArguments().get(0))); | |
| 270 | + }}; | |
| 264 | 271 | case SET: |
| 265 | - return new HashSet<Object>(){{ add(getFixedValue2(type.getTypeArguments().get(0))); }}; | |
| 272 | + return new HashSet<Object>() {{ | |
| 273 | + add(getFixedValue2(type.getTypeArguments().get(0))); | |
| 274 | + }}; | |
| 266 | 275 | case MAP: |
| 267 | - return new HashMap<Object, Object>(){{ put(getFixedValue2(type.getTypeArguments().get(0)), getFixedValue2(type.getTypeArguments().get(1))); }}; | |
| 276 | + return new HashMap<Object, Object>() {{ | |
| 277 | + put(getFixedValue2(type.getTypeArguments().get(0)), getFixedValue2(type.getTypeArguments().get(1))); | |
| 278 | + }}; | |
| 268 | 279 | } |
| 269 | 280 | } catch (Exception e) { |
| 270 | 281 | throw new RuntimeException(e); |
| @@ -321,8 +332,8 @@ | ||
| 321 | 332 | logger.info("Waiting for stopped node: " + node); |
| 322 | 333 | else if (waitForOut) |
| 323 | 334 | logger.info("Waiting for decommissioned node: " + node); |
| 324 | - else | |
| 325 | - logger.info("Waiting for upcoming node: " + node); | |
| 335 | + else | |
| 336 | + logger.info("Waiting for upcoming node: " + node); | |
| 326 | 337 | |
| 327 | 338 | // In the case where the we've killed the last node in the cluster, if we haven't |
| 328 | 339 | // tried doing an actual query, the driver won't realize that last node is dead until |
| @@ -334,7 +345,7 @@ | ||
| 334 | 345 | |
| 335 | 346 | InetAddress address; |
| 336 | 347 | try { |
| 337 | - address = InetAddress.getByName(node); | |
| 348 | + address = InetAddress.getByName(node); | |
| 338 | 349 | } catch (Exception e) { |
| 339 | 350 | // That's a problem but that's not *our* problem |
| 340 | 351 | return; |
| @@ -344,11 +355,17 @@ | ||
| 344 | 355 | for (int i = 0; i < maxTry; ++i) { |
| 345 | 356 | for (Host host : metadata.getAllHosts()) { |
| 346 | 357 | if (host.getAddress().equals(address) && testHost(host, waitForDead)) { |
| 347 | - try { Thread.sleep(10000); } catch (Exception e) {} | |
| 358 | + try { | |
| 359 | + Thread.sleep(10000); | |
| 360 | + } catch (Exception e) { | |
| 361 | + } | |
| 348 | 362 | return; |
| 349 | 363 | } |
| 350 | 364 | } |
| 351 | - try { Thread.sleep(1000); } catch (Exception e) {} | |
| 365 | + try { | |
| 366 | + Thread.sleep(1000); | |
| 367 | + } catch (Exception e) { | |
| 368 | + } | |
| 352 | 369 | } |
| 353 | 370 | |
| 354 | 371 | for (Host host : metadata.getAllHosts()) { |
| @@ -363,7 +380,7 @@ | ||
| 363 | 380 | } |
| 364 | 381 | } |
| 365 | 382 | |
| 366 | - if (waitForOut){ | |
| 383 | + if (waitForOut) { | |
| 367 | 384 | return; |
| 368 | 385 | } else { |
| 369 | 386 | logger.info(node + " is not part of the cluster after " + maxTry + 's'); |
| @@ -392,12 +409,12 @@ | ||
| 392 | 409 | |
| 393 | 410 | public static Host findOrWaitForHost(final Cluster cluster, final String address, long duration, TimeUnit unit) { |
| 394 | 411 | Host host = findHost(cluster, address); |
| 395 | - if(host == null) { | |
| 412 | + if (host == null) { | |
| 396 | 413 | final CountDownLatch addSignal = new CountDownLatch(1); |
| 397 | 414 | Host.StateListener addListener = new StateListenerBase() { |
| 398 | 415 | @Override |
| 399 | 416 | public void onAdd(Host host) { |
| 400 | - if(host.getAddress().getHostAddress().equals(address)) { | |
| 417 | + if (host.getAddress().getHostAddress().equals(address)) { | |
| 401 | 418 | // for a new node, because of this we also listen for add events. |
| 402 | 419 | addSignal.countDown(); |
| 403 | 420 | } |
| @@ -437,8 +454,8 @@ | ||
| 437 | 454 | ControlConnection controlConnection = cluster.manager.controlConnection; |
| 438 | 455 | long durationNs = TimeUnit.NANOSECONDS.convert(duration, unit); |
| 439 | 456 | long start = System.nanoTime(); |
| 440 | - while(System.nanoTime() - start < durationNs) { | |
| 441 | - if(controlConnection.isOpen()) { | |
| 457 | + while (System.nanoTime() - start < durationNs) { | |
| 458 | + if (controlConnection.isOpen()) { | |
| 442 | 459 | return controlConnection.connectedHost(); |
| 443 | 460 | } |
| 444 | 461 | Uninterruptibles.sleepUninterruptibly(100, TimeUnit.MILLISECONDS); |
| @@ -447,7 +464,7 @@ | ||
| 447 | 464 | } |
| 448 | 465 | |
| 449 | 466 | public static HostConnectionPool poolOf(Session session, int hostNumber) { |
| 450 | - SessionManager sessionManager = (SessionManager)session; | |
| 467 | + SessionManager sessionManager = (SessionManager) session; | |
| 451 | 468 | return sessionManager.pools.get(findHost(session.getCluster(), hostNumber)); |
| 452 | 469 | } |
| 453 | 470 | |
| @@ -455,6 +472,7 @@ | ||
| 455 | 472 | Configuration configuration = cluster.getConfiguration(); |
| 456 | 473 | return configuration.getPoolingOptions().getCoreConnectionsPerHost(HostDistance.LOCAL); |
| 457 | 474 | } |
| 475 | + | |
| 458 | 476 | /** |
| 459 | 477 | * @return A Scassandra instance with an arbitrarily chosen binary port from 8042-8142 and admin port from |
| 460 | 478 | * 8052-8152. |
| @@ -492,7 +510,7 @@ | ||
| 492 | 510 | String version = System.getProperty("cassandra.version"); |
| 493 | 511 | String[] versionArray = version.split("\\.|-"); |
| 494 | 512 | double major = Double.parseDouble(versionArray[0] + "." + versionArray[1]); |
| 495 | - if(major < 2.0) { | |
| 513 | + if (major < 2.0) { | |
| 496 | 514 | return 1; |
| 497 | 515 | } else { |
| 498 | 516 | return 2; |
| @@ -506,9 +524,9 @@ | ||
| 506 | 524 | Host controlHost = cluster.manager.controlConnection.connectedHost(); |
| 507 | 525 | List<InetSocketAddress> singleAddress = Collections.singletonList(controlHost.getSocketAddress()); |
| 508 | 526 | return Cluster.builder() |
| 509 | - .addContactPointsWithPorts(singleAddress) | |
| 510 | - .withLoadBalancingPolicy(new WhiteListPolicy(new RoundRobinPolicy(), singleAddress)) | |
| 511 | - .build(); | |
| 527 | + .addContactPointsWithPorts(singleAddress) | |
| 528 | + .withLoadBalancingPolicy(new WhiteListPolicy(new RoundRobinPolicy(), singleAddress)) | |
| 529 | + .build(); | |
| 512 | 530 | } |
| 513 | 531 | |
| 514 | 532 | /** |
| @@ -516,8 +534,8 @@ | ||
| 516 | 534 | */ |
| 517 | 535 | public static QueryOptions nonDebouncingQueryOptions() { |
| 518 | 536 | return new QueryOptions().setRefreshNodeIntervalMillis(0) |
| 519 | - .setRefreshNodeListIntervalMillis(0) | |
| 520 | - .setRefreshSchemaIntervalMillis(0); | |
| 537 | + .setRefreshNodeListIntervalMillis(0) | |
| 538 | + .setRefreshSchemaIntervalMillis(0); | |
| 521 | 539 | } |
| 522 | 540 | |
| 523 | 541 | /** |
modified driver-core/src/test/java/com/datastax/driver/core/TimeoutStressTest.java +23 −23
| @@ -74,9 +74,9 @@ | ||
| 74 | 74 | ccmBridge = CCMBridge.builder("test").withNodes(3).build(); |
| 75 | 75 | channelMonitor = new SocketChannelMonitor(); |
| 76 | 76 | nodes = Lists.newArrayList( |
| 77 | - new InetSocketAddress(CCMBridge.IP_PREFIX + '1', 9042), | |
| 78 | - new InetSocketAddress(CCMBridge.IP_PREFIX + '2', 9042), | |
| 79 | - new InetSocketAddress(CCMBridge.IP_PREFIX + '3', 9042) | |
| 77 | + new InetSocketAddress(CCMBridge.IP_PREFIX + '1', 9042), | |
| 78 | + new InetSocketAddress(CCMBridge.IP_PREFIX + '2', 9042), | |
| 79 | + new InetSocketAddress(CCMBridge.IP_PREFIX + '3', 9042) | |
| 80 | 80 | ); |
| 81 | 81 | |
| 82 | 82 | PoolingOptions poolingOptions = new PoolingOptions().setCoreConnectionsPerHost(HostDistance.LOCAL, 8); |
| @@ -91,33 +91,33 @@ | ||
| 91 | 91 | |
| 92 | 92 | @AfterClass(groups = "stress") |
| 93 | 93 | public void afterClass() { |
| 94 | - if(ccmBridge != null) { | |
| 94 | + if (ccmBridge != null) { | |
| 95 | 95 | ccmBridge.stop(); |
| 96 | 96 | } |
| 97 | - if(channelMonitor != null) { | |
| 97 | + if (channelMonitor != null) { | |
| 98 | 98 | channelMonitor.stop(); |
| 99 | 99 | } |
| 100 | - if(cluster != null) { | |
| 100 | + if (cluster != null) { | |
| 101 | 101 | cluster.close(); |
| 102 | 102 | } |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | /** |
| 106 | - * <p> | |
| 106 | + * <p/> | |
| 107 | 107 | * Validates that under extreme timeout conditions the driver is able to properly maintain connection pools in |
| 108 | 108 | * addition to not leaking connections. |
| 109 | - * | |
| 110 | - * <p> | |
| 109 | + * <p/> | |
| 110 | + * <p/> | |
| 111 | 111 | * Does the following: |
| 112 | 112 | * <ol> |
| 113 | - * <li>Creates a table and loads 30k rows in a single partition.</li> | |
| 114 | - * <li>Sets the connection and read timeout {@link SocketOptions} to very low values.</li> | |
| 115 | - * <li>Spawns workers that concurrently execute queries.</li> | |
| 116 | - * <li>For some duration, repeatedly measures number of open socket connections and warns if exceeded.</li> | |
| 117 | - * <li>After a duration, resets {@link SocketOptions} to defaults.</li> | |
| 118 | - * <li>Wait for 20 seconds for reaper to remove old connections and restore pools.</li> | |
| 119 | - * <li>Ensure pools are restored.</li> | |
| 120 | - * <li>Shutdown session and ensure that there remains only 1 open connection.</li> | |
| 113 | + * <li>Creates a table and loads 30k rows in a single partition.</li> | |
| 114 | + * <li>Sets the connection and read timeout {@link SocketOptions} to very low values.</li> | |
| 115 | + * <li>Spawns workers that concurrently execute queries.</li> | |
| 116 | + * <li>For some duration, repeatedly measures number of open socket connections and warns if exceeded.</li> | |
| 117 | + * <li>After a duration, resets {@link SocketOptions} to defaults.</li> | |
| 118 | + * <li>Wait for 20 seconds for reaper to remove old connections and restore pools.</li> | |
| 119 | + * <li>Ensure pools are restored.</li> | |
| 120 | + * <li>Shutdown session and ensure that there remains only 1 open connection.</li> | |
| 121 | 121 | * </ol> |
| 122 | 122 | * |
| 123 | 123 | * @test_category connection:connection_pool |
| @@ -164,7 +164,7 @@ | ||
| 164 | 164 | |
| 165 | 165 | // Ensure that we don't exceed maximum connections. Log as warning as there will be a bit of a timing |
| 166 | 166 | // factor between retrieving open connections and checking the reaper. |
| 167 | - if(openChannels.size() > maxConnections) { | |
| 167 | + if (openChannels.size() > maxConnections) { | |
| 168 | 168 | logger.warn("{} of open channels: {} exceeds maximum expected: {}. " + |
| 169 | 169 | "This could be because there are connections to be cleaned up in the reaper.", |
| 170 | 170 | openChannels.size(), maxConnections, openChannels); |
| @@ -180,7 +180,7 @@ | ||
| 180 | 180 | .setReadTimeoutMillis(SocketOptions.DEFAULT_READ_TIMEOUT_MILLIS); |
| 181 | 181 | |
| 182 | 182 | logger.debug("Sleeping 20 seconds to allow connection reaper to clean up connections " + |
| 183 | - "and for the pools to recover."); | |
| 183 | + "and for the pools to recover."); | |
| 184 | 184 | Uninterruptibles.sleepUninterruptibly(20, TimeUnit.SECONDS); |
| 185 | 185 | |
| 186 | 186 | Collection<SocketChannel> openChannels = channelMonitor.openChannels(nodes); |
| @@ -250,7 +250,7 @@ | ||
| 250 | 250 | @Override |
| 251 | 251 | public void run() { |
| 252 | 252 | |
| 253 | - while(!stopped.get()) { | |
| 253 | + while (!stopped.get()) { | |
| 254 | 254 | try { |
| 255 | 255 | concurrentQueries.acquire(); |
| 256 | 256 | ResultSetFuture future = session.executeAsync(statement.bind("0")); |
| @@ -259,21 +259,21 @@ | ||
| 259 | 259 | @Override |
| 260 | 260 | public void onSuccess(ResultSet result) { |
| 261 | 261 | concurrentQueries.release(); |
| 262 | - if(executedQueries.incrementAndGet() % 1000 == 0) | |
| 262 | + if (executedQueries.incrementAndGet() % 1000 == 0) | |
| 263 | 263 | logger.debug("Successfully executed {}. rows: {}", executedQueries.get(), result.getAvailableWithoutFetching()); |
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | @Override |
| 267 | 267 | public void onFailure(Throwable t) { |
| 268 | 268 | concurrentQueries.release(); |
| 269 | - if(t instanceof NoHostAvailableException) { | |
| 269 | + if (t instanceof NoHostAvailableException) { | |
| 270 | 270 | //logger.error("NHAE: {}", t.getMessage()); |
| 271 | 271 | } else { |
| 272 | 272 | //logger.error("Exception", t); |
| 273 | 273 | } |
| 274 | 274 | } |
| 275 | 275 | }); |
| 276 | - } catch(Exception e) { | |
| 276 | + } catch (Exception e) { | |
| 277 | 277 | logger.error("Failure while submitting query.", e); |
| 278 | 278 | } |
| 279 | 279 | } |
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/TypeCodecTest.java +6 −7
| @@ -15,14 +15,13 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.util.Collections; | |
| 19 | -import java.util.List; | |
| 20 | - | |
| 21 | -import org.testng.collections.Lists; | |
| 22 | - | |
| 23 | 18 | import com.google.common.base.Strings; |
| 24 | 19 | import org.testng.Assert; |
| 25 | 20 | import org.testng.annotations.Test; |
| 21 | +import org.testng.collections.Lists; | |
| 22 | + | |
| 23 | +import java.util.Collections; | |
| 24 | +import java.util.List; | |
| 26 | 25 | |
| 27 | 26 | import static com.datastax.driver.core.DataType.text; |
| 28 | 27 | |
| @@ -54,7 +53,7 @@ | ||
| 54 | 53 | Assert.assertNotNull(mapType); |
| 55 | 54 | } |
| 56 | 55 | |
| 57 | - @Test(groups = "unit", expectedExceptions = { IllegalArgumentException.class }) | |
| 56 | + @Test(groups = "unit", expectedExceptions = {IllegalArgumentException.class}) | |
| 58 | 57 | public void collectionTooLargeTest() throws Exception { |
| 59 | 58 | TypeCodec<List<Integer>> listType = TypeCodec.listOf(DataType.cint()); |
| 60 | 59 | List<Integer> list = Collections.nCopies(65536, 1); |
| @@ -62,7 +61,7 @@ | ||
| 62 | 61 | listType.serialize(list); |
| 63 | 62 | } |
| 64 | 63 | |
| 65 | - @Test(groups = "unit", expectedExceptions = { IllegalArgumentException.class }) | |
| 64 | + @Test(groups = "unit", expectedExceptions = {IllegalArgumentException.class}) | |
| 66 | 65 | public void collectionElementTooLargeTest() throws Exception { |
| 67 | 66 | TypeCodec<List<String>> listType = TypeCodec.listOf(DataType.text()); |
| 68 | 67 | List<String> list = Lists.newArrayList(Strings.repeat("a", 65536)); |
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/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.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(TestUtils.CREATE_TABLE_SIMPLE_FORMAT, table) | |
| 55 | + String.format(TestUtils.CREATE_KEYSPACE_SIMPLE_FORMAT, keyspace, 1), | |
| 56 | + "USE " + keyspace, | |
| 57 | + String.format(TestUtils.CREATE_TABLE_SIMPLE_FORMAT, 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/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 +20 −26
| @@ -15,35 +15,29 @@ | ||
| 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.*; | |
| 21 | 19 | import com.google.common.collect.ImmutableList; |
| 22 | 20 | import com.google.common.collect.ImmutableMap; |
| 23 | 21 | import org.mockito.Mockito; |
| 24 | 22 | import org.scassandra.Scassandra; |
| 25 | 23 | import org.scassandra.http.client.PrimingRequest; |
| 26 | -import org.testng.annotations.AfterClass; | |
| 27 | 24 | import org.testng.annotations.AfterMethod; |
| 28 | -import org.testng.annotations.BeforeClass; | |
| 29 | 25 | import org.testng.annotations.BeforeMethod; |
| 30 | 26 | |
| 31 | -import static org.assertj.core.api.Assertions.assertThat; | |
| 32 | -import static org.mockito.Matchers.any; | |
| 33 | -import static org.mockito.Matchers.anyBoolean; | |
| 34 | -import static org.mockito.Matchers.anyInt; | |
| 35 | -import static org.mockito.Mockito.times; | |
| 36 | - | |
| 37 | -import com.datastax.driver.core.*; | |
| 27 | +import java.util.List; | |
| 28 | +import java.util.Map; | |
| 38 | 29 | |
| 39 | 30 | import static com.datastax.driver.core.TestUtils.nonQuietClusterCloseOptions; |
| 31 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 32 | +import static org.mockito.Matchers.*; | |
| 33 | +import static org.mockito.Mockito.times; | |
| 40 | 34 | |
| 41 | 35 | /** |
| 42 | 36 | * Base class for retry policy integration tests. |
| 43 | - * | |
| 37 | + * <p/> | |
| 44 | 38 | * We use SCassandra to easily simulate specific errors (unavailable, read timeout...) on nodes, |
| 45 | 39 | * and SortingLoadBalancingPolicy to get a predictable order of the query plan (always host1, host2, host3). |
| 46 | - * | |
| 40 | + * <p/> | |
| 47 | 41 | * Note that SCassandra only allows a limited number of test cases, for instance it always returns errors |
| 48 | 42 | * with receivedResponses = 0. If that becomes more finely tuneable in the future, we'll be able to add more |
| 49 | 43 | * tests in child classes. |
| @@ -67,11 +61,11 @@ | ||
| 67 | 61 | scassandras.init(); |
| 68 | 62 | |
| 69 | 63 | cluster = Cluster.builder() |
| 70 | - .addContactPoint(CCMBridge.ipOfNode(1)) | |
| 71 | - .withRetryPolicy(retryPolicy) | |
| 72 | - .withLoadBalancingPolicy(new SortingLoadBalancingPolicy()) | |
| 73 | - .withNettyOptions(nonQuietClusterCloseOptions) | |
| 74 | - .build(); | |
| 64 | + .addContactPoint(CCMBridge.ipOfNode(1)) | |
| 65 | + .withRetryPolicy(retryPolicy) | |
| 66 | + .withLoadBalancingPolicy(new SortingLoadBalancingPolicy()) | |
| 67 | + .withNettyOptions(nonQuietClusterCloseOptions) | |
| 68 | + .build(); | |
| 75 | 69 | |
| 76 | 70 | session = cluster.connect(); |
| 77 | 71 | |
| @@ -83,16 +77,16 @@ | ||
| 83 | 77 | |
| 84 | 78 | Mockito.reset(retryPolicy); |
| 85 | 79 | |
| 86 | - for(Scassandra node : scassandras.nodes()) { | |
| 80 | + for (Scassandra node : scassandras.nodes()) { | |
| 87 | 81 | node.activityClient().clearAllRecordedActivity(); |
| 88 | 82 | } |
| 89 | 83 | } |
| 90 | 84 | |
| 91 | 85 | protected void simulateError(int hostNumber, PrimingRequest.Result result) { |
| 92 | 86 | scassandras.node(hostNumber).primingClient().prime(PrimingRequest.queryBuilder() |
| 93 | - .withQuery("mock query") | |
| 94 | - .withResult(result) | |
| 95 | - .build()); | |
| 87 | + .withQuery("mock query") | |
| 88 | + .withResult(result) | |
| 89 | + .build()); | |
| 96 | 90 | } |
| 97 | 91 | |
| 98 | 92 | protected void simulateNormalResponse(int hostNumber) { |
| @@ -116,18 +110,18 @@ | ||
| 116 | 110 | |
| 117 | 111 | protected void assertOnReadTimeoutWasCalled(int times) { |
| 118 | 112 | Mockito.verify(retryPolicy, times(times)).onReadTimeout( |
| 119 | - any(Statement.class), any(ConsistencyLevel.class), anyInt(), anyInt(), anyBoolean(), anyInt()); | |
| 113 | + any(Statement.class), any(ConsistencyLevel.class), anyInt(), anyInt(), anyBoolean(), anyInt()); | |
| 120 | 114 | |
| 121 | 115 | } |
| 122 | 116 | |
| 123 | 117 | protected void assertOnWriteTimeoutWasCalled(int times) { |
| 124 | 118 | Mockito.verify(retryPolicy, times(times)).onWriteTimeout( |
| 125 | - any(Statement.class), any(ConsistencyLevel.class), any(WriteType.class), anyInt(), anyInt(), anyInt()); | |
| 119 | + any(Statement.class), any(ConsistencyLevel.class), any(WriteType.class), anyInt(), anyInt(), anyInt()); | |
| 126 | 120 | } |
| 127 | 121 | |
| 128 | 122 | protected void assertOnUnavailableWasCalled(int times) { |
| 129 | 123 | Mockito.verify(retryPolicy, times(times)).onUnavailable( |
| 130 | - any(Statement.class), any(ConsistencyLevel.class), anyInt(), anyInt(), anyInt()); | |
| 124 | + any(Statement.class), any(ConsistencyLevel.class), anyInt(), anyInt(), anyInt()); | |
| 131 | 125 | } |
| 132 | 126 | |
| 133 | 127 | 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 +7 −8
| @@ -15,6 +15,11 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core.policies; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.ConsistencyLevel; | |
| 19 | +import com.datastax.driver.core.ResultSet; | |
| 20 | +import com.datastax.driver.core.Statement; | |
| 21 | +import com.datastax.driver.core.WriteType; | |
| 22 | +import com.datastax.driver.core.exceptions.UnavailableException; | |
| 18 | 23 | import org.testng.annotations.Test; |
| 19 | 24 | |
| 20 | 25 | import static org.assertj.core.api.Assertions.assertThat; |
| @@ -22,12 +27,6 @@ | ||
| 22 | 27 | import static org.scassandra.http.client.PrimingRequest.Result.read_request_timeout; |
| 23 | 28 | import static org.scassandra.http.client.PrimingRequest.Result.unavailable; |
| 24 | 29 | |
| 25 | -import com.datastax.driver.core.ConsistencyLevel; | |
| 26 | -import com.datastax.driver.core.ResultSet; | |
| 27 | -import com.datastax.driver.core.Statement; | |
| 28 | -import com.datastax.driver.core.WriteType; | |
| 29 | -import com.datastax.driver.core.exceptions.UnavailableException; | |
| 30 | - | |
| 31 | 30 | /** |
| 32 | 31 | * Integration test with a custom implementation, to test retry and ignore decisions. |
| 33 | 32 | */ |
| @@ -84,8 +83,8 @@ | ||
| 84 | 83 | @Override |
| 85 | 84 | public RetryDecision onUnavailable(Statement statement, ConsistencyLevel cl, int requiredReplica, int aliveReplica, int nbRetry) { |
| 86 | 85 | return (nbRetry == 0) |
| 87 | - ? RetryDecision.retry(cl) | |
| 88 | - : RetryDecision.rethrow(); | |
| 86 | + ? RetryDecision.retry(cl) | |
| 87 | + : RetryDecision.rethrow(); | |
| 89 | 88 | } |
| 90 | 89 | } |
| 91 | 90 | } |
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 +8 −12
| @@ -20,22 +20,18 @@ | ||
| 20 | 20 | import com.datastax.driver.core.Metrics; |
| 21 | 21 | import com.datastax.driver.core.Session; |
| 22 | 22 | import com.datastax.driver.core.exceptions.NoHostAvailableException; |
| 23 | - | |
| 24 | -import org.scassandra.Scassandra; | |
| 25 | -import org.testng.annotations.Test; | |
| 26 | - | |
| 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 | 23 | import com.datastax.driver.core.exceptions.ReadTimeoutException; |
| 34 | 24 | import com.datastax.driver.core.exceptions.UnavailableException; |
| 35 | 25 | import com.datastax.driver.core.exceptions.WriteTimeoutException; |
| 26 | +import org.scassandra.Scassandra; | |
| 27 | +import org.testng.annotations.Test; | |
| 36 | 28 | |
| 37 | 29 | import java.util.Collections; |
| 38 | 30 | |
| 31 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 32 | +import static org.assertj.core.api.Assertions.fail; | |
| 33 | +import static org.scassandra.http.client.PrimingRequest.Result.*; | |
| 34 | + | |
| 39 | 35 | public class DefaultRetryPolicyIntegrationTest extends AbstractRetryPolicyIntegrationTest { |
| 40 | 36 | public DefaultRetryPolicyIntegrationTest() { |
| 41 | 37 | super(DefaultRetryPolicy.INSTANCE); |
| @@ -119,7 +115,7 @@ | ||
| 119 | 115 | try { |
| 120 | 116 | Session whiteListedSession = whiteListedCluster.connect(); |
| 121 | 117 | // Clear all activity as result of connect. |
| 122 | - for(Scassandra node : scassandras.nodes()) { | |
| 118 | + for (Scassandra node : scassandras.nodes()) { | |
| 123 | 119 | node.activityClient().clearAllRecordedActivity(); |
| 124 | 120 | } |
| 125 | 121 | |
| @@ -128,7 +124,7 @@ | ||
| 128 | 124 | try { |
| 129 | 125 | query(whiteListedSession); |
| 130 | 126 | fail("expected an NoHostAvailableException"); |
| 131 | - } catch(NoHostAvailableException e) { | |
| 127 | + } catch (NoHostAvailableException e) { | |
| 132 | 128 | // ok |
| 133 | 129 | Throwable error = e.getErrors().get(host1.getSocketAddress()); |
| 134 | 130 | assertThat(error).isNotNull(); |
modified driver-core/src/test/java/com/datastax/driver/core/policies/DelegatingLoadBalancingPolicy.java +5 −5
| @@ -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, CloseableLoadBalancingPolicy { |
| @@ -75,6 +75,6 @@ | ||
| 75 | 75 | @Override |
| 76 | 76 | public void close() { |
| 77 | 77 | if (delegate instanceof CloseableLoadBalancingPolicy) |
| 78 | - ((CloseableLoadBalancingPolicy)delegate).close(); | |
| 78 | + ((CloseableLoadBalancingPolicy) delegate).close(); | |
| 79 | 79 | } |
| 80 | 80 | } |
| No newline at the end of the file |
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/EC2MultiRegionAddressTranslaterTest.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 | EC2MultiRegionAddressTranslater translater = new EC2MultiRegionAddressTranslater(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 | - EC2MultiRegionAddressTranslater.reverse(address) | |
| 82 | + EC2MultiRegionAddressTranslater.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 | - EC2MultiRegionAddressTranslater.reverse(address) | |
| 92 | + EC2MultiRegionAddressTranslater.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 +4 −7
| @@ -15,17 +15,14 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core.policies; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.exceptions.ReadTimeoutException; | |
| 19 | +import com.datastax.driver.core.exceptions.UnavailableException; | |
| 20 | +import com.datastax.driver.core.exceptions.WriteTimeoutException; | |
| 18 | 21 | import org.testng.annotations.Test; |
| 19 | 22 | |
| 20 | 23 | import static org.assertj.core.api.Assertions.assertThat; |
| 21 | 24 | import static org.assertj.core.api.Assertions.fail; |
| 22 | -import static org.scassandra.http.client.PrimingRequest.Result.read_request_timeout; | |
| 23 | -import static org.scassandra.http.client.PrimingRequest.Result.unavailable; | |
| 24 | -import static org.scassandra.http.client.PrimingRequest.Result.write_request_timeout; | |
| 25 | - | |
| 26 | -import com.datastax.driver.core.exceptions.ReadTimeoutException; | |
| 27 | -import com.datastax.driver.core.exceptions.UnavailableException; | |
| 28 | -import com.datastax.driver.core.exceptions.WriteTimeoutException; | |
| 25 | +import static org.scassandra.http.client.PrimingRequest.Result.*; | |
| 29 | 26 | |
| 30 | 27 | public class FallthroughRetryPolicyIntegrationTest extends AbstractRetryPolicyIntegrationTest { |
| 31 | 28 | public FallthroughRetryPolicyIntegrationTest() { |
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/LatencyAwarePolicyTest.java +22 −24
| @@ -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 | /** |
| @@ -60,13 +58,13 @@ | ||
| 60 | 58 | // given |
| 61 | 59 | String query = "SELECT foo FROM bar"; |
| 62 | 60 | primingClient.prime( |
| 63 | - queryBuilder() | |
| 64 | - .withQuery(query) | |
| 65 | - .build() | |
| 61 | + queryBuilder() | |
| 62 | + .withQuery(query) | |
| 63 | + .build() | |
| 66 | 64 | ); |
| 67 | 65 | LatencyAwarePolicy latencyAwarePolicy = LatencyAwarePolicy.builder(new RoundRobinPolicy()) |
| 68 | - .withMininumMeasurements(1) | |
| 69 | - .build(); | |
| 66 | + .withMininumMeasurements(1) | |
| 67 | + .build(); | |
| 70 | 68 | Cluster.Builder builder = super.createClusterBuilder(); |
| 71 | 69 | builder.withLoadBalancingPolicy(latencyAwarePolicy); |
| 72 | 70 | Cluster cluster = builder.build(); |
| @@ -98,14 +96,14 @@ | ||
| 98 | 96 | // given |
| 99 | 97 | String query = "SELECT foo FROM bar"; |
| 100 | 98 | primingClient.prime( |
| 101 | - queryBuilder() | |
| 102 | - .withQuery(query) | |
| 103 | - .withResult(unavailable) | |
| 104 | - .build() | |
| 99 | + queryBuilder() | |
| 100 | + .withQuery(query) | |
| 101 | + .withResult(unavailable) | |
| 102 | + .build() | |
| 105 | 103 | ); |
| 106 | 104 | LatencyAwarePolicy latencyAwarePolicy = LatencyAwarePolicy.builder(new RoundRobinPolicy()) |
| 107 | - .withMininumMeasurements(1) | |
| 108 | - .build(); | |
| 105 | + .withMininumMeasurements(1) | |
| 106 | + .build(); | |
| 109 | 107 | Cluster.Builder builder = super.createClusterBuilder(); |
| 110 | 108 | builder.withLoadBalancingPolicy(latencyAwarePolicy); |
| 111 | 109 | Cluster cluster = builder.build(); |
| @@ -138,14 +136,14 @@ | ||
| 138 | 136 | } |
| 139 | 137 | } |
| 140 | 138 | |
| 141 | - @Test(groups= "short") | |
| 139 | + @Test(groups = "short") | |
| 142 | 140 | public void should_consider_latency_when_read_timeout() throws Exception { |
| 143 | 141 | String query = "SELECT foo FROM bar"; |
| 144 | 142 | primingClient.prime( |
| 145 | - queryBuilder() | |
| 146 | - .withQuery(query) | |
| 147 | - .withResult(read_request_timeout) | |
| 148 | - .build() | |
| 143 | + queryBuilder() | |
| 144 | + .withQuery(query) | |
| 145 | + .withResult(read_request_timeout) | |
| 146 | + .build() | |
| 149 | 147 | ); |
| 150 | 148 | |
| 151 | 149 | 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/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 −76
| @@ -15,33 +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.BoundStatement; | |
| 28 | -import com.datastax.driver.core.CCMBridge; | |
| 29 | -import com.datastax.driver.core.Cluster; | |
| 30 | -import com.datastax.driver.core.DataType; | |
| 31 | -import com.datastax.driver.core.Host; | |
| 32 | -import com.datastax.driver.core.PreparedStatement; | |
| 33 | -import com.datastax.driver.core.QueryTracker; | |
| 34 | -import com.datastax.driver.core.ResultSet; | |
| 35 | -import com.datastax.driver.core.Row; | |
| 36 | -import com.datastax.driver.core.ScassandraCluster; | |
| 37 | -import com.datastax.driver.core.Session; | |
| 38 | -import com.datastax.driver.core.SimpleStatement; | |
| 39 | -import com.datastax.driver.core.TestUtils; | |
| 25 | +import java.nio.ByteBuffer; | |
| 26 | +import java.util.List; | |
| 40 | 27 | |
| 41 | 28 | import static com.datastax.driver.core.Assertions.assertThat; |
| 42 | -import static com.datastax.driver.core.TestUtils.CREATE_KEYSPACE_SIMPLE_FORMAT; | |
| 43 | -import static com.datastax.driver.core.TestUtils.SIMPLE_KEYSPACE; | |
| 44 | -import static com.datastax.driver.core.TestUtils.nonQuietClusterCloseOptions; | |
| 29 | +import static com.datastax.driver.core.TestUtils.*; | |
| 45 | 30 | |
| 46 | 31 | public class TokenAwarePolicyTest { |
| 47 | 32 | |
| @@ -52,12 +37,12 @@ | ||
| 52 | 37 | queryTracker = new QueryTracker(); |
| 53 | 38 | } |
| 54 | 39 | |
| 55 | - @DataProvider(name="shuffleProvider") | |
| 56 | - public Object[][] shuffleProvider () { | |
| 57 | - return new Object[][] { | |
| 58 | - { true }, | |
| 59 | - { false }, | |
| 60 | - { null } | |
| 40 | + @DataProvider(name = "shuffleProvider") | |
| 41 | + public Object[][] shuffleProvider() { | |
| 42 | + return new Object[][]{ | |
| 43 | + {true}, | |
| 44 | + {false}, | |
| 45 | + {null} | |
| 61 | 46 | }; |
| 62 | 47 | } |
| 63 | 48 | |
| @@ -68,16 +53,16 @@ | ||
| 68 | 53 | * |
| 69 | 54 | * @test_category load_balancing:token_aware |
| 70 | 55 | */ |
| 71 | - @Test(groups="short", dataProvider="shuffleProvider") | |
| 56 | + @Test(groups = "short", dataProvider = "shuffleProvider") | |
| 72 | 57 | public void should_shuffle_replicas_based_on_configuration(Boolean shuffleReplicas) { |
| 73 | 58 | // given: an 8 node cluster using TokenAwarePolicy and some shuffle replica configuration with a keyspace with replication factor of 3. |
| 74 | 59 | ScassandraCluster sCluster = ScassandraCluster.builder() |
| 75 | - .withNodes(8) | |
| 76 | - .withSimpleKeyspace("keyspace", 3) | |
| 77 | - .build(); | |
| 60 | + .withNodes(8) | |
| 61 | + .withSimpleKeyspace("keyspace", 3) | |
| 62 | + .build(); | |
| 78 | 63 | |
| 79 | 64 | LoadBalancingPolicy loadBalancingPolicy; |
| 80 | - if(shuffleReplicas == null) { | |
| 65 | + if (shuffleReplicas == null) { | |
| 81 | 66 | loadBalancingPolicy = new TokenAwarePolicy(new RoundRobinPolicy()); |
| 82 | 67 | shuffleReplicas = true; |
| 83 | 68 | } else { |
| @@ -85,9 +70,9 @@ | ||
| 85 | 70 | } |
| 86 | 71 | |
| 87 | 72 | Cluster cluster = Cluster.builder().addContactPoints(sCluster.address(1)) |
| 88 | - .withNettyOptions(nonQuietClusterCloseOptions) | |
| 89 | - .withLoadBalancingPolicy(loadBalancingPolicy) | |
| 90 | - .build(); | |
| 73 | + .withNettyOptions(nonQuietClusterCloseOptions) | |
| 74 | + .withLoadBalancingPolicy(loadBalancingPolicy) | |
| 75 | + .build(); | |
| 91 | 76 | |
| 92 | 77 | try { |
| 93 | 78 | sCluster.init(); |
| @@ -100,9 +85,9 @@ | ||
| 100 | 85 | // then: The replicas resolved from the cluster metadata must match node 6 and its replicas. |
| 101 | 86 | List<Host> replicas = Lists.newArrayList(cluster.getMetadata().getReplicas("keyspace", routingKey)); |
| 102 | 87 | assertThat(replicas).containsExactly( |
| 103 | - sCluster.host(cluster, 1, 6), | |
| 104 | - sCluster.host(cluster, 1, 7), | |
| 105 | - sCluster.host(cluster, 1, 8)); | |
| 88 | + sCluster.host(cluster, 1, 6), | |
| 89 | + sCluster.host(cluster, 1, 7), | |
| 90 | + sCluster.host(cluster, 1, 8)); | |
| 106 | 91 | |
| 107 | 92 | // then: generating a query plan on a statement using that routing key should properly prioritize node 6 and its replicas. |
| 108 | 93 | SimpleStatement statement = new SimpleStatement("select * from table where k=5"); |
| @@ -110,16 +95,16 @@ | ||
| 110 | 95 | statement.setKeyspace("keyspace"); |
| 111 | 96 | |
| 112 | 97 | boolean shuffledAtLeastOnce = false; |
| 113 | - for(int i = 0; i < 1024; i++) { | |
| 98 | + for (int i = 0; i < 1024; i++) { | |
| 114 | 99 | List<Host> queryPlan = Lists.newArrayList(loadBalancingPolicy.newQueryPlan(null, statement)); |
| 115 | 100 | assertThat(queryPlan).containsOnlyElementsOf(cluster.getMetadata().getAllHosts()); |
| 116 | 101 | |
| 117 | 102 | List<Host> firstThree = queryPlan.subList(0, 3); |
| 118 | 103 | // then: if shuffle replicas was used or using default, the first three hosts returned should be 6,7,8 in any order. |
| 119 | 104 | // if shuffle replicas was not used, the first three hosts returned should be 6,7,8 in that order. |
| 120 | - if(shuffleReplicas) { | |
| 105 | + if (shuffleReplicas) { | |
| 121 | 106 | assertThat(firstThree).containsOnlyElementsOf(replicas); |
| 122 | - if(!firstThree.equals(replicas)) { | |
| 107 | + if (!firstThree.equals(replicas)) { | |
| 123 | 108 | shuffledAtLeastOnce = true; |
| 124 | 109 | } |
| 125 | 110 | } else { |
| @@ -142,17 +127,17 @@ | ||
| 142 | 127 | * |
| 143 | 128 | * @test_category load_balancing:token_aware |
| 144 | 129 | */ |
| 145 | - @Test(groups="short") | |
| 130 | + @Test(groups = "short") | |
| 146 | 131 | public void should_choose_proper_host_based_on_routing_key() { |
| 147 | 132 | // given: A 3 node cluster using TokenAwarePolicy with a replication factor of 1. |
| 148 | 133 | ScassandraCluster sCluster = ScassandraCluster.builder() |
| 149 | - .withNodes(3) | |
| 150 | - .withSimpleKeyspace("keyspace", 1) | |
| 151 | - .build(); | |
| 134 | + .withNodes(3) | |
| 135 | + .withSimpleKeyspace("keyspace", 1) | |
| 136 | + .build(); | |
| 152 | 137 | Cluster cluster = Cluster.builder().addContactPoints(sCluster.address(1)) |
| 153 | - .withNettyOptions(nonQuietClusterCloseOptions) | |
| 154 | - .withLoadBalancingPolicy(new TokenAwarePolicy(new RoundRobinPolicy())) | |
| 155 | - .build(); | |
| 138 | + .withNettyOptions(nonQuietClusterCloseOptions) | |
| 139 | + .withLoadBalancingPolicy(new TokenAwarePolicy(new RoundRobinPolicy())) | |
| 140 | + .build(); | |
| 156 | 141 | |
| 157 | 142 | // when: A query is made with a routing key |
| 158 | 143 | try { |
| @@ -163,8 +148,8 @@ | ||
| 163 | 148 | // Encodes into murmur hash '4557949199137838892' which should belong be owned by node 3. |
| 164 | 149 | ByteBuffer routingKey = DataType.text().serialize("should_choose_proper_host_based_on_routing_key"); |
| 165 | 150 | SimpleStatement statement = new SimpleStatement("select * from table where k=5") |
| 166 | - .setRoutingKey(routingKey) | |
| 167 | - .setKeyspace("keyspace"); | |
| 151 | + .setRoutingKey(routingKey) | |
| 152 | + .setKeyspace("keyspace"); | |
| 168 | 153 | |
| 169 | 154 | queryTracker.query(session, 10, statement); |
| 170 | 155 | |
| @@ -185,20 +170,20 @@ | ||
| 185 | 170 | * |
| 186 | 171 | * @test_category load_balancing:token_aware |
| 187 | 172 | */ |
| 188 | - @Test(groups="short") | |
| 173 | + @Test(groups = "short") | |
| 189 | 174 | public void should_choose_host_in_local_dc_when_using_network_topology_strategy_and_dc_aware() { |
| 190 | 175 | // given: A 6 node, 2 DC cluster with RF 1:1, using TokenAwarePolicy wrapping DCAwareRoundRobinPolicy with remote hosts. |
| 191 | 176 | ScassandraCluster sCluster = ScassandraCluster.builder() |
| 192 | - .withNodes(3, 3) | |
| 193 | - .withNetworkTopologyKeyspace("keyspace", ImmutableMap.of(1, 1, 2, 1)) | |
| 194 | - .build(); | |
| 195 | - Cluster cluster = Cluster.builder().addContactPoints(sCluster.address(2,1)) | |
| 196 | - .withNettyOptions(nonQuietClusterCloseOptions) | |
| 197 | - .withLoadBalancingPolicy(new TokenAwarePolicy(DCAwareRoundRobinPolicy.builder() | |
| 198 | - .withLocalDc(ScassandraCluster.datacenter(2)) | |
| 199 | - .withUsedHostsPerRemoteDc(3) | |
| 200 | - .build())) | |
| 201 | - .build(); | |
| 177 | + .withNodes(3, 3) | |
| 178 | + .withNetworkTopologyKeyspace("keyspace", ImmutableMap.of(1, 1, 2, 1)) | |
| 179 | + .build(); | |
| 180 | + Cluster cluster = Cluster.builder().addContactPoints(sCluster.address(2, 1)) | |
| 181 | + .withNettyOptions(nonQuietClusterCloseOptions) | |
| 182 | + .withLoadBalancingPolicy(new TokenAwarePolicy(DCAwareRoundRobinPolicy.builder() | |
| 183 | + .withLocalDc(ScassandraCluster.datacenter(2)) | |
| 184 | + .withUsedHostsPerRemoteDc(3) | |
| 185 | + .build())) | |
| 186 | + .build(); | |
| 202 | 187 | |
| 203 | 188 | // when: A query is made with a routing key |
| 204 | 189 | try { |
| @@ -209,8 +194,8 @@ | ||
| 209 | 194 | // Encodes into murmur hash '-8124212968526248339' which should belong to 1:1 in DC1 and 2:1 in DC2. |
| 210 | 195 | ByteBuffer routingKey = DataType.text().serialize("should_choose_host_in_local_dc_when_using_network_topology_strategy_and_dc_aware"); |
| 211 | 196 | SimpleStatement statement = new SimpleStatement("select * from table where k=5") |
| 212 | - .setRoutingKey(routingKey) | |
| 213 | - .setKeyspace("keyspace"); | |
| 197 | + .setRoutingKey(routingKey) | |
| 198 | + .setKeyspace("keyspace"); | |
| 214 | 199 | |
| 215 | 200 | queryTracker.query(session, 10, statement); |
| 216 | 201 | |
| @@ -230,18 +215,18 @@ | ||
| 230 | 215 | * |
| 231 | 216 | * @test_category load_balancing:token_aware |
| 232 | 217 | */ |
| 233 | - @Test(groups="short") | |
| 218 | + @Test(groups = "short") | |
| 234 | 219 | public void should_use_other_nodes_when_replicas_having_token_are_down() { |
| 235 | 220 | // given: A 4 node cluster using TokenAwarePolicy with a replication factor of 2. |
| 236 | 221 | ScassandraCluster sCluster = ScassandraCluster.builder() |
| 237 | - .withNodes(4) | |
| 238 | - .withSimpleKeyspace("keyspace", 2) | |
| 239 | - .build(); | |
| 222 | + .withNodes(4) | |
| 223 | + .withSimpleKeyspace("keyspace", 2) | |
| 224 | + .build(); | |
| 240 | 225 | Cluster cluster = Cluster.builder().addContactPoints(sCluster.address(2)) |
| 241 | - .withNettyOptions(nonQuietClusterCloseOptions) | |
| 242 | - // Don't shuffle replicas just to keep test deterministic. | |
| 243 | - .withLoadBalancingPolicy(new TokenAwarePolicy(new RoundRobinPolicy(), false)) | |
| 244 | - .build(); | |
| 226 | + .withNettyOptions(nonQuietClusterCloseOptions) | |
| 227 | + // Don't shuffle replicas just to keep test deterministic. | |
| 228 | + .withLoadBalancingPolicy(new TokenAwarePolicy(new RoundRobinPolicy(), false)) | |
| 229 | + .build(); | |
| 245 | 230 | |
| 246 | 231 | try { |
| 247 | 232 | sCluster.init(); |
| @@ -252,8 +237,8 @@ | ||
| 252 | 237 | // Encodes into murmur hash '6444339665561646341' which should belong to node 4. |
| 253 | 238 | ByteBuffer routingKey = DataType.text().serialize("should_use_other_nodes_when_replicas_having_token_are_down"); |
| 254 | 239 | SimpleStatement statement = new SimpleStatement("select * from table where k=5") |
| 255 | - .setRoutingKey(routingKey) | |
| 256 | - .setKeyspace("keyspace"); | |
| 240 | + .setRoutingKey(routingKey) | |
| 241 | + .setKeyspace("keyspace"); | |
| 257 | 242 | |
| 258 | 243 | queryTracker.query(session, 10, statement); |
| 259 | 244 | |
| @@ -326,9 +311,9 @@ | ||
| 326 | 311 | CCMBridge ccm = CCMBridge.builder("TokenAwarePolicyTest").withNodes(3).notStarted().build(); |
| 327 | 312 | |
| 328 | 313 | Cluster cluster = Cluster.builder() |
| 329 | - .withLoadBalancingPolicy(new TokenAwarePolicy(new RoundRobinPolicy())) | |
| 330 | - .addContactPoint(CCMBridge.ipOfNode(1)) | |
| 331 | - .build(); | |
| 314 | + .withLoadBalancingPolicy(new TokenAwarePolicy(new RoundRobinPolicy())) | |
| 315 | + .addContactPoint(CCMBridge.ipOfNode(1)) | |
| 316 | + .build(); | |
| 332 | 317 | |
| 333 | 318 | try { |
| 334 | 319 | ccm.start(); |
| @@ -344,11 +329,11 @@ | ||
| 344 | 329 | BoundStatement insertBs = insertPs.bind(1, 2, 3); |
| 345 | 330 | |
| 346 | 331 | PreparedStatement selectPs = session.prepare("SELECT * FROM " + table + " WHERE k1=? and k2=?"); |
| 347 | - BoundStatement selectBs = selectPs.bind(1,2); | |
| 332 | + BoundStatement selectBs = selectPs.bind(1, 2); | |
| 348 | 333 | |
| 349 | 334 | // when: executing a prepared statement with a composite partition key. |
| 350 | 335 | // then: should query the correct node (1) in for both insert and select queries. |
| 351 | - for(int i = 0; i < 10; i++) { | |
| 336 | + for (int i = 0; i < 10; i++) { | |
| 352 | 337 | ResultSet rs = session.execute(insertBs); |
| 353 | 338 | assertThat(rs.getExecutionInfo().getQueriedHost()).isEqualTo(TestUtils.findHost(cluster, 1)); |
| 354 | 339 |
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/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(TestUtils.CREATE_TABLE_SIMPLE_FORMAT, 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(TestUtils.CREATE_TABLE_SIMPLE_FORMAT, 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 +19 −17
| @@ -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,9 +217,9 @@ | ||
| 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; |
| @@ -241,9 +243,9 @@ | ||
| 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 +8 −10
| @@ -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 |
modified driver-core/src/test/java/com/datastax/driver/core/querybuilder/QueryBuilderTest.java +116 −97
| @@ -15,24 +15,20 @@ | ||
| 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 | - | |
| 23 | -import org.testng.annotations.Test; | |
| 24 | - | |
| 25 | -import static org.assertj.core.api.Assertions.assertThat; | |
| 26 | -import static org.testng.Assert.assertEquals; | |
| 27 | -import static org.testng.Assert.assertTrue; | |
| 28 | -import static org.testng.Assert.fail; | |
| 29 | - | |
| 30 | 18 | import com.datastax.driver.core.ConsistencyLevel; |
| 31 | 19 | import com.datastax.driver.core.RegularStatement; |
| 32 | 20 | import com.datastax.driver.core.Statement; |
| 33 | 21 | import com.datastax.driver.core.exceptions.InvalidQueryException; |
| 22 | +import org.testng.annotations.Test; | |
| 23 | + | |
| 24 | +import java.math.BigDecimal; | |
| 25 | +import java.math.BigInteger; | |
| 26 | +import java.net.InetAddress; | |
| 27 | +import java.util.*; | |
| 34 | 28 | |
| 35 | 29 | import static com.datastax.driver.core.querybuilder.QueryBuilder.*; |
| 30 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 31 | +import static org.testng.Assert.*; | |
| 36 | 32 | |
| 37 | 33 | public class QueryBuilderTest { |
| 38 | 34 | |
| @@ -52,10 +48,10 @@ | ||
| 52 | 48 | |
| 53 | 49 | 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;"; |
| 54 | 50 | select = select("a", "b", quote("C")).from("foo") |
| 55 | - .where(in("a", InetAddress.getByName("127.0.0.1"), InetAddress.getByName("127.0.0.3"))) | |
| 56 | - .and(eq(quote("C"), "foo")) | |
| 57 | - .orderBy(asc("a"), desc("b")) | |
| 58 | - .limit(42); | |
| 51 | + .where(in("a", InetAddress.getByName("127.0.0.1"), InetAddress.getByName("127.0.0.3"))) | |
| 52 | + .and(eq(quote("C"), "foo")) | |
| 53 | + .orderBy(asc("a"), desc("b")) | |
| 54 | + .limit(42); | |
| 59 | 55 | assertEquals(select.toString(), query); |
| 60 | 56 | |
| 61 | 57 | query = "SELECT writetime(a),ttl(a) FROM foo ALLOW FILTERING;"; |
| @@ -163,63 +159,67 @@ | ||
| 163 | 159 | |
| 164 | 160 | 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;"; |
| 165 | 161 | insert = insertInto("foo") |
| 166 | - .value("a", 123) | |
| 167 | - .value("b", InetAddress.getByName("127.0.0.1")) | |
| 168 | - .value(quote("C"), "foo'bar") | |
| 169 | - .value("d", new TreeMap<String, Integer>() {{ | |
| 170 | - put("x", 3); | |
| 171 | - put("y", 2); | |
| 172 | - }}) | |
| 173 | - .using(timestamp(42)).and(ttl(24)); | |
| 162 | + .value("a", 123) | |
| 163 | + .value("b", InetAddress.getByName("127.0.0.1")) | |
| 164 | + .value(quote("C"), "foo'bar") | |
| 165 | + .value("d", new TreeMap<String, Integer>() {{ | |
| 166 | + put("x", 3); | |
| 167 | + put("y", 2); | |
| 168 | + }}) | |
| 169 | + .using(timestamp(42)).and(ttl(24)); | |
| 174 | 170 | assertEquals(insert.toString(), query); |
| 175 | 171 | |
| 176 | 172 | query = "INSERT INTO foo(a,b) VALUES (2,null);"; |
| 177 | 173 | insert = insertInto("foo") |
| 178 | - .value("a", 2) | |
| 179 | - .value("b", null); | |
| 174 | + .value("a", 2) | |
| 175 | + .value("b", null); | |
| 180 | 176 | assertEquals(insert.toString(), query); |
| 181 | 177 | |
| 182 | 178 | query = "INSERT INTO foo(a,b) VALUES ({2,3,4},3.4) USING TTL 24 AND TIMESTAMP 42;"; |
| 183 | - insert = insertInto("foo").values(new String[]{ "a", "b" }, new Object[]{ new TreeSet<Integer>() {{ | |
| 179 | + insert = insertInto("foo").values(new String[]{"a", "b"}, new Object[]{new TreeSet<Integer>() {{ | |
| 184 | 180 | add(2); |
| 185 | 181 | add(3); |
| 186 | 182 | add(4); |
| 187 | - }}, 3.4 }).using(ttl(24)).and(timestamp(42)); | |
| 183 | + }}, 3.4}).using(ttl(24)).and(timestamp(42)); | |
| 188 | 184 | assertEquals(insert.toString(), query); |
| 189 | 185 | |
| 190 | 186 | query = "INSERT INTO foo.bar(a,b) VALUES ({2,3,4},3.4) USING TTL ? AND TIMESTAMP ?;"; |
| 191 | 187 | insert = insertInto("foo", "bar") |
| 192 | - .values(new String[]{ "a", "b" }, new Object[]{ new TreeSet<Integer>() {{ | |
| 193 | - add(2); | |
| 194 | - add(3); | |
| 195 | - add(4); | |
| 196 | - }}, 3.4 }) | |
| 197 | - .using(ttl(bindMarker())) | |
| 198 | - .and(timestamp(bindMarker())); | |
| 188 | + .values(new String[]{"a", "b"}, new Object[]{new TreeSet<Integer>() {{ | |
| 189 | + add(2); | |
| 190 | + add(3); | |
| 191 | + add(4); | |
| 192 | + }}, 3.4}) | |
| 193 | + .using(ttl(bindMarker())) | |
| 194 | + .and(timestamp(bindMarker())); | |
| 199 | 195 | assertEquals(insert.toString(), query); |
| 200 | 196 | |
| 201 | 197 | // commutative result of TIMESTAMP |
| 202 | 198 | query = "INSERT INTO foo.bar(a,b,c) VALUES ({2,3,4},3.4,123) USING TIMESTAMP 42;"; |
| 203 | 199 | insert = insertInto("foo", "bar") |
| 204 | - .using(timestamp(42)) | |
| 205 | - .values(new String[]{ "a", "b" }, new Object[]{ new TreeSet<Integer>() {{ | |
| 206 | - add(2); | |
| 207 | - add(3); | |
| 208 | - add(4); | |
| 209 | - }}, 3.4 }) | |
| 210 | - .value("c", 123); | |
| 200 | + .using(timestamp(42)) | |
| 201 | + .values(new String[]{"a", "b"}, new Object[]{new TreeSet<Integer>() {{ | |
| 202 | + add(2); | |
| 203 | + add(3); | |
| 204 | + add(4); | |
| 205 | + }}, 3.4}) | |
| 206 | + .value("c", 123); | |
| 211 | 207 | assertEquals(insert.toString(), query); |
| 212 | 208 | |
| 213 | 209 | // commutative result of value() and values() |
| 214 | 210 | query = "INSERT INTO foo(c,a,b) VALUES (123,{2,3,4},3.4) USING TIMESTAMP 42;"; |
| 215 | 211 | insert = insertInto("foo") |
| 216 | - .using(timestamp(42)) | |
| 217 | - .value("c", 123) | |
| 218 | - .values(new String[]{ "a", "b"}, new Object[]{ new TreeSet<Integer>(){{ add(2); add(3); add(4); }}, 3.4 }); | |
| 212 | + .using(timestamp(42)) | |
| 213 | + .value("c", 123) | |
| 214 | + .values(new String[]{"a", "b"}, new Object[]{new TreeSet<Integer>() {{ | |
| 215 | + add(2); | |
| 216 | + add(3); | |
| 217 | + add(4); | |
| 218 | + }}, 3.4}); | |
| 219 | 219 | assertEquals(insert.toString(), query); |
| 220 | 220 | |
| 221 | 221 | try { |
| 222 | - insert = insertInto("foo").values(new String[]{ "a", "b"}, new Object[]{ 1, 2, 3 }); | |
| 222 | + insert = insertInto("foo").values(new String[]{"a", "b"}, new Object[]{1, 2, 3}); | |
| 223 | 223 | fail(); |
| 224 | 224 | } catch (IllegalArgumentException e) { |
| 225 | 225 | assertEquals(e.getMessage(), "Got 2 names but 3 values"); |
| @@ -255,20 +255,31 @@ | ||
| 255 | 255 | assertEquals(update.toString(), query); |
| 256 | 256 | |
| 257 | 257 | query = "UPDATE foo SET b=b-[1,2,3],c=c+{1},d=d+{2,3,4};"; |
| 258 | - update = update("foo").with(discardAll("b", Arrays.asList(1, 2, 3))).and(add("c", 1)).and(addAll("d", new TreeSet<Integer>(){{ add(2); add(3); add(4); }})); | |
| 258 | + update = update("foo").with(discardAll("b", Arrays.asList(1, 2, 3))).and(add("c", 1)).and(addAll("d", new TreeSet<Integer>() {{ | |
| 259 | + add(2); | |
| 260 | + add(3); | |
| 261 | + add(4); | |
| 262 | + }})); | |
| 259 | 263 | assertEquals(update.toString(), query); |
| 260 | 264 | |
| 261 | 265 | query = "UPDATE foo SET b=b-{2,3,4},c['k']='v',d=d+{'x':3,'y':2};"; |
| 262 | - update = update("foo").with(removeAll("b", new TreeSet<Integer>(){{ add(2); add(3); add(4); }})) | |
| 263 | - .and(put("c", "k", "v")) | |
| 264 | - .and(putAll("d", new TreeMap<String, Integer>(){{ put("x", 3); put("y", 2); }})); | |
| 266 | + update = update("foo").with(removeAll("b", new TreeSet<Integer>() {{ | |
| 267 | + add(2); | |
| 268 | + add(3); | |
| 269 | + add(4); | |
| 270 | + }})) | |
| 271 | + .and(put("c", "k", "v")) | |
| 272 | + .and(putAll("d", new TreeMap<String, Integer>() {{ | |
| 273 | + put("x", 3); | |
| 274 | + put("y", 2); | |
| 275 | + }})); | |
| 265 | 276 | assertEquals(update.toString(), query); |
| 266 | 277 | |
| 267 | 278 | query = "UPDATE foo USING TTL 400;"; |
| 268 | 279 | update = update("foo").using(ttl(400)); |
| 269 | 280 | assertEquals(update.toString(), query); |
| 270 | 281 | |
| 271 | - query = "UPDATE foo SET a="+new BigDecimal(3.2)+",b=42 WHERE k=2;"; | |
| 282 | + query = "UPDATE foo SET a=" + new BigDecimal(3.2) + ",b=42 WHERE k=2;"; | |
| 272 | 283 | update = update("foo").with(set("a", new BigDecimal(3.2))).and(set("b", new BigInteger("42"))).where(eq("k", 2)); |
| 273 | 284 | assertEquals(update.toString(), query); |
| 274 | 285 | |
| @@ -300,7 +311,7 @@ | ||
| 300 | 311 | update = update("foo").with(set("x", 3)).where(eq("k", 2)).ifExists(); |
| 301 | 312 | assertThat(update.toString()).isEqualTo("UPDATE foo SET x=3 WHERE k=2 IF EXISTS;"); |
| 302 | 313 | } |
| 303 | - | |
| 314 | + | |
| 304 | 315 | @Test(groups = "unit") |
| 305 | 316 | public void deleteTest() throws Exception { |
| 306 | 317 | |
| @@ -373,10 +384,14 @@ | ||
| 373 | 384 | query += "DELETE a[3],b['foo'],c FROM foo WHERE k=1;"; |
| 374 | 385 | query += "APPLY BATCH;"; |
| 375 | 386 | batch = batch() |
| 376 | - .add(insertInto("foo").values(new String[]{ "a", "b"}, new Object[]{ new TreeSet<Integer>(){{ add(2); add(3); add(4); }}, 3.4 })) | |
| 377 | - .add(update("foo").with(setIdx("a", 2, "foo")).and(prependAll("b", Arrays.asList(3, 2, 1))).and(remove("c", "a")).where(eq("k", 2))) | |
| 378 | - .add(delete().listElt("a", 3).mapElt("b", "foo").column("c").from("foo").where(eq("k", 1))) | |
| 379 | - .using(timestamp(42)); | |
| 387 | + .add(insertInto("foo").values(new String[]{"a", "b"}, new Object[]{new TreeSet<Integer>() {{ | |
| 388 | + add(2); | |
| 389 | + add(3); | |
| 390 | + add(4); | |
| 391 | + }}, 3.4})) | |
| 392 | + .add(update("foo").with(setIdx("a", 2, "foo")).and(prependAll("b", Arrays.asList(3, 2, 1))).and(remove("c", "a")).where(eq("k", 2))) | |
| 393 | + .add(delete().listElt("a", 3).mapElt("b", "foo").column("c").from("foo").where(eq("k", 1))) | |
| 394 | + .using(timestamp(42)); | |
| 380 | 395 | assertEquals(batch.toString(), query); |
| 381 | 396 | |
| 382 | 397 | // Test passing batch(statement) |
| @@ -401,10 +416,10 @@ | ||
| 401 | 416 | query += "UPDATE foo SET c=c+3;"; |
| 402 | 417 | query += "APPLY BATCH;"; |
| 403 | 418 | batch = batch() |
| 404 | - .add(update("foo").with(incr("a", 1))) | |
| 405 | - .add(update("foo").with(incr("b", 2))) | |
| 406 | - .add(update("foo").with(incr("c", 3))) | |
| 407 | - .using(timestamp(42)); | |
| 419 | + .add(update("foo").with(incr("a", 1))) | |
| 420 | + .add(update("foo").with(incr("b", 2))) | |
| 421 | + .add(update("foo").with(incr("c", 3))) | |
| 422 | + .using(timestamp(42)); | |
| 408 | 423 | assertEquals(batch.toString(), query); |
| 409 | 424 | |
| 410 | 425 | // Test single increments |
| @@ -414,10 +429,10 @@ | ||
| 414 | 429 | query += "UPDATE foo SET c=c+1;"; |
| 415 | 430 | query += "APPLY BATCH;"; |
| 416 | 431 | batch = batch() |
| 417 | - .add(update("foo").with(incr("a"))) | |
| 418 | - .add(update("foo").with(incr("b"))) | |
| 419 | - .add(update("foo").with(incr("c"))) | |
| 420 | - .using(timestamp(42)); | |
| 432 | + .add(update("foo").with(incr("a"))) | |
| 433 | + .add(update("foo").with(incr("b"))) | |
| 434 | + .add(update("foo").with(incr("c"))) | |
| 435 | + .using(timestamp(42)); | |
| 421 | 436 | assertEquals(batch.toString(), query); |
| 422 | 437 | |
| 423 | 438 | // Test value decrements |
| @@ -427,10 +442,10 @@ | ||
| 427 | 442 | query += "UPDATE foo SET c=c-3;"; |
| 428 | 443 | query += "APPLY BATCH;"; |
| 429 | 444 | batch = batch() |
| 430 | - .add(update("foo").with(decr("a", 1))) | |
| 431 | - .add(update("foo").with(decr("b", 2))) | |
| 432 | - .add(update("foo").with(decr("c", 3))) | |
| 433 | - .using(timestamp(42)); | |
| 445 | + .add(update("foo").with(decr("a", 1))) | |
| 446 | + .add(update("foo").with(decr("b", 2))) | |
| 447 | + .add(update("foo").with(decr("c", 3))) | |
| 448 | + .using(timestamp(42)); | |
| 434 | 449 | assertEquals(batch.toString(), query); |
| 435 | 450 | |
| 436 | 451 | // Test single decrements |
| @@ -440,10 +455,10 @@ | ||
| 440 | 455 | query += "UPDATE foo SET c=c-1;"; |
| 441 | 456 | query += "APPLY BATCH;"; |
| 442 | 457 | batch = batch() |
| 443 | - .add(update("foo").with(decr("a"))) | |
| 444 | - .add(update("foo").with(decr("b"))) | |
| 445 | - .add(update("foo").with(decr("c"))) | |
| 446 | - .using(timestamp(42)); | |
| 458 | + .add(update("foo").with(decr("a"))) | |
| 459 | + .add(update("foo").with(decr("b"))) | |
| 460 | + .add(update("foo").with(decr("c"))) | |
| 461 | + .using(timestamp(42)); | |
| 447 | 462 | assertEquals(batch.toString(), query); |
| 448 | 463 | |
| 449 | 464 | // Test negative decrements and negative increments |
| @@ -453,23 +468,23 @@ | ||
| 453 | 468 | query += "UPDATE foo SET c=c-3;"; |
| 454 | 469 | query += "APPLY BATCH;"; |
| 455 | 470 | batch = batch() |
| 456 | - .add(update("foo").with(decr("a", -1))) | |
| 457 | - .add(update("foo").with(incr("b", -2))) | |
| 458 | - .add(update("foo").with(decr("c", 3))) | |
| 459 | - .using(timestamp(42)); | |
| 471 | + .add(update("foo").with(decr("a", -1))) | |
| 472 | + .add(update("foo").with(incr("b", -2))) | |
| 473 | + .add(update("foo").with(decr("c", 3))) | |
| 474 | + .using(timestamp(42)); | |
| 460 | 475 | assertEquals(batch.toString(), query); |
| 461 | 476 | } |
| 462 | 477 | |
| 463 | - @Test(groups = "unit", expectedExceptions={IllegalArgumentException.class}) | |
| 478 | + @Test(groups = "unit", expectedExceptions = {IllegalArgumentException.class}) | |
| 464 | 479 | public void batchMixedCounterTest() throws Exception { |
| 465 | 480 | String query; |
| 466 | 481 | Statement batch; |
| 467 | 482 | |
| 468 | 483 | batch = batch() |
| 469 | - .add(update("foo").with(incr("a", 1))) | |
| 470 | - .add(update("foo").with(set("b", 2))) | |
| 471 | - .add(update("foo").with(incr("c", 3))) | |
| 472 | - .using(timestamp(42)); | |
| 484 | + .add(update("foo").with(incr("a", 1))) | |
| 485 | + .add(update("foo").with(set("b", 2))) | |
| 486 | + .add(update("foo").with(incr("c", 3))) | |
| 487 | + .using(timestamp(42)); | |
| 473 | 488 | } |
| 474 | 489 | |
| 475 | 490 | @Test(groups = "unit") |
| @@ -479,8 +494,8 @@ | ||
| 479 | 494 | |
| 480 | 495 | query = "INSERT INTO test(k,c) VALUES (0,?);"; |
| 481 | 496 | insert = insertInto("test") |
| 482 | - .value("k", 0) | |
| 483 | - .value("c", bindMarker()); | |
| 497 | + .value("k", 0) | |
| 498 | + .value("c", bindMarker()); | |
| 484 | 499 | assertEquals(insert.toString(), query); |
| 485 | 500 | } |
| 486 | 501 | |
| @@ -580,7 +595,11 @@ | ||
| 580 | 595 | assertEquals(insert.toString(), query); |
| 581 | 596 | |
| 582 | 597 | query = "INSERT INTO foo(a,b) VALUES ({'2''} space','3','4'},3.4) USING TTL 24 AND TIMESTAMP 42;"; |
| 583 | - 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)); | |
| 598 | + insert = insertInto("foo").values(new String[]{"a", "b"}, new Object[]{new TreeSet<String>() {{ | |
| 599 | + add("2'} space"); | |
| 600 | + add("3"); | |
| 601 | + add("4"); | |
| 602 | + }}, 3.4}).using(ttl(24)).and(timestamp(42)); | |
| 584 | 603 | assertEquals(insert.toString(), query); |
| 585 | 604 | } |
| 586 | 605 | |
| @@ -680,22 +699,22 @@ | ||
| 680 | 699 | @Test(groups = "unit") |
| 681 | 700 | public void quotingTest() { |
| 682 | 701 | assertEquals(QueryBuilder.select().from("Metrics", "epochs").getQueryString(), |
| 683 | - "SELECT * FROM Metrics.epochs;"); | |
| 702 | + "SELECT * FROM Metrics.epochs;"); | |
| 684 | 703 | assertEquals(QueryBuilder.select().from("Metrics", quote("epochs")).getQueryString(), |
| 685 | - "SELECT * FROM Metrics.\"epochs\";"); | |
| 704 | + "SELECT * FROM Metrics.\"epochs\";"); | |
| 686 | 705 | assertEquals(QueryBuilder.select().from(quote("Metrics"), "epochs").getQueryString(), |
| 687 | - "SELECT * FROM \"Metrics\".epochs;"); | |
| 706 | + "SELECT * FROM \"Metrics\".epochs;"); | |
| 688 | 707 | assertEquals(QueryBuilder.select().from(quote("Metrics"), quote("epochs")).getQueryString(), |
| 689 | - "SELECT * FROM \"Metrics\".\"epochs\";"); | |
| 708 | + "SELECT * FROM \"Metrics\".\"epochs\";"); | |
| 690 | 709 | |
| 691 | 710 | assertEquals(QueryBuilder.insertInto("Metrics", "epochs").getQueryString(), |
| 692 | - "INSERT INTO Metrics.epochs() VALUES ();"); | |
| 711 | + "INSERT INTO Metrics.epochs() VALUES ();"); | |
| 693 | 712 | assertEquals(QueryBuilder.insertInto("Metrics", quote("epochs")).getQueryString(), |
| 694 | - "INSERT INTO Metrics.\"epochs\"() VALUES ();"); | |
| 713 | + "INSERT INTO Metrics.\"epochs\"() VALUES ();"); | |
| 695 | 714 | assertEquals(QueryBuilder.insertInto(quote("Metrics"), "epochs").getQueryString(), |
| 696 | - "INSERT INTO \"Metrics\".epochs() VALUES ();"); | |
| 715 | + "INSERT INTO \"Metrics\".epochs() VALUES ();"); | |
| 697 | 716 | assertEquals(QueryBuilder.insertInto(quote("Metrics"), quote("epochs")).getQueryString(), |
| 698 | - "INSERT INTO \"Metrics\".\"epochs\"() VALUES ();"); | |
| 717 | + "INSERT INTO \"Metrics\".\"epochs\"() VALUES ();"); | |
| 699 | 718 | } |
| 700 | 719 | |
| 701 | 720 | @Test(groups = "unit") |
| @@ -709,7 +728,7 @@ | ||
| 709 | 728 | |
| 710 | 729 | query = "SELECT * FROM foo WHERE k=4 AND (c1,c2)>=('a',2) AND (c1,c2)<('b',0);"; |
| 711 | 730 | select = select().all().from("foo").where(eq("k", 4)).and(gte(Arrays.asList("c1", "c2"), Arrays.<Object>asList("a", 2))) |
| 712 | - .and(lt(Arrays.asList("c1", "c2"), Arrays.<Object>asList("b", 0))); | |
| 731 | + .and(lt(Arrays.asList("c1", "c2"), Arrays.<Object>asList("b", 0))); | |
| 713 | 732 | assertEquals(select.toString(), query); |
| 714 | 733 | |
| 715 | 734 | query = "SELECT * FROM foo WHERE k=4 AND (c1,c2)<=('a',2);"; |
| @@ -729,8 +748,8 @@ | ||
| 729 | 748 | |
| 730 | 749 | // If the excessive count results from successive DSL calls, we don't check it on the fly so this statement works: |
| 731 | 750 | BuiltStatement statement = select().all().from("foo") |
| 732 | - .where(eq("bar", "a")) | |
| 733 | - .and(in("baz", values.toArray())); | |
| 751 | + .where(eq("bar", "a")) | |
| 752 | + .and(in("baz", values.toArray())); | |
| 734 | 753 | |
| 735 | 754 | // But we still want to check it client-side, to fail fast instead of sending a bad query to Cassandra. |
| 736 | 755 | // getValues() is called on any RegularStatement before we send it (see SessionManager.makeRequestMessage). |
| @@ -779,12 +798,12 @@ | ||
| 779 | 798 | assertThat(select.getValues()).isNull(); |
| 780 | 799 | } |
| 781 | 800 | |
| 782 | - @Test(groups = "unit", expectedExceptions = { IllegalStateException.class }) | |
| 801 | + @Test(groups = "unit", expectedExceptions = {IllegalStateException.class}) | |
| 783 | 802 | public void should_throw_ISE_if_getObject_called_on_statement_without_values() { |
| 784 | 803 | select().from("test").where(eq("foo", 42)).getObject(0); // integers are appended to the CQL string |
| 785 | 804 | } |
| 786 | 805 | |
| 787 | - @Test(groups = "unit", expectedExceptions = { IndexOutOfBoundsException.class }) | |
| 806 | + @Test(groups = "unit", expectedExceptions = {IndexOutOfBoundsException.class}) | |
| 788 | 807 | public void should_throw_IOOBE_if_getObject_called_with_wrong_index() { |
| 789 | 808 | select().from("test").where(eq("foo", new Object())).getObject(1); |
| 790 | 809 | } |
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 +4 −4
| @@ -15,6 +15,9 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core.utils; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.DataType; | |
| 19 | +import org.testng.annotations.Test; | |
| 20 | + | |
| 18 | 21 | import java.nio.ByteBuffer; |
| 19 | 22 | import java.util.HashSet; |
| 20 | 23 | import java.util.Random; |
| @@ -22,12 +25,9 @@ | ||
| 22 | 25 | import java.util.UUID; |
| 23 | 26 | import java.util.concurrent.ConcurrentSkipListSet; |
| 24 | 27 | |
| 25 | -import org.testng.annotations.Test; | |
| 26 | 28 | import static org.testng.Assert.assertEquals; |
| 27 | 29 | import static org.testng.Assert.assertTrue; |
| 28 | 30 | |
| 29 | -import com.datastax.driver.core.DataType; | |
| 30 | - | |
| 31 | 31 | public class UUIDsTest { |
| 32 | 32 | |
| 33 | 33 | @Test(groups = "unit") |
| @@ -103,7 +103,7 @@ | ||
| 103 | 103 | int nbPerTstamp = 10; |
| 104 | 104 | |
| 105 | 105 | for (int i = 0; i < nbTstamp; i++) { |
| 106 | - long tstamp = (long)random.nextInt(); | |
| 106 | + long tstamp = (long) random.nextInt(); | |
| 107 | 107 | for (int j = 0; j < nbPerTstamp; j++) { |
| 108 | 108 | assertWithin(new UUID(UUIDs.makeMSB(UUIDs.fromUnixTimestamp(tstamp)), random.nextLong()), UUIDs.startOf(tstamp), UUIDs.endOf(tstamp)); |
| 109 | 109 | } |
modified driver-dse/src/main/java/com/datastax/driver/auth/DseAuthProvider.java +15 −18
| @@ -22,28 +22,28 @@ | ||
| 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 | - * | |
| 36 | + * <p/> | |
| 37 | + * <p/> | |
| 38 | 38 | * See the following documents for further details on the |
| 39 | 39 | * <a href="https://docs.oracle.com/javase/6/docs/technotes/guides/security/jgss/tutorials/LoginConfigFile.html">JAAS Login Configuration File</a> and the |
| 40 | 40 | * <a href="http://docs.oracle.com/javase/6/docs/technotes/guides/security/jaas/tutorials/GeneralAcnOnly.html">JAAS Authentication Tutorial</a> |
| 41 | 41 | * for more on JAAS in general. |
| 42 | - * | |
| 42 | + * <p/> | |
| 43 | 43 | * <h1>Authentication using ticket cache</h1> |
| 44 | 44 | * Run <code>kinit</code> to obtain a ticket and populate the cache before |
| 45 | 45 | * connecting. JAAS config: |
| 46 | - | |
| 46 | + * <p/> | |
| 47 | 47 | * <pre> |
| 48 | 48 | * DseClient { |
| 49 | 49 | * com.sun.security.auth.module.Krb5LoginModule required |
| @@ -51,13 +51,13 @@ | ||
| 51 | 51 | * renewTGT=true; |
| 52 | 52 | * }; |
| 53 | 53 | * </pre> |
| 54 | - * | |
| 55 | - * | |
| 54 | + * <p/> | |
| 55 | + * <p/> | |
| 56 | 56 | * <h1>Authentication using a keytab file</h1> |
| 57 | 57 | * To enable authentication using a keytab file, specify its location on disk. |
| 58 | 58 | * If your keytab contains more than one principal key, you should also specify |
| 59 | 59 | * which one to select. |
| 60 | - * | |
| 60 | + * <p/> | |
| 61 | 61 | * <pre> |
| 62 | 62 | * DseClient { |
| 63 | 63 | * com.sun.security.auth.module.Krb5LoginModule required |
| @@ -66,23 +66,20 @@ | ||
| 66 | 66 | * principal="user@MYDOMAIN.COM"; |
| 67 | 67 | * }; |
| 68 | 68 | * </pre> |
| 69 | - * | |
| 69 | + * <p/> | |
| 70 | 70 | * To connect to clusters using internal authentication, use the standard method for |
| 71 | 71 | * setting credentials. eg: |
| 72 | - * | |
| 72 | + * <p/> | |
| 73 | 73 | * <pre> |
| 74 | 74 | * Cluster cluster = Cluster.builder() |
| 75 | 75 | * .addContactPoint(hostname) |
| 76 | 76 | * .withCredentials("username", "password") |
| 77 | 77 | * .build(); |
| 78 | 78 | * </pre> |
| 79 | - * | |
| 80 | 79 | */ |
| 81 | -public class DseAuthProvider implements AuthProvider | |
| 82 | -{ | |
| 80 | +public class DseAuthProvider implements AuthProvider { | |
| 83 | 81 | @Override |
| 84 | - public Authenticator newAuthenticator(InetSocketAddress host) throws AuthenticationException | |
| 85 | - { | |
| 82 | + public Authenticator newAuthenticator(InetSocketAddress host) throws AuthenticationException { | |
| 86 | 83 | return new KerberosAuthenticator(host); |
| 87 | 84 | } |
| 88 | 85 | } |
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 +33 −34
| @@ -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,11 +22,12 @@ | ||
| 27 | 22 | import com.datastax.driver.osgi.api.MailboxMessage; |
| 28 | 23 | import com.datastax.driver.osgi.api.MailboxService; |
| 29 | 24 | |
| 30 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.bindMarker; | |
| 31 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.delete; | |
| 32 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; | |
| 33 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.insertInto; | |
| 34 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.select; | |
| 25 | +import java.util.ArrayList; | |
| 26 | +import java.util.Collection; | |
| 27 | +import java.util.Date; | |
| 28 | +import java.util.UUID; | |
| 29 | + | |
| 30 | +import static com.datastax.driver.core.querybuilder.QueryBuilder.*; | |
| 35 | 31 | |
| 36 | 32 | public class MailboxImpl implements MailboxService { |
| 37 | 33 | |
| @@ -55,7 +51,7 @@ | ||
| 55 | 51 | } |
| 56 | 52 | |
| 57 | 53 | public synchronized void init() { |
| 58 | - if(initialized) | |
| 54 | + if (initialized) | |
| 59 | 55 | return; |
| 60 | 56 | |
| 61 | 57 | // Create the schema if it does not exist. |
| @@ -63,53 +59,55 @@ | ||
| 63 | 59 | session.execute("USE " + keyspace); |
| 64 | 60 | } catch (InvalidQueryException e) { |
| 65 | 61 | session.execute("CREATE KEYSPACE " + keyspace + |
| 66 | - " with replication = {'class': 'SimpleStrategy', 'replication_factor' : 1}"); | |
| 62 | + " with replication = {'class': 'SimpleStrategy', 'replication_factor' : 1}"); | |
| 67 | 63 | |
| 68 | 64 | session.execute("CREATE TABLE " + keyspace + "." + TABLE + " (" + |
| 69 | - "recipient text," + | |
| 70 | - "time timeuuid," + | |
| 71 | - "sender text," + | |
| 72 | - "body text," + | |
| 73 | - "PRIMARY KEY (recipient, time))"); | |
| 65 | + "recipient text," + | |
| 66 | + "time timeuuid," + | |
| 67 | + "sender text," + | |
| 68 | + "body text," + | |
| 69 | + "PRIMARY KEY (recipient, time))"); | |
| 74 | 70 | } |
| 75 | 71 | |
| 76 | 72 | retrieveStatement = session.prepare(select() |
| 77 | - .from(keyspace, TABLE) | |
| 78 | - .where(eq("recipient", bindMarker()))); | |
| 73 | + .from(keyspace, TABLE) | |
| 74 | + .where(eq("recipient", bindMarker()))); | |
| 79 | 75 | |
| 80 | 76 | insertStatement = session.prepare(insertInto(keyspace, TABLE) |
| 81 | - .value("recipient", bindMarker()) | |
| 82 | - .value("time", bindMarker()) | |
| 83 | - .value("sender", bindMarker()) | |
| 84 | - .value("body", bindMarker())); | |
| 77 | + .value("recipient", bindMarker()) | |
| 78 | + .value("time", bindMarker()) | |
| 79 | + .value("sender", bindMarker()) | |
| 80 | + .value("body", bindMarker())); | |
| 85 | 81 | |
| 86 | 82 | deleteStatement = session.prepare(delete().from(keyspace, TABLE) |
| 87 | - .where(eq("recipient", bindMarker()))); | |
| 83 | + .where(eq("recipient", bindMarker()))); | |
| 88 | 84 | |
| 89 | 85 | initialized = true; |
| 90 | 86 | } |
| 91 | 87 | |
| 92 | - @Override public Collection<MailboxMessage> getMessages(String recipient) throws MailboxException { | |
| 88 | + @Override | |
| 89 | + public Collection<MailboxMessage> getMessages(String recipient) throws MailboxException { | |
| 93 | 90 | try { |
| 94 | 91 | BoundStatement statement = new BoundStatement(retrieveStatement); |
| 95 | 92 | statement.setString(0, recipient); |
| 96 | 93 | ResultSet result = session.execute(statement); |
| 97 | 94 | |
| 98 | 95 | Collection<MailboxMessage> messages = new ArrayList<MailboxMessage>(); |
| 99 | - for(Row input : result) { | |
| 96 | + for (Row input : result) { | |
| 100 | 97 | Date date = new Date(UUIDs.unixTimestamp(input.getUUID("time"))); |
| 101 | 98 | messages.add(new MailboxMessage(input.getString("recipient"), |
| 102 | - date, | |
| 103 | - input.getString("sender"), | |
| 104 | - input.getString("body"))); | |
| 99 | + date, | |
| 100 | + input.getString("sender"), | |
| 101 | + input.getString("body"))); | |
| 105 | 102 | } |
| 106 | 103 | return messages; |
| 107 | - } catch(Exception e) { | |
| 104 | + } catch (Exception e) { | |
| 108 | 105 | throw new MailboxException(e); |
| 109 | 106 | } |
| 110 | 107 | } |
| 111 | 108 | |
| 112 | - @Override public UUID sendMessage(MailboxMessage message) throws MailboxException { | |
| 109 | + @Override | |
| 110 | + public UUID sendMessage(MailboxMessage message) throws MailboxException { | |
| 113 | 111 | try { |
| 114 | 112 | UUID time = UUIDs.startOf(message.getDate().getTime()); |
| 115 | 113 | |
| @@ -121,17 +119,18 @@ | ||
| 121 | 119 | |
| 122 | 120 | session.execute(statement); |
| 123 | 121 | return time; |
| 124 | - } catch(Exception e) { | |
| 122 | + } catch (Exception e) { | |
| 125 | 123 | throw new MailboxException(e); |
| 126 | 124 | } |
| 127 | 125 | } |
| 128 | 126 | |
| 129 | - @Override public void clearMailbox(String recipient) throws MailboxException { | |
| 127 | + @Override | |
| 128 | + public void clearMailbox(String recipient) throws MailboxException { | |
| 130 | 129 | try { |
| 131 | 130 | BoundStatement statement = new BoundStatement(deleteStatement); |
| 132 | 131 | statement.setString(0, recipient); |
| 133 | 132 | session.execute(statement); |
| 134 | - } catch(Exception e) { | |
| 133 | + } catch (Exception e) { | |
| 135 | 134 | throw new MailboxException(e); |
| 136 | 135 | } |
| 137 | 136 | } |
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/MailboxServiceIT.java +59 −58
| @@ -15,11 +15,10 @@ | ||
| 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.core.CCMBridge; | |
| 19 | +import com.datastax.driver.osgi.api.MailboxException; | |
| 20 | +import com.datastax.driver.osgi.api.MailboxMessage; | |
| 21 | +import com.datastax.driver.osgi.api.MailboxService; | |
| 23 | 22 | import org.ops4j.pax.exam.Configuration; |
| 24 | 23 | import org.ops4j.pax.exam.Option; |
| 25 | 24 | import org.ops4j.pax.exam.options.CompositeOption; |
| @@ -29,20 +28,20 @@ | ||
| 29 | 28 | import org.testng.annotations.Listeners; |
| 30 | 29 | import org.testng.annotations.Test; |
| 31 | 30 | |
| 32 | -import static org.ops4j.pax.exam.CoreOptions.*; | |
| 33 | -import static org.testng.Assert.assertEquals; | |
| 34 | - | |
| 35 | -import com.datastax.driver.core.CCMBridge; | |
| 36 | -import com.datastax.driver.osgi.api.MailboxException; | |
| 37 | -import com.datastax.driver.osgi.api.MailboxMessage; | |
| 38 | -import com.datastax.driver.osgi.api.MailboxService; | |
| 31 | +import javax.inject.Inject; | |
| 32 | +import java.util.ArrayList; | |
| 33 | +import java.util.Collection; | |
| 34 | +import java.util.GregorianCalendar; | |
| 39 | 35 | |
| 40 | 36 | import static com.datastax.driver.osgi.VersionProvider.projectVersion; |
| 37 | +import static org.ops4j.pax.exam.CoreOptions.*; | |
| 38 | +import static org.testng.Assert.assertEquals; | |
| 41 | 39 | |
| 42 | 40 | @Listeners({CCMBridgeListener.class, PaxExam.class}) |
| 43 | -@Test(groups="short") | |
| 41 | +@Test(groups = "short") | |
| 44 | 42 | public class MailboxServiceIT { |
| 45 | - @Inject MailboxService service; | |
| 43 | + @Inject | |
| 44 | + MailboxService service; | |
| 46 | 45 | |
| 47 | 46 | private UrlProvisionOption driverBundle() { |
| 48 | 47 | return driverBundle(false); |
| @@ -61,13 +60,14 @@ | ||
| 61 | 60 | final String nettyVersion = "4.0.27.Final"; |
| 62 | 61 | return new CompositeOption() { |
| 63 | 62 | |
| 64 | - @Override public Option[] getOptions() { | |
| 63 | + @Override | |
| 64 | + public Option[] getOptions() { | |
| 65 | 65 | return options( |
| 66 | - mavenBundle("io.netty", "netty-buffer", nettyVersion), | |
| 67 | - mavenBundle("io.netty", "netty-codec", nettyVersion), | |
| 68 | - mavenBundle("io.netty", "netty-common", nettyVersion), | |
| 69 | - mavenBundle("io.netty", "netty-handler", nettyVersion), | |
| 70 | - mavenBundle("io.netty", "netty-transport", nettyVersion) | |
| 66 | + mavenBundle("io.netty", "netty-buffer", nettyVersion), | |
| 67 | + mavenBundle("io.netty", "netty-codec", nettyVersion), | |
| 68 | + mavenBundle("io.netty", "netty-common", nettyVersion), | |
| 69 | + mavenBundle("io.netty", "netty-handler", nettyVersion), | |
| 70 | + mavenBundle("io.netty", "netty-transport", nettyVersion) | |
| 71 | 71 | ); |
| 72 | 72 | } |
| 73 | 73 | }; |
| @@ -76,15 +76,16 @@ | ||
| 76 | 76 | private CompositeOption defaultOptions() { |
| 77 | 77 | return new CompositeOption() { |
| 78 | 78 | |
| 79 | - @Override public Option[] getOptions() { | |
| 79 | + @Override | |
| 80 | + public Option[] getOptions() { | |
| 80 | 81 | return options( |
| 81 | - systemProperty("cassandra.contactpoints").value(CCMBridge.IP_PREFIX + 1), | |
| 82 | - bundle("reference:file:target/classes"), | |
| 83 | - mavenBundle("com.codahale.metrics", "metrics-core", "3.0.2"), | |
| 84 | - mavenBundle("org.slf4j", "slf4j-api", "1.7.5"), | |
| 85 | - mavenBundle("org.slf4j", "slf4j-simple", "1.7.5").noStart(), | |
| 86 | - systemPackages("org.testng", "org.junit", "org.junit.runner", "org.junit.runner.manipulation", | |
| 87 | - "org.junit.runner.notification", "com.jcabi.manifests") | |
| 82 | + systemProperty("cassandra.contactpoints").value(CCMBridge.IP_PREFIX + 1), | |
| 83 | + bundle("reference:file:target/classes"), | |
| 84 | + mavenBundle("com.codahale.metrics", "metrics-core", "3.0.2"), | |
| 85 | + mavenBundle("org.slf4j", "slf4j-api", "1.7.5"), | |
| 86 | + mavenBundle("org.slf4j", "slf4j-simple", "1.7.5").noStart(), | |
| 87 | + systemPackages("org.testng", "org.junit", "org.junit.runner", "org.junit.runner.manipulation", | |
| 88 | + "org.junit.runner.notification", "com.jcabi.manifests") | |
| 88 | 89 | ); |
| 89 | 90 | } |
| 90 | 91 | }; |
| @@ -93,59 +94,59 @@ | ||
| 93 | 94 | @Configuration |
| 94 | 95 | public Option[] shadedConfig() { |
| 95 | 96 | return options( |
| 96 | - driverBundle(true), | |
| 97 | - guavaBundle(), | |
| 98 | - defaultOptions() | |
| 97 | + driverBundle(true), | |
| 98 | + guavaBundle(), | |
| 99 | + defaultOptions() | |
| 99 | 100 | ); |
| 100 | 101 | } |
| 101 | 102 | |
| 102 | 103 | @Configuration |
| 103 | 104 | public Option[] defaultConfig() { |
| 104 | 105 | return options( |
| 105 | - driverBundle(), | |
| 106 | - guavaBundle(), | |
| 107 | - nettyBundles(), | |
| 108 | - defaultOptions() | |
| 106 | + driverBundle(), | |
| 107 | + guavaBundle(), | |
| 108 | + nettyBundles(), | |
| 109 | + defaultOptions() | |
| 109 | 110 | ); |
| 110 | 111 | } |
| 111 | 112 | |
| 112 | 113 | @Configuration |
| 113 | 114 | public Option[] guava15Config() { |
| 114 | 115 | return options( |
| 115 | - driverBundle(), | |
| 116 | - nettyBundles(), | |
| 117 | - guavaBundle().version("15.0"), | |
| 118 | - defaultOptions() | |
| 116 | + driverBundle(), | |
| 117 | + nettyBundles(), | |
| 118 | + guavaBundle().version("15.0"), | |
| 119 | + defaultOptions() | |
| 119 | 120 | ); |
| 120 | 121 | } |
| 121 | 122 | |
| 122 | 123 | @Configuration |
| 123 | 124 | public Option[] guava16Config() { |
| 124 | 125 | return options( |
| 125 | - driverBundle(), | |
| 126 | - nettyBundles(), | |
| 127 | - guavaBundle().version("16.0.1"), | |
| 128 | - defaultOptions() | |
| 126 | + driverBundle(), | |
| 127 | + nettyBundles(), | |
| 128 | + guavaBundle().version("16.0.1"), | |
| 129 | + defaultOptions() | |
| 129 | 130 | ); |
| 130 | 131 | } |
| 131 | 132 | |
| 132 | 133 | @Configuration |
| 133 | 134 | public Option[] guava17Config() { |
| 134 | 135 | return options( |
| 135 | - driverBundle(), | |
| 136 | - nettyBundles(), | |
| 137 | - guavaBundle().version("17.0"), | |
| 138 | - defaultOptions() | |
| 136 | + driverBundle(), | |
| 137 | + nettyBundles(), | |
| 138 | + guavaBundle().version("17.0"), | |
| 139 | + defaultOptions() | |
| 139 | 140 | ); |
| 140 | 141 | } |
| 141 | 142 | |
| 142 | 143 | @Configuration |
| 143 | 144 | public Option[] guava18Config() { |
| 144 | 145 | return options( |
| 145 | - driverBundle(), | |
| 146 | - nettyBundles(), | |
| 147 | - guavaBundle().version("18.0"), | |
| 148 | - defaultOptions() | |
| 146 | + driverBundle(), | |
| 147 | + nettyBundles(), | |
| 148 | + guavaBundle().version("18.0"), | |
| 149 | + defaultOptions() | |
| 149 | 150 | ); |
| 150 | 151 | } |
| 151 | 152 | |
| @@ -154,15 +155,15 @@ | ||
| 154 | 155 | * Exercises a 'mailbox' service provided by an OSGi bundle that depends on the driver. Ensures that |
| 155 | 156 | * queries can be made through the service with the current given configuration. |
| 156 | 157 | * </p> |
| 157 | - * | |
| 158 | + * <p/> | |
| 158 | 159 | * The following configurations are tried (defined via methods with the @Configuration annotation): |
| 159 | 160 | * <ol> |
| 160 | - * <li>Default bundle (Driver with all of it's dependencies)</li> | |
| 161 | - * <li>Shaded bundle (Driver with netty shaded)</li> | |
| 162 | - * <li>With Guava 15</li> | |
| 163 | - * <li>With Guava 16</li> | |
| 164 | - * <li>With Guava 17</li> | |
| 165 | - * <li>With Guava 18</li> | |
| 161 | + * <li>Default bundle (Driver with all of it's dependencies)</li> | |
| 162 | + * <li>Shaded bundle (Driver with netty shaded)</li> | |
| 163 | + * <li>With Guava 15</li> | |
| 164 | + * <li>With Guava 16</li> | |
| 165 | + * <li>With Guava 17</li> | |
| 166 | + * <li>With Guava 18</li> | |
| 166 | 167 | * </ol> |
| 167 | 168 | * |
| 168 | 169 | * @test_category packaging |
modified driver-examples/osgi/src/test/java/com/datastax/driver/osgi/VersionProvider.java +2 −1
| @@ -20,12 +20,13 @@ | ||
| 20 | 20 | /** |
| 21 | 21 | * Attempts to resolve the project version from the Bundle manifest. If not present, will throw RuntimeException |
| 22 | 22 | * on initialization. If this happens, try building with 'mvn compile' to generate the Bundle manifest. |
| 23 | - * | |
| 23 | + * <p/> | |
| 24 | 24 | * In IntelliJ you can have compile run after make by right clicking on 'compile' in the 'Maven Projects' tool window. |
| 25 | 25 | */ |
| 26 | 26 | public class VersionProvider { |
| 27 | 27 | |
| 28 | 28 | private static String PROJECT_VERSION; |
| 29 | + | |
| 29 | 30 | static { |
| 30 | 31 | String bundleName = Manifests.read("Bundle-SymbolicName"); |
| 31 | 32 | if (bundleName.equals("com.datastax.driver.osgi")) { |
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) | |
| 108 | - : createPrepared(id, iterations, options, session); | |
| 106 | + ? createRegular(id, iterations, options) | |
| 107 | + : createPrepared(id, iterations, options, session); | |
| 109 | 108 | } |
| 110 | 109 | |
| 111 | 110 | public QueryGenerator createRegular(int id, int iterations, OptionSet options) { |
| 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) | |
| 188 | - : createPrepared(id, iterations, session); | |
| 186 | + ? createRegular(id, iterations) | |
| 187 | + : createPrepared(id, iterations, session); | |
| 189 | 188 | } |
| 190 | 189 | |
| 191 | 190 | public QueryGenerator createRegular(long id, int iterations) { |
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.setMaxSimultaneousRequestsPerConnectionThreshold(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..."); |