Polishing.
Simplify invocation chain, simplify tests. See #1248 Original pull request: #1249.
This commit is contained in:
@@ -34,6 +34,7 @@ import com.datastax.oss.driver.api.core.CqlIdentifier;
|
||||
* @author Mark Paluch
|
||||
* @author Lukasz Antoniak
|
||||
* @author Tomasz Lelek
|
||||
* @author Thomas Strauß
|
||||
* @see QueryOptions
|
||||
*/
|
||||
public class WriteOptions extends QueryOptions {
|
||||
@@ -46,8 +47,7 @@ public class WriteOptions extends QueryOptions {
|
||||
|
||||
protected WriteOptions(@Nullable ConsistencyLevel consistencyLevel, ExecutionProfileResolver executionProfileResolver,
|
||||
@Nullable CqlIdentifier keyspace, @Nullable Integer pageSize, @Nullable ConsistencyLevel serialConsistencyLevel,
|
||||
Duration timeout, Duration ttl,
|
||||
@Nullable Long timestamp, @Nullable Boolean tracing) {
|
||||
Duration timeout, Duration ttl, @Nullable Long timestamp, @Nullable Boolean tracing) {
|
||||
|
||||
super(consistencyLevel, executionProfileResolver, keyspace, pageSize, serialConsistencyLevel, timeout, tracing);
|
||||
|
||||
@@ -293,12 +293,7 @@ public class WriteOptions extends QueryOptions {
|
||||
* @return {@code this} {@link WriteOptionsBuilder}
|
||||
*/
|
||||
public WriteOptionsBuilder ttl(int ttl) {
|
||||
|
||||
Assert.isTrue(ttl >= 0, "TTL must be greater than equal to zero");
|
||||
|
||||
this.ttl = Duration.ofSeconds(ttl);
|
||||
|
||||
return this;
|
||||
return ttl(Duration.ofSeconds(ttl));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -94,29 +94,14 @@ class WriteOptionsUnitTests {
|
||||
|
||||
@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
|
||||
}
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> WriteOptions.builder().ttl(0));
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> WriteOptions.builder().ttl(Duration.ZERO));
|
||||
}
|
||||
|
||||
@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
|
||||
}
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> WriteOptions.builder().ttl(-1));
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> WriteOptions.builder().ttl(Duration.of(-1, ChronoUnit.MICROS)));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user