File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed
spring-data-cassandra/src
main/java/org/springframework/data/cassandra/core/cql
test/java/org/springframework/data/cassandra/core/cql Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -147,6 +147,7 @@ public int hashCode() {
147147 *
148148 * @author Mark Paluch
149149 * @author Lukasz Antoniak
150+ * @author Thomas Strauß
150151 * @since 1.5
151152 */
152153 public static class WriteOptionsBuilder extends QueryOptionsBuilder {
@@ -310,7 +311,7 @@ public WriteOptionsBuilder ttl(int ttl) {
310311 public WriteOptionsBuilder ttl (Duration ttl ) {
311312
312313 Assert .notNull (ttl , "TTL must not be null" );
313- Assert .isTrue (!ttl .isNegative (), "TTL must be greater than equal to zero" );
314+ Assert .isTrue (!ttl .isNegative () && ! ttl . isZero () , "TTL must be greater than equal to zero" );
314315
315316 this .ttl = ttl ;
316317
Original file line number Diff line number Diff line change 2121import java .time .Instant ;
2222import java .time .LocalDateTime ;
2323import java .time .ZoneOffset ;
24+ import java .time .temporal .ChronoUnit ;
2425
2526import org .junit .jupiter .api .Test ;
2627
3132 * Unit tests for {@link WriteOptions}.
3233 *
3334 * @author Mark Paluch
35+ * @author Thomas Strauß
3436 */
3537class WriteOptionsUnitTests {
3638
@@ -89,4 +91,32 @@ void buildWriteOptionsMutate() {
8991 assertThat (mutated .getPageSize ()).isEqualTo (10 );
9092 assertThat (mutated .getTracing ()).isTrue ();
9193 }
94+
95+ @ Test // GH-1248
96+ void buildWriteOptionsWithTtlDurationZero () {
97+ try {
98+ WriteOptions writeOptions = WriteOptions .builder ()
99+ .ttl (Duration .ZERO )
100+ .build ();
101+
102+ fail ("WiteOptionsBuilder must not allow zero TTL" );
103+ }
104+ catch (Exception e ) {
105+ // expected behavior
106+ }
107+ }
108+
109+ @ Test // GH-1248
110+ void buildWriteOptionsWithTtlNegativeDuration () {
111+ try {
112+ WriteOptions writeOptions = WriteOptions .builder ()
113+ .ttl (Duration .of (-1 , ChronoUnit .MICROS ))
114+ .build ();
115+
116+ fail ("WiteOptionsBuilder must not allow negative TTL" );
117+ }
118+ catch (Exception e ) {
119+ // expected behavior
120+ }
121+ }
92122}
You can’t perform that action at this time.
0 commit comments