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:
@@ -148,6 +148,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 {
|
||||
@@ -306,7 +307,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;
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ import com.datastax.oss.driver.api.core.DefaultConsistencyLevel;
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author Thomas Strauß
|
||||
* @author Tudor Marc
|
||||
*/
|
||||
class WriteOptionsUnitTests {
|
||||
|
||||
@@ -92,16 +93,18 @@ class WriteOptionsUnitTests {
|
||||
assertThat(mutated.getTracing()).isTrue();
|
||||
}
|
||||
|
||||
@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