Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ public int hashCode() {
* Builder for {@link QueryOptions}.
*
* @author Mark Paluch
* @author Seungho Kang
* @since 1.5
*/
public static class QueryOptionsBuilder {
Expand Down Expand Up @@ -482,8 +483,7 @@ public QueryOptionsBuilder readTimeout(long readTimeout, TimeUnit timeUnit) {
@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;

Expand Down Expand Up @@ -548,7 +548,7 @@ public QueryOptionsBuilder serialConsistencyLevel(ConsistencyLevel consistencyLe
*/
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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
* @author Mark Paluch
* @author Tomasz Lelek
* @author Sam Lightfoot
* @author Seungho Kang
*/
class QueryOptionsUnitTests {

Expand Down Expand Up @@ -86,4 +87,34 @@ void buildQueryOptionsMutate() {
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());
}
}