Polishing.

Simplify invocation chain, simplify tests.

See #1248
Original pull request: #1249.
This commit is contained in:
Mark Paluch
2022-03-28 10:48:55 +02:00
parent d46d6a470a
commit 0dae41395a
2 changed files with 8 additions and 28 deletions

View File

@@ -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));
}
/**

View File

@@ -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)));
}
}