Allow WriterOptionsBuilder to set ttl to 0.
Value 0 tells the Cassandra driver to disable the ttl. Original pull request: #1270. Closes #1262
This commit is contained in:
@@ -153,6 +153,7 @@ public class WriteOptions extends QueryOptions {
|
||||
* @author Mark Paluch
|
||||
* @author Lukasz Antoniak
|
||||
* @author Thomas Strauß
|
||||
* @author Tudor Marc
|
||||
* @since 1.5
|
||||
*/
|
||||
public static class WriteOptionsBuilder extends QueryOptionsBuilder {
|
||||
@@ -341,7 +342,7 @@ public class WriteOptions extends QueryOptions {
|
||||
public WriteOptionsBuilder ttl(Duration ttl) {
|
||||
|
||||
Assert.notNull(ttl, "TTL must not be null");
|
||||
Assert.isTrue(!ttl.isNegative() && !ttl.isZero(), "TTL must be greater than equal to zero");
|
||||
Assert.isTrue(!ttl.isNegative(), "TTL must be greater than equal to zero");
|
||||
|
||||
this.ttl = ttl;
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ import com.datastax.oss.driver.api.core.DefaultConsistencyLevel;
|
||||
* @author Mark Paluch
|
||||
* @author Sam Lightfoot
|
||||
* @author Thomas Strauß
|
||||
* @author Tudor Marc
|
||||
*/
|
||||
class WriteOptionsUnitTests {
|
||||
|
||||
@@ -107,16 +108,18 @@ class WriteOptionsUnitTests {
|
||||
assertThat(writeOptions.getRoutingKey()).isEqualTo(ByteBuffer.allocate(1));
|
||||
}
|
||||
|
||||
@Test // GH-1248
|
||||
void buildWriteOptionsWithTtlDurationZero() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> WriteOptions.builder().ttl(0));
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> WriteOptions.builder().ttl(Duration.ZERO));
|
||||
}
|
||||
|
||||
@Test // GH-1248
|
||||
void buildWriteOptionsWithTtlNegativeDuration() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> WriteOptions.builder().ttl(-1));
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> WriteOptions.builder().ttl(Duration.of(-1, ChronoUnit.MICROS)));
|
||||
}
|
||||
|
||||
@Test // GH-1262
|
||||
void buildZeroDurationTtlWriterOptions() {
|
||||
|
||||
WriteOptions writeOptions = WriteOptions.builder().ttl(0).build();
|
||||
|
||||
assertThat(writeOptions.getTtl()).isEqualTo(Duration.ZERO);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user