kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 51a5bab7c4ed6bba6eed16f4e5dc9cda5d482485d8b4a1519a7a8dfde713df70 |
|---|---|
| Author | olim7t <omichallat+github@gmail.com> · 2016-04-12 16:22 +02:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2016-04-19 11:59 +02:00 |
| Parents | d4e62c9f03b8 |
5 files changed
modified changelog/README.md +1 −0
| @@ -5,6 +5,7 @@ | ||
| 5 | 5 | - [bug] JAVA-1132: Executing bound statement with no variables results in exception with protocol v1. |
| 6 | 6 | - [improvement] JAVA-1040: SimpleStatement parameters support in QueryLogger. |
| 7 | 7 | - [improvement] JAVA-1151: Fail fast if HdrHistogram is not in the classpath. |
| 8 | +- [improvement] JAVA-1154: Allow individual Statement to cancel the read timeout. | |
| 8 | 9 | |
| 9 | 10 | Merged from 2.1 branch: |
| 10 | 11 |
modified driver-core/src/main/java/com/datastax/driver/core/Connection.java +4 −4
| @@ -506,11 +506,11 @@ | ||
| 506 | 506 | return write(callback, -1, true); |
| 507 | 507 | } |
| 508 | 508 | |
| 509 | - ResponseHandler write(ResponseCallback callback, long readTimeoutMillis, boolean startTimeout) throws ConnectionException, BusyConnectionException { | |
| 509 | + ResponseHandler write(ResponseCallback callback, long statementReadTimeoutMillis, boolean startTimeout) throws ConnectionException, BusyConnectionException { | |
| 510 | 510 | |
| 511 | 511 | Message.Request request = callback.request(); |
| 512 | 512 | |
| 513 | - ResponseHandler handler = new ResponseHandler(this, readTimeoutMillis, callback); | |
| 513 | + ResponseHandler handler = new ResponseHandler(this, statementReadTimeoutMillis, callback); | |
| 514 | 514 | dispatcher.add(handler); |
| 515 | 515 | request.setStreamId(handler.streamId); |
| 516 | 516 | |
| @@ -1228,9 +1228,9 @@ | ||
| 1228 | 1228 | |
| 1229 | 1229 | private final AtomicBoolean isCancelled = new AtomicBoolean(); |
| 1230 | 1230 | |
| 1231 | - ResponseHandler(Connection connection, long readTimeoutMillis, ResponseCallback callback) throws BusyConnectionException { | |
| 1231 | + ResponseHandler(Connection connection, long statementReadTimeoutMillis, ResponseCallback callback) throws BusyConnectionException { | |
| 1232 | 1232 | this.connection = connection; |
| 1233 | - this.readTimeoutMillis = (readTimeoutMillis > 0) ? readTimeoutMillis : connection.factory.getReadTimeoutMillis(); | |
| 1233 | + this.readTimeoutMillis = (statementReadTimeoutMillis >= 0) ? statementReadTimeoutMillis : connection.factory.getReadTimeoutMillis(); | |
| 1234 | 1234 | this.streamId = connection.dispatcher.streamIdHandler.next(); |
| 1235 | 1235 | if (streamId == -1) |
| 1236 | 1236 | throw new BusyConnectionException(connection.address); |
modified driver-core/src/main/java/com/datastax/driver/core/SocketOptions.java +2 −4
| @@ -123,11 +123,9 @@ | ||
| 123 | 123 | * </li> |
| 124 | 124 | * </ul> |
| 125 | 125 | * <p/> |
| 126 | - * Setting a value of 0 disables read timeouts. | |
| 127 | - * <p/> | |
| 128 | - * The default value is {@link #DEFAULT_READ_TIMEOUT_MILLIS}. | |
| 126 | + * If you don't call this method, the default value is {@link #DEFAULT_READ_TIMEOUT_MILLIS}. | |
| 129 | 127 | * |
| 130 | - * @param readTimeoutMillis the timeout to set. | |
| 128 | + * @param readTimeoutMillis the timeout to set. If it is less than or equal to 0, read timeouts are disabled. | |
| 131 | 129 | * @return this {@code SocketOptions}. |
| 132 | 130 | */ |
| 133 | 131 | public SocketOptions setReadTimeoutMillis(int readTimeoutMillis) { |
modified driver-core/src/main/java/com/datastax/driver/core/Statement.java +4 −1
| @@ -19,6 +19,7 @@ | ||
| 19 | 19 | import com.datastax.driver.core.exceptions.UnsupportedProtocolVersionException; |
| 20 | 20 | import com.datastax.driver.core.policies.RetryPolicy; |
| 21 | 21 | import com.datastax.driver.core.querybuilder.BuiltStatement; |
| 22 | +import com.google.common.base.Preconditions; | |
| 22 | 23 | import com.google.common.collect.ImmutableMap; |
| 23 | 24 | |
| 24 | 25 | import java.nio.ByteBuffer; |
| @@ -330,10 +331,12 @@ | ||
| 330 | 331 | * You should override this only for statements for which the coordinator may allow a longer server-side |
| 331 | 332 | * timeout (for example aggregation queries). |
| 332 | 333 | * |
| 333 | - * @param readTimeoutMillis the timeout to set. Must be greater than 0 (or the default will be used). | |
| 334 | + * @param readTimeoutMillis the timeout to set. Negative values are not allowed. If it is 0, the read timeout will | |
| 335 | + * be disabled for this statement. | |
| 334 | 336 | * @return this {@code Statement} object. |
| 335 | 337 | */ |
| 336 | 338 | public Statement setReadTimeoutMillis(int readTimeoutMillis) { |
| 339 | + Preconditions.checkArgument(readTimeoutMillis >= 0, "read timeout must be >= 0"); | |
| 337 | 340 | this.readTimeoutMillis = readTimeoutMillis; |
| 338 | 341 | return this; |
| 339 | 342 | } |
modified driver-core/src/test/java/com/datastax/driver/core/ReadTimeoutTest.java +6 −0
| @@ -58,4 +58,10 @@ | ||
| 58 | 58 | Statement statement = new SimpleStatement(query).setReadTimeoutMillis(200); |
| 59 | 59 | session.execute(statement); |
| 60 | 60 | } |
| 61 | + | |
| 62 | + @Test(groups = "short") | |
| 63 | + public void should_disable_timeout_if_set_to_zero_at_statement_level() { | |
| 64 | + Statement statement = new SimpleStatement(query).setReadTimeoutMillis(0); | |
| 65 | + session.execute(statement); | |
| 66 | + } | |
| 61 | 67 | } |