Skip to content

Allow WriterOptionsBuilder to set ttl to 0. #1270

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ public int hashCode() {
* @author Mark Paluch
* @author Lukasz Antoniak
* @author Thomas Strauß
* @author Tudor Marc
* @since 1.5
*/
public static class WriteOptionsBuilder extends QueryOptionsBuilder {
Expand Down Expand Up @@ -288,7 +289,7 @@ public WriteOptionsBuilder ttl(int ttl) {
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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
* @author Mark Paluch
* @author Sam Lightfoot
* @author Thomas Strauß
* @author Tudor Marc
*/
class WriteOptionsUnitTests {

Expand Down Expand Up @@ -107,16 +108,18 @@ void buildWriteOptionsMutate() {
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);
}
}