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 43405cb

Browse files
tudormarcmp911de
authored andcommitted
Allow WriterOptionsBuilder to set ttl to 0.
Value 0 tells the Cassandra driver to disable the ttl. Original pull request: #1270. Closes #1262
1 parent 8645713 commit 43405cb

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ public int hashCode() {
153153
* @author Mark Paluch
154154
* @author Lukasz Antoniak
155155
* @author Thomas Strauß
156+
* @author Tudor Marc
156157
* @since 1.5
157158
*/
158159
public static class WriteOptionsBuilder extends QueryOptionsBuilder {
@@ -341,7 +342,7 @@ public WriteOptionsBuilder ttl(int ttl) {
341342
public WriteOptionsBuilder ttl(Duration ttl) {
342343

343344
Assert.notNull(ttl, "TTL must not be null");
344-
Assert.isTrue(!ttl.isNegative() && !ttl.isZero(), "TTL must be greater than equal to zero");
345+
Assert.isTrue(!ttl.isNegative(), "TTL must be greater than equal to zero");
345346

346347
this.ttl = ttl;
347348

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
* @author Mark Paluch
3636
* @author Sam Lightfoot
3737
* @author Thomas Strauß
38+
* @author Tudor Marc
3839
*/
3940
class WriteOptionsUnitTests {
4041

@@ -107,16 +108,18 @@ void buildWriteOptionsMutate() {
107108
assertThat(writeOptions.getRoutingKey()).isEqualTo(ByteBuffer.allocate(1));
108109
}
109110

110-
@Test // GH-1248
111-
void buildWriteOptionsWithTtlDurationZero() {
112-
assertThatIllegalArgumentException().isThrownBy(() -> WriteOptions.builder().ttl(0));
113-
assertThatIllegalArgumentException().isThrownBy(() -> WriteOptions.builder().ttl(Duration.ZERO));
114-
}
115-
116111
@Test // GH-1248
117112
void buildWriteOptionsWithTtlNegativeDuration() {
118113
assertThatIllegalArgumentException().isThrownBy(() -> WriteOptions.builder().ttl(-1));
119114
assertThatIllegalArgumentException()
120115
.isThrownBy(() -> WriteOptions.builder().ttl(Duration.of(-1, ChronoUnit.MICROS)));
121116
}
117+
118+
@Test // GH-1262
119+
void buildZeroDurationTtlWriterOptions() {
120+
121+
WriteOptions writeOptions = WriteOptions.builder().ttl(0).build();
122+
123+
assertThat(writeOptions.getTtl()).isEqualTo(Duration.ZERO);
124+
}
122125
}

0 commit comments

Comments
(0)

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