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 @@ -143,6 +143,7 @@ public int hashCode() {
143143 *
144144 * @author Mark Paluch
145145 * @author Lukasz Antoniak
146+ * @author Thomas Strauß
146147 * @since 1.5
147148 */
148149 public static class WriteOptionsBuilder extends QueryOptionsBuilder {
@@ -291,7 +292,7 @@ public WriteOptionsBuilder ttl(int ttl) {
291292 public WriteOptionsBuilder ttl (Duration ttl ) {
292293
293294 Assert .notNull (ttl , "TTL must not be null" );
294- Assert .isTrue (!ttl .isNegative (), "TTL must be greater than equal to zero" );
295+ Assert .isTrue (!ttl .isNegative () && ! ttl . isZero () , "TTL must be greater than equal to zero" );
295296
296297 this .ttl = ttl ;
297298
Original file line number Diff line number Diff line change 2222import java .time .Instant ;
2323import java .time .LocalDateTime ;
2424import java .time .ZoneOffset ;
25+ import java .time .temporal .ChronoUnit ;
2526
2627import org .junit .jupiter .api .Test ;
2728
3334 *
3435 * @author Mark Paluch
3536 * @author Sam Lightfoot
37+ * @author Thomas Strauß
3638 */
3739class WriteOptionsUnitTests {
3840
@@ -106,4 +108,32 @@ void buildWriteOptionsMutate() {
106108 CqlIdentifier .fromCql ("routing_keyspace" ));
107109 assertThat (writeOptions .getRoutingKey ()).isEqualTo (ByteBuffer .allocate (1 ));
108110 }
111+
112+ @ Test // GH-1248
113+ void buildWriteOptionsWithTtlDurationZero () {
114+ try {
115+ WriteOptions writeOptions = WriteOptions .builder ()
116+ .ttl (Duration .ZERO )
117+ .build ();
118+
119+ fail ("WiteOptionsBuilder must not allow zero TTL" );
120+ }
121+ catch (Exception e ) {
122+ // expected behavior
123+ }
124+ }
125+
126+ @ Test // GH-1248
127+ void buildWriteOptionsWithTtlNegativeDuration () {
128+ try {
129+ WriteOptions writeOptions = WriteOptions .builder ()
130+ .ttl (Duration .of (-1 , ChronoUnit .MICROS ))
131+ .build ();
132+
133+ fail ("WiteOptionsBuilder must not allow negative TTL" );
134+ }
135+ catch (Exception e ) {
136+ // expected behavior
137+ }
138+ }
109139}
You can’t perform that action at this time.
0 commit comments