Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit de11972

Browse files
committed
Allow QueryOptions to set timeout to 0.
If it is zero, the read timeout will be disabled for this statement. Closes #1494
1 parent 100b267 commit de11972

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

‎spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/QueryOptions.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ public int hashCode() {
284284
* Builder for {@link QueryOptions}.
285285
*
286286
* @author Mark Paluch
287+
* @author Seungho Kang
287288
* @since 1.5
288289
*/
289290
public static class QueryOptionsBuilder {
@@ -482,8 +483,7 @@ public QueryOptionsBuilder readTimeout(long readTimeout, TimeUnit timeUnit) {
482483
@Deprecated
483484
public QueryOptionsBuilder readTimeout(Duration readTimeout) {
484485

485-
Assert.isTrue(!readTimeout.isZero() && !readTimeout.isNegative(),
486-
"ReadTimeout must be greater than equal to zero");
486+
Assert.isTrue(!readTimeout.isNegative(), "ReadTimeout must be greater than equal to zero");
487487

488488
this.timeout = readTimeout;
489489

@@ -548,7 +548,7 @@ public QueryOptionsBuilder serialConsistencyLevel(ConsistencyLevel consistencyLe
548548
*/
549549
public QueryOptionsBuilder timeout(Duration timeout) {
550550

551-
Assert.isTrue(!timeout.isZero() && !timeout.isNegative(), "ReadTimeout must be greater than equal to zero");
551+
Assert.isTrue(!timeout.isNegative(), "ReadTimeout must be greater than equal to zero");
552552

553553
this.timeout = timeout;
554554

‎spring-data-cassandra/src/test/java/org/springframework/data/cassandra/core/cql/QueryOptionsUnitTests.java‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
* @author Mark Paluch
3232
* @author Tomasz Lelek
3333
* @author Sam Lightfoot
34+
* @author Seungho Kang
3435
*/
3536
class QueryOptionsUnitTests {
3637

@@ -86,4 +87,34 @@ void buildQueryOptionsMutate() {
8687
assertThat(mutated.getRoutingKeyspace()).isEqualTo(CqlIdentifier.fromCql("rksl"));
8788
assertThat(mutated.getRoutingKey()).isEqualTo(ByteBuffer.allocate(1));
8889
}
90+
91+
@Test // GH-1494
92+
void buildZeroDurationTimeoutQueryOptions() {
93+
94+
QueryOptions queryOptions = QueryOptions.builder().timeout(Duration.ofSeconds(0)).build();
95+
96+
assertThat(queryOptions.getTimeout()).isEqualTo(Duration.ZERO);
97+
}
98+
99+
@Test // GH-1494
100+
void shouldRejectNegativeDurationTimeoutQueryOptions() {
101+
102+
assertThatIllegalArgumentException().isThrownBy(
103+
() -> QueryOptions.builder().timeout(Duration.ofSeconds(-1)).build());
104+
}
105+
106+
@Test // GH-1494
107+
void buildZeroDurationReadTimeoutQueryOptions() {
108+
109+
QueryOptions queryOptions = QueryOptions.builder().readTimeout(Duration.ofSeconds(0)).build();
110+
111+
assertThat(queryOptions.getReadTimeout()).isEqualTo(Duration.ZERO);
112+
}
113+
114+
@Test // GH-1494
115+
void shouldRejectNegativeDurationReadTimeoutQueryOptions() {
116+
117+
assertThatIllegalArgumentException().isThrownBy(
118+
() -> QueryOptions.builder().readTimeout(Duration.ofSeconds(-1)).build());
119+
}
89120
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /