Skip to content

Commit 7c13c01

Browse files
committed
Fix mapping of Cassandra's idle-timeout and heartbeat-interval
Previous to this commit the connection idle timeout and heartbeat interval were mapped to seconds whereas Cassandra expects ms for all duration types. This commit fixes the mapping and removes the default duration unit since it should be considered ms like every other duration properties. Closes gh-23249
1 parent aab4ee9 commit 7c13c01

File tree

2 files changed

+5
-11
lines changed

2 files changed

+5
-11
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cassandra/CassandraAutoConfiguration.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,11 @@ private void mapConnectionOptions(CassandraProperties properties, CassandraDrive
146146
}
147147

148148
private void mapPoolingOptions(CassandraProperties properties, CassandraDriverOptions options) {
149-
PropertyMapper map = PropertyMapper.get();
149+
PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
150150
CassandraProperties.Pool poolProperties = properties.getPool();
151-
map.from(poolProperties::getIdleTimeout).whenNonNull().asInt(Duration::getSeconds)
151+
map.from(poolProperties::getIdleTimeout).asInt(Duration::toMillis)
152152
.to((idleTimeout) -> options.add(DefaultDriverOption.HEARTBEAT_TIMEOUT, idleTimeout));
153-
map.from(poolProperties::getHeartbeatInterval).whenNonNull().asInt(Duration::getSeconds)
153+
map.from(poolProperties::getHeartbeatInterval).asInt(Duration::toMillis)
154154
.to((heartBeatInterval) -> options.add(DefaultDriverOption.HEARTBEAT_INTERVAL, heartBeatInterval));
155155
}
156156

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cassandra/CassandraProperties.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package org.springframework.boot.autoconfigure.cassandra;
1818

1919
import java.time.Duration;
20-
import java.time.temporal.ChronoUnit;
2120
import java.util.ArrayList;
2221
import java.util.Collections;
2322
import java.util.List;
@@ -26,7 +25,6 @@
2625

2726
import org.springframework.boot.context.properties.ConfigurationProperties;
2827
import org.springframework.boot.context.properties.DeprecatedConfigurationProperty;
29-
import org.springframework.boot.convert.DurationUnit;
3028

3129
/**
3230
* Configuration properties for Cassandra.
@@ -360,18 +358,14 @@ public Throttler getThrottler() {
360358
public static class Pool {
361359

362360
/**
363-
* Idle timeout before an idle connection is removed. If a duration suffix is not
364-
* specified, seconds will be used.
361+
* Idle timeout before an idle connection is removed.
365362
*/
366-
@DurationUnit(ChronoUnit.SECONDS)
367363
private Duration idleTimeout = Duration.ofSeconds(120);
368364

369365
/**
370366
* Heartbeat interval after which a message is sent on an idle connection to make
371-
* sure it's still alive. If a duration suffix is not specified, seconds will be
372-
* used.
367+
* sure it's still alive.
373368
*/
374-
@DurationUnit(ChronoUnit.SECONDS)
375369
private Duration heartbeatInterval = Duration.ofSeconds(30);
376370

377371
public Duration getIdleTimeout() {

0 commit comments

Comments
 (0)