Fixes assertion for TTL duration in WriteOptionsBuilder.
Closes #1248 Original pull request: #1249.
This commit is contained in:
committed by
Mark Paluch
parent
9c009bc572
commit
0509bf58ed
@@ -143,6 +143,7 @@ public class WriteOptions extends QueryOptions {
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author Lukasz Antoniak
|
||||
* @author Thomas Strauß
|
||||
* @since 1.5
|
||||
*/
|
||||
public static class WriteOptionsBuilder extends QueryOptionsBuilder {
|
||||
@@ -291,7 +292,7 @@ public class WriteOptions extends QueryOptions {
|
||||
public WriteOptionsBuilder ttl(Duration ttl) {
|
||||
|
||||
Assert.notNull(ttl, "TTL must not be null");
|
||||
Assert.isTrue(!ttl.isNegative(), "TTL must be greater than equal to zero");
|
||||
Assert.isTrue(!ttl.isNegative() && !ttl.isZero(), "TTL must be greater than equal to zero");
|
||||
|
||||
this.ttl = ttl;
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -33,6 +34,7 @@ import com.datastax.oss.driver.api.core.DefaultConsistencyLevel;
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author Sam Lightfoot
|
||||
* @author Thomas Strauß
|
||||
*/
|
||||
class WriteOptionsUnitTests {
|
||||
|
||||
@@ -106,4 +108,32 @@ class WriteOptionsUnitTests {
|
||||
CqlIdentifier.fromCql("routing_keyspace"));
|
||||
assertThat(writeOptions.getRoutingKey()).isEqualTo(ByteBuffer.allocate(1));
|
||||
}
|
||||
|
||||
@Test // GH-1248
|
||||
void buildWriteOptionsWithTtlDurationZero() {
|
||||
try {
|
||||
WriteOptions writeOptions = WriteOptions.builder()
|
||||
.ttl(Duration.ZERO)
|
||||
.build();
|
||||
|
||||
fail("WiteOptionsBuilder must not allow zero TTL");
|
||||
}
|
||||
catch (Exception e) {
|
||||
// expected behavior
|
||||
}
|
||||
}
|
||||
|
||||
@Test // GH-1248
|
||||
void buildWriteOptionsWithTtlNegativeDuration() {
|
||||
try {
|
||||
WriteOptions writeOptions = WriteOptions.builder()
|
||||
.ttl(Duration.of(-1, ChronoUnit.MICROS))
|
||||
.build();
|
||||
|
||||
fail("WiteOptionsBuilder must not allow negative TTL");
|
||||
}
|
||||
catch (Exception e) {
|
||||
// expected behavior
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user