Allow QueryOptions to disable timeout.
If it is zero, the read timeout will be disabled for this statement. Closes #1494 Original pull request: #1495
This commit is contained in:
@@ -284,6 +284,7 @@ public class QueryOptions {
|
||||
* Builder for {@link QueryOptions}.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author Seungho Kang
|
||||
* @since 1.5
|
||||
*/
|
||||
public static class QueryOptionsBuilder {
|
||||
@@ -482,8 +483,7 @@ public class QueryOptions {
|
||||
@Deprecated
|
||||
public QueryOptionsBuilder readTimeout(Duration readTimeout) {
|
||||
|
||||
Assert.isTrue(!readTimeout.isZero() && !readTimeout.isNegative(),
|
||||
"ReadTimeout must be greater than equal to zero");
|
||||
Assert.isTrue(!readTimeout.isNegative(), "ReadTimeout must be greater than equal to zero");
|
||||
|
||||
this.timeout = readTimeout;
|
||||
|
||||
@@ -548,7 +548,7 @@ public class QueryOptions {
|
||||
*/
|
||||
public QueryOptionsBuilder timeout(Duration timeout) {
|
||||
|
||||
Assert.isTrue(!timeout.isZero() && !timeout.isNegative(), "ReadTimeout must be greater than equal to zero");
|
||||
Assert.isTrue(!timeout.isNegative(), "ReadTimeout must be greater than equal to zero");
|
||||
|
||||
this.timeout = timeout;
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ import com.datastax.oss.driver.api.core.DefaultConsistencyLevel;
|
||||
* @author Mark Paluch
|
||||
* @author Tomasz Lelek
|
||||
* @author Sam Lightfoot
|
||||
* @author Seungho Kang
|
||||
*/
|
||||
class QueryOptionsUnitTests {
|
||||
|
||||
@@ -86,4 +87,34 @@ class QueryOptionsUnitTests {
|
||||
assertThat(mutated.getRoutingKeyspace()).isEqualTo(CqlIdentifier.fromCql("rksl"));
|
||||
assertThat(mutated.getRoutingKey()).isEqualTo(ByteBuffer.allocate(1));
|
||||
}
|
||||
|
||||
@Test // GH-1494
|
||||
void buildZeroDurationTimeoutQueryOptions() {
|
||||
|
||||
QueryOptions queryOptions = QueryOptions.builder().timeout(Duration.ofSeconds(0)).build();
|
||||
|
||||
assertThat(queryOptions.getTimeout()).isEqualTo(Duration.ZERO);
|
||||
}
|
||||
|
||||
@Test // GH-1494
|
||||
void shouldRejectNegativeDurationTimeoutQueryOptions() {
|
||||
|
||||
assertThatIllegalArgumentException().isThrownBy(
|
||||
() -> QueryOptions.builder().timeout(Duration.ofSeconds(-1)).build());
|
||||
}
|
||||
|
||||
@Test // GH-1494
|
||||
void buildZeroDurationReadTimeoutQueryOptions() {
|
||||
|
||||
QueryOptions queryOptions = QueryOptions.builder().readTimeout(Duration.ofSeconds(0)).build();
|
||||
|
||||
assertThat(queryOptions.getReadTimeout()).isEqualTo(Duration.ZERO);
|
||||
}
|
||||
|
||||
@Test // GH-1494
|
||||
void shouldRejectNegativeDurationReadTimeoutQueryOptions() {
|
||||
|
||||
assertThatIllegalArgumentException().isThrownBy(
|
||||
() -> QueryOptions.builder().readTimeout(Duration.ofSeconds(-1)).build());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user