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 @@ -151,6 +151,7 @@ public int hashCode() {
151
151
*
152
152
* @author Mark Paluch
153
153
* @author Lukasz Antoniak
154
+ * @author Thomas Strauß
154
155
* @since 1.5
155
156
*/
156
157
public static class WriteOptionsBuilder extends QueryOptionsBuilder {
@@ -344,7 +345,7 @@ public WriteOptionsBuilder ttl(int ttl) {
344
345
public WriteOptionsBuilder ttl (Duration ttl ) {
345
346
346
347
Assert .notNull (ttl , "TTL must not be null" );
347
- Assert .isTrue (!ttl .isNegative (), "TTL must be greater than equal to zero" );
348
+ Assert .isTrue (!ttl .isNegative () && ! ttl . isZero () , "TTL must be greater than equal to zero" );
348
349
349
350
this .ttl = ttl ;
350
351
Original file line number Diff line number Diff line change 22
22
import java .time .Instant ;
23
23
import java .time .LocalDateTime ;
24
24
import java .time .ZoneOffset ;
25
+ import java .time .temporal .ChronoUnit ;
25
26
26
27
import org .junit .jupiter .api .Test ;
27
28
33
34
*
34
35
* @author Mark Paluch
35
36
* @author Sam Lightfoot
37
+ * @author Thomas Strauß
36
38
*/
37
39
class WriteOptionsUnitTests {
38
40
@@ -106,4 +108,32 @@ void buildWriteOptionsMutate() {
106
108
CqlIdentifier .fromCql ("routing_keyspace" ));
107
109
assertThat (writeOptions .getRoutingKey ()).isEqualTo (ByteBuffer .allocate (1 ));
108
110
}
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
+ }
109
139
}
You can’t perform that action at this time.
0 commit comments