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 Mark Paluch
|
||||||
* @author Lukasz Antoniak
|
* @author Lukasz Antoniak
|
||||||
* @author Thomas Strauß
|
* @author Thomas Strauß
|
||||||
|
* @author Tudor Marc
|
||||||
* @since 1.5
|
* @since 1.5
|
||||||
*/
|
*/
|
||||||
public static class WriteOptionsBuilder extends QueryOptionsBuilder {
|
public static class WriteOptionsBuilder extends QueryOptionsBuilder {
|
||||||
@@ -341,7 +342,7 @@ public class WriteOptions extends QueryOptions {
|
|||||||
public WriteOptionsBuilder ttl(Duration ttl) {
|
public WriteOptionsBuilder ttl(Duration ttl) {
|
||||||
|
|
||||||
Assert.notNull(ttl, "TTL must not be null");
|
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;
|
this.ttl = ttl;
|
||||||
|
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ import com.datastax.oss.driver.api.core.DefaultConsistencyLevel;
|
|||||||
* @author Mark Paluch
|
* @author Mark Paluch
|
||||||
* @author Sam Lightfoot
|
* @author Sam Lightfoot
|
||||||
* @author Thomas Strauß
|
* @author Thomas Strauß
|
||||||
|
* @author Tudor Marc
|
||||||
*/
|
*/
|
||||||
class WriteOptionsUnitTests {
|
class WriteOptionsUnitTests {
|
||||||
|
|
||||||
@@ -107,16 +108,18 @@ class WriteOptionsUnitTests {
|
|||||||
assertThat(writeOptions.getRoutingKey()).isEqualTo(ByteBuffer.allocate(1));
|
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
|
@Test // GH-1248
|
||||||
void buildWriteOptionsWithTtlNegativeDuration() {
|
void buildWriteOptionsWithTtlNegativeDuration() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() -> WriteOptions.builder().ttl(-1));
|
assertThatIllegalArgumentException().isThrownBy(() -> WriteOptions.builder().ttl(-1));
|
||||||
assertThatIllegalArgumentException()
|
assertThatIllegalArgumentException()
|
||||||
.isThrownBy(() -> WriteOptions.builder().ttl(Duration.of(-1, ChronoUnit.MICROS)));
|
.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