Skip to content

Commit 17850b7

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 0dca3e6 commit 17850b7

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ public int hashCode() {
148148
* @author Mark Paluch
149149
* @author Lukasz Antoniak
150150
* @author Thomas Strauß
151+
* @author Tudor Marc
151152
* @since 1.5
152153
*/
153154
public static class WriteOptionsBuilder extends QueryOptionsBuilder {
@@ -306,7 +307,7 @@ public WriteOptionsBuilder ttl(int ttl) {
306307
public WriteOptionsBuilder ttl(Duration ttl) {
307308

308309
Assert.notNull(ttl, "TTL must not be null");
309-
Assert.isTrue(!ttl.isNegative() && !ttl.isZero(), "TTL must be greater than equal to zero");
310+
Assert.isTrue(!ttl.isNegative(), "TTL must be greater than equal to zero");
310311

311312
this.ttl = ttl;
312313

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

+9-6
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
*
3434
* @author Mark Paluch
3535
* @author Thomas Strauß
36+
* @author Tudor Marc
3637
*/
3738
class WriteOptionsUnitTests {
3839

@@ -92,16 +93,18 @@ void buildWriteOptionsMutate() {
9293
assertThat(mutated.getTracing()).isTrue();
9394
}
9495

95-
@Test // GH-1248
96-
void buildWriteOptionsWithTtlDurationZero() {
97-
assertThatIllegalArgumentException().isThrownBy(() -> WriteOptions.builder().ttl(0));
98-
assertThatIllegalArgumentException().isThrownBy(() -> WriteOptions.builder().ttl(Duration.ZERO));
99-
}
100-
10196
@Test // GH-1248
10297
void buildWriteOptionsWithTtlNegativeDuration() {
10398
assertThatIllegalArgumentException().isThrownBy(() -> WriteOptions.builder().ttl(-1));
10499
assertThatIllegalArgumentException()
105100
.isThrownBy(() -> WriteOptions.builder().ttl(Duration.of(-1, ChronoUnit.MICROS)));
106101
}
102+
103+
@Test // GH-1262
104+
void buildZeroDurationTtlWriterOptions() {
105+
106+
WriteOptions writeOptions = WriteOptions.builder().ttl(0).build();
107+
108+
assertThat(writeOptions.getTtl()).isEqualTo(Duration.ZERO);
109+
}
107110
}

0 commit comments

Comments
 (0)